Protect Unit Micro AI: ensure units are on AI side

In general, the units specified in the MAI setup should be on the AI side.  However, that might change during a scenario, for example when there is an event that switches units to other sides.
This commit is contained in:
mattsc 2021-03-03 08:14:46 -08:00
parent c61494e1dc
commit 778fde4fbe
3 changed files with 3 additions and 3 deletions

View file

@ -10,7 +10,7 @@ function ca_protect_unit_attack:evaluation(cfg)
local units = {}
for u in wml.child_range(cfg, "unit") do
table.insert(units, AH.get_units_with_attacks { id = u.id }[1])
table.insert(units, AH.get_units_with_attacks { id = u.id, side = wesnoth.current.side }[1])
end
if (not units[1]) then return 0 end

View file

@ -5,7 +5,7 @@ local ca_protect_unit_finish, PU_unit, PU_goal = {}
function ca_protect_unit_finish:evaluation(cfg)
-- If a unit can make it to the goal, this is the first thing that happens
for u in wml.child_range(cfg, "unit") do
local unit = AH.get_units_with_moves { id = u.id }[1]
local unit = AH.get_units_with_moves { id = u.id, side = wesnoth.current.side }[1]
if unit then
local path, cost = AH.find_path_with_shroud(unit, u.goal_x, u.goal_y)
if (cost <= unit.moves) and ((unit.x ~= u.goal_x) or (unit.y ~= u.goal_y)) then

View file

@ -5,7 +5,7 @@ local BC = wesnoth.require "ai/lua/battle_calcs.lua"
local function get_protected_units(cfg)
local units = {}
for u in wml.child_range(cfg, "unit") do
table.insert(units, AH.get_units_with_moves { id = u.id }[1])
table.insert(units, AH.get_units_with_moves { id = u.id, side = wesnoth.current.side }[1])
end
return units
end