Support [set_variable]round=trunc

(cherry-picked from commit beb5dc75aa)
This commit is contained in:
Celtic Minstrel 2018-03-30 12:51:18 -04:00
parent 6c068684d6
commit 52d3b7bb6a

View file

@ -70,6 +70,11 @@ function wesnoth.wml_actions.set_variable(cfg)
wesnoth.set_variable(name, math.ceil(var))
elseif round_val == "floor" then
wesnoth.set_variable(name, math.floor(var))
elseif round_val == "trunc" then
-- Storing to a variable first because modf returns two values,
-- and I'm not sure if set_variable will complain about the extra parameter
local new_val = math.modf(var)
wesnoth.set_variable(name, new_val)
else
local decimals = math.modf(tonumber(round_val) or 0)
local value = var * (10 ^ decimals)