]> granicus.if.org Git - nethack/commitdiff
fix #K3317 - warning when eating corpse
authorPatR <rankin@nethack.org>
Sun, 2 May 2021 01:36:46 +0000 (18:36 -0700)
committerPatR <rankin@nethack.org>
Sun, 2 May 2021 01:36:46 +0000 (18:36 -0700)
The report was misleading because the warning about partly eaten
food being more nutritious than untouched food was actually given
when the partly eaten corpse was used to calculate hit points of
the new monster as the corpse was reviving as a zombie, rather
than when a bite was taken from it.  Pull request #497 had correct
analysis and a fix, although I've put the fix in a different place.

Closes #497

doc/fixes37.0
src/do.c
src/mkobj.c

index 2fa7ad50d9f9124f59b6fd5818fd9ca7aff7df69..77318ab9b75fc07ee47f225932adc87c6747194f 100644 (file)
@@ -1,4 +1,4 @@
-NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.518 $ $NHDT-Date: 1619640466 2021/04/28 20:07:46 $
+NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.519 $ $NHDT-Date: 1619919402 2021/05/02 01:36:42 $
 
 General Fixes and Modified Features
 -----------------------------------
@@ -637,6 +637,11 @@ if an invisible hero managed to convert an unaligned altar to an aligned one
        with color enabled, altar wasn't immediately redrawn with new color
 repair some regressions to (a)pply introduced by "getobj refactor" patch
 fix ^X feedback when held typo: "unseen createure" -> "unseen creature"
+if a <foo> corpse was set to revive as a <foo> zombie and corpse was partly
+       eaten at revival time and monster <foo> is defined as providing more
+       nutrition that <foo> zombie, oeaten_stat() could give the warning
+       "partly eaten food more nutritious than untouched food" when used to
+       calculate zombie's hit points (depended upon how much had been eaten)
 
 curses: 'msg_window' option wasn't functional for curses unless the binary
        also included tty support
index 74333dd895b17754802eccfce869fddb086cb7bc..72270855c1286894be397b64d01b573c7cf3c8bf 100644 (file)
--- a/src/do.c
+++ b/src/do.c
@@ -1,4 +1,4 @@
-/* NetHack 3.7 do.c    $NHDT-Date: 1608673689 2020/12/22 21:48:09 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.256 $ */
+/* NetHack 3.7 do.c    $NHDT-Date: 1619919402 2021/05/02 01:36:42 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.267 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Derek S. Ray, 2015. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -1969,7 +1969,7 @@ zombify_mon(anything *arg, long timeout)
         if (has_omonst(body))
             free_omonst(body);
 
-        body->corpsenm = zmon;
+        set_corpsenm(body, zmon);
         revive_mon(arg, timeout);
     } else {
         rot_corpse(arg, timeout);
index 71295af3dd44dfbc7124e62bc34e28a459017d77..8fef52db36ad1fed5a801143f0ccb0df280002c6 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 mkobj.c $NHDT-Date: 1606343579 2020/11/25 22:32:59 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.191 $ */
+/* NetHack 3.7 mkobj.c $NHDT-Date: 1619919403 2021/05/02 01:36:43 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.198 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Derek S. Ray, 2015. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -1060,7 +1060,7 @@ mksobj(int otyp, boolean init, boolean artif)
 
 /*
  * Several areas of the code made direct reassignments
- * to obj->corpsenm. Because some special handling is
+ * to obj->corpsenm.  Because some special handling is
  * required in certain cases, place that handling here
  * and call this routine in place of the direct assignment.
  *
@@ -1079,18 +1079,35 @@ mksobj(int otyp, boolean init, boolean artif)
  *
  */
 void
-set_corpsenm(struct objobj, int id)
+set_corpsenm(struct obj *obj, int id)
 {
+    int old_id = obj->corpsenm;
     long when = 0L;
 
     if (obj->timed) {
-        if (obj->otyp == EGG)
+        if (obj->otyp == EGG) {
             when = stop_timer(HATCH_EGG, obj_to_any(obj));
-        else {
+        else {
             when = 0L;
             obj_stop_timers(obj); /* corpse or figurine */
         }
     }
+    /* oeaten is used to determine how much nutrition is left in
+       multiple-bite food and also used to derive how many hit points
+       a creature resurrected from a partly eaten corpse gets; latter
+       is of interest when a <foo> corpse revives as a <foo> zombie
+       in case they are defined with different mons[].cnutrit values */
+    if (obj->otyp == CORPSE && obj->oeaten != 0
+        /* when oeaten is non-zero, index old_id can't be NON_PM
+           and divisor mons[old_id].cnutrit can't be zero */
+        && mons[old_id].cnutrit != mons[id].cnutrit) {
+        /* oeaten and cnutrit are unsigned; theoretically that could
+           be 16 bits and the calculation might overflow, so force long */
+        obj->oeaten = (unsigned) ((long) obj->oeaten
+                                  * (long) mons[id].cnutrit
+                                  / (long) mons[old_id].cnutrit);
+    }
+
     obj->corpsenm = id;
     switch (obj->otyp) {
     case CORPSE: