Source:NetHack 3.6.0/src/eat.c

From NetHackWiki
Jump to: navigation, search

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

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

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

Top of file[edit]

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

is_edible[edit]

  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.      if (u.umonnum == PM_GELATINOUS_CUBE && is_organic(obj)
  21.          /* [g.cubes can eat containers and retain all contents
  22.              as engulfed items, but poly'd player can't do that] */
  23.          && !Has_contents(obj))
  24.          return TRUE;
  25.  
  26.      /* return (boolean) !!index(comestibles, obj->oclass); */
  27.      return (boolean) (obj->oclass == FOOD_CLASS);
  28.  }
  29.  

init_uhunger[edit]

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


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

eatmupdate[edit]

  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[edit]

  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[edit]

  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[edit]

  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[edit]

  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.  

touchfood[edit]

  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 =
  16.              (otmp->otyp == CORPSE ? mons[otmp->corpsenm].cnutrit
  17.                                    : objects[otmp->otyp].oc_nutrition);
  18.      }
  19.  
  20.      if (carried(otmp)) {
  21.          freeinv(otmp);
  22.          if (inv_cnt(FALSE) >= 52) {
  23.              sellobj_state(SELL_DONTSELL);
  24.              dropy(otmp);
  25.              sellobj_state(SELL_NORMAL);
  26.          } else {
  27.              otmp->nomerge = 1; /* used to prevent merge */
  28.              otmp = addinv(otmp);
  29.              otmp->nomerge = 0;
  30.          }
  31.      }
  32.      return otmp;
  33.  }
  34.  

food_disappears[edit]

  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[edit]

  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[edit]

  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[edit]

  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[edit]

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

eating_conducts[edit]

  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[edit]

  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)
  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)
  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 is 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)
  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)
  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[edit]

  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) || (Upolyd && same_race(youmonst.data, fptr)))) {
  23.          if (allowmsg) {
  24.              if (Upolyd && your_race(fptr))
  25.                  You("have a bad feeling deep inside.");
  26.              You("cannibal!  You will regret this!");
  27.          }
  28.          HAggravate_monster |= FROMOUTSIDE;
  29.          change_luck(-rn1(4, 2)); /* -5..-2 */
  30.          return TRUE;
  31.      }
  32.      return FALSE;
  33.  }
  34.  

cprefx[edit]

  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[edit]

  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.  

intrinsic_possible[edit]

  1.  /*
  2.   * If you add an intrinsic that can be gotten by eating a monster, add it
  3.   * to intrinsic_possible() and givit().  (It must already be in prop.h to
  4.   * be an intrinsic property.)
  5.   * It would be very easy to make the intrinsics not try to give you one
  6.   * that you already had by checking to see if you have it in
  7.   * intrinsic_possible() instead of givit(), but we're not that nice.
  8.   */
  9.  
  10.  /* intrinsic_possible() returns TRUE iff a monster can give an intrinsic. */
  11.  STATIC_OVL int
  12.  intrinsic_possible(type, ptr)
  13.  int type;
  14.  register struct permonst *ptr;
  15.  {
  16.      int res = 0;
  17.  
  18.  #ifdef DEBUG
  19.  #define ifdebugresist(Msg)      \
  20.      do {                        \
  21.          if (res)                \
  22.              debugpline0(Msg);   \
  23.      } while (0)
  24.  #else
  25.  #define ifdebugresist(Msg) /*empty*/
  26.  #endif
  27.      switch (type) {
  28.      case FIRE_RES:
  29.          res = (ptr->mconveys & MR_FIRE) != 0;
  30.          ifdebugresist("can get fire resistance");
  31.          break;
  32.      case SLEEP_RES:
  33.          res = (ptr->mconveys & MR_SLEEP) != 0;
  34.          ifdebugresist("can get sleep resistance");
  35.          break;
  36.      case COLD_RES:
  37.          res = (ptr->mconveys & MR_COLD) != 0;
  38.          ifdebugresist("can get cold resistance");
  39.          break;
  40.      case DISINT_RES:
  41.          res = (ptr->mconveys & MR_DISINT) != 0;
  42.          ifdebugresist("can get disintegration resistance");
  43.          break;
  44.      case SHOCK_RES: /* shock (electricity) resistance */
  45.          res = (ptr->mconveys & MR_ELEC) != 0;
  46.          ifdebugresist("can get shock resistance");
  47.          break;
  48.      case POISON_RES:
  49.          res = (ptr->mconveys & MR_POISON) != 0;
  50.          ifdebugresist("can get poison resistance");
  51.          break;
  52.      case TELEPORT:
  53.          res = can_teleport(ptr);
  54.          ifdebugresist("can get teleport");
  55.          break;
  56.      case TELEPORT_CONTROL:
  57.          res = control_teleport(ptr);
  58.          ifdebugresist("can get teleport control");
  59.          break;
  60.      case TELEPAT:
  61.          res = telepathic(ptr);
  62.          ifdebugresist("can get telepathy");
  63.          break;
  64.      default:
  65.          /* res stays 0 */
  66.          break;
  67.      }
  68.  #undef ifdebugresist
  69.      return res;
  70.  }
  71.  

givit[edit]

  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[edit]

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

violated_vegetarian[edit]

  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[edit]

  1.  /* common code to check and possibly charge for 1 context.tin.tin,
  2.   * will split() context.tin.tin if necessary */
  3.  STATIC_PTR void
  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.  }
  18.  

tin_variety_txt[edit]

  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[edit]

  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[edit]

  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[edit]

  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[edit]

  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.          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.              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.              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.          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.              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
  106.              .food++; /* don't need vegan/vegetarian checks for spinach */
  107.          if (!tin->cursed)
  108.              pline("This makes you feel like %s!",
  109.                    Hallucination ? "Swee'pea" : "Popeye");
  110.          gainstr(tin, 0, FALSE);
  111.  
  112.          costly_tin(COST_OPEN);
  113.  
  114.          lesshungry(tin->blessed
  115.                        ? 600                   /* blessed */
  116.                        : !tin->cursed
  117.                           ? (400 + rnd(200))   /* uncursed */
  118.                           : (200 + rnd(400))); /* cursed */
  119.      }
  120.  
  121.  use_up_tin:
  122.      if (carried(tin))
  123.          useup(tin);
  124.      else
  125.          useupf(tin, 1L);
  126.      context.tin.tin = (struct obj *) 0;
  127.      context.tin.o_id = 0;
  128.  }
  129.  

opentin[edit]

  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[edit]

  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 CRYSKNIFE:
  38.              tmp = 3;
  39.              break;
  40.          case PICK_AXE:
  41.          case AXE:
  42.              tmp = 6;
  43.              break;
  44.          default:
  45.              goto no_opener;
  46.          }
  47.          pline("Using %s you try to open the tin.", yobjnam(uwep, (char *) 0));
  48.      } else {
  49.      no_opener:
  50.          pline("It is not so easy to open this tin.");
  51.          if (Glib) {
  52.              pline_The("tin slips from your %s.",
  53.                        makeplural(body_part(FINGER)));
  54.              if (otmp->quan > 1L) {
  55.                  otmp = splitobj(otmp, 1L);
  56.              }
  57.              if (carried(otmp))
  58.                  dropx(otmp);
  59.              else
  60.                  stackobj(otmp);
  61.              return;
  62.          }
  63.          tmp = rn1(1 + 500 / ((int) (ACURR(A_DEX) + ACURRSTR)), 10);
  64.      }
  65.  
  66.      context.tin.tin = otmp;
  67.      context.tin.o_id = otmp->o_id;
  68.      if (!tmp) {
  69.          consume_tin(mesg); /* begin immediately */
  70.      } else {
  71.          context.tin.reqtime = tmp;
  72.          context.tin.usedtime = 0;
  73.          set_occupation(opentin, "opening the tin", 0);
  74.      }
  75.      return;
  76.  }
  77.  

Hear_again[edit]

  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.      return 0;
  9.  }
  10.  

rottenfood[edit]

  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.          make_blinded((long) d(2, 10), FALSE);
  16.          if (!Blind)
  17.              Your1(vision_clears);
  18.      } else if (!rn2(3)) {
  19.          const char *what, *where;
  20.          int duration = rnd(10);
  21.  
  22.          if (!Blind)
  23.              what = "goes", where = "dark";
  24.          else if (Levitation || Is_airlevel(&u.uz) || Is_waterlevel(&u.uz))
  25.              what = "you lose control of", where = "yourself";
  26.          else
  27.              what = "you slap against the",
  28.              where = (u.usteed) ? "saddle" : surface(u.ux, u.uy);
  29.          pline_The("world spins and %s %s.", what, where);
  30.          incr_itimeout(&HDeaf, duration);
  31.          nomul(-duration);
  32.          multi_reason = "unconscious from rotten food";
  33.          nomovemsg = "You are conscious again.";
  34.          afternmv = Hear_again;
  35.          return 1;
  36.      }
  37.      return 0;
  38.  }
  39.  

eatcorpse[edit]

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

start_eating[edit]

  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: %lx (victual = %lx)", (unsigned long) otmp,
  9.                  (unsigned long) context.victual.piece);
  10.      debugpline1("reqtime = %d", context.victual.reqtime);
  11.      debugpline1("(original reqtime = %d)", objects[otmp->otyp].oc_delay);
  12.      debugpline1("nmod = %d", context.victual.nmod);
  13.      debugpline1("oeaten = %d", otmp->oeaten);
  14.      context.victual.fullwarn = context.victual.doreset = FALSE;
  15.      context.victual.eating = TRUE;
  16.  
  17.      if (otmp->otyp == CORPSE || otmp->globby) {
  18.          cprefx(context.victual.piece->corpsenm);
  19.          if (!context.victual.piece || !context.victual.eating) {
  20.              /* rider revived, or died and lifesaved */
  21.              return;
  22.          }
  23.      }
  24.  
  25.      old_nomovemsg = nomovemsg;
  26.      if (bite()) {
  27.          /* survived choking, finish off food that's nearly done;
  28.             need this to handle cockatrice eggs, fortune cookies, etc */
  29.          if (++context.victual.usedtime >= context.victual.reqtime) {
  30.              /* don't want done_eating() to issue nomovemsg if it
  31.                 is due to vomit() called by bite() */
  32.              save_nomovemsg = nomovemsg;
  33.              if (!old_nomovemsg)
  34.                  nomovemsg = 0;
  35.              done_eating(FALSE);
  36.              if (!old_nomovemsg)
  37.                  nomovemsg = save_nomovemsg;
  38.          }
  39.          return;
  40.      }
  41.  
  42.      if (++context.victual.usedtime >= context.victual.reqtime) {
  43.          /* print "finish eating" message if they just resumed -dlc */
  44.          done_eating(context.victual.reqtime > 1 ? TRUE : FALSE);
  45.          return;
  46.      }
  47.  
  48.      Sprintf(msgbuf, "eating %s", food_xname(otmp, TRUE));
  49.      set_occupation(eatfood, msgbuf, 0);
  50.  }
  51.  

fprefx[edit]

  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 MEATBALL:
  34.      case MEAT_STICK:
  35.      case HUGE_CHUNK_OF_MEAT:
  36.      case MEAT_RING:
  37.          goto give_feedback;
  38.      case CLOVE_OF_GARLIC:
  39.          if (is_undead(youmonst.data)) {
  40.              make_vomiting((long) rn1(context.victual.reqtime, 5), FALSE);
  41.              break;
  42.          }
  43.          /* else FALLTHRU */
  44.      default:
  45.          if (otmp->otyp == SLIME_MOLD && !otmp->cursed
  46.              && otmp->spe == context.current_fruit) {
  47.              pline("My, that was a %s %s!",
  48.                    Hallucination ? "primo" : "yummy",
  49.                    singular(otmp, xname));
  50.          } else if (otmp->otyp == APPLE && otmp->cursed && !Sleep_resistance) {
  51.              ; /* skip core joke; feedback deferred til fpostfx() */
  52.  
  53.  #if defined(MAC) || defined(MACOSX)
  54.          /* KMH -- Why should Unix have all the fun?
  55.             We check MACOSX before UNIX to get the Apple-specific apple
  56.             message; the '#if UNIX' code will still kick in for pear. */
  57.          } else if (otmp->otyp == APPLE) {
  58.              pline("Delicious!  Must be a Macintosh!");
  59.  #endif
  60.  
  61.  #ifdef UNIX
  62.          } else if (otmp->otyp == APPLE || otmp->otyp == PEAR) {
  63.              if (!Hallucination) {
  64.                  pline("Core dumped.");
  65.              } else {
  66.                  /* This is based on an old Usenet joke, a fake a.out manual
  67.                   * page
  68.                   */
  69.                  int x = rnd(100);
  70.  
  71.                  pline("%s -- core dumped.",
  72.                        (x <= 75)
  73.                           ? "Segmentation fault"
  74.                           : (x <= 99)
  75.                              ? "Bus error"
  76.                              : "Yo' mama");
  77.              }
  78.  #endif
  79.          } else if (otmp->otyp == EGG && stale_egg(otmp)) {
  80.              pline("Ugh.  Rotten egg."); /* perhaps others like it */
  81.              make_vomiting((Vomiting & TIMEOUT) + (long) d(10, 4), TRUE);
  82.          } else {
  83.          give_feedback:
  84.              pline("This %s is %s", singular(otmp, xname),
  85.                    otmp->cursed
  86.                       ? (Hallucination ? "grody!" : "terrible!")
  87.                       : (otmp->otyp == CRAM_RATION
  88.                          || otmp->otyp == K_RATION
  89.                          || otmp->otyp == C_RATION)
  90.                          ? "bland."
  91.                          : Hallucination ? "gnarly!" : "delicious!");
  92.          }
  93.          break; /* default */
  94.      } /* switch */
  95.  }
  96.  

bounded_increase[edit]

  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[edit]

  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[edit]

  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[edit]

  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.  #ifdef MAIL
  23.      if (otmp->otyp == SCR_MAIL) {
  24.          /* no nutrition */
  25.          pline("This junk mail is less than satisfying.");
  26.      }
  27.  #endif
  28.      if (otmp->oclass == POTION_CLASS) {
  29.          otmp->quan++; /* dopotion() does a useup() */
  30.          (void) dopotion(otmp);
  31.      } else if (otmp->oclass == RING_CLASS || otmp->oclass == AMULET_CLASS) {
  32.          eataccessory(otmp);
  33.      } else if (otmp->otyp == LEASH && otmp->leashmon) {
  34.          o_unleash(otmp);
  35.      }
  36.  
  37.      /* KMH -- idea by "Tommy the Terrorist" */
  38.      if (otmp->otyp == TRIDENT && !otmp->cursed) {
  39.          /* sugarless chewing gum which used to be heavily advertised on TV */
  40.          pline(Hallucination ? "Four out of five dentists agree."
  41.                              : "That was pure chewing satisfaction!");
  42.          exercise(A_WIS, TRUE);
  43.      }
  44.      if (otmp->otyp == FLINT && !otmp->cursed) {
  45.          /* chewable vitamin for kids based on "The Flintstones" TV cartoon */
  46.          pline("Yabba-dabba delicious!");
  47.          exercise(A_CON, TRUE);
  48.      }
  49.  
  50.      if (otmp == uwep && otmp->quan == 1L)
  51.          uwepgone();
  52.      if (otmp == uquiver && otmp->quan == 1L)
  53.          uqwepgone();
  54.      if (otmp == uswapwep && otmp->quan == 1L)
  55.          uswapwepgone();
  56.  
  57.      if (otmp == uball)
  58.          unpunish();
  59.      if (otmp == uchain)
  60.          unpunish(); /* but no useup() */
  61.      else if (carried(otmp))
  62.          useup(otmp);
  63.      else
  64.          useupf(otmp, 1L);
  65.  }
  66.  

foodword[edit]

  1.  /* NOTE: the order of these words exactly corresponds to the
  2.     order of oc_material values #define'd in objclass.h. */
  3.  static const char *foodwords[] = {
  4.      "meal",    "liquid",  "wax",       "food", "meat",     "paper",
  5.      "cloth",   "leather", "wood",      "bone", "scale",    "metal",
  6.      "metal",   "metal",   "silver",    "gold", "platinum", "mithril",
  7.      "plastic", "glass",   "rich food", "stone"
  8.  };
  9.  
  10.  STATIC_OVL const char *
  11.  foodword(otmp)
  12.  struct obj *otmp;
  13.  {
  14.      if (otmp->oclass == FOOD_CLASS)
  15.          return "food";
  16.      if (otmp->oclass == GEM_CLASS && objects[otmp->otyp].oc_material == GLASS
  17.          && otmp->dknown)
  18.          makeknown(otmp->otyp);
  19.      return foodwords[objects[otmp->otyp].oc_material];
  20.  }
  21.  

fpostfx[edit]

  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[edit]

  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[edit]

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

doeat[edit]

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

bite[edit]

  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[edit]

  1.  /* as time goes by - called by moveloop() and domove() */
  2.  void
  3.  gethungry()
  4.  {
  5.      if (u.uinvulnerable)
  6.          return; /* you don't feel hungrier */
  7.  
  8.      if ((!u.usleep || !rn2(10)) /* slow metabolic rate while asleep */
  9.          && (carnivorous(youmonst.data) || herbivorous(youmonst.data))
  10.          && !Slow_digestion)
  11.          u.uhunger--; /* ordinary food consumption */
  12.  
  13.      if (moves % 2) { /* odd turns */
  14.          /* Regeneration uses up food, unless due to an artifact */
  15.          if ((HRegeneration & ~FROMFORM)
  16.              || (ERegeneration & ~(W_ARTI | W_WEP)))
  17.              u.uhunger--;
  18.          if (near_capacity() > SLT_ENCUMBER)
  19.              u.uhunger--;
  20.      } else { /* even turns */
  21.          if (Hunger)
  22.              u.uhunger--;
  23.          /* Conflict uses up food too */
  24.          if (HConflict || (EConflict & (~W_ARTI)))
  25.              u.uhunger--;
  26.          /* +0 charged rings don't do anything, so don't affect hunger */
  27.          /* Slow digestion still uses ring hunger */
  28.          switch ((int) (moves % 20)) { /* note: use even cases only */
  29.          case 4:
  30.              if (uleft && (uleft->spe || !objects[uleft->otyp].oc_charged))
  31.                  u.uhunger--;
  32.              break;
  33.          case 8:
  34.              if (uamul)
  35.                  u.uhunger--;
  36.              break;
  37.          case 12:
  38.              if (uright && (uright->spe || !objects[uright->otyp].oc_charged))
  39.                  u.uhunger--;
  40.              break;
  41.          case 16:
  42.              if (u.uhave.amulet)
  43.                  u.uhunger--;
  44.              break;
  45.          default:
  46.              break;
  47.          }
  48.      }
  49.      newuhs(TRUE);
  50.  }
  51.  

morehungry[edit]

  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[edit]

  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[edit]

  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[edit]

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

reset_faint[edit]

  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[edit]

  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.          if (is_fainted())
  54.              newhs = FAINTED;
  55.          if (u.uhs <= WEAK || rn2(20 - u.uhunger / 10) >= 19) {
  56.              if (!is_fainted() && multi >= 0 /* %% */) {
  57.                  int duration = 10 - (u.uhunger / 10);
  58.  
  59.                  /* stop what you're doing, then faint */
  60.                  stop_occupation();
  61.                  You("faint from lack of food.");
  62.                  if (!Levitation)
  63.                      selftouch("Falling, you");
  64.                  incr_itimeout(&HDeaf, duration);
  65.                  nomul(-duration);
  66.                  multi_reason = "fainted from lack of food";
  67.                  nomovemsg = "You regain consciousness.";
  68.                  afternmv = unfaint;
  69.                  newhs = FAINTED;
  70.              }
  71.          } else if (u.uhunger < -(int) (200 + 20 * ACURR(A_CON))) {
  72.              u.uhs = STARVED;
  73.              context.botl = 1;
  74.              bot();
  75.              You("die from starvation.");
  76.              killer.format = KILLED_BY;
  77.              Strcpy(killer.name, "starvation");
  78.              done(STARVING);
  79.              /* if we return, we lifesaved, and that calls newuhs */
  80.              return;
  81.          }
  82.      }
  83.  
  84.      if (newhs != u.uhs) {
  85.          if (newhs >= WEAK && u.uhs < WEAK)
  86.              losestr(1); /* this may kill you -- see below */
  87.          else if (newhs < WEAK && u.uhs >= WEAK)
  88.              losestr(-1);
  89.          switch (newhs) {
  90.          case HUNGRY:
  91.              if (Hallucination) {
  92.                  You((!incr) ? "now have a lesser case of the munchies."
  93.                              : "are getting the munchies.");
  94.              } else
  95.                  You((!incr) ? "only feel hungry now."
  96.                              : (u.uhunger < 145)
  97.                                    ? "feel hungry."
  98.                                    : "are beginning to feel hungry.");
  99.              if (incr && occupation
  100.                  && (occupation != eatfood && occupation != opentin))
  101.                  stop_occupation();
  102.              context.travel = context.travel1 = context.mv = context.run = 0;
  103.              break;
  104.          case WEAK:
  105.              if (Hallucination)
  106.                  pline((!incr) ? "You still have the munchies."
  107.                : "The munchies are interfering with your motor capabilities.");
  108.              else if (incr && (Role_if(PM_WIZARD) || Race_if(PM_ELF)
  109.                                || Role_if(PM_VALKYRIE)))
  110.                  pline("%s needs food, badly!",
  111.                        (Role_if(PM_WIZARD) || Role_if(PM_VALKYRIE))
  112.                            ? urole.name.m
  113.                            : "Elf");
  114.              else
  115.                  You((!incr)
  116.                          ? "feel weak now."
  117.                          : (u.uhunger < 45) ? "feel weak."
  118.                                             : "are beginning to feel weak.");
  119.              if (incr && occupation
  120.                  && (occupation != eatfood && occupation != opentin))
  121.                  stop_occupation();
  122.              context.travel = context.travel1 = context.mv = context.run = 0;
  123.              break;
  124.          }
  125.          u.uhs = newhs;
  126.          context.botl = 1;
  127.          bot();
  128.          if ((Upolyd ? u.mh : u.uhp) < 1) {
  129.              You("die from hunger and exhaustion.");
  130.              killer.format = KILLED_BY;
  131.              Strcpy(killer.name, "exhaustion");
  132.              done(STARVING);
  133.              return;
  134.          }
  135.      }
  136.  }
  137.  

floorfood[edit]

  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 (!can_reach_floor(TRUE) || (feeding && u.usteed)
  17.          || (is_pool_or_lava(u.ux, u.uy)
  18.              && (Wwalking || is_clinger(youmonst.data)
  19.                  || (Flying && !Breathless))))
  20.          goto skipfloor;
  21.  
  22.      if (feeding && metallivorous(youmonst.data)) {
  23.          struct obj *gold;
  24.          struct trap *ttmp = t_at(u.ux, u.uy);
  25.  
  26.          if (ttmp && ttmp->tseen && ttmp->ttyp == BEAR_TRAP) {
  27.              /* If not already stuck in the trap, perhaps there should
  28.                 be a chance to becoming trapped?  Probably not, because
  29.                 then the trap would just get eaten on the _next_ turn... */
  30.              Sprintf(qbuf, "There is a bear trap here (%s); eat it?",
  31.                      (u.utrap && u.utraptype == TT_BEARTRAP) ? "holding you"
  32.                                                              : "armed");
  33.              if ((c = yn_function(qbuf, ynqchars, 'n')) == 'y') {
  34.                  u.utrap = u.utraptype = 0;
  35.                  deltrap(ttmp);
  36.                  return mksobj(BEARTRAP, TRUE, FALSE);
  37.              } else if (c == 'q') {
  38.                  return (struct obj *) 0;
  39.              }
  40.          }
  41.  
  42.          if (youmonst.data != &mons[PM_RUST_MONSTER]
  43.              && (gold = g_at(u.ux, u.uy)) != 0) {
  44.              if (gold->quan == 1L)
  45.                  Sprintf(qbuf, "There is 1 gold piece here; eat it?");
  46.              else
  47.                  Sprintf(qbuf, "There are %ld gold pieces here; eat them?",
  48.                          gold->quan);
  49.              if ((c = yn_function(qbuf, ynqchars, 'n')) == 'y') {
  50.                  return gold;
  51.              } else if (c == 'q') {
  52.                  return (struct obj *) 0;
  53.              }
  54.          }
  55.      }
  56.  
  57.      /* Is there some food (probably a heavy corpse) here on the ground? */
  58.      for (otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere) {
  59.          if (corpsecheck
  60.                  ? (otmp->otyp == CORPSE
  61.                     && (corpsecheck == 1 || tinnable(otmp)))
  62.                  : feeding ? (otmp->oclass != COIN_CLASS && is_edible(otmp))
  63.                            : otmp->oclass == FOOD_CLASS) {
  64.              char qsfx[QBUFSZ];
  65.              boolean one = (otmp->quan == 1L);
  66.  
  67.              /* "There is <an object> here; <verb> it?" or
  68.                 "There are <N objects> here; <verb> one?" */
  69.              Sprintf(qbuf, "There %s ", otense(otmp, "are"));
  70.              Sprintf(qsfx, " here; %s %s?", verb, one ? "it" : "one");
  71.              (void) safe_qbuf(qbuf, qbuf, qsfx, otmp, doname, ansimpleoname,
  72.                               one ? something : (const char *) "things");
  73.              if ((c = yn_function(qbuf, ynqchars, 'n')) == 'y')
  74.                  return  otmp;
  75.              else if (c == 'q')
  76.                  return (struct obj *) 0;
  77.          }
  78.      }
  79.  
  80.  skipfloor:
  81.      /* We cannot use ALL_CLASSES since that causes getobj() to skip its
  82.       * "ugly checks" and we need to check for inedible items.
  83.       */
  84.      otmp =
  85.          getobj(feeding ? allobj : offering ? offerfodder : comestibles, verb);
  86.      if (corpsecheck && otmp && !(offering && otmp->oclass == AMULET_CLASS))
  87.          if (otmp->otyp != CORPSE || (corpsecheck == 2 && !tinnable(otmp))) {
  88.              You_cant("%s that!", verb);
  89.              return (struct obj *) 0;
  90.          }
  91.      return otmp;
  92.  }
  93.  

vomit[edit]

  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.      nomul(-2);
  13.      multi_reason = "vomiting";
  14.      nomovemsg = You_can_move_again;
  15.  }
  16.  

eaten_stat[edit]

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

consume_oeaten[edit]

  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[edit]

  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[edit]

  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*/