Rewrite helper.move_unit_fake to not use a WML variable
This commit is contained in:
parent
d732ef00c2
commit
40bf04ec8e
1 changed files with 15 additions and 28 deletions
|
@ -60,43 +60,30 @@ end
|
||||||
--! Fakes the move of a unit satisfying the given @a filter to position @a x, @a y.
|
--! Fakes the move of a unit satisfying the given @a filter to position @a x, @a y.
|
||||||
--! @note Usable only during WML actions.
|
--! @note Usable only during WML actions.
|
||||||
function helper.move_unit_fake(filter, to_x, to_y)
|
function helper.move_unit_fake(filter, to_x, to_y)
|
||||||
wml_actions.store_unit({
|
local moving_unit = wesnoth.get_units(filter)[1]
|
||||||
[1] = { "filter", filter },
|
local from_x, from_y = moving_unit.x, moving_unit.y
|
||||||
variable = "LUA_move_unit",
|
|
||||||
kill = false
|
|
||||||
})
|
|
||||||
local from_x = wml.variables["LUA_move_unit.x"]
|
|
||||||
local from_y = wml.variables["LUA_move_unit.y"]
|
|
||||||
|
|
||||||
wml_actions.scroll_to({ x=from_x, y=from_y })
|
wesnoth.intf.scroll_to_hex(from_x, from_y)
|
||||||
|
to_x, to_y = wesnoth.find_vacant_tile(x, y, moving_unit)
|
||||||
|
|
||||||
if to_x < from_x then
|
if to_x < from_x then
|
||||||
wml.variables["LUA_move_unit.facing"] = "sw"
|
moving_unit.facing = "sw"
|
||||||
elseif to_x > from_x then
|
elseif to_x > from_x then
|
||||||
wml.variables["LUA_move_unit.facing"] = "se"
|
moving_unit.facing = "se"
|
||||||
end
|
end
|
||||||
wml.variables["LUA_move_unit.x"] = to_x
|
moving_unit:extract()
|
||||||
wml.variables["LUA_move_unit.y"] = to_y
|
|
||||||
|
|
||||||
wml_actions.kill({
|
wml_actions.move_unit_fake{
|
||||||
x = from_x,
|
type = moving_unit.type,
|
||||||
y = from_y,
|
gender = moving_unit.gender,
|
||||||
animate = false,
|
variation = moving.variation,
|
||||||
fire_event = false
|
side = moving_unit.side,
|
||||||
})
|
|
||||||
|
|
||||||
wml_actions.move_unit_fake({
|
|
||||||
type = "$LUA_move_unit.type",
|
|
||||||
gender = "$LUA_move_unit.gender",
|
|
||||||
variation = "$LUA_move_unit.variation",
|
|
||||||
side = "$LUA_move_unit.side",
|
|
||||||
x = from_x .. ',' .. to_x,
|
x = from_x .. ',' .. to_x,
|
||||||
y = from_y .. ',' .. to_y
|
y = from_y .. ',' .. to_y
|
||||||
})
|
}
|
||||||
|
|
||||||
wml_actions.unstore_unit({ variable="LUA_move_unit", find_vacant=true })
|
moving_unit:to_map(to_x, to_y)
|
||||||
wml_actions.redraw({})
|
wml_actions.redraw{}
|
||||||
wml.variables["LUA_move_unit"] = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Metatable that redirects access to wml.variables_proxy
|
-- Metatable that redirects access to wml.variables_proxy
|
||||||
|
|
Loading…
Add table
Reference in a new issue