From f6a592b7f9c86d68c609e45642d3952afbb274e7 Mon Sep 17 00:00:00 2001 From: nhmall Date: Tue, 18 Aug 2026 10:24:35 -0400 Subject: [PATCH] glob nutrition should match owt reduction reported directly to devteam as an impossible() call within eaten_stat() (internal tracking number 3216) --- doc/fixes5-0-1.txt | 2 ++ src/mkobj.c | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/doc/fixes5-0-1.txt b/doc/fixes5-0-1.txt index 56675db80..2feee9be0 100644 --- a/doc/fixes5-0-1.txt +++ b/doc/fixes5-0-1.txt @@ -83,6 +83,8 @@ cmdstr[] buffer was not being initialized in handler_rebind_keys_add() don't catch thrown objects while asleep don't refer to pet as "Your pet" until after the taming process has finished checkpoint fixes (pr #1660 by k21971) +upon return to a level, catch up on remaining nutrition value by the same + percentage as the catch up for the weight Platform- and/or Interface-Specific Fixes diff --git a/src/mkobj.c b/src/mkobj.c index 47bfc4108..2ed92d009 100644 --- a/src/mkobj.c +++ b/src/mkobj.c @@ -1510,7 +1510,7 @@ shrink_glob( shrink = FALSE, gone = FALSE, updinv = FALSE; struct obj *contnr = (obj->where == OBJ_CONTAINED) ? obj->ocontainer : 0, *topcontnr = 0; - unsigned old_top_owt = 0; + unsigned old_top_owt = 0, old_owt = obj->owt; if (!obj->globby) { impossible("shrink_glob for non-glob [%d: %s]?", @@ -1539,12 +1539,25 @@ shrink_glob( obj->owt = 0; /* not required; accurately reflects obj's state */ shrinking_glob_gone(obj); } else { - /* shrank but not gone; reduce remaining weight */ + + /* shrank but not gone; reduce remaining weight + and food-content (if needed) */ obj->owt -= (unsigned) delta; /* when contained, update container's weight (recursively if nested); won't be in a container carried by hero (since catching up for lost time never applies in that situation) but might be in one on floor or one carried by a monster */ + if (old_owt && obj->oeaten) { + unsigned percent_reduction = 100 - ((obj->owt * 100) / old_owt), + oeaten_reduction; + + /* reduce remaining nutrition by same percentage */ + oeaten_reduction = (percent_reduction * obj->oeaten + 50) / 100; + + if (oeaten_reduction <= obj->oeaten) + obj->oeaten -= oeaten_reduction; + + } if (contnr) container_weight(contnr); /* resume regular shrinking */ @@ -1674,6 +1687,8 @@ shrinking_glob_gone(struct obj *obj) { xint16 owhere = obj->where; + /* obfree() should take care of eating_glob() food fixups */ + if (owhere == OBJ_INVENT) { if (obj->owornmask) { remove_worn_item(obj, FALSE);