Improved variable setting in [heal_unit] and [harm_unit]

This commit is contained in:
Elvish_Hunter 2022-01-16 13:13:52 +01:00
parent 1456066d4d
commit 608a2bf85e
3 changed files with 7 additions and 5 deletions

View file

@ -70,6 +70,9 @@
* Tweaked margins around the main menu's bottom row.
* Difficulty no longer displayed in the Load Game dialog when it is not relevant to a save file (issue #5321)
### WML Engine
* `[heal_unit]` no longer sets the `heal_amount` variable.
* `[heal_unit]` now supports a `variable=` key.
* Added an `id` field to the items of the arrays generated by `[harm_unit]`.
### Miscellaneous and Bug Fixes
* Fixed: keyboard input during the loading screen intermittently caused a crash (issue #4447)
* AI: fixed custom synced commands not changing the game state

View file

@ -186,7 +186,7 @@ function wml_actions.harm_unit(cfg)
end
if variable then
wml.variables[string.format("%s[%d]", variable, index - 1)] = { harm_amount = damage }
wml.variables[string.format("%s[%d]", variable, index - 1)] = { id = unit_to_harm.id, harm_amount = damage }
end
-- both units may no longer be alive at this point, so double check

View file

@ -23,7 +23,7 @@ function wesnoth.wml_actions.heal_unit(cfg)
local heal_full = cfg.amount == "full" or cfg.amount == nil
local moves_full = cfg.moves == "full"
local heal_amount_set = false
local variable = cfg.variable
for i,u in ipairs(who) do
local heal_amount = u.max_hitpoints - u.hitpoints
local new_hitpoints
@ -65,9 +65,8 @@ function wesnoth.wml_actions.heal_unit(cfg)
u.status.unhealable = false
end
if not heal_amount_set then
heal_amount_set = true
wml.variables["heal_amount"] = heal_amount
if variable then
wml.variables[string.format("%s[%d]", variable, i-1)] = {id = u.id, heal_amount = heal_amount}
end
end
end