Split eating non-food into separate function

This commit is contained in:
Pasi Kallinen
2023-03-19 15:12:08 +02:00
parent bf3e784798
commit e29bfcab54

162
src/eat.c
View File

@@ -33,6 +33,7 @@ static void fprefx(struct obj *);
static void fpostfx(struct obj *);
static int bite(void);
static int edibility_prompts(struct obj *);
static int doeat_nonfood(struct obj *);
static int tinopen_ok(struct obj *);
static int rottenfood(struct obj *);
static void eatspecial(void);
@@ -2607,13 +2608,95 @@ edibility_prompts(struct obj *otmp)
return 0;
}
static int
doeat_nonfood(struct obj *otmp)
{
int basenutrit; /* nutrition of full item */
int ll_conduct = 0;
boolean nodelicious = FALSE;
int material;
gc.context.victual.reqtime = 1;
gc.context.victual.piece = otmp;
gc.context.victual.o_id = otmp->o_id;
/* Don't split it, we don't need to if it's 1 move */
gc.context.victual.usedtime = 0;
gc.context.victual.canchoke = (u.uhs == SATIATED);
/* Note: gold weighs 1 pt. for each 1000 pieces (see
pickup.c) so gold and non-gold is consistent. */
if (otmp->oclass == COIN_CLASS)
basenutrit = ((otmp->quan > 200000L) ? 2000
: (int) (otmp->quan / 100L));
else if (otmp->oclass == BALL_CLASS || otmp->oclass == CHAIN_CLASS)
basenutrit = weight(otmp);
/* oc_nutrition is usually weight anyway */
else
basenutrit = objects[otmp->otyp].oc_nutrition;
#ifdef MAIL_STRUCTURES
if (otmp->otyp == SCR_MAIL) {
basenutrit = 0;
nodelicious = TRUE;
}
#endif
gc.context.victual.nmod = basenutrit;
gc.context.victual.eating = 1; /* needed for lesshungry() */
if (!u.uconduct.food++) {
ll_conduct++;
livelog_printf(LL_CONDUCT, "ate for the first time (%s)",
food_xname(otmp, FALSE));
}
material = objects[otmp->otyp].oc_material;
if (material == LEATHER || material == BONE
|| material == DRAGON_HIDE || material == WAX) {
if (!u.uconduct.unvegan++ && !ll_conduct) {
livelog_printf(LL_CONDUCT,
"consumed animal products for the first time, by eating %s",
an(food_xname(otmp, FALSE)));
ll_conduct++;
}
if (material != WAX) {
if (!u.uconduct.unvegetarian && !ll_conduct)
livelog_printf(LL_CONDUCT,
"tasted meat by-products for the first time, by eating %s",
an(food_xname(otmp, FALSE)));
violated_vegetarian();
}
}
if (otmp->cursed) {
(void) rottenfood(otmp);
nodelicious = TRUE;
} else if (objects[otmp->otyp].oc_material == PAPER)
nodelicious = TRUE;
if (otmp->oclass == WEAPON_CLASS && otmp->opoisoned) {
pline("Ecch - that must have been poisonous!");
if (!Poison_resistance) {
poison_strdmg(rnd(4), rnd(15), xname(otmp), KILLED_BY_AN);
} else
You("seem unaffected by the poison.");
} else if (!nodelicious) {
pline("%s%s is delicious!",
(obj_is_pname(otmp)
&& otmp->oartifact < ART_ORB_OF_DETECTION)
? ""
: "This ",
(otmp->oclass == COIN_CLASS)
? foodword(otmp)
: singular(otmp, xname));
}
eatspecial();
return ECMD_TIME;
}
/* the #eat command */
int
doeat(void)
{
struct obj *otmp;
int basenutrit; /* nutrition of full item */
boolean dont_start = FALSE, nodelicious = FALSE,
boolean dont_start = FALSE,
already_partly_eaten;
int ll_conduct = 0;
@@ -2711,82 +2794,9 @@ doeat(void)
trycall(otmp);
return ECMD_TIME;
}
if (otmp->oclass != FOOD_CLASS) {
int material;
if (otmp->oclass != FOOD_CLASS)
return doeat_nonfood(otmp);
gc.context.victual.reqtime = 1;
gc.context.victual.piece = otmp;
gc.context.victual.o_id = otmp->o_id;
/* Don't split it, we don't need to if it's 1 move */
gc.context.victual.usedtime = 0;
gc.context.victual.canchoke = (u.uhs == SATIATED);
/* Note: gold weighs 1 pt. for each 1000 pieces (see
pickup.c) so gold and non-gold is consistent. */
if (otmp->oclass == COIN_CLASS)
basenutrit = ((otmp->quan > 200000L) ? 2000
: (int) (otmp->quan / 100L));
else if (otmp->oclass == BALL_CLASS || otmp->oclass == CHAIN_CLASS)
basenutrit = weight(otmp);
/* oc_nutrition is usually weight anyway */
else
basenutrit = objects[otmp->otyp].oc_nutrition;
#ifdef MAIL_STRUCTURES
if (otmp->otyp == SCR_MAIL) {
basenutrit = 0;
nodelicious = TRUE;
}
#endif
gc.context.victual.nmod = basenutrit;
gc.context.victual.eating = 1; /* needed for lesshungry() */
if (!u.uconduct.food++) {
ll_conduct++;
livelog_printf(LL_CONDUCT, "ate for the first time (%s)",
food_xname(otmp, FALSE));
}
material = objects[otmp->otyp].oc_material;
if (material == LEATHER || material == BONE
|| material == DRAGON_HIDE || material == WAX) {
if (!u.uconduct.unvegan++ && !ll_conduct) {
livelog_printf(LL_CONDUCT,
"consumed animal products for the first time, by eating %s",
an(food_xname(otmp, FALSE)));
ll_conduct++;
}
if (material != WAX) {
if (!u.uconduct.unvegetarian && !ll_conduct)
livelog_printf(LL_CONDUCT,
"tasted meat by-products for the first time, by eating %s",
an(food_xname(otmp, FALSE)));
violated_vegetarian();
}
}
if (otmp->cursed) {
(void) rottenfood(otmp);
nodelicious = TRUE;
} else if (objects[otmp->otyp].oc_material == PAPER)
nodelicious = TRUE;
if (otmp->oclass == WEAPON_CLASS && otmp->opoisoned) {
pline("Ecch - that must have been poisonous!");
if (!Poison_resistance) {
poison_strdmg(rnd(4), rnd(15), xname(otmp), KILLED_BY_AN);
} else
You("seem unaffected by the poison.");
} else if (!nodelicious) {
pline("%s%s is delicious!",
(obj_is_pname(otmp)
&& otmp->oartifact < ART_ORB_OF_DETECTION)
? ""
: "This ",
(otmp->oclass == COIN_CLASS)
? foodword(otmp)
: singular(otmp, xname));
}
eatspecial();
return ECMD_TIME;
}
if (otmp == gc.context.victual.piece) {
boolean one_bite_left