Add a few more tags to the [modify_unit] optimized path

This commit is contained in:
Celtic Minstrel 2019-11-16 15:12:28 -05:00
parent 1f36590e80
commit cd6283f8db
5 changed files with 28 additions and 5 deletions

View file

@ -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

View file

@ -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

View file

@ -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) { \

View file

@ -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 {

View file

@ -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.
*