battle_calcs.best_defense_map(): add parameter ignore_these_units

This is a table of enemy units whose ZoC is to be ignored for route
finding.  It is useful for determing where the enemy can move while
ignoring own units (enemies of the enemy) that have not moved yet.
This commit is contained in:
mattsc 2013-10-31 08:22:15 -07:00
parent 526debf3e9
commit 554a95749a

View file

@ -1322,11 +1322,16 @@ function battle_calcs.best_defense_map(units, cfg)
-- For each hex, the value is the maximum of any of the units that can reach that hex
-- cfg: table with config parameters
-- max_moves: if set use max_moves for units (this setting is always used for units on other sides)
-- ignore_these_units: table of enemy units whose ZoC is to be ignored for route finding
cfg = cfg or {}
local defense_map = LS.create()
if cfg.ignore_these_units then
for i,u in ipairs(cfg.ignore_these_units) do wesnoth.extract_unit(u) end
end
for i,u in ipairs(units) do
-- Set max_moves according to the cfg value
local max_moves = cfg.max_moves
@ -1346,6 +1351,10 @@ function battle_calcs.best_defense_map(units, cfg)
end
end
if cfg.ignore_these_units then
for i,u in ipairs(cfg.ignore_these_units) do wesnoth.put_unit(u.x, u.y, u) end
end
return defense_map
end