From 7096116296d08d98de6702a9d7153be7fb35df26 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Sun, 14 Aug 2022 17:48:59 +0300 Subject: [PATCH] Fix best weapon calculations --- src/combat_ai.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/combat_ai.cc b/src/combat_ai.cc index da67e41..9a42bd8 100644 --- a/src/combat_ai.cc +++ b/src/combat_ai.cc @@ -1714,17 +1714,18 @@ static Object* _ai_best_weapon(Object* attacker, Object* weapon1, Object* weapon return NULL; } - avgDamage1 = (maxDamage - minDamage) / 2; + // SFALL: Fix avg damage calculation. + avgDamage1 = (maxDamage + minDamage) / 2; if (_item_w_area_damage_radius(weapon1, HIT_MODE_RIGHT_WEAPON_PRIMARY) > 0 && defender != NULL) { attack.weapon = weapon1; _compute_explosion_on_extras(&attack, 0, weaponIsGrenade(weapon1), 1); avgDamage1 *= attack.extrasLength + 1; } - // TODO: Probably an error, why it takes [weapon2], should likely use - // [weapon1]. - if (weaponGetPerk(weapon2) != -1) { - avgDamage1 *= 5; + // SFALL: Fix for the incorrect item being checked. + if (weaponGetPerk(weapon1) != -1) { + // SFALL: Lower weapon score multiplier for having perk. + avgDamage1 *= 2; } if (defender != NULL) { @@ -1758,7 +1759,8 @@ static Object* _ai_best_weapon(Object* attacker, Object* weapon1, Object* weapon return NULL; } - avgDamage2 = (maxDamage - minDamage) / 2; + // SFALL: Fix avg damage calculation. + avgDamage2 = (maxDamage + minDamage) / 2; if (_item_w_area_damage_radius(weapon2, HIT_MODE_RIGHT_WEAPON_PRIMARY) > 0 && defender != NULL) { attack.weapon = weapon2; _compute_explosion_on_extras(&attack, 0, weaponIsGrenade(weapon2), 1); @@ -1766,7 +1768,8 @@ static Object* _ai_best_weapon(Object* attacker, Object* weapon1, Object* weapon } if (weaponGetPerk(weapon2) != -1) { - avgDamage2 *= 5; + // SFALL: Lower weapon score multiplier for having perk. + avgDamage2 *= 2; } if (defender != NULL) {