Repository navigation
Allow themed room subrooms to be filled - #347
Closed
copperwater wants to merge 7 commits into
Closed
copperwater wants to merge 7 commits into
copperwater wants to merge 7 commits into
Conversation
copperwater
force-pushed
the
themerm_fill_subrooms
branch
from
May 19, 2020 03:13
de63a36 to
2b1c07c
Compare
I noticed that any subrooms created within a themed room were bare - they never had any monsters, objects, traps, or anything really, regardless of whether filled = 1 was set on them. As a result, they're pretty boring. It turns out that the code in makelevel() responsible for stocking ordinary rooms with stuff only looped through g.rooms, and completely ignored subrooms. (Subrooms would not get stocked with items by virtue of being part of the larger room; I tested this by dialing the item generation in rooms way up, and none of those items ever got placed in a subroom.) To fix this, I've extracted the code that populates an ordinary room into its own function, fill_ordinary_room, and made it recurse into its own subrooms. (I also renamed fill_rooms and fill_room to include the word "special" in their names, because they only deal with special rooms.) Note that since special rooms follow a separate codepath, an ordinary subroom of a special room won't get stocked; perhaps these functions should be unified in the future. The fill_ordinary_room code is pretty much a verbatim cut and paste from makelevel, so there is not currently any consideration for the size of the subroom or the fact that it is a subroom with respect to how many monsters, traps, objects, etc get placed. I'm not sure whether other things such as stair selection will ever select themed room subrooms, or whether they too only look at g.rooms.
No code in this function would actually do anything if it were called on a themed room, but since it is pretty clearly intended for the "regular" special rooms, it's probably best to explicitly avoid themed rooms as well.
copperwater
force-pushed
the
themerm_fill_subrooms
branch
from
May 21, 2020 13:38
a7209af to
03c13b7
Compare
The existing system was a confusing mess of competing names (filled, needfill, prefilled, etc) that had varying semantics, with prefilled being the worst offender as it meant at least three different things in various contexts. This commit unifies everything in the code under "needfill", and everything in Lua under "filled", which defaults to 0 everywhere. This also removes the second argument to fill_special_room; that function now just checks the needfill of the room it's passed. As before, a filled == 2 value is used for a special room to indicate that the room should set the appropriate level flag, but shouldn't actually be stocked with anything (for instance, King Arthur's throne room); the difference is that this now comes directly from the lua script instead of being manipulated within sp_lev.c. The prefilled argument had one use case that is occasionally used in the level files: if the level designer had specified an ordinary region with prefilled = 1, it would become a room to control monster arrivals on a level -- monsters that arrive within the bounds of a room are supposed to stay there. However, not all of the places where the comments indicated this was being used were using it correctly; I tested this by letting a few monsters fall through the knox portal (they're supposed to be constrained to the entry room) and waiting a hundred turns, then going through the portal; they were not constrained to the room and had "wandered" through its walls. Instead of trying to maintain this special case, I have added an optional "arrival_room" boolean argument to des.region, which forces it to create a room for the purposes of constraining monster arrival. I have gone through and replaced occurrences of prefilled in lua files with the appropriate filled option (or arrival, as needed). In some cases, that resulted in questionable regions such as a filled ordinary area in a non-themeroom (I just dropped the filled=1), or an area which didn't do anything, not even lighting (which I deleted).
The fill_special_rooms function was only stocking two types of rooms: top-level rooms in g.rooms, and their immediate subrooms. If there were a special room 2 or more levels down, it would not get filled. (No special levels currently define such a special room, so this bug is latent.) To address this, I changed fill_special_rooms to iterate only through the top level rooms, and fill_special_room to recurse through all of its subrooms (if any) before filling itself.
There is code in fixup_special for stocking Medusa's lair with statues of players from the leaderboard. It makes two assumptions: that there will always be at least one room defined on Medusa's level, and that the statues should be placed in the first room defined. In the process of removing prefilled, some of these rooms suddenly became non-rooms, and this caused problems. This commit ensures that the regions for turning into rooms to hold the statues are present and come first. In the process of writing this commit, I discovered a bug: the statue stocking code for medusa in fixup_special naively chooses the spot at which to place its final statue by selecting independent x and y coordinates with somex and somey. This is responsible for a statue occasionally being embedded in a wall or in iron bars on medusa-2 and medusa-4: the rooms defined to receive statues are irregular, and some of the possible coordinates happen to be walls, bars, and water. The proper fix here is to add lua functionality so that the level designer can specify that they want a leaderboard corpse or statue, and remove the medusa special case from fixup_special, but that's rather out of scope for what I'm doing here.
The plan is to unify special room filling code and cause special rooms to be filled as the very last stage of level creation. Since this will occur after fixup_special, it was necessary to address the one remaining piece of code in there that affects special room filling. (The Medusa code remaining in there doesn't have to do with special rooms.)
This unifies the two separate special-room-stocking code paths, one in the standard dungeon generator and one in the special level generator (neither of which reacted to themed rooms, which is the reason for this commit) into the end of makelevel(), placing the special room stocking as the very last step of level creation. Under the new system, when a regular or special level decides to create a special room, it sets that room's rtype, but the room is not stocked until later. It already worked this way for special levels, so the main difference here is in the normal level generation, where the mkroom family of functions identifies and marks a room as a special room, but stops short of filling it. (I suppose perhaps the mkroom, mkzoo, mkshop family of functions would be better off changing their names to "pickroom" and so on.) This also restructures makelevel() itself a bit, but the only real change is that the paths that call makemaz don't return immediately afterward; they continue to the special room stocking code. Also, this code was lifted from fill_special_rooms, which is now not used anywhere, so it has been deleted. I don't really like how fill_ordinary_room is in mklev.c and fill_special_room is in sp_lev.c; they seem like they'd be better off in mkroom.c, but in the interest of not making unnecessary code changes, I'll just recommend it.
copperwater
force-pushed
the
themerm_fill_subrooms
branch
from
May 22, 2020 05:02
59c41ce to
3badf03
Compare
Contributor
Author
|
Merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I noticed that any subrooms created within a themed room were bare - they never had any monsters, objects, traps, or anything really, regardless of whether filled = 1 was set on them. As a result, they're
pretty boring, and I wanted to fix this.
Then I noticed that special rooms incorporated into themed rooms (or just themed rooms defined with a type that wasn't "ordinary" or "themed") were being left empty as well. One thing led to another and I wound up refactoring some parts of the level creation code and fixing some bugs along the way.
The broad strokes: