From 9e291234f54f701d6ece880dbff10ac343ee7a0d Mon Sep 17 00:00:00 2001 From: copperwater Date: Sun, 21 May 2023 18:16:15 -0400 Subject: [PATCH] Implement builds_up correctly, resolving its FIXME The FIXME comment noted that builds_up would return an incorrect false value for a dungeon branch that builds upwards but is only 1 level, but that this is a latent problem because no such branch exists in NetHack. Such a branch does exist in xNetHack, and it causes the debug fuzzer to crash ("mon_arrive: no corresponding portal" because it can't find the correct-direction stairs), so I figured I might as well fix it upstream. --- src/dungeon.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/dungeon.c b/src/dungeon.c index d03ca20bc..510a7a3f1 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -1413,12 +1413,19 @@ boolean builds_up(d_level *lev) { dungeon *dptr = &gd.dungeons[lev->dnum]; - /* - * FIXME: this misclassifies a single level branch reached via stairs - * from below. Saving grace is that no such branches currently exist. - */ - return (boolean) (dptr->num_dunlevs > 1 - && dptr->entry_lev == dptr->num_dunlevs); + branch *br; + if (dptr->num_dunlevs > 1) + return (boolean) (dptr->entry_lev == dptr->num_dunlevs); + /* else, single-level branch; find the branch connection that connects this + * dungeon from a parent dungeon and determine whether it builds up from + * that */ + for (br = gb.branches; br; br = br->next) { + if (on_level(lev, &br->end2)) { + return br->end1_up; + } + } + impossible("builds_up: can't find branch for dungeon %d", lev->dnum); + return FALSE; } /* goto the next level (or appropriate dungeon) */