Attached is a lib you can drop in an empty campaign file, run oncampaignload and then "dungeonGen" function. You can set width, height and fill.
The result is currently represented in an simple html form and its rooms only.
the principle behind the generator (if youre interested)
I got this (partially) from the donjon generator:
1. max room size is 1/4 of the dungeon size
2. room can only start on odd coordinates and have an odd length and width
3. resulting dungeon starts a an empty array [] and is filled with grid coordinates: {x:3;y:5}. Every coord represents an open space on that spot in the dungeon.
the filling:
4. first a room (random size) is build by creating a set of coords which allow for an offset {x:[r:0+x];y:[r:0+y]}, {x:[r:1+x];y:[r:0+y]}, {x:[r:2+x];y:[r:0+y]}, etc.
5. then the offset is randomly decided and applied to the array (Wiki: json.evaluate())
6. next its checked whether the room overlaps with an existing room (using Wiki: json.intersection()(dungeon, room), if so then a new random offset is determined. Rinse and repeat.
7. a while loop is used to keep iterating until the fill target is met. (so yes if you enter a fill target >100% then you have a chance for an inf loop
1. max room size is 1/4 of the dungeon size
2. room can only start on odd coordinates and have an odd length and width
3. resulting dungeon starts a an empty array [] and is filled with grid coordinates: {x:3;y:5}. Every coord represents an open space on that spot in the dungeon.
the filling:
4. first a room (random size) is build by creating a set of coords which allow for an offset {x:[r:0+x];y:[r:0+y]}, {x:[r:1+x];y:[r:0+y]}, {x:[r:2+x];y:[r:0+y]}, etc.
5. then the offset is randomly decided and applied to the array (Wiki: json.evaluate())
6. next its checked whether the room overlaps with an existing room (using Wiki: json.intersection()(dungeon, room), if so then a new random offset is determined. Rinse and repeat.
7. a while loop is used to keep iterating until the fill target is met. (so yes if you enter a fill target >100% then you have a chance for an inf loop
Comment, suggestions are most welcome
EDIT: Let me also phrase some concrete questions:
- What kind of algorithm can I use for creating corridors
(I have already some idead, but curious to others)
One method I can think of:
1 pick a random spot in the dungeon (again odd coords only!!)
2 check whether the spot is 'solid' (so no room or other corridor) (if not back to 1)
3 50% chance for initial horizontal or vertical direction (e.g. horizontal)
4 check all 4 SECOND (the first connections are all even coords and thus empty!!) connecting points for 'solid' if none then discard this coord and pick a new one.
5 Randomly choose a direction from the available 1,2,3 or 4 available directions and pick that direction (always in steps of 2 so you end up in an odd coord!!).
6 in 70% of the cases keep going in that direction, the other 30% take another direction
7 keep doing this until you hit a wall
8 rinse and repeat 1 to 7 until a certain 'fill' is reached.
1 pick a random spot in the dungeon (again odd coords only!!)
2 check whether the spot is 'solid' (so no room or other corridor) (if not back to 1)
3 50% chance for initial horizontal or vertical direction (e.g. horizontal)
4 check all 4 SECOND (the first connections are all even coords and thus empty!!) connecting points for 'solid' if none then discard this coord and pick a new one.
5 Randomly choose a direction from the available 1,2,3 or 4 available directions and pick that direction (always in steps of 2 so you end up in an odd coord!!).
6 in 70% of the cases keep going in that direction, the other 30% take another direction
7 keep doing this until you hit a wall
8 rinse and repeat 1 to 7 until a certain 'fill' is reached.
Note: I don't need code, I just need a procedural description of how to go with that.