]> granicus.if.org Git - nethack/commitdiff
more wormgone
authorPatR <rankin@nethack.org>
Sun, 15 May 2022 01:10:42 +0000 (18:10 -0700)
committerPatR <rankin@nethack.org>
Sun, 15 May 2022 01:10:42 +0000 (18:10 -0700)
When wormgone() takes a long worm off the map, clear its stale mx,my
coordinates.  None of its callers need those anymore.

Also a bit of potential long worm clean up that occurred to me when
I looked at object bypass handling.  Expected to be a no-op here.

src/dog.c
src/worm.c
src/worn.c

index 965b21741506d02711d27d19dcf04ce0e51e560f..e05968d90aee80bd85a028fea8dca45e22f4a642 100644 (file)
--- a/src/dog.c
+++ b/src/dog.c
@@ -1,4 +1,4 @@
-/* NetHack 3.7 dog.c   $NHDT-Date: 1652524227 2022/05/14 10:30:27 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.119 $ */
+/* NetHack 3.7 dog.c   $NHDT-Date: 1652577033 2022/05/15 01:10:33 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.120 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2011. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -609,9 +609,7 @@ mon_leave(struct monst *mtmp)
            more segments than can fit in that field gets truncated */
         num_segs = min(cnt, MAX_NUM_WORMS - 1);
         wormgone(mtmp); /* discard tail segments, take head off map */
-        /* this used to be place_monster() but relmon() doesn't
-           need that as long as coordinates reflect actual state */
-        mtmp->mx = mtmp->my = 0; /* off normal map */
+        /* mtmp->mx,mtmp->my is now 0,0 */
     }
 
     return num_segs;
@@ -722,14 +720,13 @@ migrate_to_level(
     xchar xyflags, mx = mtmp->mx, my = mtmp->my; /* <mx,my> needed below */
     int num_segs; /* count of worm segments */
 
-    /* prepare to take mtmp off the map */
-    num_segs = mon_leave(mtmp);
-
     if (mtmp->mleashed) {
         mtmp->mtame--;
         m_unleash(mtmp, TRUE);
     }
 
+    /* prepare to take mtmp off the map */
+    num_segs = mon_leave(mtmp);
     /* take off map and move mtmp from fmon list to migrating_mons */
     relmon(mtmp, &g.migrating_mons); /* mtmp->mx,my get changed to 0,0 */
     mtmp->mstate |= MON_MIGRATING;
index 53561657d226ad7ef22cef768188704a10ff4f51..188a053f9b526a87859fe4f6c68b3d93a7ab5a5a 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 worm.c  $NHDT-Date: 1608236444 2020/12/17 20:20:44 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.49 $ */
+/* NetHack 3.7 worm.c  $NHDT-Date: 1652577033 2022/05/15 01:10:33 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.55 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2009. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -297,23 +297,38 @@ worm_nomove(struct monst *worm)
 /*
  *  wormgone()
  *
- *  Check for mon->wormno before calling this function!
+ *  Kill a worm tail.  Also takes the head off the map.  Caller needs to
+ *  keep track of what its coordinates were if planning to put it back.
  *
- *  Kill a worm tail.
+ *  Should only be called when mon->wormno is non-zero.
  */
 void
 wormgone(struct monst *worm)
 {
     int wnum = worm->wormno;
 
-    worm->wormno = 0;
-    /*  This will also remove the real monster (ie 'w') from the its
-     *  position in level.monsters[][].
+    if (!wnum) /* note: continuing with wnum==0 runs to completion */
+        impossible("wormgone: wormno is 0");
+
+    worm->wormno = 0; /* still a long worm but doesn't grow/shrink anymore */
+    /*
+     *  This will also remove the real monster (ie 'w') from the its
+     *  position in level.monsters[][].  (That happens when removing
+     *  the hidden tail segment which is co-located with the head.)
      */
     toss_wsegs(wtails[wnum], TRUE);
+    worm->mx = worm->my = 0; /* 'worm' is no longer on map but has not
+                              * been killed off; caller might put it back */
 
     wheads[wnum] = wtails[wnum] = (struct wseg *) 0;
     wgrowtime[wnum] = 0L;
+
+    /* we don't expect to encounter this here but check for it anyway;
+       when a long worm gets created by a polymorph zap, it gets flagged
+       with MCORPSENM()==PM_LONG_WORM so that the same zap won't trigger
+       another polymorph if it hits the new tail */
+    if (worm->data == &mons[PM_LONG_WORM] && has_mcorpsenm(worm))
+        MCORPSENM(worm) = NON_PM; /* not polymorph-proof */
 }
 
 /*
index 74578fc904902c19abdb52a836d783d1395e3dd3..9e704a8c052df28904c7988ac11dba1279dcac12 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 worn.c  $NHDT-Date: 1649529637 2022/04/09 18:40:37 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.82 $ */
+/* NetHack 3.7 worn.c  $NHDT-Date: 1652577035 2022/05/15 01:10:35 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.84 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2013. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -860,8 +860,9 @@ bypass_obj(struct obj *obj)
 
 /* set or clear the bypass bit in a list of objects */
 void
-bypass_objlist(struct obj *objchain,
-               boolean on) /* TRUE => set, FALSE => clear */
+bypass_objlist(
+    struct obj *objchain,
+    boolean on) /* TRUE => set, FALSE => clear */
 {
     if (on && objchain)
         g.context.bypasses = TRUE;