Source:NetHack 3.6.0/src/potion.c

From NetHackWiki
(Redirected from Source:Potion.c)
Jump to: navigation, search

Below is the full text to potion.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/potion.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

  1.  /* NetHack 3.6	potion.c	$NHDT-Date: 1446861768 2015/11/07 02:02:48 $  $NHDT-Branch: master $:$NHDT-Revision: 1.121 $ */
  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.  boolean notonhead = FALSE;
  8.  
  9.  static NEARDATA int nothing, unkn;
  10.  static NEARDATA const char beverages[] = { POTION_CLASS, 0 };
  11.  
  12.  STATIC_DCL long FDECL(itimeout, (long));
  13.  STATIC_DCL long FDECL(itimeout_incr, (long, int));
  14.  STATIC_DCL void NDECL(ghost_from_bottle);
  15.  STATIC_DCL boolean
  16.  FDECL(H2Opotion_dip, (struct obj *, struct obj *, BOOLEAN_P, const char *));
  17.  STATIC_DCL short FDECL(mixtype, (struct obj *, struct obj *));
  18.  

itimeout

  1.  /* force `val' to be within valid range for intrinsic timeout value */
  2.  STATIC_OVL long
  3.  itimeout(val)
  4.  long val;
  5.  {
  6.      if (val >= TIMEOUT)
  7.          val = TIMEOUT;
  8.      else if (val < 1)
  9.          val = 0;
  10.  
  11.      return val;
  12.  }
  13.  

itimeout_incr

  1.  /* increment `old' by `incr' and force result to be valid intrinsic timeout */
  2.  STATIC_OVL long
  3.  itimeout_incr(old, incr)
  4.  long old;
  5.  int incr;
  6.  {
  7.      return itimeout((old & TIMEOUT) + (long) incr);
  8.  }
  9.  

set_itimeout

  1.  /* set the timeout field of intrinsic `which' */
  2.  void
  3.  set_itimeout(which, val)
  4.  long *which, val;
  5.  {
  6.      *which &= ~TIMEOUT;
  7.      *which |= itimeout(val);
  8.  }
  9.  

incr_itimeout

  1.  /* increment the timeout field of intrinsic `which' */
  2.  void
  3.  incr_itimeout(which, incr)
  4.  long *which;
  5.  int incr;
  6.  {
  7.      set_itimeout(which, itimeout_incr(*which, incr));
  8.  }
  9.  

make_confused

  1.  void
  2.  make_confused(xtime, talk)
  3.  long xtime;
  4.  boolean talk;
  5.  {
  6.      long old = HConfusion;
  7.  
  8.      if (Unaware)
  9.          talk = FALSE;
  10.  
  11.      if (!xtime && old) {
  12.          if (talk)
  13.              You_feel("less %s now.", Hallucination ? "trippy" : "confused");
  14.      }
  15.      if ((xtime && !old) || (!xtime && old))
  16.          context.botl = TRUE;
  17.  
  18.      set_itimeout(&HConfusion, xtime);
  19.  }
  20.  

make_stunned

  1.  void
  2.  make_stunned(xtime, talk)
  3.  long xtime;
  4.  boolean talk;
  5.  {
  6.      long old = HStun;
  7.  
  8.      if (Unaware)
  9.          talk = FALSE;
  10.  
  11.      if (!xtime && old) {
  12.          if (talk)
  13.              You_feel("%s now.",
  14.                       Hallucination ? "less wobbly" : "a bit steadier");
  15.      }
  16.      if (xtime && !old) {
  17.          if (talk) {
  18.              if (u.usteed)
  19.                  You("wobble in the saddle.");
  20.              else
  21.                  You("%s...", stagger(youmonst.data, "stagger"));
  22.          }
  23.      }
  24.      if ((!xtime && old) || (xtime && !old))
  25.          context.botl = TRUE;
  26.  
  27.      set_itimeout(&HStun, xtime);
  28.  }
  29.  

make_sick

  1.  void
  2.  make_sick(xtime, cause, talk, type)
  3.  long xtime;
  4.  const char *cause; /* sickness cause */
  5.  boolean talk;
  6.  int type;
  7.  {
  8.      long old = Sick;
  9.  
  10.  #if 0
  11.      if (Unaware)
  12.          talk = FALSE;
  13.  #endif
  14.      if (xtime > 0L) {
  15.          if (Sick_resistance)
  16.              return;
  17.          if (!old) {
  18.              /* newly sick */
  19.              You_feel("deathly sick.");
  20.          } else {
  21.              /* already sick */
  22.              if (talk)
  23.                  You_feel("%s worse.", xtime <= Sick / 2L ? "much" : "even");
  24.          }
  25.          set_itimeout(&Sick, xtime);
  26.          u.usick_type |= type;
  27.          context.botl = TRUE;
  28.      } else if (old && (type & u.usick_type)) {
  29.          /* was sick, now not */
  30.          u.usick_type &= ~type;
  31.          if (u.usick_type) { /* only partly cured */
  32.              if (talk)
  33.                  You_feel("somewhat better.");
  34.              set_itimeout(&Sick, Sick * 2); /* approximation */
  35.          } else {
  36.              if (talk)
  37.                  You_feel("cured.  What a relief!");
  38.              Sick = 0L; /* set_itimeout(&Sick, 0L) */
  39.          }
  40.          context.botl = TRUE;
  41.      }
  42.  
  43.      if (Sick) {
  44.          exercise(A_CON, FALSE);
  45.          delayed_killer(SICK, KILLED_BY_AN, cause);
  46.      } else
  47.          dealloc_killer(find_delayed_killer(SICK));
  48.  }
  49.  

make_slimed

  1.  void
  2.  make_slimed(xtime, msg)
  3.  long xtime;
  4.  const char *msg;
  5.  {
  6.      long old = Slimed;
  7.  
  8.  #if 0
  9.      if (Unaware)
  10.          msg = 0;
  11.  #endif
  12.      if ((!xtime && old) || (xtime && !old)) {
  13.          if (msg)
  14.              pline1(msg);
  15.          context.botl = 1;
  16.      }
  17.      set_itimeout(&Slimed, xtime);
  18.      if (!Slimed)
  19.          dealloc_killer(find_delayed_killer(SLIMED));
  20.  }
  21.  

make_stoned

  1.  /* start or stop petrification */
  2.  void
  3.  make_stoned(xtime, msg, killedby, killername)
  4.  long xtime;
  5.  const char *msg;
  6.  int killedby;
  7.  const char *killername;
  8.  {
  9.      long old = Stoned;
  10.  
  11.  #if 0
  12.      if (Unaware)
  13.          msg = 0;
  14.  #endif
  15.      if ((!xtime && old) || (xtime && !old)) {
  16.          if (msg)
  17.              pline1(msg);
  18.          /* context.botl = 1;   --- Stoned is not a status line item */
  19.      }
  20.      set_itimeout(&Stoned, xtime);
  21.      if (!Stoned)
  22.          dealloc_killer(find_delayed_killer(STONED));
  23.      else if (!old)
  24.          delayed_killer(STONED, killedby, killername);
  25.  }
  26.  

make_vomiting

  1.  void
  2.  make_vomiting(xtime, talk)
  3.  long xtime;
  4.  boolean talk;
  5.  {
  6.      long old = Vomiting;
  7.  
  8.      if (Unaware)
  9.          talk = FALSE;
  10.  
  11.      if (!xtime && old)
  12.          if (talk)
  13.              You_feel("much less nauseated now.");
  14.  
  15.      set_itimeout(&Vomiting, xtime);
  16.  }
  17.  

make_blinded

  1.  static const char vismsg[] = "vision seems to %s for a moment but is %s now.";
  2.  static const char eyemsg[] = "%s momentarily %s.";
  3.  
  4.  void
  5.  make_blinded(xtime, talk)
  6.  long xtime;
  7.  boolean talk;
  8.  {
  9.      long old = Blinded;
  10.      boolean u_could_see, can_see_now;
  11.      const char *eyes;
  12.  
  13.      /* we need to probe ahead in case the Eyes of the Overworld
  14.         are or will be overriding blindness */
  15.      u_could_see = !Blind;
  16.      Blinded = xtime ? 1L : 0L;
  17.      can_see_now = !Blind;
  18.      Blinded = old; /* restore */
  19.  
  20.      if (Unaware)
  21.          talk = FALSE;
  22.  
  23.      if (can_see_now && !u_could_see) { /* regaining sight */
  24.          if (talk) {
  25.              if (Hallucination)
  26.                  pline("Far out!  Everything is all cosmic again!");
  27.              else
  28.                  You("can see again.");
  29.          }
  30.      } else if (old && !xtime) {
  31.          /* clearing temporary blindness without toggling blindness */
  32.          if (talk) {
  33.              if (!haseyes(youmonst.data)) {
  34.                  strange_feeling((struct obj *) 0, (char *) 0);
  35.              } else if (Blindfolded) {
  36.                  eyes = body_part(EYE);
  37.                  if (eyecount(youmonst.data) != 1)
  38.                      eyes = makeplural(eyes);
  39.                  Your(eyemsg, eyes, vtense(eyes, "itch"));
  40.              } else { /* Eyes of the Overworld */
  41.                  Your(vismsg, "brighten", Hallucination ? "sadder" : "normal");
  42.              }
  43.          }
  44.      }
  45.  
  46.      if (u_could_see && !can_see_now) { /* losing sight */
  47.          if (talk) {
  48.              if (Hallucination)
  49.                  pline("Oh, bummer!  Everything is dark!  Help!");
  50.              else
  51.                  pline("A cloud of darkness falls upon you.");
  52.          }
  53.          /* Before the hero goes blind, set the ball&chain variables. */
  54.          if (Punished)
  55.              set_bc(0);
  56.      } else if (!old && xtime) {
  57.          /* setting temporary blindness without toggling blindness */
  58.          if (talk) {
  59.              if (!haseyes(youmonst.data)) {
  60.                  strange_feeling((struct obj *) 0, (char *) 0);
  61.              } else if (Blindfolded) {
  62.                  eyes = body_part(EYE);
  63.                  if (eyecount(youmonst.data) != 1)
  64.                      eyes = makeplural(eyes);
  65.                  Your(eyemsg, eyes, vtense(eyes, "twitch"));
  66.              } else { /* Eyes of the Overworld */
  67.                  Your(vismsg, "dim", Hallucination ? "happier" : "normal");
  68.              }
  69.          }
  70.      }
  71.  
  72.      set_itimeout(&Blinded, xtime);
  73.  
  74.      if (u_could_see ^ can_see_now) { /* one or the other but not both */
  75.          context.botl = 1;
  76.          vision_full_recalc = 1; /* blindness just got toggled */
  77.          /* this vision recalculation used to be deferred until
  78.             moveloop(), but that made it possible for vision
  79.             irregularities to occur (cited case was force bolt
  80.             hitting adjacent potion of blindness and then a
  81.             secret door; hero was blinded by vapors but then
  82.             got the message "a door appears in the wall") */
  83.          vision_recalc(0);
  84.          if (Blind_telepat || Infravision)
  85.              see_monsters();
  86.  
  87.          /* avoid either of the sequences
  88.             "Sting starts glowing", [become blind], "Sting stops quivering" or
  89.             "Sting starts quivering", [regain sight], "Sting stops glowing"
  90.             by giving "Sting is quivering" when becoming blind or
  91.             "Sting is glowing" when regaining sight so that the eventual
  92.             "stops" message matches */
  93.          if (warn_obj_cnt && uwep && (EWarn_of_mon & W_WEP) != 0L)
  94.              Sting_effects(-1);
  95.          /* update dknown flag for inventory picked up while blind */
  96.          if (can_see_now)
  97.              learn_unseen_invent();
  98.      }
  99.  }
  100.  

make_hallucinated

  1.  boolean
  2.  make_hallucinated(xtime, talk, mask)
  3.  long xtime; /* nonzero if this is an attempt to turn on hallucination */
  4.  boolean talk;
  5.  long mask; /* nonzero if resistance status should change by mask */
  6.  {
  7.      long old = HHallucination;
  8.      boolean changed = 0;
  9.      const char *message, *verb;
  10.  
  11.      if (Unaware)
  12.          talk = FALSE;
  13.  
  14.      message = (!xtime) ? "Everything %s SO boring now."
  15.                         : "Oh wow!  Everything %s so cosmic!";
  16.      verb = (!Blind) ? "looks" : "feels";
  17.  
  18.      if (mask) {
  19.          if (HHallucination)
  20.              changed = TRUE;
  21.  
  22.          if (!xtime)
  23.              EHalluc_resistance |= mask;
  24.          else
  25.              EHalluc_resistance &= ~mask;
  26.      } else {
  27.          if (!EHalluc_resistance && (!!HHallucination != !!xtime))
  28.              changed = TRUE;
  29.          set_itimeout(&HHallucination, xtime);
  30.  
  31.          /* clearing temporary hallucination without toggling vision */
  32.          if (!changed && !HHallucination && old && talk) {
  33.              if (!haseyes(youmonst.data)) {
  34.                  strange_feeling((struct obj *) 0, (char *) 0);
  35.              } else if (Blind) {
  36.                  const char *eyes = body_part(EYE);
  37.  
  38.                  if (eyecount(youmonst.data) != 1)
  39.                      eyes = makeplural(eyes);
  40.                  Your(eyemsg, eyes, vtense(eyes, "itch"));
  41.              } else { /* Grayswandir */
  42.                  Your(vismsg, "flatten", "normal");
  43.              }
  44.          }
  45.      }
  46.  
  47.      if (changed) {
  48.          /* in case we're mimicking an orange (hallucinatory form
  49.             of mimicking gold) update the mimicking's-over message */
  50.          if (!Hallucination)
  51.              eatmupdate();
  52.  
  53.          if (u.uswallow) {
  54.              swallowed(0); /* redraw swallow display */
  55.          } else {
  56.              /* The see_* routines should be called *before* the pline. */
  57.              see_monsters();
  58.              see_objects();
  59.              see_traps();
  60.          }
  61.  
  62.          /* for perm_inv and anything similar
  63.          (eg. Qt windowport's equipped items display) */
  64.          update_inventory();
  65.  
  66.          context.botl = 1;
  67.          if (talk)
  68.              pline(message, verb);
  69.      }
  70.      return changed;
  71.  }
  72.  

make_deaf

  1.  void
  2.  make_deaf(xtime, talk)
  3.  long xtime;
  4.  boolean talk;
  5.  {
  6.      long old = HDeaf;
  7.      boolean toggled = FALSE;
  8.  
  9.      if (Unaware)
  10.          talk = FALSE;
  11.  
  12.      if (!xtime && old) {
  13.          if (talk)
  14.              You("can hear again.");
  15.          toggled = TRUE;
  16.      } else if (xtime && !old) {
  17.          if (talk)
  18.              You("are unable to hear anything.");
  19.          toggled = TRUE;
  20.      }
  21.      /* deafness isn't presently shown on status line, but
  22.         request a status update in case that changes someday */
  23.      if (toggled)
  24.          context.botl = TRUE;
  25.  
  26.      set_itimeout(&HDeaf, xtime);
  27.  }
  28.  

ghost_from_bottle

  1.  STATIC_OVL void
  2.  ghost_from_bottle()
  3.  {
  4.      struct monst *mtmp = makemon(&mons[PM_GHOST], u.ux, u.uy, NO_MM_FLAGS);
  5.  
  6.      if (!mtmp) {
  7.          pline("This bottle turns out to be empty.");
  8.          return;
  9.      }
  10.      if (Blind) {
  11.          pline("As you open the bottle, %s emerges.", something);
  12.          return;
  13.      }
  14.      pline("As you open the bottle, an enormous %s emerges!",
  15.            Hallucination ? rndmonnam(NULL) : (const char *) "ghost");
  16.      if (flags.verbose)
  17.          You("are frightened to death, and unable to move.");
  18.      nomul(-3);
  19.      multi_reason = "being frightened to death";
  20.      nomovemsg = "You regain your composure.";
  21.  }
  22.  

dodrink

  1.  /* "Quaffing is like drinking, except you spill more." - Terry Pratchett */
  2.  int
  3.  dodrink()
  4.  {
  5.      register struct obj *otmp;
  6.      const char *potion_descr;
  7.  
  8.      if (Strangled) {
  9.          pline("If you can't breathe air, how can you drink liquid?");
  10.          return 0;
  11.      }
  12.      /* Is there a fountain to drink from here? */
  13.      if (IS_FOUNTAIN(levl[u.ux][u.uy].typ)
  14.          /* not as low as floor level but similar restrictions apply */
  15.          && can_reach_floor(FALSE)) {
  16.          if (yn("Drink from the fountain?") == 'y') {
  17.              drinkfountain();
  18.              return 1;
  19.          }
  20.      }
  21.      /* Or a kitchen sink? */
  22.      if (IS_SINK(levl[u.ux][u.uy].typ)
  23.          /* not as low as floor level but similar restrictions apply */
  24.          && can_reach_floor(FALSE)) {
  25.          if (yn("Drink from the sink?") == 'y') {
  26.              drinksink();
  27.              return 1;
  28.          }
  29.      }
  30.      /* Or are you surrounded by water? */
  31.      if (Underwater && !u.uswallow) {
  32.          if (yn("Drink the water around you?") == 'y') {
  33.              pline("Do you know what lives in this water?");
  34.              return 1;
  35.          }
  36.      }
  37.  
  38.      otmp = getobj(beverages, "drink");
  39.      if (!otmp)
  40.          return 0;
  41.  
  42.      /* quan > 1 used to be left to useup(), but we need to force
  43.         the current potion to be unworn, and don't want to do
  44.         that for the entire stack when starting with more than 1.
  45.         [Drinking a wielded potion of polymorph can trigger a shape
  46.         change which causes hero's weapon to be dropped.  In 3.4.x,
  47.         that led to an "object lost" panic since subsequent useup()
  48.         was no longer dealing with an inventory item.  Unwearing
  49.         the current potion is intended to keep it in inventory.] */
  50.      if (otmp->quan > 1L) {
  51.          otmp = splitobj(otmp, 1L);
  52.          otmp->owornmask = 0L; /* rest of original stuck unaffected */
  53.      } else if (otmp->owornmask) {
  54.          remove_worn_item(otmp, FALSE);
  55.      }
  56.      otmp->in_use = TRUE; /* you've opened the stopper */
  57.  
  58.      potion_descr = OBJ_DESCR(objects[otmp->otyp]);
  59.      if (potion_descr) {
  60.          if (!strcmp(potion_descr, "milky")
  61.              && !(mvitals[PM_GHOST].mvflags & G_GONE)
  62.              && !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_GHOST].born))) {
  63.              ghost_from_bottle();
  64.              useup(otmp);
  65.              return 1;
  66.          } else if (!strcmp(potion_descr, "smoky")
  67.                     && !(mvitals[PM_DJINNI].mvflags & G_GONE)
  68.                     && !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_DJINNI].born))) {
  69.              djinni_from_bottle(otmp);
  70.              useup(otmp);
  71.              return 1;
  72.          }
  73.      }
  74.      return dopotion(otmp);
  75.  }
  76.  

dopotion

  1.  int
  2.  dopotion(otmp)
  3.  register struct obj *otmp;
  4.  {
  5.      int retval;
  6.  
  7.      otmp->in_use = TRUE;
  8.      nothing = unkn = 0;
  9.      if ((retval = peffects(otmp)) >= 0)
  10.          return retval;
  11.  
  12.      if (nothing) {
  13.          unkn++;
  14.          You("have a %s feeling for a moment, then it passes.",
  15.              Hallucination ? "normal" : "peculiar");
  16.      }
  17.      if (otmp->dknown && !objects[otmp->otyp].oc_name_known) {
  18.          if (!unkn) {
  19.              makeknown(otmp->otyp);
  20.              more_experienced(0, 10);
  21.          } else if (!objects[otmp->otyp].oc_uname)
  22.              docall(otmp);
  23.      }
  24.      useup(otmp);
  25.      return 1;
  26.  }
  27.  

peffects

  1.  int
  2.  peffects(otmp)
  3.  register struct obj *otmp;
  4.  {
  5.      register int i, ii, lim;
  6.  
  7.      switch (otmp->otyp) {
  8.      case POT_RESTORE_ABILITY:
  9.      case SPE_RESTORE_ABILITY:
  10.          unkn++;
  11.          if (otmp->cursed) {
  12.              pline("Ulch!  This makes you feel mediocre!");
  13.              break;
  14.          } else {
  15.              /* unlike unicorn horn, overrides Fixed_abil */
  16.              pline("Wow!  This makes you feel %s!",
  17.                    (otmp->blessed)
  18.                        ? (unfixable_trouble_count(FALSE) ? "better" : "great")
  19.                        : "good");
  20.              i = rn2(A_MAX); /* start at a random point */
  21.              for (ii = 0; ii < A_MAX; ii++) {
  22.                  lim = AMAX(i);
  23.                  if (i == A_STR && u.uhs >= 3)
  24.                      --lim; /* WEAK */
  25.                  if (ABASE(i) < lim) {
  26.                      ABASE(i) = lim;
  27.                      context.botl = 1;
  28.                      /* only first found if not blessed */
  29.                      if (!otmp->blessed)
  30.                          break;
  31.                  }
  32.                  if (++i >= A_MAX)
  33.                      i = 0;
  34.              }
  35.          }
  36.          break;
  37.      case POT_HALLUCINATION:
  38.          if (Hallucination || Halluc_resistance)
  39.              nothing++;
  40.          (void) make_hallucinated(
  41.              itimeout_incr(HHallucination, rn1(200, 600 - 300 * bcsign(otmp))),
  42.              TRUE, 0L);
  43.          break;
  44.      case POT_WATER:
  45.          if (!otmp->blessed && !otmp->cursed) {
  46.              pline("This tastes like water.");
  47.              u.uhunger += rnd(10);
  48.              newuhs(FALSE);
  49.              break;
  50.          }
  51.          unkn++;
  52.          if (is_undead(youmonst.data) || is_demon(youmonst.data)
  53.              || u.ualign.type == A_CHAOTIC) {
  54.              if (otmp->blessed) {
  55.                  pline("This burns like acid!");
  56.                  exercise(A_CON, FALSE);
  57.                  if (u.ulycn >= LOW_PM) {
  58.                      Your("affinity to %s disappears!",
  59.                           makeplural(mons[u.ulycn].mname));
  60.                      if (youmonst.data == &mons[u.ulycn])
  61.                          you_unwere(FALSE);
  62.                      u.ulycn = NON_PM; /* cure lycanthropy */
  63.                  }
  64.                  losehp(Maybe_Half_Phys(d(2, 6)), "potion of holy water",
  65.                         KILLED_BY_AN);
  66.              } else if (otmp->cursed) {
  67.                  You_feel("quite proud of yourself.");
  68.                  healup(d(2, 6), 0, 0, 0);
  69.                  if (u.ulycn >= LOW_PM && !Upolyd)
  70.                      you_were();
  71.                  exercise(A_CON, TRUE);
  72.              }
  73.          } else {
  74.              if (otmp->blessed) {
  75.                  You_feel("full of awe.");
  76.                  make_sick(0L, (char *) 0, TRUE, SICK_ALL);
  77.                  exercise(A_WIS, TRUE);
  78.                  exercise(A_CON, TRUE);
  79.                  if (u.ulycn >= LOW_PM)
  80.                      you_unwere(TRUE); /* "Purified" */
  81.                  /* make_confused(0L, TRUE); */
  82.              } else {
  83.                  if (u.ualign.type == A_LAWFUL) {
  84.                      pline("This burns like acid!");
  85.                      losehp(Maybe_Half_Phys(d(2, 6)), "potion of unholy water",
  86.                             KILLED_BY_AN);
  87.                  } else
  88.                      You_feel("full of dread.");
  89.                  if (u.ulycn >= LOW_PM && !Upolyd)
  90.                      you_were();
  91.                  exercise(A_CON, FALSE);
  92.              }
  93.          }
  94.          break;
  95.      case POT_BOOZE:
  96.          unkn++;
  97.          pline("Ooph!  This tastes like %s%s!",
  98.                otmp->odiluted ? "watered down " : "",
  99.                Hallucination ? "dandelion wine" : "liquid fire");
  100.          if (!otmp->blessed)
  101.              make_confused(itimeout_incr(HConfusion, d(3, 8)), FALSE);
  102.          /* the whiskey makes us feel better */
  103.          if (!otmp->odiluted)
  104.              healup(1, 0, FALSE, FALSE);
  105.          u.uhunger += 10 * (2 + bcsign(otmp));
  106.          newuhs(FALSE);
  107.          exercise(A_WIS, FALSE);
  108.          if (otmp->cursed) {
  109.              You("pass out.");
  110.              multi = -rnd(15);
  111.              nomovemsg = "You awake with a headache.";
  112.          }
  113.          break;
  114.      case POT_ENLIGHTENMENT:
  115.          if (otmp->cursed) {
  116.              unkn++;
  117.              You("have an uneasy feeling...");
  118.              exercise(A_WIS, FALSE);
  119.          } else {
  120.              if (otmp->blessed) {
  121.                  (void) adjattrib(A_INT, 1, FALSE);
  122.                  (void) adjattrib(A_WIS, 1, FALSE);
  123.              }
  124.              You_feel("self-knowledgeable...");
  125.              display_nhwindow(WIN_MESSAGE, FALSE);
  126.              enlightenment(MAGICENLIGHTENMENT, ENL_GAMEINPROGRESS);
  127.              pline_The("feeling subsides.");
  128.              exercise(A_WIS, TRUE);
  129.          }
  130.          break;
  131.      case SPE_INVISIBILITY:
  132.          /* spell cannot penetrate mummy wrapping */
  133.          if (BInvis && uarmc->otyp == MUMMY_WRAPPING) {
  134.              You_feel("rather itchy under %s.", yname(uarmc));
  135.              break;
  136.          }
  137.          /* FALLTHRU */
  138.      case POT_INVISIBILITY:
  139.          if (Invis || Blind || BInvis) {
  140.              nothing++;
  141.          } else {
  142.              self_invis_message();
  143.          }
  144.          if (otmp->blessed)
  145.              HInvis |= FROMOUTSIDE;
  146.          else
  147.              incr_itimeout(&HInvis, rn1(15, 31));
  148.          newsym(u.ux, u.uy); /* update position */
  149.          if (otmp->cursed) {
  150.              pline("For some reason, you feel your presence is known.");
  151.              aggravate();
  152.          }
  153.          break;
  154.      case POT_SEE_INVISIBLE: /* tastes like fruit juice in Rogue */
  155.      case POT_FRUIT_JUICE: {
  156.          int msg = Invisible && !Blind;
  157.  
  158.          unkn++;
  159.          if (otmp->cursed)
  160.              pline("Yecch!  This tastes %s.",
  161.                    Hallucination ? "overripe" : "rotten");
  162.          else
  163.              pline(
  164.                  Hallucination
  165.                      ? "This tastes like 10%% real %s%s all-natural beverage."
  166.                      : "This tastes like %s%s.",
  167.                  otmp->odiluted ? "reconstituted " : "", fruitname(TRUE));
  168.          if (otmp->otyp == POT_FRUIT_JUICE) {
  169.              u.uhunger += (otmp->odiluted ? 5 : 10) * (2 + bcsign(otmp));
  170.              newuhs(FALSE);
  171.              break;
  172.          }
  173.          if (!otmp->cursed) {
  174.              /* Tell them they can see again immediately, which
  175.               * will help them identify the potion...
  176.               */
  177.              make_blinded(0L, TRUE);
  178.          }
  179.          if (otmp->blessed)
  180.              HSee_invisible |= FROMOUTSIDE;
  181.          else
  182.              incr_itimeout(&HSee_invisible, rn1(100, 750));
  183.          set_mimic_blocking(); /* do special mimic handling */
  184.          see_monsters();       /* see invisible monsters */
  185.          newsym(u.ux, u.uy);   /* see yourself! */
  186.          if (msg && !Blind) {  /* Blind possible if polymorphed */
  187.              You("can see through yourself, but you are visible!");
  188.              unkn--;
  189.          }
  190.          break;
  191.      }
  192.      case POT_PARALYSIS:
  193.          if (Free_action) {
  194.              You("stiffen momentarily.");
  195.          } else {
  196.              if (Levitation || Is_airlevel(&u.uz) || Is_waterlevel(&u.uz))
  197.                  You("are motionlessly suspended.");
  198.              else if (u.usteed)
  199.                  You("are frozen in place!");
  200.              else
  201.                  Your("%s are frozen to the %s!", makeplural(body_part(FOOT)),
  202.                       surface(u.ux, u.uy));
  203.              nomul(-(rn1(10, 25 - 12 * bcsign(otmp))));
  204.              multi_reason = "frozen by a potion";
  205.              nomovemsg = You_can_move_again;
  206.              exercise(A_DEX, FALSE);
  207.          }
  208.          break;
  209.      case POT_SLEEPING:
  210.          if (Sleep_resistance || Free_action) {
  211.              You("yawn.");
  212.          } else {
  213.              You("suddenly fall asleep!");
  214.              fall_asleep(-rn1(10, 25 - 12 * bcsign(otmp)), TRUE);
  215.          }
  216.          break;
  217.      case POT_MONSTER_DETECTION:
  218.      case SPE_DETECT_MONSTERS:
  219.          if (otmp->blessed) {
  220.              int x, y;
  221.  
  222.              if (Detect_monsters)
  223.                  nothing++;
  224.              unkn++;
  225.              /* after a while, repeated uses become less effective */
  226.              if ((HDetect_monsters & TIMEOUT) >= 300L)
  227.                  i = 1;
  228.              else
  229.                  i = rn1(40, 21);
  230.              incr_itimeout(&HDetect_monsters, i);
  231.              for (x = 1; x < COLNO; x++) {
  232.                  for (y = 0; y < ROWNO; y++) {
  233.                      if (levl[x][y].glyph == GLYPH_INVISIBLE) {
  234.                          unmap_object(x, y);
  235.                          newsym(x, y);
  236.                      }
  237.                      if (MON_AT(x, y))
  238.                          unkn = 0;
  239.                  }
  240.              }
  241.              see_monsters();
  242.              if (unkn)
  243.                  You_feel("lonely.");
  244.              break;
  245.          }
  246.          if (monster_detect(otmp, 0))
  247.              return 1; /* nothing detected */
  248.          exercise(A_WIS, TRUE);
  249.          break;
  250.      case POT_OBJECT_DETECTION:
  251.      case SPE_DETECT_TREASURE:
  252.          if (object_detect(otmp, 0))
  253.              return 1; /* nothing detected */
  254.          exercise(A_WIS, TRUE);
  255.          break;
  256.      case POT_SICKNESS:
  257.          pline("Yecch!  This stuff tastes like poison.");
  258.          if (otmp->blessed) {
  259.              pline("(But in fact it was mildly stale %s.)", fruitname(TRUE));
  260.              if (!Role_if(PM_HEALER)) {
  261.                  /* NB: blessed otmp->fromsink is not possible */
  262.                  losehp(1, "mildly contaminated potion", KILLED_BY_AN);
  263.              }
  264.          } else {
  265.              if (Poison_resistance)
  266.                  pline("(But in fact it was biologically contaminated %s.)",
  267.                        fruitname(TRUE));
  268.              if (Role_if(PM_HEALER)) {
  269.                  pline("Fortunately, you have been immunized.");
  270.              } else {
  271.                  char contaminant[BUFSZ];
  272.                  int typ = rn2(A_MAX);
  273.  
  274.                  Sprintf(contaminant, "%s%s",
  275.                          (Poison_resistance) ? "mildly " : "",
  276.                          (otmp->fromsink) ? "contaminated tap water"
  277.                                           : "contaminated potion");
  278.                  if (!Fixed_abil) {
  279.                      poisontell(typ, FALSE);
  280.                      (void) adjattrib(typ, Poison_resistance ? -1 : -rn1(4, 3),
  281.                                       1);
  282.                  }
  283.                  if (!Poison_resistance) {
  284.                      if (otmp->fromsink)
  285.                          losehp(rnd(10) + 5 * !!(otmp->cursed), contaminant,
  286.                                 KILLED_BY);
  287.                      else
  288.                          losehp(rnd(10) + 5 * !!(otmp->cursed), contaminant,
  289.                                 KILLED_BY_AN);
  290.                  } else {
  291.                      /* rnd loss is so that unblessed poorer than blessed */
  292.                      losehp(1 + rn2(2), contaminant,
  293.                             (otmp->fromsink) ? KILLED_BY : KILLED_BY_AN);
  294.                  }
  295.                  exercise(A_CON, FALSE);
  296.              }
  297.          }
  298.          if (Hallucination) {
  299.              You("are shocked back to your senses!");
  300.              (void) make_hallucinated(0L, FALSE, 0L);
  301.          }
  302.          break;
  303.      case POT_CONFUSION:
  304.          if (!Confusion) {
  305.              if (Hallucination) {
  306.                  pline("What a trippy feeling!");
  307.                  unkn++;
  308.              } else
  309.                  pline("Huh, What?  Where am I?");
  310.          } else
  311.              nothing++;
  312.          make_confused(itimeout_incr(HConfusion,
  313.                                      rn1(7, 16 - 8 * bcsign(otmp))),
  314.                        FALSE);
  315.          break;
  316.      case POT_GAIN_ABILITY:
  317.          if (otmp->cursed) {
  318.              pline("Ulch!  That potion tasted foul!");
  319.              unkn++;
  320.          } else if (Fixed_abil) {
  321.              nothing++;
  322.          } else {      /* If blessed, increase all; if not, try up to */
  323.              int itmp; /* 6 times to find one which can be increased. */
  324.  
  325.              i = -1;   /* increment to 0 */
  326.              for (ii = A_MAX; ii > 0; ii--) {
  327.                  i = (otmp->blessed ? i + 1 : rn2(A_MAX));
  328.                  /* only give "your X is already as high as it can get"
  329.                     message on last attempt (except blessed potions) */
  330.                  itmp = (otmp->blessed || ii == 1) ? 0 : -1;
  331.                  if (adjattrib(i, 1, itmp) && !otmp->blessed)
  332.                      break;
  333.              }
  334.          }
  335.          break;
  336.      case POT_SPEED:
  337.          if (Wounded_legs && !otmp->cursed && !u.usteed) {
  338.              /* heal_legs() would heal steeds legs */
  339.              heal_legs();
  340.              unkn++;
  341.              break;
  342.          }
  343.          /* FALLTHRU */
  344.      case SPE_HASTE_SELF:
  345.          if (!Very_fast) { /* wwf@doe.carleton.ca */
  346.              You("are suddenly moving %sfaster.", Fast ? "" : "much ");
  347.          } else {
  348.              Your("%s get new energy.", makeplural(body_part(LEG)));
  349.              unkn++;
  350.          }
  351.          exercise(A_DEX, TRUE);
  352.          incr_itimeout(&HFast, rn1(10, 100 + 60 * bcsign(otmp)));
  353.          break;
  354.      case POT_BLINDNESS:
  355.          if (Blind)
  356.              nothing++;
  357.          make_blinded(itimeout_incr(Blinded,
  358.                                     rn1(200, 250 - 125 * bcsign(otmp))),
  359.                       (boolean) !Blind);
  360.          break;
  361.      case POT_GAIN_LEVEL:
  362.          if (otmp->cursed) {
  363.              unkn++;
  364.              /* they went up a level */
  365.              if ((ledger_no(&u.uz) == 1 && u.uhave.amulet)
  366.                  || Can_rise_up(u.ux, u.uy, &u.uz)) {
  367.                  const char *riseup = "rise up, through the %s!";
  368.  
  369.                  if (ledger_no(&u.uz) == 1) {
  370.                      You(riseup, ceiling(u.ux, u.uy));
  371.                      goto_level(&earth_level, FALSE, FALSE, FALSE);
  372.                  } else {
  373.                      register int newlev = depth(&u.uz) - 1;
  374.                      d_level newlevel;
  375.  
  376.                      get_level(&newlevel, newlev);
  377.                      if (on_level(&newlevel, &u.uz)) {
  378.                          pline("It tasted bad.");
  379.                          break;
  380.                      } else
  381.                          You(riseup, ceiling(u.ux, u.uy));
  382.                      goto_level(&newlevel, FALSE, FALSE, FALSE);
  383.                  }
  384.              } else
  385.                  You("have an uneasy feeling.");
  386.              break;
  387.          }
  388.          pluslvl(FALSE);
  389.          /* blessed potions place you at a random spot in the
  390.             middle of the new level instead of the low point */
  391.          if (otmp->blessed)
  392.              u.uexp = rndexp(TRUE);
  393.          break;
  394.      case POT_HEALING:
  395.          You_feel("better.");
  396.          healup(d(6 + 2 * bcsign(otmp), 4), !otmp->cursed ? 1 : 0,
  397.                 !!otmp->blessed, !otmp->cursed);
  398.          exercise(A_CON, TRUE);
  399.          break;
  400.      case POT_EXTRA_HEALING:
  401.          You_feel("much better.");
  402.          healup(d(6 + 2 * bcsign(otmp), 8),
  403.                 otmp->blessed ? 5 : !otmp->cursed ? 2 : 0, !otmp->cursed,
  404.                 TRUE);
  405.          (void) make_hallucinated(0L, TRUE, 0L);
  406.          exercise(A_CON, TRUE);
  407.          exercise(A_STR, TRUE);
  408.          break;
  409.      case POT_FULL_HEALING:
  410.          You_feel("completely healed.");
  411.          healup(400, 4 + 4 * bcsign(otmp), !otmp->cursed, TRUE);
  412.          /* Restore one lost level if blessed */
  413.          if (otmp->blessed && u.ulevel < u.ulevelmax) {
  414.              /* when multiple levels have been lost, drinking
  415.                 multiple potions will only get half of them back */
  416.              u.ulevelmax -= 1;
  417.              pluslvl(FALSE);
  418.          }
  419.          (void) make_hallucinated(0L, TRUE, 0L);
  420.          exercise(A_STR, TRUE);
  421.          exercise(A_CON, TRUE);
  422.          break;
  423.      case POT_LEVITATION:
  424.      case SPE_LEVITATION:
  425.          if (otmp->cursed)
  426.              HLevitation &= ~I_SPECIAL;
  427.          if (!Levitation && !BLevitation) {
  428.              /* kludge to ensure proper operation of float_up() */
  429.              set_itimeout(&HLevitation, 1L);
  430.              float_up();
  431.              /* reverse kludge */
  432.              set_itimeout(&HLevitation, 0L);
  433.              if (otmp->cursed) {
  434.                  if ((u.ux == xupstair && u.uy == yupstair)
  435.                      || (sstairs.up && u.ux == sstairs.sx
  436.                          && u.uy == sstairs.sy)
  437.                      || (xupladder && u.ux == xupladder
  438.                          && u.uy == yupladder)) {
  439.                      (void) doup();
  440.                  } else if (has_ceiling(&u.uz)) {
  441.                      int dmg = uarmh ? 1 : rnd(10);
  442.  
  443.                      You("hit your %s on the %s.", body_part(HEAD),
  444.                          ceiling(u.ux, u.uy));
  445.                      losehp(Maybe_Half_Phys(dmg), "colliding with the ceiling",
  446.                             KILLED_BY);
  447.                  }
  448.              } /*cursed*/
  449.          } else
  450.              nothing++;
  451.          if (otmp->blessed) {
  452.              incr_itimeout(&HLevitation, rn1(50, 250));
  453.              HLevitation |= I_SPECIAL;
  454.          } else
  455.              incr_itimeout(&HLevitation, rn1(140, 10));
  456.          if (Levitation)
  457.              spoteffects(FALSE); /* for sinks */
  458.          float_vs_flight();
  459.          break;
  460.      case POT_GAIN_ENERGY: { /* M. Stephenson */
  461.          int num;
  462.  
  463.          if (otmp->cursed)
  464.              You_feel("lackluster.");
  465.          else
  466.              pline("Magical energies course through your body.");
  467.  
  468.          /* old: num = rnd(5) + 5 * otmp->blessed + 1;
  469.           *      blessed:  +7..11 max & current (+9 avg)
  470.           *      uncursed: +2.. 6 max & current (+4 avg)
  471.           *      cursed:   -2.. 6 max & current (-4 avg)
  472.           * new: (3.6.0)
  473.           *      blessed:  +3..18 max (+10.5 avg), +9..54 current (+31.5 avg)
  474.           *      uncursed: +2..12 max (+ 7   avg), +6..36 current (+21   avg)
  475.           *      cursed:   -1.. 6 max (- 3.5 avg), -3..18 current (-10.5 avg)
  476.           */
  477.          num = d(otmp->blessed ? 3 : !otmp->cursed ? 2 : 1, 6);
  478.          if (otmp->cursed)
  479.              num = -num; /* subtract instead of add when cursed */
  480.          u.uenmax += num;
  481.          if (u.uenmax <= 0)
  482.              u.uenmax = 0;
  483.          u.uen += 3 * num;
  484.          if (u.uen > u.uenmax)
  485.              u.uen = u.uenmax;
  486.          else if (u.uen <= 0)
  487.              u.uen = 0;
  488.          context.botl = 1;
  489.          exercise(A_WIS, TRUE);
  490.          break;
  491.      }
  492.      case POT_OIL: { /* P. Winner */
  493.          boolean good_for_you = FALSE;
  494.  
  495.          if (otmp->lamplit) {
  496.              if (likes_fire(youmonst.data)) {
  497.                  pline("Ahh, a refreshing drink.");
  498.                  good_for_you = TRUE;
  499.              } else {
  500.                  You("burn your %s.", body_part(FACE));
  501.                  /* fire damage */
  502.                  losehp(d(Fire_resistance ? 1 : 3, 4), "burning potion of oil",
  503.                         KILLED_BY_AN);
  504.              }
  505.          } else if (otmp->cursed)
  506.              pline("This tastes like castor oil.");
  507.          else
  508.              pline("That was smooth!");
  509.          exercise(A_WIS, good_for_you);
  510.          break;
  511.      }
  512.      case POT_ACID:
  513.          if (Acid_resistance) {
  514.              /* Not necessarily a creature who _likes_ acid */
  515.              pline("This tastes %s.", Hallucination ? "tangy" : "sour");
  516.          } else {
  517.              int dmg;
  518.  
  519.              pline("This burns%s!",
  520.                    otmp->blessed ? " a little" : otmp->cursed ? " a lot"
  521.                                                               : " like acid");
  522.              dmg = d(otmp->cursed ? 2 : 1, otmp->blessed ? 4 : 8);
  523.              losehp(Maybe_Half_Phys(dmg), "potion of acid", KILLED_BY_AN);
  524.              exercise(A_CON, FALSE);
  525.          }
  526.          if (Stoned)
  527.              fix_petrification();
  528.          unkn++; /* holy/unholy water can burn like acid too */
  529.          break;
  530.      case POT_POLYMORPH:
  531.          You_feel("a little %s.", Hallucination ? "normal" : "strange");
  532.          if (!Unchanging)
  533.              polyself(0);
  534.          break;
  535.      default:
  536.          impossible("What a funny potion! (%u)", otmp->otyp);
  537.          return 0;
  538.      }
  539.      return -1;
  540.  }
  541.  

healup

  1.  void
  2.  healup(nhp, nxtra, curesick, cureblind)
  3.  int nhp, nxtra;
  4.  register boolean curesick, cureblind;
  5.  {
  6.      if (nhp) {
  7.          if (Upolyd) {
  8.              u.mh += nhp;
  9.              if (u.mh > u.mhmax)
  10.                  u.mh = (u.mhmax += nxtra);
  11.          } else {
  12.              u.uhp += nhp;
  13.              if (u.uhp > u.uhpmax)
  14.                  u.uhp = (u.uhpmax += nxtra);
  15.          }
  16.      }
  17.      if (cureblind)
  18.          make_blinded(0L, TRUE);
  19.      if (curesick) {
  20.          make_vomiting(0L, TRUE);
  21.          make_sick(0L, (char *) 0, TRUE, SICK_ALL);
  22.      }
  23.      context.botl = 1;
  24.      return;
  25.  }
  26.  

strange_feeling

  1.  void
  2.  strange_feeling(obj, txt)
  3.  struct obj *obj;
  4.  const char *txt;
  5.  {
  6.      if (flags.beginner || !txt)
  7.          You("have a %s feeling for a moment, then it passes.",
  8.              Hallucination ? "normal" : "strange");
  9.      else
  10.          pline1(txt);
  11.  
  12.      if (!obj) /* e.g., crystal ball finds no traps */
  13.          return;
  14.  
  15.      if (obj->dknown && !objects[obj->otyp].oc_name_known
  16.          && !objects[obj->otyp].oc_uname)
  17.          docall(obj);
  18.  
  19.      useup(obj);
  20.  }
  21.  

bottlename

  1.  const char *bottlenames[] = { "bottle", "phial", "flagon", "carafe",
  2.                                "flask",  "jar",   "vial" };
  3.  
  4.  const char *
  5.  bottlename()
  6.  {
  7.      return bottlenames[rn2(SIZE(bottlenames))];
  8.  }
  9.  

H2Opotion_dip

  1.  /* handle item dipped into water potion or steed saddle splashed by same */
  2.  STATIC_OVL boolean
  3.  H2Opotion_dip(potion, targobj, useeit, objphrase)
  4.  struct obj *potion, *targobj;
  5.  boolean useeit;
  6.  const char *objphrase; /* "Your widget glows" or "Steed's saddle glows" */
  7.  {
  8.      void FDECL((*func), (OBJ_P)) = 0;
  9.      const char *glowcolor = 0;
  10.  #define COST_alter (-2)
  11.  #define COST_none (-1)
  12.      int costchange = COST_none;
  13.      boolean altfmt = FALSE, res = FALSE;
  14.  
  15.      if (!potion || potion->otyp != POT_WATER)
  16.          return FALSE;
  17.  
  18.      if (potion->blessed) {
  19.          if (targobj->cursed) {
  20.              func = uncurse;
  21.              glowcolor = NH_AMBER;
  22.              costchange = COST_UNCURS;
  23.          } else if (!targobj->blessed) {
  24.              func = bless;
  25.              glowcolor = NH_LIGHT_BLUE;
  26.              costchange = COST_alter;
  27.              altfmt = TRUE; /* "with a <color> aura" */
  28.          }
  29.      } else if (potion->cursed) {
  30.          if (targobj->blessed) {
  31.              func = unbless;
  32.              glowcolor = "brown";
  33.              costchange = COST_UNBLSS;
  34.          } else if (!targobj->cursed) {
  35.              func = curse;
  36.              glowcolor = NH_BLACK;
  37.              costchange = COST_alter;
  38.              altfmt = TRUE;
  39.          }
  40.      } else {
  41.          /* dipping into uncursed water; carried() check skips steed saddle */
  42.          if (carried(targobj)) {
  43.              if (water_damage(targobj, 0, TRUE) != ER_NOTHING)
  44.                  res = TRUE;
  45.          }
  46.      }
  47.      if (func) {
  48.          /* give feedback before altering the target object;
  49.             this used to set obj->bknown even when not seeing
  50.             the effect; now hero has to see the glow, and bknown
  51.             is cleared instead of set if perception is distorted */
  52.          if (useeit) {
  53.              glowcolor = hcolor(glowcolor);
  54.              if (altfmt)
  55.                  pline("%s with %s aura.", objphrase, an(glowcolor));
  56.              else
  57.                  pline("%s %s.", objphrase, glowcolor);
  58.              iflags.last_msg = PLNMSG_OBJ_GLOWS;
  59.              targobj->bknown = !Hallucination;
  60.          }
  61.          /* potions of water are the only shop goods whose price depends
  62.             on their curse/bless state */
  63.          if (targobj->unpaid && targobj->otyp == POT_WATER) {
  64.              if (costchange == COST_alter)
  65.                  /* added blessing or cursing; update shop
  66.                     bill to reflect item's new higher price */
  67.                  alter_cost(targobj, 0L);
  68.              else if (costchange != COST_none)
  69.                  /* removed blessing or cursing; you
  70.                     degraded it, now you'll have to buy it... */
  71.                  costly_alteration(targobj, costchange);
  72.          }
  73.          /* finally, change curse/bless state */
  74.          (*func)(targobj);
  75.          res = TRUE;
  76.      }
  77.      return res;
  78.  }
  79.  

potionhit

  1.  void
  2.  potionhit(mon, obj, your_fault)
  3.  register struct monst *mon;
  4.  register struct obj *obj;
  5.  boolean your_fault;
  6.  {
  7.      const char *botlnam = bottlename();
  8.      boolean isyou = (mon == &youmonst);
  9.      int distance;
  10.      struct obj *saddle = (struct obj *) 0;
  11.      boolean hit_saddle = FALSE;
  12.  
  13.      if (isyou) {
  14.          distance = 0;
  15.          pline_The("%s crashes on your %s and breaks into shards.", botlnam,
  16.                    body_part(HEAD));
  17.          losehp(Maybe_Half_Phys(rnd(2)), "thrown potion", KILLED_BY_AN);
  18.      } else {
  19.          /* sometimes it hits the saddle */
  20.          if (((mon->misc_worn_check & W_SADDLE)
  21.               && (saddle = which_armor(mon, W_SADDLE)))
  22.              && (!rn2(10)
  23.                  || (obj->otyp == POT_WATER
  24.                      && ((rnl(10) > 7 && obj->cursed)
  25.                          || (rnl(10) < 4 && obj->blessed) || !rn2(3)))))
  26.              hit_saddle = TRUE;
  27.          distance = distu(mon->mx, mon->my);
  28.          if (!cansee(mon->mx, mon->my))
  29.              pline("Crash!");
  30.          else {
  31.              char *mnam = mon_nam(mon);
  32.              char buf[BUFSZ];
  33.  
  34.              if (hit_saddle && saddle) {
  35.                  Sprintf(buf, "%s saddle",
  36.                          s_suffix(x_monnam(mon, ARTICLE_THE, (char *) 0,
  37.                                            (SUPPRESS_IT | SUPPRESS_SADDLE),
  38.                                            FALSE)));
  39.              } else if (has_head(mon->data)) {
  40.                  Sprintf(buf, "%s %s", s_suffix(mnam),
  41.                          (notonhead ? "body" : "head"));
  42.              } else {
  43.                  Strcpy(buf, mnam);
  44.              }
  45.              pline_The("%s crashes on %s and breaks into shards.", botlnam,
  46.                        buf);
  47.          }
  48.          if (rn2(5) && mon->mhp > 1 && !hit_saddle)
  49.              mon->mhp--;
  50.      }
  51.  
  52.      /* oil doesn't instantly evaporate; Neither does a saddle hit */
  53.      if (obj->otyp != POT_OIL && !hit_saddle && cansee(mon->mx, mon->my))
  54.          pline("%s.", Tobjnam(obj, "evaporate"));
  55.  
  56.      if (isyou) {
  57.          switch (obj->otyp) {
  58.          case POT_OIL:
  59.              if (obj->lamplit)
  60.                  explode_oil(obj, u.ux, u.uy);
  61.              break;
  62.          case POT_POLYMORPH:
  63.              You_feel("a little %s.", Hallucination ? "normal" : "strange");
  64.              if (!Unchanging && !Antimagic)
  65.                  polyself(0);
  66.              break;
  67.          case POT_ACID:
  68.              if (!Acid_resistance) {
  69.                  int dmg;
  70.                  pline("This burns%s!",
  71.                        obj->blessed ? " a little"
  72.                                     : obj->cursed ? " a lot" : "");
  73.                  dmg = d(obj->cursed ? 2 : 1, obj->blessed ? 4 : 8);
  74.                  losehp(Maybe_Half_Phys(dmg), "potion of acid", KILLED_BY_AN);
  75.              }
  76.              break;
  77.          }
  78.      } else if (hit_saddle && saddle) {
  79.          char *mnam, buf[BUFSZ], saddle_glows[BUFSZ];
  80.          boolean affected = FALSE;
  81.          boolean useeit = !Blind && canseemon(mon) && cansee(mon->mx, mon->my);
  82.  
  83.          mnam = x_monnam(mon, ARTICLE_THE, (char *) 0,
  84.                          (SUPPRESS_IT | SUPPRESS_SADDLE), FALSE);
  85.          Sprintf(buf, "%s", upstart(s_suffix(mnam)));
  86.  
  87.          switch (obj->otyp) {
  88.          case POT_WATER:
  89.              Sprintf(saddle_glows, "%s %s", buf, aobjnam(saddle, "glow"));
  90.              affected = H2Opotion_dip(obj, saddle, useeit, saddle_glows);
  91.              break;
  92.          case POT_POLYMORPH:
  93.              /* Do we allow the saddle to polymorph? */
  94.              break;
  95.          }
  96.          if (useeit && !affected)
  97.              pline("%s %s wet.", buf, aobjnam(saddle, "get"));
  98.      } else {
  99.          boolean angermon = TRUE;
  100.  
  101.          if (!your_fault)
  102.              angermon = FALSE;
  103.          switch (obj->otyp) {
  104.          case POT_HEALING:
  105.          case POT_EXTRA_HEALING:
  106.          case POT_FULL_HEALING:
  107.              if (mon->data == &mons[PM_PESTILENCE])
  108.                  goto do_illness;
  109.          /*FALLTHRU*/
  110.          case POT_RESTORE_ABILITY:
  111.          case POT_GAIN_ABILITY:
  112.          do_healing:
  113.              angermon = FALSE;
  114.              if (mon->mhp < mon->mhpmax) {
  115.                  mon->mhp = mon->mhpmax;
  116.                  if (canseemon(mon))
  117.                      pline("%s looks sound and hale again.", Monnam(mon));
  118.              }
  119.              break;
  120.          case POT_SICKNESS:
  121.              if (mon->data == &mons[PM_PESTILENCE])
  122.                  goto do_healing;
  123.              if (dmgtype(mon->data, AD_DISE)
  124.                  /* won't happen, see prior goto */
  125.                  || dmgtype(mon->data, AD_PEST)
  126.                  /* most common case */
  127.                  || resists_poison(mon)) {
  128.                  if (canseemon(mon))
  129.                      pline("%s looks unharmed.", Monnam(mon));
  130.                  break;
  131.              }
  132.          do_illness:
  133.              if ((mon->mhpmax > 3) && !resist(mon, POTION_CLASS, 0, NOTELL))
  134.                  mon->mhpmax /= 2;
  135.              if ((mon->mhp > 2) && !resist(mon, POTION_CLASS, 0, NOTELL))
  136.                  mon->mhp /= 2;
  137.              if (mon->mhp > mon->mhpmax)
  138.                  mon->mhp = mon->mhpmax;
  139.              if (canseemon(mon))
  140.                  pline("%s looks rather ill.", Monnam(mon));
  141.              break;
  142.          case POT_CONFUSION:
  143.          case POT_BOOZE:
  144.              if (!resist(mon, POTION_CLASS, 0, NOTELL))
  145.                  mon->mconf = TRUE;
  146.              break;
  147.          case POT_INVISIBILITY:
  148.              angermon = FALSE;
  149.              mon_set_minvis(mon);
  150.              break;
  151.          case POT_SLEEPING:
  152.              /* wakeup() doesn't rouse victims of temporary sleep */
  153.              if (sleep_monst(mon, rnd(12), POTION_CLASS)) {
  154.                  pline("%s falls asleep.", Monnam(mon));
  155.                  slept_monst(mon);
  156.              }
  157.              break;
  158.          case POT_PARALYSIS:
  159.              if (mon->mcanmove) {
  160.                  /* really should be rnd(5) for consistency with players
  161.                   * breathing potions, but...
  162.                   */
  163.                  paralyze_monst(mon, rnd(25));
  164.              }
  165.              break;
  166.          case POT_SPEED:
  167.              angermon = FALSE;
  168.              mon_adjust_speed(mon, 1, obj);
  169.              break;
  170.          case POT_BLINDNESS:
  171.              if (haseyes(mon->data)) {
  172.                  register int btmp = 64 + rn2(32)
  173.                              + rn2(32) * !resist(mon, POTION_CLASS, 0, NOTELL);
  174.  
  175.                  btmp += mon->mblinded;
  176.                  mon->mblinded = min(btmp, 127);
  177.                  mon->mcansee = 0;
  178.              }
  179.              break;
  180.          case POT_WATER:
  181.              if (is_undead(mon->data) || is_demon(mon->data)
  182.                  || is_were(mon->data) || is_vampshifter(mon)) {
  183.                  if (obj->blessed) {
  184.                      pline("%s %s in pain!", Monnam(mon),
  185.                            is_silent(mon->data) ? "writhes" : "shrieks");
  186.                      if (!is_silent(mon->data))
  187.                          wake_nearto(mon->mx, mon->my, mon->data->mlevel * 10);
  188.                      mon->mhp -= d(2, 6);
  189.                      /* should only be by you */
  190.                      if (mon->mhp < 1)
  191.                          killed(mon);
  192.                      else if (is_were(mon->data) && !is_human(mon->data))
  193.                          new_were(mon); /* revert to human */
  194.                  } else if (obj->cursed) {
  195.                      angermon = FALSE;
  196.                      if (canseemon(mon))
  197.                          pline("%s looks healthier.", Monnam(mon));
  198.                      mon->mhp += d(2, 6);
  199.                      if (mon->mhp > mon->mhpmax)
  200.                          mon->mhp = mon->mhpmax;
  201.                      if (is_were(mon->data) && is_human(mon->data)
  202.                          && !Protection_from_shape_changers)
  203.                          new_were(mon); /* transform into beast */
  204.                  }
  205.              } else if (mon->data == &mons[PM_GREMLIN]) {
  206.                  angermon = FALSE;
  207.                  (void) split_mon(mon, (struct monst *) 0);
  208.              } else if (mon->data == &mons[PM_IRON_GOLEM]) {
  209.                  if (canseemon(mon))
  210.                      pline("%s rusts.", Monnam(mon));
  211.                  mon->mhp -= d(1, 6);
  212.                  /* should only be by you */
  213.                  if (mon->mhp < 1)
  214.                      killed(mon);
  215.              }
  216.              break;
  217.          case POT_OIL:
  218.              if (obj->lamplit)
  219.                  explode_oil(obj, mon->mx, mon->my);
  220.              break;
  221.          case POT_ACID:
  222.              if (!resists_acid(mon) && !resist(mon, POTION_CLASS, 0, NOTELL)) {
  223.                  pline("%s %s in pain!", Monnam(mon),
  224.                        is_silent(mon->data) ? "writhes" : "shrieks");
  225.                  if (!is_silent(mon->data))
  226.                      wake_nearto(mon->mx, mon->my, mon->data->mlevel * 10);
  227.                  mon->mhp -= d(obj->cursed ? 2 : 1, obj->blessed ? 4 : 8);
  228.                  if (mon->mhp < 1) {
  229.                      if (your_fault)
  230.                          killed(mon);
  231.                      else
  232.                          monkilled(mon, "", AD_ACID);
  233.                  }
  234.              }
  235.              break;
  236.          case POT_POLYMORPH:
  237.              (void) bhitm(mon, obj);
  238.              break;
  239.          /*
  240.          case POT_GAIN_LEVEL:
  241.          case POT_LEVITATION:
  242.          case POT_FRUIT_JUICE:
  243.          case POT_MONSTER_DETECTION:
  244.          case POT_OBJECT_DETECTION:
  245.              break;
  246.          */
  247.          }
  248.          if (angermon)
  249.              wakeup(mon);
  250.          else
  251.              mon->msleeping = 0;
  252.      }
  253.  
  254.      /* Note: potionbreathe() does its own docall() */
  255.      if ((distance == 0 || ((distance < 3) && rn2(5)))
  256.          && (!breathless(youmonst.data) || haseyes(youmonst.data)))
  257.          potionbreathe(obj);
  258.      else if (obj->dknown && !objects[obj->otyp].oc_name_known
  259.               && !objects[obj->otyp].oc_uname && cansee(mon->mx, mon->my))
  260.          docall(obj);
  261.      if (*u.ushops && obj->unpaid) {
  262.          struct monst *shkp = shop_keeper(*in_rooms(u.ux, u.uy, SHOPBASE));
  263.  
  264.          if (shkp)
  265.              (void) stolen_value(obj, u.ux, u.uy, (boolean) shkp->mpeaceful,
  266.                                  FALSE);
  267.          else
  268.              obj->unpaid = 0;
  269.      }
  270.      obfree(obj, (struct obj *) 0);
  271.  }
  272.  

potionbreathe

  1.  /* vapors are inhaled or get in your eyes */
  2.  void
  3.  potionbreathe(obj)
  4.  register struct obj *obj;
  5.  {
  6.      register int i, ii, isdone, kn = 0;
  7.  
  8.      switch (obj->otyp) {
  9.      case POT_RESTORE_ABILITY:
  10.      case POT_GAIN_ABILITY:
  11.          if (obj->cursed) {
  12.              if (!breathless(youmonst.data))
  13.                  pline("Ulch!  That potion smells terrible!");
  14.              else if (haseyes(youmonst.data)) {
  15.                  const char *eyes = body_part(EYE);
  16.  
  17.                  if (eyecount(youmonst.data) != 1)
  18.                      eyes = makeplural(eyes);
  19.                  Your("%s %s!", eyes, vtense(eyes, "sting"));
  20.              }
  21.              break;
  22.          } else {
  23.              i = rn2(A_MAX); /* start at a random point */
  24.              for (isdone = ii = 0; !isdone && ii < A_MAX; ii++) {
  25.                  if (ABASE(i) < AMAX(i)) {
  26.                      ABASE(i)++;
  27.                      /* only first found if not blessed */
  28.                      isdone = !(obj->blessed);
  29.                      context.botl = 1;
  30.                  }
  31.                  if (++i >= A_MAX)
  32.                      i = 0;
  33.              }
  34.          }
  35.          break;
  36.      case POT_FULL_HEALING:
  37.          if (Upolyd && u.mh < u.mhmax)
  38.              u.mh++, context.botl = 1;
  39.          if (u.uhp < u.uhpmax)
  40.              u.uhp++, context.botl = 1;
  41.          /*FALLTHRU*/
  42.      case POT_EXTRA_HEALING:
  43.          if (Upolyd && u.mh < u.mhmax)
  44.              u.mh++, context.botl = 1;
  45.          if (u.uhp < u.uhpmax)
  46.              u.uhp++, context.botl = 1;
  47.          /*FALLTHRU*/
  48.      case POT_HEALING:
  49.          if (Upolyd && u.mh < u.mhmax)
  50.              u.mh++, context.botl = 1;
  51.          if (u.uhp < u.uhpmax)
  52.              u.uhp++, context.botl = 1;
  53.          exercise(A_CON, TRUE);
  54.          break;
  55.      case POT_SICKNESS:
  56.          if (!Role_if(PM_HEALER)) {
  57.              if (Upolyd) {
  58.                  if (u.mh <= 5)
  59.                      u.mh = 1;
  60.                  else
  61.                      u.mh -= 5;
  62.              } else {
  63.                  if (u.uhp <= 5)
  64.                      u.uhp = 1;
  65.                  else
  66.                      u.uhp -= 5;
  67.              }
  68.              context.botl = 1;
  69.              exercise(A_CON, FALSE);
  70.          }
  71.          break;
  72.      case POT_HALLUCINATION:
  73.          You("have a momentary vision.");
  74.          break;
  75.      case POT_CONFUSION:
  76.      case POT_BOOZE:
  77.          if (!Confusion)
  78.              You_feel("somewhat dizzy.");
  79.          make_confused(itimeout_incr(HConfusion, rnd(5)), FALSE);
  80.          break;
  81.      case POT_INVISIBILITY:
  82.          if (!Blind && !Invis) {
  83.              kn++;
  84.              pline("For an instant you %s!",
  85.                    See_invisible ? "could see right through yourself"
  86.                                  : "couldn't see yourself");
  87.          }
  88.          break;
  89.      case POT_PARALYSIS:
  90.          kn++;
  91.          if (!Free_action) {
  92.              pline("%s seems to be holding you.", Something);
  93.              nomul(-rnd(5));
  94.              multi_reason = "frozen by a potion";
  95.              nomovemsg = You_can_move_again;
  96.              exercise(A_DEX, FALSE);
  97.          } else
  98.              You("stiffen momentarily.");
  99.          break;
  100.      case POT_SLEEPING:
  101.          kn++;
  102.          if (!Free_action && !Sleep_resistance) {
  103.              You_feel("rather tired.");
  104.              nomul(-rnd(5));
  105.              multi_reason = "sleeping off a magical draught";
  106.              nomovemsg = You_can_move_again;
  107.              exercise(A_DEX, FALSE);
  108.          } else
  109.              You("yawn.");
  110.          break;
  111.      case POT_SPEED:
  112.          if (!Fast)
  113.              Your("knees seem more flexible now.");
  114.          incr_itimeout(&HFast, rnd(5));
  115.          exercise(A_DEX, TRUE);
  116.          break;
  117.      case POT_BLINDNESS:
  118.          if (!Blind && !Unaware) {
  119.              kn++;
  120.              pline("It suddenly gets dark.");
  121.          }
  122.          make_blinded(itimeout_incr(Blinded, rnd(5)), FALSE);
  123.          if (!Blind && !Unaware)
  124.              Your1(vision_clears);
  125.          break;
  126.      case POT_WATER:
  127.          if (u.umonnum == PM_GREMLIN) {
  128.              (void) split_mon(&youmonst, (struct monst *) 0);
  129.          } else if (u.ulycn >= LOW_PM) {
  130.              /* vapor from [un]holy water will trigger
  131.                 transformation but won't cure lycanthropy */
  132.              if (obj->blessed && youmonst.data == &mons[u.ulycn])
  133.                  you_unwere(FALSE);
  134.              else if (obj->cursed && !Upolyd)
  135.                  you_were();
  136.          }
  137.          break;
  138.      case POT_ACID:
  139.      case POT_POLYMORPH:
  140.          exercise(A_CON, FALSE);
  141.          break;
  142.      /*
  143.      case POT_GAIN_LEVEL:
  144.      case POT_LEVITATION:
  145.      case POT_FRUIT_JUICE:
  146.      case POT_MONSTER_DETECTION:
  147.      case POT_OBJECT_DETECTION:
  148.      case POT_OIL:
  149.          break;
  150.       */
  151.      }
  152.      /* note: no obfree() */
  153.      if (obj->dknown) {
  154.          if (kn)
  155.              makeknown(obj->otyp);
  156.          else if (!objects[obj->otyp].oc_name_known
  157.                   && !objects[obj->otyp].oc_uname)
  158.              docall(obj);
  159.      }
  160.  }
  161.  

mixtype

  1.  /* returns the potion type when o1 is dipped in o2 */
  2.  STATIC_OVL short
  3.  mixtype(o1, o2)
  4.  register struct obj *o1, *o2;
  5.  {
  6.      /* cut down on the number of cases below */
  7.      if (o1->oclass == POTION_CLASS
  8.          && (o2->otyp == POT_GAIN_LEVEL || o2->otyp == POT_GAIN_ENERGY
  9.              || o2->otyp == POT_HEALING || o2->otyp == POT_EXTRA_HEALING
  10.              || o2->otyp == POT_FULL_HEALING || o2->otyp == POT_ENLIGHTENMENT
  11.              || o2->otyp == POT_FRUIT_JUICE)) {
  12.          struct obj *swp;
  13.  
  14.          swp = o1;
  15.          o1 = o2;
  16.          o2 = swp;
  17.      }
  18.  
  19.      switch (o1->otyp) {
  20.      case POT_HEALING:
  21.          switch (o2->otyp) {
  22.          case POT_SPEED:
  23.          case POT_GAIN_LEVEL:
  24.          case POT_GAIN_ENERGY:
  25.              return POT_EXTRA_HEALING;
  26.          }
  27.      case POT_EXTRA_HEALING:
  28.          switch (o2->otyp) {
  29.          case POT_GAIN_LEVEL:
  30.          case POT_GAIN_ENERGY:
  31.              return POT_FULL_HEALING;
  32.          }
  33.      case POT_FULL_HEALING:
  34.          switch (o2->otyp) {
  35.          case POT_GAIN_LEVEL:
  36.          case POT_GAIN_ENERGY:
  37.              return POT_GAIN_ABILITY;
  38.          }
  39.      case UNICORN_HORN:
  40.          switch (o2->otyp) {
  41.          case POT_SICKNESS:
  42.              return POT_FRUIT_JUICE;
  43.          case POT_HALLUCINATION:
  44.          case POT_BLINDNESS:
  45.          case POT_CONFUSION:
  46.              return POT_WATER;
  47.          }
  48.          break;
  49.      case AMETHYST: /* "a-methyst" == "not intoxicated" */
  50.          if (o2->otyp == POT_BOOZE)
  51.              return POT_FRUIT_JUICE;
  52.          break;
  53.      case POT_GAIN_LEVEL:
  54.      case POT_GAIN_ENERGY:
  55.          switch (o2->otyp) {
  56.          case POT_CONFUSION:
  57.              return (rn2(3) ? POT_BOOZE : POT_ENLIGHTENMENT);
  58.          case POT_HEALING:
  59.              return POT_EXTRA_HEALING;
  60.          case POT_EXTRA_HEALING:
  61.              return POT_FULL_HEALING;
  62.          case POT_FULL_HEALING:
  63.              return POT_GAIN_ABILITY;
  64.          case POT_FRUIT_JUICE:
  65.              return POT_SEE_INVISIBLE;
  66.          case POT_BOOZE:
  67.              return POT_HALLUCINATION;
  68.          }
  69.          break;
  70.      case POT_FRUIT_JUICE:
  71.          switch (o2->otyp) {
  72.          case POT_SICKNESS:
  73.              return POT_SICKNESS;
  74.          case POT_SPEED:
  75.              return POT_BOOZE;
  76.          case POT_GAIN_LEVEL:
  77.          case POT_GAIN_ENERGY:
  78.              return POT_SEE_INVISIBLE;
  79.          }
  80.          break;
  81.      case POT_ENLIGHTENMENT:
  82.          switch (o2->otyp) {
  83.          case POT_LEVITATION:
  84.              if (rn2(3))
  85.                  return POT_GAIN_LEVEL;
  86.              break;
  87.          case POT_FRUIT_JUICE:
  88.              return POT_BOOZE;
  89.          case POT_BOOZE:
  90.              return POT_CONFUSION;
  91.          }
  92.          break;
  93.      }
  94.  
  95.      return 0;
  96.  }
  97.  

dodip

  1.  /* #dip command */
  2.  int
  3.  dodip()
  4.  {
  5.      register struct obj *potion, *obj;
  6.      struct obj *singlepotion;
  7.      uchar here;
  8.      char allowall[2];
  9.      short mixture;
  10.      char qbuf[QBUFSZ], qtoo[QBUFSZ];
  11.  
  12.      allowall[0] = ALL_CLASSES;
  13.      allowall[1] = '\0';
  14.      if (!(obj = getobj(allowall, "dip")))
  15.          return 0;
  16.      if (inaccessible_equipment(obj, "dip", FALSE))
  17.          return 0;
  18.  
  19.      Sprintf(qbuf, "dip %s into", thesimpleoname(obj));
  20.      here = levl[u.ux][u.uy].typ;
  21.      /* Is there a fountain to dip into here? */
  22.      if (IS_FOUNTAIN(here)) {
  23.          /* "Dip <the object> into the fountain?" */
  24.          Sprintf(qtoo, "%s the fountain?", qbuf);
  25.          if (yn(upstart(qtoo)) == 'y') {
  26.              dipfountain(obj);
  27.              return 1;
  28.          }
  29.      } else if (is_pool(u.ux, u.uy)) {
  30.          const char *pooltype = waterbody_name(u.ux, u.uy);
  31.  
  32.          /* "Dip <the object> into the {pool, moat, &c}?" */
  33.          Sprintf(qtoo, "%s the %s?", qbuf, pooltype);
  34.          if (yn(upstart(qtoo)) == 'y') {
  35.              if (Levitation) {
  36.                  floating_above(pooltype);
  37.              } else if (u.usteed && !is_swimmer(u.usteed->data)
  38.                         && P_SKILL(P_RIDING) < P_BASIC) {
  39.                  rider_cant_reach(); /* not skilled enough to reach */
  40.              } else {
  41.                  if (obj->otyp == POT_ACID)
  42.                      obj->in_use = 1;
  43.                  if (water_damage(obj, 0, TRUE) != ER_DESTROYED && obj->in_use)
  44.                      useup(obj);
  45.              }
  46.              return 1;
  47.          }
  48.      }
  49.  
  50.      /* "What do you want to dip <the object> into?" */
  51.      potion = getobj(beverages, qbuf); /* "dip into" */
  52.      if (!potion)
  53.          return 0;
  54.      if (potion == obj && potion->quan == 1L) {
  55.          pline("That is a potion bottle, not a Klein bottle!");
  56.          return 0;
  57.      }
  58.      potion->in_use = TRUE; /* assume it will be used up */
  59.      if (potion->otyp == POT_WATER) {
  60.          boolean useeit = !Blind || (obj == ublindf && Blindfolded_only);
  61.          const char *obj_glows = Yobjnam2(obj, "glow");
  62.  
  63.          if (H2Opotion_dip(potion, obj, useeit, obj_glows))
  64.              goto poof;
  65.      } else if (obj->otyp == POT_POLYMORPH || potion->otyp == POT_POLYMORPH) {
  66.          /* some objects can't be polymorphed */
  67.          if (obj->otyp == potion->otyp /* both POT_POLY */
  68.              || obj->otyp == WAN_POLYMORPH || obj->otyp == SPE_POLYMORPH
  69.              || obj == uball || obj == uskin
  70.              || obj_resists(obj->otyp == POT_POLYMORPH ? potion : obj,
  71.                             5, 95)) {
  72.              pline1(nothing_happens);
  73.          } else {
  74.              boolean was_wep, was_swapwep, was_quiver;
  75.              short save_otyp = obj->otyp;
  76.  
  77.              /* KMH, conduct */
  78.              u.uconduct.polypiles++;
  79.  
  80.              was_wep = (obj == uwep);
  81.              was_swapwep = (obj == uswapwep);
  82.              was_quiver = (obj == uquiver);
  83.  
  84.              obj = poly_obj(obj, STRANGE_OBJECT);
  85.  
  86.              if (was_wep)
  87.                  setuwep(obj);
  88.              else if (was_swapwep)
  89.                  setuswapwep(obj);
  90.              else if (was_quiver)
  91.                  setuqwep(obj);
  92.  
  93.              if (obj->otyp != save_otyp) {
  94.                  makeknown(POT_POLYMORPH);
  95.                  useup(potion);
  96.                  prinv((char *) 0, obj, 0L);
  97.                  return 1;
  98.              } else {
  99.                  pline("Nothing seems to happen.");
  100.                  goto poof;
  101.              }
  102.          }
  103.          potion->in_use = FALSE; /* didn't go poof */
  104.          return 1;
  105.      } else if (obj->oclass == POTION_CLASS && obj->otyp != potion->otyp) {
  106.          long amt = obj->quan;
  107.  
  108.          Strcpy(qbuf, "The");
  109.          if (amt > (objects[potion->otyp].oc_magic ? 2L : 9L)) {
  110.              /* trying to dip multiple potions will usually affect only a
  111.                 subset; pick an amount between 2 and min(N,9), inclusive */
  112.              amt -= 1L;
  113.              do {
  114.                  amt = (long) rnd((int) amt);
  115.              } while (amt >= 9L);
  116.              amt += 1L;
  117.              if (amt < obj->quan) {
  118.                  obj = splitobj(obj, amt);
  119.                  Sprintf(qbuf, "%ld of the", obj->quan);
  120.              }
  121.          }
  122.          /* [N of] the {obj(s)} mix(es) with [one of] {the potion}... */
  123.          pline("%s %s %s with %s%s...", qbuf, simpleonames(obj),
  124.                otense(obj, "mix"), (potion->quan > 1L) ? "one of " : "",
  125.                thesimpleoname(potion));
  126.          /* Mixing potions is dangerous...
  127.             KMH, balance patch -- acid is particularly unstable */
  128.          if (obj->cursed || obj->otyp == POT_ACID || !rn2(10)) {
  129.              /* it would be better to use up the whole stack in advance
  130.                 of the message, but we can't because we need to keep it
  131.                 around for potionbreathe() [and we can't set obj->in_use
  132.                 to 'amt' because that's not implemented] */
  133.              obj->in_use = 1;
  134.              pline("BOOM!  They explode!");
  135.              wake_nearto(u.ux, u.uy, (BOLT_LIM + 1) * (BOLT_LIM + 1));
  136.              exercise(A_STR, FALSE);
  137.              if (!breathless(youmonst.data) || haseyes(youmonst.data))
  138.                  potionbreathe(obj);
  139.              useupall(obj);
  140.              useup(potion);
  141.              losehp((int) (amt + rnd(9)), /* not physical damage */
  142.                     "alchemic blast", KILLED_BY_AN);
  143.              return 1;
  144.          }
  145.  
  146.          obj->blessed = obj->cursed = obj->bknown = 0;
  147.          if (Blind || Hallucination)
  148.              obj->dknown = 0;
  149.  
  150.          if ((mixture = mixtype(obj, potion)) != 0) {
  151.              obj->otyp = mixture;
  152.          } else {
  153.              switch (obj->odiluted ? 1 : rnd(8)) {
  154.              case 1:
  155.                  obj->otyp = POT_WATER;
  156.                  break;
  157.              case 2:
  158.              case 3:
  159.                  obj->otyp = POT_SICKNESS;
  160.                  break;
  161.              case 4: {
  162.                  struct obj *otmp = mkobj(POTION_CLASS, FALSE);
  163.  
  164.                  obj->otyp = otmp->otyp;
  165.                  obfree(otmp, (struct obj *) 0);
  166.                  break;
  167.              }
  168.              default:
  169.                  useupall(obj);
  170.                  useup(potion);
  171.                  if (!Blind)
  172.                      pline_The("mixture glows brightly and evaporates.");
  173.                  return 1;
  174.              }
  175.          }
  176.          obj->odiluted = (obj->otyp != POT_WATER);
  177.  
  178.          if (obj->otyp == POT_WATER && !Hallucination) {
  179.              pline_The("mixture bubbles%s.", Blind ? "" : ", then clears");
  180.          } else if (!Blind) {
  181.              pline_The("mixture looks %s.",
  182.                        hcolor(OBJ_DESCR(objects[obj->otyp])));
  183.          }
  184.  
  185.          useup(potion);
  186.          /* this is required when 'obj' was split off from a bigger stack,
  187.             so that 'obj' will now be assigned its own inventory slot;
  188.             it has a side-effect of merging 'obj' into another compatible
  189.             stack if there is one, so we do it even when no split has
  190.             been made in order to get the merge result for both cases;
  191.             as a consequence, mixing while Fumbling drops the mixture */
  192.          freeinv(obj);
  193.          (void) hold_another_object(obj, "You drop %s!", doname(obj),
  194.                                     (const char *) 0);
  195.          return 1;
  196.      }
  197.  
  198.      if (potion->otyp == POT_ACID && obj->otyp == CORPSE
  199.          && obj->corpsenm == PM_LICHEN && !Blind) {
  200.          pline("%s %s %s around the edges.", The(cxname(obj)),
  201.                otense(obj, "turn"),
  202.                potion->odiluted ? hcolor(NH_ORANGE) : hcolor(NH_RED));
  203.          potion->in_use = FALSE; /* didn't go poof */
  204.          return 1;
  205.      }
  206.  
  207.      if (potion->otyp == POT_WATER && obj->otyp == TOWEL) {
  208.          pline_The("towel soaks it up!");
  209.          /* wetting towel already done via water_damage() in H2Opotion_dip */
  210.          goto poof;
  211.      }
  212.  
  213.      if (is_poisonable(obj)) {
  214.          if (potion->otyp == POT_SICKNESS && !obj->opoisoned) {
  215.              char buf[BUFSZ];
  216.  
  217.              if (potion->quan > 1L)
  218.                  Sprintf(buf, "One of %s", the(xname(potion)));
  219.              else
  220.                  Strcpy(buf, The(xname(potion)));
  221.              pline("%s forms a coating on %s.", buf, the(xname(obj)));
  222.              obj->opoisoned = TRUE;
  223.              goto poof;
  224.          } else if (obj->opoisoned && (potion->otyp == POT_HEALING
  225.                                        || potion->otyp == POT_EXTRA_HEALING
  226.                                        || potion->otyp == POT_FULL_HEALING)) {
  227.              pline("A coating wears off %s.", the(xname(obj)));
  228.              obj->opoisoned = 0;
  229.              goto poof;
  230.          }
  231.      }
  232.  
  233.      if (potion->otyp == POT_ACID) {
  234.          if (erode_obj(obj, 0, ERODE_CORRODE, EF_GREASE) != ER_NOTHING)
  235.              goto poof;
  236.      }
  237.  
  238.      if (potion->otyp == POT_OIL) {
  239.          boolean wisx = FALSE;
  240.  
  241.          if (potion->lamplit) { /* burning */
  242.              fire_damage(obj, TRUE, u.ux, u.uy);
  243.          } else if (potion->cursed) {
  244.              pline_The("potion spills and covers your %s with oil.",
  245.                        makeplural(body_part(FINGER)));
  246.              incr_itimeout(&Glib, d(2, 10));
  247.          } else if (obj->oclass != WEAPON_CLASS && !is_weptool(obj)) {
  248.              /* the following cases apply only to weapons */
  249.              goto more_dips;
  250.              /* Oil removes rust and corrosion, but doesn't unburn.
  251.               * Arrows, etc are classed as metallic due to arrowhead
  252.               * material, but dipping in oil shouldn't repair them.
  253.               */
  254.          } else if ((!is_rustprone(obj) && !is_corrodeable(obj))
  255.                     || is_ammo(obj) || (!obj->oeroded && !obj->oeroded2)) {
  256.              /* uses up potion, doesn't set obj->greased */
  257.              pline("%s %s with an oily sheen.", Yname2(obj),
  258.                    otense(obj, "gleam"));
  259.          } else {
  260.              pline("%s %s less %s.", Yname2(obj), otense(obj, "are"),
  261.                    (obj->oeroded && obj->oeroded2)
  262.                        ? "corroded and rusty"
  263.                        : obj->oeroded ? "rusty" : "corroded");
  264.              if (obj->oeroded > 0)
  265.                  obj->oeroded--;
  266.              if (obj->oeroded2 > 0)
  267.                  obj->oeroded2--;
  268.              wisx = TRUE;
  269.          }
  270.          exercise(A_WIS, wisx);
  271.          makeknown(potion->otyp);
  272.          useup(potion);
  273.          return 1;
  274.      }
  275.  more_dips:
  276.  
  277.      /* Allow filling of MAGIC_LAMPs to prevent identification by player */
  278.      if ((obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP)
  279.          && (potion->otyp == POT_OIL)) {
  280.          /* Turn off engine before fueling, turn off fuel too :-)  */
  281.          if (obj->lamplit || potion->lamplit) {
  282.              useup(potion);
  283.              explode(u.ux, u.uy, 11, d(6, 6), 0, EXPL_FIERY);
  284.              exercise(A_WIS, FALSE);
  285.              return 1;
  286.          }
  287.          /* Adding oil to an empty magic lamp renders it into an oil lamp */
  288.          if ((obj->otyp == MAGIC_LAMP) && obj->spe == 0) {
  289.              obj->otyp = OIL_LAMP;
  290.              obj->age = 0;
  291.          }
  292.          if (obj->age > 1000L) {
  293.              pline("%s %s full.", Yname2(obj), otense(obj, "are"));
  294.              potion->in_use = FALSE; /* didn't go poof */
  295.          } else {
  296.              You("fill %s with oil.", yname(obj));
  297.              check_unpaid(potion);        /* Yendorian Fuel Tax */
  298.              obj->age += 2 * potion->age; /* burns more efficiently */
  299.              if (obj->age > 1500L)
  300.                  obj->age = 1500L;
  301.              useup(potion);
  302.              exercise(A_WIS, TRUE);
  303.          }
  304.          makeknown(POT_OIL);
  305.          obj->spe = 1;
  306.          update_inventory();
  307.          return 1;
  308.      }
  309.  
  310.      potion->in_use = FALSE; /* didn't go poof */
  311.      if ((obj->otyp == UNICORN_HORN || obj->otyp == AMETHYST)
  312.          && (mixture = mixtype(obj, potion)) != 0) {
  313.          char oldbuf[BUFSZ], newbuf[BUFSZ];
  314.          short old_otyp = potion->otyp;
  315.          boolean old_dknown = FALSE;
  316.          boolean more_than_one = potion->quan > 1L;
  317.  
  318.          oldbuf[0] = '\0';
  319.          if (potion->dknown) {
  320.              old_dknown = TRUE;
  321.              Sprintf(oldbuf, "%s ", hcolor(OBJ_DESCR(objects[potion->otyp])));
  322.          }
  323.          /* with multiple merged potions, split off one and
  324.             just clear it */
  325.          if (potion->quan > 1L) {
  326.              singlepotion = splitobj(potion, 1L);
  327.          } else
  328.              singlepotion = potion;
  329.  
  330.          costly_alteration(singlepotion, COST_NUTRLZ);
  331.          singlepotion->otyp = mixture;
  332.          singlepotion->blessed = 0;
  333.          if (mixture == POT_WATER)
  334.              singlepotion->cursed = singlepotion->odiluted = 0;
  335.          else
  336.              singlepotion->cursed = obj->cursed; /* odiluted left as-is */
  337.          singlepotion->bknown = FALSE;
  338.          if (Blind) {
  339.              singlepotion->dknown = FALSE;
  340.          } else {
  341.              singlepotion->dknown = !Hallucination;
  342.              if (mixture == POT_WATER && singlepotion->dknown)
  343.                  Sprintf(newbuf, "clears");
  344.              else
  345.                  Sprintf(newbuf, "turns %s",
  346.                          hcolor(OBJ_DESCR(objects[mixture])));
  347.              pline_The("%spotion%s %s.", oldbuf,
  348.                        more_than_one ? " that you dipped into" : "", newbuf);
  349.              if (!objects[old_otyp].oc_uname
  350.                  && !objects[old_otyp].oc_name_known && old_dknown) {
  351.                  struct obj fakeobj;
  352.                  fakeobj = zeroobj;
  353.                  fakeobj.dknown = 1;
  354.                  fakeobj.otyp = old_otyp;
  355.                  fakeobj.oclass = POTION_CLASS;
  356.                  docall(&fakeobj);
  357.              }
  358.          }
  359.          obj_extract_self(singlepotion);
  360.          singlepotion =
  361.              hold_another_object(singlepotion, "You juggle and drop %s!",
  362.                                  doname(singlepotion), (const char *) 0);
  363.          update_inventory();
  364.          return 1;
  365.      }
  366.  
  367.      pline("Interesting...");
  368.      return 1;
  369.  
  370.  poof:
  371.      if (!objects[potion->otyp].oc_name_known
  372.          && !objects[potion->otyp].oc_uname)
  373.          docall(potion);
  374.      useup(potion);
  375.      return 1;
  376.  }
  377.  

mongrantswish

  1.  /* *monp grants a wish and then leaves the game */
  2.  void
  3.  mongrantswish(monp)
  4.  struct monst **monp;
  5.  {
  6.      struct monst *mon = *monp;
  7.      int mx = mon->mx, my = mon->my, glyph = glyph_at(mx, my);
  8.  
  9.      /* remove the monster first in case wish proves to be fatal
  10.         (blasted by artifact), to keep it out of resulting bones file */
  11.      mongone(mon);
  12.      *monp = 0; /* inform caller that monster is gone */
  13.      /* hide that removal from player--map is visible during wish prompt */
  14.      tmp_at(DISP_ALWAYS, glyph);
  15.      tmp_at(mx, my);
  16.      /* grant the wish */
  17.      makewish();
  18.      /* clean up */
  19.      tmp_at(DISP_END, 0);
  20.  }
  21.  

djinni_from_bottle

  1.  void
  2.  djinni_from_bottle(obj)
  3.  struct obj *obj;
  4.  {
  5.      struct monst *mtmp;
  6.      int chance;
  7.  
  8.      if (!(mtmp = makemon(&mons[PM_DJINNI], u.ux, u.uy, NO_MM_FLAGS))) {
  9.          pline("It turns out to be empty.");
  10.          return;
  11.      }
  12.  
  13.      if (!Blind) {
  14.          pline("In a cloud of smoke, %s emerges!", a_monnam(mtmp));
  15.          pline("%s speaks.", Monnam(mtmp));
  16.      } else {
  17.          You("smell acrid fumes.");
  18.          pline("%s speaks.", Something);
  19.      }
  20.  
  21.      chance = rn2(5);
  22.      if (obj->blessed)
  23.          chance = (chance == 4) ? rnd(4) : 0;
  24.      else if (obj->cursed)
  25.          chance = (chance == 0) ? rn2(4) : 4;
  26.      /* 0,1,2,3,4:  b=80%,5,5,5,5; nc=20%,20,20,20,20; c=5%,5,5,5,80 */
  27.  
  28.      switch (chance) {
  29.      case 0:
  30.          verbalize("I am in your debt.  I will grant one wish!");
  31.          /* give a wish and discard the monster (mtmp set to null) */
  32.          mongrantswish(&mtmp);
  33.          break;
  34.      case 1:
  35.          verbalize("Thank you for freeing me!");
  36.          (void) tamedog(mtmp, (struct obj *) 0);
  37.          break;
  38.      case 2:
  39.          verbalize("You freed me!");
  40.          mtmp->mpeaceful = TRUE;
  41.          set_malign(mtmp);
  42.          break;
  43.      case 3:
  44.          verbalize("It is about time!");
  45.          if (canspotmon(mtmp))
  46.              pline("%s vanishes.", Monnam(mtmp));
  47.          mongone(mtmp);
  48.          break;
  49.      default:
  50.          verbalize("You disturbed me, fool!");
  51.          mtmp->mpeaceful = FALSE;
  52.          set_malign(mtmp);
  53.          break;
  54.      }
  55.  }
  56.  

split_mon

  1.  /* clone a gremlin or mold (2nd arg non-null implies heat as the trigger);
  2.     hit points are cut in half (odd HP stays with original) */
  3.  struct monst *
  4.  split_mon(mon, mtmp)
  5.  struct monst *mon,  /* monster being split */
  6.               *mtmp; /* optional attacker whose heat triggered it */
  7.  {
  8.      struct monst *mtmp2;
  9.      char reason[BUFSZ];
  10.  
  11.      reason[0] = '\0';
  12.      if (mtmp)
  13.          Sprintf(reason, " from %s heat",
  14.                  (mtmp == &youmonst) ? the_your[1]
  15.                                      : (const char *) s_suffix(mon_nam(mtmp)));
  16.  
  17.      if (mon == &youmonst) {
  18.          mtmp2 = cloneu();
  19.          if (mtmp2) {
  20.              mtmp2->mhpmax = u.mhmax / 2;
  21.              u.mhmax -= mtmp2->mhpmax;
  22.              context.botl = 1;
  23.              You("multiply%s!", reason);
  24.          }
  25.      } else {
  26.          mtmp2 = clone_mon(mon, 0, 0);
  27.          if (mtmp2) {
  28.              mtmp2->mhpmax = mon->mhpmax / 2;
  29.              mon->mhpmax -= mtmp2->mhpmax;
  30.              if (canspotmon(mon))
  31.                  pline("%s multiplies%s!", Monnam(mon), reason);
  32.          }
  33.      }
  34.      return mtmp2;
  35.  }
  36.  
  37.  /*potion.c*/