From 6a8a22aba24fb07e5ab85397a9a867940251d3d9 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Fri, 12 Jun 2026 15:17:15 +0300 Subject: [PATCH] Move iter->exists() check to first --- Strategic/Assignments.cpp | 2 +- Tactical/Arms Dealer Init.cpp | 6 ++--- Tactical/Items.cpp | 42 +++++++++++++++---------------- Tactical/LOS.cpp | 2 +- Tactical/ShopKeeper Interface.cpp | 2 +- Tactical/SoldierTooltips.cpp | 2 +- Tactical/Turn Based Input.cpp | 4 +-- Tactical/UI Cursors.cpp | 2 +- Tactical/Weapons.cpp | 12 ++++----- TacticalAI/Attacks.cpp | 2 +- 10 files changed, 38 insertions(+), 38 deletions(-) diff --git a/Strategic/Assignments.cpp b/Strategic/Assignments.cpp index 969fefe3..9dbb5cfc 100644 --- a/Strategic/Assignments.cpp +++ b/Strategic/Assignments.cpp @@ -5081,7 +5081,7 @@ OBJECTTYPE* FindRepairableItemInSpecificPocket(SOLDIERTYPE * pSoldier, OBJECTTYP // have to check for attachments after... for (attachmentList::iterator iter = (*pObj)[subObject]->attachments.begin(); iter != (*pObj)[subObject]->attachments.end(); ++iter) { // if it's repairable and NEEDS repairing - if ( IsItemRepairable( pSoldier, iter->usItem, (*iter)[subObject]->data.objectStatus, (*iter)[subObject]->data.sRepairThreshold ) && iter->exists() ) { + if ( iter->exists() && IsItemRepairable( pSoldier, iter->usItem, (*iter)[subObject]->data.objectStatus, (*iter)[subObject]->data.sRepairThreshold ) ) { return( &(*iter) ); } } diff --git a/Tactical/Arms Dealer Init.cpp b/Tactical/Arms Dealer Init.cpp index 4793cfe8..7cd5d927 100644 --- a/Tactical/Arms Dealer Init.cpp +++ b/Tactical/Arms Dealer Init.cpp @@ -1423,7 +1423,7 @@ void AddObjectToArmsDealerInventory( UINT8 ubArmsDealer, OBJECTTYPE *pObject ) for (attachmentList::iterator iter = seperateObject[0]->attachments.begin(); iter != seperateObject[0]->attachments.end();) { // ARM: Note: this is only used for selling, not repairs, so attachmentes are seperated when sold to a dealer // If the attachment is detachable - if (! (Item[ iter->usItem ].inseparable ) && iter->exists()) + if (! (iter->exists() && Item[ iter->usItem ].inseparable)) { // add this particular attachment (they can't be imprinted, or themselves have attachments!) AddObjectToArmsDealerInventory( ubArmsDealer, &(*iter) ); @@ -1931,7 +1931,7 @@ UINT32 CalculateObjectItemRepairTime( UINT8 ubArmsDealer, OBJECTTYPE *pItemObjec // add time to repair any attachments on it for (attachmentList::iterator iter = (*pItemObject)[x]->attachments.begin(); iter != (*pItemObject)[x]->attachments.end(); ++iter) { // if damaged and repairable - if ( ( (*iter)[x]->data.objectStatus < 100 ) && CanDealerRepairItem( ubArmsDealer, iter->usItem ) && iter->exists()) + if ( iter->exists() && ( (*iter)[x]->data.objectStatus < 100 ) && CanDealerRepairItem( ubArmsDealer, iter->usItem ) ) { //uiRepairTime += CalculateSimpleItemRepairTime( ubArmsDealer, iter->usItem, (*iter)[x]->data.objectStatus ); uiRepairTime += CalculateObjectItemRepairTime( ubArmsDealer, &(*iter) ); @@ -1988,7 +1988,7 @@ UINT32 CalculateObjectItemRepairCost( UINT8 ubArmsDealer, OBJECTTYPE *pItemObjec // add cost of repairing any attachments on it for (attachmentList::iterator iter = (*pItemObject)[x]->attachments.begin(); iter != (*pItemObject)[x]->attachments.end(); ++iter) { // if damaged and repairable - if ( ( (*iter)[x]->data.objectStatus < 100 ) && CanDealerRepairItem( ubArmsDealer, iter->usItem ) && iter->exists()) + if ( iter->exists() && ( (*iter)[x]->data.objectStatus < 100 ) && CanDealerRepairItem( ubArmsDealer, iter->usItem ) ) { uiRepairCost += CalculateObjectItemRepairCost( ubArmsDealer, &(*iter)); } diff --git a/Tactical/Items.cpp b/Tactical/Items.cpp index 96f6237a..82151081 100644 --- a/Tactical/Items.cpp +++ b/Tactical/Items.cpp @@ -1995,7 +1995,7 @@ OBJECTTYPE* FindAttachment( OBJECTTYPE * pObj, UINT16 usItem, UINT8 subObject ) { if (pObj->exists() == true) { for (attachmentList::iterator iter = (*pObj)[subObject]->attachments.begin(); iter != (*pObj)[subObject]->attachments.end(); ++iter) { - if (iter->usItem == usItem && iter->exists()) + if ( iter->exists() && iter->usItem == usItem ) { return &(*iter); } @@ -2008,7 +2008,7 @@ OBJECTTYPE* FindAttachmentByClass( OBJECTTYPE * pObj, UINT32 uiItemClass, UINT8 { if (pObj->exists() == true) { for (attachmentList::iterator iter = (*pObj)[subObject]->attachments.begin(); iter != (*pObj)[subObject]->attachments.end(); ++iter) { - if (Item[iter->usItem].usItemClass == uiItemClass && iter->exists()) + if ( iter->exists() && Item[iter->usItem].usItemClass == uiItemClass ) { return &(*iter); } @@ -2021,7 +2021,7 @@ OBJECTTYPE* FindAttachmentByAttachmentClass( OBJECTTYPE * pObj, UINT32 uiAttachm { if (pObj->exists() == true) { for (attachmentList::iterator iter = (*pObj)[subObject]->attachments.begin(); iter != (*pObj)[subObject]->attachments.end(); ++iter) { - if (Item[iter->usItem].attachmentclass == uiAttachmentClass && iter->exists()) + if ( iter->exists() && Item[iter->usItem].attachmentclass == uiAttachmentClass ) { return &(*iter); } @@ -2139,7 +2139,7 @@ OBJECTTYPE* FindNonSmokeLaunchableAttachment( OBJECTTYPE * pObj, UINT16 usWeapon if (pObj->exists() == true) { for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if (ValidLaunchable( iter->usItem, usWeapon) && Explosive[Item[iter->usItem].ubClassIndex].ubType != EXPLOSV_SMOKE && iter->exists()) + if ( iter->exists() && ValidLaunchable( iter->usItem, usWeapon) && Explosive[Item[iter->usItem].ubClassIndex].ubType != EXPLOSV_SMOKE ) { return &(*iter); } @@ -10422,7 +10422,7 @@ BOOLEAN NCTHIsScoped( OBJECTTYPE * pObj ) return TRUE; for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if ( Item[iter->usItem].scopemagfactor > 1.0 && iter->exists() ) + if ( iter->exists() && Item[iter->usItem].scopemagfactor > 1.0 ) return TRUE; } } @@ -10441,7 +10441,7 @@ BOOLEAN IsScoped( OBJECTTYPE * pObj ) return TRUE; for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if ( Item[iter->usItem].aimbonus > 0 && iter->exists()) + if ( iter->exists() && Item[iter->usItem].aimbonus > 0 ) return TRUE; } } @@ -10528,7 +10528,7 @@ INT16 GetBaseScopeAimBonus( OBJECTTYPE * pObj, INT32 iRange ) //Search for the most powerful scope we can use. for(attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); iter++) { - if(Item[iter->usItem].aimbonus > bonus && iRange >= Item[iter->usItem].minrangeforaimbonus && iter->exists()) + if( iter->exists() && Item[iter->usItem].aimbonus > bonus && iRange >= Item[iter->usItem].minrangeforaimbonus ) { bonus = Item[iter->usItem].aimbonus; } @@ -10606,7 +10606,7 @@ UINT32 FindRangeBonusAttachment( OBJECTTYPE * pObj ) { if (pObj->exists() == true) { for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if (Item[iter->usItem].rangebonus > 0 && iter->exists()) + if ( iter->exists() && Item[iter->usItem].rangebonus > 0 ) { return( Item[iter->usItem].uiIndex ); } @@ -10627,7 +10627,7 @@ INT16 GetRangeBonus( OBJECTTYPE * pObj ) bonus += Item[(*pObj)[0]->data.gun.usGunAmmoItem].rangebonus; for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if ( !ItemIsDuckbill(iter->usItem) || (ItemIsDuckbill(iter->usItem) && (*pObj)[0]->data.gun.ubGunAmmoType == AMMO_BUCKSHOT ) && iter->exists()) + if ( iter->exists() && !ItemIsDuckbill(iter->usItem) || (ItemIsDuckbill(iter->usItem) && (*pObj)[0]->data.gun.ubGunAmmoType == AMMO_BUCKSHOT ) ) bonus += BonusReduce( Item[iter->usItem].rangebonus, (*iter)[0]->data.objectStatus ); } } @@ -12053,7 +12053,7 @@ BOOLEAN HasThermalOptics( SOLDIERTYPE * pSoldier ) OBJECTTYPE* pObj = &pSoldier->inv[HANDPOS]; if (pObj->exists() == true) { for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if (ItemIsThermalOptics(iter->usItem) && iter->exists() ) + if ( iter->exists() && ItemIsThermalOptics(iter->usItem) ) return TRUE; } } @@ -12110,7 +12110,7 @@ BOOLEAN IsDuckbill( OBJECTTYPE * pObj ) return TRUE; for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if (ItemIsDuckbill(iter->usItem) && iter->exists() ) + if ( iter->exists() && ItemIsDuckbill(iter->usItem) ) { return( TRUE ); } @@ -12161,7 +12161,7 @@ BOOLEAN IsDetonatorAttached( OBJECTTYPE * pObj ) // return TRUE; for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if ( IsAttachmentClass( iter->usItem, AC_DETONATOR ) && iter->exists() ) + if ( iter->exists() && IsAttachmentClass( iter->usItem, AC_DETONATOR ) ) { return( TRUE ); } @@ -12177,7 +12177,7 @@ BOOLEAN IsRemoteDetonatorAttached( OBJECTTYPE * pObj ) // return TRUE; for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if ( IsAttachmentClass( iter->usItem, AC_REMOTEDET ) && iter->exists() ) + if ( iter->exists() && IsAttachmentClass( iter->usItem, AC_REMOTEDET ) ) { return( TRUE ); } @@ -12449,7 +12449,7 @@ OBJECTTYPE* FindAttachedBatteries( OBJECTTYPE * pObj ) { if (pObj->exists() == true) { for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if (ItemIsBatteries(iter->usItem) && iter->exists()) + if ( iter->exists() && ItemIsBatteries(iter->usItem) ) { return( &(*iter) ); } @@ -12681,7 +12681,7 @@ INT16 GetCamoBonus( OBJECTTYPE * pObj ) bonus = (Item[pObj->usItem].camobonus);// * (WEAPON_STATUS_MOD((*pObj)[0]->data.objectStatus) / 100)) ; for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if (!ItemIsCamoKit(iter->usItem) && iter->exists()) + if ( iter->exists() && !ItemIsCamoKit(iter->usItem) ) bonus += (INT16) (Item[iter->usItem].camobonus);// * (WEAPON_STATUS_MOD((*iter)[0]->data.objectStatus) / 100)); } } @@ -12694,7 +12694,7 @@ INT16 GetUrbanCamoBonus( OBJECTTYPE * pObj ) bonus = (Item[pObj->usItem].urbanCamobonus);// * (WEAPON_STATUS_MOD((*pObj)[0]->data.objectStatus) / 100)) ; for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if (!ItemIsCamoKit(iter->usItem) && iter->exists()) + if ( iter->exists() && !ItemIsCamoKit(iter->usItem) ) bonus += (INT16) (Item[iter->usItem].urbanCamobonus);// * (WEAPON_STATUS_MOD((*iter)[0]->data.objectStatus) / 100)); } } @@ -12707,7 +12707,7 @@ INT16 GetDesertCamoBonus( OBJECTTYPE * pObj ) bonus = (Item[pObj->usItem].desertCamobonus);// * (WEAPON_STATUS_MOD((*pObj)[0]->data.objectStatus) / 100)) ; for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if (!ItemIsCamoKit(iter->usItem) && iter->exists()) + if ( iter->exists() && !ItemIsCamoKit(iter->usItem) ) bonus += (INT16) (Item[iter->usItem].desertCamobonus);// * (WEAPON_STATUS_MOD((*iter)[0]->data.objectStatus) / 100)); } } @@ -12720,7 +12720,7 @@ INT16 GetSnowCamoBonus( OBJECTTYPE * pObj ) bonus = (Item[pObj->usItem].snowCamobonus);// * (WEAPON_STATUS_MOD((*pObj)[0]->data.objectStatus) / 100)) ; for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if (!ItemIsCamoKit(iter->usItem) && iter->exists()) + if ( iter->exists() && !ItemIsCamoKit(iter->usItem) ) bonus += (INT16) (Item[iter->usItem].snowCamobonus);// * (WEAPON_STATUS_MOD((*iter)[0]->data.objectStatus) / 100)); } } @@ -13165,7 +13165,7 @@ OBJECTTYPE* FindNightGogglesInInv( SOLDIERTYPE * pSoldier, INT8 * bSlot, BOOLEAN if (searchAllInventory) { for (UINT8 loop = 0; loop < pSoldier->inv[bLoop].ubNumberOfObjects; loop ++){ for (attachmentList::iterator iter = pSoldier->inv[bLoop][loop]->attachments.begin(); iter != pSoldier->inv[bLoop][loop]->attachments.end(); ++iter) { - if ( Item[ iter->usItem ].cavevisionrangebonus > bonusToBeat && Item[ iter->usItem ].usItemClass == IC_FACE && iter->exists() ) { + if ( iter->exists() && Item[ iter->usItem ].cavevisionrangebonus > bonusToBeat && Item[ iter->usItem ].usItemClass == IC_FACE ) { pGoggles = &(*iter); *bSlot = bLoop; *isAttach = TRUE; @@ -14141,7 +14141,7 @@ INT16 GetAverageBestLaserRange( OBJECTTYPE * pObj ) } for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if (Item[iter->usItem].bestlaserrange > 0 && iter->exists()) + if ( iter->exists() && Item[iter->usItem].bestlaserrange > 0 ) { numModifiers++; bonus += (FLOAT) Item[iter->usItem].bestlaserrange; @@ -14167,7 +14167,7 @@ INT16 GetBestLaserRange( OBJECTTYPE * pObj ) } for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if (Item[iter->usItem].bestlaserrange > range && iter->exists()) + if ( iter->exists() && Item[iter->usItem].bestlaserrange > range ) { range = Item[iter->usItem].bestlaserrange; } diff --git a/Tactical/LOS.cpp b/Tactical/LOS.cpp index 3c18abc5..2cee0ede 100644 --- a/Tactical/LOS.cpp +++ b/Tactical/LOS.cpp @@ -171,7 +171,7 @@ INT32 GetSpreadPattern( OBJECTTYPE * pObj ) //If there are attachments, check them. Stop on the first one with something defined. //Dear God, I hate C++ iterators. What a fugly mess. //WarmSteel - I made it even messier ;3 for (attachmentList::iterator iter = pObj[0][0]->attachments.begin(); iter != pObj[0][0]->attachments.end(); ++iter){ - if( (n=Item[ iter->usItem ].spreadPattern) && iter->exists()){ + if( iter->exists() && (n=Item[ iter->usItem ].spreadPattern) ){ //An attachment has it, and it trumps everything, so return it's value. return n;} } diff --git a/Tactical/ShopKeeper Interface.cpp b/Tactical/ShopKeeper Interface.cpp index 3273c51e..85e013f9 100644 --- a/Tactical/ShopKeeper Interface.cpp +++ b/Tactical/ShopKeeper Interface.cpp @@ -3031,7 +3031,7 @@ BOOLEAN RepairIsDone(DEALER_SPECIAL_ITEM* pSpecial) // max condition of all permanent attachments on it for (attachmentList::iterator iter = RepairItem.ItemObject[0]->attachments.begin(); iter != RepairItem.ItemObject[0]->attachments.end(); ++iter) { - if ( CanDealerRepairItem( gbSelectedArmsDealerID, iter->usItem ) && iter->exists()) + if ( iter->exists() && CanDealerRepairItem( gbSelectedArmsDealerID, iter->usItem ) ) { // fix it up (*iter)[0]->data.objectStatus = 100; diff --git a/Tactical/SoldierTooltips.cpp b/Tactical/SoldierTooltips.cpp index f49c877e..6b3a6f4b 100644 --- a/Tactical/SoldierTooltips.cpp +++ b/Tactical/SoldierTooltips.cpp @@ -147,7 +147,7 @@ void SoldierTooltip( SOLDIERTYPE* pSoldier ) { OBJECTTYPE* pObject = &(gusSelectedSoldier->inv[HANDPOS]); for (attachmentList::iterator iter = (*pObject)[0]->attachments.begin(); iter != (*pObject)[0]->attachments.end(); ++iter) { - if ( Item[iter->usItem].visionrangebonus > 0 && iter->exists()) + if ( iter->exists() && Item[iter->usItem].visionrangebonus > 0 ) { fMercIsUsingScope = TRUE; break; diff --git a/Tactical/Turn Based Input.cpp b/Tactical/Turn Based Input.cpp index 78511d2f..0d4739ac 100644 --- a/Tactical/Turn Based Input.cpp +++ b/Tactical/Turn Based Input.cpp @@ -6770,7 +6770,7 @@ void SwapGogglesUniformly(SOLDIERTYPE *pTeamSoldier, BOOLEAN fToNightVision) pObj = &(pTeamSoldier->inv[gear]); for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if ( Item[ iter->usItem ].nightvisionrangebonus > bestBonus && Item[ iter->usItem ].usItemClass == IC_FACE && iter->exists()) + if ( iter->exists() && Item[ iter->usItem ].nightvisionrangebonus > bestBonus && Item[ iter->usItem ].usItemClass == IC_FACE ) { pGoggles = &(*iter); bestBonus = Item[ iter->usItem ].nightvisionrangebonus; @@ -6818,7 +6818,7 @@ void SwapGogglesUniformly(SOLDIERTYPE *pTeamSoldier, BOOLEAN fToNightVision) pObj = &(pTeamSoldier->inv[gear]); for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if ( Item[ iter->usItem ].brightlightvisionrangebonus > bestBonus && Item[ iter->usItem ].usItemClass == IC_FACE && iter->exists()) + if ( iter->exists() && Item[ iter->usItem ].brightlightvisionrangebonus > bestBonus && Item[ iter->usItem ].usItemClass == IC_FACE ) { pGoggles = &(*iter); bestBonus = Item[ iter->usItem ].brightlightvisionrangebonus; diff --git a/Tactical/UI Cursors.cpp b/Tactical/UI Cursors.cpp index 5bf3f397..47078091 100644 --- a/Tactical/UI Cursors.cpp +++ b/Tactical/UI Cursors.cpp @@ -2081,7 +2081,7 @@ UINT8 HandleNonActivatedTossCursor( SOLDIERTYPE *pSoldier, INT32 sGridNo, BOOLEA //sevenfm this should be checked only for guns because we can throw items with attached explosives if(Item[pObj->usItem].usItemClass & IC_WEAPON ) for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if ( Item[ iter->usItem ].usItemClass & IC_EXPLOSV && iter->exists()) + if ( iter->exists() && Item[ iter->usItem ].usItemClass & IC_EXPLOSV ) { pObject = &(*iter); break; diff --git a/Tactical/Weapons.cpp b/Tactical/Weapons.cpp index a378fceb..79731524 100644 --- a/Tactical/Weapons.cpp +++ b/Tactical/Weapons.cpp @@ -1036,7 +1036,7 @@ INT32 EffectiveArmour( OBJECTTYPE * pObj ) iValue = iValue * (*pObj)[0]->data.objectStatus * Armour[ Item[pObj->usItem].ubClassIndex ].ubCoverage / 10000; for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if (Item[iter->usItem].usItemClass == IC_ARMOUR && (*iter)[0]->data.objectStatus > 0 && iter->exists()) + if ( iter->exists() && Item[iter->usItem].usItemClass == IC_ARMOUR && (*iter)[0]->data.objectStatus > 0 ) { INT32 iValue2; @@ -1214,7 +1214,7 @@ INT32 ExplosiveEffectiveArmour( OBJECTTYPE * pObj ) } for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if (Item[iter->usItem].usItemClass == IC_ARMOUR && (*iter)[0]->data.objectStatus > 0 && iter->exists()) + if ( iter->exists() && Item[iter->usItem].usItemClass == IC_ARMOUR && (*iter)[0]->data.objectStatus > 0 ) { INT32 iValue2; @@ -1295,7 +1295,7 @@ INT16 FireEffectiveArmour( OBJECTTYPE * pObj ) for ( attachmentList::iterator iter = ( *pObj )[0]->attachments.begin(); iter != ( *pObj )[0]->attachments.end(); ++iter ) { - if ( Item[iter->usItem].usItemClass == IC_ARMOUR && ( *iter )[0]->data.objectStatus > 0 && iter->exists() ) + if ( iter->exists() && Item[iter->usItem].usItemClass == IC_ARMOUR && ( *iter )[0]->data.objectStatus > 0 ) { iValue += Item[iter->usItem].sFireResistance * ( *iter )[0]->data.objectStatus / 100; } @@ -5111,7 +5111,7 @@ BOOLEAN UseLauncher( SOLDIERTYPE *pSoldier, INT32 sTargetGridNo ) pObj = &(pSoldier->inv[HANDPOS]); attachmentList::iterator iter; for (iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if ( Item[ iter->usItem ].usItemClass & IC_EXPLOSV && iter->exists()) + if ( iter->exists() && Item[ iter->usItem ].usItemClass & IC_EXPLOSV ) { break; } @@ -8025,7 +8025,7 @@ INT32 TotalArmourProtection( SOLDIERTYPE * pTarget, UINT8 ubHitLocation, INT32 i if (pArmour->exists() == true) { for (attachmentList::iterator iter = (*pArmour)[0]->attachments.begin(); iter != (*pArmour)[0]->attachments.end(); ++iter) { - if (Item[iter->usItem].usItemClass == IC_ARMOUR && (*iter)[0]->data.objectStatus > 0 && iter->exists()) + if ( iter->exists() && Item[iter->usItem].usItemClass == IC_ARMOUR && (*iter)[0]->data.objectStatus > 0 ) { // bullet got through jacket; apply ceramic plate armour INT32 protection = ArmourProtection( pTarget, Item[iter->usItem].ubClassIndex, &((*iter)[0]->data.objectStatus), iImpact, ubAmmoType, &plateHit ); @@ -8071,7 +8071,7 @@ INT32 TotalArmourProtection( SOLDIERTYPE * pTarget, UINT8 ubHitLocation, INT32 i { //Madd: put any attachments that someone might have added to the armour in the merc's inventory for (attachmentList::iterator iter = (*pArmour)[0]->attachments.begin(); iter != (*pArmour)[0]->attachments.end(); ++iter) { - if ( !AutoPlaceObject( pTarget, &(*iter), FALSE ) && iter->exists()) + if ( iter->exists() && !AutoPlaceObject( pTarget, &(*iter), FALSE ) ) { // put it on the ground AddItemToPool( pTarget->sGridNo, &(*iter), 1, pTarget->pathing.bLevel, 0 , -1 ); } diff --git a/TacticalAI/Attacks.cpp b/TacticalAI/Attacks.cpp index bc33eb3c..e64d5c9b 100644 --- a/TacticalAI/Attacks.cpp +++ b/TacticalAI/Attacks.cpp @@ -2207,7 +2207,7 @@ INT32 EstimateShotDamage(SOLDIERTYPE *pSoldier, SOLDIERTYPE *pOpponent, INT16 ub // check for ceramic plates; these do affect monster spit for (attachmentList::iterator iter = pOpponent->inv[VESTPOS][0]->attachments.begin(); iter != pOpponent->inv[VESTPOS][0]->attachments.end(); ++iter) { - if (Item[iter->usItem].usItemClass == IC_ARMOUR && (*iter)[0]->data.objectStatus > 0 && iter->exists() ) + if ( iter->exists() && Item[iter->usItem].usItemClass == IC_ARMOUR && (*iter)[0]->data.objectStatus > 0 ) { iTorsoProt += (INT32) Armour[Item[iter->usItem].ubClassIndex].ubProtection * (INT32) (*iter)[0]->data.objectStatus / 100;