An Approach to Making Random Dungeons
by Gary Haussmann · 01/02/2006 (1:56 pm) · 10 comments
I'm a big fan of the old dungeon crawl games (like Nethack) that auto-generated random dungeons and populated them with monsters. So over the holiday break I attempted to make a reasonable generator that would take torque interiors and assemble them in a mission file to approximate the old-school dungeon setup. The initial results were surprisingly easy to produce, but there are many little details to iron out.
Step 1: Make a bunch of modular interiors representing parts of the dungeon. This includes things like hallways, small rooms, and stairs/ramps. Each part will correspond to a single tile in my autogenerated maze, and has to be a standard size and have openings/doors at the right spot. This way all the parts will fit together so that, for instance, the west door of room #323 will match up with the hallway opening of hallway part #193. The screenshot shows a simple part representing a hallway turn.

Step 2: Generate the maze. Here I just have a python script generate a simple maze, like the kind you would have done in an undergraduate algorithms class. The script then tries to match up interiors to appropriate tiles. For instance, a tile with openings to the west and east would correspond to a straight hallway, or perhaps a room with two doors on opposing walls.
The screenshot shows a text dump of the results: The walls of the maze are the "#" characters and tiles are filled with different letters to indicate which DIF structure was placed there. It's only for debugging, so it doesn't really have to make a lot of sense...

Step 3: Generate a mission file containing all the interiors at the proper position and orientation. Load mission. Profit! Here is an example dungeon made up of a 5 x 5 x 2 region of tiles. Yeah, it's three-dimensional, so there are two floors; the ramps are kind of a problem. You can also see some "missing" parts, since I haven't made enough interiors to cover all the possible tile configurations. If the script can't find an interior that matches up to a given tile in the maze, that tile is just left as empty space.

And here is a debugging shot that clearly shows the parts that make up the "Dungeon"

It's not really that easy, though. Slapping dozens of interiors all in one spot is a good way to drag down your FPS, so I'm thinking heavy use of LOD will be needed here. The other main problem is lighting, which stems from my use of portals. The portals block off sunlight from reaching the inside of each part, but since I can't stick the portal at the very edge of each interior, the edges of each part will get lit up. Here you can clearly see the joints between dungeon parts since they are lit up by the sunlight leaking in. Also, lights placed in one DIF won't illuminate other DIF, so the light in a specific room won't bleed out into the adjacent hallways.

Luckily, Universal Static Lights (USL) from the lighting pack can help a lot. The main advantage here is that USL's will illuminate multiple interiors seamlessly, so it's much less obvious where the joints go. In the previous shot, the green illumination is from a USL. Currently I've just turned off the sun altogether and rely on USL's, although if anyone can suggest better methods I could use here I would greatly appreciate it. Here's the same mission file with only USL's in it.

Finally, note that you can make bigger and more complex structures as long as they fit into the tile system. Here is a bigger room which occupies a 2x2 tile region on the map.

Anyway, a nice little diversion over the holidays. I still need to make some more structures (and better ones) but the siren's call of Real Work is wafting to my ears...
Step 1: Make a bunch of modular interiors representing parts of the dungeon. This includes things like hallways, small rooms, and stairs/ramps. Each part will correspond to a single tile in my autogenerated maze, and has to be a standard size and have openings/doors at the right spot. This way all the parts will fit together so that, for instance, the west door of room #323 will match up with the hallway opening of hallway part #193. The screenshot shows a simple part representing a hallway turn.

Step 2: Generate the maze. Here I just have a python script generate a simple maze, like the kind you would have done in an undergraduate algorithms class. The script then tries to match up interiors to appropriate tiles. For instance, a tile with openings to the west and east would correspond to a straight hallway, or perhaps a room with two doors on opposing walls.
The screenshot shows a text dump of the results: The walls of the maze are the "#" characters and tiles are filled with different letters to indicate which DIF structure was placed there. It's only for debugging, so it doesn't really have to make a lot of sense...

Step 3: Generate a mission file containing all the interiors at the proper position and orientation. Load mission. Profit! Here is an example dungeon made up of a 5 x 5 x 2 region of tiles. Yeah, it's three-dimensional, so there are two floors; the ramps are kind of a problem. You can also see some "missing" parts, since I haven't made enough interiors to cover all the possible tile configurations. If the script can't find an interior that matches up to a given tile in the maze, that tile is just left as empty space.

And here is a debugging shot that clearly shows the parts that make up the "Dungeon"

It's not really that easy, though. Slapping dozens of interiors all in one spot is a good way to drag down your FPS, so I'm thinking heavy use of LOD will be needed here. The other main problem is lighting, which stems from my use of portals. The portals block off sunlight from reaching the inside of each part, but since I can't stick the portal at the very edge of each interior, the edges of each part will get lit up. Here you can clearly see the joints between dungeon parts since they are lit up by the sunlight leaking in. Also, lights placed in one DIF won't illuminate other DIF, so the light in a specific room won't bleed out into the adjacent hallways.

Luckily, Universal Static Lights (USL) from the lighting pack can help a lot. The main advantage here is that USL's will illuminate multiple interiors seamlessly, so it's much less obvious where the joints go. In the previous shot, the green illumination is from a USL. Currently I've just turned off the sun altogether and rely on USL's, although if anyone can suggest better methods I could use here I would greatly appreciate it. Here's the same mission file with only USL's in it.

Finally, note that you can make bigger and more complex structures as long as they fit into the tile system. Here is a bigger room which occupies a 2x2 tile region on the map.

Anyway, a nice little diversion over the holidays. I still need to make some more structures (and better ones) but the siren's call of Real Work is wafting to my ears...
About the author
#2
When will it be released ?
01/02/2006 (2:21 pm)
very nice, this will help with making dungeon and testing for light leaks etcWhen will it be released ?
#3
01/02/2006 (2:31 pm)
I'm impressed
#4
01/02/2006 (3:07 pm)
thats good will it be released? I would buy.
#5
01/02/2006 (3:57 pm)
I'm not sure if I gather correctly, does it generate the mission file automatically? Or does it just give you a guide for putting the missions together?
#6
01/02/2006 (4:48 pm)
Wow.... sign me up. I hope you're releasing this. Man its awesome.
#7
This is just proof-of-concept stuff. A setup appropriate for release would need to allow you to hit some "play random dungeon now!" button from the main menu which would then drop you into a fully functioning random dungeon. That would require a LOT more coding work. Not to mention that I'd have to make a buttload more interiors and make them nice-looking :P
01/02/2006 (7:27 pm)
Brian, the python script currently generates a dungeon.mis file and dumps it into the missions/ directory, so that part is pretty automated. In theory you would want to automate the entire process.This is just proof-of-concept stuff. A setup appropriate for release would need to allow you to hit some "play random dungeon now!" button from the main menu which would then drop you into a fully functioning random dungeon. That would require a LOT more coding work. Not to mention that I'd have to make a buttload more interiors and make them nice-looking :P
#8
01/02/2006 (7:29 pm)
This is really, really cool. I was playing with something similar with progressive mission files a while back. I didn't prototype it to this extent, though. Nice!
#9
Perhaps you could directly generate a .map file consisting of all the brushes of the segments stuck together to solve your "too many interiors in one spot" problem...
Then again, that might also bog down your system, and you'd have to remove duplicate portal brushes from the exits.
Of course, you could still go for combined .map's and .mis' - stick A x A segments into a .map, with B x B segments total as .dif's in the .mis.
01/03/2006 (2:22 am)
Neato idea!Perhaps you could directly generate a .map file consisting of all the brushes of the segments stuck together to solve your "too many interiors in one spot" problem...
Then again, that might also bog down your system, and you'd have to remove duplicate portal brushes from the exits.
Of course, you could still go for combined .map's and .mis' - stick A x A segments into a .map, with B x B segments total as .dif's in the .mis.
#10
http://users.tkk.fi/~vhelin/dippa.ps
http://users.tkk.fi/~vhelin/lg.html
:D
04/06/2006 (2:24 pm)
Nice, looks very much like the 3D building generator I wrote as a part of my Master's Thesis back in 2003:http://users.tkk.fi/~vhelin/dippa.ps
http://users.tkk.fi/~vhelin/lg.html
:D

Torque Owner Brett Fattori
- Brett