Healer Support MAI: make [filter] work correctly when aggression=0

Previously, all healers were excluded from attacks when aggression=0
was set, not only those specified in [filter].
This commit is contained in:
mattsc 2013-06-07 06:48:44 -07:00
parent b9a35cb3db
commit ec21fad877
2 changed files with 11 additions and 9 deletions

View file

@ -22,7 +22,7 @@ return {
return score
end
function healer_support:initialize_healer_support_exec()
function healer_support:initialize_healer_support_exec(cfg)
--print(' Initializing healer_support at beginning of Turn ' .. wesnoth.current.turn)
-- First, modify the attacks aspect to exclude healers
@ -39,10 +39,12 @@ return {
action = "add",
path = "aspect[attacks].facet",
{ "facet", {
name = "ai_default_rca::aspect_attacks",
id = "no_healers_attack",
invalidate_on_gamestate_change = "yes",
{ "filter_own", { { "not", { ability = "healing" } } } }
name = "ai_default_rca::aspect_attacks",
id = "no_healers_attack",
invalidate_on_gamestate_change = "yes",
{ "filter_own", {
{ "not", { ability = "healing", { "and", cfg.filter } } }
} }
} }
}
@ -101,7 +103,7 @@ return {
formula = '$this_unit.moves = 0', { "and", cfg.filter }
}
local all_units = wesnoth.get_units{ side = wesnoth.current.side,
local all_units = wesnoth.get_units{ side = wesnoth.current.side,
{"and", cfg.filter_second}
}
@ -139,7 +141,7 @@ return {
}
local enemy_attack_map = BC.get_attack_map(enemies)
--AH.put_labels(enemy_attack_map.units)
local avoid_map = LS.of_pairs(ai.get_avoid())
-- Put units back out there
@ -167,7 +169,7 @@ return {
if (H.distance_between(u.x, u.y, r[1], r[2]) == 1) then
-- !!!!!!! These ratings have to be positive or the method doesn't work !!!!!!!!!
rating = rating + u.max_hitpoints - u.hitpoints
-- If injured_units_only = true then don't count units with full HP
if (u.max_hitpoints - u.hitpoints > 0) or (not cfg.injured_units_only) then
rating = rating + 15 * (enemy_attack_map.units:get(u.x, u.y) or 0)

View file

@ -168,7 +168,7 @@ function wesnoth.wml_actions.micro_ai(cfg)
local CA_parms = {
{
id = 'initialize_healer_support', eval_name = 'initialize_healer_support_eval', exec_name = 'initialize_healer_support_exec',
max_score = 999990, cfg_table = {}
max_score = 999990, cfg_table = cfg_hs
},
{
id = 'healer_support', eval_name = 'healer_support_eval', exec_name = 'healer_support_exec',