mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 23:42:59 +00:00
Patch maze3d to support the path dimennsion settings, but there's some weirdness going on
This commit is contained in:
parent
2720f62d09
commit
29223a3455
2 changed files with 91 additions and 42 deletions
|
@ -21,15 +21,15 @@ end
|
||||||
-- Initialise the world
|
-- Initialise the world
|
||||||
start_time = os.clock()
|
start_time = os.clock()
|
||||||
|
|
||||||
function generate_maze3d(seed, width, height, depth)
|
local function generate_maze3d(seed, width, height, depth, path_length, path_width, path_depth)
|
||||||
start_time = os.clock()
|
|
||||||
|
|
||||||
print("Generating maze "..width.."x"..height.."x"..depth)
|
if not path_length then path_length = 2 end
|
||||||
|
if not path_width then path_width = 1 end
|
||||||
|
if not path_depth then path_depth = 1 end
|
||||||
|
|
||||||
|
-- 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
|
|
||||||
height = height - 1
|
|
||||||
|
|
||||||
local world = {}
|
local world = {}
|
||||||
for z = 0, depth, 1 do
|
for z = 0, depth, 1 do
|
||||||
world[z] = {}
|
world[z] = {}
|
||||||
|
@ -52,22 +52,22 @@ function generate_maze3d(seed, width, height, depth)
|
||||||
--print("Nodes left: " .. #nodes)
|
--print("Nodes left: " .. #nodes)
|
||||||
|
|
||||||
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 - path_length > 0 and world[cz - path_length][cy][cx] == "#" then
|
||||||
directions = directions .. "-"
|
directions = directions .. "-"
|
||||||
end
|
end
|
||||||
if cz + 2 < depth and world[cz + 2][cy][cx] == "#" then
|
if cz + path_length < depth-path_depth and world[cz + path_length][cy][cx] == "#" then
|
||||||
directions = directions .. "+"
|
directions = directions .. "+"
|
||||||
end
|
end
|
||||||
if cy - 2 > 0 and world[cz][cy - 2][cx] == "#" then
|
if cy - path_length > 0 and world[cz][cy - path_length][cx] == "#" then
|
||||||
directions = directions .. "u"
|
directions = directions .. "u"
|
||||||
end
|
end
|
||||||
if cy + 2 < height and world[cz][cy + 2][cx] == "#" then
|
if cy + path_length < height-path_width and world[cz][cy + path_length][cx] == "#" then
|
||||||
directions = directions .. "d"
|
directions = directions .. "d"
|
||||||
end
|
end
|
||||||
if cx - 2 > 0 and world[cz][cy][cx - 2] == "#" then
|
if cx - path_length > 0 and world[cz][cy][cx - path_length] == "#" then
|
||||||
directions = directions .. "l"
|
directions = directions .. "l"
|
||||||
end
|
end
|
||||||
if cx + 2 < width and world[cz][cy][cx + 2] == "#" then
|
if cx + path_length < width-path_width and world[cz][cy][cx + path_length] == "#" then
|
||||||
directions = directions .. "r"
|
directions = directions .. "r"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -80,30 +80,73 @@ function generate_maze3d(seed, width, height, depth)
|
||||||
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)
|
||||||
|
|
||||||
|
|
||||||
if curdir == "+" then
|
if curdir == "+" then
|
||||||
world[cz + 1][cy][cx] = " "
|
for iz = cz,cz+path_length+(path_depth-1) do
|
||||||
world[cz + 2][cy][cx] = " "
|
for ix = cx,cx+(path_width-1) do
|
||||||
cz = cz + 2
|
for iy = cy,cy+(path_width-1) do
|
||||||
|
world[iz][iy][ix] = " "
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- world[cz + 1][cy][cx] = " "
|
||||||
|
-- world[cz + 2][cy][cx] = " "
|
||||||
|
cz = cz + path_length
|
||||||
elseif curdir == "-" then
|
elseif curdir == "-" then
|
||||||
world[cz - 1][cy][cx] = " "
|
for iz = cz,cz-path_length do
|
||||||
world[cz - 2][cy][cx] = " "
|
for ix = cx,cx+(path_width-1) do
|
||||||
cz = cz - 2
|
for iy = cy,cy+(path_width-1) do
|
||||||
|
world[iz][iy][ix] = " "
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- world[cz - 1][cy][cx] = " "
|
||||||
|
-- world[cz - 2][cy][cx] = " "
|
||||||
|
cz = cz - path_length
|
||||||
elseif curdir == "u" then
|
elseif curdir == "u" then
|
||||||
world[cz][cy - 1][cx] = " "
|
for iz = cz,cz+(path_depth-1) do
|
||||||
world[cz][cy - 2][cx] = " "
|
for ix = cx,cx+(path_width-1) do
|
||||||
cy = cy - 2
|
for iy = cy-path_length,cy do
|
||||||
|
world[iz][iy][ix] = " "
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- world[cz][cy - 1][cx] = " "
|
||||||
|
-- world[cz][cy - 2][cx] = " "
|
||||||
|
cy = cy - path_length
|
||||||
elseif curdir == "d" then
|
elseif curdir == "d" then
|
||||||
world[cz][cy + 1][cx] = " "
|
for iz = cz,cz+(path_depth-1) do
|
||||||
world[cz][cy + 2][cx] = " "
|
for ix = cx,cx+(path_width-1) do
|
||||||
cy = cy + 2
|
for iy = cy,cy+path_length+(path_width-1) do
|
||||||
|
world[iz][iy][ix] = " "
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- world[cz][cy + 1][cx] = " "
|
||||||
|
-- world[cz][cy + 2][cx] = " "
|
||||||
|
cy = cy + path_length
|
||||||
elseif curdir == "l" then
|
elseif curdir == "l" then
|
||||||
world[cz][cy][cx - 1] = " "
|
for iz = cz,cz+(path_depth-1) do
|
||||||
world[cz][cy][cx - 2] = " "
|
for iy = cy,cy+(path_width-1) do
|
||||||
cx = cx - 2
|
for ix = cx-path_length,cx do
|
||||||
|
world[iz][iy][ix] = " "
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- world[cz][cy][cx - 1] = " "
|
||||||
|
-- world[cz][cy][cx - 2] = " "
|
||||||
|
cx = cx - path_length
|
||||||
elseif curdir == "r" then
|
elseif curdir == "r" then
|
||||||
world[cz][cy][cx + 1] = " "
|
for iz = cz,cz+(path_depth-1) do
|
||||||
world[cz][cy][cx + 2] = " "
|
for iy = cy,cy+(path_width-1) do
|
||||||
cx = cx + 2
|
for ix = cx,cx+path_length+(path_width-1) do
|
||||||
|
world[iz][iy][ix] = " "
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- world[cz][cy][cx + 1] = " "
|
||||||
|
-- world[cz][cy][cx + 2] = " "
|
||||||
|
cx = cx + path_length
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(nodes, { x = cx, y = cy, z = cz })
|
table.insert(nodes, { x = cx, y = cy, z = cz })
|
||||||
|
@ -122,14 +165,12 @@ function generate_maze3d(seed, width, height, depth)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end_time = os.clock()
|
|
||||||
|
|
||||||
return world
|
return world
|
||||||
end
|
end
|
||||||
|
|
||||||
-- local world = maze(os.time(), width, height)
|
-- local world = maze(os.time(), width, height)
|
||||||
|
|
||||||
function worldedit.maze3d(pos1, pos2, target_node, seed)
|
function worldeditadditions.maze3d(pos1, pos2, target_node, seed, path_length, path_width, path_depth)
|
||||||
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
-- pos2 will always have the highest co-ordinates now
|
-- pos2 will always have the highest co-ordinates now
|
||||||
|
|
||||||
|
@ -159,7 +200,7 @@ function worldedit.maze3d(pos1, pos2, target_node, seed)
|
||||||
|
|
||||||
minetest.log("action", "Generating "..extent.x.."x"..extent.z.."x"..extent.z.." 3d maze from pos1 " .. worldeditadditions.vector.tostring(pos1).." to pos2 "..worldeditadditions.vector.tostring(pos2))
|
minetest.log("action", "Generating "..extent.x.."x"..extent.z.."x"..extent.z.." 3d maze from pos1 " .. worldeditadditions.vector.tostring(pos1).." to pos2 "..worldeditadditions.vector.tostring(pos2))
|
||||||
|
|
||||||
local maze = generate_maze3d(seed, extent.z, extent.y, extent.x) -- x & need to be the opposite way around to how we index it
|
local maze = generate_maze3d(seed, extent.z, extent.y, extent.x, path_length, path_width, path_depth) -- x & z need to be the opposite way around to how we index it
|
||||||
-- printspace3d(maze, extent.z, extent.y, extent.x)
|
-- printspace3d(maze, extent.z, extent.y, extent.x)
|
||||||
|
|
||||||
-- z y x is the preferred loop order, but that isn't really possible here
|
-- z y x is the preferred loop order, but that isn't really possible here
|
||||||
|
|
|
@ -6,7 +6,7 @@ local we_c = worldeditadditions_commands
|
||||||
-- ██ ██ ██ ██ ██ ███ ██
|
-- ██ ██ ██ ██ ██ ███ ██
|
||||||
-- ██ ██ ██ ██ ███████ ███████
|
-- ██ ██ ██ ██ ███████ ███████
|
||||||
|
|
||||||
local function parse_params_maze(params_text)
|
local function parse_params_maze(params_text, is_3d)
|
||||||
if not params_text then
|
if not params_text then
|
||||||
return nil, nil, nil, nil
|
return nil, nil, nil, nil
|
||||||
end
|
end
|
||||||
|
@ -17,6 +17,11 @@ local function parse_params_maze(params_text)
|
||||||
local seed = os.time()
|
local seed = os.time()
|
||||||
local path_length = 2
|
local path_length = 2
|
||||||
local path_width = 1
|
local path_width = 1
|
||||||
|
local path_depth = 1
|
||||||
|
|
||||||
|
local param_index_seed = 4
|
||||||
|
if is_3d then param_index_seed = 5 end
|
||||||
|
|
||||||
|
|
||||||
if #parts >= 2 then
|
if #parts >= 2 then
|
||||||
path_length = tonumber(parts[2])
|
path_length = tonumber(parts[2])
|
||||||
|
@ -24,13 +29,16 @@ local function parse_params_maze(params_text)
|
||||||
if #parts >= 3 then
|
if #parts >= 3 then
|
||||||
path_width = tonumber(parts[3])
|
path_width = tonumber(parts[3])
|
||||||
end
|
end
|
||||||
if #parts >= 4 then
|
if #parts >= 4 and is_3d then
|
||||||
seed = tonumber(parts[4])
|
path_depth = tonumber(parts[4])
|
||||||
|
end
|
||||||
|
if #parts >= param_index_seed then
|
||||||
|
seed = tonumber(parts[param_index_seed])
|
||||||
end
|
end
|
||||||
|
|
||||||
replace_node = worldedit.normalize_nodename(replace_node)
|
replace_node = worldedit.normalize_nodename(replace_node)
|
||||||
|
|
||||||
return replace_node, seed, path_length, path_width
|
return replace_node, seed, path_length, path_width, path_depth
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_chatcommand("/maze", {
|
minetest.register_chatcommand("/maze", {
|
||||||
|
@ -80,11 +88,11 @@ minetest.register_chatcommand("/maze", {
|
||||||
-- ██ ██ ██ ██ ███████ ███████ ██████ ██████
|
-- ██ ██ ██ ██ ███████ ███████ ██████ ██████
|
||||||
|
|
||||||
minetest.register_chatcommand("/maze3d", {
|
minetest.register_chatcommand("/maze3d", {
|
||||||
params = "<replace_node> [<seed>]",
|
params = "<replace_node> [<path_length> [<path_width> [<path_depth> [<seed>]]]]",
|
||||||
description = "Generates a 3d maze covering the currently selected area (must be at least 3x3x3) with replace_node as the walls. Optionally takes a (integer) seed.",
|
description = "Generates a 3d maze covering the currently selected area (must be at least 3x3x3) with replace_node as the walls. Optionally takes a (integer) seed and the path length, width, and depth (see the documentation in the worldeditadditions README for more information).",
|
||||||
privs = { worldedit = true },
|
privs = { worldedit = true },
|
||||||
func = we_c.safe_region(function(name, params_text)
|
func = we_c.safe_region(function(name, params_text)
|
||||||
local replace_node, seed, has_seed = parse_params_maze(params_text)
|
local replace_node, seed, path_length, path_width, path_depth = parse_params_maze(params_text)
|
||||||
|
|
||||||
if not replace_node then
|
if not replace_node then
|
||||||
worldedit.player_notify(name, "Error: Invalid node name.")
|
worldedit.player_notify(name, "Error: Invalid node name.")
|
||||||
|
@ -97,7 +105,7 @@ minetest.register_chatcommand("/maze3d", {
|
||||||
if not seed then seed = os.time() end
|
if not seed then seed = os.time() end
|
||||||
|
|
||||||
local start_time = os.clock()
|
local start_time = os.clock()
|
||||||
local replaced = worldedit.maze3d(worldedit.pos1[name], worldedit.pos2[name], replace_node, seed)
|
local replaced = worldeditadditions.maze3d(worldedit.pos1[name], worldedit.pos2[name], replace_node, seed, path_length, path_width, path_depth)
|
||||||
local time_taken = os.clock() - start_time
|
local time_taken = os.clock() - start_time
|
||||||
|
|
||||||
worldedit.player_notify(name, replaced .. " nodes replaced in " .. time_taken .. "s")
|
worldedit.player_notify(name, replaced .. " nodes replaced in " .. time_taken .. "s")
|
||||||
|
|
Loading…
Reference in a new issue