Make fire spread direction truly random

This patch initializes the random number generator used in mcl_fire with
the current Unix timestamp. It also corrects two biases in fire spread
that were caused by nodes being iterated over in a predictable way.
This commit is contained in:
cora 2022-02-08 01:45:54 +01:00 committed by Nils Dagsson Moskopp
parent 6c2fb98160
commit ef7370550f
No known key found for this signature in database
GPG key ID: A3BC671C35191080

View file

@ -36,12 +36,14 @@ local adjacents = {
{ x = 0, y = 0, z = 1 }, { x = 0, y = 0, z = 1 },
} }
local function shuffle_adjacents() math.randomseed(os.time())
for i = #adjacents, 1, -1 do local function shuffle_table(t)
for i = #t, 1, -1 do
local r = math.random(i) local r = math.random(i)
adjacents[i], adjacents[r] = adjacents[r], adjacents[i] t[i], t[r] = t[r], t[i]
end end
end end
shuffle_table(adjacents)
local function has_flammable(pos) local function has_flammable(pos)
for k,v in pairs(adjacents) do for k,v in pairs(adjacents) do
@ -368,6 +370,7 @@ minetest.register_abm({
local function check_aircube(p1,p2) local function check_aircube(p1,p2)
local nds=minetest.find_nodes_in_area(p1,p2,{"air"}) local nds=minetest.find_nodes_in_area(p1,p2,{"air"})
shuffle_table(nds)
for k,v in pairs(nds) do for k,v in pairs(nds) do
if has_flammable(v) then return v end if has_flammable(v) then return v end
end end
@ -409,7 +412,7 @@ else -- Fire enabled
local p = get_ignitable(pos) local p = get_ignitable(pos)
if p then if p then
spawn_fire(p) spawn_fire(p)
shuffle_adjacents() shuffle_table(adjacents)
end end
end end
}) })