battle_calcs.lua: avoid using formula= in SUFs

It’s slow for finding units with moves or attacks left. The alternative
method of getting all units and then looping over the table with a
condition is much faster.
This commit is contained in:
mattsc 2014-04-17 19:36:22 -07:00
parent 19eff08fd7
commit e87240c67f

View file

@ -1131,8 +1131,10 @@ function battle_calcs.get_attack_map_unit(unit, cfg)
-- MP left off the map (for enemy pathfinding)
local units_MP = {}
if (unit.side ~= wesnoth.current.side) then
units_MP = wesnoth.get_units { side = wesnoth.current.side, formula = '$this_unit.moves > 0' }
for _,uMP in ipairs(units_MP) do wesnoth.extract_unit(uMP) end
local all_units = wesnoth.get_units { side = wesnoth.current.side }
for _,unit in ipairs(all_units) do
if (unit.moves > 0) then table.insert(units_MP, unit) end
end
end
-- Find hexes the unit can reach