Fix [animate_unit][facing] not working.

This also tweaks the animator:add() API, replacing the facing key
with a target key and requiring it to be an adjacent location.
This commit is contained in:
Celtic Minstrel 2017-04-09 01:29:10 -04:00
parent e1a579da51
commit 7835e05d93
2 changed files with 8 additions and 3 deletions

View file

@ -78,6 +78,7 @@ local function add_animation(anim, cfg)
local facing_loc = wesnoth.get_locations(facing)[1]
if facing_loc then
local dir = wesnoth.map_location.get_relative_dir(unit.x, unit.y, facing_loc[1], facing_loc[2])
unit.facing = dir
facing = wesnoth.map_location.get_direction(unit.x, unit.y, dir)
else
facing = nil
@ -92,7 +93,7 @@ local function add_animation(anim, cfg)
end
anim:add(unit, cfg.flag, hits, {
facing = facing,
target = facing,
value = {tonumber(cfg.value) or 0, tonumber(cfg.value_second) or 0},
with_bars = not not cfg.with_bars,
text = text,

View file

@ -359,8 +359,12 @@ static int impl_add_animation(lua_State* L)
const_attack_ptr primary, secondary;
if(lua_istable(L, 5)) {
lua_getfield(L, 5, "facing");
if(!luaW_tolocation(L, -1, dest)) {
lua_getfield(L, 5, "target");
if(luaW_tolocation(L, -1, dest)) {
if(!tiles_adjacent(dest, u.get_location())) {
return luaL_argerror(L, -1, "target must be adjacent to the animated unit");
}
} else {
// luaW_tolocation may set the location to (0,0) if it fails
dest = map_location();
if(!lua_isnoneornil(L, -1)) {