From 2a17a077847ca458a5589e41cb90df9784df9eb6 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Wed, 31 Aug 2022 22:02:08 +0300 Subject: [PATCH] Fix AI behaviour for Snipe distance preference --- src/combat_ai.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/combat_ai.cc b/src/combat_ai.cc index 51123b0..640d0b2 100644 --- a/src/combat_ai.cc +++ b/src/combat_ai.cc @@ -2827,9 +2827,22 @@ int _cai_perform_distance_prefs(Object* a1, Object* a2) break; case DISTANCE_SNIPE: if (a2 != NULL) { - if (objectGetDistanceBetween(a1, a2) < 10) { - // NOTE: some odd code omitted - _ai_move_away(a1, a2, 10); + // SFALL: Fix AI behavior for "Snipe" distance preference. + int distance = objectGetDistanceBetween(a1, a2); + if (distance < 10) { + int attackCost = weaponGetActionPointCost(a1, HIT_MODE_RIGHT_WEAPON_PRIMARY, false); + int movementPoints = a1->data.critter.combat.ap - attackCost; + if (movementPoints > 0) { + if (movementPoints + distance - 1 < 5) { + int attackerRating = _combatai_rating(a1); + int defenderRating = _combatai_rating(a2); + if (attackerRating < defenderRating) { + _ai_move_away(a1, a2, 10); + } + } + } else { + _ai_move_away(a1, a2, 10); + } } } break;