Wear spacesuit accounting for server lag

This makes spacesuit wear independent from server lag. The timer
between updates should average one second. If it is more,
multiplying by the timer value increases wear as if an update had
happened at every additional step (except the wear value would be
rounded to an integer between 0 and 65535 every time).

Because the real average is slightly higher than one second,
multiplying by the timer value decreases how long the spacesuit
lasts. With one additional step per update and steps of
0.034 seconds (the average time I get in singleplayer), that means
2 or 3 additional wear. So I also decrease armor_use to 70, which
restores the spacesuit to lasting as long as before or slightly
longer.

Also, this allows increasing the minimum timer value to two seconds
or more without needing to change the armor_use value.
This commit is contained in:
coil
2019-06-11 14:23:23 -04:00
parent 4b3b497089
commit 4e3d5ac072
2 changed files with 7 additions and 7 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ minetest.register_globalstep(function(dtime)
for i, stack in pairs(armor_inv:get_list("armor")) do for i, stack in pairs(armor_inv:get_list("armor")) do
if not stack:is_empty() then if not stack:is_empty() then
local name = stack:get_name() local name = stack:get_name()
local use = minetest.get_item_group(name, "armor_use") or 0 local use = minetest.get_item_group(name, "armor_use") * timer or 0
armor:damage(player, i, stack, use) armor:damage(player, i, stack, use)
end end
end end
+1 -1
View File
@@ -1,6 +1,6 @@
spacesuit = { spacesuit = {
armor_use = tonumber(minetest.settings:get("spacesuit.armor_use")) or 75, armor_use = tonumber(minetest.settings:get("spacesuit.armor_use")) or 70,
} }