From 86e21d43a852a6488e18261bd664a85043218dd0 Mon Sep 17 00:00:00 2001 From: Flugente Date: Sun, 5 Jul 2015 12:44:12 +0000 Subject: [PATCH] If the player retreats from an enemy attack that was targetted at this sector, the enemy group pursuits instead of being given new orders. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@7901 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Strategic/Strategic AI.cpp | 11 --------- Strategic/Strategic AI.h | 7 ++++++ Strategic/Strategic Movement.cpp | 38 +++++++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/Strategic/Strategic AI.cpp b/Strategic/Strategic AI.cpp index 21c4ce16c..85e7b0f28 100644 --- a/Strategic/Strategic AI.cpp +++ b/Strategic/Strategic AI.cpp @@ -503,17 +503,6 @@ void SAIReportError( STR16 wErrorString ); #define SAIReportError( a ) //define it out #endif -enum SAIMOVECODE -{ - DIRECT, - EVASIVE, - STAGE, -}; -void MoveSAIGroupToSector( GROUP **pGroup, UINT8 ubSectorID, UINT32 uiMoveCode, UINT8 ubIntention ); - - - - /* This is only a dirty fix to prevent CTD: * when loading a game, sometimes I found that * 'gGarrisonGroup' was not allocated. diff --git a/Strategic/Strategic AI.h b/Strategic/Strategic AI.h index de12e970e..7ef50ff28 100644 --- a/Strategic/Strategic AI.h +++ b/Strategic/Strategic AI.h @@ -59,6 +59,13 @@ INT16 FindGarrisonIndexForGroupIDPending( UINT8 ubGroupID ); GROUP* FindPendingGroupInSector( UINT8 ubSectorID ); +enum SAIMOVECODE +{ + DIRECT, + EVASIVE, + STAGE, +}; +void MoveSAIGroupToSector( GROUP **pGroup, UINT8 ubSectorID, UINT32 uiMoveCode, UINT8 ubIntention ); void RepollSAIGroup( GROUP *pGroup ); diff --git a/Strategic/Strategic Movement.cpp b/Strategic/Strategic Movement.cpp index c16296098..59b084df4 100644 --- a/Strategic/Strategic Movement.cpp +++ b/Strategic/Strategic Movement.cpp @@ -4758,7 +4758,43 @@ void ResetMovementForNonPlayerGroup( GROUP *pGroup ) #ifdef JA2UB //Ja25 No strategic ai #else - RepollSAIGroup( pGroup ); + // Flugente: instead of just running back to their original sector, enemy patrols on pursuit should follow player groups + // first, determine whether there are any player groups nearby + BOOLEAN sucess = FALSE; + GROUP* pOtherGroup = gpGroupList; + while ( pOtherGroup ) + { + if ( pOtherGroup->usGroupTeam == OUR_TEAM ) + { + if ( pGroup->ubSectorX == pOtherGroup->ubSectorX && pGroup->ubSectorY == pOtherGroup->ubSectorY ) + { + MoveSAIGroupToSector( &pGroup, (UINT8)SECTOR( pOtherGroup->ubNextX, pOtherGroup->ubNextY ), DIRECT, PURSUIT ); + + // the group has to be delayed - otherwise they could arrive at the same time as the player, resulting in odd behaviour during insertion + DeleteStrategicEvent( EVENT_GROUP_ARRIVAL, pGroup->ubGroupID ); + + // NOTE: This can cause the arrival time to be > GetWorldTotalMin() + TraverseTime, so keep that in mind + // if you have any code that uses these 3 values to figure out how far along its route a group is! + SetGroupArrivalTime( pGroup, pOtherGroup->uiArrivalTime + 5 ); + + if ( !AddStrategicEvent( EVENT_GROUP_ARRIVAL, pGroup->uiArrivalTime, pGroup->ubGroupID ) ) + { + AssertMsg( 0, "Failed to add movement event." ); + break; + } + + sucess = TRUE; + + break; + } + } + pOtherGroup = pOtherGroup->next; + } + + if ( !sucess ) + { + RepollSAIGroup( pGroup ); + } #endif return;