fix pull request #504 - partly eaten food

that has no nutritional value.  Prevent applying the partly eaten
attribute to wished for food if the full nutrition isn't at least 2.
The problem case was 0 nutrition wraith corpse, yielding "partly
eaten food (1) more nutritious than untouched food (0)" when setting
the corpse's weight.  That one was possible in 3.6.x, unlike corpse
that was actually partly eaten and then revived as a zombie (which
was just fixed for triggering the same warning).

Wishing really ought to ignore "partly eaten" for anything that is
normally eaten in one bite but I'm not sure how to handle that.

Fixes #504
This commit is contained in:
PatR
2021-05-06 17:52:30 -07:00
parent ad7f2afef9
commit cecda13ab2
4 changed files with 38 additions and 13 deletions
+3 -1
View File
@@ -1,4 +1,4 @@
NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.525 $ $NHDT-Date: 1620329775 2021/05/06 19:36:15 $ NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.526 $ $NHDT-Date: 1620348705 2021/05/07 00:51:45 $
General Fixes and Modified Features General Fixes and Modified Features
----------------------------------- -----------------------------------
@@ -502,6 +502,8 @@ any blessed key was behaving as if was the rogue's Master Key when unlocking
when an unseen non-pet picks up or uses an item, hero loses known/dknown/ when an unseen non-pet picks up or uses an item, hero loses known/dknown/
bknown/cknown/lknown memory of that item (so becomes unidentified; in bknown/cknown/lknown memory of that item (so becomes unidentified; in
particular, player won't be asked what to call unseen thrown potion) particular, player won't be asked what to call unseen thrown potion)
wishing for a partly eaten wraith corpse yielded "partly eaten food (1) more
nutritious than untouched food (0)"
Fixes to 3.7.0-x Problems that Were Exposed Via git Repository Fixes to 3.7.0-x Problems that Were Exposed Via git Repository
+2 -1
View File
@@ -1,4 +1,4 @@
/* NetHack 3.7 extern.h $NHDT-Date: 1620329773 2021/05/06 19:36:13 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.968 $ */ /* NetHack 3.7 extern.h $NHDT-Date: 1620348705 2021/05/07 00:51:45 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.969 $ */
/* Copyright (c) Steve Creps, 1988. */ /* Copyright (c) Steve Creps, 1988. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -647,6 +647,7 @@ extern boolean is_edible(struct obj *);
extern void init_uhunger(void); extern void init_uhunger(void);
extern int Hear_again(void); extern int Hear_again(void);
extern void reset_eat(void); extern void reset_eat(void);
extern unsigned obj_nutrition(struct obj *);
extern int doeat(void); extern int doeat(void);
extern int use_tin_opener(struct obj *); extern int use_tin_opener(struct obj *);
extern void gethungry(void); extern void gethungry(void);
+22 -4
View File
@@ -1,4 +1,4 @@
/* NetHack 3.7 eat.c $NHDT-Date: 1603507384 2020/10/24 02:43:04 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.235 $ */ /* NetHack 3.7 eat.c $NHDT-Date: 1620348708 2021/05/07 00:51:48 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.242 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2012. */ /*-Copyright (c) Robert Patrick Rankin, 2012. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -14,7 +14,6 @@ static int unfaint(void);
static const char *food_xname(struct obj *, boolean); static const char *food_xname(struct obj *, boolean);
static void choke(struct obj *); static void choke(struct obj *);
static void recalc_wt(void); static void recalc_wt(void);
static unsigned obj_nutrition(struct obj *);
static struct obj *touchfood(struct obj *); static struct obj *touchfood(struct obj *);
static void do_reset_eat(void); static void do_reset_eat(void);
static void done_eating(boolean); static void done_eating(boolean);
@@ -293,7 +292,7 @@ reset_eat(void)
} }
/* base nutrition of a food-class object */ /* base nutrition of a food-class object */
static unsigned unsigned
obj_nutrition(struct obj *otmp) obj_nutrition(struct obj *otmp)
{ {
unsigned nut = (otmp->otyp == CORPSE) ? mons[otmp->corpsenm].cnutrit unsigned nut = (otmp->otyp == CORPSE) ? mons[otmp->corpsenm].cnutrit
@@ -1012,7 +1011,8 @@ cpostfx(int pm)
Hallucination Hallucination
? "You suddenly dread being peeled and mimic %s again!" ? "You suddenly dread being peeled and mimic %s again!"
: "You now prefer mimicking %s again.", : "You now prefer mimicking %s again.",
an(Upolyd ? pmname(g.youmonst.data, Ugender) : g.urace.noun)); an(Upolyd ? pmname(g.youmonst.data, Ugender)
: g.urace.noun));
g.eatmbuf = dupstr(buf); g.eatmbuf = dupstr(buf);
g.nomovemsg = g.eatmbuf; g.nomovemsg = g.eatmbuf;
g.afternmv = eatmdone; g.afternmv = eatmdone;
@@ -3373,6 +3373,24 @@ eaten_stat(int base, struct obj *obj)
void void
consume_oeaten(struct obj *obj, int amt) consume_oeaten(struct obj *obj, int amt)
{ {
if (!obj_nutrition(obj)) {
char itembuf[40];
int otyp = obj->otyp;
if (otyp == CORPSE || otyp == EGG || otyp == TIN) {
Strcpy(itembuf, (otyp == CORPSE) ? "corpse"
: (otyp == EGG) ? "egg"
: (otyp == TIN) ? "tin" : "other?");
Sprintf(eos(itembuf), " [%d]", obj->corpsenm);
} else {
Sprintf(itembuf, "%d", otyp);
}
impossible(
"oeaten: attempting to set 0 nutrition food (%s) partially eaten",
itembuf);
return;
}
/* /*
* This is a hack to try to squelch several long standing mystery * This is a hack to try to squelch several long standing mystery
* food bugs. A better solution would be to rewrite the entire * food bugs. A better solution would be to rewrite the entire
+11 -7
View File
@@ -1,4 +1,4 @@
/* NetHack 3.7 objnam.c $NHDT-Date: 1612053751 2021/01/31 00:42:31 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.313 $ */ /* NetHack 3.7 objnam.c $NHDT-Date: 1620348711 2021/05/07 00:51:51 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.315 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2011. */ /*-Copyright (c) Robert Patrick Rankin, 2011. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -4515,12 +4515,16 @@ readobjnam(char* bp, struct obj* no_wish)
} }
if (d.halfeaten && d.otmp->oclass == FOOD_CLASS) { if (d.halfeaten && d.otmp->oclass == FOOD_CLASS) {
if (d.otmp->otyp == CORPSE) unsigned nut = obj_nutrition(d.otmp);
d.otmp->oeaten = mons[d.otmp->corpsenm].cnutrit;
else /* do this adjustment before setting up object's weight; skip
d.otmp->oeaten = objects[d.otmp->otyp].oc_nutrition; "partly eaten" for food with 0 nutrition (wraith corpse) or for
/* (do this adjustment before setting up object's weight) */ anything that couldn't take more than one bite (1 nutrition;
consume_oeaten(d.otmp, 1); ought to check for one-bite instead but that's complicated) */
if (nut > 1) {
d.otmp->oeaten = nut;
consume_oeaten(d.otmp, 1);
}
} }
d.otmp->owt = weight(d.otmp); d.otmp->owt = weight(d.otmp);
if (d.very && d.otmp->otyp == HEAVY_IRON_BALL) if (d.very && d.otmp->otyp == HEAVY_IRON_BALL)