]> granicus.if.org Git - nethack/commitdiff
Fill special rooms recursively rather than only at top level
authorcopperwater <aosdict@gmail.com>
Thu, 21 May 2020 12:48:24 +0000 (08:48 -0400)
committerPasi Kallinen <paxed@alt.org>
Sun, 27 Sep 2020 15:54:15 +0000 (18:54 +0300)
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.

src/sp_lev.c

index 258fa8f66effda8c1333b4771b824dd2cac18c51..39e2e037dfef51c80b00cc1ab760500b61258645 100755 (executable)
@@ -1041,11 +1041,7 @@ fill_special_rooms()
     int tmpi, m;
 
     for (tmpi = 0; tmpi < g.nroom; tmpi++) {
-        if (g.rooms[tmpi].needfill)
-            fill_special_room(&g.rooms[tmpi]);
-        for (m = 0; m < g.rooms[tmpi].nsubrooms; m++)
-            if (g.rooms[tmpi].sbrooms[m]->needfill)
-                fill_special_room(g.rooms[tmpi].sbrooms[m]);
+        fill_special_room(&g.rooms[tmpi]);
     }
 }
 
@@ -2685,6 +2681,15 @@ void
 fill_special_room(croom)
 struct mkroom *croom;
 {
+    int i;
+
+    /* First recurse into subrooms. We don't want to block an ordinary room with
+     * a special subroom from having the subroom filled, or an unfilled outer
+     * room preventing a special subroom from being filled. */
+    for (i = 0; i < croom->nsubrooms; ++i) {
+        fill_special_room(croom->sbrooms[i]);
+    }
+
     if (!croom || croom->rtype == OROOM || croom->rtype == THEMEROOM
         || croom->needfill == FILL_NONE)
         return;