From 7d5fa80180d0d748898f6841223b9ae7dc127f26 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Sat, 24 Dec 2022 10:52:57 -0500 Subject: [PATCH] WML: Adjust the weapon selection logic for [kill] (#7196) * WML: Adjust the weapon selection logic for [kill] The previous logic simply did not make sense, especially for the secondary weapon. For example, it would ignore the secondary weapon specification if the primary weapon was not found on the secondary unit, which does not make any sense. The cases that this changes are: - There is a secondary unit and a primary attack, but no matching attack was found. Previously it would use the default, now it pretends that attack exists. - There is a secondary attack specified, but no primary attack, either because it was unspecified or because it didn't match any attack on the secondary unit In both these cases, the animation runs as if a matching attack exists, rather than using no attack and choosing the default animation. Adjust the log level too. --- data/lua/wml/kill.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/data/lua/wml/kill.lua b/data/lua/wml/kill.lua index 41664073a9e..13046bf41ec 100644 --- a/data/lua/wml/kill.lua +++ b/data/lua/wml/kill.lua @@ -50,20 +50,28 @@ function wesnoth.wml_actions.kill(cfg) -- In other words, the attacker's weapon. The attacker is the secondary unit. -- In the victory animation, this is simply swapped. if primary then + local found_attack = nil if secondary_unit then - primary = secondary_unit:find_attack(primary) + found_attack = secondary_unit:find_attack(primary) + end + if found_attack then + primary = found_attack else primary = wesnoth.units.create_weapon(primary) end - wesnoth.log('err', "Primary weapon:\n" .. wml.tostring(primary.__cfg)) + wesnoth.log('info', "Primary weapon:\n" .. wml.tostring(primary.__cfg)) end if secondary then + local found_weapon = nil if primary then - secondary = unit:find_attack(secondary) + found_weapon = unit:find_attack(secondary) + end + if found_weapon then + secondary = found_weapon else secondary = wesnoth.units.create_weapon(secondary) end - wesnoth.log('err', "Secondary weapon:\n" .. wml.tostring(secondary.__cfg)) + wesnoth.log('info', "Secondary weapon:\n" .. wml.tostring(secondary.__cfg)) end anim:add(unit, "death", "kill", {primary = primary, secondary = secondary}) if secondary_unit then