From 0e529070c4807d36ca29b9c3748ba2a4309bfafb Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Thu, 17 Aug 2023 19:42:43 +0300 Subject: [PATCH] Allow AI to shoot with lower aim if out of AP for current aim level --- TacticalAI/AIMain.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/TacticalAI/AIMain.cpp b/TacticalAI/AIMain.cpp index 827515f58..6aae43e67 100644 --- a/TacticalAI/AIMain.cpp +++ b/TacticalAI/AIMain.cpp @@ -2299,6 +2299,17 @@ INT8 ExecuteAction(SOLDIERTYPE *pSoldier) usHandItem = GetAttachedGrenadeLauncher(&pSoldier->inv[HANDPOS]); iRetCode = HandleItem( pSoldier, pSoldier->aiData.usActionData, pSoldier->bTargetLevel, usHandItem, FALSE ); + // If AI cannot shoot because of lack of APs, attempt to try again with lower aim. + // Usually happens when they have to turn before shooting. Without this, the game would cancel soldier's whole turn + if (iRetCode == ITEM_HANDLE_NOAPS && pSoldier->aiData.bAimTime > 0) + { + do + { + pSoldier->aiData.bAimTime -= 1; + iRetCode = HandleItem(pSoldier, pSoldier->aiData.usActionData, pSoldier->bTargetLevel, usHandItem, FALSE); + } while (iRetCode == ITEM_HANDLE_NOAPS && pSoldier->aiData.bAimTime > 0); + } + if ( iRetCode != ITEM_HANDLE_OK) { if ( iRetCode != ITEM_HANDLE_BROKEN ) // if the item broke, this is 'legal' and doesn't need reporting