]> granicus.if.org Git - nethack/commitdiff
Add sanity checking for long worms
authorPasi Kallinen <paxed@alt.org>
Fri, 16 Jun 2017 15:27:25 +0000 (18:27 +0300)
committerPasi Kallinen <paxed@alt.org>
Fri, 16 Jun 2017 15:27:25 +0000 (18:27 +0300)
include/extern.h
src/mon.c
src/worm.c

index 72df6d58dee17fd5ec673a096ab580d1ef24be7b..6b92d680dbea2110121fc09ee138a17192b9a0f6 100644 (file)
@@ -2761,6 +2761,7 @@ 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(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));
 E int FDECL(size_wseg, (struct monst *));
index 33a84372e2049823416d7a11ab8f0a9f4f5e2907..69d64490b32a3af7d01b83aa421b744bb1513a5f 100644 (file)
--- a/src/mon.c
+++ b/src/mon.c
@@ -93,6 +93,8 @@ mon_sanity_check()
         else if (level.monsters[x][y] != mtmp)
             impossible("mon (%s) at <%d,%d> is not there!",
                        fmt_ptr((genericptr_t) mtmp), x, y);
+        else if (mtmp->wormno)
+            sanity_check_worm(mtmp);
     }
 
     for (x = 0; x < COLNO; x++)
index ac69ea72b235e6a7a2e10761183ce1c723ae4c11..4e5d12dd83d5773955f7902b13c0966c35e90476 100644 (file)
@@ -569,6 +569,28 @@ struct monst *worm;
     }
 }
 
+void
+sanity_check_worm(worm)
+struct monst *worm;
+{
+    struct wseg *curr;
+
+    if (!worm)
+        panic("no worm!");
+    if (!worm->wormno)
+        panic("not a worm?!");
+
+    curr = wtails[worm->wormno];
+
+    while (curr != wheads[worm->wormno]) {
+        if (!isok(curr->wx, curr->wy))
+            panic("worm seg not isok");
+        if (level.monsters[curr->wx][curr->wy] != worm)
+            panic("worm not at seg location");
+        curr = curr->nseg;
+    }
+}
+
 /*
  *  remove_worm()
  *