diff --git a/Laptop/AimMembers.cpp b/Laptop/AimMembers.cpp index ec6bab4c..3a0fe9bc 100644 --- a/Laptop/AimMembers.cpp +++ b/Laptop/AimMembers.cpp @@ -1585,12 +1585,13 @@ BOOLEAN DisplayMercsInventory(UINT8 ubMercID) //tais: disable Weaponbox Mouseregions to stop crashing when changing kit selection and hovering over item //tooltips for weaponbox - for(i=0;iinv.size(); ubCounter++ ) + UINT8 invsize = pSoldier->inv.size(); + for( ubCounter = 0; ubCounter < invsize; ++ubCounter ) { PosX = iScreenWidthOffset + 397 + 3; PosY = iScreenHeightOffset + 200 + 8 +( ubItemCount * ( 29 ) ); @@ -2543,7 +2544,7 @@ void RenderInventoryForCharacter( INT32 iId, INT32 iSlot ) { if( uiCurrentInventoryIndex > ubUpToCount ) { - ubUpToCount++; + ++ubUpToCount; } else { @@ -2778,21 +2779,20 @@ void EnableDisableInventoryScrollButtons( void ) INT32 GetNumberOfInventoryItemsOnCurrentMerc( void ) { // in current team mode?..nope...move on - if (!fCurrentTeamMode) { + if (!fCurrentTeamMode) return( 0 ); - } SOLDIERTYPE *pSoldier = &Menptr[currentTeamList[currentTeamIndex]]; - unsigned ubCount = 0; - for (unsigned ubCounter = 0; ubCounter < pSoldier->inv.size(); ++ubCounter) + INT32 ubCount = 0; + UINT8 invsize = pSoldier->inv.size(); + for (UINT8 ubCounter = 0; ubCounter < invsize; ++ubCounter) { - if( ( pSoldier->inv[ ubCounter ].exists() == true) ) { + if( ( pSoldier->inv[ ubCounter ].exists() == true) ) ++ubCount; - } } - return (INT32)ubCount; + return ubCount; } void CreateDestroyPersonnelInventoryScrollButtons( void ) @@ -6225,7 +6225,8 @@ INT32 GetFundsOnMerc( SOLDIERTYPE *pSoldier ) } // run through grunts pockets and count all the spare change - for( iCurrentPocket = 0; iCurrentPocket < pSoldier->inv.size(); iCurrentPocket++ ) + UINT32 invsize = pSoldier->inv.size(); + for( iCurrentPocket = 0; iCurrentPocket < invsize; ++iCurrentPocket ) { if ( Item[ pSoldier->inv[ iCurrentPocket ] .usItem ].usItemClass == IC_MONEY ) { @@ -6249,7 +6250,8 @@ BOOLEAN TransferFundsFromMercToBank( SOLDIERTYPE *pSoldier, INT32 iCurrentBalanc UINT32 iCurrentPocket = 0; INT32 iAmountLeftToTake = iCurrentBalance; // run through grunts pockets and count all the spare change - for( iCurrentPocket = 0; iCurrentPocket < pSoldier->inv.size(); iCurrentPocket++ ) + UINT32 invsize = pSoldier->inv.size(); + for( iCurrentPocket = 0; iCurrentPocket < invsize; ++iCurrentPocket ) { if ( Item[ pSoldier->inv[ iCurrentPocket ] .usItem ].usItemClass == IC_MONEY ) { diff --git a/Strategic/Assignments.cpp b/Strategic/Assignments.cpp index 10037aee..19e6c81c 100644 --- a/Strategic/Assignments.cpp +++ b/Strategic/Assignments.cpp @@ -3827,7 +3827,8 @@ OBJECTTYPE* FindRepairableItemInLBENODE(SOLDIERTYPE * pSoldier, OBJECTTYPE * pOb if(pObj->IsActiveLBE(subObject) == true) { LBENODE* pLBE = pObj->GetLBEPointer(subObject); - for(UINT8 lbePocket = 0; lbePocket < pLBE->inv.size(); lbePocket++) + UINT8 invsize = pLBE->inv.size(); + for(UINT8 lbePocket = 0; lbePocket < invsize; ++lbePocket) { for(UINT8 ubItemsInPocket = 0; ubItemsInPocket < pLBE->inv[lbePocket].ubNumberOfObjects; ubItemsInPocket++) { @@ -4035,7 +4036,8 @@ BOOLEAN RepairObject( SOLDIERTYPE * pSoldier, SOLDIERTYPE * pOwner, OBJECTTYPE * if(UsingNewInventorySystem() == true && Item[pObj->usItem].usItemClass == IC_LBEGEAR && pObj->IsActiveLBE(ubLoop) == true) { LBENODE* pLBE = pObj->GetLBEPointer(ubLoop); - for(lbeLoop = 0; lbeLoop < pLBE->inv.size(); lbeLoop++) + UINT8 invsize = pLBE->inv.size(); + for(lbeLoop = 0; lbeLoop < invsize; ++lbeLoop) { if(RepairObject(pSoldier, pOwner, &pLBE->inv[lbeLoop], pubRepairPtsLeft)) { diff --git a/Strategic/Auto Resolve.cpp b/Strategic/Auto Resolve.cpp index 6c82f2c1..62c5d965 100644 --- a/Strategic/Auto Resolve.cpp +++ b/Strategic/Auto Resolve.cpp @@ -4256,7 +4256,9 @@ BOOLEAN FireAShot( SOLDIERCELL *pAttacker ) pAttacker->bWeaponSlot = SECONDHANDPOS; return TRUE; } - for( UINT32 i = 0; i < pSoldier->inv.size(); i++ ) + + UINT8 invsize = pSoldier->inv.size(); + for( UINT8 i = 0; i < invsize; ++i ) { pItem = &pSoldier->inv[ i ]; @@ -4297,7 +4299,8 @@ BOOLEAN FireAShot( SOLDIERCELL *pAttacker ) BOOLEAN AttackerHasKnife( SOLDIERCELL *pAttacker ) { - for( UINT32 i = 0; i < pAttacker->pSoldier->inv.size(); i++ ) + UINT8 invsize = pAttacker->pSoldier->inv.size(); + for( UINT8 i = 0; i < invsize; ++i ) { if( Item[ pAttacker->pSoldier->inv[ i ].usItem ].usItemClass == IC_BLADE ) { @@ -4312,7 +4315,8 @@ BOOLEAN AttackerHasKnife( SOLDIERCELL *pAttacker ) BOOLEAN TargetHasLoadedGun( SOLDIERTYPE *pSoldier ) { OBJECTTYPE *pItem; - for( UINT32 i = 0; i < pSoldier->inv.size(); i++ ) + UINT8 invsize = pSoldier->inv.size(); + for( UINT8 i = 0; i < invsize; ++i ) { pItem = &pSoldier->inv[ i ]; if( Item[ pItem->usItem ].usItemClass == IC_GUN ) diff --git a/Strategic/Hourly Update.cpp b/Strategic/Hourly Update.cpp index 43a8c2ac..d0a7b47d 100644 --- a/Strategic/Hourly Update.cpp +++ b/Strategic/Hourly Update.cpp @@ -341,7 +341,7 @@ void HourlyLarryUpdate() BOOLEAN fBar = FALSE; OBJECTTYPE* pObj = NULL; - for( INT32 cnt = gTacticalStatus.Team[ OUR_TEAM ].bFirstID; cnt <= gTacticalStatus.Team[ OUR_TEAM ].bLastID; ++cnt ) + for( UINT32 cnt = gTacticalStatus.Team[ OUR_TEAM ].bFirstID; cnt <= gTacticalStatus.Team[ OUR_TEAM ].bLastID; ++cnt ) { pSoldier = MercPtrs[ cnt ]; diff --git a/Strategic/Map Screen Interface Map Inventory.cpp b/Strategic/Map Screen Interface Map Inventory.cpp index 2bc10550..16ac8689 100644 --- a/Strategic/Map Screen Interface Map Inventory.cpp +++ b/Strategic/Map Screen Interface Map Inventory.cpp @@ -4067,14 +4067,15 @@ INT32 SellItem( OBJECTTYPE& object, BOOLEAN fAll, BOOLEAN useModifier ) { //CHRISL: If we're selling an LBE Item, we need to verify if it's an LBENODE, first. If it is, we need to sell // everything stored in the LBENODE before we sell teh LBE Item itself. - for(UINT8 ubLoop = 0; ubLoop < object.ubNumberOfObjects; ubLoop++) + for(UINT8 ubLoop = 0; ubLoop < object.ubNumberOfObjects; ++ubLoop) { if(object.IsActiveLBE(ubLoop) == true) { LBENODE* pLBE = object.GetLBEPointer(ubLoop); if(pLBE) { - for(unsigned int x = 0; x < pLBE->inv.size(); x++) + UINT8 invsize = pLBE->inv.size(); + for(UINT8 x = 0; x < invsize; ++x) { if(pLBE->inv[x].exists() == true) { diff --git a/Strategic/Map Screen Interface.cpp b/Strategic/Map Screen Interface.cpp index aeaf172b..3f67ed13 100644 --- a/Strategic/Map Screen Interface.cpp +++ b/Strategic/Map Screen Interface.cpp @@ -1620,7 +1620,8 @@ void HandleLeavingOfEquipmentInCurrentSector( UINT32 uiMercId ) } } - for( UINT32 iCounter = 0; iCounter < Menptr[ uiMercId ].inv.size(); iCounter++ ) + UINT32 invsize = Menptr[ uiMercId ].inv.size(); + for( UINT32 iCounter = 0; iCounter < invsize; ++iCounter ) { // slot found, // check if actual item @@ -1639,7 +1640,6 @@ void HandleLeavingOfEquipmentInCurrentSector( UINT32 uiMercId ) } DropKeysInKeyRing( MercPtrs[ uiMercId ], sGridNo, MercPtrs[ uiMercId ]->pathing.bLevel, 1, FALSE, 0, FALSE ); - } @@ -1886,7 +1886,8 @@ INT32 SetUpDropItemListForMerc( UINT32 uiMercId ) return( -1 ); } - for( UINT32 iCounter = 0; iCounter < Menptr[ uiMercId ].inv.size(); iCounter++ ) + UINT32 invsize = Menptr[ uiMercId ].inv.size(); + for( UINT32 iCounter = 0; iCounter < invsize; ++iCounter ) { // slot found, // check if actual item diff --git a/Strategic/Queen Command.cpp b/Strategic/Queen Command.cpp index 728dc6fa..27908800 100644 --- a/Strategic/Queen Command.cpp +++ b/Strategic/Queen Command.cpp @@ -2183,7 +2183,8 @@ void EnemyCapturesPlayerSoldier( SOLDIERTYPE *pSoldier ) pSoldier->pathing.bLevel = 0; // OK, drop all items! - for ( i = 0; i < pSoldier->inv.size(); i++ ) + UINT32 invsize = pSoldier->inv.size(); + for ( i = 0; i < invsize; ++i ) { if( pSoldier->inv[ i ].exists() == true ) { @@ -2216,7 +2217,8 @@ void EnemyCapturesPlayerSoldier( SOLDIERTYPE *pSoldier ) pSoldier->pathing.bLevel = 0; // OK, drop all items! - for ( i = 0; i < pSoldier->inv.size(); i++ ) + UINT32 invsize = pSoldier->inv.size(); + for ( i = 0; i < invsize; ++i ) { if( pSoldier->inv[ i ].exists() == true ) { diff --git a/Strategic/Quest Debug System.cpp b/Strategic/Quest Debug System.cpp index 388379de..924abf15 100644 --- a/Strategic/Quest Debug System.cpp +++ b/Strategic/Quest Debug System.cpp @@ -3179,11 +3179,13 @@ void CreateDestroyDisplayNPCInventoryPopup( UINT8 ubAction ) DrawTextToScreen( gMercProfiles[ gNpcListBox.sCurSelectedItem ].zNickname, QUEST_DBS_NPC_INV_POPUP_X, QUEST_DBS_NPC_INV_POPUP_Y+20, QUEST_DBS_NPC_INV_POPUP_WIDTH, QUEST_DBS_FONT_TITLE, QUEST_DBS_COLOR_SUBTITLE, FONT_MCOLOR_BLACK, FALSE, CENTER_JUSTIFIED ); usPosY = QUEST_DBS_NPC_INV_POPUP_Y + 40; - for( i=0; iinv.size(); i++) + + UINT16 invsize = pSoldier->inv.size(); + for( i=0; iinv[i].exists() == false) { + if (pSoldier->inv[i].exists() == false) continue; - } + // if ( !LoadItemInfo( pSoldier->inv[ i ].usItem, zItemName, zItemDesc ) ) // Assert(0); wcscpy( zItemName, ShortItemNames[ pSoldier->inv[ i ].usItem ] ); @@ -3691,7 +3693,7 @@ void RefreshAllNPCInventory() { UINT16 usCnt; UINT16 usItemCnt; - UINT16 usItem; + UINT16 usItem; for ( usCnt=0; usCnt < TOTAL_SOLDIERS; usCnt++ ) { @@ -3704,7 +3706,8 @@ void RefreshAllNPCInventory() if ( gProfilesRPC[Menptr[ usCnt ].ubProfile].ProfilId == Menptr[ usCnt ].ubProfile || gProfilesNPC[Menptr[ usCnt ].ubProfile].ProfilId == Menptr[ usCnt ].ubProfile || gProfilesVehicle[Menptr[ usCnt ].ubProfile].ProfilId == Menptr[ usCnt ].ubProfile ) { //refresh the mercs inventory - for ( usItemCnt = 0; usItemCnt< Menptr[ usCnt ].inv.size(); usItemCnt++ ) + UINT16 invsize = Menptr[ usCnt ].inv.size(); + for ( usItemCnt = 0; usItemCnt< invsize; ++usItemCnt ) { if ( gMercProfiles[ Menptr[ usCnt ].ubProfile ].inv[ usItemCnt ] != NOTHING ) { diff --git a/Strategic/Strategic Merc Handler.cpp b/Strategic/Strategic Merc Handler.cpp index 25156bba..230803f1 100644 --- a/Strategic/Strategic Merc Handler.cpp +++ b/Strategic/Strategic Merc Handler.cpp @@ -797,8 +797,8 @@ BOOLEAN SoldierHasWorseEquipmentThanUsedTo( SOLDIERTYPE *pSoldier ) INT32 bBestGun = -1; INT32 bBestGunIndex = -1; - - for ( UINT32 cnt = 0; cnt < pSoldier->inv.size(); cnt++ ) + UINT32 invsize = pSoldier->inv.size(); + for ( UINT32 cnt = 0; cnt < invsize; ++cnt ) { // Look for best gun/armour if ( pSoldier->inv[cnt].exists() == true ) diff --git a/Tactical/Handle Items.cpp b/Tactical/Handle Items.cpp index c3016d9c..b75244dc 100644 --- a/Tactical/Handle Items.cpp +++ b/Tactical/Handle Items.cpp @@ -6394,7 +6394,8 @@ UINT8 StealItems(SOLDIERTYPE* pSoldier,SOLDIERTYPE* pOpponent, UINT8* ubIndexRet //Create a temporary item pool, with index in Opponent's inventory as index pItemPool=NULL; - for(i=0 ; iinv.size(); i++) + UINT8 invsize = pOpponent->inv.size(); + for(i=0 ; ibActive && pSoldier->bInSector ) { @@ -5749,7 +5749,7 @@ UINT32 UIHandleRubberBandOnTerrain( UI_EVENT *pUIEvent ) // ATE:Check at least for one guy that's in point! cnt = gTacticalStatus.Team[ gbPlayerNum ].bFirstID; - for ( pSoldier = MercPtrs[ cnt ]; cnt <= gTacticalStatus.Team[ gbPlayerNum ].bLastID; cnt++, pSoldier++ ) + for ( pSoldier = MercPtrs[ cnt ]; cnt <= gTacticalStatus.Team[ gbPlayerNum ].bLastID; ++cnt, pSoldier++ ) { // Check if this guy is OK to control.... if ( OK_CONTROLLABLE_MERC( pSoldier ) && !( pSoldier->flags.uiStatusFlags & ( SOLDIER_VEHICLE | SOLDIER_PASSENGER | SOLDIER_DRIVER ) ) ) @@ -5777,7 +5777,7 @@ UINT32 UIHandleRubberBandOnTerrain( UI_EVENT *pUIEvent ) // ATE: Now loop through our guys and see if any fit! cnt = gTacticalStatus.Team[ gbPlayerNum ].bFirstID; - for ( pSoldier = MercPtrs[ cnt ]; cnt <= gTacticalStatus.Team[ gbPlayerNum ].bLastID; cnt++, pSoldier++ ) + for ( pSoldier = MercPtrs[ cnt ]; cnt <= gTacticalStatus.Team[ gbPlayerNum ].bLastID; ++cnt, pSoldier++ ) { // Check if this guy is OK to control.... @@ -5805,7 +5805,6 @@ UINT32 UIHandleRubberBandOnTerrain( UI_EVENT *pUIEvent ) } } - return( GAME_SCREEN ); } @@ -5978,7 +5977,6 @@ BOOLEAN IsValidTalkableNPC( UINT8 ubSoldierID, BOOLEAN fGive , BOOLEAN fAllowMer SOLDIERTYPE *pSoldier = MercPtrs[ ubSoldierID ]; BOOLEAN fValidGuy = FALSE; - if ( gusSelectedSoldier != NOBODY ) { if ( AM_A_ROBOT( MercPtrs[ gusSelectedSoldier ] ) ) @@ -6009,7 +6007,6 @@ BOOLEAN IsValidTalkableNPC( UINT8 ubSoldierID, BOOLEAN fGive , BOOLEAN fAllowMer return( FALSE ); } - // IF BAD GUY - CHECK VISIVILITY if ( pSoldier->bTeam != gbPlayerNum ) { @@ -6742,13 +6739,13 @@ void SetInterfaceHeightLevel( ) // ATE: Use an entry point to determine what height to use.... - if( gMapInformation.sNorthGridNo != -1 ) + if( gMapInformation.sNorthGridNo != NOWHERE ) sGridNo = gMapInformation.sNorthGridNo; - else if( gMapInformation.sEastGridNo != -1 ) + else if( gMapInformation.sEastGridNo != NOWHERE ) sGridNo = gMapInformation.sEastGridNo; - else if( gMapInformation.sSouthGridNo != -1 ) + else if( gMapInformation.sSouthGridNo != NOWHERE ) sGridNo = gMapInformation.sSouthGridNo; - else if( gMapInformation.sWestGridNo != -1 ) + else if( gMapInformation.sWestGridNo != NOWHERE ) sGridNo = gMapInformation.sWestGridNo; else { diff --git a/Tactical/Interface Items.cpp b/Tactical/Interface Items.cpp index 2dbf7936..80ddc937 100644 --- a/Tactical/Interface Items.cpp +++ b/Tactical/Interface Items.cpp @@ -1633,7 +1633,8 @@ void HandleRenderInvSlots( SOLDIERTYPE *pSoldier, UINT8 fDirtyLevel ) } else { - for ( UINT32 cnt = 0; cnt < pSoldier->inv.size(); cnt++ ) + UINT32 invsize = pSoldier->inv.size(); + for ( UINT32 cnt = 0; cnt < invsize; ++cnt ) { if ( fDirtyLevel == DIRTYLEVEL2 ) { @@ -1717,7 +1718,8 @@ std::vector * getSoldierGuns( SOLDIERTYPE *pTeamSoldier ) std::vector * guns = new std::vector; // Search for gun in soldier inventory - for (bLoop = 0; bLoop < pTeamSoldier->inv.size(); bLoop++) + UINT32 invsize = pTeamSoldier->inv.size(); + for (bLoop = 0; bLoop < invsize; ++bLoop) { if ( (Item[pTeamSoldier->inv[bLoop].usItem].usItemClass & IC_GUN) || (Item[pTeamSoldier->inv[bLoop].usItem].usItemClass == IC_LAUNCHER) ) @@ -2800,7 +2802,8 @@ BOOLEAN SoldierContainsAnyCompatibleStuff( SOLDIERTYPE *pSoldier, OBJECTTYPE *pT if( ( Item [ pTestObject->usItem ].usItemClass & IC_GUN ) ) { - for ( cnt = 0; cnt < pSoldier->inv.size(); cnt++ ) + UINT32 invsize = pSoldier->inv.size(); + for ( cnt = 0; cnt < invsize; ++cnt ) { pObject = &(pSoldier->inv[ cnt ]); @@ -2813,7 +2816,8 @@ BOOLEAN SoldierContainsAnyCompatibleStuff( SOLDIERTYPE *pSoldier, OBJECTTYPE *pT if( ( Item [ pTestObject->usItem ].usItemClass & IC_AMMO ) ) { - for ( cnt = 0; cnt < pSoldier->inv.size(); cnt++ ) + UINT32 invsize = pSoldier->inv.size(); + for ( cnt = 0; cnt < invsize; ++cnt ) { pObject = &(pSoldier->inv[ cnt ]); @@ -2898,7 +2902,8 @@ BOOLEAN HandleCompatibleAmmoUIForMapScreen( SOLDIERTYPE *pSoldier, INT32 bInvPos // ATE: If pTest object is NULL, test only for existence of syringes, etc... if ( pTestObject == NULL ) { - for ( cnt = 0; cnt < pSoldier->inv.size(); cnt++ ) + UINT32 invsize = pSoldier->inv.size(); + for ( cnt = 0; cnt < invsize; ++cnt ) { pObject = &(pSoldier->inv[ cnt ]); @@ -2948,7 +2953,8 @@ BOOLEAN HandleCompatibleAmmoUIForMapScreen( SOLDIERTYPE *pSoldier, INT32 bInvPos if ( !(Item[ pTestObject->usItem ].hiddenaddon ) ) { // First test attachments, which almost any type of item can have.... - for ( cnt = 0; cnt < pSoldier->inv.size(); cnt++ ) + UINT32 invsize = pSoldier->inv.size(); + for ( cnt = 0; cnt < invsize; ++cnt ) { pObject = &(pSoldier->inv[ cnt ]); @@ -2990,7 +2996,8 @@ BOOLEAN HandleCompatibleAmmoUIForMapScreen( SOLDIERTYPE *pSoldier, INT32 bInvPos if ( ( Item [ pTestObject->usItem ].usItemClass & IC_GUN ) ) { - for ( cnt = 0; cnt < pSoldier->inv.size(); cnt++ ) + UINT32 invsize = pSoldier->inv.size(); + for ( cnt = 0; cnt < invsize; ++cnt ) { pObject = &(pSoldier->inv[ cnt ]); @@ -3009,7 +3016,8 @@ BOOLEAN HandleCompatibleAmmoUIForMapScreen( SOLDIERTYPE *pSoldier, INT32 bInvPos } else if( ( Item [ pTestObject->usItem ].usItemClass & IC_AMMO ) ) { - for ( cnt = 0; cnt < pSoldier->inv.size(); cnt++ ) + UINT32 invsize = pSoldier->inv.size(); + for ( cnt = 0; cnt < invsize; ++cnt ) { pObject = &(pSoldier->inv[ cnt ]); @@ -3166,7 +3174,8 @@ BOOLEAN InternalHandleCompatibleAmmoUI( SOLDIERTYPE *pSoldier, OBJECTTYPE *pTest // ATE: If pTest object is NULL, test only for existence of syringes, etc... if ( pTestObject == NULL ) { - for ( cnt = 0; cnt < pSoldier->inv.size(); cnt++ ) + UINT32 invsize = pSoldier->inv.size(); + for ( cnt = 0; cnt < invsize; ++cnt ) { pObject = &(pSoldier->inv[ cnt ]); @@ -3213,7 +3222,8 @@ BOOLEAN InternalHandleCompatibleAmmoUI( SOLDIERTYPE *pSoldier, OBJECTTYPE *pTest } // First test attachments, which almost any type of item can have.... - for ( cnt = 0; cnt < pSoldier->inv.size(); cnt++ ) + UINT32 invsize = pSoldier->inv.size(); + for ( cnt = 0; cnt < invsize; ++cnt ) { pObject = &(pSoldier->inv[ cnt ]); @@ -3253,7 +3263,8 @@ BOOLEAN InternalHandleCompatibleAmmoUI( SOLDIERTYPE *pSoldier, OBJECTTYPE *pTest //{ if( ( Item [ pTestObject->usItem ].usItemClass & IC_GUN ) ) { - for ( cnt = 0; cnt < pSoldier->inv.size(); cnt++ ) + UINT32 invsize = pSoldier->inv.size(); + for ( cnt = 0; cnt < invsize; ++cnt ) { pObject = &(pSoldier->inv[ cnt ]); @@ -3273,7 +3284,8 @@ BOOLEAN InternalHandleCompatibleAmmoUI( SOLDIERTYPE *pSoldier, OBJECTTYPE *pTest else if( ( Item [ pTestObject->usItem ].usItemClass & IC_AMMO ) ) { - for ( cnt = 0; cnt < pSoldier->inv.size(); cnt++ ) + UINT32 invsize = pSoldier->inv.size(); + for ( cnt = 0; cnt < invsize; ++cnt ) { pObject = &(pSoldier->inv[ cnt ]); @@ -3438,11 +3450,11 @@ void HandleNewlyAddedItems( SOLDIERTYPE *pSoldier, BOOLEAN *fDirtyLevel ) return; } - UINT32 cnt; INT16 sX, sY; OBJECTTYPE *pObject; - for ( cnt = 0; cnt < pSoldier->inv.size(); cnt++ ) + UINT32 invsize = pSoldier->inv.size(); + for ( UINT32 cnt = 0; cnt < invsize; ++cnt ) { if ( pSoldier->inv.bNewItemCount[ cnt ] == -2 ) { @@ -3468,27 +3480,25 @@ void HandleNewlyAddedItems( SOLDIERTYPE *pSoldier, BOOLEAN *fDirtyLevel ) INVRenderItem( guiSAVEBUFFER, pSoldier, pObject, sX, sY, gSMInvData[ cnt ].sWidth, gSMInvData[ cnt ].sHeight, DIRTYLEVEL2, NULL, 0, TRUE, us16BPPItemCyclePlacedItemColors[ pSoldier->inv.bNewItemCycleCount[ cnt ] ] ); } - } } void CheckForAnyNewlyAddedItems( SOLDIERTYPE *pSoldier ) { // OK, l0ok for any new... - for ( UINT32 cnt = 0; cnt < pSoldier->inv.size(); cnt++ ) + UINT32 invsize = pSoldier->inv.size(); + for ( UINT32 cnt = 0; cnt < invsize; ++cnt ) { if ( pSoldier->inv.bNewItemCount[ cnt ] == -1 ) { pSoldier->inv.bNewItemCount[ cnt ] = NEW_ITEM_CYCLES - 1; } } - } void DegradeNewlyAddedItems( ) { UINT32 uiTime; - UINT32 cnt, cnt2; SOLDIERTYPE *pSoldier; // If time done @@ -3498,14 +3508,15 @@ void DegradeNewlyAddedItems( ) { guiNewlyPlacedItemTimer = uiTime; - for ( cnt2 = 0; cnt2 < gGameOptions.ubSquadSize; cnt2++ ) + for ( UINT32 cnt2 = 0; cnt2 < gGameOptions.ubSquadSize; ++cnt2 ) { // GET SOLDIER if ( gTeamPanel[ cnt2 ].fOccupied ) { pSoldier = MercPtrs[ gTeamPanel[ cnt2 ].ubID ]; - for ( cnt = 0; cnt < pSoldier->inv.size(); cnt++ ) + UINT32 invsize = pSoldier->inv.size(); + for ( UINT32 cnt = 0; cnt < invsize; ++cnt ) { if ( pSoldier->inv.bNewItemCount[ cnt ] > 0 ) { diff --git a/Tactical/Interface Panels.cpp b/Tactical/Interface Panels.cpp index ec8314ec..3c4b3906 100644 --- a/Tactical/Interface Panels.cpp +++ b/Tactical/Interface Panels.cpp @@ -1141,7 +1141,8 @@ void ReevaluateItemHatches( SOLDIERTYPE *pSoldier, BOOLEAN fAllValid ) if ( ( gpItemPointer != NULL ) && !fAllValid ) { // check all inventory positions and mark the ones where cursor item won't fit as invalid - for ( cnt = 0; cnt < pSoldier->inv.size(); cnt++ ) + UINT32 invsize = pSoldier->inv.size(); + for ( cnt = 0; cnt < invsize; ++cnt ) { gbInvalidPlacementSlot[ cnt ] = !CanItemFitInPosition( pSoldier, gpItemPointer, (INT8)cnt, FALSE ); @@ -1165,7 +1166,7 @@ void ReevaluateItemHatches( SOLDIERTYPE *pSoldier, BOOLEAN fAllValid ) else { // mark all inventory positions as valid - for ( cnt = 0; cnt < NUM_INV_SLOTS; cnt++ ) + for ( cnt = 0; cnt < NUM_INV_SLOTS; ++cnt ) { gbInvalidPlacementSlot[ cnt ] = FALSE; } diff --git a/Tactical/Inventory Choosing.cpp b/Tactical/Inventory Choosing.cpp index 2e054c88..d1171a81 100644 --- a/Tactical/Inventory Choosing.cpp +++ b/Tactical/Inventory Choosing.cpp @@ -872,8 +872,10 @@ void GenerateRandomEquipment( SOLDIERCREATE_STRUCT *pp, INT8 bSoldierClass, INT8 #endif } - for ( i = 0; i < pp->Inv.size(); i++ ) - { //clear items, but only if they have write status. + UINT32 invsize = pp->Inv.size(); + for( i = 0; i < invsize; ++i ) + { + //clear items, but only if they have write status. if( !(pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE) ) { DeleteObj(&pp->Inv[ i ]); @@ -1008,9 +1010,11 @@ void ChooseWeaponForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp, INT8 bWeaponC // if gun was pre-selected (rcvd negative weapon class) and needs ammo if( bWeaponClass < 0 && bAmmoClips ) - { //Linda has added a specific gun to the merc's inventory, but no ammo. So, we + { + //Linda has added a specific gun to the merc's inventory, but no ammo. So, we //will choose ammunition that works with the gun. - for( i = 0; i < pp->Inv.size(); i++ ) + UINT16 invsize = pp->Inv.size(); + for( i = 0; i < invsize; ++i ) { if( Item[ pp->Inv[ i ].usItem ].usItemClass == IC_GUN && pp->Inv[ i ].exists() == true) { @@ -2596,7 +2600,8 @@ else if ( (SOLDIER_CLASS_ENEMY( bSoldierClass ) || ( gGameExternalOptions.ubMilitiaDropEquipment > 0 && SOLDIER_CLASS_MILITIA( bSoldierClass ) )) && !IsAutoResolveActive() ) { // SPECIAL handling for weapons: we'll always drop a weapon type that has never been dropped before - for( i = 0; i < pp->Inv.size(); i++ ) + UINT32 invsize = pp->Inv.size(); + for( i = 0; i < invsize; ++i ) { usItem = pp->Inv[ i ].usItem; //TODO: someday maybe pp->Inv[i].fFlags &= ~ITEM_REPAIRABLE; @@ -2684,7 +2689,8 @@ else if( fAmmo ) { // now drops ALL ammo found, not just the first slot - for( i = 0; i < pp->Inv.size(); i++ ) + UINT32 invsize = pp->Inv.size(); + for( i = 0; i < invsize; ++i ) { uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass; if( uiItemClass == IC_AMMO ) @@ -2702,7 +2708,8 @@ else if( fWeapon ) { ubNumMatches = 0; - for( i = 0; i < pp->Inv.size(); i++ ) + UINT32 invsize = pp->Inv.size(); + for( i = 0; i < invsize; ++i ) { uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass; if( uiItemClass == IC_GUN || uiItemClass == IC_LAUNCHER ) @@ -2710,12 +2717,12 @@ else if( pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE ) break; else - ubNumMatches++; + ++ubNumMatches; } } if ( ubNumMatches > 0 ) { - for( i = 0; i < pp->Inv.size(); i++ ) + for( i = 0; i < invsize; ++i ) { uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass; if( uiItemClass == IC_GUN || uiItemClass == IC_LAUNCHER ) @@ -2735,7 +2742,8 @@ else if( fArmour ) { ubNumMatches = 0; - for( i = 0; i < pp->Inv.size(); i++ ) + UINT32 invsize = pp->Inv.size(); + for( i = 0; i < invsize; ++i ) { uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass; if( uiItemClass == IC_ARMOUR ) @@ -2743,12 +2751,12 @@ else if( pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE ) break; else - ubNumMatches++; + ++ubNumMatches; } } if ( ubNumMatches > 0 ) { - for( i = 0; i < pp->Inv.size(); i++ ) + for( i = 0; i < invsize; ++i ) { uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass; if( uiItemClass == IC_ARMOUR ) @@ -2767,7 +2775,8 @@ else if( fKnife) { - for( i = 0; i < pp->Inv.size(); i++ ) + UINT32 invsize = pp->Inv.size(); + for( i = 0; i < invsize; ++i ) { // drops FIRST knife found uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass; @@ -2788,7 +2797,8 @@ else if( fGrenades ) { ubNumMatches = 0; - for( i = 0; i < pp->Inv.size(); i++ ) + UINT32 invsize = pp->Inv.size(); + for( i = 0; i < invsize; ++i ) { uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass; if( uiItemClass == IC_GRENADE ) @@ -2796,12 +2806,12 @@ else if( pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE ) break; else - ubNumMatches++; + ++ubNumMatches; } } if ( ubNumMatches > 0 ) { - for( i = 0; i < pp->Inv.size(); i++ ) + for( i = 0; i < invsize; ++i ) { uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass; if( uiItemClass == IC_GRENADE ) @@ -2821,7 +2831,8 @@ else if( fKit ) { ubNumMatches = 0; - for( i = 0; i < pp->Inv.size(); i++ ) + UINT32 invsize = pp->Inv.size(); + for( i = 0; i < invsize; ++i ) { uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass; if( uiItemClass == IC_MEDKIT || uiItemClass == IC_KIT ) @@ -2834,7 +2845,7 @@ else } if ( ubNumMatches > 0 ) { - for( i = 0; i < pp->Inv.size(); i++ ) + for( i = 0; i < invsize; ++i ) { uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass; if( uiItemClass == IC_MEDKIT || uiItemClass == IC_KIT ) @@ -2854,7 +2865,8 @@ else if( fFace ) { ubNumMatches = 0; - for( i = 0; i < pp->Inv.size(); i++ ) + UINT32 invsize = pp->Inv.size(); + for( i = 0; i < invsize; ++i ) { uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass; if( uiItemClass == IC_FACE ) @@ -2862,12 +2874,12 @@ else if( pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE ) break; else - ubNumMatches++; + ++ubNumMatches; } } if ( ubNumMatches > 0 ) { - for( i = 0; i < pp->Inv.size(); i++ ) + for( i = 0; i < invsize; ++i ) { uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass; if( uiItemClass == IC_FACE ) @@ -2887,7 +2899,8 @@ else if( fMisc ) { ubNumMatches = 0; - for( i = 0; i < pp->Inv.size(); i++ ) + UINT32 invsize = pp->Inv.size(); + for( i = 0; i < invsize; ++i ) { uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass; if( uiItemClass == IC_MISC ) @@ -2895,12 +2908,12 @@ else if( pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE ) break; else - ubNumMatches++; + ++ubNumMatches; } } if ( ubNumMatches > 0 ) { - for( i = 0; i < pp->Inv.size(); i++ ) + for( i = 0; i < invsize; ++i ) { uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass; if( uiItemClass == IC_MISC ) @@ -2921,8 +2934,9 @@ else else if (gGameExternalOptions.ubEnemiesItemDrop == 1) { // Loop through the enemy inter - for( i = 0; i < pp->Inv.size(); i++ ) - { + UINT32 invsize = pp->Inv.size(); + for( i = 0; i < invsize; ++i ) + { uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass; // We are allowed to change the object and it is not the first (nothing) object @@ -2933,7 +2947,7 @@ else if( uiItemClass == IC_GUN) { // Find matching weaponType in the XML - for (j = 0; j < MAX_DROP_ITEMS; j++) + for (j = 0; j < MAX_DROP_ITEMS; ++j) { // We have no more weapon items->exit from loop if (j > 0 && gEnemyWeaponDrops[j].uiIndex == 0) @@ -2974,7 +2988,7 @@ else else if (uiItemClass == IC_AMMO) { // Find matching ammo in the XML - for (j = 0; j < MAX_DROP_ITEMS; j++) + for (j = 0; j < MAX_DROP_ITEMS; ++j) { // We have no more ammo items->exit from loop if (j > 0 && gEnemyAmmoDrops[j].uiIndex == 0) @@ -2986,7 +3000,7 @@ else uiRandomValue = Random(100); if (uiRandomValue == 0) - uiRandomValue++; + ++uiRandomValue; // militia if ( SOLDIER_CLASS_MILITIA( bSoldierClass ) ) @@ -3047,7 +3061,6 @@ else } } - break; } } @@ -3068,7 +3081,7 @@ else uiRandomValue = Random(100); if (uiRandomValue == 0) - uiRandomValue++; + ++uiRandomValue; // militia if ( SOLDIER_CLASS_MILITIA( bSoldierClass ) ) @@ -3251,7 +3264,8 @@ void ReplaceExtendedGuns( SOLDIERCREATE_STRUCT *pp, INT8 bSoldierClass ) INT8 bWeaponClass; UINT16 usItem, usNewGun, usAmmo, usNewAmmo; - for ( uiLoop = 0; uiLoop < pp->Inv.size(); uiLoop++ ) + UINT32 invsize = pp->Inv.size(); + for ( uiLoop = 0; uiLoop < invsize; ++uiLoop ) { usItem = pp->Inv[ uiLoop ].usItem; @@ -3289,7 +3303,8 @@ void ReplaceExtendedGuns( SOLDIERCREATE_STRUCT *pp, INT8 bSoldierClass ) // must search through inventory and replace ammo accordingly - for ( uiLoop2 = 0; uiLoop2 < pp->Inv.size(); uiLoop2++ ) + UINT32 invsize = pp->Inv.size(); + for ( uiLoop2 = 0; uiLoop2 < invsize; ++uiLoop2 ) { usAmmo = pp->Inv[ uiLoop2 ].usItem; if ( (Item[ usAmmo ].usItemClass & IC_AMMO) ) diff --git a/Tactical/Item Types.cpp b/Tactical/Item Types.cpp index f9b01a8a..4ea8adc0 100644 --- a/Tactical/Item Types.cpp +++ b/Tactical/Item Types.cpp @@ -80,11 +80,13 @@ bool DestroyLBEIfEmpty(OBJECTTYPE* pObj) { if (pObj->IsActiveLBE(0) == true) { LBENODE* pLBE = pObj->GetLBEPointer(0); - if (pLBE) { - for (unsigned int x = 0; x < pLBE->inv.size(); ++x) { - if (pLBE->inv[x].exists() == true) { + if (pLBE) + { + UINT16 plbesize = pLBE->inv.size(); + for (UINT16 x = 0; x < plbesize; ++x) + { + if (pLBE->inv[x].exists() == true) return false; - } } for (std::list::iterator iter = LBEArray.begin(); iter != LBEArray.end(); ++iter) { if (iter->uniqueID == pLBE->uniqueID) { @@ -107,38 +109,44 @@ void DestroyLBE(OBJECTTYPE* pObj) LBENODE* pLBE = pObj->GetLBEPointer(0); if(pLBE) { - for(unsigned int x = 0; x < pLBE->inv.size(); x++) + UINT16 plbesize = pLBE->inv.size(); + for(UINT16 x = 0; x < plbesize; ++x) { if(pLBE->inv[x].exists() == true) { pLBE->inv[x].initialize(); } } - for (std::list::iterator iter = LBEArray.begin(); iter != LBEArray.end(); ++iter) { - if (iter->uniqueID == pLBE->uniqueID) { + for (std::list::iterator iter = LBEArray.begin(); iter != LBEArray.end(); ++iter) + { + if (iter->uniqueID == pLBE->uniqueID) + { LBEArray.erase(iter); break; } } + (*pObj)[0]->data.lbe.uniqueID = 0; (*pObj)[0]->data.lbe.bLBE = 0; return; } } + return; } void MoveItemsInSlotsToLBE( SOLDIERTYPE *pSoldier, std::vector& LBESlots, LBENODE* pLBE, OBJECTTYPE* pObj) { - - for(unsigned int i=0; iinv.size(); + UINT16 lbesize = LBESlots.size(); + for(UINT16 i=0; iinv[LBESlots[i]].exists() == false) // No item in this pocket continue; // Found an item in a default pocket so get it's ItemSize UINT16 dSize = CalculateItemSize(&pSoldier->inv[LBESlots[i]]); - for(unsigned int j=0; jinv.size(); j++) // Search through LBE and see if item fits anywhere + for(unsigned int j=0; jinv[j].exists() == true) // Item already stored in LBENODE pocket continue; @@ -368,15 +376,19 @@ BOOLEAN MoveItemFromLBEItem( SOLDIERTYPE *pSoldier, UINT32 uiHandPos, OBJECTTYPE } } } - if (DestroyLBEIfEmpty(pObj) == false) { + + if (DestroyLBEIfEmpty(pObj) == false) + { //we should have copied all the items from the LBE to the soldier //which means the LBE should be empty and destroyed. However, if it's not empty, we need to force place //some items so that we can empty the LBE without losing anything. - for(unsigned int i = 0; i < LBESlots.size(); i++) + UINT16 invsize = pSoldier->inv.size(); + UINT16 lbesize = LBESlots.size(); + for(UINT16 i = 0; i < lbesize; ++i) { if(pLBE->inv[i].exists() == true) { - for(unsigned int j = BIGPOCKSTART; j < pSoldier->inv.size(); j++) + for(UINT16 j = BIGPOCKSTART; j < invsize; ++j) { if(pSoldier->inv[j].exists() == false) { @@ -385,6 +397,7 @@ BOOLEAN MoveItemFromLBEItem( SOLDIERTYPE *pSoldier, UINT32 uiHandPos, OBJECTTYPE } } } + //Now, check one last time and if we still have an object, drop it to the ground if(pLBE->inv[i].exists() == true) { diff --git a/Tactical/Items.cpp b/Tactical/Items.cpp index 31178d0d..4d0da23b 100644 --- a/Tactical/Items.cpp +++ b/Tactical/Items.cpp @@ -1550,7 +1550,8 @@ INT8 FindBestWeaponIfCurrentIsOutOfRange(SOLDIERTYPE * pSoldier, INT8 bCurrentWe INT8 secondBestWeapon = 0; //search for weapons that meet the range, then sort by damage. //if there are no weapons that meet the range, then use the longest range we can find - for (INT8 bLoop = 0; bLoop < (INT8) pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for (INT8 bLoop = 0; bLoop < invsize; ++bLoop) { //if this is a weapon if (Item[pSoldier->inv[bLoop].usItem].usItemClass & (IC_WEAPON | IC_THROWN) && pSoldier->inv[bLoop].exists() == true) @@ -1618,9 +1619,8 @@ INT8 FindMetalDetectorInHand( SOLDIERTYPE * pSoldier ) INT8 FindLockBomb( SOLDIERTYPE * pSoldier ) { - INT8 bLoop; - - for (bLoop = 0; bLoop < (INT8) pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for (INT8 bLoop = 0; bLoop < invsize; ++bLoop) { if (Item[pSoldier->inv[bLoop].usItem].lockbomb && pSoldier->inv[bLoop].exists() == true) { @@ -1632,9 +1632,8 @@ INT8 FindLockBomb( SOLDIERTYPE * pSoldier ) INT8 FindUsableObj( SOLDIERTYPE * pSoldier, UINT16 usItem ) { - INT8 bLoop; - - for (bLoop = 0; bLoop < (INT8) pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for (INT8 bLoop = 0; bLoop < invsize; ++bLoop) { if ( pSoldier->inv[bLoop].usItem == usItem && pSoldier->inv[bLoop].exists() == true @@ -1649,9 +1648,8 @@ INT8 FindUsableObj( SOLDIERTYPE * pSoldier, UINT16 usItem ) INT8 FindObjExcludingSlot( SOLDIERTYPE * pSoldier, UINT16 usItem, INT8 bExcludeSlot ) { - INT8 bLoop; - - for (bLoop = 0; bLoop < (INT8)pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for (INT8 bLoop = 0; bLoop < invsize; ++bLoop) { if (bLoop == bExcludeSlot) { @@ -1686,7 +1684,6 @@ INT8 FindObj( SOLDIERTYPE * pSoldier, UINT16 usItem, INT8 bLower, INT8 bUpper ) INT8 FindObjInObjRange( SOLDIERTYPE * pSoldier, UINT16 usItem1, UINT16 usItem2 ) { - INT8 bLoop; UINT16 usTemp; if (usItem1 > usItem2 ) @@ -1697,7 +1694,8 @@ INT8 FindObjInObjRange( SOLDIERTYPE * pSoldier, UINT16 usItem1, UINT16 usItem2 ) usItem1 = usTemp; } - for (bLoop = 0; bLoop < (INT8) pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for (INT8 bLoop = 0; bLoop < invsize; ++bLoop) { usTemp = pSoldier->inv[bLoop].usItem; if ( usTemp >= usItem1 && usTemp <= usItem2 && pSoldier->inv[bLoop].exists() == true) @@ -1712,9 +1710,8 @@ INT8 FindObjInObjRange( SOLDIERTYPE * pSoldier, UINT16 usItem1, UINT16 usItem2 ) INT8 FindObjClass( SOLDIERTYPE * pSoldier, UINT32 usItemClass ) { - INT8 bLoop; - - for (bLoop = 0; bLoop < (INT8)pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for (INT8 bLoop = 0; bLoop < invsize; ++bLoop) { if (Item[pSoldier->inv[bLoop].usItem].usItemClass & usItemClass && pSoldier->inv[bLoop].exists() == true) { @@ -1730,13 +1727,13 @@ INT8 FindAIUsableObjClass( SOLDIERTYPE * pSoldier, UINT32 usItemClass ) // the "unusable by AI" flag set. // uses & rather than == so that this function can search for any weapon - INT8 bLoop; // This is for the AI only so: // Do not consider tank cannons or rocket launchers to be "guns" - for (bLoop = 0; bLoop < (INT8) pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for (INT8 bLoop = 0; bLoop < invsize; ++bLoop) { if (pSoldier->inv[bLoop].exists() == true) { if ( (Item[pSoldier->inv[bLoop].usItem].usItemClass & usItemClass) && !(pSoldier->inv[bLoop].fFlags & OBJECT_AI_UNUSABLE) && (pSoldier->inv[bLoop][0]->data.objectStatus >= USABLE ) ) @@ -1823,9 +1820,8 @@ BOOLEAN GLGrenadeInSlot(SOLDIERTYPE *pSoldier, INT8 bSlot ) // for grenade launchers INT8 FindGLGrenade( SOLDIERTYPE * pSoldier ) { - INT8 bLoop; - - for (bLoop = 0; bLoop < (INT8)pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for (INT8 bLoop = 0; bLoop < invsize; ++bLoop) { if (GLGrenadeInSlot( pSoldier, bLoop )) { @@ -1849,10 +1845,13 @@ INT8 FindThrowableGrenade( SOLDIERTYPE * pSoldier ) fCheckForFlares = TRUE; } } + + INT8 invsize = (INT8)pSoldier->inv.size(); + if (fCheckForFlares) { // Do a priority check for flares first - for (bLoop = 0; bLoop < (INT8)pSoldier->inv.size(); bLoop++) + for (bLoop = 0; bLoop < invsize; ++bLoop) { if (pSoldier->inv[bLoop].exists() == true) { if ( Item[pSoldier->inv[ bLoop ].usItem].flare ) @@ -1863,7 +1862,7 @@ INT8 FindThrowableGrenade( SOLDIERTYPE * pSoldier ) } } - for (bLoop = 0; bLoop < (INT8)pSoldier->inv.size(); bLoop++) + for (bLoop = 0; bLoop < invsize; ++bLoop) { if (pSoldier->inv[bLoop].exists() == true) { if ( (Item[ pSoldier->inv[ bLoop ].usItem ].usItemClass & IC_GRENADE) && // Try this check instead, to avoid tossing RPG rounds !GLGrenadeInSlot( pSoldier, bLoop ) && @@ -1933,7 +1932,8 @@ INT8 FindLaunchable( SOLDIERTYPE * pSoldier, UINT16 usWeapon ) { INT8 bLoop; DebugMsg(TOPIC_JA2, DBG_LEVEL_3, String("FindLaunchable: weapon=%d",usWeapon)); - for (bLoop = 0; bLoop < (INT8)pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for (bLoop = 0; bLoop < invsize; ++bLoop) { if (pSoldier->inv[bLoop].exists() == true) { if ( ValidLaunchable( pSoldier->inv[ bLoop ].usItem , usWeapon ) ) @@ -1952,7 +1952,8 @@ INT8 FindNonSmokeLaunchable( SOLDIERTYPE * pSoldier, UINT16 usWeapon ) { INT8 bLoop; DebugMsg(TOPIC_JA2, DBG_LEVEL_3, String("FindNonSmokeLaunchable: weapon=%d",usWeapon)); - for (bLoop = 0; bLoop < (INT8)pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for (bLoop = 0; bLoop < invsize; ++bLoop) { if (pSoldier->inv[bLoop].exists() == true) { if ( ValidLaunchable( pSoldier->inv[ bLoop ].usItem , usWeapon ) && Explosive[Item[pSoldier->inv[ bLoop ].usItem].ubClassIndex].ubType != EXPLOSV_SMOKE ) @@ -2894,7 +2895,8 @@ UINT16 CalculateItemSize( OBJECTTYPE *pObject ) } // LBENODE has it's ItemSize adjusted based on what it's storing - if(pObject->IsActiveLBE(numStacked) == true) { + if(pObject->IsActiveLBE(numStacked) == true) + { LBENODE* pLBE = pObject->GetLBEPointer(numStacked); if(pLBE) { @@ -2905,7 +2907,8 @@ UINT16 CalculateItemSize( OBJECTTYPE *pObject ) UINT16 pIndex, testSize, maxSize; UINT8 pocketCapacity, numberOfSizeIncrements; FLOAT currentPocketPercent, currentPocketPartOfTotal; - for(unsigned int x = 0; x < pLBE->inv.size(); x++) + UINT16 invsize = pLBE->inv.size(); + for(UINT16 x = 0; x < invsize; ++x) { if(LoadBearingEquipment[Item[pObject->usItem].ubClassIndex].lbePocketIndex[x] != 0) { @@ -2914,7 +2917,7 @@ UINT16 CalculateItemSize( OBJECTTYPE *pObject ) } } //Now, look through each active pocket - for(unsigned int x = 0; x < pLBE->inv.size(); x++) + for(UINT16 x = 0; x < invsize; ++x) { if(pLBE->inv[x].exists() == true) { @@ -2942,7 +2945,7 @@ UINT16 CalculateItemSize( OBJECTTYPE *pObject ) newSize = 0; maxSize = max(iSize, LoadBearingEquipment[Item[pObject->usItem].ubClassIndex].lbeFilledSize); // Look for the ItemSize of the largest item in this LBENODE - for(unsigned int x = 0; x < pLBE->inv.size(); ++x) + for(UINT16 x = 0; x < invsize; ++x) { if(pLBE->inv[x].exists() == true) { @@ -3074,8 +3077,10 @@ UINT16 OBJECTTYPE::GetWeightOfObjectInStack(unsigned int index) if(pItem->usItemClass == IC_LBEGEAR && IsActiveLBE(index) && (UsingNewInventorySystem() == true)) { LBENODE* pLBE = GetLBEPointer(index); - if (pLBE) { - for ( unsigned int subObjects = 0; subObjects < pLBE->inv.size(); subObjects++) + if (pLBE) + { + UINT16 invsize = pLBE->inv.size(); + for ( UINT16 subObjects = 0; subObjects < pLBE->inv.size(); ++subObjects) { if (pLBE->inv[subObjects].exists() == true) { @@ -3125,7 +3130,8 @@ UINT32 CalculateCarriedWeight( SOLDIERTYPE * pSoldier ) UINT32 ubStrengthForCarrying; //Pulmu: Changes for dynamic ammo weight - for( ubLoop = 0; ubLoop < pSoldier->inv.size(); ubLoop++) + UINT8 invsize = pSoldier->inv.size(); + for( ubLoop = 0; ubLoop < invsize; ++ubLoop) { //ADB the weight of the object is already counting stacked objects, attachments, et al uiTotalWeight += CalculateObjectWeight(&pSoldier->inv[ubLoop]); @@ -3156,7 +3162,6 @@ UINT32 CalculateCarriedWeight( SOLDIERTYPE * pSoldier ) uiPercent = (UINT32)(((FLOAT)20 * (FLOAT)gGameExternalOptions.iStrengthToLiftHalfKilo) * uiTotalWeight) / ( ubStrengthForCarrying ); return( uiPercent ); - } void DeleteObj(OBJECTTYPE * pObj ) @@ -3668,8 +3673,8 @@ INT8 FindAmmo( SOLDIERTYPE * pSoldier, UINT8 ubCalibre, UINT16 ubMagSize, UINT8 INVTYPE * pItem; //CHRISL: Update this to search for the largest appropriate mag if ubMagSize = ANY_MAGSIZE - - for (bLoop = HANDPOS; bLoop < (INT8)pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for (bLoop = HANDPOS; bLoop < invsize; ++bLoop) { //CHRISL: If in NIV, in combat and backpack is closed, don't look inside if(UsingNewAttachmentSystem() == true && (gTacticalStatus.uiFlags & INCOMBAT) && IsBackpackSlot(bLoop) == true && pSoldier->flags.ZipperFlag == FALSE) @@ -8445,7 +8450,8 @@ BOOLEAN RemoveObjectFromSoldierProfile( UINT8 ubProfile, UINT16 usItem ) return( TRUE ); } MERCPROFILESTRUCT* pProfile = &gMercProfiles[ ubProfile ]; - for (unsigned int bLoop = 0; bLoop < pProfile->inv.size(); bLoop++) + UINT8 invsize = pProfile->inv.size(); + for (UINT8 bLoop = 0; bLoop < invsize; ++bLoop) { if ( pProfile->inv[ bLoop ] == usItem ) { @@ -8495,9 +8501,9 @@ void SetMoneyInSoldierProfile( UINT8 ubProfile, UINT32 uiMoney ) INT8 FindObjectInSoldierProfile( UINT8 ubProfile, UINT16 usItem ) { - MERCPROFILESTRUCT* pProfile = &gMercProfiles[ ubProfile ]; - for (unsigned int bLoop = 0; bLoop < pProfile->inv.size(); bLoop++) + INT8 invsize = (INT8)pProfile->inv.size(); + for (INT8 bLoop = 0; bLoop < invsize; ++bLoop) { if ( pProfile->bInvNumber[ bLoop ] > 0 ) { @@ -8700,7 +8706,6 @@ BOOLEAN DamageItem( OBJECTTYPE * pObject, INT32 iDamage, BOOLEAN fOnGround ) void CheckEquipmentForDamage( SOLDIERTYPE *pSoldier, INT32 iDamage ) { - INT8 bSlot; BOOLEAN fBlowsUp; UINT8 ubNumberOfObjects; @@ -8709,7 +8714,8 @@ void CheckEquipmentForDamage( SOLDIERTYPE *pSoldier, INT32 iDamage ) return; } - for (bSlot = 0; bSlot < (INT8) pSoldier->inv.size(); bSlot++) + UINT8 invsize = pSoldier->inv.size(); + for (UINT8 bSlot = 0; bSlot < invsize; ++bSlot) { if (pSoldier->inv[bSlot].exists() == false) { continue; @@ -8744,11 +8750,11 @@ void CheckEquipmentForDamage( SOLDIERTYPE *pSoldier, INT32 iDamage ) void CheckEquipmentForFragileItemDamage( SOLDIERTYPE *pSoldier, INT32 iDamage ) { // glass jars etc can be damaged by falling over - INT8 bSlot; UINT8 ubNumberOfObjects; BOOLEAN fPlayedGlassBreak = FALSE; - for (bSlot = 0; bSlot < (INT8) pSoldier->inv.size(); bSlot++) + UINT8 invsize = pSoldier->inv.size(); + for (UINT8 bSlot = 0; bSlot < invsize; ++bSlot) { if (pSoldier->inv[bSlot].exists() == false) { continue; @@ -10912,7 +10918,7 @@ INT16 GetNightVisionRangeBonus( SOLDIERTYPE * pSoldier, UINT8 bLightLevel ) //ADB and AXP 28.03.2007: CtH bug fix: We also want to check on a firing weapon, "raised" alone is not enough ;) bool usingGunScope = WeaponReady(pSoldier); // CHRISL: - for (int i = BODYPOSSTART; i < BODYPOSFINAL; i++) + for (int i = BODYPOSSTART; i < BODYPOSFINAL; ++i ) { // More optimization pObj = &( pSoldier->inv[i]); @@ -11327,17 +11333,16 @@ INT16 GetTotalVisionRangeBonus( SOLDIERTYPE * pSoldier, UINT8 bLightLevel ) bonus += GetCaveVisionRangeBonus(pSoldier, bLightLevel); } } + else if ( bLightLevel < NORMAL_LIGHTLEVEL_DAY ) + { + bonus += GetBrightLightVisionRangeBonus(pSoldier, bLightLevel); + } if ( bLightLevel < NORMAL_LIGHTLEVEL_NIGHT ) { bonus += GetDayVisionRangeBonus(pSoldier, bLightLevel); } - if ( bLightLevel < NORMAL_LIGHTLEVEL_DAY ) - { - bonus += GetBrightLightVisionRangeBonus(pSoldier, bLightLevel); - } - // Flugente: drugs can alter our sight if ( pSoldier->drugs.bDrugEffect[ DRUG_TYPE_VISION ] ) { @@ -11918,9 +11923,8 @@ BOOLEAN EXPLOSIVE_GUN ( UINT16 x) INT8 FindRocketLauncherOrCannon( SOLDIERTYPE * pSoldier ) { - INT8 bLoop; - - for (bLoop = 0; bLoop < (INT8) pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for ( INT8 bLoop = 0; bLoop < invsize; ++bLoop) { if (pSoldier->inv[bLoop].exists() == true) { if (Item[pSoldier->inv[bLoop].usItem].rocketlauncher || Item[pSoldier->inv[bLoop].usItem].cannon ) @@ -11934,9 +11938,8 @@ INT8 FindRocketLauncherOrCannon( SOLDIERTYPE * pSoldier ) INT8 FindRocketLauncher( SOLDIERTYPE * pSoldier ) { - INT8 bLoop; - - for (bLoop = 0; bLoop < (INT8) pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for ( INT8 bLoop = 0; bLoop < invsize; ++bLoop) { if (pSoldier->inv[bLoop].exists() == true) { if (Item[pSoldier->inv[bLoop].usItem].rocketlauncher ) @@ -11950,9 +11953,8 @@ INT8 FindRocketLauncher( SOLDIERTYPE * pSoldier ) INT8 FindCannon( SOLDIERTYPE * pSoldier ) { - INT8 bLoop; - - for (bLoop = 0; bLoop < (INT8) pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for ( INT8 bLoop = 0; bLoop < invsize; ++bLoop) { if (pSoldier->inv[bLoop].exists() == true) { if ( Item[pSoldier->inv[bLoop].usItem].cannon ) @@ -11967,11 +11969,12 @@ INT8 FindCannon( SOLDIERTYPE * pSoldier ) INT8 FindUsableCrowbar( SOLDIERTYPE * pSoldier ) { //JMich_SkillModifiers: Adding a bonus check, to return the best crowbar, and modifying the return value. - INT8 bLoop, bonus, FoundCrowbar; + INT8 bonus, FoundCrowbar; FoundCrowbar = NO_SLOT; bonus = -101; - for (bLoop = 0; bLoop < (INT8) pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for ( INT8 bLoop = 0; bLoop < invsize; ++bLoop) { if (pSoldier->inv[bLoop].exists() == true) { if ( Item[pSoldier->inv[bLoop].usItem].crowbar && pSoldier->inv[bLoop][0]->data.objectStatus >= USABLE && Item[pSoldier->inv[bLoop].usItem].CrowbarModifier > bonus) @@ -11996,11 +11999,11 @@ OBJECTTYPE* FindAttachedBatteries( OBJECTTYPE * pObj ) } return( 0 ); } + INT8 FindToolkit( SOLDIERTYPE * pSoldier ) { - INT8 bLoop; - - for (bLoop = 0; bLoop < (INT8) pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for ( INT8 bLoop = 0; bLoop < invsize; ++bLoop) { if (pSoldier->inv[bLoop].exists() == true) { if (Item[pSoldier->inv[bLoop].usItem].toolkit ) @@ -12011,11 +12014,11 @@ INT8 FindToolkit( SOLDIERTYPE * pSoldier ) } return( NO_SLOT ); } + INT8 FindMedKit( SOLDIERTYPE * pSoldier ) { - INT8 bLoop; - - for (bLoop = 0; bLoop < (INT8) pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for ( INT8 bLoop = 0; bLoop < invsize; ++bLoop) { if (pSoldier->inv[bLoop].exists() == true) { if (Item[pSoldier->inv[bLoop].usItem].medicalkit ) @@ -12026,11 +12029,11 @@ INT8 FindMedKit( SOLDIERTYPE * pSoldier ) } return( NO_SLOT ); } + INT8 FindFirstAidKit( SOLDIERTYPE * pSoldier ) { - INT8 bLoop; - - for (bLoop = 0; bLoop < (INT8) pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for ( INT8 bLoop = 0; bLoop < invsize; ++bLoop) { if (pSoldier->inv[bLoop].exists() == true) { if (Item[pSoldier->inv[bLoop].usItem].firstaidkit ) @@ -12041,11 +12044,11 @@ INT8 FindFirstAidKit( SOLDIERTYPE * pSoldier ) } return( NO_SLOT ); } + INT8 FindCamoKit( SOLDIERTYPE * pSoldier ) { - INT8 bLoop; - - for (bLoop = 0; bLoop < (INT8) pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for ( INT8 bLoop = 0; bLoop < invsize; ++bLoop) { if (pSoldier->inv[bLoop].exists() == true) { if (Item[pSoldier->inv[bLoop].usItem].camouflagekit ) @@ -12056,14 +12059,16 @@ INT8 FindCamoKit( SOLDIERTYPE * pSoldier ) } return( NO_SLOT ); } + //JMich_SkillModifiers: Adding a function to see if we have an item with disarm bonus INT8 FindDisarmKit( SOLDIERTYPE * pSoldier ) { - INT8 bLoop, bonus, FoundKit; + INT8 bonus, FoundKit; FoundKit = NO_SLOT; bonus = 0; - for (bLoop = 0; bLoop < (INT8) pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for ( INT8 bLoop = 0; bLoop < invsize; ++bLoop) { if (pSoldier->inv[bLoop].exists() == true) { if ( ( ( Item[pSoldier->inv[bLoop].usItem].DisarmModifier * pSoldier->inv[bLoop][0]->data.objectStatus ) / 100 ) > bonus ) @@ -12075,17 +12080,20 @@ INT8 FindDisarmKit( SOLDIERTYPE * pSoldier ) } return( FoundKit ); } + INT8 FindLocksmithKit( SOLDIERTYPE * pSoldier ) { //JMich_SkillModifiers: Adding a bonus check, to return the best LocksmithKit, and modifying the return value. - INT8 bLoop, bonus, FoundKit; + INT8 bonus, FoundKit; FoundKit = NO_SLOT; bonus = -101; - for (bLoop = 0; bLoop < (INT8) pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for ( INT8 bLoop = 0; bLoop < invsize; ++bLoop) { - if (pSoldier->inv[bLoop].exists() == true) { - if (Item[pSoldier->inv[bLoop].usItem].locksmithkit ) + if (pSoldier->inv[bLoop].exists() == true) + { + if (Item[pSoldier->inv[bLoop].usItem].locksmithkit ) { //JMich_SkillModifiers: If the locksmith kit has a bonus, reduce it based on the status, so we use the best bonus. if (Item[pSoldier->inv[bLoop].usItem].LockPickModifier > 0 ) @@ -12094,9 +12102,9 @@ INT8 FindLocksmithKit( SOLDIERTYPE * pSoldier ) { bonus = ( Item[pSoldier->inv[bLoop].usItem].LockPickModifier * pSoldier->inv[bLoop][0]->data.objectStatus / 100 ); FoundKit = bLoop; - } + } - } + } //JMich_SkillModifiers: If on the other hand the locksmith is a shoddy one, keep that penalty regardless of status. else { @@ -12104,18 +12112,17 @@ INT8 FindLocksmithKit( SOLDIERTYPE * pSoldier ) { bonus = Item[pSoldier->inv[bLoop].usItem].LockPickModifier; FoundKit = bLoop; - } -} + } + } } } } return( FoundKit ); } + INT8 FindWalkman( SOLDIERTYPE * pSoldier ) { - INT8 bLoop; - - for (bLoop = BODYPOSSTART; bLoop < BODYPOSFINAL; bLoop++) + for (INT8 bLoop = BODYPOSSTART; bLoop < BODYPOSFINAL; bLoop++) { if (pSoldier->inv[bLoop].exists() == true) { if (Item[pSoldier->inv[bLoop].usItem].walkman ) @@ -12126,14 +12133,15 @@ INT8 FindWalkman( SOLDIERTYPE * pSoldier ) } return( NO_SLOT ); } + INT8 FindTrigger( SOLDIERTYPE * pSoldier ) { - INT8 bLoop; - - for (bLoop = 0; bLoop < (INT8) pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for ( INT8 bLoop = 0; bLoop < invsize; ++bLoop) { - if (pSoldier->inv[bLoop].exists() == true) { - if (Item[pSoldier->inv[bLoop].usItem].remotetrigger ) + if (pSoldier->inv[bLoop].exists() == true) + { + if (Item[pSoldier->inv[bLoop].usItem].remotetrigger ) { return( bLoop ); } @@ -12141,11 +12149,10 @@ INT8 FindTrigger( SOLDIERTYPE * pSoldier ) } return( NO_SLOT ); } + INT8 FindRemoteControl( SOLDIERTYPE * pSoldier ) { - INT8 bLoop; - - for (bLoop = BODYPOSSTART; bLoop < BODYPOSFINAL; bLoop++) + for (INT8 bLoop = BODYPOSSTART; bLoop < BODYPOSFINAL; ++bLoop) { if (pSoldier->inv[bLoop].exists() == true) { if (Item[pSoldier->inv[bLoop].usItem].robotremotecontrol ) @@ -12162,7 +12169,7 @@ UINT16 LowestLaunchableCoolness(UINT16 launcherIndex) UINT16 i = 0; UINT16 lowestCoolness = 999; - for( i = 0; i < MAXITEMS; i++ ) + for( i = 0; i < MAXITEMS; ++i ) { if ( Item[i].usItemClass == 0 ) break; @@ -12186,7 +12193,7 @@ UINT16 PickARandomLaunchable(UINT16 itemIndex) // WANNE: This should fix the hang on the merc positioning screen (fix by Razer) //while( !usNumMatches ) { //Count the number of valid launchables - for( i = 0; i < MAXITEMS; i++ ) + for( i = 0; i < MAXITEMS; ++i ) { if ( Item[i].usItemClass == 0 ) break; @@ -12199,7 +12206,7 @@ UINT16 PickARandomLaunchable(UINT16 itemIndex) if( usNumMatches ) { usRandom = (UINT16)Random( usNumMatches ); - for( i = 0; i < MAXITEMS; i++ ) + for( i = 0; i < MAXITEMS; ++i ) { if ( Item[i].usItemClass == 0 ) break; @@ -13437,7 +13444,7 @@ INT16 GetWornStealth( 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 ) ttl += GetStealthBonus(&pSoldier->inv[bLoop]); @@ -14049,7 +14056,7 @@ BOOLEAN UseTotalMedicalKitPoints( SOLDIERTYPE * pSoldier, UINT16 usPointsToConsu // add up kit points of all medkits // CHRISL: Changed to dynamically determine max inventory locations. - for (ubPocket = HANDPOS; ubPocket < NUM_INV_SLOTS; ubPocket++) + for (ubPocket = HANDPOS; ubPocket < NUM_INV_SLOTS; ++ubPocket) { if ( IsMedicalKitItem( &( pSoldier->inv[ ubPocket ] ) ) ) { @@ -15277,7 +15284,8 @@ UINT8 GetInventorySleepModifier( SOLDIERTYPE *pSoldier ) { UINT8 modifier = 0; - for ( UINT8 i = 0; i < pSoldier->inv.size(); i++ ) + UINT8 invsize = pSoldier->inv.size(); + for ( UINT8 i = 0; i < invsize; ++i ) { if( pSoldier->inv[ i ].exists() == true && Item[ pSoldier->inv[i].usItem ].ubSleepModifier > 0 ) { diff --git a/Tactical/Keys.cpp b/Tactical/Keys.cpp index f8ac8ed8..384d043c 100644 --- a/Tactical/Keys.cpp +++ b/Tactical/Keys.cpp @@ -194,9 +194,8 @@ BOOLEAN KeyExistsInKeyRing( SOLDIERTYPE *pSoldier, UINT8 ubKeyID, UINT8 * pubPos BOOLEAN KeyExistsInInventory( SOLDIERTYPE *pSoldier, UINT8 ubKeyID ) { - UINT8 ubLoop; - - for (ubLoop = 0; ubLoop < pSoldier->inv.size(); ubLoop++) + UINT8 invsize = pSoldier->inv.size(); + for (UINT8 ubLoop = 0; ubLoop < invsize; ++ubLoop) { if (Item[pSoldier->inv[ubLoop].usItem].usItemClass == IC_KEY) { @@ -742,7 +741,7 @@ BOOLEAN AttemptToBlowUpLock( SOLDIERTYPE * pSoldier, DOOR * pDoor ) } // Flugente: flat bonus to using door breaching charges - iResult = SkillCheck( pSoldier, PLANTING_BOMB_CHECK, pSoldier->GetBackgroundValue(BG_BONUS_BREACHINGCHARGE) ); + iResult = SkillCheck( pSoldier, PLANTING_BOMB_CHECK, (INT8)pSoldier->GetBackgroundValue(BG_BONUS_BREACHINGCHARGE) ); if (iResult >= -20) { // Do explosive graphic.... diff --git a/Tactical/Map Information.cpp b/Tactical/Map Information.cpp index 741cbdd6..afa97737 100644 --- a/Tactical/Map Information.cpp +++ b/Tactical/Map Information.cpp @@ -271,7 +271,7 @@ void UpdateOldVersionMap() { gMapInformation.ubMapVersion++; //6) Change all doors to FIRSTDOOR - for( i = 0; i < WORLD_MAX; i++ ) + for( i = 0; i < WORLD_MAX; ++i ) { //NOTE: Here are the index values for the various doors //DOOR OPEN CLOSED @@ -348,7 +348,8 @@ void UpdateOldVersionMap() //Bug #04) Assign enemy mercs default army color code if applicable if( curr->pDetailedPlacement ) { - for( i = 0; i < curr->pDetailedPlacement->Inv.size(); i++ ) + INT32 invsize = (INT32)curr->pDetailedPlacement->Inv.size(); + for( i = 0; i < invsize; ++i ) { //make all items undroppable, even if it is empty. This will allow for //random item generation, while empty, droppable slots are locked as empty //during random item generation. @@ -476,7 +477,7 @@ void UpdateOldVersionMap() } if( gMapInformation.ubMapVersion < 13 ) { //replace all merc ammo inventory slots status value with the max ammo that the clip can hold. - INT32 i, cnt; + INT32 cnt; OBJECTTYPE *pItem; gMapInformation.ubMapVersion++; //Bug 10) Padding on detailed placements is uninitialized. Clear all data starting at @@ -486,12 +487,13 @@ void UpdateOldVersionMap() { if( curr->pDetailedPlacement ) { - for ( i = 0; i < curr->pDetailedPlacement->Inv.size(); i++ ) + UINT32 invsize = curr->pDetailedPlacement->Inv.size(); + for ( UINT32 i = 0; i < invsize; ++i ) { pItem = &curr->pDetailedPlacement->Inv[ i ]; if( Item[ pItem->usItem ].usItemClass & IC_AMMO ) { - for( cnt = 0; cnt < pItem->ubNumberOfObjects; cnt++ ) + for( cnt = 0; cnt < pItem->ubNumberOfObjects; ++cnt ) { pItem->shots.ubShotsLeft[ cnt ] = Magazine[ Item[ pItem->usItem ].ubClassIndex ].ubMagSize; } @@ -571,7 +573,8 @@ void UpdateOldVersionMap() { if( curr->pDetailedPlacement ) { - for( UINT32 i = 0; i < curr->pDetailedPlacement->Inv.size(); i++ ) + UINT32 invsize = curr->pDetailedPlacement->Inv.size(); + for( UINT32 i = 0; i < invsize; ++i ) { if( !curr->pDetailedPlacement->Inv[ i ].usItem ) { @@ -645,7 +648,8 @@ void AutoCalculateItemNoOverwriteStatus() { if( curr->pDetailedPlacement ) { - for( UINT32 i = 0; i < curr->pDetailedPlacement->Inv.size(); i++ ) + UINT32 invsize = curr->pDetailedPlacement->Inv.size(); + for( UINT32 i = 0; i < invsize; ++i ) { pItem = &curr->pDetailedPlacement->Inv[ i ]; if( pItem->exists() == true ) diff --git a/Tactical/Overhead.cpp b/Tactical/Overhead.cpp index 33e7455e..f183b142 100644 --- a/Tactical/Overhead.cpp +++ b/Tactical/Overhead.cpp @@ -4990,7 +4990,7 @@ BOOLEAN TeamMemberNear(INT8 bTeam, INT32 sGridNo, INT32 iRange) UINT8 bLoop; SOLDIERTYPE * pSoldier; - for (bLoop=gTacticalStatus.Team[bTeam].bFirstID, pSoldier=MercPtrs[bLoop]; bLoop <= gTacticalStatus.Team[bTeam].bLastID; bLoop++, pSoldier++) + for (bLoop=gTacticalStatus.Team[bTeam].bFirstID, pSoldier=MercPtrs[bLoop]; bLoop <= gTacticalStatus.Team[bTeam].bLastID; ++bLoop, pSoldier++) { if (pSoldier->bActive && pSoldier->bInSector && (pSoldier->stats.bLife >= OKLIFE) && !( pSoldier->flags.uiStatusFlags & SOLDIER_GASSED ) ) { @@ -5042,52 +5042,47 @@ INT32 FindAdjacentGridEx( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 *pubDirect *psAdjustedGridNo = sGridNo; } - // CHECK IF IT'S THE SAME ONE AS WE'RE ON, IF SO, RETURN THAT! - if ( pSoldier->sGridNo == sGridNo && !FindStructure( sGridNo, ( STRUCTURE_SWITCH ) ) ) - { - // OK, if we are looking for a door, it may be in the same tile as us, so find the direction we - // have to face to get to the door, not just our initial direction... - // If we are in the same tile as a switch, we can NEVER pull it.... - if( fDoor ) - { - // This can only happen if a door was to the south to east of us! + // Flugente: change condition order + // OK, if we are looking for a door, it may be in the same tile as us, so find the direction we + // have to face to get to the door, not just our initial direction... + // If we are in the same tile as a switch, we can NEVER pull it.... + if (pubDirection && fDoor ) + { + // CHECK IF IT'S THE SAME ONE AS WE'RE ON, IF SO, RETURN THAT! + if ( pSoldier->sGridNo == sGridNo && !FindStructure( sGridNo, ( STRUCTURE_SWITCH ) ) ) + { + // This can only happen if a door was to the south to east of us! - // Do south! - //sSpot = NewGridNo( sGridNo, DirectionInc( SOUTH ) ); + // Do south! + //sSpot = NewGridNo( sGridNo, DirectionInc( SOUTH ) ); - // ATE: Added: Switch behave EXACTLY like doors - pDoor = FindStructure( sGridNo, ( STRUCTURE_ANYDOOR ) ); + // ATE: Added: Switch behave EXACTLY like doors + pDoor = FindStructure( sGridNo, ( STRUCTURE_ANYDOOR ) ); - if ( pDoor != NULL ) - { - // Get orinetation - ubWallOrientation = pDoor->ubWallOrientation; + if ( pDoor != NULL ) + { + // Get orinetation + ubWallOrientation = pDoor->ubWallOrientation; - if ( ubWallOrientation == OUTSIDE_TOP_LEFT || ubWallOrientation == INSIDE_TOP_LEFT ) - { - // To the south! - sSpot = NewGridNo( sGridNo, DirectionInc( SOUTH ) ); - if (pubDirection) - { - (*pubDirection) = (UINT8)GetDirectionFromGridNo( sSpot, pSoldier ); - } - } + if ( ubWallOrientation == OUTSIDE_TOP_LEFT || ubWallOrientation == INSIDE_TOP_LEFT ) + { + // To the south! + sSpot = NewGridNo( sGridNo, DirectionInc( SOUTH ) ); + (*pubDirection) = (UINT8)GetDirectionFromGridNo( sSpot, pSoldier ); + } - if ( ubWallOrientation == OUTSIDE_TOP_RIGHT || ubWallOrientation == INSIDE_TOP_RIGHT ) - { - // TO the east! - sSpot = NewGridNo( sGridNo, DirectionInc( EAST ) ); - if (pubDirection) - { - (*pubDirection) = (UINT8)GetDirectionFromGridNo( sSpot, pSoldier ); - } - } - } - } + if ( ubWallOrientation == OUTSIDE_TOP_RIGHT || ubWallOrientation == INSIDE_TOP_RIGHT ) + { + // TO the east! + sSpot = NewGridNo( sGridNo, DirectionInc( EAST ) ); + (*pubDirection) = (UINT8)GetDirectionFromGridNo( sSpot, pSoldier ); + } + } - // Use soldier's direction - return( sGridNo ); - } + // Use soldier's direction + return( sGridNo ); + } + } // Look for a door! if (fDoor) @@ -5101,20 +5096,20 @@ INT32 FindAdjacentGridEx( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 *pubDirect if ( fForceToPerson ) { - if ( FindSoldier( sGridNo, &usSoldierIndex, &uiMercFlags, FIND_SOLDIER_GRIDNO ) ) - { - sGridNo = MercPtrs[ usSoldierIndex ]->sGridNo; - if ( psAdjustedGridNo != NULL ) - { - *psAdjustedGridNo = sGridNo; + if ( psAdjustedGridNo != NULL ) + { + if ( FindSoldier( sGridNo, &usSoldierIndex, &uiMercFlags, FIND_SOLDIER_GRIDNO ) ) + { + sGridNo = MercPtrs[ usSoldierIndex ]->sGridNo; + *psAdjustedGridNo = sGridNo; - // Use direction to this guy! - if (pubDirection) - { - (*pubDirection) = (UINT8)GetDirectionFromGridNo( sGridNo, pSoldier ); - } - } - } + // Use direction to this guy! + if (pubDirection) + { + (*pubDirection) = (UINT8)GetDirectionFromGridNo( sGridNo, pSoldier ); + } + } + } } @@ -5137,25 +5132,22 @@ INT32 FindAdjacentGridEx( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 *pubDirect fCheckGivenGridNo = FALSE; } - if ( fCheckGivenGridNo ) { sDistance = PlotPath( pSoldier, sGridNo, NO_COPYROUTE, NO_PLOT, TEMPORARY, (INT16)pSoldier->usUIMovementMode, NOT_STEALTH, FORWARD, pSoldier->bActionPoints ); if ( sDistance > 0 ) { - if ( sDistance < sClosest ) { - sClosest = sDistance; + sClosest = sDistance; sCloseGridNo = sGridNo; } } } } - - for (INT8 cnt = 0; cnt < 4; cnt++) + for (INT8 cnt = 0; cnt < 4; ++cnt) { // MOVE OUT TWO DIRECTIONS sFourGrids[cnt] = sSpot = NewGridNo( sGridNo, DirectionInc( sDirs[ cnt ] ) ); @@ -5284,12 +5276,13 @@ INT32 FindAdjacentGridEx( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 *pubDirect //} if ( TileIsOutOfBounds( sCloseGridNo ) ) { - return( -1 ); + return( NOWHERE ); } + return( sCloseGridNo ); } - else - return( -1 ); + + return( NOWHERE ); } @@ -5340,15 +5333,12 @@ INT32 FindNextToAdjacentGridEx( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 *pub pDoor = NULL; } - if ( fForceToPerson ) + if ( fForceToPerson && psAdjustedGridNo != NULL ) { if ( FindSoldier( sGridNo, &usSoldierIndex, &uiMercFlags, FIND_SOLDIER_GRIDNO ) ) { sGridNo = MercPtrs[ usSoldierIndex ]->sGridNo; - if ( psAdjustedGridNo != NULL ) - { - *psAdjustedGridNo = sGridNo; - } + *psAdjustedGridNo = sGridNo; } } @@ -5371,7 +5361,6 @@ INT32 FindNextToAdjacentGridEx( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 *pub if ( sDistance > 0 ) { - if ( sDistance < sClosest ) { sClosest = sDistance; @@ -5513,12 +5502,13 @@ INT32 FindNextToAdjacentGridEx( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 *pub if (TileIsOutOfBounds(sCloseGridNo)) { - return( -1 ); + return( NOWHERE ); } + return( sCloseGridNo ); } - else - return( -1 ); + + return( NOWHERE ); @@ -5564,7 +5554,7 @@ INT32 FindAdjacentPunchTarget( SOLDIERTYPE * pSoldier, SOLDIERTYPE * pTargetSold INT32 sSpot; UINT8 ubGuyThere; - for ( INT8 cnt = 0; cnt < NUM_WORLD_DIRECTIONS; cnt++ ) + for ( UINT8 cnt = 0; cnt < NUM_WORLD_DIRECTIONS; ++cnt ) { sSpot = NewGridNo( pSoldier->sGridNo, DirectionInc( cnt ) ); @@ -5582,7 +5572,7 @@ INT32 FindAdjacentPunchTarget( SOLDIERTYPE * pSoldier, SOLDIERTYPE * pTargetSold // We've got a guy here.... // Who is the one we want...... *psAdjustedTargetGridNo = pTargetSoldier->sGridNo; - *pubDirection = ( UINT8 )cnt; + *pubDirection = cnt; return( sSpot ); } } @@ -5605,7 +5595,6 @@ BOOLEAN UIOKMoveDestination( SOLDIERTYPE *pSoldier, INT32 usMapPos ) } } - if ( !NewOKDestination( pSoldier, usMapPos, FALSE, (INT8) gsInterfaceLevel ) ) { return( FALSE ); @@ -5626,8 +5615,7 @@ BOOLEAN UIOKMoveDestination( SOLDIERTYPE *pSoldier, INT32 usMapPos ) //{ // return( FALSE ); //} - - + return( TRUE); } @@ -5637,7 +5625,7 @@ void HandleTeamServices( UINT8 ubTeamNum ) INT32 cnt; SOLDIERTYPE *pTeamSoldier, *pTargetSoldier; UINT32 uiPointsUsed; - UINT16 usSoldierIndex, usInHand; + UINT16 usSoldierIndex; UINT16 usKitPts; INT8 bSlot; BOOLEAN fDone; @@ -5646,7 +5634,7 @@ void HandleTeamServices( UINT8 ubTeamNum ) cnt = gTacticalStatus.Team[ ubTeamNum ].bFirstID; // look for all mercs on the same team, - for ( pTeamSoldier = MercPtrs[ cnt ]; cnt <= gTacticalStatus.Team[ ubTeamNum ].bLastID; cnt++,pTeamSoldier++) + for ( pTeamSoldier = MercPtrs[ cnt ]; cnt <= gTacticalStatus.Team[ ubTeamNum ].bLastID; ++cnt, pTeamSoldier++) { if ( pTeamSoldier->stats.bLife >= OKLIFE && pTeamSoldier->bActive && pTeamSoldier->bInSector ) { @@ -5654,10 +5642,7 @@ void HandleTeamServices( UINT8 ubTeamNum ) // Check for different events! // FOR DOING AID if ( pTeamSoldier->usAnimState == GIVING_AID || pTeamSoldier->usAnimState == GIVING_AID_PRN ) - { - // Get medkit info - usInHand = pTeamSoldier->inv[ HANDPOS ].usItem; - + { // Get victim pointer usSoldierIndex = WhoIsThere2( pTeamSoldier->sTargetGridNo, pTeamSoldier->pathing.bLevel ); if ( usSoldierIndex != NOBODY ) @@ -5717,14 +5702,12 @@ void HandleTeamServices( UINT8 ubTeamNum ) { pTeamSoldier->DoMercBattleSound( (INT8)( BATTLE_SOUND_CURSE1 ) ); } - } } } } } } - } } @@ -5732,7 +5715,7 @@ void HandlePlayerServices( SOLDIERTYPE *pTeamSoldier ) { SOLDIERTYPE *pTargetSoldier; UINT32 uiPointsUsed; - UINT16 usSoldierIndex, usInHand; + UINT16 usSoldierIndex; UINT16 usKitPts; INT8 bSlot; BOOLEAN fDone = FALSE; @@ -5743,9 +5726,6 @@ void HandlePlayerServices( SOLDIERTYPE *pTeamSoldier ) // FOR DOING AID if ( pTeamSoldier->usAnimState == GIVING_AID || pTeamSoldier->usAnimState == GIVING_AID_PRN ) { - // Get medkit info - usInHand = pTeamSoldier->inv[ HANDPOS ].usItem; - // Get victim pointer usSoldierIndex = WhoIsThere2( pTeamSoldier->sTargetGridNo, pTeamSoldier->pathing.bLevel ); @@ -5853,7 +5833,7 @@ void CommonEnterCombatModeCode( ) // OK, loop thorugh all guys and stop them! // Loop through all mercs and make go - for ( pSoldier = Menptr, cnt = 0; cnt < TOTAL_SOLDIERS; pSoldier++, cnt++ ) + for ( pSoldier = Menptr, cnt = 0; cnt < TOTAL_SOLDIERS; pSoldier++, ++cnt ) { if ( pSoldier->bActive ) { @@ -5908,7 +5888,7 @@ void CommonEnterCombatModeCode( ) } } - if ( !gTacticalStatus.fHasEnteredCombatModeSinceEntering ) + /*if ( !gTacticalStatus.fHasEnteredCombatModeSinceEntering ) { // ATE: reset player's movement mode at the very start of // combat @@ -5916,7 +5896,7 @@ void CommonEnterCombatModeCode( ) //{ //pSoldier->usUIMovementMode = RUNNING; //} - } + }*/ } } } @@ -5940,7 +5920,6 @@ void CommonEnterCombatModeCode( ) SetMusicMode( MUSIC_TACTICAL_BATTLE ); DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"CommonEnterCombatMode done"); - } @@ -5991,7 +5970,7 @@ void EnterCombatMode( UINT8 ubStartingTeam ) { DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"EnterCombatMode continuing... nobody selected"); // OK, look through and find one.... - for ( cnt = gTacticalStatus.Team[ gbPlayerNum ].bFirstID, pTeamSoldier = MercPtrs[ cnt ]; cnt <= gTacticalStatus.Team[ gbPlayerNum ].bLastID; cnt++, pTeamSoldier++ ) + for ( cnt = gTacticalStatus.Team[ gbPlayerNum ].bFirstID, pTeamSoldier = MercPtrs[ cnt ]; cnt <= gTacticalStatus.Team[ gbPlayerNum ].bLastID; ++cnt, pTeamSoldier++ ) { if ( OK_CONTROLLABLE_MERC( pTeamSoldier ) && pTeamSoldier->aiData.bOppCnt > 0 ) { @@ -6021,7 +6000,6 @@ void EnterCombatMode( UINT8 ubStartingTeam ) } DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"EnterCombatMode done"); - } @@ -10083,7 +10061,7 @@ INT8 CheckStatusNearbyFriendlies( SOLDIERTYPE *pSoldier ) } } // Incapacitated or heavily suppressed friends will not be good for our tolerance! - else if (pLeader != pSoldier && pLeader->bActive && (pLeader->aiData.bShock > pSoldier->aiData.bShock || pLeader->stats.bLife <= OKLIFE) ) + else if ( (pLeader->aiData.bShock > pSoldier->aiData.bShock || pLeader->stats.bLife <= OKLIFE) ) { usEffectiveRangeToLeader = PythSpacesAway( pSoldier->sGridNo, pLeader->sGridNo ); // If they are no more than 5 tiles away, diff --git a/Tactical/Points.cpp b/Tactical/Points.cpp index 36db9816..e4f756c3 100644 --- a/Tactical/Points.cpp +++ b/Tactical/Points.cpp @@ -2611,17 +2611,18 @@ INT16 MinPtsToMove(SOLDIERTYPE *pSoldier) // WANNE - BMP: FIX: Valid directions are only from 0-7!! //for (cnt=0; cnt <= 8; cnt++) - for (cnt=0; cnt < 8; cnt++) + for (cnt=0; cnt < 8; ++cnt) { - sGridNo = NewGridNo(pSoldier->sGridNo,DirectionInc(cnt)); - if (sGridNo != pSoldier->sGridNo) + sGridNo = NewGridNo(pSoldier->sGridNo,DirectionInc(cnt)); + if (sGridNo != pSoldier->sGridNo) + { + if ( (sCost=ActionPointCost( pSoldier, sGridNo, cnt , pSoldier->usUIMovementMode ) ) < sLowest ) { - if ( (sCost=ActionPointCost( pSoldier, sGridNo, cnt , pSoldier->usUIMovementMode ) ) < sLowest ) - { - sLowest = sCost; + sLowest = sCost; } } } + return(sLowest);//dnl ch64 290813 100AP made INT8 return obsolete } diff --git a/Tactical/Rotting Corpses.cpp b/Tactical/Rotting Corpses.cpp index 045c6066..40e058a2 100644 --- a/Tactical/Rotting Corpses.cpp +++ b/Tactical/Rotting Corpses.cpp @@ -990,7 +990,8 @@ BOOLEAN TurnSoldierIntoCorpse( SOLDIERTYPE *pSoldier, BOOLEAN fRemoveMerc, BOOLE else { // OK, Place what objects this guy was carrying on the ground! - for ( cnt = 0; cnt < pSoldier->inv.size(); ++cnt ) + UINT32 invsize = pSoldier->inv.size(); + for ( cnt = 0; cnt < invsize; ++cnt ) { pObj = &( pSoldier->inv[ cnt ] ); @@ -2414,7 +2415,6 @@ void ReduceAmmoDroppedByNonPlayerSoldiers( SOLDIERTYPE *pSoldier, INT32 iInvSlot Assert( pSoldier ); Assert( ( iInvSlot >= 0 ) && ( iInvSlot < (INT32)pSoldier->inv.size() ) ); - // if not a player soldier if ( pSoldier->bTeam != gbPlayerNum ) { diff --git a/Tactical/ShopKeeper Interface.cpp b/Tactical/ShopKeeper Interface.cpp index a4de315a..3be19b0c 100644 --- a/Tactical/ShopKeeper Interface.cpp +++ b/Tactical/ShopKeeper Interface.cpp @@ -6374,18 +6374,17 @@ BOOLEAN RemoveRepairItemFromDealersOfferArea( INT16 bSlot ) INT8 GetInvSlotOfUnfullMoneyInMercInventory( SOLDIERTYPE *pSoldier ) { - UINT8 ubCnt; - //loop through the soldier's inventory - for( ubCnt=0; ubCnt < pSoldier->inv.size(); ubCnt++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for( INT8 bCnt=0; bCnt < invsize; ++bCnt) { // Look for MONEY only, not Gold or Silver!!! And look for a slot not already full - if( ( pSoldier->inv[ ubCnt ].usItem == MONEY ) && ( pSoldier->inv[ ubCnt ][0]->data.money.uiMoneyAmount < MoneySlotLimit( ubCnt ) ) ) + if( ( pSoldier->inv[ bCnt ].usItem == MONEY ) && ( pSoldier->inv[ bCnt ][0]->data.money.uiMoneyAmount < MoneySlotLimit( bCnt ) ) ) { - return( ubCnt ); + return( bCnt ); } } - return( - 1 ); + return( NO_SLOT ); } diff --git a/Tactical/Soldier Control.cpp b/Tactical/Soldier Control.cpp index 0b8ffe44..0e4927cc 100644 --- a/Tactical/Soldier Control.cpp +++ b/Tactical/Soldier Control.cpp @@ -1070,7 +1070,8 @@ UINT32 SOLDIERTYPE::GetChecksum( ) uiChecksum *= (this->stats.bExpLevel + 1); uiChecksum += (this->ubProfile + 1); - for ( uiLoop = 0; uiLoop < this->inv.size(); uiLoop++ ) + UINT32 invsize = this->inv.size(); + for ( uiLoop = 0; uiLoop < invsize; ++uiLoop ) { uiChecksum += this->inv[ uiLoop ].usItem; uiChecksum += this->inv[ uiLoop ].ubNumberOfObjects; @@ -1221,7 +1222,8 @@ UINT32 MERCPROFILESTRUCT::GetChecksum( ) // put in some multipliers too! uiChecksum *= (this->bExpLevel + 1); - for ( uiLoop = 0; uiLoop < this->inv.size(); uiLoop++ ) + UINT32 invsize = this->inv.size(); + for ( uiLoop = 0; uiLoop < invsize; ++uiLoop ) { uiChecksum += this->inv[ uiLoop ]; uiChecksum += this->bInvNumber[ uiLoop ]; @@ -20614,11 +20616,13 @@ UINT8 GetSquadleadersCountInVicinity( SOLDIERTYPE * pSoldier, BOOLEAN fWithHighe // check if within distance // if both have extended ear, the distance is bigger and they don't need to sea each other // note that enemy always get the bonus if within distance, regardless of extended ears - if (((( HasExtendedEarOn( pSoldier ) && HasExtendedEarOn( MercPtrs[ cnt ] )) || ( pSoldier->bTeam == ENEMY_TEAM ) ) && (PythSpacesAway( pSoldier->sGridNo, MercPtrs[ cnt ]->sGridNo ) <= gSkillTraitValues.usSLRadiusExtendedEar) ) || + // Flugente: moved around arguments for speed reason + if ( fDontCheckDistance || + (PythSpacesAway( pSoldier->sGridNo, MercPtrs[ cnt ]->sGridNo ) <= gSkillTraitValues.usSLRadiusNormal) || //((SoldierToVirtualSoldierLineOfSightTest( MercPtrs[ cnt ], pSoldier->sGridNo, pSoldier->pathing.bLevel, ANIM_STAND, TRUE, CALC_FROM_ALL_DIRS ) || //SoldierToVirtualSoldierLineOfSightTest( pSoldier, MercPtrs[ cnt ]->sGridNo, MercPtrs[ cnt ]->pathing.bLevel, ANIM_STAND, TRUE, CALC_FROM_ALL_DIRS ) ) && - (PythSpacesAway( pSoldier->sGridNo, MercPtrs[ cnt ]->sGridNo ) <= gSkillTraitValues.usSLRadiusNormal) || - fDontCheckDistance ) + ( ( pSoldier->bTeam == ENEMY_TEAM || (HasExtendedEarOn( pSoldier ) && HasExtendedEarOn( MercPtrs[ cnt ] ) ) ) && PythSpacesAway( pSoldier->sGridNo, MercPtrs[ cnt ]->sGridNo ) <= gSkillTraitValues.usSLRadiusExtendedEar ) + ) { // If checking for higher level SL // also count in already aquired level increses from other SLs @@ -20631,6 +20635,7 @@ UINT8 GetSquadleadersCountInVicinity( SOLDIERTYPE * pSoldier, BOOLEAN fWithHighe { ubNumberSL += NUM_SKILL_TRAITS( MercPtrs[ cnt ], SQUADLEADER_NT ); } + if (ubNumberSL >= gSkillTraitValues.ubSLMaxBonuses) break; } @@ -20640,18 +20645,20 @@ UINT8 GetSquadleadersCountInVicinity( SOLDIERTYPE * pSoldier, BOOLEAN fWithHighe // special loop for militia - they can get a bonus from our mercs if ( pSoldier->bTeam == MILITIA_TEAM && ubNumberSL < gSkillTraitValues.ubSLMaxBonuses ) { - for ( cnt = gTacticalStatus.Team[ OUR_TEAM ].bFirstID ; cnt <= gTacticalStatus.Team[ OUR_TEAM ].bLastID ; cnt++ ) + for ( cnt = gTacticalStatus.Team[ OUR_TEAM ].bFirstID ; cnt <= gTacticalStatus.Team[ OUR_TEAM ].bLastID ; ++cnt ) { // Get active conscious soldier if (MercPtrs[ cnt ] != pSoldier && MercPtrs[ cnt ]->bActive && //MercPtrs[ cnt ]->aiData.bShock < 20 && MercPtrs[ cnt ]->stats.bLife >= OKLIFE && HAS_SKILL_TRAIT( MercPtrs[ cnt ], SQUADLEADER_NT )) { // check if within distance - if (((HasExtendedEarOn( MercPtrs[ cnt ] ) && (PythSpacesAway( pSoldier->sGridNo, MercPtrs[ cnt ]->sGridNo ) <= gSkillTraitValues.usSLRadiusExtendedEar) ) || - //((SoldierToVirtualSoldierLineOfSightTest( MercPtrs[ cnt ], pSoldier->sGridNo, pSoldier->pathing.bLevel, ANIM_STAND, TRUE, CALC_FROM_ALL_DIRS ) || - //SoldierToVirtualSoldierLineOfSightTest( pSoldier, MercPtrs[ cnt ]->sGridNo, MercPtrs[ cnt ]->pathing.bLevel, ANIM_STAND, TRUE, CALC_FROM_ALL_DIRS ) ) && - (PythSpacesAway( pSoldier->sGridNo, MercPtrs[ cnt ]->sGridNo ) <= gSkillTraitValues.usSLRadiusNormal)) || - fDontCheckDistance ) + // Flugente: moved around arguments for speed reason + if ( fDontCheckDistance || + (PythSpacesAway( pSoldier->sGridNo, MercPtrs[ cnt ]->sGridNo ) <= gSkillTraitValues.usSLRadiusNormal) || + //((SoldierToVirtualSoldierLineOfSightTest( MercPtrs[ cnt ], pSoldier->sGridNo, pSoldier->pathing.bLevel, ANIM_STAND, TRUE, CALC_FROM_ALL_DIRS ) || + //SoldierToVirtualSoldierLineOfSightTest( pSoldier, MercPtrs[ cnt ]->sGridNo, MercPtrs[ cnt ]->pathing.bLevel, ANIM_STAND, TRUE, CALC_FROM_ALL_DIRS ) ) && + ((HasExtendedEarOn( MercPtrs[ cnt ] ) && PythSpacesAway( pSoldier->sGridNo, MercPtrs[ cnt ]->sGridNo ) <= gSkillTraitValues.usSLRadiusExtendedEar) ) + ) { // If checking for higher level SL // also count in already aquired level increses from other SLs @@ -20664,6 +20671,7 @@ UINT8 GetSquadleadersCountInVicinity( SOLDIERTYPE * pSoldier, BOOLEAN fWithHighe { ubNumberSL += NUM_SKILL_TRAITS( MercPtrs[ cnt ], SQUADLEADER_NT ); } + if (ubNumberSL >= gSkillTraitValues.ubSLMaxBonuses) break; } diff --git a/Tactical/Soldier Create.cpp b/Tactical/Soldier Create.cpp index df917a5c..3df0340e 100644 --- a/Tactical/Soldier Create.cpp +++ b/Tactical/Soldier Create.cpp @@ -2549,7 +2549,8 @@ void CreateStaticDetailedPlacementGivenBasicPlacementInfo( SOLDIERCREATE_STRUCT memcpy( spp->sPatrolGrid, bp->sPatrolGrid, sizeof( INT32 ) * MAXPATROLGRIDS ); //Starts with nothing - for( i = 0; i < spp->Inv.size(); i++ ) + UINT32 invsize = spp->Inv.size(); + for( i = 0; i < invsize; ++i ) { DeleteObj(&spp->Inv[ i ]); spp->Inv[ i ].fFlags |= OBJECT_UNDROPPABLE; @@ -2628,7 +2629,8 @@ void CreateDetailedPlacementGivenStaticDetailedPlacementAndBasicPlacementInfo( //This isn't perfect, however, it blindly brings over the items from the static //detailed placement. Due to the order of things, other items would - for( i = 0; i < spp->Inv.size(); i++ ) + UINT32 invsize = spp->Inv.size(); + for( i = 0; i < invsize; ++i ) { //copy over static items and empty slots that are droppable (signifies a forced empty slot) if( spp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE ) @@ -2776,7 +2778,8 @@ void UpdateStaticDetailedPlacementWithProfileInformation( SOLDIERCREATE_STRUCT * spp->bBodyType = pProfile->ubBodyType; // Copy over inv if we want to - for ( cnt = 0; cnt < pProfile->inv.size(); cnt++ ) + UINT32 invsize = pProfile->inv.size(); + for ( cnt = 0; cnt < invsize; ++cnt ) { CreateItems( pProfile->inv[ cnt ], pProfile->bInvStatus[ cnt ], pProfile->bInvNumber[ cnt ], &(spp->Inv[ cnt ]) ); } @@ -3531,7 +3534,6 @@ void CopyProfileItems( SOLDIERTYPE *pSoldier, SOLDIERCREATE_STRUCT *pCreateStruc BOOLEAN success; BOOLEAN fRet; - pProfile = &(gMercProfiles[pCreateStruct->ubProfile]); // Copy over inv if we want to @@ -3544,7 +3546,8 @@ void CopyProfileItems( SOLDIERTYPE *pSoldier, SOLDIERCREATE_STRUCT *pCreateStruc // CHRISL: Resort profile items to use LBE pockets properly DistributeInitialGear(pProfile); //place all items that are NOT attachments - for ( cnt = 0; cnt < pProfile->inv.size(); cnt++ ) + UINT32 invsize = pProfile->inv.size(); + for ( cnt = 0; cnt < pProfile->inv.size(); ++cnt ) { if ( pProfile->inv[ cnt ] == NOTHING || Item[pProfile->inv[cnt]].attachment) { continue; @@ -3564,8 +3567,9 @@ void CopyProfileItems( SOLDIERTYPE *pSoldier, SOLDIERCREATE_STRUCT *pCreateStruc } } } + //done placing all non attachments, now place all attachments on objects! - for ( cnt = 0; cnt < pProfile->inv.size(); cnt++ ) + for ( cnt = 0; cnt < invsize; ++cnt ) { if ( pProfile->inv[ cnt ] == NOTHING) { continue; @@ -4647,7 +4651,8 @@ BOOLEAN AssignTraitsToSoldier( SOLDIERTYPE *pSoldier, SOLDIERCREATE_STRUCT *pCre BOOLEAN fRadioSetFound = FALSE; // FIRST FIND OUT THE COMPOSITION OF OUR GEAR - for (bLoop = 0; bLoop < (INT8) pSoldier->inv.size(); bLoop++) + INT8 invsize = (INT8)pSoldier->inv.size(); + for (bLoop = 0; bLoop < invsize; ++bLoop) { if (pCreateStruct->Inv[bLoop].exists() == true) { diff --git a/Tactical/Soldier Profile.cpp b/Tactical/Soldier Profile.cpp index 196dce0f..731eae70 100644 --- a/Tactical/Soldier Profile.cpp +++ b/Tactical/Soldier Profile.cpp @@ -882,7 +882,8 @@ BOOLEAN LoadMercProfiles(void) gMercProfiles[uiLoop].bMainGunAttractiveness = -1; gMercProfiles[uiLoop].bArmourAttractiveness = -1; - for ( uiLoop2 = 0; uiLoop2 < gMercProfiles[uiLoop].inv.size(); uiLoop2++ ) + UINT32 invsize = gMercProfiles[ uiLoop ].inv.size(); + for ( uiLoop2 = 0; uiLoop2 < invsize; ++uiLoop2 ) { usItem = gMercProfiles[uiLoop].inv[ uiLoop2 ]; @@ -933,7 +934,7 @@ BOOLEAN LoadMercProfiles(void) //with old binary file optional gear prices which got ported into MercProfiles.xml gMercProfiles[ uiLoop ].usOptionalGearCost = 0; UINT16 tempGearCost = 0; - for ( uiLoop2 = 0; uiLoop2< gMercProfiles[ uiLoop ].inv.size(); uiLoop2++ ) + for ( uiLoop2 = 0; uiLoop2< invsize; ++uiLoop2 ) { if ( gMercProfiles[ uiLoop ].inv[ uiLoop2 ] != NOTHING ) { @@ -1771,15 +1772,17 @@ SOLDIERTYPE *ChangeSoldierTeam( SOLDIERTYPE *pSoldier, UINT8 ubTeam ) //if(UsingNewInventorySystem() == true) { // Start by direct copy of all BODYPOS items (armor, hands, head and LBE) - for(cnt = 0; cnt < (UINT32)BODYPOSFINAL; cnt++) + for(cnt = 0; cnt < (UINT32)BODYPOSFINAL; ++cnt) { pNewSoldier->inv[cnt] = pSoldier->inv[cnt]; } + // Next, direct copy of the gunsling and knife pockets pNewSoldier->inv[GUNSLINGPOCKPOS] = pSoldier->inv[GUNSLINGPOCKPOS]; pNewSoldier->inv[KNIFEPOCKPOS] = pSoldier->inv[KNIFEPOCKPOS]; // Then, try to autoplace everything else - for(cnt = BIGPOCKSTART; cnt < pNewSoldier->inv.size(); cnt++ ) + UINT32 invsize = pNewSoldier->inv.size(); + for(cnt = BIGPOCKSTART; cnt < invsize; ++cnt ) { if(pSoldier->inv[cnt].exists() == true) { diff --git a/Tactical/Tactical Save.cpp b/Tactical/Tactical Save.cpp index 074de457..d4eb8c42 100644 --- a/Tactical/Tactical Save.cpp +++ b/Tactical/Tactical Save.cpp @@ -2803,7 +2803,7 @@ BOOLEAN AddDeadSoldierToUnLoadedSector( INT16 sMapX, INT16 sMapY, UINT8 bMapZ, S { UINT32 uiNumberOfItems; std::vector pWorldItems;//dnl ch75 271013 - UINT i; + UINT8 i; UINT8 bCount=0; UINT16 uiFlagsForWorldItems=0; UINT16 usFlagsForRottingCorpse=0; @@ -2837,7 +2837,8 @@ BOOLEAN AddDeadSoldierToUnLoadedSector( INT16 sMapX, INT16 sMapY, UINT8 bMapZ, S //go through and and find out how many items there are uiNumberOfItems = 0; - for ( i = 0; i < pSoldier->inv.size(); i++ ) + UINT8 invsize = pSoldier->inv.size(); + for ( i = 0; i < invsize; ++i ) { if( pSoldier->inv[ i ].exists() == true ) { @@ -2855,8 +2856,7 @@ BOOLEAN AddDeadSoldierToUnLoadedSector( INT16 sMapX, INT16 sMapY, UINT8 bMapZ, S //if the item can be dropped if( !( pSoldier->inv[ i ].fFlags & OBJECT_UNDROPPABLE ) || pSoldier->bTeam == gbPlayerNum ) { - - uiNumberOfItems++; + ++uiNumberOfItems; } } } @@ -2875,7 +2875,7 @@ BOOLEAN AddDeadSoldierToUnLoadedSector( INT16 sMapX, INT16 sMapY, UINT8 bMapZ, S //loop through all the soldiers items and add them to the world item array bCount = 0; - for ( i = 0; i < pSoldier->inv.size(); i++ ) + for ( i = 0; i < invsize; ++i ) { if( pSoldier->inv[ i ].exists() == true ) { @@ -2897,7 +2897,7 @@ BOOLEAN AddDeadSoldierToUnLoadedSector( INT16 sMapX, INT16 sMapY, UINT8 bMapZ, S pSoldier->inv[i][0]->data.objectStatus = max(pSoldier->inv[i][0]->data.objectStatus,1); // never below 1% } pWorldItems[ bCount ].object = pSoldier->inv[i]; - bCount++; + ++bCount; } } } @@ -2907,7 +2907,7 @@ BOOLEAN AddDeadSoldierToUnLoadedSector( INT16 sMapX, INT16 sMapY, UINT8 bMapZ, S //CHRISL: Now that we've copied the dead soldiers items to pWorldItems, we need to actually remove the items from the dead soldier. Otherwise we have // actually duplicated the items and there's a chance that these duplicated items will again find their way to sector. - for ( i = 0; i < pSoldier->inv.size(); i++ ) + for ( i = 0; i < invsize; ++i ) { if( pSoldier->inv[ i ].exists() == true ) { @@ -3002,7 +3002,8 @@ UINT32 LBENODEChecksum( LBENODE * pNode ) uiChecksum *= (pNode->lbeIndex +1); uiChecksum += (pNode->ubID +1); - for ( uiLoop = 0; uiLoop < pNode->inv.size(); uiLoop++ ) + UINT32 invsize = pNode->inv.size(); + for ( uiLoop = 0; uiLoop < invsize; ++uiLoop ) { uiChecksum += pNode->inv[ uiLoop ].usItem; } diff --git a/Tactical/Turn Based Input.cpp b/Tactical/Turn Based Input.cpp index 7a30be09..b156963f 100644 --- a/Tactical/Turn Based Input.cpp +++ b/Tactical/Turn Based Input.cpp @@ -2823,7 +2823,8 @@ void GetKeyboardInput( UINT32 *puiNewEvent ) { if(MercPtrs[loop]->bActive && MercPtrs[loop]->bInSector) { - for(unsigned int pocket=0; pocket < MercPtrs[loop]->inv.size(); pocket++) + UINT32 invsize = MercPtrs[loop]->inv.size(); + for(UINT32 pocket=0; pocket < invsize; ++pocket) { if(MercPtrs[loop]->inv[pocket].usItem == crateItem) { @@ -7348,7 +7349,7 @@ void HandleTBReloadAll( void ) if (! ( gTacticalStatus.fEnemyInSector ) ) { SOLDIERTYPE *pTeamSoldier; - INT8 bLoop; + UINT8 bLoop; UINT16 bullets; OBJECTTYPE *pGun, *pAmmo, *pAmmoMags; @@ -7357,9 +7358,9 @@ void HandleTBReloadAll( void ) { if ( OK_CONTROLLABLE_MERC( pTeamSoldier ) && pTeamSoldier->bAssignment == CurrentSquad( ) && !AM_A_ROBOT( pTeamSoldier ) ) { - // Search for gun in soldier inventory - for (UINT32 bLoop2 = 0; bLoop2 < pTeamSoldier->inv.size(); bLoop2++) + UINT32 invsize = pTeamSoldier->inv.size(); + for (UINT32 bLoop2 = 0; bLoop2 < invsize; ++bLoop2) { if ( (Item[pTeamSoldier->inv[bLoop2].usItem].usItemClass & IC_GUN) || (Item[pTeamSoldier->inv[bLoop2].usItem].usItemClass == IC_LAUNCHER) ) { @@ -7367,9 +7368,8 @@ void HandleTBReloadAll( void ) //if magazine is not full if ( (*pGun)[0]->data.gun.ubGunShotsLeft < GetMagSize( pGun ) ) { - // Search for ammo in sector - for ( UINT32 uiLoop = 0; uiLoop < guiNumWorldItems; uiLoop++ ) + for ( UINT32 uiLoop = 0; uiLoop < guiNumWorldItems; ++uiLoop ) { if ( (gWorldItems[ uiLoop ].bVisible == TRUE) && (gWorldItems[ uiLoop ].fExists) && (gWorldItems[ uiLoop ].usFlags & WORLD_ITEM_REACHABLE) && !(gWorldItems[ uiLoop ].usFlags & WORLD_ITEM_ARMED_BOMB) )//item exists, is reachable, is visible and is not trapped { @@ -7410,7 +7410,8 @@ void HandleTBReloadAll( void ) if ( OK_CONTROLLABLE_MERC( pTeamSoldier ) && pTeamSoldier->bAssignment == CurrentSquad( ) && !AM_A_ROBOT( pTeamSoldier ) ) { // Search for ammo in soldier inventory - for (UINT32 bLoop2 = 0; bLoop2 < pTeamSoldier->inv.size(); bLoop2++) + UINT32 invsize = pTeamSoldier->inv.size(); + for (UINT32 bLoop2 = 0; bLoop2 < invsize; ++bLoop2) { if ( Item[pTeamSoldier->inv[bLoop2].usItem].usItemClass & IC_AMMO ) { @@ -7421,7 +7422,7 @@ void HandleTBReloadAll( void ) if ( (*pAmmoMags)[stackMag]->data.ubShotsLeft < Magazine[Item[pAmmoMags->usItem].ubClassIndex].ubMagSize ) { // Search for ammo in sector - for ( UINT32 uiLoop = 0; uiLoop < guiNumWorldItems; uiLoop++ ) + for ( UINT32 uiLoop = 0; uiLoop < guiNumWorldItems; ++uiLoop ) { if ( (gWorldItems[ uiLoop ].bVisible == TRUE) && (gWorldItems[ uiLoop ].fExists) && (gWorldItems[ uiLoop ].usFlags & WORLD_ITEM_REACHABLE) && !(gWorldItems[ uiLoop ].usFlags & WORLD_ITEM_ARMED_BOMB) )//item exists, is reachable, is visible and is not trapped { @@ -7442,9 +7443,9 @@ void HandleTBReloadAll( void ) (*pAmmoMags)[stackMag]->data.ubShotsLeft += bullets; (*pAmmo)[0]->data.ubShotsLeft -= bullets; - fCharacterInfoPanelDirty = TRUE; - fInterfacePanelDirty = DIRTYLEVEL2; - } + fCharacterInfoPanelDirty = TRUE; + fInterfacePanelDirty = DIRTYLEVEL2; + } if ((*pAmmo)[0]->data.ubShotsLeft == 0) { @@ -7458,7 +7459,8 @@ void HandleTBReloadAll( void ) //MM: if magazines still are partly empty, look through inventory for boxes and crates if ( (*pAmmoMags)[stackMag]->data.ubShotsLeft < Magazine[Item[pAmmoMags->usItem].ubClassIndex].ubMagSize ) { - for (UINT32 uiLoop = 0; uiLoop < pTeamSoldier->inv.size(); uiLoop++) + UINT32 invsize = pTeamSoldier->inv.size(); + for (UINT32 uiLoop = 0; uiLoop < invsize; ++uiLoop) { if ( (Item[pTeamSoldier->inv[uiLoop].usItem].usItemClass & IC_AMMO) && Magazine[Item[pTeamSoldier->inv[uiLoop].usItem].ubClassIndex].ubMagType >= AMMO_BOX ) { @@ -7494,9 +7496,8 @@ void HandleTBReloadAll( void ) OBJECTTYPE *pGun2 = FindAttachedWeapon(pGun, IC_GUN); if ( (*pGun2)[0]->data.gun.ubGunShotsLeft < GetMagSize( pGun2 ) ) { - // Search for ammo in sector - for ( UINT32 uiLoop = 0; uiLoop < guiNumWorldItems; uiLoop++ ) + for ( UINT32 uiLoop = 0; uiLoop < guiNumWorldItems; ++uiLoop ) { if ( (gWorldItems[ uiLoop ].bVisible == TRUE) && (gWorldItems[ uiLoop ].fExists) && (gWorldItems[ uiLoop ].usFlags & WORLD_ITEM_REACHABLE) && !(gWorldItems[ uiLoop ].usFlags & WORLD_ITEM_ARMED_BOMB) )//item exists, is reachable, is visible and is not trapped { @@ -7535,10 +7536,10 @@ void HandleTBReloadAll( void ) else { SOLDIERTYPE *pTeamSoldier; - INT8 bLoop; + UINT8 bLoop; OBJECTTYPE *pGun, *pAmmo; - for (bLoop=gTacticalStatus.Team[gbPlayerNum].bFirstID, pTeamSoldier=MercPtrs[bLoop]; bLoop <= gTacticalStatus.Team[gbPlayerNum].bLastID; bLoop++, pTeamSoldier++) + for (bLoop=gTacticalStatus.Team[gbPlayerNum].bFirstID, pTeamSoldier=MercPtrs[bLoop]; bLoop <= gTacticalStatus.Team[gbPlayerNum].bLastID; ++bLoop, pTeamSoldier++) { if ( OK_CONTROLLABLE_MERC( pTeamSoldier ) && pTeamSoldier->bAssignment == CurrentSquad( ) && !AM_A_ROBOT( pTeamSoldier ) ) { @@ -7558,7 +7559,8 @@ void HandleTBReloadAll( void ) else { // Search for gun in soldier inventory - for (UINT32 bLoop2 = 0; bLoop2 < pTeamSoldier->inv.size(); bLoop2++) + UINT32 invsize = pTeamSoldier->inv.size(); + for (UINT32 bLoop2 = 0; bLoop2 < invsize; ++bLoop2) { if ( (Item[pTeamSoldier->inv[bLoop2].usItem].usItemClass & IC_GUN) || (Item[pTeamSoldier->inv[bLoop2].usItem].usItemClass == IC_LAUNCHER) ) { @@ -7566,9 +7568,8 @@ void HandleTBReloadAll( void ) //if magazine is not full if ( (*pGun)[0]->data.gun.ubGunShotsLeft < GetMagSize( pGun ) ) { - // Search for ammo in soldier inventory - for ( UINT32 uiLoop = 0; uiLoop < pTeamSoldier->inv.size(); uiLoop++ ) + for ( UINT32 uiLoop = 0; uiLoop < invsize; ++uiLoop ) { if ( (Item[pTeamSoldier->inv[uiLoop].usItem].usItemClass & IC_AMMO ) ) // the item is ammo { @@ -7590,10 +7591,7 @@ void HandleTBReloadAll( void ) } } } - - } - } } } diff --git a/Tactical/XML_MercStartingGear.cpp b/Tactical/XML_MercStartingGear.cpp index b8af320e..54f0978b 100644 --- a/Tactical/XML_MercStartingGear.cpp +++ b/Tactical/XML_MercStartingGear.cpp @@ -211,14 +211,16 @@ MercStartingGearEndElementHandle(void *userData, const XML_Char *name) pData->curMercStartingGear.PriceModifier = 0; pData->curMercStartingGear.AbsolutePrice = -1; pData->curMercStartingGear.mGearKitName[0] = '\0'; - for(unsigned int i = 0; i < pData->curMercStartingGear.inv.size(); i++) + UINT32 invsize = pData->curMercStartingGear.inv.size(); + for(UINT32 i = 0; i < invsize; ++i) { pData->curMercStartingGear.inv[i] = 0; pData->curMercStartingGear.iStatus[i] = 0; pData->curMercStartingGear.iDrop[i] = 0; pData->curMercStartingGear.iNumber[i] = 0; } - for(unsigned int i = 0; i < pData->curMercStartingGear.lbe.size(); i++) + UINT32 lbesize = pData->curMercStartingGear.lbe.size(); + for(UINT32 i = 0; i < lbesize; ++i) { pData->curMercStartingGear.lbe[i] = 0; pData->curMercStartingGear.lStatus[i] = 0; diff --git a/Tactical/opplist.cpp b/Tactical/opplist.cpp index c1d47b67..4716c47c 100644 --- a/Tactical/opplist.cpp +++ b/Tactical/opplist.cpp @@ -813,17 +813,17 @@ void CheckHostileOrSayQuoteList( void ) void HandleSight(SOLDIERTYPE *pSoldier, UINT8 ubSightFlags) { - UINT32 uiLoop; - SOLDIERTYPE *pThem; - INT8 bTempNewSituation; + UINT32 uiLoop; + SOLDIERTYPE *pThem; + INT8 bTempNewSituation; - if (!pSoldier->bActive || !pSoldier->bInSector || pSoldier->flags.uiStatusFlags & SOLDIER_DEAD ) - { - // I DON'T THINK SO! - return; - } + if (!pSoldier->bActive || !pSoldier->bInSector || pSoldier->flags.uiStatusFlags & SOLDIER_DEAD ) + { + // I DON'T THINK SO! + return; + } - gubSightFlags = ubSightFlags; + gubSightFlags = ubSightFlags; if ( gubBestToMakeSightingSize != BEST_SIGHTING_ARRAY_SIZE_ALL_TEAMS_LOOK_FOR_ALL ) { @@ -841,7 +841,7 @@ void HandleSight(SOLDIERTYPE *pSoldier, UINT8 ubSightFlags) InitSightArrays(); } - for ( uiLoop = 0; uiLoop < NUM_WATCHED_LOCS; uiLoop++ ) + for ( uiLoop = 0; uiLoop < NUM_WATCHED_LOCS; ++uiLoop ) { gfWatchedLocHasBeenIncremented[ pSoldier->ubID ][ uiLoop ] = FALSE; } @@ -855,7 +855,6 @@ void HandleSight(SOLDIERTYPE *pSoldier, UINT8 ubSightFlags) // if we've been told to make this soldier look (& others look back at him) if (ubSightFlags & SIGHT_LOOK) { - // if this soldier's under our control and well enough to look if (pSoldier->stats.bLife >= OKLIFE ) { @@ -915,13 +914,13 @@ void HandleSight(SOLDIERTYPE *pSoldier, UINT8 ubSightFlags) RadioSightings(pSoldier,EVERYBODY, MILITIA_TEAM); #endif*/ //ddd{ -if(gGameExternalOptions.bWeSeeWhatMilitiaSeesAndViceVersa) - RadioSightings(pSoldier,EVERYBODY, MILITIA_TEAM); + if(gGameExternalOptions.bWeSeeWhatMilitiaSeesAndViceVersa) + RadioSightings(pSoldier,EVERYBODY, MILITIA_TEAM); #ifdef ENABLE_MP_FRIENDLY_PLAYERS_SHARE_SAME_FOV - //haydent - if(is_networked && pSoldier->bSide == 0 && pSoldier->bTeam != OUR_TEAM) - RadioSightings(pSoldier,EVERYBODY, OUR_TEAM); + //haydent + if(is_networked && pSoldier->bSide == 0 && pSoldier->bTeam != OUR_TEAM) + RadioSightings(pSoldier,EVERYBODY, OUR_TEAM); #endif //ddd} @@ -944,7 +943,6 @@ if(gGameExternalOptions.bWeSeeWhatMilitiaSeesAndViceVersa) pSoldier->bNewOppCnt = 0; pSoldier->pathing.bNeedToLook = FALSE; - // Temporary for opplist synching - disable random order radioing #ifndef RECORDOPPLIST // if this soldier's NOT on our team (MAY be under our control, though!) @@ -952,11 +950,10 @@ if(gGameExternalOptions.bWeSeeWhatMilitiaSeesAndViceVersa) OurTeamRadiosRandomlyAbout(pSoldier->ubID); // radio about him only #endif - // all non-humans under our control would now radio, if they were allowed // to radio automatically (but they're not). So just nuke new opp cnt // NEW: under LOCALOPPLIST, humans on other teams now also radio in here - for (uiLoop = 0; uiLoop < guiNumMercSlots; uiLoop++) + for (uiLoop = 0; uiLoop < guiNumMercSlots; ++uiLoop) { pThem = MercSlots[ uiLoop ]; @@ -983,13 +980,12 @@ if(gGameExternalOptions.bWeSeeWhatMilitiaSeesAndViceVersa) else if ( gGameOptions.ubDifficultyLevel >= DIF_LEVEL_MEDIUM ) { // don't allow admins to radio - if ( pThem->bTeam == ENEMY_TEAM && gTacticalStatus.Team[ ENEMY_TEAM ].bAwareOfOpposition && pThem->ubSoldierClass != SOLDIER_CLASS_ADMINISTRATOR ) + if ( pThem->bTeam == ENEMY_TEAM && gTacticalStatus.Team[ ENEMY_TEAM ].bAwareOfOpposition && pThem->ubSoldierClass != SOLDIER_CLASS_ADMINISTRATOR ) { RadioSightings(pThem,EVERYBODY, pThem->bTeam ); } } - pThem->bNewOppCnt = 0; pThem->pathing.bNeedToLook = FALSE; } @@ -1079,11 +1075,11 @@ INT16 TeamNoLongerSeesMan( UINT8 ubTeam, SOLDIERTYPE *pOpponent, UINT8 ubExclude bLoop = gTacticalStatus.Team[ubTeam].bFirstID; - // look for all mercs on the same team, check opplists for this soldier - for (pMate = MercPtrs[bLoop]; bLoop <= gTacticalStatus.Team[ubTeam].bLastID; bLoop++,pMate++) + // look for all mercs on the same team, check opplists for this soldier + for (pMate = MercPtrs[bLoop]; bLoop <= gTacticalStatus.Team[ubTeam].bLastID; ++bLoop,pMate++) { - // if this "teammate" is me, myself, or I (whom we want to exclude) - if (bLoop == ubExcludeID) + // if this "teammate" is me, myself, or I (whom we want to exclude) + if (bLoop == ubExcludeID) continue; // skip to next teammate, I KNOW I don't see him... // if this merc is not on the same team @@ -1180,29 +1176,30 @@ INT16 MaxNormalDistanceVisible( void ) INT16 SOLDIERTYPE::GetMaxDistanceVisible(INT32 sGridNo, INT8 bLevel, int calcAsType) { - if (sGridNo == -1) { + if (sGridNo == NOWHERE) + { return MaxNormalDistanceVisible(); } - if (bLevel == -1) { + + if (bLevel == -1) + { bLevel = this->pathing.bLevel; } - if (calcAsType == CALC_FROM_ALL_DIRS) { + if (calcAsType == CALC_FROM_ALL_DIRS) + { return DistanceVisible( this, DIRECTION_IRRELEVANT, DIRECTION_IRRELEVANT, sGridNo, bLevel ); } - else { - return DistanceVisible( this, (SoldierHasLimitedVision(this) ? this->pathing.bDesiredDirection : DIRECTION_IRRELEVANT), DIRECTION_IRRELEVANT, sGridNo, bLevel ); - } + + return DistanceVisible( this, (SoldierHasLimitedVision(this) ? this->pathing.bDesiredDirection : DIRECTION_IRRELEVANT), DIRECTION_IRRELEVANT, sGridNo, bLevel ); } INT16 DistanceVisible( SOLDIERTYPE *pSoldier, INT8 bFacingDir, INT8 bSubjectDir, INT32 sSubjectGridNo, INT8 bLevel ) { INT16 sDistVisible; INT8 bLightLevel; - SOLDIERTYPE * pSubject; BOOLEAN sideViewLimit = FALSE; - - pSubject = SimpleFindSoldier( sSubjectGridNo, bLevel ); + SOLDIERTYPE* pSubject = SimpleFindSoldier( sSubjectGridNo, bLevel ); if (pSoldier->flags.uiStatusFlags & SOLDIER_MONSTER) { @@ -1210,6 +1207,7 @@ INT16 DistanceVisible( SOLDIERTYPE *pSoldier, INT8 bFacingDir, INT8 bSubjectDir, { return( FALSE ); } + return( DistanceSmellable( pSoldier, pSubject ) ); } @@ -1233,7 +1231,6 @@ INT16 DistanceVisible( SOLDIERTYPE *pSoldier, INT8 bFacingDir, INT8 bSubjectDir, } else { - if (pSoldier->sGridNo == sSubjectGridNo) { // looking up or down or two people accidentally in same tile... don't want it to be 0! @@ -1241,19 +1238,24 @@ INT16 DistanceVisible( SOLDIERTYPE *pSoldier, INT8 bFacingDir, INT8 bSubjectDir, } else { + // Flugente: no need to calculate this multiple times + BOOLEAN fLimitedVision = SoldierHasLimitedVision(pSoldier); + // Lesh: added this - if( SoldierHasLimitedVision(pSoldier) ) + if( fLimitedVision ) { bSubjectDir = (INT8) GetDirectionToGridNoFromGridNo( pSoldier->sGridNo, sSubjectGridNo ); } - if (bFacingDir == DIRECTION_IRRELEVANT) { + + if (bFacingDir == DIRECTION_IRRELEVANT) + { bFacingDir = pSoldier->ubDirection; } sDistVisible = gbLookDistance[bFacingDir][bSubjectDir]; // Lesh: and this - if ( (sDistVisible == 0) && (SoldierHasLimitedVision(pSoldier)) ) + if ( (sDistVisible == 0) && fLimitedVision ) return(0); if ( sDistVisible != STRAIGHT ) @@ -1301,7 +1303,7 @@ INT16 DistanceVisible( SOLDIERTYPE *pSoldier, INT8 bFacingDir, INT8 bSubjectDir, // valid map references then use the ambient light level instead. if ( TileIsOutOfBounds( sSubjectGridNo ) ) { - DebugMsg(TOPIC_JA2, DBG_LEVEL_3, String("113/UC Warning! Tried to detect the light level when character %ls[%d] looks at a location outside of the valid map (gridno %d). Assigning default %d", + DebugMsg(TOPIC_JA2, DBG_LEVEL_3, String("113/UC Warning! Tried to detect the light level when character %ls[%d] looks at a location outside of the valid map (gridno %d). Assigning default %d", pSoldier->name, pSoldier->ubID, pSoldier->sGridNo, ubAmbientLightLevel)); bLightLevel = ubAmbientLightLevel; @@ -1329,21 +1331,21 @@ INT16 DistanceVisible( SOLDIERTYPE *pSoldier, INT8 bFacingDir, INT8 bSubjectDir, // HEADROCK HAM 3.2: Further reduce sightrange for cowering characters. // SANDRO - this calls many sub-functions over and over, we should at least skip this for civilians and such - if ((gGameExternalOptions.ubCoweringReducesSightRange == 1 || gGameExternalOptions.ubCoweringReducesSightRange == 2) && - IS_MERC_BODY_TYPE(pSoldier) && (pSoldier->bTeam == ENEMY_TEAM || pSoldier->bTeam == MILITIA_TEAM || pSoldier->bTeam == gbPlayerNum) ) + // Flugente: we can check for more conditions before calculating suppression tolerance + if ( (gGameExternalOptions.ubCoweringReducesSightRange == 1 || gGameExternalOptions.ubCoweringReducesSightRange == 2) && + IS_MERC_BODY_TYPE(pSoldier) && (pSoldier->bTeam == ENEMY_TEAM || pSoldier->bTeam == MILITIA_TEAM || pSoldier->bTeam == gbPlayerNum) && + gGameExternalOptions.ubMaxSuppressionShock > 0 && sDistVisible > 0 ) { INT8 bTolerance = CalcSuppressionTolerance( pSoldier ); // Make sure character is cowering. - if ( pSoldier->aiData.bShock >= bTolerance && gGameExternalOptions.ubMaxSuppressionShock > 0 && - sDistVisible > 0 ) + if ( pSoldier->aiData.bShock >= bTolerance ) { sDistVisible = __max(1,(sDistVisible * (gGameExternalOptions.ubMaxSuppressionShock - pSoldier->aiData.bShock)) / gGameExternalOptions.ubMaxSuppressionShock); } } } - // give one step better vision for people with nightops // old/new traits check - SANDRO if (gGameOptions.fNewTraitSystem) @@ -1361,7 +1363,7 @@ INT16 DistanceVisible( SOLDIERTYPE *pSoldier, INT8 bFacingDir, INT8 bSubjectDir, { sDistVisible += NightBonusScale( UVGOGGLES_BONUS, bLightLevel); } - else if ( AM_A_ROBOT( pSoldier ) ) + else if ( AM_A_ROBOT( pSoldier ) ) { sDistVisible += NightBonusScale( NIGHTSIGHTGOGGLES_BONUS, bLightLevel); } @@ -1373,8 +1375,9 @@ INT16 DistanceVisible( SOLDIERTYPE *pSoldier, INT8 bFacingDir, INT8 bSubjectDir, if ( TANK(pSoldier) && sDistVisible > 0 && pSubject) { sDistVisible = __max( sDistVisible + 5, pSubject->GetMaxDistanceVisible(pSoldier->sGridNo, pSoldier->pathing.bLevel) ); - } - else { + } + else + { sDistVisible = __max( sDistVisible + 5, pSoldier->GetMaxDistanceVisible() ); } #endif @@ -1852,24 +1855,25 @@ void HandleManNoLongerSeen( SOLDIERTYPE * pSoldier, SOLDIERTYPE * pOpponent, INT #ifdef ENABLE_MP_FRIENDLY_PLAYERS_SHARE_SAME_FOV -//haydent -if(is_networked && pSoldier->bSide == 0) -{ - //stay visible -} -else + //haydent + if(is_networked && pSoldier->bSide == 0) + { + //stay visible + } + else #endif -{ - if(gGameExternalOptions.bWeSeeWhatMilitiaSeesAndViceVersa) - { if ( (pSoldier->bTeam == gbPlayerNum || pSoldier->bTeam == MILITIA_TEAM) && !(pOpponent->bTeam == gbPlayerNum || pOpponent->bTeam == MILITIA_TEAM ) ) - pOpponent->bVisible = 0; - } - else - { - if ( pSoldier->bTeam == gbPlayerNum && pOpponent->bTeam != gbPlayerNum ) - pOpponent->bVisible = 0; - } -}//haydent + { + if(gGameExternalOptions.bWeSeeWhatMilitiaSeesAndViceVersa) + { + if ( (pSoldier->bTeam == gbPlayerNum || pSoldier->bTeam == MILITIA_TEAM) && !(pOpponent->bTeam == gbPlayerNum || pOpponent->bTeam == MILITIA_TEAM ) ) + pOpponent->bVisible = 0; + } + else + { + if ( pSoldier->bTeam == gbPlayerNum && pOpponent->bTeam != gbPlayerNum ) + pOpponent->bVisible = 0; + } + }//haydent } } #ifdef TESTOPPLIST @@ -1910,12 +1914,11 @@ INT16 ManLooksForMan(SOLDIERTYPE *pSoldier, SOLDIERTYPE *pOpponent, UINT8 ubCall #endif return(success); } - */ - // if we're somehow looking while inactive, at base, dead or dying - if (!pSoldier->bActive || !pSoldier->bInSector || (pSoldier->stats.bLife < OKLIFE)) - { + // if we're somehow looking while inactive, at base, dead or dying + if (!pSoldier->bActive || !pSoldier->bInSector || (pSoldier->stats.bLife < OKLIFE)) + { /* #ifdef BETAVERSION sprintf(tempstr,"ManLooksForMan: ERROR - %s is looking while inactive/at base/dead/dying. Caller %s", @@ -1934,14 +1937,12 @@ INT16 ManLooksForMan(SOLDIERTYPE *pSoldier, SOLDIERTYPE *pOpponent, UINT8 ubCall String("ERROR: ManLooksForMan - WE are inactive/dead etc ID %d(%S)to ID %d",pSoldier->ubID,pSoldier->name,pOpponent->ubID) ); #endif - return(FALSE); + return(FALSE); } - - - // if we're somehow looking for a guy who is inactive, at base, or already dead - if (!pOpponent->bActive || !pOpponent->bInSector || pOpponent->stats.bLife <= 0 || TileIsOutOfBounds(pOpponent->sGridNo)) - { + // if we're somehow looking for a guy who is inactive, at base, or already dead + if (!pOpponent->bActive || !pOpponent->bInSector || pOpponent->stats.bLife <= 0 || TileIsOutOfBounds(pOpponent->sGridNo)) + { /* #ifdef BETAVERSION sprintf(tempstr,"ManLooksForMan: ERROR - %s looks for %s, who is inactive/at base/dead. Caller %s", @@ -1956,16 +1957,16 @@ INT16 ManLooksForMan(SOLDIERTYPE *pSoldier, SOLDIERTYPE *pOpponent, UINT8 ubCall */ #ifdef TESTOPPLIST - DebugMsg( TOPIC_JA2OPPLIST, DBG_LEVEL_3, + DebugMsg( TOPIC_JA2OPPLIST, DBG_LEVEL_3, String("ERROR: ManLooksForMan - TARGET is inactive etc ID %d(%S)to ID %d",pSoldier->ubID,pSoldier->name,pOpponent->ubID) ); #endif - return(FALSE); - } + return(FALSE); + } - // if he's looking for a guy who is on the same team - if (pSoldier->bTeam == pOpponent->bTeam) + // if he's looking for a guy who is on the same team + if (pSoldier->bTeam == pOpponent->bTeam) { /* #ifdef BETAVERSION @@ -1984,10 +1985,11 @@ INT16 ManLooksForMan(SOLDIERTYPE *pSoldier, SOLDIERTYPE *pOpponent, UINT8 ubCall String("ERROR: ManLooksForMan - SAME TEAM ID %d(%S)to ID %d",pSoldier->ubID,pSoldier->name,pOpponent->ubID) ); #endif - return(FALSE); + return(FALSE); } - if (pSoldier->stats.bLife < OKLIFE || pSoldier->flags.fMercAsleep == TRUE ) + // Flugente: we already checked for OKLIFE above.. + if ( pSoldier->flags.fMercAsleep ) { return( FALSE ); } @@ -2039,54 +2041,53 @@ INT16 ManLooksForMan(SOLDIERTYPE *pSoldier, SOLDIERTYPE *pOpponent, UINT8 ubCall } */ - pPersOL = &(pSoldier->aiData.bOppList[pOpponent->ubID]); - pbPublOL = &(gbPublicOpplist[pSoldier->bTeam][pOpponent->ubID]); + pPersOL = &(pSoldier->aiData.bOppList[pOpponent->ubID]); + pbPublOL = &(gbPublicOpplist[pSoldier->bTeam][pOpponent->ubID]); - - // if soldier is known about (SEEN or HEARD within last few turns) - if (*pPersOL || *pbPublOL) + // if soldier is known about (SEEN or HEARD within last few turns) + if (*pPersOL || *pbPublOL) { - bAware = TRUE; + bAware = TRUE; - // then we look for him full viewing distance in EVERY direction + // then we look for him full viewing distance in EVERY direction - //ADB the comment above says EVERY direction but the code used to be: - //sDistVisible = DistanceVisible(pSoldier, (SoldierHasLimitedVision(pSoldier) ? pSoldier->bDesiredDirection : DIRECTION_IRRELEVANT), 0, pOpponent->sGridNo, pOpponent->bLevel, pOpponent ); - //if the code below says CALC_FROM_ALL_DIRS, then the opponent will NOT be greyed out if a merc sees him and a second merc turns away from him - //calcing from the wanted dir will make the opponent be greyed out, which I think is the intended effect - sDistVisible = pSoldier->GetMaxDistanceVisible( pOpponent->sGridNo, pOpponent->pathing.bLevel, CALC_FROM_WANTED_DIR ); - //if (pSoldier->ubID == 0) + //ADB the comment above says EVERY direction but the code used to be: + //sDistVisible = DistanceVisible(pSoldier, (SoldierHasLimitedVision(pSoldier) ? pSoldier->bDesiredDirection : DIRECTION_IRRELEVANT), 0, pOpponent->sGridNo, pOpponent->bLevel, pOpponent ); + //if the code below says CALC_FROM_ALL_DIRS, then the opponent will NOT be greyed out if a merc sees him and a second merc turns away from him + //calcing from the wanted dir will make the opponent be greyed out, which I think is the intended effect + sDistVisible = pSoldier->GetMaxDistanceVisible( pOpponent->sGridNo, pOpponent->pathing.bLevel, CALC_FROM_WANTED_DIR ); + //if (pSoldier->ubID == 0) //sprintf(gDebugStr,"ALREADY KNOW: ME %d him %d val %d",pSoldier->ubID,pOpponent->ubID,pSoldier->bOppList[pOpponent->ubID]); - } - else // soldier is not currently known about - { - // distance we "see" then depends on the direction he is located from us - bDir = atan8(pSoldier->sX,pSoldier->sY,pOpponent->sX,pOpponent->sY); - // BIG NOTE: must use desdir instead of direction, since in a projected - // situation, the direction may still be changing if it's one of the first - // few animation steps when this guy's turn to do his stepped look comes up - sDistVisible = DistanceVisible(pSoldier,pSoldier->pathing.bDesiredDirection,bDir, pOpponent->sGridNo, pOpponent->pathing.bLevel ); - //if (pSoldier->ubID == 0) - //sprintf(gDebugStr,"dist visible %d: my dir %d to him %d",sDistVisible,pSoldier->bDesiredDirection,bDir); - } + } + else // soldier is not currently known about + { + // distance we "see" then depends on the direction he is located from us + bDir = atan8(pSoldier->sX,pSoldier->sY,pOpponent->sX,pOpponent->sY); + // BIG NOTE: must use desdir instead of direction, since in a projected + // situation, the direction may still be changing if it's one of the first + // few animation steps when this guy's turn to do his stepped look comes up + sDistVisible = DistanceVisible(pSoldier,pSoldier->pathing.bDesiredDirection,bDir, pOpponent->sGridNo, pOpponent->pathing.bLevel ); + //if (pSoldier->ubID == 0) + //sprintf(gDebugStr,"dist visible %d: my dir %d to him %d",sDistVisible,pSoldier->bDesiredDirection,bDir); + } - // calculate how many spaces away soldier is (using Pythagoras' theorem) - sDistAway = PythSpacesAway(pSoldier->sGridNo,pOpponent->sGridNo); + // calculate how many spaces away soldier is (using Pythagoras' theorem) + sDistAway = PythSpacesAway(pSoldier->sGridNo,pOpponent->sGridNo); #ifdef TESTOPPLIST DebugMsg( TOPIC_JA2OPPLIST, DBG_LEVEL_3, String( "MANLOOKSFORMAN: ID %d(%S) to ID %d: sDistAway %d sDistVisible %d",pSoldier->ubID,pSoldier->name,pOpponent->ubID,sDistAway,sDistVisible) ); #endif - // if we see close enough to see the soldier - if (sDistAway <= sDistVisible) - { - // and we can trace a line of sight to his x,y coordinates - // must use the REAL opplist value here since we may or may not know of him - if (SoldierToSoldierLineOfSightTest(pSoldier,pOpponent,bAware,sDistVisible)) - { + // if we see close enough to see the soldier + if (sDistAway <= sDistVisible) + { + // and we can trace a line of sight to his x,y coordinates + // must use the REAL opplist value here since we may or may not know of him + if (SoldierToSoldierLineOfSightTest(pSoldier,pOpponent,bAware,sDistVisible)) + { ManSeesMan(pSoldier,pOpponent,pOpponent->sGridNo,pOpponent->pathing.bLevel,MANLOOKSFORMAN,ubCaller); bSuccess = TRUE; - } + } #ifdef TESTOPPLIST else DebugMsg( TOPIC_JA2OPPLIST, DBG_LEVEL_3, String("FAILED LINEOFSIGHT: ID %d (%S)to ID %d Personally %d, public %d",pSoldier->ubID,pSoldier->name,pOpponent->ubID,*pPersOL,*pbPublOL) ); @@ -2100,8 +2101,7 @@ INT16 ManLooksForMan(SOLDIERTYPE *pSoldier, SOLDIERTYPE *pOpponent, UINT8 ubCall // (do this even if we don't have LOS, to close doors that *BREAK* LOS) RevealDoorsAlongLOS(); */ - - } + } @@ -2116,36 +2116,28 @@ INT16 ManLooksForMan(SOLDIERTYPE *pSoldier, SOLDIERTYPE *pOpponent, UINT8 ubCall #endif */ - // if soldier seen personally LAST time could not be seen THIS time - if (!bSuccess && (*pPersOL == SEEN_CURRENTLY)) - { - HandleManNoLongerSeen( pSoldier, pOpponent, pPersOL, pbPublOL ); - } - else - { - if (!bSuccess) + // if soldier seen personally LAST time could not be seen THIS time + if (!bSuccess && (*pPersOL == SEEN_CURRENTLY)) { -#ifdef TESTOPPLIST - DebugMsg( TOPIC_JA2OPPLIST, DBG_LEVEL_3, String("NO LONGER VISIBLE ID %d (%S)to ID %d Personally %d, public %d success: %d",pSoldier->ubID,pSoldier->name,pOpponent->ubID,*pPersOL,*pbPublOL,bSuccess) ); -#endif - - - // we didn't see the opponent, but since we didn't last time, we should be - //if (*pbPublOL) - //pOpponent->bVisible = TRUE; + HandleManNoLongerSeen( pSoldier, pOpponent, pPersOL, pbPublOL ); } #ifdef TESTOPPLIST else - DebugMsg( TOPIC_JA2OPPLIST, DBG_LEVEL_3, String("COOL. STILL VISIBLE ID %d (%S)to ID %d Personally %d, public %d success: %d",pSoldier->ubID,pSoldier->name,pOpponent->ubID,*pPersOL,*pbPublOL,bSuccess) ); + { + if (!bSuccess) + { + DebugMsg( TOPIC_JA2OPPLIST, DBG_LEVEL_3, String("NO LONGER VISIBLE ID %d (%S)to ID %d Personally %d, public %d success: %d",pSoldier->ubID,pSoldier->name,pOpponent->ubID,*pPersOL,*pbPublOL,bSuccess) ); + + // we didn't see the opponent, but since we didn't last time, we should be + //if (*pbPublOL) + //pOpponent->bVisible = TRUE; + } + else + DebugMsg( TOPIC_JA2OPPLIST, DBG_LEVEL_3, String("COOL. STILL VISIBLE ID %d (%S)to ID %d Personally %d, public %d success: %d",pSoldier->ubID,pSoldier->name,pOpponent->ubID,*pPersOL,*pbPublOL,bSuccess) ); + } #endif - - - -} - - - - return(bSuccess); + + return(bSuccess); } @@ -3117,13 +3109,13 @@ void UpdatePublic(UINT8 ubTeam, UINT8 ubID, INT8 bNewOpplist, INT32 sGridNo, INT // if team has been told about a guy the team was completely unaware of if (ubTeamMustLookAgain) { - // then everyone on team who's not aware of guynum must look for him - cnt = gTacticalStatus.Team[ubTeam].bFirstID; + // then everyone on team who's not aware of guynum must look for him + cnt = gTacticalStatus.Team[ubTeam].bFirstID; - for (pSoldier = MercPtrs[cnt]; cnt <= gTacticalStatus.Team[ubTeam].bLastID; cnt++,pSoldier++) - { - // if this soldier is active, in this sector, and well enough to look - if (pSoldier->bActive && pSoldier->bInSector && (pSoldier->stats.bLife >= OKLIFE) && !( pSoldier->flags.uiStatusFlags & SOLDIER_GASSED ) ) + for (pSoldier = MercPtrs[cnt]; cnt <= gTacticalStatus.Team[ubTeam].bLastID; ++cnt, pSoldier++) + { + // if this soldier is active, in this sector, and well enough to look + if (pSoldier->bActive && pSoldier->bInSector && (pSoldier->stats.bLife >= OKLIFE) && !( pSoldier->flags.uiStatusFlags & SOLDIER_GASSED ) ) { // if soldier isn't aware of guynum, give him another chance to see if (pSoldier->aiData.bOppList[ubID] == NOT_HEARD_OR_SEEN) @@ -3152,24 +3144,19 @@ void UpdatePersonal(SOLDIERTYPE *pSoldier, UINT8 ubID, INT8 bNewOpplist, INT32 s { /* #ifdef RECORDOPPLIST - fprintf(OpplistFile,"UpdatePersonal - for %d about %d to %d (was %d) at g%d\n", - ptr->guynum,guynum,newOpplist,ptr->opplist[guynum],gridno); + fprintf(OpplistFile,"UpdatePersonal - for %d about %d to %d (was %d) at g%d\n", ptr->guynum,guynum,newOpplist,ptr->opplist[guynum],gridno); #endif - */ - - - - // if new opplist is more up-to-date, or we are just wiping it for some reason - if ((gubKnowledgeValue[pSoldier->aiData.bOppList[ubID] - OLDEST_HEARD_VALUE][bNewOpplist - OLDEST_HEARD_VALUE] > 0) || - (bNewOpplist == NOT_HEARD_OR_SEEN)) + + // if new opplist is more up-to-date, or we are just wiping it for some reason + if ((gubKnowledgeValue[pSoldier->aiData.bOppList[ubID] - OLDEST_HEARD_VALUE][bNewOpplist - OLDEST_HEARD_VALUE] > 0) || (bNewOpplist == NOT_HEARD_OR_SEEN)) { - pSoldier->aiData.bOppList[ubID] = bNewOpplist; + pSoldier->aiData.bOppList[ubID] = bNewOpplist; } - // always update the gridno, no matter what - gsLastKnownOppLoc[pSoldier->ubID][ubID] = sGridNo; - gbLastKnownOppLevel[pSoldier->ubID][ubID] = bLevel; + // always update the gridno, no matter what + gsLastKnownOppLoc[pSoldier->ubID][ubID] = sGridNo; + gbLastKnownOppLevel[pSoldier->ubID][ubID] = bLevel; } @@ -3692,12 +3679,12 @@ DebugMsg( TOPIC_JA2OPPLIST, DBG_LEVEL_3, // hang a pointer to the start of this guy's opponents in the public opplist pbPublOL = &(gbPublicOpplist[ubTeamToRadioTo][start]); - pOpponent = MercPtrs[start]; + pOpponent = MercPtrs[start]; - // loop through every one of this guy's opponents - for (iLoop = start; iLoop < end; iLoop++,pOpponent++,pPersOL++,pbPublOL++) + // loop through every one of this guy's opponents + for (iLoop = start; iLoop < end; ++iLoop,pOpponent++,pPersOL++,pbPublOL++) { - fContactSeen = FALSE; + fContactSeen = FALSE; #ifdef TESTOPPLIST DebugMsg( TOPIC_JA2OPPLIST, DBG_LEVEL_3, @@ -3823,11 +3810,11 @@ DebugMsg( TOPIC_JA2OPPLIST, DBG_LEVEL_3, // if he has publicly not been seen now, or anytime during this turn if ((*pbPublOL != SEEN_CURRENTLY) && (*pbPublOL != SEEN_THIS_TURN)) - { - // chalk up another "revealed" enemy - revealedEnemies++; - fContactSeen = TRUE; - } + { + // chalk up another "revealed" enemy + ++revealedEnemies; + fContactSeen = TRUE; + } else { if ( MercPtrs[0]->stats.bLife < 10 ) @@ -5302,9 +5289,9 @@ void DebugSoldierPage4( ) UINT8 MovementNoise( SOLDIERTYPE *pSoldier ) { - INT32 iStealthSkill, iRoll; - UINT8 ubMaxVolume, ubVolume, ubBandaged, ubEffLife; - INT8 bInWater = FALSE; + INT32 iStealthSkill, iRoll; + UINT8 ubMaxVolume, ubVolume, ubBandaged, ubEffLife; + INT8 bInWater = FALSE; if ( pSoldier->bTeam == ENEMY_TEAM ) { @@ -5330,8 +5317,9 @@ UINT8 MovementNoise( SOLDIERTYPE *pSoldier ) iStealthSkill += 25 * NUM_SKILL_TRAITS( pSoldier, STEALTHY_OT ); } - if ( GetWornStealth(pSoldier) > 0 ) - iStealthSkill += GetWornStealth(pSoldier) / 2; + INT16 wornstealth = GetWornStealth(pSoldier); + if ( wornstealth > 0 ) + iStealthSkill += wornstealth / 2; //NumMessage("Base Stealth = ",stealthSkill); @@ -5475,16 +5463,15 @@ UINT8 DoorOpeningNoise( SOLDIERTYPE *pSoldier ) { ubDoorNoise = DOOR_NOISE_VOLUME; } + if ( MovementNoise( pSoldier ) ) { // failed any stealth checks return( ubDoorNoise ); } - else - { - // succeeded in being stealthy! - return( 0 ); - } + + // succeeded in being stealthy! + return( 0 ); } void MakeNoise(UINT8 ubNoiseMaker, INT32 sGridNo, INT8 bLevel, UINT8 ubTerrType, UINT8 ubVolume, UINT8 ubNoiseType, STR16 zNoiseMessage ) @@ -5511,7 +5498,6 @@ void MakeNoise(UINT8 ubNoiseMaker, INT32 sGridNo, INT8 bLevel, UINT8 ubTerrType, // now call directly OurNoise( SNoise.ubNoiseMaker, SNoise.sGridNo, SNoise.bLevel, SNoise.ubTerrType, SNoise.ubVolume, SNoise.ubNoiseType, SNoise.zNoiseMessage ); - } /* @@ -5587,14 +5573,10 @@ void MakeNoise(UINT8 ubNoiseMaker, INT32 sGridNo, INT8 bLevel, UINT8 ubTerrType, void OurNoise( UINT8 ubNoiseMaker, INT32 sGridNo, INT8 bLevel, UINT8 ubTerrType, UINT8 ubVolume, UINT8 ubNoiseType, STR16 zNoiseMessage ) { - SOLDIERTYPE *pSoldier; - - #ifdef BYPASSNOISE return; #endif - #ifdef BETAVERSION tempstr = String("OurNoise: ubNoiseType = %s, ubNoiseMaker = %d, ubNoiseMode = %d, sGridNo = %d, ubVolume = %d", NoiseTypeStr[ubNoiseType],ubNoiseMaker,ubNoiseMode,sGridNo,ubVolume); @@ -5611,14 +5593,11 @@ void OurNoise( UINT8 ubNoiseMaker, INT32 sGridNo, INT8 bLevel, UINT8 ubTerrType, if ((gTacticalStatus.uiFlags & TURNBASED) && (gTacticalStatus.uiFlags & INCOMBAT) && (ubNoiseMaker < TOTAL_SOLDIERS) && !gfDelayResolvingBestSightingDueToDoor ) { - pSoldier = MercPtrs[ubNoiseMaker]; - // interrupts are possible, resolve them now (we're in control here) // (you can't interrupt NOBODY, even if you hear the noise) - ResolveInterruptsVs(pSoldier,NOISEINTERRUPT); + ResolveInterruptsVs(MercPtrs[ubNoiseMaker],NOISEINTERRUPT); } - } @@ -6389,11 +6368,12 @@ void HearNoise(SOLDIERTYPE *pSoldier, UINT8 ubNoiseMaker, INT32 sGridNo, INT8 bL bSourceSeen = TRUE; // if this sounds like a door opening/closing (could also be a crate) - if (ubNoiseType == NOISE_CREAKING) + // Flugente: unused check + /*if (ubNoiseType == NOISE_CREAKING) { // then look around and update ALL doors that have secretly changed //LookForDoors(pSoldier,AWARE); - } + }*/ } } diff --git a/TileEngine/Explosion Control.cpp b/TileEngine/Explosion Control.cpp index 5de75063..d7495358 100644 --- a/TileEngine/Explosion Control.cpp +++ b/TileEngine/Explosion Control.cpp @@ -4202,7 +4202,7 @@ void DecayBombTimers( void ) // Flugente: we have to check every inventory for armed bombs and do the countdown for them, too // Flugente: new stuff: we can now also arm bombs in our inventory, and detonate/defuse those bombs remotely // So we have to look at every item in every inventory in this sector - for (UINT32 cnt = 0; cnt < guiNumMercSlots; cnt++ ) + for (UINT32 cnt = 0; cnt < guiNumMercSlots; ++cnt ) { SOLDIERTYPE* pSoldier = MercSlots[ cnt ]; @@ -4362,7 +4362,7 @@ void SetOffBombsByFrequency( UINT8 ubID, INT8 bFrequency ) // Flugente: new stuff: we can now also arm bombs in our inventory, and detonate/defuse those bombs remotely // So we have to look at every item in every inventory in this sector - for (UINT32 cnt = 0; cnt < guiNumMercSlots; cnt++ ) + for (UINT32 cnt = 0; cnt < guiNumMercSlots; ++cnt ) { SOLDIERTYPE* pSoldier = MercSlots[ cnt ]; diff --git a/TileEngine/overhead map.cpp b/TileEngine/overhead map.cpp index 3ef3da1e..4044a380 100644 --- a/TileEngine/overhead map.cpp +++ b/TileEngine/overhead map.cpp @@ -1063,28 +1063,24 @@ void RenderOverheadMap( INT16 sStartPointX_M, INT16 sStartPointY_M, INT16 sStart { pTile = &( gSmTileDB[ pNode->usIndex ] ); - // Flugente: uninformed hack - //if ( pTile && pTile->vo ) + sX = sTempPosX_S; + sY = sTempPosY_S; + + if( gTileDatabase[ pNode->usIndex ].uiFlags & IGNORE_WORLD_HEIGHT ) { - sX = sTempPosX_S; - sY = sTempPosY_S; - - if( gTileDatabase[ pNode->usIndex ].uiFlags & IGNORE_WORLD_HEIGHT ) - { - sY -= sModifiedHeight; - } - else - { - sY -= sHeight; - } - - sY += ( gsRenderHeight / 5 ); - - pTile->vo->pShadeCurrent= gSmTileSurf[ pTile->fType ].vo->pShades[pNode->ubShadeLevel]; - - // RENDER! - Blt8BPPDataTo16BPPBufferTransparent((UINT16*)pDestBuf, uiDestPitchBYTES, pTile->vo, sX, sY, pTile->usSubIndex ); + sY -= sModifiedHeight; } + else + { + sY -= sHeight; + } + + sY += ( gsRenderHeight / 5 ); + + pTile->vo->pShadeCurrent= gSmTileSurf[ pTile->fType ].vo->pShades[pNode->ubShadeLevel]; + + // RENDER! + Blt8BPPDataTo16BPPBufferTransparent((UINT16*)pDestBuf, uiDestPitchBYTES, pTile->vo, sX, sY, pTile->usSubIndex ); } } pNode = pNode->pNext; @@ -1097,25 +1093,21 @@ void RenderOverheadMap( INT16 sStartPointX_M, INT16 sStartPointY_M, INT16 sStart { pTile = &( gSmTileDB[ pNode->usIndex ] ); - // Flugente: uninformed hack - //if ( pTile && pTile->vo ) - { - sX = sTempPosX_S; - sY = sTempPosY_S - sHeight; - //dnl ch82 081213 - sY = sTempPosY_S; - if(gTileDatabase[pNode->usIndex].uiFlags & IGNORE_WORLD_HEIGHT) - sY -= sModifiedHeight; - else - sY -= sHeight; + sX = sTempPosX_S; + sY = sTempPosY_S - sHeight; + //dnl ch82 081213 + sY = sTempPosY_S; + if(gTileDatabase[pNode->usIndex].uiFlags & IGNORE_WORLD_HEIGHT) + sY -= sModifiedHeight; + else + sY -= sHeight; - sY += ( gsRenderHeight / 5 ); + sY += ( gsRenderHeight / 5 ); - pTile->vo->pShadeCurrent= gSmTileSurf[ pTile->fType ].vo->pShades[pNode->ubShadeLevel]; + pTile->vo->pShadeCurrent= gSmTileSurf[ pTile->fType ].vo->pShades[pNode->ubShadeLevel]; - // RENDER! - Blt8BPPDataTo16BPPBufferShadow((UINT16*)pDestBuf, uiDestPitchBYTES, pTile->vo, sX, sY, pTile->usSubIndex ); - } + // RENDER! + Blt8BPPDataTo16BPPBufferShadow((UINT16*)pDestBuf, uiDestPitchBYTES, pTile->vo, sX, sY, pTile->usSubIndex ); } pNode = pNode->pNext; } @@ -1130,28 +1122,24 @@ void RenderOverheadMap( INT16 sStartPointX_M, INT16 sStartPointY_M, INT16 sStart { pTile = &( gSmTileDB[ pNode->usIndex ] ); - // Flugente: uninformed hack - //if ( pTile && pTile->vo ) + sX = sTempPosX_S; + sY = sTempPosY_S - (gTileDatabase[ pNode->usIndex ].sOffsetHeight/5); + + if( gTileDatabase[ pNode->usIndex ].uiFlags & IGNORE_WORLD_HEIGHT ) { - sX = sTempPosX_S; - sY = sTempPosY_S - (gTileDatabase[ pNode->usIndex ].sOffsetHeight/5); - - if( gTileDatabase[ pNode->usIndex ].uiFlags & IGNORE_WORLD_HEIGHT ) - { - sY -= sModifiedHeight; - } - else - { - sY -= sHeight; - } - - sY += ( gsRenderHeight / 5 ); - - pTile->vo->pShadeCurrent= gSmTileSurf[ pTile->fType ].vo->pShades[pNode->ubShadeLevel]; - - // RENDER! - Blt8BPPDataTo16BPPBufferTransparent((UINT16*)pDestBuf, uiDestPitchBYTES, pTile->vo, sX, sY, pTile->usSubIndex ); + sY -= sModifiedHeight; } + else + { + sY -= sHeight; + } + + sY += ( gsRenderHeight / 5 ); + + pTile->vo->pShadeCurrent= gSmTileSurf[ pTile->fType ].vo->pShades[pNode->ubShadeLevel]; + + // RENDER! + Blt8BPPDataTo16BPPBufferTransparent((UINT16*)pDestBuf, uiDestPitchBYTES, pTile->vo, sX, sY, pTile->usSubIndex ); } } pNode = pNode->pNext;