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

lufia2ac: prevent "door stairs" and "rare stairs" #2341

Merged
merged 1 commit into from
Oct 23, 2023

Conversation

el-u
Copy link
Collaborator

@el-u el-u commented Oct 22, 2023

What is this fixing or adding?

(PR tries to fix a bug of the vanilla game.) The floors of the Ancient Cave are randomly generated, but generally the layout follows some rules. For example, the stairs leading to the next floor can only be placed in certain spots. In particular, they cannot usually be placed near doors. However, the floor generation algorithm is imperfect: it does not search thoroughly enough for a valid spot to place the stairs. On rare occasions, this can lead to one of the following two types of anomalies:

door stairs rare stairs
stairs directly in front of a door stairs one tile behind a doorway
bug_door_stairs bug_rare_stairs

Door stairs are obviously undesirable; they can make it impossible to fully explore the current floor because one cannot pass through the door without prematurely triggering the exit to the next level. The second kind, rare stairs, are not inherently bad, but it is clear that the original algorithm treats them exactly like door stairs and makes some (but apparently not enough) effort to try prevent them.

This PR introduces some new code that runs only when the original floor generation algorithm reaches the point where it "gives up" trying to select a safe spot to place the stairs. It then performs an exhaustive scan of the whole floor canvas, counts all nodes that are valid for stair placement, and randomly chooses one of them. (While it is theoretically possible to devise floor geometries that would have zero good positions for stairs, it is unclear whether the game could really create such layouts in practice. Nevertheless, should such an extreme case arise, the new algorithm includes as a fallback a second, less restrictive pass that would allow rare stairs in these special situations while still avoiding the "greater evil" of door stairs.)

How was this tested?

  1. This change was part of the build that we ran for https://discord.com/channels/731205301247803413/1135115153315221504/1135115153315221504
  2. Additionally, I wrote some ASM to detect these kinds of floors and then let it run the floor generation algorithm in an endless loop, set to break out only if an anomalous floor was found. When applied to the old floor generation algorithm, this would take on average less than an hour to get a hit. With the change from this PR applied, I could not find a single anomalous floor even after simulating over 500 hours of SNES generating random floors.

@ThePhar ThePhar added the is: bug/fix Issues that are reporting bugs or pull requests that are fixing bugs. label Oct 22, 2023
@Berserker66 Berserker66 merged commit 8109d4a into ArchipelagoMW:main Oct 23, 2023
7 checks passed
@el-u el-u deleted the lufia2ac-main branch October 23, 2023 22:44
FlySniper pushed a commit to FlySniper/Archipelago that referenced this pull request Nov 14, 2023
Jouramie pushed a commit to Jouramie/Archipelago that referenced this pull request Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is: bug/fix Issues that are reporting bugs or pull requests that are fixing bugs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants