From 2c2d8c92763302b849de2dc69a2a15dc6c1f591c Mon Sep 17 00:00:00 2001 From: Sevenfm Date: Tue, 20 Oct 2020 21:20:26 +0000 Subject: [PATCH] AI: - improved civilian cower/run away code - CancelAIAction: reset bNextAction and next action data - clear next action data before making decisions - militia always try to spare grenades unless under attack or using flares git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@8905 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- TacticalAI/AIMain.cpp | 12 ++++++++++++ TacticalAI/Attacks.cpp | 6 ++++++ TacticalAI/DecideAction.cpp | 2 ++ TacticalAI/Realtime.cpp | 6 ++++++ 4 files changed, 26 insertions(+) diff --git a/TacticalAI/AIMain.cpp b/TacticalAI/AIMain.cpp index 2266f255..9d6bdee3 100644 --- a/TacticalAI/AIMain.cpp +++ b/TacticalAI/AIMain.cpp @@ -1462,6 +1462,12 @@ void CancelAIAction(SOLDIERTYPE *pSoldier, UINT8 ubForce) pSoldier->aiData.bBypassToGreen = FALSE; ActionDone(pSoldier); + + // sevenfm: reset next action + pSoldier->aiData.bNextAction = AI_ACTION_NONE; + pSoldier->aiData.usNextActionData = 0; + pSoldier->aiData.bNextTargetLevel = 0; + pSoldier->iNextActionSpecialData = 0; } @@ -1653,6 +1659,12 @@ void TurnBasedHandleNPCAI(SOLDIERTYPE *pSoldier) } else { + // sevenfm: clear next action data before making decisions + pSoldier->aiData.bNextAction = AI_ACTION_NONE; + pSoldier->aiData.usNextActionData = 0; + pSoldier->aiData.bNextTargetLevel = 0; + pSoldier->iNextActionSpecialData = 0; + if (!(gTacticalStatus.uiFlags & ENGAGED_IN_CONV)) { if(!pSoldier->ai_masterplan_) // if the Soldier has no plan, create one diff --git a/TacticalAI/Attacks.cpp b/TacticalAI/Attacks.cpp index 6cb99ea6..90749f72 100644 --- a/TacticalAI/Attacks.cpp +++ b/TacticalAI/Attacks.cpp @@ -1336,6 +1336,12 @@ void CalcBestThrow(SOLDIERTYPE *pSoldier, ATTACKTYPE *pBestThrow) fSpare = FALSE; } + // militia always try to spare grenades unless under attack or using flares + if (pSoldier->bTeam == MILITIA_TEAM && !pSoldier->aiData.bUnderFire && !Item[usGrenade].flare) + { + fSpare = TRUE; + } + // need 3 opponents for 0 difficulty, 1 opponent for max difficulty if (fSpare && ubOpponentCnt < 3 - ubDiff / 2) { diff --git a/TacticalAI/DecideAction.cpp b/TacticalAI/DecideAction.cpp index e9265d1d..0cda6a2b 100644 --- a/TacticalAI/DecideAction.cpp +++ b/TacticalAI/DecideAction.cpp @@ -2517,6 +2517,7 @@ INT8 DecideActionRed(SOLDIERTYPE *pSoldier) // sevenfm: before deciding anything, stop cowering if (SoldierAI(pSoldier) && + !fCivilian && ubCanMove && pSoldier->stats.bLife >= OKLIFE && !pSoldier->bCollapsed && @@ -4909,6 +4910,7 @@ INT16 ubMinAPCost; // sevenfm: before deciding anything, stop cowering if (SoldierAI(pSoldier) && + !fCivilian && ubCanMove && pSoldier->stats.bLife >= OKLIFE && !pSoldier->bCollapsed && diff --git a/TacticalAI/Realtime.cpp b/TacticalAI/Realtime.cpp index 3bbeb1fa..4898bb2c 100644 --- a/TacticalAI/Realtime.cpp +++ b/TacticalAI/Realtime.cpp @@ -185,6 +185,12 @@ void RTHandleAI( SOLDIERTYPE * pSoldier ) } else { + // sevenfm: clear next action data before making decision + pSoldier->aiData.bNextAction = AI_ACTION_NONE; + pSoldier->aiData.usNextActionData = 0; + pSoldier->aiData.bNextTargetLevel = 0; + pSoldier->iNextActionSpecialData = 0; + if (!(gTacticalStatus.uiFlags & ENGAGED_IN_CONV)) { if(!pSoldier->ai_masterplan_) // if the Soldier has no plan, create one