From 3389f3fb246d5b04778f6e5eff1916021fa56f9d Mon Sep 17 00:00:00 2001 From: Flugente Date: Tue, 8 Jul 2014 23:12:26 +0000 Subject: [PATCH] Fix: overflow in EliminateAllEnemies(...) (by anv) git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@7322 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Strategic/Auto Resolve.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Strategic/Auto Resolve.cpp b/Strategic/Auto Resolve.cpp index 5bf6eefb..94675fb8 100644 --- a/Strategic/Auto Resolve.cpp +++ b/Strategic/Auto Resolve.cpp @@ -438,23 +438,34 @@ void EliminateAllEnemies( UINT8 ubSectorX, UINT8 ubSectorY ) pGroup = gpGroupList; pSector = &SectorInfo[ SECTOR( ubSectorX, ubSectorY ) ]; + UINT8 ubNumTanks = 0; // if we're doing this from the Pre-Battle interface, gpAR is NULL, and RemoveAutoResolveInterface(0 won't happen, so // we must process the enemies killed right here & give out loyalty bonuses as if the battle had been fought & won if( !gpAR ) { - GetNumberOfEnemiesInSector( ubSectorX, ubSectorY, &ubNumEnemies[ 0 ], &ubNumEnemies[ 1 ], &ubNumEnemies[ 2 ], &ubNumEnemies[ 3 ] ); + GetNumberOfEnemiesInSector( ubSectorX, ubSectorY, &ubNumEnemies[ 0 ], &ubNumEnemies[ 1 ], &ubNumEnemies[ 2 ], &ubNumTanks ); - for ( ubRankIndex = 0; ubRankIndex < NUM_ENEMY_RANKS; ubRankIndex++ ) + for ( ubRankIndex = 0; ubRankIndex < NUM_ENEMY_RANKS; ++ubRankIndex ) { - for ( i = 0; i < ubNumEnemies[ ubRankIndex ]; i++ ) + for ( i = 0; i < ubNumEnemies[ ubRankIndex ]; ++i ) { - if( ProcessLoyalty() )HandleGlobalLoyaltyEvent( GLOBAL_LOYALTY_ENEMY_KILLED, ubSectorX, ubSectorY, 0 ); + if( ProcessLoyalty() ) + HandleGlobalLoyaltyEvent( GLOBAL_LOYALTY_ENEMY_KILLED, ubSectorX, ubSectorY, 0 ); + TrackEnemiesKilled( ENEMY_KILLED_IN_AUTO_RESOLVE, RankIndexToSoldierClass( ubRankIndex ) ); } } - if( ProcessLoyalty() )HandleGlobalLoyaltyEvent( GLOBAL_LOYALTY_BATTLE_WON, ubSectorX, ubSectorY, 0 ); + if ( ProcessLoyalty( ) ) + { + for ( i = 0; i < ubNumTanks; ++i ) + { + HandleGlobalLoyaltyEvent( GLOBAL_LOYALTY_ENEMY_KILLED, ubSectorX, ubSectorY, 0 ); + } + + HandleGlobalLoyaltyEvent( GLOBAL_LOYALTY_BATTLE_WON, ubSectorX, ubSectorY, 0 ); + } } if( !gpAR || gpAR->ubBattleStatus != BATTLE_IN_PROGRESS )