From: PatR Date: Sun, 2 May 2021 01:36:46 +0000 (-0700) Subject: fix #K3317 - warning when eating corpse X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c0c7190f74a328fe2d2a6ab169bcd1630bf114c2;p=nethack fix #K3317 - warning when eating corpse 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 --- diff --git a/doc/fixes37.0 b/doc/fixes37.0 index 2fa7ad50d..77318ab9b 100644 --- a/doc/fixes37.0 +++ b/doc/fixes37.0 @@ -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 corpse was set to revive as a zombie and corpse was partly + eaten at revival time and monster is defined as providing more + nutrition that 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 diff --git a/src/do.c b/src/do.c index 74333dd89..72270855c 100644 --- 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); diff --git a/src/mkobj.c b/src/mkobj.c index 71295af3d..8fef52db3 100644 --- a/src/mkobj.c +++ b/src/mkobj.c @@ -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 obj* obj, 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 corpse revives as a 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: