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.
This commit is contained in:
Celtic Minstrel 2022-12-24 10:52:57 -05:00 committed by GitHub
parent c8701e2ef5
commit 7d5fa80180
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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