Cleaned up arms dealer code

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@8519 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Flugente
2018-01-28 20:51:07 +00:00
parent a9452840af
commit e7ce503e9e
3 changed files with 135 additions and 285 deletions
+84 -153
View File
@@ -181,11 +181,10 @@ bool DEALER_SPECIAL_ITEM::operator ==(const DEALER_SPECIAL_ITEM& compare)
void InitAllArmsDealers() void InitAllArmsDealers()
{ {
UINT8 ubArmsDealer;
ShutDownArmsDealers(); ShutDownArmsDealers();
//Initialize the initial status & inventory for each of the arms dealers //Initialize the initial status & inventory for each of the arms dealers
for( ubArmsDealer = 0; ubArmsDealer < NUM_ARMS_DEALERS; ubArmsDealer++ ) for( UINT8 ubArmsDealer = 0; ubArmsDealer < NUM_ARMS_DEALERS; ++ubArmsDealer )
{ {
InitializeOneArmsDealer( ubArmsDealer ); InitializeOneArmsDealer( ubArmsDealer );
} }
@@ -215,8 +214,9 @@ void InitializeOneArmsDealer( UINT8 ubArmsDealer )
//loop through all the item types //loop through all the item types
for ( usItemIndex = 1; usItemIndex < gMAXITEMS_READ; ++usItemIndex ) for ( usItemIndex = 1; usItemIndex < gMAXITEMS_READ; ++usItemIndex )
{ {
if ( Item[usItemIndex].usItemClass == 0 ) if ( Item[usItemIndex].usItemClass == 0 )
break; break;
//Can the item be sold by the arms dealer //Can the item be sold by the arms dealer
if( CanDealerTransactItem( ubArmsDealer, usItemIndex, FALSE ) ) if( CanDealerTransactItem( ubArmsDealer, usItemIndex, FALSE ) )
{ {
@@ -232,14 +232,11 @@ void InitializeOneArmsDealer( UINT8 ubArmsDealer )
} }
} }
void ShutDownArmsDealers() void ShutDownArmsDealers()
{ {
gArmsDealersInventory.clear(); gArmsDealersInventory.clear();
} }
BOOLEAN SaveArmsDealerInventoryToSaveGameFile( HWFILE hFile ) BOOLEAN SaveArmsDealerInventoryToSaveGameFile( HWFILE hFile )
{ {
UINT32 uiNumBytesWritten; UINT32 uiNumBytesWritten;
@@ -259,18 +256,22 @@ BOOLEAN SaveArmsDealerInventoryToSaveGameFile( HWFILE hFile )
} }
//loop through all the dealers inventories //loop through all the dealers inventories
for( ubArmsDealer=0; ubArmsDealer<NUM_ARMS_DEALERS; ubArmsDealer++ ) for( ubArmsDealer=0; ubArmsDealer<NUM_ARMS_DEALERS; ++ubArmsDealer )
{ {
int size = gArmsDealersInventory.empty() ? 0 : gArmsDealersInventory[ubArmsDealer].size(); int size = gArmsDealersInventory.empty() ? 0 : gArmsDealersInventory[ubArmsDealer].size();
if (!FileWrite( hFile, &size, sizeof( int ), &uiNumBytesWritten )) if (!FileWrite( hFile, &size, sizeof( int ), &uiNumBytesWritten ))
{ {
return( FALSE ); return( FALSE );
} }
if(gArmsDealersInventory.empty()) continue;
if(gArmsDealersInventory.empty())
continue;
//loop through this dealer's individual items //loop through this dealer's individual items
for (DealerItemList::iterator iter = gArmsDealersInventory[ubArmsDealer].begin(); for (DealerItemList::iterator iter = gArmsDealersInventory[ubArmsDealer].begin(); iter != gArmsDealersInventory[ubArmsDealer].end(); ++iter)
iter != gArmsDealersInventory[ubArmsDealer].end(); ++iter) { {
if (! iter->Save(hFile) ) { if (! iter->Save(hFile) )
{
return FALSE; return FALSE;
} }
} }
@@ -308,7 +309,6 @@ void DEALER_SPECIAL_ITEM::ConvertFrom101(OLD_DEALER_ITEM_HEADER_101& header, OLD
gArmsDealersInventory[ubArmsDealer].push_back(*this); gArmsDealersInventory[ubArmsDealer].push_back(*this);
}; };
void DailyUpdateOfArmsDealersInventory() void DailyUpdateOfArmsDealersInventory()
{ {
// if Gabby has creature blood, start turning it into extra elixir // if Gabby has creature blood, start turning it into extra elixir
@@ -327,18 +327,15 @@ void DailyUpdateOfArmsDealersInventory()
AdjustCertainDealersInventory( ); AdjustCertainDealersInventory( );
} }
// Once a day, loop through each dealer's inventory items and possibly sell some // Once a day, loop through each dealer's inventory items and possibly sell some
void SimulateArmsDealerCustomer() void SimulateArmsDealerCustomer()
{ {
UINT8 ubArmsDealer=0;
UINT16 usItemIndex;
UINT8 ubItemsSold=0; UINT8 ubItemsSold=0;
static int numPerfectItems[MAXITEMS]; static int numPerfectItems[MAXITEMS];
//loop through all the arms dealers //loop through all the arms dealers
for( ubArmsDealer=0;ubArmsDealer<NUM_ARMS_DEALERS; ++ubArmsDealer ) for( UINT8 ubArmsDealer=0;ubArmsDealer<NUM_ARMS_DEALERS; ++ubArmsDealer )
{ {
if( gArmsDealerStatus[ ubArmsDealer ].fOutOfBusiness ) if( gArmsDealerStatus[ ubArmsDealer ].fOutOfBusiness )
continue; continue;
@@ -359,7 +356,7 @@ void SimulateArmsDealerCustomer()
} }
//loop through all items of the same type //loop through all items of the same type
for ( usItemIndex = 1; usItemIndex < gMAXITEMS_READ; ++usItemIndex ) for ( UINT16 usItemIndex = 1; usItemIndex < gMAXITEMS_READ; ++usItemIndex )
{ {
if ( Item[usItemIndex].usItemClass == 0 ) if ( Item[usItemIndex].usItemClass == 0 )
break; break;
@@ -383,6 +380,7 @@ void SimulateArmsDealerCustomer()
{ {
ubItemsSold = HowManyItemsAreSold( ubArmsDealer, usItemIndex, numPerfectItems[usItemIndex], FALSE); ubItemsSold = HowManyItemsAreSold( ubArmsDealer, usItemIndex, numPerfectItems[usItemIndex], FALSE);
} }
if ( ubItemsSold > 0) if ( ubItemsSold > 0)
{ {
RemoveItemFromArmsDealerInventory( ubArmsDealer, usItemIndex, ubItemsSold); RemoveItemFromArmsDealerInventory( ubArmsDealer, usItemIndex, ubItemsSold);
@@ -424,8 +422,7 @@ void DailyCheckOnItemQuantities()
UINT8 ubNumItems; UINT8 ubNumItems;
UINT32 uiArrivalDay; UINT32 uiArrivalDay;
UINT8 ubReorderDays; UINT8 ubReorderDays;
//loop through all the arms dealers //loop through all the arms dealers
for( ubArmsDealer=0;ubArmsDealer<NUM_ARMS_DEALERS; ++ubArmsDealer ) for( ubArmsDealer=0;ubArmsDealer<NUM_ARMS_DEALERS; ++ubArmsDealer )
{ {
@@ -444,14 +441,18 @@ void DailyCheckOnItemQuantities()
int numTotalItems[MAXITEMS] = { 0 }; int numTotalItems[MAXITEMS] = { 0 };
bool itemsAreOnOrder[MAXITEMS] = { false }; bool itemsAreOnOrder[MAXITEMS] = { false };
for (DealerItemList::iterator iter = gArmsDealersInventory[ ubArmsDealer ].begin(); for (DealerItemList::iterator iter = gArmsDealersInventory[ ubArmsDealer ].begin(); iter != gArmsDealersInventory[ ubArmsDealer ].end(); ++iter)
iter != gArmsDealersInventory[ ubArmsDealer ].end(); ++iter) { {
if (iter->object.exists() == true) { if (iter->object.exists() == true)
if (iter->IsBeingOrdered() == false) { {
if (iter->IsBeingOrdered() == false)
{
numTotalItems[iter->object.usItem] += iter->object.ubNumberOfObjects; numTotalItems[iter->object.usItem] += iter->object.ubNumberOfObjects;
} }
else { else
{
itemsAreOnOrder[iter->object.usItem] = true; itemsAreOnOrder[iter->object.usItem] = true;
//and today is the day the items come in //and today is the day the items come in
if( iter->uiOrderArrivalTime >= GetWorldDay() ) if( iter->uiOrderArrivalTime >= GetWorldDay() )
{ {
@@ -464,8 +465,7 @@ void DailyCheckOnItemQuantities()
//set the fact the raul refreshed his inventory //set the fact the raul refreshed his inventory
SetFactTrue( FACT_RAULS_INVENTORY_CHANGED_SINCE_LAST_VISIT ); SetFactTrue( FACT_RAULS_INVENTORY_CHANGED_SINCE_LAST_VISIT );
} }
#endif #endif
} }
} }
} }
@@ -518,7 +518,7 @@ void DailyCheckOnItemQuantities()
} }
#else #else
ubReorderDays = ( UINT8) ( armsDealerInfo[ ubArmsDealer ].daysDelayMin + Random( armsDealerInfo[ ubArmsDealer ].daysDelayMax - armsDealerInfo[ ubArmsDealer ].daysDelayMin ) ); ubReorderDays = ( UINT8) ( armsDealerInfo[ ubArmsDealer ].daysDelayMin + Random( armsDealerInfo[ ubArmsDealer ].daysDelayMax - armsDealerInfo[ ubArmsDealer ].daysDelayMin ) );
#endif #endif
//Determine when the inventory should arrive //Determine when the inventory should arrive
uiArrivalDay = GetWorldDay() + ubReorderDays; // consider changing this to minutes uiArrivalDay = GetWorldDay() + ubReorderDays; // consider changing this to minutes
@@ -536,13 +536,14 @@ void DailyCheckOnItemQuantities()
void OrderDealerItems(int armsDealer, int usItem, int numItems, int arrivalDay) void OrderDealerItems(int armsDealer, int usItem, int numItems, int arrivalDay)
{ {
int perfectItems = 0; int perfectItems = 0;
for (int x = 0; x < numItems; ++x) { for (int x = 0; x < numItems; ++x)
{
int ubItemCondition = DetermineDealerItemCondition( armsDealer, usItem); int ubItemCondition = DetermineDealerItemCondition( armsDealer, usItem);
// if the item is brand new // if the item is brand new
if ( ubItemCondition == 100) if ( ubItemCondition == 100)
{ {
perfectItems++; ++perfectItems;
} }
else else
{ {
@@ -582,12 +583,14 @@ void ConvertCreatureBloodToElixir( void )
UINT8 ubBloodAvailable = 0; UINT8 ubBloodAvailable = 0;
UINT8 ubAmountToConvert; UINT8 ubAmountToConvert;
for (DealerItemList::iterator iter = gArmsDealersInventory[ ARMS_DEALER_GABBY ].begin(); for (DealerItemList::iterator iter = gArmsDealersInventory[ ARMS_DEALER_GABBY ].begin(); iter != gArmsDealersInventory[ ARMS_DEALER_GABBY ].end(); ++iter)
iter != gArmsDealersInventory[ ARMS_DEALER_GABBY ].end(); ++iter) { {
if (iter->ItemIsInInventory() == true && iter->object.usItem == JAR_CREATURE_BLOOD) { if (iter->ItemIsInInventory() == true && iter->object.usItem == JAR_CREATURE_BLOOD)
{
ubBloodAvailable += iter->object.ubNumberOfObjects; ubBloodAvailable += iter->object.ubNumberOfObjects;
} }
} }
if ( ubBloodAvailable ) if ( ubBloodAvailable )
{ {
// start converting blood into elixir! // start converting blood into elixir!
@@ -633,8 +636,7 @@ BOOLEAN AdjustCertainDealersInventory( )
} }
#ifdef JA2UB #ifdef JA2UB
//------------UB--------------------- //------------UB---------------------
//if Raul hasnt yet sold the barret //if Raul hasnt yet sold the barret
if( !( gArmsDealerStatus[ ARMS_DEALER_RAUL ].ubSpecificDealerFlags & ARMS_DEALER_FLAG__RAUL_HAS_SOLD_BARRETT_TO_PLAYER ) ) if( !( gArmsDealerStatus[ ARMS_DEALER_RAUL ].ubSpecificDealerFlags & ARMS_DEALER_FLAG__RAUL_HAS_SOLD_BARRETT_TO_PLAYER ) )
{ {
@@ -661,7 +663,6 @@ BOOLEAN AdjustCertainDealersInventory( )
GuaranteeAtMostNumOfItemsForItem( ARMS_DEALER_BETTY, LAPTOP_TRANSMITTER, 0 ); //4500 GuaranteeAtMostNumOfItemsForItem( ARMS_DEALER_BETTY, LAPTOP_TRANSMITTER, 0 ); //4500
} }
if( gubQuest[ QUEST_GET_RID_BLOODCATS_AT_BETTYS ] != QUESTDONE ) if( gubQuest[ QUEST_GET_RID_BLOODCATS_AT_BETTYS ] != QUESTDONE )
{ {
//make sure she doesnt sell these items just yet //make sure she doesnt sell these items just yet
@@ -678,8 +679,6 @@ BOOLEAN AdjustCertainDealersInventory( )
return( TRUE ); return( TRUE );
} }
void LimitArmsDealersInventory( UINT8 ubArmsDealer, UINT32 uiDealerItemType, UINT8 ubMaxNumberOfItemType ) void LimitArmsDealersInventory( UINT8 ubArmsDealer, UINT32 uiDealerItemType, UINT8 ubMaxNumberOfItemType )
{ {
if( gArmsDealerStatus[ ubArmsDealer ].fOutOfBusiness ) if( gArmsDealerStatus[ ubArmsDealer ].fOutOfBusiness )
@@ -716,7 +715,7 @@ void LimitArmsDealersInventory( UINT8 ubArmsDealer, UINT32 uiDealerItemType, UIN
{ {
// all ammo of same type counts as only one item // all ammo of same type counts as only one item
ubNumberOfAvailableItem.push_back(1); ubNumberOfAvailableItem.push_back(1);
uiTotalNumberOfItems++; ++uiTotalNumberOfItems;
} }
else else
{ {
@@ -735,7 +734,7 @@ void LimitArmsDealersInventory( UINT8 ubArmsDealer, UINT32 uiDealerItemType, UIN
{ {
uiRandomChoice = Random( uiTotalNumberOfItems ); uiRandomChoice = Random( uiTotalNumberOfItems );
for ( uiIndex = 0; uiIndex < usAvailableItems.size(); uiIndex++ ) for ( uiIndex = 0; uiIndex < usAvailableItems.size(); ++uiIndex )
{ {
if ( uiRandomChoice <= ubNumberOfAvailableItem[ uiIndex ] ) if ( uiRandomChoice <= ubNumberOfAvailableItem[ uiIndex ] )
{ {
@@ -759,9 +758,8 @@ void LimitArmsDealersInventory( UINT8 ubArmsDealer, UINT32 uiDealerItemType, UIN
ubNumberOfAvailableItem.pop_back(); ubNumberOfAvailableItem.pop_back();
// decrement count of # of items to remove // decrement count of # of items to remove
uiItemsToRemove--; --uiItemsToRemove;
break; // and out of 'for' loop break; // and out of 'for' loop
} }
else else
{ {
@@ -812,7 +810,6 @@ void LimitArmsDealersInventory( UINT8 ubArmsDealer, UINT32 uiDealerItemType, UIN
} }
} }
void GuaranteeAtLeastOneItemOfType( UINT8 ubArmsDealer, UINT32 uiDealerItemType ) void GuaranteeAtLeastOneItemOfType( UINT8 ubArmsDealer, UINT32 uiDealerItemType )
{ {
UINT16 usItemIndex; UINT16 usItemIndex;
@@ -827,9 +824,10 @@ void GuaranteeAtLeastOneItemOfType( UINT8 ubArmsDealer, UINT32 uiDealerItemType
// not permitted for repair dealers - would take extra code to avoid counting items under repair! // not permitted for repair dealers - would take extra code to avoid counting items under repair!
//Assert( !DoesDealerDoRepairs( ubArmsDealer ) ); //Assert( !DoesDealerDoRepairs( ubArmsDealer ) );
int numTotalItems[MAXITEMS] = { 0 }; int numTotalItems[MAXITEMS] = { 0 };
for (DealerItemList::iterator iter = gArmsDealersInventory[ ubArmsDealer ].begin(); for (DealerItemList::iterator iter = gArmsDealersInventory[ ubArmsDealer ].begin(); iter != gArmsDealersInventory[ ubArmsDealer ].end(); ++iter)
iter != gArmsDealersInventory[ ubArmsDealer ].end(); ++iter) { {
if (iter->ItemIsInInventory() == true && iter->IsUnderRepair() == false) { if (iter->ItemIsInInventory() == true && iter->IsUnderRepair() == false)
{
numTotalItems[iter->object.usItem] += iter->object.ubNumberOfObjects; numTotalItems[iter->object.usItem] += iter->object.ubNumberOfObjects;
} }
} }
@@ -870,13 +868,12 @@ void GuaranteeAtLeastOneItemOfType( UINT8 ubArmsDealer, UINT32 uiDealerItemType
return; return;
} }
// CJC: randomly pick one of available items by weighted random selection. // CJC: randomly pick one of available items by weighted random selection.
// randomize number within uiTotalChances and then loop forwards till we find that item // randomize number within uiTotalChances and then loop forwards till we find that item
uiRandomChoice = Random( uiTotalChances ); uiRandomChoice = Random( uiTotalChances );
for ( uiIndex = 0; uiIndex < usAvailableItems.size(); uiIndex++ ) for ( uiIndex = 0; uiIndex < usAvailableItems.size(); ++uiIndex )
{ {
if ( uiRandomChoice <= ubChanceForAvailableItem[ uiIndex ] ) if ( uiRandomChoice <= ubChanceForAvailableItem[ uiIndex ] )
{ {
@@ -896,7 +893,6 @@ void GuaranteeAtLeastOneItemOfType( UINT8 ubArmsDealer, UINT32 uiDealerItemType
void GuaranteeAtMostNumOfItemsForItem( UINT8 ubArmsDealer, INT16 sItemIndex, UINT8 ubAtMostNumItems ) void GuaranteeAtMostNumOfItemsForItem( UINT8 ubArmsDealer, INT16 sItemIndex, UINT8 ubAtMostNumItems )
{ {
if( gArmsDealerStatus[ ubArmsDealer ].fOutOfBusiness ) if( gArmsDealerStatus[ ubArmsDealer ].fOutOfBusiness )
return; return;
@@ -904,14 +900,14 @@ void GuaranteeAtMostNumOfItemsForItem( UINT8 ubArmsDealer, INT16 sItemIndex, UIN
// not permitted for repair dealers - would take extra code to avoid counting items under repair! // not permitted for repair dealers - would take extra code to avoid counting items under repair!
//Assert( !DoesDealerDoRepairs( ubArmsDealer ) ); //Assert( !DoesDealerDoRepairs( ubArmsDealer ) );
int itemsIHave = 0; int itemsIHave = 0;
for (DealerItemList::iterator iter = gArmsDealersInventory[ ubArmsDealer ].begin(); for (DealerItemList::iterator iter = gArmsDealersInventory[ ubArmsDealer ].begin(); iter != gArmsDealersInventory[ ubArmsDealer ].end(); ++iter)
iter != gArmsDealersInventory[ ubArmsDealer ].end(); ++iter) { {
if (iter->ItemIsInInventory() == true if (iter->ItemIsInInventory() == true &&
&& iter->object.usItem == sItemIndex iter->object.usItem == sItemIndex &&
&& iter->IsUnderRepair() == false) { iter->IsUnderRepair() == false)
{
itemsIHave -= iter->object.ubNumberOfObjects; itemsIHave -= iter->object.ubNumberOfObjects;
//if there are any of these in stock //if there are any of these in stock
} }
} }
} }
@@ -925,11 +921,12 @@ void GuaranteeAtLeastXItemsOfIndex( UINT8 ubArmsDealer, UINT16 usItemIndex, UINT
// not permitted for repair dealers - would take extra code to avoid counting items under repair! // not permitted for repair dealers - would take extra code to avoid counting items under repair!
//Assert( !DoesDealerDoRepairs( ubArmsDealer ) ); //Assert( !DoesDealerDoRepairs( ubArmsDealer ) );
int itemsIHave = 0; int itemsIHave = 0;
for (DealerItemList::iterator iter = gArmsDealersInventory[ ubArmsDealer ].begin(); for (DealerItemList::iterator iter = gArmsDealersInventory[ ubArmsDealer ].begin(); iter != gArmsDealersInventory[ ubArmsDealer ].end(); ++iter)
iter != gArmsDealersInventory[ ubArmsDealer ].end(); ++iter) { {
if (iter->ItemIsInInventory() == true if (iter->ItemIsInInventory() == true
&& iter->object.usItem == usItemIndex && iter->object.usItem == usItemIndex
&& iter->IsUnderRepair() == false) { && iter->IsUnderRepair() == false)
{
itemsIHave += iter->object.ubNumberOfObjects; itemsIHave += iter->object.ubNumberOfObjects;
//if there are any of these in stock //if there are any of these in stock
if( itemsIHave >= ubHowMany ) if( itemsIHave >= ubHowMany )
@@ -939,8 +936,7 @@ void GuaranteeAtLeastXItemsOfIndex( UINT8 ubArmsDealer, UINT16 usItemIndex, UINT
} }
} }
} }
// if he can stock it (it appears in his inventory list) // if he can stock it (it appears in his inventory list)
// RESTRICTION REMOVED: Jake must be able to guarantee GAS even though it's not in his list, it's presence is conditional // RESTRICTION REMOVED: Jake must be able to guarantee GAS even though it's not in his list, it's presence is conditional
// if( GetDealersMaxItemAmount( ubArmsDealer, usItemIndex ) > 0) // if( GetDealersMaxItemAmount( ubArmsDealer, usItemIndex ) > 0)
@@ -950,8 +946,6 @@ void GuaranteeAtLeastXItemsOfIndex( UINT8 ubArmsDealer, UINT16 usItemIndex, UINT
} }
} }
UINT32 GetArmsDealerItemTypeFromItemNumber( UINT16 usItem ) UINT32 GetArmsDealerItemTypeFromItemNumber( UINT16 usItem )
{ {
switch( Item[ usItem ].usItemClass ) switch( Item[ usItem ].usItemClass )
@@ -1137,8 +1131,6 @@ UINT32 GetArmsDealerItemTypeFromItemNumber( UINT16 usItem )
return( 0 ); return( 0 );
} }
BOOLEAN IsMercADealer( UINT8 ubMercID ) BOOLEAN IsMercADealer( UINT8 ubMercID )
{ {
// Manny is not actually a valid dealer unless a particular event sets that fact // Manny is not actually a valid dealer unless a particular event sets that fact
@@ -1179,16 +1171,11 @@ UINT8 GetTypeOfArmsDealer( UINT8 ubDealerID )
return( armsDealerInfo[ ubDealerID ].ubTypeOfArmsDealer ); return( armsDealerInfo[ ubDealerID ].ubTypeOfArmsDealer );
} }
BOOLEAN DoesDealerDoRepairs( UINT8 ubArmsDealer ) BOOLEAN DoesDealerDoRepairs( UINT8 ubArmsDealer )
{ {
if( armsDealerInfo[ ubArmsDealer ].ubTypeOfArmsDealer == ARMS_DEALER_REPAIRS ) return ( armsDealerInfo[ubArmsDealer].ubTypeOfArmsDealer == ARMS_DEALER_REPAIRS );
return( TRUE );
else
return( FALSE );
} }
BOOLEAN RepairmanIsFixingItemsButNoneAreDoneYet( UINT8 ubProfileID ) BOOLEAN RepairmanIsFixingItemsButNoneAreDoneYet( UINT8 ubProfileID )
{ {
INT8 bArmsDealer; INT8 bArmsDealer;
@@ -1203,11 +1190,11 @@ BOOLEAN RepairmanIsFixingItemsButNoneAreDoneYet( UINT8 ubProfileID )
return( FALSE ); return( FALSE );
//loop through the dealers inventory and check if there are only unrepaired items //loop through the dealers inventory and check if there are only unrepaired items
for (DealerItemList::iterator iter = gArmsDealersInventory[ bArmsDealer ].begin(); for (DealerItemList::iterator iter = gArmsDealersInventory[ bArmsDealer ].begin(); iter != gArmsDealersInventory[ bArmsDealer ].end(); ++iter)
iter != gArmsDealersInventory[ bArmsDealer ].end(); ++iter) { {
if (iter->ItemIsInInventory() == false) { if (iter->ItemIsInInventory() == false)
continue; continue;
}
if ( Item[iter->object.usItem].usItemClass == 0 ) if ( Item[iter->object.usItem].usItemClass == 0 )
continue; continue;
@@ -1343,7 +1330,6 @@ BOOLEAN CanDealerRepairItem( UINT8 ubArmsDealer, UINT16 usItemIndex )
return(FALSE); return(FALSE);
} }
void ArmsDealerGetsFreshStock( UINT8 ubArmsDealer, UINT16 usItemIndex, UINT8 ubNumItems ) void ArmsDealerGetsFreshStock( UINT8 ubArmsDealer, UINT16 usItemIndex, UINT8 ubNumItems )
{ {
UINT8 ubCnt; UINT8 ubCnt;
@@ -1358,7 +1344,7 @@ void ArmsDealerGetsFreshStock( UINT8 ubArmsDealer, UINT16 usItemIndex, UINT8 ubN
// if the item is brand new // if the item is brand new
if ( ubItemCondition == 100) if ( ubItemCondition == 100)
{ {
ubPerfectOnes++; ++ubPerfectOnes;
} }
else else
{ {
@@ -1376,8 +1362,6 @@ void ArmsDealerGetsFreshStock( UINT8 ubArmsDealer, UINT16 usItemIndex, UINT8 ubN
} }
} }
UINT8 DetermineDealerItemCondition( UINT8 ubArmsDealer, UINT16 usItemIndex ) UINT8 DetermineDealerItemCondition( UINT8 ubArmsDealer, UINT16 usItemIndex )
{ {
UINT8 ubCondition = 100; UINT8 ubCondition = 100;
@@ -1400,10 +1384,7 @@ UINT8 DetermineDealerItemCondition( UINT8 ubArmsDealer, UINT16 usItemIndex )
BOOLEAN ItemContainsLiquid( UINT16 usItemIndex ) BOOLEAN ItemContainsLiquid( UINT16 usItemIndex )
{ {
if(Item[usItemIndex].containsliquid) return Item[usItemIndex].containsliquid;
return TRUE;
else
return FALSE;
//switch ( usItemIndex ) //switch ( usItemIndex )
//{ //{
@@ -1442,47 +1423,25 @@ bool ItemIsSpecial(DEALER_SPECIAL_ITEM& item)
UINT16 CountTotalItemsRepairDealerHasInForRepairs( UINT8 ubArmsDealer ) UINT16 CountTotalItemsRepairDealerHasInForRepairs( UINT8 ubArmsDealer )
{ {
//if the dealer is not a repair dealer, no need to count, return 0
if ( !DoesDealerDoRepairs( ubArmsDealer ) )
return 0;
UINT16 usHowManyInForRepairs = 0; UINT16 usHowManyInForRepairs = 0;
//if the dealer is not a repair dealer, no need to count, return 0 for ( DealerItemList::iterator iter = gArmsDealersInventory[ubArmsDealer].begin(); iter != gArmsDealersInventory[ubArmsDealer].end(); ++iter )
if( !DoesDealerDoRepairs( ubArmsDealer ) )
return( 0 );
//loop through the dealers inventory and count the number of items in for repairs
for ( UINT16 usItemIndex = 0; usItemIndex < gMAXITEMS_READ; ++usItemIndex )
{ {
usHowManyInForRepairs += CountSpecificItemsRepairDealerHasInForRepairs( ubArmsDealer, usItemIndex ); if ( iter->object.exists() && iter->IsUnderRepair() )
{
++usHowManyInForRepairs;
}
} }
return( usHowManyInForRepairs ); return( usHowManyInForRepairs );
} }
UINT8 CountSpecificItemsRepairDealerHasInForRepairs( UINT8 ubArmsDealer, UINT16 usItemIndex )
{
UINT8 ubHowManyInForRepairs = 0;
//if the dealer is not a repair dealer, no need to count, return 0
if( !DoesDealerDoRepairs( ubArmsDealer ) )
return( 0 );
for (DealerItemList::iterator iter = gArmsDealersInventory[ ubArmsDealer ].begin();
iter != gArmsDealersInventory[ ubArmsDealer ].end(); ++iter) {
if (iter->object.exists() == true && iter->object.usItem == usItemIndex) {
if( iter->IsUnderRepair() == true )
{
++ubHowManyInForRepairs;
}
}
}
return( ubHowManyInForRepairs );
}
void AddObjectToArmsDealerInventory( UINT8 ubArmsDealer, OBJECTTYPE *pObject ) void AddObjectToArmsDealerInventory( UINT8 ubArmsDealer, OBJECTTYPE *pObject )
{ {
// split up all the components of an objecttype and add them as seperate items into the dealer's inventory // split up all the components of an objecttype and add them as seperate items into the dealer's inventory
OBJECTTYPE seperateObject; OBJECTTYPE seperateObject;
int total = 0; int total = 0;
@@ -2127,7 +2086,6 @@ BOOLEAN DoesItemAppearInDealerInventoryList( UINT8 ubArmsDealer, UINT16 usItemIn
DEALER_POSSIBLE_INV *pDealerInv=NULL; DEALER_POSSIBLE_INV *pDealerInv=NULL;
UINT16 usCnt; UINT16 usCnt;
// the others will buy only things that appear in their own "for sale" inventory lists // the others will buy only things that appear in their own "for sale" inventory lists
pDealerInv = GetPointerToDealersPossibleInventory( ubArmsDealer ); pDealerInv = GetPointerToDealersPossibleInventory( ubArmsDealer );
Assert( pDealerInv != NULL ); Assert( pDealerInv != NULL );
@@ -2146,22 +2104,19 @@ BOOLEAN DoesItemAppearInDealerInventoryList( UINT8 ubArmsDealer, UINT16 usItemIn
} }
} }
usCnt++; ++usCnt;
} }
return( FALSE ); return( FALSE );
} }
UINT16 CalcValueOfItemToDealer( UINT8 ubArmsDealer, UINT16 usItemIndex, BOOLEAN fDealerSelling ) UINT16 CalcValueOfItemToDealer( UINT8 ubArmsDealer, UINT16 usItemIndex, BOOLEAN fDealerSelling )
{ {
UINT16 usBasePrice; UINT16 usBasePrice;
UINT8 ubItemPriceClass; UINT8 ubItemPriceClass;
UINT8 ubDealerPriceClass; UINT8 ubDealerPriceClass;
UINT16 usValueToThisDealer; UINT16 usValueToThisDealer;
usBasePrice = Item[ usItemIndex ].usPrice; usBasePrice = Item[ usItemIndex ].usPrice;
if ( usBasePrice == 0 ) if ( usBasePrice == 0 )
@@ -2169,8 +2124,7 @@ UINT16 CalcValueOfItemToDealer( UINT8 ubArmsDealer, UINT16 usItemIndex, BOOLEAN
// worthless to any dealer // worthless to any dealer
return( 0 ); return( 0 );
} }
// figure out the price class this dealer prefers // figure out the price class this dealer prefers
switch ( ubArmsDealer ) switch ( ubArmsDealer )
{ {
@@ -2195,8 +2149,7 @@ UINT16 CalcValueOfItemToDealer( UINT8 ubArmsDealer, UINT16 usItemIndex, BOOLEAN
return( 0 ); return( 0 );
} }
} }
// the rest of this function applies only to the "general" dealers ( Jake, Keith, and Franz ) // the rest of this function applies only to the "general" dealers ( Jake, Keith, and Franz )
// Micky & Gabby specialize in creature parts & such, the others don't buy these at all (exception: jars) // Micky & Gabby specialize in creature parts & such, the others don't buy these at all (exception: jars)
@@ -2215,15 +2168,13 @@ UINT16 CalcValueOfItemToDealer( UINT8 ubArmsDealer, UINT16 usItemIndex, BOOLEAN
return( 0 ); return( 0 );
} }
} }
// figure out which price class it belongs to // figure out which price class it belongs to
if ( usBasePrice < 100 ) if ( usBasePrice < 100 )
{ {
ubItemPriceClass = PRICE_CLASS_JUNK; ubItemPriceClass = PRICE_CLASS_JUNK;
} }
else else if ( usBasePrice < 1000 )
if ( usBasePrice < 1000 )
{ {
ubItemPriceClass = PRICE_CLASS_CHEAP; ubItemPriceClass = PRICE_CLASS_CHEAP;
} }
@@ -2231,8 +2182,7 @@ UINT16 CalcValueOfItemToDealer( UINT8 ubArmsDealer, UINT16 usItemIndex, BOOLEAN
{ {
ubItemPriceClass = PRICE_CLASS_EXPENSIVE; ubItemPriceClass = PRICE_CLASS_EXPENSIVE;
} }
if( !fDealerSelling ) if( !fDealerSelling )
{ {
// junk dealer won't buy expensive stuff at all, expensive dealer won't buy junk at all // junk dealer won't buy expensive stuff at all, expensive dealer won't buy junk at all
@@ -2273,7 +2223,6 @@ UINT16 CalcValueOfItemToDealer( UINT8 ubArmsDealer, UINT16 usItemIndex, BOOLEAN
return( usValueToThisDealer ); return( usValueToThisDealer );
} }
void GuaranteeMinimumAlcohol( UINT8 ubArmsDealer ) void GuaranteeMinimumAlcohol( UINT8 ubArmsDealer )
{ {
GuaranteeAtLeastXItemsOfIndex( ubArmsDealer, BEER, ( UINT8 ) ( GetDealersMaxItemAmount( ubArmsDealer, BEER ) / 3 ) ); GuaranteeAtLeastXItemsOfIndex( ubArmsDealer, BEER, ( UINT8 ) ( GetDealersMaxItemAmount( ubArmsDealer, BEER ) / 3 ) );
@@ -2281,22 +2230,11 @@ void GuaranteeMinimumAlcohol( UINT8 ubArmsDealer )
GuaranteeAtLeastXItemsOfIndex( ubArmsDealer, ALCOHOL, ( UINT8 ) ( GetDealersMaxItemAmount( ubArmsDealer, ALCOHOL ) / 3 ) ); GuaranteeAtLeastXItemsOfIndex( ubArmsDealer, ALCOHOL, ( UINT8 ) ( GetDealersMaxItemAmount( ubArmsDealer, ALCOHOL ) / 3 ) );
} }
BOOLEAN ItemIsARocketRifle( INT16 sItemIndex ) BOOLEAN ItemIsARocketRifle( INT16 sItemIndex )
{ {
if ( Item[sItemIndex].fingerprintid ) return( Item[sItemIndex].fingerprintid );
{
return( TRUE );
}
else
{
return( FALSE );
}
} }
BOOLEAN GetArmsDealerShopHours( UINT8 ubArmsDealer, UINT32 *puiOpeningTime, UINT32 *puiClosingTime ) BOOLEAN GetArmsDealerShopHours( UINT8 ubArmsDealer, UINT32 *puiOpeningTime, UINT32 *puiClosingTime )
{ {
SOLDIERTYPE *pSoldier; SOLDIERTYPE *pSoldier;
@@ -2317,16 +2255,13 @@ BOOLEAN GetArmsDealerShopHours( UINT8 ubArmsDealer, UINT32 *puiOpeningTime, UINT
return( TRUE ); return( TRUE );
} }
UINT32 CalculateOvernightRepairDelay( UINT8 ubArmsDealer, UINT32 uiTimeWhenFreeToStartIt, UINT32 uiMinutesToFix ) UINT32 CalculateOvernightRepairDelay( UINT8 ubArmsDealer, UINT32 uiTimeWhenFreeToStartIt, UINT32 uiMinutesToFix )
{ {
UINT32 uiOpeningTime, uiClosingTime; UINT32 uiOpeningTime, uiClosingTime;
UINT32 uiMinutesClosedOvernight; UINT32 uiMinutesClosedOvernight;
UINT32 uiDelayInDays = 0; UINT32 uiDelayInDays = 0;
UINT32 uiDoneToday; UINT32 uiDoneToday;
Assert( uiMinutesToFix > 0 ); Assert( uiMinutesToFix > 0 );
// convert world time into 24hr military time for the day he's gonna start on it // convert world time into 24hr military time for the day he's gonna start on it
@@ -2360,8 +2295,6 @@ UINT32 CalculateOvernightRepairDelay( UINT8 ubArmsDealer, UINT32 uiTimeWhenFreeT
return ( uiDelayInDays * uiMinutesClosedOvernight ); return ( uiDelayInDays * uiMinutesClosedOvernight );
} }
UINT32 CalculateMinutesClosedBetween( UINT8 ubArmsDealer, UINT32 uiStartTime, UINT32 uiEndTime ) UINT32 CalculateMinutesClosedBetween( UINT8 ubArmsDealer, UINT32 uiStartTime, UINT32 uiEndTime )
{ {
UINT32 uiOpeningTime, uiClosingTime; UINT32 uiOpeningTime, uiClosingTime;
@@ -2386,8 +2319,7 @@ UINT32 CalculateMinutesClosedBetween( UINT8 ubArmsDealer, UINT32 uiStartTime, UI
// close for 1 less than that many full nights... // close for 1 less than that many full nights...
uiMinutesClosed = ( uiDaysDifference - 1 ) * uiMinutesClosedOvernight; uiMinutesClosed = ( uiDaysDifference - 1 ) * uiMinutesClosedOvernight;
} }
// add partial day's closing // add partial day's closing
// convert start and end times into 24hr military time // convert start and end times into 24hr military time
@@ -2399,8 +2331,7 @@ UINT32 CalculateMinutesClosedBetween( UINT8 ubArmsDealer, UINT32 uiStartTime, UI
{ {
uiEndTime = NUM_MIN_IN_DAY; uiEndTime = NUM_MIN_IN_DAY;
} }
if ( uiStartTime == uiEndTime ) if ( uiStartTime == uiEndTime )
{ {
if ( uiDaysDifference == 0 ) if ( uiDaysDifference == 0 )
@@ -2412,6 +2343,7 @@ UINT32 CalculateMinutesClosedBetween( UINT8 ubArmsDealer, UINT32 uiStartTime, UI
uiMinutesClosed += uiMinutesClosedOvernight; uiMinutesClosed += uiMinutesClosedOvernight;
} }
} }
if ( uiStartTime < uiEndTime ) if ( uiStartTime < uiEndTime )
{ {
if ( uiStartTime < uiOpeningTime ) if ( uiStartTime < uiOpeningTime )
@@ -2448,7 +2380,6 @@ void AddTexsVideosToBettysInventory()
GuaranteeAtLeastXItemsOfIndex( ARMS_DEALER_BETTY, TEX_MOVIE_HAVE_HONDA, 1 ); GuaranteeAtLeastXItemsOfIndex( ARMS_DEALER_BETTY, TEX_MOVIE_HAVE_HONDA, 1 );
} }
BOOLEAN CanThisItemBeSoldToSimulatedCustomer( UINT8 ubArmsDealerID, UINT16 usItemIndex ) BOOLEAN CanThisItemBeSoldToSimulatedCustomer( UINT8 ubArmsDealerID, UINT16 usItemIndex )
{ {
switch( ubArmsDealerID ) switch( ubArmsDealerID )
+7 -18
View File
@@ -75,10 +75,9 @@ enum
#define ARMS_DEALER_SMGCLASS 0x00000002 // 2 #define ARMS_DEALER_SMGCLASS 0x00000002 // 2
#define ARMS_DEALER_RIFLECLASS 0x00000004 // 4 #define ARMS_DEALER_RIFLECLASS 0x00000004 // 4
#define ARMS_DEALER_MGCLASS 0x00000008 // 8 #define ARMS_DEALER_MGCLASS 0x00000008 // 8
#define ARMS_DEALER_SHOTGUNCLASS 0x00000010 // 16 #define ARMS_DEALER_SHOTGUNCLASS 0x00000010 // 16
#define ARMS_DEALER_KNIFECLASS 0x00000020 // 32 #define ARMS_DEALER_KNIFECLASS 0x00000020 // 32
#define ARMS_DEALER_BLADE 0x00000040 // 64 #define ARMS_DEALER_BLADE 0x00000040 // 64
#define ARMS_DEALER_LAUNCHER 0x00000080 // 128 #define ARMS_DEALER_LAUNCHER 0x00000080 // 128
@@ -90,35 +89,26 @@ enum
#define ARMS_DEALER_GRENADE 0x00001000 // 4096 #define ARMS_DEALER_GRENADE 0x00001000 // 4096
#define ARMS_DEALER_BOMB 0x00002000 // 8192 #define ARMS_DEALER_BOMB 0x00002000 // 8192
#define ARMS_DEALER_EXPLOSV 0x00004000 // 16384 #define ARMS_DEALER_EXPLOSV 0x00004000 // 16384
#define ARMS_DEALER_KIT 0x00008000 // 32764 #define ARMS_DEALER_KIT 0x00008000 // 32764
#define ARMS_DEALER_FACE 0x00010000 // 65536 #define ARMS_DEALER_FACE 0x00010000 // 65536
//#define ARMS_DEALER_THROWN 0x00020000 // 131072
//#define ARMS_DEALER_KEY 0x00040000 // 262144
//#define ARMS_DEALER_VIDEO_CAMERA 0x00020000 // 131072
#define ARMS_DEALER_DETONATORS 0x00040000 // 262144 #define ARMS_DEALER_DETONATORS 0x00040000 // 262144
#define ARMS_DEALER_ATTACHMENTS 0x00080000 // 524288 #define ARMS_DEALER_ATTACHMENTS 0x00080000 // 524288
#define ARMS_DEALER_ALCOHOL 0x00100000 // 1048576 #define ARMS_DEALER_ALCOHOL 0x00100000 // 1048576
#define ARMS_DEALER_ELECTRONICS 0x00200000 // 2097152 #define ARMS_DEALER_ELECTRONICS 0x00200000 // 2097152
#define ARMS_DEALER_HARDWARE 0x00400000 | ARMS_DEALER_KIT #define ARMS_DEALER_HARDWARE 0x00400000 | ARMS_DEALER_KIT
#define ARMS_DEALER_MEDICAL 0x00800000 | ARMS_DEALER_MEDKIT #define ARMS_DEALER_MEDICAL 0x00800000 | ARMS_DEALER_MEDKIT
//#define ARMS_DEALER_EMPTY_JAR 0x01000000 // 16777216
#define ARMS_DEALER_CREATURE_PARTS 0x02000000 // 33554432 #define ARMS_DEALER_CREATURE_PARTS 0x02000000 // 33554432
#define ARMS_DEALER_ROCKET_RIFLE 0x04000000 // 67108864 #define ARMS_DEALER_ROCKET_RIFLE 0x04000000 // 67108864
#define ARMS_DEALER_ONLY_USED_ITEMS 0x08000000 // 134217728 #define ARMS_DEALER_ONLY_USED_ITEMS 0x08000000 // 134217728
#define ARMS_DEALER_GIVES_CHANGE 0x10000000 // 268435456 //The arms dealer will give the required change when doing a transaction
#define ARMS_DEALER_ACCEPTS_GIFTS 0x20000000 // 536870912 //The arms dealer is the kind of person who will accept gifts #define ARMS_DEALER_GIVES_CHANGE 0x10000000 // 268435456 //The dealer will give the required change when doing a transaction
#define ARMS_DEALER_SOME_USED_ITEMS 0x40000000 // 1073741824 //The arms dealer can have used items in his inventory #define ARMS_DEALER_ACCEPTS_GIFTS 0x20000000 // 536870912 //The dealer is the kind of person who will accept gifts
#define ARMS_DEALER_HAS_NO_INVENTORY 0x80000000 // 2147483648 //The arms dealer does not carry any inventory #define ARMS_DEALER_SOME_USED_ITEMS 0x40000000 // 1073741824 //The dealer can have used items in his inventory
#define ARMS_DEALER_HAS_NO_INVENTORY 0x80000000 // 2147483648 //The dealer does not carry any inventory
#define ARMS_DEALER_BIG_GUNS ARMS_DEALER_SMGCLASS | ARMS_DEALER_RIFLECLASS | ARMS_DEALER_MGCLASS | ARMS_DEALER_SHOTGUNCLASS #define ARMS_DEALER_BIG_GUNS ARMS_DEALER_SMGCLASS | ARMS_DEALER_RIFLECLASS | ARMS_DEALER_MGCLASS | ARMS_DEALER_SHOTGUNCLASS
@@ -349,8 +339,7 @@ UINT32 GetArmsDealerItemTypeFromItemNumber( UINT16 usItem );
//Count every single item the dealer has in stock //Count every single item the dealer has in stock
//UINT32 CountTotalItemsInArmsDealersInventory( UINT8 ubArmsDealer ); //UINT32 CountTotalItemsInArmsDealersInventory( UINT8 ubArmsDealer );
//Count only the # of "distinct" item types (for shopkeeper purposes) //Count only the # of "distinct" item types (for shopkeeper purposes)
UINT16 CountTotalItemsRepairDealerHasInForRepairs( UINT8 ubArmsDealer ); UINT16 CountTotalItemsRepairDealerHasInForRepairs( UINT8 ubArmsDealer );
UINT8 CountSpecificItemsRepairDealerHasInForRepairs( UINT8 ubArmsDealer, UINT16 usItemIndex );
void AddObjectToArmsDealerInventory( UINT8 ubArmsDealer, OBJECTTYPE *pObject ); void AddObjectToArmsDealerInventory( UINT8 ubArmsDealer, OBJECTTYPE *pObject );
+44 -114
View File
@@ -17,15 +17,12 @@
#include "connect.h" #include "connect.h"
#endif #endif
//forward declarations of common classes to eliminate includes //forward declarations of common classes to eliminate includes
class OBJECTTYPE; class OBJECTTYPE;
class SOLDIERTYPE; class SOLDIERTYPE;
extern INT8 gbSelectedArmsDealerID; extern INT8 gbSelectedArmsDealerID;
// CHRISL: Updated this to include IC_LBEGEAR class // CHRISL: Updated this to include IC_LBEGEAR class
// This table controls the order items appear in inventory at BR's and dealers, and which kinds of items are sold used // This table controls the order items appear in inventory at BR's and dealers, and which kinds of items are sold used
ITEM_SORT_ENTRY DealerItemSortInfo[ ] = ITEM_SORT_ENTRY DealerItemSortInfo[ ] =
@@ -56,8 +53,6 @@ ITEM_SORT_ENTRY DealerItemSortInfo[ ] =
{ IC_NONE, NOGUNCLASS, }, { IC_NONE, NOGUNCLASS, },
}; };
// //
// Setup the inventory arrays for each of the arms dealers // Setup the inventory arrays for each of the arms dealers
// //
@@ -697,9 +692,23 @@ DEALER_POSSIBLE_INV gArmsDealerAdditional[ADDITIONAL_ARMS_DEALERS][MAXITEMS+1];
// prototypes // prototypes
INT8 GetMaxItemAmount( DEALER_POSSIBLE_INV *pInv, UINT16 usItemIndex ); INT8 GetMaxItemAmount( DEALER_POSSIBLE_INV *pInv, UINT16 usItemIndex )
{
UINT16 usCnt = 0;
//loop through the array until a the LAST_DEALER_ITEM is hit
while ( pInv[usCnt].sItemIndex != LAST_DEALER_ITEM )
{
//if this item is the one we want
if ( pInv[usCnt].sItemIndex == usItemIndex )
return( pInv[usCnt].ubOptimalNumber );
// move to the next item
++usCnt;
}
return( NO_DEALER_ITEM );
}
INT8 GetDealersMaxItemAmount( UINT8 ubDealerID, UINT16 usItemIndex ) INT8 GetDealersMaxItemAmount( UINT8 ubDealerID, UINT16 usItemIndex )
{ {
@@ -812,26 +821,6 @@ INT8 GetDealersMaxItemAmount( UINT8 ubDealerID, UINT16 usItemIndex )
} }
} }
INT8 GetMaxItemAmount( DEALER_POSSIBLE_INV *pInv, UINT16 usItemIndex )
{
UINT16 usCnt=0;
//loop through the array until a the LAST_DEALER_ITEM is hit
while( pInv[ usCnt ].sItemIndex != LAST_DEALER_ITEM )
{
//if this item is the one we want
if( pInv[ usCnt ].sItemIndex == usItemIndex )
return( pInv[ usCnt ].ubOptimalNumber );
// move to the next item
usCnt++;
}
return( NO_DEALER_ITEM );
}
DEALER_POSSIBLE_INV *GetPointerToDealersPossibleInventory( UINT8 ubArmsDealerID ) DEALER_POSSIBLE_INV *GetPointerToDealersPossibleInventory( UINT8 ubArmsDealerID )
{ {
switch( ubArmsDealerID ) switch( ubArmsDealerID )
@@ -940,7 +929,6 @@ DEALER_POSSIBLE_INV *GetPointerToDealersPossibleInventory( UINT8 ubArmsDealerID
} }
} }
//Madd: added boolean fUsed //Madd: added boolean fUsed
UINT8 GetCurrentSuitabilityForItem( INT8 bArmsDealer, UINT16 usItemIndex, BOOLEAN fUsed ) UINT8 GetCurrentSuitabilityForItem( INT8 bArmsDealer, UINT16 usItemIndex, BOOLEAN fUsed )
{ {
@@ -948,8 +936,7 @@ UINT8 GetCurrentSuitabilityForItem( INT8 bArmsDealer, UINT16 usItemIndex, BOOLEA
unsigned ubMinCoolness, ubMaxCoolness; unsigned ubMinCoolness, ubMaxCoolness;
const int bobbyRaysID = -1; const int bobbyRaysID = -1;
// item suitability varies with the player's maximum progress through the game. The farther he gets, the better items // item suitability varies with the player's maximum progress through the game. The farther he gets, the better items
// we make available. Weak items become more and more infrequent later in the game, although they never quite vanish. // we make available. Weak items become more and more infrequent later in the game, although they never quite vanish.
@@ -965,8 +952,7 @@ UINT8 GetCurrentSuitabilityForItem( INT8 bArmsDealer, UINT16 usItemIndex, BOOLEA
{ {
return(ITEM_SUITABILITY_NONE); return(ITEM_SUITABILITY_NONE);
} }
ubItemCoolness = Item[ usItemIndex ].ubCoolness; ubItemCoolness = Item[ usItemIndex ].ubCoolness;
if (ubItemCoolness == 0) if (ubItemCoolness == 0)
@@ -991,19 +977,16 @@ UINT8 GetCurrentSuitabilityForItem( INT8 bArmsDealer, UINT16 usItemIndex, BOOLEA
if ( Item[usItemIndex].medical || Item[usItemIndex].canteen || Item[usItemIndex].medicalkit || Item[usItemIndex].locksmithkit || Item[usItemIndex].toolkit || Item[usItemIndex].crowbar || Item[usItemIndex].jar ) if ( Item[usItemIndex].medical || Item[usItemIndex].canteen || Item[usItemIndex].medicalkit || Item[usItemIndex].locksmithkit || Item[usItemIndex].toolkit || Item[usItemIndex].crowbar || Item[usItemIndex].jar )
return(ITEM_SUITABILITY_ALWAYS); return(ITEM_SUITABILITY_ALWAYS);
//} //}
// If it's not BobbyRay, Tony, or Devin // If it's not BobbyRay, Tony, or Devin
if (bArmsDealer != bobbyRaysID && armsDealerInfo[bArmsDealer].allInventoryAlwaysAvailable) if (bArmsDealer != bobbyRaysID && armsDealerInfo[bArmsDealer].allInventoryAlwaysAvailable)
{ {
// all the other dealers have very limited inventories, so their suitability remains constant at all times in game // all the other dealers have very limited inventories, so their suitability remains constant at all times in game
return(ITEM_SUITABILITY_HIGH); return(ITEM_SUITABILITY_HIGH);
} }
// figure out the appropriate range of coolness based on player's maximum progress so far // figure out the appropriate range of coolness based on player's maximum progress so far
if ( bArmsDealer == bobbyRaysID ) { if ( bArmsDealer == bobbyRaysID ) {
ubMinCoolness = 1; ubMinCoolness = 1;
ubMaxCoolness = HighestPlayerProgressPercentage() / 10 + 1; ubMaxCoolness = HighestPlayerProgressPercentage() / 10 + 1;
@@ -1093,20 +1076,16 @@ UINT8 GetCurrentSuitabilityForItem( INT8 bArmsDealer, UINT16 usItemIndex, BOOLEA
return(ITEM_SUITABILITY_LOW); return(ITEM_SUITABILITY_LOW);
} }
UINT8 ChanceOfItemTransaction( INT8 bArmsDealer, UINT16 usItemIndex, BOOLEAN fDealerIsSelling, BOOLEAN fUsed ) UINT8 ChanceOfItemTransaction( INT8 bArmsDealer, UINT16 usItemIndex, BOOLEAN fDealerIsSelling, BOOLEAN fUsed )
{ {
UINT8 ubItemCoolness; UINT8 ubItemCoolness;
UINT8 ubChance = 0; UINT8 ubChance = 0;
BOOLEAN fBobbyRay = FALSE; BOOLEAN fBobbyRay = FALSE;
// make sure dealers don't carry used items that they shouldn't // make sure dealers don't carry used items that they shouldn't
if ( fUsed && !fDealerIsSelling && !CanDealerItemBeSoldUsed( usItemIndex ) ) if ( fUsed && !fDealerIsSelling && !CanDealerItemBeSoldUsed( usItemIndex ) )
return( 0 ); return( 0 );
if (bArmsDealer == -1) if (bArmsDealer == -1)
{ {
// Bobby Ray has an easier time getting resupplied than the local dealers do // Bobby Ray has an easier time getting resupplied than the local dealers do
@@ -1185,20 +1164,14 @@ UINT8 ChanceOfItemTransaction( INT8 bArmsDealer, UINT16 usItemIndex, BOOLEAN fDe
ubChance /= 2; ubChance /= 2;
} }
} }
return(ubChance); return(ubChance);
} }
BOOLEAN ItemTransactionOccurs( INT8 bArmsDealer, UINT16 usItemIndex, BOOLEAN fDealerIsSelling, BOOLEAN fUsed ) BOOLEAN ItemTransactionOccurs( INT8 bArmsDealer, UINT16 usItemIndex, BOOLEAN fDealerIsSelling, BOOLEAN fUsed )
{ {
UINT8 ubChance; INT16 sInventorySlot;
INT16 sInventorySlot; UINT8 ubChance = ChanceOfItemTransaction( bArmsDealer, usItemIndex, fDealerIsSelling, fUsed );
ubChance = ChanceOfItemTransaction( bArmsDealer, usItemIndex, fDealerIsSelling, fUsed );
// if the dealer is buying, and a chance exists (i.e. the item is "eligible") // if the dealer is buying, and a chance exists (i.e. the item is "eligible")
if (!fDealerIsSelling && (ubChance > 0)) if (!fDealerIsSelling && (ubChance > 0))
@@ -1224,66 +1197,44 @@ BOOLEAN ItemTransactionOccurs( INT8 bArmsDealer, UINT16 usItemIndex, BOOLEAN fDe
} }
// roll to see if a transaction occurs // roll to see if a transaction occurs
if (Random(100) < ubChance) return Chance( ubChance );
{
return(TRUE);
}
else
{
return(FALSE);
}
} }
UINT8 DetermineInitialInvItems( INT8 bArmsDealerID, UINT16 usItemIndex, UINT8 ubChances, BOOLEAN fUsed) UINT8 DetermineInitialInvItems( INT8 bArmsDealerID, UINT16 usItemIndex, UINT8 ubChances, BOOLEAN fUsed)
{ {
UINT8 ubNumBought; if ( is_networked )
UINT8 ubCnt; return ubChances;
// initial inventory is now rolled for one item at a time, instead of one type at a time, to improve variety // initial inventory is now rolled for one item at a time, instead of one type at a time, to improve variety
ubNumBought = 0; UINT8 ubNumBought = 0;
for (ubCnt = 0; ubCnt < ubChances; ubCnt++)
for ( UINT8 ubCnt = 0; ubCnt < ubChances; ++ubCnt)
{ {
if (!is_networked) if ( ItemTransactionOccurs( bArmsDealerID, usItemIndex, DEALER_BUYING, fUsed ) )
{ {
if (ItemTransactionOccurs( bArmsDealerID, usItemIndex, DEALER_BUYING, fUsed)) ++ubNumBought;
{
ubNumBought++;
}
}
else
{
ubNumBought++;
} }
} }
return( ubNumBought ); return( ubNumBought );
} }
UINT8 HowManyItemsAreSold( INT8 bArmsDealerID, UINT16 usItemIndex, UINT8 ubNumInStock, BOOLEAN fUsed) UINT8 HowManyItemsAreSold( INT8 bArmsDealerID, UINT16 usItemIndex, UINT8 ubNumInStock, BOOLEAN fUsed)
{ {
UINT8 ubNumSold;
UINT8 ubCnt;
// items are now virtually "sold" one at a time // items are now virtually "sold" one at a time
ubNumSold = 0; UINT8 ubNumSold = 0;
for (ubCnt = 0; ubCnt < ubNumInStock; ubCnt++) for ( UINT8 ubCnt = 0; ubCnt < ubNumInStock; ++ubCnt)
{ {
if (ItemTransactionOccurs( bArmsDealerID, usItemIndex, DEALER_SELLING, fUsed)) if (ItemTransactionOccurs( bArmsDealerID, usItemIndex, DEALER_SELLING, fUsed))
{ {
ubNumSold++; ++ubNumSold;
} }
} }
return( ubNumSold ); return( ubNumSold );
} }
UINT8 HowManyItemsToReorder(UINT8 ubWanted, UINT8 ubStillHave) UINT8 HowManyItemsToReorder(UINT8 ubWanted, UINT8 ubStillHave)
{ {
UINT8 ubNumReordered = 0; UINT8 ubNumReordered = 0;
@@ -1312,36 +1263,21 @@ UINT8 HowManyItemsToReorder(UINT8 ubWanted, UINT8 ubStillHave)
return(ubNumReordered); return(ubNumReordered);
} }
int BobbyRayItemQsortCompare(const void *pArg1, const void *pArg2) int BobbyRayItemQsortCompare(const void *pArg1, const void *pArg2)
{ {
UINT16 usItem1Index; UINT16 usItem1Index = ( ( STORE_INVENTORY * ) pArg1 )->usItemIndex;
UINT16 usItem2Index; UINT16 usItem2Index = ( ( STORE_INVENTORY * ) pArg2 )->usItemIndex;
UINT8 ubItem1Quality;
UINT8 ubItem2Quality;
usItem1Index = ( ( STORE_INVENTORY * ) pArg1 )->usItemIndex; UINT8 ubItem1Quality = ( ( STORE_INVENTORY * ) pArg1 )->ubItemQuality;
usItem2Index = ( ( STORE_INVENTORY * ) pArg2 )->usItemIndex; UINT8 ubItem2Quality = ( ( STORE_INVENTORY * ) pArg2 )->ubItemQuality;
ubItem1Quality = ( ( STORE_INVENTORY * ) pArg1 )->ubItemQuality;
ubItem2Quality = ( ( STORE_INVENTORY * ) pArg2 )->ubItemQuality;
return( CompareItemsForSorting( usItem1Index, usItem2Index, ubItem1Quality, ubItem2Quality ) ); return( CompareItemsForSorting( usItem1Index, usItem2Index, ubItem1Quality, ubItem2Quality ) );
} }
int CompareItemsForSorting( UINT16 usItem1Index, UINT16 usItem2Index, UINT16 ubItem1Quality, UINT16 ubItem2Quality ) int CompareItemsForSorting( UINT16 usItem1Index, UINT16 usItem2Index, UINT16 ubItem1Quality, UINT16 ubItem2Quality )
{ {
UINT8 ubItem1Category; UINT8 ubItem1Category = GetDealerItemCategoryNumber( usItem1Index );
UINT8 ubItem2Category; UINT8 ubItem2Category = GetDealerItemCategoryNumber( usItem2Index );
//UINT16 usItem1Price;
//UINT16 usItem2Price;
//UINT8 ubItem1Coolness;
//UINT8 ubItem2Coolness;
ubItem1Category = GetDealerItemCategoryNumber( usItem1Index );
ubItem2Category = GetDealerItemCategoryNumber( usItem2Index );
// lower category first // lower category first
if ( ubItem1Category < ubItem2Category ) if ( ubItem1Category < ubItem2Category )
@@ -1470,15 +1406,11 @@ int CompareItemsForSorting( UINT16 usItem1Index, UINT16 usItem2Index, UINT16 ubI
return( 0 ); return( 0 );
} }
UINT8 GetDealerItemCategoryNumber( UINT16 usItemIndex ) UINT8 GetDealerItemCategoryNumber( UINT16 usItemIndex )
{ {
UINT32 uiItemClass;
UINT8 ubWeaponClass; UINT8 ubWeaponClass;
UINT8 ubCategory = 0; UINT8 ubCategory = 0;
UINT32 uiItemClass = Item[ usItemIndex ].usItemClass;
uiItemClass = Item[ usItemIndex ].usItemClass;
if ( usItemIndex < gMAXITEMS_READ && IsWeapon( usItemIndex ) ) if ( usItemIndex < gMAXITEMS_READ && IsWeapon( usItemIndex ) )
{ {
@@ -1524,8 +1456,6 @@ UINT8 GetDealerItemCategoryNumber( UINT16 usItemIndex )
return( 0 ); return( 0 );
} }
BOOLEAN CanDealerItemBeSoldUsed( UINT16 usItemIndex ) BOOLEAN CanDealerItemBeSoldUsed( UINT16 usItemIndex )
{ {
// if ( !( Item[ usItemIndex ].fFlags & ITEM_DAMAGEABLE ) ) // if ( !( Item[ usItemIndex ].fFlags & ITEM_DAMAGEABLE ) )