From cd193c7f5ee0e29fb10bd4a447934dc3d9b58d8f Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sun, 4 Feb 2024 16:07:03 +0200 Subject: [PATCH] Call TurnBasedHandleNPCAI() if no action is in progress Several actions would sometimes get stuck in a forever loop, where they would not be executed, since no proper path for executing the actions is found. Originally TurnBasedHandleNPCAI() would only be called if aidata.bAction was AI_ACTION_NONE. Now we'll call it if an action is not already in progress, and will be executed if the action is affordable. --- TacticalAI/AIMain.cpp | 56 +++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/TacticalAI/AIMain.cpp b/TacticalAI/AIMain.cpp index 0e78ef59..1aa88ee3 100644 --- a/TacticalAI/AIMain.cpp +++ b/TacticalAI/AIMain.cpp @@ -859,7 +859,7 @@ void HandleSoldierAI( SOLDIERTYPE *pSoldier ) // FIXME - this function is named return; } - if (pSoldier->aiData.bAction == AI_ACTION_NONE) + if (!pSoldier->aiData.bActionInProgress) { // being handled so turn off muzzle flash if ( pSoldier->flags.fMuzzleFlash ) @@ -1837,42 +1837,42 @@ void TurnBasedHandleNPCAI(SOLDIERTYPE *pSoldier) { pSoldier->aiData.bAction = AI_ACTION_NONE; } + } - // if he chose to continue doing nothing - if (pSoldier->aiData.bAction == AI_ACTION_NONE) - { + // if he chose to continue doing nothing + if (pSoldier->aiData.bAction == AI_ACTION_NONE) + { #ifdef RECORDNET - fprintf(NetDebugFile,"\tMOVED BECOMING TRUE: Chose to do nothing, guynum %d\n",pSoldier->ubID); + fprintf(NetDebugFile,"\tMOVED BECOMING TRUE: Chose to do nothing, guynum %d\n",pSoldier->ubID); #endif - DebugMsg (TOPIC_JA2AI,DBG_LEVEL_3,"NPC has no action assigned"); - NPCDoesNothing(pSoldier); // sets pSoldier->moved to TRUE - return; - } - // to get here, we MUST have an action selected, but not in progress... - // see if we can afford to do this action - if (IsActionAffordable(pSoldier)) - { - NPCDoesAct(pSoldier); + DebugMsg (TOPIC_JA2AI,DBG_LEVEL_3,"NPC has no action assigned"); + NPCDoesNothing(pSoldier); // sets pSoldier->moved to TRUE + return; + } + // to get here, we MUST have an action selected, but not in progress... + // see if we can afford to do this action + if (IsActionAffordable(pSoldier)) + { + NPCDoesAct(pSoldier); - // perform the chosen action - pSoldier->aiData.bActionInProgress = ExecuteAction(pSoldier); // if started, mark us as busy + // perform the chosen action + pSoldier->aiData.bActionInProgress = ExecuteAction(pSoldier); // if started, mark us as busy - if ( !pSoldier->aiData.bActionInProgress && !TileIsOutOfBounds(pSoldier->sAbsoluteFinalDestination)) - { - // turn based... abort this guy's turn - EndAIGuysTurn( pSoldier ); - } - } - else + if ( !pSoldier->aiData.bActionInProgress && !TileIsOutOfBounds(pSoldier->sAbsoluteFinalDestination)) { -#ifdef DEBUGDECISIONS - AINumMessage("HandleManAI - Not enough APs, skipping guy#",pSoldier->ubID); -#endif - HaltMoveForSoldierOutOfPoints( pSoldier); - return; + // turn based... abort this guy's turn + EndAIGuysTurn( pSoldier ); } } + else + { +#ifdef DEBUGDECISIONS + AINumMessage("HandleManAI - Not enough APs, skipping guy#",pSoldier->ubID); +#endif + HaltMoveForSoldierOutOfPoints( pSoldier); + return; + } }