lufia2ac: prevent "door stairs" and "rare stairs" #2341
Merged
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.
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 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?