diff --git a/GameVersion.cpp b/GameVersion.cpp index 0fe8e0c5..ce8b13b1 100644 --- a/GameVersion.cpp +++ b/GameVersion.cpp @@ -15,9 +15,9 @@ #ifdef JA2EDITOR #ifdef JA2UB - CHAR16 zVersionLabel[256] = { L"Unfinished Business - Map Editor v1.13.7529 (Development Build)" }; + CHAR16 zVersionLabel[256] = { L"Unfinished Business - Map Editor v1.13.7599 (Development Build)" }; #else - CHAR16 zVersionLabel[256] = { L"Map Editor v1.13.7529 (Development Build)" }; + CHAR16 zVersionLabel[256] = { L"Map Editor v1.13.7599 (Development Build)" }; #endif // ------------------------------ @@ -27,11 +27,11 @@ //DEBUG BUILD VERSION #ifdef JA2UB - CHAR16 zVersionLabel[256] = { L"Debug: Unfinished Business - v1.13.7529 (Development Build)" }; + CHAR16 zVersionLabel[256] = { L"Debug: Unfinished Business - v1.13.7599 (Development Build)" }; #elif defined (JA113DEMO) - CHAR16 zVersionLabel[256] = { L"Debug: JA2 Demo - v1.13.7529 (Development Build)" }; + CHAR16 zVersionLabel[256] = { L"Debug: JA2 Demo - v1.13.7599 (Development Build)" }; #else - CHAR16 zVersionLabel[256] = { L"Debug: v1.13.7529 (Development Build)" }; + CHAR16 zVersionLabel[256] = { L"Debug: v1.13.7599 (Development Build)" }; #endif #elif defined CRIPPLED_VERSION @@ -46,16 +46,16 @@ //RELEASE BUILD VERSION #ifdef JA2UB - CHAR16 zVersionLabel[256] = { L"Release Unfinished Business - v1.13.7529 (Development Build)" }; + CHAR16 zVersionLabel[256] = { L"Release Unfinished Business - v1.13.7599 (Development Build)" }; #elif defined (JA113DEMO) - CHAR16 zVersionLabel[256] = { L"Release JA2 Demo - v1.13.7529 (Development Build)" }; + CHAR16 zVersionLabel[256] = { L"Release JA2 Demo - v1.13.7599 (Development Build)" }; #else - CHAR16 zVersionLabel[256] = { L"Release v1.13.7529 (Development Build)" }; + CHAR16 zVersionLabel[256] = { L"Release v1.13.7599 (Development Build)" }; #endif #endif -CHAR8 czVersionNumber[16] = { "Build 14.09.24" }; //YY.MM.DD +CHAR8 czVersionNumber[16] = { "Build 14.10.19" }; //YY.MM.DD CHAR16 zTrackingNumber[16] = { L"Z" }; // SAVE_GAME_VERSION is defined in header, change it there diff --git a/Laptop/BobbyR.cpp b/Laptop/BobbyR.cpp index 3b4f2357..0908fe1a 100644 --- a/Laptop/BobbyR.cpp +++ b/Laptop/BobbyR.cpp @@ -620,19 +620,17 @@ void InitBobbyRayInventory() BOOLEAN InitBobbyRayNewInventory() { - UINT16 i; UINT16 usBobbyrIndex = 0; - memset( LaptopSaveInfo.BobbyRayInventory, 0, sizeof(STORE_INVENTORY) * MAXITEMS); // add all the NEW items he can ever sell into his possible inventory list, for now in order by item # - for( i = 0; i < MAXITEMS; i++ ) + for( UINT16 i = 0; i < MAXITEMS; ++i ) { //if Bobby Ray sells this, it can be sold, and it's allowed into this game (some depend on e.g. gun-nut option) // if( ( StoreInventory[ i ][ BOBBY_RAY_NEW ] != 0) && !( Item[ i ].fFlags & ITEM_NOT_BUYABLE ) && ItemIsLegal( i ) ) LaptopSaveInfo.BobbyRayInventory[ usBobbyrIndex ].usItemIndex = i; - usBobbyrIndex++; + ++usBobbyrIndex; } if ( usBobbyrIndex > 1 ) @@ -641,7 +639,6 @@ BOOLEAN InitBobbyRayNewInventory() qsort( LaptopSaveInfo.BobbyRayInventory, usBobbyrIndex, sizeof( STORE_INVENTORY ), BobbyRayItemQsortCompare ); } - // remember how many entries in the list are valid LaptopSaveInfo.usInventoryListLength[ BOBBY_RAY_NEW ] = usBobbyrIndex; // also mark the end of the list of valid item entries @@ -653,14 +650,13 @@ BOOLEAN InitBobbyRayNewInventory() BOOLEAN InitBobbyRayUsedInventory() { - UINT16 i; UINT16 usBobbyrIndex = 0; memset( LaptopSaveInfo.BobbyRayUsedInventory, 0, sizeof(STORE_INVENTORY) * MAXITEMS); // add all the NEW items he can ever sell into his possible inventory list, for now in order by item # - for( i = 0; i < MAXITEMS; i++ ) + for( UINT16 i = 0; i < MAXITEMS; ++i ) { //if Bobby Ray sells this, it can be sold, and it's allowed into this game (some depend on e.g. gun-nut option) // if( ( StoreInventory[ i ][ BOBBY_RAY_USED ] != 0) && !( Item[ i ].fFlags & ITEM_NOT_BUYABLE ) && ItemIsLegal( i ) ) @@ -668,7 +664,7 @@ BOOLEAN InitBobbyRayUsedInventory() if ( CanDealerItemBeSoldUsed( i ) ) { LaptopSaveInfo.BobbyRayUsedInventory[ usBobbyrIndex ].usItemIndex = i; - usBobbyrIndex++; + ++usBobbyrIndex; } } @@ -700,7 +696,7 @@ void DailyUpdateOfBobbyRaysNewInventory() SimulateBobbyRayCustomer(LaptopSaveInfo.BobbyRayInventory, BOBBY_RAY_NEW); //loop through all items BR can stock to see what needs reordering - for(i = 0; i < LaptopSaveInfo.usInventoryListLength[BOBBY_RAY_NEW]; i++) + for(i = 0; i < LaptopSaveInfo.usInventoryListLength[BOBBY_RAY_NEW]; ++i) { // the index is NOT the item #, get that from the table usItemIndex = LaptopSaveInfo.BobbyRayInventory[ i ].usItemIndex; @@ -951,13 +947,11 @@ void SimulateBobbyRayCustomer(STORE_INVENTORY *pInventoryArray, BOOLEAN fUsed) void CancelAllPendingBRPurchaseOrders(void) { - INT16 i; - // remove all the BR-Order events off the event queue DeleteAllStrategicEventsOfType( EVENT_UPDATE_BOBBY_RAY_INVENTORY ); // zero out all the quantities on order - for(i = 0; i < MAXITEMS; i++) + for( UINT16 i = 0; i < MAXITEMS; ++i) { LaptopSaveInfo.BobbyRayInventory[ i ].ubQtyOnOrder = 0; LaptopSaveInfo.BobbyRayUsedInventory[ i ].ubQtyOnOrder = 0; @@ -967,11 +961,3 @@ void CancelAllPendingBRPurchaseOrders(void) DailyUpdateOfBobbyRaysNewInventory(); DailyUpdateOfBobbyRaysUsedInventory(); } - - - - - - - - diff --git a/Laptop/BobbyRGuns.cpp b/Laptop/BobbyRGuns.cpp index 7357d743..9504f402 100644 --- a/Laptop/BobbyRGuns.cpp +++ b/Laptop/BobbyRGuns.cpp @@ -2519,7 +2519,7 @@ void SetFirstLastPagesForNew( UINT32 uiClassMask, INT32 iFilter, INT32 iSubFilte gubCurPage = 0; //First loop through to get the first and last index indexs - for(i=0; i 0) @@ -830,17 +830,14 @@ void SetupStoreInventory( STORE_INVENTORY *pInventoryArray, BOOLEAN fUsed ) BOOLEAN DoesGunOfSameClassExistInInventory( UINT8 ubItemIndex, UINT8 ubDealerID ) { - UINT16 i; - STORE_INVENTORY *pInventoryArray; pInventoryArray = GetPtrToStoreInventory( ubDealerID ); if( pInventoryArray == NULL ) return( FALSE ); - - + //go through all of the guns - for(i=0; iobject); @@ -873,14 +871,16 @@ BOOLEAN LoadArmsDealerInventoryFromSavedGameFile( HWFILE hFile ) } //if there are any items on order, order them - if ((*pOldArmsDealersInventory)[ubArmsDealer][usItemIndex].ubQtyOnOrder) { + if ((*pOldArmsDealersInventory)[ubArmsDealer][usItemIndex].ubQtyOnOrder) + { OrderDealerItems(ubArmsDealer, usItemIndex, (*pOldArmsDealersInventory)[ubArmsDealer][usItemIndex].ubQtyOnOrder, (*pOldArmsDealersInventory)[ubArmsDealer][usItemIndex].uiOrderArrivalTime); } //if there are any special elements allocated for this item, load them - for ( int x = 0; x < (*pOldArmsDealersInventory)[ubArmsDealer][usItemIndex].ubElementsAlloced; ++x) { + for ( int x = 0; x < (*pOldArmsDealersInventory)[ubArmsDealer][usItemIndex].ubElementsAlloced; ++x) + { if (!FileRead( hFile, &oldSpecial, sizeof( OLD_DEALER_SPECIAL_ITEM_101 ), &uiNumBytesRead )) { return( FALSE ); diff --git a/Strategic/Map Screen Interface Map Inventory.cpp b/Strategic/Map Screen Interface Map Inventory.cpp index 5c2649b6..a75954bd 100644 --- a/Strategic/Map Screen Interface Map Inventory.cpp +++ b/Strategic/Map Screen Interface Map Inventory.cpp @@ -2054,10 +2054,10 @@ void BuildStashForSelectedSector( INT16 sMapX, INT16 sMapY, INT16 sMapZ ) // was temporay used to get #items in file, now count what actually is added fNumTotal = 0; // now run through list and copy reference - for(UINT32 i = 0; i < fWorldItems.size(); i++ ) + for(UINT32 i = 0; i < fWorldItems.size(); ++i ) { // TEST!! If the item exists, and is NOT VALID, report it - if( fWorldItems[i].fExists && fWorldItems[ i ].object.usItem > MAXITEMS ) + if( fWorldItems[i].fExists && fWorldItems[ i ].object.usItem > gMAXITEMS_READ ) { ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_BETAVERSION, L"The %d item in the list is NOT valid (ID%d). Please send save. DF 1.", i, fWorldItems[i].object.usItem ); } @@ -4744,7 +4744,7 @@ void SortSectorInventoryAmmo(bool useBoxes) while (ammoPresent && loopCount <= 10 ) { // Start scanning through the entire Sector Inventory pool. - for(UINT32 iInvCounter = 0; iInvCounter < uiOrigInvSize; iInvCounter++) + for(UINT32 iInvCounter = 0; iInvCounter < uiOrigInvSize; ++iInvCounter) { // Set values crateItem = 0; @@ -4770,7 +4770,7 @@ void SortSectorInventoryAmmo(bool useBoxes) // as possible into crates. // Look through all items in the game to try and find an ammocrate that can contain this kind of ammo. - for(int iCrateLoop = 0; iCrateLoop < MAXITEMS; iCrateLoop++) + for ( int iCrateLoop = 0; iCrateLoop < gMAXITEMS_READ; ++iCrateLoop ) { // Is it the right ammo crate? if( Item[iCrateLoop].usItemClass == IC_AMMO && @@ -4788,7 +4788,7 @@ void SortSectorInventoryAmmo(bool useBoxes) if(crateItem != 0) { // Excellent. Let see if a crate like this already exists in the Sector Inventory. - for(UINT32 iInvCounter2=0; iInvCounter2 < pInventoryPoolList.size(); iInvCounter2++) + for(UINT32 iInvCounter2=0; iInvCounter2 < pInventoryPoolList.size(); ++iInvCounter2) { // Non-empty slots please... if(pInventoryPoolList[iInvCounter2].object.exists() == true) diff --git a/Tactical/Arms Dealer Init.cpp b/Tactical/Arms Dealer Init.cpp index bc7ad54f..377ed1cf 100644 --- a/Tactical/Arms Dealer Init.cpp +++ b/Tactical/Arms Dealer Init.cpp @@ -197,8 +197,7 @@ void InitAllArmsDealers() void InitializeOneArmsDealer( UINT8 ubArmsDealer ) { UINT16 usItemIndex; - UINT8 ubNumItems=0; - + UINT8 ubNumItems=0; memset( &( gArmsDealerStatus[ ubArmsDealer ] ), 0, sizeof( ARMS_DEALER_STATUS ) ); gArmsDealersInventory.resize(gArmsDealersInventory.size() + 1); @@ -212,9 +211,8 @@ void InitializeOneArmsDealer( UINT8 ubArmsDealer ) return; } - //loop through all the item types - for( usItemIndex = 1; usItemIndex < MAXITEMS; usItemIndex++ ) + for ( usItemIndex = 1; usItemIndex < gMAXITEMS_READ; ++usItemIndex ) { if ( Item[usItemIndex].usItemClass == 0 ) break; @@ -332,14 +330,14 @@ void DailyUpdateOfArmsDealersInventory() // Once a day, loop through each dealer's inventory items and possibly sell some void SimulateArmsDealerCustomer() { - UINT8 ubArmsDealer=0; + UINT8 ubArmsDealer=0; UINT16 usItemIndex; UINT8 ubItemsSold=0; static int numPerfectItems[MAXITEMS]; //loop through all the arms dealers - for( ubArmsDealer=0;ubArmsDealerItemIsInInventory() == true && iter->bItemCondition == 100) { + DealerItemList::iterator iterend = gArmsDealersInventory[ubArmsDealer].end( ); + for (DealerItemList::iterator iter = gArmsDealersInventory[ ubArmsDealer ].begin(); iter != iterend; ++iter ) + { + if (iter->ItemIsInInventory() == true && iter->bItemCondition == 100) + { numPerfectItems[iter->object.usItem] += iter->object.ubNumberOfObjects; } } //loop through all items of the same type - for( usItemIndex = 1; usItemIndex < MAXITEMS; usItemIndex++ ) + for ( usItemIndex = 1; usItemIndex < gMAXITEMS_READ; ++usItemIndex ) { if ( Item[usItemIndex].usItemClass == 0 ) break; @@ -389,19 +389,21 @@ void SimulateArmsDealerCustomer() } } - for (DealerItemList::iterator iter = gArmsDealersInventory[ ubArmsDealer ].begin(); - iter != gArmsDealersInventory[ ubArmsDealer ].end(); ++iter) { + iterend = gArmsDealersInventory[ubArmsDealer].end(); + for (DealerItemList::iterator iter = gArmsDealersInventory[ ubArmsDealer ].begin(); iter != iterend; ++iter ) + { // next, try to sell all the used ones, gotta do these one at a time so we can remove them by element // don't worry about negative condition, repairmen can't come this far, they don't sell! - if (iter->bItemCondition < 100 && iter->bItemCondition > 0) { - if ( iter->ItemIsInInventory() == true) { + if (iter->bItemCondition < 100 && iter->bItemCondition > 0) + { + if ( iter->ItemIsInInventory() == true) + { // try selling just this one if (HowManyItemsAreSold( ubArmsDealer, iter->object.usItem, 1, TRUE) > 0) { iter = gArmsDealersInventory[ ubArmsDealer ].erase(iter); - if (iter == gArmsDealersInventory[ ubArmsDealer ].end()) { + if (iter == gArmsDealersInventory[ ubArmsDealer ].end() ) break; - } } } } @@ -424,7 +426,7 @@ void DailyCheckOnItemQuantities() //loop through all the arms dealers - for( ubArmsDealer=0;ubArmsDealer usAvailableItems; std::vector ubNumberOfAvailableItem; //loop through all items of the same class and count the number in stock - for( usItemIndex = 1; usItemIndex < MAXITEMS; usItemIndex++ ) + for ( usItemIndex = 1; usItemIndex < gMAXITEMS_READ; ++usItemIndex ) { - if ( Item[usItemIndex].usItemClass == 0 ) - break; //if there is some items in stock if( numTotalItems[usItemIndex] > 0) { @@ -838,10 +836,8 @@ void GuaranteeAtLeastOneItemOfType( UINT8 ubArmsDealer, UINT32 uiDealerItemType std::vector usAvailableItems; std::vector ubChanceForAvailableItem; //loop through all items of the same type - for( usItemIndex = 1; usItemIndex < MAXITEMS; usItemIndex++ ) + for ( usItemIndex = 1; usItemIndex < gMAXITEMS_READ; ++usItemIndex ) { - if ( Item[usItemIndex].usItemClass == 0 ) - break; //if the item is of the same dealer item type if( uiDealerItemType & GetArmsDealerItemTypeFromItemNumber( usItemIndex ) ) { @@ -1447,7 +1443,6 @@ bool ItemIsSpecial(DEALER_SPECIAL_ITEM& item) UINT16 CountTotalItemsRepairDealerHasInForRepairs( UINT8 ubArmsDealer ) { - UINT16 usItemIndex; UINT16 usHowManyInForRepairs = 0; //if the dealer is not a repair dealer, no need to count, return 0 @@ -1455,10 +1450,8 @@ UINT16 CountTotalItemsRepairDealerHasInForRepairs( UINT8 ubArmsDealer ) return( 0 ); //loop through the dealers inventory and count the number of items in for repairs - for( usItemIndex=0; usItemIndex < MAXITEMS; usItemIndex++ ) + for ( UINT16 usItemIndex = 0; usItemIndex < gMAXITEMS_READ; ++usItemIndex ) { - if ( Item[usItemIndex].usItemClass == 0 ) - break; usHowManyInForRepairs += CountSpecificItemsRepairDealerHasInForRepairs( ubArmsDealer, usItemIndex ); } @@ -1474,13 +1467,12 @@ UINT8 CountSpecificItemsRepairDealerHasInForRepairs( UINT8 ubArmsDealer, UINT16 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++; + ++ubHowManyInForRepairs; } } } @@ -1697,11 +1689,13 @@ void RemoveItemFromArmsDealerInventory( UINT8 ubArmsDealer, UINT16 usItemIndex, { return; } - for (DealerItemList::iterator iter = gArmsDealersInventory[ ubArmsDealer ].begin(); iter != gArmsDealersInventory[ ubArmsDealer ].end(); iter++){ - if (iter->ItemIsInInventory() == true && iter->object.usItem == usItemIndex) { + for (DealerItemList::iterator iter = gArmsDealersInventory[ ubArmsDealer ].begin(); iter != gArmsDealersInventory[ ubArmsDealer ].end(); ++iter) + { + if (iter->ItemIsInInventory() == true && iter->object.usItem == usItemIndex) + { if(pObj != 0) { - for(unsigned int i = 0; i < ubHowMany; i++) + for(unsigned int i = 0; i < ubHowMany; ++i) { if((*pObj)[i]->operator == (*iter->object[i])) match = TRUE; diff --git a/Tactical/ArmsDealerInvInit.cpp b/Tactical/ArmsDealerInvInit.cpp index dd901eaa..df066d3b 100644 --- a/Tactical/ArmsDealerInvInit.cpp +++ b/Tactical/ArmsDealerInvInit.cpp @@ -1459,14 +1459,13 @@ int CompareItemsForSorting( UINT16 usItem1Index, UINT16 usItem2Index, UINT16 ubI UINT8 GetDealerItemCategoryNumber( UINT16 usItemIndex ) { - UINT32 uiItemClass; + UINT32 uiItemClass; UINT8 ubWeaponClass; UINT8 ubCategory = 0; - uiItemClass = Item[ usItemIndex ].usItemClass; - if ( usItemIndex < MAXITEMS && IsWeapon(usItemIndex) ) + if ( usItemIndex < gMAXITEMS_READ && IsWeapon( usItemIndex ) ) { ubWeaponClass = 0;// Madd: commented out so we can sort guns by name instead ... Weapon[ usItemIndex ].ubWeaponClass; } @@ -1476,7 +1475,6 @@ UINT8 GetDealerItemCategoryNumber( UINT16 usItemIndex ) ubWeaponClass = 0; } - ubCategory = 0; // search table until end-of-list marker is encountered @@ -1502,7 +1500,7 @@ UINT8 GetDealerItemCategoryNumber( UINT16 usItemIndex ) } // check vs. next category in the list - ubCategory++; + ++ubCategory; } // WANNE: commented the assert out, because we always get the assertion in debug mode! diff --git a/Tactical/Interface Items.cpp b/Tactical/Interface Items.cpp index a15a40a3..2925133f 100644 --- a/Tactical/Interface Items.cpp +++ b/Tactical/Interface Items.cpp @@ -1647,15 +1647,15 @@ void HandleRenderInvSlots( SOLDIERTYPE *pSoldier, UINT8 fDirtyLevel ) { if ( fDirtyLevel == DIRTYLEVEL2 ) { -# if defined( _DEBUG ) /* Sergeant_Kolja, to be removed later again */ - if( pSoldier->inv[ cnt ][0]->data.gun.ubGunAmmoType >= MAXITEMS ) - { - DebugMsg(TOPIC_JA2, DBG_LEVEL_1, String("pObject (%S) corrupted! GetHelpTextForItem() can crash.", (pSoldier->inv[ cnt ].usIteminv[ cnt ].usItem].szItemName : L"???" )); - ScreenMsg( MSG_FONT_RED, MSG_DEBUG, L"pObject (%s) corrupted! GetHelpTextForItem() can crash.", (pSoldier->inv[ cnt ].usIteminv[ cnt ].usItem].szItemName : L"???" ); - DebugBreak(); - AssertMsg( 0, "pObject corrupted! GetHelpTextForItem() can crash." ); - } -# endif +#if defined( _DEBUG ) /* Sergeant_Kolja, to be removed later again */ + if ( pSoldier->inv[cnt][0]->data.gun.ubGunAmmoType >= gMAXITEMS_READ ) + { + DebugMsg( TOPIC_JA2, DBG_LEVEL_1, String( "pObject (%S) corrupted! GetHelpTextForItem() can crash.", (pSoldier->inv[cnt].usIteminv[cnt].usItem].szItemName : L"???" ) ); + ScreenMsg( MSG_FONT_RED, MSG_DEBUG, L"pObject (%s) corrupted! GetHelpTextForItem() can crash.", (pSoldier->inv[cnt].usIteminv[cnt].usItem].szItemName : L"???" ); + DebugBreak(); + AssertMsg( 0, "pObject corrupted! GetHelpTextForItem() can crash." ); + } +#endif GetHelpTextForItem( pStr, &( pSoldier->inv[ cnt ] ), pSoldier ); @@ -2227,14 +2227,16 @@ void addFaceGearToPocketPopup( SOLDIERTYPE *pSoldier, INT16 sPocket, POPUP* popu } -void addAmmoToPocketPopup( SOLDIERTYPE *pSoldier, INT16 sPocket, POPUP* popup ){ - +void addAmmoToPocketPopup( SOLDIERTYPE *pSoldier, INT16 sPocket, POPUP* popup ) +{ // get the guns on current soldier std::vector * guns = getSoldierGuns(pSoldier); if( guns != NULL && guns->size() > 0) { INT16 lbePocket = pocketTypeInSlot(pSoldier, sPocket); + + UINT32 poolsize = pInventoryPoolList.size( ); for(std::vector::iterator gun=guns->begin(); gun != guns->end(); ++gun) { @@ -2245,16 +2247,16 @@ void addAmmoToPocketPopup( SOLDIERTYPE *pSoldier, INT16 sPocket, POPUP* popup ){ //o->color_background = COLOR_LTGREY; //find the ammo item we want to try and create - for(UINT32 loop = 0; loop < MAXITEMS; loop++) + for ( UINT32 loop = 0; loop < gMAXITEMS_READ; ++loop ) { - if(Item[loop].usItemClass == IC_AMMO) + if(Item[loop].usItemClass & IC_AMMO) { if( Magazine[Item[loop].ubClassIndex].ubCalibre == Weapon[ (*gun)->usItem ].ubCalibre && Magazine[Item[loop].ubClassIndex].ubMagSize == GetMagSize((*gun)) && ( lbePocket == -1 || LBEPocketType[lbePocket].ItemCapacityPerSize[ Item[loop].ItemSize ] > 0 ) ) - { // found ammo for gun, look for its ammo crate in sector. - - for(UINT16 i = 0; i < pInventoryPoolList.size(); i++) + { + // found ammo for gun, look for its ammo crate in sector. + for ( UINT16 i = 0; i < poolsize; ++i ) { // TODO: index ammo crates in sector, don't loop over entire inventory for each mag/gun if( Item[ pInventoryPoolList[i].object.usItem ].usItemClass == IC_AMMO // really looking at ammo? Class indexes also exist for other item classes! @@ -2265,10 +2267,11 @@ void addAmmoToPocketPopup( SOLDIERTYPE *pSoldier, INT16 sPocket, POPUP* popup ){ == Magazine[ Item[loop].ubClassIndex ].ubCalibre // as the mag we found? ) { - ammoFound++; + ++ammoFound; UINT8 capacity = 0; - if( lbePocket != -1 ){ + if( lbePocket != -1 ) + { UINT16 ammoLeft = pInventoryPoolList[i].object.objectStack.begin()->data.ubShotsLeft; UINT16 magSize = Magazine[ Item[loop].ubClassIndex ].ubMagSize; @@ -2276,9 +2279,12 @@ void addAmmoToPocketPopup( SOLDIERTYPE *pSoldier, INT16 sPocket, POPUP* popup ){ capacity = min( maxPerPocket, UINT8(ammoLeft/magSize) ); } - else if( CanItemFitInPosition(pSoldier, &pInventoryPoolList[i].object, sPocket, FALSE) ){ + else if( CanItemFitInPosition(pSoldier, &pInventoryPoolList[i].object, sPocket, FALSE) ) + { capacity = 1; - } else { + } + else + { continue; } @@ -2307,7 +2313,6 @@ void addAmmoToPocketPopup( SOLDIERTYPE *pSoldier, INT16 sPocket, POPUP* popup ){ POPUP_OPTION * o = popup->addOption( &std::wstring( gszPocketPopupText[POCKET_POPUP_NO_GUNS] ), NULL ); o->color_shade = COLOR_RED; } - } POPUP * createPopupForPocket( SOLDIERTYPE *pSoldier, INT16 sPocket ){ @@ -2505,8 +2510,10 @@ void INVRenderINVPanelItem( SOLDIERTYPE *pSoldier, INT16 sPocket, UINT8 fDirtyLe // CHRISL: Only run if we're looking at a legitimate pocket if((UsingNewInventorySystem() == false) && !oldInv[sPocket]) return; + if((pSoldier->flags.uiStatusFlags & SOLDIER_VEHICLE) && UsingNewInventorySystem() == true && !vehicleInv[sPocket]) return; + INT16 sX, sY, newX, newY; INT16 sBarX, sBarY; OBJECTTYPE *pObject; @@ -2516,7 +2523,6 @@ void INVRenderINVPanelItem( SOLDIERTYPE *pSoldier, INT16 sPocket, UINT8 fDirtyLe BOOLEAN fHatchItOut = FALSE; UINT32 iClass; - //Assign the screen guiCurrentItemDescriptionScreen = guiCurrentScreen; @@ -2525,7 +2531,7 @@ void INVRenderINVPanelItem( SOLDIERTYPE *pSoldier, INT16 sPocket, UINT8 fDirtyLe sX = gSMInvData[ sPocket ].sX; sY = gSMInvData[ sPocket ].sY; - if((UsingNewInventorySystem() == true) && !(pSoldier->flags.uiStatusFlags & SOLDIER_VEHICLE)) + if ( UsingNewInventorySystem() && !(pSoldier->flags.uiStatusFlags & SOLDIER_VEHICLE)) { // If sPocket is not an equiped pocket, gather pocket information if(icClass[sPocket] != ITEM_NOT_FOUND) @@ -2536,29 +2542,35 @@ void INVRenderINVPanelItem( SOLDIERTYPE *pSoldier, INT16 sPocket, UINT8 fDirtyLe case VEST_PACK: case COMBAT_PACK: case BACKPACK: - - if(pSoldier->inv[icLBE[sPocket]].exists() == false){ - lbePocket = LoadBearingEquipment[Item[icDefault[sPocket]].ubClassIndex].lbePocketIndex[icPocket[sPocket]]; - }else{ - lbePocket = LoadBearingEquipment[Item[pSoldier->inv[icLBE[sPocket]].usItem].ubClassIndex].lbePocketIndex[icPocket[sPocket]]; - if( lbePocket == 0 && LoadBearingEquipment[Item[pSoldier->inv[icLBE[sPocket]].usItem].ubClassIndex].lbePocketsAvailable & (UINT16)pow((double)2, icPocket[sPocket])){ - lbePocket = GetPocketFromAttachment(&pSoldier->inv[icLBE[sPocket]], icPocket[sPocket]); - } - } - iClass = Item[pSoldier->inv[sPocket].usItem].usItemClass; - if(icLBE[sPocket] == BPACKPOCKPOS && !(pSoldier->flags.ZipperFlag) && (gTacticalStatus.uiFlags & INCOMBAT)) + + if ( icLBE[sPocket] == BPACKPOCKPOS && !(pSoldier->flags.ZipperFlag) && (gTacticalStatus.uiFlags & INCOMBAT) ) lbePocket = 0; + else if( !pSoldier->inv[icLBE[sPocket]].exists() ) + { + lbePocket = LoadBearingEquipment[Item[icDefault[sPocket]].ubClassIndex].lbePocketIndex[icPocket[sPocket]]; + } + else + { + lbePocket = LoadBearingEquipment[Item[pSoldier->inv[icLBE[sPocket]].usItem].ubClassIndex].lbePocketIndex[icPocket[sPocket]]; + if( lbePocket == 0 && LoadBearingEquipment[Item[pSoldier->inv[icLBE[sPocket]].usItem].ubClassIndex].lbePocketsAvailable & (UINT16)pow((double)2, icPocket[sPocket])) + { + lbePocket = GetPocketFromAttachment(&pSoldier->inv[icLBE[sPocket]], icPocket[sPocket]); + } + } + + iClass = Item[pSoldier->inv[sPocket].usItem].usItemClass; + if (lbePocket == 0) // Deactivate Pocket { fHatchItOut = TRUE; } - else if ( pObject->exists() == false ) // Nothing in sPocket. Display silouhette. + else if ( !pObject->exists() ) // Nothing in sPocket. Display silouhette. { INVRenderSilhouette( guiSAVEBUFFER, lbePocket, 0, sX, sY, gSMInvData[ sPocket ].sWidth, gSMInvData[ sPocket ].sHeight); } break; case LBE_POCKET: - if ( pObject->exists() == false ) + if ( !pObject->exists() ) { if ( sPocket == VESTPOCKPOS ) lbePocket = 0; @@ -2574,14 +2586,13 @@ void INVRenderINVPanelItem( SOLDIERTYPE *pSoldier, INT16 sPocket, UINT8 fDirtyLe INVRenderSilhouette( guiSAVEBUFFER, ITEM_NOT_FOUND, lbePocket, sX, sY, gSMInvData[ sPocket ].sWidth, gSMInvData[ sPocket ].sHeight); } // Removed backpack/gunsling restrictions - if ( CheckActivationStatus(pSoldier, CPACKPOCKPOS, BPACKPOCKPOS, sPocket)/* || - (sPocket == BPACKPOCKPOS && pSoldier->inv[GUNSLINGPOCKPOS].exists() == true)*/) + if ( CheckActivationStatus(pSoldier, CPACKPOCKPOS, BPACKPOCKPOS, sPocket) ) { fHatchItOut = TRUE; } break; case OTHER_POCKET: - if ( pObject->exists() == false ) + if ( !pObject->exists() ) { if ( sPocket == GUNSLINGPOCKPOS ) // Gun Sling lbePocket = 1; @@ -2591,10 +2602,10 @@ void INVRenderINVPanelItem( SOLDIERTYPE *pSoldier, INT16 sPocket, UINT8 fDirtyLe } break; default: - if ( pObject->exists() == false ) + /*if ( pObject->exists() == false ) { // Display appropriate silouhette - } + }*/ break; } } @@ -2642,21 +2653,20 @@ void INVRenderINVPanelItem( SOLDIERTYPE *pSoldier, INT16 sPocket, UINT8 fDirtyLe } // IF it's the second hand and this hand cannot contain anything, remove the second hand position graphic -// if (sPocket == SECONDHANDPOS && Item[pSoldier->inv[HANDPOS].usItem].fFlags & ITEM_TWO_HANDED) if (sPocket == SECONDHANDPOS && Item[pSoldier->inv[HANDPOS].usItem].twohanded ) { // CHRISL: Change coords for STI that covers 2nd hand location when carrying a 2handed weapon if( guiCurrentItemDescriptionScreen != MAP_SCREEN ) { - newX = ((UsingNewInventorySystem() == false)) ? (xResOffset + 217) : ((SCREEN_WIDTH - xResSize)/2 + 114); - newY = ((UsingNewInventorySystem() == false)) ? sY : (sY - 1); + newX = !UsingNewInventorySystem() ? (xResOffset + 217) : ((SCREEN_WIDTH - xResSize)/2 + 114); + newY = !UsingNewInventorySystem() ? sY : (sY - 1); BltVideoObjectFromIndex( guiSAVEBUFFER, guiSecItemHiddenVO, UsingNewInventorySystem(), newX, newY, VO_BLT_SRCTRANSPARENCY, NULL ); RestoreExternBackgroundRect( newX, newY, 72, 28 ); } else { - newX = ((UsingNewInventorySystem() == false)) ? (14 + xResOffset) : (6 + xResOffset); - newY = ((UsingNewInventorySystem() == false)) ? (218 + yResOffset) : (217 + yResOffset); + newX = !UsingNewInventorySystem( ) ? (14 + xResOffset) : (6 + xResOffset); + newY = !UsingNewInventorySystem( ) ? (218 + yResOffset) : (217 + yResOffset); BltVideoObjectFromIndex( guiSAVEBUFFER, guiMapInvSecondHandBlockout, UsingNewInventorySystem(), newX, newY, VO_BLT_SRCTRANSPARENCY, NULL ); RestoreExternBackgroundRect( newX, newY, 102, 24 ); } @@ -2675,43 +2685,55 @@ void INVRenderINVPanelItem( SOLDIERTYPE *pSoldier, INT16 sPocket, UINT8 fDirtyLe } //Now render as normal - //INVRenderItem( guiSAVEBUFFER, pObject, (INT16)(sX + gSMInvData[ sPocket ].sSubX), (INT16)(sY + gSMInvData[ sPocket ].sSubY), gSMInvData[ sPocket ].sWidth, gSMInvData[ sPocket ].sHeight, fDirtyLevel, &(gfSM_HandInvDispText[ sPocket ] ) ); INVRenderItem( guiSAVEBUFFER, pSoldier, pObject, sX, sY, gSMInvData[ sPocket ].sWidth, gSMInvData[ sPocket ].sHeight, fRenderDirtyLevel, NULL, 0, fOutline, sOutlineColor ); + + // Flugente: decide whether we want to draw a hatch on the object. The old code was inefficient, as we did a number of costly checks and later decided differently regardless + // We thus change the order of the statements - // CHRISL: Display pocket capacity if we're holding something in the cursor - if (!gfSMDisableForItems && (UsingNewInventorySystem() == true) && gpItemPointer != NULL) + //if we are in the shop keeper interface + if ( (guiTacticalInterfaceFlags & INTERFACE_SHOPKEEP_INTERFACE) && !gbInvalidPlacementSlot[sPocket] && ShouldSoldierDisplayHatchOnItem( pSoldier->ubProfile, sPocket ) ) { - UINT8 itemSlotLimit = ItemSlotLimit(gpItemPointer, sPocket, pSoldier); - RenderPocketItemCapacity( guiSAVEBUFFER, itemSlotLimit, sPocket, pSoldier, &pSoldier->inv[sPocket], sX, sY ); - if(itemSlotLimit == 0 && !CanItemFitInPosition(pSoldier, gpItemPointer, (INT8)sPocket, FALSE)) { - fHatchItOut = TRUE; - } + fHatchItOut = TRUE; } - - // CHRISL: Change whether we hatch a pocket to be dependant on the current item - if(gpItemPointer != NULL) + // CHRISL: Don't hatch second hand position if we're holding a two handed item + else if ( sPocket == SECONDHANDPOS && Item[pSoldier->inv[HANDPOS].usItem].twohanded ) { - if(!gfSMDisableForItems && !CanItemFitInPosition(pSoldier, gpItemPointer, (INT8)sPocket, FALSE)){ - if((UsingNewAttachmentSystem()==false && !ValidAttachment(gpItemPointer->usItem, pObject )) || - (UsingNewAttachmentSystem()==true && !ValidItemAttachmentSlot(pObject, gpItemPointer->usItem, FALSE, FALSE))){ + fHatchItOut = FALSE; + } + else if ( !gfSMDisableForItems ) + { + if ( gpItemPointer != NULL && !CanItemFitInPosition( pSoldier, gpItemPointer, (INT8)sPocket, FALSE ) ) + { + // CHRISL: Display pocket capacity if we're holding something in the cursor + if ( UsingNewInventorySystem( ) ) + { + UINT8 itemSlotLimit = ItemSlotLimit( gpItemPointer, sPocket, pSoldier ); + RenderPocketItemCapacity( guiSAVEBUFFER, itemSlotLimit, sPocket, pSoldier, &pSoldier->inv[sPocket], sX, sY ); + + if ( itemSlotLimit == 0 ) + { + fHatchItOut = TRUE; + } + } + + // CHRISL: Change whether we hatch a pocket to be dependant on the current item + if ( (!UsingNewAttachmentSystem( ) && !ValidAttachment( gpItemPointer->usItem, pObject )) || + (UsingNewAttachmentSystem( ) && !ValidItemAttachmentSlot( pObject, gpItemPointer->usItem, FALSE, FALSE )) ) + { fHatchItOut = TRUE; } - else{ + else + { fHatchItOut = FALSE; } } + else if ( pObject->exists( ) ) + { + if ( !CanItemFitInPosition( pSoldier, pObject, (INT8)sPocket, FALSE ) ) + fHatchItOut = TRUE; + } } - else if(pObject->exists() == true) - { - if(!gfSMDisableForItems && !CanItemFitInPosition(pSoldier, pObject, (INT8)sPocket, FALSE)) - fHatchItOut = TRUE; - } - // CHRISL: Don't hatch second hand position if we're holding a two handed item - if(sPocket == SECONDHANDPOS) - { - if(Item[pSoldier->inv[HANDPOS].usItem].twohanded) - fHatchItOut = FALSE; - } + #if 0 if ( gbInvalidPlacementSlot[ sPocket ] ) { @@ -2726,15 +2748,6 @@ void INVRenderINVPanelItem( SOLDIERTYPE *pSoldier, INT16 sPocket, UINT8 fDirtyLe } #endif - //if we are in the shop keeper interface - if( guiTacticalInterfaceFlags & INTERFACE_SHOPKEEP_INTERFACE ) - { - if( ShouldSoldierDisplayHatchOnItem( pSoldier->ubProfile, sPocket ) && !gbInvalidPlacementSlot[ sPocket ] ) - { - fHatchItOut = TRUE; - } - } - if ( fHatchItOut ) { UINT32 uiWhichBuffer = ( guiCurrentItemDescriptionScreen == MAP_SCREEN ) ? guiSAVEBUFFER : guiRENDERBUFFER; @@ -2742,14 +2755,13 @@ void INVRenderINVPanelItem( SOLDIERTYPE *pSoldier, INT16 sPocket, UINT8 fDirtyLe } // if there's an item in there - if ( pObject->exists() == true ) + if ( pObject->exists() ) { // Add item status bar sBarX = sX - gSMInvData[ sPocket ].sBarDx; sBarY = sY + gSMInvData[ sPocket ].sBarDy; DrawItemUIBarEx( pObject, 0, sBarX, sBarY, ITEM_BAR_WIDTH, ITEM_BAR_HEIGHT, Get16BPPColor( STATUS_BAR ), Get16BPPColor( STATUS_BAR_SHADOW ), TRUE , guiSAVEBUFFER); } - } @@ -2783,11 +2795,11 @@ BOOLEAN CompatibleItemForApplyingOnMerc( OBJECTTYPE *pTestObject ) { UINT16 usItem = pTestObject->usItem; - // ATE: If in mapscreen, return false always.... + // ATE: If in mapscreen, return false always.... if( guiTacticalInterfaceFlags & INTERFACE_MAPSCREEN ) - { - return( FALSE ); - } + { + return( FALSE ); + } // ATE: Would be nice to have flag here to check for these types.... if ( Item[usItem].camouflagekit || usItem == ADRENALINE_BOOSTER || usItem == REGEN_BOOSTER || @@ -2796,10 +2808,8 @@ BOOLEAN CompatibleItemForApplyingOnMerc( OBJECTTYPE *pTestObject ) { return( TRUE ); } - else - { - return( FALSE ); - } + + return( FALSE ); } @@ -2852,7 +2862,7 @@ void HandleAnyMercInSquadHasCompatibleStuff( UINT8 ubSquad, OBJECTTYPE *pObject, return; } - for( iCounter = 0; iCounter < NUMBER_OF_SOLDIERS_PER_SQUAD; iCounter++ ) + for( iCounter = 0; iCounter < NUMBER_OF_SOLDIERS_PER_SQUAD; ++iCounter ) { if( Squad[ iCurrentTacticalSquad ][ iCounter ] != NULL ) { @@ -2870,7 +2880,6 @@ void HandleAnyMercInSquadHasCompatibleStuff( UINT8 ubSquad, OBJECTTYPE *pObject, } } } - } BOOLEAN IsMutuallyValidAttachmentOrLaunchable(UINT16 usAttItem, UINT16 usItem)//dnl ch76 091113 @@ -2880,7 +2889,7 @@ BOOLEAN IsMutuallyValidAttachmentOrLaunchable(UINT16 usAttItem, UINT16 usItem)// { if(Attachment[uiLoop][0] == usAttItem && Attachment[uiLoop][1] == usItem || Attachment[uiLoop][0] == usItem && Attachment[uiLoop][1] == usAttItem || Launchable[uiLoop][0] == usAttItem && Launchable[uiLoop][1] == usItem || Launchable[uiLoop][0] == usItem && Launchable[uiLoop][1] == usAttItem) return(TRUE); - uiLoop++; + ++uiLoop; } return(FALSE); } @@ -2926,11 +2935,9 @@ BOOLEAN HandleCompatibleAmmoUIForMapScreen( SOLDIERTYPE *pSoldier, INT32 bInvPos // IT's an OK calibere ammo, do something! // Render Item with specific color gbCompatibleAmmo[ cnt ] = fOn; - } } - if ( gpItemPointer != NULL ) { if ( CompatibleItemForApplyingOnMerc( gpItemPointer ) ) @@ -3002,7 +3009,6 @@ BOOLEAN HandleCompatibleAmmoUIForMapScreen( SOLDIERTYPE *pSoldier, INT32 bInvPos } } - if ( ( Item [ pTestObject->usItem ].usItemClass & IC_GUN ) ) { UINT32 invsize = pSoldier->inv.size(); @@ -3044,8 +3050,7 @@ BOOLEAN HandleCompatibleAmmoUIForMapScreen( SOLDIERTYPE *pSoldier, INT32 bInvPos } } } - - + return( fFound ); } @@ -3075,7 +3080,7 @@ BOOLEAN HandleCompatibleAmmoUIForMapInventory( SOLDIERTYPE *pSoldier, INT32 bInv } // First test attachments, which almost any type of item can have.... - for ( cnt = 0; cnt < MAP_INVENTORY_POOL_SLOT_COUNT; cnt++ ) + for ( cnt = 0; cnt < MAP_INVENTORY_POOL_SLOT_COUNT; ++cnt ) { pObject = &( pInventoryPoolList[ iStartSlotNumber + cnt ].object ); @@ -3110,7 +3115,7 @@ BOOLEAN HandleCompatibleAmmoUIForMapInventory( SOLDIERTYPE *pSoldier, INT32 bInv if( ( Item [ pTestObject->usItem ].usItemClass & IC_GUN ) ) { - for ( cnt = 0; cnt < MAP_INVENTORY_POOL_SLOT_COUNT; cnt++ ) + for ( cnt = 0; cnt < MAP_INVENTORY_POOL_SLOT_COUNT; ++cnt ) { pObject = &( pInventoryPoolList[ iStartSlotNumber + cnt ].object ); @@ -3129,7 +3134,7 @@ BOOLEAN HandleCompatibleAmmoUIForMapInventory( SOLDIERTYPE *pSoldier, INT32 bInv } else if( ( Item [ pTestObject->usItem ].usItemClass & IC_AMMO ) ) { - for ( cnt = 0; cnt < MAP_INVENTORY_POOL_SLOT_COUNT; cnt++ ) + for ( cnt = 0; cnt < MAP_INVENTORY_POOL_SLOT_COUNT; ++cnt ) { pObject = &( pInventoryPoolList[ iStartSlotNumber + cnt ].object ); @@ -3143,22 +3148,20 @@ BOOLEAN HandleCompatibleAmmoUIForMapInventory( SOLDIERTYPE *pSoldier, INT32 bInv // IT's an OK calibere ammo, do something! // Render Item with specific color fMapInventoryItemCompatable[ cnt ] = fOn; - } } } - return( fFound ); } BOOLEAN InternalHandleCompatibleAmmoUI( SOLDIERTYPE *pSoldier, OBJECTTYPE *pTestObject, BOOLEAN fOn ) { - BOOLEAN fFound = FALSE; - UINT32 cnt; + BOOLEAN fFound = FALSE; + UINT32 cnt; OBJECTTYPE *pObject; - BOOLEAN fFoundAttachment = FALSE; + BOOLEAN fFoundAttachment = FALSE; //Moa 09/26/2013: this is a hack to avoid frequent recalc and rerender of screen when mouse is over an item, its less work and less error prone then rewriting several functions (various mousecallbacks, >4 renderfunctions and probalby some others too) static OBJECTTYPE* previousObject = NULL; @@ -3198,11 +3201,9 @@ BOOLEAN InternalHandleCompatibleAmmoUI( SOLDIERTYPE *pSoldier, OBJECTTYPE *pTest // IT's an OK calibere ammo, do something! // Render Item with specific color gbCompatibleAmmo[ cnt ] = fOn; - } } - if ( gpItemPointer != NULL ) { if ( CompatibleItemForApplyingOnMerc( gpItemPointer ) ) @@ -3272,7 +3273,6 @@ BOOLEAN InternalHandleCompatibleAmmoUI( SOLDIERTYPE *pSoldier, OBJECTTYPE *pTest //{ if( ( Item [ pTestObject->usItem ].usItemClass & IC_GUN ) ) { - UINT32 invsize = pSoldier->inv.size(); for ( cnt = 0; cnt < invsize; ++cnt ) { pObject = &(pSoldier->inv[ cnt ]); @@ -3290,10 +3290,8 @@ BOOLEAN InternalHandleCompatibleAmmoUI( SOLDIERTYPE *pSoldier, OBJECTTYPE *pTest } } } - else if( ( Item [ pTestObject->usItem ].usItemClass & IC_AMMO ) ) { - UINT32 invsize = pSoldier->inv.size(); for ( cnt = 0; cnt < invsize; ++cnt ) { pObject = &(pSoldier->inv[ cnt ]); @@ -3312,10 +3310,10 @@ BOOLEAN InternalHandleCompatibleAmmoUI( SOLDIERTYPE *pSoldier, OBJECTTYPE *pTest } } } - else if ( CompatibleItemForApplyingOnMerc( pTestObject ) ) + //If we are currently NOT in the Shopkeeper interface + else if ( !(guiTacticalInterfaceFlags & INTERFACE_SHOPKEEP_INTERFACE) ) { - //If we are currently NOT in the Shopkeeper interface - if( !( guiTacticalInterfaceFlags & INTERFACE_SHOPKEEP_INTERFACE ) ) + if ( CompatibleItemForApplyingOnMerc( pTestObject ) ) { fFound = TRUE; gbCompatibleApplyItem = fOn; @@ -3326,7 +3324,7 @@ BOOLEAN InternalHandleCompatibleAmmoUI( SOLDIERTYPE *pSoldier, OBJECTTYPE *pTest if ( !fFound ) { - for ( cnt = 0; cnt < NUM_INV_SLOTS; cnt++ ) + for ( cnt = 0; cnt < NUM_INV_SLOTS; ++cnt ) { if ( gbCompatibleAmmo[ cnt ] ) { @@ -3354,9 +3352,7 @@ BOOLEAN InternalHandleCompatibleAmmoUI( SOLDIERTYPE *pSoldier, OBJECTTYPE *pTest void ResetCompatibleItemArray( ) { - INT32 cnt = 0; - - for ( cnt = 0; cnt < NUM_INV_SLOTS; cnt++ ) + for ( INT32 cnt = 0; cnt < NUM_INV_SLOTS; ++cnt ) { if ( gbCompatibleAmmo[ cnt ] ) { @@ -3392,7 +3388,7 @@ BOOLEAN HandleCompatibleAmmoUI( SOLDIERTYPE *pSoldier, INT8 bInvPos, BOOLEAN fOn { gpHighLightedItemObject = NULL; - for ( cnt = 0; cnt < NUM_INV_SLOTS; cnt++ ) + for ( cnt = 0; cnt < NUM_INV_SLOTS; ++cnt ) { if ( gbCompatibleAmmo[ cnt ] ) { @@ -3432,11 +3428,9 @@ BOOLEAN HandleCompatibleAmmoUI( SOLDIERTYPE *pSoldier, INT8 bInvPos, BOOLEAN fOn { pTestObject = &(pSoldier->inv[ bInvPos ]); } - } return( InternalHandleCompatibleAmmoUI( pSoldier, pTestObject, fOn ) ); - } void GetSlotInvXY( UINT8 ubPos, INT16 *psX, INT16 *psY ) @@ -3471,23 +3465,20 @@ void HandleNewlyAddedItems( SOLDIERTYPE *pSoldier, BOOLEAN *fDirtyLevel ) *fDirtyLevel = DIRTYLEVEL2; pSoldier->inv.bNewItemCount[ cnt ] = 0; } - - if ( pSoldier->inv.bNewItemCount[ cnt ] > 0 ) + else if ( pSoldier->inv.bNewItemCount[ cnt ] > 0 ) { - sX = gSMInvData[ cnt ].sX; sY = gSMInvData[ cnt ].sY; pObject = &(pSoldier->inv[ cnt ]); - if ( pObject->exists() == false ) + if ( !pObject->exists() ) { gbNewItem[ cnt ] = 0; continue; } INVRenderItem( guiSAVEBUFFER, pSoldier, pObject, sX, sY, gSMInvData[ cnt ].sWidth, gSMInvData[ cnt ].sHeight, DIRTYLEVEL2, NULL, 0, TRUE, us16BPPItemCyclePlacedItemColors[ pSoldier->inv.bNewItemCycleCount[ cnt ] ] ); - } } } @@ -3561,11 +3552,10 @@ void InitItemInterface( ) { UINT32 cnt, cnt2; - for ( cnt = 0, cnt2 = 0; cnt2 < 20; cnt+=3, cnt2++ ) + for ( cnt = 0, cnt2 = 0; cnt2 < 20; cnt+=3, ++cnt2 ) { us16BPPItemCyclePlacedItemColors[ cnt2 ] = Get16BPPColor( FROMRGB( ubRGBItemCyclePlacedItemColors[ cnt ], ubRGBItemCyclePlacedItemColors[ cnt + 1 ], ubRGBItemCyclePlacedItemColors[ cnt + 2] ) ); } - } // CHRISL: Function to display pocket inventory quantity based on object in cursor @@ -3574,8 +3564,9 @@ void RenderPocketItemCapacity( UINT32 uiWhichBuffer, INT8 pCapacity, INT16 bPos, static CHAR16 pStr[ 100 ]; // Can pocket hold the item in the cursor? - if(InItemDescriptionBox( )) + if( InItemDescriptionBox( ) ) return; + if(pSoldier != NULL && !CanItemFitInPosition( pSoldier, gpItemPointer, (INT8)bPos, FALSE )) { // Further check to see if the cursor item is valid ammo or a valid attachment @@ -3622,10 +3613,11 @@ void RenderPocketItemCapacity( UINT32 uiWhichBuffer, INT8 pCapacity, INT16 bPos, { RestoreExternBackgroundRect( sX, sY, 15, 15 ); } + mprintf( sX, sY, pStr ); gprintfinvalidate( sX, sY, pStr ); - return; } + // CHRISL: New function to render silhouettes void INVRenderSilhouette( UINT32 uiBuffer, INT16 PocketIndex, INT16 SilIndex, INT16 sX, INT16 sY, INT16 sWidth, INT16 sHeight) { @@ -3636,8 +3628,10 @@ void INVRenderSilhouette( UINT32 uiBuffer, INT16 PocketIndex, INT16 SilIndex, IN if(gfSMDisableForItems) return; + SetFont( ITEM_FONT ); GetVideoObject( &hVObject, guiSILHOUETTE ); + if ( PocketIndex != ITEM_NOT_FOUND ) SilIndex = LBEPocketType[PocketIndex].pSilhouette; @@ -3663,7 +3657,7 @@ void INVRenderSilhouette( UINT32 uiBuffer, INT16 PocketIndex, INT16 SilIndex, IN } } -// Flugente FTW 1: Function to get the number of the item condition string +// Flugente: Function to get the number of the item condition string UINT8 GetTemperatureString( FLOAT overheatpercentage, UINT32* apRed, UINT32* apGreen, UINT32* abBlue ) { *apRed = (UINT32) ( gGameExternalOptions.ubOverheatThermometerRedOffset + (255 - gGameExternalOptions.ubOverheatThermometerRedOffset) * ( (max(1.0, overheatpercentage) - 1.0)/(max(1.0, overheatpercentage)) ) ); @@ -3695,7 +3689,7 @@ void INVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pObjec { UINT16 uiStringLength; INVTYPE *pItem; - ETRLEObject *pTrav; + ETRLEObject *pTrav; UINT32 usHeight, usWidth; INT16 sCenX, sCenY, sNewY, sNewX; HVOBJECT hVObject; @@ -3705,7 +3699,7 @@ void INVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pObjec static CHAR16 pStr[ 100 ], pStr2[ 100 ]; - if ( pObject->exists() == false ) + if ( !pObject->exists() ) { return; } @@ -3728,19 +3722,17 @@ void INVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pObjec usHeight = (UINT32)pTrav->usHeight; usWidth = (UINT32)pTrav->usWidth; - - // CENTER IN SLOT! // CANCEL OFFSETS! sCenX = sX + (INT16)( abs( sWidth - (double)usWidth ) / 2 ) - pTrav->sOffsetX; sCenY = sY + (INT16)( abs( sHeight - (double)usHeight ) / 2 ) - pTrav->sOffsetY; // Shadow area - if(gGameSettings.fOptions[ TOPTION_SHOW_ITEM_SHADOW ]) BltVideoObjectOutlineShadowFromIndex( uiBuffer, GetInterfaceGraphicForItem( pItem ), usGraphicNum, sCenX - 2, sCenY + 2 ); + if(gGameSettings.fOptions[ TOPTION_SHOW_ITEM_SHADOW ]) + BltVideoObjectOutlineShadowFromIndex( uiBuffer, GetInterfaceGraphicForItem( pItem ), usGraphicNum, sCenX - 2, sCenY + 2 ); BltVideoObjectOutlineFromIndex( uiBuffer, GetInterfaceGraphicForItem( pItem ), usGraphicNum, sCenX, sCenY, sOutlineColor, fOutline ); - if ( uiBuffer == FRAME_BUFFER ) { InvalidateRegion( sX, sY, (INT16)(sX + sWidth), (INT16)(sY + sHeight ) ); @@ -3749,6 +3741,7 @@ void INVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pObjec { RestoreExternBackgroundRect( sX, sY, sWidth, sHeight ); } + //Moa: set encyclopedia item visibility EncyclopediaSetItemAsVisible( pItem->uiIndex, ENC_ITEM_DISCOVERED ); } @@ -3757,10 +3750,8 @@ void INVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pObjec if ( fDirtyLevel != DIRTYLEVEL0 ) { - if ( ubStatusIndex < RENDER_ITEM_ATTACHMENT1 ) { - SetFontBackground( FONT_MCOLOR_BLACK ); SetFontForeground( FONT_MCOLOR_DKGRAY ); #if 1 @@ -3787,7 +3778,6 @@ void INVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pObjec mprintf( sNewX, sNewY, pStr ); gprintfinvalidate( sNewX, sNewY, pStr ); } - } #endif @@ -3951,8 +3941,8 @@ void INVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pObjec gprintfinvalidate( sNewX, sNewY, pStr ); } - // Flugente - if ( gGameExternalOptions.fWeaponOverheating && gGameExternalOptions.fDisplayOverheatThermometer && ( pItem->usItemClass & (IC_GUN | IC_LAUNCHER) || Item[pObject->usItem].barrel == TRUE ) ) + // Flugente: overheating + if ( gGameExternalOptions.fWeaponOverheating && gGameExternalOptions.fDisplayOverheatThermometer && ( pItem->usItemClass & (IC_GUN | IC_LAUNCHER) || Item[pObject->usItem].barrel ) ) { OBJECTTYPE* pObjShown = pObject; @@ -3969,10 +3959,11 @@ void INVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pObjec DrawItemUIBarEx( pObjShown, DRAW_ITEM_TEMPERATURE, sX, sY + sHeight-1, ITEMDESC_ITEM_STATUS_WIDTH, sHeight-1, colour, colour, TRUE, guiSAVEBUFFER ); } - // Flugente: display condition of food if it can decay - if ( gGameOptions.fFoodSystem == TRUE && Item[pObject->usItem].foodtype > 0 ) + // Flugente: heat displays + if ( OVERHEATING_MAX_TEMPERATURE > 0 ) { - if ( OVERHEATING_MAX_TEMPERATURE > 0 ) + // Flugente: display condition of food if it can decay + if ( gGameOptions.fFoodSystem && Item[pObject->usItem].foodtype > 0 ) { FLOAT condition = (*pObject)[0]->data.bTemperature / OVERHEATING_MAX_TEMPERATURE; @@ -3984,12 +3975,8 @@ void INVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pObjec DrawItemUIBarEx( pObject, DRAW_ITEM_TEMPERATURE, sX, sY + sHeight-1, ITEMDESC_ITEM_STATUS_WIDTH, (INT16)((sHeight-1)*(1-condition)), colour, colour, TRUE, guiSAVEBUFFER); } - } - - // Flugente: display energy level of power packs - if ( HasItemFlag(pObject->usItem, POWER_PACK) ) - { - if ( OVERHEATING_MAX_TEMPERATURE > 0 ) + // Flugente: display energy level of power packs + else if ( HasItemFlag(pObject->usItem, POWER_PACK) ) { FLOAT energylevel = (*pObject)[0]->data.bTemperature / (FLOAT)OVERHEATING_MAX_TEMPERATURE; @@ -4033,7 +4020,7 @@ void INVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pObjec // added by Flugente // HEADROCK HAM 4: Advanced Icons - if (guiItemInfoAdvancedIcon == 0) + if ( !guiItemInfoAdvancedIcon ) { // added by Flugente // HEADROCK HAM 4: Advanced Icons @@ -4119,7 +4106,7 @@ void INVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pObjec } } - if((UsingNewInventorySystem() == true)) + if ( UsingNewInventorySystem() ) { // CHRISL: Display astrisk when LBENODE active if ( pObject->HasAnyActiveLBEs(pSoldier, iter) ) @@ -4144,7 +4131,7 @@ void INVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pObjec } } - if ( pSoldier && pObject == &(pSoldier->inv[HANDPOS] ) && pSoldier->bWeaponMode != WM_NORMAL && Item[pSoldier->inv[HANDPOS].usItem].usItemClass == IC_GUN ) + if ( pSoldier && pObject == &(pSoldier->inv[HANDPOS] ) && pSoldier->bWeaponMode != WM_NORMAL && Item[pSoldier->inv[HANDPOS].usItem].usItemClass & IC_GUN ) { sNewY = sY + 13; // rather arbitrary if ( pSoldier->bWeaponMode == WM_BURST ) @@ -4209,7 +4196,7 @@ void INVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pObjec // SANDRO - display BRST/AUTO on the second weapon too, if we are going to fire dual bursts if ( pSoldier && pObject == &(pSoldier->inv[SECONDHANDPOS] ) && (pSoldier->bWeaponMode == WM_BURST || pSoldier->bWeaponMode == WM_AUTOFIRE) && - Item[pSoldier->inv[HANDPOS].usItem].usItemClass == IC_GUN && + Item[pSoldier->inv[HANDPOS].usItem].usItemClass & IC_GUN && !(Item[ pSoldier->inv[HANDPOS ].usItem ].twohanded ) && pSoldier->IsValidSecondHandBurst() ) { @@ -4316,10 +4303,6 @@ void INVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pObjec } mprintf( sNewX, sNewY, pStr ); gprintfinvalidate( sNewX, sNewY, pStr ); - - //sNewX = sX + 1; - - //SetFontForeground( FONT_MCOLOR_DKGRAY ); } } } @@ -4455,7 +4438,7 @@ void MAPINVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pOb static CHAR16 pStr[ 100 ], pStr2[ 100 ]; - if ( pObject->exists() == false ) + if ( !pObject->exists() ) { return; } @@ -4527,7 +4510,7 @@ void MAPINVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pOb } //////////////////// GUN DATA ////////////////// - if ( pItem->usItemClass == IC_GUN && !Item[pObject->usItem].rocketlauncher ) + if ( pItem->usItemClass & IC_GUN && !Item[pObject->usItem].rocketlauncher ) { //////////////// AMMO REMAINING @@ -4705,7 +4688,7 @@ void MAPINVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pOb break; } - for(unsigned int cnt=0; cntinv[cnt].exists() == true) usCountLBEItems++; @@ -4721,8 +4704,8 @@ void MAPINVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pOb sNewY = sY + 4; BltVideoObject( uiBuffer , hVObject, 3, sNewX, sNewY , VO_BLT_SRCTRANSPARENCY,NULL ); - usCountLBEItems--; - for (INT16 x = 0; x < usCountLBEItems; x++) + --usCountLBEItems; + for (INT16 x = 0; x < usCountLBEItems; ++x ) { // Draw small blue asterisk pTrav = &(hVObject->pETRLEObject[ 4 ] ); @@ -4919,34 +4902,34 @@ INT16 CycleItems( INT16 usOldItem ) { if ( _KeyDown( SHIFT ) ) { - usOldItem--; + --usOldItem; if ( usOldItem < 1 ) { - usOldItem = MAXITEMS-1; + usOldItem = gMAXITEMS_READ - 1; } while ( usOldItem > 0 && ( Item[usOldItem].usItemClass == IC_NONE || Item[usOldItem].usItemClass == 0 )) { - usOldItem--; + --usOldItem; if(usOldItem < 1) - usOldItem = MAXITEMS-1; + usOldItem = gMAXITEMS_READ - 1; } } else { - usOldItem++; - if ( usOldItem > MAXITEMS ) + ++usOldItem; + if ( usOldItem > gMAXITEMS_READ ) { usOldItem = 0; } - while (usOldItem < MAXITEMS && (Item[usOldItem].usItemClass == IC_NONE || Item[usOldItem].usItemClass == 0 )) + while ( usOldItem < gMAXITEMS_READ && (Item[usOldItem].usItemClass == IC_NONE || Item[usOldItem].usItemClass == 0) ) { - usOldItem++; - if(usOldItem >= MAXITEMS) + ++usOldItem; + if ( usOldItem >= gMAXITEMS_READ ) usOldItem = 1; } } - if ( usOldItem > MAXITEMS ) + if ( usOldItem > gMAXITEMS_READ ) { usOldItem = 0; } @@ -5623,7 +5606,8 @@ void UpdateAttachmentTooltips(OBJECTTYPE *pObject, UINT8 ubStatusIndex) //dnl ch76 081113 std::vector attachedList; - for(UINT8 x=0; x<(*pObject)[ubStatusIndex]->attachments.size(); x++)// attached item list rather create here then inside loop to gain performance + UINT8 size = (*pObject)[ubStatusIndex]->attachments.size( ); + for ( UINT8 x = 0; x < size; ++x )// attached item list rather create here then inside loop to gain performance { OBJECTTYPE* pAttachment2 = (*pObject)[ubStatusIndex]->GetAttachmentAtIndex(x); if(pAttachment2->exists()) @@ -5633,7 +5617,7 @@ void UpdateAttachmentTooltips(OBJECTTYPE *pObject, UINT8 ubStatusIndex) //start by deleting the currently defined regions if they exist //BOB : also, clean up the popup boxes (in case they're still around) // and init them to NULL in case they contain garbage - for (INT32 cnt = 0; cnt < MAX_ATTACHMENTS; cnt++ ) + for (INT32 cnt = 0; cnt < MAX_ATTACHMENTS; ++cnt ) { if( gItemDescAttachmentRegions[cnt].IDNumber != 0 ) MSYS_RemoveRegion( &gItemDescAttachmentRegions[cnt]); @@ -5646,7 +5630,7 @@ void UpdateAttachmentTooltips(OBJECTTYPE *pObject, UINT8 ubStatusIndex) gItemDescAttachmentPopupsInitialized = TRUE; //now, create new regions - for (slotCount = 0; ;++slotCount ) + for (slotCount = 0; ; ++slotCount ) { //stopping conditions, not inside the for loop because it is different depending on the attachment system. if (UsingNewAttachmentSystem()==true) { @@ -5690,8 +5674,9 @@ void UpdateAttachmentTooltips(OBJECTTYPE *pObject, UINT8 ubStatusIndex) UINT16 usLoopSlotID = usAttachmentSlotIndexVector[slotCount]; attachList.clear(); + //Print all attachments that fit on this item. - for(UINT16 usLoop = 0; usLoop < MAXATTACHMENTS; usLoop++) + for(UINT16 usLoop = 0; usLoop < MAXATTACHMENTS; ++usLoop) { //We no longer find valid attachments from AttachmentSlots.xml so we need to work a bit harder to get our list usAttachment = 0; //Madd: Common Attachment Framework @@ -5769,7 +5754,8 @@ void UpdateAttachmentTooltips(OBJECTTYPE *pObject, UINT8 ubStatusIndex) } } - if(attachList.size()>0){ + if( !attachList.empty() ) + { parseList = attachList; for(std::vector::iterator pIter=parseList.begin(); pIter != parseList.end(); ++pIter){ BOOLEAN fDuplicate = FALSE; @@ -6811,21 +6797,27 @@ void RenderItemDescriptionBox( ) // - the item is a grenade // - the item is a bomb and has a detonator or remote detonator attached BOOLEAN renderTransformIcon = FALSE; - if ( ( (guiCurrentScreen == GAME_SCREEN || guiCurrentScreen == MAP_SCREEN) && gpItemDescObject->ubNumberOfObjects == 1 ) && - ( (Item[gpItemDescObject->usItem].usItemClass == IC_GRENADE) || - ( (Item[gpItemDescObject->usItem].usItemClass == IC_BOMB) && HasAttachmentOfClass( gpItemDescObject, (AC_DETONATOR | AC_REMOTEDET)) ) ) ) + if ( ((guiCurrentScreen == GAME_SCREEN || guiCurrentScreen == MAP_SCREEN) && gpItemDescObject->ubNumberOfObjects == 1) && + ((Item[gpItemDescObject->usItem].usItemClass == IC_GRENADE) || + ((Item[gpItemDescObject->usItem].usItemClass == IC_BOMB) && HasAttachmentOfClass( gpItemDescObject, (AC_DETONATOR | AC_REMOTEDET) ))) ) + { renderTransformIcon = TRUE; - if (!renderTransformIcon) - for (UINT16 x = 0; x < MAXITEMS; x++) + } + else + { + for ( UINT16 x = 0; x < gMAXITEMS_READ; ++x ) { if (Transform[x].usItem == (UINT16)-1) break; + else if ( Transform[x].usItem == gpItemDescObject->usItem ) { renderTransformIcon = TRUE; break; } } + } + if (renderTransformIcon) BltVideoObjectFromIndex( guiSAVEBUFFER, guiTransformIconGraphic, 0, (ITEMDESC_ITEM_X+ITEMDESC_ITEM_WIDTH)-13, (ITEMDESC_ITEM_Y+ITEMDESC_ITEM_HEIGHT)-17, VO_BLT_SRCTRANSPARENCY, NULL ); } @@ -12002,16 +11994,16 @@ void GetHelpTextForItem( STR16 pzStr, OBJECTTYPE *pObject, SOLDIERTYPE *pSoldier Remove when fixed! */ # if defined( _DEBUG ) - if ( ((*pObject)[0]->data.gun.ubGunAmmoType >= MAXITEMS) ) - { - DebugMsg(TOPIC_JA2, DBG_LEVEL_1, String( "corrupted pObject (%S) found in GetHelpTextForItem()", (usItemdata.gun.ubGunAmmoType >= gMAXITEMS_READ) ) + { + DebugMsg( TOPIC_JA2, DBG_LEVEL_1, String( "corrupted pObject (%S) found in GetHelpTextForItem()", (usItemexists() == true ) + if ( pObject->exists() ) { // Retrieve the status of the items //CHRISL: If looking at an item in stack popup, show just that item @@ -12022,7 +12014,7 @@ void GetHelpTextForItem( STR16 pzStr, OBJECTTYPE *pObject, SOLDIERTYPE *pSoldier (*pObject)[0]->data.objectStatus = __min((*pObject)[0]->data.objectStatus, 100); sValue = (*pObject)[0]->data.objectStatus; - for(INT16 i = 1; i < pObject->ubNumberOfObjects; i++){ + for(INT16 i = 1; i < pObject->ubNumberOfObjects; ++i){ if(Item[pObject->usItem].usItemClass != IC_AMMO) (*pObject)[ i ]->data.objectStatus = __min((*pObject)[ i ]->data.objectStatus, 100); if((*pObject)[ i ]->data.objectStatus < sValue) @@ -13270,7 +13262,7 @@ void ItemDescTransformRegionCallback( MOUSE_REGION *pRegion, INT32 reason ) if (fShowMapInventoryPool) { // Is our object currently in the pool? - for (UINT32 x = 0; x < pInventoryPoolList.size(); x++) + for (UINT32 x = 0; x < pInventoryPoolList.size(); ++x) { if (pInventoryPoolList[x].object.exists()) { @@ -13287,7 +13279,7 @@ void ItemDescTransformRegionCallback( MOUSE_REGION *pRegion, INT32 reason ) if (fCrateInPool) { - for (UINT16 x = 0; x < MAXITEMS; x++) + for ( UINT16 x = 0; x < gMAXITEMS_READ; ++x ) { if ( Item[x].usItemClass & IC_AMMO ) { @@ -13329,7 +13321,7 @@ void ItemDescTransformRegionCallback( MOUSE_REGION *pRegion, INT32 reason ) { if ( Item[gpItemDescObject->usItem].usItemClass == IC_BOMB && HasAttachmentOfClass( gpItemDescObject, (AC_DETONATOR | AC_REMOTEDET)) ) { - iTransformIndex++; + ++iTransformIndex; UINT16 usAPCost = APBPConstants[AP_INVENTORY_ARM]; @@ -13377,7 +13369,7 @@ void ItemDescTransformRegionCallback( MOUSE_REGION *pRegion, INT32 reason ) } else if ( Item[gpItemDescObject->usItem].usItemClass == IC_GRENADE ) { - iTransformIndex++; + ++iTransformIndex; UINT16 usAPCost = APBPConstants[AP_INVENTORY_ARM]; @@ -13406,7 +13398,7 @@ void ItemDescTransformRegionCallback( MOUSE_REGION *pRegion, INT32 reason ) // onyl allow transformations if the item is not an armed bomb if ( !fHaveToDisarm ) { - for (INT32 x = 0; x < MAXITEMS; x++) + for ( INT32 x = 0; x < gMAXITEMS_READ; ++x ) { if (Transform[x].usItem == (UINT16)-1) { @@ -13414,7 +13406,7 @@ void ItemDescTransformRegionCallback( MOUSE_REGION *pRegion, INT32 reason ) } if (Transform[x].usItem == gpItemDescObject->usItem) { - iTransformIndex++; + ++iTransformIndex; CHAR16 MenuRowText[300]; if ( Transform[x].usAPCost > 0 && gTacticalStatus.uiFlags & INCOMBAT && gTacticalStatus.uiFlags & TURNBASED ) @@ -13472,7 +13464,7 @@ void ItemDescTransformRegionCallback( MOUSE_REGION *pRegion, INT32 reason ) // Now that the popup is initialized, lets set the help text for each line. Note that we have to do it here // (rather than before) because only now are the MOUSE_REGIONs ready to receive help text at all!! INT32 iNumOptions = 0; - for (INT32 x = 0; x < MAXITEMS; x++) + for ( INT32 x = 0; x < gMAXITEMS_READ; ++x ) { if (Transform[x].usItem == (UINT16)-1) { @@ -13481,10 +13473,9 @@ void ItemDescTransformRegionCallback( MOUSE_REGION *pRegion, INT32 reason ) if (Transform[x].usItem == gpItemDescObject->usItem) { SetRegionFastHelpText( &(gItemDescTransformPopup->MenuRegion[iNumOptions]), Transform[x].szTooltipText ); - iNumOptions++; + ++iNumOptions; } } - } else if (reason == MSYS_CALLBACK_REASON_RBUTTON_UP ) { @@ -14150,7 +14141,7 @@ void TransformationMenuPopup_SplitCrateInInventory( ) UINT32 uiBestRoundCapacity = 0; UINT16 usBestItem = 0; - for (UINT16 x = 0; x < MAXITEMS; x++) + for ( UINT16 x = 0; x < gMAXITEMS_READ; ++x ) { if (Item[x].usItemClass & IC_AMMO) { diff --git a/Tactical/Interface Panels.cpp b/Tactical/Interface Panels.cpp index c43d75ca..4e263f8a 100644 --- a/Tactical/Interface Panels.cpp +++ b/Tactical/Interface Panels.cpp @@ -3021,7 +3021,7 @@ void RenderSMPanel( BOOLEAN *pfDirty ) // lets rearrange our skills to a temp array // we also get the number of lines (skills) to be displayed - for ( UINT8 ubCnt = 1; ubCnt < NUM_SKILLTRAITS_NT; ubCnt++ ) + for ( UINT8 ubCnt = 1; ubCnt < NUM_SKILLTRAITS_NT; ++ubCnt ) { if ( ProfileHasSkillTrait( gpSMCurrentMerc->ubProfile, ubCnt ) == 2 ) { @@ -3041,7 +3041,7 @@ void RenderSMPanel( BOOLEAN *pfDirty ) } else { - for ( UINT8 ubCnt = 0; ubCnt < bNumSkillTraits; ubCnt++ ) + for ( UINT8 ubCnt = 0; ubCnt < bNumSkillTraits; ++ubCnt ) { swprintf( sTemp, L"%s\n", gzMercSkillTextNew[ ubTempSkillArray[ubCnt] ] ); wcscat( pStr, sTemp ); diff --git a/Tactical/Interface Utils.cpp b/Tactical/Interface Utils.cpp index 8c868103..5cc45212 100644 --- a/Tactical/Interface Utils.cpp +++ b/Tactical/Interface Utils.cpp @@ -21,7 +21,7 @@ #include "GameSettings.h" #endif -#define LIFE_BAR_SHADOW FROMRGB( 108, 12, 12 ) +#define LIFE_BAR_SHADOW FROMRGB( 108, 12, 12 ) #define LIFE_BAR FROMRGB( 200, 0, 0 ) #define BANDAGE_BAR_SHADOW FROMRGB( 156, 60, 60 ) #define BANDAGE_BAR FROMRGB( 222, 132, 132 ) @@ -81,7 +81,6 @@ STR pbCarPortraitFileNames[ ]={ // load int he portraits for the car faces that will be use in mapscreen BOOLEAN LoadCarPortraitValues( void ) { - INT32 iCounter = 0; VOBJECT_DESC VObjectDesc; /* @@ -91,15 +90,15 @@ BOOLEAN LoadCarPortraitValues( void ) } */ - for( iCounter = 0; iCounter < NUM_PROFILES; iCounter++ ) + for ( INT32 iCounter = 0; iCounter < NUM_PROFILES; ++iCounter ) { // silversurfer: fixed to make sure that we only create objects for vehicles that have a face defined // otherwise CHECKF will fail and return FALSE breaking the for loop and ignoring any further vehicles if ( gProfilesVehicle[ iCounter ].ProfilId == iCounter && gNewVehicle[ iCounter ].szIconFace[0] != 0 ) { - VObjectDesc.fCreateFlags = VOBJECT_CREATE_FROMFILE; - strcpy( VObjectDesc.ImageFile, gNewVehicle[ iCounter ].szIconFace ); - CHECKF( AddVideoObject( &VObjectDesc, (UINT32 *)&giCarPortraits[ iCounter ] ) ); + VObjectDesc.fCreateFlags = VOBJECT_CREATE_FROMFILE; + strcpy( VObjectDesc.ImageFile, gNewVehicle[ iCounter ].szIconFace ); + CHECKF( AddVideoObject( &VObjectDesc, (UINT32 *)&giCarPortraits[ iCounter ] ) ); } } @@ -116,8 +115,6 @@ BOOLEAN LoadCarPortraitValues( void ) // get rid of the images we loaded for the mapscreen car portraits void UnLoadCarPortraits( void ) { - INT32 iCounter = 0; - // car protraits loaded? /* if( giCarPortraits[ 0 ] == -1 ) @@ -132,15 +129,13 @@ void UnLoadCarPortraits( void ) } */ - for( iCounter = 0; iCounter < NUM_PROFILES; iCounter++ ) + for ( INT32 iCounter = 0; iCounter < NUM_PROFILES; ++iCounter ) { if ( gProfilesVehicle[ iCounter ].ProfilId == iCounter ) { DeleteVideoObjectFromIndex( giCarPortraits[ iCounter ] ); } } - - return; } @@ -281,19 +276,18 @@ void DrawLifeUIBarEx( SOLDIERTYPE *pSoldier, INT16 sXPos, INT16 sYPos, INT16 sWi } UnLockVideoSurface( uiBuffer ); - } void DrawBreathUIBarEx( SOLDIERTYPE *pSoldier, INT16 sXPos, INT16 sYPos, INT16 sWidth, INT16 sHeight, BOOLEAN fErase, UINT32 uiBuffer ) { - FLOAT dStart, dEnd, dPercentage; + FLOAT dStart, dEnd, dPercentage; //UINT16 usLineColor; UINT32 uiDestPitchBYTES; - UINT8 *pDestBuf; + UINT8 *pDestBuf; UINT16 usLineColor; - HVOBJECT hHandle; + HVOBJECT hHandle; // Erase what was there if ( fErase ) @@ -307,12 +301,10 @@ void DrawBreathUIBarEx( SOLDIERTYPE *pSoldier, INT16 sXPos, INT16 sYPos, INT16 s return; } - - // DO MAX MAX BREATH dPercentage = 1.; - dEnd = dPercentage * sHeight; - dStart = sYPos; + dEnd = dPercentage * sHeight; + dStart = sYPos; // brown guy GetVideoObject( &hHandle, guiBrownBackgroundForTeamPanel ); @@ -323,21 +315,18 @@ void DrawBreathUIBarEx( SOLDIERTYPE *pSoldier, INT16 sXPos, INT16 sYPos, INT16 s if( gusSelectedSoldier == pSoldier->ubID && gTacticalStatus.ubCurrentTeam == OUR_TEAM && OK_INTERRUPT_MERC( pSoldier ) ) { // gold, the second entry in the .sti - BltVideoObject( uiBuffer , hHandle, 1, sXPos, ( INT16 )( sYPos - sHeight ), VO_BLT_SRCTRANSPARENCY, NULL ); - + BltVideoObject( uiBuffer , hHandle, 1, sXPos, ( INT16 )( sYPos - sHeight ), VO_BLT_SRCTRANSPARENCY, NULL ); } else { // brown, first entry - BltVideoObject( uiBuffer , hHandle, 0, sXPos, ( INT16 )( sYPos - sHeight ), VO_BLT_SRCTRANSPARENCY, NULL ); - + BltVideoObject( uiBuffer , hHandle, 0, sXPos, ( INT16 )( sYPos - sHeight ), VO_BLT_SRCTRANSPARENCY, NULL ); } } else { // brown, first entry - BltVideoObject( uiBuffer , hHandle, 0, sXPos, ( INT16 )( sYPos - sHeight ), VO_BLT_SRCTRANSPARENCY, NULL ); - + BltVideoObject( uiBuffer , hHandle, 0, sXPos, ( INT16 )( sYPos - sHeight ), VO_BLT_SRCTRANSPARENCY, NULL ); } pDestBuf = LockVideoSurface( uiBuffer, &uiDestPitchBYTES ); @@ -360,9 +349,6 @@ void DrawBreathUIBarEx( SOLDIERTYPE *pSoldier, INT16 sXPos, INT16 sYPos, INT16 s RectangleDraw( TRUE, sXPos+ 2, (INT32)dStart, sXPos + 2, (INT32)( dStart - dEnd ), usLineColor, pDestBuf ); } - - - dPercentage = (FLOAT)pSoldier->bBreathMax / (FLOAT)100; dEnd = dPercentage * sHeight; dStart = sYPos; @@ -376,7 +362,6 @@ void DrawBreathUIBarEx( SOLDIERTYPE *pSoldier, INT16 sXPos, INT16 sYPos, INT16 s usLineColor = Get16BPPColor( CURR_MAX_BREATH_SHADOW ); RectangleDraw( TRUE, sXPos+ 2, (INT32)dStart, sXPos + 2, (INT32)( dStart - dEnd ), usLineColor, pDestBuf ); - // NOW DO BREATH dPercentage = (FLOAT)pSoldier->bBreath / (FLOAT)100; dEnd = dPercentage * sHeight; @@ -390,10 +375,8 @@ void DrawBreathUIBarEx( SOLDIERTYPE *pSoldier, INT16 sXPos, INT16 sYPos, INT16 s usLineColor = Get16BPPColor( CURR_BREATH_BAR_SHADOW ); RectangleDraw( TRUE, sXPos+ 2, (INT32)dStart, sXPos + 2, (INT32)( dStart - dEnd ), usLineColor, pDestBuf ); - - + UnLockVideoSurface( uiBuffer ); - } void DrawMoraleUIBarEx( SOLDIERTYPE *pSoldier, INT16 sXPos, INT16 sYPos, INT16 sWidth, INT16 sHeight, BOOLEAN fErase, UINT32 uiBuffer ) @@ -420,7 +403,6 @@ void DrawMoraleUIBarEx( SOLDIERTYPE *pSoldier, INT16 sXPos, INT16 sYPos, INT16 s pDestBuf = LockVideoSurface( uiBuffer, &uiDestPitchBYTES ); SetClippingRegionAndImageWidth( uiDestPitchBYTES, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT ); - // FIRST DO BREATH dPercentage = (FLOAT)pSoldier->aiData.bMorale / (FLOAT)100; dEnd = dPercentage * sHeight; @@ -434,24 +416,21 @@ void DrawMoraleUIBarEx( SOLDIERTYPE *pSoldier, INT16 sXPos, INT16 sYPos, INT16 s usLineColor = Get16BPPColor( MORALE_BAR_SHADOW ); RectangleDraw( TRUE, sXPos+ 2, (INT32)dStart, sXPos + 2, (INT32)( dStart - dEnd ), usLineColor, pDestBuf ); - - + UnLockVideoSurface( uiBuffer ); - } void DrawItemUIBarEx( OBJECTTYPE *pObject, UINT8 ubStatus, INT16 sXPos, INT16 sYPos, INT16 sWidth, INT16 sHeight, INT16 sColor1, INT16 sColor2, BOOLEAN fErase, UINT32 uiBuffer, UINT8 iter ) { - FLOAT dStart, dEnd, dPercentage; + FLOAT dStart, dEnd, dPercentage; //UINT16 usLineColor; UINT32 uiDestPitchBYTES; - UINT8 *pDestBuf; + UINT8 *pDestBuf; UINT16 usLineColor; - INT16 sValue; - - + INT16 sValue; + if ( ubStatus >= DRAW_ITEM_STATUS_ATTACHMENT1 ) { sValue = 0; @@ -469,18 +448,15 @@ void DrawItemUIBarEx( OBJECTTYPE *pObject, UINT8 ubStatus, INT16 sXPos, INT16 sY } else { - if (ubStatus < pObject->ubNumberOfObjects) { + if (ubStatus < pObject->ubNumberOfObjects) sValue = (*pObject)[ ubStatus ]->data.objectStatus; - } - else { + else sValue = 0; - } } // Adjust for ammo, other thingys.. if( Item[ pObject->usItem ].usItemClass & IC_AMMO ) { - sValue = sValue * 100 / Magazine[ Item[ pObject->usItem ].ubClassIndex ].ubMagSize; if ( sValue < 0 ) @@ -488,17 +464,13 @@ void DrawItemUIBarEx( OBJECTTYPE *pObject, UINT8 ubStatus, INT16 sXPos, INT16 sY sValue = (*pObject)[iter]->data.ubShotsLeft * 100 / Magazine[ Item[ pObject->usItem ].ubClassIndex ].ubMagSize; DebugMsg ( TOPIC_JA2, DBG_LEVEL_3, String("Ammo status: shots left %d * 100 / Mag Size %d = value %d",(*pObject)[iter]->data.ubShotsLeft,Magazine[ Item[ pObject->usItem ].ubClassIndex ].ubMagSize,sValue )); } - if ( sValue > 100 ) - { - sValue = 100; - } + if ( sValue > 100 ) + sValue = 100; } if( Item[ pObject->usItem ].usItemClass & IC_KEY ) - { sValue =100; - } // Flugente if ( ubStatus == DRAW_ITEM_TEMPERATURE ) @@ -531,14 +503,14 @@ void DrawItemUIBarEx( OBJECTTYPE *pObject, UINT8 ubStatus, INT16 sXPos, INT16 sY // ATE: Subtract 1 to exagerate bad status if ( sValue < 100 && sValue > 1 ) { - sValue--; + --sValue; } // Erase what was there - if ( fErase ) + /*if ( fErase ) { - //RestoreExternBackgroundRect( sXPos, (INT16)(sYPos - sHeight), sWidth, (INT16)(sHeight + 1 ) ); - } + RestoreExternBackgroundRect( sXPos, (INT16)(sYPos - sHeight), sWidth, (INT16)(sHeight + 1 ) ); + }*/ pDestBuf = LockVideoSurface( uiBuffer, &uiDestPitchBYTES ); SetClippingRegionAndImageWidth( uiDestPitchBYTES, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT ); @@ -560,14 +532,12 @@ void DrawItemUIBarEx( OBJECTTYPE *pObject, UINT8 ubStatus, INT16 sXPos, INT16 sY RectangleDraw( TRUE, sXPos + 1, (INT32)(dStart - repairthresholdend), sXPos + 1, (INT32)( dStart - sHeight ) , usLineColor, pDestBuf ); } - //usLineColor = Get16BPPColor( STATUS_BAR ); usLineColor = sColor1; RectangleDraw( TRUE, sXPos, (INT32)dStart, sXPos, (INT32)( dStart - dEnd ) , usLineColor, pDestBuf ); usLineColor = sColor2; RectangleDraw( TRUE, sXPos+ 1, (INT32)dStart, sXPos + 1, (INT32)( dStart - dEnd ), usLineColor, pDestBuf ); - UnLockVideoSurface( uiBuffer ); if ( uiBuffer == guiSAVEBUFFER ) @@ -578,7 +548,6 @@ void DrawItemUIBarEx( OBJECTTYPE *pObject, UINT8 ubStatus, INT16 sXPos, INT16 sY { InvalidateRegion( sXPos, (INT16)(sYPos - sHeight), sXPos + sWidth, (INT16)(sYPos + 1 ) ); } - } void RenderSoldierFace( SOLDIERTYPE *pSoldier, INT16 sFaceX, INT16 sFaceY, BOOLEAN fAutoFace ) @@ -586,10 +555,8 @@ void RenderSoldierFace( SOLDIERTYPE *pSoldier, INT16 sFaceX, INT16 sFaceY, BOOLE BOOLEAN fDoFace = FALSE; // UINT8 ubVehicleType = 0; - if ( pSoldier->bActive ) { - if( pSoldier->flags.uiStatusFlags & SOLDIER_VEHICLE ) { // get the type of vehicle @@ -641,7 +608,6 @@ void RenderSoldierFace( SOLDIERTYPE *pSoldier, INT16 sFaceX, INT16 sFaceY, BOOLE //} RestoreExternBackgroundRect( sFaceX, sFaceY, FACE_WIDTH, FACE_HEIGHT ); } - } // HEADROCK HAM 5: This function draws a rectangle around the item image in the zoomed inventory diff --git a/Tactical/Interface.cpp b/Tactical/Interface.cpp index 2de06bbe..3b3655a4 100644 --- a/Tactical/Interface.cpp +++ b/Tactical/Interface.cpp @@ -305,41 +305,35 @@ extern FLOAT Distance2D( FLOAT dDeltaX, FLOAT dDeltaY ); // Flugente: toggle display of enemy role indicators BOOLEAN gDisplayEnemyRoles = TRUE; +#define SCSTI ".STI" +#define SCSTI_IMP "_IMP.STI" + BOOLEAN InitializeFaceGearGraphics() { VOBJECT_DESC VObjectDesc; char fileName[500]; - for(UINT32 iCounter2 = 1; iCounter2 < MAXITEMS; iCounter2++ ) - { - VObjectDesc.fCreateFlags = VSURFACE_CREATE_FROMFILE; - - #define SCSTI ".STI" - + for ( UINT32 iCounter2 = 1; iCounter2 < gMAXITEMS_READ; ++iCounter2 ) + { if ( zNewFaceGear[iCounter2].Type > 0 ) { - strcpy(fileName, zNewFaceGear[iCounter2].szFile); - strcat(fileName, SCSTI); - strcpy(VObjectDesc.ImageFile, fileName); - CHECKF(AddVideoObject(&VObjectDesc,&zNewFaceGear[iCounter2].uiIndex)); + { + VObjectDesc.fCreateFlags = VSURFACE_CREATE_FROMFILE; + strcpy(fileName, zNewFaceGear[iCounter2].szFile); + strcat(fileName, SCSTI); + strcpy(VObjectDesc.ImageFile, fileName); + CHECKF(AddVideoObject(&VObjectDesc,&zNewFaceGear[iCounter2].uiIndex)); + } - } - } - - for(UINT32 iCounter2 = 1; iCounter2 < MAXITEMS; iCounter2++ ) - { - VObjectDesc.fCreateFlags = VSURFACE_CREATE_FROMFILE; - - #define SCSTI_IMP "_IMP.STI" - - if ( zNewFaceGear[iCounter2].Type > 0 ) - { //IMP - strcpy(fileName, zNewFaceGear[iCounter2].szFile); - strcat(fileName, SCSTI_IMP); - strcpy(VObjectDesc.ImageFile, fileName); - CHECKF(AddVideoObject(&VObjectDesc,&zNewFaceGearIMP[iCounter2].uiIndex)); + { + VObjectDesc.fCreateFlags = VSURFACE_CREATE_FROMFILE; + strcpy( fileName, zNewFaceGear[iCounter2].szFile ); + strcat( fileName, SCSTI_IMP ); + strcpy( VObjectDesc.ImageFile, fileName ); + CHECKF( AddVideoObject( &VObjectDesc, &zNewFaceGearIMP[iCounter2].uiIndex ) ); + } } } @@ -562,40 +556,6 @@ BOOLEAN InitializeTacticalInterface( ) InitializeFaceGearGraphics(); - /* - for( iCounter2 = 1; iCounter2 < MAXITEMS; iCounter2++ ) - { - VObjectDesc.fCreateFlags = VSURFACE_CREATE_FROMFILE; - - #define SCSTI ".STI" - - if ( zNewFaceGear[iCounter2].Type > 0 ) - { - strcpy(fileName, zNewFaceGear[iCounter2].szFile); - strcat(fileName, SCSTI); - strcpy(VObjectDesc.ImageFile, fileName); - CHECKF(AddVideoObject(&VObjectDesc,&zNewFaceGear[iCounter2].uiIndex)); - - } - } - - for( iCounter2 = 1; iCounter2 < MAXITEMS; iCounter2++ ) - { - VObjectDesc.fCreateFlags = VSURFACE_CREATE_FROMFILE; - - #define SCSTI_IMP "_IMP.STI" - - if ( zNewFaceGear[iCounter2].Type > 0 ) - { - //IMP - strcpy(fileName, zNewFaceGear[iCounter2].szFile); - strcat(fileName, SCSTI_IMP); - strcpy(VObjectDesc.ImageFile, fileName); - CHECKF(AddVideoObject(&VObjectDesc,&zNewFaceGearIMP[iCounter2].uiIndex)); - } - } - */ - // LOAD RADIO VObjectDesc.fCreateFlags = VOBJECT_CREATE_FROMFILE; FilenameForBPP("INTERFACE\\radio.sti", VObjectDesc.ImageFile); diff --git a/Tactical/Inventory Choosing.cpp b/Tactical/Inventory Choosing.cpp index b016985c..3c014c61 100644 --- a/Tactical/Inventory Choosing.cpp +++ b/Tactical/Inventory Choosing.cpp @@ -140,7 +140,7 @@ void InitArmyGunTypes(void) DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"InitArmyGunTypes mark weapons as not dropped"); // set all flags that track whether this weapon type has been dropped before to FALSE - for (ubWeapon = 0; ubWeapon < MAXITEMS; ubWeapon++) + for (ubWeapon = 0; ubWeapon < MAXITEMS; ++ubWeapon) { DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("InitArmyGunTypes marking weapons %d", ubWeapon)); gStrategicStatus.fWeaponDroppedAlready[ubWeapon] = FALSE; @@ -2627,7 +2627,7 @@ else if (gGameExternalOptions.ubEnemiesItemDrop == 0) { // if it's a weapon (monster parts included - they won't drop due to checks elsewhere!) - if ((usItem > NONE) && (usItem < MAXITEMS )) // Madd -- this should be ok set to maxitems instead of max_Weapons + if ( (usItem > NONE) && (usItem < gMAXITEMS_READ) ) // Madd -- this should be ok set to maxitems instead of max_Weapons { // and we're allowed to change its flags if(! (pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE )) diff --git a/Tactical/Item Types.h b/Tactical/Item Types.h index 1a8e0734..18fe1bba 100644 --- a/Tactical/Item Types.h +++ b/Tactical/Item Types.h @@ -1674,6 +1674,9 @@ typedef enum MAXITEMS = 16001 } ITEMDEFINE; +// Flugente: in order not to loop over MAXITEMS items if we only have a few thousand, remember the actual number of items in the xml +extern UINT32 gMAXITEMS_READ; + /* CHRISL: Arrays to track ic group information. These allow us to determine which LBE slots control which pockets and what LBE class the pockets are.*/ // { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54} diff --git a/Tactical/Items.cpp b/Tactical/Items.cpp index b8409b17..f0f156f0 100644 --- a/Tactical/Items.cpp +++ b/Tactical/Items.cpp @@ -1437,7 +1437,7 @@ UINT8 ItemSlotLimit( OBJECTTYPE * pObject, INT16 bSlot, SOLDIERTYPE *pSoldier, B //} // WANNE: This fixes the stacking problem of silver nuggets!! - if (Item[usItem].usItemClass == IC_MONEY) + if (Item[usItem].usItemClass & IC_MONEY) { //need to have money "stackable" in all slots to trick it into merging return 2; @@ -1484,18 +1484,27 @@ UINT8 ItemSlotLimit( OBJECTTYPE * pObject, INT16 bSlot, SOLDIERTYPE *pSoldier, B else if (bSlot == KNIFEPOCKPOS) { pIndex = KNIFE_POCKET_TYPE; } - else { + else + { Assert(icLBE[bSlot] != -1 && icDefault[bSlot] != -1 && icPocket[bSlot] != -1); //find the class of the LBE, then find what size the pocket of the slot in the LBE is - if (pSoldier == NULL || pSoldier->inv[icLBE[bSlot]].exists() == false) { + if (pSoldier == NULL || !pSoldier->inv[icLBE[bSlot]].exists() ) + { pIndex = LoadBearingEquipment[Item[icDefault[bSlot]].ubClassIndex].lbePocketIndex[icPocket[bSlot]]; } - else { + else + { pIndex = LoadBearingEquipment[Item[pSoldier->inv[icLBE[bSlot]].usItem].ubClassIndex].lbePocketIndex[icPocket[bSlot]]; - if( pIndex == 0 && LoadBearingEquipment[Item[pSoldier->inv[icLBE[bSlot]].usItem].ubClassIndex].lbePocketsAvailable & (UINT16)pow((double)2, icPocket[bSlot])){ + if( pIndex == 0 && LoadBearingEquipment[Item[pSoldier->inv[icLBE[bSlot]].usItem].ubClassIndex].lbePocketsAvailable & (UINT16)pow((double)2, icPocket[bSlot])) + { pIndex = GetPocketFromAttachment(&pSoldier->inv[icLBE[bSlot]], icPocket[bSlot]); + } } } + + if ( LBEPocketType[pIndex].pRestriction != 0 && !(LBEPocketType[pIndex].pRestriction & Item[usItem].usItemClass) ) + { + return 0; } //We need to actually check the size of the largest stored item as well as the size of the current item @@ -1516,11 +1525,7 @@ UINT8 ItemSlotLimit( OBJECTTYPE * pObject, INT16 bSlot, SOLDIERTYPE *pSoldier, B //this could be changed, we know guns are physically able to stack //if ( iSize < 10 && ubSlotLimit > 1) - // ubSlotLimit = 1; - - if(LBEPocketType[pIndex].pRestriction != 0 && !(LBEPocketType[pIndex].pRestriction & Item[usItem].usItemClass)) { - return 0; - } + // ubSlotLimit = 1; return( ubSlotLimit ); } @@ -1994,31 +1999,43 @@ UINT16 FindLegalGrenade(UINT16 usItem) { UINT16 newItem = 0; UINT16 usClass = Item[usItem].ubClassIndex; - if(UsingNewAttachmentSystem()==false) + + if ( !UsingNewAttachmentSystem() ) return usItem; - for(UINT16 loop = 0; loop < MAXITEMS+1; loop++){ + + for ( UINT16 loop = 0; loop < gMAXITEMS_READ + 1; ++loop ) + { if(loop == usClass) continue; + if(Explosive[usClass].ubType == Explosive[loop].ubType && Explosive[usClass].ubDamage == Explosive[loop].ubDamage && Explosive[usClass].ubStunDamage == Explosive[loop].ubStunDamage && Explosive[usClass].ubRadius == Explosive[loop].ubRadius && Explosive[usClass].ubVolume == Explosive[loop].ubVolume && Explosive[usClass].ubVolatility == Explosive[loop].ubVolatility && Explosive[usClass].ubAnimationID == Explosive[loop].ubAnimationID && Explosive[usClass].ubDuration == Explosive[loop].ubDuration - && Explosive[usClass].ubStartRadius == Explosive[loop].ubStartRadius && Explosive[loop].ubMagSize == 1){ + && Explosive[usClass].ubStartRadius == Explosive[loop].ubStartRadius && Explosive[loop].ubMagSize == 1) + { newItem = loop; break; } + if(Explosive[loop].uiIndex == 0 && loop > 0) break; } - if(newItem > 0){ - for(UINT16 loop = 1; loop < MAXITEMS+1; loop++){ + + if(newItem > 0) + { + for ( UINT16 loop = 1; loop < gMAXITEMS_READ; ++loop ) + { if(Item[loop].uiIndex == 0) break; - if(Item[loop].usItemClass & IC_GRENADE && Item[loop].ubClassIndex == newItem){ + + if(Item[loop].usItemClass & IC_GRENADE && Item[loop].ubClassIndex == newItem) + { return Item[loop].uiIndex; } } } + return usItem; } @@ -2184,16 +2201,11 @@ BOOLEAN ValidAttachment( UINT16 usAttachment, UINT16 usItem, UINT8 * pubAPCost ) BOOLEAN ValidAttachment( UINT16 usAttachment, OBJECTTYPE * pObj, UINT8 * pubAPCost, UINT8 subObject, std::vector usAttachmentSlotIndexVector) { - if (pObj->exists() == false) { + if ( !pObj->exists() ) return FALSE; - } - if(UsingNewAttachmentSystem()==true) + if( UsingNewAttachmentSystem() ) { - UINT16 usSlotIndex = 0; - BOOLEAN foundValidAttachment = FALSE; - UINT16 usLoop = 0; - //It's possible we've entered this function without being passed the usAttachmentSlotIndexVector parameter if(usAttachmentSlotIndexVector.empty()) usAttachmentSlotIndexVector = GetItemSlots(pObj); @@ -2201,29 +2213,35 @@ BOOLEAN ValidAttachment( UINT16 usAttachment, OBJECTTYPE * pObj, UINT8 * pubAPCo //Still no slots means nothing will ever be valid if(usAttachmentSlotIndexVector.empty()) return FALSE; - + //Madd: Common Attachment Framework - foundValidAttachment = IsAttachmentPointAvailable(pObj, subObject, usAttachment); - if (foundValidAttachment && pubAPCost ) + if ( pubAPCost && IsAttachmentPointAvailable( pObj, subObject, usAttachment ) ) + { *pubAPCost = Item[usAttachment].ubAttachToPointAPCost; + + return TRUE; + } else { //Check if the attachment is valid with the main item - foundValidAttachment = (ValidAttachment(usAttachment, pObj->usItem, pubAPCost) || ValidLaunchable(usAttachment, pObj->usItem)); + if ( ValidAttachment(usAttachment, pObj->usItem, pubAPCost) || ValidLaunchable(usAttachment, pObj->usItem) ) + return TRUE; //Loop through all attachment points on the main item - for(attachmentList::iterator iter = (*pObj)[subObject]->attachments.begin(); iter != (*pObj)[subObject]->attachments.end() && !foundValidAttachment; ++iter) + for(attachmentList::iterator iter = (*pObj)[subObject]->attachments.begin(); iter != (*pObj)[subObject]->attachments.end(); ++iter) { - if(iter->exists()) - foundValidAttachment = (ValidAttachment(usAttachment, iter->usItem, pubAPCost) || ValidLaunchable(usAttachment, iter->usItem)); + if ( iter->exists() ) + { + if ( ValidAttachment(usAttachment, iter->usItem, pubAPCost) || ValidLaunchable(usAttachment, iter->usItem) ) + return TRUE; + } } } - return ( foundValidAttachment ); - } - else - { - return( ValidAttachment(usAttachment, pObj->usItem, pubAPCost) ); + + return FALSE; } + + return( ValidAttachment(usAttachment, pObj->usItem, pubAPCost) ); } UINT8 AttachmentAPCost( UINT16 usAttachment, UINT16 usItem, SOLDIERTYPE * pSoldier ) // SANDRO - added argument @@ -2880,24 +2898,29 @@ UINT16 CalculateItemSize( OBJECTTYPE *pObject ) iSize = gGameExternalOptions.guiMaxItemSize; //for each object in the stack, hopefully there is only 1 - for (int numStacked = 0; numStacked < pObject->ubNumberOfObjects; ++numStacked) { + for (int numStacked = 0; numStacked < pObject->ubNumberOfObjects; ++numStacked) + { //some weapon attachments can adjust the ItemSize of a weapon - if(iSizeattachments.begin(); iter != (*pObject)[numStacked]->attachments.end(); ++iter) { - if (iter->exists() == true) { + if(iSizeattachments.begin(); iter != (*pObject)[numStacked]->attachments.end(); ++iter) + { + if ( iter->exists() ) + { iSize += Item[iter->usItem].itemsizebonus; // CHRISL: This is to catch things if we try and reduce ItemSize when we're already at 0 } } - if(iSize > gGameExternalOptions.guiMaxItemSize || iSize < 0) //JMich + + if(iSize > gGameExternalOptions.guiMaxItemSize || iSize < 0) //JMich iSize = 0; - if(iSize > gGameExternalOptions.guiMaxWeaponSize) //JMich - iSize = gGameExternalOptions.guiMaxWeaponSize; //JMich + if(iSize > gGameExternalOptions.guiMaxWeaponSize) //JMich + iSize = gGameExternalOptions.guiMaxWeaponSize; //JMich } // LBENODE has it's ItemSize adjusted based on what it's storing - if(pObject->IsActiveLBE(numStacked) == true) + if( pObject->IsActiveLBE(numStacked) ) { LBENODE* pLBE = pObject->GetLBEPointer(numStacked); if(pLBE) @@ -2921,7 +2944,7 @@ UINT16 CalculateItemSize( OBJECTTYPE *pObject ) //Now, look through each active pocket for(UINT16 x = 0; x < invsize; ++x) { - if(pLBE->inv[x].exists() == true) + if ( pLBE->inv[x].exists() ) { pIndex = LoadBearingEquipment[Item[pObject->usItem].ubClassIndex].lbePocketIndex[x]; testSize = CalculateItemSize(&pLBE->inv[x]); @@ -3782,7 +3805,7 @@ INT8 FindAmmoToReload( SOLDIERTYPE * pSoldier, INT8 bWeaponIn, INT8 bExcludeSlot } else { - for(int i=0;iusItem){ + if (Attachment[uiLoop][1] == pObj->usItem) + { fItem = Attachment[uiLoop][0]; if(fItem && ItemIsLegal(fItem, TRUE)) uiSlotFlag |= Item[fItem].nasAttachmentClass; } - if (Launchable[uiLoop][1] == pObj->usItem ){ + if (Launchable[uiLoop][1] == pObj->usItem ) + { fItem = Launchable[uiLoop][0]; if(fItem && ItemIsLegal(fItem, TRUE)) uiSlotFlag |= Item[fItem].nasAttachmentClass; } - uiLoop++; - if (Attachment[uiLoop][0] == 0 && Launchable[uiLoop][0] == 0 && Item[uiLoop].usItemClass == 0 ){ + ++uiLoop; + + if (Attachment[uiLoop][0] == 0 && Launchable[uiLoop][0] == 0 && Item[uiLoop].usItemClass == 0 ) + { // No more attachments to search break; } } - return uiSlotFlag; + return uiSlotFlag; } //WarmSteel - This function returns the available item slot indexes in a vector. -std::vector GetItemSlots(OBJECTTYPE* pObj, UINT8 subObject, BOOLEAN fAttachment){ +std::vector GetItemSlots(OBJECTTYPE* pObj, UINT8 subObject, BOOLEAN fAttachment) +{ std::vector tempItemSlots; std::vector tempAttachmentSlots; std::vector tempSlots; @@ -5514,37 +5542,51 @@ std::vector GetItemSlots(OBJECTTYPE* pObj, UINT8 subObject, BOOLEAN fAtt UINT16 magSize = 0; UINT64 fItemSlots = 0; //MM: Bumped the NAS UINT32s to UINT64s UINT64 fItemLayout = 0; + BOOLEAN fIsLBE = FALSE; - if(UsingNewAttachmentSystem()==false || !pObj->exists()) + if( !UsingNewAttachmentSystem() || !pObj->exists() ) return tempItemSlots; //CHRISL: We no longer need the ItemSlotAssign.xml file but we do still need to figure out which slots an item can have //Start by searching Attachments.xml and Launchables.xml for valid attachments for the primary object fItemSlots = SetAttachmentSlotsFlag(pObj); - fItemLayout = Item[pObj->usItem].nasLayoutClass; - if(Item[pObj->usItem].grenadelauncher || Item[pObj->usItem].rocketlauncher) - magSize = GetMagSize(pObj); - + //Next, let's figure out which slots the item gives us access to - if(fItemSlots){ //We don't need to do anything if the item gets no slots - for(UINT8 sClass = 0; sClass < 64; sClass++){ //go through each attachment class and find the slots the item should have + if( fItemSlots ) + { + fItemLayout = Item[pObj->usItem].nasLayoutClass; + fIsLBE = (Item[pObj->usItem].usItemClass & IC_LBEGEAR); + if ( Item[pObj->usItem].grenadelauncher || Item[pObj->usItem].rocketlauncher ) + magSize = GetMagSize( pObj ); + + //We don't need to do anything if the item gets no slots + for(UINT8 sClass = 0; sClass < 64; ++sClass) + { + //go through each attachment class and find the slots the item should have UINT64 uiClass = (UINT64)pow((double)2, (int)sClass); UINT32 slotSize = tempItemSlots.size(); - if(fItemSlots & uiClass){ //don't bother with this slot if it's not a valid class - for(UINT32 sCount = 1; sCount < MAXITEMS+1; sCount++) + + if(fItemSlots & uiClass) + { + //don't bother with this slot if it's not a valid class + for ( UINT32 sCount = 1; sCount < gMAXITEMS_READ; ++sCount ) { - if(AttachmentSlots[sCount].uiSlotIndex == 0) + if( !AttachmentSlots[sCount].uiSlotIndex ) break; + if(AttachmentSlots[sCount].nasAttachmentClass & uiClass && AttachmentSlots[sCount].nasLayoutClass & fItemLayout) //found a slot { - if(magSize > 0 && AttachmentSlots[sCount].fMultiShot) - magSize--; - else if(AttachmentSlots[sCount].fMultiShot) - continue; - - if(Item[pObj->usItem].usItemClass == IC_LBEGEAR && AttachmentSlots[sCount].ubPocketMapping > 0) + if ( AttachmentSlots[sCount].fMultiShot ) { - if(LoadBearingEquipment[Item[pObj->usItem].ubClassIndex].lbePocketsAvailable & (UINT16)pow((double)2, AttachmentSlots[sCount].ubPocketMapping - 1)) + if ( magSize ) + --magSize; + else + continue; + } + + if ( fIsLBE && AttachmentSlots[sCount].ubPocketMapping ) + { + if ( LoadBearingEquipment[Item[pObj->usItem].ubClassIndex].lbePocketsAvailable & (UINT16)pow((double)2, AttachmentSlots[sCount].ubPocketMapping - 1) ) { tempItemSlots.push_back(AttachmentSlots[sCount].uiSlotIndex); } @@ -5555,12 +5597,19 @@ std::vector GetItemSlots(OBJECTTYPE* pObj, UINT8 subObject, BOOLEAN fAtt } } } - if(slotSize == tempItemSlots.size()){ //we didn't find a layout specific slot so try to find a default layout slot - for(UINT32 sCount = 1; sCount < MAXITEMS+1; sCount++){ - if(AttachmentSlots[sCount].uiSlotIndex == 0) + + if( slotSize == tempItemSlots.size() ) + { + //we didn't find a layout specific slot so try to find a default layout slot + for ( UINT32 sCount = 1; sCount < gMAXITEMS_READ; ++sCount ) + { + if( !AttachmentSlots[sCount].uiSlotIndex ) break; - if(AttachmentSlots[sCount].nasAttachmentClass & uiClass && AttachmentSlots[sCount].nasLayoutClass == 1){ //found a default slot - tempItemSlots.push_back(AttachmentSlots[sCount].uiSlotIndex); + + if ( AttachmentSlots[sCount].nasAttachmentClass & uiClass && AttachmentSlots[sCount].nasLayoutClass == 1 ) + { + //found a default slot + tempItemSlots.push_back(AttachmentSlots[sCount].uiSlotIndex); } } } @@ -5570,34 +5619,46 @@ std::vector GetItemSlots(OBJECTTYPE* pObj, UINT8 subObject, BOOLEAN fAtt //Now that we've setup tempItemSlots for the main item, let's look at the individual attachments //Madd: Only record these extra slots if the item has its attachment flag set! - for(attachmentList::iterator iter = (*pObj)[subObject]->attachments.begin(); iter != (*pObj)[subObject]->attachments.end(); ++iter){ - if(iter->exists() && Item[iter->usItem].attachment && (*iter)[0]->attachments.size() > 0){ + for(attachmentList::iterator iter = (*pObj)[subObject]->attachments.begin(); iter != (*pObj)[subObject]->attachments.end(); ++iter) + { + if(iter->exists() && Item[iter->usItem].attachment && !(*iter)[0]->attachments.empty() ) + { OBJECTTYPE* pAttachment = &(*iter); tempSlots = GetItemSlots(pAttachment,0,TRUE); - for(UINT8 x = 0; x < tempSlots.size(); x++) + + for(UINT8 x = 0; x < tempSlots.size(); ++x) tempAttachmentSlots.push_back(tempSlots[x]); } } //Now that we have tempAttachmentSlots, put it all together, assuming we're woking on the main item - if(!fAttachment){ - if(tempAttachmentSlots.size() > 0){ //Add attachmentSlots to itemSlots - for(UINT8 attachSlot = 0; attachSlot < tempAttachmentSlots.size(); attachSlot++){ + if(!fAttachment) + { + if( !tempAttachmentSlots.empty() ) + { + //Add attachmentSlots to itemSlots + for(UINT8 attachSlot = 0; attachSlot < tempAttachmentSlots.size(); ++attachSlot) + { tempItemSlots.push_back(tempAttachmentSlots[attachSlot]); } } + tempSlots = tempItemSlots; - for(std::vector::iterator iter1 = tempSlots.begin(); iter1 != tempSlots.end(); ++iter1){ + for(std::vector::iterator iter1 = tempSlots.begin(); iter1 != tempSlots.end(); ++iter1) + { BOOLEAN fSlotDuplicated = FALSE; - for(std::vector::iterator iter = tempItemSlots.begin(); iter != tempItemSlots.end();){ + for(std::vector::iterator iter = tempItemSlots.begin(); iter != tempItemSlots.end();) + { UINT16 i1 = *iter1; UINT16 i = *iter; - if(i1 == i && !fSlotDuplicated){ + if(i1 == i && !fSlotDuplicated) + { fSlotDuplicated = TRUE; ++iter; continue; } - else if(i1 == i && fSlotDuplicated){ + else if(i1 == i && fSlotDuplicated) + { iter = tempItemSlots.erase(iter); continue; } @@ -5605,9 +5666,11 @@ std::vector GetItemSlots(OBJECTTYPE* pObj, UINT8 subObject, BOOLEAN fAtt ++iter; } } + //If we still have no attachment slots, look through Merges.xml to see if we have merges and use the 4 default slots if we do //Should we throw on default slots regardless of whether there is an entry in Merges? Ammo doesn't have Merges entries but we still need slots for them. - if(tempItemSlots.size() == 0){ + if( tempItemSlots.empty() ) + { // INT32 iLoop = 0; // while( 1 ){ // if (Merge[iLoop][1] == pObj->usItem) @@ -6007,13 +6070,14 @@ BOOLEAN CanItemFitInPosition( SOLDIERTYPE *pSoldier, OBJECTTYPE *pObj, INT8 bPos UINT32 pRestrict=0; // CHRISL: Only check valid pockets - if((UsingNewInventorySystem() == false) && !oldInv[bPos]) + if ( UsingNewInventorySystem( ) ) + { + if ( pSoldier->flags.uiStatusFlags & SOLDIER_VEHICLE ) + return ( CanItemFitInVehicle( pSoldier, pObj, bPos, fDoingPlacement ) ); + } + else if ( !oldInv[bPos] ) return(FALSE); - if((pSoldier->flags.uiStatusFlags & SOLDIER_VEHICLE) && UsingNewInventorySystem() == true) - return(CanItemFitInVehicle(pSoldier, pObj, bPos, fDoingPlacement)); - - ubSlotLimit = ItemSlotLimit( pObj, bPos, pSoldier ); - + switch( bPos ) { case SECONDHANDPOS: @@ -6025,10 +6089,10 @@ BOOLEAN CanItemFitInPosition( SOLDIERTYPE *pSoldier, OBJECTTYPE *pObj, INT8 bPos case HANDPOS: if (Item[ pObj->usItem ].twohanded ) { - if (pSoldier->inv[HANDPOS].exists() == true && pSoldier->inv[SECONDHANDPOS].exists() == true) + if ( pSoldier->inv[HANDPOS].exists() && pSoldier->inv[SECONDHANDPOS].exists() ) { // two items in hands; try moving the second one so we can swap - if (FitsInSmallPocket(&pSoldier->inv[SECONDHANDPOS]) == true) + if ( FitsInSmallPocket(&pSoldier->inv[SECONDHANDPOS]) ) { bNewPos = FindEmptySlotWithin( pSoldier, BIGPOCKSTART, NUM_INV_SLOTS ); } @@ -6125,10 +6189,10 @@ BOOLEAN CanItemFitInPosition( SOLDIERTYPE *pSoldier, OBJECTTYPE *pObj, INT8 bPos // Removed backpack/gunsling restrictions //if(pSoldier->inv[GUNSLINGPOCKPOS].exists() == true) // return( FALSE ); - if(pSoldier->inv[CPACKPOCKPOS].exists() == true) + if ( pSoldier->inv[CPACKPOCKPOS].exists() ) { //DBrot: changed to bitwise comparison - if(((LoadBearingEquipment[Item[pSoldier->inv[CPACKPOCKPOS].usItem].ubClassIndex].lbeCombo & LoadBearingEquipment[Item[pObj->usItem].ubClassIndex].lbeCombo) ==0)|| + if( ((LoadBearingEquipment[Item[pSoldier->inv[CPACKPOCKPOS].usItem].ubClassIndex].lbeCombo & LoadBearingEquipment[Item[pObj->usItem].ubClassIndex].lbeCombo) ==0) || LoadBearingEquipment[Item[pSoldier->inv[CPACKPOCKPOS].usItem].ubClassIndex].lbeCombo == 0) { return( FALSE ); @@ -6139,10 +6203,10 @@ BOOLEAN CanItemFitInPosition( SOLDIERTYPE *pSoldier, OBJECTTYPE *pObj, INT8 bPos //if (Item[pObj->usItem].usItemClass != IC_GUN && Item[pObj->usItem].usItemClass != IC_BLADE && Item[pObj->usItem].usItemClass != IC_LAUNCHER) if(pObj->usItem == MONEY) return( FALSE ); - if(Item[pObj->usItem].usItemClass == IC_AMMO || Item[pObj->usItem].usItemClass == IC_GRENADE) + + if ( Item[pObj->usItem].usItemClass & (IC_AMMO | IC_GRENADE) ) return(CompatibleAmmoForGun(pObj, &pSoldier->inv[GUNSLINGPOCKPOS]) || ValidAttachment(pObj->usItem, &(pSoldier->inv[GUNSLINGPOCKPOS]) ) || ValidLaunchable(pObj->usItem, pSoldier->inv[GUNSLINGPOCKPOS].usItem)); - //recalc slot limit to exclude ItemSize attachment modifiers - ubSlotLimit = ItemSlotLimit( pObj, bPos, pSoldier, FALSE ); + // Removed backpack/gunsling restrictions //if(pSoldier->inv[BPACKPOCKPOS].exists() == true) // return(CompatibleAmmoForGun(pObj, &pSoldier->inv[GUNSLINGPOCKPOS])); @@ -6195,18 +6259,21 @@ BOOLEAN CanItemFitInPosition( SOLDIERTYPE *pSoldier, OBJECTTYPE *pObj, INT8 bPos case SMALLPOCK28POS: case SMALLPOCK29POS: case SMALLPOCK30POS: - if((UsingNewInventorySystem() == true)) + if( UsingNewInventorySystem() ) { if(icLBE[bPos] == BPACKPOCKPOS && (!(pSoldier->flags.ZipperFlag) || (pSoldier->flags.ZipperFlag && gAnimControl[pSoldier->usAnimState].ubEndHeight == ANIM_STAND)) && (gTacticalStatus.uiFlags & INCOMBAT)) return( FALSE ); - lbePocket = (pSoldier->inv[icLBE[bPos]].exists() == false) ? LoadBearingEquipment[Item[icDefault[bPos]].ubClassIndex].lbePocketIndex[icPocket[bPos]] : LoadBearingEquipment[Item[pSoldier->inv[icLBE[bPos]].usItem].ubClassIndex].lbePocketIndex[icPocket[bPos]]; - if( lbePocket == 0 && LoadBearingEquipment[Item[pSoldier->inv[icLBE[bPos]].usItem].ubClassIndex].lbePocketsAvailable & (UINT16)pow((double)2, icPocket[bPos])){ + + lbePocket = ( !pSoldier->inv[icLBE[bPos]].exists() ) ? LoadBearingEquipment[Item[icDefault[bPos]].ubClassIndex].lbePocketIndex[icPocket[bPos]] : LoadBearingEquipment[Item[pSoldier->inv[icLBE[bPos]].usItem].ubClassIndex].lbePocketIndex[icPocket[bPos]]; + + if( lbePocket == 0 && LoadBearingEquipment[Item[pSoldier->inv[icLBE[bPos]].usItem].ubClassIndex].lbePocketsAvailable & (UINT16)pow((double)2, icPocket[bPos])) + { lbePocket = GetPocketFromAttachment(&pSoldier->inv[icLBE[bPos]], icPocket[bPos]); } pRestrict = LBEPocketType[lbePocket].pRestriction; - if(pRestrict != 0) - if(!(pRestrict & Item[pObj->usItem].usItemClass)) + if ( pRestrict != 0) + if ( !(pRestrict & Item[pObj->usItem].usItemClass) ) lbePocket = 0; } break; @@ -6214,23 +6281,39 @@ BOOLEAN CanItemFitInPosition( SOLDIERTYPE *pSoldier, OBJECTTYPE *pObj, INT8 bPos break; } - if((UsingNewInventorySystem() == false)) + if ( !UsingNewInventorySystem() ) { - if (ubSlotLimit == 0 && bPos >= SMALLPOCKSTART ) + if ( bPos >= SMALLPOCKSTART ) { + // Flugente: we call this function a lot. As ItemSlotLimit is somewhat expensive, limiting the amount of calls helps avoid a fps drop if the inventory is open + if ( bPos == GUNSLINGPOCKPOS ) + //recalc slot limit to exclude ItemSize attachment modifiers + ubSlotLimit = ItemSlotLimit( pObj, bPos, pSoldier, FALSE ); + else + ubSlotLimit = ItemSlotLimit( pObj, bPos, pSoldier ); + // doesn't fit! - return( FALSE ); + if ( !ubSlotLimit ) + return( FALSE ); } } else { // CHRISL: lbePocket==0 means pocket disabled. ubSlotLimit==0 means pocket can't hold item - if ( lbePocket == 0 || ubSlotLimit == 0 ) + if ( lbePocket == 0 ) return ( CompatibleAmmoForGun(pObj, &pSoldier->inv[bPos]) || ValidAttachment(pObj->usItem, &(pSoldier->inv[bPos]) ) || ValidLaunchable(pObj->usItem, pSoldier->inv[bPos].usItem) ); + else + { + // Flugente: we call this function a lot. As ItemSlotLimit is somewhat expensive, limiting the amount of calls helps avoid a fps drop if the inventory is open + if ( bPos == GUNSLINGPOCKPOS ) + //recalc slot limit to exclude ItemSize attachment modifiers + ubSlotLimit = ItemSlotLimit( pObj, bPos, pSoldier, FALSE ); + else + ubSlotLimit = ItemSlotLimit( pObj, bPos, pSoldier ); - // CHRISL: Adjust parameters to include the new inventory system - if (ubSlotLimit == 0 && bPos >= BIGPOCKFINAL ) - return( CompatibleAmmoForGun(pObj, &pSoldier->inv[bPos]) || ValidAttachment(pObj->usItem, &(pSoldier->inv[bPos]) ) || ValidLaunchable(pObj->usItem, pSoldier->inv[bPos].usItem) ); + if ( !ubSlotLimit ) + return (CompatibleAmmoForGun( pObj, &pSoldier->inv[bPos] ) || ValidAttachment( pObj->usItem, &(pSoldier->inv[bPos]) ) || ValidLaunchable( pObj->usItem, pSoldier->inv[bPos].usItem )); + } } return( TRUE ); @@ -6452,19 +6535,22 @@ BOOLEAN PlaceObject( SOLDIERTYPE * pSoldier, INT8 bPos, OBJECTTYPE * pObj ) UINT8 capacity=0; UINT8 bLoop; //find the ammo item we want to try and create - for(int loop = 0; loop < MAXITEMS; loop++) + for ( int loop = 0; loop < gMAXITEMS_READ; ++loop ) { - if(Item[loop].usItemClass == IC_AMMO) + if(Item[loop].usItemClass & IC_AMMO) { if(Magazine[Item[loop].ubClassIndex].ubCalibre == Weapon[pObjUsed->usItem].ubCalibre && Magazine[Item[loop].ubClassIndex].ubAmmoType == Magazine[Item[pObj->usItem].ubClassIndex].ubAmmoType && Magazine[Item[loop].ubClassIndex].ubMagSize == GetMagSize(pObjUsed) && Magazine[Item[loop].ubClassIndex].ubMagType < AMMO_BOX ) + { newItem = loop; + break; + } } } //Create a stack of up to 5 "newItem" clips tempStack.initialize(); clipCreated = false; ubShotsLeft = (*pObj)[0]->data.ubShotsLeft; - for(UINT8 clip = 0; clip < 5; clip++) + for(UINT8 clip = 0; clip < 5; ++clip) { magSize = GetMagSize(pObjUsed); if(ubShotsLeft < magSize) @@ -7486,8 +7572,6 @@ UINT16 UseKitPoints( OBJECTTYPE * pObj, UINT16 usPoints, SOLDIERTYPE *pSoldier ) UINT16 MagazineClassIndexToItemType(UINT16 usMagIndex) { - UINT16 usLoop; - // Note: if any ammo items in the item table are separated from the main group, // this function will have to be rewritten to scan the item table for an item // with item class ammo, which has class index usMagIndex @@ -7495,13 +7579,8 @@ UINT16 MagazineClassIndexToItemType(UINT16 usMagIndex) // WANNE: Now ammo can be inserted anywhere in Items.xml (before only on index > 70 [FIRST_AMMO] (fix by Realist) //for (usLoop = FIRST_AMMO; usLoop < MAXITEMS; usLoop++) - for (usLoop = 0; usLoop < MAXITEMS; usLoop++) + for ( UINT16 usLoop = 0; usLoop < gMAXITEMS_READ; ++usLoop ) { - if ( Item[usLoop].usItemClass == 0 ) - { - DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String( "MagazineClassIndexToItemType: breaking at index %d", usLoop ) ); - break; - } if (Item[usLoop].ubClassIndex == usMagIndex && Item[usLoop].usItemClass == IC_AMMO ) { DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String( "MagazineClassIndexToItemType: return %d", usLoop ) ); @@ -7903,7 +7982,7 @@ BOOLEAN CreateItem( UINT16 usItem, INT16 bStatus, OBJECTTYPE * pObj ) DebugMsg(TOPIC_JA2,DBG_LEVEL_3,String("CreateItem: usItem = %d",usItem)); BOOLEAN fRet; - if (usItem >= MAXITEMS) + if ( usItem >= gMAXITEMS_READ ) { DebugBreakpoint(); return( FALSE ); @@ -9925,23 +10004,23 @@ void TurnOffXRayEffects( SOLDIERTYPE * pSoldier ) #ifdef JA2TESTVERSION void DumpItemsList( void ) { - CHAR8 zPrintFileName[60]; - FILE *FDump; + CHAR8 zPrintFileName[60]; + FILE *FDump; UINT16 usItem; INVTYPE *pItem; - // open output file + // open output file strcpy(zPrintFileName, "ItemDump.txt"); - FDump = fopen(zPrintFileName, "wt"); + FDump = fopen(zPrintFileName, "wt"); - if (FDump == NULL) - return; + if (FDump == NULL) + return; // print headings fprintf(FDump, " ITEM COOLNESS VALUE\n"); fprintf(FDump, "============================ ======== =====\n"); - for( usItem = 0; usItem < MAXITEMS; usItem++ ) + for ( usItem = 0; usItem < MAXITEMS; ++usItem ) { pItem= &( Item[ usItem ] ); @@ -9951,7 +10030,7 @@ void DumpItemsList( void ) } } - fclose(FDump); + fclose(FDump); } #endif // JA2TESTVERSION @@ -10765,11 +10844,12 @@ INT16 GetRateOfFireBonus( OBJECTTYPE * pObj ) { INT16 bonus=0; - if (pObj->exists() == true) { - if( (MAXITEMS <= pObj->usItem) || (MAXITEMS <= (*pObj)[0]->data.gun.usGunAmmoItem) ) + if ( pObj->exists() ) + { + if ( (gMAXITEMS_READ <= pObj->usItem) || (gMAXITEMS_READ <= (*pObj)[0]->data.gun.usGunAmmoItem) ) { - DebugMsg(TOPIC_JA2, DBG_LEVEL_1, String("GetRateOfFireBonus would crash: pObj->usItem=%d or (*pObj)[0]->data.gun.usGunAmmoItem=%d ist higher than max %d", pObj->usItem, (*pObj)[0]->data.gun.usGunAmmoItem, MAXITEMS )); - ScreenMsg( MSG_FONT_RED, MSG_DEBUG, L"GetRateOfFireBonus would crash: pObj->usItem=%d or (*pObj)[0]->data.gun.usGunAmmoItem=%d ist higher than max %d", pObj->usItem, (*pObj)[0]->data.gun.usGunAmmoItem, MAXITEMS ); + DebugMsg( TOPIC_JA2, DBG_LEVEL_1, String( "GetRateOfFireBonus would crash: pObj->usItem=%d or (*pObj)[0]->data.gun.usGunAmmoItem=%d ist higher than max %d", pObj->usItem, (*pObj)[0]->data.gun.usGunAmmoItem, gMAXITEMS_READ ) ); + ScreenMsg( MSG_FONT_RED, MSG_DEBUG, L"GetRateOfFireBonus would crash: pObj->usItem=%d or (*pObj)[0]->data.gun.usGunAmmoItem=%d ist higher than max %d", pObj->usItem, (*pObj)[0]->data.gun.usGunAmmoItem, gMAXITEMS_READ ); AssertMsg( 0, "GetRateOfFireBonus would crash" ); return 0; /* cannot calculate Bonus, this only happens sometimes in FULLSCREEN */ } @@ -10777,8 +10857,10 @@ INT16 GetRateOfFireBonus( OBJECTTYPE * pObj ) bonus = BonusReduceMore( Item[pObj->usItem].rateoffirebonus, (*pObj)[0]->data.objectStatus ); bonus += Item[(*pObj)[0]->data.gun.usGunAmmoItem].rateoffirebonus ; - for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if(iter->exists()){ + for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) + { + if(iter->exists()) + { bonus += BonusReduceMore( Item[iter->usItem].rateoffirebonus, (*iter)[0]->data.objectStatus ); } } @@ -11982,15 +12064,18 @@ INT16 GetAttachedArmourBonus( OBJECTTYPE * pObj ) INT16 GetBulletSpeedBonus( OBJECTTYPE * pObj ) { INT16 bonus = 0; - if (pObj->exists() == true) { - bonus = Item[pObj->usItem].bulletspeedbonus ; - bonus += Item[(*pObj)[0]->data.gun.usGunAmmoItem].bulletspeedbonus ; + if (pObj->exists() ) + { + bonus = Item[pObj->usItem].bulletspeedbonus; + bonus += Item[(*pObj)[0]->data.gun.usGunAmmoItem].bulletspeedbonus; - for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { + for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) + { if(iter->exists()) bonus = bonus +Item[iter->usItem].bulletspeedbonus ; } } + return( bonus ); } @@ -12205,9 +12290,10 @@ INT8 FindLocksmithKit( SOLDIERTYPE * pSoldier ) INT8 FindWalkman( SOLDIERTYPE * pSoldier ) { - for (INT8 bLoop = BODYPOSSTART; bLoop < BODYPOSFINAL; bLoop++) + for (INT8 bLoop = BODYPOSSTART; bLoop < BODYPOSFINAL; ++bLoop) { - if (pSoldier->inv[bLoop].exists() == true) { + if (pSoldier->inv[bLoop].exists() ) + { if (Item[pSoldier->inv[bLoop].usItem].walkman ) { return( bLoop ); @@ -12252,16 +12338,14 @@ UINT16 LowestLaunchableCoolness(UINT16 launcherIndex) UINT16 i = 0; UINT16 lowestCoolness = 999; - for( i = 0; i < MAXITEMS; ++i ) + for ( i = 0; i < gMAXITEMS_READ; ++i ) { - if ( Item[i].usItemClass == 0 ) - break; - if( ValidLaunchable( i, launcherIndex ) && ItemIsLegal(i) && Item[i].ubCoolness <= lowestCoolness ) { lowestCoolness = Item[i].ubCoolness; } } + return lowestCoolness; } @@ -12312,7 +12396,7 @@ UINT16 PickARandomLaunchable(UINT16 itemIndex) UINT16 maxcoolness = max( HighestPlayerProgressPercentage() / 10, lowestCoolness ); std::vector legalvec; - for ( UINT16 i = 0; i < MAXITEMS; ++i ) + for ( UINT16 i = 0; i < gMAXITEMS_READ; ++i ) { if ( Item[i].usItemClass == 0 ) break; @@ -12338,6 +12422,7 @@ UINT16 PickARandomLaunchable(UINT16 itemIndex) return 0; } + INT16 GetCamoBonus( OBJECTTYPE * pObj ) { INT16 bonus = 0; @@ -12395,9 +12480,9 @@ INT16 GetWornCamo( SOLDIERTYPE * pSoldier ) INT8 bLoop; INT16 ttl=0; - for (bLoop = HELMETPOS; bLoop <= LEGPOS; bLoop++) + for (bLoop = HELMETPOS; bLoop <= LEGPOS; ++bLoop) { - if ( pSoldier->inv[bLoop].exists() == true ) + if ( pSoldier->inv[bLoop].exists() ) { ttl += GetCamoBonus(&pSoldier->inv[bLoop]); if ( UsingNewInventorySystem() ) @@ -12420,9 +12505,9 @@ INT16 GetWornCamo( SOLDIERTYPE * pSoldier ) } // CHRISL: Add additional loop for LBE items while using new inventory system - if((UsingNewInventorySystem() == true)) + if( UsingNewInventorySystem() ) { - for (bLoop = VESTPOCKPOS; bLoop <= BPACKPOCKPOS; bLoop++) + for (bLoop = VESTPOCKPOS; bLoop <= BPACKPOCKPOS; ++bLoop) { if ( pSoldier->inv[bLoop].exists() == true ) ttl += GetCamoBonus(&pSoldier->inv[bLoop]); @@ -12444,9 +12529,9 @@ INT16 GetWornUrbanCamo( SOLDIERTYPE * pSoldier ) INT8 bLoop; INT16 ttl=0; - for (bLoop = HELMETPOS; bLoop <= LEGPOS; bLoop++) + for (bLoop = HELMETPOS; bLoop <= LEGPOS; ++bLoop) { - if ( pSoldier->inv[bLoop].exists() == true ) + if ( pSoldier->inv[bLoop].exists() ) { ttl += GetUrbanCamoBonus(&pSoldier->inv[bLoop]); if ( UsingNewInventorySystem() ) @@ -12469,9 +12554,9 @@ INT16 GetWornUrbanCamo( SOLDIERTYPE * pSoldier ) } // CHRISL: Add additional loop for LBE items while using new inventory system - if((UsingNewInventorySystem() == true)) + if( UsingNewInventorySystem() ) { - for (bLoop = VESTPOCKPOS; bLoop <= BPACKPOCKPOS; bLoop++) + for (bLoop = VESTPOCKPOS; bLoop <= BPACKPOCKPOS; ++bLoop) { if ( pSoldier->inv[bLoop].exists() == true ) ttl += GetUrbanCamoBonus(&pSoldier->inv[bLoop]); @@ -12541,7 +12626,7 @@ INT16 GetWornSnowCamo( SOLDIERTYPE * pSoldier ) INT8 bLoop; INT16 ttl=0; - for (bLoop = HELMETPOS; bLoop <= LEGPOS; bLoop++) + for (bLoop = HELMETPOS; bLoop <= LEGPOS; ++bLoop) { if ( pSoldier->inv[bLoop].exists() == true ) { @@ -12647,9 +12732,9 @@ void ApplyEquipmentBonuses(SOLDIERTYPE * pSoldier) UINT16 GetFirstExplosiveOfType(UINT16 expType) { - for (int i=0;iinv[bLoop].exists() == true ) + if ( pSoldier->inv[bLoop].exists() ) ttl += GetStealthBonus(&pSoldier->inv[bLoop]); } @@ -13734,9 +13819,7 @@ INT16 GetBestLaserRange( OBJECTTYPE * pObj ) // HEADROCK: This function determines the bipod bonii of the gun or its attachments INT16 GetBipodBonus( OBJECTTYPE * pObj ) { - INT16 bonus=0; - - bonus = Item[pObj->usItem].bipod; + INT16 bonus = Item[pObj->usItem].bipod; for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter){ if(iter->exists()) @@ -13811,11 +13894,10 @@ INT16 GetItemVisionRangeBonus( OBJECTTYPE * pObj, INT16 VisionType ) UINT8 GetItemPercentTunnelVision( OBJECTTYPE * pObj ) { - UINT8 bonus = 0; + UINT8 bonus = Item[ pObj->usItem ].percenttunnelvision; - bonus += Item[ pObj->usItem ].percenttunnelvision; - - for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { + for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) + { if(iter->exists()) bonus += Item[iter->usItem].percenttunnelvision; } @@ -13832,7 +13914,8 @@ INT16 GetItemHearingRangeBonus( OBJECTTYPE * pObj ) bonus += Item[ pObj->usItem ].hearingrangebonus; - for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { + for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) + { if(iter->exists()) bonus += Item[ iter->usItem ].hearingrangebonus; } @@ -13853,12 +13936,14 @@ BOOLEAN IsFlashSuppressorAlt( OBJECTTYPE * pObj ) if ( Item[(*pObj)[0]->data.gun.usGunAmmoItem].hidemuzzleflash ) return TRUE; - for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if (Item[iter->usItem].hidemuzzleflash && iter->exists() ) + for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) + { + if ( iter->exists( ) && Item[iter->usItem].hidemuzzleflash ) { return( TRUE ); } } + return( FALSE ); } @@ -13869,7 +13954,8 @@ INT16 GetBasicStealthBonus( OBJECTTYPE * pObj ) if ( pObj->exists() == true ) { bonus = Item[pObj->usItem].stealthbonus; - for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { + for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) + { if(iter->exists()) bonus += (INT16) Item[iter->usItem].stealthbonus; } @@ -13889,11 +13975,11 @@ INT32 GetGunAccuracy( OBJECTTYPE *pObj ) accuracyheatmultiplicator = max(0.0f, 1.0f - accuracymalus); } - if(UsingNewCTHSystem() == false) + if ( !UsingNewCTHSystem() ) return( (INT32)(accuracyheatmultiplicator * Weapon[pObj->usItem].bAccuracy) ); INT32 bonus = 0; - if ( pObj->exists() == true ) + if ( pObj->exists() ) { bonus = (INT32)(accuracyheatmultiplicator * Weapon[Item[pObj->usItem].uiIndex].nAccuracy); bonus = (bonus * (*pObj)[0]->data.gun.bGunStatus) / 100; @@ -13922,7 +14008,7 @@ INT32 GetGunAccuracy( OBJECTTYPE *pObj ) INT32 GetAccuracyModifier( OBJECTTYPE *pObj ) { INT32 bonus = 0; - if ( pObj->exists() == true && UsingNewCTHSystem() == true ) + if ( pObj->exists() && UsingNewCTHSystem() ) { bonus += Item[ pObj->usItem ].percentaccuracymodifier; @@ -13945,25 +14031,25 @@ INT32 GetAccuracyModifier( OBJECTTYPE *pObj ) // CHRISL: Carrying an empty backpack in a none BACKPACKPOS location shoudln't be an issue. INT8 FindBackpackOnSoldier( SOLDIERTYPE * pSoldier ) { - INT8 bLoop; - - for (bLoop = 0; bLoop < NUM_INV_SLOTS ; bLoop++) + for ( INT8 bLoop = 0; bLoop < NUM_INV_SLOTS; ++bLoop ) { if (pSoldier->inv[bLoop].exists()) { if( bLoop == BPACKPOCKPOS ) return( bLoop ); - if (Item[pSoldier->inv[bLoop].usItem].usItemClass == IC_LBEGEAR && + + if (Item[pSoldier->inv[bLoop].usItem].usItemClass & IC_LBEGEAR && LoadBearingEquipment[Item[pSoldier->inv[bLoop].usItem].ubClassIndex].lbeClass == BACKPACK) { - for (INT8 bLoop2 = 0; bLoop2 < pSoldier->inv[bLoop].ubNumberOfObjects; bLoop2++) + for (INT8 bLoop2 = 0; bLoop2 < pSoldier->inv[bLoop].ubNumberOfObjects; ++bLoop2) { - if(pSoldier->inv[bLoop].IsActiveLBE(bLoop2) == true) + if ( pSoldier->inv[bLoop].IsActiveLBE(bLoop2) ) return( bLoop ); } } } } + return( ITEM_NOT_FOUND ); } @@ -14060,7 +14146,7 @@ INT16 ReduceCamoFromSoldier( SOLDIERTYPE * pSoldier, INT16 iCamoToRemove, INT16 if ( iCamoToRemovePart < 0 ) iCamoToRemovePart = 0; - for (i = 0; i < 4; i++ ) // 4 times should be enough, a little paranoya here + for (i = 0; i < 4; ++i ) // 4 times should be enough, a little paranoya here { // first, try to reduce jungle camo if ( ((iCamoToRemove / (1 + iCamoToRemovePart)) <= pSoldier->bCamo) && (pSoldier->bCamo > 0) && (iCamoToSkip != 1) ) @@ -14372,50 +14458,59 @@ BOOLEAN HasAttachmentOfClass( OBJECTTYPE * pObj, UINT32 aFlag ) return( FALSE ); } //DBrot: calculate the volume already taken up by other pouches attached to this carrier -UINT8 GetVolumeAlreadyTaken(OBJECTTYPE * pObj, INT16 exceptSlot){ +UINT8 GetVolumeAlreadyTaken(OBJECTTYPE * pObj, INT16 exceptSlot) +{ UINT8 sum=0; if ( pObj->exists() ) { std::vector usAttachmentSlotIndexVector = GetItemSlots(pObj); OBJECTTYPE* pAttachment; - UINT16 slotCount; - for (slotCount = 0; slotCount < usAttachmentSlotIndexVector.size(); slotCount++ ){ + for ( UINT16 slotCount = 0; slotCount < usAttachmentSlotIndexVector.size( ); ++slotCount ) + { if( slotCount == exceptSlot) continue; pAttachment = (*pObj)[0]->GetAttachmentAtIndex(slotCount); - if(pAttachment->exists() && Item[pAttachment->usItem].usItemClass == IC_LBEGEAR){ + if(pAttachment->exists() && Item[pAttachment->usItem].usItemClass == IC_LBEGEAR) + { sum += LBEPocketType[GetFirstPocketOnItem(pAttachment->usItem)].pVolume; } } } + return sum; } //DBrot: search the attachments for a pocket INT16 GetPocketFromAttachment(OBJECTTYPE * pObj, UINT8 pMap){ std::vector usAttachmentSlotIndexVector = GetItemSlots(pObj); OBJECTTYPE* pAttachment; - UINT16 slotCount; - for (slotCount = 0; slotCount < usAttachmentSlotIndexVector.size(); slotCount++ ){ - if(AttachmentSlots[usAttachmentSlotIndexVector[slotCount]].ubPocketMapping -1 == pMap){ + for ( UINT16 slotCount = 0; slotCount < usAttachmentSlotIndexVector.size( ); ++slotCount ) + { + if(AttachmentSlots[usAttachmentSlotIndexVector[slotCount]].ubPocketMapping -1 == pMap) + { pAttachment = (*pObj)[0]->GetAttachmentAtIndex(slotCount); - if(pAttachment->exists() && Item[pAttachment->usItem].usItemClass == IC_LBEGEAR){ + if(pAttachment->exists() && Item[pAttachment->usItem].usItemClass == IC_LBEGEAR) + { return(GetFirstPocketOnItem(pAttachment->usItem)); - } } } + return 0; } -UINT8 GetFirstPocketOnItem(UINT16 usIndex){ - UINT8 pPocket = 0; - for(UINT8 i = 0; i < LoadBearingEquipment[Item[usIndex].ubClassIndex].lbePocketIndex.size(); i++){ - pPocket = LoadBearingEquipment[Item[usIndex].ubClassIndex].lbePocketIndex[i]; - if(pPocket){ - return pPocket; +UINT8 GetFirstPocketOnItem(UINT16 usIndex) +{ + UINT8 pocket = 0; + for(UINT8 i = 0; i < LoadBearingEquipment[Item[usIndex].ubClassIndex].lbePocketIndex.size(); ++i) + { + pocket = LoadBearingEquipment[Item[usIndex].ubClassIndex].lbePocketIndex[i]; + if ( pocket ) + { + return pocket; } } - return pPocket; + + return pocket; } extern void HandleSight(SOLDIERTYPE *pSoldier, UINT8 ubSightFlags); @@ -14473,7 +14568,7 @@ BOOLEAN OBJECTTYPE::TransformObject( SOLDIERTYPE * pSoldier, UINT8 ubStatusIndex } // Read all result items for this transformation. Record them into an array. - for (UINT32 curResult = 0; curResult < MAX_NUM_TRANSFORMATION_RESULTS; curResult++) + for (UINT32 curResult = 0; curResult < MAX_NUM_TRANSFORMATION_RESULTS; ++curResult) { if (Transform->usResult[curResult] > 0) { @@ -14485,7 +14580,7 @@ BOOLEAN OBJECTTYPE::TransformObject( SOLDIERTYPE * pSoldier, UINT8 ubStatusIndex usResult[curResult] = rdresult; // Count the number of valid result items - iNumResults++; + ++iNumResults; } } @@ -14553,7 +14648,7 @@ BOOLEAN OBJECTTYPE::TransformObject( SOLDIERTYPE * pSoldier, UINT8 ubStatusIndex attachmentList unattachableList; this->usItem = usResult[0]; // Repeat for each object in the stack. - for ( UINT8 x = 0; x < this->ubNumberOfObjects; x++ ) + for ( UINT8 x = 0; x < this->ubNumberOfObjects; ++x ) { unattachableList = ReInitMergedItem(pSoldier, this, usOldItem, x); } @@ -14568,7 +14663,7 @@ BOOLEAN OBJECTTYPE::TransformObject( SOLDIERTYPE * pSoldier, UINT8 ubStatusIndex UINT32 uiNewClass = Item[this->usItem].usItemClass; // Flugente: if the new item is a food item (and the old one wasn't), we define it to be fresh, so adjust its temperature - if ( Item[usOldItem].foodtype == 0 && Item[this->usItem].foodtype > 0 ) + if ( Item[usOldItem].foodtype == 0 && Item[this->usItem].foodtype > 0 ) (*this)[0]->data.bTemperature = OVERHEATING_MAX_TEMPERATURE; // Make a clone of this object, so that we can point the DescBox to it later if we run into any problems. @@ -14661,7 +14756,7 @@ BOOLEAN OBJECTTYPE::TransformObject( SOLDIERTYPE * pSoldier, UINT8 ubStatusIndex //if (uiOrigClass & IC_LBEGEAR || uiNewClass & IC_LBEGEAR ) if (!fItemInPool) { - for (INT8 bPocket = HELMETPOS; bPocket < NUM_INV_SLOTS; bPocket++) + for (INT8 bPocket = HELMETPOS; bPocket < NUM_INV_SLOTS; ++bPocket) { if (pSoldier->inv[bPocket].exists()) { @@ -14697,27 +14792,34 @@ BOOLEAN OBJECTTYPE::TransformObject( SOLDIERTYPE * pSoldier, UINT8 ubStatusIndex // sector pool. // Iterate through the results array we've constructed earlier. - for (UINT32 x = 1; x < iNumResults; x++) + for (UINT32 x = 1; x < iNumResults; ++x) { - for (UINT32 y = 0; y < ubOrigNumObjects; y++) + for (UINT32 y = 0; y < ubOrigNumObjects; ++y) { // Create the result item. Set its condition to match that of the original. CreateItem( usResult[x], ubOrigStatus, &gTempObject ); //Madd: sometimes we have leftover attachments that couldn't fit on first result, so we try reattaching them here // I am the prince of copy pasta ;) - for (attachmentList::iterator iter = unattachableList.begin(); iter != unattachableList.end();) { - if( ValidItemAttachmentSlot(&gTempObject, iter->usItem, TRUE, FALSE, ubStatusIndex )){ + for (attachmentList::iterator iter = unattachableList.begin(); iter != unattachableList.end();) + { + if( ValidItemAttachmentSlot(&gTempObject, iter->usItem, TRUE, FALSE, ubStatusIndex )) + { //This seems to be rather valid. Can't be 100% sure though. OBJECTTYPE tempAttachment; // Madd: we must recreate the attachments because they may themselves have default inseparable attachments... CreateItem(iter->usItem, (*iter)[0]->data.objectStatus, &tempAttachment); - if(gTempObject.AttachObject(NULL, &tempAttachment, FALSE, ubStatusIndex)){ + if(gTempObject.AttachObject(NULL, &tempAttachment, FALSE, ubStatusIndex)) + { //remove this object from the list, so we don't try to attach it to the next result iter = unattachableList.erase(iter); - } else { + } + else + { ++iter; } - } else { + } + else + { ++iter; } } @@ -14794,7 +14896,7 @@ bool IsAttachmentPointAvailable( OBJECTTYPE * pObject, UINT8 subObject, UINT32 a { if (pObject) { - if (Item[pObject->usItem].ulAvailableAttachmentPoint > 0 && (Item[attachmentID].attachment || Item[attachmentID].usItemClass & IC_GRENADE || Item[attachmentID].usItemClass & IC_BOMB)&& Item[attachmentID].ulAttachmentPoint & GetAvailableAttachmentPoint(pObject, subObject)) + if ( Item[pObject->usItem].ulAvailableAttachmentPoint > 0 && (Item[attachmentID].attachment || Item[attachmentID].usItemClass & (IC_GRENADE | IC_BOMB) ) && Item[attachmentID].ulAttachmentPoint & GetAvailableAttachmentPoint( pObject, subObject ) ) return true; } @@ -14804,19 +14906,19 @@ bool IsAttachmentPointAvailable( OBJECTTYPE * pObject, UINT8 subObject, UINT32 a //Madd: Common Attachment Framework - if we already know the point bool IsAttachmentPointAvailable( UINT64 point, UINT32 attachmentID, BOOLEAN onlyCheckAttachments ) { - if (point > 0 && (!onlyCheckAttachments || (Item[attachmentID].attachment || Item[attachmentID].usItemClass & IC_GRENADE || Item[attachmentID].usItemClass & IC_BOMB)) && Item[attachmentID].ulAttachmentPoint & point) + if ( point > 0 && (!onlyCheckAttachments || (Item[attachmentID].attachment || Item[attachmentID].usItemClass & (IC_GRENADE | IC_BOMB) )) && Item[attachmentID].ulAttachmentPoint & point ) return true; - else - return false; + + return false; } //Madd: Common Attachment Framework, doesn't look at attachments bool IsAttachmentPointAvailable( UINT32 itemID, UINT32 attachmentID ) { - if (Item[itemID].ulAvailableAttachmentPoint > 0 && (Item[attachmentID].attachment || Item[attachmentID].usItemClass & IC_GRENADE || Item[attachmentID].usItemClass & IC_BOMB) && Item[attachmentID].ulAttachmentPoint & Item[itemID].ulAvailableAttachmentPoint) + if ( Item[itemID].ulAvailableAttachmentPoint > 0 && (Item[attachmentID].attachment || Item[attachmentID].usItemClass & (IC_GRENADE | IC_BOMB) ) && Item[attachmentID].ulAttachmentPoint & Item[itemID].ulAvailableAttachmentPoint ) return true; - else - return false; + + return false; } //Madd: Common Attachment Framework, get point value from object + attachments @@ -14828,7 +14930,7 @@ UINT64 GetAvailableAttachmentPoint (OBJECTTYPE * pObject, UINT8 subObject) point = Item[pObject->usItem].ulAvailableAttachmentPoint; for (attachmentList::iterator iter = (*pObject)[subObject]->attachments.begin(); iter != (*pObject)[subObject]->attachments.end(); ++iter) { - if(iter->exists() && Item[iter->usItem].ulAvailableAttachmentPoint > 0 && Item[iter->usItem].attachment ) + if(iter->exists() && Item[iter->usItem].ulAvailableAttachmentPoint && Item[iter->usItem].attachment ) point |= Item[iter->usItem].ulAvailableAttachmentPoint; } } @@ -14862,7 +14964,7 @@ BOOLEAN HasItemFlag( UINT16 usItem, UINT32 aFlag ) BOOLEAN GetFirstItemWithFlag( UINT16* pusItem, UINT32 aFlag ) { register UINT16 i; - for (i = 1; i < MAXITEMS; ++i) + for ( i = 1; i < gMAXITEMS_READ; ++i ) { if ( HasItemFlag(i, aFlag) ) { @@ -15122,13 +15224,13 @@ BOOLEAN GetFirstClothesItemWithSpecificData( UINT16* pusItem, PaletteRepID aPalV if ( !GetPaletteRepIndexFromID(aPalPants, &filler) ) pantsok = TRUE; - // getting the best item isn't straightforward. As combo clothes can be found first, we will search for each item whose clothestype matches, and retreive the loest item that has + // getting the best item isn't straightforward. As combo clothes can be found first, we will search for each item whose clothestype matches, and retrieve the lowest item that has // the lowest clothestype UINT32 bestclothestype = 999999; UINT16 bestitem = 0; register UINT16 i; - for (i = 1; i < MAXITEMS; ++i) + for ( i = 1; i < gMAXITEMS_READ; ++i ) { if ( Item[i].clothestype > 0 ) { diff --git a/Tactical/RandomMerc.cpp b/Tactical/RandomMerc.cpp index 26f73a52..420383b4 100644 --- a/Tactical/RandomMerc.cpp +++ b/Tactical/RandomMerc.cpp @@ -92,7 +92,7 @@ void InitRandomMercs() // HLT DEX AGI STR WIS MRK LDR MEC EXP MED //populate random gear list - for (int i = 0;i < MAXITEMS; i++) + for ( int i = 0; i < gMAXITEMS_READ; ++i ) { INVTYPE* item = &Item[i]; diff --git a/Tactical/Tactical Save.cpp b/Tactical/Tactical Save.cpp index 78e18047..d2c18ebb 100644 --- a/Tactical/Tactical Save.cpp +++ b/Tactical/Tactical Save.cpp @@ -1105,7 +1105,7 @@ void HandleAllReachAbleItemsInTheSector( INT16 sSectorX, INT16 sSectorY, INT8 bS { sGridNo2 = gMapInformation.sIsolatedGridNo; - for( uiCounter = gTacticalStatus.Team[ gbPlayerNum ].bFirstID; uiCounter < gTacticalStatus.Team[ gbPlayerNum ].bLastID; uiCounter++ ) + for( uiCounter = gTacticalStatus.Team[ gbPlayerNum ].bFirstID; uiCounter < gTacticalStatus.Team[ gbPlayerNum ].bLastID; ++uiCounter ) { pSoldier = MercPtrs[ uiCounter ]; if ( pSoldier && pSoldier->bActive && pSoldier->stats.bLife > 0 && pSoldier->sSectorX == sSectorX && pSoldier->sSectorY == sSectorY && pSoldier->bSectorZ == bSectorZ ) @@ -1122,12 +1122,11 @@ void HandleAllReachAbleItemsInTheSector( INT16 sSectorX, INT16 sSectorY, INT8 bS { sGridNo2 = NOWHERE; } - } GlobalItemsReachableTest( sGridNo, sGridNo2 ); - for( uiCounter = 0; uiCounter < guiNumWorldItems; uiCounter++ ) + for( uiCounter = 0; uiCounter < guiNumWorldItems; ++uiCounter ) { // reset reachablity fReachable = FALSE; diff --git a/Tactical/Turn Based Input.cpp b/Tactical/Turn Based Input.cpp index 9d01b92f..88c5682f 100644 --- a/Tactical/Turn Based Input.cpp +++ b/Tactical/Turn Based Input.cpp @@ -3457,10 +3457,11 @@ void GetKeyboardInput( UINT32 *puiNewEvent ) { if(CHEATER_CHEAT_LEVEL()) { - for(UINT16 i=FIRST_WEAPON; iReLoadSoldierAnimationDueToHandItemChange( usOldHandItem, pSoldier->inv[HANDPOS].usItem ); DirtyMercPanelInterface( pSoldier, DIRTYLEVEL2 ); - } } @@ -8039,11 +8039,8 @@ void HandleTacticalAmmoCrates( UINT8 magType ) //we have a valid, ammo item. Look through Items.xml and see if we have an ammo crate for // this ammo type - for(int iLoop = 0; iLoop < MAXITEMS; iLoop++) + for ( int iLoop = 0; iLoop < gMAXITEMS_READ; ++iLoop ) { - if (Item[iLoop].usItemClass == 0) - break; //no more valid items after this point - //if ammo crate && calibers match && Ammo Types match if(Item[iLoop].usItemClass == IC_AMMO && Magazine[Item[iLoop].ubClassIndex].ubMagType == magType && Magazine[Item[iLoop].ubClassIndex].ubCalibre == Magazine[Item[worldItem].ubClassIndex].ubCalibre && Magazine[Item[iLoop].ubClassIndex].ubAmmoType == Magazine[Item[worldItem].ubClassIndex].ubAmmoType) { @@ -8056,7 +8053,7 @@ void HandleTacticalAmmoCrates( UINT8 magType ) if(crateItem != 0) { //look through world items first - for(unsigned int loop=0; loop < guiNumWorldItems; loop++) + for(unsigned int loop=0; loop < guiNumWorldItems; ++loop) { if(gWorldItems[loop].object.usItem == crateItem) { @@ -8121,7 +8118,7 @@ void HandleTacticalAmmoCrates( UINT8 magType ) //MM: loop through ammo multiple times, as boxes and crates may take a few passes to fill ammoPresent = false; - for(unsigned int wItem = 0; wItem < guiNumWorldItems; wItem++) + for(unsigned int wItem = 0; wItem < guiNumWorldItems; ++wItem) { if(Item[gWorldItems[wItem].object.usItem].usItemClass == IC_AMMO && gWorldItems[wItem].bVisible == TRUE && gWorldItems[wItem].fExists && (gWorldItems[wItem].usFlags & WORLD_ITEM_REACHABLE) && !(gWorldItems[wItem].usFlags & WORLD_ITEM_ARMED_BOMB)) { @@ -8142,7 +8139,7 @@ void HandleTacticalAmmoCrates( UINT8 magType ) void HandleTacticalInventoryMenu( void ) { - for( INT32 cnt = 0; cnt < TACTICAL_INVENTORY_DIALOG_NUM; cnt++) + for( INT32 cnt = 0; cnt < TACTICAL_INVENTORY_DIALOG_NUM; ++cnt) { wcscpy( gzUserDefinedButton[cnt], szTacticalInventoryDialogString[cnt+1] ); gzUserDefinedButtonColor[cnt] = 0; @@ -8218,7 +8215,7 @@ void TacticalInventoryMessageBoxCallBack( UINT8 ubExitValue ) void HandleTacticalCoverMenu( void ) { - for( INT32 cnt = 0; cnt < TACTICAL_COVER_DIALOG_NUM; cnt++) + for( INT32 cnt = 0; cnt < TACTICAL_COVER_DIALOG_NUM; ++cnt) { wcscpy( gzUserDefinedButton[cnt], szTacticalCoverDialogString[cnt+1] ); gzUserDefinedButtonColor[cnt] = 0; @@ -8363,7 +8360,7 @@ void HandleTacticalTransformItem( void ) BOOLEAN FindTransformation( UINT16 usItem, TransformInfoStruct **pTransformation ) { // find transformation - for (INT32 x = 0; x < MAXITEMS; x++) + for ( INT32 x = 0; x < gMAXITEMS_READ; ++x ) { if ( Transform[x].usItem == (UINT16)-1 ) { @@ -8389,7 +8386,7 @@ void HandleTacticalMoveItems( void ) if ( GetSoldier( &pSoldier, gusSelectedSoldier ) ) { - for ( UINT32 uiLoop = 0; uiLoop < guiNumWorldItems; uiLoop++ ) //for all items in sector + for ( UINT32 uiLoop = 0; uiLoop < guiNumWorldItems; ++uiLoop ) //for all items in sector { if ( (gWorldItems[ uiLoop ].bVisible == TRUE) && (gWorldItems[ uiLoop ].fExists) && (gWorldItems[ uiLoop ].usFlags & WORLD_ITEM_REACHABLE) && !(gWorldItems[ uiLoop ].usFlags & WORLD_ITEM_ARMED_BOMB) && (gWorldItems[ uiLoop ].sGridNo != pSoldier->sGridNo) )//item exists and is reachable and is not already on soldiers tile { diff --git a/Tactical/Weapons.cpp b/Tactical/Weapons.cpp index 9bb06236..961eb886 100644 --- a/Tactical/Weapons.cpp +++ b/Tactical/Weapons.cpp @@ -816,7 +816,7 @@ BOOLEAN WriteWeaponStats() UINT32 cnt; FilePrintf(hFile,"\r\n"); - for(cnt = 0;cnt < MAXITEMS;cnt++) + for(cnt = 0;cnt < MAXITEMS; ++cnt) { CHAR8 * szRemainder = Weapon[cnt].szWeaponName; //the remaining string to be output (for making valid XML) diff --git a/TacticalAI/AIMain.cpp b/TacticalAI/AIMain.cpp index f7ba195e..76be1e48 100644 --- a/TacticalAI/AIMain.cpp +++ b/TacticalAI/AIMain.cpp @@ -1573,18 +1573,15 @@ void AIDecideRadioAnimation( SOLDIERTYPE *pSoldier ) UINT32 GetTankCannonIndex() { - UINT32 tankCannonIndex = 0; - - for (UINT32 i = 0; i < MAXITEMS; i++) + for ( UINT32 i = 0; i < gMAXITEMS_READ; ++i ) { if (Item[i].cannon) { - tankCannonIndex = Item[i].uiIndex; - break; + return Item[i].uiIndex; } } - return tankCannonIndex; + return 0; } diff --git a/Utils/Text Utils.cpp b/Utils/Text Utils.cpp index f57a0979..65900d55 100644 --- a/Utils/Text Utils.cpp +++ b/Utils/Text Utils.cpp @@ -971,15 +971,12 @@ BOOLEAN LoadShortNameItemInfo(UINT16 ubIndex, STR16 pNameString ) void LoadAllItemNames( void ) { - UINT16 usLoop; - - for (usLoop = 0; usLoop < MAXITEMS; usLoop++) + for ( UINT16 usLoop = 0; usLoop < gMAXITEMS_READ; ++usLoop ) { LoadItemInfo( usLoop, ItemNames[usLoop], NULL ); // Load short item info LoadShortNameItemInfo( usLoop, ShortItemNames[usLoop] ); - } } diff --git a/Utils/XML_Items.cpp b/Utils/XML_Items.cpp index 95dd03b8..bda6fbf9 100644 --- a/Utils/XML_Items.cpp +++ b/Utils/XML_Items.cpp @@ -38,6 +38,9 @@ #include "store inventory.h" #endif +// Flugente: in order not to loop over MAXITEMS items if we only have a few thousand, remember the actual number of items in the xml +UINT32 gMAXITEMS_READ = 0; + struct { PARSE_STAGE curElement; @@ -381,6 +384,9 @@ itemEndElementHandle(void *userData, const XML_Char *name) InheritStanceModifiers( pData ); pData->curArray[pData->curItem.uiIndex] = pData->curItem; //write the item into the table + + // Flugente: new item -> read items increase + gMAXITEMS_READ = pData->curItem.uiIndex; } else if ( sizeof(pData->curItem.szItemName)>0 && localizedTextOnly ) { @@ -1477,10 +1483,10 @@ itemEndElementHandle(void *userData, const XML_Char *name) pData->curItem.usItemFlag |= DISEASEPROTECTION_HAND; } - pData->maxReadDepth--; + --pData->maxReadDepth; } - pData->currentDepth--; + --pData->currentDepth; } @@ -1519,11 +1525,9 @@ BOOLEAN ReadInItemStats(STR fileName, BOOLEAN localizedVersion ) lpcBuffer[uiFSize] = 0; //add a null terminator FileClose( hFile ); - XML_SetElementHandler(parser, itemStartElementHandle, itemEndElementHandle); XML_SetCharacterDataHandler(parser, itemCharacterDataHandle); - memset(&pData,0,sizeof(pData)); pData.curArray = Item; @@ -1531,7 +1535,6 @@ BOOLEAN ReadInItemStats(STR fileName, BOOLEAN localizedVersion ) XML_SetUserData(parser, &pData); - if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE)) { CHAR8 errorBuf[511]; @@ -1542,21 +1545,14 @@ BOOLEAN ReadInItemStats(STR fileName, BOOLEAN localizedVersion ) MemFree(lpcBuffer); return FALSE; } + + // item read was x -> x+1 items + ++gMAXITEMS_READ; MemFree(lpcBuffer); - XML_ParserFree(parser); - - //DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("done reading item stats")); - //CHAR16 str[512]; - //for (int i = 0; i < MAXITEMS; i++) - //{ - // swprintf(str, Item[i].szLongItemName); - // DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("ReadInItemStats: long item name: %s", str)); - //} - return( TRUE ); } BOOLEAN WriteItemStats() @@ -1576,7 +1572,7 @@ BOOLEAN WriteItemStats() CHAR16 strDesc[500]; FilePrintf(hFile,"\r\n"); - for(cnt = 0;cnt < 351;cnt++)//just do the old limit for now + for(cnt = 0;cnt < 351; ++cnt)//just do the old limit for now { LoadShortNameItemInfo( (UINT16)cnt, str );