mirror of
https://github.com/1dot13/source.git
synced 2026-07-29 13:52:17 +02:00
New feature: random items allow spawn not themselves, but an item from a brad selection
- specify random items in RandomItems.xml - when the game creates a random item, it searches all vialbe items according to random item class and picks one randomly - this allows mappers to place items in maps that are more independent of the xml-set used, however the random items themselves msut be the same in map&mod - can also be used to broaden the enemy gun/item choices selection - for more reference, see http://www.bears-pit.com/board/ubbthreads.php/topics/310793.html#Post310793 FIX: sector curfew value was interpreted wrong git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@5594 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
@@ -7649,6 +7649,12 @@ BOOLEAN CreateItem( UINT16 usItem, INT16 bStatus, OBJECTTYPE * pObj )
|
||||
DebugBreakpoint();
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// Flugente: random items
|
||||
UINT16 newitemfromrandom = 0;
|
||||
if ( GetItemFromRandomItem(usItem, &newitemfromrandom) )
|
||||
usItem = newitemfromrandom;
|
||||
|
||||
if (Item[ usItem ].usItemClass == IC_GUN)
|
||||
{
|
||||
fRet = CreateGun( usItem, bStatus, pObj );
|
||||
@@ -14705,3 +14711,167 @@ BOOLEAN GetFirstClothesItemWithSpecificData( UINT16* pusItem, PaletteRepID aPalV
|
||||
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
#define RANDOM_ITEM_MAX_NUMBER 200
|
||||
#define RANDOM_TABOO_MAX 50
|
||||
#define RANDOM_XML_LENGTH 10
|
||||
|
||||
UINT16 randomitemarray[RANDOM_ITEM_MAX_NUMBER];
|
||||
UINT16 randomitemtabooarray[RANDOM_TABOO_MAX]; // We remember which random items we added, to prevent loops
|
||||
UINT16 randomitemclasstabooarray[RANDOM_TABOO_MAX]; // We also remember the random item classes
|
||||
|
||||
UINT16 itemcnt = 0;
|
||||
UINT16 rdtaboocnt = 0;
|
||||
UINT16 rdclasstaboocnt = 0;
|
||||
|
||||
INT8 rditemmaxcoolness = 0;
|
||||
|
||||
BOOL AddToRandomListFromRandomItemClass( UINT16 usRandomItemClass );
|
||||
BOOL AddToRandomListFromRandomItem( UINT16 usRandomItem );
|
||||
BOOL AddToRandomListFromItem( UINT16 usItem );
|
||||
BOOL RandomItemClassIsTaboo( UINT16 usRandomItemClass );
|
||||
BOOL RandomItemIsTaboo( UINT16 usRandomItem );
|
||||
|
||||
BOOLEAN GetItemFromRandomItem( UINT16 usRandomItem, UINT16* pusNewItem )
|
||||
{
|
||||
*pusNewItem = 0;
|
||||
|
||||
// is this a random item?
|
||||
if ( Item[usRandomItem].randomitem > 0 )
|
||||
{
|
||||
// we build a list of all the items in the random item class this item references to
|
||||
// We also have to check for other random item classes
|
||||
// as it is also possible to reference to other random items, we also have to check for them
|
||||
|
||||
// clear the random item arrays and reset the counters
|
||||
for ( int i = 0; i < RANDOM_ITEM_MAX_NUMBER; ++i)
|
||||
randomitemarray[i] = 0;
|
||||
|
||||
for ( int i = 0; i < RANDOM_TABOO_MAX; ++i)
|
||||
{
|
||||
randomitemtabooarray[i] = 0;
|
||||
randomitemclasstabooarray[i] = 0;
|
||||
}
|
||||
|
||||
itemcnt = 0;
|
||||
rdtaboocnt = 0;
|
||||
rdclasstaboocnt = 0;
|
||||
|
||||
// determine maximum allowed coolness
|
||||
// TODO: adjust this depending on a random item coolness modificator
|
||||
rditemmaxcoolness = HighestPlayerProgressPercentage() / 10 + 1 + Item[usRandomItem].randomitemcoolnessmodificator; // the random item itself can modify coolness
|
||||
|
||||
// build the list of items to choose from. We will search down the random item class an can even branch into mulitple other random item classes.
|
||||
// We only stop if maximum number of items or random item classes is reached
|
||||
AddToRandomListFromRandomItem(usRandomItem);
|
||||
|
||||
if ( itemcnt )
|
||||
{
|
||||
// select a random item from our list
|
||||
UINT16 random = Random(itemcnt);
|
||||
|
||||
*pusNewItem = randomitemarray[random];
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL AddToRandomListFromRandomItemClass( UINT16 usRandomItemClass )
|
||||
{
|
||||
if ( usRandomItemClass && !RandomItemClassIsTaboo(usRandomItemClass) )
|
||||
{
|
||||
// end if we reached the maximum number of taboos
|
||||
if ( rdclasstaboocnt >= RANDOM_TABOO_MAX )
|
||||
return FALSE;
|
||||
|
||||
// add items
|
||||
for ( int i = 0; i < RANDOM_XML_LENGTH; ++i)
|
||||
{
|
||||
// if this returns false, we're either at the maximum number of items or taboos - both reasons to end
|
||||
if ( !AddToRandomListFromItem(gRandomItemClass[usRandomItemClass].item[i]) )
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// add random item classes
|
||||
for ( int i = 0; i < RANDOM_XML_LENGTH; ++i)
|
||||
{
|
||||
// if this returns false, we're either at the maximum number of items or taboos - both reasons to end
|
||||
if ( !AddToRandomListFromRandomItemClass(gRandomItemClass[usRandomItemClass].randomitem[i]) )
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// add from a random item to the list
|
||||
BOOL AddToRandomListFromRandomItem( UINT16 usRandomItem )
|
||||
{
|
||||
if ( Item[usRandomItem].randomitem > 0 && !RandomItemIsTaboo( usRandomItem ) )
|
||||
{
|
||||
// end if we reached the maximum number of taboos
|
||||
if ( rdtaboocnt >= RANDOM_TABOO_MAX )
|
||||
return FALSE;
|
||||
|
||||
return AddToRandomListFromRandomItemClass(Item[usRandomItem].randomitem);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// add an item to the list
|
||||
BOOL AddToRandomListFromItem( UINT16 usItem )
|
||||
{
|
||||
if ( usItem )
|
||||
{
|
||||
// is it another random item?
|
||||
if ( Item[usItem].randomitem > 0 )
|
||||
{
|
||||
// continue adding items from this new random item
|
||||
return AddToRandomListFromRandomItem(usItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
// only allow those items that are viable at the current progress
|
||||
if ( Item[usItem].ubCoolness <= rditemmaxcoolness )
|
||||
randomitemarray[itemcnt++] = usItem;
|
||||
|
||||
// if maximum is reached, return false, thereby signalling an end
|
||||
return ( itemcnt < RANDOM_ITEM_MAX_NUMBER );
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// check wether this class is already on the taboo list (forbidden to add from there again, because this can lead to loops). If not, add this to the taboo list
|
||||
BOOL RandomItemClassIsTaboo( UINT16 usRandomItemClass )
|
||||
{
|
||||
for ( int i = 0; i < rdclasstaboocnt; ++i)
|
||||
{
|
||||
if ( randomitemclasstabooarray[i] == usRandomItemClass )
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// add to taboo list
|
||||
randomitemclasstabooarray[rdclasstaboocnt++] = usRandomItemClass;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL RandomItemIsTaboo( UINT16 usRandomItem )
|
||||
{
|
||||
for ( int i = 0; i < rdtaboocnt; ++i)
|
||||
{
|
||||
if ( randomitemtabooarray[i] == usRandomItem )
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// add to taboo list
|
||||
randomitemtabooarray[rdtaboocnt++] = usRandomItem;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user