]> granicus.if.org Git - nethack/commitdiff
Keep swamp within the room boundaries
authorPasi Kallinen <paxed@alt.org>
Fri, 9 Jul 2021 15:34:42 +0000 (18:34 +0300)
committerPasi Kallinen <paxed@alt.org>
Fri, 9 Jul 2021 15:34:46 +0000 (18:34 +0300)
If a swamp special room was generated in an irregular room, it could
go outside the boundaries of that room.

Fixes #546

src/mkroom.c

index 60448e078f1623a6aef789b53191333de488f570..1a791e08fef8a1cdf5f4aa03b8d94705491d8b7a 100644 (file)
@@ -512,6 +512,7 @@ mkswamp(void) /* Michiel Huisjes & Fred de Wilde */
 {
     register struct mkroom *sroom;
     register int sx, sy, i, eelct = 0;
+    int rmno;
 
     for (i = 0; i < 5; i++) { /* turn up to 5 rooms swampy */
         sroom = &g.rooms[rn2(g.nroom)];
@@ -519,10 +520,14 @@ mkswamp(void) /* Michiel Huisjes & Fred de Wilde */
             || has_dnstairs(sroom))
             continue;
 
+        rmno = (sroom - g.rooms) + ROOMOFFSET;
+
         /* satisfied; make a swamp */
         sroom->rtype = SWAMP;
         for (sx = sroom->lx; sx <= sroom->hx; sx++)
-            for (sy = sroom->ly; sy <= sroom->hy; sy++)
+            for (sy = sroom->ly; sy <= sroom->hy; sy++) {
+                if (!IS_ROOM(levl[sx][sy].typ) || levl[sx][sy].roomno != rmno)
+                    continue;
                 if (!OBJ_AT(sx, sy) && !MON_AT(sx, sy) && !t_at(sx, sy)
                     && !nexttodoor(sx, sy)) {
                     if ((sx + sy) % 2) {
@@ -541,6 +546,7 @@ mkswamp(void) /* Michiel Huisjes & Fred de Wilde */
                         (void) makemon(mkclass(S_FUNGUS, 0), sx, sy,
                                        NO_MM_FLAGS);
                 }
+            }
         g.level.flags.has_swamp = 1;
     }
 }