Skip to content

Commit

Permalink
Allow [move_unit]to_location to take a list of waypoints
Browse files Browse the repository at this point in the history
(cherry-picked from commit 622db9d)
  • Loading branch information
CelticMinstrel committed Oct 7, 2018
1 parent 9686d20 commit 4ce00c6
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions data/lua/wml/move_unit.lua
@@ -1,15 +1,32 @@
local helper = wesnoth.require "helper"
local utils = wesnoth.require "wml-utils"

local function path_locs(path)
if path.location_id then
-- Index is 1 for x, 2 for y
local function special_locations(index)
return function()
for loc in utils.split(path.location_id) do
loc = wesnoth.special_locations[loc]
if loc then coroutine.yield(loc[index]) end
end
end
end
return coroutine.wrap(special_locations(1)), coroutine.wrap(special_locations(2))
else
return utils.split(path.to_x), utils.split(path.to_y)
end
end

function wesnoth.wml_actions.move_unit(cfg)
local coordinate_error = "invalid location in [move_unit]"
local to_x, to_y
if cfg.to_location and wesnoth.special_locations[cfg.to_location] then
to_x, to_y = table.unpack(wesnoth.special_locations[cfg.to_location])
local path
if cfg.to_location then
path = {location_id = cfg.to_location}
else
to_x = cfg.to_x
to_y = cfg.to_y
path = {to_x = cfg.to_x, to_y = cfg.to_y}
end
if not to_x or not to_y then
if not path then
helper.wml_error(coordinate_error)
end
local fire_event = cfg.fire_event
Expand All @@ -20,10 +37,9 @@ function wesnoth.wml_actions.move_unit(cfg)
cfg.to_location, cfg.to_x, cfg.to_y, cfg.fire_event = nil
local units = wesnoth.get_units(cfg)

local pattern = "[^%s,]+"
for current_unit_index, current_unit in ipairs(units) do
if not fire_event or current_unit.valid then
local xs, ys = string.gmatch(to_x, pattern), string.gmatch(to_y, pattern)
local xs, ys = path_locs(path)
local move_string_x = current_unit.x
local move_string_y = current_unit.y
local pass_check = nil
Expand Down

0 comments on commit 4ce00c6

Please sign in to comment.