Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes/improvements to map generation #210

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

ChronoQuote
Copy link

836ab8e Fix CalculateRoomExtents

shrinkAmount was applied before the potential min/max swap, resulting in room extents being larger than intended if the swap occurred. This fix resolves some instances of room overlap but not all.

6565fea Fix room2C forcing

After generating the facility layout, the game tries to force a room2C (corner tile) into each zone that doesn't have one. To do this, it finds a room1 (dead end tile) and checks whether there's space to extend it one tile forward then one tile sideways, forming an L shape. But it wasn't checking the correct spots to determine whether there's space, so sometimes the L would graze by another room1. Luckily, room shapes are recalculated when rooms are created, so the room2C would end up being a room3 (T-shaped tile) and the grazed room1 would end up being a room2 (hallway tile). However, room assignment still expected the additional room2C and room1, and so those tiles' room assignments got pushed to the next available room2C and room1, meaning not only that those rooms likely ended up in the wrong zone, but also that the very last room2C assignment (usually room2ccont, the electrical center, required to beat the game) and the very last room1 assignment (usually gateaentrance, required for two endings and for the MTF to spawn) never occurred.

I used a seed checker I created to check 10000 seeds before and after the fix. The fix reduced the ratio of unbeatable seeds from 5.28% to 3.72%. I hope to use this branch to reduce this ratio even further (without rewriting the whole map system).

Here's seed "n790" before the fix:
image

Notice that coffin and room2cpit, both HCZ rooms, are in EZ. Also notice that gateaentrance and room2ccont are missing. These problems were all caused by the forcing of a room2C just north of the room4 (four-way tile) in the center of the image.

Here's what that area looked like before the forcing:
image

The room1 north of the room4 is selected as a candidate for extension into an L shape. To determine which way the room1 could be extended, the game checks these four spots:
image

The southern spot is occupied, so the extension would be northward. To determine whether there's space, the game first checks these three spots:
image

They're empty, so to determine whether there's space to extend east after extending north, the game checks these three spots:
image

Some are occupied, so to determine whether there's space to instead extend west after extending north, the game checks these three spots:
image

They're empty, so the extension is performed, resulting in what we see in the final image.

With the fix, after the extension direction is determined, these are the spots that get checked for forward extension:
image

And if they're empty, these are the spots that get checked for sideways extension:
image image

In this case, the forward extension check fails.

Here's what "n790" looks like after the fix:
image

Much better!

shrinkAmount was applied before the potential min/max swap, resulting in room extents being larger than intended if the swap occurred. This fix resolves some instances of room overlap but not all.
After generating the facility layout, the game tries to force a room2C (corner tile) into each zone that doesn't have one. To do this, it finds a room1 (dead end tile) and checks whether there's space to extend it one tile forward then one tile sideways, forming an L shape. But it wasn't checking the correct spots to determine whether there's space, so sometimes the L would graze by another room1. Luckily, room shapes are recalculated when rooms are created, so the room2C would end up being a room3 (T-shaped tile) and the grazed room1 would end up being a room2 (hallway tile). However, room assignment still expected the additional room2C and room1, and so those tiles' room assignments got pushed to the next available room2C and room1, meaning not only that those rooms likely ended up in the wrong zone, but also that the very last room2C assignment (usually room2ccont, the electrical center, required to beat the game) and the very last room1 assignment (usually gateaentrance, required for two endings and for the MTF to spawn) never occurred.

I used a seed checker I created to check 10000 seeds before and after the fix. The fix reduced the ratio of unbeatable seeds from 5.28% to 3.72%. I hope to use this branch to reduce this ratio even further (without rewriting the whole map system).
@Jabka666
Copy link
Contributor

Jabka666 commented Sep 5, 2022

Is the custom map size up to date? Better to make MapSize as constants

- Fix GetZone incorrectly using MapWidth instead of MapHeight
- Make random hallway width dependent on MapWidth to fix maps remaining narrow despite a high MapWidth; the multipliers 0.6 and 0.85 were chosen as they are the only multiples of 0.05 that allow the two expressions to resolve to 10 and 15 when MapWidth is at its intended value of 18
- Split "map size" options.ini option into "map width" and "map height" options to increase customizability
@ChronoQuote
Copy link
Author

98409ed Fix custom map sizes

  • Fix GetZone incorrectly using MapWidth instead of MapHeight
  • Make random hallway width dependent on MapWidth to fix maps remaining narrow despite a high MapWidth; the multipliers 0.6 and 0.85 were chosen as they are the only multiples of 0.05 that allow the two expressions to resolve to 10 and 15 when MapWidth is at its intended value of 18
  • Split "map size" options.ini option into "map width" and "map height" options to increase customizability

Before:
Fix custom map sizes (before 1)
Fix custom map sizes (before 2)

Notice the zone sizes and amounts of checkpoint (green) rooms. Also notice how much of the width-40 map the facility actually occupies.

After:
Fix custom map sizes (after 1)
Fix custom map sizes (after 2)

PreventRoomOverlap is a function that tries to resolve a room's overlap issues by potentially swapping it with another room of the same shape. The disableoverlapcheck key makes a room exempt from PreventRoomOverlap's effects. Although the intro room, the pocket dimension, and 1499's dimension are big enough to not actually be swapped with anything, there is no reason they should even be considered for swapping by PreventRoomOverlap, so this commit gives them each the disableoverlapcheck key.
Copy link
Contributor

@Jabka666 Jabka666 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will you remove disableoverlapcheck parameter for room966?

@ChronoQuote
Copy link
Author

Will you remove disableoverlapcheck parameter for room966?

Rooms with geometry far below or far above them, like room049 or room3storage, have disableoverlapcheck = true. For some reason, room966 has this random geometry below it:
image
I heard it's actually a piece of room049, but I don't know why a piece of room049 is in room966. I think it should be removed from the mesh before disableoverlapcheck = true can be removed.

Jabka666 and others added 3 commits September 24, 2022 22:36
I_Zone\Transition[0] represents the y value of checkpoint1 room tiles plus one, and I_Zone\Transition[1] represents the y value of checkpoint2 room tiles plus one. These values are used to determine which type of door to place between rooms in each zone during map generation, as well as which zone's ambient sounds or music to play during gameplay. Previously the values were hardcoded based on the vanilla map height of 18 but they are now generalized based on MapHeight.
@Jabka666
Copy link
Contributor

Jabka666 commented Oct 1, 2022

  • Optimized room;
  • Removed extra r\Objects;
  • Disabled disableoverlapcheck parameter because I removed a lower extra part. I took room966 from UE, so a room with red lights is slightly changed. Because of that I moved security camera and NVG positions and replaced monitor image in SL_monitors.
    Before:
    Untitled3
    Untitled4
    After:
    Untitled
    Untitled2

@ChronoQuote
Copy link
Author

ChronoQuote commented Oct 22, 2022

  • Optimized room;
  • Removed extra r\Objects;
  • Disabled disableoverlapcheck parameter because I removed a lower extra part. I took room966 from UE, so a room with red lights is slightly changed. Because of that I moved security camera and NVG positions and replaced monitor image in SL_monitors.

I think you should've put this room966 update in a separate branch. This branch is for map generation fixes. The fact that room966 has disableoverlapcheck=true is pretty inconsequential and doesn't need to be fixed in this branch if it means changing the way room966 looks.

Because your room966 has a different amount of room lights (7 instead of 5), the RNG function will be called a different amount of times when room966 is generated. This means seeds will now contain different rooms than they used to.

@Jabka666
Copy link
Contributor

  • Optimized room;
  • Removed extra r\Objects;
  • Disabled disableoverlapcheck parameter because I removed a lower extra part. I took room966 from UE, so a room with red lights is slightly changed. Because of that I moved security camera and NVG positions and replaced monitor image in SL_monitors.

I think you should've put this room966 update in a separate branch. This branch is for map generation fixes. The fact that room966 has disableoverlapcheck=true is pretty inconsequential and doesn't need to be fixed in this branch if it means changing the way room966 looks.

Because your room966 has a different amount of room lights (7 instead of 5), the RNG function will be called a different amount of times when room966 is generated. This means seeds will now contain different rooms than they used to.

Isn't that easier to reduce lights amount?

@ChronoQuote
Copy link
Author

ChronoQuote commented Oct 23, 2022

Isn't that easier to reduce lights amount?

Not sure what you mean. Feel free to edit the room so that it has 5 lights instead of 7 if you would like to. I was just suggesting that these room966 changes be in a separate PR.

Edit: Jabka and I agreed to revert the changes.

@Sooslick
Copy link

Sooslick commented Feb 7, 2023

Btw, you can add "room2toilets" to forced rooms list in entrance zone. Generator creates most of maps with no toilets at all, making 100% walkthrough impossible due to "by researcher james..." achievement.

@ChronoQuote ChronoQuote mentioned this pull request Sep 9, 2023
This reverts commit 2909285, reversing
changes made to f47eafd.
@ChronoQuote
Copy link
Author

ChronoQuote commented Sep 15, 2023

8c7381b Revert "Merge pull request #3 from Jabka666/Fix-for-room966"

This reverts commit 2909285, reversing changes made to f47eafd.

13a51b6 Fix/improve ranges of room-forcing code

After preliminary map generation, some code tries forcing more room1s, room4s, and room2Cs into each zone if necessary. The room1 code scans for empty spaces to turn into room1s, while the room4 & room2C code scan for rooms to extend in such a way to create a room4 or room2C.

The ranges of the room1- and room2C-forcing code were a bit small, so some seeds didn't generate enough room1s or room2Cs even if there was space. Many important rooms (like room2ccont) are room1s or room2Cs, so this is arguably one of the biggest issues with the live game.

Meanwhile, the range of the room4-forcing code was quite big, so extensions would sometimes be performed past zone boundaries or into the outer edges of the map, which (via some other factors) led to issues like SCP-895's chamber being placed deep in the Entrance Zone, or SCP-372's chamber taking the place of the start room.

These changes make the ranges of the room-forcing code as large as they can be without causing issues, thus solving/mitigating the problems mentioned above. See commit for more info.

Range of the room1-forcing code before and after these changes:
room1 Regions Before room1 Regions After
An extra condition had to be added to ensure that a room1 could only be forced into the bottom row of zone 1 or 2 if it is attached to from above instead of from the side or below. The bottom row of zone 0 is still off-limits because forcing a room1 there could change the position of the start room, which was an issue with the room4-forcing code.
Stats from 100000 random seeds before and after these changes:
room1 Stats Before room1 Stats After

Range of the room2C-forcing code before and after these changes:
room2C Regions Before room4 & room2C Regions After
This code looks for a room1 in these regions to extend into a hook-like shape containing a room2C (see the first comment on this PR for details). A boundary is colored blue if the code is allowed to extend across it, or red if not. Previously, all boundaries were blue, which might be why the regions were made so small. A handful of extra conditions had to be added to achieve the red boundaries of the new, larger regions. (And although it's not clear from the picture, a room1 can't be extended out and around the corner of any of the new regions. Pretend the red lines are infinitely long.)
Stats from 100000 random seeds before and after these changes:
room2C Stats Before room2C Stats After
(No more seeds missing the electrical center!)

Range of the room4-forcing code before and after these changes:
room4 Regions Before room4 & room2C Regions After
This code looks for a room3 in these regions to extend into a room4. Boundaries are colored as before. Previously, all boundaries were blue and the regions were quite big, which led to the issues with room4-forcing mentioned earlier. A handful of extra conditions had to be added to achieve the red boundaries of the new regions. While the issues are now fixed, the spawn frequency of room4s has unfortunately decreased, but luckily no room4s in the game are tied to progression or achievements.
Stats from 100000 random seeds before and after these changes:
room4 Stats Before room4 Stats After
A way to increase the spawn frequency of room4s again in zone 0 could be to find a way to fix the position of the start room so that a room3 extending into the bottom row isn't an issue.

Example seeds before and after these changes (open for more detail):
c3jdfxea
Was missing room2ccont, 008, room035, and coffin.

03deisj
coffin was deep in zone 2 and room1lifts was accessible from zone 1.

v80yd02
roompj took the place of start and zone 1 had no room2C.

@ChronoQuote ChronoQuote changed the title Fixes to map generation Fixes/improvements to map generation Sep 15, 2023
After preliminary map generation, some code tries forcing more room1s, room4s, and room2Cs into each zone if necessary. The room1 code scans for empty spaces to turn into room1s, while the room4 & room2C code scan for rooms to extend in such a way to create a room4 or room2C.

The ranges of the room1- and room2C-forcing code were a bit small, so some seeds didn't generate enough room1s or room2Cs even if there was space. Many important rooms (like room2ccont) are room1s or room2Cs, so this is arguably one of the biggest issues with the live game.

Meanwhile, the range of the room4-forcing code was quite big, so extensions would sometimes be performed past zone boundaries or into the outer edges of the map, which (via some other factors) led to issues like SCP-895's chamber being placed deep in the Entrance Zone, or SCP-372's chamber taking the place of the start room.

These changes make the ranges of the room-forcing code as large as they can be without causing issues, thus solving/mitigating the problems mentioned above. As part of these changes,
- The variables controlling the ranges were renamed for clarity (since "zone" and "temp2" for a min and max was extremely cursed) and are now based on the accurate zone transition y-levels given by I_Zone\Transition
- A bunch of extra conditions had to be added to handle the room-forcing code's behavior along the edges of the newly defined regions (e.g. only allowing a room1 to be forced into the bottom row of zone 1 or 2 if it is attached to from above instead of from the side or below)
- The vertical scanning direction of the room2C-forcing code was reversed to decrease the likelihood that, due to the increased vertical range, the room2C containing room2ccont is forced in at the very top of the map right next to an exit gate
- The local ZoneAmount was removed because ZONEAMOUNT already exists as a const and the code that used ZoneAmount was replaced
- An inexplicable five-line gap in the middle of the code was reduced to a one-line gap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants