mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 15:33:00 +00:00
maze3d: make paths more 'branchy'
This commit is contained in:
parent
dc65c721bd
commit
394f3ec4ef
1 changed files with 13 additions and 22 deletions
|
@ -22,7 +22,9 @@ end
|
||||||
start_time = os.clock()
|
start_time = os.clock()
|
||||||
|
|
||||||
function generate_maze3d(seed, width, height, depth)
|
function generate_maze3d(seed, width, height, depth)
|
||||||
-- print("Generating maze "..width.."x"..height.."x"..depth)
|
start_time = os.clock()
|
||||||
|
|
||||||
|
print("Generating maze "..width.."x"..height.."x"..depth)
|
||||||
math.randomseed(seed) -- seed the random number generator with the system clock
|
math.randomseed(seed) -- seed the random number generator with the system clock
|
||||||
|
|
||||||
width = width - 1
|
width = width - 1
|
||||||
|
@ -52,7 +54,6 @@ function generate_maze3d(seed, width, height, depth)
|
||||||
local directions = "" -- the different directions we can move in
|
local directions = "" -- the different directions we can move in
|
||||||
if cz - 2 > 0 and world[cz - 2][cy][cx] == "#" then
|
if cz - 2 > 0 and world[cz - 2][cy][cx] == "#" then
|
||||||
directions = directions .. "-"
|
directions = directions .. "-"
|
||||||
-- print("cz: "..cz..", cz - 2: "..(cz-2)..", here: '"..world[cz][cy][cx].."', there: '"..world[cz - 2][cy][cx].."'")
|
|
||||||
end
|
end
|
||||||
if cz + 2 < depth and world[cz + 2][cy][cx] == "#" then
|
if cz + 2 < depth and world[cz + 2][cy][cx] == "#" then
|
||||||
directions = directions .. "+"
|
directions = directions .. "+"
|
||||||
|
@ -70,17 +71,15 @@ function generate_maze3d(seed, width, height, depth)
|
||||||
directions = directions .. "r"
|
directions = directions .. "r"
|
||||||
end
|
end
|
||||||
|
|
||||||
-- print("Currently at ("..cx..", "..cy..", "..cz..") - directions: "..directions)
|
-- If this is 1 or less, then we will switch our attention to another candidate node after moving
|
||||||
|
local shift_attention = math.random(0, 3)
|
||||||
|
|
||||||
--print("radar output: '" .. directions .. "' (length: " .. #directions .. "), curnode: " .. curnode)
|
--print("radar output: '" .. directions .. "' (length: " .. #directions .. "), curnode: " .. curnode)
|
||||||
if #directions > 0 then
|
if #directions > 0 then
|
||||||
-- we still have somewhere that we can go
|
-- we still have somewhere that we can go
|
||||||
--print("This node is not a dead end yet.")
|
|
||||||
local curdirnum = math.random(1, #directions)
|
local curdirnum = math.random(1, #directions)
|
||||||
local curdir = string.sub(directions, curdirnum, curdirnum)
|
local curdir = string.sub(directions, curdirnum, curdirnum)
|
||||||
|
|
||||||
-- print("Picked direction '"..curdir.."' (index "..curdirnum..")")
|
|
||||||
|
|
||||||
if curdir == "+" then
|
if curdir == "+" then
|
||||||
world[cz + 1][cy][cx] = " "
|
world[cz + 1][cy][cx] = " "
|
||||||
world[cz + 2][cy][cx] = " "
|
world[cz + 2][cy][cx] = " "
|
||||||
|
@ -107,31 +106,23 @@ function generate_maze3d(seed, width, height, depth)
|
||||||
cx = cx + 2
|
cx = cx + 2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- print("Now at ("..cx..", "..cy..", "..cz..") ")
|
|
||||||
|
|
||||||
table.insert(nodes, { x = cx, y = cy, z = cz })
|
table.insert(nodes, { x = cx, y = cy, z = cz })
|
||||||
else
|
else
|
||||||
-- print("The node at " .. curnode .. " is a dead end.")
|
|
||||||
table.remove(nodes, curnode)
|
table.remove(nodes, curnode)
|
||||||
|
end
|
||||||
|
|
||||||
|
if #directions == 0 or shift_attention <= 1 then
|
||||||
if #nodes > 0 then
|
if #nodes > 0 then
|
||||||
--print("performing teleport.");
|
|
||||||
curnode = math.random(1, #nodes)
|
curnode = math.random(1, #nodes)
|
||||||
--print("New node: " .. curnode)
|
|
||||||
-- print("Nodes table: ")
|
|
||||||
-- print_r(nodes)
|
|
||||||
cx = nodes[curnode]["x"]
|
cx = nodes[curnode]["x"]
|
||||||
cy = nodes[curnode]["y"]
|
cy = nodes[curnode]["y"]
|
||||||
cz = nodes[curnode]["z"]
|
cz = nodes[curnode]["z"]
|
||||||
else
|
|
||||||
--print("Maze generation complete, no teleportation necessary.")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- io.read("*l")
|
end
|
||||||
-- print("\n\n\n\n\n\n\n\n\n")
|
|
||||||
-- printspace(world, width + 1, height + 1, depth + 1)
|
|
||||||
|
|
||||||
end
|
end_time = os.clock()
|
||||||
|
|
||||||
return world
|
return world
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue