From 56d35bef0dfe08c669dab4fbef931477255e43fc Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Wed, 31 Aug 2022 20:25:40 +0300 Subject: [PATCH] Add more checks for AI to pick secondary hit mode --- src/combat_ai.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/combat_ai.cc b/src/combat_ai.cc index 61ebad3..51123b0 100644 --- a/src/combat_ai.cc +++ b/src/combat_ai.cc @@ -2156,6 +2156,20 @@ static int _ai_pick_hit_mode(Object* a1, Object* a2, Object* a3) } } + // SFALL: Add a check for the weapon range and the AP cost when AI is + // choosing weapon attack modes. + if (useSecondaryMode) { + if (objectGetDistanceBetween(a1, a3) > weaponGetRange(a1, HIT_MODE_RIGHT_WEAPON_SECONDARY)) { + useSecondaryMode = false; + } + } + + if (useSecondaryMode) { + if (a1->data.critter.combat.ap < weaponGetActionPointCost(a1, HIT_MODE_RIGHT_WEAPON_SECONDARY, false)) { + useSecondaryMode = false; + } + } + if (useSecondaryMode) { if (attackType != ATTACK_TYPE_THROW || _ai_search_inven_weap(a1, 0, a3) != NULL