A more efficient implementation of [store_reachable_locations].
Could probably still be made faster.
This commit is contained in:
parent
3bd47bcb15
commit
8454d10c37
1 changed files with 17 additions and 18 deletions
|
@ -386,43 +386,42 @@ function wml_actions.store_reachable_locations(cfg)
|
||||||
local viewing_side = cfg.viewing_side or 0
|
local viewing_side = cfg.viewing_side or 0
|
||||||
local variable = cfg.variable or helper.wml_error "[store_reachable_locations] missing required variable= key"
|
local variable = cfg.variable or helper.wml_error "[store_reachable_locations] missing required variable= key"
|
||||||
|
|
||||||
local res = location_set.create()
|
local reach = location_set.create()
|
||||||
|
local unit_reach = location_set.create()
|
||||||
|
|
||||||
for i,unit in ipairs(wesnoth.get_units(unit_filter)) do
|
for i,unit in ipairs(wesnoth.get_units(unit_filter)) do
|
||||||
local reach
|
unit_reach:clear()
|
||||||
|
|
||||||
if range == "movement" or range == "attack" then
|
if range == "movement" or range == "attack" then
|
||||||
if moves == "max" then
|
if moves == "max" then
|
||||||
local real_moves = unit.moves
|
local real_moves = unit.moves
|
||||||
unit.moves = unit.max_moves
|
unit.moves = unit.max_moves
|
||||||
reach = wesnoth.find_reach(unit, { viewing_side = viewing_side } )
|
unit_reach = location_set.of_pairs(wesnoth.find_reach(unit, { viewing_side = viewing_side } ))
|
||||||
unit.moves = real_moves
|
unit.moves = real_moves
|
||||||
else
|
else
|
||||||
reach = wesnoth.find_reach(unit)
|
unit_reach = location_set.of_pairs(wesnoth.find_reach(unit, { viewing_side = viewing_side } ))
|
||||||
end
|
end
|
||||||
elseif range == "vision" then
|
elseif range == "vision" then
|
||||||
local real_moves = unit.moves
|
local real_moves = unit.moves
|
||||||
unit.moves = unit.max_moves
|
unit.moves = unit.max_moves
|
||||||
reach = wesnoth.find_reach(unit, { viewing_side = viewing_side, ignore_units=yes } )
|
unit_reach = location_set.of_pairs(wesnoth.find_reach(unit, { viewing_side = viewing_side, ignore_units=yes } ))
|
||||||
unit.moves = real_moves
|
unit.moves = real_moves
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO: the radius expansion for "vision" and "attack" is way too slow
|
|
||||||
|
|
||||||
for j,loc in ipairs(reach) do
|
|
||||||
if wesnoth.match_location(loc[1], loc[2], location_filter) then
|
|
||||||
res:insert(loc[1], loc[2])
|
|
||||||
end
|
|
||||||
|
|
||||||
if range == "vision" or range == "attack" then
|
if range == "vision" or range == "attack" then
|
||||||
res:of_pairs(wesnoth.get_locations
|
unit_reach:to_wml_var "unit_reach_array"
|
||||||
{ { "filter_adjacent_location", { x=loc[1], y=loc[2] } },
|
reach:of_pairs(wesnoth.get_locations { find_in = "unit_reach_array", radius = "1" } )
|
||||||
{ "and", location_filter } })
|
unit_reach:of_wml_var "unit_reach_array"
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
res:to_wml_var(variable)
|
reach:union(unit_reach)
|
||||||
|
end
|
||||||
|
|
||||||
|
reach:to_wml_var(variable)
|
||||||
|
reach = location_set.of_pairs(wesnoth.get_locations { find_in = variable, { "and", location_filter } } )
|
||||||
|
reach:to_wml_var(variable)
|
||||||
|
|
||||||
|
wesnoth.set_variable("unit_reach_array")
|
||||||
end
|
end
|
||||||
|
|
||||||
function wml_actions.hide_unit(cfg)
|
function wml_actions.hide_unit(cfg)
|
||||||
|
|
Loading…
Add table
Reference in a new issue