Accept [effect] in [modify_unit]

This commit is contained in:
Celtic Minstrel 2016-08-02 00:01:48 -04:00
parent 7e6a1892bb
commit 6dab777f66
4 changed files with 22 additions and 0 deletions

View file

@ -15,6 +15,9 @@ Version 1.13.5+dev:
- [else] sub-tag, WML to execute if no unit found for the role
* New help_text= key for [trait] to set the description displayed in the help.
* Added tag id= [fire_event], which allows raising events by id
* [modify_unit] now understands [effect] tags, which it applies directly.
This replaces the use of [object] with no_write=yes (which will be removed
in the next release).
* Lua API:
* Added new functions wesnoth.fire_event_by_id and fire_event_by_name. The old
function wesnoth.fire_event is now an alias for wesnoth.fire_event_by_name

View file

@ -51,6 +51,18 @@ function wml_actions.modify_unit(cfg)
wesnoth.add_modification(unit, current_tag, mod)
unit = unit.__cfg;
wesnoth.set_variable(unit_path, unit)
elseif current_tag == "effect" then
local mod = current_table[2]
local apply_to = mod.apply_to
if wesnoth.effects[apply_to] then
local unit = wesnoth.get_variable(unit_path)
unit = wesnoth.create_unit(unit)
wesnoth.effects[apply_to](unit, mod)
unit = unit.__cfg;
wesnoth.set_variable(unit_path, unit)
else
helper.wml_error("[modify_unit] had invalid [effect]apply_to value")
end
else
local tag_index = children_handled[current_tag] or 0
handle_child(current_table[2], string.format("%s.%s[%u]",

View file

@ -27,6 +27,10 @@ function wml_actions.object(cfg)
text = tostring(cfg.description or "")
command_type = "then"
if cfg.no_write ~= nil then
wesnoth.log("wml", "[object]no_write=yes is deprecated in favour of placing [effect] tags in [modify_unit]")
end
local dvs = cfg.delayed_variable_substitution
local add = cfg.no_write ~= true
if dvs then

View file

@ -3613,6 +3613,9 @@ static int intf_add_modification(lua_State *L)
if (!lua_isnone(L, 4)) {
write_to_mods = luaW_toboolean(L, 4);
}
if(sm.empty()) {
write_to_mods = false;
}
config cfg = luaW_checkconfig(L, 3);
u.add_modification(sm, cfg, !write_to_mods);