AI: ensure all CAs respect unit guardian status
This adds the correct behavior for the castle_switch, move_to_any_enemy and place_healers CAs. It was already in place for the other former ExpAI CAs (except for recruiting and spread_poison, for which it does not apply). This automatically also adds this behavior to the Healer Support Micro AI.
This commit is contained in:
parent
24af20cf83
commit
3e70358d8d
3 changed files with 12 additions and 11 deletions
|
@ -35,12 +35,12 @@ function ca_castle_switch:evaluation(cfg, data, filter_own)
|
|||
return 0
|
||||
end
|
||||
|
||||
local leader = wesnoth.units.find_on_map {
|
||||
side = wesnoth.current.side,
|
||||
canrecruit = 'yes',
|
||||
formula = '(movement_left = total_movement) and (hitpoints = max_hitpoints)',
|
||||
{ "and", filter_own }
|
||||
}[1]
|
||||
local leader = AH.get_units_with_moves({
|
||||
side = wesnoth.current.side,
|
||||
canrecruit = 'yes',
|
||||
formula = '(movement_left = total_movement) and (hitpoints = max_hitpoints)',
|
||||
{ "and", filter_own }
|
||||
}, true)[1]
|
||||
if not leader then
|
||||
-- CA is irrelevant if no leader or the leader may have moved from another CA
|
||||
data.leader_target = nil
|
||||
|
@ -191,11 +191,11 @@ function ca_castle_switch:evaluation(cfg, data, filter_own)
|
|||
end
|
||||
|
||||
function ca_castle_switch:execution(cfg, data, filter_own)
|
||||
local leader = wesnoth.units.find_on_map {
|
||||
local leader = AH.get_units_with_moves({
|
||||
side = wesnoth.current.side,
|
||||
canrecruit = 'yes',
|
||||
{ "and", filter_own }
|
||||
}[1]
|
||||
}, true)[1]
|
||||
|
||||
if AH.print_exec() then AH.print_ts(' Executing castle_switch CA') end
|
||||
if AH.show_messages() then wesnoth.wml_actions.message { speaker = leader.id, message = 'Switching castles' } end
|
||||
|
|
|
@ -13,11 +13,11 @@ function ca_move_to_any_enemy:evaluation(cfg, data, filter_own)
|
|||
local start_time, ca_name = wesnoth.get_time_stamp() / 1000., 'move_to_any_enemy'
|
||||
if AH.print_eval() then AH.print_ts(' - Evaluating move_to_any_enemy CA:') end
|
||||
|
||||
local units = AH.get_units_with_moves {
|
||||
local units = AH.get_units_with_moves({
|
||||
side = wesnoth.current.side,
|
||||
canrecruit = 'no',
|
||||
{ "and", filter_own }
|
||||
}
|
||||
}, true)
|
||||
|
||||
if (not units[1]) then
|
||||
-- No units with moves left
|
||||
|
|
|
@ -19,7 +19,8 @@ function ca_healer_move:evaluation(cfg, data)
|
|||
|
||||
local healers, healers_noMP = {}, {}
|
||||
for _,healer in ipairs(all_healers) do
|
||||
if (healer.moves > 0) then
|
||||
-- For the purpose of this evaluation, guardians count as units without moves
|
||||
if (healer.moves > 0) and (not healer.status.guardian) then
|
||||
table.insert(healers, healer)
|
||||
else
|
||||
table.insert(healers_noMP, healer)
|
||||
|
|
Loading…
Add table
Reference in a new issue