Hi! This is a highly theoretical discussion (kind of a thought experiment) of how one might implement quasi-roguelike level design (random, different on each playthrough) using event code alone. (I wouldn't be shocked if someone had already tackled this topic and done a better job of it.)
I'm using RMMV but theoretically this should be possible using most versions of RPG Maker. NOT included: a way to enforce permadeath. For that I'm thinking you're going to need scripts.
Anyway, this is totally a case of me writing something out because if it turns out to be impossible, implausible, or impractical it will be much easier and less time consuming to figure that out "on paper" (or be told it by someone here smarter than me lol) than implementing it in the engine.
That said, some constraints are assumed here. One is that each map is the minimum map size allowable by your resolution (using the default resolution, this is 17x13). First, you create stock maps of set shapes and sizes. I think you could probably get away with just these fifteen templates:
If we wanted to get fancy and make things feel more roguelike-like we'd want to have a wide variety of different bespoke, fancy, individually non-random "entry vaults" (a la DCSS) but for the sake of argument, let's say we always start with a map that is Dead-End, From Down that always connects to a four-way intersection before any randomization happens.
Schrodinger's Maps
Now, each subsequent "level" map needs the following:
a) Its own variable, which I'll call MAP x SubID for now. Replace x with the Map ID in question.
b) To contain every possible map from the direction of entry (6, I think).
For instance, starting with our four way intersection example, we'd create Map IDs 003, 004, and 005, for going left, down, and right respectively and three variables, MAP 3 SubID, MAP 4 SubID, Map 5 SubID, that will be linked to those maps. Then inside those maps we would create every map could be arrived at from going in that direction. I.e.:
The first time you went left at the first + intersection, you'd set MAP3 SubID to a random integer from 1 thru 6 (so essentialy, 1d6). This would determine if going left would lead you to a #2, a #3, a #4, #8, a #10, or a #13. That map's "SubID" would then be set, so that every time you used that "teleport" event, it would always lead to the same place, the same "version" of MAP3 and no longer be in a state of "quantum flux" (hence the reference to Schrodinger's Cat). Going right from that intersection would lead you either to a #2, #3, #5, #9, #11, or #12, and fix that as the destination of that path, and going down from that intersection would lead you either to a #1, #3, #7, #10, #11, or #14.
Problem I: Impossible Spaces
One immediate problem that arises--besides that your project is going to have at least six times the number of maps as it would if you weren't using this method, although in actuality your project only uses tons of clones of 15 different maps--is that these random destinations can result in impossible combinations. For instance, look at our first four way intersection. Say you go down from that into a #11. Whereas if you go left, you enter a #8. So far, so good. But the problem is, going down from that #8 (which is the only way to progress from an 8 having entered from the right), if you didn't "roll" a destination of 3, 7, or 10, you'd wind with in a room that doesn't connect to the #11 that should, on a grid, be immediately to the right of it. For instance if you "rolled" a 14 (crappy ascii map warning):
∩
Г +
U ⅃
See the problem? It's entirely possible for whatever map shape you enter going south to fail to "connect" to the map to the left and/or right of it in the way that it should.
I have a workaround for this, but it's 4% technical and 96% imaginative in nature. It is to keep the basic scheme above, but to make every one of the shapes above have you "exit" via a down staircase and "enter" via an up staircase. This results in equally impossible spaces, but their impossiblity isn't nearly as obvious when you add in abstracted verticality when each staircase moves you an indetermined vertical distance. For instance, maybe the room shaped like a backwards L leads to a #2 anyway, that #2 is just "BELOW"/"ABOVE" the #14 that "should" be occupying that space on an imaginary 2D grid. This may still lead to configurations that don't make sense with our understanding of Euclidean geometry, but if your setting is wild enough, you can have all kinds of fun with in-game justifications of why the dungeon works like this, from the proverbial shrug of "a wizard did it" that's available in any high fantasy setting, to elaborate quantum physics based technobabble in a scifi game to well, "Silent Hill making sense would defeat the purpose".
This method also supports having a DEPTH or "Z-Level" variable that consistently increments as you go downwards (and decrements as you go upwards) that would let you keep track of a player's total PROGRESS in descending (or you could flip descending/ascending if you were doing a "climb a tower" style roguelike as opposed to the standard "race to the bottom level" roguelike) through the dungeon and then you could use that variable as a benchmark/milestone to determine what level of monsters and treasure/gear are randomly generated (I assume if you want to do something roguelike-like you can figure out on your own how to randomize your treasure/encounters, it is much simpler and in any case not within the scope of this little tutorial/thought experiment). Even if you weren't to use this workaround, you're still probably going to want a "progress" variable equivalent to Depth that tracks how far the player is into the dungeon (basically, every time that a room gets randomly rolled and "set", this variable goes up by 1, and optionally goes back down when you retreat and back up when you advance again).
Problem II: Impossible Progress?
A problem I don't have a solution for is that it's very possible (if not quite likely) that this method will eventually result in a dead end in every direction and no way to progress. The only workaround for this I can think of is not ideal: remove dead ends/the possibility of dead ends entirely. But that a) requires your meta-map to expand infinitely in every direction and b) reduces the variety of what shapes a given map can lead to by 26%. Problem A can, I think, be worked around by having every direction start ending in dead ends once the DEPTH/Z-Level/Progress variable gets high enough, or even having four variables, Down, Left, Right, Up, tracking how many "screens" the player progresses in each direction. Problem B doesn't break the system, but it does exacerbate the "monotony" problem inherent to your game/dungeon consisting almost entirely of 15 endlessly cloned and occasionally reskinned map shapes/templates by reducing that number from 15 to just 11 and in general mazes without the occasional dead end are less interesting mazes. Esp. since dead ends are great places to put bosses/treasure.
Other Problems I Haven't Thought Of?
You tell me, gang! I'm definitely not a scripter, and my spatial awareness and understanding of mathematics and logic (in the mathematical/compsci sense) is I think a little below average. I have two decades of experience "coding" events in RM and have played many roguelikes (never beaten one, except for SotS: The Pit on Easy mode, which I don't count because it was on Easy) but that's where my qualifications begin and end. I could have entirely missed a glaring flaw in the above logic that makes even what I've written impossible to implement! I think this methodology/implementation is more practical for the occasional random dungeon in a game not entirely based on dungeon crawling as opposed to a traditional roguelike-like experience where the entire game takes place in a giant randomized megadungeon
I'm using RMMV but theoretically this should be possible using most versions of RPG Maker. NOT included: a way to enforce permadeath. For that I'm thinking you're going to need scripts.
Anyway, this is totally a case of me writing something out because if it turns out to be impossible, implausible, or impractical it will be much easier and less time consuming to figure that out "on paper" (or be told it by someone here smarter than me lol) than implementing it in the engine.
That said, some constraints are assumed here. One is that each map is the minimum map size allowable by your resolution (using the default resolution, this is 17x13). First, you create stock maps of set shapes and sizes. I think you could probably get away with just these fifteen templates:
- Straight Corridor Up/Down
- Straight Corridor Left/Right
- Four Way Intersection
- T-Intersection (Enter From Right)
- T-Intersection (Enter From Left)
- T-Intersection (Enter From Bottom)
- T-Intersection (Enter From Top)
- Corner, Down/Right
- Corner, Down/Left
- Corner, Up/Right
- Corner, Up/Left
- Dead-End, From Left.*
- Dead-End, From Right.*
- Dead-End, From Up.*
- Dead-End, From Down.*
If we wanted to get fancy and make things feel more roguelike-like we'd want to have a wide variety of different bespoke, fancy, individually non-random "entry vaults" (a la DCSS) but for the sake of argument, let's say we always start with a map that is Dead-End, From Down that always connects to a four-way intersection before any randomization happens.
Schrodinger's Maps
Now, each subsequent "level" map needs the following:
a) Its own variable, which I'll call MAP x SubID for now. Replace x with the Map ID in question.
b) To contain every possible map from the direction of entry (6, I think).
For instance, starting with our four way intersection example, we'd create Map IDs 003, 004, and 005, for going left, down, and right respectively and three variables, MAP 3 SubID, MAP 4 SubID, Map 5 SubID, that will be linked to those maps. Then inside those maps we would create every map could be arrived at from going in that direction. I.e.:
- Going left can lead to 2, 3, 4, 8, 10, or 13.
- Going down can lead to 1, 3, 7, 10, 11, or 14.
- Going right can lead to 2, 3, 5, 9, 11, or 12.
The first time you went left at the first + intersection, you'd set MAP3 SubID to a random integer from 1 thru 6 (so essentialy, 1d6). This would determine if going left would lead you to a #2, a #3, a #4, #8, a #10, or a #13. That map's "SubID" would then be set, so that every time you used that "teleport" event, it would always lead to the same place, the same "version" of MAP3 and no longer be in a state of "quantum flux" (hence the reference to Schrodinger's Cat). Going right from that intersection would lead you either to a #2, #3, #5, #9, #11, or #12, and fix that as the destination of that path, and going down from that intersection would lead you either to a #1, #3, #7, #10, #11, or #14.
Problem I: Impossible Spaces
One immediate problem that arises--besides that your project is going to have at least six times the number of maps as it would if you weren't using this method, although in actuality your project only uses tons of clones of 15 different maps--is that these random destinations can result in impossible combinations. For instance, look at our first four way intersection. Say you go down from that into a #11. Whereas if you go left, you enter a #8. So far, so good. But the problem is, going down from that #8 (which is the only way to progress from an 8 having entered from the right), if you didn't "roll" a destination of 3, 7, or 10, you'd wind with in a room that doesn't connect to the #11 that should, on a grid, be immediately to the right of it. For instance if you "rolled" a 14 (crappy ascii map warning):
∩
Г +
U ⅃
See the problem? It's entirely possible for whatever map shape you enter going south to fail to "connect" to the map to the left and/or right of it in the way that it should.
I have a workaround for this, but it's 4% technical and 96% imaginative in nature. It is to keep the basic scheme above, but to make every one of the shapes above have you "exit" via a down staircase and "enter" via an up staircase. This results in equally impossible spaces, but their impossiblity isn't nearly as obvious when you add in abstracted verticality when each staircase moves you an indetermined vertical distance. For instance, maybe the room shaped like a backwards L leads to a #2 anyway, that #2 is just "BELOW"/"ABOVE" the #14 that "should" be occupying that space on an imaginary 2D grid. This may still lead to configurations that don't make sense with our understanding of Euclidean geometry, but if your setting is wild enough, you can have all kinds of fun with in-game justifications of why the dungeon works like this, from the proverbial shrug of "a wizard did it" that's available in any high fantasy setting, to elaborate quantum physics based technobabble in a scifi game to well, "Silent Hill making sense would defeat the purpose".
This method also supports having a DEPTH or "Z-Level" variable that consistently increments as you go downwards (and decrements as you go upwards) that would let you keep track of a player's total PROGRESS in descending (or you could flip descending/ascending if you were doing a "climb a tower" style roguelike as opposed to the standard "race to the bottom level" roguelike) through the dungeon and then you could use that variable as a benchmark/milestone to determine what level of monsters and treasure/gear are randomly generated (I assume if you want to do something roguelike-like you can figure out on your own how to randomize your treasure/encounters, it is much simpler and in any case not within the scope of this little tutorial/thought experiment). Even if you weren't to use this workaround, you're still probably going to want a "progress" variable equivalent to Depth that tracks how far the player is into the dungeon (basically, every time that a room gets randomly rolled and "set", this variable goes up by 1, and optionally goes back down when you retreat and back up when you advance again).
Problem II: Impossible Progress?
A problem I don't have a solution for is that it's very possible (if not quite likely) that this method will eventually result in a dead end in every direction and no way to progress. The only workaround for this I can think of is not ideal: remove dead ends/the possibility of dead ends entirely. But that a) requires your meta-map to expand infinitely in every direction and b) reduces the variety of what shapes a given map can lead to by 26%. Problem A can, I think, be worked around by having every direction start ending in dead ends once the DEPTH/Z-Level/Progress variable gets high enough, or even having four variables, Down, Left, Right, Up, tracking how many "screens" the player progresses in each direction. Problem B doesn't break the system, but it does exacerbate the "monotony" problem inherent to your game/dungeon consisting almost entirely of 15 endlessly cloned and occasionally reskinned map shapes/templates by reducing that number from 15 to just 11 and in general mazes without the occasional dead end are less interesting mazes. Esp. since dead ends are great places to put bosses/treasure.
Other Problems I Haven't Thought Of?
You tell me, gang! I'm definitely not a scripter, and my spatial awareness and understanding of mathematics and logic (in the mathematical/compsci sense) is I think a little below average. I have two decades of experience "coding" events in RM and have played many roguelikes (never beaten one, except for SotS: The Pit on Easy mode, which I don't count because it was on Easy) but that's where my qualifications begin and end. I could have entirely missed a glaring flaw in the above logic that makes even what I've written impossible to implement! I think this methodology/implementation is more practical for the occasional random dungeon in a game not entirely based on dungeon crawling as opposed to a traditional roguelike-like experience where the entire game takes place in a giant randomized megadungeon