Check if action should stay inprogress state

Several actions tended to get stuck in an invalid state, where it was completed, but aiData.bActionInProgress was still TRUE resulting in an AI deadlock.

If such a situation is found, Actiondone is now called, preventing the deadlock
This commit is contained in:
Asdow
2024-02-04 16:10:26 +02:00
parent cd193c7f5e
commit 01327265a3
+28 -1
View File
@@ -440,6 +440,27 @@ void DebugQuestInfo(STR szOutput)
}
}
static INT16 ShouldActionStayInProgress(SOLDIERTYPE* pSoldier)
{
// this here should never happen, but it seems to (turns sometimes hang!)
if ((pSoldier->aiData.bAction == AI_ACTION_CHANGE_FACING) && (pSoldier->pathing.bDesiredDirection != pSoldier->aiData.usActionData))
{
// don't try to pay any more APs for this, it was paid for once already!
pSoldier->pathing.bDesiredDirection = (INT8)pSoldier->aiData.usActionData; // turn to face direction in actionData
return(TRUE);
}
else if ((pSoldier->aiData.bAction == AI_ACTION_CHANGE_FACING) && (pSoldier->pathing.bDesiredDirection == pSoldier->aiData.usActionData))
{
return(FALSE);
}
else if (pSoldier->aiData.bAction == AI_ACTION_END_TURN || pSoldier->aiData.bAction == AI_ACTION_NONE)
{
return(FALSE);
}
// needs more time to complete action
return(TRUE);
}
BOOLEAN InitAI( void )
{
@@ -992,6 +1013,12 @@ void HandleSoldierAI( SOLDIERTYPE *pSoldier ) // FIXME - this function is named
{
ActionDone(pSoldier);
}
if (!ShouldActionStayInProgress(pSoldier))
{
DebugAI(AI_MSG_INFO, pSoldier, String("Action % s was stuck as being in progress. Canceling action", wszAction[pSoldier->aiData.bAction]));
ActionDone(pSoldier);
}
}
/*********
End of new overall AI system
@@ -1460,7 +1487,7 @@ void FreeUpNPCFromRoofClimb(SOLDIERTYPE *pSoldier )
void ActionDone(SOLDIERTYPE *pSoldier)
{
// if an action is currently selected
if (pSoldier->aiData.bAction != AI_ACTION_NONE)
//if (pSoldier->aiData.bAction != AI_ACTION_NONE)
{
if (pSoldier->flags.uiStatusFlags & SOLDIER_MONSTER)
{