Track tree-growth while player is distant.

As long as the game clock is running, even if the area is not
loaded and processing ABMs, tree growth will "catch up" when the
area gets loaded.

I was hoping to build a time-integrated "soaking API" to deal with
this and short-circuit the box-mueller calculation to do model the
soak as time-continuous in O(1) time, but this is good enough to
get the expected behavior for now.

If I add more long-term time-integrated stochastic processes (i.e.
not just cooking recipes) then I can do the refac at that time.
This commit is contained in:
Aaron Suen 2019-08-31 10:27:29 -04:00
parent 442a6f89ef
commit 859b70fab5

View File

@ -116,7 +116,13 @@ nodecore.register_limited_abm({
minsize = 1,
maxsize = 3,
})
local g = (meta:get_float("growth") or 0) + rate * math_random()
local g = meta:get_float("growth") or 0
local now = minetest.get_gametime()
local t = meta:get_float("start") or now
while t <= now do
g = g + rate * math_random()
t = t + 10
end
if g >= 5000 then
meta:from_table({})
local place = {x = pos.x - 2, y = pos.y, z = pos.z - 2}
@ -124,5 +130,6 @@ nodecore.register_limited_abm({
"random", {}, false)
end
meta:set_float("growth", g)
meta:set_float("start", t)
end
})