Source:NetHack 3.6.0/src/zap.c

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

Below is the full text to zap.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/zap.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	zap.c	$NHDT-Date: 1447987787 2015/11/20 02:49:47 $  $NHDT-Branch: master $:$NHDT-Revision: 1.236 $ */
  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.  /* Disintegration rays have special treatment; corpses are never left.
  8.   * But the routine which calculates the damage is separate from the routine
  9.   * which kills the monster.  The damage routine returns this cookie to
  10.   * indicate that the monster should be disintegrated.
  11.   */
  12.  #define MAGIC_COOKIE 1000
  13.  
  14.  static NEARDATA boolean obj_zapped;
  15.  static NEARDATA int poly_zapped;
  16.  
  17.  extern boolean notonhead; /* for long worms */
  18.  
  19.  /* kludge to use mondied instead of killed */
  20.  extern boolean m_using;
  21.  
  22.  STATIC_DCL void FDECL(polyuse, (struct obj *, int, int));
  23.  STATIC_DCL void FDECL(create_polymon, (struct obj *, int));
  24.  STATIC_DCL int FDECL(stone_to_flesh_obj, (struct obj *));
  25.  STATIC_DCL boolean FDECL(zap_updown, (struct obj *));
  26.  STATIC_DCL void FDECL(zhitu, (int, int, const char *, XCHAR_P, XCHAR_P));
  27.  STATIC_DCL void FDECL(revive_egg, (struct obj *));
  28.  STATIC_DCL boolean FDECL(zap_steed, (struct obj *));
  29.  STATIC_DCL void FDECL(skiprange, (int, int *, int *));
  30.  
  31.  STATIC_DCL int FDECL(zap_hit, (int, int));
  32.  STATIC_OVL void FDECL(disintegrate_mon, (struct monst *, int, const char *));
  33.  STATIC_DCL void FDECL(backfire, (struct obj *));
  34.  STATIC_DCL int FDECL(spell_hit_bonus, (int));
  35.  
  36.  #define ZT_MAGIC_MISSILE (AD_MAGM - 1)
  37.  #define ZT_FIRE (AD_FIRE - 1)
  38.  #define ZT_COLD (AD_COLD - 1)
  39.  #define ZT_SLEEP (AD_SLEE - 1)
  40.  #define ZT_DEATH (AD_DISN - 1) /* or disintegration */
  41.  #define ZT_LIGHTNING (AD_ELEC - 1)
  42.  #define ZT_POISON_GAS (AD_DRST - 1)
  43.  #define ZT_ACID (AD_ACID - 1)
  44.  /* 8 and 9 are currently unassigned */
  45.  
  46.  #define ZT_WAND(x) (x)
  47.  #define ZT_SPELL(x) (10 + (x))
  48.  #define ZT_BREATH(x) (20 + (x))
  49.  
  50.  #define is_hero_spell(type) ((type) >= 10 && (type) < 20)
  51.  
  52.  #define M_IN_WATER(ptr) \
  53.      ((ptr)->mlet == S_EEL || amphibious(ptr) || is_swimmer(ptr))
  54.  
  55.  STATIC_VAR const char are_blinded_by_the_flash[] =
  56.      "are blinded by the flash!";
  57.  
  58.  const char *const flash_types[] =
  59.      {                  /* also used in buzzmu(mcastu.c) */
  60.        "magic missile", /* Wands must be 0-9 */
  61.        "bolt of fire", "bolt of cold", "sleep ray", "death ray",
  62.        "bolt of lightning", "", "", "", "",
  63.  
  64.        "magic missile", /* Spell equivalents must be 10-19 */
  65.        "fireball", "cone of cold", "sleep ray", "finger of death",
  66.        "bolt of lightning", /* There is no spell, used for retribution */
  67.        "", "", "", "",
  68.  
  69.        "blast of missiles", /* Dragon breath equivalents 20-29*/
  70.        "blast of fire", "blast of frost", "blast of sleep gas",
  71.        "blast of disintegration", "blast of lightning", "blast of poison gas",
  72.        "blast of acid", "", ""
  73.      };
  74.  

learnwand

  1.  /*
  2.   * Recognizing unseen wands by zapping:  in 3.4.3 and earlier, zapping
  3.   * most wand types while blind would add that type to the discoveries
  4.   * list even if it had never been seen (ie, picked up while blinded
  5.   * and shown in inventory as simply "a wand").  This behavior has been
  6.   * changed; now such wands won't be discovered.  But if the type is
  7.   * already discovered, then the individual wand whose effect was just
  8.   * observed will be flagged as if seen.  [You already know wands of
  9.   * striking; you zap "a wand" and observe striking effect (presumably
  10.   * by sound or touch); it'll become shown in inventory as "a wand of
  11.   * striking".]
  12.   *
  13.   * Unfortunately, the new behavior isn't really correct either.  There
  14.   * should be an `eknown' bit for "effect known" added for wands (and
  15.   * for potions since quaffing one of a stack is similar) so that the
  16.   * particular wand which has been zapped would have its type become
  17.   * known (it would change from "a wand" to "a wand of striking", for
  18.   * example) without the type becoming discovered or other unknown wands
  19.   * of that type showing additional information.  When blindness ends,
  20.   * all objects in inventory with the eknown bit set would be discovered
  21.   * and other items of the same type would become known as such.
  22.   */
  23.  
  24.  /* wand discovery gets special handling when hero is blinded */
  25.  void
  26.  learnwand(obj)
  27.  struct obj *obj;
  28.  {
  29.      /* For a wand (or wand-like tool) zapped by the player, if the
  30.         effect was observable (determined by caller; usually seen, but
  31.         possibly heard or felt if the hero is blinded) then discover the
  32.         object type provided that the object itself is known (as more
  33.         than just "a wand").  If object type is already discovered and
  34.         we observed the effect, mark the individual wand as having been
  35.         seen.  Suppress spells (which use fake spellbook object for `obj')
  36.         so that casting a spell won't re-discover its forgotten book. */
  37.      if (obj->oclass != SPBOOK_CLASS) {
  38.          /* if type already discovered, treat this item has having been seen
  39.             even if hero is currently blinded (skips redundant makeknown) */
  40.          if (objects[obj->otyp].oc_name_known) {
  41.              obj->dknown = 1; /* will usually be set already */
  42.  
  43.          /* otherwise discover it if item itself has been or can be seen */
  44.          } else {
  45.              /* in case it was picked up while blind and then zapped without
  46.                 examining inventory after regaining sight (bypassing xname) */
  47.              if (!Blind)
  48.                  obj->dknown = 1;
  49.              /* make the discovery iff we know what we're manipulating */
  50.              if (obj->dknown)
  51.                  makeknown(obj->otyp);
  52.          }
  53.      }
  54.  }
  55.  

bhitm

  1.  /* Routines for IMMEDIATE wands and spells. */
  2.  /* bhitm: monster mtmp was hit by the effect of wand or spell otmp */
  3.  int
  4.  bhitm(mtmp, otmp)
  5.  struct monst *mtmp;
  6.  struct obj *otmp;
  7.  {
  8.      boolean wake = TRUE; /* Most 'zaps' should wake monster */
  9.      boolean reveal_invis = FALSE, learn_it = FALSE;
  10.      boolean dbldam = Role_if(PM_KNIGHT) && u.uhave.questart;
  11.      int dmg, otyp = otmp->otyp;
  12.      const char *zap_type_text = "spell";
  13.      struct obj *obj;
  14.      boolean disguised_mimic =
  15.          (mtmp->data->mlet == S_MIMIC && mtmp->m_ap_type != M_AP_NOTHING);
  16.  
  17.      if (u.uswallow && mtmp == u.ustuck)
  18.          reveal_invis = FALSE;
  19.  
  20.      switch (otyp) {
  21.      case WAN_STRIKING:
  22.          zap_type_text = "wand";
  23.      /* fall through */
  24.      case SPE_FORCE_BOLT:
  25.          reveal_invis = TRUE;
  26.          if (resists_magm(mtmp)) { /* match effect on player */
  27.              shieldeff(mtmp->mx, mtmp->my);
  28.              pline("Boing!");
  29.              break; /* skip makeknown */
  30.          } else if (u.uswallow || rnd(20) < 10 + find_mac(mtmp)) {
  31.              dmg = d(2, 12);
  32.              if (dbldam)
  33.                  dmg *= 2;
  34.              if (otyp == SPE_FORCE_BOLT)
  35.                  dmg = spell_damage_bonus(dmg);
  36.              hit(zap_type_text, mtmp, exclam(dmg));
  37.              (void) resist(mtmp, otmp->oclass, dmg, TELL);
  38.          } else
  39.              miss(zap_type_text, mtmp);
  40.          learn_it = TRUE;
  41.          break;
  42.      case WAN_SLOW_MONSTER:
  43.      case SPE_SLOW_MONSTER:
  44.          if (!resist(mtmp, otmp->oclass, 0, NOTELL)) {
  45.              mon_adjust_speed(mtmp, -1, otmp);
  46.              m_dowear(mtmp, FALSE); /* might want speed boots */
  47.              if (u.uswallow && (mtmp == u.ustuck) && is_whirly(mtmp->data)) {
  48.                  You("disrupt %s!", mon_nam(mtmp));
  49.                  pline("A huge hole opens up...");
  50.                  expels(mtmp, mtmp->data, TRUE);
  51.              }
  52.          }
  53.          break;
  54.      case WAN_SPEED_MONSTER:
  55.          if (!resist(mtmp, otmp->oclass, 0, NOTELL)) {
  56.              mon_adjust_speed(mtmp, 1, otmp);
  57.              m_dowear(mtmp, FALSE); /* might want speed boots */
  58.          }
  59.          break;
  60.      case WAN_UNDEAD_TURNING:
  61.      case SPE_TURN_UNDEAD:
  62.          wake = FALSE;
  63.          if (unturn_dead(mtmp))
  64.              wake = TRUE;
  65.          if (is_undead(mtmp->data) || is_vampshifter(mtmp)) {
  66.              reveal_invis = TRUE;
  67.              wake = TRUE;
  68.              dmg = rnd(8);
  69.              if (dbldam)
  70.                  dmg *= 2;
  71.              if (otyp == SPE_TURN_UNDEAD)
  72.                  dmg = spell_damage_bonus(dmg);
  73.              context.bypasses = TRUE; /* for make_corpse() */
  74.              if (!resist(mtmp, otmp->oclass, dmg, NOTELL)) {
  75.                  if (mtmp->mhp > 0)
  76.                      monflee(mtmp, 0, FALSE, TRUE);
  77.              }
  78.          }
  79.          break;
  80.      case WAN_POLYMORPH:
  81.      case SPE_POLYMORPH:
  82.      case POT_POLYMORPH:
  83.          if (resists_magm(mtmp)) {
  84.              /* magic resistance protects from polymorph traps, so make
  85.                 it guard against involuntary polymorph attacks too... */
  86.              shieldeff(mtmp->mx, mtmp->my);
  87.          } else if (!resist(mtmp, otmp->oclass, 0, NOTELL)) {
  88.              /* dropped inventory (due to death by system shock,
  89.                 or loss of wielded weapon and/or worn armor due to
  90.                 limitations of new shape) won't be hit by this zap */
  91.              for (obj = mtmp->minvent; obj; obj = obj->nobj)
  92.                  bypass_obj(obj);
  93.              /* natural shapechangers aren't affected by system shock
  94.                 (unless protection from shapechangers is interfering
  95.                 with their metabolism...) */
  96.              if (mtmp->cham == NON_PM && !rn2(25)) {
  97.                  if (canseemon(mtmp)) {
  98.                      pline("%s shudders!", Monnam(mtmp));
  99.                      learn_it = TRUE;
  100.                  }
  101.                  /* context.bypasses = TRUE; ## for make_corpse() */
  102.                  /* no corpse after system shock */
  103.                  xkilled(mtmp, 3);
  104.              } else if (newcham(mtmp, (struct permonst *) 0,
  105.                                 (otyp != POT_POLYMORPH), FALSE)) {
  106.                  if (!Hallucination && canspotmon(mtmp))
  107.                      learn_it = TRUE;
  108.              }
  109.          }
  110.          break;
  111.      case WAN_CANCELLATION:
  112.      case SPE_CANCELLATION:
  113.          (void) cancel_monst(mtmp, otmp, TRUE, TRUE, FALSE);
  114.          break;
  115.      case WAN_TELEPORTATION:
  116.      case SPE_TELEPORT_AWAY:
  117.          reveal_invis = !u_teleport_mon(mtmp, TRUE);
  118.          break;
  119.      case WAN_MAKE_INVISIBLE: {
  120.          int oldinvis = mtmp->minvis;
  121.          char nambuf[BUFSZ];
  122.  
  123.          /* format monster's name before altering its visibility */
  124.          Strcpy(nambuf, Monnam(mtmp));
  125.          mon_set_minvis(mtmp);
  126.          if (!oldinvis && knowninvisible(mtmp)) {
  127.              pline("%s turns transparent!", nambuf);
  128.              learn_it = TRUE;
  129.          }
  130.          break;
  131.      }
  132.      case WAN_LOCKING:
  133.      case SPE_WIZARD_LOCK:
  134.          wake = closeholdingtrap(mtmp, &learn_it);
  135.          break;
  136.      case WAN_PROBING:
  137.          wake = FALSE;
  138.          reveal_invis = TRUE;
  139.          probe_monster(mtmp);
  140.          learn_it = TRUE;
  141.          break;
  142.      case WAN_OPENING:
  143.      case SPE_KNOCK:
  144.          wake = FALSE; /* don't want immediate counterattack */
  145.          if (u.uswallow && mtmp == u.ustuck) {
  146.              if (is_animal(mtmp->data)) {
  147.                  if (Blind)
  148.                      You_feel("a sudden rush of air!");
  149.                  else
  150.                      pline("%s opens its mouth!", Monnam(mtmp));
  151.              }
  152.              expels(mtmp, mtmp->data, TRUE);
  153.              /* zap which hits steed will only release saddle if it
  154.                 doesn't hit a holding or falling trap; playability
  155.                 here overrides the more logical target ordering */
  156.          } else if (openholdingtrap(mtmp, &learn_it)) {
  157.              break;
  158.          } else if (openfallingtrap(mtmp, TRUE, &learn_it)) {
  159.              /* mtmp might now be on the migrating monsters list */
  160.              break;
  161.          } else if ((obj = which_armor(mtmp, W_SADDLE)) != 0) {
  162.              char buf[BUFSZ];
  163.  
  164.              Sprintf(buf, "%s %s", s_suffix(Monnam(mtmp)),
  165.                      distant_name(obj, xname));
  166.              if (cansee(mtmp->mx, mtmp->my)) {
  167.                  if (!canspotmon(mtmp))
  168.                      Strcpy(buf, An(distant_name(obj, xname)));
  169.                  pline("%s falls to the %s.", buf,
  170.                        surface(mtmp->mx, mtmp->my));
  171.              } else if (canspotmon(mtmp)) {
  172.                  pline("%s falls off.", buf);
  173.              }
  174.              obj_extract_self(obj);
  175.              mdrop_obj(mtmp, obj, FALSE);
  176.          }
  177.          break;
  178.      case SPE_HEALING:
  179.      case SPE_EXTRA_HEALING:
  180.          reveal_invis = TRUE;
  181.          if (mtmp->data != &mons[PM_PESTILENCE]) {
  182.              wake = FALSE; /* wakeup() makes the target angry */
  183.              mtmp->mhp += d(6, otyp == SPE_EXTRA_HEALING ? 8 : 4);
  184.              if (mtmp->mhp > mtmp->mhpmax)
  185.                  mtmp->mhp = mtmp->mhpmax;
  186.              if (mtmp->mblinded) {
  187.                  mtmp->mblinded = 0;
  188.                  mtmp->mcansee = 1;
  189.              }
  190.              if (canseemon(mtmp)) {
  191.                  if (disguised_mimic) {
  192.                      if (is_obj_mappear(mtmp,STRANGE_OBJECT)) {
  193.                          /* it can do better now */
  194.                          set_mimic_sym(mtmp);
  195.                          newsym(mtmp->mx, mtmp->my);
  196.                      } else
  197.                          mimic_hit_msg(mtmp, otyp);
  198.                  } else
  199.                      pline("%s looks%s better.", Monnam(mtmp),
  200.                            otyp == SPE_EXTRA_HEALING ? " much" : "");
  201.              }
  202.              if (mtmp->mtame || mtmp->mpeaceful) {
  203.                  adjalign(Role_if(PM_HEALER) ? 1 : sgn(u.ualign.type));
  204.              }
  205.          } else { /* Pestilence */
  206.              /* Pestilence will always resist; damage is half of 3d{4,8} */
  207.              (void) resist(mtmp, otmp->oclass,
  208.                            d(3, otyp == SPE_EXTRA_HEALING ? 8 : 4), TELL);
  209.          }
  210.          break;
  211.      case WAN_LIGHT: /* (broken wand) */
  212.          if (flash_hits_mon(mtmp, otmp)) {
  213.              learn_it = TRUE;
  214.              reveal_invis = TRUE;
  215.          }
  216.          break;
  217.      case WAN_SLEEP: /* (broken wand) */
  218.          /* [wakeup() doesn't rouse victims of temporary sleep,
  219.             so it's okay to leave `wake' set to TRUE here] */
  220.          reveal_invis = TRUE;
  221.          if (sleep_monst(mtmp, d(1 + otmp->spe, 12), WAND_CLASS))
  222.              slept_monst(mtmp);
  223.          if (!Blind)
  224.              learn_it = TRUE;
  225.          break;
  226.      case SPE_STONE_TO_FLESH:
  227.          if (monsndx(mtmp->data) == PM_STONE_GOLEM) {
  228.              char *name = Monnam(mtmp);
  229.  
  230.              /* turn into flesh golem */
  231.              if (newcham(mtmp, &mons[PM_FLESH_GOLEM], FALSE, FALSE)) {
  232.                  if (canseemon(mtmp))
  233.                      pline("%s turns to flesh!", name);
  234.              } else {
  235.                  if (canseemon(mtmp))
  236.                      pline("%s looks rather fleshy for a moment.", name);
  237.              }
  238.          } else
  239.              wake = FALSE;
  240.          break;
  241.      case SPE_DRAIN_LIFE:
  242.          dmg = monhp_per_lvl(mtmp);
  243.          if (dbldam)
  244.              dmg *= 2;
  245.          if (otyp == SPE_DRAIN_LIFE)
  246.              dmg = spell_damage_bonus(dmg);
  247.          if (resists_drli(mtmp))
  248.              shieldeff(mtmp->mx, mtmp->my);
  249.          else if (!resist(mtmp, otmp->oclass, dmg, NOTELL) && mtmp->mhp > 0) {
  250.              mtmp->mhp -= dmg;
  251.              mtmp->mhpmax -= dmg;
  252.              if (mtmp->mhp <= 0 || mtmp->mhpmax <= 0 || mtmp->m_lev < 1)
  253.                  xkilled(mtmp, 1);
  254.              else {
  255.                  mtmp->m_lev--;
  256.                  if (canseemon(mtmp))
  257.                      pline("%s suddenly seems weaker!", Monnam(mtmp));
  258.              }
  259.          }
  260.          break;
  261.      case WAN_NOTHING:
  262.          wake = FALSE;
  263.          break;
  264.      default:
  265.          impossible("What an interesting effect (%d)", otyp);
  266.          break;
  267.      }
  268.      if (wake) {
  269.          if (mtmp->mhp > 0) {
  270.              wakeup(mtmp);
  271.              m_respond(mtmp);
  272.              if (mtmp->isshk && !*u.ushops)
  273.                  hot_pursuit(mtmp);
  274.          } else if (mtmp->m_ap_type)
  275.              seemimic(mtmp); /* might unblock if mimicing a boulder/door */
  276.      }
  277.      /* note: bhitpos won't be set if swallowed, but that's okay since
  278.       * reveal_invis will be false.  We can't use mtmp->mx, my since it
  279.       * might be an invisible worm hit on the tail.
  280.       */
  281.      if (reveal_invis) {
  282.          if (mtmp->mhp > 0 && cansee(bhitpos.x, bhitpos.y)
  283.              && !canspotmon(mtmp))
  284.              map_invisible(bhitpos.x, bhitpos.y);
  285.      }
  286.      /* if effect was observable then discover the wand type provided
  287.         that the wand itself has been seen */
  288.      if (learn_it)
  289.          learnwand(otmp);
  290.      return 0;
  291.  }
  292.  

probe_monster

  1.  void
  2.  probe_monster(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      struct obj *otmp;
  6.  
  7.      mstatusline(mtmp);
  8.      if (notonhead)
  9.          return; /* don't show minvent for long worm tail */
  10.  
  11.      if (mtmp->minvent) {
  12.          for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) {
  13.              otmp->dknown = 1; /* treat as "seen" */
  14.              if (Is_container(otmp) || otmp->otyp == STATUE) {
  15.                  otmp->lknown = 1;
  16.                  if (!SchroedingersBox(otmp))
  17.                      otmp->cknown = 1;
  18.              }
  19.          }
  20.          (void) display_minventory(mtmp, MINV_ALL | MINV_NOLET, (char *) 0);
  21.      } else {
  22.          pline("%s is not carrying anything%s.", noit_Monnam(mtmp),
  23.                (u.uswallow && mtmp == u.ustuck) ? " besides you" : "");
  24.      }
  25.  }
  26.  

get_obj_location

  1.  /*
  2.   * Return the object's physical location.  This only makes sense for
  3.   * objects that are currently on the level (i.e. migrating objects
  4.   * are nowhere).  By default, only things that can be seen (in hero's
  5.   * inventory, monster's inventory, or on the ground) are reported.
  6.   * By adding BURIED_TOO and/or CONTAINED_TOO flags, you can also get
  7.   * the location of buried and contained objects.  Note that if an
  8.   * object is carried by a monster, its reported position may change
  9.   * from turn to turn.  This function returns FALSE if the position
  10.   * is not available or subject to the constraints above.
  11.   */
  12.  boolean
  13.  get_obj_location(obj, xp, yp, locflags)
  14.  struct obj *obj;
  15.  xchar *xp, *yp;
  16.  int locflags;
  17.  {
  18.      switch (obj->where) {
  19.      case OBJ_INVENT:
  20.          *xp = u.ux;
  21.          *yp = u.uy;
  22.          return TRUE;
  23.      case OBJ_FLOOR:
  24.          *xp = obj->ox;
  25.          *yp = obj->oy;
  26.          return TRUE;
  27.      case OBJ_MINVENT:
  28.          if (obj->ocarry->mx) {
  29.              *xp = obj->ocarry->mx;
  30.              *yp = obj->ocarry->my;
  31.              return TRUE;
  32.          }
  33.          break; /* !mx => migrating monster */
  34.      case OBJ_BURIED:
  35.          if (locflags & BURIED_TOO) {
  36.              *xp = obj->ox;
  37.              *yp = obj->oy;
  38.              return TRUE;
  39.          }
  40.          break;
  41.      case OBJ_CONTAINED:
  42.          if (locflags & CONTAINED_TOO)
  43.              return get_obj_location(obj->ocontainer, xp, yp, locflags);
  44.          break;
  45.      }
  46.      *xp = *yp = 0;
  47.      return FALSE;
  48.  }
  49.  

get_mon_location

  1.  boolean
  2.  get_mon_location(mon, xp, yp, locflags)
  3.  struct monst *mon;
  4.  xchar *xp, *yp;
  5.  int locflags; /* non-zero means get location even if monster is buried */
  6.  {
  7.      if (mon == &youmonst) {
  8.          *xp = u.ux;
  9.          *yp = u.uy;
  10.          return TRUE;
  11.      } else if (mon->mx > 0 && (!mon->mburied || locflags)) {
  12.          *xp = mon->mx;
  13.          *yp = mon->my;
  14.          return TRUE;
  15.      } else { /* migrating or buried */
  16.          *xp = *yp = 0;
  17.          return FALSE;
  18.      }
  19.  }
  20.  

montraits

  1.  /* used by revive() and animate_statue() */
  2.  struct monst *
  3.  montraits(obj, cc)
  4.  struct obj *obj;
  5.  coord *cc;
  6.  {
  7.      struct monst *mtmp = (struct monst *) 0;
  8.      struct monst *mtmp2 = (struct monst *) 0;
  9.  
  10.      if (has_omonst(obj))
  11.          mtmp2 = get_mtraits(obj, TRUE);
  12.      if (mtmp2) {
  13.          /* save_mtraits() validated mtmp2->mnum */
  14.          mtmp2->data = &mons[mtmp2->mnum];
  15.          if (mtmp2->mhpmax <= 0 && !is_rider(mtmp2->data))
  16.              return (struct monst *) 0;
  17.          mtmp = makemon(mtmp2->data, cc->x, cc->y,
  18.                         NO_MINVENT | MM_NOWAIT | MM_NOCOUNTBIRTH);
  19.          if (!mtmp)
  20.              return mtmp;
  21.  
  22.          /* heal the monster */
  23.          if (mtmp->mhpmax > mtmp2->mhpmax && is_rider(mtmp2->data))
  24.              mtmp2->mhpmax = mtmp->mhpmax;
  25.          mtmp2->mhp = mtmp2->mhpmax;
  26.          /* Get these ones from mtmp */
  27.          mtmp2->minvent = mtmp->minvent; /*redundant*/
  28.          /* monster ID is available if the monster died in the current
  29.             game, but will be zero if the corpse was in a bones level
  30.             (we cleared it when loading bones) */
  31.          if (mtmp->m_id) {
  32.              mtmp2->m_id = mtmp->m_id;
  33.              /* might be bringing quest leader back to life */
  34.              if (quest_status.leader_is_dead &&
  35.                  /* leader_is_dead implies leader_m_id is valid */
  36.                  mtmp2->m_id == quest_status.leader_m_id)
  37.                  quest_status.leader_is_dead = FALSE;
  38.          }
  39.          mtmp2->mx = mtmp->mx;
  40.          mtmp2->my = mtmp->my;
  41.          mtmp2->mux = mtmp->mux;
  42.          mtmp2->muy = mtmp->muy;
  43.          mtmp2->mw = mtmp->mw;
  44.          mtmp2->wormno = mtmp->wormno;
  45.          mtmp2->misc_worn_check = mtmp->misc_worn_check;
  46.          mtmp2->weapon_check = mtmp->weapon_check;
  47.          mtmp2->mtrapseen = mtmp->mtrapseen;
  48.          mtmp2->mflee = mtmp->mflee;
  49.          mtmp2->mburied = mtmp->mburied;
  50.          mtmp2->mundetected = mtmp->mundetected;
  51.          mtmp2->mfleetim = mtmp->mfleetim;
  52.          mtmp2->mlstmv = mtmp->mlstmv;
  53.          mtmp2->m_ap_type = mtmp->m_ap_type;
  54.          /* set these ones explicitly */
  55.          mtmp2->mrevived = 1;
  56.          mtmp2->mavenge = 0;
  57.          mtmp2->meating = 0;
  58.          mtmp2->mleashed = 0;
  59.          mtmp2->mtrapped = 0;
  60.          mtmp2->msleeping = 0;
  61.          mtmp2->mfrozen = 0;
  62.          mtmp2->mcanmove = 1;
  63.          /* most cancelled monsters return to normal,
  64.             but some need to stay cancelled */
  65.          if (!dmgtype(mtmp2->data, AD_SEDU)
  66.              && (!SYSOPT_SEDUCE || !dmgtype(mtmp2->data, AD_SSEX)))
  67.              mtmp2->mcan = 0;
  68.          mtmp2->mcansee = 1; /* set like in makemon */
  69.          mtmp2->mblinded = 0;
  70.          mtmp2->mstun = 0;
  71.          mtmp2->mconf = 0;
  72.          replmon(mtmp, mtmp2);
  73.          newsym(mtmp2->mx, mtmp2->my); /* Might now be invisible */
  74.  
  75.          /* in case Protection_from_shape_changers is different
  76.             now than it was when the traits were stored */
  77.          restore_cham(mtmp2);
  78.      }
  79.      return mtmp2;
  80.  }
  81.  

get_container_location

  1.  /*
  2.   * get_container_location() returns the following information
  3.   * about the outermost container:
  4.   * loc argument gets set to:
  5.   *      OBJ_INVENT      if in hero's inventory; return 0.
  6.   *      OBJ_FLOOR       if on the floor; return 0.
  7.   *      OBJ_BURIED      if buried; return 0.
  8.   *      OBJ_MINVENT     if in monster's inventory; return monster.
  9.   * container_nesting is updated with the nesting depth of the containers
  10.   * if applicable.
  11.   */
  12.  struct monst *
  13.  get_container_location(obj, loc, container_nesting)
  14.  struct obj *obj;
  15.  int *loc;
  16.  int *container_nesting;
  17.  {
  18.      if (!obj || !loc)
  19.          return 0;
  20.  
  21.      if (container_nesting)
  22.          *container_nesting = 0;
  23.      while (obj && obj->where == OBJ_CONTAINED) {
  24.          if (container_nesting)
  25.              *container_nesting += 1;
  26.          obj = obj->ocontainer;
  27.      }
  28.      if (obj) {
  29.          *loc = obj->where; /* outermost container's location */
  30.          if (obj->where == OBJ_MINVENT)
  31.              return obj->ocarry;
  32.      }
  33.      return (struct monst *) 0;
  34.  }
  35.  

revive

  1.  /*
  2.   * Attempt to revive the given corpse, return the revived monster if
  3.   * successful.  Note: this does NOT use up the corpse if it fails.
  4.   */
  5.  struct monst *
  6.  revive(corpse, by_hero)
  7.  struct obj *corpse;
  8.  boolean by_hero;
  9.  {
  10.      struct monst *mtmp = 0;
  11.      struct permonst *mptr;
  12.      struct obj *container;
  13.      coord xy;
  14.      xchar x, y;
  15.      int montype, container_nesting = 0;
  16.  
  17.      if (corpse->otyp != CORPSE) {
  18.          impossible("Attempting to revive %s?", xname(corpse));
  19.          return (struct monst *) 0;
  20.      }
  21.  
  22.      x = y = 0;
  23.      if (corpse->where != OBJ_CONTAINED) {
  24.          /* only for invent, minvent, or floor */
  25.          container = 0;
  26.          (void) get_obj_location(corpse, &x, &y, 0);
  27.      } else {
  28.          /* deal with corpses in [possibly nested] containers */
  29.          struct monst *carrier;
  30.          int holder = OBJ_FREE;
  31.  
  32.          container = corpse->ocontainer;
  33.          carrier =
  34.              get_container_location(container, &holder, &container_nesting);
  35.          switch (holder) {
  36.          case OBJ_MINVENT:
  37.              x = carrier->mx, y = carrier->my;
  38.              break;
  39.          case OBJ_INVENT:
  40.              x = u.ux, y = u.uy;
  41.              break;
  42.          case OBJ_FLOOR:
  43.              (void) get_obj_location(corpse, &x, &y, CONTAINED_TOO);
  44.              break;
  45.          default:
  46.              break; /* x,y are 0 */
  47.          }
  48.      }
  49.      if (!x || !y ||
  50.          /* Rules for revival from containers:
  51.             - the container cannot be locked
  52.             - the container cannot be heavily nested (>2 is arbitrary)
  53.             - the container cannot be a statue or bag of holding
  54.             (except in very rare cases for the latter)
  55.          */
  56.          (container && (container->olocked || container_nesting > 2
  57.                         || container->otyp == STATUE
  58.                         || (container->otyp == BAG_OF_HOLDING && rn2(40)))))
  59.          return (struct monst *) 0;
  60.  
  61.      /* record the object's location now that we're sure where it is */
  62.      corpse->ox = x, corpse->oy = y;
  63.  
  64.      /* prepare for the monster */
  65.      montype = corpse->corpsenm;
  66.      mptr = &mons[montype];
  67.      /* [should probably handle recorporealization first; if corpse and
  68.         ghost are at same location, revived creature shouldn't be bumped
  69.         to an adjacent spot by ghost which joins with it] */
  70.      if (MON_AT(x, y)) {
  71.          if (enexto(&xy, x, y, mptr))
  72.              x = xy.x, y = xy.y;
  73.      }
  74.  
  75.      if (mons[montype].mlet == S_EEL && !IS_POOL(levl[x][y].typ)) {
  76.          if (by_hero && cansee(x,y))
  77.              pline("%s twitches feebly.",
  78.                  upstart(corpse_xname(corpse, (const char *) 0, CXN_PFX_THE)));
  79.          return (struct monst *) 0;
  80.      }
  81.  
  82.      if (cant_revive(&montype, TRUE, corpse)) {
  83.          /* make a zombie or doppelganger instead */
  84.          /* note: montype has changed; mptr keeps old value for newcham() */
  85.          mtmp = makemon(&mons[montype], x, y, NO_MINVENT | MM_NOWAIT);
  86.          if (mtmp) {
  87.              /* skip ghost handling */
  88.              if (has_omid(corpse))
  89.                  free_omid(corpse);
  90.              if (has_omonst(corpse))
  91.                  free_omonst(corpse);
  92.              if (mtmp->cham == PM_DOPPELGANGER) {
  93.                  /* change shape to match the corpse */
  94.                  (void) newcham(mtmp, mptr, FALSE, FALSE);
  95.              } else if (mtmp->data->mlet == S_ZOMBIE) {
  96.                  mtmp->mhp = mtmp->mhpmax = 100;
  97.                  mon_adjust_speed(mtmp, 2, (struct obj *) 0); /* MFAST */
  98.              }
  99.          }
  100.      } else if (has_omonst(corpse)) {
  101.          /* use saved traits */
  102.          xy.x = x, xy.y = y;
  103.          mtmp = montraits(corpse, &xy);
  104.          if (mtmp && mtmp->mtame && !mtmp->isminion)
  105.              wary_dog(mtmp, TRUE);
  106.      } else {
  107.          /* make a new monster */
  108.          mtmp = makemon(mptr, x, y, NO_MINVENT | MM_NOWAIT | MM_NOCOUNTBIRTH);
  109.      }
  110.      if (!mtmp)
  111.          return (struct monst *) 0;
  112.  
  113.      /* hiders shouldn't already be re-hidden when they revive */
  114.      if (mtmp->mundetected) {
  115.          mtmp->mundetected = 0;
  116.          newsym(mtmp->mx, mtmp->my);
  117.      }
  118.      if (mtmp->m_ap_type)
  119.          seemimic(mtmp);
  120.  
  121.      /* if this is caused by the hero there might be a shop charge */
  122.      if (by_hero) {
  123.          struct monst *shkp = 0;
  124.  
  125.          x = corpse->ox, y = corpse->oy;
  126.          if (costly_spot(x, y))
  127.              shkp = shop_keeper(*in_rooms(x, y, SHOPBASE));
  128.  
  129.          if (cansee(x, y))
  130.              pline(
  131.                  "%s glows iridescently.",
  132.                  upstart(corpse_xname(corpse, (const char *) 0, CXN_PFX_THE)));
  133.          else if (shkp)
  134.              /* need some prior description of the corpse since
  135.                 stolen_value() will refer to the object as "it" */
  136.              pline("A corpse is resuscitated.");
  137.  
  138.          /* don't charge for shopkeeper's own corpse if we just revived him */
  139.          if (shkp && mtmp != shkp)
  140.              (void) stolen_value(corpse, x, y, (boolean) shkp->mpeaceful,
  141.                                  FALSE);
  142.  
  143.          /* [we don't give any comparable message about the corpse for
  144.             the !by_hero case because caller might have already done so] */
  145.      }
  146.  
  147.      /* handle recorporealization of an active ghost */
  148.      if (has_omid(corpse)) {
  149.          unsigned m_id;
  150.          struct monst *ghost;
  151.          struct obj *otmp;
  152.  
  153.          (void) memcpy((genericptr_t) &m_id, (genericptr_t) OMID(corpse),
  154.                        sizeof m_id);
  155.          ghost = find_mid(m_id, FM_FMON);
  156.          if (ghost && ghost->data == &mons[PM_GHOST]) {
  157.              if (canseemon(ghost))
  158.                  pline("%s is suddenly drawn into its former body!",
  159.                        Monnam(ghost));
  160.              /* transfer the ghost's inventory along with it */
  161.              while ((otmp = ghost->minvent) != 0) {
  162.                  obj_extract_self(otmp);
  163.                  add_to_minv(mtmp, otmp);
  164.              }
  165.              /* tame the revived monster if its ghost was tame */
  166.              if (ghost->mtame && !mtmp->mtame) {
  167.                  if (tamedog(mtmp, (struct obj *) 0)) {
  168.                      /* ghost's edog data is ignored */
  169.                      mtmp->mtame = ghost->mtame;
  170.                  }
  171.              }
  172.              /* was ghost, now alive, it's all very confusing */
  173.              mtmp->mconf = 1;
  174.              /* separate ghost monster no longer exists */
  175.              mongone(ghost);
  176.          }
  177.          free_omid(corpse);
  178.      }
  179.  
  180.      /* monster retains its name */
  181.      if (has_oname(corpse))
  182.          mtmp = christen_monst(mtmp, ONAME(corpse));
  183.      /* partially eaten corpse yields wounded monster */
  184.      if (corpse->oeaten)
  185.          mtmp->mhp = eaten_stat(mtmp->mhp, corpse);
  186.      /* track that this monster was revived at least once */
  187.      mtmp->mrevived = 1;
  188.  
  189.      /* finally, get rid of the corpse--it's gone now */
  190.      switch (corpse->where) {
  191.      case OBJ_INVENT:
  192.          useup(corpse);
  193.          break;
  194.      case OBJ_FLOOR:
  195.          /* in case MON_AT+enexto for invisible mon */
  196.          x = corpse->ox, y = corpse->oy;
  197.          /* not useupf(), which charges */
  198.          if (corpse->quan > 1L)
  199.              corpse = splitobj(corpse, 1L);
  200.          delobj(corpse);
  201.          newsym(x, y);
  202.          break;
  203.      case OBJ_MINVENT:
  204.          m_useup(corpse->ocarry, corpse);
  205.          break;
  206.      case OBJ_CONTAINED:
  207.          obj_extract_self(corpse);
  208.          obfree(corpse, (struct obj *) 0);
  209.          break;
  210.      default:
  211.          panic("revive");
  212.      }
  213.  
  214.      return mtmp;
  215.  }
  216.  

revive_egg

  1.  STATIC_OVL void
  2.  revive_egg(obj)
  3.  struct obj *obj;
  4.  {
  5.      /*
  6.       * Note: generic eggs with corpsenm set to NON_PM will never hatch.
  7.       */
  8.      if (obj->otyp != EGG)
  9.          return;
  10.      if (obj->corpsenm != NON_PM && !dead_species(obj->corpsenm, TRUE))
  11.          attach_egg_hatch_timeout(obj, 0L);
  12.  }
  13.  

unturn_dead

  1.  /* try to revive all corpses and eggs carried by `mon' */
  2.  int
  3.  unturn_dead(mon)
  4.  struct monst *mon;
  5.  {
  6.      struct obj *otmp, *otmp2;
  7.      struct monst *mtmp2;
  8.      char owner[BUFSZ], corpse[BUFSZ];
  9.      boolean youseeit;
  10.      int once = 0, res = 0;
  11.  
  12.      youseeit = (mon == &youmonst) ? TRUE : canseemon(mon);
  13.      otmp2 = (mon == &youmonst) ? invent : mon->minvent;
  14.  
  15.      while ((otmp = otmp2) != 0) {
  16.          otmp2 = otmp->nobj;
  17.          if (otmp->otyp == EGG)
  18.              revive_egg(otmp);
  19.          if (otmp->otyp != CORPSE)
  20.              continue;
  21.          /* save the name; the object is liable to go away */
  22.          if (youseeit)
  23.              Strcpy(corpse,
  24.                     corpse_xname(otmp, (const char *) 0, CXN_SINGULAR));
  25.  
  26.          /* for a merged group, only one is revived; should this be fixed? */
  27.          if ((mtmp2 = revive(otmp, !context.mon_moving)) != 0) {
  28.              ++res;
  29.              if (youseeit) {
  30.                  if (!once++)
  31.                      Strcpy(owner, (mon == &youmonst) ? "Your"
  32.                                                       : s_suffix(Monnam(mon)));
  33.                  pline("%s %s suddenly comes alive!", owner, corpse);
  34.              } else if (canseemon(mtmp2))
  35.                  pline("%s suddenly appears!", Amonnam(mtmp2));
  36.          }
  37.      }
  38.      return res;
  39.  }
  40.  

cancel_item

  1.  /* cancel obj, possibly carried by you or a monster */
  2.  void
  3.  cancel_item(obj)
  4.  register struct obj *obj;
  5.  {
  6.      boolean u_ring = (obj == uleft || obj == uright);
  7.      int otyp = obj->otyp;
  8.  
  9.      switch (otyp) {
  10.      case RIN_GAIN_STRENGTH:
  11.          if ((obj->owornmask & W_RING) && u_ring) {
  12.              ABON(A_STR) -= obj->spe;
  13.              context.botl = 1;
  14.          }
  15.          break;
  16.      case RIN_GAIN_CONSTITUTION:
  17.          if ((obj->owornmask & W_RING) && u_ring) {
  18.              ABON(A_CON) -= obj->spe;
  19.              context.botl = 1;
  20.          }
  21.          break;
  22.      case RIN_ADORNMENT:
  23.          if ((obj->owornmask & W_RING) && u_ring) {
  24.              ABON(A_CHA) -= obj->spe;
  25.              context.botl = 1;
  26.          }
  27.          break;
  28.      case RIN_INCREASE_ACCURACY:
  29.          if ((obj->owornmask & W_RING) && u_ring)
  30.              u.uhitinc -= obj->spe;
  31.          break;
  32.      case RIN_INCREASE_DAMAGE:
  33.          if ((obj->owornmask & W_RING) && u_ring)
  34.              u.udaminc -= obj->spe;
  35.          break;
  36.      case GAUNTLETS_OF_DEXTERITY:
  37.          if ((obj->owornmask & W_ARMG) && (obj == uarmg)) {
  38.              ABON(A_DEX) -= obj->spe;
  39.              context.botl = 1;
  40.          }
  41.          break;
  42.      case HELM_OF_BRILLIANCE:
  43.          if ((obj->owornmask & W_ARMH) && (obj == uarmh)) {
  44.              ABON(A_INT) -= obj->spe;
  45.              ABON(A_WIS) -= obj->spe;
  46.              context.botl = 1;
  47.          }
  48.          break;
  49.          /* case RIN_PROTECTION:  not needed */
  50.      }
  51.      if (objects[otyp].oc_magic
  52.          || (obj->spe && (obj->oclass == ARMOR_CLASS
  53.                           || obj->oclass == WEAPON_CLASS || is_weptool(obj)))
  54.          || otyp == POT_ACID
  55.          || otyp == POT_SICKNESS
  56.          || (otyp == POT_WATER && (obj->blessed || obj->cursed))) {
  57.          if (obj->spe != ((obj->oclass == WAND_CLASS) ? -1 : 0)
  58.              && otyp != WAN_CANCELLATION /* can't cancel cancellation */
  59.              && otyp != MAGIC_LAMP /* cancelling doesn't remove djinni */
  60.              && otyp != CANDELABRUM_OF_INVOCATION) {
  61.              costly_alteration(obj, COST_CANCEL);
  62.              obj->spe = (obj->oclass == WAND_CLASS) ? -1 : 0;
  63.          }
  64.          switch (obj->oclass) {
  65.          case SCROLL_CLASS:
  66.              costly_alteration(obj, COST_CANCEL);
  67.              obj->otyp = SCR_BLANK_PAPER;
  68.              obj->spe = 0;
  69.              break;
  70.          case SPBOOK_CLASS:
  71.              if (otyp != SPE_CANCELLATION && otyp != SPE_NOVEL
  72.                  && otyp != SPE_BOOK_OF_THE_DEAD) {
  73.                  costly_alteration(obj, COST_CANCEL);
  74.                  obj->otyp = SPE_BLANK_PAPER;
  75.              }
  76.              break;
  77.          case POTION_CLASS:
  78.              costly_alteration(obj,
  79.                                (otyp != POT_WATER)
  80.                                    ? COST_CANCEL
  81.                                    : obj->cursed ? COST_UNCURS : COST_UNBLSS);
  82.              if (otyp == POT_SICKNESS || otyp == POT_SEE_INVISIBLE) {
  83.                  /* sickness is "biologically contaminated" fruit juice;
  84.                     cancel it and it just becomes fruit juice...
  85.                     whereas see invisible tastes like "enchanted" fruit
  86.                     juice, it similarly cancels */
  87.                  obj->otyp = POT_FRUIT_JUICE;
  88.              } else {
  89.                  obj->otyp = POT_WATER;
  90.                  obj->odiluted = 0; /* same as any other water */
  91.              }
  92.              break;
  93.          }
  94.      }
  95.      unbless(obj);
  96.      uncurse(obj);
  97.      return;
  98.  }
  99.  

drain_item

  1.  /* Remove a positive enchantment or charge from obj,
  2.   * possibly carried by you or a monster
  3.   */
  4.  boolean
  5.  drain_item(obj)
  6.  register struct obj *obj;
  7.  {
  8.      boolean u_ring;
  9.  
  10.      /* Is this a charged/enchanted object? */
  11.      if (!obj
  12.          || (!objects[obj->otyp].oc_charged && obj->oclass != WEAPON_CLASS
  13.              && obj->oclass != ARMOR_CLASS && !is_weptool(obj))
  14.          || obj->spe <= 0)
  15.          return FALSE;
  16.      if (defends(AD_DRLI, obj) || defends_when_carried(AD_DRLI, obj)
  17.          || obj_resists(obj, 10, 90))
  18.          return FALSE;
  19.  
  20.      /* Charge for the cost of the object */
  21.      costly_alteration(obj, COST_DRAIN);
  22.  
  23.      /* Drain the object and any implied effects */
  24.      obj->spe--;
  25.      u_ring = (obj == uleft) || (obj == uright);
  26.      switch (obj->otyp) {
  27.      case RIN_GAIN_STRENGTH:
  28.          if ((obj->owornmask & W_RING) && u_ring) {
  29.              ABON(A_STR)--;
  30.              context.botl = 1;
  31.          }
  32.          break;
  33.      case RIN_GAIN_CONSTITUTION:
  34.          if ((obj->owornmask & W_RING) && u_ring) {
  35.              ABON(A_CON)--;
  36.              context.botl = 1;
  37.          }
  38.          break;
  39.      case RIN_ADORNMENT:
  40.          if ((obj->owornmask & W_RING) && u_ring) {
  41.              ABON(A_CHA)--;
  42.              context.botl = 1;
  43.          }
  44.          break;
  45.      case RIN_INCREASE_ACCURACY:
  46.          if ((obj->owornmask & W_RING) && u_ring)
  47.              u.uhitinc--;
  48.          break;
  49.      case RIN_INCREASE_DAMAGE:
  50.          if ((obj->owornmask & W_RING) && u_ring)
  51.              u.udaminc--;
  52.          break;
  53.      case HELM_OF_BRILLIANCE:
  54.          if ((obj->owornmask & W_ARMH) && (obj == uarmh)) {
  55.              ABON(A_INT)--;
  56.              ABON(A_WIS)--;
  57.              context.botl = 1;
  58.          }
  59.          break;
  60.      case GAUNTLETS_OF_DEXTERITY:
  61.          if ((obj->owornmask & W_ARMG) && (obj == uarmg)) {
  62.              ABON(A_DEX)--;
  63.              context.botl = 1;
  64.          }
  65.          break;
  66.      case RIN_PROTECTION:
  67.          context.botl = 1;
  68.          break;
  69.      }
  70.      if (carried(obj))
  71.          update_inventory();
  72.      return TRUE;
  73.  }
  74.  

obj_resists

  1.  boolean
  2.  obj_resists(obj, ochance, achance)
  3.  struct obj *obj;
  4.  int ochance, achance; /* percent chance for ordinary objects, artifacts */
  5.  {
  6.      if (obj->otyp == AMULET_OF_YENDOR
  7.          || obj->otyp == SPE_BOOK_OF_THE_DEAD
  8.          || obj->otyp == CANDELABRUM_OF_INVOCATION
  9.          || obj->otyp == BELL_OF_OPENING
  10.          || (obj->otyp == CORPSE && is_rider(&mons[obj->corpsenm]))) {
  11.          return TRUE;
  12.      } else {
  13.          int chance = rn2(100);
  14.  
  15.          return (boolean) (chance < (obj->oartifact ? achance : ochance));
  16.      }
  17.  }
  18.  

obj_shudders

  1.  boolean
  2.  obj_shudders(obj)
  3.  struct obj *obj;
  4.  {
  5.      int zap_odds;
  6.  
  7.      if (context.bypasses && obj->bypass)
  8.          return FALSE;
  9.  
  10.      if (obj->oclass == WAND_CLASS)
  11.          zap_odds = 3; /* half-life = 2 zaps */
  12.      else if (obj->cursed)
  13.          zap_odds = 3; /* half-life = 2 zaps */
  14.      else if (obj->blessed)
  15.          zap_odds = 12; /* half-life = 8 zaps */
  16.      else
  17.          zap_odds = 8; /* half-life = 6 zaps */
  18.  
  19.      /* adjust for "large" quantities of identical things */
  20.      if (obj->quan > 4L)
  21.          zap_odds /= 2;
  22.  
  23.      return (boolean) !rn2(zap_odds);
  24.  }
  25.  

polyuse

  1.  /* Use up at least minwt number of things made of material mat.
  2.   * There's also a chance that other stuff will be used up.  Finally,
  3.   * there's a random factor here to keep from always using the stuff
  4.   * at the top of the pile.
  5.   */
  6.  STATIC_OVL void
  7.  polyuse(objhdr, mat, minwt)
  8.  struct obj *objhdr;
  9.  int mat, minwt;
  10.  {
  11.      register struct obj *otmp, *otmp2;
  12.  
  13.      for (otmp = objhdr; minwt > 0 && otmp; otmp = otmp2) {
  14.          otmp2 = otmp->nexthere;
  15.          if (context.bypasses && otmp->bypass)
  16.              continue;
  17.          if (otmp == uball || otmp == uchain)
  18.              continue;
  19.          if (obj_resists(otmp, 0, 0))
  20.              continue; /* preserve unique objects */
  21.  #ifdef MAIL
  22.          if (otmp->otyp == SCR_MAIL)
  23.              continue;
  24.  #endif
  25.  
  26.          if (((int) objects[otmp->otyp].oc_material == mat)
  27.              == (rn2(minwt + 1) != 0)) {
  28.              /* appropriately add damage to bill */
  29.              if (costly_spot(otmp->ox, otmp->oy)) {
  30.                  if (*u.ushops)
  31.                      addtobill(otmp, FALSE, FALSE, FALSE);
  32.                  else
  33.                      (void) stolen_value(otmp, otmp->ox, otmp->oy, FALSE,
  34.                                          FALSE);
  35.              }
  36.              if (otmp->quan < LARGEST_INT)
  37.                  minwt -= (int) otmp->quan;
  38.              else
  39.                  minwt = 0;
  40.              delobj(otmp);
  41.          }
  42.      }
  43.  }
  44.  

create_polymon

  1.  /*
  2.   * Polymorph some of the stuff in this pile into a monster, preferably
  3.   * a golem of the kind okind.
  4.   */
  5.  STATIC_OVL void
  6.  create_polymon(obj, okind)
  7.  struct obj *obj;
  8.  int okind;
  9.  {
  10.      struct permonst *mdat = (struct permonst *) 0;
  11.      struct monst *mtmp;
  12.      const char *material;
  13.      int pm_index;
  14.  
  15.      if (context.bypasses) {
  16.          /* this is approximate because the "no golems" !obj->nexthere
  17.             check below doesn't understand bypassed objects; but it
  18.             should suffice since bypassed objects always end up as a
  19.             consecutive group at the top of their pile */
  20.          while (obj && obj->bypass)
  21.              obj = obj->nexthere;
  22.      }
  23.  
  24.      /* no golems if you zap only one object -- not enough stuff */
  25.      if (!obj || (!obj->nexthere && obj->quan == 1L))
  26.          return;
  27.  
  28.      /* some of these choices are arbitrary */
  29.      switch (okind) {
  30.      case IRON:
  31.      case METAL:
  32.      case MITHRIL:
  33.          pm_index = PM_IRON_GOLEM;
  34.          material = "metal ";
  35.          break;
  36.      case COPPER:
  37.      case SILVER:
  38.      case PLATINUM:
  39.      case GEMSTONE:
  40.      case MINERAL:
  41.          pm_index = rn2(2) ? PM_STONE_GOLEM : PM_CLAY_GOLEM;
  42.          material = "lithic ";
  43.          break;
  44.      case 0:
  45.      case FLESH:
  46.          /* there is no flesh type, but all food is type 0, so we use it */
  47.          pm_index = PM_FLESH_GOLEM;
  48.          material = "organic ";
  49.          break;
  50.      case WOOD:
  51.          pm_index = PM_WOOD_GOLEM;
  52.          material = "wood ";
  53.          break;
  54.      case LEATHER:
  55.          pm_index = PM_LEATHER_GOLEM;
  56.          material = "leather ";
  57.          break;
  58.      case CLOTH:
  59.          pm_index = PM_ROPE_GOLEM;
  60.          material = "cloth ";
  61.          break;
  62.      case BONE:
  63.          pm_index = PM_SKELETON; /* nearest thing to "bone golem" */
  64.          material = "bony ";
  65.          break;
  66.      case GOLD:
  67.          pm_index = PM_GOLD_GOLEM;
  68.          material = "gold ";
  69.          break;
  70.      case GLASS:
  71.          pm_index = PM_GLASS_GOLEM;
  72.          material = "glassy ";
  73.          break;
  74.      case PAPER:
  75.          pm_index = PM_PAPER_GOLEM;
  76.          material = "paper ";
  77.          break;
  78.      default:
  79.          /* if all else fails... */
  80.          pm_index = PM_STRAW_GOLEM;
  81.          material = "";
  82.          break;
  83.      }
  84.  
  85.      if (!(mvitals[pm_index].mvflags & G_GENOD))
  86.          mdat = &mons[pm_index];
  87.  
  88.      mtmp = makemon(mdat, obj->ox, obj->oy, NO_MM_FLAGS);
  89.      polyuse(obj, okind, (int) mons[pm_index].cwt);
  90.  
  91.      if (mtmp && cansee(mtmp->mx, mtmp->my)) {
  92.          pline("Some %sobjects meld, and %s arises from the pile!", material,
  93.                a_monnam(mtmp));
  94.      }
  95.  }
  96.  

do_osshock

  1.  /* Assumes obj is on the floor. */
  2.  void
  3.  do_osshock(obj)
  4.  struct obj *obj;
  5.  {
  6.      long i;
  7.  
  8.  #ifdef MAIL
  9.      if (obj->otyp == SCR_MAIL)
  10.          return;
  11.  #endif
  12.      obj_zapped = TRUE;
  13.  
  14.      if (poly_zapped < 0) {
  15.          /* some may metamorphosize */
  16.          for (i = obj->quan; i; i--)
  17.              if (!rn2(Luck + 45)) {
  18.                  poly_zapped = objects[obj->otyp].oc_material;
  19.                  break;
  20.              }
  21.      }
  22.  
  23.      /* if quan > 1 then some will survive intact */
  24.      if (obj->quan > 1L) {
  25.          if (obj->quan > LARGEST_INT)
  26.              obj = splitobj(obj, (long) rnd(30000));
  27.          else
  28.              obj = splitobj(obj, (long) rnd((int) obj->quan - 1));
  29.      }
  30.  
  31.      /* appropriately add damage to bill */
  32.      if (costly_spot(obj->ox, obj->oy)) {
  33.          if (*u.ushops)
  34.              addtobill(obj, FALSE, FALSE, FALSE);
  35.          else
  36.              (void) stolen_value(obj, obj->ox, obj->oy, FALSE, FALSE);
  37.      }
  38.  
  39.      /* zap the object */
  40.      delobj(obj);
  41.  }
  42.  


poly_obj

  1.  /* classes of items whose current charge count carries over across polymorph
  2.   */
  3.  static const char charged_objs[] = { WAND_CLASS, WEAPON_CLASS, ARMOR_CLASS,
  4.                                       '\0' };
  5.  
  6.  /*
  7.   * Polymorph the object to the given object ID.  If the ID is STRANGE_OBJECT
  8.   * then pick random object from the source's class (this is the standard
  9.   * "polymorph" case).  If ID is set to a specific object, inhibit fusing
  10.   * n objects into 1.  This could have been added as a flag, but currently
  11.   * it is tied to not being the standard polymorph case. The new polymorphed
  12.   * object replaces obj in its link chains.  Return value is a pointer to
  13.   * the new object.
  14.   *
  15.   * This should be safe to call for an object anywhere.
  16.   */
  17.  struct obj *
  18.  poly_obj(obj, id)
  19.  struct obj *obj;
  20.  int id;
  21.  {
  22.      struct obj *otmp;
  23.      xchar ox, oy;
  24.      boolean can_merge = (id == STRANGE_OBJECT);
  25.      int obj_location = obj->where;
  26.  
  27.      if (obj->otyp == BOULDER)
  28.          sokoban_guilt();
  29.      if (id == STRANGE_OBJECT) { /* preserve symbol */
  30.          int try_limit = 3;
  31.          unsigned magic_obj = objects[obj->otyp].oc_magic;
  32.  
  33.          if (obj->otyp == UNICORN_HORN && obj->degraded_horn)
  34.              magic_obj = 0;
  35.          /* Try up to 3 times to make the magic-or-not status of
  36.             the new item be the same as it was for the old one. */
  37.          otmp = (struct obj *) 0;
  38.          do {
  39.              if (otmp)
  40.                  delobj(otmp);
  41.              otmp = mkobj(obj->oclass, FALSE);
  42.          } while (--try_limit > 0
  43.                   && objects[otmp->otyp].oc_magic != magic_obj);
  44.      } else {
  45.          /* literally replace obj with this new thing */
  46.          otmp = mksobj(id, FALSE, FALSE);
  47.  /* Actually more things use corpsenm but they polymorph differently */
  48.  #define USES_CORPSENM(typ) \
  49.      ((typ) == CORPSE || (typ) == STATUE || (typ) == FIGURINE)
  50.  
  51.          if (USES_CORPSENM(obj->otyp) && USES_CORPSENM(id))
  52.              set_corpsenm(otmp, obj->corpsenm);
  53.  #undef USES_CORPSENM
  54.      }
  55.  
  56.      /* preserve quantity */
  57.      otmp->quan = obj->quan;
  58.      /* preserve the shopkeepers (lack of) interest */
  59.      otmp->no_charge = obj->no_charge;
  60.      /* preserve inventory letter if in inventory */
  61.      if (obj_location == OBJ_INVENT)
  62.          otmp->invlet = obj->invlet;
  63.  #ifdef MAIL
  64.      /* You can't send yourself 100 mail messages and then
  65.       * polymorph them into useful scrolls
  66.       */
  67.      if (obj->otyp == SCR_MAIL) {
  68.          otmp->otyp = SCR_MAIL;
  69.          otmp->spe = 1;
  70.      }
  71.  #endif
  72.  
  73.      /* avoid abusing eggs laid by you */
  74.      if (obj->otyp == EGG && obj->spe) {
  75.          int mnum, tryct = 100;
  76.  
  77.          /* first, turn into a generic egg */
  78.          if (otmp->otyp == EGG)
  79.              kill_egg(otmp);
  80.          else {
  81.              otmp->otyp = EGG;
  82.              otmp->owt = weight(otmp);
  83.          }
  84.          otmp->corpsenm = NON_PM;
  85.          otmp->spe = 0;
  86.  
  87.          /* now change it into something laid by the hero */
  88.          while (tryct--) {
  89.              mnum = can_be_hatched(random_monster());
  90.              if (mnum != NON_PM && !dead_species(mnum, TRUE)) {
  91.                  otmp->spe = 1;            /* laid by hero */
  92.                  set_corpsenm(otmp, mnum); /* also sets hatch timer */
  93.                  break;
  94.              }
  95.          }
  96.      }
  97.  
  98.      /* keep special fields (including charges on wands) */
  99.      if (index(charged_objs, otmp->oclass))
  100.          otmp->spe = obj->spe;
  101.      otmp->recharged = obj->recharged;
  102.  
  103.      otmp->cursed = obj->cursed;
  104.      otmp->blessed = obj->blessed;
  105.      otmp->oeroded = obj->oeroded;
  106.      otmp->oeroded2 = obj->oeroded2;
  107.      if (!is_flammable(otmp) && !is_rustprone(otmp))
  108.          otmp->oeroded = 0;
  109.      if (!is_corrodeable(otmp) && !is_rottable(otmp))
  110.          otmp->oeroded2 = 0;
  111.      if (is_damageable(otmp))
  112.          otmp->oerodeproof = obj->oerodeproof;
  113.  
  114.      /* Keep chest/box traps and poisoned ammo if we may */
  115.      if (obj->otrapped && Is_box(otmp))
  116.          otmp->otrapped = TRUE;
  117.  
  118.      if (obj->opoisoned && is_poisonable(otmp))
  119.          otmp->opoisoned = TRUE;
  120.  
  121.      if (id == STRANGE_OBJECT && obj->otyp == CORPSE) {
  122.          /* turn crocodile corpses into shoes */
  123.          if (obj->corpsenm == PM_CROCODILE) {
  124.              otmp->otyp = LOW_BOOTS;
  125.              otmp->oclass = ARMOR_CLASS;
  126.              otmp->spe = 0;
  127.              otmp->oeroded = 0;
  128.              otmp->oerodeproof = TRUE;
  129.              otmp->quan = 1L;
  130.              otmp->cursed = FALSE;
  131.          }
  132.      }
  133.  
  134.      /* no box contents --KAA */
  135.      if (Has_contents(otmp))
  136.          delete_contents(otmp);
  137.  
  138.      /* 'n' merged objects may be fused into 1 object */
  139.      if (otmp->quan > 1L && (!objects[otmp->otyp].oc_merge
  140.                              || (can_merge && otmp->quan > (long) rn2(1000))))
  141.          otmp->quan = 1L;
  142.  
  143.      switch (otmp->oclass) {
  144.      case TOOL_CLASS:
  145.          if (otmp->otyp == MAGIC_LAMP) {
  146.              otmp->otyp = OIL_LAMP;
  147.              otmp->age = 1500L; /* "best" oil lamp possible */
  148.          } else if (otmp->otyp == MAGIC_MARKER) {
  149.              otmp->recharged = 1; /* degraded quality */
  150.          }
  151.          /* don't care about the recharge count of other tools */
  152.          break;
  153.  
  154.      case WAND_CLASS:
  155.          while (otmp->otyp == WAN_WISHING || otmp->otyp == WAN_POLYMORPH)
  156.              otmp->otyp = rnd_class(WAN_LIGHT, WAN_LIGHTNING);
  157.          /* altering the object tends to degrade its quality
  158.             (analogous to spellbook `read count' handling) */
  159.          if ((int) otmp->recharged < rn2(7)) /* recharge_limit */
  160.              otmp->recharged++;
  161.          break;
  162.  
  163.      case POTION_CLASS:
  164.          while (otmp->otyp == POT_POLYMORPH)
  165.              otmp->otyp = rnd_class(POT_GAIN_ABILITY, POT_WATER);
  166.          break;
  167.  
  168.      case SPBOOK_CLASS:
  169.          while (otmp->otyp == SPE_POLYMORPH)
  170.              otmp->otyp = rnd_class(SPE_DIG, SPE_BLANK_PAPER);
  171.          /* reduce spellbook abuse; non-blank books degrade */
  172.          if (otmp->otyp != SPE_BLANK_PAPER) {
  173.              otmp->spestudied = obj->spestudied + 1;
  174.              if (otmp->spestudied > MAX_SPELL_STUDY) {
  175.                  otmp->otyp = SPE_BLANK_PAPER;
  176.                  /* writing a new book over it will yield an unstudied
  177.                     one; re-polymorphing this one as-is may or may not
  178.                     get something non-blank */
  179.                  otmp->spestudied = rn2(otmp->spestudied);
  180.              }
  181.          }
  182.          break;
  183.  
  184.      case GEM_CLASS:
  185.          if (otmp->quan > (long) rnd(4)
  186.              && objects[obj->otyp].oc_material == MINERAL
  187.              && objects[otmp->otyp].oc_material != MINERAL) {
  188.              otmp->otyp = ROCK; /* transmutation backfired */
  189.              otmp->quan /= 2L;  /* some material has been lost */
  190.          }
  191.          break;
  192.      }
  193.  
  194.      /* update the weight */
  195.      otmp->owt = weight(otmp);
  196.  
  197.      /* handle polymorph of worn item: stone-to-flesh cast on self can
  198.         affect multiple objects at once, but their new forms won't
  199.         produce any side-effects; a single worn item dipped into potion
  200.         of polymorph can produce side-effects but those won't yield out
  201.         of sequence messages because current polymorph is finished */
  202.      if (obj_location == OBJ_INVENT && obj->owornmask) {
  203.          long old_wornmask = obj->owornmask & ~(W_ART | W_ARTI),
  204.               new_wornmask = wearslot(otmp);
  205.          boolean was_twohanded = bimanual(obj), was_twoweap = u.twoweap;
  206.  
  207.          remove_worn_item(obj, TRUE);
  208.          /* if the new form can be worn in the same slot, make it so
  209.             [possible extension:  if it could be worn in some other
  210.             slot which is currently unfilled, wear it there instead] */
  211.          if ((old_wornmask & W_QUIVER) != 0L) {
  212.              setuqwep(otmp);
  213.          } else if ((old_wornmask & W_SWAPWEP) != 0L) {
  214.              if (was_twohanded || !bimanual(otmp))
  215.                  setuswapwep(otmp);
  216.              if (was_twoweap && uswapwep)
  217.                  u.twoweap = TRUE;
  218.          } else if ((old_wornmask & W_WEP) != 0L) {
  219.              if (was_twohanded || !bimanual(otmp) || !uarms)
  220.                  setuwep(otmp);
  221.              if (was_twoweap && uwep && !bimanual(uwep))
  222.                  u.twoweap = TRUE;
  223.          } else if ((old_wornmask & new_wornmask) != 0L) {
  224.              new_wornmask &= old_wornmask;
  225.              setworn(otmp, new_wornmask);
  226.              set_wear(otmp); /* Armor_on() for side-effects */
  227.          }
  228.      }
  229.  
  230.      /* ** we are now done adjusting the object ** */
  231.  
  232.      /* swap otmp for obj */
  233.      replace_object(obj, otmp);
  234.      if (obj_location == OBJ_INVENT) {
  235.          /*
  236.           * We may need to do extra adjustments for the hero if we're
  237.           * messing with the hero's inventory.  The following calls are
  238.           * equivalent to calling freeinv on obj and addinv on otmp,
  239.           * while doing an in-place swap of the actual objects.
  240.           */
  241.          freeinv_core(obj);
  242.          addinv_core1(otmp);
  243.          addinv_core2(otmp);
  244.      } else if (obj_location == OBJ_FLOOR) {
  245.          ox = otmp->ox, oy = otmp->oy; /* set by replace_object() */
  246.          if (obj->otyp == BOULDER && otmp->otyp != BOULDER
  247.              && !does_block(ox, oy, &levl[ox][oy]))
  248.              unblock_point(ox, oy);
  249.          else if (obj->otyp != BOULDER && otmp->otyp == BOULDER)
  250.              /* (checking does_block() here would be redundant) */
  251.              block_point(ox, oy);
  252.      }
  253.  
  254.      if ((!carried(otmp) || obj->unpaid)
  255.          && get_obj_location(otmp, &ox, &oy, BURIED_TOO | CONTAINED_TOO)
  256.          && costly_spot(ox, oy)) {
  257.          register struct monst *shkp =
  258.              shop_keeper(*in_rooms(ox, oy, SHOPBASE));
  259.  
  260.          if ((!obj->no_charge
  261.               || (Has_contents(obj)
  262.                   && (contained_cost(obj, shkp, 0L, FALSE, FALSE) != 0L)))
  263.              && inhishop(shkp)) {
  264.              if (shkp->mpeaceful) {
  265.                  if (*u.ushops
  266.                      && *in_rooms(u.ux, u.uy, 0)
  267.                             == *in_rooms(shkp->mx, shkp->my, 0)
  268.                      && !costly_spot(u.ux, u.uy))
  269.                      make_angry_shk(shkp, ox, oy);
  270.                  else {
  271.                      pline("%s gets angry!", Monnam(shkp));
  272.                      hot_pursuit(shkp);
  273.                  }
  274.              } else
  275.                  Norep("%s is furious!", Monnam(shkp));
  276.          }
  277.      }
  278.      delobj(obj);
  279.      return otmp;
  280.  }
  281.  

stone_to_flesh_obj

  1.  /* stone-to-flesh spell hits and maybe transforms or animates obj */
  2.  STATIC_OVL int
  3.  stone_to_flesh_obj(obj)
  4.  struct obj *obj;
  5.  {
  6.      int res = 1; /* affected object by default */
  7.      struct permonst *ptr;
  8.      struct monst *mon;
  9.      struct obj *item;
  10.      xchar oox, ooy;
  11.      boolean smell = FALSE, golem_xform = FALSE;
  12.  
  13.      if (objects[obj->otyp].oc_material != MINERAL
  14.          && objects[obj->otyp].oc_material != GEMSTONE)
  15.          return 0;
  16.      /* Heart of Ahriman usually resists; ordinary items rarely do */
  17.      if (obj_resists(obj, 2, 98))
  18.          return 0;
  19.  
  20.      (void) get_obj_location(obj, &oox, &ooy, 0);
  21.      /* add more if stone objects are added.. */
  22.      switch (objects[obj->otyp].oc_class) {
  23.      case ROCK_CLASS: /* boulders and statues */
  24.      case TOOL_CLASS: /* figurines */
  25.          if (obj->otyp == BOULDER) {
  26.              obj = poly_obj(obj, HUGE_CHUNK_OF_MEAT);
  27.              smell = TRUE;
  28.          } else if (obj->otyp == STATUE || obj->otyp == FIGURINE) {
  29.              ptr = &mons[obj->corpsenm];
  30.              if (is_golem(ptr)) {
  31.                  golem_xform = (ptr != &mons[PM_FLESH_GOLEM]);
  32.              } else if (vegetarian(ptr)) {
  33.                  /* Don't animate monsters that aren't flesh */
  34.                  obj = poly_obj(obj, MEATBALL);
  35.                  smell = TRUE;
  36.                  break;
  37.              }
  38.              if (obj->otyp == STATUE) {
  39.                  /* animate_statue() forces all golems to become flesh golems
  40.                   */
  41.                  mon = animate_statue(obj, oox, ooy, ANIMATE_SPELL, (int *) 0);
  42.              } else { /* (obj->otyp == FIGURINE) */
  43.                  if (golem_xform)
  44.                      ptr = &mons[PM_FLESH_GOLEM];
  45.                  mon = makemon(ptr, oox, ooy, NO_MINVENT);
  46.                  if (mon) {
  47.                      if (costly_spot(oox, ooy) && !obj->no_charge) {
  48.                          if (costly_spot(u.ux, u.uy))
  49.                              addtobill(obj, carried(obj), FALSE, FALSE);
  50.                          else
  51.                              stolen_value(obj, oox, ooy, TRUE, FALSE);
  52.                      }
  53.                      if (obj->timed)
  54.                          obj_stop_timers(obj);
  55.                      if (carried(obj))
  56.                          useup(obj);
  57.                      else
  58.                          delobj(obj);
  59.                      if (cansee(mon->mx, mon->my))
  60.                          pline_The("figurine %sanimates!",
  61.                                    golem_xform ? "turns to flesh and " : "");
  62.                  }
  63.              }
  64.              if (mon) {
  65.                  ptr = mon->data;
  66.                  /* this golem handling is redundant... */
  67.                  if (is_golem(ptr) && ptr != &mons[PM_FLESH_GOLEM])
  68.                      (void) newcham(mon, &mons[PM_FLESH_GOLEM], TRUE, FALSE);
  69.              } else if ((ptr->geno & (G_NOCORPSE | G_UNIQ)) != 0) {
  70.                  /* didn't revive but can't leave corpse either */
  71.                  res = 0;
  72.              } else {
  73.                  /* unlikely to get here since genociding monsters also
  74.                     sets the G_NOCORPSE flag; drop statue's contents */
  75.                  while ((item = obj->cobj) != 0) {
  76.                      bypass_obj(item); /* make stone-to-flesh miss it */
  77.                      obj_extract_self(item);
  78.                      place_object(item, oox, ooy);
  79.                  }
  80.                  obj = poly_obj(obj, CORPSE);
  81.              }
  82.          } else { /* miscellaneous tool or unexpected rock... */
  83.              res = 0;
  84.          }
  85.          break;
  86.      /* maybe add weird things to become? */
  87.      case RING_CLASS: /* some of the rings are stone */
  88.          obj = poly_obj(obj, MEAT_RING);
  89.          smell = TRUE;
  90.          break;
  91.      case WAND_CLASS: /* marble wand */
  92.          obj = poly_obj(obj, MEAT_STICK);
  93.          smell = TRUE;
  94.          break;
  95.      case GEM_CLASS: /* stones & gems */
  96.          obj = poly_obj(obj, MEATBALL);
  97.          smell = TRUE;
  98.          break;
  99.      case WEAPON_CLASS: /* crysknife */
  100.          /*FALLTHRU*/
  101.      default:
  102.          res = 0;
  103.          break;
  104.      }
  105.  
  106.      if (smell) {
  107.          /* non-meat eaters smell meat, meat eaters smell its flavor;
  108.             monks are considered non-meat eaters regardless of behavior;
  109.             other roles are non-meat eaters if they haven't broken
  110.             vegetarian conduct yet (or if poly'd into non-carnivorous/
  111.             non-omnivorous form, regardless of whether it's herbivorous,
  112.             non-eating, or something stranger) */
  113.          if (Role_if(PM_MONK) || !u.uconduct.unvegetarian
  114.              || !carnivorous(youmonst.data))
  115.              Norep("You smell the odor of meat.");
  116.          else
  117.              Norep("You smell a delicious smell.");
  118.      }
  119.      newsym(oox, ooy);
  120.      return res;
  121.  }
  122.  

bhito

  1.  /*
  2.   * Object obj was hit by the effect of the wand/spell otmp.  Return
  3.   * non-zero if the wand/spell had any effect.
  4.   */
  5.  int
  6.  bhito(obj, otmp)
  7.  struct obj *obj, *otmp;
  8.  {
  9.      int res = 1; /* affected object by default */
  10.      boolean learn_it = FALSE, maybelearnit;
  11.  
  12.      /* fundamental: a wand effect hitting itself doesn't do anything;
  13.         otherwise we need to guard against accessing otmp after something
  14.         strange has happened to it (along the lines of polymorph or
  15.         stone-to-flesh [which aren't good examples since polymorph wands
  16.         aren't affected by polymorph zaps and stone-to-flesh isn't
  17.         available in wand form, but the concept still applies...]) */
  18.      if (obj == otmp)
  19.          return 0;
  20.  
  21.      if (obj->bypass) {
  22.          /* The bypass bit is currently only used as follows:
  23.           *
  24.           * POLYMORPH - When a monster being polymorphed drops something
  25.           *             from its inventory as a result of the change.
  26.           *             If the items fall to the floor, they are not
  27.           *             subject to direct subsequent polymorphing
  28.           *             themselves on that same zap. This makes it
  29.           *             consistent with items that remain in the
  30.           *             monster's inventory. They are not polymorphed
  31.           *             either.
  32.           * UNDEAD_TURNING - When an undead creature gets killed via
  33.           *             undead turning, prevent its corpse from being
  34.           *             immediately revived by the same effect.
  35.           * STONE_TO_FLESH - If a statue can't be revived, its
  36.           *             contents get dropped before turning it into
  37.           *             meat; prevent those contents from being hit.
  38.           * retouch_equipment() - bypass flag is used to track which
  39.           *             items have been handled (bhito isn't involved).
  40.           * menu_drop(), askchain() - inventory traversal where multiple
  41.           *             Drop can alter the invent chain while traversal
  42.           *             is in progress (bhito isn't involved).
  43.           *
  44.           * The bypass bit on all objects is reset each turn, whenever
  45.           * context.bypasses is set.
  46.           *
  47.           * We check the obj->bypass bit above AND context.bypasses
  48.           * as a safeguard against any stray occurrence left in an obj
  49.           * struct someplace, although that should never happen.
  50.           */
  51.          if (context.bypasses) {
  52.              return 0;
  53.          } else {
  54.              debugpline1("%s for a moment.", Tobjnam(obj, "pulsate"));
  55.              obj->bypass = 0;
  56.          }
  57.      }
  58.  
  59.      /*
  60.       * Some parts of this function expect the object to be on the floor
  61.       * obj->{ox,oy} to be valid.  The exception to this (so far) is
  62.       * for the STONE_TO_FLESH spell.
  63.       */
  64.      if (!(obj->where == OBJ_FLOOR || otmp->otyp == SPE_STONE_TO_FLESH))
  65.          impossible("bhito: obj is not floor or Stone To Flesh spell");
  66.  
  67.      if (obj == uball) {
  68.          res = 0;
  69.      } else if (obj == uchain) {
  70.          if (otmp->otyp == WAN_OPENING || otmp->otyp == SPE_KNOCK) {
  71.              learn_it = TRUE;
  72.              unpunish();
  73.          } else
  74.              res = 0;
  75.      } else
  76.          switch (otmp->otyp) {
  77.          case WAN_POLYMORPH:
  78.          case SPE_POLYMORPH:
  79.              if (obj->otyp == WAN_POLYMORPH || obj->otyp == SPE_POLYMORPH
  80.                  || obj->otyp == POT_POLYMORPH || obj_resists(obj, 5, 95)) {
  81.                  res = 0;
  82.                  break;
  83.              }
  84.              /* KMH, conduct */
  85.              u.uconduct.polypiles++;
  86.              /* any saved lock context will be dangerously obsolete */
  87.              if (Is_box(obj))
  88.                  (void) boxlock(obj, otmp);
  89.  
  90.              if (obj_shudders(obj)) {
  91.                  boolean cover =
  92.                      ((obj == level.objects[u.ux][u.uy]) && u.uundetected
  93.                       && hides_under(youmonst.data));
  94.  
  95.                  if (cansee(obj->ox, obj->oy))
  96.                      learn_it = TRUE;
  97.                  do_osshock(obj);
  98.                  /* eek - your cover might have been blown */
  99.                  if (cover)
  100.                      (void) hideunder(&youmonst);
  101.                  break;
  102.              }
  103.              obj = poly_obj(obj, STRANGE_OBJECT);
  104.              newsym(obj->ox, obj->oy);
  105.              break;
  106.          case WAN_PROBING:
  107.              res = !obj->dknown;
  108.              /* target object has now been "seen (up close)" */
  109.              obj->dknown = 1;
  110.              if (Is_container(obj) || obj->otyp == STATUE) {
  111.                  obj->cknown = obj->lknown = 1;
  112.                  if (!obj->cobj) {
  113.                      boolean catbox = SchroedingersBox(obj);
  114.  
  115.                      /* we don't want to force alive vs dead
  116.                         determination for Schroedinger's Cat here,
  117.                         so just make probing be inconclusive for it */
  118.                      if (catbox)
  119.                          obj->cknown = 0;
  120.                      pline("%s empty.", Tobjnam(obj, catbox ? "seem" : "are"));
  121.                  } else {
  122.                      struct obj *o;
  123.                      /* view contents (not recursively) */
  124.                      for (o = obj->cobj; o; o = o->nobj)
  125.                          o->dknown = 1; /* "seen", even if blind */
  126.                      (void) display_cinventory(obj);
  127.                  }
  128.                  res = 1;
  129.              }
  130.              if (res)
  131.                  learn_it = TRUE;
  132.              break;
  133.          case WAN_STRIKING:
  134.          case SPE_FORCE_BOLT:
  135.              /* learn the type if you see or hear something break
  136.                 (the sound could be implicit) */
  137.              maybelearnit = cansee(obj->ox, obj->oy) || !Deaf;
  138.              if (obj->otyp == BOULDER) {
  139.                  if (cansee(obj->ox, obj->oy))
  140.                      pline_The("boulder falls apart.");
  141.                  else
  142.                      You_hear("a crumbling sound.");
  143.                  fracture_rock(obj);
  144.              } else if (obj->otyp == STATUE) {
  145.                  if (break_statue(obj)) {
  146.                      if (cansee(obj->ox, obj->oy)) {
  147.                          if (Hallucination)
  148.                              pline_The("%s shatters.", rndmonnam(NULL));
  149.                          else
  150.                              pline_The("statue shatters.");
  151.                      } else
  152.                          You_hear("a crumbling sound.");
  153.                  }
  154.              } else {
  155.                  if (context.mon_moving
  156.                          ? !breaks(obj, obj->ox, obj->oy)
  157.                          : !hero_breaks(obj, obj->ox, obj->oy, FALSE))
  158.                      maybelearnit = FALSE; /* nothing broke */
  159.                  res = 0;
  160.              }
  161.              if (maybelearnit)
  162.                  learn_it = TRUE;
  163.              break;
  164.          case WAN_CANCELLATION:
  165.          case SPE_CANCELLATION:
  166.              cancel_item(obj);
  167.  #ifdef TEXTCOLOR
  168.              newsym(obj->ox, obj->oy); /* might change color */
  169.  #endif
  170.              break;
  171.          case SPE_DRAIN_LIFE:
  172.              (void) drain_item(obj);
  173.              break;
  174.          case WAN_TELEPORTATION:
  175.          case SPE_TELEPORT_AWAY:
  176.              (void) rloco(obj);
  177.              break;
  178.          case WAN_MAKE_INVISIBLE:
  179.              break;
  180.          case WAN_UNDEAD_TURNING:
  181.          case SPE_TURN_UNDEAD:
  182.              if (obj->otyp == EGG) {
  183.                  revive_egg(obj);
  184.              } else if (obj->otyp == CORPSE) {
  185.                  int corpsenm = corpse_revive_type(obj);
  186.  
  187.                  res = !!revive(obj, TRUE);
  188.                  if (res && Role_if(PM_HEALER)) {
  189.                      if (Hallucination && !Deaf) {
  190.                          You_hear("the sound of a defibrillator.");
  191.                          learn_it = TRUE;
  192.                      } else if (!Blind) {
  193.                          You("observe %s %s change dramatically.",
  194.                              s_suffix(an(mons[corpsenm].mname)),
  195.                              nonliving(&mons[corpsenm]) ? "motility"
  196.                                                         : "health");
  197.                          learn_it = TRUE;
  198.                      }
  199.                      if (learn_it)
  200.                          exercise(A_WIS, TRUE);
  201.                  }
  202.              }
  203.              break;
  204.          case WAN_OPENING:
  205.          case SPE_KNOCK:
  206.          case WAN_LOCKING:
  207.          case SPE_WIZARD_LOCK:
  208.              if (Is_box(obj))
  209.                  res = boxlock(obj, otmp);
  210.              else
  211.                  res = 0;
  212.              if (res)
  213.                  learn_it = TRUE;
  214.              break;
  215.          case WAN_SLOW_MONSTER: /* no effect on objects */
  216.          case SPE_SLOW_MONSTER:
  217.          case WAN_SPEED_MONSTER:
  218.          case WAN_NOTHING:
  219.          case SPE_HEALING:
  220.          case SPE_EXTRA_HEALING:
  221.              res = 0;
  222.              break;
  223.          case SPE_STONE_TO_FLESH:
  224.              res = stone_to_flesh_obj(obj);
  225.              break;
  226.          default:
  227.              impossible("What an interesting effect (%d)", otmp->otyp);
  228.              break;
  229.          }
  230.      /* if effect was observable then discover the wand type provided
  231.         that the wand itself has been seen */
  232.      if (learn_it)
  233.          learnwand(otmp);
  234.      return res;
  235.  }
  236.  

bhitpile

  1.  /* returns nonzero if something was hit */
  2.  int
  3.  bhitpile(obj, fhito, tx, ty, zz)
  4.  struct obj *obj;
  5.  int FDECL((*fhito), (OBJ_P, OBJ_P));
  6.  int tx, ty;
  7.  schar zz;
  8.  {
  9.      int hitanything = 0;
  10.      register struct obj *otmp, *next_obj;
  11.  
  12.      if (obj->otyp == SPE_FORCE_BOLT || obj->otyp == WAN_STRIKING) {
  13.          struct trap *t = t_at(tx, ty);
  14.  
  15.          /* We can't settle for the default calling sequence of
  16.             bhito(otmp) -> break_statue(otmp) -> activate_statue_trap(ox,oy)
  17.             because that last call might end up operating on our `next_obj'
  18.             (below), rather than on the current object, if it happens to
  19.             encounter a statue which mustn't become animated. */
  20.          if (t && t->ttyp == STATUE_TRAP
  21.              && activate_statue_trap(t, tx, ty, TRUE))
  22.              learnwand(obj);
  23.      }
  24.  
  25.      poly_zapped = -1;
  26.      for (otmp = level.objects[tx][ty]; otmp; otmp = next_obj) {
  27.          next_obj = otmp->nexthere;
  28.          /* for zap downwards, don't hit object poly'd hero is hiding under */
  29.          if (zz > 0 && u.uundetected && otmp == level.objects[u.ux][u.uy]
  30.              && hides_under(youmonst.data))
  31.              continue;
  32.  
  33.          hitanything += (*fhito)(otmp, obj);
  34.      }
  35.      if (poly_zapped >= 0)
  36.          create_polymon(level.objects[tx][ty], poly_zapped);
  37.  
  38.      return hitanything;
  39.  }
  40.  

zappable

  1.  /*
  2.   * zappable - returns 1 if zap is available, 0 otherwise.
  3.   *            it removes a charge from the wand if zappable.
  4.   * added by GAN 11/03/86
  5.   */
  6.  int
  7.  zappable(wand)
  8.  register struct obj *wand;
  9.  {
  10.      if (wand->spe < 0 || (wand->spe == 0 && rn2(121)))
  11.          return 0;
  12.      if (wand->spe == 0)
  13.          You("wrest one last charge from the worn-out wand.");
  14.      wand->spe--;
  15.      return 1;
  16.  }
  17.  

zapnodir

  1.  /*
  2.   * zapnodir - zaps a NODIR wand/spell.
  3.   * added by GAN 11/03/86
  4.   */
  5.  void
  6.  zapnodir(obj)
  7.  register struct obj *obj;
  8.  {
  9.      boolean known = FALSE;
  10.  
  11.      switch (obj->otyp) {
  12.      case WAN_LIGHT:
  13.      case SPE_LIGHT:
  14.          litroom(TRUE, obj);
  15.          if (!Blind)
  16.              known = TRUE;
  17.          if (lightdamage(obj, TRUE, 5))
  18.              known = TRUE;
  19.          break;
  20.      case WAN_SECRET_DOOR_DETECTION:
  21.      case SPE_DETECT_UNSEEN:
  22.          if (!findit())
  23.              return;
  24.          if (!Blind)
  25.              known = TRUE;
  26.          break;
  27.      case WAN_CREATE_MONSTER:
  28.          known = create_critters(rn2(23) ? 1 : rn1(7, 2),
  29.                                  (struct permonst *) 0, FALSE);
  30.          break;
  31.      case WAN_WISHING:
  32.          known = TRUE;
  33.          if (Luck + rn2(5) < 0) {
  34.              pline("Unfortunately, nothing happens.");
  35.              break;
  36.          }
  37.          makewish();
  38.          break;
  39.      case WAN_ENLIGHTENMENT:
  40.          known = TRUE;
  41.          You_feel("self-knowledgeable...");
  42.          display_nhwindow(WIN_MESSAGE, FALSE);
  43.          enlightenment(MAGICENLIGHTENMENT, ENL_GAMEINPROGRESS);
  44.          pline_The("feeling subsides.");
  45.          exercise(A_WIS, TRUE);
  46.          break;
  47.      }
  48.      if (known) {
  49.          if (!objects[obj->otyp].oc_name_known)
  50.              more_experienced(0, 10);
  51.          /* effect was observable; discover the wand type provided
  52.             that the wand itself has been seen */
  53.          learnwand(obj);
  54.      }
  55.  }
  56.  

backfire

  1.  STATIC_OVL void
  2.  backfire(otmp)
  3.  struct obj *otmp;
  4.  {
  5.      int dmg;
  6.      otmp->in_use = TRUE; /* in case losehp() is fatal */
  7.      pline("%s suddenly explodes!", The(xname(otmp)));
  8.      dmg = d(otmp->spe + 2, 6);
  9.      losehp(Maybe_Half_Phys(dmg), "exploding wand", KILLED_BY_AN);
  10.      useup(otmp);
  11.  }
  12.  

dozap

  1.  static NEARDATA const char zap_syms[] = { WAND_CLASS, 0 };
  2.  
  3.  /* 'z' command (or 'y' if numbed_pad==-1) */
  4.  int
  5.  dozap()
  6.  {
  7.      register struct obj *obj;
  8.      int damage;
  9.  
  10.      if (check_capacity((char *) 0))
  11.          return 0;
  12.      obj = getobj(zap_syms, "zap");
  13.      if (!obj)
  14.          return 0;
  15.  
  16.      check_unpaid(obj);
  17.  
  18.      /* zappable addition done by GAN 11/03/86 */
  19.      if (!zappable(obj))
  20.          pline1(nothing_happens);
  21.      else if (obj->cursed && !rn2(WAND_BACKFIRE_CHANCE)) {
  22.          backfire(obj); /* the wand blows up in your face! */
  23.          exercise(A_STR, FALSE);
  24.          return 1;
  25.      } else if (!(objects[obj->otyp].oc_dir == NODIR) && !getdir((char *) 0)) {
  26.          if (!Blind)
  27.              pline("%s glows and fades.", The(xname(obj)));
  28.          /* make him pay for knowing !NODIR */
  29.      } else if (!u.dx && !u.dy && !u.dz
  30.                 && !(objects[obj->otyp].oc_dir == NODIR)) {
  31.          if ((damage = zapyourself(obj, TRUE)) != 0) {
  32.              char buf[BUFSZ];
  33.              Sprintf(buf, "zapped %sself with a wand", uhim());
  34.              losehp(Maybe_Half_Phys(damage), buf, NO_KILLER_PREFIX);
  35.          }
  36.      } else {
  37.          /*      Are we having fun yet?
  38.           * weffects -> buzz(obj->otyp) -> zhitm (temple priest) ->
  39.           * attack -> hitum -> known_hitum -> ghod_hitsu ->
  40.           * buzz(AD_ELEC) -> destroy_item(WAND_CLASS) ->
  41.           * useup -> obfree -> dealloc_obj -> free(obj)
  42.           */
  43.          current_wand = obj;
  44.          weffects(obj);
  45.          obj = current_wand;
  46.          current_wand = 0;
  47.      }
  48.      if (obj && obj->spe < 0) {
  49.          pline("%s to dust.", Tobjnam(obj, "turn"));
  50.          useup(obj);
  51.      }
  52.      update_inventory(); /* maybe used a charge */
  53.      return 1;
  54.  }
  55.  

zapyourself

  1.  int
  2.  zapyourself(obj, ordinary)
  3.  struct obj *obj;
  4.  boolean ordinary;
  5.  {
  6.      boolean learn_it = FALSE;
  7.      int damage = 0;
  8.  
  9.      switch (obj->otyp) {
  10.      case WAN_STRIKING:
  11.      case SPE_FORCE_BOLT:
  12.          learn_it = TRUE;
  13.          if (Antimagic) {
  14.              shieldeff(u.ux, u.uy);
  15.              pline("Boing!");
  16.          } else {
  17.              if (ordinary) {
  18.                  You("bash yourself!");
  19.                  damage = d(2, 12);
  20.              } else
  21.                  damage = d(1 + obj->spe, 6);
  22.              exercise(A_STR, FALSE);
  23.          }
  24.          break;
  25.  
  26.      case WAN_LIGHTNING:
  27.          learn_it = TRUE;
  28.          if (!Shock_resistance) {
  29.              You("shock yourself!");
  30.              damage = d(12, 6);
  31.              exercise(A_CON, FALSE);
  32.          } else {
  33.              shieldeff(u.ux, u.uy);
  34.              You("zap yourself, but seem unharmed.");
  35.              ugolemeffects(AD_ELEC, d(12, 6));
  36.          }
  37.          destroy_item(WAND_CLASS, AD_ELEC);
  38.          destroy_item(RING_CLASS, AD_ELEC);
  39.          (void) flashburn((long) rnd(100));
  40.          break;
  41.  
  42.      case SPE_FIREBALL:
  43.          You("explode a fireball on top of yourself!");
  44.          explode(u.ux, u.uy, 11, d(6, 6), WAND_CLASS, EXPL_FIERY);
  45.          break;
  46.      case WAN_FIRE:
  47.      case FIRE_HORN:
  48.          learn_it = TRUE;
  49.          if (Fire_resistance) {
  50.              shieldeff(u.ux, u.uy);
  51.              You_feel("rather warm.");
  52.              ugolemeffects(AD_FIRE, d(12, 6));
  53.          } else {
  54.              pline("You've set yourself afire!");
  55.              damage = d(12, 6);
  56.          }
  57.          burn_away_slime();
  58.          (void) burnarmor(&youmonst);
  59.          destroy_item(SCROLL_CLASS, AD_FIRE);
  60.          destroy_item(POTION_CLASS, AD_FIRE);
  61.          destroy_item(SPBOOK_CLASS, AD_FIRE);
  62.          destroy_item(FOOD_CLASS, AD_FIRE); /* only slime for now */
  63.          break;
  64.  
  65.      case WAN_COLD:
  66.      case SPE_CONE_OF_COLD:
  67.      case FROST_HORN:
  68.          learn_it = TRUE;
  69.          if (Cold_resistance) {
  70.              shieldeff(u.ux, u.uy);
  71.              You_feel("a little chill.");
  72.              ugolemeffects(AD_COLD, d(12, 6));
  73.          } else {
  74.              You("imitate a popsicle!");
  75.              damage = d(12, 6);
  76.          }
  77.          destroy_item(POTION_CLASS, AD_COLD);
  78.          break;
  79.  
  80.      case WAN_MAGIC_MISSILE:
  81.      case SPE_MAGIC_MISSILE:
  82.          learn_it = TRUE;
  83.          if (Antimagic) {
  84.              shieldeff(u.ux, u.uy);
  85.              pline_The("missiles bounce!");
  86.          } else {
  87.              damage = d(4, 6);
  88.              pline("Idiot!  You've shot yourself!");
  89.          }
  90.          break;
  91.  
  92.      case WAN_POLYMORPH:
  93.      case SPE_POLYMORPH:
  94.          if (!Unchanging) {
  95.              learn_it = TRUE;
  96.              polyself(0);
  97.          }
  98.          break;
  99.  
  100.      case WAN_CANCELLATION:
  101.      case SPE_CANCELLATION:
  102.          (void) cancel_monst(&youmonst, obj, TRUE, FALSE, TRUE);
  103.          break;
  104.  
  105.      case SPE_DRAIN_LIFE:
  106.          if (!Drain_resistance) {
  107.              learn_it = TRUE; /* (no effect for spells...) */
  108.              losexp("life drainage");
  109.          }
  110.          damage = 0; /* No additional damage */
  111.          break;
  112.  
  113.      case WAN_MAKE_INVISIBLE: {
  114.          /* have to test before changing HInvis but must change
  115.           * HInvis before doing newsym().
  116.           */
  117.          int msg = !Invis && !Blind && !BInvis;
  118.  
  119.          if (BInvis && uarmc->otyp == MUMMY_WRAPPING) {
  120.              /* A mummy wrapping absorbs it and protects you */
  121.              You_feel("rather itchy under %s.", yname(uarmc));
  122.              break;
  123.          }
  124.          if (ordinary || !rn2(10)) { /* permanent */
  125.              HInvis |= FROMOUTSIDE;
  126.          } else { /* temporary */
  127.              incr_itimeout(&HInvis, d(obj->spe, 250));
  128.          }
  129.          if (msg) {
  130.              learn_it = TRUE;
  131.              newsym(u.ux, u.uy);
  132.              self_invis_message();
  133.          }
  134.          break;
  135.      }
  136.  
  137.      case WAN_SPEED_MONSTER:
  138.          if (!(HFast & INTRINSIC)) {
  139.              learn_it = TRUE;
  140.              if (!Fast)
  141.                  You("speed up.");
  142.              else
  143.                  Your("quickness feels more natural.");
  144.              exercise(A_DEX, TRUE);
  145.          }
  146.          HFast |= FROMOUTSIDE;
  147.          break;
  148.  
  149.      case WAN_SLEEP:
  150.      case SPE_SLEEP:
  151.          learn_it = TRUE;
  152.          if (Sleep_resistance) {
  153.              shieldeff(u.ux, u.uy);
  154.              You("don't feel sleepy!");
  155.          } else {
  156.              pline_The("sleep ray hits you!");
  157.              fall_asleep(-rnd(50), TRUE);
  158.          }
  159.          break;
  160.  
  161.      case WAN_SLOW_MONSTER:
  162.      case SPE_SLOW_MONSTER:
  163.          if (HFast & (TIMEOUT | INTRINSIC)) {
  164.              learn_it = TRUE;
  165.              u_slow_down();
  166.          }
  167.          break;
  168.  
  169.      case WAN_TELEPORTATION:
  170.      case SPE_TELEPORT_AWAY:
  171.          tele();
  172.          /* same criteria as when mounted (zap_steed) */
  173.          if ((Teleport_control && !Stunned) || !couldsee(u.ux0, u.uy0)
  174.              || distu(u.ux0, u.uy0) >= 16)
  175.              learn_it = TRUE;
  176.          break;
  177.  
  178.      case WAN_DEATH:
  179.      case SPE_FINGER_OF_DEATH:
  180.          if (nonliving(youmonst.data) || is_demon(youmonst.data)) {
  181.              pline((obj->otyp == WAN_DEATH)
  182.                        ? "The wand shoots an apparently harmless beam at you."
  183.                        : "You seem no deader than before.");
  184.              break;
  185.          }
  186.          learn_it = TRUE;
  187.          Sprintf(killer.name, "shot %sself with a death ray", uhim());
  188.          killer.format = NO_KILLER_PREFIX;
  189.          You("irradiate yourself with pure energy!");
  190.          You("die.");
  191.          /* They might survive with an amulet of life saving */
  192.          done(DIED);
  193.          break;
  194.      case WAN_UNDEAD_TURNING:
  195.      case SPE_TURN_UNDEAD:
  196.          learn_it = TRUE;
  197.          (void) unturn_dead(&youmonst);
  198.          if (is_undead(youmonst.data)) {
  199.              You_feel("frightened and %sstunned.",
  200.                       Stunned ? "even more " : "");
  201.              make_stunned((HStun & TIMEOUT) + (long) rnd(30), FALSE);
  202.          } else
  203.              You("shudder in dread.");
  204.          break;
  205.      case SPE_HEALING:
  206.      case SPE_EXTRA_HEALING:
  207.          learn_it = TRUE; /* (no effect for spells...) */
  208.          healup(d(6, obj->otyp == SPE_EXTRA_HEALING ? 8 : 4), 0, FALSE,
  209.                 (obj->otyp == SPE_EXTRA_HEALING));
  210.          You_feel("%sbetter.", obj->otyp == SPE_EXTRA_HEALING ? "much " : "");
  211.          break;
  212.      case WAN_LIGHT: /* (broken wand) */
  213.          /* assert( !ordinary ); */
  214.          damage = d(obj->spe, 25);
  215.      case EXPENSIVE_CAMERA:
  216.          if (!damage)
  217.              damage = 5;
  218.          damage = lightdamage(obj, ordinary, damage);
  219.          damage += rnd(25);
  220.          if (flashburn((long) damage))
  221.              learn_it = TRUE;
  222.          damage = 0; /* reset */
  223.          break;
  224.      case WAN_OPENING:
  225.      case SPE_KNOCK:
  226.          if (Punished) {
  227.              learn_it = TRUE;
  228.              unpunish();
  229.          }
  230.          if (u.utrap) { /* escape web or bear trap */
  231.              (void) openholdingtrap(&youmonst, &learn_it);
  232.          } else { /* trigger previously escaped trapdoor */
  233.              (void) openfallingtrap(&youmonst, TRUE, &learn_it);
  234.          }
  235.          break;
  236.      case WAN_LOCKING:
  237.      case SPE_WIZARD_LOCK:
  238.          if (!u.utrap) {
  239.              (void) closeholdingtrap(&youmonst, &learn_it);
  240.          }
  241.          break;
  242.      case WAN_DIGGING:
  243.      case SPE_DIG:
  244.      case SPE_DETECT_UNSEEN:
  245.      case WAN_NOTHING:
  246.          break;
  247.      case WAN_PROBING: {
  248.          struct obj *otmp;
  249.  
  250.          for (otmp = invent; otmp; otmp = otmp->nobj) {
  251.              otmp->dknown = 1;
  252.              if (Is_container(otmp) || otmp->otyp == STATUE) {
  253.                  otmp->lknown = 1;
  254.                  if (!SchroedingersBox(otmp))
  255.                      otmp->cknown = 1;
  256.              }
  257.          }
  258.          learn_it = TRUE;
  259.          ustatusline();
  260.          break;
  261.      }
  262.      case SPE_STONE_TO_FLESH: {
  263.          struct obj *otmp, *onxt;
  264.          boolean didmerge;
  265.  
  266.          if (u.umonnum == PM_STONE_GOLEM) {
  267.              learn_it = TRUE;
  268.              (void) polymon(PM_FLESH_GOLEM);
  269.          }
  270.          if (Stoned) {
  271.              learn_it = TRUE;
  272.              fix_petrification(); /* saved! */
  273.          }
  274.          /* but at a cost.. */
  275.          for (otmp = invent; otmp; otmp = onxt) {
  276.              onxt = otmp->nobj;
  277.              if (bhito(otmp, obj))
  278.                  learn_it = TRUE;
  279.          }
  280.          /*
  281.           * It is possible that we can now merge some inventory.
  282.           * Do a highly paranoid merge.  Restart from the beginning
  283.           * until no merges.
  284.           */
  285.          do {
  286.              didmerge = FALSE;
  287.              for (otmp = invent; !didmerge && otmp; otmp = otmp->nobj)
  288.                  for (onxt = otmp->nobj; onxt; onxt = onxt->nobj)
  289.                      if (merged(&otmp, &onxt)) {
  290.                          didmerge = TRUE;
  291.                          break;
  292.                      }
  293.          } while (didmerge);
  294.          break;
  295.      }
  296.      default:
  297.          impossible("zapyourself: object %d used?", obj->otyp);
  298.          break;
  299.      }
  300.      /* if effect was observable then discover the wand type provided
  301.         that the wand itself has been seen */
  302.      if (learn_it)
  303.          learnwand(obj);
  304.      return damage;
  305.  }
  306.  

ubreatheu

  1.  /* called when poly'd hero uses breath attack against self */
  2.  void
  3.  ubreatheu(mattk)
  4.  struct attack *mattk;
  5.  {
  6.      int dtyp = 20 + mattk->adtyp - 1;      /* breath by hero */
  7.      const char *fltxt = flash_types[dtyp]; /* blast of <something> */
  8.  
  9.      zhitu(dtyp, mattk->damn, fltxt, u.ux, u.uy);
  10.  }
  11.  

lightdamage

  1.  /* light damages hero in gremlin form */
  2.  int
  3.  lightdamage(obj, ordinary, amt)
  4.  struct obj *obj;  /* item making light (fake book if spell) */
  5.  boolean ordinary; /* wand/camera zap vs wand destruction */
  6.  int amt;          /* pseudo-damage used to determine blindness duration */
  7.  {
  8.      char buf[BUFSZ];
  9.      const char *how;
  10.      int dmg = amt;
  11.  
  12.      if (dmg && youmonst.data == &mons[PM_GREMLIN]) {
  13.          /* reduce high values (from destruction of wand with many charges) */
  14.          dmg = rnd(dmg);
  15.          if (dmg > 10)
  16.              dmg = 10 + rnd(dmg - 10);
  17.          if (dmg > 20)
  18.              dmg = 20;
  19.          pline("Ow, that light hurts%c", (dmg > 2 || u.mh <= 5) ? '!' : '.');
  20.          /* [composing killer/reason is superfluous here; if fatal, cause
  21.             of death will always be "killed while stuck in creature form"] */
  22.          if (obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS)
  23.              ordinary = FALSE; /* say blasted rather than zapped */
  24.          how = (obj->oclass != SPBOOK_CLASS)
  25.                    ? (const char *) ansimpleoname(obj)
  26.                    : "spell of light";
  27.          Sprintf(buf, "%s %sself with %s", ordinary ? "zapped" : "blasted",
  28.                  uhim(), how);
  29.          /* might rehumanize(); could be fatal, but only for Unchanging */
  30.          losehp(Maybe_Half_Phys(dmg), buf, NO_KILLER_PREFIX);
  31.      }
  32.      return dmg;
  33.  }
  34.  

flashburn

  1.  /* light[ning] causes blindness */
  2.  boolean
  3.  flashburn(duration)
  4.  long duration;
  5.  {
  6.      if (!resists_blnd(&youmonst)) {
  7.          You(are_blinded_by_the_flash);
  8.          make_blinded(duration, FALSE);
  9.          if (!Blind)
  10.              Your1(vision_clears);
  11.          return TRUE;
  12.      }
  13.      return FALSE;
  14.  }
  15.  

zap_steed

  1.  /* you've zapped a wand downwards while riding
  2.   * Return TRUE if the steed was hit by the wand.
  3.   * Return FALSE if the steed was not hit by the wand.
  4.   */
  5.  STATIC_OVL boolean
  6.  zap_steed(obj)
  7.  struct obj *obj; /* wand or spell */
  8.  {
  9.      int steedhit = FALSE;
  10.  
  11.      switch (obj->otyp) {
  12.      /*
  13.       * Wands that are allowed to hit the steed
  14.       * Carefully test the results of any that are
  15.       * moved here from the bottom section.
  16.       */
  17.      case WAN_PROBING:
  18.          probe_monster(u.usteed);
  19.          learnwand(obj);
  20.          steedhit = TRUE;
  21.          break;
  22.      case WAN_TELEPORTATION:
  23.      case SPE_TELEPORT_AWAY:
  24.          /* you go together */
  25.          tele();
  26.          /* same criteria as when unmounted (zapyourself) */
  27.          if ((Teleport_control && !Stunned) || !couldsee(u.ux0, u.uy0)
  28.              || distu(u.ux0, u.uy0) >= 16)
  29.              learnwand(obj);
  30.          steedhit = TRUE;
  31.          break;
  32.  
  33.      /* Default processing via bhitm() for these */
  34.      case SPE_CURE_SICKNESS:
  35.      case WAN_MAKE_INVISIBLE:
  36.      case WAN_CANCELLATION:
  37.      case SPE_CANCELLATION:
  38.      case WAN_POLYMORPH:
  39.      case SPE_POLYMORPH:
  40.      case WAN_STRIKING:
  41.      case SPE_FORCE_BOLT:
  42.      case WAN_SLOW_MONSTER:
  43.      case SPE_SLOW_MONSTER:
  44.      case WAN_SPEED_MONSTER:
  45.      case SPE_HEALING:
  46.      case SPE_EXTRA_HEALING:
  47.      case SPE_DRAIN_LIFE:
  48.      case WAN_OPENING:
  49.      case SPE_KNOCK:
  50.          (void) bhitm(u.usteed, obj);
  51.          steedhit = TRUE;
  52.          break;
  53.  
  54.      default:
  55.          steedhit = FALSE;
  56.          break;
  57.      }
  58.      return steedhit;
  59.  }
  60.  

cancel_monst

  1.  /*
  2.   * cancel a monster (possibly the hero).  inventory is cancelled only
  3.   * if the monster is zapping itself directly, since otherwise the
  4.   * effect is too strong.  currently non-hero monsters do not zap
  5.   * themselves with cancellation.
  6.   */
  7.  boolean
  8.  cancel_monst(mdef, obj, youattack, allow_cancel_kill, self_cancel)
  9.  register struct monst *mdef;
  10.  register struct obj *obj;
  11.  boolean youattack, allow_cancel_kill, self_cancel;
  12.  {
  13.      boolean youdefend = (mdef == &youmonst);
  14.      static const char writing_vanishes[] =
  15.          "Some writing vanishes from %s head!";
  16.      static const char your[] = "your"; /* should be extern */
  17.  
  18.      if (youdefend ? (!youattack && Antimagic)
  19.                    : resist(mdef, obj->oclass, 0, NOTELL))
  20.          return FALSE; /* resisted cancellation */
  21.  
  22.      if (self_cancel) { /* 1st cancel inventory */
  23.          struct obj *otmp;
  24.  
  25.          for (otmp = (youdefend ? invent : mdef->minvent); otmp;
  26.               otmp = otmp->nobj)
  27.              cancel_item(otmp);
  28.          if (youdefend) {
  29.              context.botl = 1; /* potential AC change */
  30.              find_ac();
  31.          }
  32.      }
  33.  
  34.      /* now handle special cases */
  35.      if (youdefend) {
  36.          if (Upolyd) {
  37.              if ((u.umonnum == PM_CLAY_GOLEM) && !Blind)
  38.                  pline(writing_vanishes, your);
  39.  
  40.              if (Unchanging)
  41.                  Your("amulet grows hot for a moment, then cools.");
  42.              else
  43.                  rehumanize();
  44.          }
  45.      } else {
  46.          mdef->mcan = TRUE;
  47.  
  48.          if (is_were(mdef->data) && mdef->data->mlet != S_HUMAN)
  49.              were_change(mdef);
  50.  
  51.          if (mdef->data == &mons[PM_CLAY_GOLEM]) {
  52.              if (canseemon(mdef))
  53.                  pline(writing_vanishes, s_suffix(mon_nam(mdef)));
  54.  
  55.              if (allow_cancel_kill) {
  56.                  if (youattack)
  57.                      killed(mdef);
  58.                  else
  59.                      monkilled(mdef, "", AD_SPEL);
  60.              }
  61.          }
  62.      }
  63.      return TRUE;
  64.  }
  65.  

zap_updown

  1.  /* you've zapped an immediate type wand up or down */
  2.  STATIC_OVL boolean
  3.  zap_updown(obj)
  4.  struct obj *obj; /* wand or spell */
  5.  {
  6.      boolean striking = FALSE, disclose = FALSE;
  7.      int x, y, xx, yy, ptmp;
  8.      struct obj *otmp;
  9.      struct engr *e;
  10.      struct trap *ttmp;
  11.      char buf[BUFSZ];
  12.  
  13.      /* some wands have special effects other than normal bhitpile */
  14.      /* drawbridge might change <u.ux,u.uy> */
  15.      x = xx = u.ux;     /* <x,y> is zap location */
  16.      y = yy = u.uy;     /* <xx,yy> is drawbridge (portcullis) position */
  17.      ttmp = t_at(x, y); /* trap if there is one */
  18.  
  19.      switch (obj->otyp) {
  20.      case WAN_PROBING:
  21.          ptmp = 0;
  22.          if (u.dz < 0) {
  23.              You("probe towards the %s.", ceiling(x, y));
  24.          } else {
  25.              ptmp += bhitpile(obj, bhito, x, y, u.dz);
  26.              You("probe beneath the %s.", surface(x, y));
  27.              ptmp += display_binventory(x, y, TRUE);
  28.          }
  29.          if (!ptmp)
  30.              Your("probe reveals nothing.");
  31.          return TRUE; /* we've done our own bhitpile */
  32.      case WAN_OPENING:
  33.      case SPE_KNOCK:
  34.          /* up or down, but at closed portcullis only */
  35.          if (is_db_wall(x, y) && find_drawbridge(&xx, &yy)) {
  36.              open_drawbridge(xx, yy);
  37.              disclose = TRUE;
  38.          } else if (u.dz > 0 && (x == xdnstair && y == ydnstair) &&
  39.                     /* can't use the stairs down to quest level 2 until
  40.                        leader "unlocks" them; give feedback if you try */
  41.                     on_level(&u.uz, &qstart_level) && !ok_to_quest()) {
  42.              pline_The("stairs seem to ripple momentarily.");
  43.              disclose = TRUE;
  44.          }
  45.          /* down will release you from bear trap or web */
  46.          if (u.dz > 0 && u.utrap) {
  47.              (void) openholdingtrap(&youmonst, &disclose);
  48.              /* down will trigger trapdoor, hole, or [spiked-] pit */
  49.          } else if (u.dz > 0 && !u.utrap) {
  50.              (void) openfallingtrap(&youmonst, FALSE, &disclose);
  51.          }
  52.          break;
  53.      case WAN_STRIKING:
  54.      case SPE_FORCE_BOLT:
  55.          striking = TRUE;
  56.          /*FALLTHRU*/
  57.      case WAN_LOCKING:
  58.      case SPE_WIZARD_LOCK:
  59.          /* down at open bridge or up or down at open portcullis */
  60.          if (((levl[x][y].typ == DRAWBRIDGE_DOWN)
  61.                   ? (u.dz > 0)
  62.                   : (is_drawbridge_wall(x, y) >= 0 && !is_db_wall(x, y)))
  63.              && find_drawbridge(&xx, &yy)) {
  64.              if (!striking)
  65.                  close_drawbridge(xx, yy);
  66.              else
  67.                  destroy_drawbridge(xx, yy);
  68.              disclose = TRUE;
  69.          } else if (striking && u.dz < 0 && rn2(3) && !Is_airlevel(&u.uz)
  70.                     && !Is_waterlevel(&u.uz) && !Underwater
  71.                     && !Is_qstart(&u.uz)) {
  72.              int dmg;
  73.              /* similar to zap_dig() */
  74.              pline("A rock is dislodged from the %s and falls on your %s.",
  75.                    ceiling(x, y), body_part(HEAD));
  76.              dmg = rnd((uarmh && is_metallic(uarmh)) ? 2 : 6);
  77.              losehp(Maybe_Half_Phys(dmg), "falling rock", KILLED_BY_AN);
  78.              if ((otmp = mksobj_at(ROCK, x, y, FALSE, FALSE)) != 0) {
  79.                  (void) xname(otmp); /* set dknown, maybe bknown */
  80.                  stackobj(otmp);
  81.              }
  82.              newsym(x, y);
  83.          } else if (u.dz > 0 && ttmp) {
  84.              if (!striking && closeholdingtrap(&youmonst, &disclose)) {
  85.                  ; /* now stuck in web or bear trap */
  86.              } else if (striking && ttmp->ttyp == TRAPDOOR) {
  87.                  /* striking transforms trapdoor into hole */
  88.                  if (Blind && !ttmp->tseen) {
  89.                      pline("%s beneath you shatters.", Something);
  90.                  } else if (!ttmp->tseen) { /* => !Blind */
  91.                      pline("There's a trapdoor beneath you; it shatters.");
  92.                  } else {
  93.                      pline("The trapdoor beneath you shatters.");
  94.                      disclose = TRUE;
  95.                  }
  96.                  ttmp->ttyp = HOLE;
  97.                  ttmp->tseen = 1;
  98.                  newsym(x, y);
  99.                  /* might fall down hole */
  100.                  dotrap(ttmp, 0);
  101.              } else if (!striking && ttmp->ttyp == HOLE) {
  102.                  /* locking transforms hole into trapdoor */
  103.                  ttmp->ttyp = TRAPDOOR;
  104.                  if (Blind || !ttmp->tseen) {
  105.                      pline("Some %s swirls beneath you.",
  106.                            is_ice(x, y) ? "frost" : "dust");
  107.                  } else {
  108.                      ttmp->tseen = 1;
  109.                      newsym(x, y);
  110.                      pline("A trapdoor appears beneath you.");
  111.                      disclose = TRUE;
  112.                  }
  113.                  /* hadn't fallen down hole; won't fall now */
  114.              }
  115.          }
  116.          break;
  117.      case SPE_STONE_TO_FLESH:
  118.          if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz) || Underwater
  119.              || (Is_qstart(&u.uz) && u.dz < 0)) {
  120.              pline1(nothing_happens);
  121.          } else if (u.dz < 0) { /* we should do more... */
  122.              pline("Blood drips on your %s.", body_part(FACE));
  123.          } else if (u.dz > 0 && !OBJ_AT(u.ux, u.uy)) {
  124.              /*
  125.              Print this message only if there wasn't an engraving
  126.              affected here.  If water or ice, act like waterlevel case.
  127.              */
  128.              e = engr_at(u.ux, u.uy);
  129.              if (!(e && e->engr_type == ENGRAVE)) {
  130.                  if (is_pool(u.ux, u.uy) || is_ice(u.ux, u.uy))
  131.                      pline1(nothing_happens);
  132.                  else
  133.                      pline("Blood %ss %s your %s.",
  134.                            is_lava(u.ux, u.uy) ? "boil" : "pool",
  135.                            Levitation ? "beneath" : "at",
  136.                            makeplural(body_part(FOOT)));
  137.              }
  138.          }
  139.          break;
  140.      default:
  141.          break;
  142.      }
  143.  
  144.      if (u.dz > 0) {
  145.          /* zapping downward */
  146.          (void) bhitpile(obj, bhito, x, y, u.dz);
  147.  
  148.          /* subset of engraving effects; none sets `disclose' */
  149.          if ((e = engr_at(x, y)) != 0 && e->engr_type != HEADSTONE) {
  150.              switch (obj->otyp) {
  151.              case WAN_POLYMORPH:
  152.              case SPE_POLYMORPH:
  153.                  del_engr(e);
  154.                  make_engr_at(x, y, random_engraving(buf), moves, (xchar) 0);
  155.                  break;
  156.              case WAN_CANCELLATION:
  157.              case SPE_CANCELLATION:
  158.              case WAN_MAKE_INVISIBLE:
  159.                  del_engr(e);
  160.                  break;
  161.              case WAN_TELEPORTATION:
  162.              case SPE_TELEPORT_AWAY:
  163.                  rloc_engr(e);
  164.                  break;
  165.              case SPE_STONE_TO_FLESH:
  166.                  if (e->engr_type == ENGRAVE) {
  167.                      /* only affects things in stone */
  168.                      pline_The(Hallucination
  169.                                    ? "floor runs like butter!"
  170.                                    : "edges on the floor get smoother.");
  171.                      wipe_engr_at(x, y, d(2, 4), TRUE);
  172.                  }
  173.                  break;
  174.              case WAN_STRIKING:
  175.              case SPE_FORCE_BOLT:
  176.                  wipe_engr_at(x, y, d(2, 4), TRUE);
  177.                  break;
  178.              default:
  179.                  break;
  180.              }
  181.          }
  182.      } else if (u.dz < 0) {
  183.          /* zapping upward */
  184.  
  185.          /* game flavor: if you're hiding under "something"
  186.           * a zap upward should hit that "something".
  187.           */
  188.          if (u.uundetected && hides_under(youmonst.data)) {
  189.              int hitit = 0;
  190.              otmp = level.objects[u.ux][u.uy];
  191.  
  192.              if (otmp)
  193.                  hitit = bhito(otmp, obj);
  194.              if (hitit) {
  195.                  (void) hideunder(&youmonst);
  196.                  disclose = TRUE;
  197.              }
  198.          }
  199.      }
  200.  
  201.      return disclose;
  202.  }
  203.  

zapsetup

  1.  /* used by do_break_wand() was well as by weffects() */
  2.  void
  3.  zapsetup()
  4.  {
  5.      obj_zapped = FALSE;
  6.  }
  7.  

zapwrapup

  1.  void
  2.  zapwrapup()
  3.  {
  4.      /* if do_osshock() set obj_zapped while polying, give a message now */
  5.      if (obj_zapped)
  6.          You_feel("shuddering vibrations.");
  7.      obj_zapped = FALSE;
  8.  }
  9.  

weffects

  1.  /* called for various wand and spell effects - M. Stephenson */
  2.  void
  3.  weffects(obj)
  4.  struct obj *obj;
  5.  {
  6.      int otyp = obj->otyp;
  7.      boolean disclose = FALSE, was_unkn = !objects[otyp].oc_name_known;
  8.  
  9.      exercise(A_WIS, TRUE);
  10.      if (u.usteed && (objects[otyp].oc_dir != NODIR) && !u.dx && !u.dy
  11.          && (u.dz > 0) && zap_steed(obj)) {
  12.          disclose = TRUE;
  13.      } else if (objects[otyp].oc_dir == IMMEDIATE) {
  14.          zapsetup(); /* reset obj_zapped */
  15.          if (u.uswallow) {
  16.              (void) bhitm(u.ustuck, obj);
  17.              /* [how about `bhitpile(u.ustuck->minvent)' effect?] */
  18.          } else if (u.dz) {
  19.              disclose = zap_updown(obj);
  20.          } else {
  21.              (void) bhit(u.dx, u.dy, rn1(8, 6), ZAPPED_WAND, bhitm, bhito,
  22.                          &obj);
  23.          }
  24.          zapwrapup(); /* give feedback for obj_zapped */
  25.  
  26.      } else if (objects[otyp].oc_dir == NODIR) {
  27.          zapnodir(obj);
  28.  
  29.      } else {
  30.          /* neither immediate nor directionless */
  31.  
  32.          if (otyp == WAN_DIGGING || otyp == SPE_DIG)
  33.              zap_dig();
  34.          else if (otyp >= SPE_MAGIC_MISSILE && otyp <= SPE_FINGER_OF_DEATH)
  35.              buzz(otyp - SPE_MAGIC_MISSILE + 10, u.ulevel / 2 + 1, u.ux, u.uy,
  36.                   u.dx, u.dy);
  37.          else if (otyp >= WAN_MAGIC_MISSILE && otyp <= WAN_LIGHTNING)
  38.              buzz(otyp - WAN_MAGIC_MISSILE,
  39.                   (otyp == WAN_MAGIC_MISSILE) ? 2 : 6, u.ux, u.uy, u.dx, u.dy);
  40.          else
  41.              impossible("weffects: unexpected spell or wand");
  42.          disclose = TRUE;
  43.      }
  44.      if (disclose) {
  45.          learnwand(obj);
  46.          if (was_unkn)
  47.              more_experienced(0, 10);
  48.      }
  49.      return;
  50.  }
  51.  

spell_damage_bonus

  1.  /* augment damage for a spell dased on the hero's intelligence (and level) */
  2.  int
  3.  spell_damage_bonus(dmg)
  4.  int dmg; /* base amount to be adjusted by bonus or penalty */
  5.  {
  6.      int intell = ACURR(A_INT);
  7.  
  8.      /* Punish low intelligence before low level else low intelligence
  9.         gets punished only when high level */
  10.      if (intell <= 9) {
  11.          /* -3 penalty, but never reduce combined amount below 1
  12.             (if dmg is 0 for some reason, we're careful to leave it there) */
  13.          if (dmg > 1)
  14.              dmg = (dmg <= 3) ? 1 : dmg - 3;
  15.      } else if (intell <= 13 || u.ulevel < 5)
  16.          ; /* no bonus or penalty; dmg remains same */
  17.      else if (intell <= 18)
  18.          dmg += 1;
  19.      else if (intell <= 24 || u.ulevel < 14)
  20.          dmg += 2;
  21.      else
  22.          dmg += 3; /* Int 25 */
  23.  
  24.      return dmg;
  25.  }
  26.  

spell_hit_bonus

  1.  /*
  2.   * Generate the to hit bonus for a spell.  Based on the hero's skill in
  3.   * spell class and dexterity.
  4.   */
  5.  STATIC_OVL int
  6.  spell_hit_bonus(skill)
  7.  int skill;
  8.  {
  9.      int hit_bon = 0;
  10.      int dex = ACURR(A_DEX);
  11.  
  12.      switch (P_SKILL(spell_skilltype(skill))) {
  13.      case P_ISRESTRICTED:
  14.      case P_UNSKILLED:
  15.          hit_bon = -4;
  16.          break;
  17.      case P_BASIC:
  18.          hit_bon = 0;
  19.          break;
  20.      case P_SKILLED:
  21.          hit_bon = 2;
  22.          break;
  23.      case P_EXPERT:
  24.          hit_bon = 3;
  25.          break;
  26.      }
  27.  
  28.      if (dex < 4)
  29.          hit_bon -= 3;
  30.      else if (dex < 6)
  31.          hit_bon -= 2;
  32.      else if (dex < 8)
  33.          hit_bon -= 1;
  34.      else if (dex < 14)
  35.          /* Will change when print stuff below removed */
  36.          hit_bon -= 0;
  37.      else
  38.          /* Even increment for dextrous heroes (see weapon.c abon) */
  39.          hit_bon += dex - 14;
  40.  
  41.      return hit_bon;
  42.  }
  43.  

exclam

  1.  const char *
  2.  exclam(force)
  3.  int force;
  4.  {
  5.      /* force == 0 occurs e.g. with sleep ray */
  6.      /* note that large force is usual with wands so that !! would
  7.              require information about hand/weapon/wand */
  8.      return (const char *) ((force < 0) ? "?" : (force <= 4) ? "." : "!");
  9.  }
  10.  

hit

  1.  void
  2.  hit(str, mtmp, force)
  3.  const char *str;
  4.  struct monst *mtmp;
  5.  const char *force; /* usually either "." or "!" */
  6.  {
  7.      if ((!cansee(bhitpos.x, bhitpos.y) && !canspotmon(mtmp)
  8.           && !(u.uswallow && mtmp == u.ustuck)) || !flags.verbose)
  9.          pline("%s %s it.", The(str), vtense(str, "hit"));
  10.      else
  11.          pline("%s %s %s%s", The(str), vtense(str, "hit"),
  12.                mon_nam(mtmp), force);
  13.  }
  14.  

miss

  1.  void
  2.  miss(str, mtmp)
  3.  register const char *str;
  4.  register struct monst *mtmp;
  5.  {
  6.      pline(
  7.          "%s %s %s.", The(str), vtense(str, "miss"),
  8.          ((cansee(bhitpos.x, bhitpos.y) || canspotmon(mtmp)) && flags.verbose)
  9.              ? mon_nam(mtmp)
  10.              : "it");
  11.  }
  12.  

skiprange

  1.  STATIC_OVL void
  2.  skiprange(range, skipstart, skipend)
  3.  int range, *skipstart, *skipend;
  4.  {
  5.      int tr = (range / 4);
  6.      int tmp = range - ((tr > 0) ? rnd(tr) : 0);
  7.      *skipstart = tmp;
  8.      *skipend = tmp - ((tmp / 4) * rnd(3));
  9.      if (*skipend >= tmp)
  10.          *skipend = tmp - 1;
  11.  }
  12.  

bhit

  1.  /*
  2.   *  Called for the following distance effects:
  3.   *      when a weapon is thrown (weapon == THROWN_WEAPON)
  4.   *      when an object is kicked (KICKED_WEAPON)
  5.   *      when an IMMEDIATE wand is zapped (ZAPPED_WAND)
  6.   *      when a light beam is flashed (FLASHED_LIGHT)
  7.   *      when a mirror is applied (INVIS_BEAM)
  8.   *  A thrown/kicked object falls down at end of its range or when a monster
  9.   *  is hit.  The variable 'bhitpos' is set to the final position of the weapon
  10.   *  thrown/zapped.  The ray of a wand may affect (by calling a provided
  11.   *  function) several objects and monsters on its path.  The return value
  12.   *  is the monster hit (weapon != ZAPPED_WAND), or a null monster pointer.
  13.   *
  14.   * Thrown and kicked objects (THROWN_WEAPON or KICKED_WEAPON) may be
  15.   * destroyed and *pobj set to NULL to indicate this.
  16.   *
  17.   *  Check !u.uswallow before calling bhit().
  18.   *  This function reveals the absence of a remembered invisible monster in
  19.   *  necessary cases (throwing or kicking weapons).  The presence of a real
  20.   *  one is revealed for a weapon, but if not a weapon is left up to fhitm().
  21.   */
  22.  struct monst *
  23.  bhit(ddx, ddy, range, weapon, fhitm, fhito, pobj)
  24.  register int ddx, ddy, range;          /* direction and range */
  25.  int weapon;                            /* see values in hack.h */
  26.  int FDECL((*fhitm), (MONST_P, OBJ_P)), /* fns called when mon/obj hit */
  27.      FDECL((*fhito), (OBJ_P, OBJ_P));
  28.  struct obj **pobj; /* object tossed/used, set to NULL
  29.                      * if object is destroyed */
  30.  {
  31.      struct monst *mtmp;
  32.      struct obj *obj = *pobj;
  33.      uchar typ;
  34.      boolean shopdoor = FALSE, point_blank = TRUE;
  35.      boolean in_skip = FALSE, allow_skip = FALSE;
  36.      int skiprange_start = 0, skiprange_end = 0, skipcount = 0;
  37.  
  38.      if (weapon == KICKED_WEAPON) {
  39.          /* object starts one square in front of player */
  40.          bhitpos.x = u.ux + ddx;
  41.          bhitpos.y = u.uy + ddy;
  42.          range--;
  43.      } else {
  44.          bhitpos.x = u.ux;
  45.          bhitpos.y = u.uy;
  46.      }
  47.  
  48.      if (weapon == THROWN_WEAPON && obj && obj->otyp == ROCK) {
  49.          skiprange(range, &skiprange_start, &skiprange_end);
  50.          allow_skip = !rn2(3);
  51.      }
  52.  
  53.      if (weapon == FLASHED_LIGHT) {
  54.          tmp_at(DISP_BEAM, cmap_to_glyph(S_flashbeam));
  55.      } else if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM)
  56.          tmp_at(DISP_FLASH, obj_to_glyph(obj));
  57.  
  58.      while (range-- > 0) {
  59.          int x, y;
  60.  
  61.          bhitpos.x += ddx;
  62.          bhitpos.y += ddy;
  63.          x = bhitpos.x;
  64.          y = bhitpos.y;
  65.  
  66.          if (!isok(x, y)) {
  67.              bhitpos.x -= ddx;
  68.              bhitpos.y -= ddy;
  69.              break;
  70.          }
  71.  
  72.          if (is_pick(obj) && inside_shop(x, y)
  73.              && (mtmp = shkcatch(obj, x, y))) {
  74.              tmp_at(DISP_END, 0);
  75.              return mtmp;
  76.          }
  77.  
  78.          typ = levl[bhitpos.x][bhitpos.y].typ;
  79.  
  80.          /* iron bars will block anything big enough */
  81.          if ((weapon == THROWN_WEAPON || weapon == KICKED_WEAPON)
  82.              && typ == IRONBARS && hits_bars(pobj, x - ddx, y - ddy,
  83.                                              point_blank ? 0 : !rn2(5), 1)) {
  84.              /* caveat: obj might now be null... */
  85.              obj = *pobj;
  86.              bhitpos.x -= ddx;
  87.              bhitpos.y -= ddy;
  88.              break;
  89.          }
  90.  
  91.          if (weapon == ZAPPED_WAND && find_drawbridge(&x, &y)) {
  92.              boolean learn_it = FALSE;
  93.  
  94.              switch (obj->otyp) {
  95.              case WAN_OPENING:
  96.              case SPE_KNOCK:
  97.                  if (is_db_wall(bhitpos.x, bhitpos.y)) {
  98.                      if (cansee(x, y) || cansee(bhitpos.x, bhitpos.y))
  99.                          learn_it = TRUE;
  100.                      open_drawbridge(x, y);
  101.                  }
  102.                  break;
  103.              case WAN_LOCKING:
  104.              case SPE_WIZARD_LOCK:
  105.                  if ((cansee(x, y) || cansee(bhitpos.x, bhitpos.y))
  106.                      && levl[x][y].typ == DRAWBRIDGE_DOWN)
  107.                      learn_it = TRUE;
  108.                  close_drawbridge(x, y);
  109.                  break;
  110.              case WAN_STRIKING:
  111.              case SPE_FORCE_BOLT:
  112.                  if (typ != DRAWBRIDGE_UP)
  113.                      destroy_drawbridge(x, y);
  114.                  learn_it = TRUE;
  115.                  break;
  116.              }
  117.              if (learn_it)
  118.                  learnwand(obj);
  119.          }
  120.  
  121.          mtmp = m_at(bhitpos.x, bhitpos.y);
  122.  
  123.          /*
  124.           * skipping rocks
  125.           *
  126.           * skiprange_start is only set if this is a thrown rock
  127.           */
  128.          if (skiprange_start && (range == skiprange_start) && allow_skip) {
  129.              if (is_pool(bhitpos.x, bhitpos.y) && !mtmp) {
  130.                  in_skip = TRUE;
  131.                  if (!Blind)
  132.                      pline("%s %s%s.", Yname2(obj), otense(obj, "skip"),
  133.                            skipcount ? " again" : "");
  134.                  else
  135.                      You_hear("%s skip.", yname(obj));
  136.                  skipcount++;
  137.              } else if (skiprange_start > skiprange_end + 1) {
  138.                  --skiprange_start;
  139.              }
  140.          }
  141.          if (in_skip) {
  142.              if (range <= skiprange_end) {
  143.                  in_skip = FALSE;
  144.                  if (range > 3) /* another bounce? */
  145.                      skiprange(range, &skiprange_start, &skiprange_end);
  146.              } else if (mtmp && M_IN_WATER(mtmp->data)) {
  147.                  if ((!Blind && canseemon(mtmp)) || sensemon(mtmp))
  148.                      pline("%s %s over %s.", Yname2(obj), otense(obj, "pass"),
  149.                            mon_nam(mtmp));
  150.              }
  151.          }
  152.  
  153.          if (mtmp && !(in_skip && M_IN_WATER(mtmp->data))) {
  154.              notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my);
  155.              if (weapon == FLASHED_LIGHT) {
  156.                  /* FLASHED_LIGHT hitting invisible monster should
  157.                     pass through instead of stop so we call
  158.                     flash_hits_mon() directly rather than returning
  159.                     mtmp back to caller.  That allows the flash to
  160.                     keep on going.  Note that we use mtmp->minvis
  161.                     not canspotmon() because it makes no difference
  162.                     whether the hero can see the monster or not. */
  163.                  if (mtmp->minvis) {
  164.                      obj->ox = u.ux, obj->oy = u.uy;
  165.                      (void) flash_hits_mon(mtmp, obj);
  166.                  } else {
  167.                      tmp_at(DISP_END, 0);
  168.                      return mtmp; /* caller will call flash_hits_mon */
  169.                  }
  170.              } else if (weapon == INVIS_BEAM) {
  171.                  /* Like FLASHED_LIGHT, INVIS_BEAM should continue
  172.                     through invisible targets; unlike it, we aren't
  173.                     prepared for multiple hits so just get first one
  174.                     that's either visible or could see its invisible
  175.                     self.  [No tmp_at() cleanup is needed here.] */
  176.                  if (!mtmp->minvis || perceives(mtmp->data))
  177.                      return mtmp;
  178.              } else if (weapon != ZAPPED_WAND) {
  179.                  /* THROWN_WEAPON, KICKED_WEAPON */
  180.                  tmp_at(DISP_END, 0);
  181.                  if (cansee(bhitpos.x, bhitpos.y) && !canspotmon(mtmp))
  182.                      map_invisible(bhitpos.x, bhitpos.y);
  183.                  return mtmp;
  184.              } else {
  185.                  /* ZAPPED_WAND */
  186.                  (*fhitm)(mtmp, obj);
  187.                  range -= 3;
  188.              }
  189.          } else {
  190.              if (weapon == ZAPPED_WAND && obj->otyp == WAN_PROBING
  191.                  && glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph)) {
  192.                  unmap_object(bhitpos.x, bhitpos.y);
  193.                  newsym(x, y);
  194.              }
  195.          }
  196.          if (fhito) {
  197.              if (bhitpile(obj, fhito, bhitpos.x, bhitpos.y, 0))
  198.                  range--;
  199.          } else {
  200.              if (weapon == KICKED_WEAPON
  201.                  && ((obj->oclass == COIN_CLASS
  202.                       && OBJ_AT(bhitpos.x, bhitpos.y))
  203.                      || ship_object(obj, bhitpos.x, bhitpos.y,
  204.                                     costly_spot(bhitpos.x, bhitpos.y)))) {
  205.                  tmp_at(DISP_END, 0);
  206.                  return (struct monst *) 0;
  207.              }
  208.          }
  209.          if (weapon == ZAPPED_WAND && (IS_DOOR(typ) || typ == SDOOR)) {
  210.              switch (obj->otyp) {
  211.              case WAN_OPENING:
  212.              case WAN_LOCKING:
  213.              case WAN_STRIKING:
  214.              case SPE_KNOCK:
  215.              case SPE_WIZARD_LOCK:
  216.              case SPE_FORCE_BOLT:
  217.                  if (doorlock(obj, bhitpos.x, bhitpos.y)) {
  218.                      if (cansee(bhitpos.x, bhitpos.y)
  219.                          || (obj->otyp == WAN_STRIKING && !Deaf))
  220.                          learnwand(obj);
  221.                      if (levl[bhitpos.x][bhitpos.y].doormask == D_BROKEN
  222.                          && *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE)) {
  223.                          shopdoor = TRUE;
  224.                          add_damage(bhitpos.x, bhitpos.y, 400L);
  225.                      }
  226.                  }
  227.                  break;
  228.              }
  229.          }
  230.          if (!ZAP_POS(typ) || closed_door(bhitpos.x, bhitpos.y)) {
  231.              bhitpos.x -= ddx;
  232.              bhitpos.y -= ddy;
  233.              break;
  234.          }
  235.          if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM) {
  236.              /* 'I' present but no monster: erase */
  237.              /* do this before the tmp_at() */
  238.              if (glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph)
  239.                  && cansee(x, y)) {
  240.                  unmap_object(bhitpos.x, bhitpos.y);
  241.                  newsym(x, y);
  242.              }
  243.              tmp_at(bhitpos.x, bhitpos.y);
  244.              delay_output();
  245.              /* kicked objects fall in pools */
  246.              if ((weapon == KICKED_WEAPON)
  247.                  && (is_pool(bhitpos.x, bhitpos.y)
  248.                      || is_lava(bhitpos.x, bhitpos.y)))
  249.                  break;
  250.              if (IS_SINK(typ) && weapon != FLASHED_LIGHT)
  251.                  break; /* physical objects fall onto sink */
  252.          }
  253.          /* limit range of ball so hero won't make an invalid move */
  254.          if (weapon == THROWN_WEAPON && range > 0
  255.              && obj->otyp == HEAVY_IRON_BALL) {
  256.              struct obj *bobj;
  257.              struct trap *t;
  258.              if ((bobj = sobj_at(BOULDER, x, y)) != 0) {
  259.                  if (cansee(x, y))
  260.                      pline("%s hits %s.", The(distant_name(obj, xname)),
  261.                            an(xname(bobj)));
  262.                  range = 0;
  263.              } else if (obj == uball) {
  264.                  if (!test_move(x - ddx, y - ddy, ddx, ddy, TEST_MOVE)) {
  265.                      /* nb: it didn't hit anything directly */
  266.                      if (cansee(x, y))
  267.                          pline("%s jerks to an abrupt halt.",
  268.                                The(distant_name(obj, xname))); /* lame */
  269.                      range = 0;
  270.                  } else if (Sokoban && (t = t_at(x, y)) != 0
  271.                             && (t->ttyp == PIT || t->ttyp == SPIKED_PIT
  272.                                 || t->ttyp == HOLE || t->ttyp == TRAPDOOR)) {
  273.                      /* hero falls into the trap, so ball stops */
  274.                      range = 0;
  275.                  }
  276.              }
  277.          }
  278.  
  279.          /* thrown/kicked missile has moved away from its starting spot */
  280.          point_blank = FALSE; /* affects passing through iron bars */
  281.      }
  282.  
  283.      if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM)
  284.          tmp_at(DISP_END, 0);
  285.  
  286.      if (shopdoor)
  287.          pay_for_damage("destroy", FALSE);
  288.  
  289.      return (struct monst *) 0;
  290.  }
  291.  

boomhit

  1.  /* process thrown boomerang, which travels a curving path...
  2.   * A multi-shot volley ought to have all missiles in flight at once,
  3.   * but we're called separately for each one.  We terminate the volley
  4.   * early on a failed catch since continuing to throw after being hit
  5.   * is too obviously silly.
  6.   */
  7.  struct monst *
  8.  boomhit(obj, dx, dy)
  9.  struct obj *obj;
  10.  int dx, dy;
  11.  {
  12.      register int i, ct;
  13.      int boom; /* showsym[] index  */
  14.      struct monst *mtmp;
  15.      boolean counterclockwise = TRUE; /* right-handed throw */
  16.  
  17.      /* counterclockwise traversal patterns:
  18.       *  ..........................54.................................
  19.       *  ..................43.....6..3....765.........................
  20.       *  ..........32.....5..2...7...2...8...4....87..................
  21.       *  .........4..1....6..1...8..1....9...3...9..6.....98..........
  22.       *  ..21@....5...@...7..@....9@......@12....@...5...@..7.....@9..
  23.       *  .3...9....6..9....89.....................1..4...1..6....1..8.
  24.       *  .4...8.....78.............................23....2..5...2...7.
  25.       *  ..567............................................34....3..6..
  26.       *  ........................................................45...
  27.       * (invert rows for corresponding clockwise patterns)
  28.       */
  29.  
  30.      bhitpos.x = u.ux;
  31.      bhitpos.y = u.uy;
  32.      boom = counterclockwise ? S_boomleft : S_boomright;
  33.      for (i = 0; i < 8; i++)
  34.          if (xdir[i] == dx && ydir[i] == dy)
  35.              break;
  36.      tmp_at(DISP_FLASH, cmap_to_glyph(boom));
  37.      for (ct = 0; ct < 10; ct++) {
  38.          i = (i + 8) % 8;                          /* 0..7 (8 -> 0, -1 -> 7) */
  39.          boom = (S_boomleft + S_boomright - boom); /* toggle */
  40.          tmp_at(DISP_CHANGE, cmap_to_glyph(boom)); /* change glyph */
  41.          dx = xdir[i];
  42.          dy = ydir[i];
  43.          bhitpos.x += dx;
  44.          bhitpos.y += dy;
  45.          if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) {
  46.              m_respond(mtmp);
  47.              tmp_at(DISP_END, 0);
  48.              return mtmp;
  49.          }
  50.          if (!ZAP_POS(levl[bhitpos.x][bhitpos.y].typ)
  51.              || closed_door(bhitpos.x, bhitpos.y)) {
  52.              bhitpos.x -= dx;
  53.              bhitpos.y -= dy;
  54.              break;
  55.          }
  56.          if (bhitpos.x == u.ux && bhitpos.y == u.uy) { /* ct == 9 */
  57.              if (Fumbling || rn2(20) >= ACURR(A_DEX)) {
  58.                  /* we hit ourselves */
  59.                  (void) thitu(10 + obj->spe, dmgval(obj, &youmonst), obj,
  60.                               "boomerang");
  61.                  endmultishot(TRUE);
  62.                  break;
  63.              } else { /* we catch it */
  64.                  tmp_at(DISP_END, 0);
  65.                  You("skillfully catch the boomerang.");
  66.                  return &youmonst;
  67.              }
  68.          }
  69.          tmp_at(bhitpos.x, bhitpos.y);
  70.          delay_output();
  71.          if (IS_SINK(levl[bhitpos.x][bhitpos.y].typ)) {
  72.              if (!Deaf)
  73.                  pline("Klonk!");
  74.              break; /* boomerang falls on sink */
  75.          }
  76.          /* ct==0, initial position, we want next delta to be same;
  77.             ct==5, opposite position, repeat delta undoes first one */
  78.          if (ct % 5 != 0)
  79.              i += (counterclockwise ? -1 : 1);
  80.      }
  81.      tmp_at(DISP_END, 0); /* do not leave last symbol */
  82.      return (struct monst *) 0;
  83.  }
  84.  

zhitm

  1.  /* used by buzz(); also used by munslime(muse.c); returns damage to mon */
  2.  int
  3.  zhitm(mon, type, nd, ootmp)
  4.  register struct monst *mon;
  5.  register int type, nd;
  6.  struct obj **ootmp; /* to return worn armor for caller to disintegrate */
  7.  {
  8.      register int tmp = 0;
  9.      register int abstype = abs(type) % 10;
  10.      boolean sho_shieldeff = FALSE;
  11.      boolean spellcaster = is_hero_spell(type); /* maybe get a bonus! */
  12.  
  13.      *ootmp = (struct obj *) 0;
  14.      switch (abstype) {
  15.      case ZT_MAGIC_MISSILE:
  16.          if (resists_magm(mon)) {
  17.              sho_shieldeff = TRUE;
  18.              break;
  19.          }
  20.          tmp = d(nd, 6);
  21.          if (spellcaster)
  22.              tmp = spell_damage_bonus(tmp);
  23.          break;
  24.      case ZT_FIRE:
  25.          if (resists_fire(mon)) {
  26.              sho_shieldeff = TRUE;
  27.              break;
  28.          }
  29.          tmp = d(nd, 6);
  30.          if (resists_cold(mon))
  31.              tmp += 7;
  32.          if (spellcaster)
  33.              tmp = spell_damage_bonus(tmp);
  34.          if (burnarmor(mon)) {
  35.              if (!rn2(3))
  36.                  (void) destroy_mitem(mon, POTION_CLASS, AD_FIRE);
  37.              if (!rn2(3))
  38.                  (void) destroy_mitem(mon, SCROLL_CLASS, AD_FIRE);
  39.              if (!rn2(5))
  40.                  (void) destroy_mitem(mon, SPBOOK_CLASS, AD_FIRE);
  41.              destroy_mitem(mon, FOOD_CLASS, AD_FIRE); /* carried slime */
  42.          }
  43.          break;
  44.      case ZT_COLD:
  45.          if (resists_cold(mon)) {
  46.              sho_shieldeff = TRUE;
  47.              break;
  48.          }
  49.          tmp = d(nd, 6);
  50.          if (resists_fire(mon))
  51.              tmp += d(nd, 3);
  52.          if (spellcaster)
  53.              tmp = spell_damage_bonus(tmp);
  54.          if (!rn2(3))
  55.              (void) destroy_mitem(mon, POTION_CLASS, AD_COLD);
  56.          break;
  57.      case ZT_SLEEP:
  58.          tmp = 0;
  59.          (void) sleep_monst(mon, d(nd, 25),
  60.                             type == ZT_WAND(ZT_SLEEP) ? WAND_CLASS : '\0');
  61.          break;
  62.      case ZT_DEATH:                              /* death/disintegration */
  63.          if (abs(type) != ZT_BREATH(ZT_DEATH)) { /* death */
  64.              if (mon->data == &mons[PM_DEATH]) {
  65.                  mon->mhpmax += mon->mhpmax / 2;
  66.                  if (mon->mhpmax >= MAGIC_COOKIE)
  67.                      mon->mhpmax = MAGIC_COOKIE - 1;
  68.                  mon->mhp = mon->mhpmax;
  69.                  tmp = 0;
  70.                  break;
  71.              }
  72.              if (nonliving(mon->data) || is_demon(mon->data)
  73.                  || is_vampshifter(mon) || resists_magm(mon)) {
  74.                  /* similar to player */
  75.                  sho_shieldeff = TRUE;
  76.                  break;
  77.              }
  78.              type = -1; /* so they don't get saving throws */
  79.          } else {
  80.              struct obj *otmp2;
  81.  
  82.              if (resists_disint(mon)) {
  83.                  sho_shieldeff = TRUE;
  84.              } else if (mon->misc_worn_check & W_ARMS) {
  85.                  /* destroy shield; victim survives */
  86.                  *ootmp = which_armor(mon, W_ARMS);
  87.              } else if (mon->misc_worn_check & W_ARM) {
  88.                  /* destroy body armor, also cloak if present */
  89.                  *ootmp = which_armor(mon, W_ARM);
  90.                  if ((otmp2 = which_armor(mon, W_ARMC)) != 0)
  91.                      m_useup(mon, otmp2);
  92.              } else {
  93.                  /* no body armor, victim dies; destroy cloak
  94.                     and shirt now in case target gets life-saved */
  95.                  tmp = MAGIC_COOKIE;
  96.                  if ((otmp2 = which_armor(mon, W_ARMC)) != 0)
  97.                      m_useup(mon, otmp2);
  98.                  if ((otmp2 = which_armor(mon, W_ARMU)) != 0)
  99.                      m_useup(mon, otmp2);
  100.              }
  101.              type = -1; /* no saving throw wanted */
  102.              break;     /* not ordinary damage */
  103.          }
  104.          tmp = mon->mhp + 1;
  105.          break;
  106.      case ZT_LIGHTNING:
  107.          if (resists_elec(mon)) {
  108.              sho_shieldeff = TRUE;
  109.              tmp = 0;
  110.              /* can still blind the monster */
  111.          } else
  112.              tmp = d(nd, 6);
  113.          if (spellcaster)
  114.              tmp = spell_damage_bonus(tmp);
  115.          if (!resists_blnd(mon)
  116.              && !(type > 0 && u.uswallow && mon == u.ustuck)) {
  117.              register unsigned rnd_tmp = rnd(50);
  118.              mon->mcansee = 0;
  119.              if ((mon->mblinded + rnd_tmp) > 127)
  120.                  mon->mblinded = 127;
  121.              else
  122.                  mon->mblinded += rnd_tmp;
  123.          }
  124.          if (!rn2(3))
  125.              (void) destroy_mitem(mon, WAND_CLASS, AD_ELEC);
  126.          /* not actually possible yet */
  127.          if (!rn2(3))
  128.              (void) destroy_mitem(mon, RING_CLASS, AD_ELEC);
  129.          break;
  130.      case ZT_POISON_GAS:
  131.          if (resists_poison(mon)) {
  132.              sho_shieldeff = TRUE;
  133.              break;
  134.          }
  135.          tmp = d(nd, 6);
  136.          break;
  137.      case ZT_ACID:
  138.          if (resists_acid(mon)) {
  139.              sho_shieldeff = TRUE;
  140.              break;
  141.          }
  142.          tmp = d(nd, 6);
  143.          if (!rn2(6))
  144.              acid_damage(MON_WEP(mon));
  145.          if (!rn2(6))
  146.              erode_armor(mon, ERODE_CORRODE);
  147.          break;
  148.      }
  149.      if (sho_shieldeff)
  150.          shieldeff(mon->mx, mon->my);
  151.      if (is_hero_spell(type) && (Role_if(PM_KNIGHT) && u.uhave.questart))
  152.          tmp *= 2;
  153.      if (tmp > 0 && type >= 0
  154.          && resist(mon, type < ZT_SPELL(0) ? WAND_CLASS : '\0', 0, NOTELL))
  155.          tmp /= 2;
  156.      if (tmp < 0)
  157.          tmp = 0; /* don't allow negative damage */
  158.      debugpline3("zapped monster hp = %d (= %d - %d)", mon->mhp - tmp,
  159.                  mon->mhp, tmp);
  160.      mon->mhp -= tmp;
  161.      return tmp;
  162.  }
  163.  

zhitu

  1.  STATIC_OVL void
  2.  zhitu(type, nd, fltxt, sx, sy)
  3.  int type, nd;
  4.  const char *fltxt;
  5.  xchar sx, sy;
  6.  {
  7.      int dam = 0, abstyp = abs(type);
  8.  
  9.      switch (abstyp % 10) {
  10.      case ZT_MAGIC_MISSILE:
  11.          if (Antimagic) {
  12.              shieldeff(sx, sy);
  13.              pline_The("missiles bounce off!");
  14.          } else {
  15.              dam = d(nd, 6);
  16.              exercise(A_STR, FALSE);
  17.          }
  18.          break;
  19.      case ZT_FIRE:
  20.          if (Fire_resistance) {
  21.              shieldeff(sx, sy);
  22.              You("don't feel hot!");
  23.              ugolemeffects(AD_FIRE, d(nd, 6));
  24.          } else {
  25.              dam = d(nd, 6);
  26.          }
  27.          burn_away_slime();
  28.          if (burnarmor(&youmonst)) { /* "body hit" */
  29.              if (!rn2(3))
  30.                  destroy_item(POTION_CLASS, AD_FIRE);
  31.              if (!rn2(3))
  32.                  destroy_item(SCROLL_CLASS, AD_FIRE);
  33.              if (!rn2(5))
  34.                  destroy_item(SPBOOK_CLASS, AD_FIRE);
  35.              destroy_item(FOOD_CLASS, AD_FIRE);
  36.          }
  37.          break;
  38.      case ZT_COLD:
  39.          if (Cold_resistance) {
  40.              shieldeff(sx, sy);
  41.              You("don't feel cold.");
  42.              ugolemeffects(AD_COLD, d(nd, 6));
  43.          } else {
  44.              dam = d(nd, 6);
  45.          }
  46.          if (!rn2(3))
  47.              destroy_item(POTION_CLASS, AD_COLD);
  48.          break;
  49.      case ZT_SLEEP:
  50.          if (Sleep_resistance) {
  51.              shieldeff(u.ux, u.uy);
  52.              You("don't feel sleepy.");
  53.          } else {
  54.              fall_asleep(-d(nd, 25), TRUE); /* sleep ray */
  55.          }
  56.          break;
  57.      case ZT_DEATH:
  58.          if (abstyp == ZT_BREATH(ZT_DEATH)) {
  59.              if (Disint_resistance) {
  60.                  You("are not disintegrated.");
  61.                  break;
  62.              } else if (uarms) {
  63.                  /* destroy shield; other possessions are safe */
  64.                  (void) destroy_arm(uarms);
  65.                  break;
  66.              } else if (uarm) {
  67.                  /* destroy suit; if present, cloak goes too */
  68.                  if (uarmc)
  69.                      (void) destroy_arm(uarmc);
  70.                  (void) destroy_arm(uarm);
  71.                  break;
  72.              }
  73.              /* no shield or suit, you're dead; wipe out cloak
  74.                 and/or shirt in case of life-saving or bones */
  75.              if (uarmc)
  76.                  (void) destroy_arm(uarmc);
  77.              if (uarmu)
  78.                  (void) destroy_arm(uarmu);
  79.          } else if (nonliving(youmonst.data) || is_demon(youmonst.data)) {
  80.              shieldeff(sx, sy);
  81.              You("seem unaffected.");
  82.              break;
  83.          } else if (Antimagic) {
  84.              shieldeff(sx, sy);
  85.              You("aren't affected.");
  86.              break;
  87.          }
  88.          killer.format = KILLED_BY_AN;
  89.          Strcpy(killer.name, fltxt ? fltxt : "");
  90.          /* when killed by disintegration breath, don't leave corpse */
  91.          u.ugrave_arise = (type == -ZT_BREATH(ZT_DEATH)) ? -3 : NON_PM;
  92.          done(DIED);
  93.          return; /* lifesaved */
  94.      case ZT_LIGHTNING:
  95.          if (Shock_resistance) {
  96.              shieldeff(sx, sy);
  97.              You("aren't affected.");
  98.              ugolemeffects(AD_ELEC, d(nd, 6));
  99.          } else {
  100.              dam = d(nd, 6);
  101.              exercise(A_CON, FALSE);
  102.          }
  103.          if (!rn2(3))
  104.              destroy_item(WAND_CLASS, AD_ELEC);
  105.          if (!rn2(3))
  106.              destroy_item(RING_CLASS, AD_ELEC);
  107.          break;
  108.      case ZT_POISON_GAS:
  109.          poisoned("blast", A_DEX, "poisoned blast", 15, FALSE);
  110.          break;
  111.      case ZT_ACID:
  112.          if (Acid_resistance) {
  113.              pline_The("acid doesn't hurt.");
  114.              dam = 0;
  115.          } else {
  116.              pline_The("acid burns!");
  117.              dam = d(nd, 6);
  118.              exercise(A_STR, FALSE);
  119.          }
  120.          /* using two weapons at once makes both of them more vulnerable */
  121.          if (!rn2(u.twoweap ? 3 : 6))
  122.              acid_damage(uwep);
  123.          if (u.twoweap && !rn2(3))
  124.              acid_damage(uswapwep);
  125.          if (!rn2(6))
  126.              erode_armor(&youmonst, ERODE_CORRODE);
  127.          break;
  128.      }
  129.  
  130.      /* Half_spell_damage protection yields half-damage for wands & spells,
  131.         including hero's own ricochets; breath attacks do full damage */
  132.      if (dam && Half_spell_damage && !(abstyp >= 20 && abstyp <= 29))
  133.          dam = (dam + 1) / 2;
  134.      losehp(dam, fltxt, KILLED_BY_AN);
  135.      return;
  136.  }
  137.  

burn_floor_objects

  1.  /*
  2.   * burn objects (such as scrolls and spellbooks) on floor
  3.   * at position x,y; return the number of objects burned
  4.   */
  5.  int
  6.  burn_floor_objects(x, y, give_feedback, u_caused)
  7.  int x, y;
  8.  boolean give_feedback; /* caller needs to decide about visibility checks */
  9.  boolean u_caused;
  10.  {
  11.      struct obj *obj, *obj2;
  12.      long i, scrquan, delquan;
  13.      char buf1[BUFSZ], buf2[BUFSZ];
  14.      int cnt = 0;
  15.  
  16.      for (obj = level.objects[x][y]; obj; obj = obj2) {
  17.          obj2 = obj->nexthere;
  18.          if (obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS
  19.              || (obj->oclass == FOOD_CLASS
  20.                  && obj->otyp == GLOB_OF_GREEN_SLIME)) {
  21.              if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL
  22.                  || obj_resists(obj, 2, 100))
  23.                  continue;
  24.              scrquan = obj->quan; /* number present */
  25.              delquan = 0L;        /* number to destroy */
  26.              for (i = scrquan; i > 0L; i--)
  27.                  if (!rn2(3))
  28.                      delquan++;
  29.              if (delquan) {
  30.                  /* save name before potential delobj() */
  31.                  if (give_feedback) {
  32.                      obj->quan = 1L;
  33.                      Strcpy(buf1, (x == u.ux && y == u.uy)
  34.                                       ? xname(obj)
  35.                                       : distant_name(obj, xname));
  36.                      obj->quan = 2L;
  37.                      Strcpy(buf2, (x == u.ux && y == u.uy)
  38.                                       ? xname(obj)
  39.                                       : distant_name(obj, xname));
  40.                      obj->quan = scrquan;
  41.                  }
  42.                  /* useupf(), which charges, only if hero caused damage */
  43.                  if (u_caused)
  44.                      useupf(obj, delquan);
  45.                  else if (delquan < scrquan)
  46.                      obj->quan -= delquan;
  47.                  else
  48.                      delobj(obj);
  49.                  cnt += delquan;
  50.                  if (give_feedback) {
  51.                      if (delquan > 1L)
  52.                          pline("%ld %s burn.", delquan, buf2);
  53.                      else
  54.                          pline("%s burns.", An(buf1));
  55.                  }
  56.              }
  57.          }
  58.      }
  59.      return cnt;
  60.  }
  61.  

zap_hit

  1.  /* will zap/spell/breath attack score a hit against armor class `ac'? */
  2.  STATIC_OVL int
  3.  zap_hit(ac, type)
  4.  int ac;
  5.  int type; /* either hero cast spell type or 0 */
  6.  {
  7.      int chance = rn2(20);
  8.      int spell_bonus = type ? spell_hit_bonus(type) : 0;
  9.  
  10.      /* small chance for naked target to avoid being hit */
  11.      if (!chance)
  12.          return rnd(10) < ac + spell_bonus;
  13.  
  14.      /* very high armor protection does not achieve invulnerability */
  15.      ac = AC_VALUE(ac);
  16.  
  17.      return (3 - chance < ac + spell_bonus);
  18.  }
  19.  

disintegrate_mon

  1.  STATIC_OVL void
  2.  disintegrate_mon(mon, type, fltxt)
  3.  struct monst *mon;
  4.  int type; /* hero vs other */
  5.  const char *fltxt;
  6.  {
  7.      struct obj *otmp, *otmp2, *m_amulet = mlifesaver(mon);
  8.  
  9.      if (canseemon(mon)) {
  10.          if (!m_amulet)
  11.              pline("%s is disintegrated!", Monnam(mon));
  12.          else
  13.              hit(fltxt, mon, "!");
  14.      }
  15.  
  16.  /* note: worn amulet of life saving must be preserved in order to operate */
  17.  #define oresist_disintegration(obj)                                       \
  18.      (objects[obj->otyp].oc_oprop == DISINT_RES || obj_resists(obj, 5, 50) \
  19.       || is_quest_artifact(obj) || obj == m_amulet)
  20.  
  21.      for (otmp = mon->minvent; otmp; otmp = otmp2) {
  22.          otmp2 = otmp->nobj;
  23.          if (!oresist_disintegration(otmp)) {
  24.              if (otmp->owornmask) {
  25.                  /* in case monster's life gets saved */
  26.                  mon->misc_worn_check &= ~otmp->owornmask;
  27.                  if (otmp->owornmask & W_WEP)
  28.                      setmnotwielded(mon, otmp);
  29.                  /* also dismounts hero if this object is steed's saddle */
  30.                  update_mon_intrinsics(mon, otmp, FALSE, TRUE);
  31.                  otmp->owornmask = 0L;
  32.              }
  33.              obj_extract_self(otmp);
  34.              obfree(otmp, (struct obj *) 0);
  35.          }
  36.      }
  37.  
  38.  #undef oresist_disintegration
  39.  
  40.      if (type < 0)
  41.          monkilled(mon, (char *) 0, -AD_RBRE);
  42.      else
  43.          xkilled(mon, 2);
  44.  }
  45.  

buzz

  1.  /*
  2.   * type ==   0 to   9 : you shooting a wand
  3.   * type ==  10 to  19 : you casting a spell
  4.   * type ==  20 to  29 : you breathing as a monster
  5.   * type == -10 to -19 : monster casting spell
  6.   * type == -20 to -29 : monster breathing at you
  7.   * type == -30 to -39 : monster shooting a wand
  8.   * called with dx = dy = 0 with vertical bolts
  9.   */
  10.  void
  11.  buzz(type, nd, sx, sy, dx, dy)
  12.  register int type, nd;
  13.  register xchar sx, sy;
  14.  register int dx, dy;
  15.  {
  16.      int range, abstype = abs(type) % 10;
  17.      struct rm *lev;
  18.      register xchar lsx, lsy;
  19.      struct monst *mon;
  20.      coord save_bhitpos;
  21.      boolean shopdamage = FALSE;
  22.      const char *fltxt;
  23.      struct obj *otmp;
  24.      int spell_type;
  25.  
  26.      /* if its a Hero Spell then get its SPE_TYPE */
  27.      spell_type = is_hero_spell(type) ? SPE_MAGIC_MISSILE + abstype : 0;
  28.  
  29.      fltxt = flash_types[(type <= -30) ? abstype : abs(type)];
  30.      if (u.uswallow) {
  31.          register int tmp;
  32.  
  33.          if (type < 0)
  34.              return;
  35.          tmp = zhitm(u.ustuck, type, nd, &otmp);
  36.          if (!u.ustuck)
  37.              u.uswallow = 0;
  38.          else
  39.              pline("%s rips into %s%s", The(fltxt), mon_nam(u.ustuck),
  40.                    exclam(tmp));
  41.          /* Using disintegration from the inside only makes a hole... */
  42.          if (tmp == MAGIC_COOKIE)
  43.              u.ustuck->mhp = 0;
  44.          if (u.ustuck->mhp < 1)
  45.              killed(u.ustuck);
  46.          return;
  47.      }
  48.      if (type < 0)
  49.          newsym(u.ux, u.uy);
  50.      range = rn1(7, 7);
  51.      if (dx == 0 && dy == 0)
  52.          range = 1;
  53.      save_bhitpos = bhitpos;
  54.  
  55.      tmp_at(DISP_BEAM, zapdir_to_glyph(dx, dy, abstype));
  56.      while (range-- > 0) {
  57.          lsx = sx;
  58.          sx += dx;
  59.          lsy = sy;
  60.          sy += dy;
  61.          if (isok(sx, sy) && (lev = &levl[sx][sy])->typ) {
  62.              mon = m_at(sx, sy);
  63.              if (cansee(sx, sy)) {
  64.                  /* reveal/unreveal invisible monsters before tmp_at() */
  65.                  if (mon && !canspotmon(mon))
  66.                      map_invisible(sx, sy);
  67.                  else if (!mon && glyph_is_invisible(levl[sx][sy].glyph)) {
  68.                      unmap_object(sx, sy);
  69.                      newsym(sx, sy);
  70.                  }
  71.                  if (ZAP_POS(lev->typ) || (isok(lsx, lsy) && cansee(lsx, lsy)))
  72.                      tmp_at(sx, sy);
  73.                  delay_output(); /* wait a little */
  74.              }
  75.          } else
  76.              goto make_bounce;
  77.  
  78.          /* hit() and miss() need bhitpos to match the target */
  79.          bhitpos.x = sx, bhitpos.y = sy;
  80.          /* Fireballs only damage when they explode */
  81.          if (type != ZT_SPELL(ZT_FIRE))
  82.              range += zap_over_floor(sx, sy, type, &shopdamage, 0);
  83.  
  84.          if (mon) {
  85.              if (type == ZT_SPELL(ZT_FIRE))
  86.                  break;
  87.              if (type >= 0)
  88.                  mon->mstrategy &= ~STRAT_WAITMASK;
  89.          buzzmonst:
  90.              if (zap_hit(find_mac(mon), spell_type)) {
  91.                  if (mon_reflects(mon, (char *) 0)) {
  92.                      if (cansee(mon->mx, mon->my)) {
  93.                          hit(fltxt, mon, exclam(0));
  94.                          shieldeff(mon->mx, mon->my);
  95.                          (void) mon_reflects(mon,
  96.                                              "But it reflects from %s %s!");
  97.                      }
  98.                      dx = -dx;
  99.                      dy = -dy;
  100.                  } else {
  101.                      boolean mon_could_move = mon->mcanmove;
  102.                      int tmp = zhitm(mon, type, nd, &otmp);
  103.  
  104.                      if (is_rider(mon->data)
  105.                          && abs(type) == ZT_BREATH(ZT_DEATH)) {
  106.                          if (canseemon(mon)) {
  107.                              hit(fltxt, mon, ".");
  108.                              pline("%s disintegrates.", Monnam(mon));
  109.                              pline("%s body reintegrates before your %s!",
  110.                                    s_suffix(Monnam(mon)),
  111.                                    (eyecount(youmonst.data) == 1)
  112.                                        ? body_part(EYE)
  113.                                        : makeplural(body_part(EYE)));
  114.                              pline("%s resurrects!", Monnam(mon));
  115.                          }
  116.                          mon->mhp = mon->mhpmax;
  117.                          break; /* Out of while loop */
  118.                      }
  119.                      if (mon->data == &mons[PM_DEATH] && abstype == ZT_DEATH) {
  120.                          if (canseemon(mon)) {
  121.                              hit(fltxt, mon, ".");
  122.                              pline("%s absorbs the deadly %s!", Monnam(mon),
  123.                                    type == ZT_BREATH(ZT_DEATH) ? "blast"
  124.                                                                : "ray");
  125.                              pline("It seems even stronger than before.");
  126.                          }
  127.                          break; /* Out of while loop */
  128.                      }
  129.  
  130.                      if (tmp == MAGIC_COOKIE) { /* disintegration */
  131.                          disintegrate_mon(mon, type, fltxt);
  132.                      } else if (mon->mhp < 1) {
  133.                          if (type < 0)
  134.                              monkilled(mon, fltxt, AD_RBRE);
  135.                          else
  136.                              killed(mon);
  137.                      } else {
  138.                          if (!otmp) {
  139.                              /* normal non-fatal hit */
  140.                              hit(fltxt, mon, exclam(tmp));
  141.                          } else {
  142.                              /* some armor was destroyed; no damage done */
  143.                              if (canseemon(mon))
  144.                                  pline("%s %s is disintegrated!",
  145.                                        s_suffix(Monnam(mon)),
  146.                                        distant_name(otmp, xname));
  147.                              m_useup(mon, otmp);
  148.                          }
  149.                          if (mon_could_move && !mon->mcanmove) /* ZT_SLEEP */
  150.                              slept_monst(mon);
  151.                      }
  152.                  }
  153.                  range -= 2;
  154.              } else {
  155.                  miss(fltxt, mon);
  156.              }
  157.          } else if (sx == u.ux && sy == u.uy && range >= 0) {
  158.              nomul(0);
  159.              if (u.usteed && !rn2(3) && !mon_reflects(u.usteed, (char *) 0)) {
  160.                  mon = u.usteed;
  161.                  goto buzzmonst;
  162.              } else if (zap_hit((int) u.uac, 0)) {
  163.                  range -= 2;
  164.                  pline("%s hits you!", The(fltxt));
  165.                  if (Reflecting) {
  166.                      if (!Blind) {
  167.                          (void) ureflects("But %s reflects from your %s!",
  168.                                           "it");
  169.                      } else
  170.                          pline("For some reason you are not affected.");
  171.                      dx = -dx;
  172.                      dy = -dy;
  173.                      shieldeff(sx, sy);
  174.                  } else {
  175.                      zhitu(type, nd, fltxt, sx, sy);
  176.                  }
  177.              } else if (!Blind) {
  178.                  pline("%s whizzes by you!", The(fltxt));
  179.              } else if (abstype == ZT_LIGHTNING) {
  180.                  Your("%s tingles.", body_part(ARM));
  181.              }
  182.              if (abstype == ZT_LIGHTNING)
  183.                  (void) flashburn((long) d(nd, 50));
  184.              stop_occupation();
  185.              nomul(0);
  186.          }
  187.  
  188.          if (!ZAP_POS(lev->typ) || (closed_door(sx, sy) && (range >= 0))) {
  189.              int bounce;
  190.              uchar rmn;
  191.  
  192.          make_bounce:
  193.              if (type == ZT_SPELL(ZT_FIRE)) {
  194.                  sx = lsx;
  195.                  sy = lsy;
  196.                  break; /* fireballs explode before the wall */
  197.              }
  198.              bounce = 0;
  199.              range--;
  200.              if (range && isok(lsx, lsy) && cansee(lsx, lsy)) {
  201.                      pline("%s %s!", The(fltxt),
  202.                            Is_airlevel(&u.uz)
  203.                            ? "vanishes into the aether"
  204.                            : "bounces");
  205.                      if (Is_airlevel(&u.uz)) goto get_out_buzz;
  206.              }
  207.              if (!dx || !dy || !rn2(20)) {
  208.                  dx = -dx;
  209.                  dy = -dy;
  210.              } else {
  211.                  if (isok(sx, lsy) && ZAP_POS(rmn = levl[sx][lsy].typ)
  212.                      && !closed_door(sx, lsy)
  213.                      && (IS_ROOM(rmn) || (isok(sx + dx, lsy)
  214.                                           && ZAP_POS(levl[sx + dx][lsy].typ))))
  215.                      bounce = 1;
  216.                  if (isok(lsx, sy) && ZAP_POS(rmn = levl[lsx][sy].typ)
  217.                      && !closed_door(lsx, sy)
  218.                      && (IS_ROOM(rmn) || (isok(lsx, sy + dy)
  219.                                           && ZAP_POS(levl[lsx][sy + dy].typ))))
  220.                      if (!bounce || rn2(2))
  221.                          bounce = 2;
  222.  
  223.                  switch (bounce) {
  224.                  case 0:
  225.                      dx = -dx; /* fall into... */
  226.                  case 1:
  227.                      dy = -dy;
  228.                      break;
  229.                  case 2:
  230.                      dx = -dx;
  231.                      break;
  232.                  }
  233.                  tmp_at(DISP_CHANGE, zapdir_to_glyph(dx, dy, abstype));
  234.              }
  235.          }
  236.      }
  237.      tmp_at(DISP_END, 0);
  238.      if (type == ZT_SPELL(ZT_FIRE))
  239.          explode(sx, sy, type, d(12, 6), 0, EXPL_FIERY);
  240.   get_out_buzz:
  241.      if (shopdamage)
  242.          pay_for_damage(abstype == ZT_FIRE
  243.                            ? "burn away"
  244.                            : abstype == ZT_COLD
  245.                               ? "shatter"
  246.                               /* "damage" indicates wall rather than door */
  247.                               : abstype == ZT_ACID
  248.                               ? "damage"
  249.                                  : abstype == ZT_DEATH
  250.                                     ? "disintegrate"
  251.                                     : "destroy",
  252.                         FALSE);
  253.      bhitpos = save_bhitpos;
  254.  }
  255.  

melt_ice

  1.  void
  2.  melt_ice(x, y, msg)
  3.  xchar x, y;
  4.  const char *msg;
  5.  {
  6.      struct rm *lev = &levl[x][y];
  7.      struct obj *otmp;
  8.  
  9.      if (!msg)
  10.          msg = "The ice crackles and melts.";
  11.      if (lev->typ == DRAWBRIDGE_UP) {
  12.          lev->drawbridgemask &= ~DB_ICE; /* revert to DB_MOAT */
  13.      } else { /* lev->typ == ICE */
  14.  #ifdef STUPID
  15.          if (lev->icedpool == ICED_POOL)
  16.              lev->typ = POOL;
  17.          else
  18.              lev->typ = MOAT;
  19.  #else
  20.          lev->typ = (lev->icedpool == ICED_POOL ? POOL : MOAT);
  21.  #endif
  22.          lev->icedpool = 0;
  23.      }
  24.      spot_stop_timers(x, y, MELT_ICE_AWAY); /* no more ice to melt away */
  25.      obj_ice_effects(x, y, FALSE);
  26.      unearth_objs(x, y);
  27.      if (Underwater)
  28.          vision_recalc(1);
  29.      newsym(x, y);
  30.      if (cansee(x, y))
  31.          Norep("%s", msg);
  32.      if ((otmp = sobj_at(BOULDER, x, y)) != 0) {
  33.          if (cansee(x, y))
  34.              pline("%s settles...", An(xname(otmp)));
  35.          do {
  36.              obj_extract_self(otmp); /* boulder isn't being pushed */
  37.              if (!boulder_hits_pool(otmp, x, y, FALSE))
  38.                  impossible("melt_ice: no pool?");
  39.              /* try again if there's another boulder and pool didn't fill */
  40.          } while (is_pool(x, y) && (otmp = sobj_at(BOULDER, x, y)) != 0);
  41.          newsym(x, y);
  42.      }
  43.      if (x == u.ux && y == u.uy)
  44.          spoteffects(TRUE); /* possibly drown, notice objects */
  45.  }
  46.  

start_melt_ice_timeout

  1.  #define MIN_ICE_TIME 50
  2.  #define MAX_ICE_TIME 2000
  3.  /*
  4.   * Usually start a melt_ice timer; sometimes the ice will become
  5.   * permanent instead.
  6.   */
  7.  void
  8.  start_melt_ice_timeout(x, y, min_time)
  9.  xchar x, y;
  10.  long min_time; /* <x,y>'s old melt timeout (deleted by time we get here) */
  11.  {
  12.      int when;
  13.      long where;
  14.  
  15.      when = (int) min_time;
  16.      if (when < MIN_ICE_TIME - 1)
  17.          when = MIN_ICE_TIME - 1;
  18.  
  19.      /* random timeout; surrounding ice locations ought to be a factor... */
  20.      while (++when <= MAX_ICE_TIME)
  21.          if (!rn2((MAX_ICE_TIME - when) + MIN_ICE_TIME))
  22.              break;
  23.  
  24.      /* if we're within MAX_ICE_TIME, install a melt timer;
  25.         otherwise, omit it to leave this ice permanent */
  26.      if (when <= MAX_ICE_TIME) {
  27.          where = ((long) x << 16) | (long) y;
  28.          (void) start_timer((long) when, TIMER_LEVEL, MELT_ICE_AWAY,
  29.                             long_to_any(where));
  30.      }
  31.  }
  32.  #undef MIN_ICE_TIME
  33.  #undef MAX_ICE_TIME
  34.  

melt_ice_away

  1.  /*
  2.   * Called when ice has melted completely away.
  3.   */
  4.  void
  5.  melt_ice_away(arg, timeout)
  6.  anything *arg;
  7.  long timeout UNUSED;
  8.  {
  9.      xchar x, y;
  10.      long where = arg->a_long;
  11.  
  12.      y = (xchar) (where & 0xFFFF);
  13.      x = (xchar) ((where >> 16) & 0xFFFF);
  14.      /* melt_ice does newsym when appropriate */
  15.      melt_ice(x, y, "Some ice melts away.");
  16.  }
  17.  

zap_over_floor

  1.  /* Burn floor scrolls, evaporate pools, etc... in a single square.
  2.   * Used both for normal bolts of fire, cold, etc... and for fireballs.
  3.   * Sets shopdamage to TRUE if a shop door is destroyed, and returns the
  4.   * amount by which range is reduced (the latter is just ignored by fireballs)
  5.   */
  6.  int
  7.  zap_over_floor(x, y, type, shopdamage, exploding_wand_typ)
  8.  xchar x, y;
  9.  int type;
  10.  boolean *shopdamage;
  11.  short exploding_wand_typ;
  12.  {
  13.      const char *zapverb;
  14.      struct monst *mon;
  15.      struct trap *t;
  16.      struct rm *lev = &levl[x][y];
  17.      boolean see_it = cansee(x, y), yourzap;
  18.      int rangemod = 0, abstype = abs(type) % 10;
  19.  
  20.      switch (abstype) {
  21.      case ZT_FIRE:
  22.          t = t_at(x, y);
  23.          if (t && t->ttyp == WEB) {
  24.              /* a burning web is too flimsy to notice if you can't see it */
  25.              if (see_it)
  26.                  Norep("A web bursts into flames!");
  27.              (void) delfloortrap(t);
  28.              if (see_it)
  29.                  newsym(x, y);
  30.          }
  31.          if (is_ice(x, y)) {
  32.              melt_ice(x, y, (char *) 0);
  33.          } else if (is_pool(x, y)) {
  34.              const char *msgtxt = "You hear hissing gas.";
  35.  
  36.              if (lev->typ != POOL) { /* MOAT or DRAWBRIDGE_UP */
  37.                  if (see_it)
  38.                      msgtxt = "Some water evaporates.";
  39.              } else {
  40.                  rangemod -= 3;
  41.                  lev->typ = ROOM;
  42.                  t = maketrap(x, y, PIT);
  43.                  if (t)
  44.                      t->tseen = 1;
  45.                  if (see_it)
  46.                      msgtxt = "The water evaporates.";
  47.              }
  48.              Norep("%s", msgtxt);
  49.              if (lev->typ == ROOM)
  50.                  newsym(x, y);
  51.          } else if (IS_FOUNTAIN(lev->typ)) {
  52.              if (see_it)
  53.                  pline("Steam billows from the fountain.");
  54.              rangemod -= 1;
  55.              dryup(x, y, type > 0);
  56.          }
  57.          break; /* ZT_FIRE */
  58.  
  59.      case ZT_COLD:
  60.          if (is_pool(x, y) || is_lava(x, y)) {
  61.              boolean lava = is_lava(x, y);
  62.              boolean moat = is_moat(x, y);
  63.  
  64.              if (lev->typ == WATER) {
  65.                  /* For now, don't let WATER freeze. */
  66.                  if (see_it)
  67.                      pline_The("water freezes for a moment.");
  68.                  else
  69.                      You_hear("a soft crackling.");
  70.                  rangemod -= 1000; /* stop */
  71.              } else {
  72.                  rangemod -= 3;
  73.                  if (lev->typ == DRAWBRIDGE_UP) {
  74.                      lev->drawbridgemask &= ~DB_UNDER; /* clear lava */
  75.                      lev->drawbridgemask |= (lava ? DB_FLOOR : DB_ICE);
  76.                  } else {
  77.                      if (!lava)
  78.                          lev->icedpool =
  79.                              (lev->typ == POOL ? ICED_POOL : ICED_MOAT);
  80.                      lev->typ = (lava ? ROOM : ICE);
  81.                  }
  82.                  bury_objs(x, y);
  83.                  if (see_it) {
  84.                      if (lava)
  85.                          Norep("The lava cools and solidifies.");
  86.                      else if (moat)
  87.                          Norep("The %s is bridged with ice!",
  88.                                waterbody_name(x, y));
  89.                      else
  90.                          Norep("The water freezes.");
  91.                      newsym(x, y);
  92.                  } else if (!lava)
  93.                      You_hear("a crackling sound.");
  94.  
  95.                  if (x == u.ux && y == u.uy) {
  96.                      if (u.uinwater) { /* not just `if (Underwater)' */
  97.                          /* leave the no longer existent water */
  98.                          u.uinwater = 0;
  99.                          u.uundetected = 0;
  100.                          docrt();
  101.                          vision_full_recalc = 1;
  102.                      } else if (u.utrap && u.utraptype == TT_LAVA) {
  103.                          if (Passes_walls) {
  104.                              u.utrap = 0;
  105.                              You("pass through the now-solid rock.");
  106.                          } else {
  107.                              u.utrap = rn1(50, 20);
  108.                              u.utraptype = TT_INFLOOR;
  109.                              You("are firmly stuck in the cooling rock.");
  110.                          }
  111.                      }
  112.                  } else if ((mon = m_at(x, y)) != 0) {
  113.                      /* probably ought to do some hefty damage to any
  114.                         non-ice creature caught in freezing water;
  115.                         at a minimum, eels are forced out of hiding */
  116.                      if (is_swimmer(mon->data) && mon->mundetected) {
  117.                          mon->mundetected = 0;
  118.                          newsym(x, y);
  119.                      }
  120.                  }
  121.                  if (!lava) {
  122.                      start_melt_ice_timeout(x, y, 0L);
  123.                      obj_ice_effects(x, y, TRUE);
  124.                  }
  125.              } /* ?WATER */
  126.  
  127.          } else if (is_ice(x, y)) {
  128.              long melt_time;
  129.  
  130.              /* Already ice here, so just firm it up. */
  131.              /* Now ensure that only ice that is already timed is affected */
  132.              if ((melt_time = spot_time_left(x, y, MELT_ICE_AWAY)) != 0L) {
  133.                  spot_stop_timers(x, y, MELT_ICE_AWAY);
  134.                  start_melt_ice_timeout(x, y, melt_time);
  135.              }
  136.          }
  137.          break; /* ZT_COLD */
  138.  
  139.      case ZT_ACID:
  140.          if (lev->typ == IRONBARS) {
  141.              if ((lev->wall_info & W_NONDIGGABLE) != 0) {
  142.                  if (see_it)
  143.                      Norep("The %s corrode somewhat but remain intact.",
  144.                            defsyms[S_bars].explanation);
  145.                  /* but nothing actually happens... */
  146.              } else {
  147.                  rangemod -= 3;
  148.                  if (see_it)
  149.                      Norep("The %s melt.", defsyms[S_bars].explanation);
  150.                  if (*in_rooms(x, y, SHOPBASE)) {
  151.                      /* in case we ever have a shop bounded by bars */
  152.                      lev->typ = ROOM;
  153.                      if (see_it)
  154.                          newsym(x, y);
  155.                      add_damage(x, y, (type >= 0) ? 300L : 0L);
  156.                      if (type >= 0)
  157.                          *shopdamage = TRUE;
  158.                  } else {
  159.                      lev->typ = DOOR;
  160.                      lev->doormask = D_NODOOR;
  161.                      if (see_it)
  162.                          newsym(x, y);
  163.                  }
  164.              }
  165.          }
  166.          break; /* ZT_ACID */
  167.  
  168.      default:
  169.          break;
  170.      }
  171.  
  172.      /* set up zap text for possible door feedback; for exploding wand, we
  173.         want "the blast" rather than "your blast" even if hero caused it */
  174.      yourzap = (type >= 0 && !exploding_wand_typ);
  175.      zapverb = "blast"; /* breath attack or wand explosion */
  176.      if (!exploding_wand_typ) {
  177.          if (abs(type) < ZT_SPELL(0))
  178.              zapverb = "bolt"; /* wand zap */
  179.          else if (abs(type) < ZT_BREATH(0))
  180.              zapverb = "spell";
  181.      }
  182.  
  183.      /* secret door gets revealed, converted into regular door */
  184.      if (levl[x][y].typ == SDOOR) {
  185.          cvt_sdoor_to_door(&levl[x][y]); /* .typ = DOOR */
  186.          /* target spot will now pass closed_door() test below
  187.             (except on rogue level) */
  188.          newsym(x, y);
  189.          if (see_it)
  190.              pline("%s %s reveals a secret door.",
  191.                    yourzap ? "Your" : "The", zapverb);
  192.          else if (Is_rogue_level(&u.uz))
  193.              draft_message(FALSE); /* "You feel a draft." (open doorway) */
  194.      }
  195.  
  196.      /* regular door absorbs remaining zap range, possibly gets destroyed */
  197.      if (closed_door(x, y)) {
  198.          int new_doormask = -1;
  199.          const char *see_txt = 0, *sense_txt = 0, *hear_txt = 0;
  200.  
  201.          rangemod = -1000;
  202.          switch (abstype) {
  203.          case ZT_FIRE:
  204.              new_doormask = D_NODOOR;
  205.              see_txt = "The door is consumed in flames!";
  206.              sense_txt = "smell smoke.";
  207.              break;
  208.          case ZT_COLD:
  209.              new_doormask = D_NODOOR;
  210.              see_txt = "The door freezes and shatters!";
  211.              sense_txt = "feel cold.";
  212.              break;
  213.          case ZT_DEATH:
  214.              /* death spells/wands don't disintegrate */
  215.              if (abs(type) != ZT_BREATH(ZT_DEATH))
  216.                  goto def_case;
  217.              new_doormask = D_NODOOR;
  218.              see_txt = "The door disintegrates!";
  219.              hear_txt = "crashing wood.";
  220.              break;
  221.          case ZT_LIGHTNING:
  222.              new_doormask = D_BROKEN;
  223.              see_txt = "The door splinters!";
  224.              hear_txt = "crackling.";
  225.              break;
  226.          default:
  227.          def_case:
  228.              if (exploding_wand_typ > 0) {
  229.                  /* Magical explosion from misc exploding wand */
  230.                  if (exploding_wand_typ == WAN_STRIKING) {
  231.                      new_doormask = D_BROKEN;
  232.                      see_txt = "The door crashes open!";
  233.                      sense_txt = "feel a burst of cool air.";
  234.                      break;
  235.                  }
  236.              }
  237.              if (see_it) {
  238.                  /* "the door absorbs the blast" would be
  239.                     inaccurate for an exploding wand since
  240.                     other adjacent locations still get hit */
  241.                  if (exploding_wand_typ)
  242.                      pline_The("door remains intact.");
  243.                  else
  244.                      pline_The("door absorbs %s %s!", yourzap ? "your" : "the",
  245.                                zapverb);
  246.              } else
  247.                  You_feel("vibrations.");
  248.              break;
  249.          }
  250.          if (new_doormask >= 0) { /* door gets broken */
  251.              if (*in_rooms(x, y, SHOPBASE)) {
  252.                  if (type >= 0) {
  253.                      add_damage(x, y, 400L);
  254.                      *shopdamage = TRUE;
  255.                  } else /* caused by monster */
  256.                      add_damage(x, y, 0L);
  257.              }
  258.              lev->doormask = new_doormask;
  259.              unblock_point(x, y); /* vision */
  260.              if (see_it) {
  261.                  pline1(see_txt);
  262.                  newsym(x, y);
  263.              } else if (sense_txt) {
  264.                  You1(sense_txt);
  265.              } else if (hear_txt)
  266.                  You_hear1(hear_txt);
  267.              if (picking_at(x, y)) {
  268.                  stop_occupation();
  269.                  reset_pick();
  270.              }
  271.          }
  272.      }
  273.  
  274.      if (OBJ_AT(x, y) && abstype == ZT_FIRE)
  275.          if (burn_floor_objects(x, y, FALSE, type > 0) && couldsee(x, y)) {
  276.              newsym(x, y);
  277.              You("%s of smoke.", !Blind ? "see a puff" : "smell a whiff");
  278.          }
  279.      if ((mon = m_at(x, y)) != 0) {
  280.          /* Cannot use wakeup() which also angers the monster */
  281.          mon->msleeping = 0;
  282.          if (mon->m_ap_type)
  283.              seemimic(mon);
  284.          if (type >= 0) {
  285.              setmangry(mon);
  286.              if (mon->ispriest && *in_rooms(mon->mx, mon->my, TEMPLE))
  287.                  ghod_hitsu(mon);
  288.              if (mon->isshk && !*u.ushops)
  289.                  hot_pursuit(mon);
  290.          }
  291.      }
  292.      return rangemod;
  293.  }
  294.  

fracture_rock

  1.  /* fractured by pick-axe or wand of striking */
  2.  void
  3.  fracture_rock(obj)
  4.  register struct obj *obj; /* no texts here! */
  5.  {
  6.      xchar x, y;
  7.      boolean by_you = !context.mon_moving;
  8.  
  9.      if (by_you && get_obj_location(obj, &x, &y, 0) && costly_spot(x, y)) {
  10.          struct monst *shkp = 0;
  11.          char objroom = *in_rooms(x, y, SHOPBASE);
  12.  
  13.          if (billable(&shkp, obj, objroom, FALSE)) {
  14.              /* shop message says "you owe <shk> <$> for it!" so we need
  15.                 to precede that with a message explaining what "it" is */
  16.              You("fracture %s %s.", s_suffix(shkname(shkp)), xname(obj));
  17.              breakobj(obj, x, y, TRUE, FALSE); /* charges for shop goods */
  18.          }
  19.      }
  20.      if (by_you && obj->otyp == BOULDER)
  21.          sokoban_guilt();
  22.  
  23.      obj->otyp = ROCK;
  24.      obj->oclass = GEM_CLASS;
  25.      obj->quan = (long) rn1(60, 7);
  26.      obj->owt = weight(obj);
  27.      obj->dknown = obj->bknown = obj->rknown = 0;
  28.      obj->known = objects[obj->otyp].oc_uses_known ? 0 : 1;
  29.      dealloc_oextra(obj);
  30.  
  31.      if (obj->where == OBJ_FLOOR) {
  32.          obj_extract_self(obj); /* move rocks back on top */
  33.          place_object(obj, obj->ox, obj->oy);
  34.          if (!does_block(obj->ox, obj->oy, &levl[obj->ox][obj->oy]))
  35.              unblock_point(obj->ox, obj->oy);
  36.          if (cansee(obj->ox, obj->oy))
  37.              newsym(obj->ox, obj->oy);
  38.      }
  39.  }
  40.  

break_statue

  1.  /* handle statue hit by striking/force bolt/pick-axe */
  2.  boolean
  3.  break_statue(obj)
  4.  register struct obj *obj;
  5.  {
  6.      /* [obj is assumed to be on floor, so no get_obj_location() needed] */
  7.      struct trap *trap = t_at(obj->ox, obj->oy);
  8.      struct obj *item;
  9.      boolean by_you = !context.mon_moving;
  10.  
  11.      if (trap && trap->ttyp == STATUE_TRAP
  12.          && activate_statue_trap(trap, obj->ox, obj->oy, TRUE))
  13.          return FALSE;
  14.      /* drop any objects contained inside the statue */
  15.      while ((item = obj->cobj) != 0) {
  16.          obj_extract_self(item);
  17.          place_object(item, obj->ox, obj->oy);
  18.      }
  19.      if (by_you && Role_if(PM_ARCHEOLOGIST) && (obj->spe & STATUE_HISTORIC)) {
  20.          You_feel("guilty about damaging such a historic statue.");
  21.          adjalign(-1);
  22.      }
  23.      obj->spe = 0;
  24.      fracture_rock(obj);
  25.      return TRUE;
  26.  }
  27.  

destroy_item

  1.  /*
  2.   * destroy_strings[dindx][0:singular,1:plural,2:killer_reason]
  3.   *      [0] freezing potion
  4.   *      [1] boiling potion other than oil
  5.   *      [2] boiling potion of oil
  6.   *      [3] burning scroll
  7.   *      [4] burning spellbook
  8.   *      [5] shocked ring
  9.   *      [6] shocked wand
  10.   * (books, rings, and wands don't stack so don't need plural form;
  11.   *  crumbling ring doesn't do damage so doesn't need killer reason)
  12.   */
  13.  const char *const destroy_strings[][3] = {
  14.      /* also used in trap.c */
  15.      { "freezes and shatters", "freeze and shatter", "shattered potion" },
  16.      { "boils and explodes", "boil and explode", "boiling potion" },
  17.      { "ignites and explodes", "ignite and explode", "exploding potion" },
  18.      { "catches fire and burns", "catch fire and burn", "burning scroll" },
  19.      { "catches fire and burns", "", "burning book" },
  20.      { "turns to dust and vanishes", "", "" },
  21.      { "breaks apart and explodes", "", "exploding wand" },
  22.  };
  23.  
  24.  void
  25.  destroy_item(osym, dmgtyp)
  26.  register int osym, dmgtyp;
  27.  {
  28.      register struct obj *obj, *obj2;
  29.      int dmg, xresist, skip;
  30.      long i, cnt, quan;
  31.      int dindx;
  32.      const char *mult;
  33.      boolean physical_damage;
  34.  
  35.      for (obj = invent; obj; obj = obj2) {
  36.          obj2 = obj->nobj;
  37.          physical_damage = FALSE;
  38.          if (obj->oclass != osym)
  39.              continue; /* test only objs of type osym */
  40.          if (obj->oartifact)
  41.              continue; /* don't destroy artifacts */
  42.          if (obj->in_use && obj->quan == 1L)
  43.              continue; /* not available */
  44.          xresist = skip = 0;
  45.          /* lint suppression */
  46.          dmg = dindx = 0;
  47.          quan = 0L;
  48.  
  49.          switch (dmgtyp) {
  50.          case AD_COLD:
  51.              if (osym == POTION_CLASS && obj->otyp != POT_OIL) {
  52.                  quan = obj->quan;
  53.                  dindx = 0;
  54.                  dmg = rnd(4);
  55.              } else
  56.                  skip++;
  57.              break;
  58.          case AD_FIRE:
  59.              xresist = (Fire_resistance && obj->oclass != POTION_CLASS
  60.                         && obj->otyp != GLOB_OF_GREEN_SLIME);
  61.  
  62.              if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL)
  63.                  skip++;
  64.              if (obj->otyp == SPE_BOOK_OF_THE_DEAD) {
  65.                  skip++;
  66.                  if (!Blind)
  67.                      pline("%s glows a strange %s, but remains intact.",
  68.                            The(xname(obj)), hcolor("dark red"));
  69.              }
  70.              quan = obj->quan;
  71.              switch (osym) {
  72.              case POTION_CLASS:
  73.                  dindx = (obj->otyp != POT_OIL) ? 1 : 2;
  74.                  dmg = rnd(6);
  75.                  break;
  76.              case SCROLL_CLASS:
  77.                  dindx = 3;
  78.                  dmg = 1;
  79.                  break;
  80.              case SPBOOK_CLASS:
  81.                  dindx = 4;
  82.                  dmg = 1;
  83.                  break;
  84.              case FOOD_CLASS:
  85.                  if (obj->otyp == GLOB_OF_GREEN_SLIME) {
  86.                      dindx = obj->owt / 20;
  87.                      dmg = 1;
  88.                  } else {
  89.                      skip++;
  90.                  }
  91.                  break;
  92.              default:
  93.                  skip++;
  94.                  break;
  95.              }
  96.              break;
  97.          case AD_ELEC:
  98.              xresist = (Shock_resistance && obj->oclass != RING_CLASS);
  99.              quan = obj->quan;
  100.              switch (osym) {
  101.              case RING_CLASS:
  102.                  if (obj->otyp == RIN_SHOCK_RESISTANCE) {
  103.                      skip++;
  104.                      break;
  105.                  }
  106.                  dindx = 5;
  107.                  dmg = 0;
  108.                  break;
  109.              case WAND_CLASS:
  110.                  if (obj->otyp == WAN_LIGHTNING) {
  111.                      skip++;
  112.                      break;
  113.                  }
  114.  #if 0
  115.                  if (obj == current_wand) {  skip++;  break;  }
  116.  #endif
  117.                  dindx = 6;
  118.                  dmg = rnd(10);
  119.                  break;
  120.              default:
  121.                  skip++;
  122.                  break;
  123.              }
  124.              break;
  125.          default:
  126.              skip++;
  127.              break;
  128.          }
  129.          if (!skip) {
  130.              if (obj->in_use)
  131.                  --quan; /* one will be used up elsewhere */
  132.              for (i = cnt = 0L; i < quan; i++)
  133.                  if (!rn2(3))
  134.                      cnt++;
  135.  
  136.              if (!cnt)
  137.                  continue;
  138.              mult = (cnt == quan)
  139.                         ? (quan > 1) ? "All of your " : "Your"
  140.                         : (cnt == 1L) ? "One of your" : "Some of your";
  141.              pline("%s %s %s!", mult, xname(obj),
  142.                    destroy_strings[dindx][(cnt > 1L)]);
  143.              if (osym == POTION_CLASS && dmgtyp != AD_COLD) {
  144.                  if (!breathless(youmonst.data) || haseyes(youmonst.data))
  145.                      potionbreathe(obj);
  146.              }
  147.              if (obj->owornmask) {
  148.                  if (obj->owornmask & W_RING) /* ring being worn */
  149.                      Ring_gone(obj);
  150.                  else
  151.                      setnotworn(obj);
  152.              }
  153.              if (obj == current_wand)
  154.                  current_wand = 0; /* destroyed */
  155.              for (i = 0; i < cnt; i++)
  156.                  useup(obj);
  157.              if (dmg) {
  158.                  if (xresist)
  159.                      You("aren't hurt!");
  160.                  else {
  161.                      const char *how = destroy_strings[dindx][2];
  162.                      boolean one = (cnt == 1L);
  163.  
  164.                      if (physical_damage)
  165.                          dmg = Maybe_Half_Phys(dmg);
  166.                      losehp(dmg, one ? how : (const char *) makeplural(how),
  167.                             one ? KILLED_BY_AN : KILLED_BY);
  168.                      exercise(A_STR, FALSE);
  169.                  }
  170.              }
  171.          }
  172.      }
  173.      return;
  174.  }
  175.  

destroy_mitem

  1.  int
  2.  destroy_mitem(mtmp, osym, dmgtyp)
  3.  struct monst *mtmp;
  4.  int osym, dmgtyp;
  5.  {
  6.      struct obj *obj, *obj2;
  7.      int skip, tmp = 0;
  8.      long i, cnt, quan;
  9.      int dindx;
  10.      boolean vis;
  11.  
  12.      if (mtmp == &youmonst) { /* this simplifies artifact_hit() */
  13.          destroy_item(osym, dmgtyp);
  14.          return 0; /* arbitrary; value doesn't matter to artifact_hit() */
  15.      }
  16.  
  17.      vis = canseemon(mtmp);
  18.      for (obj = mtmp->minvent; obj; obj = obj2) {
  19.          obj2 = obj->nobj;
  20.          if (obj->oclass != osym)
  21.              continue; /* test only objs of type osym */
  22.          skip = 0;
  23.          quan = 0L;
  24.          dindx = 0;
  25.  
  26.          switch (dmgtyp) {
  27.          case AD_COLD:
  28.              if (osym == POTION_CLASS && obj->otyp != POT_OIL) {
  29.                  quan = obj->quan;
  30.                  dindx = 0;
  31.                  tmp++;
  32.              } else
  33.                  skip++;
  34.              break;
  35.          case AD_FIRE:
  36.              if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL)
  37.                  skip++;
  38.              if (obj->otyp == SPE_BOOK_OF_THE_DEAD) {
  39.                  skip++;
  40.                  if (vis)
  41.                      pline("%s glows a strange %s, but remains intact.",
  42.                            The(distant_name(obj, xname)), hcolor("dark red"));
  43.              }
  44.              quan = obj->quan;
  45.              switch (osym) {
  46.              case POTION_CLASS:
  47.                  dindx = (obj->otyp != POT_OIL) ? 1 : 2;
  48.                  tmp++;
  49.                  break;
  50.              case SCROLL_CLASS:
  51.                  dindx = 3;
  52.                  tmp++;
  53.                  break;
  54.              case SPBOOK_CLASS:
  55.                  dindx = 4;
  56.                  tmp++;
  57.                  break;
  58.              case FOOD_CLASS:
  59.                  if (obj->otyp == GLOB_OF_GREEN_SLIME) {
  60.                      dindx = obj->owt / 20;
  61.                      tmp++;
  62.                  } else {
  63.                      skip++;
  64.                  }
  65.                  break;
  66.              default:
  67.                  skip++;
  68.                  break;
  69.              }
  70.              break;
  71.          case AD_ELEC:
  72.              quan = obj->quan;
  73.              switch (osym) {
  74.              case RING_CLASS:
  75.                  if (obj->otyp == RIN_SHOCK_RESISTANCE) {
  76.                      skip++;
  77.                      break;
  78.                  }
  79.                  dindx = 5;
  80.                  break;
  81.              case WAND_CLASS:
  82.                  if (obj->otyp == WAN_LIGHTNING) {
  83.                      skip++;
  84.                      break;
  85.                  }
  86.                  dindx = 6;
  87.                  tmp++;
  88.                  break;
  89.              default:
  90.                  skip++;
  91.                  break;
  92.              }
  93.              break;
  94.          default:
  95.              skip++;
  96.              break;
  97.          }
  98.          if (!skip) {
  99.              for (i = cnt = 0L; i < quan; i++)
  100.                  if (!rn2(3))
  101.                      cnt++;
  102.  
  103.              if (!cnt)
  104.                  continue;
  105.              if (vis)
  106.                  pline("%s%s %s!",
  107.                        (cnt == obj->quan) ? "" : (cnt > 1L) ? "Some of "
  108.                                                             : "One of ",
  109.                        (cnt == obj->quan) ? Yname2(obj) : yname(obj),
  110.                        destroy_strings[dindx][(cnt > 1L)]);
  111.              for (i = 0; i < cnt; i++)
  112.                  m_useup(mtmp, obj);
  113.          }
  114.      }
  115.      return tmp;
  116.  }
  117.  

resist

  1.  int
  2.  resist(mtmp, oclass, damage, tell)
  3.  struct monst *mtmp;
  4.  char oclass;
  5.  int damage, tell;
  6.  {
  7.      int resisted;
  8.      int alev, dlev;
  9.  
  10.      /* attack level */
  11.      switch (oclass) {
  12.      case WAND_CLASS:
  13.          alev = 12;
  14.          break;
  15.      case TOOL_CLASS:
  16.          alev = 10;
  17.          break; /* instrument */
  18.      case WEAPON_CLASS:
  19.          alev = 10;
  20.          break; /* artifact */
  21.      case SCROLL_CLASS:
  22.          alev = 9;
  23.          break;
  24.      case POTION_CLASS:
  25.          alev = 6;
  26.          break;
  27.      case RING_CLASS:
  28.          alev = 5;
  29.          break;
  30.      default:
  31.          alev = u.ulevel;
  32.          break; /* spell */
  33.      }
  34.      /* defense level */
  35.      dlev = (int) mtmp->m_lev;
  36.      if (dlev > 50)
  37.          dlev = 50;
  38.      else if (dlev < 1)
  39.          dlev = is_mplayer(mtmp->data) ? u.ulevel : 1;
  40.  
  41.      resisted = rn2(100 + alev - dlev) < mtmp->data->mr;
  42.      if (resisted) {
  43.          if (tell) {
  44.              shieldeff(mtmp->mx, mtmp->my);
  45.              pline("%s resists!", Monnam(mtmp));
  46.          }
  47.          damage = (damage + 1) / 2;
  48.      }
  49.  
  50.      if (damage) {
  51.          mtmp->mhp -= damage;
  52.          if (mtmp->mhp < 1) {
  53.              if (m_using)
  54.                  monkilled(mtmp, "", AD_RBRE);
  55.              else
  56.                  killed(mtmp);
  57.          }
  58.      }
  59.      return resisted;
  60.  }
  61.  

wishcmdassist

  1.  #define MAXWISHTRY 5
  2.  
  3.  STATIC_OVL void
  4.  wishcmdassist(triesleft)
  5.  int triesleft;
  6.  {
  7.      static NEARDATA const char *
  8.          wishinfo[] = {
  9.    "Wish details:",
  10.    "",
  11.    "Enter the name of an object, such as \"potion of monster detection\",",
  12.    "\"scroll labeled README\", \"elven mithril-coat\", or \"Grimtooth\"",
  13.    "(without the quotes).",
  14.    "",
  15.    "For object types which come in stacks, you may specify a plural name",
  16.    "such as \"potions of healing\", or specify a count, such as \"1000 gold",
  17.    "pieces\", although that aspect of your wish might not be granted.",
  18.    "",
  19.    "You may also specify various prefix values which might be used to",
  20.    "modify the item, such as \"uncursed\" or \"rustproof\" or \"+1\".",
  21.    "Most modifiers shown when viewing your inventory can be specified.",
  22.    "",
  23.    "You may specify 'nothing' to explicitly decline this wish.",
  24.    0,
  25.      },
  26.          preserve_wishless[] = "Doing so will preserve 'wishless' conduct.",
  27.          retry_info[] =
  28.                      "If you specify an unrecognized object name %s%s time%s,",
  29.          retry_too[] = "a randomly chosen item will be granted.",
  30.          suppress_cmdassist[] =
  31.              "(Suppress this assistance with !cmdassist in your config file.)",
  32.          *cardinals[] = { "zero",  "one",  "two", "three", "four", "five" },
  33.          too_many[] = "too many";
  34.      int i;
  35.      winid win;
  36.      char buf[BUFSZ];
  37.  
  38.      win = create_nhwindow(NHW_TEXT);
  39.      if (!win)
  40.          return;
  41.      for (i = 0; i < SIZE(wishinfo) - 1; ++i)
  42.          putstr(win, 0, wishinfo[i]);
  43.      if (!u.uconduct.wishes)
  44.          putstr(win, 0, preserve_wishless);
  45.      putstr(win, 0, "");
  46.      Sprintf(buf, retry_info,
  47.              (triesleft >= 0 && triesleft < SIZE(cardinals))
  48.                 ? cardinals[triesleft]
  49.                 : too_many,
  50.              (triesleft < MAXWISHTRY) ? " more" : "",
  51.              plur(triesleft));
  52.      putstr(win, 0, buf);
  53.      putstr(win, 0, retry_too);
  54.      putstr(win, 0, "");
  55.      if (iflags.cmdassist)
  56.          putstr(win, 0, suppress_cmdassist);
  57.      display_nhwindow(win, FALSE);
  58.      destroy_nhwindow(win);
  59.  }
  60.  

makewish

  1.  void
  2.  makewish()
  3.  {
  4.      char buf[BUFSZ], promptbuf[BUFSZ];
  5.      struct obj *otmp, nothing;
  6.      int tries = 0;
  7.  
  8.      promptbuf[0] = '\0';
  9.      nothing = zeroobj; /* lint suppression; only its address matters */
  10.      if (flags.verbose)
  11.          You("may wish for an object.");
  12.  retry:
  13.      Strcpy(promptbuf, "For what do you wish");
  14.      if (iflags.cmdassist && tries > 0)
  15.          Strcat(promptbuf, " (enter 'help' for assistance)");
  16.      Strcat(promptbuf, "?");
  17.      getlin(promptbuf, buf);
  18.      (void) mungspaces(buf);
  19.      if (buf[0] == '\033') {
  20.          buf[0] = '\0';
  21.      } else if (!strcmpi(buf, "help")) {
  22.          wishcmdassist(MAXWISHTRY - tries);
  23.          goto retry;
  24.      }
  25.      /*
  26.       *  Note: if they wished for and got a non-object successfully,
  27.       *  otmp == &zeroobj.  That includes gold, or an artifact that
  28.       *  has been denied.  Wishing for "nothing" requires a separate
  29.       *  value to remain distinct.
  30.       */
  31.      otmp = readobjnam(buf, &nothing);
  32.      if (!otmp) {
  33.          pline("Nothing fitting that description exists in the game.");
  34.          if (++tries < MAXWISHTRY)
  35.              goto retry;
  36.          pline1(thats_enough_tries);
  37.          otmp = readobjnam((char<