Source:NetHack 3.6.4/src/eat.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to eat.c from the source code of NetHack 3.6.4. To link to a particular line, write [[Source:NetHack 3.6.4/src/eat.c#line12]], for example.

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

1. /* NetHack 3.6	eat.c	$NHDT-Date: 1574900825 2019/11/28 00:27:05 $  $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.206 $ */
2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3. /*-Copyright (c) Robert Patrick Rankin, 2012. */
4. /* NetHack may be freely redistributed.  See license for details. */
5. 
6. #include "hack.h"
7. 
8. STATIC_PTR int NDECL(eatmdone);
9. STATIC_PTR int NDECL(eatfood);
10. STATIC_PTR struct obj *FDECL(costly_tin, (int));
11. STATIC_PTR int NDECL(opentin);
12. STATIC_PTR int NDECL(unfaint);
13. 
14. STATIC_DCL const char *FDECL(food_xname, (struct obj *, BOOLEAN_P));
15. STATIC_DCL void FDECL(choke, (struct obj *));
16. STATIC_DCL void NDECL(recalc_wt);
17. STATIC_DCL unsigned FDECL(obj_nutrition, (struct obj *));
18. STATIC_DCL struct obj *FDECL(touchfood, (struct obj *));
19. STATIC_DCL void NDECL(do_reset_eat);
20. STATIC_DCL void FDECL(done_eating, (BOOLEAN_P));
21. STATIC_DCL void FDECL(cprefx, (int));
22. STATIC_DCL int FDECL(intrinsic_possible, (int, struct permonst *));
23. STATIC_DCL void FDECL(givit, (int, struct permonst *));
24. STATIC_DCL void FDECL(cpostfx, (int));
25. STATIC_DCL void FDECL(consume_tin, (const char *));
26. STATIC_DCL void FDECL(start_tin, (struct obj *));
27. STATIC_DCL int FDECL(eatcorpse, (struct obj *));
28. STATIC_DCL void FDECL(start_eating, (struct obj *, BOOLEAN_P));
29. STATIC_DCL void FDECL(fprefx, (struct obj *));
30. STATIC_DCL void FDECL(fpostfx, (struct obj *));
31. STATIC_DCL int NDECL(bite);
32. STATIC_DCL int FDECL(edibility_prompts, (struct obj *));
33. STATIC_DCL int FDECL(rottenfood, (struct obj *));
34. STATIC_DCL void NDECL(eatspecial);
35. STATIC_DCL int FDECL(bounded_increase, (int, int, int));
36. STATIC_DCL void FDECL(accessory_has_effect, (struct obj *));
37. STATIC_DCL void FDECL(eataccessory, (struct obj *));
38. STATIC_DCL const char *FDECL(foodword, (struct obj *));
39. STATIC_DCL int FDECL(tin_variety, (struct obj *, BOOLEAN_P));
40. STATIC_DCL boolean FDECL(maybe_cannibal, (int, BOOLEAN_P));
41. 
42. char msgbuf[BUFSZ];
43. 
44. /* also used to see if you're allowed to eat cats and dogs */
45. #define CANNIBAL_ALLOWED() (Role_if(PM_CAVEMAN) || Race_if(PM_ORC))
46. 
47. /* monster types that cause hero to be turned into stone if eaten */
48. #define flesh_petrifies(pm) (touch_petrifies(pm) || (pm) == &mons[PM_MEDUSA])
49. 
50. /* Rider corpses are treated as non-rotting so that attempting to eat one
51.    will be sure to reach the stage of eating where that meal is fatal */
52. #define nonrotting_corpse(mnum) \
53.     ((mnum) == PM_LIZARD || (mnum) == PM_LICHEN || is_rider(&mons[mnum]))
54. 
55. /* non-rotting non-corpses; unlike lizard corpses, these items will behave
56.    as if rotten if they are cursed (fortune cookies handled elsewhere) */
57. #define nonrotting_food(otyp) \
58.     ((otyp) == LEMBAS_WAFER || (otyp) == CRAM_RATION)
59. 
60. STATIC_OVL NEARDATA const char comestibles[] = { FOOD_CLASS, 0 };
61. STATIC_OVL NEARDATA const char offerfodder[] = { FOOD_CLASS, AMULET_CLASS,
62.                                                  0 };
63. 
64. /* Gold must come first for getobj(). */
65. STATIC_OVL NEARDATA const char allobj[] = {
66.     COIN_CLASS,   WEAPON_CLASS, ARMOR_CLASS,  POTION_CLASS,
67.     SCROLL_CLASS, WAND_CLASS,   RING_CLASS,   AMULET_CLASS,
68.     FOOD_CLASS,   TOOL_CLASS,   GEM_CLASS,    ROCK_CLASS,
69.     BALL_CLASS,   CHAIN_CLASS,  SPBOOK_CLASS, 0
70. };
71. 
72. STATIC_OVL boolean force_save_hs = FALSE;
73. 
74. /* see hunger states in hack.h - texts used on bottom line */
75. const char *hu_stat[] = { "Satiated", "        ", "Hungry  ", "Weak    ",
76.                           "Fainting", "Fainted ", "Starved " };
77. 
78. /*
79.  * Decide whether a particular object can be eaten by the possibly
80.  * polymorphed character.  Not used for monster checks.
81.  */
82. boolean
83. is_edible(obj)
84. register struct obj *obj;
85. {
86.     /* protect invocation tools but not Rider corpses (handled elsewhere)*/
87.     /* if (obj->oclass != FOOD_CLASS && obj_resists(obj, 0, 0)) */
88.     if (objects[obj->otyp].oc_unique)
89.         return FALSE;
90.     /* above also prevents the Amulet from being eaten, so we must never
91.        allow fake amulets to be eaten either [which is already the case] */
92. 
93.     if (metallivorous(youmonst.data) && is_metallic(obj)
94.         && (youmonst.data != &mons[PM_RUST_MONSTER] || is_rustprone(obj)))
95.         return TRUE;
96. 
97.     /* Ghouls only eat non-veggy corpses or eggs (see dogfood()) */
98.     if (u.umonnum == PM_GHOUL)
99.         return (boolean)((obj->otyp == CORPSE
100.                           && !vegan(&mons[obj->corpsenm]))
101.                          || (obj->otyp == EGG));
102. 
103.     if (u.umonnum == PM_GELATINOUS_CUBE && is_organic(obj)
104.         /* [g.cubes can eat containers and retain all contents
105.             as engulfed items, but poly'd player can't do that] */
106.         && !Has_contents(obj))
107.         return TRUE;
108. 
109.     /* return (boolean) !!index(comestibles, obj->oclass); */
110.     return (boolean) (obj->oclass == FOOD_CLASS);
111. }
112. 
113. /* used for hero init, life saving (if choking), and prayer results of fix
114.    starving, fix weak from hunger, or golden glow boon (if u.uhunger < 900) */
115. void
116. init_uhunger()
117. {
118.     context.botl = (u.uhs != NOT_HUNGRY || ATEMP(A_STR) < 0);
119.     u.uhunger = 900;
120.     u.uhs = NOT_HUNGRY;
121.     if (ATEMP(A_STR) < 0) {
122.         ATEMP(A_STR) = 0;
123.         (void) encumber_msg();
124.     }
125. }
126. 
127. /* tin types [SPINACH_TIN = -1, overrides corpsenm, nut==600] */
128. static const struct {
129.     const char *txt;                      /* description */
130.     int nut;                              /* nutrition */
131.     Bitfield(fodder, 1);                  /* stocked by health food shops */
132.     Bitfield(greasy, 1);                  /* causes slippery fingers */
133. } tintxts[] = { { "rotten", -50, 0, 0 },  /* ROTTEN_TIN = 0 */
134.                 { "homemade", 50, 1, 0 }, /* HOMEMADE_TIN = 1 */
135.                 { "soup made from", 20, 1, 0 },
136.                 { "french fried", 40, 0, 1 },
137.                 { "pickled", 40, 1, 0 },
138.                 { "boiled", 50, 1, 0 },
139.                 { "smoked", 50, 1, 0 },
140.                 { "dried", 55, 1, 0 },
141.                 { "deep fried", 60, 0, 1 },
142.                 { "szechuan", 70, 1, 0 },
143.                 { "broiled", 80, 0, 0 },
144.                 { "stir fried", 80, 0, 1 },
145.                 { "sauteed", 95, 0, 0 },
146.                 { "candied", 100, 1, 0 },
147.                 { "pureed", 500, 1, 0 },
148.                 { "", 0, 0, 0 } };
149. #define TTSZ SIZE(tintxts)
150. 
151. static char *eatmbuf = 0; /* set by cpostfx() */
152. 
153. /* called after mimicing is over */
154. STATIC_PTR int
155. eatmdone(VOID_ARGS)
156. {
157.     /* release `eatmbuf' */
158.     if (eatmbuf) {
159.         if (nomovemsg == eatmbuf)
160.             nomovemsg = 0;
161.         free((genericptr_t) eatmbuf), eatmbuf = 0;
162.     }
163.     /* update display */
164.     if (U_AP_TYPE) {
165.         youmonst.m_ap_type = M_AP_NOTHING;
166.         newsym(u.ux, u.uy);
167.     }
168.     return 0;
169. }
170. 
171. /* called when hallucination is toggled */
172. void
173. eatmupdate()
174. {
175.     const char *altmsg = 0;
176.     int altapp = 0; /* lint suppression */
177. 
178.     if (!eatmbuf || nomovemsg != eatmbuf)
179.         return;
180. 
181.     if (is_obj_mappear(&youmonst,ORANGE) && !Hallucination) {
182.         /* revert from hallucinatory to "normal" mimicking */
183.         altmsg = "You now prefer mimicking yourself.";
184.         altapp = GOLD_PIECE;
185.     } else if (is_obj_mappear(&youmonst,GOLD_PIECE) && Hallucination) {
186.         /* won't happen; anything which might make immobilized
187.            hero begin hallucinating (black light attack, theft
188.            of Grayswandir) will terminate the mimicry first */
189.         altmsg = "Your rind escaped intact.";
190.         altapp = ORANGE;
191.     }
192. 
193.     if (altmsg) {
194.         /* replace end-of-mimicking message */
195.         if (strlen(altmsg) > strlen(eatmbuf)) {
196.             free((genericptr_t) eatmbuf);
197.             eatmbuf = (char *) alloc(strlen(altmsg) + 1);
198.         }
199.         nomovemsg = strcpy(eatmbuf, altmsg);
200.         /* update current image */
201.         youmonst.mappearance = altapp;
202.         newsym(u.ux, u.uy);
203.     }
204. }
205. 
206. /* ``[the(] singular(food, xname) [)] */
207. STATIC_OVL const char *
208. food_xname(food, the_pfx)
209. struct obj *food;
210. boolean the_pfx;
211. {
212.     const char *result;
213. 
214.     if (food->otyp == CORPSE) {
215.         result = corpse_xname(food, (const char *) 0,
216.                               CXN_SINGULAR | (the_pfx ? CXN_PFX_THE : 0));
217.         /* not strictly needed since pname values are capitalized
218.            and the() is a no-op for them */
219.         if (type_is_pname(&mons[food->corpsenm]))
220.             the_pfx = FALSE;
221.     } else {
222.         /* the ordinary case */
223.         result = singular(food, xname);
224.     }
225.     if (the_pfx)
226.         result = the(result);
227.     return result;
228. }
229. 
230. /* Created by GAN 01/28/87
231.  * Amended by AKP 09/22/87: if not hard, don't choke, just vomit.
232.  * Amended by 3.  06/12/89: if not hard, sometimes choke anyway, to keep risk.
233.  *                11/10/89: if hard, rarely vomit anyway, for slim chance.
234.  *
235.  * To a full belly all food is bad. (It.)
236.  */
237. STATIC_OVL void
238. choke(food)
239. struct obj *food;
240. {
241.     /* only happens if you were satiated */
242.     if (u.uhs != SATIATED) {
243.         if (!food || food->otyp != AMULET_OF_STRANGULATION)
244.             return;
245.     } else if (Role_if(PM_KNIGHT) && u.ualign.type == A_LAWFUL) {
246.         adjalign(-1); /* gluttony is unchivalrous */
247.         You_feel("like a glutton!");
248.     }
249. 
250.     exercise(A_CON, FALSE);
251. 
252.     if (Breathless || (!Strangled && !rn2(20))) {
253.         /* choking by eating AoS doesn't involve stuffing yourself */
254.         if (food && food->otyp == AMULET_OF_STRANGULATION) {
255.             You("choke, but recover your composure.");
256.             return;
257.         }
258.         You("stuff yourself and then vomit voluminously.");
259.         morehungry(1000); /* you just got *very* sick! */
260.         vomit();
261.     } else {
262.         killer.format = KILLED_BY_AN;
263.         /*
264.          * Note all "killer"s below read "Choked on %s" on the
265.          * high score list & tombstone.  So plan accordingly.
266.          */
267.         if (food) {
268.             You("choke over your %s.", foodword(food));
269.             if (food->oclass == COIN_CLASS) {
270.                 Strcpy(killer.name, "very rich meal");
271.             } else {
272.                 killer.format = KILLED_BY;
273.                 Strcpy(killer.name, killer_xname(food));
274.             }
275.         } else {
276.             You("choke over it.");
277.             Strcpy(killer.name, "quick snack");
278.         }
279.         You("die...");
280.         done(CHOKING);
281.     }
282. }
283. 
284. /* modify object wt. depending on time spent consuming it */
285. STATIC_OVL void
286. recalc_wt()
287. {
288.     struct obj *piece = context.victual.piece;
289.     if (!piece) {
290.         impossible("recalc_wt without piece");
291.         return;
292.     }
293.     debugpline1("Old weight = %d", piece->owt);
294.     debugpline2("Used time = %d, Req'd time = %d", context.victual.usedtime,
295.                 context.victual.reqtime);
296.     piece->owt = weight(piece);
297.     debugpline1("New weight = %d", piece->owt);
298. }
299. 
300. /* called when eating interrupted by an event */
301. void
302. reset_eat()
303. {
304.     /* we only set a flag here - the actual reset process is done after
305.      * the round is spent eating.
306.      */
307.     if (context.victual.eating && !context.victual.doreset) {
308.         debugpline0("reset_eat...");
309.         context.victual.doreset = TRUE;
310.     }
311.     return;
312. }
313. 
314. /* base nutrition of a food-class object */
315. STATIC_OVL unsigned
316. obj_nutrition(otmp)
317. struct obj *otmp;
318. {
319.     unsigned nut = (otmp->otyp == CORPSE) ? mons[otmp->corpsenm].cnutrit
320.                       : otmp->globby ? otmp->owt
321.                          : (unsigned) objects[otmp->otyp].oc_nutrition;
322. 
323.     if (otmp->otyp == LEMBAS_WAFER) {
324.         if (maybe_polyd(is_elf(youmonst.data), Race_if(PM_ELF)))
325.             nut += nut / 4; /* 800 -> 1000 */
326.         else if (maybe_polyd(is_orc(youmonst.data), Race_if(PM_ORC)))
327.             nut -= nut / 4; /* 800 -> 600 */
328.         /* prevent polymorph making a partly eaten wafer
329.            become more nutritious than an untouched one */
330.         if (otmp->oeaten >= nut)
331.             otmp->oeaten = (otmp->oeaten < objects[LEMBAS_WAFER].oc_nutrition)
332.                               ? (nut - 1) : nut;
333.     } else if (otmp->otyp == CRAM_RATION) {
334.         if (maybe_polyd(is_dwarf(youmonst.data), Race_if(PM_DWARF)))
335.             nut += nut / 6; /* 600 -> 700 */
336.     }
337.     return nut;
338. }
339. 
340. STATIC_OVL struct obj *
341. touchfood(otmp)
342. struct obj *otmp;
343. {
344.     if (otmp->quan > 1L) {
345.         if (!carried(otmp))
346.             (void) splitobj(otmp, otmp->quan - 1L);
347.         else
348.             otmp = splitobj(otmp, 1L);
349.         debugpline0("split object,");
350.     }
351. 
352.     if (!otmp->oeaten) {
353.         costly_alteration(otmp, COST_BITE);
354.         otmp->oeaten = obj_nutrition(otmp);
355.     }
356. 
357.     if (carried(otmp)) {
358.         freeinv(otmp);
359.         if (inv_cnt(FALSE) >= 52) {
360.             sellobj_state(SELL_DONTSELL);
361.             dropy(otmp);
362.             sellobj_state(SELL_NORMAL);
363.         } else {
364.             otmp->nomerge = 1; /* used to prevent merge */
365.             otmp = addinv(otmp);
366.             otmp->nomerge = 0;
367.         }
368.     }
369.     return otmp;
370. }
371. 
372. /* When food decays, in the middle of your meal, we don't want to dereference
373.  * any dangling pointers, so set it to null (which should still trigger
374.  * do_reset_eat() at the beginning of eatfood()) and check for null pointers
375.  * in do_reset_eat().
376.  */
377. void
378. food_disappears(obj)
379. struct obj *obj;
380. {
381.     if (obj == context.victual.piece) {
382.         context.victual.piece = (struct obj *) 0;
383.         context.victual.o_id = 0;
384.     }
385.     if (obj->timed)
386.         obj_stop_timers(obj);
387. }
388. 
389. /* renaming an object used to result in it having a different address,
390.    so the sequence start eating/opening, get interrupted, name the food,
391.    resume eating/opening would restart from scratch */
392. void
393. food_substitution(old_obj, new_obj)
394. struct obj *old_obj, *new_obj;
395. {
396.     if (old_obj == context.victual.piece) {
397.         context.victual.piece = new_obj;
398.         context.victual.o_id = new_obj->o_id;
399.     }
400.     if (old_obj == context.tin.tin) {
401.         context.tin.tin = new_obj;
402.         context.tin.o_id = new_obj->o_id;
403.     }
404. }
405. 
406. STATIC_OVL void
407. do_reset_eat()
408. {
409.     debugpline0("do_reset_eat...");
410.     if (context.victual.piece) {
411.         context.victual.o_id = 0;
412.         context.victual.piece = touchfood(context.victual.piece);
413.         if (context.victual.piece)
414.             context.victual.o_id = context.victual.piece->o_id;
415.         recalc_wt();
416.     }
417.     context.victual.fullwarn = context.victual.eating =
418.         context.victual.doreset = FALSE;
419.     /* Do not set canchoke to FALSE; if we continue eating the same object
420.      * we need to know if canchoke was set when they started eating it the
421.      * previous time.  And if we don't continue eating the same object
422.      * canchoke always gets recalculated anyway.
423.      */
424.     stop_occupation();
425.     newuhs(FALSE);
426. }
427. 
428. /* called each move during eating process */
429. STATIC_PTR int
430. eatfood(VOID_ARGS)
431. {
432.     if (!context.victual.piece
433.         || (!carried(context.victual.piece)
434.             && !obj_here(context.victual.piece, u.ux, u.uy))) {
435.         /* maybe it was stolen? */
436.         do_reset_eat();
437.         return 0;
438.     }
439.     if (!context.victual.eating)
440.         return 0;
441. 
442.     if (++context.victual.usedtime <= context.victual.reqtime) {
443.         if (bite())
444.             return 0;
445.         return 1; /* still busy */
446.     } else {        /* done */
447.         done_eating(TRUE);
448.         return 0;
449.     }
450. }
451. 
452. STATIC_OVL void
453. done_eating(message)
454. boolean message;
455. {
456.     struct obj *piece = context.victual.piece;
457. 
458.     piece->in_use = TRUE;
459.     occupation = 0; /* do this early, so newuhs() knows we're done */
460.     newuhs(FALSE);
461.     if (nomovemsg) {
462.         if (message)
463.             pline1(nomovemsg);
464.         nomovemsg = 0;
465.     } else if (message)
466.         You("finish eating %s.", food_xname(piece, TRUE));
467. 
468.     if (piece->otyp == CORPSE || piece->globby)
469.         cpostfx(piece->corpsenm);
470.     else
471.         fpostfx(piece);
472. 
473.     if (carried(piece))
474.         useup(piece);
475.     else
476.         useupf(piece, 1L);
477.     context.victual.piece = (struct obj *) 0;
478.     context.victual.o_id = 0;
479.     context.victual.fullwarn = context.victual.eating =
480.         context.victual.doreset = FALSE;
481. }
482. 
483. void
484. eating_conducts(pd)
485. struct permonst *pd;
486. {
487.     u.uconduct.food++;
488.     if (!vegan(pd))
489.         u.uconduct.unvegan++;
490.     if (!vegetarian(pd))
491.         violated_vegetarian();
492. }
493. 
494. /* handle side-effects of mind flayer's tentacle attack */
495. int
496. eat_brains(magr, mdef, visflag, dmg_p)
497. struct monst *magr, *mdef;
498. boolean visflag;
499. int *dmg_p; /* for dishing out extra damage in lieu of Int loss */
500. {
501.     struct permonst *pd = mdef->data;
502.     boolean give_nutrit = FALSE;
503.     int result = MM_HIT, xtra_dmg = rnd(10);
504. 
505.     if (noncorporeal(pd)) {
506.         if (visflag)
507.             pline("%s brain is unharmed.",
508.                   (mdef == &youmonst) ? "Your" : s_suffix(Monnam(mdef)));
509.         return MM_MISS; /* side-effects can't occur */
510.     } else if (magr == &youmonst) {
511.         You("eat %s brain!", s_suffix(mon_nam(mdef)));
512.     } else if (mdef == &youmonst) {
513.         Your("brain is eaten!");
514.     } else { /* monster against monster */
515.         if (visflag && canspotmon(mdef))
516.             pline("%s brain is eaten!", s_suffix(Monnam(mdef)));
517.     }
518. 
519.     if (flesh_petrifies(pd)) {
520.         /* mind flayer has attempted to eat the brains of a petrification
521.            inducing critter (most likely Medusa; attacking a cockatrice via
522.            tentacle-touch should have been caught before reaching this far) */
523.         if (magr == &youmonst) {
524.             if (!Stone_resistance && !Stoned)
525.                 make_stoned(5L, (char *) 0, KILLED_BY_AN, pd->mname);
526.         } else {
527.             /* no need to check for poly_when_stoned or Stone_resistance;
528.                mind flayers don't have those capabilities */
529.             if (visflag && canseemon(magr))
530.                 pline("%s turns to stone!", Monnam(magr));
531.             monstone(magr);
532.             if (!DEADMONSTER(magr)) {
533.                 /* life-saved; don't continue eating the brains */
534.                 return MM_MISS;
535.             } else {
536.                 if (magr->mtame && !visflag)
537.                     /* parallels mhitm.c's brief_feeling */
538.                     You("have a sad thought for a moment, then it passes.");
539.                 return MM_AGR_DIED;
540.             }
541.         }
542.     }
543. 
544.     if (magr == &youmonst) {
545.         /*
546.          * player mind flayer is eating something's brain
547.          */
548.         eating_conducts(pd);
549.         if (mindless(pd)) { /* (cannibalism not possible here) */
550.             pline("%s doesn't notice.", Monnam(mdef));
551.             /* all done; no extra harm inflicted upon target */
552.             return MM_MISS;
553.         } else if (is_rider(pd)) {
554.             pline("Ingesting that is fatal.");
555.             Sprintf(killer.name, "unwisely ate the brain of %s", pd->mname);
556.             killer.format = NO_KILLER_PREFIX;
557.             done(DIED);
558.             /* life-saving needed to reach here */
559.             exercise(A_WIS, FALSE);
560.             *dmg_p += xtra_dmg; /* Rider takes extra damage */
561.         } else {
562.             morehungry(-rnd(30)); /* cannot choke */
563.             if (ABASE(A_INT) < AMAX(A_INT)) {
564.                 /* recover lost Int; won't increase current max */
565.                 ABASE(A_INT) += rnd(4);
566.                 if (ABASE(A_INT) > AMAX(A_INT))
567.                     ABASE(A_INT) = AMAX(A_INT);
568.                 context.botl = 1;
569.             }
570.             exercise(A_WIS, TRUE);
571.             *dmg_p += xtra_dmg;
572.         }
573.         /* targetting another mind flayer or your own underlying species
574.            is cannibalism */
575.         (void) maybe_cannibal(monsndx(pd), TRUE);
576. 
577.     } else if (mdef == &youmonst) {
578.         /*
579.          * monster mind flayer is eating hero's brain
580.          */
581.         /* no such thing as mindless players */
582.         if (ABASE(A_INT) <= ATTRMIN(A_INT)) {
583.             static NEARDATA const char brainlessness[] = "brainlessness";
584. 
585.             if (Lifesaved) {
586.                 Strcpy(killer.name, brainlessness);
587.                 killer.format = KILLED_BY;
588.                 done(DIED);
589.                 /* amulet of life saving has now been used up */
590.                 pline("Unfortunately your brain is still gone.");
591.                 /* sanity check against adding other forms of life-saving */
592.                 u.uprops[LIFESAVED].extrinsic =
593.                     u.uprops[LIFESAVED].intrinsic = 0L;
594.             } else {
595.                 Your("last thought fades away.");
596.             }
597.             Strcpy(killer.name, brainlessness);
598.             killer.format = KILLED_BY;
599.             done(DIED);
600.             /* can only get here when in wizard or explore mode and user has
601.                explicitly chosen not to die; arbitrarily boost intelligence */
602.             ABASE(A_INT) = ATTRMIN(A_INT) + 2;
603.             You_feel("like a scarecrow.");
604.         }
605.         give_nutrit = TRUE; /* in case a conflicted pet is doing this */
606.         exercise(A_WIS, FALSE);
607.         /* caller handles Int and memory loss */
608. 
609.     } else { /* mhitm */
610.         /*
611.          * monster mind flayer is eating another monster's brain
612.          */
613.         if (mindless(pd)) {
614.             if (visflag && canspotmon(mdef))
615.                 pline("%s doesn't notice.", Monnam(mdef));
616.             return MM_MISS;
617.         } else if (is_rider(pd)) {
618.             mondied(magr);
619.             if (DEADMONSTER(magr))
620.                 result = MM_AGR_DIED;
621.             /* Rider takes extra damage regardless of whether attacker dies */
622.             *dmg_p += xtra_dmg;
623.         } else {
624.             *dmg_p += xtra_dmg;
625.             give_nutrit = TRUE;
626.             if (*dmg_p >= mdef->mhp && visflag && canspotmon(mdef))
627.                 pline("%s last thought fades away...",
628.                       s_suffix(Monnam(mdef)));
629.         }
630.     }
631. 
632.     if (give_nutrit && magr->mtame && !magr->isminion) {
633.         EDOG(magr)->hungrytime += rnd(60);
634.         magr->mconf = 0;
635.     }
636. 
637.     return result;
638. }
639. 
640. /* eating a corpse or egg of one's own species is usually naughty */
641. STATIC_OVL boolean
642. maybe_cannibal(pm, allowmsg)
643. int pm;
644. boolean allowmsg;
645. {
646.     static NEARDATA long ate_brains = 0L;
647.     struct permonst *fptr = &mons[pm]; /* food type */
648. 
649.     /* when poly'd into a mind flayer, multiple tentacle hits in one
650.        turn cause multiple digestion checks to occur; avoid giving
651.        multiple luck penalties for the same attack */
652.     if (moves == ate_brains)
653.         return FALSE;
654.     ate_brains = moves; /* ate_anything, not just brains... */
655. 
656.     if (!CANNIBAL_ALLOWED()
657.         /* non-cannibalistic heroes shouldn't eat own species ever
658.            and also shouldn't eat current species when polymorphed
659.            (even if having the form of something which doesn't care
660.            about cannibalism--hero's innate traits aren't altered) */
661.         && (your_race(fptr)
662.             || (Upolyd && same_race(youmonst.data, fptr))
663.             || (u.ulycn >= LOW_PM && were_beastie(pm) == u.ulycn))) {
664.         if (allowmsg) {
665.             if (Upolyd && your_race(fptr))
666.                 You("have a bad feeling deep inside.");
667.             You("cannibal!  You will regret this!");
668.         }
669.         HAggravate_monster |= FROMOUTSIDE;
670.         change_luck(-rn1(4, 2)); /* -5..-2 */
671.         return TRUE;
672.     }
673.     return FALSE;
674. }
675. 
676. STATIC_OVL void
677. cprefx(pm)
678. register int pm;
679. {
680.     (void) maybe_cannibal(pm, TRUE);
681.     if (flesh_petrifies(&mons[pm])) {
682.         if (!Stone_resistance
683.             && !(poly_when_stoned(youmonst.data)
684.                  && polymon(PM_STONE_GOLEM))) {
685.             Sprintf(killer.name, "tasting %s meat", mons[pm].mname);
686.             killer.format = KILLED_BY;
687.             You("turn to stone.");
688.             done(STONING);
689.             if (context.victual.piece)
690.                 context.victual.eating = FALSE;
691.             return; /* lifesaved */
692.         }
693.     }
694. 
695.     switch (pm) {
696.     case PM_LITTLE_DOG:
697.     case PM_DOG:
698.     case PM_LARGE_DOG:
699.     case PM_KITTEN:
700.     case PM_HOUSECAT:
701.     case PM_LARGE_CAT:
702.         /* cannibals are allowed to eat domestic animals without penalty */
703.         if (!CANNIBAL_ALLOWED()) {
704.             You_feel("that eating the %s was a bad idea.", mons[pm].mname);
705.             HAggravate_monster |= FROMOUTSIDE;
706.         }
707.         break;
708.     case PM_LIZARD:
709.         if (Stoned)
710.             fix_petrification();
711.         break;
712.     case PM_DEATH:
713.     case PM_PESTILENCE:
714.     case PM_FAMINE: {
715.         pline("Eating that is instantly fatal.");
716.         Sprintf(killer.name, "unwisely ate the body of %s", mons[pm].mname);
717.         killer.format = NO_KILLER_PREFIX;
718.         done(DIED);
719.         /* life-saving needed to reach here */
720.         exercise(A_WIS, FALSE);
721.         /* It so happens that since we know these monsters */
722.         /* cannot appear in tins, context.victual.piece will always */
723.         /* be what we want, which is not generally true. */
724.         if (revive_corpse(context.victual.piece)) {
725.             context.victual.piece = (struct obj *) 0;
726.             context.victual.o_id = 0;
727.         }
728.         return;
729.     }
730.     case PM_GREEN_SLIME:
731.         if (!Slimed && !Unchanging && !slimeproof(youmonst.data)) {
732.             You("don't feel very well.");
733.             make_slimed(10L, (char *) 0);
734.             delayed_killer(SLIMED, KILLED_BY_AN, "");
735.         }
736.     /* Fall through */
737.     default:
738.         if (acidic(&mons[pm]) && Stoned)
739.             fix_petrification();
740.         break;
741.     }
742. }
743. 
744. void
745. fix_petrification()
746. {
747.     char buf[BUFSZ];
748. 
749.     if (Hallucination)
750.         Sprintf(buf, "What a pity--you just ruined a future piece of %sart!",
751.                 ACURR(A_CHA) > 15 ? "fine " : "");
752.     else
753.         Strcpy(buf, "You feel limber!");
754.     make_stoned(0L, buf, 0, (char *) 0);
755. }
756. 
757. /*
758.  * If you add an intrinsic that can be gotten by eating a monster, add it
759.  * to intrinsic_possible() and givit().  (It must already be in prop.h to
760.  * be an intrinsic property.)
761.  * It would be very easy to make the intrinsics not try to give you one
762.  * that you already had by checking to see if you have it in
763.  * intrinsic_possible() instead of givit(), but we're not that nice.
764.  */
765. 
766. /* intrinsic_possible() returns TRUE iff a monster can give an intrinsic. */
767. STATIC_OVL int
768. intrinsic_possible(type, ptr)
769. int type;
770. register struct permonst *ptr;
771. {
772.     int res = 0;
773. 
774. #ifdef DEBUG
775. #define ifdebugresist(Msg)      \
776.     do {                        \
777.         if (res)                \
778.             debugpline0(Msg);   \
779.     } while (0)
780. #else
781. #define ifdebugresist(Msg) /*empty*/
782. #endif
783.     switch (type) {
784.     case FIRE_RES:
785.         res = (ptr->mconveys & MR_FIRE) != 0;
786.         ifdebugresist("can get fire resistance");
787.         break;
788.     case SLEEP_RES:
789.         res = (ptr->mconveys & MR_SLEEP) != 0;
790.         ifdebugresist("can get sleep resistance");
791.         break;
792.     case COLD_RES:
793.         res = (ptr->mconveys & MR_COLD) != 0;
794.         ifdebugresist("can get cold resistance");
795.         break;
796.     case DISINT_RES:
797.         res = (ptr->mconveys & MR_DISINT) != 0;
798.         ifdebugresist("can get disintegration resistance");
799.         break;
800.     case SHOCK_RES: /* shock (electricity) resistance */
801.         res = (ptr->mconveys & MR_ELEC) != 0;
802.         ifdebugresist("can get shock resistance");
803.         break;
804.     case POISON_RES:
805.         res = (ptr->mconveys & MR_POISON) != 0;
806.         ifdebugresist("can get poison resistance");
807.         break;
808.     case TELEPORT:
809.         res = can_teleport(ptr);
810.         ifdebugresist("can get teleport");
811.         break;
812.     case TELEPORT_CONTROL:
813.         res = control_teleport(ptr);
814.         ifdebugresist("can get teleport control");
815.         break;
816.     case TELEPAT:
817.         res = telepathic(ptr);
818.         ifdebugresist("can get telepathy");
819.         break;
820.     default:
821.         /* res stays 0 */
822.         break;
823.     }
824. #undef ifdebugresist
825.     return res;
826. }
827. 
828. /* givit() tries to give you an intrinsic based on the monster's level
829.  * and what type of intrinsic it is trying to give you.
830.  */
831. STATIC_OVL void
832. givit(type, ptr)
833. int type;
834. register struct permonst *ptr;
835. {
836.     register int chance;
837. 
838.     debugpline1("Attempting to give intrinsic %d", type);
839.     /* some intrinsics are easier to get than others */
840.     switch (type) {
841.     case POISON_RES:
842.         if ((ptr == &mons[PM_KILLER_BEE] || ptr == &mons[PM_SCORPION])
843.             && !rn2(4))
844.             chance = 1;
845.         else
846.             chance = 15;
847.         break;
848.     case TELEPORT:
849.         chance = 10;
850.         break;
851.     case TELEPORT_CONTROL:
852.         chance = 12;
853.         break;
854.     case TELEPAT:
855.         chance = 1;
856.         break;
857.     default:
858.         chance = 15;
859.         break;
860.     }
861. 
862.     if (ptr->mlevel <= rn2(chance))
863.         return; /* failed die roll */
864. 
865.     switch (type) {
866.     case FIRE_RES:
867.         debugpline0("Trying to give fire resistance");
868.         if (!(HFire_resistance & FROMOUTSIDE)) {
869.             You(Hallucination ? "be chillin'." : "feel a momentary chill.");
870.             HFire_resistance |= FROMOUTSIDE;
871.         }
872.         break;
873.     case SLEEP_RES:
874.         debugpline0("Trying to give sleep resistance");
875.         if (!(HSleep_resistance & FROMOUTSIDE)) {
876.             You_feel("wide awake.");
877.             HSleep_resistance |= FROMOUTSIDE;
878.         }
879.         break;
880.     case COLD_RES:
881.         debugpline0("Trying to give cold resistance");
882.         if (!(HCold_resistance & FROMOUTSIDE)) {
883.             You_feel("full of hot air.");
884.             HCold_resistance |= FROMOUTSIDE;
885.         }
886.         break;
887.     case DISINT_RES:
888.         debugpline0("Trying to give disintegration resistance");
889.         if (!(HDisint_resistance & FROMOUTSIDE)) {
890.             You_feel(Hallucination ? "totally together, man." : "very firm.");
891.             HDisint_resistance |= FROMOUTSIDE;
892.         }
893.         break;
894.     case SHOCK_RES: /* shock (electricity) resistance */
895.         debugpline0("Trying to give shock resistance");
896.         if (!(HShock_resistance & FROMOUTSIDE)) {
897.             if (Hallucination)
898.                 You_feel("grounded in reality.");
899.             else
900.                 Your("health currently feels amplified!");
901.             HShock_resistance |= FROMOUTSIDE;
902.         }
903.         break;
904.     case POISON_RES:
905.         debugpline0("Trying to give poison resistance");
906.         if (!(HPoison_resistance & FROMOUTSIDE)) {
907.             You_feel(Poison_resistance ? "especially healthy." : "healthy.");
908.             HPoison_resistance |= FROMOUTSIDE;
909.         }
910.         break;
911.     case TELEPORT:
912.         debugpline0("Trying to give teleport");
913.         if (!(HTeleportation & FROMOUTSIDE)) {
914.             You_feel(Hallucination ? "diffuse." : "very jumpy.");
915.             HTeleportation |= FROMOUTSIDE;
916.         }
917.         break;
918.     case TELEPORT_CONTROL:
919.         debugpline0("Trying to give teleport control");
920.         if (!(HTeleport_control & FROMOUTSIDE)) {
921.             You_feel(Hallucination ? "centered in your personal space."
922.                                    : "in control of yourself.");
923.             HTeleport_control |= FROMOUTSIDE;
924.         }
925.         break;
926.     case TELEPAT:
927.         debugpline0("Trying to give telepathy");
928.         if (!(HTelepat & FROMOUTSIDE)) {
929.             You_feel(Hallucination ? "in touch with the cosmos."
930.                                    : "a strange mental acuity.");
931.             HTelepat |= FROMOUTSIDE;
932.             /* If blind, make sure monsters show up. */
933.             if (Blind)
934.                 see_monsters();
935.         }
936.         break;
937.     default:
938.         debugpline0("Tried to give an impossible intrinsic");
939.         break;
940.     }
941. }
942. 
943. /* called after completely consuming a corpse */
944. STATIC_OVL void
945. cpostfx(pm)
946. int pm;
947. {
948.     int tmp = 0;
949.     int catch_lycanthropy = NON_PM;
950.     boolean check_intrinsics = FALSE;
951. 
952.     /* in case `afternmv' didn't get called for previously mimicking
953.        gold, clean up now to avoid `eatmbuf' memory leak */
954.     if (eatmbuf)
955.         (void) eatmdone();
956. 
957.     switch (pm) {
958.     case PM_NEWT:
959.         /* MRKR: "eye of newt" may give small magical energy boost */
960.         if (rn2(3) || 3 * u.uen <= 2 * u.uenmax) {
961.             int old_uen = u.uen;
962. 
963.             u.uen += rnd(3);
964.             if (u.uen > u.uenmax) {
965.                 if (!rn2(3))
966.                     u.uenmax++;
967.                 u.uen = u.uenmax;
968.             }
969.             if (old_uen != u.uen) {
970.                 You_feel("a mild buzz.");
971.                 context.botl = 1;
972.             }
973.         }
974.         break;
975.     case PM_WRAITH:
976.         pluslvl(FALSE);
977.         break;
978.     case PM_HUMAN_WERERAT:
979.         catch_lycanthropy = PM_WERERAT;
980.         break;
981.     case PM_HUMAN_WEREJACKAL:
982.         catch_lycanthropy = PM_WEREJACKAL;
983.         break;
984.     case PM_HUMAN_WEREWOLF:
985.         catch_lycanthropy = PM_WEREWOLF;
986.         break;
987.     case PM_NURSE:
988.         if (Upolyd)
989.             u.mh = u.mhmax;
990.         else
991.             u.uhp = u.uhpmax;
992.         make_blinded(0L, !u.ucreamed);
993.         context.botl = 1;
994.         check_intrinsics = TRUE; /* might also convey poison resistance */
995.         break;
996.     case PM_STALKER:
997.         if (!Invis) {
998.             set_itimeout(&HInvis, (long) rn1(100, 50));
999.             if (!Blind && !BInvis)
1000.                 self_invis_message();
1001.         } else {
1002.             if (!(HInvis & INTRINSIC))
1003.                 You_feel("hidden!");
1004.             HInvis |= FROMOUTSIDE;
1005.             HSee_invisible |= FROMOUTSIDE;
1006.         }
1007.         newsym(u.ux, u.uy);
1008.         /*FALLTHRU*/
1009.     case PM_YELLOW_LIGHT:
1010.     case PM_GIANT_BAT:
1011.         make_stunned((HStun & TIMEOUT) + 30L, FALSE);
1012.         /*FALLTHRU*/
1013.     case PM_BAT:
1014.         make_stunned((HStun & TIMEOUT) + 30L, FALSE);
1015.         break;
1016.     case PM_GIANT_MIMIC:
1017.         tmp += 10;
1018.         /*FALLTHRU*/
1019.     case PM_LARGE_MIMIC:
1020.         tmp += 20;
1021.         /*FALLTHRU*/
1022.     case PM_SMALL_MIMIC:
1023.         tmp += 20;
1024.         if (youmonst.data->mlet != S_MIMIC && !Unchanging) {
1025.             char buf[BUFSZ];
1026. 
1027.             u.uconduct.polyselfs++; /* you're changing form */
1028.             You_cant("resist the temptation to mimic %s.",
1029.                      Hallucination ? "an orange" : "a pile of gold");
1030.             /* A pile of gold can't ride. */
1031.             if (u.usteed)
1032.                 dismount_steed(DISMOUNT_FELL);
1033.             nomul(-tmp);
1034.             multi_reason = "pretending to be a pile of gold";
1035.             Sprintf(buf,
1036.                     Hallucination
1037.                        ? "You suddenly dread being peeled and mimic %s again!"
1038.                        : "You now prefer mimicking %s again.",
1039.                     an(Upolyd ? youmonst.data->mname : urace.noun));
1040.             eatmbuf = dupstr(buf);
1041.             nomovemsg = eatmbuf;
1042.             afternmv = eatmdone;
1043.             /* ??? what if this was set before? */
1044.             youmonst.m_ap_type = M_AP_OBJECT;
1045.             youmonst.mappearance = Hallucination ? ORANGE : GOLD_PIECE;
1046.             newsym(u.ux, u.uy);
1047.             curs_on_u();
1048.             /* make gold symbol show up now */
1049.             display_nhwindow(WIN_MAP, TRUE);
1050.         }
1051.         break;
1052.     case PM_QUANTUM_MECHANIC:
1053.         Your("velocity suddenly seems very uncertain!");
1054.         if (HFast & INTRINSIC) {
1055.             HFast &= ~INTRINSIC;
1056.             You("seem slower.");
1057.         } else {
1058.             HFast |= FROMOUTSIDE;
1059.             You("seem faster.");
1060.         }
1061.         break;
1062.     case PM_LIZARD:
1063.         if ((HStun & TIMEOUT) > 2)
1064.             make_stunned(2L, FALSE);
1065.         if ((HConfusion & TIMEOUT) > 2)
1066.             make_confused(2L, FALSE);
1067.         break;
1068.     case PM_CHAMELEON:
1069.     case PM_DOPPELGANGER:
1070.     case PM_SANDESTIN: /* moot--they don't leave corpses */
1071.         if (Unchanging) {
1072.             You_feel("momentarily different."); /* same as poly trap */
1073.         } else {
1074.             You_feel("a change coming over you.");
1075.             polyself(0);
1076.         }
1077.         break;
1078.     case PM_DISENCHANTER:
1079.         /* picks an intrinsic at random and removes it; there's
1080.            no feedback if hero already lacks the chosen ability */
1081.         debugpline0("using attrcurse to strip an intrinsic");
1082.         attrcurse();
1083.         break;
1084.     case PM_MIND_FLAYER:
1085.     case PM_MASTER_MIND_FLAYER:
1086.         if (ABASE(A_INT) < ATTRMAX(A_INT)) {
1087.             if (!rn2(2)) {
1088.                 pline("Yum!  That was real brain food!");
1089.                 (void) adjattrib(A_INT, 1, FALSE);
1090.                 break; /* don't give them telepathy, too */
1091.             }
1092.         } else {
1093.             pline("For some reason, that tasted bland.");
1094.         }
1095.     /*FALLTHRU*/
1096.     default:
1097.         check_intrinsics = TRUE;
1098.         break;
1099.     }
1100. 
1101.     /* possibly convey an intrinsic */
1102.     if (check_intrinsics) {
1103.         struct permonst *ptr = &mons[pm];
1104.         boolean conveys_STR = is_giant(ptr);
1105.         int i, count;
1106. 
1107.         if (dmgtype(ptr, AD_STUN) || dmgtype(ptr, AD_HALU)
1108.             || pm == PM_VIOLET_FUNGUS) {
1109.             pline("Oh wow!  Great stuff!");
1110.             (void) make_hallucinated((HHallucination & TIMEOUT) + 200L, FALSE,
1111.                                      0L);
1112.         }
1113. 
1114.         /* Check the monster for all of the intrinsics.  If this
1115.          * monster can give more than one, pick one to try to give
1116.          * from among all it can give.
1117.          *
1118.          * Strength from giants is now treated like an intrinsic
1119.          * rather than being given unconditionally.
1120.          */
1121.         count = 0; /* number of possible intrinsics */
1122.         tmp = 0;   /* which one we will try to give */
1123.         if (conveys_STR) {
1124.             count = 1;
1125.             tmp = -1; /* use -1 as fake prop index for STR */
1126.             debugpline1("\"Intrinsic\" strength, %d", tmp);
1127.         }
1128.         for (i = 1; i <= LAST_PROP; i++) {
1129.             if (!intrinsic_possible(i, ptr))
1130.                 continue;
1131.             ++count;
1132.             /* a 1 in count chance of replacing the old choice
1133.                with this one, and a count-1 in count chance
1134.                of keeping the old choice (note that 1 in 1 and
1135.                0 in 1 are what we want for the first candidate) */
1136.             if (!rn2(count)) {
1137.                 debugpline2("Intrinsic %d replacing %d", i, tmp);
1138.                 tmp = i;
1139.             }
1140.         }
1141.         /* if strength is the only candidate, give it 50% chance */
1142.         if (conveys_STR && count == 1 && !rn2(2))
1143.             tmp = 0;
1144.         /* if something was chosen, give it now (givit() might fail) */
1145.         if (tmp == -1)
1146.             gainstr((struct obj *) 0, 0, TRUE);
1147.         else if (tmp > 0)
1148.             givit(tmp, ptr);
1149.     } /* check_intrinsics */
1150. 
1151.     if (catch_lycanthropy >= LOW_PM) {
1152.         set_ulycn(catch_lycanthropy);
1153.         retouch_equipment(2);
1154.     }
1155.     return;
1156. }
1157. 
1158. void
1159. violated_vegetarian()
1160. {
1161.     u.uconduct.unvegetarian++;
1162.     if (Role_if(PM_MONK)) {
1163.         You_feel("guilty.");
1164.         adjalign(-1);
1165.     }
1166.     return;
1167. }
1168. 
1169. /* common code to check and possibly charge for 1 context.tin.tin,
1170.  * will split() context.tin.tin if necessary */
1171. STATIC_PTR struct obj *
1172. costly_tin(alter_type)
1173. int alter_type; /* COST_xxx */
1174. {
1175.     struct obj *tin = context.tin.tin;
1176. 
1177.     if (carried(tin) ? tin->unpaid
1178.                      : (costly_spot(tin->ox, tin->oy) && !tin->no_charge)) {
1179.         if (tin->quan > 1L) {
1180.             tin = context.tin.tin = splitobj(tin, 1L);
1181.             context.tin.o_id = tin->o_id;
1182.         }
1183.         costly_alteration(tin, alter_type);
1184.     }
1185.     return tin;
1186. }
1187. 
1188. int
1189. tin_variety_txt(s, tinvariety)
1190. char *s;
1191. int *tinvariety;
1192. {
1193.     int k, l;
1194. 
1195.     if (s && tinvariety) {
1196.         *tinvariety = -1;
1197.         for (k = 0; k < TTSZ - 1; ++k) {
1198.             l = (int) strlen(tintxts[k].txt);
1199.             if (!strncmpi(s, tintxts[k].txt, l) && ((int) strlen(s) > l)
1200.                 && s[l] == ' ') {
1201.                 *tinvariety = k;
1202.                 return (l + 1);
1203.             }
1204.         }
1205.     }
1206.     return 0;
1207. }
1208. 
1209. /*
1210.  * This assumes that buf already contains the word "tin",
1211.  * as is the case with caller xname().
1212.  */
1213. void
1214. tin_details(obj, mnum, buf)
1215. struct obj *obj;
1216. int mnum;
1217. char *buf;
1218. {
1219.     char buf2[BUFSZ];
1220.     int r = tin_variety(obj, TRUE);
1221. 
1222.     if (obj && buf) {
1223.         if (r == SPINACH_TIN)
1224.             Strcat(buf, " of spinach");
1225.         else if (mnum == NON_PM)
1226.             Strcpy(buf, "empty tin");
1227.         else {
1228.             if ((obj->cknown || iflags.override_ID) && obj->spe < 0) {
1229.                 if (r == ROTTEN_TIN || r == HOMEMADE_TIN) {
1230.                     /* put these before the word tin */
1231.                     Sprintf(buf2, "%s %s of ", tintxts[r].txt, buf);
1232.                     Strcpy(buf, buf2);
1233.                 } else {
1234.                     Sprintf(eos(buf), " of %s ", tintxts[r].txt);
1235.                 }
1236.             } else {
1237.                 Strcpy(eos(buf), " of ");
1238.             }
1239.             if (vegetarian(&mons[mnum]))
1240.                 Sprintf(eos(buf), "%s", mons[mnum].mname);
1241.             else
1242.                 Sprintf(eos(buf), "%s meat", mons[mnum].mname);
1243.         }
1244.     }
1245. }
1246. 
1247. void
1248. set_tin_variety(obj, forcetype)
1249. struct obj *obj;
1250. int forcetype;
1251. {
1252.     register int r;
1253. 
1254.     if (forcetype == SPINACH_TIN
1255.         || (forcetype == HEALTHY_TIN
1256.             && (obj->corpsenm == NON_PM /* empty or already spinach */
1257.                 || !vegetarian(&mons[obj->corpsenm])))) { /* replace meat */
1258.         obj->corpsenm = NON_PM; /* not based on any monster */
1259.         obj->spe = 1;           /* spinach */
1260.         return;
1261.     } else if (forcetype == HEALTHY_TIN) {
1262.         r = tin_variety(obj, FALSE);
1263.         if (r < 0 || r >= TTSZ)
1264.             r = ROTTEN_TIN; /* shouldn't happen */
1265.         while ((r == ROTTEN_TIN && !obj->cursed) || !tintxts[r].fodder)
1266.             r = rn2(TTSZ - 1);
1267.     } else if (forcetype >= 0 && forcetype < TTSZ - 1) {
1268.         r = forcetype;
1269.     } else {               /* RANDOM_TIN */
1270.         r = rn2(TTSZ - 1); /* take your pick */
1271.         if (r == ROTTEN_TIN && nonrotting_corpse(obj->corpsenm))
1272.             r = HOMEMADE_TIN; /* lizards don't rot */
1273.     }
1274.     obj->spe = -(r + 1); /* offset by 1 to allow index 0 */
1275. }
1276. 
1277. STATIC_OVL int
1278. tin_variety(obj, disp)
1279. struct obj *obj;
1280. boolean disp; /* we're just displaying so leave things alone */
1281. {
1282.     register int r;
1283. 
1284.     if (obj->spe == 1) {
1285.         r = SPINACH_TIN;
1286.     } else if (obj->cursed) {
1287.         r = ROTTEN_TIN; /* always rotten if cursed */
1288.     } else if (obj->spe < 0) {
1289.         r = -(obj->spe);
1290.         --r; /* get rid of the offset */
1291.     } else
1292.         r = rn2(TTSZ - 1);
1293. 
1294.     if (!disp && r == HOMEMADE_TIN && !obj->blessed && !rn2(7))
1295.         r = ROTTEN_TIN; /* some homemade tins go bad */
1296. 
1297.     if (r == ROTTEN_TIN && nonrotting_corpse(obj->corpsenm))
1298.         r = HOMEMADE_TIN; /* lizards don't rot */
1299.     return r;
1300. }
1301. 
1302. STATIC_OVL void
1303. consume_tin(mesg)
1304. const char *mesg;
1305. {
1306.     const char *what;
1307.     int which, mnum, r;
1308.     struct obj *tin = context.tin.tin;
1309. 
1310.     r = tin_variety(tin, FALSE);
1311.     if (tin->otrapped || (tin->cursed && r != HOMEMADE_TIN && !rn2(8))) {
1312.         b_trapped("tin", 0);
1313.         tin = costly_tin(COST_DSTROY);
1314.         goto use_up_tin;
1315.     }
1316. 
1317.     pline1(mesg); /* "You succeed in opening the tin." */
1318. 
1319.     if (r != SPINACH_TIN) {
1320.         mnum = tin->corpsenm;
1321.         if (mnum == NON_PM) {
1322.             pline("It turns out to be empty.");
1323.             tin->dknown = tin->known = 1;
1324.             tin = costly_tin(COST_OPEN);
1325.             goto use_up_tin;
1326.         }
1327. 
1328.         which = 0; /* 0=>plural, 1=>as-is, 2=>"the" prefix */
1329.         if ((mnum == PM_COCKATRICE || mnum == PM_CHICKATRICE)
1330.             && (Stone_resistance || Hallucination)) {
1331.             what = "chicken";
1332.             which = 1; /* suppress pluralization */
1333.         } else if (Hallucination) {
1334.             what = rndmonnam(NULL);
1335.         } else {
1336.             what = mons[mnum].mname;
1337.             if (the_unique_pm(&mons[mnum]))
1338.                 which = 2;
1339.             else if (type_is_pname(&mons[mnum]))
1340.                 which = 1;
1341.         }
1342.         if (which == 0)
1343.             what = makeplural(what);
1344.         else if (which == 2)
1345.             what = the(what);
1346. 
1347.         pline("It smells like %s.", what);
1348.         if (yn("Eat it?") == 'n') {
1349.             if (flags.verbose)
1350.                 You("discard the open tin.");
1351.             if (!Hallucination)
1352.                 tin->dknown = tin->known = 1;
1353.             tin = costly_tin(COST_OPEN);
1354.             goto use_up_tin;
1355.         }
1356. 
1357.         /* in case stop_occupation() was called on previous meal */
1358.         context.victual.piece = (struct obj *) 0;
1359.         context.victual.o_id = 0;
1360.         context.victual.fullwarn = context.victual.eating =
1361.             context.victual.doreset = FALSE;
1362. 
1363.         You("consume %s %s.", tintxts[r].txt, mons[mnum].mname);
1364. 
1365.         eating_conducts(&mons[mnum]);
1366. 
1367.         tin->dknown = tin->known = 1;
1368.         cprefx(mnum);
1369.         cpostfx(mnum);
1370. 
1371.         /* charge for one at pre-eating cost */
1372.         tin = costly_tin(COST_OPEN);
1373. 
1374.         if (tintxts[r].nut < 0) /* rotten */
1375.             make_vomiting((long) rn1(15, 10), FALSE);
1376.         else
1377.             lesshungry(tintxts[r].nut);
1378. 
1379.         if (tintxts[r].greasy) {
1380.             /* Assume !Glib, because you can't open tins when Glib. */
1381.             make_glib(rn1(11, 5)); /* 5..15 */
1382.             pline("Eating %s food made your %s very slippery.",
1383.                   tintxts[r].txt, fingers_or_gloves(TRUE));
1384.         }
1385. 
1386.     } else { /* spinach... */
1387.         if (tin->cursed) {
1388.             pline("It contains some decaying%s%s substance.",
1389.                   Blind ? "" : " ", Blind ? "" : hcolor(NH_GREEN));
1390.         } else {
1391.             pline("It contains spinach.");
1392.             tin->dknown = tin->known = 1;
1393.         }
1394. 
1395.         if (yn("Eat it?") == 'n') {
1396.             if (flags.verbose)
1397.                 You("discard the open tin.");
1398.             tin = costly_tin(COST_OPEN);
1399.             goto use_up_tin;
1400.         }
1401. 
1402.         /*
1403.          * Same order as with non-spinach above:
1404.          * conduct update, side-effects, shop handling, and nutrition.
1405.          */
1406.         u.uconduct.food++; /* don't need vegetarian checks for spinach */
1407.         if (!tin->cursed)
1408.             pline("This makes you feel like %s!",
1409.                   /* "Swee'pea" is a character from the Popeye cartoons */
1410.                   Hallucination ? "Swee'pea"
1411.                   /* "feel like Popeye" unless sustain ability suppresses
1412.                      any attribute change; this slightly oversimplifies
1413.                      things:  we want "Popeye" if no strength increase
1414.                      occurs due to already being at maximum, but we won't
1415.                      get it if at-maximum and fixed-abil both apply */
1416.                   : !Fixed_abil ? "Popeye"
1417.                   /* no gain, feel like another character from Popeye */
1418.                   : (flags.female ? "Olive Oyl" : "Bluto"));
1419.         gainstr(tin, 0, FALSE);
1420. 
1421.         tin = costly_tin(COST_OPEN);
1422.         lesshungry(tin->blessed ? 600                   /* blessed */
1423.                    : !tin->cursed ? (400 + rnd(200))    /* uncursed */
1424.                      : (200 + rnd(400)));               /* cursed */
1425.     }
1426. 
1427.  use_up_tin:
1428.     if (carried(tin))
1429.         useup(tin);
1430.     else
1431.         useupf(tin, 1L);
1432.     context.tin.tin = (struct obj *) 0;
1433.     context.tin.o_id = 0;
1434. }
1435. 
1436. /* called during each move whilst opening a tin */
1437. STATIC_PTR int
1438. opentin(VOID_ARGS)
1439. {
1440.     /* perhaps it was stolen (although that should cause interruption) */
1441.     if (!carried(context.tin.tin)
1442.         && (!obj_here(context.tin.tin, u.ux, u.uy) || !can_reach_floor(TRUE)))
1443.         return 0; /* %% probably we should use tinoid */
1444.     if (context.tin.usedtime++ >= 50) {
1445.         You("give up your attempt to open the tin.");
1446.         return 0;
1447.     }
1448.     if (context.tin.usedtime < context.tin.reqtime)
1449.         return 1; /* still busy */
1450. 
1451.     consume_tin("You succeed in opening the tin.");
1452.     return 0;
1453. }
1454. 
1455. /* called when starting to open a tin */
1456. STATIC_OVL void
1457. start_tin(otmp)
1458. struct obj *otmp;
1459. {
1460.     const char *mesg = 0;
1461.     register int tmp;
1462. 
1463.     if (metallivorous(youmonst.data)) {
1464.         mesg = "You bite right into the metal tin...";
1465.         tmp = 0;
1466.     } else if (cantwield(youmonst.data)) { /* nohands || verysmall */
1467.         You("cannot handle the tin properly to open it.");
1468.         return;
1469.     } else if (otmp->blessed) {
1470.         /* 50/50 chance for immediate access vs 1 turn delay (unless
1471.            wielding blessed tin opener which always yields immediate
1472.            access); 1 turn delay case is non-deterministic:  getting
1473.            interrupted and retrying might yield another 1 turn delay
1474.            or might open immediately on 2nd (or 3rd, 4th, ...) try */
1475.         tmp = (uwep && uwep->blessed && uwep->otyp == TIN_OPENER) ? 0 : rn2(2);
1476.         if (!tmp)
1477.             mesg = "The tin opens like magic!";
1478.         else
1479.             pline_The("tin seems easy to open.");
1480.     } else if (uwep) {
1481.         switch (uwep->otyp) {
1482.         case TIN_OPENER:
1483.             mesg = "You easily open the tin."; /* iff tmp==0 */
1484.             tmp = rn2(uwep->cursed ? 3 : !uwep->blessed ? 2 : 1);
1485.             break;
1486.         case DAGGER:
1487.         case SILVER_DAGGER:
1488.         case ELVEN_DAGGER:
1489.         case ORCISH_DAGGER:
1490.         case ATHAME:
1491.         case KNIFE:
1492.         case STILETTO:
1493.         case CRYSKNIFE:
1494.             tmp = 3;
1495.             break;
1496.         case PICK_AXE:
1497.         case AXE:
1498.             tmp = 6;
1499.             break;
1500.         default:
1501.             goto no_opener;
1502.         }
1503.         pline("Using %s you try to open the tin.", yobjnam(uwep, (char *) 0));
1504.     } else {
1505.  no_opener:
1506.         pline("It is not so easy to open this tin.");
1507.         if (Glib) {
1508.             pline_The("tin slips from your %s.", fingers_or_gloves(FALSE));
1509.             if (otmp->quan > 1L) {
1510.                 otmp = splitobj(otmp, 1L);
1511.             }
1512.             if (carried(otmp))
1513.                 dropx(otmp);
1514.             else
1515.                 stackobj(otmp);
1516.             return;
1517.         }
1518.         tmp = rn1(1 + 500 / ((int) (ACURR(A_DEX) + ACURRSTR)), 10);
1519.     }
1520. 
1521.     context.tin.tin = otmp;
1522.     context.tin.o_id = otmp->o_id;
1523.     if (!tmp) {
1524.         consume_tin(mesg); /* begin immediately */
1525.     } else {
1526.         context.tin.reqtime = tmp;
1527.         context.tin.usedtime = 0;
1528.         set_occupation(opentin, "opening the tin", 0);
1529.     }
1530.     return;
1531. }
1532. 
1533. /* called when waking up after fainting */
1534. int
1535. Hear_again(VOID_ARGS)
1536. {
1537.     /* Chance of deafness going away while fainted/sleeping/etc. */
1538.     if (!rn2(2)) {
1539.         make_deaf(0L, FALSE);
1540.         context.botl = TRUE;
1541.     }
1542.     return 0;
1543. }
1544. 
1545. /* called on the "first bite" of rotten food */
1546. STATIC_OVL int
1547. rottenfood(obj)
1548. struct obj *obj;
1549. {
1550.     pline("Blecch!  Rotten %s!", foodword(obj));
1551.     if (!rn2(4)) {
1552.         if (Hallucination)
1553.             You_feel("rather trippy.");
1554.         else
1555.             You_feel("rather %s.", body_part(LIGHT_HEADED));
1556.         make_confused(HConfusion + d(2, 4), FALSE);
1557.     } else if (!rn2(4) && !Blind) {
1558.         pline("Everything suddenly goes dark.");
1559.         /* hero is not Blind, but Blinded timer might be nonzero if
1560.            blindness is being overridden by the Eyes of the Overworld */
1561.         make_blinded((Blinded & TIMEOUT) + (long) d(2, 10), FALSE);
1562.         if (!Blind)
1563.             Your1(vision_clears);
1564.     } else if (!rn2(3)) {
1565.         const char *what, *where;
1566.         int duration = rnd(10);
1567. 
1568.         if (!Blind)
1569.             what = "goes", where = "dark";
1570.         else if (Levitation || Is_airlevel(&u.uz) || Is_waterlevel(&u.uz))
1571.             what = "you lose control of", where = "yourself";
1572.         else
1573.             what = "you slap against the",
1574.             where = (u.usteed) ? "saddle" : surface(u.ux, u.uy);
1575.         pline_The("world spins and %s %s.", what, where);
1576.         incr_itimeout(&HDeaf, duration);
1577.         context.botl = TRUE;
1578.         nomul(-duration);
1579.         multi_reason = "unconscious from rotten food";
1580.         nomovemsg = "You are conscious again.";
1581.         afternmv = Hear_again;
1582.         return 1;
1583.     }
1584.     return 0;
1585. }
1586. 
1587. /* called when a corpse is selected as food */
1588. STATIC_OVL int
1589. eatcorpse(otmp)
1590. struct obj *otmp;
1591. {
1592.     int retcode = 0, tp = 0, mnum = otmp->corpsenm;
1593.     long rotted = 0L;
1594.     boolean stoneable = (flesh_petrifies(&mons[mnum]) && !Stone_resistance
1595.                          && !poly_when_stoned(youmonst.data)),
1596.             slimeable = (mnum == PM_GREEN_SLIME && !Slimed && !Unchanging
1597.                          && !slimeproof(youmonst.data)),
1598.             glob = otmp->globby ? TRUE : FALSE;
1599. 
1600.     /* KMH, conduct */
1601.     if (!vegan(&mons[mnum]))
1602.         u.uconduct.unvegan++;
1603.     if (!vegetarian(&mons[mnum]))
1604.         violated_vegetarian();
1605. 
1606.     if (!nonrotting_corpse(mnum)) {
1607.         long age = peek_at_iced_corpse_age(otmp);
1608. 
1609.         rotted = (monstermoves - age) / (10L + rn2(20));
1610.         if (otmp->cursed)
1611.             rotted += 2L;
1612.         else if (otmp->blessed)
1613.             rotted -= 2L;
1614.     }
1615. 
1616.     if (mnum != PM_ACID_BLOB && !stoneable && !slimeable && rotted > 5L) {
1617.         boolean cannibal = maybe_cannibal(mnum, FALSE);
1618. 
1619.         pline("Ulch - that %s was tainted%s!",
1620.               (mons[mnum].mlet == S_FUNGUS) ? "fungoid vegetation"
1621.                   : glob ? "glob"
1622.                       : vegetarian(&mons[mnum]) ? "protoplasm"
1623.                           : "meat",
1624.               cannibal ? ", you cannibal" : "");
1625.         if (Sick_resistance) {
1626.             pline("It doesn't seem at all sickening, though...");
1627.         } else {
1628.             long sick_time;
1629. 
1630.             sick_time = (long) rn1(10, 10);
1631.             /* make sure new ill doesn't result in improvement */
1632.             if (Sick && (sick_time > Sick))
1633.                 sick_time = (Sick > 1L) ? Sick - 1L : 1L;
1634.             make_sick(sick_time, corpse_xname(otmp, "rotted", CXN_NORMAL),
1635.                       TRUE, SICK_VOMITABLE);
1636. 
1637.             pline("(It must have died too long ago to be safe to eat.)");
1638.         }
1639.         if (carried(otmp))
1640.             useup(otmp);
1641.         else
1642.             useupf(otmp, 1L);
1643.         return 2;
1644.     } else if (acidic(&mons[mnum]) && !Acid_resistance) {
1645.         tp++;
1646.         You("have a very bad case of stomach acid.");   /* not body_part() */
1647.         losehp(rnd(15), !glob ? "acidic corpse" : "acidic glob",
1648.                KILLED_BY_AN); /* acid damage */
1649.     } else if (poisonous(&mons[mnum]) && rn2(5)) {
1650.         tp++;
1651.         pline("Ecch - that must have been poisonous!");
1652.         if (!Poison_resistance) {
1653.             losestr(rnd(4));
1654.             losehp(rnd(15), !glob ? "poisonous corpse" : "poisonous glob",
1655.                    KILLED_BY_AN);
1656.         } else
1657.             You("seem unaffected by the poison.");
1658.     /* now any corpse left too long will make you mildly ill */
1659.     } else if ((rotted > 5L || (rotted > 3L && rn2(5))) && !Sick_resistance) {
1660.         tp++;
1661.         You_feel("%ssick.", (Sick) ? "very " : "");
1662.         losehp(rnd(8), !glob ? "cadaver" : "rotted glob", KILLED_BY_AN);
1663.     }
1664. 
1665.     /* delay is weight dependent */
1666.     context.victual.reqtime = 3 + ((!glob ? mons[mnum].cwt : otmp->owt) >> 6);
1667. 
1668.     if (!tp && !nonrotting_corpse(mnum) && (otmp->orotten || !rn2(7))) {
1669.         if (rottenfood(otmp)) {
1670.             otmp->orotten = TRUE;
1671.             (void) touchfood(otmp);
1672.             retcode = 1;
1673.         }
1674. 
1675.         if (!mons[otmp->corpsenm].cnutrit) {
1676.             /* no nutrition: rots away, no message if you passed out */
1677.             if (!retcode)
1678.                 pline_The("corpse rots away completely.");
1679.             if (carried(otmp))
1680.                 useup(otmp);
1681.             else
1682.                 useupf(otmp, 1L);
1683.             retcode = 2;
1684.         }
1685. 
1686.         if (!retcode)
1687.             consume_oeaten(otmp, 2); /* oeaten >>= 2 */
1688.     } else if ((mnum == PM_COCKATRICE || mnum == PM_CHICKATRICE)
1689.                && (Stone_resistance || Hallucination)) {
1690.         pline("This tastes just like chicken!");
1691.     } else if (mnum == PM_FLOATING_EYE && u.umonnum == PM_RAVEN) {
1692.         You("peck the eyeball with delight.");
1693.     } else {
1694.         /* yummy is always False for omnivores, palatable always True */
1695.         boolean yummy = (vegan(&mons[mnum])
1696.                             ? (!carnivorous(youmonst.data)
1697.                                && herbivorous(youmonst.data))
1698.                             : (carnivorous(youmonst.data)
1699.                                && !herbivorous(youmonst.data))),
1700.             palatable = ((vegetarian(&mons[mnum])
1701.                           ? herbivorous(youmonst.data)
1702.                           : carnivorous(youmonst.data))
1703.                          && rn2(10)
1704.                          && ((rotted < 1) ? TRUE : !rn2(rotted+1)));
1705.         const char *pmxnam = food_xname(otmp, FALSE);
1706. 
1707.         if (!strncmpi(pmxnam, "the ", 4))
1708.             pmxnam += 4;
1709.         pline("%s%s %s %s%c",
1710.               type_is_pname(&mons[mnum])
1711.                  ? "" : the_unique_pm(&mons[mnum]) ? "The " : "This ",
1712.               pmxnam,
1713.               Hallucination ? "is" : "tastes",
1714.                   /* tiger reference is to TV ads for "Frosted Flakes",
1715.                      breakfast cereal targeted at kids by "Tony the tiger" */
1716.               Hallucination
1717.                  ? (yummy ? ((u.umonnum == PM_TIGER) ? "gr-r-reat" : "gnarly")
1718.                           : palatable ? "copacetic" : "grody")
1719.                  : (yummy ? "delicious" : palatable ? "okay" : "terrible"),
1720.               (yummy || !palatable) ? '!' : '.');
1721.     }
1722. 
1723.     return retcode;
1724. }
1725. 
1726. /* called as you start to eat */
1727. STATIC_OVL void
1728. start_eating(otmp, already_partly_eaten)
1729. struct obj *otmp;
1730. boolean already_partly_eaten;
1731. {
1732.     const char *old_nomovemsg, *save_nomovemsg;
1733. 
1734.     debugpline2("start_eating: %s (victual = %s)",
1735.                 /* note: fmt_ptr() returns a static buffer but supports
1736.                    several such so we don't need to copy the first result
1737.                    before calling it a second time */
1738.                 fmt_ptr((genericptr_t) otmp),
1739.                 fmt_ptr((genericptr_t) context.victual.piece));
1740.     debugpline1("reqtime = %d", context.victual.reqtime);
1741.     debugpline1("(original reqtime = %d)", objects[otmp->otyp].oc_delay);
1742.     debugpline1("nmod = %d", context.victual.nmod);
1743.     debugpline1("oeaten = %d", otmp->oeaten);
1744.     context.victual.fullwarn = context.victual.doreset = FALSE;
1745.     context.victual.eating = TRUE;
1746. 
1747.     if (otmp->otyp == CORPSE || otmp->globby) {
1748.         cprefx(context.victual.piece->corpsenm);
1749.         if (!context.victual.piece || !context.victual.eating) {
1750.             /* rider revived, or died and lifesaved */
1751.             return;
1752.         }
1753.     }
1754. 
1755.     old_nomovemsg = nomovemsg;
1756.     if (bite()) {
1757.         /* survived choking, finish off food that's nearly done;
1758.            need this to handle cockatrice eggs, fortune cookies, etc */
1759.         if (++context.victual.usedtime >= context.victual.reqtime) {
1760.             /* don't want done_eating() to issue nomovemsg if it
1761.                is due to vomit() called by bite() */
1762.             save_nomovemsg = nomovemsg;
1763.             if (!old_nomovemsg)
1764.                 nomovemsg = 0;
1765.             done_eating(FALSE);
1766.             if (!old_nomovemsg)
1767.                 nomovemsg = save_nomovemsg;
1768.         }
1769.         return;
1770.     }
1771. 
1772.     if (++context.victual.usedtime >= context.victual.reqtime) {
1773.         /* print "finish eating" message if they just resumed -dlc */
1774.         done_eating((context.victual.reqtime > 1
1775.                      || already_partly_eaten) ? TRUE : FALSE);
1776.         return;
1777.     }
1778. 
1779.     Sprintf(msgbuf, "eating %s", food_xname(otmp, TRUE));
1780.     set_occupation(eatfood, msgbuf, 0);
1781. }
1782. 
1783. /*
1784.  * Called on "first bite" of (non-corpse) food, after touchfood() has
1785.  * marked it 'partly eaten'.  Used for non-rotten non-tin non-corpse food.
1786.  * Messages should use present tense since multi-turn food won't be
1787.  * finishing at the time they're issued.
1788.  */
1789. STATIC_OVL void
1790. fprefx(otmp)
1791. struct obj *otmp;
1792. {
1793.     switch (otmp->otyp) {
1794.     case FOOD_RATION: /* nutrition 800 */
1795.         /* 200+800 remains below 1000+1, the satiation threshold */
1796.         if (u.uhunger <= 200)
1797.             pline("%s!", Hallucination ? "Oh wow, like, superior, man"
1798.                                        : "This food really hits the spot");
1799. 
1800.         /* 700-1+800 remains below 1500, the choking threshold which
1801.            triggers "you're having a hard time getting it down" feedback */
1802.         else if (u.uhunger < 700)
1803.             pline("This satiates your %s!", body_part(STOMACH));
1804.         /* [satiation message may be inaccurate if eating gets interrupted] */
1805.         break;
1806.     case TRIPE_RATION:
1807.         if (carnivorous(youmonst.data) && !humanoid(youmonst.data)) {
1808.             pline("This tripe ration is surprisingly good!");
1809.         } else if (maybe_polyd(is_orc(youmonst.data), Race_if(PM_ORC))) {
1810.             pline(Hallucination ? "Tastes great!  Less filling!"
1811.                                 : "Mmm, tripe... not bad!");
1812.         } else {
1813.             pline("Yak - dog food!");
1814.             more_experienced(1, 0);
1815.             newexplevel();
1816.             /* not cannibalism, but we use similar criteria
1817.                for deciding whether to be sickened by this meal */
1818.             if (rn2(2) && !CANNIBAL_ALLOWED())
1819.                 make_vomiting((long) rn1(context.victual.reqtime, 14), FALSE);
1820.         }
1821.         break;
1822.     case LEMBAS_WAFER:
1823.         if (maybe_polyd(is_orc(youmonst.data), Race_if(PM_ORC))) {
1824.             pline("%s", "!#?&* elf kibble!");
1825.             break;
1826.         } else if (maybe_polyd(is_elf(youmonst.data), Race_if(PM_ELF))) {
1827.             pline("A little goes a long way.");
1828.             break;
1829.         }
1830.         goto give_feedback;
1831.     case MEATBALL:
1832.     case MEAT_STICK:
1833.     case HUGE_CHUNK_OF_MEAT:
1834.     case MEAT_RING:
1835.         goto give_feedback;
1836.     case CLOVE_OF_GARLIC:
1837.         if (is_undead(youmonst.data)) {
1838.             make_vomiting((long) rn1(context.victual.reqtime, 5), FALSE);
1839.             break;
1840.         }
1841.         /*FALLTHRU*/
1842.     default:
1843.         if (otmp->otyp == SLIME_MOLD && !otmp->cursed
1844.             && otmp->spe == context.current_fruit) {
1845.             pline("My, this is a %s %s!",
1846.                   Hallucination ? "primo" : "yummy",
1847.                   singular(otmp, xname));
1848.         } else if (otmp->otyp == APPLE && otmp->cursed && !Sleep_resistance) {
1849.             ; /* skip core joke; feedback deferred til fpostfx() */
1850. 
1851. #if defined(MAC) || defined(MACOSX)
1852.         /* KMH -- Why should Unix have all the fun?
1853.            We check MACOSX before UNIX to get the Apple-specific apple
1854.            message; the '#if UNIX' code will still kick in for pear. */
1855.         } else if (otmp->otyp == APPLE) {
1856.             pline("Delicious!  Must be a Macintosh!");
1857. #endif
1858. 
1859. #ifdef UNIX
1860.         } else if (otmp->otyp == APPLE || otmp->otyp == PEAR) {
1861.             if (!Hallucination) {
1862.                 pline("Core dumped.");
1863.             } else {
1864.                 /* based on an old Usenet joke, a fake a.out manual page */
1865.                 int x = rnd(100);
1866. 
1867.                 pline("%s -- core dumped.",
1868.                       (x <= 75)
1869.                          ? "Segmentation fault"
1870.                          : (x <= 99)
1871.                             ? "Bus error"
1872.                             : "Yo' mama");
1873.             }
1874. #endif
1875.         } else if (otmp->otyp == EGG && stale_egg(otmp)) {
1876.             pline("Ugh.  Rotten egg."); /* perhaps others like it */
1877.             /* increasing existing nausea means that it will take longer
1878.                before eventual vomit, but also means that constitution
1879.                will be abused more times before illness completes */
1880.             make_vomiting((Vomiting & TIMEOUT) + (long) d(10, 4), TRUE);
1881.         } else {
1882.  give_feedback:
1883.             pline("This %s is %s", singular(otmp, xname),
1884.                   otmp->cursed
1885.                      ? (Hallucination ? "grody!" : "terrible!")
1886.                      : (otmp->otyp == CRAM_RATION
1887.                         || otmp->otyp == K_RATION
1888.                         || otmp->otyp == C_RATION)
1889.                         ? "bland."
1890.                         : Hallucination ? "gnarly!" : "delicious!");
1891.         }
1892.         break; /* default */
1893.     } /* switch */
1894. }
1895. 
1896. /* increment a combat intrinsic with limits on its growth */
1897. STATIC_OVL int
1898. bounded_increase(old, inc, typ)
1899. int old, inc, typ;
1900. {
1901.     int absold, absinc, sgnold, sgninc;
1902. 
1903.     /* don't include any amount coming from worn rings (caller handles
1904.        'protection' differently) */
1905.     if (uright && uright->otyp == typ && typ != RIN_PROTECTION)
1906.         old -= uright->spe;
1907.     if (uleft && uleft->otyp == typ && typ != RIN_PROTECTION)
1908.         old -= uleft->spe;
1909.     absold = abs(old), absinc = abs(inc);
1910.     sgnold = sgn(old), sgninc = sgn(inc);
1911. 
1912.     if (absinc == 0 || sgnold != sgninc || absold + absinc < 10) {
1913.         ; /* use inc as-is */
1914.     } else if (absold + absinc < 20) {
1915.         absinc = rnd(absinc); /* 1..n */
1916.         if (absold + absinc < 10)
1917.             absinc = 10 - absold;
1918.         inc = sgninc * absinc;
1919.     } else if (absold + absinc < 40) {
1920.         absinc = rn2(absinc) ? 1 : 0;
1921.         if (absold + absinc < 20)
1922.             absinc = rnd(20 - absold);
1923.         inc = sgninc * absinc;
1924.     } else {
1925.         inc = 0; /* no further increase allowed via this method */
1926.     }
1927.     /* put amount from worn rings back */
1928.     if (uright && uright->otyp == typ && typ != RIN_PROTECTION)
1929.         old += uright->spe;
1930.     if (uleft && uleft->otyp == typ && typ != RIN_PROTECTION)
1931.         old += uleft->spe;
1932.     return old + inc;
1933. }
1934. 
1935. STATIC_OVL void
1936. accessory_has_effect(otmp)
1937. struct obj *otmp;
1938. {
1939.     pline("Magic spreads through your body as you digest the %s.",
1940.           (otmp->oclass == RING_CLASS) ? "ring" : "amulet");
1941. }
1942. 
1943. STATIC_OVL void
1944. eataccessory(otmp)
1945. struct obj *otmp;
1946. {
1947.     int typ = otmp->otyp;
1948.     long oldprop;
1949. 
1950.     /* Note: rings are not so common that this is unbalancing. */
1951.     /* (How often do you even _find_ 3 rings of polymorph in a game?) */
1952.     oldprop = u.uprops[objects[typ].oc_oprop].intrinsic;
1953.     if (otmp == uleft || otmp == uright) {
1954.         Ring_gone(otmp);
1955.         if (u.uhp <= 0)
1956.             return; /* died from sink fall */
1957.     }
1958.     otmp->known = otmp->dknown = 1; /* by taste */
1959.     if (!rn2(otmp->oclass == RING_CLASS ? 3 : 5)) {
1960.         switch (otmp->otyp) {
1961.         default:
1962.             if (!objects[typ].oc_oprop)
1963.                 break; /* should never happen */
1964. 
1965.             if (!(u.uprops[objects[typ].oc_oprop].intrinsic & FROMOUTSIDE))
1966.                 accessory_has_effect(otmp);
1967. 
1968.             u.uprops[objects[typ].oc_oprop].intrinsic |= FROMOUTSIDE;
1969. 
1970.             switch (typ) {
1971.             case RIN_SEE_INVISIBLE:
1972.                 set_mimic_blocking();
1973.                 see_monsters();
1974.                 if (Invis && !oldprop && !ESee_invisible
1975.                     && !perceives(youmonst.data) && !Blind) {
1976.                     newsym(u.ux, u.uy);
1977.                     pline("Suddenly you can see yourself.");
1978.                     makeknown(typ);
1979.                 }
1980.                 break;
1981.             case RIN_INVISIBILITY:
1982.                 if (!oldprop && !EInvis && !BInvis && !See_invisible
1983.                     && !Blind) {
1984.                     newsym(u.ux, u.uy);
1985.                     Your("body takes on a %s transparency...",
1986.                          Hallucination ? "normal" : "strange");
1987.                     makeknown(typ);
1988.                 }
1989.                 break;
1990.             case RIN_PROTECTION_FROM_SHAPE_CHAN:
1991.                 rescham();
1992.                 break;
1993.             case RIN_LEVITATION:
1994.                 /* undo the `.intrinsic |= FROMOUTSIDE' done above */
1995.                 u.uprops[LEVITATION].intrinsic = oldprop;
1996.                 if (!Levitation) {
1997.                     float_up();
1998.                     incr_itimeout(&HLevitation, d(10, 20));
1999.                     makeknown(typ);
2000.                 }
2001.                 break;
2002.             } /* inner switch */
2003.             break; /* default case of outer switch */
2004. 
2005.         case RIN_ADORNMENT:
2006.             accessory_has_effect(otmp);
2007.             if (adjattrib(A_CHA, otmp->spe, -1))
2008.                 makeknown(typ);
2009.             break;
2010.         case RIN_GAIN_STRENGTH:
2011.             accessory_has_effect(otmp);
2012.             if (adjattrib(A_STR, otmp->spe, -1))
2013.                 makeknown(typ);
2014.             break;
2015.         case RIN_GAIN_CONSTITUTION:
2016.             accessory_has_effect(otmp);
2017.             if (adjattrib(A_CON, otmp->spe, -1))
2018.                 makeknown(typ);
2019.             break;
2020.         case RIN_INCREASE_ACCURACY:
2021.             accessory_has_effect(otmp);
2022.             u.uhitinc = (schar) bounded_increase((int) u.uhitinc, otmp->spe,
2023.                                                  RIN_INCREASE_ACCURACY);
2024.             break;
2025.         case RIN_INCREASE_DAMAGE:
2026.             accessory_has_effect(otmp);
2027.             u.udaminc = (schar) bounded_increase((int) u.udaminc, otmp->spe,
2028.                                                  RIN_INCREASE_DAMAGE);
2029.             break;
2030.         case RIN_PROTECTION:
2031.             accessory_has_effect(otmp);
2032.             HProtection |= FROMOUTSIDE;
2033.             u.ublessed = bounded_increase(u.ublessed, otmp->spe,
2034.                                           RIN_PROTECTION);
2035.             context.botl = 1;
2036.             break;
2037.         case RIN_FREE_ACTION:
2038.             /* Give sleep resistance instead */
2039.             if (!(HSleep_resistance & FROMOUTSIDE))
2040.                 accessory_has_effect(otmp);
2041.             if (!Sleep_resistance)
2042.                 You_feel("wide awake.");
2043.             HSleep_resistance |= FROMOUTSIDE;
2044.             break;
2045.         case AMULET_OF_CHANGE:
2046.             accessory_has_effect(otmp);
2047.             makeknown(typ);
2048.             change_sex();
2049.             You("are suddenly very %s!",
2050.                 flags.female ? "feminine" : "masculine");
2051.             context.botl = 1;
2052.             break;
2053.         case AMULET_OF_UNCHANGING:
2054.             /* un-change: it's a pun */
2055.             if (!Unchanging && Upolyd) {
2056.                 accessory_has_effect(otmp);
2057.                 makeknown(typ);
2058.                 rehumanize();
2059.             }
2060.             break;
2061.         case AMULET_OF_STRANGULATION: /* bad idea! */
2062.             /* no message--this gives no permanent effect */
2063.             choke(otmp);
2064.             break;
2065.         case AMULET_OF_RESTFUL_SLEEP: { /* another bad idea! */
2066.             long newnap = (long) rnd(100), oldnap = (HSleepy & TIMEOUT);
2067. 
2068.             if (!(HSleepy & FROMOUTSIDE))
2069.                 accessory_has_effect(otmp);
2070.             HSleepy |= FROMOUTSIDE;
2071.             /* might also be wearing one; use shorter of two timeouts */
2072.             if (newnap < oldnap || oldnap == 0L)
2073.                 HSleepy = (HSleepy & ~TIMEOUT) | newnap;
2074.             break;
2075.         }
2076.         case RIN_SUSTAIN_ABILITY:
2077.         case AMULET_OF_LIFE_SAVING:
2078.         case AMULET_OF_REFLECTION: /* nice try */
2079.             /* can't eat Amulet of Yendor or fakes,
2080.              * and no oc_prop even if you could -3.
2081.              */
2082.             break;
2083.         }
2084.     }
2085. }
2086. 
2087. /* called after eating non-food */
2088. STATIC_OVL void
2089. eatspecial()
2090. {
2091.     struct obj *otmp = context.victual.piece;
2092. 
2093.     /* lesshungry wants an occupation to handle choke messages correctly */
2094.     set_occupation(eatfood, "eating non-food", 0);
2095.     lesshungry(context.victual.nmod);
2096.     occupation = 0;
2097.     context.victual.piece = (struct obj *) 0;
2098.     context.victual.o_id = 0;
2099.     context.victual.eating = 0;
2100.     if (otmp->oclass == COIN_CLASS) {
2101.         if (carried(otmp))
2102.             useupall(otmp);
2103.         else
2104.             useupf(otmp, otmp->quan);
2105.         vault_gd_watching(GD_EATGOLD);
2106.         return;
2107.     }
2108.     if (objects[otmp->otyp].oc_material == PAPER) {
2109. #ifdef MAIL
2110.         if (otmp->otyp == SCR_MAIL)
2111.             /* no nutrition */
2112.             pline("This junk mail is less than satisfying.");
2113.         else
2114. #endif
2115.         if (otmp->otyp == SCR_SCARE_MONSTER)
2116.             /* to eat scroll, hero is currently polymorphed into a monster */
2117.             pline("Yuck%c", otmp->blessed ? '!' : '.');
2118.         else if (otmp->oclass == SCROLL_CLASS
2119.                  /* check description after checking for specific scrolls */
2120.                  && !strcmpi(OBJ_DESCR(objects[otmp->otyp]), "YUM YUM"))
2121.             pline("Yum%c", otmp->blessed ? '!' : '.');
2122.         else
2123.             pline("Needs salt...");
2124.     }
2125.     if (otmp->oclass == POTION_CLASS) {
2126.         otmp->quan++; /* dopotion() does a useup() */
2127.         (void) dopotion(otmp);
2128.     } else if (otmp->oclass == RING_CLASS || otmp->oclass == AMULET_CLASS) {
2129.         eataccessory(otmp);
2130.     } else if (otmp->otyp == LEASH && otmp->leashmon) {
2131.         o_unleash(otmp);
2132.     }
2133. 
2134.     /* KMH -- idea by "Tommy the Terrorist" */
2135.     if (otmp->otyp == TRIDENT && !otmp->cursed) {
2136.         /* sugarless chewing gum which used to be heavily advertised on TV */
2137.         pline(Hallucination ? "Four out of five dentists agree."
2138.                             : "That was pure chewing satisfaction!");
2139.         exercise(A_WIS, TRUE);
2140.     }
2141.     if (otmp->otyp == FLINT && !otmp->cursed) {
2142.         /* chewable vitamin for kids based on "The Flintstones" TV cartoon */
2143.         pline("Yabba-dabba delicious!");
2144.         exercise(A_CON, TRUE);
2145.     }
2146. 
2147.     if (otmp == uwep && otmp->quan == 1L)
2148.         uwepgone();
2149.     if (otmp == uquiver && otmp->quan == 1L)
2150.         uqwepgone();
2151.     if (otmp == uswapwep && otmp->quan == 1L)
2152.         uswapwepgone();
2153. 
2154.     if (otmp == uball)
2155.         unpunish();
2156.     if (otmp == uchain)
2157.         unpunish(); /* but no useup() */
2158.     else if (carried(otmp))
2159.         useup(otmp);
2160.     else
2161.         useupf(otmp, 1L);
2162. }
2163. 
2164. /* NOTE: the order of these words exactly corresponds to the
2165.    order of oc_material values #define'd in objclass.h. */
2166. static const char *foodwords[] = {
2167.     "meal",    "liquid",  "wax",       "food", "meat",     "paper",
2168.     "cloth",   "leather", "wood",      "bone", "scale",    "metal",
2169.     "metal",   "metal",   "silver",    "gold", "platinum", "mithril",
2170.     "plastic", "glass",   "rich food", "stone"
2171. };
2172. 
2173. STATIC_OVL const char *
2174. foodword(otmp)
2175. struct obj *otmp;
2176. {
2177.     if (otmp->oclass == FOOD_CLASS)
2178.         return "food";
2179.     if (otmp->oclass == GEM_CLASS && objects[otmp->otyp].oc_material == GLASS
2180.         && otmp->dknown)
2181.         makeknown(otmp->otyp);
2182.     return foodwords[objects[otmp->otyp].oc_material];
2183. }
2184. 
2185. /* called after consuming (non-corpse) food */
2186. STATIC_OVL void
2187. fpostfx(otmp)
2188. struct obj *otmp;
2189. {
2190.     switch (otmp->otyp) {
2191.     case SPRIG_OF_WOLFSBANE:
2192.         if (u.ulycn >= LOW_PM || is_were(youmonst.data))
2193.             you_unwere(TRUE);
2194.         break;
2195.     case CARROT:
2196.         if (!u.uswallow
2197.             || !attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_BLND))
2198.             make_blinded((long) u.ucreamed, TRUE);
2199.         break;
2200.     case FORTUNE_COOKIE:
2201.         outrumor(bcsign(otmp), BY_COOKIE);
2202.         if (!Blind)
2203.             u.uconduct.literate++;
2204.         break;
2205.     case LUMP_OF_ROYAL_JELLY:
2206.         /* This stuff seems to be VERY healthy! */
2207.         gainstr(otmp, 1, TRUE);
2208.         if (Upolyd) {
2209.             u.mh += otmp->cursed ? -rnd(20) : rnd(20);
2210.             if (u.mh > u.mhmax) {
2211.                 if (!rn2(17))
2212.                     u.mhmax++;
2213.                 u.mh = u.mhmax;
2214.             } else if (u.mh <= 0) {
2215.                 rehumanize();
2216.             }
2217.         } else {
2218.             u.uhp += otmp->cursed ? -rnd(20) : rnd(20);
2219.             if (u.uhp > u.uhpmax) {
2220.                 if (!rn2(17))
2221.                     u.uhpmax++;
2222.                 u.uhp = u.uhpmax;
2223.             } else if (u.uhp <= 0) {
2224.                 killer.format = KILLED_BY_AN;
2225.                 Strcpy(killer.name, "rotten lump of royal jelly");
2226.                 done(POISONING);
2227.             }
2228.         }
2229.         if (!otmp->cursed)
2230.             heal_legs(0);
2231.         break;
2232.     case EGG:
2233.         if (flesh_petrifies(&mons[otmp->corpsenm])) {
2234.             if (!Stone_resistance
2235.                 && !(poly_when_stoned(youmonst.data)
2236.                      && polymon(PM_STONE_GOLEM))) {
2237.                 if (!Stoned) {
2238.                     Sprintf(killer.name, "%s egg",
2239.                             mons[otmp->corpsenm].mname);
2240.                     make_stoned(5L, (char *) 0, KILLED_BY_AN, killer.name);
2241.                 }
2242.             }
2243.             /* note: no "tastes like chicken" message for eggs */
2244.         }
2245.         break;
2246.     case EUCALYPTUS_LEAF:
2247.         if (Sick && !otmp->cursed)
2248.             make_sick(0L, (char *) 0, TRUE, SICK_ALL);
2249.         if (Vomiting && !otmp->cursed)
2250.             make_vomiting(0L, TRUE);
2251.         break;
2252.     case APPLE:
2253.         if (otmp->cursed && !Sleep_resistance) {
2254.             /* Snow White; 'poisoned' applies to [a subset of] weapons,
2255.                not food, so we substitute cursed; fortunately our hero
2256.                won't have to wait for a prince to be rescued/revived */
2257.             if (Race_if(PM_DWARF) && Hallucination)
2258.                 verbalize("Heigh-ho, ho-hum, I think I'll skip work today.");
2259.             else if (Deaf || !flags.acoustics)
2260.                 You("fall asleep.");
2261.             else
2262.                 You_hear("sinister laughter as you fall asleep...");
2263.             fall_asleep(-rn1(11, 20), TRUE);
2264.         }
2265.         break;
2266.     }
2267.     return;
2268. }
2269. 
2270. #if 0
2271. /* intended for eating a spellbook while polymorphed, but not used;
2272.    "leather" applied to appearance, not composition, and has been
2273.    changed to "leathery" to reflect that */
2274. STATIC_DCL boolean FDECL(leather_cover, (struct obj *));
2275. 
2276. STATIC_OVL boolean
2277. leather_cover(otmp)
2278. struct obj *otmp;
2279. {
2280.     const char *odesc = OBJ_DESCR(objects[otmp->otyp]);
2281. 
2282.     if (odesc && (otmp->oclass == SPBOOK_CLASS)) {
2283.         if (!strcmp(odesc, "leather"))
2284.             return TRUE;
2285.     }
2286.     return FALSE;
2287. }
2288. #endif
2289. 
2290. /*
2291.  * return 0 if the food was not dangerous.
2292.  * return 1 if the food was dangerous and you chose to stop.
2293.  * return 2 if the food was dangerous and you chose to eat it anyway.
2294.  */
2295. STATIC_OVL int
2296. edibility_prompts(otmp)
2297. struct obj *otmp;
2298. {
2299.     /* Blessed food detection grants hero a one-use
2300.      * ability to detect food that is unfit for consumption
2301.      * or dangerous and avoid it.
2302.      */
2303.     char buf[BUFSZ], foodsmell[BUFSZ],
2304.          it_or_they[QBUFSZ], eat_it_anyway[QBUFSZ];
2305.     boolean cadaver = (otmp->otyp == CORPSE || otmp->globby),
2306.             stoneorslime = FALSE;
2307.     int material = objects[otmp->otyp].oc_material, mnum = otmp->corpsenm;
2308.     long rotted = 0L;
2309. 
2310.     Strcpy(foodsmell, Tobjnam(otmp, "smell"));
2311.     Strcpy(it_or_they, (otmp->quan == 1L) ? "it" : "they");
2312.     Sprintf(eat_it_anyway, "Eat %s anyway?",
2313.             (otmp->quan == 1L) ? "it" : "one");
2314. 
2315.     if (cadaver || otmp->otyp == EGG || otmp->otyp == TIN) {
2316.         /* These checks must match those in eatcorpse() */
2317.         stoneorslime = (flesh_petrifies(&mons[mnum]) && !Stone_resistance
2318.                         && !poly_when_stoned(youmonst.data));
2319. 
2320.         if (mnum == PM_GREEN_SLIME || otmp->otyp == GLOB_OF_GREEN_SLIME)
2321.             stoneorslime = (!Unchanging && !slimeproof(youmonst.data));
2322. 
2323.         if (cadaver && !nonrotting_corpse(mnum)) {
2324.             long age = peek_at_iced_corpse_age(otmp);
2325. 
2326.             /* worst case rather than random
2327.                in this calculation to force prompt */
2328.             rotted = (monstermoves - age) / (10L + 0 /* was rn2(20) */);
2329.             if (otmp->cursed)
2330.                 rotted += 2L;
2331.             else if (otmp->blessed)
2332.                 rotted -= 2L;
2333.         }
2334.     }
2335. 
2336.     /*
2337.      * These problems with food should be checked in
2338.      * order from most detrimental to least detrimental.
2339.      */
2340.     if (cadaver && mnum != PM_ACID_BLOB && rotted > 5L && !Sick_resistance) {
2341.         /* Tainted meat */
2342.         Sprintf(buf, "%s like %s could be tainted!  %s", foodsmell, it_or_they,
2343.                 eat_it_anyway);
2344.         if (yn_function(buf, ynchars, 'n') == 'n')
2345.             return 1;
2346.         else
2347.             return 2;
2348.     }
2349.     if (stoneorslime) {
2350.         Sprintf(buf, "%s like %s could be something very dangerous!  %s",
2351.                 foodsmell, it_or_they, eat_it_anyway);
2352.         if (yn_function(buf, ynchars, 'n') == 'n')
2353.             return 1;
2354.         else
2355.             return 2;
2356.     }
2357.     if (otmp->orotten || (cadaver && rotted > 3L)) {
2358.         /* Rotten */
2359.         Sprintf(buf, "%s like %s could be rotten! %s",  foodsmell, it_or_they,
2360.                 eat_it_anyway);
2361.         if (yn_function(buf, ynchars, 'n') == 'n')
2362.             return 1;
2363.         else
2364.             return 2;
2365.     }
2366.     if (cadaver && poisonous(&mons[mnum]) && !Poison_resistance) {
2367.         /* poisonous */
2368.         Sprintf(buf, "%s like %s might be poisonous!  %s", foodsmell,
2369.                 it_or_they, eat_it_anyway);
2370.         if (yn_function(buf, ynchars, 'n') == 'n')
2371.             return 1;
2372.         else
2373.             return 2;
2374.     }
2375.     if (otmp->otyp == APPLE && otmp->cursed && !Sleep_resistance) {
2376.         /* causes sleep, for long enough to be dangerous */
2377.         Sprintf(buf, "%s like %s might have been poisoned.  %s", foodsmell,
2378.                 it_or_they, eat_it_anyway);
2379.         return (yn_function(buf, ynchars, 'n') == 'n') ? 1 : 2;
2380.     }
2381.     if (cadaver && !vegetarian(&mons[mnum]) && !u.uconduct.unvegetarian
2382.         && Role_if(PM_MONK)) {
2383.         Sprintf(buf, "%s unhealthy.  %s", foodsmell, eat_it_anyway);
2384.         if (yn_function(buf, ynchars, 'n') == 'n')
2385.             return 1;
2386.         else
2387.             return 2;
2388.     }
2389.     if (cadaver && acidic(&mons[mnum]) && !Acid_resistance) {
2390.         Sprintf(buf, "%s rather acidic.  %s", foodsmell, eat_it_anyway);
2391.         if (yn_function(buf, ynchars, 'n') == 'n')
2392.             return 1;
2393.         else
2394.             return 2;
2395.     }
2396.     if (Upolyd && u.umonnum == PM_RUST_MONSTER && is_metallic(otmp)
2397.         && otmp->oerodeproof) {
2398.         Sprintf(buf, "%s disgusting to you right now.  %s", foodsmell,
2399.                 eat_it_anyway);
2400.         if (yn_function(buf, ynchars, 'n') == 'n')
2401.             return 1;
2402.         else
2403.             return 2;
2404.     }
2405. 
2406.     /*
2407.      * Breaks conduct, but otherwise safe.
2408.      */
2409.     if (!u.uconduct.unvegan
2410.         && ((material == LEATHER || material == BONE
2411.              || material == DRAGON_HIDE || material == WAX)
2412.             || (cadaver && !vegan(&mons[mnum])))) {
2413.         Sprintf(buf, "%s foul and unfamiliar to you.  %s", foodsmell,
2414.                 eat_it_anyway);
2415.         if (yn_function(buf, ynchars, 'n') == 'n')
2416.             return 1;
2417.         else
2418.             return 2;
2419.     }
2420.     if (!u.uconduct.unvegetarian
2421.         && ((material == LEATHER || material == BONE
2422.              || material == DRAGON_HIDE)
2423.             || (cadaver && !vegetarian(&mons[mnum])))) {
2424.         Sprintf(buf, "%s unfamiliar to you.  %s", foodsmell, eat_it_anyway);
2425.         if (yn_function(buf, ynchars, 'n') == 'n')
2426.             return 1;
2427.         else
2428.             return 2;
2429.     }
2430. 
2431.     if (cadaver && mnum != PM_ACID_BLOB && rotted > 5L && Sick_resistance) {
2432.         /* Tainted meat with Sick_resistance */
2433.         Sprintf(buf, "%s like %s could be tainted!  %s",
2434.                 foodsmell, it_or_they, eat_it_anyway);
2435.         if (yn_function(buf, ynchars, 'n') == 'n')
2436.             return 1;
2437.         else
2438.             return 2;
2439.     }
2440.     return 0;
2441. }
2442. 
2443. /* 'e' command */
2444. int
2445. doeat()
2446. {
2447.     struct obj *otmp;
2448.     int basenutrit; /* nutrition of full item */
2449.     boolean dont_start = FALSE, nodelicious = FALSE,
2450.             already_partly_eaten;
2451. 
2452.     if (Strangled) {
2453.         pline("If you can't breathe air, how can you consume solids?");
2454.         return 0;
2455.     }
2456.     if (!(otmp = floorfood("eat", 0)))
2457.         return 0;
2458.     if (check_capacity((char *) 0))
2459.         return 0;
2460. 
2461.     if (u.uedibility) {
2462.         int res = edibility_prompts(otmp);
2463. 
2464.         if (res) {
2465.             Your(
2466.                "%s stops tingling and your sense of smell returns to normal.",
2467.                  body_part(NOSE));
2468.             u.uedibility = 0;
2469.             if (res == 1)
2470.                 return 0;
2471.         }
2472.     }
2473. 
2474.     /* We have to make non-foods take 1 move to eat, unless we want to
2475.      * do ridiculous amounts of coding to deal with partly eaten plate
2476.      * mails, players who polymorph back to human in the middle of their
2477.      * metallic meal, etc....
2478.      */
2479.     if (!is_edible(otmp)) {
2480.         You("cannot eat that!");
2481.         return 0;
2482.     } else if ((otmp->owornmask & (W_ARMOR | W_TOOL | W_AMUL | W_SADDLE))
2483.                != 0) {
2484.         /* let them eat rings */
2485.         You_cant("eat %s you're wearing.", something);
2486.         return 0;
2487.     } else if (!(carried(otmp) ? retouch_object(&otmp, FALSE)
2488.                                : touch_artifact(otmp, &youmonst))) {
2489.         return 1; /* got blasted so use a turn */
2490.     }
2491.     if (is_metallic(otmp) && u.umonnum == PM_RUST_MONSTER
2492.         && otmp->oerodeproof) {
2493.         otmp->rknown = TRUE;
2494.         if (otmp->quan > 1L) {
2495.             if (!carried(otmp))
2496.                 (void) splitobj(otmp, otmp->quan - 1L);
2497.             else
2498.                 otmp = splitobj(otmp, 1L);
2499.         }
2500.         pline("Ulch - that %s was rustproofed!", xname(otmp));
2501.         /* The regurgitated object's rustproofing is gone now */
2502.         otmp->oerodeproof = 0;
2503.         make_stunned((HStun & TIMEOUT) + (long) rn2(10), TRUE);
2504.         /*
2505.          * We don't expect rust monsters to be wielding welded weapons
2506.          * or wearing cursed rings which were rustproofed, but guard
2507.          * against the possibility just in case.
2508.          */
2509.         if (welded(otmp) || (otmp->cursed && (otmp->owornmask & W_RING))) {
2510.             set_bknown(otmp, 1); /* for ring; welded() does this for weapon */
2511.             You("spit out %s.", the(xname(otmp)));
2512.         } else {
2513.             You("spit %s out onto the %s.", the(xname(otmp)),
2514.                 surface(u.ux, u.uy));
2515.             if (carried(otmp)) {
2516.                 /* no need to check for leash in use; it's not metallic */
2517.                 if (otmp->owornmask)
2518.                     remove_worn_item(otmp, FALSE);
2519.                 freeinv(otmp);
2520.                 dropy(otmp);
2521.             }
2522.             stackobj(otmp);
2523.         }
2524.         return 1;
2525.     }
2526.     /* KMH -- Slow digestion is... indigestible */
2527.     if (otmp->otyp == RIN_SLOW_DIGESTION) {
2528.         pline("This ring is indigestible!");
2529.         (void) rottenfood(otmp);
2530.         if (otmp->dknown && !objects[otmp->otyp].oc_name_known
2531.             && !objects[otmp->otyp].oc_uname)
2532.             docall(otmp);
2533.         return 1;
2534.     }
2535.     if (otmp->oclass != FOOD_CLASS) {
2536.         int material;
2537. 
2538.         context.victual.reqtime = 1;
2539.         context.victual.piece = otmp;
2540.         context.victual.o_id = otmp->o_id;
2541.         /* Don't split it, we don't need to if it's 1 move */
2542.         context.victual.usedtime = 0;
2543.         context.victual.canchoke = (u.uhs == SATIATED);
2544.         /* Note: gold weighs 1 pt. for each 1000 pieces (see
2545.            pickup.c) so gold and non-gold is consistent. */
2546.         if (otmp->oclass == COIN_CLASS)
2547.             basenutrit = ((otmp->quan > 200000L)
2548.                              ? 2000
2549.                              : (int) (otmp->quan / 100L));
2550.         else if (otmp->oclass == BALL_CLASS || otmp->oclass == CHAIN_CLASS)
2551.             basenutrit = weight(otmp);
2552.         /* oc_nutrition is usually weight anyway */
2553.         else
2554.             basenutrit = objects[otmp->otyp].oc_nutrition;
2555. #ifdef MAIL
2556.         if (otmp->otyp == SCR_MAIL) {
2557.             basenutrit = 0;
2558.             nodelicious = TRUE;
2559.         }
2560. #endif
2561.         context.victual.nmod = basenutrit;
2562.         context.victual.eating = TRUE; /* needed for lesshungry() */
2563. 
2564.         material = objects[otmp->otyp].oc_material;
2565.         if (material == LEATHER || material == BONE
2566.             || material == DRAGON_HIDE) {
2567.             u.uconduct.unvegan++;
2568.             violated_vegetarian();
2569.         } else if (material == WAX)
2570.             u.uconduct.unvegan++;
2571.         u.uconduct.food++;
2572. 
2573.         if (otmp->cursed) {
2574.             (void) rottenfood(otmp);
2575.             nodelicious = TRUE;
2576.         } else if (objects[otmp->otyp].oc_material == PAPER)
2577.             nodelicious = TRUE;
2578. 
2579.         if (otmp->oclass == WEAPON_CLASS && otmp->opoisoned) {
2580.             pline("Ecch - that must have been poisonous!");
2581.             if (!Poison_resistance) {
2582.                 losestr(rnd(4));
2583.                 losehp(rnd(15), xname(otmp), KILLED_BY_AN);
2584.             } else
2585.                 You("seem unaffected by the poison.");
2586.         } else if (!nodelicious) {
2587.             pline("%s%s is delicious!",
2588.                   (obj_is_pname(otmp)
2589.                    && otmp->oartifact < ART_ORB_OF_DETECTION)
2590.                       ? ""
2591.                       : "This ",
2592.                   (otmp->oclass == COIN_CLASS)
2593.                       ? foodword(otmp)
2594.                       : singular(otmp, xname));
2595.         }
2596.         eatspecial();
2597.         return 1;
2598.     }
2599. 
2600.     if (otmp == context.victual.piece) {
2601.         /* If they weren't able to choke, they don't suddenly become able to
2602.          * choke just because they were interrupted.  On the other hand, if
2603.          * they were able to choke before, if they lost food it's possible
2604.          * they shouldn't be able to choke now.
2605.          */
2606.         if (u.uhs != SATIATED)
2607.             context.victual.canchoke = FALSE;
2608.         context.victual.o_id = 0;
2609.         context.victual.piece = touchfood(otmp);
2610.         if (context.victual.piece)
2611.             context.victual.o_id = context.victual.piece->o_id;
2612.         You("resume %syour meal.",
2613.             (context.victual.usedtime + 1 >= context.victual.reqtime)
2614.             ? "the last bite of " : "");
2615.         start_eating(context.victual.piece, FALSE);
2616.         return 1;
2617.     }
2618. 
2619.     /* nothing in progress - so try to find something. */
2620.     /* tins are a special case */
2621.     /* tins must also check conduct separately in case they're discarded */
2622.     if (otmp->otyp == TIN) {
2623.         start_tin(otmp);
2624.         return 1;
2625.     }
2626. 
2627.     /* KMH, conduct */
2628.     u.uconduct.food++;
2629. 
2630.     already_partly_eaten = otmp->oeaten ? TRUE : FALSE;
2631.     context.victual.o_id = 0;
2632.     context.victual.piece = otmp = touchfood(otmp);
2633.     if (context.victual.piece)
2634.         context.victual.o_id = context.victual.piece->o_id;
2635.     context.victual.usedtime = 0;
2636. 
2637.     /* Now we need to calculate delay and nutritional info.
2638.      * The base nutrition calculated here and in eatcorpse() accounts
2639.      * for normal vs. rotten food.  The reqtime and nutrit values are
2640.      * then adjusted in accordance with the amount of food left.
2641.      */
2642.     if (otmp->otyp == CORPSE || otmp->globby) {
2643.         int tmp = eatcorpse(otmp);
2644. 
2645.         if (tmp == 2) {
2646.             /* used up */
2647.             context.victual.piece = (struct obj *) 0;
2648.             context.victual.o_id = 0;
2649.             return 1;
2650.         } else if (tmp)
2651.             dont_start = TRUE;
2652.         /* if not used up, eatcorpse sets up reqtime and may modify oeaten */
2653.     } else {
2654.         /* No checks for WAX, LEATHER, BONE, DRAGON_HIDE.  These are
2655.          * all handled in the != FOOD_CLASS case, above.
2656.          */
2657.         switch (objects[otmp->otyp].oc_material) {
2658.         case FLESH:
2659.             u.uconduct.unvegan++;
2660.             if (otmp->otyp != EGG) {
2661.                 violated_vegetarian();
2662.             }
2663.             break;
2664. 
2665.         default:
2666.             if (otmp->otyp == PANCAKE || otmp->otyp == FORTUNE_COOKIE /*eggs*/
2667.                 || otmp->otyp == CREAM_PIE || otmp->otyp == CANDY_BAR /*milk*/
2668.                 || otmp->otyp == LUMP_OF_ROYAL_JELLY)
2669.                 u.uconduct.unvegan++;
2670.             break;
2671.         }
2672. 
2673.         context.victual.reqtime = objects[otmp->otyp].oc_delay;
2674.         if (otmp->otyp != FORTUNE_COOKIE
2675.             && (otmp->cursed || (!nonrotting_food(otmp->otyp)
2676.                                  && (monstermoves - otmp->age)
2677.                                         > (otmp->blessed ? 50L : 30L)
2678.                                  && (otmp->orotten || !rn2(7))))) {
2679.             if (rottenfood(otmp)) {
2680.                 otmp->orotten = TRUE;
2681.                 dont_start = TRUE;
2682.             }
2683.             consume_oeaten(otmp, 1); /* oeaten >>= 1 */
2684.         } else if (!already_partly_eaten) {
2685.             fprefx(otmp);
2686.         } else {
2687.             You("%s %s.",
2688.                 (context.victual.reqtime == 1) ? "eat" : "begin eating",
2689.                 doname(otmp));
2690.         }
2691.     }
2692. 
2693.     /* re-calc the nutrition */
2694.     basenutrit = (int) obj_nutrition(otmp);
2695. 
2696.     debugpline3(
2697.      "before rounddiv: victual.reqtime == %d, oeaten == %d, basenutrit == %d",
2698.                 context.victual.reqtime, otmp->oeaten, basenutrit);
2699. 
2700.     context.victual.reqtime = (basenutrit == 0) ? 0
2701.         : rounddiv(context.victual.reqtime * (long) otmp->oeaten, basenutrit);
2702. 
2703.     debugpline1("after rounddiv: victual.reqtime == %d",
2704.                 context.victual.reqtime);
2705.     /*
2706.      * calculate the modulo value (nutrit. units per round eating)
2707.      * note: this isn't exact - you actually lose a little nutrition due
2708.      *       to this method.
2709.      * TODO: add in a "remainder" value to be given at the end of the meal.
2710.      */
2711.     if (context.victual.reqtime == 0 || otmp->oeaten == 0)
2712.         /* possible if most has been eaten before */
2713.         context.victual.nmod = 0;
2714.     else if ((int) otmp->oeaten >= context.victual.reqtime)
2715.         context.victual.nmod = -((int) otmp->oeaten
2716.                                  / context.victual.reqtime);
2717.     else
2718.         context.victual.nmod = context.victual.reqtime % otmp->oeaten;
2719.     context.victual.canchoke = (u.uhs == SATIATED);
2720. 
2721.     if (!dont_start)
2722.         start_eating(otmp, already_partly_eaten);
2723.     return 1;
2724. }
2725. 
2726. int
2727. use_tin_opener(obj)
2728. struct obj *obj;
2729. {
2730.     struct obj *otmp;
2731.     int res = 0;
2732. 
2733.     if (!carrying(TIN)) {
2734.         You("have no tin to open.");
2735.         return 0;
2736.     }
2737. 
2738.     if (obj != uwep) {
2739.         if (obj->cursed && obj->bknown) {
2740.             char qbuf[QBUFSZ];
2741. 
2742.             if (ynq(safe_qbuf(qbuf, "Really wield ", "?",
2743.                               obj, doname, thesimpleoname, "that")) != 'y')
2744.                 return 0;
2745.         }
2746.         if (!wield_tool(obj, "use"))
2747.             return 0;
2748.         res = 1;
2749.     }
2750. 
2751.     otmp = getobj(comestibles, "open");
2752.     if (!otmp)
2753.         return res;
2754. 
2755.     start_tin(otmp);
2756.     return 1;
2757. }
2758. 
2759. /* Take a single bite from a piece of food, checking for choking and
2760.  * modifying usedtime.  Returns 1 if they choked and survived, 0 otherwise.
2761.  */
2762. STATIC_OVL int
2763. bite()
2764. {
2765.     if (context.victual.canchoke && u.uhunger >= 2000) {
2766.         choke(context.victual.piece);
2767.         return 1;
2768.     }
2769.     if (context.victual.doreset) {
2770.         do_reset_eat();
2771.         return 0;
2772.     }
2773.     force_save_hs = TRUE;
2774.     if (context.victual.nmod < 0) {
2775.         lesshungry(-context.victual.nmod);
2776.         consume_oeaten(context.victual.piece,
2777.                        context.victual.nmod); /* -= -nmod */
2778.     } else if (context.victual.nmod > 0
2779.                && (context.victual.usedtime % context.victual.nmod)) {
2780.         lesshungry(1);
2781.         consume_oeaten(context.victual.piece, -1); /* -= 1 */
2782.     }
2783.     force_save_hs = FALSE;
2784.     recalc_wt();
2785.     return 0;
2786. }
2787. 
2788. /* as time goes by - called by moveloop(every move) & domove(melee attack) */
2789. void
2790. gethungry()
2791. {
2792.     if (u.uinvulnerable)
2793.         return; /* you don't feel hungrier */
2794. 
2795.     /* being polymorphed into a creature which doesn't eat prevents
2796.        this first uhunger decrement, but to stay in such form the hero
2797.        will need to wear an Amulet of Unchanging so still burn a small
2798.        amount of nutrition in the 'moves % 20' ring/amulet check below */
2799.     if ((!Unaware || !rn2(10)) /* slow metabolic rate while asleep */
2800.         && (carnivorous(youmonst.data)
2801.             || herbivorous(youmonst.data)
2802.             || metallivorous(youmonst.data))
2803.         && !Slow_digestion)
2804.         u.uhunger--; /* ordinary food consumption */
2805. 
2806.     if (moves % 2) { /* odd turns */
2807.         /* Regeneration uses up food, unless due to an artifact */
2808.         if ((HRegeneration & ~FROMFORM)
2809.             || (ERegeneration & ~(W_ARTI | W_WEP)))
2810.             u.uhunger--;
2811.         if (near_capacity() > SLT_ENCUMBER)
2812.             u.uhunger--;
2813.     } else { /* even turns */
2814.         if (Hunger)
2815.             u.uhunger--;
2816.         /* Conflict uses up food too */
2817.         if (HConflict || (EConflict & (~W_ARTI)))
2818.             u.uhunger--;
2819.         /* +0 charged rings don't do anything, so don't affect hunger.
2820.            Slow digestion cancels move hunger but still causes ring hunger. */
2821.         switch ((int) (moves % 20)) { /* note: use even cases only */
2822.         case 4:
2823.             if (uleft && (uleft->spe || !objects[uleft->otyp].oc_charged))
2824.                 u.uhunger--;
2825.             break;
2826.         case 8:
2827.             if (uamul)
2828.                 u.uhunger--;
2829.             break;
2830.         case 12:
2831.             if (uright && (uright->spe || !objects[uright->otyp].oc_charged))
2832.                 u.uhunger--;
2833.             break;
2834.         case 16:
2835.             if (u.uhave.amulet)
2836.                 u.uhunger--;
2837.             break;
2838.         default:
2839.             break;
2840.         }
2841.     }
2842.     newuhs(TRUE);
2843. }
2844. 
2845. /* called after vomiting and after performing feats of magic */
2846. void
2847. morehungry(num)
2848. int num;
2849. {
2850.     u.uhunger -= num;
2851.     newuhs(TRUE);
2852. }
2853. 
2854. /* called after eating (and after drinking fruit juice) */
2855. void
2856. lesshungry(num)
2857. int num;
2858. {
2859.     /* See comments in newuhs() for discussion on force_save_hs */
2860.     boolean iseating = (occupation == eatfood) || force_save_hs;
2861. 
2862.     debugpline1("lesshungry(%d)", num);
2863.     u.uhunger += num;
2864.     if (u.uhunger >= 2000) {
2865.         if (!iseating || context.victual.canchoke) {
2866.             if (iseating) {
2867.                 choke(context.victual.piece);
2868.                 reset_eat();
2869.             } else
2870.                 choke(occupation == opentin ? context.tin.tin
2871.                                             : (struct obj *) 0);
2872.             /* no reset_eat() */
2873.         }
2874.     } else {
2875.         /* Have lesshungry() report when you're nearly full so all eating
2876.          * warns when you're about to choke.
2877.          */
2878.         if (u.uhunger >= 1500
2879.             && (!context.victual.eating
2880.                 || (context.victual.eating && !context.victual.fullwarn))) {
2881.             pline("You're having a hard time getting all of it down.");
2882.             nomovemsg = "You're finally finished.";
2883.             if (!context.victual.eating) {
2884.                 multi = -2;
2885.             } else {
2886.                 context.victual.fullwarn = TRUE;
2887.                 if (context.victual.canchoke && context.victual.reqtime > 1) {
2888.                     /* a one-gulp food will not survive a stop */
2889.                     if (!paranoid_query(ParanoidEating, "Continue eating?")) {
2890.                         reset_eat();
2891.                         nomovemsg = (char *) 0;
2892.                     }
2893.                 }
2894.             }
2895.         }
2896.     }
2897.     newuhs(FALSE);
2898. }
2899. 
2900. STATIC_PTR
2901. int
2902. unfaint(VOID_ARGS)
2903. {
2904.     (void) Hear_again();
2905.     if (u.uhs > FAINTING)
2906.         u.uhs = FAINTING;
2907.     stop_occupation();
2908.     context.botl = 1;
2909.     return 0;
2910. }
2911. 
2912. boolean
2913. is_fainted()
2914. {
2915.     return (boolean) (u.uhs == FAINTED);
2916. }
2917. 
2918. /* call when a faint must be prematurely terminated */
2919. void
2920. reset_faint()
2921. {
2922.     if (afternmv == unfaint)
2923.         unmul("You revive.");
2924. }
2925. 
2926. /* compute and comment on your (new?) hunger status */
2927. void
2928. newuhs(incr)
2929. boolean incr;
2930. {
2931.     unsigned newhs;
2932.     static unsigned save_hs;
2933.     static boolean saved_hs = FALSE;
2934.     int h = u.uhunger;
2935. 
2936.     newhs = (h > 1000)
2937.                 ? SATIATED
2938.                 : (h > 150) ? NOT_HUNGRY
2939.                             : (h > 50) ? HUNGRY : (h > 0) ? WEAK : FAINTING;
2940. 
2941.     /* While you're eating, you may pass from WEAK to HUNGRY to NOT_HUNGRY.
2942.      * This should not produce the message "you only feel hungry now";
2943.      * that message should only appear if HUNGRY is an endpoint.  Therefore
2944.      * we check to see if we're in the middle of eating.  If so, we save
2945.      * the first hunger status, and at the end of eating we decide what
2946.      * message to print based on the _entire_ meal, not on each little bit.
2947.      */
2948.     /* It is normally possible to check if you are in the middle of a meal
2949.      * by checking occupation == eatfood, but there is one special case:
2950.      * start_eating() can call bite() for your first bite before it
2951.      * sets the occupation.
2952.      * Anyone who wants to get that case to work _without_ an ugly static
2953.      * force_save_hs variable, feel free.
2954.      */
2955.     /* Note: If you become a certain hunger status in the middle of the
2956.      * meal, and still have that same status at the end of the meal,
2957.      * this will incorrectly print the associated message at the end of
2958.      * the meal instead of the middle.  Such a case is currently
2959.      * impossible, but could become possible if a message for SATIATED
2960.      * were added or if HUNGRY and WEAK were separated by a big enough
2961.      * gap to fit two bites.
2962.      */
2963.     if (occupation == eatfood || force_save_hs) {
2964.         if (!saved_hs) {
2965.             save_hs = u.uhs;
2966.             saved_hs = TRUE;
2967.         }
2968.         u.uhs = newhs;
2969.         return;
2970.     } else {
2971.         if (saved_hs) {
2972.             u.uhs = save_hs;
2973.             saved_hs = FALSE;
2974.         }
2975.     }
2976. 
2977.     if (newhs == FAINTING) {
2978.         /* u,uhunger is likely to be negative at this point */
2979.         int uhunger_div_by_10 = sgn(u.uhunger) * ((abs(u.uhunger) + 5) / 10);
2980. 
2981.         if (is_fainted())
2982.             newhs = FAINTED;
2983.         if (u.uhs <= WEAK || rn2(20 - uhunger_div_by_10) >= 19) {
2984.             if (!is_fainted() && multi >= 0 /* %% */) {
2985.                 int duration = 10 - uhunger_div_by_10;
2986. 
2987.                 /* stop what you're doing, then faint */
2988.                 stop_occupation();
2989.                 You("faint from lack of food.");
2990.                 incr_itimeout(&HDeaf, duration);
2991.                 context.botl = TRUE;
2992.                 nomul(-duration);
2993.                 multi_reason = "fainted from lack of food";
2994.                 nomovemsg = "You regain consciousness.";
2995.                 afternmv = unfaint;
2996.                 newhs = FAINTED;
2997.                 if (!Levitation)
2998.                     selftouch("Falling, you");
2999.             }
3000. 
3001.         /* this used to be -(200 + 20 * Con) but that was when being asleep
3002.            suppressed per-turn uhunger decrement but being fainted didn't;
3003.            now uhunger becomes more negative at a slower rate */
3004.         } else if (u.uhunger < -(100 + 10 * (int) ACURR(A_CON))) {
3005.             u.uhs = STARVED;
3006.             context.botl = 1;
3007.             bot();
3008.             You("die from starvation.");
3009.             killer.format = KILLED_BY;
3010.             Strcpy(killer.name, "starvation");
3011.             done(STARVING);
3012.             /* if we return, we lifesaved, and that calls newuhs */
3013.             return;
3014.         }
3015.     }
3016. 
3017.     if (newhs != u.uhs) {
3018.         if (newhs >= WEAK && u.uhs < WEAK) {
3019.             /* this used to be losestr(1) which had the potential to
3020.                be fatal (still handled below) by reducing HP if it
3021.                tried to take base strength below minimum of 3 */
3022.             ATEMP(A_STR) = -1; /* temporary loss overrides Fixed_abil */
3023.             /* defer context.botl status update until after hunger message */
3024.         } else if (newhs < WEAK && u.uhs >= WEAK) {
3025.             /* this used to be losestr(-1) which could be abused by
3026.                becoming weak while wearing ring of sustain ability,
3027.                removing ring, eating to 'restore' strength which boosted
3028.                strength by a point each time the cycle was performed;
3029.                substituting "while polymorphed" for sustain ability and
3030.                "rehumanize" for ring removal might have done that too */
3031.             ATEMP(A_STR) = 0; /* repair of loss also overrides Fixed_abil */
3032.             /* defer context.botl status update until after hunger message */
3033.         }
3034. 
3035.         switch (newhs) {
3036.         case HUNGRY:
3037.             if (Hallucination) {
3038.                 You((!incr) ? "now have a lesser case of the munchies."
3039.                             : "are getting the munchies.");
3040.             } else
3041.                 You((!incr) ? "only feel hungry now."
3042.                             : (u.uhunger < 145)
3043.                                   ? "feel hungry."
3044.                                   : "are beginning to feel hungry.");
3045.             if (incr && occupation
3046.                 && (occupation != eatfood && occupation != opentin))
3047.                 stop_occupation();
3048.             context.travel = context.travel1 = context.mv = context.run = 0;
3049.             break;
3050.         case WEAK:
3051.             if (Hallucination)
3052.                 pline((!incr) ? "You still have the munchies."
3053.               : "The munchies are interfering with your motor capabilities.");
3054.             else if (incr && (Role_if(PM_WIZARD) || Race_if(PM_ELF)
3055.                               || Role_if(PM_VALKYRIE)))
3056.                 pline("%s needs food, badly!",
3057.                       (Role_if(PM_WIZARD) || Role_if(PM_VALKYRIE))
3058.                           ? urole.name.m
3059.                           : "Elf");
3060.             else
3061.                 You((!incr)
3062.                         ? "feel weak now."
3063.                         : (u.uhunger < 45) ? "feel weak."
3064.                                            : "are beginning to feel weak.");
3065.             if (incr && occupation
3066.                 && (occupation != eatfood && occupation != opentin))
3067.                 stop_occupation();
3068.             context.travel = context.travel1 = context.mv = context.run = 0;
3069.             break;
3070.         }
3071.         u.uhs = newhs;
3072.         context.botl = 1;
3073.         bot();
3074.         if ((Upolyd ? u.mh : u.uhp) < 1) {
3075.             You("die from hunger and exhaustion.");
3076.             killer.format = KILLED_BY;
3077.             Strcpy(killer.name, "exhaustion");
3078.             done(STARVING);
3079.             return;
3080.         }
3081.     }
3082. }
3083. 
3084. /* Returns an object representing food.
3085.  * Object may be either on floor or in inventory.
3086.  */
3087. struct obj *
3088. floorfood(verb, corpsecheck)
3089. const char *verb;
3090. int corpsecheck; /* 0, no check, 1, corpses, 2, tinnable corpses */
3091. {
3092.     register struct obj *otmp;
3093.     char qbuf[QBUFSZ];
3094.     char c;
3095.     boolean feeding = !strcmp(verb, "eat"),    /* corpsecheck==0 */
3096.         offering = !strcmp(verb, "sacrifice"); /* corpsecheck==1 */
3097. 
3098.     /* if we can't touch floor objects then use invent food only */
3099.     if (iflags.menu_requested /* command was preceded by 'm' prefix */
3100.         || !can_reach_floor(TRUE) || (feeding && u.usteed)
3101.         || (is_pool_or_lava(u.ux, u.uy)
3102.             && (Wwalking || is_clinger(youmonst.data)
3103.                 || (Flying && !Breathless))))
3104.         goto skipfloor;
3105. 
3106.     if (feeding && metallivorous(youmonst.data)) {
3107.         struct obj *gold;
3108.         struct trap *ttmp = t_at(u.ux, u.uy);
3109. 
3110.         if (ttmp && ttmp->tseen && ttmp->ttyp == BEAR_TRAP) {
3111.             boolean u_in_beartrap = (u.utrap && u.utraptype == TT_BEARTRAP);
3112. 
3113.             /* If not already stuck in the trap, perhaps there should
3114.                be a chance to becoming trapped?  Probably not, because
3115.                then the trap would just get eaten on the _next_ turn... */
3116.             Sprintf(qbuf, "There is a bear trap here (%s); eat it?",
3117.                     u_in_beartrap ? "holding you" : "armed");
3118.             if ((c = yn_function(qbuf, ynqchars, 'n')) == 'y') {
3119.                 deltrap(ttmp);
3120.                 if (u_in_beartrap)
3121.                     reset_utrap(TRUE);
3122.                 return mksobj(BEARTRAP, TRUE, FALSE);
3123.             } else if (c == 'q') {
3124.                 return (struct obj *) 0;
3125.             }
3126.         }
3127. 
3128.         if (youmonst.data != &mons[PM_RUST_MONSTER]
3129.             && (gold = g_at(u.ux, u.uy)) != 0) {
3130.             if (gold->quan == 1L)
3131.                 Sprintf(qbuf, "There is 1 gold piece here; eat it?");
3132.             else
3133.                 Sprintf(qbuf, "There are %ld gold pieces here; eat them?",
3134.                         gold->quan);
3135.             if ((c = yn_function(qbuf, ynqchars, 'n')) == 'y') {
3136.                 return gold;
3137.             } else if (c == 'q') {
3138.                 return (struct obj *) 0;
3139.             }
3140.         }
3141.     }
3142. 
3143.     /* Is there some food (probably a heavy corpse) here on the ground? */
3144.     for (otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere) {
3145.         if (corpsecheck
3146.                 ? (otmp->otyp == CORPSE
3147.                    && (corpsecheck == 1 || tinnable(otmp)))
3148.                 : feeding ? (otmp->oclass != COIN_CLASS && is_edible(otmp))
3149.                           : otmp->oclass == FOOD_CLASS) {
3150.             char qsfx[QBUFSZ];
3151.             boolean one = (otmp->quan == 1L);
3152. 
3153.             /* if blind and without gloves, attempting to eat (or tin or
3154.                offer) a cockatrice corpse is fatal before asking whether
3155.                or not to use it; otherwise, 'm<dir>' followed by 'e' could
3156.                be used to locate cockatrice corpses without touching them */
3157.             if (otmp->otyp == CORPSE && will_feel_cockatrice(otmp, FALSE)) {
3158.                 feel_cockatrice(otmp, FALSE);
3159.                 /* if life-saved (or poly'd into stone golem), terminate
3160.                    attempt to eat off floor */
3161.                 return (struct obj *) 0;
3162.             }
3163.             /* "There is <an object> here; <verb> it?" or
3164.                "There are <N objects> here; <verb> one?" */
3165.             Sprintf(qbuf, "There %s ", otense(otmp, "are"));
3166.             Sprintf(qsfx, " here; %s %s?", verb, one ? "it" : "one");
3167.             (void) safe_qbuf(qbuf, qbuf, qsfx, otmp, doname, ansimpleoname,
3168.                              one ? something : (const char *) "things");
3169.             if ((c = yn_function(qbuf, ynqchars, 'n')) == 'y')
3170.                 return  otmp;
3171.             else if (c == 'q')
3172.                 return (struct obj *) 0;
3173.         }
3174.     }
3175. 
3176.  skipfloor:
3177.     /* We cannot use ALL_CLASSES since that causes getobj() to skip its
3178.      * "ugly checks" and we need to check for inedible items.
3179.      */
3180.     otmp = getobj(feeding ? allobj : offering ? offerfodder : comestibles,
3181.                   verb);
3182.     if (corpsecheck && otmp && !(offering && otmp->oclass == AMULET_CLASS))
3183.         if (otmp->otyp != CORPSE || (corpsecheck == 2 && !tinnable(otmp))) {
3184.             You_cant("%s that!", verb);
3185.             return (struct obj *) 0;
3186.         }
3187.     return otmp;
3188. }
3189. 
3190. /* Side effects of vomiting */
3191. /* added nomul (MRS) - it makes sense, you're too busy being sick! */
3192. void
3193. vomit() /* A good idea from David Neves */
3194. {
3195.     if (cantvomit(youmonst.data)) {
3196.         /* doesn't cure food poisoning; message assumes that we aren't
3197.            dealing with some esoteric body_part() */
3198.         Your("jaw gapes convulsively.");
3199.     } else {
3200.         if (Sick && (u.usick_type & SICK_VOMITABLE) != 0)
3201.             make_sick(0L, (char *) 0, TRUE, SICK_VOMITABLE);
3202.         /* if not enough in stomach to actually vomit then dry heave;
3203.            vomiting_dialog() gives a vomit message when its countdown
3204.            reaches 0, but only if u.uhs < FAINTING (and !cantvomit()) */
3205.         if (u.uhs >= FAINTING)
3206.             Your("%s heaves convulsively!", body_part(STOMACH));
3207.     }
3208. 
3209.     /* nomul()/You_can_move_again used to be unconditional, which was
3210.        viable while eating but not for Vomiting countdown where hero might
3211.        be immobilized for some other reason at the time vomit() is called */
3212.     if (multi >= -2) {
3213.         nomul(-2);
3214.         multi_reason = "vomiting";
3215.         nomovemsg = You_can_move_again;
3216.     }
3217. }
3218. 
3219. int
3220. eaten_stat(base, obj)
3221. int base;
3222. struct obj *obj;
3223. {
3224.     long uneaten_amt, full_amount;
3225. 
3226.     /* get full_amount first; obj_nutrition() might modify obj->oeaten */
3227.     full_amount = (long) obj_nutrition(obj);
3228.     uneaten_amt = (long) obj->oeaten;
3229.     if (uneaten_amt > full_amount) {
3230.         impossible(
3231.           "partly eaten food (%ld) more nutritious than untouched food (%ld)",
3232.                    uneaten_amt, full_amount);
3233.         uneaten_amt = full_amount;
3234.     }
3235. 
3236.     base = (int) (full_amount ? (long) base * uneaten_amt / full_amount : 0L);
3237.     return (base < 1) ? 1 : base;
3238. }
3239. 
3240. /* reduce obj's oeaten field, making sure it never hits or passes 0 */
3241. void
3242. consume_oeaten(obj, amt)
3243. struct obj *obj;
3244. int amt;
3245. {
3246.     /*
3247.      * This is a hack to try to squelch several long standing mystery
3248.      * food bugs.  A better solution would be to rewrite the entire
3249.      * victual handling mechanism from scratch using a less complex
3250.      * model.  Alternatively, this routine could call done_eating()
3251.      * or food_disappears() but its callers would need revisions to
3252.      * cope with context.victual.piece unexpectedly going away.
3253.      *
3254.      * Multi-turn eating operates by setting the food's oeaten field
3255.      * to its full nutritional value and then running a counter which
3256.      * independently keeps track of whether there is any food left.
3257.      * The oeaten field can reach exactly zero on the last turn, and
3258.      * the object isn't removed from inventory until the next turn
3259.      * when the "you finish eating" message gets delivered, so the
3260.      * food would be restored to the status of untouched during that
3261.      * interval.  This resulted in unexpected encumbrance messages
3262.      * at the end of a meal (if near enough to a threshold) and would
3263.      * yield full food if there was an interruption on the critical
3264.      * turn.  Also, there have been reports over the years of food
3265.      * becoming massively heavy or producing unlimited satiation;
3266.      * this would occur if reducing oeaten via subtraction attempted
3267.      * to drop it below 0 since its unsigned type would produce a
3268.      * huge positive value instead.  So far, no one has figured out
3269.      * _why_ that inappropriate subtraction might sometimes happen.
3270.      */
3271. 
3272.     if (amt > 0) {
3273.         /* bit shift to divide the remaining amount of food */
3274.         obj->oeaten >>= amt;
3275.     } else {
3276.         /* simple decrement; value is negative so we actually add it */
3277.         if ((int) obj->oeaten > -amt)
3278.             obj->oeaten += amt;
3279.         else
3280.             obj->oeaten = 0;
3281.     }
3282. 
3283.     if (obj->oeaten == 0) {
3284.         if (obj == context.victual.piece) /* always true unless wishing... */
3285.             context.victual.reqtime =
3286.                 context.victual.usedtime; /* no bites left */
3287.         obj->oeaten = 1; /* smallest possible positive value */
3288.     }
3289. }
3290. 
3291. /* called when eatfood occupation has been interrupted,
3292.    or in the case of theft, is about to be interrupted */
3293. boolean
3294. maybe_finished_meal(stopping)
3295. boolean stopping;
3296. {
3297.     /* in case consume_oeaten() has decided that the food is all gone */
3298.     if (occupation == eatfood
3299.         && context.victual.usedtime >= context.victual.reqtime) {
3300.         if (stopping)
3301.             occupation = 0; /* for do_reset_eat */
3302.         (void) eatfood();   /* calls done_eating() to use up
3303.                                context.victual.piece */
3304.         return TRUE;
3305.     }
3306.     return FALSE;
3307. }
3308. 
3309. /* Tin of <something> to the rescue?  Decide whether current occupation
3310.    is an attempt to eat a tin of something capable of saving hero's life.
3311.    We don't care about consumption of non-tinned food here because special
3312.    effects there take place on first bite rather than at end of occupation.
3313.    [Popeye the Sailor gets out of trouble by eating tins of spinach. :-] */
3314. boolean
3315. Popeye(threat)
3316. int threat;
3317. {
3318.     struct obj *otin;
3319.     int mndx;
3320. 
3321.     if (occupation != opentin)
3322.         return FALSE;
3323.     otin = context.tin.tin;
3324.     /* make sure hero still has access to tin */
3325.     if (!carried(otin)
3326.         && (!obj_here(otin, u.ux, u.uy) || !can_reach_floor(TRUE)))
3327.         return FALSE;
3328.     /* unknown tin is assumed to be helpful */
3329.     if (!otin->known)
3330.         return TRUE;
3331.     /* known tin is helpful if it will stop life-threatening problem */
3332.     mndx = otin->corpsenm;
3333.     switch (threat) {
3334.     /* note: not used; hunger code bypasses stop_occupation() when eating */
3335.     case HUNGER:
3336.         return (boolean) (mndx != NON_PM || otin->spe == 1);
3337.     /* flesh from lizards and acidic critters stops petrification */
3338.     case STONED:
3339.         return (boolean) (mndx >= LOW_PM
3340.                           && (mndx == PM_LIZARD || acidic(&mons[mndx])));
3341.     /* no tins can cure these (yet?) */
3342.     case SLIMED:
3343.     case SICK:
3344.     case VOMITING:
3345.         break;
3346.     default:
3347.         break;
3348.     }
3349.     return FALSE;
3350. }
3351. 
3352. /*eat.c*/