Fix AI behaviour for Snipe distance preference

This commit is contained in:
Alexander Batalov 2022-08-31 22:02:08 +03:00
parent 56d35bef0d
commit 2a17a07784
1 changed files with 16 additions and 3 deletions

View File

@ -2827,11 +2827,24 @@ 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
// 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;
}