2019-01-06 12:02:37 -05:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2019-08-31 09:26:53 -04:00
|
|
|
local ipairs, math, minetest, nodecore, pairs, table
|
|
|
|
= ipairs, math, minetest, nodecore, pairs, table
|
2019-01-06 12:02:37 -05:00
|
|
|
local math_random, table_insert
|
|
|
|
= math.random, table.insert
|
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
|
|
|
local dirs = nodecore.dirs()
|
|
|
|
|
|
|
|
function nodecore.scan_flood(pos, range, func)
|
|
|
|
local q = {pos}
|
2019-12-01 11:08:12 -05:00
|
|
|
local seen = {}
|
2019-01-06 12:02:37 -05:00
|
|
|
for d = 0, range do
|
2019-08-31 09:26:53 -04:00
|
|
|
local nxt = {}
|
|
|
|
for _, p in ipairs(q) do
|
2019-01-06 19:23:18 -05:00
|
|
|
local res = func(p, d)
|
2019-01-06 12:02:37 -05:00
|
|
|
if res then return res end
|
|
|
|
if res == nil then
|
2019-08-31 09:26:53 -04:00
|
|
|
for _, v in pairs(dirs) do
|
2019-01-06 12:02:37 -05:00
|
|
|
local np = {
|
|
|
|
x = p.x + v.x,
|
|
|
|
y = p.y + v.y,
|
2020-06-17 00:54:21 -04:00
|
|
|
z = p.z + v.z,
|
|
|
|
prev = p
|
2019-01-06 12:02:37 -05:00
|
|
|
}
|
|
|
|
local nk = minetest.hash_node_position(np)
|
|
|
|
if not seen[nk] then
|
|
|
|
seen[nk] = true
|
|
|
|
np.dir = v
|
2019-08-31 09:26:53 -04:00
|
|
|
table_insert(nxt, np)
|
2019-01-06 12:02:37 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-08-31 09:26:53 -04:00
|
|
|
if #nxt < 1 then break end
|
|
|
|
for i = 1, #nxt do
|
|
|
|
local j = math_random(1, #nxt)
|
|
|
|
nxt[i], nxt[j] = nxt[j], nxt[i]
|
2019-01-06 12:02:37 -05:00
|
|
|
end
|
2019-08-31 09:26:53 -04:00
|
|
|
q = nxt
|
2019-01-06 12:02:37 -05:00
|
|
|
end
|
|
|
|
end
|