1
0
mirror of git://repo.or.cz/minetest_mana.git synced 2024-11-15 23:00:20 +01:00

Round input values

This commit is contained in:
Wuzzy 2015-02-20 15:19:57 +01:00
parent d400f20c55
commit 9921ba24cc

View File

@ -44,6 +44,7 @@ function mana.set(playername, value)
minetest.log("info", "[mana] Warning: mana.set was called with negative value!")
value = 0
end
value = mana.round(value)
if value > mana.playerlist[playername].maxmana then
value = mana.playerlist[playername].maxmana
end
@ -58,6 +59,7 @@ function mana.setmax(playername, value)
value = 0
minetest.log("info", "[mana] Warning: mana.setmax was called with negative value!")
end
value = mana.round(value)
if mana.playerlist[playername].maxmana ~= value then
mana.playerlist[playername].maxmana = value
if(mana.playerlist[playername].mana > value) then
@ -72,6 +74,7 @@ function mana.setregen(playername, value)
value = 0
minetest.log("info", "[mana] Warning: mana.setregen was called with negative value!")
end
value = mana.round(value)
mana.playerlist[playername].regen = value
end
@ -89,6 +92,7 @@ end
function mana.add_up_to(playername, value)
local t = mana.playerlist[playername]
value = mana.round(value)
if(t ~= nil and value >= 0) then
local excess
if((t.mana + value) > t.maxmana) then
@ -107,6 +111,7 @@ end
function mana.add(playername, value)
local t = mana.playerlist[playername]
value = mana.round(value)
if(t ~= nil and ((t.mana + value) <= t.maxmana) and value >= 0) then
t.mana = t.mana + value
mana.hud_update(playername)
@ -118,6 +123,7 @@ end
function mana.subtract(playername, value)
local t = mana.playerlist[playername]
value = mana.round(value)
if(t ~= nil and t.mana >= value and value >= 0) then
t.mana = t.mana -value
mana.hud_update(playername)
@ -129,6 +135,7 @@ end
function mana.subtract_up_to(playername, value)
local t = mana.playerlist[playername]
value = mana.round(value)
if(t ~= nil and value >= 0) then
local missing
if((t.mana - value) < 0) then
@ -291,3 +298,10 @@ else
player:hud_remove(mana.playerlist[playername].hudid)
end
end
--[===[
Helper functions
]===]
mana.round = function(x)
return math.ceil(math.floor(x+0.5))
end