Lua AIs: fix experience for killing level 0 units

This commit is contained in:
mattsc 2018-11-09 06:52:08 -08:00
parent d743a5b9f2
commit bc956b3e7f
3 changed files with 9 additions and 4 deletions

View file

@ -835,6 +835,7 @@ function battle_calcs.attack_rating(attacker, defender, dst, cfg, cache)
if (attacker.max_experience - attacker.experience <= defender_level * wesnoth.game_config.combat_experience) then
level_bonus = 1. - att_stats.hp_chance[0]
else
if (defender_level == 0) then defender_level = 0.5 end
if (attacker.max_experience - attacker.experience <= defender_level * wesnoth.game_config.kill_experience) then
level_bonus = (1. - att_stats.hp_chance[0]) * def_stats.hp_chance[0]
end
@ -881,6 +882,7 @@ function battle_calcs.attack_rating(attacker, defender, dst, cfg, cache)
if (defender.max_experience - defender.experience <= attacker_level * wesnoth.game_config.combat_experience) then
defender_level_penalty = 1. - def_stats.hp_chance[0]
else
if (attacker_level == 0) then attacker_level = 0.5 end
if (defender.max_experience - defender.experience <= attacker_level * wesnoth.game_config.kill_experience) then
defender_level_penalty = (1. - def_stats.hp_chance[0]) * att_stats.hp_chance[0]
end

View file

@ -379,25 +379,28 @@ function ca_bottleneck_move:evaluation(cfg, data)
-- Level-up-attacks will always get a rating greater than any move
for _,attack in ipairs(attacks) do
-- Only do calc. if there's a theoretical chance for leveling up (speeds things up a lot)
local eff_defender_level = attack.defender_level
if (eff_defender_level == 0) then eff_defender_level = 0.5 end
if (attack.x == loc[1]) and (attack.y == loc[2]) and
(unit.max_experience - unit.experience <= wesnoth.game_config.kill_experience * attack.defender_level)
(unit.max_experience - unit.experience <= wesnoth.game_config.kill_experience * eff_defender_level)
then
for n_weapon,weapon in ipairs(unit.attacks) do
local att_stats, def_stats = BC.simulate_combat_loc(unit, { attack.x, attack.y }, attack.defender, n_weapon)
-- Execute level-up attack when:
-- 1. max_experience-experience <= target.level*combat_experience and chance to die = 0
-- 2. max_experience-experience <= target.level*kill_experience and chance to die = 0
-- 2. kill_experience enough for leveling up and chance to die = 0
-- and chance to kill > 66% and remaining av hitpoints > 20
-- #1 is a definite level up, #2 is not, so #1 gets priority
local level_up_rating = 0
-- Note: in this conditional it needs to be the real defender level, not eff_defender_level
if (unit.max_experience - unit.experience <= wesnoth.game_config.combat_experience * attack.defender_level) then
if (att_stats.hp_chance[0] == 0) then
-- Weakest enemy is best (favors stronger weapon)
level_up_rating = 15000 - def_stats.average_hp
end
else
if (unit.max_experience - unit.experience <= wesnoth.game_config.kill_experience * attack.defender_level)
if (unit.max_experience - unit.experience <= wesnoth.game_config.kill_experience * eff_defender_level)
and (att_stats.hp_chance[0] == 0)
and (def_stats.hp_chance[0] >= 0.66)
and (att_stats.average_hp >= 20)

View file

@ -237,12 +237,12 @@ function ca_fast_attack_utils.damage_rating_unit(attacker_info, defender_info, a
-- by the chance of not dying itself.
-- Note: this can make the fractional damage negative (as it should)
local defender_level = defender_info.level
if (defender_level == 0) then defender_level = 0.5 end -- L0 units
local level_bonus = 0.
if (attacker_info.max_experience - attacker_info.experience <= defender_level * wesnoth.game_config.combat_experience) then
level_bonus = 1. - att_stat.hp_chance[0]
elseif (attacker_info.max_experience - attacker_info.experience <= defender_level * wesnoth.game_config.kill_experience) then
if (defender_level == 0) then defender_level = 0.5 end
level_bonus = (1. - att_stat.hp_chance[0]) * def_stat.hp_chance[0]
end