Support as_type=unit in [variable]formula=

This commit is contained in:
Celtic Minstrel 2022-11-27 13:12:47 -05:00
parent 516f043e89
commit 6876695e66

View file

@ -25,6 +25,10 @@ local old_variable = wesnoth.wml_conditionals.variable
function wesnoth.wml_conditionals.variable(cfg) function wesnoth.wml_conditionals.variable(cfg)
if cfg.formula then if cfg.formula then
local value = wml.variables[cfg.name] local value = wml.variables[cfg.name]
if cfg.as_type == 'unit' then
value = wesnoth.units.create(value)
-- TODO: Consider supporting other types.
end
local result = wesnoth.eval_formula(cfg.formula, {value = value}) local result = wesnoth.eval_formula(cfg.formula, {value = value})
-- WFL considers 0 as false; Lua doesn't -- WFL considers 0 as false; Lua doesn't
if result == 0 then return false end if result == 0 then return false end