Update search_surrounding algorithm

This commit is contained in:
tacigar 2016-12-24 10:20:59 +09:00
parent 8ab37c1ce6
commit 0080b81e97

View File

@ -6,12 +6,45 @@
maidroid_core._aux = {} maidroid_core._aux = {}
function maidroid_core._aux.search_surrounding(pos, pred, searching_range) function maidroid_core._aux.search_surrounding(pos, pred, searching_range)
for x = -searching_range.x, searching_range.x do pos = vector.round(pos)
for y = -searching_range.y, searching_range.y do local max_xz = math.max(searching_range.x, searching_range.z)
for z = -searching_range.z, searching_range.z do
local p = vector.add(pos, {x = x, y = y, z = z}) for j = -searching_range.y, searching_range.y do
if pred(p) then local p = vector.add({x = 0, y = j, z = 0}, pos)
return p if pred(p) then
return p
end
end
for i = 0, max_xz do
for j = -searching_range.y, searching_range.y do
for k = -i, i do
if searching_range.x >= k and searching_range.z >= i then
local p = vector.add({x = k, y = j, z = i}, pos)
if pred(p) then
return p
end
p = vector.add({x = k, y = j, z = -i}, pos)
if pred(p) then
return p
end
end
if searching_range.z >= i and searching_range.z >= k then
if i ~= k then
local p = vector.add({x = i, y = j, z = k}, pos)
if pred(p) then
return p
end
end
if -i ~= k then
local p = vector.add({x = -i, y = j, z = k}, pos)
if pred(p) then
return p
end
end
end end
end end
end end