Remove compiler warning for exceeding stack size. (#153)

* Use std::map instead of 16001 elements long array
* Remove old commented out code
This commit is contained in:
Asdow
2023-05-25 22:46:18 +03:00
committed by GitHub
parent dd004dc114
commit e4e1d472fd
+6 -49
View File
@@ -722,10 +722,7 @@ void LimitArmsDealersInventory( UINT8 ubArmsDealer, UINT32 uiDealerItemType, UIN
if( gArmsDealerStatus[ ubArmsDealer ].fOutOfBusiness )
return;
//ADB, ya, a whole 1 line of extra code!
// not permitted for repair dealers - would take extra code to avoid counting items under repair!
//Assert( !DoesDealerDoRepairs( ubArmsDealer ) );
int numTotalItems[MAXITEMS] = { 0 };
std::map< UINT16, UINT16> numTotalItems;
for (DealerItemList::iterator iter = gArmsDealersInventory[ ubArmsDealer ].begin(); iter != gArmsDealersInventory[ ubArmsDealer ].end(); ++iter) {
if (iter->ItemIsInInventory() == true && iter->IsUnderRepair() == false) {
numTotalItems[iter->object.usItem] += iter->object.ubNumberOfObjects;
@@ -742,7 +739,7 @@ void LimitArmsDealersInventory( UINT8 ubArmsDealer, UINT32 uiDealerItemType, UIN
for ( usItemIndex = 1; usItemIndex < gMAXITEMS_READ; ++usItemIndex )
{
//if there is some items in stock
if( numTotalItems[usItemIndex] > 0)
if (numTotalItems.count(usItemIndex) > 0)
{
//if the item is of the same dealer item type
if( uiDealerItemType & GetArmsDealerItemTypeFromItemNumber( usItemIndex ) )
@@ -806,45 +803,6 @@ void LimitArmsDealersInventory( UINT8 ubArmsDealer, UINT32 uiDealerItemType, UIN
}
}
/*
//loop through all items of the same type
for( usItemIndex = 1; usItemIndex < MAXITEMS; usItemIndex++ )
{
//if there are some non-repairing items in stock
if( gOldArmsDealersInventory[ ubArmsDealer ][ usItemIndex ].ubTotalItems )
{
//if the item is of the same dealer item type
if( uiDealerItemType & GetArmsDealerItemTypeFromItemNumber( usItemIndex ) )
{
// a random chance that the item will be removed
if( Random( 100 ) < 30 )
{
//remove the item
//if the dealer item type is ammo
if( uiDealerItemType == ARMS_DEALER_AMMO )
{
// remove all of them, since each ammo item counts as only one "item" here
// create item info describing a perfect item
SetSpecialItemInfoToDefaults( &SpclItemInfo );
// ammo will always be only condition 100, there's never any in special slots
RemoveItemFromArmsDealerInventory( ubArmsDealer, usItemIndex, gOldArmsDealersInventory[ ubArmsDealer ][ usItemIndex ].ubTotalItems );
}
else
{
// pick 1 random one, don't care about its condition
RemoveRandomItemFromArmsDealerInventory( ubArmsDealer, usItemIndex, 1 );
}
uiItemsToRemove--;
if( uiItemsToRemove == 0)
break;
}
}
}
}
*/
}
}
@@ -858,10 +816,8 @@ void GuaranteeAtLeastOneItemOfType( UINT8 ubArmsDealer, UINT32 uiDealerItemType
if( gArmsDealerStatus[ ubArmsDealer ].fOutOfBusiness )
return;
//ADB, ya, a whole 1 line of extra code!
// not permitted for repair dealers - would take extra code to avoid counting items under repair!
//Assert( !DoesDealerDoRepairs( ubArmsDealer ) );
int numTotalItems[MAXITEMS] = { 0 };
std::map< UINT16, UINT16> numTotalItems;
for (DealerItemList::iterator iter = gArmsDealersInventory[ ubArmsDealer ].begin(); iter != gArmsDealersInventory[ ubArmsDealer ].end(); ++iter)
{
if (iter->ItemIsInInventory() == true && iter->IsUnderRepair() == false)
@@ -870,6 +826,7 @@ void GuaranteeAtLeastOneItemOfType( UINT8 ubArmsDealer, UINT32 uiDealerItemType
}
}
std::vector<UINT16> usAvailableItems;
std::vector<UINT8> ubChanceForAvailableItem;
//loop through all items of the same type
@@ -879,7 +836,7 @@ void GuaranteeAtLeastOneItemOfType( UINT8 ubArmsDealer, UINT32 uiDealerItemType
if( uiDealerItemType & GetArmsDealerItemTypeFromItemNumber( usItemIndex ) )
{
//if there are any of these in stock
if( numTotalItems[usItemIndex] > 0 )
if( numTotalItems.count(usItemIndex) > 0 )
{
//there is already at least 1 item of that type, return
return;