diff --git a/changelog b/changelog index ff8db29d94db1..9b39a84914f7d 100644 --- a/changelog +++ b/changelog @@ -21,6 +21,8 @@ Version 1.13.6+dev: * Existing keys made mutable: shroud, fog, flag, flag_icon * WML Engine: * Removed LOW_MEM option when building. + * New ability_type key in standard unit filters matches if the unit has any + ability of the specified type (tag name). Version 1.13.6: * AI: diff --git a/data/lua/wml-tags.lua b/data/lua/wml-tags.lua index 3a4f9bfe3c5f3..89de9831822d1 100644 --- a/data/lua/wml-tags.lua +++ b/data/lua/wml-tags.lua @@ -632,7 +632,67 @@ function wml_actions.unpetrify(cfg) end function wml_actions.heal_unit(cfg) - wesnoth.heal_unit(cfg) + local healers = helper.get_child("filter_second") + if healers then + healers = wesnoth.get_units{ + ability_type = "heals", + T["and"](healers) + } + else + healers = {} + end + + local who = helper.get_child("filter") + if who then + who = wesnoth.get_units(who) + else + who = wesnoth.get_units{ + x = wesnoth.current.event_context.x1, + y = wesnoth.current.event_context.y1 + } + end + + local heal_full = cfg.amount == "full" + local moves_full = cfg.moves == "full" + local heal_amount_set = false + for i,u in ipairs(who) do + local heal_amount = u.max_hitpoints - u.hitpoints + if heal_full then + u.hitpoints = u.max_hitpoints + else + heal_amount = math.min(math.max(1, cfg.amount), heal_amount) + u.hitpoints = u.hitpoints + heal_amount + end + + if moves_full then + u.moves = u.max_moves + else + u.moves = math.min(u.max_moves, u.moves + (cfg.moves or 0)) + end + + if cfg.restore_attacks then + u.attacks_left = u.max_attacks + end + + if cfg.restore_statuses then + u.status.poisoned = false + u.status.petrified = false + u.status.slowed = false + u.status.unhealable = false + end + + if ~heal_amount_set then + heal_amount_set = true + wesnoth.set_variable("heal_amount", heal_amount) + end + + if cfg.animate then + wesnoth.animate_unit{ + T.filter(healers), + flag = "healing" + } + end + end end function wml_actions.transform_unit(cfg) diff --git a/src/scripting/game_lua_kernel.cpp b/src/scripting/game_lua_kernel.cpp index ce1a0eb50fd96..f1656ccaea337 100644 --- a/src/scripting/game_lua_kernel.cpp +++ b/src/scripting/game_lua_kernel.cpp @@ -1795,6 +1795,7 @@ int game_lua_kernel::intf_find_cost_map(lua_State *L) int game_lua_kernel::intf_heal_unit(lua_State *L) { vconfig cfg(luaW_checkvconfig(L, 1)); + WRN_LUA << "wesnoth.heal_unit is deprecated\n"; const game_events::queued_event &event_info = get_event_info(); diff --git a/src/units/filter.cpp b/src/units/filter.cpp index 99bca5c6d244c..698d0622cc8fb 100644 --- a/src/units/filter.cpp +++ b/src/units/filter.cpp @@ -377,6 +377,19 @@ bool basic_unit_filter_impl::internal_matches_filter(const unit & u, const map_l if (!match) return false; } + if (!vcfg["ability_type"].empty()) + { + bool match = false; + + for (const std::string& ability : utils::split(vcfg["ability_type"])) { + if (u.has_ability_type(ability)) { + match = true; + break; + } + } + if (!match) return false; + } + if (!vcfg["race"].empty()) { std::vector races = utils::split(vcfg["race"]); if (std::find(races.begin(), races.end(), u.race()->id()) == races.end()) {