mirror of
https://git.minetest.land/Mineclonia/Mineclonia.git
synced 2024-11-27 09:32:59 +00:00
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:
parent
6c2fb98160
commit
ef7370550f
1 changed files with 7 additions and 4 deletions
|
@ -36,12 +36,14 @@ local adjacents = {
|
|||
{ x = 0, y = 0, z = 1 },
|
||||
}
|
||||
|
||||
local function shuffle_adjacents()
|
||||
for i = #adjacents, 1, -1 do
|
||||
math.randomseed(os.time())
|
||||
local function shuffle_table(t)
|
||||
for i = #t, 1, -1 do
|
||||
local r = math.random(i)
|
||||
adjacents[i], adjacents[r] = adjacents[r], adjacents[i]
|
||||
t[i], t[r] = t[r], t[i]
|
||||
end
|
||||
end
|
||||
shuffle_table(adjacents)
|
||||
|
||||
local function has_flammable(pos)
|
||||
for k,v in pairs(adjacents) do
|
||||
|
@ -368,6 +370,7 @@ minetest.register_abm({
|
|||
|
||||
local function check_aircube(p1,p2)
|
||||
local nds=minetest.find_nodes_in_area(p1,p2,{"air"})
|
||||
shuffle_table(nds)
|
||||
for k,v in pairs(nds) do
|
||||
if has_flammable(v) then return v end
|
||||
end
|
||||
|
@ -409,7 +412,7 @@ else -- Fire enabled
|
|||
local p = get_ignitable(pos)
|
||||
if p then
|
||||
spawn_fire(p)
|
||||
shuffle_adjacents()
|
||||
shuffle_table(adjacents)
|
||||
end
|
||||
end
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue