]> granicus.if.org Git - nethack/commitdiff
long worm #stats
authorPatR <rankin@nethack.org>
Sun, 1 May 2016 07:34:36 +0000 (00:34 -0700)
committerPatR <rankin@nethack.org>
Sun, 1 May 2016 07:34:36 +0000 (00:34 -0700)
When #stats shows memory use for monsters, include long worm tails.

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

index 4bee6fcd0b43bb0e1b3409babfc6f0dc1d9f8406..3905c3382243a3f54193b221137580891ed874dc 100644 (file)
@@ -2719,6 +2719,7 @@ E void FDECL(rest_worm, (int));
 E void FDECL(place_wsegs, (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 *));
 E int FDECL(count_wsegs, (struct monst *));
 E boolean FDECL(worm_known, (struct monst *));
 E boolean FDECL(worm_cross, (int, int, int, int));
index 061a3d59e0eea88a968430e70edc3a5045ca17e2..f8f779fc50629a2f5b6f907d4dc75855e74e5790 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -144,7 +144,7 @@ extern void FDECL(show_borlandc_stats, (winid));
 #ifdef DEBUG_MIGRATING_MONS
 STATIC_PTR int NDECL(wiz_migrate_mons);
 #endif
-STATIC_DCL int FDECL(size_monst, (struct monst *));
+STATIC_DCL int FDECL(size_monst, (struct monst *, BOOLEAN_P));
 STATIC_DCL int FDECL(size_obj, (struct obj *));
 STATIC_DCL void FDECL(count_obj, (struct obj *, long *, long *,
                                   BOOLEAN_P, BOOLEAN_P));
@@ -3016,25 +3016,29 @@ long *total_size;
 }
 
 STATIC_OVL int
-size_monst(mtmp)
+size_monst(mtmp, incl_wsegs)
 struct monst *mtmp;
+boolean incl_wsegs;
 {
-    int sz = (int) sizeof(struct monst);
+    int sz = (int) sizeof (struct monst);
+
+    if (mtmp->wormno && incl_wsegs)
+        sz += size_wseg(mtmp);
 
     if (mtmp->mextra) {
-        sz += (int) sizeof(struct mextra);
+        sz += (int) sizeof (struct mextra);
         if (MNAME(mtmp))
             sz += (int) strlen(MNAME(mtmp)) + 1;
         if (EGD(mtmp))
-            sz += (int) sizeof(struct egd);
+            sz += (int) sizeof (struct egd);
         if (EPRI(mtmp))
-            sz += (int) sizeof(struct epri);
+            sz += (int) sizeof (struct epri);
         if (ESHK(mtmp))
-            sz += (int) sizeof(struct eshk);
+            sz += (int) sizeof (struct eshk);
         if (EMIN(mtmp))
-            sz += (int) sizeof(struct emin);
+            sz += (int) sizeof (struct emin);
         if (EDOG(mtmp))
-            sz += (int) sizeof(struct edog);
+            sz += (int) sizeof (struct edog);
         /* mextra->mcorpsenm doesn't point to more memory */
     }
     return sz;
@@ -3052,11 +3056,13 @@ long *total_size;
     char buf[BUFSZ];
     long count, size;
     struct monst *mon;
+    /* mon->wormno means something different for migrating_mons and mydogs */
+    boolean incl_wsegs = !strcmpi(src, "fmon");
 
     count = size = 0L;
     for (mon = chain; mon; mon = mon->nmon) {
         count++;
-        size += size_monst(mon);
+        size += size_monst(mon, incl_wsegs);
     }
     if (count || size || force) {
         *total_count += count;
index bf742ad2b7e96fed651cce37f4a616d631e3cc77..d3e9c97dedbbf84905711b1cccca250437acf23c 100644 (file)
--- a/src/mon.c
+++ b/src/mon.c
@@ -1580,7 +1580,10 @@ struct monst **monst_list; /* &migrating_mons or &mydogs or null */
             seemimic(mon);
     }
 
-    remove_monster(mx, my);
+    if (mon->wormno)
+        remove_worm(mon);
+    else
+        remove_monster(mx, my);
 
     if (mon == fmon) {
         fmon = fmon->nmon;
index 839b0193e8235ab8655d2db8b71b63ca2b724c8e..ac69ea72b235e6a7a2e10761183ce1c723ae4c11 100644 (file)
@@ -677,6 +677,14 @@ register xchar *nx, *ny;
               : (y > 1 ? (y < ROWNO ? (rn2(3) - 1) : -rn2(2)) : rn2(2)));
 }
 
+/* for size_monst(cmd.c) to support #stats */
+int
+size_wseg(worm)
+struct monst *worm;
+{
+    return (int) (count_wsegs(worm) * sizeof (struct wseg));
+}
+
 /*  count_wsegs()
  *  returns the number of segments that a worm has.
  */