diff --git a/data/lua/core.lua b/data/lua/core.lua index f9d332c93be..844bf2fab8b 100644 --- a/data/lua/core.lua +++ b/data/lua/core.lua @@ -569,6 +569,12 @@ if wesnoth.kernel_type() == "Game Lua Kernel" then end end + function wesnoth.units.find_attack(unit, filter) + for i, atk in ipairs(unit.attacks) do + if atk:matches(filter) then return atk end + end + end + -- gets map and recalllist units. function wesnoth.units.find(filter) local res = wesnoth.units.find_on_map(filter) diff --git a/data/lua/helper.lua b/data/lua/helper.lua index 86cb638c3c6..65ab83a0345 100644 --- a/data/lua/helper.lua +++ b/data/lua/helper.lua @@ -201,12 +201,6 @@ function helper.shuffle( t, random_func ) end end -function helper.find_attack(unit, filter) - for i, atk in ipairs(unit.attacks) do - if atk:matches(filter) then return atk end - end -end - -- Compatibility and deprecations helper.distance_between = wesnoth.deprecate_api('helper.distance_between', 'wesnoth.map.distance_between', 1, nil, wesnoth.map.distance_between) helper.get_child = wesnoth.deprecate_api('helper.get_child', 'wml.get_child', 1, nil, wml.get_child) @@ -221,6 +215,7 @@ if wesnoth.kernel_type() == "Game Lua Kernel" then helper.wml_error = wesnoth.deprecate_api('helper.wml_error', 'wml.error', 1, nil, wml.error) helper.move_unit_fake = wesnoth.deprecate_api('helper.move_unit_fake', 'wesnoth.interface.move_unit_fake', 1, nil, wesnoth.interface.move_unit_fake) helper.modify_unit = wesnoth.deprecate_api('helper.modify_unit', 'wesnoth.units.modify', 1, nil, wesnoth.units.modify) + helper.find_attack = wesnoth.deprecate_api('helper.find_attack', 'wesnoth.units.find_attack', 1, nil, wesnoth.units.find_attack) end helper.literal = wesnoth.deprecate_api('helper.literal', 'wml.literal', 1, nil, wml.literal) helper.parsed = wesnoth.deprecate_api('helper.parsed', 'wml.parsed', 1, nil, wml.parsed) diff --git a/data/lua/wml/animate_unit.lua b/data/lua/wml/animate_unit.lua index 04b97c97f2c..f8eb7bc0104 100644 --- a/data/lua/wml/animate_unit.lua +++ b/data/lua/wml/animate_unit.lua @@ -38,11 +38,11 @@ local function add_animation(anim, cfg) primary = wesnoth.create_weapon(primary) end if secondary then - secondary = helper.find_attack(unit, secondary) + secondary = unit:find_attack(secondary) end else if primary then - primary = helper.find_attack(unit, primary) + primary = unit:find_attack(primary) end if secondary then secondary = wesnoth.create_weapon(secondary) diff --git a/data/lua/wml/kill.lua b/data/lua/wml/kill.lua index 323d863ffa7..8df3cabffde 100644 --- a/data/lua/wml/kill.lua +++ b/data/lua/wml/kill.lua @@ -52,7 +52,7 @@ function wesnoth.wml_actions.kill(cfg) -- In the victory animation, this is simply swapped. if primary then if secondary_unit then - primary = helper.find_attack(secondary_unit, primary) + primary = secondary_unit:find_attack(primary) else primary = wesnoth.create_weapon(primary) end @@ -60,7 +60,7 @@ function wesnoth.wml_actions.kill(cfg) end if secondary then if primary then - secondary = helper.find_attack(unit, secondary) + secondary = unit:find_attack(secondary) else secondary = wesnoth.create_weapon(secondary) end