Re: Procedural map generation
Posted: Tue Dec 13, 2022 4:59 pm
Uhhh? Of what?
The lines mentioned before
Just found the functions, I dont understand them but can i just say damn its impressive you did this in one dayBrotSagtMist wrote: ↑Tue Dec 13, 2022 4:34 pm At this point i am really sorry this code is so hard to read (i wrote that in a day).
But the concept i explained above are basically just lines 258-299 in that main.lua file.
There is nothing more to it.
Code: Select all
function Makelab(s)
local x = math.random(Tilesx-5)+5
local y = math.random(Tilesy-5)+5
if not (Lab[x][y-1] or Lab[x+1][y] or Lab[x][y+1] or Lab[x-1][y]) then
Lab[x][y]=s
local r
for z = 1, 500 do
local d = math.random(STRAIGHT)
if d == 1 then
if not (Lab[x-1][y-1] or Lab[x+1][y-1]) then y=y-1 r=d end
elseif d == 2 then
if not (Lab[x+1][y-1] or Lab[x+1][y+1]) then x=x+1 r=d end
elseif d == 3 then
if not (Lab[x-1][y+1] or Lab[x+1][y+1]) then y=y+1 r=d end
elseif d == 4 then
if not (Lab[x-1][y-1] or Lab[x-1][y+1]) then x=x-1 r=d end
else
if r == 1 then
if not (Lab[x-1][y-1] or Lab[x+1][y-1]) then y=y-1 end
elseif r == 2 then
if not (Lab[x+1][y-1] or Lab[x+1][y+1]) then x=x+1 end
elseif r == 3 then
if not (Lab[x-1][y+1] or Lab[x+1][y+1]) then y=y+1 end
elseif r == 4 then
if not (Lab[x-1][y-1] or Lab[x-1][y+1]) then x=x-1 end
end
end
Lab[x][y]=s
end
else
return
end
end
function fork(x,y)
Lenght=Lenght+1
Street[x][y]=Lenght
Valids[Lenght]={x=x,y=y}
if Lab[x][y-1] and not Street[x][y-1] then fork(x,y-1) end
if Lab[x+1][y] and not Street[x+1][y] then fork(x+1,y) end
if Lab[x][y+1] and not Street[x][y+1] then fork(x,y+1) end
if Lab[x-1][y] and not Street[x-1][y] then fork(x-1,y) end
end
Hi brot, so after messing around with flood fill and pathfinding what I found out was that the chance of a working map being generated was so low that that the system would get stack overflow bugged long before it could get a good map, so what Im trying to do now is make better map generation, Ive tried some maze generation algorithms but theyre pretty hard to understand lol, you got any advice?BrotSagtMist wrote: ↑Wed Dec 14, 2022 3:46 pm Yea, jam code is not really meant to be reused, its jammed together.
But to pinpoint the process here:
Have a function walk through the map from one point to wherever its ruleset allows it to walk and save that not only in the map but a second table.
That table _is Street_ in my example.
The ruleset being: step is valid if new step is not surrounded by floor except in the direction we came from.
And we go for example 60% forward, 20% left/right to get a good walkable street.
And then the trick behind it is that Street does not only contain valid points to place your items on but also shows where to place them, with the first and latest entry being furthest away from each other, how big the map is playwise and it contains a valid path so that you can place enemies without the need of pathfinding.
And to make it a labyrinth you start forking from Street using a _contain walls left and right_ ruleset.
Im not sure what you mean
Ill check it out thank you!darkfrei wrote: ↑Wed Dec 14, 2022 8:47 pm If you want to get result trough mazes, try to understand my old mod for Factorio:
(control.lua only)
https://mods.factorio.com/mod/Mazing
a58646e25aa00b54fff890d17a4d64392614e79e.png