I’m working on my own dungeon generation system (akin to old school dungeon crawlers).
Here’s how I have it building:
A central point, which runs the script on Active, builds a path in a random direction (North, South, East, West). When it reaches the end of the path (length determined randomly, within variable set bounds), it adds the end point to a list. Then a random end point in the list is picked (including the base starting point) and another path is built off of that. It repeats this until a certain amount are built (determined randomly by variable set bounds). Then, it builds rooms based on all of the end points, of varying size. Anywhere that already has a block in place will not build a new one on top of it, preventing overlap.
The problem is this: When two path endpoints are near each other, it will result in two rooms being built on top of each other. This is expected, and in fact wanted. The problem is that occasionally, the second room is built too long and is cut off by the walls of the other room that was built there. The end result is small sections of a room being completely cut off from the rest of the dungeon.
I realize this is what happens. The problem is that I’m not sure what to do about it.
An example: There are two end points adjacent to each other vertically. The top one has a room 5x5 built off of it. The bottom one creates a room 3x9. If there are no previously existing paths going north or south of either room (so, the paths meet from the East or West), the end result is that the bottom and/or top of the second room is built behind the walls of the first room, cutting it off from the rest of the dungeon.
I do not want the second room to destroy the walls created by the first room, except so that it can be entered. A wanted effect of the generation is that there can be rooms inside of rooms, or rooms connected to half of another room and branches out, sort of like a T. The unwanted effect is sections being completely cut off by previously existing rooms.
Below is an example of what I am talking about (pardon the texture-less…everything).
In this picture, 4 paths either build from the room or in to it. As a result at least two rooms were built in the same general location. The second room was built tall, and as a result it builds outside of the first room and there is no way to access the lower portion of it because there is no south bound path.
Any suggestions on fixing this problem would be greatly appreciated.