Source:NetHack 3.6.1/src/eat.c

From NetHackWiki
(Redirected from Source:Ref/eatmupdate)
Jump to: navigation, search

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

Top of file

  1.  /* NetHack 3.6	eat.c	$NHDT-Date: 1502754159 2017/08/14 23:42:39 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.179 $ */
  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. */

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.  
  2.  #include "hack.h"
  3.  
  4.  STATIC_PTR int NDECL(eatmdone);
  5.  STATIC_PTR int NDECL(eatfood);
  6.  STATIC_PTR struct obj *FDECL(costly_tin, (int));
  7.  STATIC_PTR int NDECL(opentin);
  8.  STATIC_PTR int NDECL(unfaint);
  9.  
  10.  STATIC_DCL const char *FDECL(food_xname, (struct obj *, BOOLEAN_P));
  11.  STATIC_DCL void FDECL(choke, (struct obj *));
  12.  STATIC_DCL void NDECL(recalc_wt);
  13.  STATIC_DCL unsigned FDECL(obj_nutrition, (struct obj *));
  14.  STATIC_DCL struct obj *FDECL(touchfood, (struct obj *));
  15.  STATIC_DCL void NDECL(do_reset_eat);
  16.  STATIC_DCL void FDECL(done_eating, (BOOLEAN_P));
  17.  STATIC_DCL void FDECL(cprefx, (int));
  18.  STATIC_DCL int FDECL(intrinsic_possible, (int, struct permonst *));
  19.  STATIC_DCL void FDECL(givit, (int, struct permonst *));
  20.  STATIC_DCL void FDECL(cpostfx, (int));
  21.  STATIC_DCL void FDECL(consume_tin, (const char *));
  22.  STATIC_DCL void FDECL(start_tin, (struct obj *));
  23.  STATIC_DCL int FDECL(eatcorpse, (struct obj *));
  24.  STATIC_DCL void FDECL(start_eating, (struct obj *));
  25.  STATIC_DCL void FDECL(fprefx, (struct obj *));
  26.  STATIC_DCL void FDECL(fpostfx, (struct obj *));
  27.  STATIC_DCL int NDECL(bite);
  28.  STATIC_DCL int FDECL(edibility_prompts, (struct obj *));
  29.  STATIC_DCL int FDECL(rottenfood, (struct obj *));
  30.  STATIC_DCL void NDECL(eatspecial);
  31.  STATIC_DCL int FDECL(bounded_increase, (int, int, int));
  32.  STATIC_DCL void FDECL(accessory_has_effect, (struct obj *));
  33.  STATIC_DCL void FDECL(eataccessory, (struct obj *));
  34.  STATIC_DCL const char *FDECL(foodword, (struct obj *));
  35.  STATIC_DCL int FDECL(tin_variety, (struct obj *, BOOLEAN_P));
  36.  STATIC_DCL boolean FDECL(maybe_cannibal, (int, BOOLEAN_P));
  37.  
  38.  char msgbuf[BUFSZ];
  39.  
  40.  /* also used to see if you're allowed to eat cats and dogs */
  41.  #define CANNIBAL_ALLOWED() (Role_if(PM_CAVEMAN) || Race_if(PM_ORC))
  42.  
  43.  /* monster types that cause hero to be turned into stone if eaten */
  44.  #define flesh_petrifies(pm) (touch_petrifies(pm) || (pm) == &mons[PM_MEDUSA])
  45.  
  46.  /* Rider corpses are treated as non-rotting so that attempting to eat one
  47.     will be sure to reach the stage of eating where that meal is fatal */
  48.  #define nonrotting_corpse(mnum) \
  49.      ((mnum) == PM_LIZARD || (mnum) == PM_LICHEN || is_rider(&mons[mnum]))
  50.  
  51.  /* non-rotting non-corpses; unlike lizard corpses, these items will behave
  52.     as if rotten if they are cursed (fortune cookies handled elsewhere) */
  53.  #define nonrotting_food(otyp) \
  54.      ((otyp) == LEMBAS_WAFER || (otyp) == CRAM_RATION)
  55.  
  56.  STATIC_OVL NEARDATA const char comestibles[] = { FOOD_CLASS, 0 };
  57.  STATIC_OVL NEARDATA const char offerfodder[] = { FOOD_CLASS, AMULET_CLASS,
  58.                                                   0 };
  59.  
  60.  /* Gold must come first for getobj(). */
  61.  STATIC_OVL NEARDATA const char allobj[] = {
  62.      COIN_CLASS,   WEAPON_CLASS, ARMOR_CLASS,  POTION_CLASS,
  63.      SCROLL_CLASS, WAND_CLASS,   RING_CLASS,   AMULET_CLASS,
  64.      FOOD_CLASS,   TOOL_CLASS,   GEM_CLASS,    ROCK_CLASS,
  65.      BALL_CLASS,   CHAIN_CLASS,  SPBOOK_CLASS, 0
  66.  };
  67.  
  68.  STATIC_OVL boolean force_save_hs = FALSE;
  69.  
  70.  /* see hunger states in hack.h - texts used on bottom line */
  71.  const char *hu_stat[] = { "Satiated", "        ", "Hungry  ", "Weak    ",
  72.                            "Fainting", "Fainted ", "Starved " };
  73.  

is_edible

  1.  /*
  2.   * Decide whether a particular object can be eaten by the possibly
  3.   * polymorphed character.  Not used for monster checks.
  4.   */
  5.  boolean
  6.  is_edible(obj)
  7.  register struct obj *obj;
  8.  {
  9.      /* protect invocation tools but not Rider corpses (handled elsewhere)*/
  10.      /* if (obj->oclass != FOOD_CLASS && obj_resists(obj, 0, 0)) */
  11.      if (objects[obj->otyp].oc_unique)
  12.          return FALSE;
  13.      /* above also prevents the Amulet from being eaten, so we must never
  14.         allow fake amulets to be eaten either [which is already the case] */
  15.  
  16.      if (metallivorous(youmonst.data) && is_metallic(obj)
  17.          && (youmonst.data != &mons[PM_RUST_MONSTER] || is_rustprone(obj)))
  18.          return TRUE;
  19.  
  20.      /* Ghouls only eat non-veggy corpses or eggs (see dogfood()) */
  21.      if (u.umonnum == PM_GHOUL)
  22.          return (boolean)((obj->otyp == CORPSE
  23.                            && !vegan(&mons[obj->corpsenm]))
  24.                           || (obj->otyp == EGG));
  25.  
  26.      if (u.umonnum == PM_GELATINOUS_CUBE && is_organic(obj)
  27.          /* [g.cubes can eat containers and retain all contents
  28.              as engulfed items, but poly'd player can't do that] */
  29.          && !Has_contents(obj))
  30.          return TRUE;
  31.  
  32.      /* return (boolean) !!index(comestibles, obj->oclass); */
  33.      return (boolean) (obj->oclass == FOOD_CLASS);
  34.  }
  35.  

init_uhunger

  1.  void
  2.  init_uhunger()
  3.  {
  4.      context.botl = (u.uhs != NOT_HUNGRY || ATEMP(A_STR) < 0);
  5.      u.uhunger = 900;
  6.      u.uhs = NOT_HUNGRY;
  7.      if (ATEMP(A_STR) < 0)
  8.          ATEMP(A_STR) = 0;
  9.  }
  10.  
  11.  /* tin types [SPINACH_TIN = -1, overrides corpsenm, nut==600] */
  12.  static const struct {
  13.      const char *txt;                      /* description */
  14.      int nut;                              /* nutrition */
  15.      Bitfield(fodder, 1);                  /* stocked by health food shops */
  16.      Bitfield(greasy, 1);                  /* causes slippery fingers */
  17.  } tintxts[] = { { "rotten", -50, 0, 0 },  /* ROTTEN_TIN = 0 */
  18.                  { "homemade", 50, 1, 0 }, /* HOMEMADE_TIN = 1 */
  19.                  { "soup made from", 20, 1, 0 },
  20.                  { "french fried", 40, 0, 1 },
  21.                  { "pickled", 40, 1, 0 },
  22.                  { "boiled", 50, 1, 0 },
  23.                  { "smoked", 50, 1, 0 },
  24.                  { "dried", 55, 1, 0 },
  25.                  { "deep fried", 60, 0, 1 },
  26.                  { "szechuan", 70, 1, 0 },
  27.                  { "broiled", 80, 0, 0 },
  28.                  { "stir fried", 80, 0, 1 },
  29.                  { "sauteed", 95, 0, 0 },
  30.                  { "candied", 100, 1, 0 },
  31.                  { "pureed", 500, 1, 0 },
  32.                  { "", 0, 0, 0 } };
  33.  #define TTSZ SIZE(tintxts)
  34.  
  35.  static char *eatmbuf = 0; /* set by cpostfx() */
  36.  

eatmdone

  1.  /* called after mimicing is over */
  2.  STATIC_PTR int
  3.  eatmdone(VOID_ARGS)
  4.  {
  5.      /* release `eatmbuf' */
  6.      if (eatmbuf) {
  7.          if (nomovemsg == eatmbuf)
  8.              nomovemsg = 0;
  9.          free((genericptr_t) eatmbuf), eatmbuf = 0;
  10.      }
  11.      /* update display */
  12.      if (youmonst.m_ap_type) {
  13.          youmonst.m_ap_type = M_AP_NOTHING;
  14.          newsym(u.ux, u.uy);
  15.      }
  16.      return 0;
  17.  }
  18.  

eatmupdate

  1.  /* called when hallucination is toggled */
  2.  void
  3.  eatmupdate()
  4.  {
  5.      const char *altmsg = 0;
  6.      int altapp = 0; /* lint suppression */
  7.  
  8.      if (!eatmbuf || nomovemsg != eatmbuf)
  9.          return;
  10.  
  11.      if (is_obj_mappear(&youmonst,ORANGE) && !Hallucination) {
  12.          /* revert from hallucinatory to "normal" mimicking */
  13.          altmsg = "You now prefer mimicking yourself.";
  14.          altapp = GOLD_PIECE;
  15.      } else if (is_obj_mappear(&youmonst,GOLD_PIECE) && Hallucination) {
  16.          /* won't happen; anything which might make immobilized
  17.             hero begin hallucinating (black light attack, theft
  18.             of Grayswandir) will terminate the mimicry first */
  19.          altmsg = "Your rind escaped intact.";
  20.          altapp = ORANGE;
  21.      }
  22.  
  23.      if (altmsg) {
  24.          /* replace end-of-mimicking message */
  25.          if (strlen(altmsg) > strlen(eatmbuf)) {
  26.              free((genericptr_t) eatmbuf);
  27.              eatmbuf = (char *) alloc(strlen(altmsg) + 1);
  28.          }
  29.          nomovemsg = strcpy(eatmbuf, altmsg);
  30.          /* update current image */
  31.          youmonst.mappearance = altapp;
  32.          newsym(u.ux, u.uy);
  33.      }
  34.  }
  35.  

food_xname

  1.  /* ``[the(] singular(food, xname) [)]'' */
  2.  STATIC_OVL const char *
  3.  food_xname(food, the_pfx)
  4.  struct obj *food;
  5.  boolean the_pfx;
  6.  {
  7.      const char *result;
  8.  
  9.      if (food->otyp == CORPSE) {
  10.          result = corpse_xname(food, (const char *) 0,
  11.                                CXN_SINGULAR | (the_pfx ? CXN_PFX_THE : 0));
  12.          /* not strictly needed since pname values are capitalized
  13.             and the() is a no-op for them */
  14.          if (type_is_pname(&mons[food->corpsenm]))
  15.              the_pfx = FALSE;
  16.      } else {
  17.          /* the ordinary case */
  18.          result = singular(food, xname);
  19.      }
  20.      if (the_pfx)
  21.          result = the(result);
  22.      return result;
  23.  }
  24.  

choke

  1.  /* Created by GAN 01/28/87
  2.   * Amended by AKP 09/22/87: if not hard, don't choke, just vomit.
  3.   * Amended by 3.  06/12/89: if not hard, sometimes choke anyway, to keep risk.
  4.   *                11/10/89: if hard, rarely vomit anyway, for slim chance.
  5.   *
  6.   * To a full belly all food is bad. (It.)
  7.   */
  8.  STATIC_OVL void
  9.  choke(food)
  10.  struct obj *food;
  11.  {
  12.      /* only happens if you were satiated */
  13.      if (u.uhs != SATIATED) {
  14.          if (!food || food->otyp != AMULET_OF_STRANGULATION)
  15.              return;
  16.      } else if (Role_if(PM_KNIGHT) && u.ualign.type == A_LAWFUL) {
  17.          adjalign(-1); /* gluttony is unchivalrous */
  18.          You_feel("like a glutton!");
  19.      }
  20.  
  21.      exercise(A_CON, FALSE);
  22.  
  23.      if (Breathless || (!Strangled && !rn2(20))) {
  24.          /* choking by eating AoS doesn't involve stuffing yourself */
  25.          if (food && food->otyp == AMULET_OF_STRANGULATION) {
  26.              You("choke, but recover your composure.");
  27.              return;
  28.          }
  29.          You("stuff yourself and then vomit voluminously.");
  30.          morehungry(1000); /* you just got *very* sick! */
  31.          vomit();
  32.      } else {
  33.          killer.format = KILLED_BY_AN;
  34.          /*
  35.           * Note all "killer"s below read "Choked on %s" on the
  36.           * high score list & tombstone.  So plan accordingly.
  37.           */
  38.          if (food) {
  39.              You("choke over your %s.", foodword(food));
  40.              if (food->oclass == COIN_CLASS) {
  41.                  Strcpy(killer.name, "very rich meal");
  42.              } else {
  43.                  killer.format = KILLED_BY;
  44.                  Strcpy(killer.name, killer_xname(food));
  45.              }
  46.          } else {
  47.              You("choke over it.");
  48.              Strcpy(killer.name, "quick snack");
  49.          }
  50.          You("die...");
  51.          done(CHOKING);
  52.      }
  53.  }
  54.  

recalc_wt

  1.  /* modify object wt. depending on time spent consuming it */
  2.  STATIC_OVL void
  3.  recalc_wt()
  4.  {
  5.      struct obj *piece = context.victual.piece;
  6.      if (!piece) {
  7.          impossible("recalc_wt without piece");
  8.          return;
  9.      }
  10.      debugpline1("Old weight = %d", piece->owt);
  11.      debugpline2("Used time = %d, Req'd time = %d", context.victual.usedtime,
  12.                  context.victual.reqtime);
  13.      piece->owt = weight(piece);
  14.      debugpline1("New weight = %d", piece->owt);
  15.  }
  16.  

reset_eat

  1.  /* called when eating interrupted by an event */
  2.  void
  3.  reset_eat()
  4.  {
  5.      /* we only set a flag here - the actual reset process is done after
  6.       * the round is spent eating.
  7.       */
  8.      if (context.victual.eating && !context.victual.doreset) {
  9.          debugpline0("reset_eat...");
  10.          context.victual.doreset = TRUE;
  11.      }
  12.      return;
  13.  }
  14.  

obj_nutrition

  1.  /* base nutrition of a food-class object */
  2.  STATIC_OVL unsigned
  3.  obj_nutrition(otmp)
  4.  struct obj *otmp;
  5.  {
  6.      unsigned nut = (otmp->otyp == CORPSE) ? mons[otmp->corpsenm].cnutrit
  7.                        : otmp->globby ? otmp->owt
  8.                           : (unsigned) objects[otmp->otyp].oc_nutrition;
  9.  
  10.      if (otmp->otyp == LEMBAS_WAFER) {
  11.          if (maybe_polyd(is_elf(youmonst.data), Race_if(PM_ELF)))
  12.              nut += nut / 4; /* 800 -> 1000 */
  13.          else if (maybe_polyd(is_orc(youmonst.data), Race_if(PM_ORC)))
  14.              nut -= nut / 4; /* 800 -> 600 */
  15.          /* prevent polymorph making a partly eaten wafer
  16.             become more nutritious than an untouched one */
  17.          if (otmp->oeaten >= nut)
  18.              otmp->oeaten = (otmp->oeaten < objects[LEMBAS_WAFER].oc_nutrition)
  19.                                ? (nut - 1) : nut;
  20.      } else if (otmp->otyp == CRAM_RATION) {
  21.          if (maybe_polyd(is_dwarf(youmonst.data), Race_if(PM_DWARF)))
  22.              nut += nut / 6; /* 600 -> 700 */
  23.      }
  24.      return nut;
  25.  }
  26.  

touchfood

  1.  STATIC_OVL struct obj *
  2.  touchfood(otmp)
  3.  struct obj *otmp;
  4.  {
  5.      if (otmp->quan > 1L) {
  6.          if (!carried(otmp))
  7.              (void) splitobj(otmp, otmp->quan - 1L);
  8.          else
  9.              otmp = splitobj(otmp, 1L);
  10.          debugpline0("split object,");
  11.      }
  12.  
  13.      if (!otmp->oeaten) {
  14.          costly_alteration(otmp, COST_BITE);
  15.          otmp->oeaten = obj_nutrition(otmp);
  16.      }
  17.  
  18.      if (carried(otmp)) {
  19.          freeinv(otmp);
  20.          if (inv_cnt(FALSE) >= 52) {
  21.              sellobj_state(SELL_DONTSELL);
  22.              dropy(otmp);
  23.              sellobj_state(SELL_NORMAL);
  24.          } else {
  25.              otmp->nomerge = 1; /* used to prevent merge */
  26.              otmp = addinv(otmp);
  27.              otmp->nomerge = 0;
  28.          }
  29.      }
  30.      return otmp;
  31.  }
  32.  

food_disappears

  1.  /* When food decays, in the middle of your meal, we don't want to dereference
  2.   * any dangling pointers, so set it to null (which should still trigger
  3.   * do_reset_eat() at the beginning of eatfood()) and check for null pointers
  4.   * in do_reset_eat().
  5.   */
  6.  void
  7.  food_disappears(obj)
  8.  struct obj *obj;
  9.  {
  10.      if (obj == context.victual.piece) {
  11.          context.victual.piece = (struct obj *) 0;
  12.          context.victual.o_id = 0;
  13.      }
  14.      if (obj->timed)
  15.          obj_stop_timers(obj);
  16.  }
  17.  

food_substitution

  1.  /* renaming an object used to result in it having a different address,
  2.     so the sequence start eating/opening, get interrupted, name the food,
  3.     resume eating/opening would restart from scratch */
  4.  void
  5.  food_substitution(old_obj, new_obj)
  6.  struct obj *old_obj, *new_obj;
  7.  {
  8.      if (old_obj == context.victual.piece) {
  9.          context.victual.piece = new_obj;
  10.          context.victual.o_id = new_obj->o_id;
  11.      }
  12.      if (old_obj == context.tin.tin) {
  13.          context.tin.tin = new_obj;
  14.          context.tin.o_id = new_obj->o_id;
  15.      }
  16.  }
  17.  

do_reset_eat

  1.  STATIC_OVL void
  2.  do_reset_eat()
  3.  {
  4.      debugpline0("do_reset_eat...");
  5.      if (context.victual.piece) {
  6.          context.victual.o_id = 0;
  7.          context.victual.piece = touchfood(context.victual.piece);
  8.          if (context.victual.piece)
  9.              context.victual.o_id = context.victual.piece->o_id;
  10.          recalc_wt();
  11.      }
  12.      context.victual.fullwarn = context.victual.eating =
  13.          context.victual.doreset = FALSE;
  14.      /* Do not set canchoke to FALSE; if we continue eating the same object
  15.       * we need to know if canchoke was set when they started eating it the
  16.       * previous time.  And if we don't continue eating the same object
  17.       * canchoke always gets recalculated anyway.
  18.       */
  19.      stop_occupation();
  20.      newuhs(FALSE);
  21.  }
  22.  

eatfood

  1.  /* called each move during eating process */
  2.  STATIC_PTR int
  3.  eatfood(VOID_ARGS)
  4.  {
  5.      if (!context.victual.piece
  6.          || (!carried(context.victual.piece)
  7.              && !obj_here(context.victual.piece, u.ux, u.uy))) {
  8.          /* maybe it was stolen? */
  9.          do_reset_eat();
  10.          return 0;
  11.      }
  12.      if (!context.victual.eating)
  13.          return 0;
  14.  
  15.      if (++context.victual.usedtime <= context.victual.reqtime) {
  16.          if (bite())
  17.              return 0;
  18.          return 1; /* still busy */
  19.      } else {        /* done */
  20.          done_eating(TRUE);
  21.          return 0;
  22.      }
  23.  }
  24.  

done_eating

  1.  STATIC_OVL void
  2.  done_eating(message)
  3.  boolean message;
  4.  {
  5.      struct obj *piece = context.victual.piece;
  6.  
  7.      piece->in_use = TRUE;
  8.      occupation = 0; /* do this early, so newuhs() knows we're done */
  9.      newuhs(FALSE);
  10.      if (nomovemsg) {
  11.          if (message)
  12.              pline1(nomovemsg);
  13.          nomovemsg = 0;
  14.      } else if (message)
  15.          You("finish eating %s.", food_xname(piece, TRUE));
  16.  
  17.      if (piece->otyp == CORPSE || piece->globby)
  18.          cpostfx(piece->corpsenm);
  19.      else
  20.          fpostfx(piece);
  21.  
  22.      if (carried(piece))
  23.          useup(piece);
  24.      else
  25.          useupf(piece, 1L);
  26.      context.victual.piece = (struct obj *) 0;
  27.      context.victual.o_id = 0;
  28.      context.victual.fullwarn = context.victual.eating =
  29.          context.victual.doreset = FALSE;
  30.  }
  31.  

eating_conducts

  1.  void
  2.  eating_conducts(pd)
  3.  struct permonst *pd;
  4.  {
  5.      u.uconduct.food++;
  6.      if (!vegan(pd))
  7.          u.uconduct.unvegan++;
  8.      if (!vegetarian(pd))
  9.          violated_vegetarian();
  10.  }
  11.  

eat_brains

  1.  /* handle side-effects of mind flayer's tentacle attack */
  2.  int
  3.  eat_brains(magr, mdef, visflag, dmg_p)
  4.  struct monst *magr, *mdef;
  5.  boolean visflag;
  6.  int *dmg_p; /* for dishing out extra damage in lieu of Int loss */
  7.  {
  8.      struct permonst *pd = mdef->data;
  9.      boolean give_nutrit = FALSE;
  10.      int result = MM_HIT, xtra_dmg = rnd(10);
  11.  
  12.      if (noncorporeal(pd)) {
  13.          if (visflag)
  14.              pline("%s brain is unharmed.",
  15.                    (mdef == &youmonst) ? "Your" : s_suffix(Monnam(mdef)));
  16.          return MM_MISS; /* side-effects can't occur */
  17.      } else if (magr == &youmonst) {
  18.          You("eat %s brain!", s_suffix(mon_nam(mdef)));
  19.      } else if (mdef == &youmonst) {
  20.          Your("brain is eaten!");
  21.      } else { /* monster against monster */
  22.          if (visflag && canspotmon(mdef))
  23.              pline("%s brain is eaten!", s_suffix(Monnam(mdef)));
  24.      }
  25.  
  26.      if (flesh_petrifies(pd)) {
  27.          /* mind flayer has attempted to eat the brains of a petrification
  28.             inducing critter (most likely Medusa; attacking a cockatrice via
  29.             tentacle-touch should have been caught before reaching this far) */
  30.          if (magr == &youmonst) {
  31.              if (!Stone_resistance && !Stoned)
  32.                  make_stoned(5L, (char *) 0, KILLED_BY_AN, pd->mname);
  33.          } else {
  34.              /* no need to check for poly_when_stoned or Stone_resistance;
  35.                 mind flayers don't have those capabilities */
  36.              if (visflag && canseemon(magr))
  37.                  pline("%s turns to stone!", Monnam(magr));
  38.              monstone(magr);
  39.              if (magr->mhp > 0) {
  40.                  /* life-saved; don't continue eating the brains */
  41.                  return MM_MISS;
  42.              } else {
  43.                  if (magr->mtame && !visflag)
  44.                      /* parallels mhitm.c's brief_feeling */
  45.                      You("have a sad thought for a moment, then it passes.");
  46.                  return MM_AGR_DIED;
  47.              }
  48.          }
  49.      }
  50.  
  51.      if (magr == &youmonst) {
  52.          /*
  53.           * player mind flayer is eating something's brain
  54.           */
  55.          eating_conducts(pd);
  56.          if (mindless(pd)) { /* (cannibalism not possible here) */
  57.              pline("%s doesn't notice.", Monnam(mdef));
  58.              /* all done; no extra harm inflicted upon target */
  59.              return MM_MISS;
  60.          } else if (is_rider(pd)) {
  61.              pline("Ingesting that is fatal.");
  62.              Sprintf(killer.name, "unwisely ate the brain of %s", pd->mname);
  63.              killer.format = NO_KILLER_PREFIX;
  64.              done(DIED);
  65.              /* life-saving needed to reach here */
  66.              exercise(A_WIS, FALSE);
  67.              *dmg_p += xtra_dmg; /* Rider takes extra damage */
  68.          } else {
  69.              morehungry(-rnd(30)); /* cannot choke */
  70.              if (ABASE(A_INT) < AMAX(A_INT)) {
  71.                  /* recover lost Int; won't increase current max */
  72.                  ABASE(A_INT) += rnd(4);
  73.                  if (ABASE(A_INT) > AMAX(A_INT))
  74.                      ABASE(A_INT) = AMAX(A_INT);
  75.                  context.botl = 1;
  76.              }
  77.              exercise(A_WIS, TRUE);
  78.              *dmg_p += xtra_dmg;
  79.          }
  80.          /* targetting another mind flayer or your own underlying species
  81.             is cannibalism */
  82.          (void) maybe_cannibal(monsndx(pd), TRUE);
  83.  
  84.      } else if (mdef == &youmonst) {
  85.          /*
  86.           * monster mind flayer is eating hero's brain
  87.           */
  88.          /* no such thing as mindless players */
  89.          if (ABASE(A_INT) <= ATTRMIN(A_INT)) {
  90.              static NEARDATA const char brainlessness[] = "brainlessness";
  91.  
  92.              if (Lifesaved) {
  93.                  Strcpy(killer.name, brainlessness);
  94.                  killer.format = KILLED_BY;
  95.                  done(DIED);
  96.                  /* amulet of life saving has now been used up */
  97.                  pline("Unfortunately your brain is still gone.");
  98.                  /* sanity check against adding other forms of life-saving */
  99.                  u.uprops[LIFESAVED].extrinsic =
  100.                      u.uprops[LIFESAVED].intrinsic = 0L;
  101.              } else {
  102.                  Your("last thought fades away.");
  103.              }
  104.              Strcpy(killer.name, brainlessness);
  105.              killer.format = KILLED_BY;
  106.              done(DIED);
  107.              /* can only get here when in wizard or explore mode and user has
  108.                 explicitly chosen not to die; arbitrarily boost intelligence */
  109.              ABASE(A_INT) = ATTRMIN(A_INT) + 2;
  110.              You_feel("like a scarecrow.");
  111.          }
  112.          give_nutrit = TRUE; /* in case a conflicted pet is doing this */
  113.          exercise(A_WIS, FALSE);
  114.          /* caller handles Int and memory loss */
  115.  
  116.      } else { /* mhitm */
  117.          /*
  118.           * monster mind flayer is eating another monster's brain
  119.           */
  120.          if (mindless(pd)) {
  121.              if (visflag && canspotmon(mdef))
  122.                  pline("%s doesn't notice.", Monnam(mdef));
  123.              return MM_MISS;
  124.          } else if (is_rider(pd)) {
  125.              mondied(magr);
  126.              if (magr->mhp <= 0)
  127.                  result = MM_AGR_DIED;
  128.              /* Rider takes extra damage regardless of whether attacker dies */
  129.              *dmg_p += xtra_dmg;
  130.          } else {
  131.              *dmg_p += xtra_dmg;
  132.              give_nutrit = TRUE;
  133.              if (*dmg_p >= mdef->mhp && visflag && canspotmon(mdef))
  134.                  pline("%s last thought fades away...",
  135.                        s_suffix(Monnam(mdef)));
  136.          }
  137.      }
  138.  
  139.      if (give_nutrit && magr->mtame && !magr->isminion) {
  140.          EDOG(magr)->hungrytime += rnd(60);
  141.          magr->mconf = 0;
  142.      }
  143.  
  144.      return result;
  145.  }
  146.  

maybe_cannibal

  1.  /* eating a corpse or egg of one's own species is usually naughty */
  2.  STATIC_OVL boolean
  3.  maybe_cannibal(pm, allowmsg)
  4.  int pm;
  5.  boolean allowmsg;
  6.  {
  7.      static NEARDATA long ate_brains = 0L;
  8.      struct permonst *fptr = &mons[pm]; /* food type */
  9.  
  10.      /* when poly'd into a mind flayer, multiple tentacle hits in one
  11.         turn cause multiple digestion checks to occur; avoid giving
  12.         multiple luck penalties for the same attack */
  13.      if (moves == ate_brains)
  14.          return FALSE;
  15.      ate_brains = moves; /* ate_anything, not just brains... */
  16.  
  17.      if (!CANNIBAL_ALLOWED()
  18.          /* non-cannibalistic heroes shouldn't eat own species ever
  19.             and also shouldn't eat current species when polymorphed
  20.             (even if having the form of something which doesn't care
  21.             about cannibalism--hero's innate traits aren't altered) */
  22.          && (your_race(fptr)
  23.              || (Upolyd && same_race(youmonst.data, fptr))
  24.              || (u.ulycn >= LOW_PM && were_beastie(pm) == u.ulycn))) {
  25.          if (allowmsg) {
  26.              if (Upolyd && your_race(fptr))
  27.                  You("have a bad feeling deep inside.");
  28.              You("cannibal!  You will regret this!");
  29.          }
  30.          HAggravate_monster |= FROMOUTSIDE;
  31.          change_luck(-rn1(4, 2)); /* -5..-2 */
  32.          return TRUE;
  33.      }
  34.      return FALSE;
  35.  }
  36.  

cprefx

  1.  STATIC_OVL void
  2.  cprefx(pm)
  3.  register int pm;
  4.  {
  5.      (void) maybe_cannibal(pm, TRUE);
  6.      if (flesh_petrifies(&mons[pm])) {
  7.          if (!Stone_resistance
  8.              && !(poly_when_stoned(youmonst.data)
  9.                   && polymon(PM_STONE_GOLEM))) {
  10.              Sprintf(killer.name, "tasting %s meat", mons[pm].mname);
  11.              killer.format = KILLED_BY;
  12.              You("turn to stone.");
  13.              done(STONING);
  14.              if (context.victual.piece)
  15.                  context.victual.eating = FALSE;
  16.              return; /* lifesaved */
  17.          }
  18.      }
  19.  
  20.      switch (pm) {
  21.      case PM_LITTLE_DOG:
  22.      case PM_DOG:
  23.      case PM_LARGE_DOG:
  24.      case PM_KITTEN:
  25.      case PM_HOUSECAT:
  26.      case PM_LARGE_CAT:
  27.          /* cannibals are allowed to eat domestic animals without penalty */
  28.          if (!CANNIBAL_ALLOWED()) {
  29.              You_feel("that eating the %s was a bad idea.", mons[pm].mname);
  30.              HAggravate_monster |= FROMOUTSIDE;
  31.          }
  32.          break;
  33.      case PM_LIZARD:
  34.          if (Stoned)
  35.              fix_petrification();
  36.          break;
  37.      case PM_DEATH:
  38.      case PM_PESTILENCE:
  39.      case PM_FAMINE: {
  40.          pline("Eating that is instantly fatal.");
  41.          Sprintf(killer.name, "unwisely ate the body of %s", mons[pm].mname);
  42.          killer.format = NO_KILLER_PREFIX;
  43.          done(DIED);
  44.          /* life-saving needed to reach here */
  45.          exercise(A_WIS, FALSE);
  46.          /* It so happens that since we know these monsters */
  47.          /* cannot appear in tins, context.victual.piece will always */
  48.          /* be what we want, which is not generally true. */
  49.          if (revive_corpse(context.victual.piece)) {
  50.              context.victual.piece = (struct obj *) 0;
  51.              context.victual.o_id = 0;
  52.          }
  53.          return;
  54.      }
  55.      case PM_GREEN_SLIME:
  56.          if (!Slimed && !Unchanging && !slimeproof(youmonst.data)) {
  57.              You("don't feel very well.");
  58.              make_slimed(10L, (char *) 0);
  59.              delayed_killer(SLIMED, KILLED_BY_AN, "");
  60.          }
  61.      /* Fall through */
  62.      default:
  63.          if (acidic(&mons[pm]) && Stoned)
  64.              fix_petrification();
  65.          break;
  66.      }
  67.  }
  68.  

fix_petrification

  1.  void
  2.  fix_petrification()
  3.  {
  4.      char buf[BUFSZ];
  5.  
  6.      if (Hallucination)
  7.          Sprintf(buf, "What a pity--you just ruined a future piece of %sart!",
  8.                  ACURR(A_CHA) > 15 ? "fine " : "");
  9.      else
  10.          Strcpy(buf, "You feel limber!");
  11.      make_stoned(0L, buf, 0, (char *) 0);
  12.  }
  13.  
  14.  /*
  15.   * If you add an intrinsic that can be gotten by eating a monster, add it
  16.   * to intrinsic_possible() and givit().  (It must already be in prop.h to
  17.   * be an intrinsic property.)
  18.   * It would be very easy to make the intrinsics not try to give you one
  19.   * that you already had by checking to see if you have it in
  20.   * intrinsic_possible() instead of givit(), but we're not that nice.
  21.   */
  22.  

intrinsic_possible

  1.  /* intrinsic_possible() returns TRUE iff a monster can give an intrinsic. */
  2.  STATIC_OVL int
  3.  intrinsic_possible(type, ptr)
  4.  int type;
  5.  register struct permonst *ptr;
  6.  {
  7.      int res = 0;
  8.  
  9.  #ifdef DEBUG
  10.  #define ifdebugresist(Msg)      \
  11.      do {                        \
  12.          if (res)                \
  13.              debugpline0(Msg);   \
  14.      } while (0)
  15.  #else
  16.  #define ifdebugresist(Msg) /*empty*/
  17.  #endif
  18.      switch (type) {
  19.      case FIRE_RES:
  20.          res = (ptr->mconveys & MR_FIRE) != 0;
  21.          ifdebugresist("can get fire resistance");
  22.          break;
  23.      case SLEEP_RES:
  24.          res = (ptr->mconveys & MR_SLEEP) != 0;
  25.          ifdebugresist("can get sleep resistance");
  26.          break;
  27.      case COLD_RES:
  28.          res = (ptr->mconveys & MR_COLD) != 0;
  29.          ifdebugresist("can get cold resistance");
  30.          break;
  31.      case DISINT_RES:
  32.          res = (ptr->mconveys & MR_DISINT) != 0;
  33.          ifdebugresist("can get disintegration resistance");
  34.          break;
  35.      case SHOCK_RES: /* shock (electricity) resistance */
  36.          res = (ptr->mconveys & MR_ELEC) != 0;
  37.          ifdebugresist("can get shock resistance");
  38.          break;
  39.      case POISON_RES:
  40.          res = (ptr->mconveys & MR_POISON) != 0;
  41.          ifdebugresist("can get poison resistance");
  42.          break;
  43.      case TELEPORT:
  44.          res = can_teleport(ptr);
  45.          ifdebugresist("can get teleport");
  46.          break;
  47.      case TELEPORT_CONTROL:
  48.          res = control_teleport(ptr);
  49.          ifdebugresist("can get teleport control");
  50.          break;
  51.      case TELEPAT:
  52.          res = telepathic(ptr);
  53.          ifdebugresist("can get telepathy");
  54.          break;
  55.      default:
  56.          /* res stays 0 */
  57.          break;
  58.      }
  59.  #undef ifdebugresist
  60.      return res;
  61.  }
  62.  

givit

  1.  /* givit() tries to give you an intrinsic based on the monster's level
  2.   * and what type of intrinsic it is trying to give you.
  3.   */
  4.  STATIC_OVL void
  5.  givit(type, ptr)
  6.  int type;
  7.  register struct permonst *ptr;
  8.  {
  9.      register int chance;
  10.  
  11.      debugpline1("Attempting to give intrinsic %d", type);
  12.      /* some intrinsics are easier to get than others */
  13.      switch (type) {
  14.      case POISON_RES:
  15.          if ((ptr == &mons[PM_KILLER_BEE] || ptr == &mons[PM_SCORPION])
  16.              && !rn2(4))
  17.              chance = 1;
  18.          else
  19.              chance = 15;
  20.          break;
  21.      case TELEPORT:
  22.          chance = 10;
  23.          break;
  24.      case TELEPORT_CONTROL:
  25.          chance = 12;
  26.          break;
  27.      case TELEPAT:
  28.          chance = 1;
  29.          break;
  30.      default:
  31.          chance = 15;
  32.          break;
  33.      }
  34.  
  35.      if (ptr->mlevel <= rn2(chance))
  36.          return; /* failed die roll */
  37.  
  38.      switch (type) {
  39.      case FIRE_RES:
  40.          debugpline0("Trying to give fire resistance");
  41.          if (!(HFire_resistance & FROMOUTSIDE)) {
  42.              You(Hallucination ? "be chillin'." : "feel a momentary chill.");
  43.              HFire_resistance |= FROMOUTSIDE;
  44.          }
  45.          break;
  46.      case SLEEP_RES:
  47.          debugpline0("Trying to give sleep resistance");
  48.          if (!(HSleep_resistance & FROMOUTSIDE)) {
  49.              You_feel("wide awake.");
  50.              HSleep_resistance |= FROMOUTSIDE;
  51.          }
  52.          break;
  53.      case COLD_RES:
  54.          debugpline0("Trying to give cold resistance");
  55.          if (!(HCold_resistance & FROMOUTSIDE)) {
  56.              You_feel("full of hot air.");
  57.              HCold_resistance |= FROMOUTSIDE;
  58.          }
  59.          break;
  60.      case DISINT_RES:
  61.          debugpline0("Trying to give disintegration resistance");
  62.          if (!(HDisint_resistance & FROMOUTSIDE)) {
  63.              You_feel(Hallucination ? "totally together, man." : "very firm.");
  64.              HDisint_resistance |= FROMOUTSIDE;
  65.          }
  66.          break;
  67.      case SHOCK_RES: /* shock (electricity) resistance */
  68.          debugpline0("Trying to give shock resistance");
  69.          if (!(HShock_resistance & FROMOUTSIDE)) {
  70.              if (Hallucination)
  71.                  You_feel("grounded in reality.");
  72.              else
  73.                  Your("health currently feels amplified!");
  74.              HShock_resistance |= FROMOUTSIDE;
  75.          }
  76.          break;
  77.      case POISON_RES:
  78.          debugpline0("Trying to give poison resistance");
  79.          if (!(HPoison_resistance & FROMOUTSIDE)) {
  80.              You_feel(Poison_resistance ? "especially healthy." : "healthy.");
  81.              HPoison_resistance |= FROMOUTSIDE;
  82.          }
  83.          break;
  84.      case TELEPORT:
  85.          debugpline0("Trying to give teleport");
  86.          if (!(HTeleportation & FROMOUTSIDE)) {
  87.              You_feel(Hallucination ? "diffuse." : "very jumpy.");
  88.              HTeleportation |= FROMOUTSIDE;
  89.          }
  90.          break;
  91.      case TELEPORT_CONTROL:
  92.          debugpline0("Trying to give teleport control");
  93.          if (!(HTeleport_control & FROMOUTSIDE)) {
  94.              You_feel(Hallucination ? "centered in your personal space."
  95.                                     : "in control of yourself.");
  96.              HTeleport_control |= FROMOUTSIDE;
  97.          }
  98.          break;
  99.      case TELEPAT:
  100.          debugpline0("Trying to give telepathy");
  101.          if (!(HTelepat & FROMOUTSIDE)) {
  102.              You_feel(Hallucination ? "in touch with the cosmos."
  103.                                     : "a strange mental acuity.");
  104.              HTelepat |= FROMOUTSIDE;
  105.              /* If blind, make sure monsters show up. */
  106.              if (Blind)
  107.                  see_monsters();
  108.          }
  109.          break;
  110.      default:
  111.          debugpline0("Tried to give an impossible intrinsic");
  112.          break;
  113.      }
  114.  }
  115.  

cpostfx

  1.  /* called after completely consuming a corpse */
  2.  STATIC_OVL void
  3.  cpostfx(pm)
  4.  register int pm;
  5.  {
  6.      register int tmp = 0;
  7.      int catch_lycanthropy = NON_PM;
  8.  
  9.      /* in case `afternmv' didn't get called for previously mimicking
  10.         gold, clean up now to avoid `eatmbuf' memory leak */
  11.      if (eatmbuf)
  12.          (void) eatmdone();
  13.  
  14.      switch (pm) {
  15.      case PM_NEWT:
  16.          /* MRKR: "eye of newt" may give small magical energy boost */
  17.          if (rn2(3) || 3 * u.uen <= 2 * u.uenmax) {
  18.              int old_uen = u.uen;
  19.              u.uen += rnd(3);
  20.              if (u.uen > u.uenmax) {
  21.                  if (!rn2(3))
  22.                      u.uenmax++;
  23.                  u.uen = u.uenmax;
  24.              }
  25.              if (old_uen != u.uen) {
  26.                  You_feel("a mild buzz.");
  27.                  context.botl = 1;
  28.              }
  29.          }
  30.          break;
  31.      case PM_WRAITH:
  32.          pluslvl(FALSE);
  33.          break;
  34.      case PM_HUMAN_WERERAT:
  35.          catch_lycanthropy = PM_WERERAT;
  36.          break;
  37.      case PM_HUMAN_WEREJACKAL:
  38.          catch_lycanthropy = PM_WEREJACKAL;
  39.          break;
  40.      case PM_HUMAN_WEREWOLF:
  41.          catch_lycanthropy = PM_WEREWOLF;
  42.          break;
  43.      case PM_NURSE:
  44.          if (Upolyd)
  45.              u.mh = u.mhmax;
  46.          else
  47.              u.uhp = u.uhpmax;
  48.          make_blinded(0L, !u.ucreamed);
  49.          context.botl = 1;
  50.          break;
  51.      case PM_STALKER:
  52.          if (!Invis) {
  53.              set_itimeout(&HInvis, (long) rn1(100, 50));
  54.              if (!Blind && !BInvis)
  55.                  self_invis_message();
  56.          } else {
  57.              if (!(HInvis & INTRINSIC))
  58.                  You_feel("hidden!");
  59.              HInvis |= FROMOUTSIDE;
  60.              HSee_invisible |= FROMOUTSIDE;
  61.          }
  62.          newsym(u.ux, u.uy);
  63.          /*FALLTHRU*/
  64.      case PM_YELLOW_LIGHT:
  65.      case PM_GIANT_BAT:
  66.          make_stunned((HStun & TIMEOUT) + 30L, FALSE);
  67.          /*FALLTHRU*/
  68.      case PM_BAT:
  69.          make_stunned((HStun & TIMEOUT) + 30L, FALSE);
  70.          break;
  71.      case PM_GIANT_MIMIC:
  72.          tmp += 10;
  73.          /*FALLTHRU*/
  74.      case PM_LARGE_MIMIC:
  75.          tmp += 20;
  76.          /*FALLTHRU*/
  77.      case PM_SMALL_MIMIC:
  78.          tmp += 20;
  79.          if (youmonst.data->mlet != S_MIMIC && !Unchanging) {
  80.              char buf[BUFSZ];
  81.  
  82.              u.uconduct.polyselfs++; /* you're changing form */
  83.              You_cant("resist the temptation to mimic %s.",
  84.                       Hallucination ? "an orange" : "a pile of gold");
  85.              /* A pile of gold can't ride. */
  86.              if (u.usteed)
  87.                  dismount_steed(DISMOUNT_FELL);
  88.              nomul(-tmp);
  89.              multi_reason = "pretending to be a pile of gold";
  90.              Sprintf(buf,
  91.                      Hallucination
  92.                         ? "You suddenly dread being peeled and mimic %s again!"
  93.                         : "You now prefer mimicking %s again.",
  94.                      an(Upolyd ? youmonst.data->mname : urace.noun));
  95.              eatmbuf = dupstr(buf);
  96.              nomovemsg = eatmbuf;
  97.              afternmv = eatmdone;
  98.              /* ??? what if this was set before? */
  99.              youmonst.m_ap_type = M_AP_OBJECT;
  100.              youmonst.mappearance = Hallucination ? ORANGE : GOLD_PIECE;
  101.              newsym(u.ux, u.uy);
  102.              curs_on_u();
  103.              /* make gold symbol show up now */
  104.              display_nhwindow(WIN_MAP, TRUE);
  105.          }
  106.          break;
  107.      case PM_QUANTUM_MECHANIC:
  108.          Your("velocity suddenly seems very uncertain!");
  109.          if (HFast & INTRINSIC) {
  110.              HFast &= ~INTRINSIC;
  111.              You("seem slower.");
  112.          } else {
  113.              HFast |= FROMOUTSIDE;
  114.              You("seem faster.");
  115.          }
  116.          break;
  117.      case PM_LIZARD:
  118.          if ((HStun & TIMEOUT) > 2)
  119.              make_stunned(2L, FALSE);
  120.          if ((HConfusion & TIMEOUT) > 2)
  121.              make_confused(2L, FALSE);
  122.          break;
  123.      case PM_CHAMELEON:
  124.      case PM_DOPPELGANGER:
  125.      case PM_SANDESTIN: /* moot--they don't leave corpses */
  126.          if (Unchanging) {
  127.              You_feel("momentarily different."); /* same as poly trap */
  128.          } else {
  129.              You_feel("a change coming over you.");
  130.              polyself(0);
  131.          }
  132.          break;
  133.      case PM_DISENCHANTER:
  134.          /* picks an intrinsic at random and removes it; there's
  135.             no feedback if hero already lacks the chosen ability */
  136.          debugpline0("using attrcurse to strip an intrinsic");
  137.          attrcurse();
  138.          break;
  139.      case PM_MIND_FLAYER:
  140.      case PM_MASTER_MIND_FLAYER:
  141.          if (ABASE(A_INT) < ATTRMAX(A_INT)) {
  142.              if (!rn2(2)) {
  143.                  pline("Yum! That was real brain food!");
  144.                  (void) adjattrib(A_INT, 1, FALSE);
  145.                  break; /* don't give them telepathy, too */
  146.              }
  147.          } else {
  148.              pline("For some reason, that tasted bland.");
  149.          }
  150.      /*FALLTHRU*/
  151.      default: {
  152.          struct permonst *ptr = &mons[pm];
  153.          boolean conveys_STR = is_giant(ptr);
  154.          int i, count;
  155.  
  156.          if (dmgtype(ptr, AD_STUN) || dmgtype(ptr, AD_HALU)
  157.              || pm == PM_VIOLET_FUNGUS) {
  158.              pline("Oh wow!  Great stuff!");
  159.              (void) make_hallucinated((HHallucination & TIMEOUT) + 200L, FALSE,
  160.                                       0L);
  161.          }
  162.  
  163.          /* Check the monster for all of the intrinsics.  If this
  164.           * monster can give more than one, pick one to try to give
  165.           * from among all it can give.
  166.           *
  167.           * Strength from giants is now treated like an intrinsic
  168.           * rather than being given unconditionally.
  169.           */
  170.          count = 0; /* number of possible intrinsics */
  171.          tmp = 0;   /* which one we will try to give */
  172.          if (conveys_STR) {
  173.              count = 1;
  174.              tmp = -1; /* use -1 as fake prop index for STR */
  175.              debugpline1("\"Intrinsic\" strength, %d", tmp);
  176.          }
  177.          for (i = 1; i <= LAST_PROP; i++) {
  178.              if (!intrinsic_possible(i, ptr))
  179.                  continue;
  180.              ++count;
  181.              /* a 1 in count chance of replacing the old choice
  182.                 with this one, and a count-1 in count chance
  183.                 of keeping the old choice (note that 1 in 1 and
  184.                 0 in 1 are what we want for the first candidate) */
  185.              if (!rn2(count)) {
  186.                  debugpline2("Intrinsic %d replacing %d", i, tmp);
  187.                  tmp = i;
  188.              }
  189.          }
  190.          /* if strength is the only candidate, give it 50% chance */
  191.          if (conveys_STR && count == 1 && !rn2(2))
  192.              tmp = 0;
  193.          /* if something was chosen, give it now (givit() might fail) */
  194.          if (tmp == -1)
  195.              gainstr((struct obj *) 0, 0, TRUE);
  196.          else if (tmp > 0)
  197.              givit(tmp, ptr);
  198.          break;
  199.      } /* default case */
  200.      } /* switch */
  201.  
  202.      if (catch_lycanthropy >= LOW_PM) {
  203.          set_ulycn(catch_lycanthropy);
  204.          retouch_equipment(2);
  205.      }
  206.      return;
  207.  }
  208.  

violated_vegetarian

  1.  void
  2.  violated_vegetarian()
  3.  {
  4.      u.uconduct.unvegetarian++;
  5.      if (Role_if(PM_MONK)) {
  6.          You_feel("guilty.");
  7.          adjalign(-1);
  8.      }
  9.      return;
  10.  }
  11.  

costly_tin

  1.  /* common code to check and possibly charge for 1 context.tin.tin,
  2.   * will split() context.tin.tin if necessary */
  3.  STATIC_PTR struct obj *
  4.  costly_tin(alter_type)
  5.  int alter_type; /* COST_xxx */
  6.  {
  7.      struct obj *tin = context.tin.tin;
  8.  
  9.      if (carried(tin) ? tin->unpaid
  10.                       : (costly_spot(tin->ox, tin->oy) && !tin->no_charge)) {
  11.          if (tin->quan > 1L) {
  12.              tin = context.tin.tin = splitobj(tin, 1L);
  13.              context.tin.o_id = tin->o_id;
  14.          }
  15.          costly_alteration(tin, alter_type);
  16.      }
  17.      return tin;
  18.  }
  19.  

tin_variety_txt

  1.  int
  2.  tin_variety_txt(s, tinvariety)
  3.  char *s;
  4.  int *tinvariety;
  5.  {
  6.      int k, l;
  7.  
  8.      if (s && tinvariety) {
  9.          *tinvariety = -1;
  10.          for (k = 0; k < TTSZ - 1; ++k) {
  11.              l = (int) strlen(tintxts[k].txt);
  12.              if (!strncmpi(s, tintxts[k].txt, l) && ((int) strlen(s) > l)
  13.                  && s[l] == ' ') {
  14.                  *tinvariety = k;
  15.                  return (l + 1);
  16.              }
  17.          }
  18.      }
  19.      return 0;
  20.  }
  21.  

tin_details

  1.  /*
  2.   * This assumes that buf already contains the word "tin",
  3.   * as is the case with caller xname().
  4.   */
  5.  void
  6.  tin_details(obj, mnum, buf)
  7.  struct obj *obj;
  8.  int mnum;
  9.  char *buf;
  10.  {
  11.      char buf2[BUFSZ];
  12.      int r = tin_variety(obj, TRUE);
  13.  
  14.      if (obj && buf) {
  15.          if (r == SPINACH_TIN)
  16.              Strcat(buf, " of spinach");
  17.          else if (mnum == NON_PM)
  18.              Strcpy(buf, "empty tin");
  19.          else {
  20.              if ((obj->cknown || iflags.override_ID) && obj->spe < 0) {
  21.                  if (r == ROTTEN_TIN || r == HOMEMADE_TIN) {
  22.                      /* put these before the word tin */
  23.                      Sprintf(buf2, "%s %s of ", tintxts[r].txt, buf);
  24.                      Strcpy(buf, buf2);
  25.                  } else {
  26.                      Sprintf(eos(buf), " of %s ", tintxts[r].txt);
  27.                  }
  28.              } else {
  29.                  Strcpy(eos(buf), " of ");
  30.              }
  31.              if (vegetarian(&mons[mnum]))
  32.                  Sprintf(eos(buf), "%s", mons[mnum].mname);
  33.              else
  34.                  Sprintf(eos(buf), "%s meat", mons[mnum].mname);
  35.          }
  36.      }
  37.  }
  38.  

set_tin_variety

  1.  void
  2.  set_tin_variety(obj, forcetype)
  3.  struct obj *obj;
  4.  int forcetype;
  5.  {
  6.      register int r;
  7.  
  8.      if (forcetype == SPINACH_TIN
  9.          || (forcetype == HEALTHY_TIN
  10.              && (obj->corpsenm == NON_PM /* empty or already spinach */
  11.                  || !vegetarian(&mons[obj->corpsenm])))) { /* replace meat */
  12.          obj->corpsenm = NON_PM; /* not based on any monster */
  13.          obj->spe = 1;           /* spinach */
  14.          return;
  15.      } else if (forcetype == HEALTHY_TIN) {
  16.          r = tin_variety(obj, FALSE);
  17.          if (r < 0 || r >= TTSZ)
  18.              r = ROTTEN_TIN; /* shouldn't happen */
  19.          while ((r == ROTTEN_TIN && !obj->cursed) || !tintxts[r].fodder)
  20.              r = rn2(TTSZ - 1);
  21.      } else if (forcetype >= 0 && forcetype < TTSZ - 1) {
  22.          r = forcetype;
  23.      } else {               /* RANDOM_TIN */
  24.          r = rn2(TTSZ - 1); /* take your pick */
  25.          if (r == ROTTEN_TIN && nonrotting_corpse(obj->corpsenm))
  26.              r = HOMEMADE_TIN; /* lizards don't rot */
  27.      }
  28.      obj->spe = -(r + 1); /* offset by 1 to allow index 0 */
  29.  }
  30.  

tin_variety

  1.  STATIC_OVL int
  2.  tin_variety(obj, disp)
  3.  struct obj *obj;
  4.  boolean disp; /* we're just displaying so leave things alone */
  5.  {
  6.      register int r;
  7.  
  8.      if (obj->spe == 1) {
  9.          r = SPINACH_TIN;
  10.      } else if (obj->cursed) {
  11.          r = ROTTEN_TIN; /* always rotten if cursed */
  12.      } else if (obj->spe < 0) {
  13.          r = -(obj->spe);
  14.          --r; /* get rid of the offset */
  15.      } else
  16.          r = rn2(TTSZ - 1);
  17.  
  18.      if (!disp && r == HOMEMADE_TIN && !obj->blessed && !rn2(7))
  19.          r = ROTTEN_TIN; /* some homemade tins go bad */
  20.  
  21.      if (r == ROTTEN_TIN && nonrotting_corpse(obj->corpsenm))
  22.          r = HOMEMADE_TIN; /* lizards don't rot */
  23.      return r;
  24.  }
  25.  

consume_tin

  1.  STATIC_OVL void
  2.  consume_tin(mesg)
  3.  const char *mesg;
  4.  {
  5.      const char *what;
  6.      int which, mnum, r;
  7.      struct obj *tin = context.tin.tin;
  8.  
  9.      r = tin_variety(tin, FALSE);
  10.      if (tin->otrapped || (tin->cursed && r != HOMEMADE_TIN && !rn2(8))) {
  11.          b_trapped("tin", 0);
  12.          tin = costly_tin(COST_DSTROY);
  13.          goto use_up_tin;
  14.      }
  15.  
  16.      pline1(mesg); /* "You succeed in opening the tin." */
  17.  
  18.      if (r != SPINACH_TIN) {
  19.          mnum = tin->corpsenm;
  20.          if (mnum == NON_PM) {
  21.              pline("It turns out to be empty.");
  22.              tin->dknown = tin->known = 1;
  23.              tin = costly_tin(COST_OPEN);
  24.              goto use_up_tin;
  25.          }
  26.  
  27.          which = 0; /* 0=>plural, 1=>as-is, 2=>"the" prefix */
  28.          if ((mnum == PM_COCKATRICE || mnum == PM_CHICKATRICE)
  29.              && (Stone_resistance || Hallucination)) {
  30.              what = "chicken";
  31.              which = 1; /* suppress pluralization */
  32.          } else if (Hallucination) {
  33.              what = rndmonnam(NULL);
  34.          } else {
  35.              what = mons[mnum].mname;
  36.              if (the_unique_pm(&mons[mnum]))
  37.                  which = 2;
  38.              else if (type_is_pname(&mons[mnum]))
  39.                  which = 1;
  40.          }
  41.          if (which == 0)
  42.              what = makeplural(what);
  43.          else if (which == 2)
  44.              what = the(what);
  45.  
  46.          pline("It smells like %s.", what);
  47.          if (yn("Eat it?") == 'n') {
  48.              if (flags.verbose)
  49.                  You("discard the open tin.");
  50.              if (!Hallucination)
  51.                  tin->dknown = tin->known = 1;
  52.              tin = costly_tin(COST_OPEN);
  53.              goto use_up_tin;
  54.          }
  55.  
  56.          /* in case stop_occupation() was called on previous meal */
  57.          context.victual.piece = (struct obj *) 0;
  58.          context.victual.o_id = 0;
  59.          context.victual.fullwarn = context.victual.eating =
  60.              context.victual.doreset = FALSE;
  61.  
  62.          You("consume %s %s.", tintxts[r].txt, mons[mnum].mname);
  63.  
  64.          eating_conducts(&mons[mnum]);
  65.  
  66.          tin->dknown = tin->known = 1;
  67.          cprefx(mnum);
  68.          cpostfx(mnum);
  69.  
  70.          /* charge for one at pre-eating cost */
  71.          tin = costly_tin(COST_OPEN);
  72.  
  73.          if (tintxts[r].nut < 0) /* rotten */
  74.              make_vomiting((long) rn1(15, 10), FALSE);
  75.          else
  76.              lesshungry(tintxts[r].nut);
  77.  
  78.          if (tintxts[r].greasy) {
  79.              /* Assume !Glib, because you can't open tins when Glib. */
  80.              incr_itimeout(&Glib, rnd(15));
  81.              pline("Eating %s food made your %s very slippery.",
  82.                    tintxts[r].txt, makeplural(body_part(FINGER)));
  83.          }
  84.  
  85.      } else { /* spinach... */
  86.          if (tin->cursed) {
  87.              pline("It contains some decaying%s%s substance.",
  88.                    Blind ? "" : " ", Blind ? "" : hcolor(NH_GREEN));
  89.          } else {
  90.              pline("It contains spinach.");
  91.              tin->dknown = tin->known = 1;
  92.          }
  93.  
  94.          if (yn("Eat it?") == 'n') {
  95.              if (flags.verbose)
  96.                  You("discard the open tin.");
  97.              tin = costly_tin(COST_OPEN);
  98.              goto use_up_tin;
  99.          }
  100.  
  101.          /*
  102.           * Same order as with non-spinach above:
  103.           * conduct update, side-effects, shop handling, and nutrition.
  104.           */
  105.          u.uconduct.food++; /* don't need vegetarian checks for spinach */
  106.          if (!tin->cursed)
  107.              pline("This makes you feel like %s!",
  108.                    Hallucination ? "Swee'pea" : "Popeye");
  109.          gainstr(tin, 0, FALSE);
  110.  
  111.          tin = costly_tin(COST_OPEN);
  112.  
  113.          lesshungry(tin->blessed
  114.                        ? 600                   /* blessed */
  115.                        : !tin->cursed
  116.                           ? (400 + rnd(200))   /* uncursed */
  117.                           : (200 + rnd(400))); /* cursed */
  118.      }
  119.  
  120.  use_up_tin:
  121.      if (carried(tin))
  122.          useup(tin);
  123.      else
  124.          useupf(tin, 1L);
  125.      context.tin.tin = (struct obj *) 0;
  126.      context.tin.o_id = 0;
  127.  }
  128.  

opentin

  1.  /* called during each move whilst opening a tin */
  2.  STATIC_PTR int
  3.  opentin(VOID_ARGS)
  4.  {
  5.      /* perhaps it was stolen (although that should cause interruption) */
  6.      if (!carried(context.tin.tin)
  7.          && (!obj_here(context.tin.tin, u.ux, u.uy) || !can_reach_floor(TRUE)))
  8.          return 0; /* %% probably we should use tinoid */
  9.      if (context.tin.usedtime++ >= 50) {
  10.          You("give up your attempt to open the tin.");
  11.          return 0;
  12.      }
  13.      if (context.tin.usedtime < context.tin.reqtime)
  14.          return 1; /* still busy */
  15.  
  16.      consume_tin("You succeed in opening the tin.");
  17.      return 0;
  18.  }
  19.  

start_tin

  1.  /* called when starting to open a tin */
  2.  STATIC_OVL void
  3.  start_tin(otmp)
  4.  struct obj *otmp;
  5.  {
  6.      const char *mesg = 0;
  7.      register int tmp;
  8.  
  9.      if (metallivorous(youmonst.data)) {
  10.          mesg = "You bite right into the metal tin...";
  11.          tmp = 0;
  12.      } else if (cantwield(youmonst.data)) { /* nohands || verysmall */
  13.          You("cannot handle the tin properly to open it.");
  14.          return;
  15.      } else if (otmp->blessed) {
  16.          /* 50/50 chance for immediate access vs 1 turn delay (unless
  17.             wielding blessed tin opener which always yields immediate
  18.             access); 1 turn delay case is non-deterministic:  getting
  19.             interrupted and retrying might yield another 1 turn delay
  20.             or might open immediately on 2nd (or 3rd, 4th, ...) try */
  21.          tmp = (uwep && uwep->blessed && uwep->otyp == TIN_OPENER) ? 0 : rn2(2);
  22.          if (!tmp)
  23.              mesg = "The tin opens like magic!";
  24.          else
  25.              pline_The("tin seems easy to open.");
  26.      } else if (uwep) {
  27.          switch (uwep->otyp) {
  28.          case TIN_OPENER:
  29.              mesg = "You easily open the tin."; /* iff tmp==0 */
  30.              tmp = rn2(uwep->cursed ? 3 : !uwep->blessed ? 2 : 1);
  31.              break;
  32.          case DAGGER:
  33.          case SILVER_DAGGER:
  34.          case ELVEN_DAGGER:
  35.          case ORCISH_DAGGER:
  36.          case ATHAME:
  37.          case KNIFE:
  38.          case STILETTO:
  39.          case CRYSKNIFE:
  40.              tmp = 3;
  41.              break;
  42.          case PICK_AXE:
  43.          case AXE:
  44.              tmp = 6;
  45.              break;
  46.          default:
  47.              goto no_opener;
  48.          }
  49.          pline("Using %s you try to open the tin.", yobjnam(uwep, (char *) 0));
  50.      } else {
  51.      no_opener:
  52.          pline("It is not so easy to open this tin.");
  53.          if (Glib) {
  54.              pline_The("tin slips from your %s.",
  55.                        makeplural(body_part(FINGER)));
  56.              if (otmp->quan > 1L) {
  57.                  otmp = splitobj(otmp, 1L);
  58.              }
  59.              if (carried(otmp))
  60.                  dropx(otmp);
  61.              else
  62.                  stackobj(otmp);
  63.              return;
  64.          }
  65.          tmp = rn1(1 + 500 / ((int) (ACURR(A_DEX) + ACURRSTR)), 10);
  66.      }
  67.  
  68.      context.tin.tin = otmp;
  69.      context.tin.o_id = otmp->o_id;
  70.      if (!tmp) {
  71.          consume_tin(mesg); /* begin immediately */
  72.      } else {
  73.          context.tin.reqtime = tmp;
  74.          context.tin.usedtime = 0;
  75.          set_occupation(opentin, "opening the tin", 0);
  76.      }
  77.      return;
  78.  }
  79.  

Hear_again

  1.  /* called when waking up after fainting */
  2.  int
  3.  Hear_again(VOID_ARGS)
  4.  {
  5.      /* Chance of deafness going away while fainted/sleeping/etc. */
  6.      if (!rn2(2)) {
  7.          make_deaf(0L, FALSE);
  8.          context.botl = TRUE;
  9.      }
  10.      return 0;
  11.  }
  12.  

rottenfood

  1.  /* called on the "first bite" of rotten food */
  2.  STATIC_OVL int
  3.  rottenfood(obj)
  4.  struct obj *obj;
  5.  {
  6.      pline("Blecch!  Rotten %s!", foodword(obj));
  7.      if (!rn2(4)) {
  8.          if (Hallucination)
  9.              You_feel("rather trippy.");
  10.          else
  11.              You_feel("rather %s.", body_part(LIGHT_HEADED));
  12.          make_confused(HConfusion + d(2, 4), FALSE);
  13.      } else if (!rn2(4) && !Blind) {
  14.          pline("Everything suddenly goes dark.");
  15.          /* hero is not Blind, but Blinded timer might be nonzero if
  16.             blindness is being overridden by the Eyes of the Overworld */
  17.          make_blinded((Blinded & TIMEOUT) + (long) d(2, 10), FALSE);
  18.          if (!Blind)
  19.              Your1(vision_clears);
  20.      } else if (!rn2(3)) {
  21.          const char *what, *where;
  22.          int duration = rnd(10);
  23.  
  24.          if (!Blind)
  25.              what = "goes", where = "dark";
  26.          else if (Levitation || Is_airlevel(&u.uz) || Is_waterlevel(&u.uz))
  27.              what = "you lose control of", where = "yourself";
  28.          else
  29.              what = "you slap against the",
  30.              where = (u.usteed) ? "saddle" : surface(u.ux, u.uy);
  31.          pline_The("world spins and %s %s.", what, where);
  32.          incr_itimeout(&HDeaf, duration);
  33.          context.botl = TRUE;
  34.          nomul(-duration);
  35.          multi_reason = "unconscious from rotten food";
  36.          nomovemsg = "You are conscious again.";
  37.          afternmv = Hear_again;
  38.          return 1;
  39.      }
  40.      return 0;
  41.  }
  42.  

eatcorpse

  1.  /* called when a corpse is selected as food */
  2.  STATIC_OVL int
  3.  eatcorpse(otmp)
  4.  struct obj *otmp;
  5.  {
  6.      int retcode = 0, tp = 0, mnum = otmp->corpsenm;
  7.      long rotted = 0L;
  8.      boolean stoneable = (flesh_petrifies(&mons[mnum]) && !Stone_resistance
  9.                           && !poly_when_stoned(youmonst.data)),
  10.              slimeable = (mnum == PM_GREEN_SLIME && !Slimed && !Unchanging
  11.                           && !slimeproof(youmonst.data)),
  12.              glob = otmp->globby ? TRUE : FALSE;
  13.  
  14.      /* KMH, conduct */
  15.      if (!vegan(&mons[mnum]))
  16.          u.uconduct.unvegan++;
  17.      if (!vegetarian(&mons[mnum]))
  18.          violated_vegetarian();
  19.  
  20.      if (!nonrotting_corpse(mnum)) {
  21.          long age = peek_at_iced_corpse_age(otmp);
  22.  
  23.          rotted = (monstermoves - age) / (10L + rn2(20));
  24.          if (otmp->cursed)
  25.              rotted += 2L;
  26.          else if (otmp->blessed)
  27.              rotted -= 2L;
  28.      }
  29.  
  30.      if (mnum != PM_ACID_BLOB && !stoneable && !slimeable && rotted > 5L) {
  31.          boolean cannibal = maybe_cannibal(mnum, FALSE);
  32.  
  33.          pline("Ulch - that %s was tainted%s!",
  34.                (mons[mnum].mlet == S_FUNGUS) ? "fungoid vegetation"
  35.                    : glob ? "glob"
  36.                        : vegetarian(&mons[mnum]) ? "protoplasm"
  37.                            : "meat",
  38.                cannibal ? ", you cannibal" : "");
  39.          if (Sick_resistance) {
  40.              pline("It doesn't seem at all sickening, though...");
  41.          } else {
  42.              long sick_time;
  43.  
  44.              sick_time = (long) rn1(10, 10);
  45.              /* make sure new ill doesn't result in improvement */
  46.              if (Sick && (sick_time > Sick))
  47.                  sick_time = (Sick > 1L) ? Sick - 1L : 1L;
  48.              make_sick(sick_time, corpse_xname(otmp, "rotted", CXN_NORMAL),
  49.                        TRUE, SICK_VOMITABLE);
  50.  
  51.              pline("(It must have died too long ago to be safe to eat.)");
  52.          }
  53.          if (carried(otmp))
  54.              useup(otmp);
  55.          else
  56.              useupf(otmp, 1L);
  57.          return 2;
  58.      } else if (acidic(&mons[mnum]) && !Acid_resistance) {
  59.          tp++;
  60.          You("have a very bad case of stomach acid.");   /* not body_part() */
  61.          losehp(rnd(15), !glob ? "acidic corpse" : "acidic glob",
  62.                 KILLED_BY_AN); /* acid damage */
  63.      } else if (poisonous(&mons[mnum]) && rn2(5)) {
  64.          tp++;
  65.          pline("Ecch - that must have been poisonous!");
  66.          if (!Poison_resistance) {
  67.              losestr(rnd(4));
  68.              losehp(rnd(15), !glob ? "poisonous corpse" : "poisonous glob",
  69.                     KILLED_BY_AN);
  70.          } else
  71.              You("seem unaffected by the poison.");
  72.      /* now any corpse left too long will make you mildly ill */
  73.      } else if ((rotted > 5L || (rotted > 3L && rn2(5))) && !Sick_resistance) {
  74.          tp++;
  75.          You_feel("%ssick.", (Sick) ? "very " : "");
  76.          losehp(rnd(8), !glob ? "cadaver" : "rotted glob", KILLED_BY_AN);
  77.      }
  78.  
  79.      /* delay is weight dependent */
  80.      context.victual.reqtime = 3 + ((!glob ? mons[mnum].cwt : otmp->owt) >> 6);
  81.  
  82.      if (!tp && !nonrotting_corpse(mnum) && (otmp->orotten || !rn2(7))) {
  83.          if (rottenfood(otmp)) {
  84.              otmp->orotten = TRUE;
  85.              (void) touchfood(otmp);
  86.              retcode = 1;
  87.          }
  88.  
  89.          if (!mons[otmp->corpsenm].cnutrit) {
  90.              /* no nutrition: rots away, no message if you passed out */
  91.              if (!retcode)
  92.                  pline_The("corpse rots away completely.");
  93.              if (carried(otmp))
  94.                  useup(otmp);
  95.              else
  96.                  useupf(otmp, 1L);
  97.              retcode = 2;
  98.          }
  99.  
  100.          if (!retcode)
  101.              consume_oeaten(otmp, 2); /* oeaten >>= 2 */
  102.      } else if ((mnum == PM_COCKATRICE || mnum == PM_CHICKATRICE)
  103.                 && (Stone_resistance || Hallucination)) {
  104.          pline("This tastes just like chicken!");
  105.      } else if (mnum == PM_FLOATING_EYE && u.umonnum == PM_RAVEN) {
  106.          You("peck the eyeball with delight.");
  107.      } else {
  108.          /* yummy is always False for omnivores, palatable always True */
  109.          boolean yummy = (vegan(&mons[mnum])
  110.                              ? (!carnivorous(youmonst.data)
  111.                                 && herbivorous(youmonst.data))
  112.                              : (carnivorous(youmonst.data)
  113.                                 && !herbivorous(youmonst.data))),
  114.              palatable = ((vegetarian(&mons[mnum])
  115.                            ? herbivorous(youmonst.data)
  116.                            : carnivorous(youmonst.data))
  117.                           && rn2(10)
  118.                           && ((rotted < 1) ? TRUE : !rn2(rotted+1)));
  119.          const char *pmxnam = food_xname(otmp, FALSE);
  120.  
  121.          if (!strncmpi(pmxnam, "the ", 4))
  122.              pmxnam += 4;
  123.          pline("%s%s %s %s%c",
  124.                type_is_pname(&mons[mnum])
  125.                   ? "" : the_unique_pm(&mons[mnum]) ? "The " : "This ",
  126.                pmxnam,
  127.                Hallucination ? "is" : "tastes",
  128.                    /* tiger reference is to TV ads for "Frosted Flakes",
  129.                       breakfast cereal targeted at kids by "Tony the tiger" */
  130.                Hallucination
  131.                   ? (yummy ? ((u.umonnum == PM_TIGER) ? "gr-r-reat" : "gnarly")
  132.                            : palatable ? "copacetic" : "grody")
  133.                   : (yummy ? "delicious" : palatable ? "okay" : "terrible"),
  134.                (yummy || !palatable) ? '!' : '.');
  135.      }
  136.  
  137.      return retcode;
  138.  }
  139.  

start_eating

  1.  /* called as you start to eat */
  2.  STATIC_OVL void
  3.  start_eating(otmp)
  4.  struct obj *otmp;
  5.  {
  6.      const char *old_nomovemsg, *save_nomovemsg;
  7.  
  8.      debugpline2("start_eating: %s (victual = %s)",
  9.                  /* note: fmt_ptr() returns a static buffer but supports
  10.                     several such so we don't need to copy the first result
  11.                     before calling it a second time */
  12.                  fmt_ptr((genericptr_t) otmp),
  13.                  fmt_ptr((genericptr_t) context.victual.piece));
  14.      debugpline1("reqtime = %d", context.victual.reqtime);
  15.      debugpline1("(original reqtime = %d)", objects[otmp->otyp].oc_delay);
  16.      debugpline1("nmod = %d", context.victual.nmod);
  17.      debugpline1("oeaten = %d", otmp->oeaten);
  18.      context.victual.fullwarn = context.victual.doreset = FALSE;
  19.      context.victual.eating = TRUE;
  20.  
  21.      if (otmp->otyp == CORPSE || otmp->globby) {
  22.          cprefx(context.victual.piece->corpsenm);
  23.          if (!context.victual.piece || !context.victual.eating) {
  24.              /* rider revived, or died and lifesaved */
  25.              return;
  26.          }
  27.      }
  28.  
  29.      old_nomovemsg = nomovemsg;
  30.      if (bite()) {
  31.          /* survived choking, finish off food that's nearly done;
  32.             need this to handle cockatrice eggs, fortune cookies, etc */
  33.          if (++context.victual.usedtime >= context.victual.reqtime) {
  34.              /* don't want done_eating() to issue nomovemsg if it
  35.                 is due to vomit() called by bite() */
  36.              save_nomovemsg = nomovemsg;
  37.              if (!old_nomovemsg)
  38.                  nomovemsg = 0;
  39.              done_eating(FALSE);
  40.              if (!old_nomovemsg)
  41.                  nomovemsg = save_nomovemsg;
  42.          }
  43.          return;
  44.      }
  45.  
  46.      if (++context.victual.usedtime >= context.victual.reqtime) {
  47.          /* print "finish eating" message if they just resumed -dlc */
  48.          done_eating(context.victual.reqtime > 1 ? TRUE : FALSE);
  49.          return;
  50.      }
  51.  
  52.      Sprintf(msgbuf, "eating %s", food_xname(otmp, TRUE));
  53.      set_occupation(eatfood, msgbuf, 0);
  54.  }
  55.  

fprefx

  1.  /*
  2.   * called on "first bite" of (non-corpse) food.
  3.   * used for non-rotten non-tin non-corpse food
  4.   */
  5.  STATIC_OVL void
  6.  fprefx(otmp)
  7.  struct obj *otmp;
  8.  {
  9.      switch (otmp->otyp) {
  10.      case FOOD_RATION:
  11.          if (u.uhunger <= 200)
  12.              pline(Hallucination ? "Oh wow, like, superior, man!"
  13.                                  : "That food really hit the spot!");
  14.          else if (u.uhunger <= 700)
  15.              pline("That satiated your %s!", body_part(STOMACH));
  16.          break;
  17.      case TRIPE_RATION:
  18.          if (carnivorous(youmonst.data) && !humanoid(youmonst.data))
  19.              pline("That tripe ration was surprisingly good!");
  20.          else if (maybe_polyd(is_orc(youmonst.data), Race_if(PM_ORC)))
  21.              pline(Hallucination ? "Tastes great! Less filling!"
  22.                                  : "Mmm, tripe... not bad!");
  23.          else {
  24.              pline("Yak - dog food!");
  25.              more_experienced(1, 0);
  26.              newexplevel();
  27.              /* not cannibalism, but we use similar criteria
  28.                 for deciding whether to be sickened by this meal */
  29.              if (rn2(2) && !CANNIBAL_ALLOWED())
  30.                  make_vomiting((long) rn1(context.victual.reqtime, 14), FALSE);
  31.          }
  32.          break;
  33.      case LEMBAS_WAFER:
  34.          if (maybe_polyd(is_orc(youmonst.data), Race_if(PM_ORC))) {
  35.              pline("%s", "!#?&* elf kibble!");
  36.              break;
  37.          } else if (maybe_polyd(is_elf(youmonst.data), Race_if(PM_ELF))) {
  38.              pline("A little goes a long way.");
  39.              break;
  40.          }
  41.          goto give_feedback;
  42.      case MEATBALL:
  43.      case MEAT_STICK:
  44.      case HUGE_CHUNK_OF_MEAT:
  45.      case MEAT_RING:
  46.          goto give_feedback;
  47.      case CLOVE_OF_GARLIC:
  48.          if (is_undead(youmonst.data)) {
  49.              make_vomiting((long) rn1(context.victual.reqtime, 5), FALSE);
  50.              break;
  51.          }
  52.          /*FALLTHRU*/
  53.      default:
  54.          if (otmp->otyp == SLIME_MOLD && !otmp->cursed
  55.              && otmp->spe == context.current_fruit) {
  56.              pline("My, that was a %s %s!",
  57.                    Hallucination ? "primo" : "yummy",
  58.                    singular(otmp, xname));
  59.          } else if (otmp->otyp == APPLE && otmp->cursed && !Sleep_resistance) {
  60.              ; /* skip core joke; feedback deferred til fpostfx() */
  61.  
  62.  #if defined(MAC) || defined(MACOSX)
  63.          /* KMH -- Why should Unix have all the fun?
  64.             We check MACOSX before UNIX to get the Apple-specific apple
  65.             message; the '#if UNIX' code will still kick in for pear. */
  66.          } else if (otmp->otyp == APPLE) {
  67.              pline("Delicious!  Must be a Macintosh!");
  68.  #endif
  69.  
  70.  #ifdef UNIX
  71.          } else if (otmp->otyp == APPLE || otmp->otyp == PEAR) {
  72.              if (!Hallucination) {
  73.                  pline("Core dumped.");
  74.              } else {
  75.                  /* This is based on an old Usenet joke, a fake a.out manual
  76.                   * page
  77.                   */
  78.                  int x = rnd(100);
  79.  
  80.                  pline("%s -- core dumped.",
  81.                        (x <= 75)
  82.                           ? "Segmentation fault"
  83.                           : (x <= 99)
  84.                              ? "Bus error"
  85.                              : "Yo' mama");
  86.              }
  87.  #endif
  88.          } else if (otmp->otyp == EGG && stale_egg(otmp)) {
  89.              pline("Ugh.  Rotten egg."); /* perhaps others like it */
  90.              /* increasing existing nausea means that it will take longer
  91.                 before eventual vomit, but also means that constitution
  92.                 will be abused more times before illness completes */
  93.              make_vomiting((Vomiting & TIMEOUT) + (long) d(10, 4), TRUE);
  94.          } else {
  95.          give_feedback:
  96.              pline("This %s is %s", singular(otmp, xname),
  97.                    otmp->cursed
  98.                       ? (Hallucination ? "grody!" : "terrible!")
  99.                       : (otmp->otyp == CRAM_RATION
  100.                          || otmp->otyp == K_RATION
  101.                          || otmp->otyp == C_RATION)
  102.                          ? "bland."
  103.                          : Hallucination ? "gnarly!" : "delicious!");
  104.          }
  105.          break; /* default */
  106.      } /* switch */
  107.  }
  108.  

bounded_increase

  1.  /* increment a combat intrinsic with limits on its growth */
  2.  STATIC_OVL int
  3.  bounded_increase(old, inc, typ)
  4.  int old, inc, typ;
  5.  {
  6.      int absold, absinc, sgnold, sgninc;
  7.  
  8.      /* don't include any amount coming from worn rings */
  9.      if (uright && uright->otyp == typ)
  10.          old -= uright->spe;
  11.      if (uleft && uleft->otyp == typ)
  12.          old -= uleft->spe;
  13.      absold = abs(old), absinc = abs(inc);
  14.      sgnold = sgn(old), sgninc = sgn(inc);
  15.  
  16.      if (absinc == 0 || sgnold != sgninc || absold + absinc < 10) {
  17.          ; /* use inc as-is */
  18.      } else if (absold + absinc < 20) {
  19.          absinc = rnd(absinc); /* 1..n */
  20.          if (absold + absinc < 10)
  21.              absinc = 10 - absold;
  22.          inc = sgninc * absinc;
  23.      } else if (absold + absinc < 40) {
  24.          absinc = rn2(absinc) ? 1 : 0;
  25.          if (absold + absinc < 20)
  26.              absinc = rnd(20 - absold);
  27.          inc = sgninc * absinc;
  28.      } else {
  29.          inc = 0; /* no further increase allowed via this method */
  30.      }
  31.      return old + inc;
  32.  }
  33.  

accessory_has_effect

  1.  STATIC_OVL void
  2.  accessory_has_effect(otmp)
  3.  struct obj *otmp;
  4.  {
  5.      pline("Magic spreads through your body as you digest the %s.",
  6.            otmp->oclass == RING_CLASS ? "ring" : "amulet");
  7.  }
  8.  

eataccessory

  1.  STATIC_OVL void
  2.  eataccessory(otmp)
  3.  struct obj *otmp;
  4.  {
  5.      int typ = otmp->otyp;
  6.      long oldprop;
  7.  
  8.      /* Note: rings are not so common that this is unbalancing. */
  9.      /* (How often do you even _find_ 3 rings of polymorph in a game?) */
  10.      oldprop = u.uprops[objects[typ].oc_oprop].intrinsic;
  11.      if (otmp == uleft || otmp == uright) {
  12.          Ring_gone(otmp);
  13.          if (u.uhp <= 0)
  14.              return; /* died from sink fall */
  15.      }
  16.      otmp->known = otmp->dknown = 1; /* by taste */
  17.      if (!rn2(otmp->oclass == RING_CLASS ? 3 : 5)) {
  18.          switch (otmp->otyp) {
  19.          default:
  20.              if (!objects[typ].oc_oprop)
  21.                  break; /* should never happen */
  22.  
  23.              if (!(u.uprops[objects[typ].oc_oprop].intrinsic & FROMOUTSIDE))
  24.                  accessory_has_effect(otmp);
  25.  
  26.              u.uprops[objects[typ].oc_oprop].intrinsic |= FROMOUTSIDE;
  27.  
  28.              switch (typ) {
  29.              case RIN_SEE_INVISIBLE:
  30.                  set_mimic_blocking();
  31.                  see_monsters();
  32.                  if (Invis && !oldprop && !ESee_invisible
  33.                      && !perceives(youmonst.data) && !Blind) {
  34.                      newsym(u.ux, u.uy);
  35.                      pline("Suddenly you can see yourself.");
  36.                      makeknown(typ);
  37.                  }
  38.                  break;
  39.              case RIN_INVISIBILITY:
  40.                  if (!oldprop && !EInvis && !BInvis && !See_invisible
  41.                      && !Blind) {
  42.                      newsym(u.ux, u.uy);
  43.                      Your("body takes on a %s transparency...",
  44.                           Hallucination ? "normal" : "strange");
  45.                      makeknown(typ);
  46.                  }
  47.                  break;
  48.              case RIN_PROTECTION_FROM_SHAPE_CHAN:
  49.                  rescham();
  50.                  break;
  51.              case RIN_LEVITATION:
  52.                  /* undo the `.intrinsic |= FROMOUTSIDE' done above */
  53.                  u.uprops[LEVITATION].intrinsic = oldprop;
  54.                  if (!Levitation) {
  55.                      float_up();
  56.                      incr_itimeout(&HLevitation, d(10, 20));
  57.                      makeknown(typ);
  58.                  }
  59.                  break;
  60.              } /* inner switch */
  61.              break; /* default case of outer switch */
  62.  
  63.          case RIN_ADORNMENT:
  64.              accessory_has_effect(otmp);
  65.              if (adjattrib(A_CHA, otmp->spe, -1))
  66.                  makeknown(typ);
  67.              break;
  68.          case RIN_GAIN_STRENGTH:
  69.              accessory_has_effect(otmp);
  70.              if (adjattrib(A_STR, otmp->spe, -1))
  71.                  makeknown(typ);
  72.              break;
  73.          case RIN_GAIN_CONSTITUTION:
  74.              accessory_has_effect(otmp);
  75.              if (adjattrib(A_CON, otmp->spe, -1))
  76.                  makeknown(typ);
  77.              break;
  78.          case RIN_INCREASE_ACCURACY:
  79.              accessory_has_effect(otmp);
  80.              u.uhitinc = (schar) bounded_increase((int) u.uhitinc, otmp->spe,
  81.                                                   RIN_INCREASE_ACCURACY);
  82.              break;
  83.          case RIN_INCREASE_DAMAGE:
  84.              accessory_has_effect(otmp);
  85.              u.udaminc = (schar) bounded_increase((int) u.udaminc, otmp->spe,
  86.                                                   RIN_INCREASE_DAMAGE);
  87.              break;
  88.          case RIN_PROTECTION:
  89.              accessory_has_effect(otmp);
  90.              HProtection |= FROMOUTSIDE;
  91.              u.ublessed = bounded_increase(u.ublessed, otmp->spe,
  92.                                            RIN_PROTECTION);
  93.              context.botl = 1;
  94.              break;
  95.          case RIN_FREE_ACTION:
  96.              /* Give sleep resistance instead */
  97.              if (!(HSleep_resistance & FROMOUTSIDE))
  98.                  accessory_has_effect(otmp);
  99.              if (!Sleep_resistance)
  100.                  You_feel("wide awake.");
  101.              HSleep_resistance |= FROMOUTSIDE;
  102.              break;
  103.          case AMULET_OF_CHANGE:
  104.              accessory_has_effect(otmp);
  105.              makeknown(typ);
  106.              change_sex();
  107.              You("are suddenly very %s!",
  108.                  flags.female ? "feminine" : "masculine");
  109.              context.botl = 1;
  110.              break;
  111.          case AMULET_OF_UNCHANGING:
  112.              /* un-change: it's a pun */
  113.              if (!Unchanging && Upolyd) {
  114.                  accessory_has_effect(otmp);
  115.                  makeknown(typ);
  116.                  rehumanize();
  117.              }
  118.              break;
  119.          case AMULET_OF_STRANGULATION: /* bad idea! */
  120.              /* no message--this gives no permanent effect */
  121.              choke(otmp);
  122.              break;
  123.          case AMULET_OF_RESTFUL_SLEEP: { /* another bad idea! */
  124.              long newnap = (long) rnd(100), oldnap = (HSleepy & TIMEOUT);
  125.  
  126.              if (!(HSleepy & FROMOUTSIDE))
  127.                  accessory_has_effect(otmp);
  128.              HSleepy |= FROMOUTSIDE;
  129.              /* might also be wearing one; use shorter of two timeouts */
  130.              if (newnap < oldnap || oldnap == 0L)
  131.                  HSleepy = (HSleepy & ~TIMEOUT) | newnap;
  132.              break;
  133.          }
  134.          case RIN_SUSTAIN_ABILITY:
  135.          case AMULET_OF_LIFE_SAVING:
  136.          case AMULET_OF_REFLECTION: /* nice try */
  137.              /* can't eat Amulet of Yendor or fakes,
  138.               * and no oc_prop even if you could -3.
  139.               */
  140.              break;
  141.          }
  142.      }
  143.  }
  144.  

eatspecial

  1.  /* called after eating non-food */
  2.  STATIC_OVL void
  3.  eatspecial()
  4.  {
  5.      struct obj *otmp = context.victual.piece;
  6.  
  7.      /* lesshungry wants an occupation to handle choke messages correctly */
  8.      set_occupation(eatfood, "eating non-food", 0);
  9.      lesshungry(context.victual.nmod);
  10.      occupation = 0;
  11.      context.victual.piece = (struct obj *) 0;
  12.      context.victual.o_id = 0;
  13.      context.victual.eating = 0;
  14.      if (otmp->oclass == COIN_CLASS) {
  15.          if (carried(otmp))
  16.              useupall(otmp);
  17.          else
  18.              useupf(otmp, otmp->quan);
  19.          vault_gd_watching(GD_EATGOLD);
  20.          return;
  21.      }
  22.      if (objects[otmp->otyp].oc_material == PAPER) {
  23.  #ifdef MAIL
  24.          if (otmp->otyp == SCR_MAIL)
  25.              /* no nutrition */
  26.              pline("This junk mail is less than satisfying.");
  27.          else
  28.  #endif
  29.          if (otmp->otyp == SCR_SCARE_MONSTER)
  30.              /* to eat scroll, hero is currently polymorphed into a monster */
  31.              pline("Yuck%c", otmp->blessed ? '!' : '.');
  32.          else if (otmp->oclass == SCROLL_CLASS
  33.                   /* check description after checking for specific scrolls */
  34.                   && !strcmpi(OBJ_DESCR(objects[otmp->otyp]), "YUM YUM"))
  35.              pline("Yum%c", otmp->blessed ? '!' : '.');
  36.          else
  37.              pline("Needs salt...");
  38.      }
  39.      if (otmp->oclass == POTION_CLASS) {
  40.          otmp->quan++; /* dopotion() does a useup() */
  41.          (void) dopotion(otmp);
  42.      } else if (otmp->oclass == RING_CLASS || otmp->oclass == AMULET_CLASS) {
  43.          eataccessory(otmp);
  44.      } else if (otmp->otyp == LEASH && otmp->leashmon) {
  45.          o_unleash(otmp);
  46.      }
  47.  
  48.      /* KMH -- idea by "Tommy the Terrorist" */
  49.      if (otmp->otyp == TRIDENT && !otmp->cursed) {
  50.          /* sugarless chewing gum which used to be heavily advertised on TV */
  51.          pline(Hallucination ? "Four out of five dentists agree."
  52.                              : "That was pure chewing satisfaction!");
  53.          exercise(A_WIS, TRUE);
  54.      }
  55.      if (otmp->otyp == FLINT && !otmp->cursed) {
  56.          /* chewable vitamin for kids based on "The Flintstones" TV cartoon */
  57.          pline("Yabba-dabba delicious!");
  58.          exercise(A_CON, TRUE);
  59.      }
  60.  
  61.      if (otmp == uwep && otmp->quan == 1L)
  62.          uwepgone();
  63.      if (otmp == uquiver && otmp->quan == 1L)
  64.          uqwepgone();
  65.      if (otmp == uswapwep && otmp->quan == 1L)
  66.          uswapwepgone();
  67.  
  68.      if (otmp == uball)
  69.          unpunish();
  70.      if (otmp == uchain)
  71.          unpunish(); /* but no useup() */
  72.      else if (carried(otmp))
  73.          useup(otmp);
  74.      else
  75.          useupf(otmp, 1L);
  76.  }
  77.  
  78.  /* NOTE: the order of these words exactly corresponds to the
  79.     order of oc_material values #define'd in objclass.h. */
  80.  static const char *foodwords[] = {
  81.      "meal",    "liquid",  "wax",       "food", "meat",     "paper",
  82.      "cloth",   "leather", "wood",      "bone", "scale",    "metal",
  83.      "metal",   "metal",   "silver",    "gold", "platinum", "mithril",
  84.      "plastic", "glass",   "rich food", "stone"
  85.  };
  86.  

foodword

  1.  STATIC_OVL const char *
  2.  foodword(otmp)
  3.  struct obj *otmp;
  4.  {
  5.      if (otmp->oclass == FOOD_CLASS)
  6.          return "food";
  7.      if (otmp->oclass == GEM_CLASS && objects[otmp->otyp].oc_material == GLASS
  8.          && otmp->dknown)
  9.          makeknown(otmp->otyp);
  10.      return foodwords[objects[otmp->otyp].oc_material];
  11.  }
  12.  

fpostfx

  1.  /* called after consuming (non-corpse) food */
  2.  STATIC_OVL void
  3.  fpostfx(otmp)
  4.  struct obj *otmp;
  5.  {
  6.      switch (otmp->otyp) {
  7.      case SPRIG_OF_WOLFSBANE:
  8.          if (u.ulycn >= LOW_PM || is_were(youmonst.data))
  9.              you_unwere(TRUE);
  10.          break;
  11.      case CARROT:
  12.          if (!u.uswallow
  13.              || !attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_BLND))
  14.              make_blinded((long) u.ucreamed, TRUE);
  15.          break;
  16.      case FORTUNE_COOKIE:
  17.          outrumor(bcsign(otmp), BY_COOKIE);
  18.          if (!Blind)
  19.              u.uconduct.literate++;
  20.          break;
  21.      case LUMP_OF_ROYAL_JELLY:
  22.          /* This stuff seems to be VERY healthy! */
  23.          gainstr(otmp, 1, TRUE);
  24.          if (Upolyd) {
  25.              u.mh += otmp->cursed ? -rnd(20) : rnd(20);
  26.              if (u.mh > u.mhmax) {
  27.                  if (!rn2(17))
  28.                      u.mhmax++;
  29.                  u.mh = u.mhmax;
  30.              } else if (u.mh <= 0) {
  31.                  rehumanize();
  32.              }
  33.          } else {
  34.              u.uhp += otmp->cursed ? -rnd(20) : rnd(20);
  35.              if (u.uhp > u.uhpmax) {
  36.                  if (!rn2(17))
  37.                      u.uhpmax++;
  38.                  u.uhp = u.uhpmax;
  39.              } else if (u.uhp <= 0) {
  40.                  killer.format = KILLED_BY_AN;
  41.                  Strcpy(killer.name, "rotten lump of royal jelly");
  42.                  done(POISONING);
  43.              }
  44.          }
  45.          if (!otmp->cursed)
  46.              heal_legs();
  47.          break;
  48.      case EGG:
  49.          if (flesh_petrifies(&mons[otmp->corpsenm])) {
  50.              if (!Stone_resistance
  51.                  && !(poly_when_stoned(youmonst.data)
  52.                       && polymon(PM_STONE_GOLEM))) {
  53.                  if (!Stoned) {
  54.                      Sprintf(killer.name, "%s egg",
  55.                              mons[otmp->corpsenm].mname);
  56.                      make_stoned(5L, (char *) 0, KILLED_BY_AN, killer.name);
  57.                  }
  58.              }
  59.              /* note: no "tastes like chicken" message for eggs */
  60.          }
  61.          break;
  62.      case EUCALYPTUS_LEAF:
  63.          if (Sick && !otmp->cursed)
  64.              make_sick(0L, (char *) 0, TRUE, SICK_ALL);
  65.          if (Vomiting && !otmp->cursed)
  66.              make_vomiting(0L, TRUE);
  67.          break;
  68.      case APPLE:
  69.          if (otmp->cursed && !Sleep_resistance) {
  70.              /* Snow White; 'poisoned' applies to [a subset of] weapons,
  71.                 not food, so we substitute cursed; fortunately our hero
  72.                 won't have to wait for a prince to be rescued/revived */
  73.              if (Race_if(PM_DWARF) && Hallucination)
  74.                  verbalize("Heigh-ho, ho-hum, I think I'll skip work today.");
  75.              else if (Deaf || !flags.acoustics)
  76.                  You("fall asleep.");
  77.              else
  78.                  You_hear("sinister laughter as you fall asleep...");
  79.              fall_asleep(-rn1(11, 20), TRUE);
  80.          }
  81.          break;
  82.      }
  83.      return;
  84.  }
  85.  

leather_cover

  1.  #if 0
  2.  /* intended for eating a spellbook while polymorphed, but not used;
  3.     "leather" applied to appearance, not composition, and has been
  4.     changed to "leathery" to reflect that */
  5.  STATIC_DCL boolean FDECL(leather_cover, (struct obj *));
  6.  
  7.  STATIC_OVL boolean
  8.  leather_cover(otmp)
  9.  struct obj *otmp;
  10.  {
  11.      const char *odesc = OBJ_DESCR(objects[otmp->otyp]);
  12.  
  13.      if (odesc && (otmp->oclass == SPBOOK_CLASS)) {
  14.          if (!strcmp(odesc, "leather"))
  15.              return TRUE;
  16.      }
  17.      return FALSE;
  18.  }
  19.  #endif
  20.  

edibility_prompts

  1.  /*
  2.   * return 0 if the food was not dangerous.
  3.   * return 1 if the food was dangerous and you chose to stop.
  4.   * return 2 if the food was dangerous and you chose to eat it anyway.
  5.   */
  6.  STATIC_OVL int
  7.  edibility_prompts(otmp)
  8.  struct obj *otmp;
  9.  {
  10.      /* Blessed food detection grants hero a one-use
  11.       * ability to detect food that is unfit for consumption
  12.       * or dangerous and avoid it.
  13.       */
  14.      char buf[BUFSZ], foodsmell[BUFSZ],
  15.           it_or_they[QBUFSZ], eat_it_anyway[QBUFSZ];
  16.      boolean cadaver = (otmp->otyp == CORPSE || otmp->globby),
  17.              stoneorslime = FALSE;
  18.      int material = objects[otmp->otyp].oc_material, mnum = otmp->corpsenm;
  19.      long rotted = 0L;
  20.  
  21.      Strcpy(foodsmell, Tobjnam(otmp, "smell"));
  22.      Strcpy(it_or_they, (otmp->quan == 1L) ? "it" : "they");
  23.      Sprintf(eat_it_anyway, "Eat %s anyway?",
  24.              (otmp->quan == 1L) ? "it" : "one");
  25.  
  26.      if (cadaver || otmp->otyp == EGG || otmp->otyp == TIN) {
  27.          /* These checks must match those in eatcorpse() */
  28.          stoneorslime = (flesh_petrifies(&mons[mnum]) && !Stone_resistance
  29.                          && !poly_when_stoned(youmonst.data));
  30.  
  31.          if (mnum == PM_GREEN_SLIME || otmp->otyp == GLOB_OF_GREEN_SLIME)
  32.              stoneorslime = (!Unchanging && !slimeproof(youmonst.data));
  33.  
  34.          if (cadaver && !nonrotting_corpse(mnum)) {
  35.              long age = peek_at_iced_corpse_age(otmp);
  36.  
  37.              /* worst case rather than random
  38.                 in this calculation to force prompt */
  39.              rotted = (monstermoves - age) / (10L + 0 /* was rn2(20) */);
  40.              if (otmp->cursed)
  41.                  rotted += 2L;
  42.              else if (otmp->blessed)
  43.                  rotted -= 2L;
  44.          }
  45.      }
  46.  
  47.      /*
  48.       * These problems with food should be checked in
  49.       * order from most detrimental to least detrimental.
  50.       */
  51.      if (cadaver && mnum != PM_ACID_BLOB && rotted > 5L && !Sick_resistance) {
  52.          /* Tainted meat */
  53.          Sprintf(buf, "%s like %s could be tainted! %s", foodsmell, it_or_they,
  54.                  eat_it_anyway);
  55.          if (yn_function(buf, ynchars, 'n') == 'n')
  56.              return 1;
  57.          else
  58.              return 2;
  59.      }
  60.      if (stoneorslime) {
  61.          Sprintf(buf, "%s like %s could be something very dangerous! %s",
  62.                  foodsmell, it_or_they, eat_it_anyway);
  63.          if (yn_function(buf, ynchars, 'n') == 'n')
  64.              return 1;
  65.          else
  66.              return 2;
  67.      }
  68.      if (otmp->orotten || (cadaver && rotted > 3L)) {
  69.          /* Rotten */
  70.          Sprintf(buf, "%s like %s could be rotten! %s", foodsmell, it_or_they,
  71.                  eat_it_anyway);
  72.          if (yn_function(buf, ynchars, 'n') == 'n')
  73.              return 1;
  74.          else
  75.              return 2;
  76.      }
  77.      if (cadaver && poisonous(&mons[mnum]) && !Poison_resistance) {
  78.          /* poisonous */
  79.          Sprintf(buf, "%s like %s might be poisonous! %s", foodsmell,
  80.                  it_or_they, eat_it_anyway);
  81.          if (yn_function(buf, ynchars, 'n') == 'n')
  82.              return 1;
  83.          else
  84.              return 2;
  85.      }
  86.      if (otmp->otyp == APPLE && otmp->cursed && !Sleep_resistance) {
  87.          /* causes sleep, for long enough to be dangerous */
  88.          Sprintf(buf, "%s like %s might have been poisoned. %s", foodsmell,
  89.                  it_or_they, eat_it_anyway);
  90.          return (yn_function(buf, ynchars, 'n') == 'n') ? 1 : 2;
  91.      }
  92.      if (cadaver && !vegetarian(&mons[mnum]) && !u.uconduct.unvegetarian
  93.          && Role_if(PM_MONK)) {
  94.          Sprintf(buf, "%s unhealthy. %s", foodsmell, eat_it_anyway);
  95.          if (yn_function(buf, ynchars, 'n') == 'n')
  96.              return 1;
  97.          else
  98.              return 2;
  99.      }
  100.      if (cadaver && acidic(&mons[mnum]) && !Acid_resistance) {
  101.          Sprintf(buf, "%s rather acidic. %s", foodsmell, eat_it_anyway);
  102.          if (yn_function(buf, ynchars, 'n') == 'n')
  103.              return 1;
  104.          else
  105.              return 2;
  106.      }
  107.      if (Upolyd && u.umonnum == PM_RUST_MONSTER && is_metallic(otmp)
  108.          && otmp->oerodeproof) {
  109.          Sprintf(buf, "%s disgusting to you right now. %s", foodsmell,
  110.                  eat_it_anyway);
  111.          if (yn_function(buf, ynchars, 'n') == 'n')
  112.              return 1;
  113.          else
  114.              return 2;
  115.      }
  116.  
  117.      /*
  118.       * Breaks conduct, but otherwise safe.
  119.       */
  120.      if (!u.uconduct.unvegan
  121.          && ((material == LEATHER || material == BONE
  122.               || material == DRAGON_HIDE || material == WAX)
  123.              || (cadaver && !vegan(&mons[mnum])))) {
  124.          Sprintf(buf, "%s foul and unfamiliar to you. %s", foodsmell,
  125.                  eat_it_anyway);
  126.          if (yn_function(buf, ynchars, 'n') == 'n')
  127.              return 1;
  128.          else
  129.              return 2;
  130.      }
  131.      if (!u.uconduct.unvegetarian
  132.          && ((material == LEATHER || material == BONE
  133.               || material == DRAGON_HIDE)
  134.              || (cadaver && !vegetarian(&mons[mnum])))) {
  135.          Sprintf(buf, "%s unfamiliar to you. %s", foodsmell, eat_it_anyway);
  136.          if (yn_function(buf, ynchars, 'n') == 'n')
  137.              return 1;
  138.          else
  139.              return 2;
  140.      }
  141.  
  142.      if (cadaver && mnum != PM_ACID_BLOB && rotted > 5L && Sick_resistance) {
  143.          /* Tainted meat with Sick_resistance */
  144.          Sprintf(buf, "%s like %s could be tainted! %s", foodsmell, it_or_they,
  145.                  eat_it_anyway);
  146.          if (yn_function(buf, ynchars, 'n') == 'n')
  147.              return 1;
  148.          else
  149.              return 2;
  150.      }
  151.      return 0;
  152.  }
  153.  

doeat

  1.  /* 'e' command */
  2.  int
  3.  doeat()
  4.  {
  5.      struct obj *otmp;
  6.      int basenutrit; /* nutrition of full item */
  7.      boolean dont_start = FALSE, nodelicious = FALSE;
  8.  
  9.      if (Strangled) {
  10.          pline("If you can't breathe air, how can you consume solids?");
  11.          return 0;
  12.      }
  13.      if (!(otmp = floorfood("eat", 0)))
  14.          return 0;
  15.      if (check_capacity((char *) 0))
  16.          return 0;
  17.  
  18.      if (u.uedibility) {
  19.          int res = edibility_prompts(otmp);
  20.  
  21.          if (res) {
  22.              Your(
  23.                 "%s stops tingling and your sense of smell returns to normal.",
  24.                   body_part(NOSE));
  25.              u.uedibility = 0;
  26.              if (res == 1)
  27.                  return 0;
  28.          }
  29.      }
  30.  
  31.      /* We have to make non-foods take 1 move to eat, unless we want to
  32.       * do ridiculous amounts of coding to deal with partly eaten plate
  33.       * mails, players who polymorph back to human in the middle of their
  34.       * metallic meal, etc....
  35.       */
  36.      if (!is_edible(otmp)) {
  37.          You("cannot eat that!");
  38.          return 0;
  39.      } else if ((otmp->owornmask & (W_ARMOR | W_TOOL | W_AMUL | W_SADDLE))
  40.                 != 0) {
  41.          /* let them eat rings */
  42.          You_cant("eat %s you're wearing.", something);
  43.          return 0;
  44.      } else if (!(carried(otmp) ? retouch_object(&otmp, FALSE)
  45.                                 : touch_artifact(otmp, &youmonst))) {
  46.          return 1; /* got blasted so use a turn */
  47.      }
  48.      if (is_metallic(otmp) && u.umonnum == PM_RUST_MONSTER
  49.          && otmp->oerodeproof) {
  50.          otmp->rknown = TRUE;
  51.          if (otmp->quan > 1L) {
  52.              if (!carried(otmp))
  53.                  (void) splitobj(otmp, otmp->quan - 1L);
  54.              else
  55.                  otmp = splitobj(otmp, 1L);
  56.          }
  57.          pline("Ulch - that %s was rustproofed!", xname(otmp));
  58.          /* The regurgitated object's rustproofing is gone now */
  59.          otmp->oerodeproof = 0;
  60.          make_stunned((HStun & TIMEOUT) + (long) rn2(10), TRUE);
  61.          /*
  62.           * We don't expect rust monsters to be wielding welded weapons
  63.           * or wearing cursed rings which were rustproofed, but guard
  64.           * against the possibility just in case.
  65.           */
  66.          if (welded(otmp) || (otmp->cursed && (otmp->owornmask & W_RING))) {
  67.              otmp->bknown = 1; /* for ring; welded() does this for weapon */
  68.              You("spit out %s.", the(xname(otmp)));
  69.          } else {
  70.              You("spit %s out onto the %s.", the(xname(otmp)),
  71.                  surface(u.ux, u.uy));
  72.              if (carried(otmp)) {
  73.                  /* no need to check for leash in use; it's not metallic */
  74.                  if (otmp->owornmask)
  75.                      remove_worn_item(otmp, FALSE);
  76.                  freeinv(otmp);
  77.                  dropy(otmp);
  78.              }
  79.              stackobj(otmp);
  80.          }
  81.          return 1;
  82.      }
  83.      /* KMH -- Slow digestion is... indigestible */
  84.      if (otmp->otyp == RIN_SLOW_DIGESTION) {
  85.          pline("This ring is indigestible!");
  86.          (void) rottenfood(otmp);
  87.          if (otmp->dknown && !objects[otmp->otyp].oc_name_known
  88.              && !objects[otmp->otyp].oc_uname)
  89.              docall(otmp);
  90.          return 1;
  91.      }
  92.      if (otmp->oclass != FOOD_CLASS) {
  93.          int material;
  94.  
  95.          context.victual.reqtime = 1;
  96.          context.victual.piece = otmp;
  97.          context.victual.o_id = otmp->o_id;
  98.          /* Don't split it, we don't need to if it's 1 move */
  99.          context.victual.usedtime = 0;
  100.          context.victual.canchoke = (u.uhs == SATIATED);
  101.          /* Note: gold weighs 1 pt. for each 1000 pieces (see
  102.             pickup.c) so gold and non-gold is consistent. */
  103.          if (otmp->oclass == COIN_CLASS)
  104.              basenutrit = ((otmp->quan > 200000L)
  105.                               ? 2000
  106.                               : (int) (otmp->quan / 100L));
  107.          else if (otmp->oclass == BALL_CLASS || otmp->oclass == CHAIN_CLASS)
  108.              basenutrit = weight(otmp);
  109.          /* oc_nutrition is usually weight anyway */
  110.          else
  111.              basenutrit = objects[otmp->otyp].oc_nutrition;
  112.  #ifdef MAIL
  113.          if (otmp->otyp == SCR_MAIL) {
  114.              basenutrit = 0;
  115.              nodelicious = TRUE;
  116.          }
  117.  #endif
  118.          context.victual.nmod = basenutrit;
  119.          context.victual.eating = TRUE; /* needed for lesshungry() */
  120.  
  121.          material = objects[otmp->otyp].oc_material;
  122.          if (material == LEATHER || material == BONE
  123.              || material == DRAGON_HIDE) {
  124.              u.uconduct.unvegan++;
  125.              violated_vegetarian();
  126.          } else if (material == WAX)
  127.              u.uconduct.unvegan++;
  128.          u.uconduct.food++;
  129.  
  130.          if (otmp->cursed) {
  131.              (void) rottenfood(otmp);
  132.              nodelicious = TRUE;
  133.          } else if (objects[otmp->otyp].oc_material == PAPER)
  134.              nodelicious = TRUE;
  135.  
  136.          if (otmp->oclass == WEAPON_CLASS && otmp->opoisoned) {
  137.              pline("Ecch - that must have been poisonous!");
  138.              if (!Poison_resistance) {
  139.                  losestr(rnd(4));
  140.                  losehp(rnd(15), xname(otmp), KILLED_BY_AN);
  141.              } else
  142.                  You("seem unaffected by the poison.");
  143.          } else if (!nodelicious) {
  144.              pline("%s%s is delicious!",
  145.                    (obj_is_pname(otmp)
  146.                     && otmp->oartifact < ART_ORB_OF_DETECTION)
  147.                        ? ""
  148.                        : "This ",
  149.                    (otmp->oclass == COIN_CLASS)
  150.                        ? foodword(otmp)
  151.                        : singular(otmp, xname));
  152.          }
  153.          eatspecial();
  154.          return 1;
  155.      }
  156.  
  157.      if (otmp == context.victual.piece) {
  158.          /* If they weren't able to choke, they don't suddenly become able to
  159.           * choke just because they were interrupted.  On the other hand, if
  160.           * they were able to choke before, if they lost food it's possible
  161.           * they shouldn't be able to choke now.
  162.           */
  163.          if (u.uhs != SATIATED)
  164.              context.victual.canchoke = FALSE;
  165.          context.victual.o_id = 0;
  166.          context.victual.piece = touchfood(otmp);
  167.          if (context.victual.piece)
  168.              context.victual.o_id = context.victual.piece->o_id;
  169.          You("resume your meal.");
  170.          start_eating(context.victual.piece);
  171.          return 1;
  172.      }
  173.  
  174.      /* nothing in progress - so try to find something. */
  175.      /* tins are a special case */
  176.      /* tins must also check conduct separately in case they're discarded */
  177.      if (otmp->otyp == TIN) {
  178.          start_tin(otmp);
  179.          return 1;
  180.      }
  181.  
  182.      /* KMH, conduct */
  183.      u.uconduct.food++;
  184.  
  185.      context.victual.o_id = 0;
  186.      context.victual.piece = otmp = touchfood(otmp);
  187.      if (context.victual.piece)
  188.          context.victual.o_id = context.victual.piece->o_id;
  189.      context.victual.usedtime = 0;
  190.  
  191.      /* Now we need to calculate delay and nutritional info.
  192.       * The base nutrition calculated here and in eatcorpse() accounts
  193.       * for normal vs. rotten food.  The reqtime and nutrit values are
  194.       * then adjusted in accordance with the amount of food left.
  195.       */
  196.      if (otmp->otyp == CORPSE || otmp->globby) {
  197.          int tmp = eatcorpse(otmp);
  198.  
  199.          if (tmp == 2) {
  200.              /* used up */
  201.              context.victual.piece = (struct obj *) 0;
  202.              context.victual.o_id = 0;
  203.              return 1;
  204.          } else if (tmp)
  205.              dont_start = TRUE;
  206.          /* if not used up, eatcorpse sets up reqtime and may modify oeaten */
  207.      } else {
  208.          /* No checks for WAX, LEATHER, BONE, DRAGON_HIDE.  These are
  209.           * all handled in the != FOOD_CLASS case, above.
  210.           */
  211.          switch (objects[otmp->otyp].oc_material) {
  212.          case FLESH:
  213.              u.uconduct.unvegan++;
  214.              if (otmp->otyp != EGG) {
  215.                  violated_vegetarian();
  216.              }
  217.              break;
  218.  
  219.          default:
  220.              if (otmp->otyp == PANCAKE || otmp->otyp == FORTUNE_COOKIE /*eggs*/
  221.                  || otmp->otyp == CREAM_PIE || otmp->otyp == CANDY_BAR /*milk*/
  222.                  || otmp->otyp == LUMP_OF_ROYAL_JELLY)
  223.                  u.uconduct.unvegan++;
  224.              break;
  225.          }
  226.  
  227.          context.victual.reqtime = objects[otmp->otyp].oc_delay;
  228.          if (otmp->otyp != FORTUNE_COOKIE
  229.              && (otmp->cursed || (!nonrotting_food(otmp->otyp)
  230.                                   && (monstermoves - otmp->age)
  231.                                          > (otmp->blessed ? 50L : 30L)
  232.                                   && (otmp->orotten || !rn2(7))))) {
  233.              if (rottenfood(otmp)) {
  234.                  otmp->orotten = TRUE;
  235.                  dont_start = TRUE;
  236.              }
  237.              consume_oeaten(otmp, 1); /* oeaten >>= 1 */
  238.          } else
  239.              fprefx(otmp);
  240.      }
  241.  
  242.      /* re-calc the nutrition */
  243.      basenutrit = (int) obj_nutrition(otmp);
  244.  
  245.      debugpline3(
  246.       "before rounddiv: victual.reqtime == %d, oeaten == %d, basenutrit == %d",
  247.                  context.victual.reqtime, otmp->oeaten, basenutrit);
  248.  
  249.      context.victual.reqtime = (basenutrit == 0) ? 0
  250.          : rounddiv(context.victual.reqtime * (long) otmp->oeaten, basenutrit);
  251.  
  252.      debugpline1("after rounddiv: victual.reqtime == %d",
  253.                  context.victual.reqtime);
  254.      /*
  255.       * calculate the modulo value (nutrit. units per round eating)
  256.       * note: this isn't exact - you actually lose a little nutrition due
  257.       *       to this method.
  258.       * TODO: add in a "remainder" value to be given at the end of the meal.
  259.       */
  260.      if (context.victual.reqtime == 0 || otmp->oeaten == 0)
  261.          /* possible if most has been eaten before */
  262.          context.victual.nmod = 0;
  263.      else if ((int) otmp->oeaten >= context.victual.reqtime)
  264.          context.victual.nmod = -((int) otmp->oeaten
  265.                                   / context.victual.reqtime);
  266.      else
  267.          context.victual.nmod = context.victual.reqtime % otmp->oeaten;
  268.      context.victual.canchoke = (u.uhs == SATIATED);
  269.  
  270.      if (!dont_start)
  271.          start_eating(otmp);
  272.      return 1;
  273.  }
  274.  

use_tin_opener

  1.  int
  2.  use_tin_opener(obj)
  3.  struct obj *obj;
  4.  {
  5.      struct obj *otmp;
  6.      int res = 0;
  7.  
  8.      if (!carrying(TIN)) {
  9.          You("have no tin to open.");
  10.          return 0;
  11.      }
  12.  
  13.      if (obj != uwep) {
  14.          if (obj->cursed && obj->bknown) {
  15.              char qbuf[QBUFSZ];
  16.  
  17.              if (ynq(safe_qbuf(qbuf, "Really wield ", "?",
  18.                                obj, doname, thesimpleoname, "that")) != 'y')
  19.                  return 0;
  20.          }
  21.          if (!wield_tool(obj, "use"))
  22.              return 0;
  23.          res = 1;
  24.      }
  25.  
  26.      otmp = getobj(comestibles, "open");
  27.      if (!otmp)
  28.          return res;
  29.  
  30.      start_tin(otmp);
  31.      return 1;
  32.  }
  33.  

bite

  1.  /* Take a single bite from a piece of food, checking for choking and
  2.   * modifying usedtime.  Returns 1 if they choked and survived, 0 otherwise.
  3.   */
  4.  STATIC_OVL int
  5.  bite()
  6.  {
  7.      if (context.victual.canchoke && u.uhunger >= 2000) {
  8.          choke(context.victual.piece);
  9.          return 1;
  10.      }
  11.      if (context.victual.doreset) {
  12.          do_reset_eat();
  13.          return 0;
  14.      }
  15.      force_save_hs = TRUE;
  16.      if (context.victual.nmod < 0) {
  17.          lesshungry(-context.victual.nmod);
  18.          consume_oeaten(context.victual.piece,
  19.                         context.victual.nmod); /* -= -nmod */
  20.      } else if (context.victual.nmod > 0
  21.                 && (context.victual.usedtime % context.victual.nmod)) {
  22.          lesshungry(1);
  23.          consume_oeaten(context.victual.piece, -1); /* -= 1 */
  24.      }
  25.      force_save_hs = FALSE;
  26.      recalc_wt();
  27.      return 0;
  28.  }
  29.  

gethungry

  1.  /* as time goes by - called by moveloop(every move) & domove(melee attack) */
  2.  void
  3.  gethungry()
  4.  {
  5.      if (u.uinvulnerable)
  6.          return; /* you don't feel hungrier */
  7.  
  8.      /* being polymorphed into a creature which doesn't eat prevents
  9.         this first uhunger decrement, but to stay in such form the hero
  10.         will need to wear an Amulet of Unchanging so still burn a small
  11.         amount of nutrition in the 'moves % 20' ring/amulet check below */
  12.      if ((!Unaware || !rn2(10)) /* slow metabolic rate while asleep */
  13.          && (carnivorous(youmonst.data)
  14.              || herbivorous(youmonst.data)
  15.              || metallivorous(youmonst.data))
  16.          && !Slow_digestion)
  17.          u.uhunger--; /* ordinary food consumption */
  18.  
  19.      if (moves % 2) { /* odd turns */
  20.          /* Regeneration uses up food, unless due to an artifact */
  21.          if ((HRegeneration & ~FROMFORM)
  22.              || (ERegeneration & ~(W_ARTI | W_WEP)))
  23.              u.uhunger--;
  24.          if (near_capacity() > SLT_ENCUMBER)
  25.              u.uhunger--;
  26.      } else { /* even turns */
  27.          if (Hunger)
  28.              u.uhunger--;
  29.          /* Conflict uses up food too */
  30.          if (HConflict || (EConflict & (~W_ARTI)))
  31.              u.uhunger--;
  32.          /* +0 charged rings don't do anything, so don't affect hunger.
  33.             Slow digestion cancels move hunger but still causes ring hunger. */
  34.          switch ((int) (moves % 20)) { /* note: use even cases only */
  35.          case 4:
  36.              if (uleft && (uleft->spe || !objects[uleft->otyp].oc_charged))
  37.                  u.uhunger--;
  38.              break;
  39.          case 8:
  40.              if (uamul)
  41.                  u.uhunger--;
  42.              break;
  43.          case 12:
  44.              if (uright && (uright->spe || !objects[uright->otyp].oc_charged))
  45.                  u.uhunger--;
  46.              break;
  47.          case 16:
  48.              if (u.uhave.amulet)
  49.                  u.uhunger--;
  50.              break;
  51.          default:
  52.              break;
  53.          }
  54.      }
  55.      newuhs(TRUE);
  56.  }
  57.  

morehungry

  1.  /* called after vomiting and after performing feats of magic */
  2.  void
  3.  morehungry(num)
  4.  int num;
  5.  {
  6.      u.uhunger -= num;
  7.      newuhs(TRUE);
  8.  }
  9.  

lesshungry

  1.  /* called after eating (and after drinking fruit juice) */
  2.  void
  3.  lesshungry(num)
  4.  int num;
  5.  {
  6.      /* See comments in newuhs() for discussion on force_save_hs */
  7.      boolean iseating = (occupation == eatfood) || force_save_hs;
  8.  
  9.      debugpline1("lesshungry(%d)", num);
  10.      u.uhunger += num;
  11.      if (u.uhunger >= 2000) {
  12.          if (!iseating || context.victual.canchoke) {
  13.              if (iseating) {
  14.                  choke(context.victual.piece);
  15.                  reset_eat();
  16.              } else
  17.                  choke(occupation == opentin ? context.tin.tin
  18.                                              : (struct obj *) 0);
  19.              /* no reset_eat() */
  20.          }
  21.      } else {
  22.          /* Have lesshungry() report when you're nearly full so all eating
  23.           * warns when you're about to choke.
  24.           */
  25.          if (u.uhunger >= 1500) {
  26.              if (!context.victual.eating
  27.                  || (context.victual.eating && !context.victual.fullwarn)) {
  28.                  pline("You're having a hard time getting all of it down.");
  29.                  nomovemsg = "You're finally finished.";
  30.                  if (!context.victual.eating) {
  31.                      multi = -2;
  32.                  } else {
  33.                      context.victual.fullwarn = TRUE;
  34.                      if (context.victual.canchoke
  35.                          && context.victual.reqtime > 1) {
  36.                          /* a one-gulp food will not survive a stop */
  37.                          if (yn_function("Continue eating?", ynchars, 'n')
  38.                              != 'y') {
  39.                              reset_eat();
  40.                              nomovemsg = (char *) 0;
  41.                          }
  42.                      }
  43.                  }
  44.              }
  45.          }
  46.      }
  47.      newuhs(FALSE);
  48.  }
  49.  

unfaint

  1.  STATIC_PTR
  2.  int
  3.  unfaint(VOID_ARGS)
  4.  {
  5.      (void) Hear_again();
  6.      if (u.uhs > FAINTING)
  7.          u.uhs = FAINTING;
  8.      stop_occupation();
  9.      context.botl = 1;
  10.      return 0;
  11.  }
  12.  

is_fainted

  1.  boolean
  2.  is_fainted()
  3.  {
  4.      return (boolean) (u.uhs == FAINTED);
  5.  }
  6.  

reset_faint

  1.  /* call when a faint must be prematurely terminated */
  2.  void
  3.  reset_faint()
  4.  {
  5.      if (afternmv == unfaint)
  6.          unmul("You revive.");
  7.  }
  8.  

newuhs

  1.  /* compute and comment on your (new?) hunger status */
  2.  void
  3.  newuhs(incr)
  4.  boolean incr;
  5.  {
  6.      unsigned newhs;
  7.      static unsigned save_hs;
  8.      static boolean saved_hs = FALSE;
  9.      int h = u.uhunger;
  10.  
  11.      newhs = (h > 1000)
  12.                  ? SATIATED
  13.                  : (h > 150) ? NOT_HUNGRY
  14.                              : (h > 50) ? HUNGRY : (h > 0) ? WEAK : FAINTING;
  15.  
  16.      /* While you're eating, you may pass from WEAK to HUNGRY to NOT_HUNGRY.
  17.       * This should not produce the message "you only feel hungry now";
  18.       * that message should only appear if HUNGRY is an endpoint.  Therefore
  19.       * we check to see if we're in the middle of eating.  If so, we save
  20.       * the first hunger status, and at the end of eating we decide what
  21.       * message to print based on the _entire_ meal, not on each little bit.
  22.       */
  23.      /* It is normally possible to check if you are in the middle of a meal
  24.       * by checking occupation == eatfood, but there is one special case:
  25.       * start_eating() can call bite() for your first bite before it
  26.       * sets the occupation.
  27.       * Anyone who wants to get that case to work _without_ an ugly static
  28.       * force_save_hs variable, feel free.
  29.       */
  30.      /* Note: If you become a certain hunger status in the middle of the
  31.       * meal, and still have that same status at the end of the meal,
  32.       * this will incorrectly print the associated message at the end of
  33.       * the meal instead of the middle.  Such a case is currently
  34.       * impossible, but could become possible if a message for SATIATED
  35.       * were added or if HUNGRY and WEAK were separated by a big enough
  36.       * gap to fit two bites.
  37.       */
  38.      if (occupation == eatfood || force_save_hs) {
  39.          if (!saved_hs) {
  40.              save_hs = u.uhs;
  41.              saved_hs = TRUE;
  42.          }
  43.          u.uhs = newhs;
  44.          return;
  45.      } else {
  46.          if (saved_hs) {
  47.              u.uhs = save_hs;
  48.              saved_hs = FALSE;
  49.          }
  50.      }
  51.  
  52.      if (newhs == FAINTING) {
  53.          /* u,uhunger is likely to be negative at this point */
  54.          int uhunger_div_by_10 = sgn(u.uhunger) * ((abs(u.uhunger) + 5) / 10);
  55.  
  56.          if (is_fainted())
  57.              newhs = FAINTED;
  58.          if (u.uhs <= WEAK || rn2(20 - uhunger_div_by_10) >= 19) {
  59.              if (!is_fainted() && multi >= 0 /* %% */) {
  60.                  int duration = 10 - uhunger_div_by_10;
  61.  
  62.                  /* stop what you're doing, then faint */
  63.                  stop_occupation();
  64.                  You("faint from lack of food.");
  65.                  incr_itimeout(&HDeaf, duration);
  66.                  context.botl = TRUE;
  67.                  nomul(-duration);
  68.                  multi_reason = "fainted from lack of food";
  69.                  nomovemsg = "You regain consciousness.";
  70.                  afternmv = unfaint;
  71.                  newhs = FAINTED;
  72.                  if (!Levitation)
  73.                      selftouch("Falling, you");
  74.              }
  75.  
  76.          /* this used to be -(200 + 20 * Con) but that was when being asleep
  77.             suppressed per-turn uhunger decrement but being fainted didn't;
  78.             now uhunger becomes more negative at a slower rate */
  79.          } else if (u.uhunger < -(100 + 10 * (int) ACURR(A_CON))) {
  80.              u.uhs = STARVED;
  81.              context.botl = 1;
  82.              bot();
  83.              You("die from starvation.");
  84.              killer.format = KILLED_BY;
  85.              Strcpy(killer.name, "starvation");
  86.              done(STARVING);
  87.              /* if we return, we lifesaved, and that calls newuhs */
  88.              return;
  89.          }
  90.      }
  91.  
  92.      if (newhs != u.uhs) {
  93.          if (newhs >= WEAK && u.uhs < WEAK) {
  94.              /* this used to be losestr(1) which had the potential to
  95.                 be fatal (still handled below) by reducing HP if it
  96.                 tried to take base strength below minimum of 3 */
  97.              ATEMP(A_STR) = -1; /* temporary loss overrides Fixed_abil */
  98.              /* defer context.botl status update until after hunger message */
  99.          } else if (newhs < WEAK && u.uhs >= WEAK) {
  100.              /* this used to be losestr(-1) which could be abused by
  101.                 becoming weak while wearing ring of sustain ability,
  102.                 removing ring, eating to 'restore' strength which boosted
  103.                 strength by a point each time the cycle was performed;
  104.                 substituting "while polymorphed" for sustain ability and
  105.                 "rehumanize" for ring removal might have done that too */
  106.              ATEMP(A_STR) = 0; /* repair of loss also overrides Fixed_abil */
  107.              /* defer context.botl status update until after hunger message */
  108.          }
  109.  
  110.          switch (newhs) {
  111.          case HUNGRY:
  112.              if (Hallucination) {
  113.                  You((!incr) ? "now have a lesser case of the munchies."
  114.                              : "are getting the munchies.");
  115.              } else
  116.                  You((!incr) ? "only feel hungry now."
  117.                              : (u.uhunger < 145)
  118.                                    ? "feel hungry."
  119.                                    : "are beginning to feel hungry.");
  120.              if (incr && occupation
  121.                  && (occupation != eatfood && occupation != opentin))
  122.                  stop_occupation();
  123.              context.travel = context.travel1 = context.mv = context.run = 0;
  124.              break;
  125.          case WEAK:
  126.              if (Hallucination)
  127.                  pline((!incr) ? "You still have the munchies."
  128.                : "The munchies are interfering with your motor capabilities.");
  129.              else if (incr && (Role_if(PM_WIZARD) || Race_if(PM_ELF)
  130.                                || Role_if(PM_VALKYRIE)))
  131.                  pline("%s needs food, badly!",
  132.                        (Role_if(PM_WIZARD) || Role_if(PM_VALKYRIE))
  133.                            ? urole.name.m
  134.                            : "Elf");
  135.              else
  136.                  You((!incr)
  137.                          ? "feel weak now."
  138.                          : (u.uhunger < 45) ? "feel weak."
  139.                                             : "are beginning to feel weak.");
  140.              if (incr && occupation
  141.                  && (occupation != eatfood && occupation != opentin))
  142.                  stop_occupation();
  143.              context.travel = context.travel1 = context.mv = context.run = 0;
  144.              break;
  145.          }
  146.          u.uhs = newhs;
  147.          context.botl = 1;
  148.          bot();
  149.          if ((Upolyd ? u.mh : u.uhp) < 1) {
  150.              You("die from hunger and exhaustion.");
  151.              killer.format = KILLED_BY;
  152.              Strcpy(killer.name, "exhaustion");
  153.              done(STARVING);
  154.              return;
  155.          }
  156.      }
  157.  }
  158.  

floorfood

  1.  /* Returns an object representing food.
  2.   * Object may be either on floor or in inventory.
  3.   */
  4.  struct obj *
  5.  floorfood(verb, corpsecheck)
  6.  const char *verb;
  7.  int corpsecheck; /* 0, no check, 1, corpses, 2, tinnable corpses */
  8.  {
  9.      register struct obj *otmp;
  10.      char qbuf[QBUFSZ];
  11.      char c;
  12.      boolean feeding = !strcmp(verb, "eat"),    /* corpsecheck==0 */
  13.          offering = !strcmp(verb, "sacrifice"); /* corpsecheck==1 */
  14.  
  15.      /* if we can't touch floor objects then use invent food only */
  16.      if (iflags.menu_requested /* command was preceded by 'm' prefix */
  17.          || !can_reach_floor(TRUE) || (feeding && u.usteed)
  18.          || (is_pool_or_lava(u.ux, u.uy)
  19.              && (Wwalking || is_clinger(youmonst.data)
  20.                  || (Flying && !Breathless))))
  21.          goto skipfloor;
  22.  
  23.      if (feeding && metallivorous(youmonst.data)) {
  24.          struct obj *gold;
  25.          struct trap *ttmp = t_at(u.ux, u.uy);
  26.  
  27.          if (ttmp && ttmp->tseen && ttmp->ttyp == BEAR_TRAP) {
  28.              /* If not already stuck in the trap, perhaps there should
  29.                 be a chance to becoming trapped?  Probably not, because
  30.                 then the trap would just get eaten on the _next_ turn... */
  31.              Sprintf(qbuf, "There is a bear trap here (%s); eat it?",
  32.                      (u.utrap && u.utraptype == TT_BEARTRAP) ? "holding you"
  33.                                                              : "armed");
  34.              if ((c = yn_function(qbuf, ynqchars, 'n')) == 'y') {
  35.                  u.utrap = u.utraptype = 0;
  36.                  deltrap(ttmp);
  37.                  return mksobj(BEARTRAP, TRUE, FALSE);
  38.              } else if (c == 'q') {
  39.                  return (struct obj *) 0;
  40.              }
  41.          }
  42.  
  43.          if (youmonst.data != &mons[PM_RUST_MONSTER]
  44.              && (gold = g_at(u.ux, u.uy)) != 0) {
  45.              if (gold->quan == 1L)
  46.                  Sprintf(qbuf, "There is 1 gold piece here; eat it?");
  47.              else
  48.                  Sprintf(qbuf, "There are %ld gold pieces here; eat them?",
  49.                          gold->quan);
  50.              if ((c = yn_function(qbuf, ynqchars, 'n')) == 'y') {
  51.                  return gold;
  52.              } else if (c == 'q') {
  53.                  return (struct obj *) 0;
  54.              }
  55.          }
  56.      }
  57.  
  58.      /* Is there some food (probably a heavy corpse) here on the ground? */
  59.      for (otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere) {
  60.          if (corpsecheck
  61.                  ? (otmp->otyp == CORPSE
  62.                     && (corpsecheck == 1 || tinnable(otmp)))
  63.                  : feeding ? (otmp->oclass != COIN_CLASS && is_edible(otmp))
  64.                            : otmp->oclass == FOOD_CLASS) {
  65.              char qsfx[QBUFSZ];
  66.              boolean one = (otmp->quan == 1L);
  67.  
  68.              /* if blind and without gloves, attempting to eat (or tin or
  69.                 offer) a cockatrice corpse is fatal before asking whether
  70.                 or not to use it; otherwise, 'm<dir>' followed by 'e' could
  71.                 be used to locate cockatrice corpses without touching them */
  72.              if (otmp->otyp == CORPSE && will_feel_cockatrice(otmp, FALSE)) {
  73.                  feel_cockatrice(otmp, FALSE);
  74.                  /* if life-saved (or poly'd into stone golem), terminate
  75.                     attempt to eat off floor */
  76.                  return (struct obj *) 0;
  77.              }
  78.              /* "There is <an object> here; <verb> it?" or
  79.                 "There are <N objects> here; <verb> one?" */
  80.              Sprintf(qbuf, "There %s ", otense(otmp, "are"));
  81.              Sprintf(qsfx, " here; %s %s?", verb, one ? "it" : "one");
  82.              (void) safe_qbuf(qbuf, qbuf, qsfx, otmp, doname, ansimpleoname,
  83.                               one ? something : (const char *) "things");
  84.              if ((c = yn_function(qbuf, ynqchars, 'n')) == 'y')
  85.                  return  otmp;
  86.              else if (c == 'q')
  87.                  return (struct obj *) 0;
  88.          }
  89.      }
  90.  
  91.  skipfloor:
  92.      /* We cannot use ALL_CLASSES since that causes getobj() to skip its
  93.       * "ugly checks" and we need to check for inedible items.
  94.       */
  95.      otmp = getobj(feeding ? allobj : offering ? offerfodder : comestibles,
  96.                    verb);
  97.      if (corpsecheck && otmp && !(offering && otmp->oclass == AMULET_CLASS))
  98.          if (otmp->otyp != CORPSE || (corpsecheck == 2 && !tinnable(otmp))) {
  99.              You_cant("%s that!", verb);
  100.              return (struct obj *) 0;
  101.          }
  102.      return otmp;
  103.  }
  104.  

vomit

  1.  /* Side effects of vomiting */
  2.  /* added nomul (MRS) - it makes sense, you're too busy being sick! */
  3.  void
  4.  vomit() /* A good idea from David Neves */
  5.  {
  6.      if (cantvomit(youmonst.data)) {
  7.          /* doesn't cure food poisoning; message assumes that we aren't
  8.             dealing with some esoteric body_part() */
  9.          Your("jaw gapes convulsively.");
  10.      } else {
  11.          make_sick(0L, (char *) 0, TRUE, SICK_VOMITABLE);
  12.          /* if not enough in stomach to actually vomit then dry heave;
  13.             vomiting_dialog() gives a vomit message when its countdown
  14.             reaches 0, but only if u.uhs < FAINTING (and !cantvomit()) */
  15.          if (u.uhs >= FAINTING)
  16.              Your("%s heaves convulsively!", body_part(STOMACH));
  17.      }
  18.  
  19.      /* nomul()/You_can_move_again used to be unconditional, which was
  20.         viable while eating but not for Vomiting countdown where hero might
  21.         be immobilized for some other reason at the time vomit() is called */
  22.      if (multi >= -2) {
  23.          nomul(-2);
  24.          multi_reason = "vomiting";
  25.          nomovemsg = You_can_move_again;
  26.      }
  27.  }
  28.  

eaten_stat

  1.  int
  2.  eaten_stat(base, obj)
  3.  int base;
  4.  struct obj *obj;
  5.  {
  6.      long uneaten_amt, full_amount;
  7.  
  8.      /* get full_amount first; obj_nutrition() might modify obj->oeaten */
  9.      full_amount = (long) obj_nutrition(obj);
  10.      uneaten_amt = (long) obj->oeaten;
  11.      if (uneaten_amt > full_amount) {
  12.          impossible(
  13.            "partly eaten food (%ld) more nutritious than untouched food (%ld)",
  14.                     uneaten_amt, full_amount);
  15.          uneaten_amt = full_amount;
  16.      }
  17.  
  18.      base = (int) (full_amount ? (long) base * uneaten_amt / full_amount : 0L);
  19.      return (base < 1) ? 1 : base;
  20.  }
  21.  

consume_oeaten

  1.  /* reduce obj's oeaten field, making sure it never hits or passes 0 */
  2.  void
  3.  consume_oeaten(obj, amt)
  4.  struct obj *obj;
  5.  int amt;
  6.  {
  7.      /*
  8.       * This is a hack to try to squelch several long standing mystery
  9.       * food bugs.  A better solution would be to rewrite the entire
  10.       * victual handling mechanism from scratch using a less complex
  11.       * model.  Alternatively, this routine could call done_eating()
  12.       * or food_disappears() but its callers would need revisions to
  13.       * cope with context.victual.piece unexpectedly going away.
  14.       *
  15.       * Multi-turn eating operates by setting the food's oeaten field
  16.       * to its full nutritional value and then running a counter which
  17.       * independently keeps track of whether there is any food left.
  18.       * The oeaten field can reach exactly zero on the last turn, and
  19.       * the object isn't removed from inventory until the next turn
  20.       * when the "you finish eating" message gets delivered, so the
  21.       * food would be restored to the status of untouched during that
  22.       * interval.  This resulted in unexpected encumbrance messages
  23.       * at the end of a meal (if near enough to a threshold) and would
  24.       * yield full food if there was an interruption on the critical
  25.       * turn.  Also, there have been reports over the years of food
  26.       * becoming massively heavy or producing unlimited satiation;
  27.       * this would occur if reducing oeaten via subtraction attempted
  28.       * to drop it below 0 since its unsigned type would produce a
  29.       * huge positive value instead.  So far, no one has figured out
  30.       * _why_ that inappropriate subtraction might sometimes happen.
  31.       */
  32.  
  33.      if (amt > 0) {
  34.          /* bit shift to divide the remaining amount of food */
  35.          obj->oeaten >>= amt;
  36.      } else {
  37.          /* simple decrement; value is negative so we actually add it */
  38.          if ((int) obj->oeaten > -amt)
  39.              obj->oeaten += amt;
  40.          else
  41.              obj->oeaten = 0;
  42.      }
  43.  
  44.      if (obj->oeaten == 0) {
  45.          if (obj == context.victual.piece) /* always true unless wishing... */
  46.              context.victual.reqtime =
  47.                  context.victual.usedtime; /* no bites left */
  48.          obj->oeaten = 1; /* smallest possible positive value */
  49.      }
  50.  }
  51.  

maybe_finished_meal

  1.  /* called when eatfood occupation has been interrupted,
  2.     or in the case of theft, is about to be interrupted */
  3.  boolean
  4.  maybe_finished_meal(stopping)
  5.  boolean stopping;
  6.  {
  7.      /* in case consume_oeaten() has decided that the food is all gone */
  8.      if (occupation == eatfood
  9.          && context.victual.usedtime >= context.victual.reqtime) {
  10.          if (stopping)
  11.              occupation = 0; /* for do_reset_eat */
  12.          (void) eatfood();   /* calls done_eating() to use up
  13.                                 context.victual.piece */
  14.          return TRUE;
  15.      }
  16.      return FALSE;
  17.  }
  18.  

Popeye

  1.  /* Tin of <something> to the rescue?  Decide whether current occupation
  2.     is an attempt to eat a tin of something capable of saving hero's life.
  3.     We don't care about consumption of non-tinned food here because special
  4.     effects there take place on first bite rather than at end of occupation.
  5.     [Popeye the Sailor gets out of trouble by eating tins of spinach. :-] */
  6.  boolean
  7.  Popeye(threat)
  8.  int threat;
  9.  {
  10.      struct obj *otin;
  11.      int mndx;
  12.  
  13.      if (occupation != opentin)
  14.          return FALSE;
  15.      otin = context.tin.tin;
  16.      /* make sure hero still has access to tin */
  17.      if (!carried(otin)
  18.          && (!obj_here(otin, u.ux, u.uy) || !can_reach_floor(TRUE)))
  19.          return FALSE;
  20.      /* unknown tin is assumed to be helpful */
  21.      if (!otin->known)
  22.          return TRUE;
  23.      /* known tin is helpful if it will stop life-threatening problem */
  24.      mndx = otin->corpsenm;
  25.      switch (threat) {
  26.      /* note: not used; hunger code bypasses stop_occupation() when eating */
  27.      case HUNGER:
  28.          return (boolean) (mndx != NON_PM || otin->spe == 1);
  29.      /* flesh from lizards and acidic critters stops petrification */
  30.      case STONED:
  31.          return (boolean) (mndx >= LOW_PM
  32.                            && (mndx == PM_LIZARD || acidic(&mons[mndx])));
  33.      /* no tins can cure these (yet?) */
  34.      case SLIMED:
  35.      case SICK:
  36.      case VOMITING:
  37.          break;
  38.      default:
  39.          break;
  40.      }
  41.      return FALSE;
  42.  }
  43.  
  44.  /*eat.c*/