diff --git a/changelog.md b/changelog.md index 99187f01b36..1f5e8ef1706 100644 --- a/changelog.md +++ b/changelog.md @@ -49,7 +49,7 @@ * New wesnoth.units.find gets units on either the map or any side's recall list. * Moved to interface module: wesnoth.scroll, wesnoth.zoom, wesnoth.get_mouseover_tile * wesnoth.interface.get_displayed_unit aliased to wesnoth.unit.get_hovered - * unit portrait is now writable + * unit portrait and recall_filter are now writable ### WML engine * Support upkeep in StandardUnitFilter * [effect]apply_to=variation now supports heal_full diff --git a/data/lua/wml/modify_unit.lua b/data/lua/wml/modify_unit.lua index 31d03e42b0a..2e63b6dd652 100644 --- a/data/lua/wml/modify_unit.lua +++ b/data/lua/wml/modify_unit.lua @@ -26,6 +26,7 @@ local function make_set(t) end local known_attributes = make_set { + "mode", "x", "y", "ai_special", @@ -69,6 +70,8 @@ local known_tags = make_set { "set_variable", -- todo: "set_variables", "clear_variable", + "filter_recall", + "variables", } local function is_simple(cfg) @@ -142,6 +145,7 @@ local function simple_modify_unit(cfg) end ---------- TAGS ---------- + bool found_recall = false, found_variables = false for i, t in ipairs(wml.shallow_parsed(cfg)) do local tagname, tagcontent = t[1], t[2] if tagname == "object" or tagname == "trait" or tagname == "advancement" then @@ -162,6 +166,12 @@ local function simple_modify_unit(cfg) for i, v in pairs(tagcontent) do u.status[i] = v end + elseif not found_recall and tagname == "filter_recall" then + u.recall_filter = wml.merge(u.recall_filter, tagcontent, cfg.mode or "merge") + found_recall = true -- Ignore all but the first + elseif not found_variables and tagname == "variables" then + u.variables.__cfg = wml.merge(u.variables.__cfg, tagcontent, cfg.mode or "merge") + found_variables = true -- Ignore all but the first elseif tagname == "set_variable" then wesnoth.wml_actions.set_variable(tagcontent, u.variables) elseif tagname == "clear_variable" then diff --git a/src/scripting/lua_common.hpp b/src/scripting/lua_common.hpp index 67be9e4d5de..d0150dd91ab 100644 --- a/src/scripting/lua_common.hpp +++ b/src/scripting/lua_common.hpp @@ -345,6 +345,15 @@ do { \ } \ } while(false) +#define modify_cfg_attrib(name, accessor) \ +do { \ + if (strcmp(m, (name)) == 0) { \ + const config& cfg = luaW_checkconfig(L, 3); \ + {accessor;} \ + return 0; \ + } \ +} while(false) + #define modify_vector_string_attrib(name, accessor) \ do { \ if (strcmp(m, (name)) == 0) { \ diff --git a/src/scripting/lua_unit.cpp b/src/scripting/lua_unit.cpp index 574ae591d9e..ca2f0038b3d 100644 --- a/src/scripting/lua_unit.cpp +++ b/src/scripting/lua_unit.cpp @@ -451,6 +451,7 @@ static int impl_unit_set(lua_State *L) modify_bool_attrib("zoc", u.set_emit_zoc(value)); modify_bool_attrib("canrecruit", u.set_can_recruit(value)); modify_bool_attrib("renamable", u.set_unrenamable(!value)); + modify_cfg_attrib("recall_filter", u.set_recall_filter(cfg)); modify_vector_string_attrib("extra_recruit", u.set_recruits(value)); modify_vector_string_attrib("advances_to", u.set_advances_to(value)); @@ -625,10 +626,7 @@ static int impl_unit_variables_set(lua_State *L) return luaL_argerror(L, 2, "unknown unit"); } char const *m = luaL_checkstring(L, 2); - if(strcmp(m, "__cfg") == 0) { - u->variables() = luaW_checkconfig(L, 3); - return 0; - } + modify_cfg_attrib("__cfg", u->variables() = cfg); config& vars = u->variables(); if(lua_isnoneornil(L, 3)) { try { diff --git a/src/units/unit.hpp b/src/units/unit.hpp index e0f5bc15546..f2d624e1e7f 100644 --- a/src/units/unit.hpp +++ b/src/units/unit.hpp @@ -625,6 +625,12 @@ public: return filter_recall_; } + /** Sets the filter constraints upon which units this unit may recall, if able. */ + void set_recall_filter(const config& filter) + { + filter_recall_ = filter; + } + /** * Gets this unit's role. *