]> granicus.if.org Git - nethack/commitdiff
More long worm checks when splitting
authorPasi Kallinen <paxed@alt.org>
Mon, 19 Nov 2018 19:49:49 +0000 (21:49 +0200)
committerPasi Kallinen <paxed@alt.org>
Mon, 19 Nov 2018 19:49:52 +0000 (21:49 +0200)
When a long worm is split into two, perform more checks placing
the segments on the map.

include/extern.h
src/mon.c
src/restore.c
src/worm.c

index 8fd85e91e79c116d9c9dd4dd641f747f76fcf93b..ff0976e185d8d0c0a8058f6768d3067d1368cdcf 100644 (file)
@@ -2835,7 +2835,7 @@ E void FDECL(see_wsegs, (struct monst *));
 E void FDECL(detect_wsegs, (struct monst *, BOOLEAN_P));
 E void FDECL(save_worm, (int, int));
 E void FDECL(rest_worm, (int));
-E void FDECL(place_wsegs, (struct monst *));
+E void FDECL(place_wsegs, (struct monst *, struct monst *));
 E void FDECL(sanity_check_worm, (struct monst *));
 E void FDECL(remove_worm, (struct monst *));
 E void FDECL(place_worm_tail_randomly, (struct monst *, XCHAR_P, XCHAR_P));
index 232992d324845ea5cb0e976e0327daa40cdb3173..56c5da13f887c8416827564b5b7d4d01dee5453e 100644 (file)
--- a/src/mon.c
+++ b/src/mon.c
@@ -1587,7 +1587,7 @@ struct monst *mtmp, *mtmp2;
     if (mtmp != u.usteed) /* don't place steed onto the map */
         place_monster(mtmp2, mtmp2->mx, mtmp2->my);
     if (mtmp2->wormno)      /* update level.monsters[wseg->wx][wseg->wy] */
-        place_wsegs(mtmp2); /* locations to mtmp2 not mtmp. */
+        place_wsegs(mtmp2, NULL); /* locations to mtmp2 not mtmp. */
     if (emits_light(mtmp2->data)) {
         /* since this is so rare, we don't have any `mon_move_light_source' */
         new_light_source(mtmp2->mx, mtmp2->my, emits_light(mtmp2->data),
index f638875b81f7d9f43e198395a7af238d5a333360..f7a1e6a26a4e8af0788001d3ae1c14bcc174cd26 100644 (file)
@@ -1080,7 +1080,7 @@ boolean ghostly;
             set_residency(mtmp, FALSE);
         place_monster(mtmp, mtmp->mx, mtmp->my);
         if (mtmp->wormno)
-            place_wsegs(mtmp);
+            place_wsegs(mtmp, NULL);
 
         /* regenerate monsters while on another level */
         if (!u.uz.dlevel)
index 2a19df2886f9e6e8b5b8428fbd05eddf12da2a81..427ccd04f0261df4cd15ae6f0c2ba0e82ae363bc 100644 (file)
@@ -415,7 +415,7 @@ struct obj *weap;
     wgrowtime[new_wnum] = 0L;    /* trying to call initworm().       */
 
     /* Place the new monster at all the segment locations. */
-    place_wsegs(new_worm);
+    place_wsegs(new_worm, worm);
 
     if (context.mon_moving)
         pline("%s is cut in half.", Monnam(worm));
@@ -556,17 +556,28 @@ int fd;
  *  place_wsegs()
  *
  *  Place the segments of the given worm.  Called from restore.c
+ *  If oldworm is not NULL, assumes the oldworm segments are on map
+ *  in the same location as worm segments
  */
 void
-place_wsegs(worm)
-struct monst *worm;
+place_wsegs(worm, oldworm)
+struct monst *worm, *oldworm;
 {
     struct wseg *curr = wtails[worm->wormno];
 
     /*  if (!mtmp->wormno) return;  bullet proofing */
 
     while (curr != wheads[worm->wormno]) {
-        place_worm_seg(worm, curr->wx, curr->wy);
+        xchar x = curr->wx;
+        xchar y = curr->wy;
+
+        if (oldworm) {
+            if (m_at(x,y) == oldworm)
+                remove_monster(x, y);
+            else
+                impossible("placing worm seg <%i,%i> over another mon", x, y);
+        }
+        place_worm_seg(worm, x, y);
         curr = curr->nseg;
     }
 }