Source:NetHack 3.6.0/src/trap.c

From NetHackWiki
Jump to: navigation, search

Below is the full text to trap.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/trap.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	trap.c	$NHDT-Date: 1448492213 2015/11/25 22:56:53 $  $NHDT-Branch: master $:$NHDT-Revision: 1.249 $ */
  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.  extern const char *const destroy_strings[][3]; /* from zap.c */
  8.  
  9.  STATIC_DCL void FDECL(dofiretrap, (struct obj *));
  10.  STATIC_DCL void NDECL(domagictrap);
  11.  STATIC_DCL boolean FDECL(emergency_disrobe, (boolean *));
  12.  STATIC_DCL int FDECL(untrap_prob, (struct trap *));
  13.  STATIC_DCL void FDECL(move_into_trap, (struct trap *));
  14.  STATIC_DCL int FDECL(try_disarm, (struct trap *, BOOLEAN_P));
  15.  STATIC_DCL void FDECL(reward_untrap, (struct trap *, struct monst *));
  16.  STATIC_DCL int FDECL(disarm_holdingtrap, (struct trap *));
  17.  STATIC_DCL int FDECL(disarm_landmine, (struct trap *));
  18.  STATIC_DCL int FDECL(disarm_squeaky_board, (struct trap *));
  19.  STATIC_DCL int FDECL(disarm_shooting_trap, (struct trap *, int));
  20.  STATIC_DCL int FDECL(try_lift, (struct monst *, struct trap *, int,
  21.                                  BOOLEAN_P));
  22.  STATIC_DCL int FDECL(help_monster_out, (struct monst *, struct trap *));
  23.  STATIC_DCL boolean FDECL(thitm, (int, struct monst *, struct obj *, int,
  24.                                   BOOLEAN_P));
  25.  STATIC_DCL void FDECL(launch_drop_spot, (struct obj *, XCHAR_P, XCHAR_P));
  26.  STATIC_DCL int FDECL(mkroll_launch, (struct trap *, XCHAR_P, XCHAR_P,
  27.                                       SHORT_P, long));
  28.  STATIC_DCL boolean FDECL(isclearpath, (coord *, int, SCHAR_P, SCHAR_P));
  29.  STATIC_DCL char *FDECL(trapnote, (struct trap *, BOOLEAN_P));
  30.  #if 0
  31.  STATIC_DCL void FDECL(join_adjacent_pits, (struct trap *));
  32.  #endif
  33.  STATIC_DCL void FDECL(clear_conjoined_pits, (struct trap *));
  34.  STATIC_DCL int FDECL(steedintrap, (struct trap *, struct obj *));
  35.  STATIC_DCL boolean FDECL(keep_saddle_with_steedcorpse, (unsigned,
  36.                                                          struct obj *,
  37.                                                          struct obj *));
  38.  STATIC_DCL void NDECL(maybe_finish_sokoban);
  39.  
  40.  /* mintrap() should take a flags argument, but for time being we use this */
  41.  STATIC_VAR int force_mintrap = 0;
  42.  
  43.  STATIC_VAR const char *const a_your[2] = { "a", "your" };
  44.  STATIC_VAR const char *const A_Your[2] = { "A", "Your" };
  45.  STATIC_VAR const char tower_of_flame[] = "tower of flame";
  46.  STATIC_VAR const char *const A_gush_of_water_hits = "A gush of water hits";
  47.  STATIC_VAR const char *const blindgas[6] = { "humid",   "odorless",
  48.                                               "pungent", "chilling",
  49.                                               "acrid",   "biting" };
  50.  

burnarmor

  1.  /* called when you're hit by fire (dofiretrap,buzz,zapyourself,explode);
  2.     returns TRUE if hit on torso */
  3.  boolean
  4.  burnarmor(victim)
  5.  struct monst *victim;
  6.  {
  7.      struct obj *item;
  8.      char buf[BUFSZ];
  9.      int mat_idx, oldspe;
  10.      boolean hitting_u;
  11.  
  12.      if (!victim)
  13.          return 0;
  14.      hitting_u = (victim == &youmonst);
  15.  
  16.      /* burning damage may dry wet towel */
  17.      item = hitting_u ? carrying(TOWEL) : m_carrying(victim, TOWEL);
  18.      while (item) {
  19.          if (is_wet_towel(item)) {
  20.              oldspe = item->spe;
  21.              dry_a_towel(item, rn2(oldspe + 1), TRUE);
  22.              if (item->spe != oldspe)
  23.                  break; /* stop once one towel has been affected */
  24.          }
  25.          item = item->nobj;
  26.      }
  27.  
  28.  #define burn_dmg(obj, descr) erode_obj(obj, descr, ERODE_BURN, EF_GREASE)
  29.      while (1) {
  30.          switch (rn2(5)) {
  31.          case 0:
  32.              item = hitting_u ? uarmh : which_armor(victim, W_ARMH);
  33.              if (item) {
  34.                  mat_idx = objects[item->otyp].oc_material;
  35.                  Sprintf(buf, "%s %s", materialnm[mat_idx],
  36.                          helm_simple_name(item));
  37.              }
  38.              if (!burn_dmg(item, item ? buf : "helmet"))
  39.                  continue;
  40.              break;
  41.          case 1:
  42.              item = hitting_u ? uarmc : which_armor(victim, W_ARMC);
  43.              if (item) {
  44.                  (void) burn_dmg(item, cloak_simple_name(item));
  45.                  return TRUE;
  46.              }
  47.              item = hitting_u ? uarm : which_armor(victim, W_ARM);
  48.              if (item) {
  49.                  (void) burn_dmg(item, xname(item));
  50.                  return TRUE;
  51.              }
  52.              item = hitting_u ? uarmu : which_armor(victim, W_ARMU);
  53.              if (item)
  54.                  (void) burn_dmg(item, "shirt");
  55.              return TRUE;
  56.          case 2:
  57.              item = hitting_u ? uarms : which_armor(victim, W_ARMS);
  58.              if (!burn_dmg(item, "wooden shield"))
  59.                  continue;
  60.              break;
  61.          case 3:
  62.              item = hitting_u ? uarmg : which_armor(victim, W_ARMG);
  63.              if (!burn_dmg(item, "gloves"))
  64.                  continue;
  65.              break;
  66.          case 4:
  67.              item = hitting_u ? uarmf : which_armor(victim, W_ARMF);
  68.              if (!burn_dmg(item, "boots"))
  69.                  continue;
  70.              break;
  71.          }
  72.          break; /* Out of while loop */
  73.      }
  74.  #undef burn_dmg
  75.  
  76.      return FALSE;
  77.  }
  78.  

erode_obj

  1.  /* Generic erode-item function.
  2.   * "ostr", if non-null, is an alternate string to print instead of the
  3.   *   object's name.
  4.   * "type" is an ERODE_* value for the erosion type
  5.   * "flags" is an or-ed list of EF_* flags
  6.   *
  7.   * Returns an erosion return value (ER_*)
  8.   */
  9.  int
  10.  erode_obj(otmp, ostr, type, ef_flags)
  11.  register struct obj *otmp;
  12.  const char *ostr;
  13.  int type;
  14.  int ef_flags;
  15.  {
  16.      static NEARDATA const char *const action[] = { "smoulder", "rust", "rot",
  17.                                                     "corrode" };
  18.      static NEARDATA const char *const msg[] = { "burnt", "rusted", "rotten",
  19.                                                  "corroded" };
  20.      boolean vulnerable = FALSE;
  21.      boolean is_primary = TRUE;
  22.      boolean check_grease = ef_flags & EF_GREASE;
  23.      boolean print = ef_flags & EF_VERBOSE;
  24.      int erosion;
  25.      struct monst *victim;
  26.      boolean vismon;
  27.      boolean visobj;
  28.      int cost_type;
  29.  
  30.      if (!otmp)
  31.          return ER_NOTHING;
  32.  
  33.      victim = carried(otmp) ? &youmonst : mcarried(otmp) ? otmp->ocarry : NULL;
  34.      vismon = victim && (victim != &youmonst) && canseemon(victim);
  35.      /* Is bhitpos correct here? Ugh. */
  36.      visobj = !victim && cansee(bhitpos.x, bhitpos.y);
  37.  
  38.      switch (type) {
  39.      case ERODE_BURN:
  40.          vulnerable = is_flammable(otmp);
  41.          check_grease = FALSE;
  42.          cost_type = COST_BURN;
  43.          break;
  44.      case ERODE_RUST:
  45.          vulnerable = is_rustprone(otmp);
  46.          cost_type = COST_RUST;
  47.          break;
  48.      case ERODE_ROT:
  49.          vulnerable = is_rottable(otmp);
  50.          check_grease = FALSE;
  51.          is_primary = FALSE;
  52.          cost_type = COST_ROT;
  53.          break;
  54.      case ERODE_CORRODE:
  55.          vulnerable = is_corrodeable(otmp);
  56.          is_primary = FALSE;
  57.          cost_type = COST_CORRODE;
  58.          break;
  59.      default:
  60.          impossible("Invalid erosion type in erode_obj");
  61.          return ER_NOTHING;
  62.      }
  63.      erosion = is_primary ? otmp->oeroded : otmp->oeroded2;
  64.  
  65.      if (!ostr)
  66.          ostr = cxname(otmp);
  67.  
  68.      if (check_grease && otmp->greased) {
  69.          grease_protect(otmp, ostr, victim);
  70.          return ER_GREASED;
  71.      } else if (!vulnerable || (otmp->oerodeproof && otmp->rknown)) {
  72.          if (print && flags.verbose) {
  73.              if (victim == &youmonst)
  74.                  Your("%s %s not affected.", ostr, vtense(ostr, "are"));
  75.              else if (vismon)
  76.                  pline("%s %s %s not affected.", s_suffix(Monnam(victim)),
  77.                        ostr, vtense(ostr, "are"));
  78.          }
  79.          return ER_NOTHING;
  80.      } else if (otmp->oerodeproof || (otmp->blessed && !rnl(4))) {
  81.          if (flags.verbose && (print || otmp->oerodeproof)) {
  82.              if (victim == &youmonst)
  83.                  pline("Somehow, your %s %s not affected.", ostr,
  84.                        vtense(ostr, "are"));
  85.              else if (vismon)
  86.                  pline("Somehow, %s %s %s not affected.",
  87.                        s_suffix(mon_nam(victim)), ostr, vtense(ostr, "are"));
  88.              else if (visobj)
  89.                  pline("Somehow, the %s %s not affected.", ostr,
  90.                        vtense(ostr, "are"));
  91.          }
  92.          /* We assume here that if the object is protected because it
  93.           * is blessed, it still shows some minor signs of wear, and
  94.           * the hero can distinguish this from an object that is
  95.           * actually proof against damage. */
  96.          if (otmp->oerodeproof) {
  97.              otmp->rknown = TRUE;
  98.              if (victim == &youmonst)
  99.                  update_inventory();
  100.          }
  101.  
  102.          return ER_NOTHING;
  103.      } else if (erosion < MAX_ERODE) {
  104.          const char *adverb = (erosion + 1 == MAX_ERODE)
  105.                                   ? " completely"
  106.                                   : erosion ? " further" : "";
  107.  
  108.          if (victim == &youmonst)
  109.              Your("%s %s%s!", ostr, vtense(ostr, action[type]), adverb);
  110.          else if (vismon)
  111.              pline("%s %s %s%s!", s_suffix(Monnam(victim)), ostr,
  112.                    vtense(ostr, action[type]), adverb);
  113.          else if (visobj)
  114.              pline("The %s %s%s!", ostr, vtense(ostr, action[type]), adverb);
  115.  
  116.          if (ef_flags & EF_PAY)
  117.              costly_alteration(otmp, cost_type);
  118.  
  119.          if (is_primary)
  120.              otmp->oeroded++;
  121.          else
  122.              otmp->oeroded2++;
  123.  
  124.          if (victim == &youmonst)
  125.              update_inventory();
  126.  
  127.          return ER_DAMAGED;
  128.      } else if (ef_flags & EF_DESTROY) {
  129.          if (victim == &youmonst)
  130.              Your("%s %s away!", ostr, vtense(ostr, action[type]));
  131.          else if (vismon)
  132.              pline("%s %s %s away!", s_suffix(Monnam(victim)), ostr,
  133.                    vtense(ostr, action[type]));
  134.          else if (visobj)
  135.              pline("The %s %s away!", ostr, vtense(ostr, action[type]));
  136.  
  137.          if (ef_flags & EF_PAY)
  138.              costly_alteration(otmp, cost_type);
  139.  
  140.          setnotworn(otmp);
  141.          delobj(otmp);
  142.          return ER_DESTROYED;
  143.      } else {
  144.          if (flags.verbose && print) {
  145.              if (victim == &youmonst)
  146.                  Your("%s %s completely %s.", ostr,
  147.                       vtense(ostr, Blind ? "feel" : "look"), msg[type]);
  148.              else if (vismon)
  149.                  pline("%s %s %s completely %s.", s_suffix(Monnam(victim)),
  150.                        ostr, vtense(ostr, "look"), msg[type]);
  151.              else if (visobj)
  152.                  pline("The %s %s completely %s.", ostr, vtense(ostr, "look"),
  153.                        msg[type]);
  154.          }
  155.          return ER_NOTHING;
  156.      }
  157.  }
  158.  

grease_protect

  1.  /* Protect an item from erosion with grease. Returns TRUE if the grease
  2.   * wears off.
  3.   */
  4.  boolean
  5.  grease_protect(otmp, ostr, victim)
  6.  register struct obj *otmp;
  7.  const char *ostr;
  8.  struct monst *victim;
  9.  {
  10.      static const char txt[] = "protected by the layer of grease!";
  11.      boolean vismon = victim && (victim != &youmonst) && canseemon(victim);
  12.  
  13.      if (ostr) {
  14.          if (victim == &youmonst)
  15.              Your("%s %s %s", ostr, vtense(ostr, "are"), txt);
  16.          else if (vismon)
  17.              pline("%s's %s %s %s", Monnam(victim),
  18.                    ostr, vtense(ostr, "are"), txt);
  19.      } else if (victim == &youmonst || vismon) {
  20.          pline("%s %s", Yobjnam2(otmp, "are"), txt);
  21.      }
  22.      if (!rn2(2)) {
  23.          otmp->greased = 0;
  24.          if (carried(otmp)) {
  25.              pline_The("grease dissolves.");
  26.              update_inventory();
  27.          }
  28.          return TRUE;
  29.      }
  30.      return FALSE;
  31.  }
  32.  

maketrap

  1.  struct trap *
  2.  maketrap(x, y, typ)
  3.  register int x, y, typ;
  4.  {
  5.      static union vlaunchinfo zero_vl;
  6.      register struct trap *ttmp;
  7.      register struct rm *lev;
  8.      boolean oldplace;
  9.  
  10.      if ((ttmp = t_at(x, y)) != 0) {
  11.          if (ttmp->ttyp == MAGIC_PORTAL || ttmp->ttyp == VIBRATING_SQUARE)
  12.              return (struct trap *) 0;
  13.          oldplace = TRUE;
  14.          if (u.utrap && x == u.ux && y == u.uy
  15.              && ((u.utraptype == TT_BEARTRAP && typ != BEAR_TRAP)
  16.                  || (u.utraptype == TT_WEB && typ != WEB)
  17.                  || (u.utraptype == TT_PIT && typ != PIT
  18.                      && typ != SPIKED_PIT)))
  19.              u.utrap = 0;
  20.          /* old <tx,ty> remain valid */
  21.      } else if (IS_FURNITURE(levl[x][y].typ)) {
  22.          /* no trap on top of furniture (caller usually screens the
  23.             location to inhibit this, but wizard mode wishing doesn't) */
  24.          return (struct trap *) 0;
  25.      } else {
  26.          oldplace = FALSE;
  27.          ttmp = newtrap();
  28.          ttmp->ntrap = 0;
  29.          ttmp->tx = x;
  30.          ttmp->ty = y;
  31.      }
  32.      /* [re-]initialize all fields except ntrap (handled below) and <tx,ty> */
  33.      ttmp->vl = zero_vl;
  34.      ttmp->launch.x = ttmp->launch.y = -1; /* force error if used before set */
  35.      ttmp->dst.dnum = ttmp->dst.dlevel = -1;
  36.      ttmp->madeby_u = 0;
  37.      ttmp->once = 0;
  38.      ttmp->tseen = (typ == HOLE); /* hide non-holes */
  39.      ttmp->ttyp = typ;
  40.  
  41.      switch (typ) {
  42.      case SQKY_BOARD: {
  43.          int tavail[12], tpick[12], tcnt = 0, k;
  44.          struct trap *t;
  45.  
  46.          for (k = 0; k < 12; ++k)
  47.              tavail[k] = tpick[k] = 0;
  48.          for (t = ftrap; t; t = t->ntrap)
  49.              if (t->ttyp == SQKY_BOARD && t != ttmp)
  50.                  tavail[t->tnote] = 1;
  51.          /* now populate tpick[] with the available indices */
  52.          for (k = 0; k < 12; ++k)
  53.              if (tavail[k] == 0)
  54.                  tpick[tcnt++] = k;
  55.          /* choose an unused note; if all are in use, pick a random one */
  56.          ttmp->tnote = (short) ((tcnt > 0) ? tpick[rn2(tcnt)] : rn2(12));
  57.          break;
  58.      }
  59.      case STATUE_TRAP: { /* create a "living" statue */
  60.          struct monst *mtmp;
  61.          struct obj *otmp, *statue;
  62.          struct permonst *mptr;
  63.          int trycount = 10;
  64.  
  65.          do { /* avoid ultimately hostile co-aligned unicorn */
  66.              mptr = &mons[rndmonnum()];
  67.          } while (--trycount > 0 && is_unicorn(mptr)
  68.                   && sgn(u.ualign.type) == sgn(mptr->maligntyp));
  69.          statue = mkcorpstat(STATUE, (struct monst *) 0, mptr, x, y,
  70.                              CORPSTAT_NONE);
  71.          mtmp = makemon(&mons[statue->corpsenm], 0, 0, MM_NOCOUNTBIRTH);
  72.          if (!mtmp)
  73.              break; /* should never happen */
  74.          while (mtmp->minvent) {
  75.              otmp = mtmp->minvent;
  76.              otmp->owornmask = 0;
  77.              obj_extract_self(otmp);
  78.              (void) add_to_container(statue, otmp);
  79.          }
  80.          statue->owt = weight(statue);
  81.          mongone(mtmp);
  82.          break;
  83.      }
  84.      case ROLLING_BOULDER_TRAP: /* boulder will roll towards trigger */
  85.          (void) mkroll_launch(ttmp, x, y, BOULDER, 1L);
  86.          break;
  87.      case PIT:
  88.      case SPIKED_PIT:
  89.          ttmp->conjoined = 0;
  90.          /*FALLTHRU*/
  91.      case HOLE:
  92.      case TRAPDOOR:
  93.          lev = &levl[x][y];
  94.          if (*in_rooms(x, y, SHOPBASE)
  95.              && (typ == HOLE || typ == TRAPDOOR
  96.                  || IS_DOOR(lev->typ) || IS_WALL(lev->typ)))
  97.              add_damage(x, y, /* schedule repair */
  98.                         ((IS_DOOR(lev->typ) || IS_WALL(lev->typ))
  99.                          && !context.mon_moving)
  100.                             ? 200L
  101.                             : 0L);
  102.          lev->doormask = 0;     /* subsumes altarmask, icedpool... */
  103.          if (IS_ROOM(lev->typ)) /* && !IS_AIR(lev->typ) */
  104.              lev->typ = ROOM;
  105.          /*
  106.           * some cases which can happen when digging
  107.           * down while phazing thru solid areas
  108.           */
  109.          else if (lev->typ == STONE || lev->typ == SCORR)
  110.              lev->typ = CORR;
  111.          else if (IS_WALL(lev->typ) || lev->typ == SDOOR)
  112.              lev->typ = level.flags.is_maze_lev
  113.                             ? ROOM
  114.                             : level.flags.is_cavernous_lev ? CORR : DOOR;
  115.  
  116.          unearth_objs(x, y);
  117.          break;
  118.      }
  119.  
  120.      if (!oldplace) {
  121.          ttmp->ntrap = ftrap;
  122.          ftrap = ttmp;
  123.      } else {
  124.          /* oldplace;
  125.             it shouldn't be possible to override a sokoban pit or hole
  126.             with some other trap, but we'll check just to be safe */
  127.          if (Sokoban)
  128.              maybe_finish_sokoban();
  129.      }
  130.      return ttmp;
  131.  }
  132.  

fall_through

  1.  void
  2.  fall_through(td)
  3.  boolean td; /* td == TRUE : trap door or hole */
  4.  {
  5.      d_level dtmp;
  6.      char msgbuf[BUFSZ];
  7.      const char *dont_fall = 0;
  8.      int newlevel, bottom;
  9.  
  10.      /* we'll fall even while levitating in Sokoban; otherwise, if we
  11.         won't fall and won't be told that we aren't falling, give up now */
  12.      if (Blind && Levitation && !Sokoban)
  13.          return;
  14.  
  15.      bottom = dunlevs_in_dungeon(&u.uz);
  16.      /* when in the upper half of the quest, don't fall past the
  17.         middle "quest locate" level if hero hasn't been there yet */
  18.      if (In_quest(&u.uz)) {
  19.          int qlocate_depth = qlocate_level.dlevel;
  20.  
  21.          /* deepest reached < qlocate implies current < qlocate */
  22.          if (dunlev_reached(&u.uz) < qlocate_depth)
  23.              bottom = qlocate_depth; /* early cut-off */
  24.      }
  25.      newlevel = dunlev(&u.uz); /* current level */
  26.      do {
  27.          newlevel++;
  28.      } while (!rn2(4) && newlevel < bottom);
  29.  
  30.      if (td) {
  31.          struct trap *t = t_at(u.ux, u.uy);
  32.  
  33.          feeltrap(t);
  34.          if (!Sokoban) {
  35.              if (t->ttyp == TRAPDOOR)
  36.                  pline("A trap door opens up under you!");
  37.              else
  38.                  pline("There's a gaping hole under you!");
  39.          }
  40.      } else
  41.          pline_The("%s opens up under you!", surface(u.ux, u.uy));
  42.  
  43.      if (Sokoban && Can_fall_thru(&u.uz))
  44.          ; /* KMH -- You can't escape the Sokoban level traps */
  45.      else if (Levitation || u.ustuck
  46.               || (!Can_fall_thru(&u.uz) && !levl[u.ux][u.uy].candig) || Flying
  47.               || is_clinger(youmonst.data)
  48.               || (Inhell && !u.uevent.invoked && newlevel == bottom)) {
  49.          dont_fall = "don't fall in.";
  50.      } else if (youmonst.data->msize >= MZ_HUGE) {
  51.          dont_fall = "don't fit through.";
  52.      } else if (!next_to_u()) {
  53.          dont_fall = "are jerked back by your pet!";
  54.      }
  55.      if (dont_fall) {
  56.          You1(dont_fall);
  57.          /* hero didn't fall through, but any objects here might */
  58.          impact_drop((struct obj *) 0, u.ux, u.uy, 0);
  59.          if (!td) {
  60.              display_nhwindow(WIN_MESSAGE, FALSE);
  61.              pline_The("opening under you closes up.");
  62.          }
  63.          return;
  64.      }
  65.  
  66.      if (*u.ushops)
  67.          shopdig(1);
  68.      if (Is_stronghold(&u.uz)) {
  69.          find_hell(&dtmp);
  70.      } else {
  71.          int dist = newlevel - dunlev(&u.uz);
  72.          dtmp.dnum = u.uz.dnum;
  73.          dtmp.dlevel = newlevel;
  74.          if (dist > 1)
  75.              You("fall down a %s%sshaft!", dist > 3 ? "very " : "",
  76.                  dist > 2 ? "deep " : "");
  77.      }
  78.      if (!td)
  79.          Sprintf(msgbuf, "The hole in the %s above you closes up.",
  80.                  ceiling(u.ux, u.uy));
  81.  
  82.      schedule_goto(&dtmp, FALSE, TRUE, 0, (char *) 0,
  83.                    !td ? msgbuf : (char *) 0);
  84.  }
  85.  

animate_statue

  1.  /*
  2.   * Animate the given statue.  May have been via shatter attempt, trap,
  3.   * or stone to flesh spell.  Return a monster if successfully animated.
  4.   * If the monster is animated, the object is deleted.  If fail_reason
  5.   * is non-null, then fill in the reason for failure (or success).
  6.   *
  7.   * The cause of animation is:
  8.   *
  9.   *      ANIMATE_NORMAL  - hero "finds" the monster
  10.   *      ANIMATE_SHATTER - hero tries to destroy the statue
  11.   *      ANIMATE_SPELL   - stone to flesh spell hits the statue
  12.   *
  13.   * Perhaps x, y is not needed if we can use get_obj_location() to find
  14.   * the statue's location... ???
  15.   *
  16.   * Sequencing matters:
  17.   *      create monster; if it fails, give up with statue intact;
  18.   *      give "statue comes to life" message;
  19.   *      if statue belongs to shop, have shk give "you owe" message;
  20.   *      transfer statue contents to monster (after stolen_value());
  21.   *      delete statue.
  22.   *      [This ordering means that if the statue ends up wearing a cloak of
  23.   *       invisibility or a mummy wrapping, the visibility checks might be
  24.   *       wrong, but to avoid that we'd have to clone the statue contents
  25.   *       first in order to give them to the monster before checking their
  26.   *       shop status--it's not worth the hassle.]
  27.   */
  28.  struct monst *
  29.  animate_statue(statue, x, y, cause, fail_reason)
  30.  struct obj *statue;
  31.  xchar x, y;
  32.  int cause;
  33.  int *fail_reason;
  34.  {
  35.      int mnum = statue->corpsenm;
  36.      struct permonst *mptr = &mons[mnum];
  37.      struct monst *mon = 0, *shkp;
  38.      struct obj *item;
  39.      coord cc;
  40.      boolean historic = (Role_if(PM_ARCHEOLOGIST)
  41.                          && (statue->spe & STATUE_HISTORIC) != 0),
  42.              golem_xform = FALSE, use_saved_traits;
  43.      const char *comes_to_life;
  44.      char statuename[BUFSZ], tmpbuf[BUFSZ];
  45.      static const char historic_statue_is_gone[] =
  46.          "that the historic statue is now gone";
  47.  
  48.      if (cant_revive(&mnum, TRUE, statue)) {
  49.          /* mnum has changed; we won't be animating this statue as itself */
  50.          if (mnum != PM_DOPPELGANGER)
  51.              mptr = &mons[mnum];
  52.          use_saved_traits = FALSE;
  53.      } else if (is_golem(mptr) && cause == ANIMATE_SPELL) {
  54.          /* statue of any golem hit by stone-to-flesh becomes flesh golem */
  55.          golem_xform = (mptr != &mons[PM_FLESH_GOLEM]);
  56.          mnum = PM_FLESH_GOLEM;
  57.          mptr = &mons[PM_FLESH_GOLEM];
  58.          use_saved_traits = (has_omonst(statue) && !golem_xform);
  59.      } else {
  60.          use_saved_traits = has_omonst(statue);
  61.      }
  62.  
  63.      if (use_saved_traits) {
  64.          /* restore a petrified monster */
  65.          cc.x = x, cc.y = y;
  66.          mon = montraits(statue, &cc);
  67.          if (mon && mon->mtame && !mon->isminion)
  68.              wary_dog(mon, TRUE);
  69.      } else {
  70.          /* statues of unique monsters from bones or wishing end
  71.             up here (cant_revive() sets mnum to be doppelganger;
  72.             mptr reflects the original form for use by newcham()) */
  73.          if ((mnum == PM_DOPPELGANGER && mptr != &mons[PM_DOPPELGANGER])
  74.              /* block quest guards from other roles */
  75.              || (mptr->msound == MS_GUARDIAN
  76.                  && quest_info(MS_GUARDIAN) != mnum)) {
  77.              mon = makemon(&mons[PM_DOPPELGANGER], x, y,
  78.                            NO_MINVENT | MM_NOCOUNTBIRTH | MM_ADJACENTOK);
  79.              /* if hero has protection from shape changers, cham field will
  80.                 be NON_PM; otherwise, set form to match the statue */
  81.              if (mon && mon->cham >= LOW_PM)
  82.                  (void) newcham(mon, mptr, FALSE, FALSE);
  83.          } else
  84.              mon = makemon(mptr, x, y, (cause == ANIMATE_SPELL)
  85.                                            ? (NO_MINVENT | MM_ADJACENTOK)
  86.                                            : NO_MINVENT);
  87.      }
  88.  
  89.      if (!mon) {
  90.          if (fail_reason)
  91.              *fail_reason = unique_corpstat(&mons[statue->corpsenm])
  92.                                 ? AS_MON_IS_UNIQUE
  93.                                 : AS_NO_MON;
  94.          return (struct monst *) 0;
  95.      }
  96.  
  97.      /* a non-montraits() statue might specify gender */
  98.      if (statue->spe & STATUE_MALE)
  99.          mon->female = FALSE;
  100.      else if (statue->spe & STATUE_FEMALE)
  101.          mon->female = TRUE;
  102.      /* if statue has been named, give same name to the monster */
  103.      if (has_oname(statue))
  104.          mon = christen_monst(mon, ONAME(statue));
  105.      /* mimic statue becomes seen mimic; other hiders won't be hidden */
  106.      if (mon->m_ap_type)
  107.          seemimic(mon);
  108.      else
  109.          mon->mundetected = FALSE;
  110.      mon->msleeping = 0;
  111.      if (cause == ANIMATE_NORMAL || cause == ANIMATE_SHATTER) {
  112.          /* trap always releases hostile monster */
  113.          mon->mtame = 0; /* (might be petrified pet tossed onto trap) */
  114.          mon->mpeaceful = 0;
  115.          set_malign(mon);
  116.      }
  117.  
  118.      comes_to_life = !canspotmon(mon)
  119.                          ? "disappears"
  120.                          : golem_xform
  121.                                ? "turns into flesh"
  122.                                : (nonliving(mon->data) || is_vampshifter(mon))
  123.                                      ? "moves"
  124.                                      : "comes to life";
  125.      if ((x == u.ux && y == u.uy) || cause == ANIMATE_SPELL) {
  126.          /* "the|your|Manlobbi's statue [of a wombat]" */
  127.          shkp = shop_keeper(*in_rooms(mon->mx, mon->my, SHOPBASE));
  128.          Sprintf(statuename, "%s%s", shk_your(tmpbuf, statue),
  129.                  (cause == ANIMATE_SPELL
  130.                   /* avoid "of a shopkeeper" if it's Manlobbi himself
  131.                      (if carried, it can't be unpaid--hence won't be
  132.                      described as "Manlobbi's statue"--because there
  133.                      wasn't any living shk when statue was picked up) */
  134.                   && (mon != shkp || carried(statue)))
  135.                     ? xname(statue)
  136.                     : "statue");
  137.          pline("%s %s!", upstart(statuename), comes_to_life);
  138.      } else if (Hallucination) { /* They don't know it's a statue */
  139.          pline_The("%s suddenly seems more animated.", rndmonnam((char *) 0));
  140.      } else if (cause == ANIMATE_SHATTER) {
  141.          if (cansee(x, y))
  142.              Sprintf(statuename, "%s%s", shk_your(tmpbuf, statue),
  143.                      xname(statue));
  144.          else
  145.              Strcpy(statuename, "a statue");
  146.          pline("Instead of shattering, %s suddenly %s!", statuename,
  147.                comes_to_life);
  148.      } else { /* cause == ANIMATE_NORMAL */
  149.          You("find %s posing as a statue.",
  150.              canspotmon(mon) ? a_monnam(mon) : something);
  151.          if (!canspotmon(mon) && Blind)
  152.              map_invisible(x, y);
  153.          stop_occupation();
  154.      }
  155.  
  156.      /* if this isn't caused by a monster using a wand of striking,
  157.         there might be consequences for the hero */
  158.      if (!context.mon_moving) {
  159.          /* if statue is owned by a shop, hero will have to pay for it;
  160.             stolen_value gives a message (about debt or use of credit)
  161.             which refers to "it" so needs to follow a message describing
  162.             the object ("the statue comes to life" one above) */
  163.          if (cause != ANIMATE_NORMAL && costly_spot(x, y)
  164.              && (shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) != 0
  165.              /* avoid charging for Manlobbi's statue of Manlobbi
  166.                 if stone-to-flesh is used on petrified shopkeep */
  167.              && mon != shkp)
  168.              (void) stolen_value(statue, x, y, (boolean) shkp->mpeaceful,
  169.                                  FALSE);
  170.  
  171.          if (historic) {
  172.              You_feel("guilty %s.", historic_statue_is_gone);
  173.              adjalign(-1);
  174.          }
  175.      } else {
  176.          if (historic && cansee(x, y))
  177.              You_feel("regret %s.", historic_statue_is_gone);
  178.          /* no alignment penalty */
  179.      }
  180.  
  181.      /* transfer any statue contents to monster's inventory */
  182.      while ((item = statue->cobj) != 0) {
  183.          obj_extract_self(item);
  184.          (void) mpickobj(mon, item);
  185.      }
  186.      m_dowear(mon, TRUE);
  187.      /* in case statue is wielded and hero zaps stone-to-flesh at self */
  188.      if (statue->owornmask)
  189.          remove_worn_item(statue, TRUE);
  190.      /* statue no longer exists */
  191.      delobj(statue);
  192.  
  193.      /* avoid hiding under nothing */
  194.      if (x == u.ux && y == u.uy && Upolyd && hides_under(youmonst.data)
  195.          && !OBJ_AT(x, y))
  196.          u.uundetected = 0;
  197.  
  198.      if (fail_reason)
  199.          *fail_reason = AS_OK;
  200.      return mon;
  201.  }
  202.  

activate_statue_trap

  1.  /*
  2.   * You've either stepped onto a statue trap's location or you've triggered a
  3.   * statue trap by searching next to it or by trying to break it with a wand
  4.   * or pick-axe.
  5.   */
  6.  struct monst *
  7.  activate_statue_trap(trap, x, y, shatter)
  8.  struct trap *trap;
  9.  xchar x, y;
  10.  boolean shatter;
  11.  {
  12.      struct monst *mtmp = (struct monst *) 0;
  13.      struct obj *otmp = sobj_at(STATUE, x, y);
  14.      int fail_reason;
  15.  
  16.      /*
  17.       * Try to animate the first valid statue.  Stop the loop when we
  18.       * actually create something or the failure cause is not because
  19.       * the mon was unique.
  20.       */
  21.      deltrap(trap);
  22.      while (otmp) {
  23.          mtmp = animate_statue(otmp, x, y,
  24.                                shatter ? ANIMATE_SHATTER : ANIMATE_NORMAL,
  25.                                &fail_reason);
  26.          if (mtmp || fail_reason != AS_MON_IS_UNIQUE)
  27.              break;
  28.  
  29.          otmp = nxtobj(otmp, STATUE, TRUE);
  30.      }
  31.  
  32.      feel_newsym(x, y);
  33.      return mtmp;
  34.  }
  35.  

keep_saddle_with_steedcorpse

  1.  STATIC_OVL boolean
  2.  keep_saddle_with_steedcorpse(steed_mid, objchn, saddle)
  3.  unsigned steed_mid;
  4.  struct obj *objchn, *saddle;
  5.  {
  6.      if (!saddle)
  7.          return FALSE;
  8.      while (objchn) {
  9.          if (objchn->otyp == CORPSE && has_omonst(objchn)) {
  10.              struct monst *mtmp = OMONST(objchn);
  11.  
  12.              if (mtmp->m_id == steed_mid) {
  13.                  /* move saddle */
  14.                  xchar x, y;
  15.                  if (get_obj_location(objchn, &x, &y, 0)) {
  16.                      obj_extract_self(saddle);
  17.                      place_object(saddle, x, y);
  18.                      stackobj(saddle);
  19.                  }
  20.                  return TRUE;
  21.              }
  22.          }
  23.          if (Has_contents(objchn)
  24.              && keep_saddle_with_steedcorpse(steed_mid, objchn->cobj, saddle))
  25.              return TRUE;
  26.          objchn = objchn->nobj;
  27.      }
  28.      return FALSE;
  29.  }
  30.  

dotrap

  1.  void
  2.  dotrap(trap, trflags)
  3.  register struct trap *trap;
  4.  unsigned trflags;
  5.  {
  6.      register int ttype = trap->ttyp;
  7.      register struct obj *otmp;
  8.      boolean already_seen = trap->tseen,
  9.              forcetrap = (trflags & FORCETRAP) != 0,
  10.              webmsgok = (trflags & NOWEBMSG) == 0,
  11.              forcebungle = (trflags & FORCEBUNGLE) != 0,
  12.              plunged = (trflags & TOOKPLUNGE) != 0,
  13.              adj_pit = conjoined_pits(trap, t_at(u.ux0, u.uy0), TRUE);
  14.      int oldumort;
  15.      int steed_article = ARTICLE_THE;
  16.  
  17.      nomul(0);
  18.  
  19.      /* KMH -- You can't escape the Sokoban level traps */
  20.      if (Sokoban && (ttype == PIT || ttype == SPIKED_PIT
  21.                      || ttype == HOLE || ttype == TRAPDOOR)) {
  22.          /* The "air currents" message is still appropriate -- even when
  23.           * the hero isn't flying or levitating -- because it conveys the
  24.           * reason why the player cannot escape the trap with a dexterity
  25.           * check, clinging to the ceiling, etc.
  26.           */
  27.          pline("Air currents pull you down into %s %s!",
  28.                a_your[trap->madeby_u],
  29.                defsyms[trap_to_defsym(ttype)].explanation);
  30.          /* then proceed to normal trap effect */
  31.      } else if (already_seen && !forcetrap) {
  32.          if ((Levitation || (Flying && !plunged))
  33.              && (ttype == PIT || ttype == SPIKED_PIT || ttype == HOLE
  34.                  || ttype == BEAR_TRAP)) {
  35.              You("%s over %s %s.", Levitation ? "float" : "fly",
  36.                  a_your[trap->madeby_u],
  37.                  defsyms[trap_to_defsym(ttype)].explanation);
  38.              return;
  39.          }
  40.          if (!Fumbling && ttype != MAGIC_PORTAL && ttype != VIBRATING_SQUARE
  41.              && ttype != ANTI_MAGIC && !forcebungle && !plunged && !adj_pit
  42.              && (!rn2(5) || ((ttype == PIT || ttype == SPIKED_PIT)
  43.                              && is_clinger(youmonst.data)))) {
  44.              You("escape %s %s.", (ttype == ARROW_TRAP && !trap->madeby_u)
  45.                                       ? "an"
  46.                                       : a_your[trap->madeby_u],
  47.                  defsyms[trap_to_defsym(ttype)].explanation);
  48.              return;
  49.          }
  50.      }
  51.  
  52.      if (u.usteed) {
  53.          u.usteed->mtrapseen |= (1 << (ttype - 1));
  54.          /* suppress article in various steed messages when using its
  55.             name (which won't occur when hallucinating) */
  56.          if (has_mname(u.usteed) && !Hallucination)
  57.              steed_article = ARTICLE_NONE;
  58.      }
  59.  
  60.      switch (ttype) {
  61.      case ARROW_TRAP:
  62.          if (trap->once && trap->tseen && !rn2(15)) {
  63.              You_hear("a loud click!");
  64.              deltrap(trap);
  65.              newsym(u.ux, u.uy);
  66.              break;
  67.          }
  68.          trap->once = 1;
  69.          seetrap(trap);
  70.          pline("An arrow shoots out at you!");
  71.          otmp = mksobj(ARROW, TRUE, FALSE);
  72.          otmp->quan = 1L;
  73.          otmp->owt = weight(otmp);
  74.          otmp->opoisoned = 0;
  75.          if (u.usteed && !rn2(2) && steedintrap(trap, otmp)) { /* nothing */
  76.              ;
  77.          } else if (thitu(8, dmgval(otmp, &youmonst), otmp, "arrow")) {
  78.              obfree(otmp, (struct obj *) 0);
  79.          } else {
  80.              place_object(otmp, u.ux, u.uy);
  81.              if (!Blind)
  82.                  otmp->dknown = 1;
  83.              stackobj(otmp);
  84.              newsym(u.ux, u.uy);
  85.          }
  86.          break;
  87.  
  88.      case DART_TRAP:
  89.          if (trap->once && trap->tseen && !rn2(15)) {
  90.              You_hear("a soft click.");
  91.              deltrap(trap);
  92.              newsym(u.ux, u.uy);
  93.              break;
  94.          }
  95.          trap->once = 1;
  96.          seetrap(trap);
  97.          pline("A little dart shoots out at you!");
  98.          otmp = mksobj(DART, TRUE, FALSE);
  99.          otmp->quan = 1L;
  100.          otmp->owt = weight(otmp);
  101.          if (!rn2(6))
  102.              otmp->opoisoned = 1;
  103.          oldumort = u.umortality;
  104.          if (u.usteed && !rn2(2) && steedintrap(trap, otmp)) { /* nothing */
  105.              ;
  106.          } else if (thitu(7, dmgval(otmp, &youmonst), otmp, "little dart")) {
  107.              if (otmp->opoisoned)
  108.                  poisoned("dart", A_CON, "little dart",
  109.                           /* if damage triggered life-saving,
  110.                              poison is limited to attrib loss */
  111.                           (u.umortality > oldumort) ? 0 : 10, TRUE);
  112.              obfree(otmp, (struct obj *) 0);
  113.          } else {
  114.              place_object(otmp, u.ux, u.uy);
  115.              if (!Blind)
  116.                  otmp->dknown = 1;
  117.              stackobj(otmp);
  118.              newsym(u.ux, u.uy);
  119.          }
  120.          break;
  121.  
  122.      case ROCKTRAP:
  123.          if (trap->once && trap->tseen && !rn2(15)) {
  124.              pline("A trap door in %s opens, but nothing falls out!",
  125.                    the(ceiling(u.ux, u.uy)));
  126.              deltrap(trap);
  127.              newsym(u.ux, u.uy);
  128.          } else {
  129.              int dmg = d(2, 6); /* should be std ROCK dmg? */
  130.  
  131.              trap->once = 1;
  132.              feeltrap(trap);
  133.              otmp = mksobj_at(ROCK, u.ux, u.uy, TRUE, FALSE);
  134.              otmp->quan = 1L;
  135.              otmp->owt = weight(otmp);
  136.  
  137.              pline("A trap door in %s opens and %s falls on your %s!",
  138.                    the(ceiling(u.ux, u.uy)), an(xname(otmp)), body_part(HEAD));
  139.  
  140.              if (uarmh) {
  141.                  if (is_metallic(uarmh)) {
  142.                      pline("Fortunately, you are wearing a hard helmet.");
  143.                      dmg = 2;
  144.                  } else if (flags.verbose) {
  145.                      pline("%s does not protect you.", Yname2(uarmh));
  146.                  }
  147.              }
  148.  
  149.              if (!Blind)
  150.                  otmp->dknown = 1;
  151.              stackobj(otmp);
  152.              newsym(u.ux, u.uy); /* map the rock */
  153.  
  154.              losehp(Maybe_Half_Phys(dmg), "falling rock", KILLED_BY_AN);
  155.              exercise(A_STR, FALSE);
  156.          }
  157.          break;
  158.  
  159.      case SQKY_BOARD: /* stepped on a squeaky board */
  160.          if ((Levitation || Flying) && !forcetrap) {
  161.              if (!Blind) {
  162.                  seetrap(trap);
  163.                  if (Hallucination)
  164.                      You("notice a crease in the linoleum.");
  165.                  else
  166.                      You("notice a loose board below you.");
  167.              }
  168.          } else {
  169.              seetrap(trap);
  170.              pline("A board beneath you %s%s%s.",
  171.                    Deaf ? "vibrates" : "squeaks ",
  172.                    Deaf ? "" : trapnote(trap, 0), Deaf ? "" : " loudly");
  173.              wake_nearby();
  174.          }
  175.          break;
  176.  
  177.      case BEAR_TRAP: {
  178.          int dmg = d(2, 4);
  179.  
  180.          if ((Levitation || Flying) && !forcetrap)
  181.              break;
  182.          feeltrap(trap);
  183.          if (amorphous(youmonst.data) || is_whirly(youmonst.data)
  184.              || unsolid(youmonst.data)) {
  185.              pline("%s bear trap closes harmlessly through you.",
  186.                    A_Your[trap->madeby_u]);
  187.              break;
  188.          }
  189.          if (!u.usteed && youmonst.data->msize <= MZ_SMALL) {
  190.              pline("%s bear trap closes harmlessly over you.",
  191.                    A_Your[trap->madeby_u]);
  192.              break;
  193.          }
  194.          u.utrap = rn1(4, 4);
  195.          u.utraptype = TT_BEARTRAP;
  196.          if (u.usteed) {
  197.              pline("%s bear trap closes on %s %s!", A_Your[trap->madeby_u],
  198.                    s_suffix(mon_nam(u.usteed)), mbodypart(u.usteed, FOOT));
  199.              if (thitm(0, u.usteed, (struct obj *) 0, dmg, FALSE))
  200.                  u.utrap = 0; /* steed died, hero not trapped */
  201.          } else {
  202.              pline("%s bear trap closes on your %s!", A_Your[trap->madeby_u],
  203.                    body_part(FOOT));
  204.              set_wounded_legs(rn2(2) ? RIGHT_SIDE : LEFT_SIDE, rn1(10, 10));
  205.              if (u.umonnum == PM_OWLBEAR || u.umonnum == PM_BUGBEAR)
  206.                  You("howl in anger!");
  207.              losehp(Maybe_Half_Phys(dmg), "bear trap", KILLED_BY_AN);
  208.          }
  209.          exercise(A_DEX, FALSE);
  210.          break;
  211.      }
  212.  
  213.      case SLP_GAS_TRAP:
  214.          seetrap(trap);
  215.          if (Sleep_resistance || breathless(youmonst.data)) {
  216.              You("are enveloped in a cloud of gas!");
  217.          } else {
  218.              pline("A cloud of gas puts you to sleep!");
  219.              fall_asleep(-rnd(25), TRUE);
  220.          }
  221.          (void) steedintrap(trap, (struct obj *) 0);
  222.          break;
  223.  
  224.      case RUST_TRAP:
  225.          seetrap(trap);
  226.  
  227.          /* Unlike monsters, traps cannot aim their rust attacks at
  228.           * you, so instead of looping through and taking either the
  229.           * first rustable one or the body, we take whatever we get,
  230.           * even if it is not rustable.
  231.           */
  232.          switch (rn2(5)) {
  233.          case 0:
  234.              pline("%s you on the %s!", A_gush_of_water_hits, body_part(HEAD));
  235.              (void) water_damage(uarmh, helm_simple_name(uarmh), TRUE);
  236.              break;
  237.          case 1:
  238.              pline("%s your left %s!", A_gush_of_water_hits, body_part(ARM));
  239.              if (water_damage(uarms, "shield", TRUE) != ER_NOTHING)
  240.                  break;
  241.              if (u.twoweap || (uwep && bimanual(uwep)))
  242.                  (void) water_damage(u.twoweap ? uswapwep : uwep, 0, TRUE);
  243.          glovecheck:
  244.              (void) water_damage(uarmg, "gauntlets", TRUE);
  245.              /* Not "metal gauntlets" since it gets called
  246.               * even if it's leather for the message
  247.               */
  248.              break;
  249.          case 2:
  250.              pline("%s your right %s!", A_gush_of_water_hits, body_part(ARM));
  251.              (void) water_damage(uwep, 0, TRUE);
  252.              goto glovecheck;
  253.          default:
  254.              pline("%s you!", A_gush_of_water_hits);
  255.              for (otmp = invent; otmp; otmp = otmp->nobj)
  256.                  if (otmp->lamplit && otmp != uwep
  257.                      && (otmp != uswapwep || !u.twoweap))
  258.                      (void) snuff_lit(otmp);
  259.              if (uarmc)
  260.                  (void) water_damage(uarmc, cloak_simple_name(uarmc), TRUE);
  261.              else if (uarm)
  262.                  (void) water_damage(uarm, "armor", TRUE);
  263.              else if (uarmu)
  264.                  (void) water_damage(uarmu, "shirt", TRUE);
  265.          }
  266.          update_inventory();
  267.  
  268.          if (u.umonnum == PM_IRON_GOLEM) {
  269.              int dam = u.mhmax;
  270.  
  271.              pline("%s you!", A_gush_of_water_hits);
  272.              You("are covered with rust!");
  273.              losehp(Maybe_Half_Phys(dam), "rusting away", KILLED_BY);
  274.          } else if (u.umonnum == PM_GREMLIN && rn2(3)) {
  275.              pline("%s you!", A_gush_of_water_hits);
  276.              (void) split_mon(&youmonst, (struct monst *) 0);
  277.          }
  278.  
  279.          break;
  280.  
  281.      case FIRE_TRAP:
  282.          seetrap(trap);
  283.          dofiretrap((struct obj *) 0);
  284.          break;
  285.  
  286.      case PIT:
  287.      case SPIKED_PIT:
  288.          /* KMH -- You can't escape the Sokoban level traps */
  289.          if (!Sokoban && (Levitation || (Flying && !plunged)))
  290.              break;
  291.          feeltrap(trap);
  292.          if (!Sokoban && is_clinger(youmonst.data) && !plunged) {
  293.              if (trap->tseen) {
  294.                  You_see("%s %spit below you.", a_your[trap->madeby_u],
  295.                          ttype == SPIKED_PIT ? "spiked " : "");
  296.              } else {
  297.                  pline("%s pit %sopens up under you!", A_Your[trap->madeby_u],
  298.                        ttype == SPIKED_PIT ? "full of spikes " : "");
  299.                  You("don't fall in!");
  300.              }
  301.              break;
  302.          }
  303.          if (!Sokoban) {
  304.              char verbbuf[BUFSZ];
  305.  
  306.              if (u.usteed) {
  307.                  if ((trflags & RECURSIVETRAP) != 0)
  308.                      Sprintf(verbbuf, "and %s fall",
  309.                              x_monnam(u.usteed, steed_article, (char *) 0,
  310.                                       SUPPRESS_SADDLE, FALSE));
  311.                  else
  312.                      Sprintf(verbbuf, "lead %s",
  313.                              x_monnam(u.usteed, steed_article, "poor",
  314.                                       SUPPRESS_SADDLE, FALSE));
  315.              } else if (adj_pit) {
  316.                  You("move into an adjacent pit.");
  317.              } else {
  318.                  Strcpy(verbbuf,
  319.                         !plunged ? "fall" : (Flying ? "dive" : "plunge"));
  320.                  You("%s into %s pit!", verbbuf, a_your[trap->madeby_u]);
  321.              }
  322.          }
  323.          /* wumpus reference */
  324.          if (Role_if(PM_RANGER) && !trap->madeby_u && !trap->once
  325.              && In_quest(&u.uz) && Is_qlocate(&u.uz)) {
  326.              pline("Fortunately it has a bottom after all...");
  327.              trap->once = 1;
  328.          } else if (u.umonnum == PM_PIT_VIPER || u.umonnum == PM_PIT_FIEND) {
  329.              pline("How pitiful.  Isn't that the pits?");
  330.          }
  331.          if (ttype == SPIKED_PIT) {
  332.              const char *predicament = "on a set of sharp iron spikes";
  333.  
  334.              if (u.usteed) {
  335.                  pline("%s %s %s!",
  336.                        upstart(x_monnam(u.usteed, steed_article, "poor",
  337.                                         SUPPRESS_SADDLE, FALSE)),
  338.                        adj_pit ? "steps" : "lands", predicament);
  339.              } else
  340.                  You("%s %s!", adj_pit ? "step" : "land", predicament);
  341.          }
  342.          u.utrap = rn1(6, 2);
  343.          u.utraptype = TT_PIT;
  344.          if (!steedintrap(trap, (struct obj *) 0)) {
  345.              if (ttype == SPIKED_PIT) {
  346.                  oldumort = u.umortality;
  347.                  losehp(Maybe_Half_Phys(rnd(adj_pit ? 6 : 10)),
  348.                         plunged
  349.                             ? "deliberately plunged into a pit of iron spikes"
  350.                             : adj_pit ? "stepped into a pit of iron spikes"
  351.                                       : "fell into a pit of iron spikes",
  352.                         NO_KILLER_PREFIX);
  353.                  if (!rn2(6))
  354.                      poisoned("spikes", A_STR,
  355.                               adj_pit ? "stepping on poison spikes"
  356.                                       : "fall onto poison spikes",
  357.                               /* if damage triggered life-saving,
  358.                                  poison is limited to attrib loss */
  359.                               (u.umortality > oldumort) ? 0 : 8, FALSE);
  360.              } else {
  361.                  /* plunging flyers take spike damage but not pit damage */
  362.                  if (!adj_pit
  363.                      && !(plunged && (Flying || is_clinger(youmonst.data))))
  364.                      losehp(Maybe_Half_Phys(rnd(6)),
  365.                             plunged ? "deliberately plunged into a pit"
  366.                                     : "fell into a pit",
  367.                             NO_KILLER_PREFIX);
  368.              }
  369.              if (Punished && !carried(uball)) {
  370.                  unplacebc();
  371.                  ballfall();
  372.                  placebc();
  373.              }
  374.              if (!adj_pit)
  375.                  selftouch("Falling, you");
  376.              vision_full_recalc = 1; /* vision limits change */
  377.              exercise(A_STR, FALSE);
  378.              exercise(A_DEX, FALSE);
  379.          }
  380.          break;
  381.  
  382.      case HOLE:
  383.      case TRAPDOOR:
  384.          if (!Can_fall_thru(&u.uz)) {
  385.              seetrap(trap); /* normally done in fall_through */
  386.              impossible("dotrap: %ss cannot exist on this level.",
  387.                         defsyms[trap_to_defsym(ttype)].explanation);
  388.              break; /* don't activate it after all */
  389.          }
  390.          fall_through(TRUE);
  391.          break;
  392.  
  393.      case TELEP_TRAP:
  394.          seetrap(trap);
  395.          tele_trap(trap);
  396.          break;
  397.  
  398.      case LEVEL_TELEP:
  399.          seetrap(trap);
  400.          level_tele_trap(trap);
  401.          break;
  402.  
  403.      case WEB: /* Our luckless player has stumbled into a web. */
  404.          feeltrap(trap);
  405.          if (amorphous(youmonst.data) || is_whirly(youmonst.data)
  406.              || unsolid(youmonst.data)) {
  407.              if (acidic(youmonst.data) || u.umonnum == PM_GELATINOUS_CUBE
  408.                  || u.umonnum == PM_FIRE_ELEMENTAL) {
  409.                  if (webmsgok)
  410.                      You("%s %s spider web!",
  411.                          (u.umonnum == PM_FIRE_ELEMENTAL) ? "burn"
  412.                                                           : "dissolve",
  413.                          a_your[trap->madeby_u]);
  414.                  deltrap(trap);
  415.                  newsym(u.ux, u.uy);
  416.                  break;
  417.              }
  418.              if (webmsgok)
  419.                  You("flow through %s spider web.", a_your[trap->madeby_u]);
  420.              break;
  421.          }
  422.          if (webmaker(youmonst.data)) {
  423.              if (webmsgok)
  424.                  pline(trap->madeby_u ? "You take a walk on your web."
  425.                                       : "There is a spider web here.");
  426.              break;
  427.          }
  428.          if (webmsgok) {
  429.              char verbbuf[BUFSZ];
  430.  
  431.              if (forcetrap) {
  432.                  Strcpy(verbbuf, "are caught by");
  433.              } else if (u.usteed) {
  434.                  Sprintf(verbbuf, "lead %s into",
  435.                          x_monnam(u.usteed, steed_article, "poor",
  436.                                   SUPPRESS_SADDLE, FALSE));
  437.              } else {
  438.                  Sprintf(verbbuf, "%s into",
  439.                          Levitation ? (const char *) "float"
  440.                                     : locomotion(youmonst.data, "stumble"));
  441.              }
  442.              You("%s %s spider web!", verbbuf, a_your[trap->madeby_u]);
  443.          }
  444.          u.utraptype = TT_WEB;
  445.  
  446.          /* Time stuck in the web depends on your/steed strength. */
  447.          {
  448.              register int str = ACURR(A_STR);
  449.  
  450.              /* If mounted, the steed gets trapped.  Use mintrap
  451.               * to do all the work.  If mtrapped is set as a result,
  452.               * unset it and set utrap instead.  In the case of a
  453.               * strongmonst and mintrap said it's trapped, use a
  454.               * short but non-zero trap time.  Otherwise, monsters
  455.               * have no specific strength, so use player strength.
  456.               * This gets skipped for webmsgok, which implies that
  457.               * the steed isn't a factor.
  458.               */
  459.              if (u.usteed && webmsgok) {
  460.                  /* mtmp location might not be up to date */
  461.                  u.usteed->mx = u.ux;
  462.                  u.usteed->my = u.uy;
  463.  
  464.                  /* mintrap currently does not return 2(died) for webs */
  465.                  if (mintrap(u.usteed)) {
  466.                      u.usteed->mtrapped = 0;
  467.                      if (strongmonst(u.usteed->data))
  468.                          str = 17;
  469.                  } else {
  470.                      break;
  471.                  }
  472.  
  473.                  webmsgok = FALSE; /* mintrap printed the messages */
  474.              }
  475.              if (str <= 3)
  476.                  u.utrap = rn1(6, 6);
  477.              else if (str < 6)
  478.                  u.utrap = rn1(6, 4);
  479.              else if (str < 9)
  480.                  u.utrap = rn1(4, 4);
  481.              else if (str < 12)
  482.                  u.utrap = rn1(4, 2);
  483.              else if (str < 15)
  484.                  u.utrap = rn1(2, 2);
  485.              else if (str < 18)
  486.                  u.utrap = rnd(2);
  487.              else if (str < 69)
  488.                  u.utrap = 1;
  489.              else {
  490.                  u.utrap = 0;
  491.                  if (webmsgok)
  492.                      You("tear through %s web!", a_your[trap->madeby_u]);
  493.                  deltrap(trap);
  494.                  newsym(u.ux, u.uy); /* get rid of trap symbol */
  495.              }
  496.          }
  497.          break;
  498.  
  499.      case STATUE_TRAP:
  500.          (void) activate_statue_trap(trap, u.ux, u.uy, FALSE);
  501.          break;
  502.  
  503.      case MAGIC_TRAP: /* A magic trap. */
  504.          seetrap(trap);
  505.          if (!rn2(30)) {
  506.              deltrap(trap);
  507.              newsym(u.ux, u.uy); /* update position */
  508.              You("are caught in a magical explosion!");
  509.              losehp(rnd(10), "magical explosion", KILLED_BY_AN);
  510.              Your("body absorbs some of the magical energy!");
  511.              u.uen = (u.uenmax += 2);
  512.              break;
  513.          } else {
  514.              domagictrap();
  515.          }
  516.          (void) steedintrap(trap, (struct obj *) 0);
  517.          break;
  518.  
  519.      case ANTI_MAGIC:
  520.          seetrap(trap);
  521.          /* hero without magic resistance loses spell energy,
  522.             hero with magic resistance takes damage instead;
  523.             possibly non-intuitive but useful for play balance */
  524.          if (!Antimagic) {
  525.              drain_en(rnd(u.ulevel) + 1);
  526.          } else {
  527.              int dmgval2 = rnd(4), hp = Upolyd ? u.mh : u.uhp;
  528.  
  529.              /* Half_XXX_damage has opposite its usual effect (approx)
  530.                 but isn't cumulative if hero has more than one */
  531.              if (Half_physical_damage || Half_spell_damage)
  532.                  dmgval2 += rnd(4);
  533.              /* give Magicbane wielder dose of own medicine */
  534.              if (uwep && uwep->oartifact == ART_MAGICBANE)
  535.                  dmgval2 += rnd(4);
  536.              /* having an artifact--other than own quest one--which
  537.                 confers magic resistance simply by being carried
  538.                 also increases the effect */
  539.              for (otmp = invent; otmp; otmp = otmp->nobj)
  540.                  if (otmp->oartifact && !is_quest_artifact(otmp)
  541.                      && defends_when_carried(AD_MAGM, otmp))
  542.                      break;
  543.              if (otmp)
  544.                  dmgval2 += rnd(4);
  545.              if (Passes_walls)
  546.                  dmgval2 = (dmgval2 + 3) / 4;
  547.  
  548.              You_feel((dmgval2 >= hp) ? "unbearably torpid!"
  549.                                       : (dmgval2 >= hp / 4) ? "very lethargic."
  550.                                                             : "sluggish.");
  551.              /* opposite of magical explosion */
  552.              losehp(dmgval2, "anti-magic implosion", KILLED_BY_AN);
  553.          }
  554.          break;
  555.  
  556.      case POLY_TRAP: {
  557.          char verbbuf[BUFSZ];
  558.  
  559.          seetrap(trap);
  560.          if (u.usteed)
  561.              Sprintf(verbbuf, "lead %s",
  562.                      x_monnam(u.usteed, steed_article, (char *) 0,
  563.                               SUPPRESS_SADDLE, FALSE));
  564.          else
  565.              Sprintf(verbbuf, "%s", Levitation
  566.                                         ? (const char *) "float"
  567.                                         : locomotion(youmonst.data, "step"));
  568.          You("%s onto a polymorph trap!", verbbuf);
  569.          if (Antimagic || Unchanging) {
  570.              shieldeff(u.ux, u.uy);
  571.              You_feel("momentarily different.");
  572.              /* Trap did nothing; don't remove it --KAA */
  573.          } else {
  574.              (void) steedintrap(trap, (struct obj *) 0);
  575.              deltrap(trap);      /* delete trap before polymorph */
  576.              newsym(u.ux, u.uy); /* get rid of trap symbol */
  577.              You_feel("a change coming over you.");
  578.              polyself(0);
  579.          }
  580.          break;
  581.      }
  582.      case LANDMINE: {
  583.          unsigned steed_mid = 0;
  584.          struct obj *saddle = 0;
  585.  
  586.          if ((Levitation || Flying) && !forcetrap) {
  587.              if (!already_seen && rn2(3))
  588.                  break;
  589.              feeltrap(trap);
  590.              pline("%s %s in a pile of soil below you.",
  591.                    already_seen ? "There is" : "You discover",
  592.                    trap->madeby_u ? "the trigger of your mine" : "a trigger");
  593.              if (already_seen && rn2(3))
  594.                  break;
  595.              pline("KAABLAMM!!!  %s %s%s off!",
  596.                    forcebungle ? "Your inept attempt sets"
  597.                                : "The air currents set",
  598.                    already_seen ? a_your[trap->madeby_u] : "",
  599.                    already_seen ? " land mine" : "it");
  600.          } else {
  601.              /* prevent landmine from killing steed, throwing you to
  602.               * the ground, and you being affected again by the same
  603.               * mine because it hasn't been deleted yet
  604.               */
  605.              static boolean recursive_mine = FALSE;
  606.  
  607.              if (recursive_mine)
  608.                  break;
  609.              feeltrap(trap);
  610.              pline("KAABLAMM!!!  You triggered %s land mine!",
  611.                    a_your[trap->madeby_u]);
  612.              if (u.usteed)
  613.                  steed_mid = u.usteed->m_id;
  614.              recursive_mine = TRUE;
  615.              (void) steedintrap(trap, (struct obj *) 0);
  616.              recursive_mine = FALSE;
  617.              saddle = sobj_at(SADDLE, u.ux, u.uy);
  618.              set_wounded_legs(LEFT_SIDE, rn1(35, 41));
  619.              set_wounded_legs(RIGHT_SIDE, rn1(35, 41));
  620.              exercise(A_DEX, FALSE);
  621.          }
  622.          blow_up_landmine(trap);
  623.          if (steed_mid && saddle && !u.usteed)
  624.              (void) keep_saddle_with_steedcorpse(steed_mid, fobj, saddle);
  625.          newsym(u.ux, u.uy); /* update trap symbol */
  626.          losehp(Maybe_Half_Phys(rnd(16)), "land mine", KILLED_BY_AN);
  627.          /* fall recursively into the pit... */
  628.          if ((trap = t_at(u.ux, u.uy)) != 0)
  629.              dotrap(trap, RECURSIVETRAP);
  630.          fill_pit(u.ux, u.uy);
  631.          break;
  632.      }
  633.  
  634.      case ROLLING_BOULDER_TRAP: {
  635.          int style = ROLL | (trap->tseen ? LAUNCH_KNOWN : 0);
  636.  
  637.          feeltrap(trap);
  638.          pline("Click! You trigger a rolling boulder trap!");
  639.          if (!launch_obj(BOULDER, trap->launch.x, trap->launch.y,
  640.                          trap->launch2.x, trap->launch2.y, style)) {
  641.              deltrap(trap);
  642.              newsym(u.ux, u.uy); /* get rid of trap symbol */
  643.              pline("Fortunately for you, no boulder was released.");
  644.          }
  645.          break;
  646.      }
  647.  
  648.      case MAGIC_PORTAL:
  649.          feeltrap(trap);
  650.          domagicportal(trap);
  651.          break;
  652.  
  653.      case VIBRATING_SQUARE:
  654.          feeltrap(trap);
  655.          /* messages handled elsewhere; the trap symbol is merely to mark the
  656.           * square for future reference */
  657.          break;
  658.  
  659.      default:
  660.          feeltrap(trap);
  661.          impossible("You hit a trap of type %u", trap->ttyp);
  662.      }
  663.  }
  664.  

trapnote

  1.  STATIC_OVL char *
  2.  trapnote(trap, noprefix)
  3.  struct trap *trap;
  4.  boolean noprefix;
  5.  {
  6.      static char tnbuf[12];
  7.      const char *tn,
  8.          *tnnames[12] = { "C note",  "D flat", "D note",  "E flat",
  9.                           "E note",  "F note", "F sharp", "G note",
  10.                           "G sharp", "A note", "B flat",  "B note" };
  11.  
  12.      tnbuf[0] = '\0';
  13.      tn = tnnames[trap->tnote];
  14.      if (!noprefix)
  15.          Sprintf(tnbuf, "%s ",
  16.                  (*tn == 'A' || *tn == 'E' || *tn == 'F') ? "an" : "a");
  17.      Sprintf(eos(tnbuf), "%s", tn);
  18.      return tnbuf;
  19.  }
  20.  

steedintrap

  1.  STATIC_OVL int
  2.  steedintrap(trap, otmp)
  3.  struct trap *trap;
  4.  struct obj *otmp;
  5.  {
  6.      struct monst *steed = u.usteed;
  7.      int tt;
  8.      boolean trapkilled, steedhit;
  9.  
  10.      if (!steed || !trap)
  11.          return 0;
  12.      tt = trap->ttyp;
  13.      steed->mx = u.ux;
  14.      steed->my = u.uy;
  15.      trapkilled = steedhit = FALSE;
  16.  
  17.      switch (tt) {
  18.      case ARROW_TRAP:
  19.          if (!otmp) {
  20.              impossible("steed hit by non-existant arrow?");
  21.              return 0;
  22.          }
  23.          trapkilled = thitm(8, steed, otmp, 0, FALSE);
  24.          steedhit = TRUE;
  25.          break;
  26.      case DART_TRAP:
  27.          if (!otmp) {
  28.              impossible("steed hit by non-existant dart?");
  29.              return 0;
  30.          }
  31.          trapkilled = thitm(7, steed, otmp, 0, FALSE);
  32.          steedhit = TRUE;
  33.          break;
  34.      case SLP_GAS_TRAP:
  35.          if (!resists_sleep(steed) && !breathless(steed->data)
  36.              && !steed->msleeping && steed->mcanmove) {
  37.              if (sleep_monst(steed, rnd(25), -1))
  38.                  /* no in_sight check here; you can feel it even if blind */
  39.                  pline("%s suddenly falls asleep!", Monnam(steed));
  40.          }
  41.          steedhit = TRUE;
  42.          break;
  43.      case LANDMINE:
  44.          trapkilled = thitm(0, steed, (struct obj *) 0, rnd(16), FALSE);
  45.          steedhit = TRUE;
  46.          break;
  47.      case PIT:
  48.      case SPIKED_PIT:
  49.          trapkilled = (steed->mhp <= 0
  50.                        || thitm(0, steed, (struct obj *) 0,
  51.                                 rnd((tt == PIT) ? 6 : 10), FALSE));
  52.          steedhit = TRUE;
  53.          break;
  54.      case POLY_TRAP:
  55.          if (!resists_magm(steed) && !resist(steed, WAND_CLASS, 0, NOTELL)) {
  56.              (void) newcham(steed, (struct permonst *) 0, FALSE, FALSE);
  57.              if (!can_saddle(steed) || !can_ride(steed))
  58.                  dismount_steed(DISMOUNT_POLY);
  59.              else
  60.                  You("have to adjust yourself in the saddle on %s.",
  61.                      x_monnam(steed, ARTICLE_A, (char *) 0, SUPPRESS_SADDLE,
  62.                               FALSE));
  63.          }
  64.          steedhit = TRUE;
  65.          break;
  66.      default:
  67.          break;
  68.      }
  69.  
  70.      if (trapkilled) {
  71.          dismount_steed(DISMOUNT_POLY);
  72.          return 2;
  73.      }
  74.      return steedhit ? 1 : 0;
  75.  }
  76.  

blow_up_landmine

  1.  /* some actions common to both player and monsters for triggered landmine */
  2.  void
  3.  blow_up_landmine(trap)
  4.  struct trap *trap;
  5.  {
  6.      int x = trap->tx, y = trap->ty, dbx, dby;
  7.      struct rm *lev = &levl[x][y];
  8.  
  9.      (void) scatter(x, y, 4,
  10.                     MAY_DESTROY | MAY_HIT | MAY_FRACTURE | VIS_EFFECTS,
  11.                     (struct obj *) 0);
  12.      del_engr_at(x, y);
  13.      wake_nearto(x, y, 400);
  14.      if (IS_DOOR(lev->typ))
  15.          lev->doormask = D_BROKEN;
  16.      /* destroy drawbridge if present */
  17.      if (lev->typ == DRAWBRIDGE_DOWN || is_drawbridge_wall(x, y) >= 0) {
  18.          dbx = x, dby = y;
  19.          /* if under the portcullis, the bridge is adjacent */
  20.          if (find_drawbridge(&dbx, &dby))
  21.              destroy_drawbridge(dbx, dby);
  22.          trap = t_at(x, y); /* expected to be null after destruction */
  23.      }
  24.      /* convert landmine into pit */
  25.      if (trap) {
  26.          if (Is_waterlevel(&u.uz) || Is_airlevel(&u.uz)) {
  27.              /* no pits here */
  28.              deltrap(trap);
  29.          } else {
  30.              trap->ttyp = PIT;       /* explosion creates a pit */
  31.              trap->madeby_u = FALSE; /* resulting pit isn't yours */
  32.              seetrap(trap);          /* and it isn't concealed */
  33.          }
  34.      }
  35.  }
  36.  

launc_drop_spot

  1.  /*
  2.   * The following are used to track launched objects to
  3.   * prevent them from vanishing if you are killed. They
  4.   * will reappear at the launchplace in bones files.
  5.   */
  6.  static struct {
  7.      struct obj *obj;
  8.      xchar x, y;
  9.  } launchplace;
  10.  
  11.  static void
  12.  launch_drop_spot(obj, x, y)
  13.  struct obj *obj;
  14.  xchar x, y;
  15.  {
  16.      if (!obj) {
  17.          launchplace.obj = (struct obj *) 0;
  18.          launchplace.x = 0;
  19.          launchplace.y = 0;
  20.      } else {
  21.          launchplace.obj = obj;
  22.          launchplace.x = x;
  23.          launchplace.y = y;
  24.      }
  25.  }
  26.  

launch_in_progress

  1.  boolean
  2.  launch_in_progress()
  3.  {
  4.      if (launchplace.obj)
  5.          return TRUE;
  6.      return FALSE;
  7.  }
  8.  

force_launch_placement

  1.  void
  2.  force_launch_placement()
  3.  {
  4.      if (launchplace.obj) {
  5.          launchplace.obj->otrapped = 0;
  6.          place_object(launchplace.obj, launchplace.x, launchplace.y);
  7.      }
  8.  }
  9.  

launch_obj

  1.  /*
  2.   * Move obj from (x1,y1) to (x2,y2)
  3.   *
  4.   * Return 0 if no object was launched.
  5.   *        1 if an object was launched and placed somewhere.
  6.   *        2 if an object was launched, but used up.
  7.   */
  8.  int
  9.  launch_obj(otyp, x1, y1, x2, y2, style)
  10.  short otyp;
  11.  register int x1, y1, x2, y2;
  12.  int style;
  13.  {
  14.      register struct monst *mtmp;
  15.      register struct obj *otmp, *otmp2;
  16.      register int dx, dy;
  17.      struct obj *singleobj;
  18.      boolean used_up = FALSE;
  19.      boolean otherside = FALSE;
  20.      int dist;
  21.      int tmp;
  22.      int delaycnt = 0;
  23.  
  24.      otmp = sobj_at(otyp, x1, y1);
  25.      /* Try the other side too, for rolling boulder traps */
  26.      if (!otmp && otyp == BOULDER) {
  27.          otherside = TRUE;
  28.          otmp = sobj_at(otyp, x2, y2);
  29.      }
  30.      if (!otmp)
  31.          return 0;
  32.      if (otherside) { /* swap 'em */
  33.          int tx, ty;
  34.  
  35.          tx = x1;
  36.          ty = y1;
  37.          x1 = x2;
  38.          y1 = y2;
  39.          x2 = tx;
  40.          y2 = ty;
  41.      }
  42.  
  43.      if (otmp->quan == 1L) {
  44.          obj_extract_self(otmp);
  45.          singleobj = otmp;
  46.          otmp = (struct obj *) 0;
  47.      } else {
  48.          singleobj = splitobj(otmp, 1L);
  49.          obj_extract_self(singleobj);
  50.      }
  51.      newsym(x1, y1);
  52.      /* in case you're using a pick-axe to chop the boulder that's being
  53.         launched (perhaps a monster triggered it), destroy context so that
  54.         next dig attempt never thinks you're resuming previous effort */
  55.      if ((otyp == BOULDER || otyp == STATUE)
  56.          && singleobj->ox == context.digging.pos.x
  57.          && singleobj->oy == context.digging.pos.y)
  58.          (void) memset((genericptr_t) &context.digging, 0,
  59.                        sizeof(struct dig_info));
  60.  
  61.      dist = distmin(x1, y1, x2, y2);
  62.      bhitpos.x = x1;
  63.      bhitpos.y = y1;
  64.      dx = sgn(x2 - x1);
  65.      dy = sgn(y2 - y1);
  66.      switch (style) {
  67.      case ROLL | LAUNCH_UNSEEN:
  68.          if (otyp == BOULDER) {
  69.              You_hear(Hallucination ? "someone bowling."
  70.                                     : "rumbling in the distance.");
  71.          }
  72.          style &= ~LAUNCH_UNSEEN;
  73.          goto roll;
  74.      case ROLL | LAUNCH_KNOWN:
  75.          /* use otrapped as a flag to ohitmon */
  76.          singleobj->otrapped = 1;
  77.          style &= ~LAUNCH_KNOWN;
  78.      /* fall through */
  79.      roll:
  80.      case ROLL:
  81.          delaycnt = 2;
  82.      /* fall through */
  83.      default:
  84.          if (!delaycnt)
  85.              delaycnt = 1;
  86.          if (!cansee(bhitpos.x, bhitpos.y))
  87.              curs_on_u();
  88.          tmp_at(DISP_FLASH, obj_to_glyph(singleobj));
  89.          tmp_at(bhitpos.x, bhitpos.y);
  90.      }
  91.      /* Mark a spot to place object in bones files to prevent
  92.       * loss of object. Use the starting spot to ensure that
  93.       * a rolling boulder will still launch, which it wouldn't
  94.       * do if left midstream. Unfortunately we can't use the
  95.       * target resting spot, because there are some things/situations
  96.       * that would prevent it from ever getting there (bars), and we
  97.       * can't tell that yet.
  98.       */
  99.      launch_drop_spot(singleobj, bhitpos.x, bhitpos.y);
  100.  
  101.      /* Set the object in motion */
  102.      while (dist-- > 0 && !used_up) {
  103.          struct trap *t;
  104.          tmp_at(bhitpos.x, bhitpos.y);
  105.          tmp = delaycnt;
  106.  
  107.          /* dstage@u.washington.edu -- Delay only if hero sees it */
  108.          if (cansee(bhitpos.x, bhitpos.y))
  109.              while (tmp-- > 0)
  110.                  delay_output();
  111.  
  112.          bhitpos.x += dx;
  113.          bhitpos.y += dy;
  114.          t = t_at(bhitpos.x, bhitpos.y);
  115.  
  116.          if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) {
  117.              if (otyp == BOULDER && throws_rocks(mtmp->data)) {
  118.                  if (rn2(3)) {
  119.                      pline("%s snatches the boulder.", Monnam(mtmp));
  120.                      singleobj->otrapped = 0;
  121.                      (void) mpickobj(mtmp, singleobj);
  122.                      used_up = TRUE;
  123.                      launch_drop_spot((struct obj *) 0, 0, 0);
  124.                      break;
  125.                  }
  126.              }
  127.              if (ohitmon(mtmp, singleobj, (style == ROLL) ? -1 : dist,
  128.                          FALSE)) {
  129.                  used_up = TRUE;
  130.                  launch_drop_spot((struct obj *) 0, 0, 0);
  131.                  break;
  132.              }
  133.          } else if (bhitpos.x == u.ux && bhitpos.y == u.uy) {
  134.              if (multi)
  135.                  nomul(0);
  136.              if (thitu(9 + singleobj->spe, dmgval(singleobj, &youmonst),
  137.                        singleobj, (char *) 0))
  138.                  stop_occupation();
  139.          }
  140.          if (style == ROLL) {
  141.              if (down_gate(bhitpos.x, bhitpos.y) != -1) {
  142.                  if (ship_object(singleobj, bhitpos.x, bhitpos.y, FALSE)) {
  143.                      used_up = TRUE;
  144.                      launch_drop_spot((struct obj *) 0, 0, 0);
  145.                      break;
  146.                  }
  147.              }
  148.              if (t && otyp == BOULDER) {
  149.                  switch (t->ttyp) {
  150.                  case LANDMINE:
  151.                      if (rn2(10) > 2) {
  152.                          pline(
  153.                              "KAABLAMM!!!%s",
  154.                              cansee(bhitpos.x, bhitpos.y)
  155.                                  ? " The rolling boulder triggers a land mine."
  156.                                  : "");
  157.                          deltrap(t);
  158.                          del_engr_at(bhitpos.x, bhitpos.y);
  159.                          place_object(singleobj, bhitpos.x, bhitpos.y);
  160.                          singleobj->otrapped = 0;
  161.                          fracture_rock(singleobj);
  162.                          (void) scatter(bhitpos.x, bhitpos.y, 4,
  163.                                         MAY_DESTROY | MAY_HIT | MAY_FRACTURE
  164.                                             | VIS_EFFECTS,
  165.                                         (struct obj *) 0);
  166.                          if (cansee(bhitpos.x, bhitpos.y))
  167.                              newsym(bhitpos.x, bhitpos.y);
  168.                          used_up = TRUE;
  169.                          launch_drop_spot((struct obj *) 0, 0, 0);
  170.                      }
  171.                      break;
  172.                  case LEVEL_TELEP:
  173.                  case TELEP_TRAP:
  174.                      if (cansee(bhitpos.x, bhitpos.y))
  175.                          pline("Suddenly the rolling boulder disappears!");
  176.                      else
  177.                          You_hear("a rumbling stop abruptly.");
  178.                      singleobj->otrapped = 0;
  179.                      if (t->ttyp == TELEP_TRAP)
  180.                          (void) rloco(singleobj);
  181.                      else {
  182.                          int newlev = random_teleport_level();
  183.                          d_level dest;
  184.  
  185.                          if (newlev == depth(&u.uz) || In_endgame(&u.uz))
  186.                              continue;
  187.                          add_to_migration(singleobj);
  188.                          get_level(&dest, newlev);
  189.                          singleobj->ox = dest.dnum;
  190.                          singleobj->oy = dest.dlevel;
  191.                          singleobj->owornmask = (long) MIGR_RANDOM;
  192.                      }
  193.                      seetrap(t);
  194.                      used_up = TRUE;
  195.                      launch_drop_spot((struct obj *) 0, 0, 0);
  196.                      break;
  197.                  case PIT:
  198.                  case SPIKED_PIT:
  199.                  case HOLE:
  200.                  case TRAPDOOR:
  201.                      /* the boulder won't be used up if there is a
  202.                         monster in the trap; stop rolling anyway */
  203.                      x2 = bhitpos.x, y2 = bhitpos.y; /* stops here */
  204.                      if (flooreffects(singleobj, x2, y2, "fall")) {
  205.                          used_up = TRUE;
  206.                          launch_drop_spot((struct obj *) 0, 0, 0);
  207.                      }
  208.                      dist = -1; /* stop rolling immediately */
  209.                      break;
  210.                  }
  211.                  if (used_up || dist == -1)
  212.                      break;
  213.              }
  214.              if (flooreffects(singleobj, bhitpos.x, bhitpos.y, "fall")) {
  215.                  used_up = TRUE;
  216.                  launch_drop_spot((struct obj *) 0, 0, 0);
  217.                  break;
  218.              }
  219.              if (otyp == BOULDER
  220.                  && (otmp2 = sobj_at(BOULDER, bhitpos.x, bhitpos.y)) != 0) {
  221.                  const char *bmsg = " as one boulder sets another in motion";
  222.  
  223.                  if (!isok(bhitpos.x + dx, bhitpos.y + dy) || !dist
  224.                      || IS_ROCK(levl[bhitpos.x + dx][bhitpos.y + dy].typ))
  225.                      bmsg = " as one boulder hits another";
  226.  
  227.                  You_hear("a loud crash%s!",
  228.                           cansee(bhitpos.x, bhitpos.y) ? bmsg : "");
  229.                  obj_extract_self(otmp2);
  230.                  /* pass off the otrapped flag to the next boulder */
  231.                  otmp2->otrapped = singleobj->otrapped;
  232.                  singleobj->otrapped = 0;
  233.                  place_object(singleobj, bhitpos.x, bhitpos.y);
  234.                  singleobj = otmp2;
  235.                  otmp2 = (struct obj *) 0;
  236.                  wake_nearto(bhitpos.x, bhitpos.y, 10 * 10);
  237.              }
  238.          }
  239.          if (otyp == BOULDER && closed_door(bhitpos.x, bhitpos.y)) {
  240.              if (cansee(bhitpos.x, bhitpos.y))
  241.                  pline_The("boulder crashes through a door.");
  242.              levl[bhitpos.x][bhitpos.y].doormask = D_BROKEN;
  243.              if (dist)
  244.                  unblock_point(bhitpos.x, bhitpos.y);
  245.          }
  246.  
  247.          /* if about to hit iron bars, do so now */
  248.          if (dist > 0 && isok(bhitpos.x + dx, bhitpos.y + dy)
  249.              && levl[bhitpos.x + dx][bhitpos.y + dy].typ == IRONBARS) {
  250.              x2 = bhitpos.x, y2 = bhitpos.y; /* object stops here */
  251.              if (hits_bars(&singleobj, x2, y2, !rn2(20), 0)) {
  252.                  if (!singleobj) {
  253.                      used_up = TRUE;
  254.                      launch_drop_spot((struct obj *) 0, 0, 0);
  255.                  }
  256.                  break;
  257.              }
  258.          }
  259.      }
  260.      tmp_at(DISP_END, 0);
  261.      launch_drop_spot((struct obj *) 0, 0, 0);
  262.      if (!used_up) {
  263.          singleobj->otrapped = 0;
  264.          place_object(singleobj, x2, y2);
  265.          newsym(x2, y2);
  266.          return 1;
  267.      } else
  268.          return 2;
  269.  }
  270.  

seetrap

  1.  void
  2.  seetrap(trap)
  3.  struct trap *trap;
  4.  {
  5.      if (!trap->tseen) {
  6.          trap->tseen = 1;
  7.          newsym(trap->tx, trap->ty);
  8.      }
  9.  }
  10.  

feeltrap

  1.  /* like seetrap() but overrides vision */
  2.  void
  3.  feeltrap(trap)
  4.  struct trap *trap;
  5.  {
  6.      trap->tseen = 1;
  7.      map_trap(trap, 1);
  8.      /* in case it's beneath something, redisplay the something */
  9.      newsym(trap->tx, trap->ty);
  10.  }
  11.  

mkroll_launch

  1.  STATIC_OVL int
  2.  mkroll_launch(ttmp, x, y, otyp, ocount)
  3.  struct trap *ttmp;
  4.  xchar x, y;
  5.  short otyp;
  6.  long ocount;
  7.  {
  8.      struct obj *otmp;
  9.      register int tmp;
  10.      schar dx, dy;
  11.      int distance;
  12.      coord cc;
  13.      coord bcc;
  14.      int trycount = 0;
  15.      boolean success = FALSE;
  16.      int mindist = 4;
  17.  
  18.      if (ttmp->ttyp == ROLLING_BOULDER_TRAP)
  19.          mindist = 2;
  20.      distance = rn1(5, 4); /* 4..8 away */
  21.      tmp = rn2(8);         /* randomly pick a direction to try first */
  22.      while (distance >= mindist) {
  23.          dx = xdir[tmp];
  24.          dy = ydir[tmp];
  25.          cc.x = x;
  26.          cc.y = y;
  27.          /* Prevent boulder from being placed on water */
  28.          if (ttmp->ttyp == ROLLING_BOULDER_TRAP
  29.              && is_pool_or_lava(x + distance * dx, y + distance * dy))
  30.              success = FALSE;
  31.          else
  32.              success = isclearpath(&cc, distance, dx, dy);
  33.          if (ttmp->ttyp == ROLLING_BOULDER_TRAP) {
  34.              boolean success_otherway;
  35.  
  36.              bcc.x = x;
  37.              bcc.y = y;
  38.              success_otherway = isclearpath(&bcc, distance, -(dx), -(dy));
  39.              if (!success_otherway)
  40.                  success = FALSE;
  41.          }
  42.          if (success)
  43.              break;
  44.          if (++tmp > 7)
  45.              tmp = 0;
  46.          if ((++trycount % 8) == 0)
  47.              --distance;
  48.      }
  49.      if (!success) {
  50.          /* create the trap without any ammo, launch pt at trap location */
  51.          cc.x = bcc.x = x;
  52.          cc.y = bcc.y = y;
  53.      } else {
  54.          otmp = mksobj(otyp, TRUE, FALSE);
  55.          otmp->quan = ocount;
  56.          otmp->owt = weight(otmp);
  57.          place_object(otmp, cc.x, cc.y);
  58.          stackobj(otmp);
  59.      }
  60.      ttmp->launch.x = cc.x;
  61.      ttmp->launch.y = cc.y;
  62.      if (ttmp->ttyp == ROLLING_BOULDER_TRAP) {
  63.          ttmp->launch2.x = bcc.x;
  64.          ttmp->launch2.y = bcc.y;
  65.      } else
  66.          ttmp->launch_otyp = otyp;
  67.      newsym(ttmp->launch.x, ttmp->launch.y);
  68.      return 1;
  69.  }
  70.  

isclearpath

  1.  STATIC_OVL boolean
  2.  isclearpath(cc, distance, dx, dy)
  3.  coord *cc;
  4.  int distance;
  5.  schar dx, dy;
  6.  {
  7.      uchar typ;
  8.      xchar x, y;
  9.  
  10.      x = cc->x;
  11.      y = cc->y;
  12.      while (distance-- > 0) {
  13.          x += dx;
  14.          y += dy;
  15.          typ = levl[x][y].typ;
  16.          if (!isok(x, y) || !ZAP_POS(typ) || closed_door(x, y))
  17.              return FALSE;
  18.      }
  19.      cc->x = x;
  20.      cc->y = y;
  21.      return TRUE;
  22.  }
  23.  

mintrap

  1.  int
  2.  mintrap(mtmp)
  3.  register struct monst *mtmp;
  4.  {
  5.      register struct trap *trap = t_at(mtmp->mx, mtmp->my);
  6.      boolean trapkilled = FALSE;
  7.      struct permonst *mptr = mtmp->data;
  8.      struct obj *otmp;
  9.  
  10.      if (!trap) {
  11.          mtmp->mtrapped = 0;      /* perhaps teleported? */
  12.      } else if (mtmp->mtrapped) { /* is currently in the trap */
  13.          if (!trap->tseen && cansee(mtmp->mx, mtmp->my) && canseemon(mtmp)
  14.              && (trap->ttyp == SPIKED_PIT || trap->ttyp == BEAR_TRAP
  15.                  || trap->ttyp == HOLE || trap->ttyp == PIT
  16.                  || trap->ttyp == WEB)) {
  17.              /* If you come upon an obviously trapped monster, then
  18.               * you must be able to see the trap it's in too.
  19.               */
  20.              seetrap(trap);
  21.          }
  22.  
  23.          if (!rn2(40)) {
  24.              if (sobj_at(BOULDER, mtmp->mx, mtmp->my)
  25.                  && (trap->ttyp == PIT || trap->ttyp == SPIKED_PIT)) {
  26.                  if (!rn2(2)) {
  27.                      mtmp->mtrapped = 0;
  28.                      if (canseemon(mtmp))
  29.                          pline("%s pulls free...", Monnam(mtmp));
  30.                      fill_pit(mtmp->mx, mtmp->my);
  31.                  }
  32.              } else {
  33.                  mtmp->mtrapped = 0;
  34.              }
  35.          } else if (metallivorous(mptr)) {
  36.              if (trap->ttyp == BEAR_TRAP) {
  37.                  if (canseemon(mtmp))
  38.                      pline("%s eats a bear trap!", Monnam(mtmp));
  39.                  deltrap(trap);
  40.                  mtmp->meating = 5;
  41.                  mtmp->mtrapped = 0;
  42.              } else if (trap->ttyp == SPIKED_PIT) {
  43.                  if (canseemon(mtmp))
  44.                      pline("%s munches on some spikes!", Monnam(mtmp));
  45.                  trap->ttyp = PIT;
  46.                  mtmp->meating = 5;
  47.              }
  48.          }
  49.      } else {
  50.          register int tt = trap->ttyp;
  51.          boolean in_sight, tear_web, see_it,
  52.              inescapable = force_mintrap || ((tt == HOLE || tt == PIT)
  53.                                              && Sokoban && !trap->madeby_u);
  54.          const char *fallverb;
  55.  
  56.          /* true when called from dotrap, inescapable is not an option */
  57.          if (mtmp == u.usteed)
  58.              inescapable = TRUE;
  59.          if (!inescapable && ((mtmp->mtrapseen & (1 << (tt - 1))) != 0
  60.                               || (tt == HOLE && !mindless(mptr)))) {
  61.              /* it has been in such a trap - perhaps it escapes */
  62.              if (rn2(4))
  63.                  return 0;
  64.          } else {
  65.              mtmp->mtrapseen |= (1 << (tt - 1));
  66.          }
  67.          /* Monster is aggravated by being trapped by you.
  68.             Recognizing who made the trap isn't completely
  69.             unreasonable; everybody has their own style. */
  70.          if (trap->madeby_u && rnl(5))
  71.              setmangry(mtmp);
  72.  
  73.          in_sight = canseemon(mtmp);
  74.          see_it = cansee(mtmp->mx, mtmp->my);
  75.          /* assume hero can tell what's going on for the steed */
  76.          if (mtmp == u.usteed)
  77.              in_sight = TRUE;
  78.          switch (tt) {
  79.          case ARROW_TRAP:
  80.              if (trap->once && trap->tseen && !rn2(15)) {
  81.                  if (in_sight && see_it)
  82.                      pline("%s triggers a trap but nothing happens.",
  83.                            Monnam(mtmp));
  84.                  deltrap(trap);
  85.                  newsym(mtmp->mx, mtmp->my);
  86.                  break;
  87.              }
  88.              trap->once = 1;
  89.              otmp = mksobj(ARROW, TRUE, FALSE);
  90.              otmp->quan = 1L;
  91.              otmp->owt = weight(otmp);
  92.              otmp->opoisoned = 0;
  93.              if (in_sight)
  94.                  seetrap(trap);
  95.              if (thitm(8, mtmp, otmp, 0, FALSE))
  96.                  trapkilled = TRUE;
  97.              break;
  98.          case DART_TRAP:
  99.              if (trap->once && trap->tseen && !rn2(15)) {
  100.                  if (in_sight && see_it)
  101.                      pline("%s triggers a trap but nothing happens.",
  102.                            Monnam(mtmp));
  103.                  deltrap(trap);
  104.                  newsym(mtmp->mx, mtmp->my);
  105.                  break;
  106.              }
  107.              trap->once = 1;
  108.              otmp = mksobj(DART, TRUE, FALSE);
  109.              otmp->quan = 1L;
  110.              otmp->owt = weight(otmp);
  111.              if (!rn2(6))
  112.                  otmp->opoisoned = 1;
  113.              if (in_sight)
  114.                  seetrap(trap);
  115.              if (thitm(7, mtmp, otmp, 0, FALSE))
  116.                  trapkilled = TRUE;
  117.              break;
  118.          case ROCKTRAP:
  119.              if (trap->once && trap->tseen && !rn2(15)) {
  120.                  if (in_sight && see_it)
  121.                      pline(
  122.                          "A trap door above %s opens, but nothing falls out!",
  123.                          mon_nam(mtmp));
  124.                  deltrap(trap);
  125.                  newsym(mtmp->mx, mtmp->my);
  126.                  break;
  127.              }
  128.              trap->once = 1;
  129.              otmp = mksobj(ROCK, TRUE, FALSE);
  130.              otmp->quan = 1L;
  131.              otmp->owt = weight(otmp);
  132.              if (in_sight)
  133.                  seetrap(trap);
  134.              if (thitm(0, mtmp, otmp, d(2, 6), FALSE))
  135.                  trapkilled = TRUE;
  136.              break;
  137.          case SQKY_BOARD:
  138.              if (is_flyer(mptr))
  139.                  break;
  140.              /* stepped on a squeaky board */
  141.              if (in_sight) {
  142.                  if (!Deaf) {
  143.                      pline("A board beneath %s squeaks %s loudly.",
  144.                            mon_nam(mtmp), trapnote(trap, 0));
  145.                      seetrap(trap);
  146.                  } else {
  147.                      pline("%s stops momentarily and appears to cringe.",
  148.                            Monnam(mtmp));
  149.                  }
  150.              } else
  151.                  You_hear("a distant %s squeak.", trapnote(trap, 1));
  152.              /* wake up nearby monsters */
  153.              wake_nearto(mtmp->mx, mtmp->my, 40);
  154.              break;
  155.          case BEAR_TRAP:
  156.              if (mptr->msize > MZ_SMALL && !amorphous(mptr) && !is_flyer(mptr)
  157.                  && !is_whirly(mptr) && !unsolid(mptr)) {
  158.                  mtmp->mtrapped = 1;
  159.                  if (in_sight) {
  160.                      pline("%s is caught in %s bear trap!", Monnam(mtmp),
  161.                            a_your[trap->madeby_u]);
  162.                      seetrap(trap);
  163.                  } else {
  164.                      if (mptr == &mons[PM_OWLBEAR]
  165.                          || mptr == &mons[PM_BUGBEAR])
  166.                          You_hear("the roaring of an angry bear!");
  167.                  }
  168.              } else if (force_mintrap) {
  169.                  if (in_sight) {
  170.                      pline("%s evades %s bear trap!", Monnam(mtmp),
  171.                            a_your[trap->madeby_u]);
  172.                      seetrap(trap);
  173.                  }
  174.              }
  175.              if (mtmp->mtrapped)
  176.                  trapkilled = thitm(0, mtmp, (struct obj *) 0, d(2, 4), FALSE);
  177.              break;
  178.          case SLP_GAS_TRAP:
  179.              if (!resists_sleep(mtmp) && !breathless(mptr) && !mtmp->msleeping
  180.                  && mtmp->mcanmove) {
  181.                  if (sleep_monst(mtmp, rnd(25), -1) && in_sight) {
  182.                      pline("%s suddenly falls asleep!", Monnam(mtmp));
  183.                      seetrap(trap);
  184.                  }
  185.              }
  186.              break;
  187.          case RUST_TRAP: {
  188.              struct obj *target;
  189.  
  190.              if (in_sight)
  191.                  seetrap(trap);
  192.              switch (rn2(5)) {
  193.              case 0:
  194.                  if (in_sight)
  195.                      pline("%s %s on the %s!", A_gush_of_water_hits,
  196.                            mon_nam(mtmp), mbodypart(mtmp, HEAD));
  197.                  target = which_armor(mtmp, W_ARMH);
  198.                  (void) water_damage(target, helm_simple_name(target), TRUE);
  199.                  break;
  200.              case 1:
  201.                  if (in_sight)
  202.                      pline("%s %s's left %s!", A_gush_of_water_hits,
  203.                            mon_nam(mtmp), mbodypart(mtmp, ARM));
  204.                  target = which_armor(mtmp, W_ARMS);
  205.                  if (water_damage(target, "shield", TRUE) != ER_NOTHING)
  206.                      break;
  207.                  target = MON_WEP(mtmp);
  208.                  if (target && bimanual(target))
  209.                      (void) water_damage(target, 0, TRUE);
  210.              glovecheck:
  211.                  target = which_armor(mtmp, W_ARMG);
  212.                  (void) water_damage(target, "gauntlets", TRUE);
  213.                  break;
  214.              case 2:
  215.                  if (in_sight)
  216.                      pline("%s %s's right %s!", A_gush_of_water_hits,
  217.                            mon_nam(mtmp), mbodypart(mtmp, ARM));
  218.                  (void) water_damage(MON_WEP(mtmp), 0, TRUE);
  219.                  goto glovecheck;
  220.              default:
  221.                  if (in_sight)
  222.                      pline("%s %s!", A_gush_of_water_hits, mon_nam(mtmp));
  223.                  for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj)
  224.                      if (otmp->lamplit
  225.                          && (otmp->owornmask & (W_WEP | W_SWAPWEP)) == 0)
  226.                          (void) snuff_lit(otmp);
  227.                  if ((target = which_armor(mtmp, W_ARMC)) != 0)
  228.                      (void) water_damage(target, cloak_simple_name(target),
  229.                                          TRUE);
  230.                  else if ((target = which_armor(mtmp, W_ARM)) != 0)
  231.                      (void) water_damage(target, "armor", TRUE);
  232.                  else if ((target = which_armor(mtmp, W_ARMU)) != 0)
  233.                      (void) water_damage(target, "shirt", TRUE);
  234.              }
  235.  
  236.              if (mptr == &mons[PM_IRON_GOLEM]) {
  237.                  if (in_sight)
  238.                      pline("%s falls to pieces!", Monnam(mtmp));
  239.                  else if (mtmp->mtame)
  240.                      pline("May %s rust in peace.", mon_nam(mtmp));
  241.                  mondied(mtmp);
  242.                  if (mtmp->mhp <= 0)
  243.                      trapkilled = TRUE;
  244.              } else if (mptr == &mons[PM_GREMLIN] && rn2(3)) {
  245.                  (void) split_mon(mtmp, (struct monst *) 0);
  246.              }
  247.              break;
  248.          } /* RUST_TRAP */
  249.          case FIRE_TRAP:
  250.          mfiretrap:
  251.              if (in_sight)
  252.                  pline("A %s erupts from the %s under %s!", tower_of_flame,
  253.                        surface(mtmp->mx, mtmp->my), mon_nam(mtmp));
  254.              else if (see_it) /* evidently `mtmp' is invisible */
  255.                  You_see("a %s erupt from the %s!", tower_of_flame,
  256.                          surface(mtmp->mx, mtmp->my));
  257.  
  258.              if (resists_fire(mtmp)) {
  259.                  if (in_sight) {
  260.                      shieldeff(mtmp->mx, mtmp->my);
  261.                      pline("%s is uninjured.", Monnam(mtmp));
  262.                  }
  263.              } else {
  264.                  int num = d(2, 4), alt;
  265.                  boolean immolate = FALSE;
  266.  
  267.                  /* paper burns very fast, assume straw is tightly
  268.                   * packed and burns a bit slower */
  269.                  switch (monsndx(mptr)) {
  270.                  case PM_PAPER_GOLEM:
  271.                      immolate = TRUE;
  272.                      alt = mtmp->mhpmax;
  273.                      break;
  274.                  case PM_STRAW_GOLEM:
  275.                      alt = mtmp->mhpmax / 2;
  276.                      break;
  277.                  case PM_WOOD_GOLEM:
  278.                      alt = mtmp->mhpmax / 4;
  279.                      break;
  280.                  case PM_LEATHER_GOLEM:
  281.                      alt = mtmp->mhpmax / 8;
  282.                      break;
  283.                  default:
  284.                      alt = 0;
  285.                      break;
  286.                  }
  287.                  if (alt > num)
  288.                      num = alt;
  289.  
  290.                  if (thitm(0, mtmp, (struct obj *) 0, num, immolate))
  291.                      trapkilled = TRUE;
  292.                  else
  293.                      /* we know mhp is at least `num' below mhpmax,
  294.                         so no (mhp > mhpmax) check is needed here */
  295.                      mtmp->mhpmax -= rn2(num + 1);
  296.              }
  297.              if (burnarmor(mtmp) || rn2(3)) {
  298.                  (void) destroy_mitem(mtmp, SCROLL_CLASS, AD_FIRE);
  299.                  (void) destroy_mitem(mtmp, SPBOOK_CLASS, AD_FIRE);
  300.                  (void) destroy_mitem(mtmp, POTION_CLASS, AD_FIRE);
  301.              }
  302.              if (burn_floor_objects(mtmp->mx, mtmp->my, see_it, FALSE)
  303.                  && !see_it && distu(mtmp->mx, mtmp->my) <= 3 * 3)
  304.                  You("smell smoke.");
  305.              if (is_ice(mtmp->mx, mtmp->my))
  306.                  melt_ice(mtmp->mx, mtmp->my, (char *) 0);
  307.              if (see_it)
  308.                  seetrap(trap);
  309.              break;
  310.          case PIT:
  311.          case SPIKED_PIT:
  312.              fallverb = "falls";
  313.              if (is_flyer(mptr) || is_floater(mptr)
  314.                  || (mtmp->wormno && count_wsegs(mtmp) > 5)
  315.                  || is_clinger(mptr)) {
  316.                  if (force_mintrap && !Sokoban) {
  317.                      /* openfallingtrap; not inescapable here */
  318.                      if (in_sight) {
  319.                          seetrap(trap);
  320.                          pline("%s doesn't fall into the pit.", Monnam(mtmp));
  321.                      }
  322.                      break; /* inescapable = FALSE; */
  323.                  }
  324.                  if (!inescapable)
  325.                      break;               /* avoids trap */
  326.                  fallverb = "is dragged"; /* sokoban pit */
  327.              }
  328.              if (!passes_walls(mptr))
  329.                  mtmp->mtrapped = 1;
  330.              if (in_sight) {
  331.                  pline("%s %s into %s pit!", Monnam(mtmp), fallverb,
  332.                        a_your[trap->madeby_u]);
  333.                  if (mptr == &mons[PM_PIT_VIPER]
  334.                      || mptr == &mons[PM_PIT_FIEND])
  335.                      pline("How pitiful.  Isn't that the pits?");
  336.                  seetrap(trap);
  337.              }
  338.              mselftouch(mtmp, "Falling, ", FALSE);
  339.              if (mtmp->mhp <= 0 || thitm(0, mtmp, (struct obj *) 0,
  340.                                          rnd((tt == PIT) ? 6 : 10), FALSE))
  341.                  trapkilled = TRUE;
  342.              break;
  343.          case HOLE:
  344.          case TRAPDOOR:
  345.              if (!Can_fall_thru(&u.uz)) {
  346.                  impossible("mintrap: %ss cannot exist on this level.",
  347.                             defsyms[trap_to_defsym(tt)].explanation);
  348.                  break; /* don't activate it after all */
  349.              }
  350.              if (is_flyer(mptr) || is_floater(mptr) || mptr == &mons[PM_WUMPUS]
  351.                  || (mtmp->wormno && count_wsegs(mtmp) > 5)
  352.                  || mptr->msize >= MZ_HUGE) {
  353.                  if (force_mintrap && !Sokoban) {
  354.                      /* openfallingtrap; not inescapable here */
  355.                      if (in_sight) {
  356.                          seetrap(trap);
  357.                          if (tt == TRAPDOOR)
  358.                              pline(
  359.                              "A trap door opens, but %s doesn't fall through.",
  360.                                    mon_nam(mtmp));
  361.                          else /* (tt == HOLE) */
  362.                              pline("%s doesn't fall through the hole.",
  363.                                    Monnam(mtmp));
  364.                      }
  365.                      break; /* inescapable = FALSE; */
  366.                  }
  367.                  if (inescapable) { /* sokoban hole */
  368.                      if (in_sight) {
  369.                          pline("%s seems to be yanked down!", Monnam(mtmp));
  370.                          /* suppress message in mlevel_tele_trap() */
  371.                          in_sight = FALSE;
  372.                          seetrap(trap);
  373.                      }
  374.                  } else
  375.                      break;
  376.              }
  377.              /*FALLTHRU*/
  378.          case LEVEL_TELEP:
  379.          case MAGIC_PORTAL: {
  380.              int mlev_res;
  381.  
  382.              mlev_res = mlevel_tele_trap(mtmp, trap, inescapable, in_sight);
  383.              if (mlev_res)
  384.                  return mlev_res;
  385.              break;
  386.          }
  387.          case TELEP_TRAP:
  388.              mtele_trap(mtmp, trap, in_sight);
  389.              break;
  390.          case WEB:
  391.              /* Monster in a web. */
  392.              if (webmaker(mptr))
  393.                  break;
  394.              if (amorphous(mptr) || is_whirly(mptr) || unsolid(mptr)) {
  395.                  if (acidic(mptr) || mptr == &mons[PM_GELATINOUS_CUBE]
  396.                      || mptr == &mons[PM_FIRE_ELEMENTAL]) {
  397.                      if (in_sight)
  398.                          pline("%s %s %s spider web!", Monnam(mtmp),
  399.                                (mptr == &mons[PM_FIRE_ELEMENTAL])
  400.                                    ? "burns"
  401.                                    : "dissolves",
  402.                                a_your[trap->madeby_u]);
  403.                      deltrap(trap);
  404.                      newsym(mtmp->mx, mtmp->my);
  405.                      break;
  406.                  }
  407.                  if (in_sight) {
  408.                      pline("%s flows through %s spider web.", Monnam(mtmp),
  409.                            a_your[trap->madeby_u]);
  410.                      seetrap(trap);
  411.                  }
  412.                  break;
  413.              }
  414.              tear_web = FALSE;
  415.              switch (monsndx(mptr)) {
  416.              case PM_OWLBEAR: /* Eric Backus */
  417.              case PM_BUGBEAR:
  418.                  if (!in_sight) {
  419.                      You_hear("the roaring of a confused bear!");
  420.                      mtmp->mtrapped = 1;
  421.                      break;
  422.                  }
  423.              /* fall though */
  424.              default:
  425.                  if (mptr->mlet == S_GIANT
  426.                      /* exclude baby dragons and relatively short worms */
  427.                      || (mptr->mlet == S_DRAGON && extra_nasty(mptr))
  428.                      || (mtmp->wormno && count_wsegs(mtmp) > 5)) {
  429.                      tear_web = TRUE;
  430.                  } else if (in_sight) {
  431.                      pline("%s is caught in %s spider web.", Monnam(mtmp),
  432.                            a_your[trap->madeby_u]);
  433.                      seetrap(trap);
  434.                  }
  435.                  mtmp->mtrapped = tear_web ? 0 : 1;
  436.                  break;
  437.              /* this list is fairly arbitrary; it deliberately
  438.                 excludes wumpus & giant/ettin zombies/mummies */
  439.              case PM_TITANOTHERE:
  440.              case PM_BALUCHITHERIUM:
  441.              case PM_PURPLE_WORM:
  442.              case PM_JABBERWOCK:
  443.              case PM_IRON_GOLEM:
  444.              case PM_BALROG:
  445.              case PM_KRAKEN:
  446.              case PM_MASTODON:
  447.              case PM_ORION:
  448.              case PM_NORN:
  449.              case PM_CYCLOPS:
  450.              case PM_LORD_SURTUR:
  451.                  tear_web = TRUE;
  452.                  break;
  453.              }
  454.              if (tear_web) {
  455.                  if (in_sight)
  456.                      pline("%s tears through %s spider web!", Monnam(mtmp),
  457.                            a_your[trap->madeby_u]);
  458.                  deltrap(trap);
  459.                  newsym(mtmp->mx, mtmp->my);
  460.              } else if (force_mintrap && !mtmp->mtrapped) {
  461.                  if (in_sight) {
  462.                      pline("%s avoids %s spider web!", Monnam(mtmp),
  463.                            a_your[trap->madeby_u]);
  464.                      seetrap(trap);
  465.                  }
  466.              }
  467.              break;
  468.          case STATUE_TRAP:
  469.              break;
  470.          case MAGIC_TRAP:
  471.              /* A magic trap.  Monsters usually immune. */
  472.              if (!rn2(21))
  473.                  goto mfiretrap;
  474.              break;
  475.          case ANTI_MAGIC:
  476.              /* similar to hero's case, more or less */
  477.              if (!resists_magm(mtmp)) { /* lose spell energy */
  478.                  if (!mtmp->mcan && (attacktype(mptr, AT_MAGC)
  479.                                      || attacktype(mptr, AT_BREA))) {
  480.                      mtmp->mspec_used += d(2, 2);
  481.                      if (in_sight) {
  482.                          seetrap(trap);
  483.                          pline("%s seems lethargic.", Monnam(mtmp));
  484.                      }
  485.                  }
  486.              } else { /* take some damage */
  487.                  int dmgval2 = rnd(4);
  488.  
  489.                  if ((otmp = MON_WEP(mtmp)) != 0
  490.                      && otmp->oartifact == ART_MAGICBANE)
  491.                      dmgval2 += rnd(4);
  492.                  for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj)
  493.                      if (otmp->oartifact
  494.                          && defends_when_carried(AD_MAGM, otmp))
  495.                          break;
  496.                  if (otmp)
  497.                      dmgval2 += rnd(4);
  498.                  if (passes_walls(mptr))
  499.                      dmgval2 = (dmgval2 + 3) / 4;
  500.  
  501.                  if (in_sight)
  502.                      seetrap(trap);
  503.                  if ((mtmp->mhp -= dmgval2) <= 0)
  504.                      monkilled(mtmp,
  505.                                in_sight
  506.                                    ? "compression from an anti-magic field"
  507.                                    : (const char *) 0,
  508.                                -AD_MAGM);
  509.                  if (mtmp->mhp <= 0)
  510.                      trapkilled = TRUE;
  511.                  if (see_it)
  512.                      newsym(trap->tx, trap->ty);
  513.              }
  514.              break;
  515.          case LANDMINE:
  516.              if (rn2(3))
  517.                  break; /* monsters usually don't set it off */
  518.              if (is_flyer(mptr)) {
  519.                  boolean already_seen = trap->tseen;
  520.  
  521.                  if (in_sight && !already_seen) {
  522.                      pline("A trigger appears in a pile of soil below %s.",
  523.                            mon_nam(mtmp));
  524.                      seetrap(trap);
  525.                  }
  526.                  if (rn2(3))
  527.                      break;
  528.                  if (in_sight) {
  529.                      newsym(mtmp->mx, mtmp->my);
  530.                      pline_The("air currents set %s off!",
  531.                                already_seen ? "a land mine" : "it");
  532.                  }
  533.              } else if (in_sight) {
  534.                  newsym(mtmp->mx, mtmp->my);
  535.                  pline("KAABLAMM!!!  %s triggers %s land mine!", Monnam(mtmp),
  536.                        a_your[trap->madeby_u]);
  537.              }
  538.              if (!in_sight)
  539.                  pline("Kaablamm!  You hear an explosion in the distance!");
  540.              blow_up_landmine(trap);
  541.              /* explosion might have destroyed a drawbridge; don't
  542.                 dish out more damage if monster is already dead */
  543.              if (mtmp->mhp <= 0
  544.                  || thitm(0, mtmp, (struct obj *) 0, rnd(16), FALSE))
  545.                  trapkilled = TRUE;
  546.              else {
  547.                  /* monsters recursively fall into new pit */
  548.                  if (mintrap(mtmp) == 2)
  549.                      trapkilled = TRUE;
  550.              }
  551.              /* a boulder may fill the new pit, crushing monster */
  552.              fill_pit(trap->tx, trap->ty);
  553.              if (mtmp->mhp <= 0)
  554.                  trapkilled = TRUE;
  555.              if (unconscious()) {
  556.                  multi = -1;
  557.                  nomovemsg = "The explosion awakens you!";
  558.              }
  559.              break;
  560.          case POLY_TRAP:
  561.              if (resists_magm(mtmp)) {
  562.                  shieldeff(mtmp->mx, mtmp->my);
  563.              } else if (!resist(mtmp, WAND_CLASS, 0, NOTELL)) {
  564.                  if (newcham(mtmp, (struct permonst *) 0, FALSE, FALSE))
  565.                      /* we're done with mptr but keep it up to date */
  566.                      mptr = mtmp->data;
  567.                  if (in_sight)
  568.                      seetrap(trap);
  569.              }
  570.              break;
  571.          case ROLLING_BOULDER_TRAP:
  572.              if (!is_flyer(mptr)) {
  573.                  int style = ROLL | (in_sight ? 0 : LAUNCH_UNSEEN);
  574.  
  575.                  newsym(mtmp->mx, mtmp->my);
  576.                  if (in_sight)
  577.                      pline("Click! %s triggers %s.", Monnam(mtmp),
  578.                            trap->tseen ? "a rolling boulder trap" : something);
  579.                  if (launch_obj(BOULDER, trap->launch.x, trap->launch.y,
  580.                                 trap->launch2.x, trap->launch2.y, style)) {
  581.                      if (in_sight)
  582.                          trap->tseen = TRUE;
  583.                      if (mtmp->mhp <= 0)
  584.                          trapkilled = TRUE;
  585.                  } else {
  586.                      deltrap(trap);
  587.                      newsym(mtmp->mx, mtmp->my);
  588.                  }
  589.              }
  590.              break;
  591.          case VIBRATING_SQUARE:
  592.              if (see_it && !Blind) {
  593.                  if (in_sight)
  594.                      pline("You see a strange vibration beneath %s %s.",
  595.                            s_suffix(mon_nam(mtmp)),
  596.                            makeplural(mbodypart(mtmp, FOOT)));
  597.                  else
  598.                      pline("You see the ground vibrate in the distance.");
  599.                  seetrap(trap);
  600.              }
  601.              break;
  602.          default:
  603.              impossible("Some monster encountered a strange trap of type %d.",
  604.                         tt);
  605.          }
  606.      }
  607.      if (trapkilled)
  608.          return 2;
  609.      return mtmp->mtrapped;
  610.  }
  611.  

instapetrify

  1.  /* Combine cockatrice checks into single functions to avoid repeating code. */
  2.  void
  3.  instapetrify(str)
  4.  const char *str;
  5.  {
  6.      if (Stone_resistance)
  7.          return;
  8.      if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM))
  9.          return;
  10.      You("turn to stone...");
  11.      killer.format = KILLED_BY;
  12.      if (str != killer.name)
  13.          Strcpy(killer.name, str ? str : "");
  14.      done(STONING);
  15.  }
  16.  

minstapetrify

  1.  void
  2.  minstapetrify(mon, byplayer)
  3.  struct monst *mon;
  4.  boolean byplayer;
  5.  {
  6.      if (resists_ston(mon))
  7.          return;
  8.      if (poly_when_stoned(mon->data)) {
  9.          mon_to_stone(mon);
  10.          return;
  11.      }
  12.  
  13.      /* give a "<mon> is slowing down" message and also remove
  14.         intrinsic speed (comparable to similar effect on the hero) */
  15.      mon_adjust_speed(mon, -3, (struct obj *) 0);
  16.  
  17.      if (cansee(mon->mx, mon->my))
  18.          pline("%s turns to stone.", Monnam(mon));
  19.      if (byplayer) {
  20.          stoned = TRUE;
  21.          xkilled(mon, 0);
  22.      } else
  23.          monstone(mon);
  24.  }
  25.  

selftouch

  1.  void
  2.  selftouch(arg)
  3.  const char *arg;
  4.  {
  5.      char kbuf[BUFSZ];
  6.  
  7.      if (uwep && uwep->otyp == CORPSE && touch_petrifies(&mons[uwep->corpsenm])
  8.          && !Stone_resistance) {
  9.          pline("%s touch the %s corpse.", arg, mons[uwep->corpsenm].mname);
  10.          Sprintf(kbuf, "%s corpse", an(mons[uwep->corpsenm].mname));
  11.          instapetrify(kbuf);
  12.          /* life-saved; unwield the corpse if we can't handle it */
  13.          if (!uarmg && !Stone_resistance)
  14.              uwepgone();
  15.      }
  16.      /* Or your secondary weapon, if wielded [hypothetical; we don't
  17.         allow two-weapon combat when either weapon is a corpse] */
  18.      if (u.twoweap && uswapwep && uswapwep->otyp == CORPSE
  19.          && touch_petrifies(&mons[uswapwep->corpsenm]) && !Stone_resistance) {
  20.          pline("%s touch the %s corpse.", arg, mons[uswapwep->corpsenm].mname);
  21.          Sprintf(kbuf, "%s corpse", an(mons[uswapwep->corpsenm].mname));
  22.          instapetrify(kbuf);
  23.          /* life-saved; unwield the corpse */
  24.          if (!uarmg && !Stone_resistance)
  25.              uswapwepgone();
  26.      }
  27.  }
  28.  

mselftouch

  1.  void
  2.  mselftouch(mon, arg, byplayer)
  3.  struct monst *mon;
  4.  const char *arg;
  5.  boolean byplayer;
  6.  {
  7.      struct obj *mwep = MON_WEP(mon);
  8.  
  9.      if (mwep && mwep->otyp == CORPSE && touch_petrifies(&mons[mwep->corpsenm])
  10.          && !resists_ston(mon)) {
  11.          if (cansee(mon->mx, mon->my)) {
  12.              pline("%s%s touches %s.", arg ? arg : "",
  13.                    arg ? mon_nam(mon) : Monnam(mon),
  14.                    corpse_xname(mwep, (const char *) 0, CXN_PFX_THE));
  15.          }
  16.          minstapetrify(mon, byplayer);
  17.          /* if life-saved, might not be able to continue wielding */
  18.          if (mon->mhp > 0 && !which_armor(mon, W_ARMG) && !resists_ston(mon))
  19.              mwepgone(mon);
  20.      }
  21.  }
  22.  

float_up

  1.  /* start levitating */
  2.  void
  3.  float_up()
  4.  {
  5.      if (u.utrap) {
  6.          if (u.utraptype == TT_PIT) {
  7.              u.utrap = 0;
  8.              You("float up, out of the pit!");
  9.              vision_full_recalc = 1; /* vision limits change */
  10.              fill_pit(u.ux, u.uy);
  11.          } else if (u.utraptype == TT_INFLOOR) {
  12.              Your("body pulls upward, but your %s are still stuck.",
  13.                   makeplural(body_part(LEG)));
  14.          } else {
  15.              You("float up, only your %s is still stuck.", body_part(LEG));
  16.          }
  17.  #if 0
  18.      } else if (Is_waterlevel(&u.uz)) {
  19.          pline("It feels as though you've lost some weight.");
  20.  #endif
  21.      } else if (u.uinwater) {
  22.          spoteffects(TRUE);
  23.      } else if (u.uswallow) {
  24.          You(is_animal(u.ustuck->data) ? "float away from the %s."
  25.                                        : "spiral up into %s.",
  26.              is_animal(u.ustuck->data) ? surface(u.ux, u.uy)
  27.                                        : mon_nam(u.ustuck));
  28.      } else if (Hallucination) {
  29.          pline("Up, up, and awaaaay!  You're walking on air!");
  30.      } else if (Is_airlevel(&u.uz)) {
  31.          You("gain control over your movements.");
  32.      } else {
  33.          You("start to float in the air!");
  34.      }
  35.      if (u.usteed && !is_floater(u.usteed->data)
  36.          && !is_flyer(u.usteed->data)) {
  37.          if (Lev_at_will) {
  38.              pline("%s magically floats up!", Monnam(u.usteed));
  39.          } else {
  40.              You("cannot stay on %s.", mon_nam(u.usteed));
  41.              dismount_steed(DISMOUNT_GENERIC);
  42.          }
  43.      }
  44.      if (Flying)
  45.          You("are no longer able to control your flight.");
  46.      BFlying |= I_SPECIAL;
  47.      return;
  48.  }
  49.  

fill_pit

  1.  void
  2.  fill_pit(x, y)
  3.  int x, y;
  4.  {
  5.      struct obj *otmp;
  6.      struct trap *t;
  7.  
  8.      if ((t = t_at(x, y)) && ((t->ttyp == PIT) || (t->ttyp == SPIKED_PIT))
  9.          && (otmp = sobj_at(BOULDER, x, y))) {
  10.          obj_extract_self(otmp);
  11.          (void) flooreffects(otmp, x, y, "settle");
  12.      }
  13.  }
  14.  

flat_down

  1.  /* stop levitating */
  2.  int
  3.  float_down(hmask, emask)
  4.  long hmask, emask; /* might cancel timeout */
  5.  {
  6.      register struct trap *trap = (struct trap *) 0;
  7.      d_level current_dungeon_level;
  8.      boolean no_msg = FALSE;
  9.  
  10.      HLevitation &= ~hmask;
  11.      ELevitation &= ~emask;
  12.      if (Levitation)
  13.          return 0; /* maybe another ring/potion/boots */
  14.      if (BLevitation) {
  15.          /* Levitation is blocked, so hero is not actually floating
  16.             hence shouldn't have float_down effects and feedback */
  17.          float_vs_flight(); /* before nomul() rather than after */
  18.          return 0;
  19.      }
  20.      nomul(0); /* stop running or resting */
  21.      if (BFlying) {
  22.          /* controlled flight no longer overridden by levitation */
  23.          BFlying &= ~I_SPECIAL;
  24.          if (Flying) {
  25.              You("have stopped levitating and are now flying.");
  26.              return 1;
  27.          }
  28.      }
  29.      if (u.uswallow) {
  30.          You("float down, but you are still %s.",
  31.              is_animal(u.ustuck->data) ? "swallowed" : "engulfed");
  32.          return 1;
  33.      }
  34.  
  35.      if (Punished && !carried(uball)
  36.          && (is_pool(uball->ox, uball->oy)
  37.              || ((trap = t_at(uball->ox, uball->oy))
  38.                  && ((trap->ttyp == PIT) || (trap->ttyp == SPIKED_PIT)
  39.                      || (trap->ttyp == TRAPDOOR) || (trap->ttyp == HOLE))))) {
  40.          u.ux0 = u.ux;
  41.          u.uy0 = u.uy;
  42.          u.ux = uball->ox;
  43.          u.uy = uball->oy;
  44.          movobj(uchain, uball->ox, uball->oy);
  45.          newsym(u.ux0, u.uy0);
  46.          vision_full_recalc = 1; /* in case the hero moved. */
  47.      }
  48.      /* check for falling into pool - added by GAN 10/20/86 */
  49.      if (!Flying) {
  50.          if (!u.uswallow && u.ustuck) {
  51.              if (sticks(youmonst.data))
  52.                  You("aren't able to maintain your hold on %s.",
  53.                      mon_nam(u.ustuck));
  54.              else
  55.                  pline("Startled, %s can no longer hold you!",
  56.                        mon_nam(u.ustuck));
  57.              u.ustuck = 0;
  58.          }
  59.          /* kludge alert:
  60.           * drown() and lava_effects() print various messages almost
  61.           * every time they're called which conflict with the "fall
  62.           * into" message below.  Thus, we want to avoid printing
  63.           * confusing, duplicate or out-of-order messages.
  64.           * Use knowledge of the two routines as a hack -- this
  65.           * should really be handled differently -dlc
  66.           */
  67.          if (is_pool(u.ux, u.uy) && !Wwalking && !Swimming && !u.uinwater)
  68.              no_msg = drown();
  69.  
  70.          if (is_lava(u.ux, u.uy)) {
  71.              (void) lava_effects();
  72.              no_msg = TRUE;
  73.          }
  74.      }
  75.      if (!trap) {
  76.          trap = t_at(u.ux, u.uy);
  77.          if (Is_airlevel(&u.uz)) {
  78.              You("begin to tumble in place.");
  79.          } else if (Is_waterlevel(&u.uz) && !no_msg) {
  80.              You_feel("heavier.");
  81.          /* u.uinwater msgs already in spoteffects()/drown() */
  82.          } else if (!u.uinwater && !no_msg) {
  83.              if (!(emask & W_SADDLE)) {
  84.                  if (Sokoban && trap) {
  85.                      /* Justification elsewhere for Sokoban traps is based
  86.                       * on air currents.  This is consistent with that.
  87.                       * The unexpected additional force of the air currents
  88.                       * once levitation ceases knocks you off your feet.
  89.                       */
  90.                      if (Hallucination)
  91.                          pline("Bummer!  You've crashed.");
  92.                      else
  93.                          You("fall over.");
  94.                      losehp(rnd(2), "dangerous winds", KILLED_BY);
  95.                      if (u.usteed)
  96.                          dismount_steed(DISMOUNT_FELL);
  97.                      selftouch("As you fall, you");
  98.                  } else if (u.usteed && (is_floater(u.usteed->data)
  99.                                          || is_flyer(u.usteed->data))) {
  100.                      You("settle more firmly in the saddle.");
  101.                  } else if (Hallucination) {
  102.                      pline("Bummer!  You've %s.",
  103.                            is_pool(u.ux, u.uy)
  104.                               ? "splashed down"
  105.                               : "hit the ground");
  106.                  } else {
  107.                      You("float gently to the %s.", surface(u.ux, u.uy));
  108.                  }
  109.              }
  110.          }
  111.      }
  112.  
  113.      /* can't rely on u.uz0 for detecting trap door-induced level change;
  114.         it gets changed to reflect the new level before we can check it */
  115.      assign_level(&current_dungeon_level, &u.uz);
  116.      if (trap) {
  117.          switch (trap->ttyp) {
  118.          case STATUE_TRAP:
  119.              break;
  120.          case HOLE:
  121.          case TRAPDOOR:
  122.              if (!Can_fall_thru(&u.uz) || u.ustuck)
  123.                  break;
  124.              /*FALLTHRU*/
  125.          default:
  126.              if (!u.utrap) /* not already in the trap */
  127.                  dotrap(trap, 0);
  128.          }
  129.      }
  130.      if (!Is_airlevel(&u.uz) && !Is_waterlevel(&u.uz) && !u.uswallow
  131.          /* falling through trap door calls goto_level,
  132.             and goto_level does its own pickup() call */
  133.          && on_level(&u.uz, &current_dungeon_level))
  134.          (void) pickup(1);
  135.      return 1;
  136.  }
  137.  

climb_pit

  1.  /* shared code for climbing out of a pit */
  2.  void
  3.  climb_pit()
  4.  {
  5.      if (!u.utrap || u.utraptype != TT_PIT)
  6.          return;
  7.  
  8.      if (Passes_walls) {
  9.          /* marked as trapped so they can pick things up */
  10.          You("ascend from the pit.");
  11.          u.utrap = 0;
  12.          fill_pit(u.ux, u.uy);
  13.          vision_full_recalc = 1; /* vision limits change */
  14.      } else if (!rn2(2) && sobj_at(BOULDER, u.ux, u.uy)) {
  15.          Your("%s gets stuck in a crevice.", body_part(LEG));
  16.          display_nhwindow(WIN_MESSAGE, FALSE);
  17.          clear_nhwindow(WIN_MESSAGE);
  18.          You("free your %s.", body_part(LEG));
  19.      } else if ((Flying || is_clinger(youmonst.data)) && !Sokoban) {
  20.          /* eg fell in pit, then poly'd to a flying monster;
  21.             or used '>' to deliberately enter it */
  22.          You("%s from the pit.", Flying ? "fly" : "climb");
  23.          u.utrap = 0;
  24.          fill_pit(u.ux, u.uy);
  25.          vision_full_recalc = 1; /* vision limits change */
  26.      } else if (!(--u.utrap)) {
  27.          You("%s to the edge of the pit.",
  28.              (Sokoban && Levitation)
  29.                  ? "struggle against the air currents and float"
  30.                  : u.usteed ? "ride" : "crawl");
  31.          fill_pit(u.ux, u.uy);
  32.          vision_full_recalc = 1; /* vision limits change */
  33.      } else if (u.dz || flags.verbose) {
  34.          if (u.usteed)
  35.              Norep("%s is still in a pit.", upstart(y_monnam(u.usteed)));
  36.          else
  37.              Norep((Hallucination && !rn2(5))
  38.                        ? "You've fallen, and you can't get up."
  39.                        : "You are still in a pit.");
  40.      }
  41.  }
  42.  

dofiretrap

  1.  STATIC_OVL void
  2.  dofiretrap(box)
  3.  struct obj *box; /* null for floor trap */
  4.  {
  5.      boolean see_it = !Blind;
  6.      int num, alt;
  7.  
  8.      /* Bug: for box case, the equivalent of burn_floor_objects() ought
  9.       * to be done upon its contents.
  10.       */
  11.  
  12.      if ((box && !carried(box)) ? is_pool(box->ox, box->oy) : Underwater) {
  13.          pline("A cascade of steamy bubbles erupts from %s!",
  14.                the(box ? xname(box) : surface(u.ux, u.uy)));
  15.          if (Fire_resistance)
  16.              You("are uninjured.");
  17.          else
  18.              losehp(rnd(3), "boiling water", KILLED_BY);
  19.          return;
  20.      }
  21.      pline("A %s %s from %s!", tower_of_flame, box ? "bursts" : "erupts",
  22.            the(box ? xname(box) : surface(u.ux, u.uy)));
  23.      if (Fire_resistance) {
  24.          shieldeff(u.ux, u.uy);
  25.          num = rn2(2);
  26.      } else if (Upolyd) {
  27.          num = d(2, 4);
  28.          switch (u.umonnum) {
  29.          case PM_PAPER_GOLEM:
  30.              alt = u.mhmax;
  31.              break;
  32.          case PM_STRAW_GOLEM:
  33.              alt = u.mhmax / 2;
  34.              break;
  35.          case PM_WOOD_GOLEM:
  36.              alt = u.mhmax / 4;
  37.              break;
  38.          case PM_LEATHER_GOLEM:
  39.              alt = u.mhmax / 8;
  40.              break;
  41.          default:
  42.              alt = 0;
  43.              break;
  44.          }
  45.          if (alt > num)
  46.              num = alt;
  47.          if (u.mhmax > mons[u.umonnum].mlevel)
  48.              u.mhmax -= rn2(min(u.mhmax, num + 1)), context.botl = 1;
  49.      } else {
  50.          num = d(2, 4);
  51.          if (u.uhpmax > u.ulevel)
  52.              u.uhpmax -= rn2(min(u.uhpmax, num + 1)), context.botl = 1;
  53.      }
  54.      if (!num)
  55.          You("are uninjured.");
  56.      else
  57.          losehp(num, tower_of_flame, KILLED_BY_AN); /* fire damage */
  58.      burn_away_slime();
  59.  
  60.      if (burnarmor(&youmonst) || rn2(3)) {
  61.          destroy_item(SCROLL_CLASS, AD_FIRE);
  62.          destroy_item(SPBOOK_CLASS, AD_FIRE);
  63.          destroy_item(POTION_CLASS, AD_FIRE);
  64.      }
  65.      if (!box && burn_floor_objects(u.ux, u.uy, see_it, TRUE) && !see_it)
  66.          You("smell paper burning.");
  67.      if (is_ice(u.ux, u.uy))
  68.          melt_ice(u.ux, u.uy, (char *) 0);
  69.  }
  70.  

domagictrap

  1.  STATIC_OVL void
  2.  domagictrap()
  3.  {
  4.      register int fate = rnd(20);
  5.  
  6.      /* What happened to the poor sucker? */
  7.  
  8.      if (fate < 10) {
  9.          /* Most of the time, it creates some monsters. */
  10.          register int cnt = rnd(4);
  11.  
  12.          if (!resists_blnd(&youmonst)) {
  13.              You("are momentarily blinded by a flash of light!");
  14.              make_blinded((long) rn1(5, 10), FALSE);
  15.              if (!Blind)
  16.                  Your1(vision_clears);
  17.          } else if (!Blind) {
  18.              You_see("a flash of light!");
  19.          } else
  20.              You_hear("a deafening roar!");
  21.          incr_itimeout(&HDeaf, rn1(20, 30));
  22.          while (cnt--)
  23.              (void) makemon((struct permonst *) 0, u.ux, u.uy, NO_MM_FLAGS);
  24.      } else
  25.          switch (fate) {
  26.          case 10:
  27.          case 11:
  28.              /* sometimes nothing happens */
  29.              break;
  30.          case 12: /* a flash of fire */
  31.              dofiretrap((struct obj *) 0);
  32.              break;
  33.  
  34.          /* odd feelings */
  35.          case 13:
  36.              pline("A shiver runs up and down your %s!", body_part(SPINE));
  37.              break;
  38.          case 14:
  39.              You_hear(Hallucination ? "the moon howling at you."
  40.                                     : "distant howling.");
  41.              break;
  42.          case 15:
  43.              if (on_level(&u.uz, &qstart_level))
  44.                  You_feel(
  45.                      "%slike the prodigal son.",
  46.                      (flags.female || (Upolyd && is_neuter(youmonst.data)))
  47.                          ? "oddly "
  48.                          : "");
  49.              else
  50.                  You("suddenly yearn for %s.",
  51.                      Hallucination
  52.                          ? "Cleveland"
  53.                          : (In_quest(&u.uz) || at_dgn_entrance("The Quest"))
  54.                                ? "your nearby homeland"
  55.                                : "your distant homeland");
  56.              break;
  57.          case 16:
  58.              Your("pack shakes violently!");
  59.              break;
  60.          case 17:
  61.              You(Hallucination ? "smell hamburgers." : "smell charred flesh.");
  62.              break;
  63.          case 18:
  64.              You_feel("tired.");
  65.              break;
  66.  
  67.          /* very occasionally something nice happens. */
  68.          case 19: { /* tame nearby monsters */
  69.              int i, j;
  70.              struct monst *mtmp;
  71.  
  72.              (void) adjattrib(A_CHA, 1, FALSE);
  73.              for (i = -1; i <= 1; i++)
  74.                  for (j = -1; j <= 1; j++) {
  75.                      if (!isok(u.ux + i, u.uy + j))
  76.                          continue;
  77.                      mtmp = m_at(u.ux + i, u.uy + j);
  78.                      if (mtmp)
  79.                          (void) tamedog(mtmp, (struct obj *) 0);
  80.                  }
  81.              break;
  82.          }
  83.          case 20: { /* uncurse stuff */
  84.              struct obj pseudo;
  85.              long save_conf = HConfusion;
  86.  
  87.              pseudo = zeroobj; /* neither cursed nor blessed,
  88.                                   and zero out oextra */
  89.              pseudo.otyp = SCR_REMOVE_CURSE;
  90.              HConfusion = 0L;
  91.              (void) seffects(&pseudo);
  92.              HConfusion = save_conf;
  93.              break;
  94.          }
  95.          default:
  96.              break;
  97.          }
  98.  }
  99.  

fire_damage

  1.  /* Set an item on fire.
  2.   *   "force" means not to roll a luck-based protection check for the
  3.   *     item.
  4.   *   "x" and "y" are the coordinates to dump the contents of a
  5.   *     container, if it burns up.
  6.   *
  7.   * Return whether the object was destroyed.
  8.   */
  9.  boolean
  10.  fire_damage(obj, force, x, y)
  11.  struct obj *obj;
  12.  boolean force;
  13.  xchar x, y;
  14.  {
  15.      int chance;
  16.      struct obj *otmp, *ncobj;
  17.      int in_sight = !Blind && couldsee(x, y); /* Don't care if it's lit */
  18.      int dindx;
  19.  
  20.      /* object might light in a controlled manner */
  21.      if (catch_lit(obj))
  22.          return FALSE;
  23.  
  24.      if (Is_container(obj)) {
  25.          switch (obj->otyp) {
  26.          case ICE_BOX:
  27.              return FALSE; /* Immune */
  28.          case CHEST:
  29.              chance = 40;
  30.              break;
  31.          case LARGE_BOX:
  32.              chance = 30;
  33.              break;
  34.          default:
  35.              chance = 20;
  36.              break;
  37.          }
  38.          if ((!force && (Luck + 5) > rn2(chance))
  39.              || (is_flammable(obj) && obj->oerodeproof))
  40.              return FALSE;
  41.          /* Container is burnt up - dump contents out */
  42.          if (in_sight)
  43.              pline("%s catches fire and burns.", Yname2(obj));
  44.          if (Has_contents(obj)) {
  45.              if (in_sight)
  46.                  pline("Its contents fall out.");
  47.              for (otmp = obj->cobj; otmp; otmp = ncobj) {
  48.                  ncobj = otmp->nobj;
  49.                  obj_extract_self(otmp);
  50.                  if (!flooreffects(otmp, x, y, ""))
  51.                      place_object(otmp, x, y);
  52.              }
  53.          }
  54.          setnotworn(obj);
  55.          delobj(obj);
  56.          return TRUE;
  57.      } else if (!force && (Luck + 5) > rn2(20)) {
  58.          /*  chance per item of sustaining damage:
  59.            *     max luck (Luck==13):    10%
  60.            *     avg luck (Luck==0):     75%
  61.            *     awful luck (Luck<-4):  100%
  62.            */
  63.          return FALSE;
  64.      } else if (obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS) {
  65.          if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL)
  66.              return FALSE;
  67.          if (obj->otyp == SPE_BOOK_OF_THE_DEAD) {
  68.              if (in_sight)
  69.                  pline("Smoke rises from %s.", the(xname(obj)));
  70.              return FALSE;
  71.          }
  72.          dindx = (obj->oclass == SCROLL_CLASS) ? 3 : 4;
  73.          if (in_sight)
  74.              pline("%s %s.", Yname2(obj),
  75.                    destroy_strings[dindx][(obj->quan > 1L)]);
  76.          setnotworn(obj);
  77.          delobj(obj);
  78.          return TRUE;
  79.      } else if (obj->oclass == POTION_CLASS) {
  80.          dindx = (obj->otyp != POT_OIL) ? 1 : 2;
  81.          if (in_sight)
  82.              pline("%s %s.", Yname2(obj),
  83.                    destroy_strings[dindx][(obj->quan > 1L)]);
  84.          setnotworn(obj);
  85.          delobj(obj);
  86.          return TRUE;
  87.      } else if (erode_obj(obj, (char *) 0, ERODE_BURN, EF_DESTROY)
  88.                 == ER_DESTROYED) {
  89.          return TRUE;
  90.      }
  91.      return FALSE;
  92.  }
  93.  

fire_damage_chain

  1.  /*
  2.   * Apply fire_damage() to an entire chain.
  3.   *
  4.   * Return number of objects destroyed. --ALI
  5.   */
  6.  int
  7.  fire_damage_chain(chain, force, here, x, y)
  8.  struct obj *chain;
  9.  boolean force, here;
  10.  xchar x, y;
  11.  {
  12.      struct obj *obj, *nobj;
  13.      int num = 0;
  14.      for (obj = chain; obj; obj = nobj) {
  15.          nobj = here ? obj->nexthere : obj->nobj;
  16.          if (fire_damage(obj, force, x, y))
  17.              ++num;
  18.      }
  19.  
  20.      if (num && (Blind && !couldsee(x, y)))
  21.          You("smell smoke.");
  22.      return num;
  23.  }
  24.  

acid_damage

  1.  void
  2.  acid_damage(obj)
  3.  struct obj *obj;
  4.  {
  5.      /* Scrolls but not spellbooks can be erased by acid. */
  6.      struct monst *victim;
  7.      boolean vismon;
  8.  
  9.      if (!obj)
  10.          return;
  11.  
  12.      victim = carried(obj) ? &youmonst : mcarried(obj) ? obj->ocarry : NULL;
  13.      vismon = victim && (victim != &youmonst) && canseemon(victim);
  14.  
  15.      if (obj->greased) {
  16.          grease_protect(obj, (char *) 0, victim);
  17.      } else if (obj->oclass == SCROLL_CLASS && obj->otyp != SCR_BLANK_PAPER) {
  18.          if (obj->otyp != SCR_BLANK_PAPER
  19.  #ifdef MAIL
  20.              && obj->otyp != SCR_MAIL
  21.  #endif
  22.              ) {
  23.              if (!Blind) {
  24.                  if (victim == &youmonst)
  25.                      pline("Your %s.", aobjnam(obj, "fade"));
  26.                  else if (vismon)
  27.                      pline("%s %s.", s_suffix(Monnam(victim)),
  28.                            aobjnam(obj, "fade"));
  29.              }
  30.          }
  31.          obj->otyp = SCR_BLANK_PAPER;
  32.          obj->spe = 0;
  33.          obj->dknown = 0;
  34.      } else
  35.          erode_obj(obj, (char *) 0, ERODE_CORRODE, EF_GREASE | EF_VERBOSE);
  36.  }
  37.  

water_damage

  1.  /* context for water_damage(), managed by water_damage_chain();
  2.     when more than one stack of potions of acid explode while processing
  3.     a chain of objects, use alternate phrasing after the first message */
  4.  static struct h2o_ctx {
  5.      int dkn_boom, unk_boom; /* track dknown, !dknown separately */
  6.      boolean ctx_valid;
  7.  } acid_ctx = { 0, 0, FALSE };
  8.  
  9.  /* Get an object wet and damage it appropriately.
  10.   *   "ostr", if present, is used instead of the object name in some
  11.   *     messages.
  12.   *   "force" means not to roll luck to protect some objects.
  13.   * Returns an erosion return value (ER_*)
  14.   */
  15.  int
  16.  water_damage(obj, ostr, force)
  17.  struct obj *obj;
  18.  const char *ostr;
  19.  boolean force;
  20.  {
  21.      if (!obj)
  22.          return ER_NOTHING;
  23.  
  24.      if (snuff_lit(obj))
  25.          return ER_DAMAGED;
  26.  
  27.      if (!ostr)
  28.          ostr = cxname(obj);
  29.  
  30.      if (obj->otyp == CAN_OF_GREASE && obj->spe > 0) {
  31.          return ER_NOTHING;
  32.      } else if (obj->otyp == TOWEL && obj->spe < 7) {
  33.          wet_a_towel(obj, rnd(7), TRUE);
  34.          return ER_NOTHING;
  35.      } else if (obj->greased) {
  36.          if (!rn2(2))
  37.              obj->greased = 0;
  38.          if (carried(obj))
  39.              update_inventory();
  40.          return ER_GREASED;
  41.      } else if (Is_container(obj) && !Is_box(obj)
  42.                 && (obj->otyp != OILSKIN_SACK || (obj->cursed && !rn2(3)))) {
  43.          if (carried(obj))
  44.              pline("Water gets into your %s!", ostr);
  45.  
  46.          water_damage_chain(obj->cobj, FALSE);
  47.          return ER_NOTHING;
  48.      } else if (!force && (Luck + 5) > rn2(20)) {
  49.          /*  chance per item of sustaining damage:
  50.              *   max luck:               10%
  51.              *   avg luck (Luck==0):     75%
  52.              *   awful luck (Luck<-4):  100%
  53.              */
  54.          return ER_NOTHING;
  55.      } else if (obj->oclass == SCROLL_CLASS) {
  56.  #ifdef MAIL
  57.          if (obj->otyp == SCR_MAIL)
  58.              return 0;
  59.  #endif
  60.          if (carried(obj))
  61.              pline("Your %s %s.", ostr, vtense(ostr, "fade"));
  62.  
  63.          obj->otyp = SCR_BLANK_PAPER;
  64.          obj->dknown = 0;
  65.          obj->spe = 0;
  66.          if (carried(obj))
  67.              update_inventory();
  68.          return ER_DAMAGED;
  69.      } else if (obj->oclass == SPBOOK_CLASS) {
  70.          if (obj->otyp == SPE_BOOK_OF_THE_DEAD) {
  71.              pline("Steam rises from %s.", the(xname(obj)));
  72.              return 0;
  73.          }
  74.  
  75.          if (carried(obj))
  76.              pline("Your %s %s.", ostr, vtense(ostr, "fade"));
  77.  
  78.          if (obj->otyp == SPE_NOVEL) {
  79.              obj->novelidx = 0;
  80.              free_oname(obj);
  81.          }
  82.  
  83.          obj->otyp = SPE_BLANK_PAPER;
  84.          obj->dknown = 0;
  85.          if (carried(obj))
  86.              update_inventory();
  87.          return ER_DAMAGED;
  88.      } else if (obj->oclass == POTION_CLASS) {
  89.          if (obj->otyp == POT_ACID) {
  90.              char *bufp;
  91.              boolean one = (obj->quan == 1L), update = carried(obj),
  92.                      exploded = FALSE;
  93.  
  94.              if (Blind && !carried(obj))
  95.                  obj->dknown = 0;
  96.              if (acid_ctx.ctx_valid)
  97.                  exploded = ((obj->dknown ? acid_ctx.dkn_boom
  98.                                           : acid_ctx.unk_boom) > 0);
  99.              /* First message is
  100.               * "a [potion|<color> potion|potion of acid] explodes"
  101.               * depending on obj->dknown (potion has been seen) and
  102.               * objects[POT_ACID].oc_name_known (fully discovered),
  103.               * or "some {plural version} explode" when relevant.
  104.               * Second and subsequent messages for same chain and
  105.               * matching dknown status are
  106.               * "another [potion|<color> &c] explodes" or plural
  107.               * variant.
  108.               */
  109.              bufp = simpleonames(obj);
  110.              pline("%s %s %s!", /* "A potion explodes!" */
  111.                    !exploded ? (one ? "A" : "Some")
  112.                              : (one ? "Another" : "More"),
  113.                    bufp, vtense(bufp, "explode"));
  114.              if (acid_ctx.ctx_valid) {
  115.                  if (obj->dknown)
  116.                      acid_ctx.dkn_boom++;
  117.                  else
  118.                      acid_ctx.unk_boom++;
  119.              }
  120.              setnotworn(obj);
  121.              delobj(obj);
  122.              if (update)
  123.                  update_inventory();
  124.              return ER_DESTROYED;
  125.          } else if (obj->odiluted) {
  126.              if (carried(obj))
  127.                  pline("Your %s %s further.", ostr, vtense(ostr, "dilute"));
  128.  
  129.              obj->otyp = POT_WATER;
  130.              obj->dknown = 0;
  131.              obj->blessed = obj->cursed = 0;
  132.              obj->odiluted = 0;
  133.              if (carried(obj))
  134.                  update_inventory();
  135.              return ER_DAMAGED;
  136.          } else if (obj->otyp != POT_WATER) {
  137.              if (carried(obj))
  138.                  pline("Your %s %s.", ostr, vtense(ostr, "dilute"));
  139.  
  140.              obj->odiluted++;
  141.              if (carried(obj))
  142.                  update_inventory();
  143.              return ER_DAMAGED;
  144.          }
  145.      } else {
  146.          return erode_obj(obj, ostr, ERODE_RUST, EF_NONE);
  147.      }
  148.      return ER_NOTHING;
  149.  }
  150.  

water_damage_chain

  1.  void
  2.  water_damage_chain(obj, here)
  3.  struct obj *obj;
  4.  boolean here;
  5.  {
  6.      struct obj *otmp;
  7.  
  8.      /* initialize acid context: so far, neither seen (dknown) potions of
  9.         acid nor unseen have exploded during this water damage sequence */
  10.      acid_ctx.dkn_boom = acid_ctx.unk_boom = 0;
  11.      acid_ctx.ctx_valid = TRUE;
  12.  
  13.      for (; obj; obj = otmp) {
  14.          otmp = here ? obj->nexthere : obj->nobj;
  15.          water_damage(obj, (char *) 0, FALSE);
  16.      }
  17.  
  18.      /* reset acid context */
  19.      acid_ctx.dkn_boom = acid_ctx.unk_boom = 0;
  20.      acid_ctx.ctx_valid = FALSE;
  21.  }
  22.  

emergency_disrobe

  1.  /*
  2.   * This function is potentially expensive - rolling
  3.   * inventory list multiple times.  Luckily it's seldom needed.
  4.   * Returns TRUE if disrobing made player unencumbered enough to
  5.   * crawl out of the current predicament.
  6.   */
  7.  STATIC_OVL boolean
  8.  emergency_disrobe(lostsome)
  9.  boolean *lostsome;
  10.  {
  11.      int invc = inv_cnt(TRUE);
  12.  
  13.      while (near_capacity() > (Punished ? UNENCUMBERED : SLT_ENCUMBER)) {
  14.          register struct obj *obj, *otmp = (struct obj *) 0;
  15.          register int i;
  16.  
  17.          /* Pick a random object */
  18.          if (invc > 0) {
  19.              i = rn2(invc);
  20.              for (obj = invent; obj; obj = obj->nobj) {
  21.                  /*
  22.                   * Undroppables are: body armor, boots, gloves,
  23.                   * amulets, and rings because of the time and effort
  24.                   * in removing them + loadstone and other cursed stuff
  25.                   * for obvious reasons.
  26.                   */
  27.                  if (!((obj->otyp == LOADSTONE && obj->cursed) || obj == uamul
  28.                        || obj == uleft || obj == uright || obj == ublindf
  29.                        || obj == uarm || obj == uarmc || obj == uarmg
  30.                        || obj == uarmf || obj == uarmu
  31.                        || (obj->cursed && (obj == uarmh || obj == uarms))
  32.                        || welded(obj)))
  33.                      otmp = obj;
  34.                  /* reached the mark and found some stuff to drop? */
  35.                  if (--i < 0 && otmp)
  36.                      break;
  37.  
  38.                  /* else continue */
  39.              }
  40.          }
  41.          if (!otmp)
  42.              return FALSE; /* nothing to drop! */
  43.          if (otmp->owornmask)
  44.              remove_worn_item(otmp, FALSE);
  45.          *lostsome = TRUE;
  46.          dropx(otmp);
  47.          invc--;
  48.      }
  49.      return TRUE;
  50.  }
  51.  

drown

  1.  
  2.  /*  return TRUE iff player relocated */
  3.  boolean
  4.  drown()
  5.  {
  6.      const char *pool_of_water;
  7.      boolean inpool_ok = FALSE, crawl_ok;
  8.      int i, x, y;
  9.  
  10.      /* happily wading in the same contiguous pool */
  11.      if (u.uinwater && is_pool(u.ux - u.dx, u.uy - u.dy)
  12.          && (Swimming || Amphibious)) {
  13.          /* water effects on objects every now and then */
  14.          if (!rn2(5))
  15.              inpool_ok = TRUE;
  16.          else
  17.              return FALSE;
  18.      }
  19.  
  20.      if (!u.uinwater) {
  21.          You("%s into the water%c", Is_waterlevel(&u.uz) ? "plunge" : "fall",
  22.              Amphibious || Swimming ? '.' : '!');
  23.          if (!Swimming && !Is_waterlevel(&u.uz))
  24.              You("sink like %s.", Hallucination ? "the Titanic" : "a rock");
  25.      }
  26.  
  27.      water_damage_chain(invent, FALSE);
  28.  
  29.      if (u.umonnum == PM_GREMLIN && rn2(3))
  30.          (void) split_mon(&youmonst, (struct monst *) 0);
  31.      else if (u.umonnum == PM_IRON_GOLEM) {
  32.          You("rust!");
  33.          i = Maybe_Half_Phys(d(2, 6));
  34.          if (u.mhmax > i)
  35.              u.mhmax -= i;
  36.          losehp(i, "rusting away", KILLED_BY);
  37.      }
  38.      if (inpool_ok)
  39.          return FALSE;
  40.  
  41.      if ((i = number_leashed()) > 0) {
  42.          pline_The("leash%s slip%s loose.", (i > 1) ? "es" : "",
  43.                    (i > 1) ? "" : "s");
  44.          unleash_all();
  45.      }
  46.  
  47.      if (Amphibious || Swimming) {
  48.          if (Amphibious) {
  49.              if (flags.verbose)
  50.                  pline("But you aren't drowning.");
  51.              if (!Is_waterlevel(&u.uz)) {
  52.                  if (Hallucination)
  53.                      Your("keel hits the bottom.");
  54.                  else
  55.                      You("touch bottom.");
  56.              }
  57.          }
  58.          if (Punished) {
  59.              unplacebc();
  60.              placebc();
  61.          }
  62.          vision_recalc(2); /* unsee old position */
  63.          u.uinwater = 1;
  64.          under_water(1);
  65.          vision_full_recalc = 1;
  66.          return FALSE;
  67.      }
  68.      if ((Teleportation || can_teleport(youmonst.data)) && !Unaware
  69.          && (Teleport_control || rn2(3) < Luck + 2)) {
  70.          You("attempt a teleport spell."); /* utcsri!carroll */
  71.          if (!level.flags.noteleport) {
  72.              (void) dotele();
  73.              if (!is_pool(u.ux, u.uy))
  74.                  return TRUE;
  75.          } else
  76.              pline_The("attempted teleport spell fails.");
  77.      }
  78.      if (u.usteed) {
  79.          dismount_steed(DISMOUNT_GENERIC);
  80.          if (!is_pool(u.ux, u.uy))
  81.              return TRUE;
  82.      }
  83.      crawl_ok = FALSE;
  84.      x = y = 0; /* lint suppression */
  85.      /* if sleeping, wake up now so that we don't crawl out of water
  86.         while still asleep; we can't do that the same way that waking
  87.         due to combat is handled; note unmul() clears u.usleep */
  88.      if (u.usleep)
  89.          unmul("Suddenly you wake up!");
  90.      /* being doused will revive from fainting */
  91.      if (is_fainted())
  92.          reset_faint();
  93.      /* can't crawl if unable to move (crawl_ok flag stays false) */
  94.      if (multi < 0 || (Upolyd && !youmonst.data->mmove))
  95.          goto crawl;
  96.      /* look around for a place to crawl to */
  97.      for (i = 0; i < 100; i++) {
  98.          x = rn1(3, u.ux - 1);
  99.          y = rn1(3, u.uy - 1);
  100.          if (crawl_destination(x, y)) {
  101.              crawl_ok = TRUE;
  102.              goto crawl;
  103.          }
  104.      }
  105.      /* one more scan */
  106.      for (x = u.ux - 1; x <= u.ux + 1; x++)
  107.          for (y = u.uy - 1; y <= u.uy + 1; y++)
  108.              if (crawl_destination(x, y)) {
  109.                  crawl_ok = TRUE;
  110.                  goto crawl;
  111.              }
  112.  crawl:
  113.      if (crawl_ok) {
  114.          boolean lost = FALSE;
  115.          /* time to do some strip-tease... */
  116.          boolean succ = Is_waterlevel(&u.uz) ? TRUE : emergency_disrobe(&lost);
  117.  
  118.          You("try to crawl out of the water.");
  119.          if (lost)
  120.              You("dump some of your gear to lose weight...");
  121.          if (succ) {
  122.              pline("Pheew!  That was close.");
  123.              teleds(x, y, TRUE);
  124.              return TRUE;
  125.          }
  126.          /* still too much weight */
  127.          pline("But in vain.");
  128.      }
  129.      u.uinwater = 1;
  130.      You("drown.");
  131.      for (i = 0; i < 5; i++) { /* arbitrary number of loops */
  132.          /* killer format and name are reconstructed every iteration
  133.             because lifesaving resets them */
  134.          pool_of_water = waterbody_name(u.ux, u.uy);
  135.          killer.format = KILLED_BY_AN;
  136.          /* avoid "drowned in [a] water" */
  137.          if (!strcmp(pool_of_water, "water"))
  138.              pool_of_water = "deep water", killer.format = KILLED_BY;
  139.          Strcpy(killer.name, pool_of_water);
  140.          done(DROWNING);
  141.          /* oops, we're still alive.  better get out of the water. */
  142.          if (safe_teleds(TRUE))
  143.              break; /* successful life-save */
  144.          /* nowhere safe to land; repeat drowning loop... */
  145.          pline("You're still drowning.");
  146.      }
  147.      if (u.uinwater) {
  148.          u.uinwater = 0;
  149.          You("find yourself back %s.",
  150.              Is_waterlevel(&u.uz) ? "in an air bubble" : "on land");
  151.      }
  152.      return TRUE;
  153.  }
  154.  

drain_en

  1.  void
  2.  drain_en(n)
  3.  int n;
  4.  {
  5.      if (!u.uenmax) {
  6.          /* energy is completely gone */
  7.          You_feel("momentarily lethargic.");
  8.      } else {
  9.          /* throttle further loss a bit when there's not much left to lose */
  10.          if (n > u.uenmax || n > u.ulevel)
  11.              n = rnd(n);
  12.  
  13.          You_feel("your magical energy drain away%c", (n > u.uen) ? '!' : '.');
  14.          u.uen -= n;
  15.          if (u.uen < 0) {
  16.              u.uenmax -= rnd(-u.uen);
  17.              if (u.uenmax < 0)
  18.                  u.uenmax = 0;
  19.              u.uen = 0;
  20.          }
  21.          context.botl = 1;
  22.      }
  23.  }
  24.  

dountrap

  1.  /* disarm a trap */
  2.  int
  3.  dountrap()
  4.  {
  5.      if (near_capacity() >= HVY_ENCUMBER) {
  6.          pline("You're too strained to do that.");
  7.          return 0;
  8.      }
  9.      if ((nohands(youmonst.data) && !webmaker(youmonst.data))
  10.          || !youmonst.data->mmove) {
  11.          pline("And just how do you expect to do that?");
  12.          return 0;
  13.      } else if (u.ustuck && sticks(youmonst.data)) {
  14.          pline("You'll have to let go of %s first.", mon_nam(u.ustuck));
  15.          return 0;
  16.      }
  17.      if (u.ustuck || (welded(uwep) && bimanual(uwep))) {
  18.          Your("%s seem to be too busy for that.", makeplural(body_part(HAND)));
  19.          return 0;
  20.      }
  21.      return untrap(FALSE);
  22.  }
  23.  

untrap_prob

  1.  /* Probability of disabling a trap.  Helge Hafting */
  2.  STATIC_OVL int
  3.  untrap_prob(ttmp)
  4.  struct trap *ttmp;
  5.  {
  6.      int chance = 3;
  7.  
  8.      /* Only spiders know how to deal with webs reliably */
  9.      if (ttmp->ttyp == WEB && !webmaker(youmonst.data))
  10.          chance = 30;
  11.      if (Confusion || Hallucination)
  12.          chance++;
  13.      if (Blind)
  14.          chance++;
  15.      if (Stunned)
  16.          chance += 2;
  17.      if (Fumbling)
  18.          chance *= 2;
  19.      /* Your own traps are better known than others. */
  20.      if (ttmp && ttmp->madeby_u)
  21.          chance--;
  22.      if (Role_if(PM_ROGUE)) {
  23.          if (rn2(2 * MAXULEV) < u.ulevel)
  24.              chance--;
  25.          if (u.uhave.questart && chance > 1)
  26.              chance--;
  27.      } else if (Role_if(PM_RANGER) && chance > 1)
  28.          chance--;
  29.      return rn2(chance);
  30.  }
  31.  

cnv_trap_obj

  1.  /* Replace trap with object(s).  Helge Hafting */
  2.  void
  3.  cnv_trap_obj(otyp, cnt, ttmp, bury_it)
  4.  int otyp;
  5.  int cnt;
  6.  struct trap *ttmp;
  7.  boolean bury_it;
  8.  {
  9.      struct obj *otmp = mksobj(otyp, TRUE, FALSE);
  10.  
  11.      otmp->quan = cnt;
  12.      otmp->owt = weight(otmp);
  13.      /* Only dart traps are capable of being poisonous */
  14.      if (otyp != DART)
  15.          otmp->opoisoned = 0;
  16.      place_object(otmp, ttmp->tx, ttmp->ty);
  17.      if (bury_it) {
  18.          /* magical digging first disarms this trap, then will unearth it */
  19.          (void) bury_an_obj(otmp, (boolean *) 0);
  20.      } else {
  21.          /* Sell your own traps only... */
  22.          if (ttmp->madeby_u)
  23.              sellobj(otmp, ttmp->tx, ttmp->ty);
  24.          stackobj(otmp);
  25.      }
  26.      newsym(ttmp->tx, ttmp->ty);
  27.      if (u.utrap && ttmp->tx == u.ux && ttmp->ty == u.uy)
  28.          u.utrap = 0;
  29.      deltrap(ttmp);
  30.  }
  31.  

move_into_trap

  1.  /* while attempting to disarm an adjacent trap, we've fallen into it */
  2.  STATIC_OVL void
  3.  move_into_trap(ttmp)
  4.  struct trap *ttmp;
  5.  {
  6.      int bc = 0;
  7.      xchar x = ttmp->tx, y = ttmp->ty, bx, by, cx, cy;
  8.      boolean unused;
  9.  
  10.      bx = by = cx = cy = 0; /* lint suppression */
  11.      /* we know there's no monster in the way, and we're not trapped */
  12.      if (!Punished
  13.          || drag_ball(x, y, &bc, &bx, &by, &cx, &cy, &unused, TRUE)) {
  14.          u.ux0 = u.ux, u.uy0 = u.uy;
  15.          u.ux = x, u.uy = y;
  16.          u.umoved = TRUE;
  17.          newsym(u.ux0, u.uy0);
  18.          vision_recalc(1);
  19.          check_leash(u.ux0, u.uy0);
  20.          if (Punished)
  21.              move_bc(0, bc, bx, by, cx, cy);
  22.          /* marking the trap unseen forces dotrap() to treat it like a new
  23.             discovery and prevents pickup() -> look_here() -> check_here()
  24.             from giving a redundant "there is a <trap> here" message when
  25.             there are objects covering this trap */
  26.          ttmp->tseen = 0; /* hack for check_here() */
  27.          /* trigger the trap */
  28.          spoteffects(TRUE); /* pickup() + dotrap() */
  29.          exercise(A_WIS, FALSE);
  30.      }
  31.  }
  32.  

try_disarm

  1.  /* 0: doesn't even try
  2.   * 1: tries and fails
  3.   * 2: succeeds
  4.   */
  5.  STATIC_OVL int
  6.  try_disarm(ttmp, force_failure)
  7.  struct trap *ttmp;
  8.  boolean force_failure;
  9.  {
  10.      struct monst *mtmp = m_at(ttmp->tx, ttmp->ty);
  11.      int ttype = ttmp->ttyp;
  12.      boolean under_u = (!u.dx && !u.dy);
  13.      boolean holdingtrap = (ttype == BEAR_TRAP || ttype == WEB);
  14.  
  15.      /* Test for monster first, monsters are displayed instead of trap. */
  16.      if (mtmp && (!mtmp->mtrapped || !holdingtrap)) {
  17.          pline("%s is in the way.", Monnam(mtmp));
  18.          return 0;
  19.      }
  20.      /* We might be forced to move onto the trap's location. */
  21.      if (sobj_at(BOULDER, ttmp->tx, ttmp->ty) && !Passes_walls && !under_u) {
  22.          There("is a boulder in your way.");
  23.          return 0;
  24.      }
  25.      /* duplicate tight-space checks from test_move */
  26.      if (u.dx && u.dy && bad_rock(youmonst.data, u.ux, ttmp->ty)
  27.          && bad_rock(youmonst.data, ttmp->tx, u.uy)) {
  28.          if ((invent && (inv_weight() + weight_cap() > 600))
  29.              || bigmonst(youmonst.data)) {
  30.              /* don't allow untrap if they can't get thru to it */
  31.              You("are unable to reach the %s!",
  32.                  defsyms[trap_to_defsym(ttype)].explanation);
  33.              return 0;
  34.          }
  35.      }
  36.      /* untrappable traps are located on the ground. */
  37.      if (!can_reach_floor(TRUE)) {
  38.          if (u.usteed && P_SKILL(P_RIDING) < P_BASIC)
  39.              rider_cant_reach();
  40.          else
  41.              You("are unable to reach the %s!",
  42.                  defsyms[trap_to_defsym(ttype)].explanation);
  43.          return 0;
  44.      }
  45.  
  46.      /* Will our hero succeed? */
  47.      if (force_failure || untrap_prob(ttmp)) {
  48.          if (rnl(5)) {
  49.              pline("Whoops...");
  50.              if (mtmp) { /* must be a trap that holds monsters */
  51.                  if (ttype == BEAR_TRAP) {
  52.                      if (mtmp->mtame)
  53.                          abuse_dog(mtmp);
  54.                      if ((mtmp->mhp -= rnd(4)) <= 0)
  55.                          killed(mtmp);
  56.                  } else if (ttype == WEB) {
  57.                      if (!webmaker(youmonst.data)) {
  58.                          struct trap *ttmp2 = maketrap(u.ux, u.uy, WEB);
  59.  
  60.                          if (ttmp2) {
  61.                              pline_The(
  62.                                  "webbing sticks to you. You're caught too!");
  63.                              dotrap(ttmp2, NOWEBMSG);
  64.                              if (u.usteed && u.utrap) {
  65.                                  /* you, not steed, are trapped */
  66.                                  dismount_steed(DISMOUNT_FELL);
  67.                              }
  68.                          }
  69.                      } else
  70.                          pline("%s remains entangled.", Monnam(mtmp));
  71.                  }
  72.              } else if (under_u) {
  73.                  dotrap(ttmp, 0);
  74.              } else {
  75.                  move_into_trap(ttmp);
  76.              }
  77.          } else {
  78.              pline("%s %s is difficult to %s.",
  79.                    ttmp->madeby_u ? "Your" : under_u ? "This" : "That",
  80.                    defsyms[trap_to_defsym(ttype)].explanation,
  81.                    (ttype == WEB) ? "remove" : "disarm");
  82.          }
  83.          return 1;
  84.      }
  85.      return 2;
  86.  }
  87.  

reward_untrap

  1.  STATIC_OVL void
  2.  reward_untrap(ttmp, mtmp)
  3.  struct trap *ttmp;
  4.  struct monst *mtmp;
  5.  {
  6.      if (!ttmp->madeby_u) {
  7.          if (rnl(10) < 8 && !mtmp->mpeaceful && !mtmp->msleeping
  8.              && !mtmp->mfrozen && !mindless(mtmp->data)
  9.              && mtmp->data->mlet != S_HUMAN) {
  10.              mtmp->mpeaceful = 1;
  11.              set_malign(mtmp); /* reset alignment */
  12.              pline("%s is grateful.", Monnam(mtmp));
  13.          }
  14.          /* Helping someone out of a trap is a nice thing to do,
  15.           * A lawful may be rewarded, but not too often.  */
  16.          if (!rn2(3) && !rnl(8) && u.ualign.type == A_LAWFUL) {
  17.              adjalign(1);
  18.              You_feel("that you did the right thing.");
  19.          }
  20.      }
  21.  }
  22.  

disarm_holdingtrap

  1.  STATIC_OVL int
  2.  disarm_holdingtrap(ttmp) /* Helge Hafting */
  3.  struct trap *ttmp;
  4.  {
  5.      struct monst *mtmp;
  6.      int fails = try_disarm(ttmp, FALSE);
  7.  
  8.      if (fails < 2)
  9.          return fails;
  10.  
  11.      /* ok, disarm it. */
  12.  
  13.      /* untrap the monster, if any.
  14.         There's no need for a cockatrice test, only the trap is touched */
  15.      if ((mtmp = m_at(ttmp->tx, ttmp->ty)) != 0) {
  16.          mtmp->mtrapped = 0;
  17.          You("remove %s %s from %s.", the_your[ttmp->madeby_u],
  18.              (ttmp->ttyp == BEAR_TRAP) ? "bear trap" : "webbing",
  19.              mon_nam(mtmp));
  20.          reward_untrap(ttmp, mtmp);
  21.      } else {
  22.          if (ttmp->ttyp == BEAR_TRAP) {
  23.              You("disarm %s bear trap.", the_your[ttmp->madeby_u]);
  24.              cnv_trap_obj(BEARTRAP, 1, ttmp, FALSE);
  25.          } else /* if (ttmp->ttyp == WEB) */ {
  26.              You("succeed in removing %s web.", the_your[ttmp->madeby_u]);
  27.              deltrap(ttmp);
  28.          }
  29.      }
  30.      newsym(u.ux + u.dx, u.uy + u.dy);
  31.      return 1;
  32.  }
  33.  

disarm_landmine

  1.  STATIC_OVL int
  2.  disarm_landmine(ttmp) /* Helge Hafting */
  3.  struct trap *ttmp;
  4.  {
  5.      int fails = try_disarm(ttmp, FALSE);
  6.  
  7.      if (fails < 2)
  8.          return fails;
  9.      You("disarm %s land mine.", the_your[ttmp->madeby_u]);
  10.      cnv_trap_obj(LAND_MINE, 1, ttmp, FALSE);
  11.      return 1;
  12.  }
  13.  

disarm_squeaky_board

  1.  /* getobj will filter down to cans of grease and known potions of oil */
  2.  static NEARDATA const char oil[] = { ALL_CLASSES, TOOL_CLASS, POTION_CLASS,
  3.                                       0 };
  4.  
  5.  /* it may not make much sense to use grease on floor boards, but so what? */
  6.  STATIC_OVL int
  7.  disarm_squeaky_board(ttmp)
  8.  struct trap *ttmp;
  9.  {
  10.      struct obj *obj;
  11.      boolean bad_tool;
  12.      int fails;
  13.  
  14.      obj = getobj(oil, "untrap with");
  15.      if (!obj)
  16.          return 0;
  17.  
  18.      bad_tool = (obj->cursed
  19.                  || ((obj->otyp != POT_OIL || obj->lamplit)
  20.                      && (obj->otyp != CAN_OF_GREASE || !obj->spe)));
  21.      fails = try_disarm(ttmp, bad_tool);
  22.      if (fails < 2)
  23.          return fails;
  24.  
  25.      /* successfully used oil or grease to fix squeaky board */
  26.      if (obj->otyp == CAN_OF_GREASE) {
  27.          consume_obj_charge(obj, TRUE);
  28.      } else {
  29.          useup(obj); /* oil */
  30.          makeknown(POT_OIL);
  31.      }
  32.      You("repair the squeaky board."); /* no madeby_u */
  33.      deltrap(ttmp);
  34.      newsym(u.ux + u.dx, u.uy + u.dy);
  35.      more_experienced(1, 5);
  36.      newexplevel();
  37.      return 1;
  38.  }
  39.  

disarm_shooting_trap

  1.  /* removes traps that shoot arrows, darts, etc. */
  2.  STATIC_OVL int
  3.  disarm_shooting_trap(ttmp, otyp)
  4.  struct trap *ttmp;
  5.  int otyp;
  6.  {
  7.      int fails = try_disarm(ttmp, FALSE);
  8.  
  9.      if (fails < 2)
  10.          return fails;
  11.      You("disarm %s trap.", the_your[ttmp->madeby_u]);
  12.      cnv_trap_obj(otyp, 50 - rnl(50), ttmp, FALSE);
  13.      return 1;
  14.  }
  15.  

try_lift

  1.  /* Is the weight too heavy?
  2.   * Formula as in near_capacity() & check_capacity() */
  3.  STATIC_OVL int
  4.  try_lift(mtmp, ttmp, wt, stuff)
  5.  struct monst *mtmp;
  6.  struct trap *ttmp;
  7.  int wt;
  8.  boolean stuff;
  9.  {
  10.      int wc = weight_cap();
  11.  
  12.      if (((wt * 2) / wc) >= HVY_ENCUMBER) {
  13.          pline("%s is %s for you to lift.", Monnam(mtmp),
  14.                stuff ? "carrying too much" : "too heavy");
  15.          if (!ttmp->madeby_u && !mtmp->mpeaceful && mtmp->mcanmove
  16.              && !mindless(mtmp->data) && mtmp->data->mlet != S_HUMAN
  17.              && rnl(10) < 3) {
  18.              mtmp->mpeaceful = 1;
  19.              set_malign(mtmp); /* reset alignment */
  20.              pline("%s thinks it was nice of you to try.", Monnam(mtmp));
  21.          }
  22.          return 0;
  23.      }
  24.      return 1;
  25.  }
  26.  

help_monster_out

  1.  /* Help trapped monster (out of a (spiked) pit) */
  2.  STATIC_OVL int
  3.  help_monster_out(mtmp, ttmp)
  4.  struct monst *mtmp;
  5.  struct trap *ttmp;
  6.  {
  7.      int wt;
  8.      struct obj *otmp;
  9.      boolean uprob;
  10.  
  11.      /*
  12.       * This works when levitating too -- consistent with the ability
  13.       * to hit monsters while levitating.
  14.       *
  15.       * Should perhaps check that our hero has arms/hands at the
  16.       * moment.  Helping can also be done by engulfing...
  17.       *
  18.       * Test the monster first - monsters are displayed before traps.
  19.       */
  20.      if (!mtmp->mtrapped) {
  21.          pline("%s isn't trapped.", Monnam(mtmp));
  22.          return 0;
  23.      }
  24.      /* Do you have the necessary capacity to lift anything? */
  25.      if (check_capacity((char *) 0))
  26.          return 1;
  27.  
  28.      /* Will our hero succeed? */
  29.      if ((uprob = untrap_prob(ttmp)) && !mtmp->msleeping && mtmp->mcanmove) {
  30.          You("try to reach out your %s, but %s backs away skeptically.",
  31.              makeplural(body_part(ARM)), mon_nam(mtmp));
  32.          return 1;
  33.      }
  34.  
  35.      /* is it a cockatrice?... */
  36.      if (touch_petrifies(mtmp->data) && !uarmg && !Stone_resistance) {
  37.          You("grab the trapped %s using your bare %s.", mtmp->data->mname,
  38.              makeplural(body_part(HAND)));
  39.  
  40.          if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM)) {
  41.              display_nhwindow(WIN_MESSAGE, FALSE);
  42.          } else {
  43.              char kbuf[BUFSZ];
  44.  
  45.              Sprintf(kbuf, "trying to help %s out of a pit",
  46.                      an(mtmp->data->mname));
  47.              instapetrify(kbuf);
  48.              return 1;
  49.          }
  50.      }
  51.      /* need to do cockatrice check first if sleeping or paralyzed */
  52.      if (uprob) {
  53.          You("try to grab %s, but cannot get a firm grasp.", mon_nam(mtmp));
  54.          if (mtmp->msleeping) {
  55.              mtmp->msleeping = 0;
  56.              pline("%s awakens.", Monnam(mtmp));
  57.          }
  58.          return 1;
  59.      }
  60.  
  61.      You("reach out your %s and grab %s.", makeplural(body_part(ARM)),
  62.          mon_nam(mtmp));
  63.  
  64.      if (mtmp->msleeping) {
  65.          mtmp->msleeping = 0;
  66.          pline("%s awakens.", Monnam(mtmp));
  67.      } else if (mtmp->mfrozen && !rn2(mtmp->mfrozen)) {
  68.          /* After such manhandling, perhaps the effect wears off */
  69.          mtmp->mcanmove = 1;
  70.          mtmp->mfrozen = 0;
  71.          pline("%s stirs.", Monnam(mtmp));
  72.      }
  73.  
  74.      /* is the monster too heavy? */
  75.      wt = inv_weight() + mtmp->data->cwt;
  76.      if (!try_lift(mtmp, ttmp, wt, FALSE))
  77.          return 1;
  78.  
  79.      /* is the monster with inventory too heavy? */
  80.      for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj)
  81.          wt += otmp->owt;
  82.      if (!try_lift(mtmp, ttmp, wt, TRUE))
  83.          return 1;
  84.  
  85.      You("pull %s out of the pit.", mon_nam(mtmp));
  86.      mtmp->mtrapped = 0;
  87.      fill_pit(mtmp->mx, mtmp->my);
  88.      reward_untrap(ttmp, mtmp);
  89.      return 1;
  90.  }
  91.  

untrap

  1.  int
  2.  untrap(force)
  3.  boolean force;
  4.  {
  5.      register struct obj *otmp;
  6.      register int x, y;
  7.      int ch;
  8.      struct trap *ttmp;
  9.      struct monst *mtmp;
  10.      const char *trapdescr;
  11.      boolean here, useplural, confused = (Confusion || Hallucination),
  12.                               trap_skipped = FALSE, deal_with_floor_trap;
  13.      int boxcnt = 0;
  14.      char the_trap[BUFSZ], qbuf[QBUFSZ];
  15.  
  16.      if (!getdir((char *) 0))
  17.          return 0;
  18.      x = u.ux + u.dx;
  19.      y = u.uy + u.dy;
  20.      if (!isok(x, y)) {
  21.          pline_The("perils lurking there are beyond your grasp.");
  22.          return 0;
  23.      }
  24.      ttmp = t_at(x, y);
  25.      if (ttmp && !ttmp->tseen)
  26.          ttmp = 0;
  27.      trapdescr = ttmp ? defsyms[trap_to_defsym(ttmp->ttyp)].explanation : 0;
  28.      here = (x == u.ux && y == u.uy); /* !u.dx && !u.dy */
  29.  
  30.      if (here) /* are there are one or more containers here? */
  31.          for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere)
  32.              if (Is_box(otmp)) {
  33.                  if (++boxcnt > 1)
  34.                      break;
  35.              }
  36.  
  37.      deal_with_floor_trap = can_reach_floor(FALSE);
  38.      if (!deal_with_floor_trap) {
  39.          *the_trap = '\0';
  40.          if (ttmp)
  41.              Strcat(the_trap, an(trapdescr));
  42.          if (ttmp && boxcnt)
  43.              Strcat(the_trap, " and ");
  44.          if (boxcnt)
  45.              Strcat(the_trap, (boxcnt == 1) ? "a container" : "containers");
  46.          useplural = ((ttmp && boxcnt > 0) || boxcnt > 1);
  47.          /* note: boxcnt and useplural will always be 0 for !here case */
  48.          if (ttmp || boxcnt)
  49.              There("%s %s %s but you can't reach %s%s.",
  50.                    useplural ? "are" : "is", the_trap, here ? "here" : "there",
  51.                    useplural ? "them" : "it",
  52.                    u.usteed ? " while mounted" : "");
  53.          trap_skipped = (ttmp != 0);
  54.      } else { /* deal_with_floor_trap */
  55.  
  56.          if (ttmp) {
  57.              Strcpy(the_trap, the(trapdescr));
  58.              if (boxcnt) {
  59.                  if (ttmp->ttyp == PIT || ttmp->ttyp == SPIKED_PIT) {
  60.                      You_cant("do much about %s%s.", the_trap,
  61.                               u.utrap ? " that you're stuck in"
  62.                                       : " while standing on the edge of it");
  63.                      trap_skipped = TRUE;
  64.                      deal_with_floor_trap = FALSE;
  65.                  } else {
  66.                      Sprintf(
  67.                          qbuf, "There %s and %s here. %s %s?",
  68.                          (boxcnt == 1) ? "is a container" : "are containers",
  69.                          an(trapdescr),
  70.                          (ttmp->ttyp == WEB) ? "Remove" : "Disarm", the_trap);
  71.                      switch (ynq(qbuf)) {
  72.                      case 'q':
  73.                          return 0;
  74.                      case 'n':
  75.                          trap_skipped = TRUE;
  76.                          deal_with_floor_trap = FALSE;
  77.                          break;
  78.                      }
  79.                  }
  80.              }
  81.              if (deal_with_floor_trap) {
  82.                  if (u.utrap) {
  83.                      You("cannot deal with %s while trapped%s!", the_trap,
  84.                          (x == u.ux && y == u.uy) ? " in it" : "");
  85.                      return 1;
  86.                  }
  87.                  if ((mtmp = m_at(x, y)) != 0
  88.                      && (mtmp->m_ap_type == M_AP_FURNITURE
  89.                          || mtmp->m_ap_type == M_AP_OBJECT)) {
  90.                      stumble_onto_mimic(mtmp);
  91.                      return 1;
  92.                  }
  93.                  switch (ttmp->ttyp) {
  94.                  case BEAR_TRAP:
  95.                  case WEB:
  96.                      return disarm_holdingtrap(ttmp);
  97.                  case LANDMINE:
  98.                      return disarm_landmine(ttmp);
  99.                  case SQKY_BOARD:
  100.                      return disarm_squeaky_board(ttmp);
  101.                  case DART_TRAP:
  102.                      return disarm_shooting_trap(ttmp, DART);
  103.                  case ARROW_TRAP:
  104.                      return disarm_shooting_trap(ttmp, ARROW);
  105.                  case PIT:
  106.                  case SPIKED_PIT:
  107.                      if (here) {
  108.                          You("are already on the edge of the pit.");
  109.                          return 0;
  110.                      }
  111.                      if (!mtmp) {
  112.                          pline("Try filling the pit instead.");
  113.                          return 0;
  114.                      }
  115.                      return help_monster_out(mtmp, ttmp);
  116.                  default:
  117.                      You("cannot disable %s trap.", !here ? "that" : "this");
  118.                      return 0;
  119.                  }
  120.              }
  121.          } /* end if */
  122.  
  123.          if (boxcnt) {
  124.              for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere)
  125.                  if (Is_box(otmp)) {
  126.                      (void) safe_qbuf(qbuf, "There is ",
  127.                                       " here.  Check it for traps?", otmp,
  128.                                       doname, ansimpleoname, "a box");
  129.                      switch (ynq(qbuf)) {
  130.                      case 'q':
  131.                          return 0;
  132.                      case 'n':
  133.                          continue;
  134.                      }
  135.  
  136.                      if ((otmp->otrapped
  137.                           && (force || (!confused
  138.                                         && rn2(MAXULEV + 1 - u.ulevel) < 10)))
  139.                          || (!force && confused && !rn2(3))) {
  140.                          You("find a trap on %s!", the(xname(otmp)));
  141.                          if (!confused)
  142.                              exercise(A_WIS, TRUE);
  143.  
  144.                          switch (ynq("Disarm it?")) {
  145.                          case 'q':
  146.                              return 1;
  147.                          case 'n':
  148.                              trap_skipped = TRUE;
  149.                              continue;
  150.                          }
  151.  
  152.                          if (otmp->otrapped) {
  153.                              exercise(A_DEX, TRUE);
  154.                              ch = ACURR(A_DEX) + u.ulevel;
  155.                              if (Role_if(PM_ROGUE))
  156.                                  ch *= 2;
  157.                              if (!force && (confused || Fumbling
  158.                                             || rnd(75 + level_difficulty() / 2)
  159.                                                    > ch)) {
  160.                                  (void) chest_trap(otmp, FINGER, TRUE);
  161.                              } else {
  162.                                  You("disarm it!");
  163.                                  otmp->otrapped = 0;
  164.                              }
  165.                          } else
  166.                              pline("That %s was not trapped.", xname(otmp));
  167.                          return 1;
  168.                      } else {
  169.                          You("find no traps on %s.", the(xname(otmp)));
  170.                          return 1;
  171.                      }
  172.                  }
  173.  
  174.              You(trap_skipped ? "find no other traps here."
  175.                               : "know of no traps here.");
  176.              return 0;
  177.          }
  178.  
  179.          if (stumble_on_door_mimic(x, y))
  180.              return 1;
  181.  
  182.      } /* deal_with_floor_trap */
  183.      /* doors can be manipulated even while levitating/unskilled riding */
  184.  
  185.      if (!IS_DOOR(levl[x][y].typ)) {
  186.          if (!trap_skipped)
  187.              You("know of no traps there.");
  188.          return 0;
  189.      }
  190.  
  191.      switch (levl[x][y].doormask) {
  192.      case D_NODOOR:
  193.          You("%s no door there.", Blind ? "feel" : "see");
  194.          return 0;
  195.      case D_ISOPEN:
  196.          pline("This door is safely open.");
  197.          return 0;
  198.      case D_BROKEN:
  199.          pline("This door is broken.");
  200.          return 0;
  201.      }
  202.  
  203.      if ((levl[x][y].doormask & D_TRAPPED
  204.           && (force || (!confused && rn2(MAXULEV - u.ulevel + 11) < 10)))
  205.          || (!force && confused && !rn2(3))) {
  206.          You("find a trap on the door!");
  207.          exercise(A_WIS, TRUE);
  208.          if (ynq("Disarm it?") != 'y')
  209.              return 1;
  210.          if (levl[x][y].doormask & D_TRAPPED) {
  211.              ch = 15 + (Role_if(PM_ROGUE) ? u.ulevel * 3 : u.ulevel);
  212.              exercise(A_DEX, TRUE);
  213.              if (!force && (confused || Fumbling
  214.                             || rnd(75 + level_difficulty() / 2) > ch)) {
  215.                  You("set it off!");
  216.                  b_trapped("door", FINGER);
  217.                  levl[x][y].doormask = D_NODOOR;
  218.                  unblock_point(x, y);
  219.                  newsym(x, y);
  220.                  /* (probably ought to charge for this damage...) */
  221.                  if (*in_rooms(x, y, SHOPBASE))
  222.                      add_damage(x, y, 0L);
  223.              } else {
  224.                  You("disarm it!");
  225.                  levl[x][y].doormask &= ~D_TRAPPED;
  226.              }
  227.          } else
  228.              pline("This door was not trapped.");
  229.          return 1;
  230.      } else {
  231.          You("find no traps on the door.");
  232.          return 1;
  233.      }
  234.  }
  235.  

openholdingtrap

  1.  /* for magic unlocking; returns true if targetted monster (which might
  2.     be hero) gets untrapped; the trap remains intact */
  3.  boolean
  4.  openholdingtrap(mon, noticed)
  5.  struct monst *mon;
  6.  boolean *noticed; /* set to true iff hero notices the effect; */
  7.  {                 /* otherwise left with its previous value intact */
  8.      struct trap *t;
  9.      char buf[BUFSZ];
  10.      const char *trapdescr, *which;
  11.      boolean ishero = (mon == &youmonst);
  12.  
  13.      if (mon == u.usteed)
  14.          ishero = TRUE;
  15.      t = t_at(ishero ? u.ux : mon->mx, ishero ? u.uy : mon->my);
  16.      /* if no trap here or it's not a holding trap, we're done */
  17.      if (!t || (t->ttyp != BEAR_TRAP && t->ttyp != WEB))
  18.          return FALSE;
  19.  
  20.      trapdescr = defsyms[trap_to_defsym(t->ttyp)].explanation;
  21.      which = t->tseen ? the_your[t->madeby_u]
  22.                       : index(vowels, *trapdescr) ? "an" : "a";
  23.  
  24.      if (ishero) {
  25.          if (!u.utrap)
  26.              return FALSE;
  27.          u.utrap = 0; /* released regardless of type */
  28.          *noticed = TRUE;
  29.          /* give message only if trap was the expected type */
  30.          if (u.utraptype == TT_BEARTRAP || u.utraptype == TT_WEB) {
  31.              if (u.usteed)
  32.                  Sprintf(buf, "%s is", noit_Monnam(u.usteed));
  33.              else
  34.                  Strcpy(buf, "You are");
  35.              pline("%s released from %s %s.", buf, which, trapdescr);
  36.          }
  37.      } else {
  38.          if (!mon->mtrapped)
  39.              return FALSE;
  40.          mon->mtrapped = 0;
  41.          if (canspotmon(mon)) {
  42.              *noticed = TRUE;
  43.              pline("%s is released from %s %s.", Monnam(mon), which,
  44.                    trapdescr);
  45.          } else if (cansee(t->tx, t->ty) && t->tseen) {
  46.              *noticed = TRUE;
  47.              if (t->ttyp == WEB)
  48.                  pline("%s is released from %s %s.", Something, which,
  49.                        trapdescr);
  50.              else /* BEAR_TRAP */
  51.                  pline("%s %s opens.", upstart(strcpy(buf, which)), trapdescr);
  52.          }
  53.          /* might pacify monster if adjacent */
  54.          if (rn2(2) && distu(mon->mx, mon->my) <= 2)
  55.              reward_untrap(t, mon);
  56.      }
  57.      return TRUE;
  58.  }
  59.  

closeholdingtrap

  1.  /* for magic locking; returns true if targetted monster (which might
  2.     be hero) gets hit by a trap (might avoid actually becoming trapped) */
  3.  boolean
  4.  closeholdingtrap(mon, noticed)
  5.  struct monst *mon;
  6.  boolean *noticed; /* set to true iff hero notices the effect; */
  7.  {                 /* otherwise left with its previous value intact */
  8.      struct trap *t;
  9.      unsigned dotrapflags;
  10.      boolean ishero = (mon == &youmonst), result;
  11.  
  12.      if (mon == u.usteed)
  13.          ishero = TRUE;
  14.      t = t_at(ishero ? u.ux : mon->mx, ishero ? u.uy : mon->my);
  15.      /* if no trap here or it's not a holding trap, we're done */
  16.      if (!t || (t->ttyp != BEAR_TRAP && t->ttyp != WEB))
  17.          return FALSE;
  18.  
  19.      if (ishero) {
  20.          if (u.utrap)
  21.              return FALSE; /* already trapped */
  22.          *noticed = TRUE;
  23.          dotrapflags = FORCETRAP;
  24.          /* dotrap calls mintrap when mounted hero encounters a web */
  25.          if (u.usteed)
  26.              dotrapflags |= NOWEBMSG;
  27.          ++force_mintrap;
  28.          dotrap(t, dotrapflags);
  29.          --force_mintrap;
  30.          result = (u.utrap != 0);
  31.      } else {
  32.          if (mon->mtrapped)
  33.              return FALSE; /* already trapped */
  34.          /* you notice it if you see the trap close/tremble/whatever
  35.             or if you sense the monster who becomes trapped */
  36.          *noticed = cansee(t->tx, t->ty) || canspotmon(mon);
  37.          ++force_mintrap;
  38.          result = (mintrap(mon) != 0);
  39.          --force_mintrap;
  40.      }
  41.      return result;
  42.  }
  43.  

openfallingtrap

  1.  /* for magic unlocking; returns true if targetted monster (which might
  2.     be hero) gets hit by a trap (target might avoid its effect) */
  3.  boolean
  4.  openfallingtrap(mon, trapdoor_only, noticed)
  5.  struct monst *mon;
  6.  boolean trapdoor_only;
  7.  boolean *noticed; /* set to true iff hero notices the effect; */
  8.  {                 /* otherwise left with its previous value intact */
  9.      struct trap *t;
  10.      boolean ishero = (mon == &youmonst), result;
  11.  
  12.      if (mon == u.usteed)
  13.          ishero = TRUE;
  14.      t = t_at(ishero ? u.ux : mon->mx, ishero ? u.uy : mon->my);
  15.      /* if no trap here or it's not a falling trap, we're done
  16.         (note: falling rock traps have a trapdoor in the ceiling) */
  17.      if (!t || ((t->ttyp != TRAPDOOR && t->ttyp != ROCKTRAP)
  18.                 && (trapdoor_only || (t->ttyp != HOLE && t->ttyp != PIT
  19.                                       && t->ttyp != SPIKED_PIT))))
  20.          return FALSE;
  21.  
  22.      if (ishero) {
  23.          if (u.utrap)
  24.              return FALSE; /* already trapped */
  25.          *noticed = TRUE;
  26.          dotrap(t, FORCETRAP);
  27.          result = (u.utrap != 0);
  28.      } else {
  29.          if (mon->mtrapped)
  30.              return FALSE; /* already trapped */
  31.          /* you notice it if you see the trap close/tremble/whatever
  32.             or if you sense the monster who becomes trapped */
  33.          *noticed = cansee(t->tx, t->ty) || canspotmon(mon);
  34.          /* monster will be angered; mintrap doesn't handle that */
  35.          wakeup(mon);
  36.          ++force_mintrap;
  37.          result = (mintrap(mon) != 0);
  38.          --force_mintrap;
  39.          /* mon might now be on the migrating monsters list */
  40.      }
  41.      return TRUE;
  42.  }
  43.  

chest_trap

  1.  /* only called when the player is doing something to the chest directly */
  2.  boolean
  3.  chest_trap(obj, bodypart, disarm)
  4.  register struct obj *obj;
  5.  register int bodypart;
  6.  boolean disarm;
  7.  {
  8.      register struct obj *otmp = obj, *otmp2;
  9.      char buf[80];
  10.      const char *msg;
  11.      coord cc;
  12.  
  13.      if (get_obj_location(obj, &cc.x, &cc.y, 0)) /* might be carried */
  14.          obj->ox = cc.x, obj->oy = cc.y;
  15.  
  16.      otmp->otrapped = 0; /* trap is one-shot; clear flag first in case
  17.                             chest kills you and ends up in bones file */
  18.      You(disarm ? "set it off!" : "trigger a trap!");
  19.      display_nhwindow(WIN_MESSAGE, FALSE);
  20.      if (Luck > -13 && rn2(13 + Luck) > 7) { /* saved by luck */
  21.          /* trap went off, but good luck prevents damage */
  22.          switch (rn2(13)) {
  23.          case 12:
  24.          case 11:
  25.              msg = "explosive charge is a dud";
  26.              break;
  27.          case 10:
  28.          case 9:
  29.              msg = "electric charge is grounded";
  30.              break;
  31.          case 8:
  32.          case 7:
  33.              msg = "flame fizzles out";
  34.              break;
  35.          case 6:
  36.          case 5:
  37.          case 4:
  38.              msg = "poisoned needle misses";
  39.              break;
  40.          case 3:
  41.          case 2:
  42.          case 1:
  43.          case 0:
  44.              msg = "gas cloud blows away";
  45.              break;
  46.          default:
  47.              impossible("chest disarm bug");
  48.              msg = (char *) 0;
  49.              break;
  50.          }
  51.          if (msg)
  52.              pline("But luckily the %s!", msg);
  53.      } else {
  54.          switch (rn2(20) ? ((Luck >= 13) ? 0 : rn2(13 - Luck)) : rn2(26)) {
  55.          case 25:
  56.          case 24:
  57.          case 23:
  58.          case 22:
  59.          case 21: {
  60.              struct monst *shkp = 0;
  61.              long loss = 0L;
  62.              boolean costly, insider;
  63.              register xchar ox = obj->ox, oy = obj->oy;
  64.  
  65.              /* the obj location need not be that of player */
  66.              costly = (costly_spot(ox, oy)
  67.                        && (shkp = shop_keeper(*in_rooms(ox, oy, SHOPBASE)))
  68.                               != (struct monst *) 0);
  69.              insider = (*u.ushops && inside_shop(u.ux, u.uy)
  70.                         && *in_rooms(ox, oy, SHOPBASE) == *u.ushops);
  71.  
  72.              pline("%s!", Tobjnam(obj, "explode"));
  73.              Sprintf(buf, "exploding %s", xname(obj));
  74.  
  75.              if (costly)
  76.                  loss += stolen_value(obj, ox, oy, (boolean) shkp->mpeaceful,
  77.                                       TRUE);
  78.              delete_contents(obj);
  79.              /* we're about to delete all things at this location,
  80.               * which could include the ball & chain.
  81.               * If we attempt to call unpunish() in the
  82.               * for-loop below we can end up with otmp2
  83.               * being invalid once the chain is gone.
  84.               * Deal with ball & chain right now instead.
  85.               */
  86.              if (Punished && !carried(uball)
  87.                  && ((uchain->ox == u.ux && uchain->oy == u.uy)
  88.                      || (uball->ox == u.ux && uball->oy == u.uy)))
  89.                  unpunish();
  90.  
  91.              for (otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp2) {
  92.                  otmp2 = otmp->nexthere;
  93.                  if (costly)
  94.                      loss += stolen_value(otmp, otmp->ox, otmp->oy,
  95.                                           (boolean) shkp->mpeaceful, TRUE);
  96.                  delobj(otmp);
  97.              }
  98.              wake_nearby();
  99.              losehp(Maybe_Half_Phys(d(6, 6)), buf, KILLED_BY_AN);