]> granicus.if.org Git - nethack/commitdiff
discard migrating monsters when entering endgame
authorPatR <rankin@nethack.org>
Fri, 5 Aug 2022 21:36:11 +0000 (14:36 -0700)
committerPatR <rankin@nethack.org>
Fri, 5 Aug 2022 21:36:11 +0000 (14:36 -0700)
When the hero enters the planes branch, all the rest of the dungeon
gets discarded since it can no longer be reached.  At the time that
that takes place, throw away any migrating monsters waiting to arrive
on any of those levels.

include/extern.h
src/do.c
src/dog.c

index 96fa68f136960d1401c787360c463c21d0fffcb3..43488aa24fc98fcb04eaf5c52688b0e66d733f2d 100644 (file)
@@ -600,6 +600,7 @@ extern void mon_arrive(struct monst *, int);
 extern void mon_catchup_elapsed_time(struct monst *, long);
 extern void keepdogs(boolean);
 extern void migrate_to_level(struct monst *, coordxy, coordxy, coord *);
+extern void discard_migrating_mons(void);
 extern int dogfood(struct monst *, struct obj *);
 extern boolean tamedog(struct monst *, struct obj *);
 extern void abuse_dog(struct monst *);
index 8bb2aab5bb0b8f89bf8f1c2676b3bc10185e159c..5daeecbd576fcfa6e048e5bc2a2273a8c15a7e12 100644 (file)
--- a/src/do.c
+++ b/src/do.c
@@ -1463,6 +1463,8 @@ goto_level(
         /* mark #overview data for all dungeon branches as uninteresting */
         for (l_idx = 0; l_idx < g.n_dgns; ++l_idx)
             remdun_mapseen(l_idx);
+        /* get rid of monsters scheduled to migrate to discarded levels */
+        discard_migrating_mons();
     }
 
     if (Is_rogue_level(newlevel) || Is_rogue_level(&u.uz))
index 064cbd1a51b7a31e4f51bf9380bb534b5ff87e36..a984f03dbc92335c2da56f88d0f3e632d1ea4e02 100644 (file)
--- a/src/dog.c
+++ b/src/dog.c
@@ -843,6 +843,28 @@ migrate_to_level(
         vision_recalc(0);
 }
 
+/* when entering the endgame, levels from the dungeon and its branches are
+   discarded because they can't be reached again; do the same for monsters
+   scheduled to migrate to those levels */
+void
+discard_migrating_mons(void)
+{
+    struct monst *mtmp, **mprev;
+    d_level mdest;
+
+    for (mprev = &g.migrating_mons; (mtmp = *mprev) != 0; ) {
+        mdest.dnum = mtmp->mux;
+        mdest.dlevel = mtmp->muy;
+        /* the Wizard is kept regardless of location so that he is
+           ready to be brought back; nothing should be scheduled to
+           migrate to the endgame but if we find such, we'll keep it */
+        if (!mtmp->iswiz && !In_endgame(&mdest))
+            *mprev = mtmp->nmon; /* remove mtmp from migrating_mons */
+        else
+            mprev = &mtmp->nmon; /* keep mtmp on migrating_mons */
+    }
+}
+
 /* return quality of food; the lower the better */
 /* fungi will eat even tainted food */
 int