Source:NetHack 3.6.0/src/dothrow.c

From NetHackWiki
Jump to: navigation, search

Below is the full text to dothrow.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/dothrow.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	dothrow.c	$NHDT-Date: 1446975465 2015/11/08 09:37:45 $  $NHDT-Branch: master $:$NHDT-Revision: 1.113 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5.  /* Contains code for 't' (throw) */
  6.  
  7.  #include "hack.h"
  8.  
  9.  STATIC_DCL int FDECL(throw_obj, (struct obj *, int));
  10.  STATIC_DCL boolean FDECL(ok_to_throw, (int *));
  11.  STATIC_DCL void NDECL(autoquiver);
  12.  STATIC_DCL int FDECL(gem_accept, (struct monst *, struct obj *));
  13.  STATIC_DCL void FDECL(tmiss, (struct obj *, struct monst *, BOOLEAN_P));
  14.  STATIC_DCL int FDECL(throw_gold, (struct obj *));
  15.  STATIC_DCL void FDECL(check_shop_obj, (struct obj *, XCHAR_P, XCHAR_P,
  16.                                         BOOLEAN_P));
  17.  STATIC_DCL void FDECL(breakmsg, (struct obj *, BOOLEAN_P));
  18.  STATIC_DCL boolean FDECL(toss_up, (struct obj *, BOOLEAN_P));
  19.  STATIC_DCL boolean FDECL(throwing_weapon, (struct obj *));
  20.  STATIC_DCL void FDECL(sho_obj_return_to_u, (struct obj * obj));
  21.  STATIC_DCL boolean FDECL(mhurtle_step, (genericptr_t, int, int));
  22.  
  23.  static NEARDATA const char toss_objs[] = { ALLOW_COUNT, COIN_CLASS,
  24.                                             ALL_CLASSES, WEAPON_CLASS, 0 };
  25.  /* different default choices when wielding a sling (gold must be included) */
  26.  static NEARDATA const char bullets[] = { ALLOW_COUNT, COIN_CLASS, ALL_CLASSES,
  27.                                           GEM_CLASS, 0 };
  28.  
  29.  /* thrownobj (decl.c) tracks an object until it lands */
  30.  
  31.  extern boolean notonhead; /* for long worms */
  32.  

throw_obj

  1.  /* Throw the selected object, asking for direction */
  2.  STATIC_OVL int
  3.  throw_obj(obj, shotlimit)
  4.  struct obj *obj;
  5.  int shotlimit;
  6.  {
  7.      struct obj *otmp;
  8.      int multishot;
  9.      schar skill;
  10.      long wep_mask;
  11.      boolean twoweap, weakmultishot;
  12.  
  13.      /* ask "in what direction?" */
  14.      if (!getdir((char *) 0)) {
  15.          /* No direction specified, so cancel the throw;
  16.           * might need to undo an object split.
  17.           * We used to use freeinv(obj),addinv(obj) here, but that can
  18.           * merge obj into another stack--usually quiver--even if it hadn't
  19.           * been split from there (possibly triggering a panic in addinv),
  20.           * and freeinv+addinv potentially has other side-effects.
  21.           */
  22.          if (obj->o_id == context.objsplit.parent_oid
  23.              || obj->o_id == context.objsplit.child_oid)
  24.              (void) unsplitobj(obj);
  25.          return 0; /* no time passes */
  26.      }
  27.  
  28.      /*
  29.       * Throwing money is usually for getting rid of it when
  30.       * a leprechaun approaches, or for bribing an oncoming
  31.       * angry monster.  So throw the whole object.
  32.       *
  33.       * If the money is in quiver, throw one coin at a time,
  34.       * possibly using a sling.
  35.       */
  36.      if (obj->oclass == COIN_CLASS && obj != uquiver)
  37.          return throw_gold(obj);
  38.  
  39.      if (!canletgo(obj, "throw"))
  40.          return 0;
  41.      if (obj->oartifact == ART_MJOLLNIR && obj != uwep) {
  42.          pline("%s must be wielded before it can be thrown.", The(xname(obj)));
  43.          return 0;
  44.      }
  45.      if ((obj->oartifact == ART_MJOLLNIR && ACURR(A_STR) < STR19(25))
  46.          || (obj->otyp == BOULDER && !throws_rocks(youmonst.data))) {
  47.          pline("It's too heavy.");
  48.          return 1;
  49.      }
  50.      if (!u.dx && !u.dy && !u.dz) {
  51.          You("cannot throw an object at yourself.");
  52.          return 0;
  53.      }
  54.      u_wipe_engr(2);
  55.      if (!uarmg && obj->otyp == CORPSE && touch_petrifies(&mons[obj->corpsenm])
  56.          && !Stone_resistance) {
  57.          You("throw %s with your bare %s.",
  58.              corpse_xname(obj, (const char *) 0, CXN_PFX_THE),
  59.              /* throwing with one hand, but pluralize since the
  60.                 expression "with your bare hands" sounds better */
  61.              makeplural(body_part(HAND)));
  62.          Sprintf(killer.name, "throwing %s bare-handed", killer_xname(obj));
  63.          instapetrify(killer.name);
  64.      }
  65.      if (welded(obj)) {
  66.          weldmsg(obj);
  67.          return 1;
  68.      }
  69.      if (is_wet_towel(obj))
  70.          dry_a_towel(obj, -1, FALSE);
  71.  
  72.      /* Multishot calculations
  73.       * (potential volley of up to N missiles; default for N is 1)
  74.       */
  75.      multishot = 1;
  76.      skill = objects[obj->otyp].oc_skill;
  77.      if (obj->quan > 1L /* no point checking if there's only 1 */
  78.          /* ammo requires corresponding launcher be wielded */
  79.          && (is_ammo(obj) ? matching_launcher(obj, uwep)
  80.                           /* otherwise any stackable (non-ammo) weapon */
  81.                           : obj->oclass == WEAPON_CLASS)
  82.          && !(Confusion || Stunned)) {
  83.          /* some roles don't get a volley bonus until becoming expert */
  84.          weakmultishot = (Role_if(PM_WIZARD) || Role_if(PM_PRIEST)
  85.                           || (Role_if(PM_HEALER) && skill != P_KNIFE)
  86.                           || (Role_if(PM_TOURIST) && skill != -P_DART)
  87.                           /* poor dexterity also inhibits multishot */
  88.                           || Fumbling || ACURR(A_DEX) <= 6);
  89.  
  90.          /* Bonus if the player is proficient in this weapon... */
  91.          switch (P_SKILL(weapon_type(obj))) {
  92.          case P_EXPERT:
  93.              multishot++;
  94.          /*FALLTHRU*/
  95.          case P_SKILLED:
  96.              if (!weakmultishot)
  97.                  multishot++;
  98.              break;
  99.          default: /* basic or unskilled: no bonus */
  100.              break;
  101.          }
  102.          /* ...or is using a special weapon for their role... */
  103.          switch (Role_switch) {
  104.          case PM_CAVEMAN:
  105.              /* give bonus for low-tech gear */
  106.              if (skill == -P_SLING || skill == P_SPEAR)
  107.                  multishot++;
  108.              break;
  109.          case PM_MONK:
  110.              /* allow higher volley count despite skill limitation */
  111.              if (skill == -P_SHURIKEN)
  112.                  multishot++;
  113.              break;
  114.          case PM_RANGER:
  115.              /* arbitrary; encourage use of other missiles beside daggers */
  116.              if (skill != P_DAGGER)
  117.                  multishot++;
  118.              break;
  119.          case PM_ROGUE:
  120.              /* possibly should add knives... */
  121.              if (skill == P_DAGGER)
  122.                  multishot++;
  123.              break;
  124.          case PM_SAMURAI:
  125.              /* role-specific launcher and its ammo */
  126.              if (obj->otyp == YA && uwep && uwep->otyp == YUMI)
  127.                  multishot++;
  128.              break;
  129.          default:
  130.              break; /* No bonus */
  131.          }
  132.          /* ...or using their race's special bow; no bonus for spears */
  133.          if (!weakmultishot)
  134.              switch (Race_switch) {
  135.              case PM_ELF:
  136.                  if (obj->otyp == ELVEN_ARROW && uwep
  137.                      && uwep->otyp == ELVEN_BOW)
  138.                      multishot++;
  139.                  break;
  140.              case PM_ORC:
  141.                  if (obj->otyp == ORCISH_ARROW && uwep
  142.                      && uwep->otyp == ORCISH_BOW)
  143.                      multishot++;
  144.                  break;
  145.              case PM_GNOME:
  146.                  /* arbitrary; there isn't any gnome-specific gear */
  147.                  if (skill == -P_CROSSBOW)
  148.                      multishot++;
  149.                  break;
  150.              case PM_HUMAN:
  151.              case PM_DWARF:
  152.              default:
  153.                  break; /* No bonus */
  154.              }
  155.  
  156.          /* crossbows are slow to load and probably shouldn't allow multiple
  157.             shots at all, but that would result in players never using them;
  158.             instead, high strength is necessary to load and shoot quickly */
  159.          if (multishot > 1 && skill == -P_CROSSBOW
  160.              && ammo_and_launcher(obj, uwep)
  161.              && (int) ACURRSTR < (Race_if(PM_GNOME) ? 16 : 18))
  162.              multishot = rnd(multishot);
  163.  
  164.          multishot = rnd(multishot);
  165.          if ((long) multishot > obj->quan)
  166.              multishot = (int) obj->quan;
  167.          if (shotlimit > 0 && multishot > shotlimit)
  168.              multishot = shotlimit;
  169.      }
  170.  
  171.      m_shot.s = ammo_and_launcher(obj, uwep) ? TRUE : FALSE;
  172.      /* give a message if shooting more than one, or if player
  173.         attempted to specify a count */
  174.      if (multishot > 1 || shotlimit > 0) {
  175.          /* "You shoot N arrows." or "You throw N daggers." */
  176.          You("%s %d %s.", m_shot.s ? "shoot" : "throw",
  177.              multishot, /* (might be 1 if player gave shotlimit) */
  178.              (multishot == 1) ? singular(obj, xname) : xname(obj));
  179.      }
  180.  
  181.      wep_mask = obj->owornmask;
  182.      m_shot.o = obj->otyp;
  183.      m_shot.n = multishot;
  184.      for (m_shot.i = 1; m_shot.i <= m_shot.n; m_shot.i++) {
  185.          twoweap = u.twoweap;
  186.          /* split this object off from its slot if necessary */
  187.          if (obj->quan > 1L) {
  188.              otmp = splitobj(obj, 1L);
  189.          } else {
  190.              otmp = obj;
  191.              if (otmp->owornmask)
  192.                  remove_worn_item(otmp, FALSE);
  193.          }
  194.          freeinv(otmp);
  195.          throwit(otmp, wep_mask, twoweap);
  196.      }
  197.      m_shot.n = m_shot.i = 0;
  198.      m_shot.o = STRANGE_OBJECT;
  199.      m_shot.s = FALSE;
  200.  
  201.      return 1;
  202.  }
  203.  

ok_to_throw

  1.  /* common to dothrow() and dofire() */
  2.  STATIC_OVL boolean
  3.  ok_to_throw(shotlimit_p)
  4.  int *shotlimit_p; /* (see dothrow()) */
  5.  {
  6.      /* kludge to work around parse()'s pre-decrement of `multi' */
  7.      *shotlimit_p = (multi || save_cm) ? multi + 1 : 0;
  8.      multi = 0; /* reset; it's been used up */
  9.  
  10.      if (notake(youmonst.data)) {
  11.          You("are physically incapable of throwing or shooting anything.");
  12.          return FALSE;
  13.      } else if (nohands(youmonst.data)) {
  14.          You_cant("throw or shoot without hands."); /* not body_part(HAND) */
  15.          return FALSE;
  16.          /*[what about !freehand(), aside from cursed missile launcher?]*/
  17.      }
  18.      if (check_capacity((char *) 0))
  19.          return FALSE;
  20.      return TRUE;
  21.  }
  22.  

dothrow

  1.  /* t command - throw */
  2.  int
  3.  dothrow()
  4.  {
  5.      register struct obj *obj;
  6.      int shotlimit;
  7.  
  8.      /*
  9.       * Since some characters shoot multiple missiles at one time,
  10.       * allow user to specify a count prefix for 'f' or 't' to limit
  11.       * number of items thrown (to avoid possibly hitting something
  12.       * behind target after killing it, or perhaps to conserve ammo).
  13.       *
  14.       * Prior to 3.3.0, command ``3t'' meant ``t(shoot) t(shoot) t(shoot)''
  15.       * and took 3 turns.  Now it means ``t(shoot at most 3 missiles)''.
  16.       *
  17.       * [3.6.0:  shot count setup has been moved into ok_to_throw().]
  18.       */
  19.      if (!ok_to_throw(&shotlimit))
  20.          return 0;
  21.  
  22.      obj = getobj(uslinging() ? bullets : toss_objs, "throw");
  23.      /* it is also possible to throw food */
  24.      /* (or jewels, or iron balls... ) */
  25.  
  26.      return obj ? throw_obj(obj, shotlimit) : 0;
  27.  }
  28.  

autoquiver

  1.  /* KMH -- Automatically fill quiver */
  2.  /* Suggested by Jeffrey Bay <jbay@convex.hp.com> */
  3.  static void
  4.  autoquiver()
  5.  {
  6.      struct obj *otmp, *oammo = 0, *omissile = 0, *omisc = 0, *altammo = 0;
  7.  
  8.      if (uquiver)
  9.          return;
  10.  
  11.      /* Scan through the inventory */
  12.      for (otmp = invent; otmp; otmp = otmp->nobj) {
  13.          if (otmp->owornmask || otmp->oartifact || !otmp->dknown) {
  14.              ; /* Skip it */
  15.          } else if (otmp->otyp == ROCK
  16.                     /* seen rocks or known flint or known glass */
  17.                     || (otmp->otyp == FLINT
  18.                         && objects[otmp->otyp].oc_name_known)
  19.                     || (otmp->oclass == GEM_CLASS
  20.                         && objects[otmp->otyp].oc_material == GLASS
  21.                         && objects[otmp->otyp].oc_name_known)) {
  22.              if (uslinging())
  23.                  oammo = otmp;
  24.              else if (ammo_and_launcher(otmp, uswapwep))
  25.                  altammo = otmp;
  26.              else if (!omisc)
  27.                  omisc = otmp;
  28.          } else if (otmp->oclass == GEM_CLASS) {
  29.              ; /* skip non-rock gems--they're ammo but
  30.                   player has to select them explicitly */
  31.          } else if (is_ammo(otmp)) {
  32.              if (ammo_and_launcher(otmp, uwep))
  33.                  /* Ammo matched with launcher (bow+arrow, crossbow+bolt) */
  34.                  oammo = otmp;
  35.              else if (ammo_and_launcher(otmp, uswapwep))
  36.                  altammo = otmp;
  37.              else
  38.                  /* Mismatched ammo (no better than an ordinary weapon) */
  39.                  omisc = otmp;
  40.          } else if (is_missile(otmp)) {
  41.              /* Missile (dart, shuriken, etc.) */
  42.              omissile = otmp;
  43.          } else if (otmp->oclass == WEAPON_CLASS && throwing_weapon(otmp)) {
  44.              /* Ordinary weapon */
  45.              if (objects[otmp->otyp].oc_skill == P_DAGGER && !omissile)
  46.                  omissile = otmp;
  47.              else
  48.                  omisc = otmp;
  49.          }
  50.      }
  51.  
  52.      /* Pick the best choice */
  53.      if (oammo)
  54.          setuqwep(oammo);
  55.      else if (omissile)
  56.          setuqwep(omissile);
  57.      else if (altammo)
  58.          setuqwep(altammo);
  59.      else if (omisc)
  60.          setuqwep(omisc);
  61.  
  62.      return;
  63.  }
  64.  

dofire

  1.  /* f command -- fire: throw from the quiver */
  2.  int
  3.  dofire()
  4.  {
  5.      int shotlimit;
  6.      struct obj *obj;
  7.  
  8.      /*
  9.       * Same as dothrow(), except we use quivered missile instead
  10.       * of asking what to throw/shoot.
  11.       *
  12.       * If quiver is empty, we use autoquiver to fill it when the
  13.       * corresponding option is on.  If the option is off or if
  14.       * autoquiver doesn't select anything, we ask what to throw.
  15.       * For the last, if player's response is a stack, we put
  16.       * that stack into quiver slot provided it's not wielded.
  17.       */
  18.      if (!ok_to_throw(&shotlimit))
  19.          return 0;
  20.  
  21.      if ((obj = uquiver) == 0) {
  22.          if (!flags.autoquiver) {
  23.              You("have no ammunition readied.");
  24.          } else {
  25.              autoquiver();
  26.              if ((obj = uquiver) == 0)
  27.                  You("have nothing appropriate for your quiver.");
  28.          }
  29.          /* if autoquiver is disabled or has failed, prompt for missile;
  30.             fill quiver with it if it's not wielded */
  31.          if (!obj) {
  32.              obj = getobj(uslinging() ? bullets : toss_objs, "throw");
  33.              /* Q command doesn't allow gold in quiver */
  34.              if (obj && !obj->owornmask && obj->oclass != COIN_CLASS)
  35.                  setuqwep(obj); /* demi-autoquiver */
  36.          }
  37.          /* give feedback if quiver has now been filled */
  38.          if (uquiver) {
  39.              uquiver->owornmask &= ~W_QUIVER; /* less verbose */
  40.              prinv("You ready:", uquiver, 0L);
  41.              uquiver->owornmask |= W_QUIVER;
  42.          }
  43.      }
  44.  
  45.      return obj ? throw_obj(obj, shotlimit) : 0;
  46.  }
  47.  

endmultishot

  1.  /* if in midst of multishot shooting/throwing, stop early */
  2.  void
  3.  endmultishot(verbose)
  4.  boolean verbose;
  5.  {
  6.      if (m_shot.i < m_shot.n) {
  7.          if (verbose && !context.mon_moving) {
  8.              You("stop %s after the %d%s %s.",
  9.                  m_shot.s ? "firing" : "throwing", m_shot.i, ordin(m_shot.i),
  10.                  m_shot.s ? "shot" : "toss");
  11.          }
  12.          m_shot.n = m_shot.i; /* make current shot be the last */
  13.      }
  14.  }
  15.  

hitfloor

  1.  /*
  2.   * Object hits floor at hero's feet.  Called from drop() and throwit().
  3.   */
  4.  void
  5.  hitfloor(obj)
  6.  register struct obj *obj;
  7.  {
  8.      if (IS_SOFT(levl[u.ux][u.uy].typ) || u.uinwater) {
  9.          dropy(obj);
  10.          return;
  11.      }
  12.      if (IS_ALTAR(levl[u.ux][u.uy].typ))
  13.          doaltarobj(obj);
  14.      else
  15.          pline("%s hit%s the %s.", Doname2(obj), (obj->quan == 1L) ? "s" : "",
  16.                surface(u.ux, u.uy));
  17.  
  18.      if (hero_breaks(obj, u.ux, u.uy, TRUE))
  19.          return;
  20.      if (ship_object(obj, u.ux, u.uy, FALSE))
  21.          return;
  22.      dropz(obj, TRUE);
  23.  }
  24.  

walk_path

  1.  /*
  2.   * Walk a path from src_cc to dest_cc, calling a proc for each location
  3.   * except the starting one.  If the proc returns FALSE, stop walking
  4.   * and return FALSE.  If stopped early, dest_cc will be the location
  5.   * before the failed callback.
  6.   */
  7.  boolean
  8.  walk_path(src_cc, dest_cc, check_proc, arg)
  9.  coord *src_cc;
  10.  coord *dest_cc;
  11.  boolean FDECL((*check_proc), (genericptr_t, int, int));
  12.  genericptr_t arg;
  13.  {
  14.      int x, y, dx, dy, x_change, y_change, err, i, prev_x, prev_y;
  15.      boolean keep_going = TRUE;
  16.  
  17.      /* Use Bresenham's Line Algorithm to walk from src to dest */
  18.      dx = dest_cc->x - src_cc->x;
  19.      dy = dest_cc->y - src_cc->y;
  20.      prev_x = x = src_cc->x;
  21.      prev_y = y = src_cc->y;
  22.  
  23.      if (dx < 0) {
  24.          x_change = -1;
  25.          dx = -dx;
  26.      } else
  27.          x_change = 1;
  28.      if (dy < 0) {
  29.          y_change = -1;
  30.          dy = -dy;
  31.      } else
  32.          y_change = 1;
  33.  
  34.      i = err = 0;
  35.      if (dx < dy) {
  36.          while (i++ < dy) {
  37.              prev_x = x;
  38.              prev_y = y;
  39.              y += y_change;
  40.              err += dx << 1;
  41.              if (err > dy) {
  42.                  x += x_change;
  43.                  err -= dy << 1;
  44.              }
  45.              /* check for early exit condition */
  46.              if (!(keep_going = (*check_proc)(arg, x, y)))
  47.                  break;
  48.          }
  49.      } else {
  50.          while (i++ < dx) {
  51.              prev_x = x;
  52.              prev_y = y;
  53.              x += x_change;
  54.              err += dy << 1;
  55.              if (err > dx) {
  56.                  y += y_change;
  57.                  err -= dx << 1;
  58.              }
  59.              /* check for early exit condition */
  60.              if (!(keep_going = (*check_proc)(arg, x, y)))
  61.                  break;
  62.          }
  63.      }
  64.  
  65.      if (keep_going)
  66.          return TRUE; /* successful */
  67.  
  68.      dest_cc->x = prev_x;
  69.      dest_cc->y = prev_y;
  70.      return FALSE;
  71.  }
  72.  

hurtle_step

  1.  /*
  2.   * Single step for the hero flying through the air from jumping, flying,
  3.   * etc.  Called from hurtle() and jump() via walk_path().  We expect the
  4.   * argument to be a pointer to an integer -- the range -- which is
  5.   * used in the calculation of points off if we hit something.
  6.   *
  7.   * Bumping into monsters won't cause damage but will wake them and make
  8.   * them angry.  Auto-pickup isn't done, since you don't have control over
  9.   * your movements at the time.
  10.   *
  11.   * Possible additions/changes:
  12.   *      o really attack monster if we hit one
  13.   *      o set stunned if we hit a wall or door
  14.   *      o reset nomul when we stop
  15.   *      o creepy feeling if pass through monster (if ever implemented...)
  16.   *      o bounce off walls
  17.   *      o let jumps go over boulders
  18.   */
  19.  boolean
  20.  hurtle_step(arg, x, y)
  21.  genericptr_t arg;
  22.  int x, y;
  23.  {
  24.      int ox, oy, *range = (int *) arg;
  25.      struct obj *obj;
  26.      struct monst *mon;
  27.      boolean may_pass = TRUE;
  28.      struct trap *ttmp;
  29.      int dmg = 0;
  30.  
  31.      if (!isok(x, y)) {
  32.          You_feel("the spirits holding you back.");
  33.          return FALSE;
  34.      } else if (!in_out_region(x, y)) {
  35.          return FALSE;
  36.      } else if (*range == 0) {
  37.          return FALSE; /* previous step wants to stop now */
  38.      }
  39.  
  40.      if (!Passes_walls || !(may_pass = may_passwall(x, y))) {
  41.          if (IS_ROCK(levl[x][y].typ) || closed_door(x, y)) {
  42.              const char *s;
  43.  
  44.              pline("Ouch!");
  45.              if (IS_TREE(levl[x][y].typ))
  46.                  s = "bumping into a tree";
  47.              else if (IS_ROCK(levl[x][y].typ))
  48.                  s = "bumping into a wall";
  49.              else
  50.                  s = "bumping into a door";
  51.              dmg = rnd(2 + *range);
  52.              losehp(Maybe_Half_Phys(dmg), s, KILLED_BY);
  53.              wake_nearto(x,y, 10);
  54.              return FALSE;
  55.          }
  56.          if (levl[x][y].typ == IRONBARS) {
  57.              You("crash into some iron bars.  Ouch!");
  58.              dmg = rnd(2 + *range);
  59.              losehp(Maybe_Half_Phys(dmg), "crashing into iron bars",
  60.                     KILLED_BY);
  61.              wake_nearto(x,y, 20);
  62.              return FALSE;
  63.          }
  64.          if ((obj = sobj_at(BOULDER, x, y)) != 0) {
  65.              You("bump into a %s.  Ouch!", xname(obj));
  66.              dmg = rnd(2 + *range);
  67.              losehp(Maybe_Half_Phys(dmg), "bumping into a boulder", KILLED_BY);
  68.              wake_nearto(x,y, 10);
  69.              return FALSE;
  70.          }
  71.          if (!may_pass) {
  72.              /* did we hit a no-dig non-wall position? */
  73.              You("smack into something!");
  74.              dmg = rnd(2 + *range);
  75.              losehp(Maybe_Half_Phys(dmg), "touching the edge of the universe",
  76.                     KILLED_BY);
  77.              wake_nearto(x,y, 10);
  78.              return FALSE;
  79.          }
  80.          if ((u.ux - x) && (u.uy - y) && bad_rock(youmonst.data, u.ux, y)
  81.              && bad_rock(youmonst.data, x, u.uy)) {
  82.              boolean too_much =
  83.                  (invent && (inv_weight() + weight_cap() > 600));
  84.              /* Move at a diagonal. */
  85.              if (bigmonst(youmonst.data) || too_much) {
  86.                  You("%sget forcefully wedged into a crevice.",
  87.                      too_much ? "and all your belongings " : "");
  88.                  dmg = rnd(2 + *range);
  89.                  losehp(Maybe_Half_Phys(dmg), "wedging into a narrow crevice",
  90.                         KILLED_BY);
  91.                  wake_nearto(x,y, 10);
  92.                  return FALSE;
  93.              }
  94.          }
  95.      }
  96.  
  97.      if ((mon = m_at(x, y)) != 0) {
  98.          You("bump into %s.", a_monnam(mon));
  99.          wakeup(mon);
  100.          wake_nearto(x,y, 10);
  101.          return FALSE;
  102.      }
  103.      if ((u.ux - x) && (u.uy - y) && bad_rock(youmonst.data, u.ux, y)
  104.          && bad_rock(youmonst.data, x, u.uy)) {
  105.          /* Move at a diagonal. */
  106.          if (Sokoban) {
  107.              You("come to an abrupt halt!");
  108.              return FALSE;
  109.          }
  110.      }
  111.  
  112.      ox = u.ux;
  113.      oy = u.uy;
  114.      u_on_newpos(x, y); /* set u.<ux,uy>, u.usteed-><mx,my>; cliparound(); */
  115.      newsym(ox, oy);    /* update old position */
  116.      vision_recalc(1);  /* update for new position */
  117.      flush_screen(1);
  118.      /* FIXME:
  119.       * Each trap should really trigger on the recoil if
  120.       * it would trigger during normal movement. However,
  121.       * not all the possible side-effects of this are
  122.       * tested [as of 3.4.0] so we trigger those that
  123.       * we have tested, and offer a message for the
  124.       * ones that we have not yet tested.
  125.       */
  126.      if ((ttmp = t_at(x, y)) != 0) {
  127.          if (ttmp->ttyp == MAGIC_PORTAL) {
  128.              dotrap(ttmp, 0);
  129.              return FALSE;
  130.          } else if (ttmp->ttyp == VIBRATING_SQUARE) {
  131.              pline("The ground vibrates as you pass it.");
  132.              dotrap(ttmp, 0); /* doesn't print messages */
  133.          } else if (ttmp->ttyp == FIRE_TRAP) {
  134.              dotrap(ttmp, 0);
  135.          } else if ((ttmp->ttyp == PIT || ttmp->ttyp == SPIKED_PIT
  136.                      || ttmp->ttyp == HOLE || ttmp->ttyp == TRAPDOOR)
  137.                     && Sokoban) {
  138.              /* Air currents overcome the recoil */
  139.              dotrap(ttmp, 0);
  140.              *range = 0;
  141.              return TRUE;
  142.          } else {
  143.              if (ttmp->tseen)
  144.                  You("pass right over %s.",
  145.                      an(defsyms[trap_to_defsym(ttmp->ttyp)].explanation));
  146.          }
  147.      }
  148.      if (--*range < 0) /* make sure our range never goes negative */
  149.          *range = 0;
  150.      if (*range != 0)
  151.          delay_output();
  152.      return TRUE;
  153.  }
  154.  

mhurtle_step

  1.  STATIC_OVL boolean
  2.  mhurtle_step(arg, x, y)
  3.  genericptr_t arg;
  4.  int x, y;
  5.  {
  6.      struct monst *mon = (struct monst *) arg;
  7.  
  8.      /* TODO: Treat walls, doors, iron bars, pools, lava, etc. specially
  9.       * rather than just stopping before.
  10.       */
  11.      if (goodpos(x, y, mon, 0) && m_in_out_region(mon, x, y)) {
  12.          remove_monster(mon->mx, mon->my);
  13.          newsym(mon->mx, mon->my);
  14.          place_monster(mon, x, y);
  15.          newsym(mon->mx, mon->my);
  16.          set_apparxy(mon);
  17.          (void) mintrap(mon);
  18.          return TRUE;
  19.      }
  20.      return FALSE;
  21.  }
  22.  

hurtle

  1.  /*
  2.   * The player moves through the air for a few squares as a result of
  3.   * throwing or kicking something.
  4.   *
  5.   * dx and dy should be the direction of the hurtle, not of the original
  6.   * kick or throw and be only.
  7.   */
  8.  void
  9.  hurtle(dx, dy, range, verbose)
  10.  int dx, dy, range;
  11.  boolean verbose;
  12.  {
  13.      coord uc, cc;
  14.  
  15.      /* The chain is stretched vertically, so you shouldn't be able to move
  16.       * very far diagonally.  The premise that you should be able to move one
  17.       * spot leads to calculations that allow you to only move one spot away
  18.       * from the ball, if you are levitating over the ball, or one spot
  19.       * towards the ball, if you are at the end of the chain.  Rather than
  20.       * bother with all of that, assume that there is no slack in the chain
  21.       * for diagonal movement, give the player a message and return.
  22.       */
  23.      if (Punished && !carried(uball)) {
  24.          You_feel("a tug from the iron ball.");
  25.          nomul(0);
  26.          return;
  27.      } else if (u.utrap) {
  28.          You("are anchored by the %s.",
  29.              u.utraptype == TT_WEB
  30.                  ? "web"
  31.                  : u.utraptype == TT_LAVA
  32.                        ? "lava"
  33.                        : u.utraptype == TT_INFLOOR
  34.                              ? surface(u.ux, u.uy)
  35.                              : u.utraptype == TT_BURIEDBALL ? "buried ball"
  36.                                                             : "trap");
  37.          nomul(0);
  38.          return;
  39.      }
  40.  
  41.      /* make sure dx and dy are [-1,0,1] */
  42.      dx = sgn(dx);
  43.      dy = sgn(dy);
  44.  
  45.      if (!range || (!dx && !dy) || u.ustuck)
  46.          return; /* paranoia */
  47.  
  48.      nomul(-range);
  49.      multi_reason = "moving through the air";
  50.      nomovemsg = ""; /* it just happens */
  51.      if (verbose)
  52.          You("%s in the opposite direction.", range > 1 ? "hurtle" : "float");
  53.      /* if we're in the midst of shooting multiple projectiles, stop */
  54.      endmultishot(TRUE);
  55.      sokoban_guilt();
  56.      uc.x = u.ux;
  57.      uc.y = u.uy;
  58.      /* this setting of cc is only correct if dx and dy are [-1,0,1] only */
  59.      cc.x = u.ux + (dx * range);
  60.      cc.y = u.uy + (dy * range);
  61.      (void) walk_path(&uc, &cc, hurtle_step, (genericptr_t) &range);
  62.  }
  63.  

mhurtle

  1.  /* Move a monster through the air for a few squares.
  2.   */
  3.  void
  4.  mhurtle(mon, dx, dy, range)
  5.  struct monst *mon;
  6.  int dx, dy, range;
  7.  {
  8.      coord mc, cc;
  9.  
  10.      /* At the very least, debilitate the monster */
  11.      mon->movement = 0;
  12.      mon->mstun = 1;
  13.  
  14.      /* Is the monster stuck or too heavy to push?
  15.       * (very large monsters have too much inertia, even floaters and flyers)
  16.       */
  17.      if (mon->data->msize >= MZ_HUGE || mon == u.ustuck || mon->mtrapped)
  18.          return;
  19.  
  20.      /* Make sure dx and dy are [-1,0,1] */
  21.      dx = sgn(dx);
  22.      dy = sgn(dy);
  23.      if (!range || (!dx && !dy))
  24.          return; /* paranoia */
  25.      /* don't let grid bugs be hurtled diagonally */
  26.      if (dx && dy && NODIAG(monsndx(mon->data)))
  27.          return;
  28.  
  29.      /* Send the monster along the path */
  30.      mc.x = mon->mx;
  31.      mc.y = mon->my;
  32.      cc.x = mon->mx + (dx * range);
  33.      cc.y = mon->my + (dy * range);
  34.      (void) walk_path(&mc, &cc, mhurtle_step, (genericptr_t) mon);
  35.      return;
  36.  }
  37.  

check_shop_obj

  1.  STATIC_OVL void
  2.  check_shop_obj(obj, x, y, broken)
  3.  struct obj *obj;
  4.  xchar x, y;
  5.  boolean broken;
  6.  {
  7.      struct monst *shkp = shop_keeper(*u.ushops);
  8.  
  9.      if (!shkp)
  10.          return;
  11.  
  12.      if (broken || !costly_spot(x, y)
  13.          || *in_rooms(x, y, SHOPBASE) != *u.ushops) {
  14.          /* thrown out of a shop or into a different shop */
  15.          if (is_unpaid(obj))
  16.              (void) stolen_value(obj, u.ux, u.uy, (boolean) shkp->mpeaceful,
  17.                                  FALSE);
  18.          if (broken)
  19.              obj->no_charge = 1;
  20.      } else {
  21.          if (costly_spot(u.ux, u.uy) && costly_spot(x, y)) {
  22.              if (is_unpaid(obj))
  23.                  subfrombill(obj, shkp);
  24.              else if (x != shkp->mx || y != shkp->my)
  25.                  sellobj(obj, x, y);
  26.          }
  27.      }
  28.  }
  29.  

toss_up

  1.  /*
  2.   * Hero tosses an object upwards with appropriate consequences.
  3.   *
  4.   * Returns FALSE if the object is gone.
  5.   */
  6.  STATIC_OVL boolean
  7.  toss_up(obj, hitsroof)
  8.  struct obj *obj;
  9.  boolean hitsroof;
  10.  {
  11.      const char *action;
  12.      boolean petrifier = ((obj->otyp == EGG || obj->otyp == CORPSE)
  13.                           && touch_petrifies(&mons[obj->corpsenm]));
  14.      /* note: obj->quan == 1 */
  15.  
  16.      if (!has_ceiling(&u.uz)) {
  17.          action = "flies up into"; /* into "the sky" or "the water above" */
  18.      } else if (hitsroof) {
  19.          if (breaktest(obj)) {
  20.              pline("%s hits the %s.", Doname2(obj), ceiling(u.ux, u.uy));
  21.              breakmsg(obj, !Blind);
  22.              breakobj(obj, u.ux, u.uy, TRUE, TRUE);
  23.              return FALSE;
  24.          }
  25.          action = "hits";
  26.      } else {
  27.          action = "almost hits";
  28.      }
  29.      pline("%s %s the %s, then falls back on top of your %s.", Doname2(obj),
  30.            action, ceiling(u.ux, u.uy), body_part(HEAD));
  31.  
  32.      /* object now hits you */
  33.  
  34.      if (obj->oclass == POTION_CLASS) {
  35.          potionhit(&youmonst, obj, TRUE);
  36.      } else if (breaktest(obj)) {
  37.          int otyp = obj->otyp;
  38.          int blindinc;
  39.  
  40.          /* need to check for blindness result prior to destroying obj */
  41.          blindinc = ((otyp == CREAM_PIE || otyp == BLINDING_VENOM)
  42.                      /* AT_WEAP is ok here even if attack type was AT_SPIT */
  43.                      && can_blnd(&youmonst, &youmonst, AT_WEAP, obj))
  44.                         ? rnd(25)
  45.                         : 0;
  46.          breakmsg(obj, !Blind);
  47.          breakobj(obj, u.ux, u.uy, TRUE, TRUE);
  48.          obj = 0; /* it's now gone */
  49.          switch (otyp) {
  50.          case EGG:
  51.              if (petrifier && !Stone_resistance
  52.                  && !(poly_when_stoned(youmonst.data)
  53.                       && polymon(PM_STONE_GOLEM))) {
  54.                  /* egg ends up "all over your face"; perhaps
  55.                     visored helmet should still save you here */
  56.                  if (uarmh)
  57.                      Your("%s fails to protect you.", helm_simple_name(uarmh));
  58.                  goto petrify;
  59.              }
  60.          case CREAM_PIE:
  61.          case BLINDING_VENOM:
  62.              pline("You've got it all over your %s!", body_part(FACE));
  63.              if (blindinc) {
  64.                  if (otyp == BLINDING_VENOM && !Blind)
  65.                      pline("It blinds you!");
  66.                  u.ucreamed += blindinc;
  67.                  make_blinded(Blinded + (long) blindinc, FALSE);
  68.                  if (!Blind)
  69.                      Your1(vision_clears);
  70.              }
  71.              break;
  72.          default:
  73.              break;
  74.          }
  75.          return FALSE;
  76.      } else { /* neither potion nor other breaking object */
  77.          boolean less_damage = uarmh && is_metallic(uarmh), artimsg = FALSE;
  78.          int dmg = dmgval(obj, &youmonst);
  79.  
  80.          if (obj->oartifact)
  81.              /* need a fake die roll here; rn1(18,2) avoids 1 and 20 */
  82.              artimsg = artifact_hit((struct monst *) 0, &youmonst, obj, &dmg,
  83.                                     rn1(18, 2));
  84.  
  85.          if (!dmg) { /* probably wasn't a weapon; base damage on weight */
  86.              dmg = (int) obj->owt / 100;
  87.              if (dmg < 1)
  88.                  dmg = 1;
  89.              else if (dmg > 6)
  90.                  dmg = 6;
  91.              if (youmonst.data == &mons[PM_SHADE]
  92.                  && objects[obj->otyp].oc_material != SILVER)
  93.                  dmg = 0;
  94.          }
  95.          if (dmg > 1 && less_damage)
  96.              dmg = 1;
  97.          if (dmg > 0)
  98.              dmg += u.udaminc;
  99.          if (dmg < 0)
  100.              dmg = 0; /* beware negative rings of increase damage */
  101.          dmg = Maybe_Half_Phys(dmg);
  102.  
  103.          if (uarmh) {
  104.              if (less_damage && dmg < (Upolyd ? u.mh : u.uhp)) {
  105.                  if (!artimsg)
  106.                      pline("Fortunately, you are wearing a hard helmet.");
  107.                  /* helmet definitely protects you when it blocks petrification
  108.                   */
  109.              } else if (!petrifier) {
  110.                  if (flags.verbose)
  111.                      Your("%s does not protect you.", helm_simple_name(uarmh));
  112.              }
  113.          } else if (petrifier && !Stone_resistance
  114.                     && !(poly_when_stoned(youmonst.data)
  115.                          && polymon(PM_STONE_GOLEM))) {
  116.          petrify:
  117.              killer.format = KILLED_BY;
  118.              Strcpy(killer.name, "elementary physics"); /* "what goes up..." */
  119.              You("turn to stone.");
  120.              if (obj)
  121.                  dropy(obj); /* bypass most of hitfloor() */
  122.              thrownobj = 0;  /* now either gone or on floor */
  123.              done(STONING);
  124.              return obj ? TRUE : FALSE;
  125.          }
  126.          hitfloor(obj);
  127.          thrownobj = 0;
  128.          losehp(Maybe_Half_Phys(dmg), "falling object", KILLED_BY_AN);
  129.      }
  130.      return TRUE;
  131.  }
  132.  

throwing_weapon

  1.  /* return true for weapon meant to be thrown; excludes ammo */
  2.  STATIC_OVL boolean
  3.  throwing_weapon(obj)
  4.  struct obj *obj;
  5.  {
  6.      return (boolean) (is_missile(obj) || is_spear(obj)
  7.                        /* daggers and knife (excludes scalpel) */
  8.                        || (is_blade(obj) && !is_sword(obj)
  9.                            && (objects[obj->otyp].oc_dir & PIERCE))
  10.                        /* special cases [might want to add AXE] */
  11.                        || obj->otyp == WAR_HAMMER || obj->otyp == AKLYS);
  12.  }
  13.  

sho_obj_return_to_u

  1.  /* the currently thrown object is returning to you (not for boomerangs) */
  2.  STATIC_OVL void
  3.  sho_obj_return_to_u(obj)
  4.  struct obj *obj;
  5.  {
  6.      /* might already be our location (bounced off a wall) */
  7.      if (bhitpos.x != u.ux || bhitpos.y != u.uy) {
  8.          int x = bhitpos.x - u.dx, y = bhitpos.y - u.dy;
  9.  
  10.          tmp_at(DISP_FLASH, obj_to_glyph(obj));
  11.          while (x != u.ux || y != u.uy) {
  12.              tmp_at(x, y);
  13.              delay_output();
  14.              x -= u.dx;
  15.              y -= u.dy;
  16.          }
  17.          tmp_at(DISP_END, 0);
  18.      }
  19.  }
  20.  

throwit

  1.  /* throw an object, NB: obj may be consumed in the process */
  2.  void
  3.  throwit(obj, wep_mask, twoweap)
  4.  struct obj *obj;
  5.  long wep_mask; /* used to re-equip returning boomerang */
  6.  boolean
  7.      twoweap; /* used to restore twoweapon mode if wielded weapon returns */
  8.  {
  9.      register struct monst *mon;
  10.      register int range, urange;
  11.      boolean crossbowing, impaired = (Confusion || Stunned || Blind
  12.                                       || Hallucination || Fumbling);
  13.  
  14.      notonhead = FALSE; /* reset potentially stale value */
  15.      if ((obj->cursed || obj->greased) && (u.dx || u.dy) && !rn2(7)) {
  16.          boolean slipok = TRUE;
  17.          if (ammo_and_launcher(obj, uwep))
  18.              pline("%s!", Tobjnam(obj, "misfire"));
  19.          else {
  20.              /* only slip if it's greased or meant to be thrown */
  21.              if (obj->greased || throwing_weapon(obj))
  22.                  /* BUG: this message is grammatically incorrect if obj has
  23.                     a plural name; greased gloves or boots for instance. */
  24.                  pline("%s as you throw it!", Tobjnam(obj, "slip"));
  25.              else
  26.                  slipok = FALSE;
  27.          }
  28.          if (slipok) {
  29.              u.dx = rn2(3) - 1;
  30.              u.dy = rn2(3) - 1;
  31.              if (!u.dx && !u.dy)
  32.                  u.dz = 1;
  33.              impaired = TRUE;
  34.          }
  35.      }
  36.  
  37.      if ((u.dx || u.dy || (u.dz < 1))
  38.          && calc_capacity((int) obj->owt) > SLT_ENCUMBER
  39.          && (Upolyd ? (u.mh < 5 && u.mh != u.mhmax)
  40.                     : (u.uhp < 10 && u.uhp != u.uhpmax))
  41.          && obj->owt > (unsigned) ((Upolyd ? u.mh : u.uhp) * 2)
  42.          && !Is_airlevel(&u.uz)) {
  43.          You("have so little stamina, %s drops from your grasp.",
  44.              the(xname(obj)));
  45.          exercise(A_CON, FALSE);
  46.          u.dx = u.dy = 0;
  47.          u.dz = 1;
  48.      }
  49.  
  50.      thrownobj = obj;
  51.      thrownobj->was_thrown = 1;
  52.  
  53.      if (u.uswallow) {
  54.          mon = u.ustuck;
  55.          bhitpos.x = mon->mx;
  56.          bhitpos.y = mon->my;
  57.      } else if (u.dz) {
  58.          if (u.dz < 0 && Role_if(PM_VALKYRIE) && obj->oartifact == ART_MJOLLNIR
  59.              && !impaired) {
  60.              pline("%s the %s and returns to your hand!", Tobjnam(obj, "hit"),
  61.                    ceiling(u.ux, u.uy));
  62.              obj = addinv(obj);
  63.              (void) encumber_msg();
  64.              setuwep(obj);
  65.              u.twoweap = twoweap;
  66.          } else if (u.dz < 0) {
  67.              (void) toss_up(obj, rn2(5) && !Underwater);
  68.          } else if (u.dz > 0 && u.usteed && obj->oclass == POTION_CLASS
  69.                     && rn2(6)) {
  70.              /* alternative to prayer or wand of opening/spell of knock
  71.                 for dealing with cursed saddle:  throw holy water > */
  72.              potionhit(u.usteed, obj, TRUE);
  73.          } else {
  74.              hitfloor(obj);
  75.          }
  76.          thrownobj = (struct obj *) 0;
  77.          return;
  78.  
  79.      } else if (obj->otyp == BOOMERANG && !Underwater) {
  80.          if (Is_airlevel(&u.uz) || Levitation)
  81.              hurtle(-u.dx, -u.dy, 1, TRUE);
  82.          mon = boomhit(obj, u.dx, u.dy);
  83.          if (mon == &youmonst) { /* the thing was caught */
  84.              exercise(A_DEX, TRUE);
  85.              obj = addinv(obj);
  86.              (void) encumber_msg();
  87.              if (wep_mask && !(obj->owornmask & wep_mask)) {
  88.                  setworn(obj, wep_mask);
  89.                  u.twoweap = twoweap;
  90.              }
  91.              thrownobj = (struct obj *) 0;
  92.              return;
  93.          }
  94.      } else {
  95.          /* crossbow range is independent of strength */
  96.          crossbowing =
  97.              (ammo_and_launcher(obj, uwep) && weapon_type(uwep) == P_CROSSBOW);
  98.          urange = (crossbowing ? 18 : (int) ACURRSTR) / 2;
  99.          /* balls are easy to throw or at least roll;
  100.           * also, this insures the maximum range of a ball is greater
  101.           * than 1, so the effects from throwing attached balls are
  102.           * actually possible
  103.           */
  104.          if (obj->otyp == HEAVY_IRON_BALL)
  105.              range = urange - (int) (obj->owt / 100);
  106.          else
  107.              range = urange - (int) (obj->owt / 40);
  108.          if (obj == uball) {
  109.              if (u.ustuck)
  110.                  range = 1;
  111.              else if (range >= 5)
  112.                  range = 5;
  113.          }
  114.          if (range < 1)
  115.              range = 1;
  116.  
  117.          if (is_ammo(obj)) {
  118.              if (ammo_and_launcher(obj, uwep)) {
  119.                  if (crossbowing)
  120.                      range = BOLT_LIM;
  121.                  else
  122.                      range++;
  123.              } else if (obj->oclass != GEM_CLASS)
  124.                  range /= 2;
  125.          }
  126.  
  127.          if (Is_airlevel(&u.uz) || Levitation) {
  128.              /* action, reaction... */
  129.              urange -= range;
  130.              if (urange < 1)
  131.                  urange = 1;
  132.              range -= urange;
  133.              if (range < 1)
  134.                  range = 1;
  135.          }
  136.  
  137.          if (obj->otyp == BOULDER)
  138.              range = 20; /* you must be giant */
  139.          else if (obj->oartifact == ART_MJOLLNIR)
  140.              range = (range + 1) / 2; /* it's heavy */
  141.          else if (obj == uball && u.utrap && u.utraptype == TT_INFLOOR)
  142.              range = 1;
  143.  
  144.          if (Underwater)
  145.              range = 1;
  146.  
  147.          mon = bhit(u.dx, u.dy, range, THROWN_WEAPON,
  148.                     (int FDECL((*), (MONST_P, OBJ_P))) 0,
  149.                     (int FDECL((*), (OBJ_P, OBJ_P))) 0, &obj);
  150.          thrownobj = obj; /* obj may be null now */
  151.  
  152.          /* have to do this after bhit() so u.ux & u.uy are correct */
  153.          if (Is_airlevel(&u.uz) || Levitation)
  154.              hurtle(-u.dx, -u.dy, urange, TRUE);
  155.  
  156.          if (!obj)
  157.              return;
  158.      }
  159.  
  160.      if (mon) {
  161.          boolean obj_gone;
  162.  
  163.          if (mon->isshk && obj->where == OBJ_MINVENT && obj->ocarry == mon) {
  164.              thrownobj = (struct obj *) 0;
  165.              return; /* alert shk caught it */
  166.          }
  167.          (void) snuff_candle(obj);
  168.          notonhead = (bhitpos.x != mon->mx || bhitpos.y != mon->my);
  169.          obj_gone = thitmonst(mon, obj);
  170.          /* Monster may have been tamed; this frees old mon */
  171.          mon = m_at(bhitpos.x, bhitpos.y);
  172.  
  173.          /* [perhaps this should be moved into thitmonst or hmon] */
  174.          if (mon && mon->isshk
  175.              && (!inside_shop(u.ux, u.uy)
  176.                  || !index(in_rooms(mon->mx, mon->my, SHOPBASE), *u.ushops)))
  177.              hot_pursuit(mon);
  178.  
  179.          if (obj_gone)
  180.              thrownobj = 0;
  181.      }
  182.  
  183.      if (!thrownobj) {
  184.          ; /* missile has already been handled */
  185.      } else if (u.uswallow) {
  186.          /* ball is not picked up by monster */
  187.          if (obj != uball)
  188.              (void) mpickobj(u.ustuck, obj);
  189.          thrownobj = (struct obj *) 0;
  190.      } else {
  191.          /* the code following might become part of dropy() */
  192.          if (obj->oartifact == ART_MJOLLNIR && Role_if(PM_VALKYRIE)
  193.              && rn2(100)) {
  194.              /* we must be wearing Gauntlets of Power to get here */
  195.              sho_obj_return_to_u(obj); /* display its flight */
  196.  
  197.              if (!impaired && rn2(100)) {
  198.                  pline("%s to your hand!", Tobjnam(obj, "return"));
  199.                  obj = addinv(obj);
  200.                  (void) encumber_msg();
  201.                  setuwep(obj);
  202.                  u.twoweap = twoweap;
  203.                  if (cansee(bhitpos.x, bhitpos.y))
  204.                      newsym(bhitpos.x, bhitpos.y);
  205.              } else {
  206.                  int dmg = rn2(2);
  207.                  if (!dmg) {
  208.                      pline(Blind ? "%s lands %s your %s."
  209.                                  : "%s back to you, landing %s your %s.",
  210.                            Blind ? Something : Tobjnam(obj, "return"),
  211.                            Levitation ? "beneath" : "at",
  212.                            makeplural(body_part(FOOT)));
  213.                  } else {
  214.                      dmg += rnd(3);
  215.                      pline(Blind ? "%s your %s!"
  216.                                  : "%s back toward you, hitting your %s!",
  217.                            Tobjnam(obj, Blind ? "hit" : "fly"),
  218.                            body_part(ARM));
  219.                      (void) artifact_hit((struct monst *) 0, &youmonst, obj,
  220.                                          &dmg, 0);
  221.                      losehp(Maybe_Half_Phys(dmg), killer_xname(obj),
  222.                             KILLED_BY);
  223.                  }
  224.                  if (ship_object(obj, u.ux, u.uy, FALSE)) {
  225.                      thrownobj = (struct obj *) 0;
  226.                      return;
  227.                  }
  228.                  dropy(obj);
  229.              }
  230.              thrownobj = (struct obj *) 0;
  231.              return;
  232.          }
  233.  
  234.          if (!IS_SOFT(levl[bhitpos.x][bhitpos.y].typ) && breaktest(obj)) {
  235.              tmp_at(DISP_FLASH, obj_to_glyph(obj));
  236.              tmp_at(bhitpos.x, bhitpos.y);
  237.              delay_output();
  238.              tmp_at(DISP_END, 0);
  239.              breakmsg(obj, cansee(bhitpos.x, bhitpos.y));
  240.              breakobj(obj, bhitpos.x, bhitpos.y, TRUE, TRUE);
  241.              thrownobj = (struct obj *) 0;
  242.              return;
  243.          }
  244.          if (flooreffects(obj, bhitpos.x, bhitpos.y, "fall")) {
  245.              thrownobj = (struct obj *) 0;
  246.              return;
  247.          }
  248.          obj_no_longer_held(obj);
  249.          if (mon && mon->isshk && is_pick(obj)) {
  250.              if (cansee(bhitpos.x, bhitpos.y))
  251.                  pline("%s snatches up %s.", Monnam(mon), the(xname(obj)));
  252.              if (*u.ushops || obj->unpaid)
  253.                  check_shop_obj(obj, bhitpos.x, bhitpos.y, FALSE);
  254.              (void) mpickobj(mon, obj); /* may merge and free obj */
  255.              thrownobj = (struct obj *) 0;
  256.              return;
  257.          }
  258.          (void) snuff_candle(obj);
  259.          if (!mon && ship_object(obj, bhitpos.x, bhitpos.y, FALSE)) {
  260.              thrownobj = (struct obj *) 0;
  261.              return;
  262.          }
  263.          thrownobj = (struct obj *) 0;
  264.          place_object(obj, bhitpos.x, bhitpos.y);
  265.          /* container contents might break;
  266.             do so before turning ownership of thrownobj over to shk
  267.             (container_impact_dmg handles item already owned by shop) */
  268.          if (!IS_SOFT(levl[bhitpos.x][bhitpos.y].typ))
  269.              /* <x,y> is spot where you initiated throw, not bhitpos */
  270.              container_impact_dmg(obj, u.ux, u.uy);
  271.          /* charge for items thrown out of shop;
  272.             shk takes possession for items thrown into one */
  273.          if ((*u.ushops || obj->unpaid) && obj != uball)
  274.              check_shop_obj(obj, bhitpos.x, bhitpos.y, FALSE);
  275.  
  276.          stackobj(obj);
  277.          if (obj == uball)
  278.              drop_ball(bhitpos.x, bhitpos.y);
  279.          if (cansee(bhitpos.x, bhitpos.y))
  280.              newsym(bhitpos.x, bhitpos.y);
  281.          if (obj_sheds_light(obj))
  282.              vision_full_recalc = 1;
  283.      }
  284.  }
  285.  

omon_adj

  1.  /* an object may hit a monster; various factors adjust the chance of hitting
  2.   */
  3.  int
  4.  omon_adj(mon, obj, mon_notices)
  5.  struct monst *mon;
  6.  struct obj *obj;
  7.  boolean mon_notices;
  8.  {
  9.      int tmp = 0;
  10.  
  11.      /* size of target affects the chance of hitting */
  12.      tmp += (mon->data->msize - MZ_MEDIUM); /* -2..+5 */
  13.      /* sleeping target is more likely to be hit */
  14.      if (mon->msleeping) {
  15.          tmp += 2;
  16.          if (mon_notices)
  17.              mon->msleeping = 0;
  18.      }
  19.      /* ditto for immobilized target */
  20.      if (!mon->mcanmove || !mon->data->mmove) {
  21.          tmp += 4;
  22.          if (mon_notices && mon->data->mmove && !rn2(10)) {
  23.              mon->mcanmove = 1;
  24.              mon->mfrozen = 0;
  25.          }
  26.      }
  27.      /* some objects are more likely to hit than others */
  28.      switch (obj->otyp) {
  29.      case HEAVY_IRON_BALL:
  30.          if (obj != uball)
  31.              tmp += 2;
  32.          break;
  33.      case BOULDER:
  34.          tmp += 6;
  35.          break;
  36.      default:
  37.          if (obj->oclass == WEAPON_CLASS || is_weptool(obj)
  38.              || obj->oclass == GEM_CLASS)
  39.              tmp += hitval(obj, mon);
  40.          break;
  41.      }
  42.      return tmp;
  43.  }
  44.  

tmiss

  1.  /* thrown object misses target monster */
  2.  STATIC_OVL void
  3.  tmiss(obj, mon, maybe_wakeup)
  4.  struct obj *obj;
  5.  struct monst *mon;
  6.  boolean maybe_wakeup;
  7.  {
  8.      const char *missile = mshot_xname(obj);
  9.  
  10.      /* If the target can't be seen or doesn't look like a valid target,
  11.         avoid "the arrow misses it," or worse, "the arrows misses the mimic."
  12.         An attentive player will still notice that this is different from
  13.         an arrow just landing short of any target (no message in that case),
  14.         so will realize that there is a valid target here anyway. */
  15.      if (!canseemon(mon) || (mon->m_ap_type && mon->m_ap_type != M_AP_MONSTER))
  16.          pline("%s %s.", The(missile), otense(obj, "miss"));
  17.      else
  18.          miss(missile, mon);
  19.      if (maybe_wakeup && !rn2(3))
  20.          wakeup(mon);
  21.      return;
  22.  }
  23.  

thitmonst

  1.  #define quest_arti_hits_leader(obj, mon)      \
  2.      (obj->oartifact && is_quest_artifact(obj) \
  3.       && mon->m_id == quest_status.leader_m_id)
  4.  
  5.  /*
  6.   * Object thrown by player arrives at monster's location.
  7.   * Return 1 if obj has disappeared or otherwise been taken care of,
  8.   * 0 if caller must take care of it.
  9.   * Also used for kicked objects and for polearms/grapnel applied at range.
  10.   */
  11.  int
  12.  thitmonst(mon, obj)
  13.  register struct monst *mon;
  14.  register struct obj *obj; /* thrownobj or kickedobj or uwep */
  15.  {
  16.      register int tmp;     /* Base chance to hit */
  17.      register int disttmp; /* distance modifier */
  18.      int otyp = obj->otyp, hmode;
  19.      boolean guaranteed_hit = (u.uswallow && mon == u.ustuck);
  20.  
  21.      hmode = (obj == uwep) ? HMON_APPLIED : (obj == kickedobj) ? HMON_KICKED
  22.                                                                : HMON_THROWN;
  23.  
  24.      /* Differences from melee weapons:
  25.       *
  26.       * Dex still gives a bonus, but strength does not.
  27.       * Polymorphed players lacking attacks may still throw.
  28.       * There's a base -1 to hit.
  29.       * No bonuses for fleeing or stunned targets (they don't dodge
  30.       *    melee blows as readily, but dodging arrows is hard anyway).
  31.       * Not affected by traps, etc.
  32.       * Certain items which don't in themselves do damage ignore tmp.
  33.       * Distance and monster size affect chance to hit.
  34.       */
  35.      tmp = -1 + Luck + find_mac(mon) + u.uhitinc
  36.            + maybe_polyd(youmonst.data->mlevel, u.ulevel);
  37.      if (ACURR(A_DEX) < 4)
  38.          tmp -= 3;
  39.      else if (ACURR(A_DEX) < 6)
  40.          tmp -= 2;
  41.      else if (ACURR(A_DEX) < 8)
  42.          tmp -= 1;
  43.      else if (ACURR(A_DEX) >= 14)
  44.          tmp += (ACURR(A_DEX) - 14);
  45.  
  46.      /* Modify to-hit depending on distance; but keep it sane.
  47.       * Polearms get a distance penalty even when wielded; it's
  48.       * hard to hit at a distance.
  49.       */
  50.      disttmp = 3 - distmin(u.ux, u.uy, mon->mx, mon->my);
  51.      if (disttmp < -4)
  52.          disttmp = -4;
  53.      tmp += disttmp;
  54.  
  55.      /* gloves are a hindrance to proper use of bows */
  56.      if (uarmg && uwep && objects[uwep->otyp].oc_skill == P_BOW) {
  57.          switch (uarmg->otyp) {
  58.          case GAUNTLETS_OF_POWER: /* metal */
  59.              tmp -= 2;
  60.              break;
  61.          case GAUNTLETS_OF_FUMBLING:
  62.              tmp -= 3;
  63.              break;
  64.          case LEATHER_GLOVES:
  65.          case GAUNTLETS_OF_DEXTERITY:
  66.              break;
  67.          default:
  68.              impossible("Unknown type of gloves (%d)", uarmg->otyp);
  69.              break;
  70.          }
  71.      }
  72.  
  73.      tmp += omon_adj(mon, obj, TRUE);
  74.      if (is_orc(mon->data)
  75.          && maybe_polyd(is_elf(youmonst.data), Race_if(PM_ELF)))
  76.          tmp++;
  77.      if (guaranteed_hit) {
  78.          tmp += 1000; /* Guaranteed hit */
  79.      }
  80.  
  81.      if (obj->oclass == GEM_CLASS && is_unicorn(mon->data)) {
  82.          if (mon->msleeping || !mon->mcanmove) {
  83.              tmiss(obj, mon, FALSE);
  84.              return 0;
  85.          } else if (mon->mtame) {
  86.              pline("%s catches and drops %s.", Monnam(mon), the(xname(obj)));
  87.              return 0;
  88.          } else {
  89.              pline("%s catches %s.", Monnam(mon), the(xname(obj)));
  90.              return gem_accept(mon, obj);
  91.          }
  92.      }
  93.  
  94.      /* don't make game unwinnable if naive player throws artifact
  95.         at leader... (kicked artifact is ok too; HMON_APPLIED could
  96.         occur if quest artifact polearm or grapnel ever gets added) */
  97.      if (hmode != HMON_APPLIED && quest_arti_hits_leader(obj, mon)) {
  98.          /* not wakeup(), which angers non-tame monsters */
  99.          mon->msleeping = 0;
  100.          mon->mstrategy &= ~STRAT_WAITMASK;
  101.  
  102.          if (mon->mcanmove) {
  103.              pline("%s catches %s.", Monnam(mon), the(xname(obj)));
  104.              if (mon->mpeaceful) {
  105.                  boolean next2u = monnear(mon, u.ux, u.uy);
  106.  
  107.                  finish_quest(obj); /* acknowledge quest completion */
  108.                  pline("%s %s %s back to you.", Monnam(mon),
  109.                        (next2u ? "hands" : "tosses"), the(xname(obj)));
  110.                  if (!next2u)
  111.                      sho_obj_return_to_u(obj);
  112.                  obj = addinv(obj); /* back into your inventory */
  113.                  (void) encumber_msg();
  114.              } else {
  115.                  /* angry leader caught it and isn't returning it */
  116.                  if (*u.ushops || obj->unpaid) /* not very likely... */
  117.                      check_shop_obj(obj, mon->mx, mon->my, FALSE);
  118.                  (void) mpickobj(mon, obj);
  119.              }
  120.              return 1; /* caller doesn't need to place it */
  121.          }
  122.          return 0;
  123.      }
  124.  
  125.      if (obj->oclass == WEAPON_CLASS || is_weptool(obj)
  126.          || obj->oclass == GEM_CLASS) {
  127.          if (hmode == HMON_KICKED) {
  128.              /* throwing adjustments and weapon skill bonus don't apply */
  129.              tmp -= (is_ammo(obj) ? 5 : 3);
  130.          } else if (is_ammo(obj)) {
  131.              if (!ammo_and_launcher(obj, uwep)) {
  132.                  tmp -= 4;
  133.              } else {
  134.                  tmp += uwep->spe - greatest_erosion(uwep);
  135.                  tmp += weapon_hit_bonus(uwep);
  136.                  if (uwep->oartifact)
  137.                      tmp += spec_abon(uwep, mon);
  138.                  /*
  139.                   * Elves and Samurais are highly trained w/bows,
  140.                   * especially their own special types of bow.
  141.                   * Polymorphing won't make you a bow expert.
  142.                   */
  143.                  if ((Race_if(PM_ELF) || Role_if(PM_SAMURAI))
  144.                      && (!Upolyd || your_race(youmonst.data))
  145.                      && objects[uwep->otyp].oc_skill == P_BOW) {
  146.                      tmp++;
  147.                      if (Race_if(PM_ELF) && uwep->otyp == ELVEN_BOW)
  148.                          tmp++;
  149.                      else if (Role_if(PM_SAMURAI) && uwep->otyp == YUMI)
  150.                          tmp++;
  151.                  }
  152.              }
  153.          } else { /* thrown non-ammo or applied polearm/grapnel */
  154.              if (otyp == BOOMERANG) /* arbitrary */
  155.                  tmp += 4;
  156.              else if (throwing_weapon(obj)) /* meant to be thrown */
  157.                  tmp += 2;
  158.              else if (obj == thrownobj) /* not meant to be thrown */
  159.                  tmp -= 2;
  160.              /* we know we're dealing with a weapon or weptool handled
  161.                 by WEAPON_SKILLS once ammo objects have been excluded */
  162.              tmp += weapon_hit_bonus(obj);
  163.          }
  164.  
  165.          if (tmp >= rnd(20)) {
  166.              if (hmode == HMON_APPLIED)
  167.                  u.uconduct.weaphit++;
  168.              if (hmon(mon, obj, hmode)) { /* mon still alive */
  169.                  cutworm(mon, bhitpos.x, bhitpos.y, obj);
  170.              }
  171.              exercise(A_DEX, TRUE);
  172.              /* if hero is swallowed and projectile kills the engulfer,
  173.                 obj gets added to engulfer's inventory and then dropped,
  174.                 so we can't safely use that pointer anymore; it escapes
  175.                 the chance to be used up here... */
  176.              if (!thrownobj)
  177.                  return 1;
  178.              /* projectiles other than magic stones
  179.                 sometimes disappear when thrown */
  180.              if (objects[otyp].oc_skill < P_NONE
  181.                  && objects[otyp].oc_skill > -P_BOOMERANG
  182.                  && !objects[otyp].oc_magic) {
  183.                  /* we were breaking 2/3 of everything unconditionally.
  184.                   * we still don't want anything to survive unconditionally,
  185.                   * but we need ammo to stay around longer on average.
  186.                   */
  187.                  int broken, chance;
  188.                  chance = 3 + greatest_erosion(obj) - obj->spe;
  189.                  if (chance > 1)
  190.                      broken = rn2(chance);
  191.                  else
  192.                      broken = !rn2(4);
  193.                  if (obj->blessed && !rnl(4))
  194.                      broken = 0;
  195.  
  196.                  if (broken) {
  197.                      if (*u.ushops || obj->unpaid)
  198.                          check_shop_obj(obj, bhitpos.x, bhitpos.y, TRUE);
  199.                      obfree(obj, (struct obj *) 0);
  200.                      return 1;
  201.                  }
  202.              }
  203.              passive_obj(mon, obj, (struct attack *) 0);
  204.          } else {
  205.              tmiss(obj, mon, TRUE);
  206.              if (hmode == HMON_APPLIED)
  207.                  wakeup(mon);
  208.          }
  209.  
  210.      } else if (otyp == HEAVY_IRON_BALL) {
  211.          exercise(A_STR, TRUE);
  212.          if (tmp >= rnd(20)) {
  213.              int was_swallowed = guaranteed_hit;
  214.  
  215.              exercise(A_DEX, TRUE);
  216.              if (!hmon(mon, obj, hmode)) { /* mon killed */
  217.                  if (was_swallowed && !u.uswallow && obj == uball)
  218.                      return 1; /* already did placebc() */
  219.              }
  220.          } else {
  221.              tmiss(obj, mon, TRUE);
  222.          }
  223.  
  224.      } else if (otyp == BOULDER) {
  225.          exercise(A_STR, TRUE);
  226.          if (tmp >= rnd(20)) {
  227.              exercise(A_DEX, TRUE);
  228.              (void) hmon(mon, obj, hmode);
  229.          } else {
  230.              tmiss(obj, mon, TRUE);
  231.          }
  232.  
  233.      } else if ((otyp == EGG || otyp == CREAM_PIE || otyp == BLINDING_VENOM
  234.                  || otyp == ACID_VENOM)
  235.                 && (guaranteed_hit || ACURR(A_DEX) > rnd(25))) {
  236.          (void) hmon(mon, obj, hmode);
  237.          return 1; /* hmon used it up */
  238.  
  239.      } else if (obj->oclass == POTION_CLASS
  240.                 && (guaranteed_hit || ACURR(A_DEX) > rnd(25))) {
  241.          potionhit(mon, obj, TRUE);
  242.          return 1;
  243.  
  244.      } else if (befriend_with_obj(mon->data, obj)
  245.                 || (mon->mtame && dogfood(mon, obj) <= ACCFOOD)) {
  246.          if (tamedog(mon, obj)) {
  247.              return 1; /* obj is gone */
  248.          } else {
  249.              tmiss(obj, mon, FALSE);
  250.              mon->msleeping = 0;
  251.              mon->mstrategy &= ~STRAT_WAITMASK;
  252.          }
  253.      } else if (guaranteed_hit) {
  254.          /* this assumes that guaranteed_hit is due to swallowing */
  255.          wakeup(mon);
  256.          if (obj->otyp == CORPSE && touch_petrifies(&mons[obj->corpsenm])) {
  257.              if (is_animal(u.ustuck->data)) {
  258.                  minstapetrify(u.ustuck, TRUE);
  259.                  /* Don't leave a cockatrice corpse available in a statue */
  260.                  if (!u.uswallow) {
  261.                      delobj(obj);
  262.                      return 1;
  263.                  }
  264.              }
  265.          }
  266.          pline("%s into %s %s.", Tobjnam(obj, "vanish"),
  267.                s_suffix(mon_nam(mon)),
  268.                is_animal(u.ustuck->data) ? "entrails" : "currents");
  269.      } else {
  270.          tmiss(obj, mon, TRUE);
  271.      }
  272.  
  273.      return 0;
  274.  }
  275.  

gem_accept

  1.  STATIC_OVL int
  2.  gem_accept(mon, obj)
  3.  register struct monst *mon;
  4.  register struct obj *obj;
  5.  {
  6.      char buf[BUFSZ];
  7.      boolean is_buddy = sgn(mon->data->maligntyp) == sgn(u.ualign.type);
  8.      boolean is_gem = objects[obj->otyp].oc_material == GEMSTONE;
  9.      int ret = 0;
  10.      static NEARDATA const char nogood[] = " is not interested in your junk.";
  11.      static NEARDATA const char acceptgift[] = " accepts your gift.";
  12.      static NEARDATA const char maybeluck[] = " hesitatingly";
  13.      static NEARDATA const char noluck[] = " graciously";
  14.      static NEARDATA const char addluck[] = " gratefully";
  15.  
  16.      Strcpy(buf, Monnam(mon));
  17.      mon->mpeaceful = 1;
  18.      mon->mavenge = 0;
  19.  
  20.      /* object properly identified */
  21.      if (obj->dknown && objects[obj->otyp].oc_name_known) {
  22.          if (is_gem) {
  23.              if (is_buddy) {
  24.                  Strcat(buf, addluck);
  25.                  change_luck(5);
  26.              } else {
  27.                  Strcat(buf, maybeluck);
  28.                  change_luck(rn2(7) - 3);
  29.              }
  30.          } else {
  31.              Strcat(buf, nogood);
  32.              goto nopick;
  33.          }
  34.          /* making guesses */
  35.      } else if (has_oname(obj) || objects[obj->otyp].oc_uname) {
  36.          if (is_gem) {
  37.              if (is_buddy) {
  38.                  Strcat(buf, addluck);
  39.                  change_luck(2);
  40.              } else {
  41.                  Strcat(buf, maybeluck);
  42.                  change_luck(rn2(3) - 1);
  43.              }
  44.          } else {
  45.              Strcat(buf, nogood);
  46.              goto nopick;
  47.          }
  48.          /* value completely unknown to @ */
  49.      } else {
  50.          if (is_gem) {
  51.              if (is_buddy) {
  52.                  Strcat(buf, addluck);
  53.                  change_luck(1);
  54.              } else {
  55.                  Strcat(buf, maybeluck);
  56.                  change_luck(rn2(3) - 1);
  57.              }
  58.          } else {
  59.              Strcat(buf, noluck);
  60.          }
  61.      }
  62.      Strcat(buf, acceptgift);
  63.      if (*u.ushops || obj->unpaid)
  64.          check_shop_obj(obj, mon->mx, mon->my, TRUE);
  65.      (void) mpickobj(mon, obj); /* may merge and free obj */
  66.      ret = 1;
  67.  
  68.  nopick:
  69.      if (!Blind)
  70.          pline1(buf);
  71.      if (!tele_restrict(mon))
  72.          (void) rloc(mon, TRUE);
  73.      return ret;
  74.  }
  75.  

hero_breaks

  1.  /*
  2.   * Comments about the restructuring of the old breaks() routine.
  3.   *
  4.   * There are now three distinct phases to object breaking:
  5.   *     breaktest() - which makes the check/decision about whether the
  6.   *                   object is going to break.
  7.   *     breakmsg()  - which outputs a message about the breakage,
  8.   *                   appropriate for that particular object. Should
  9.   *                   only be called after a positive breaktest().
  10.   *                   on the object and, if it going to be called,
  11.   *                   it must be called before calling breakobj().
  12.   *                   Calling breakmsg() is optional.
  13.   *     breakobj()  - which actually does the breakage and the side-effects
  14.   *                   of breaking that particular object. This should
  15.   *                   only be called after a positive breaktest() on the
  16.   *                   object.
  17.   *
  18.   * Each of the above routines is currently static to this source module.
  19.   * There are two routines callable from outside this source module which
  20.   * perform the routines above in the correct sequence.
  21.   *
  22.   *   hero_breaks() - called when an object is to be broken as a result
  23.   *                   of something that the hero has done. (throwing it,
  24.   *                   kicking it, etc.)
  25.   *   breaks()      - called when an object is to be broken for some
  26.   *                   reason other than the hero doing something to it.
  27.   */
  28.  
  29.  /*
  30.   * The hero causes breakage of an object (throwing, dropping it, etc.)
  31.   * Return 0 if the object didn't break, 1 if the object broke.
  32.   */
  33.  int
  34.  hero_breaks(obj, x, y, from_invent)
  35.  struct obj *obj;
  36.  xchar x, y;          /* object location (ox, oy may not be right) */
  37.  boolean from_invent; /* thrown or dropped by player; maybe on shop bill */
  38.  {
  39.      boolean in_view = Blind ? FALSE : (from_invent || cansee(x, y));
  40.      if (!breaktest(obj))
  41.          return 0;
  42.      breakmsg(obj, in_view);
  43.      breakobj(obj, x, y, TRUE, from_invent);
  44.      return 1;
  45.  }
  46.  

breaks

  1.  /*
  2.   * The object is going to break for a reason other than the hero doing
  3.   * something to it.
  4.   * Return 0 if the object doesn't break, 1 if the object broke.
  5.   */
  6.  int
  7.  breaks(obj, x, y)
  8.  struct obj *obj;
  9.  xchar x, y; /* object location (ox, oy may not be right) */
  10.  {
  11.      boolean in_view = Blind ? FALSE : cansee(x, y);
  12.  
  13.      if (!breaktest(obj))
  14.          return 0;
  15.      breakmsg(obj, in_view);
  16.      breakobj(obj, x, y, FALSE, FALSE);
  17.      return 1;
  18.  }
  19.  

release_camera_demon

  1.  void
  2.  release_camera_demon(obj, x, y)
  3.  struct obj *obj;
  4.  xchar x, y;
  5.  {
  6.      struct monst *mtmp;
  7.      if (!rn2(3)
  8.          && (mtmp = makemon(&mons[rn2(3) ? PM_HOMUNCULUS : PM_IMP], x, y,
  9.                             NO_MM_FLAGS)) != 0) {
  10.          if (canspotmon(mtmp))
  11.              pline("%s is released!", Hallucination
  12.                                           ? An(rndmonnam(NULL))
  13.                                           : "The picture-painting demon");
  14.          mtmp->mpeaceful = !obj->cursed;
  15.          set_malign(mtmp);
  16.      }
  17.  }
  18.  

breakobj

  1.  /*
  2.   * Unconditionally break an object. Assumes all resistance checks
  3.   * and break messages have been delivered prior to getting here.
  4.   */
  5.  void
  6.  breakobj(obj, x, y, hero_caused, from_invent)
  7.  struct obj *obj;
  8.  xchar x, y;          /* object location (ox, oy may not be right) */
  9.  boolean hero_caused; /* is this the hero's fault? */
  10.  boolean from_invent;
  11.  {
  12.      boolean fracture = FALSE;
  13.  
  14.      switch (obj->oclass == POTION_CLASS ? POT_WATER : obj->otyp) {
  15.      case MIRROR:
  16.          if (hero_caused)
  17.              change_luck(-2);
  18.          break;
  19.      case POT_WATER:      /* really, all potions */
  20.          obj->in_use = 1; /* in case it's fatal */
  21.          if (obj->otyp == POT_OIL && obj->lamplit) {
  22.              explode_oil(obj, x, y);
  23.          } else if (distu(x, y) <= 2) {
  24.              if (!breathless(youmonst.data) || haseyes(youmonst.data)) {
  25.                  if (obj->otyp != POT_WATER) {
  26.                      if (!breathless(youmonst.data)) {
  27.                          /* [what about "familiar odor" when known?] */
  28.                          You("smell a peculiar odor...");
  29.                      } else {
  30.                          const char *eyes = body_part(EYE);
  31.  
  32.                          if (eyecount(youmonst.data) != 1)
  33.                              eyes = makeplural(eyes);
  34.                          Your("%s %s.", eyes, vtense(eyes, "water"));
  35.                      }
  36.                  }
  37.                  potionbreathe(obj);
  38.              }
  39.          }
  40.          /* monster breathing isn't handled... [yet?] */
  41.          break;
  42.      case EXPENSIVE_CAMERA:
  43.          release_camera_demon(obj, x, y);
  44.          break;
  45.      case EGG:
  46.          /* breaking your own eggs is bad luck */
  47.          if (hero_caused && obj->spe && obj->corpsenm >= LOW_PM)
  48.              change_luck((schar) -min(obj->quan, 5L));
  49.          break;
  50.      case BOULDER:
  51.      case STATUE:
  52.          /* caller will handle object disposition;
  53.             we're just doing the shop theft handling */
  54.          fracture = TRUE;
  55.          break;
  56.      default:
  57.          break;
  58.      }
  59.  
  60.      if (hero_caused) {
  61.          if (from_invent || obj->unpaid) {
  62.              if (*u.ushops || obj->unpaid)
  63.                  check_shop_obj(obj, x, y, TRUE);
  64.          } else if (!obj->no_charge && costly_spot(x, y)) {
  65.              /* it is assumed that the obj is a floor-object */
  66.              char *o_shop = in_rooms(x, y, SHOPBASE);
  67.              struct monst *shkp = shop_keeper(*o_shop);
  68.  
  69.              if (shkp) { /* (implies *o_shop != '\0') */
  70.                  static NEARDATA long lastmovetime = 0L;
  71.                  static NEARDATA boolean peaceful_shk = FALSE;
  72.                  /*  We want to base shk actions on her peacefulness
  73.                      at start of this turn, so that "simultaneous"
  74.                      multiple breakage isn't drastically worse than
  75.                      single breakage.  (ought to be done via ESHK)  */
  76.                  if (moves != lastmovetime)
  77.                      peaceful_shk = shkp->mpeaceful;
  78.                  if (stolen_value(obj, x, y, peaceful_shk, FALSE) > 0L
  79.                      && (*o_shop != u.ushops[0] || !inside_shop(u.ux, u.uy))
  80.                      && moves != lastmovetime)
  81.                      make_angry_shk(shkp, x, y);
  82.                  lastmovetime = moves;
  83.              }
  84.          }
  85.      }
  86.      if (!fracture)
  87.          delobj(obj);
  88.  }
  89.  

breaktest

  1.  /*
  2.   * Check to see if obj is going to break, but don't actually break it.
  3.   * Return 0 if the object isn't going to break, 1 if it is.
  4.   */
  5.  boolean
  6.  breaktest(obj)
  7.  struct obj *obj;
  8.  {
  9.      if (obj_resists(obj, 1, 99))
  10.          return 0;
  11.      if (objects[obj->otyp].oc_material == GLASS && !obj->oartifact
  12.          && obj->oclass != GEM_CLASS)
  13.          return 1;
  14.      switch (obj->oclass == POTION_CLASS ? POT_WATER : obj->otyp) {
  15.      case EXPENSIVE_CAMERA:
  16.      case POT_WATER: /* really, all potions */
  17.      case EGG:
  18.      case CREAM_PIE:
  19.      case MELON:
  20.      case ACID_VENOM:
  21.      case BLINDING_VENOM:
  22.          return 1;
  23.      default:
  24.          return 0;
  25.      }
  26.  }
  27.  

breakmsg

  1.  STATIC_OVL void
  2.  breakmsg(obj, in_view)
  3.  struct obj *obj;
  4.  boolean in_view;
  5.  {
  6.      const char *to_pieces;
  7.  
  8.      to_pieces = "";
  9.      switch (obj->oclass == POTION_CLASS ? POT_WATER : obj->otyp) {
  10.      default: /* glass or crystal wand */
  11.          if (obj->oclass != WAND_CLASS)
  12.              impossible("breaking odd object?");
  13.      case CRYSTAL_PLATE_MAIL:
  14.      case LENSES:
  15.      case MIRROR:
  16.      case CRYSTAL_BALL:
  17.      case EXPENSIVE_CAMERA:
  18.          to_pieces = " into a thousand pieces";
  19.      /*FALLTHRU*/
  20.      case POT_WATER: /* really, all potions */
  21.          if (!in_view)
  22.              You_hear("%s shatter!", something);
  23.          else
  24.              pline("%s shatter%s%s!", Doname2(obj),
  25.                    (obj->quan == 1L) ? "s" : "", to_pieces);
  26.          break;
  27.      case EGG:
  28.      case MELON:
  29.          pline("Splat!");
  30.          break;
  31.      case CREAM_PIE:
  32.          if (in_view)
  33.              pline("What a mess!");
  34.          break;
  35.      case ACID_VENOM:
  36.      case BLINDING_VENOM:
  37.          pline("Splash!");
  38.          break;
  39.      }
  40.  }
  41.  

throw_gold

  1.  STATIC_OVL int
  2.  throw_gold(obj)
  3.  struct obj *obj;
  4.  {
  5.      int range, odx, ody;
  6.      register struct monst *mon;
  7.  
  8.      if (!u.dx && !u.dy && !u.dz) {
  9.          You("cannot throw gold at yourself.");
  10.          return 0;
  11.      }
  12.      freeinv(obj);
  13.      if (u.uswallow) {
  14.          pline(is_animal(u.ustuck->data) ? "%s in the %s's entrails."
  15.                                          : "%s into %s.",
  16.                "The money disappears", mon_nam(u.ustuck));
  17.          add_to_minv(u.ustuck, obj);
  18.          return 1;
  19.      }
  20.  
  21.      if (u.dz) {
  22.          if (u.dz < 0 && !Is_airlevel(&u.uz) && !Underwater
  23.              && !Is_waterlevel(&u.uz)) {
  24.              pline_The("gold hits the %s, then falls back on top of your %s.",
  25.                        ceiling(u.ux, u.uy), body_part(HEAD));
  26.              /* some self damage? */
  27.              if (uarmh)
  28.                  pline("Fortunately, you are wearing %s!",
  29.                        an(helm_simple_name(uarmh)));
  30.          }
  31.          bhitpos.x = u.ux;
  32.          bhitpos.y = u.uy;
  33.      } else {
  34.          /* consistent with range for normal objects */
  35.          range = (int) ((ACURRSTR) / 2 - obj->owt / 40);
  36.  
  37.          /* see if the gold has a place to move into */
  38.          odx = u.ux + u.dx;
  39.          ody = u.uy + u.dy;
  40.          if (!ZAP_POS(levl[odx][ody].typ) || closed_door(odx, ody)) {
  41.              bhitpos.x = u.ux;
  42.              bhitpos.y = u.uy;
  43.          } else {
  44.              mon = bhit(u.dx, u.dy, range, THROWN_WEAPON,
  45.                         (int FDECL((*), (MONST_P, OBJ_P))) 0,
  46.                         (int FDECL((*), (OBJ_P, OBJ_P))) 0, &obj);
  47.              if (!obj)
  48.                  return 1; /* object is gone */
  49.              if (mon) {
  50.                  if (ghitm(mon, obj)) /* was it caught? */
  51.                      return 1;
  52.              } else {
  53.                  if (ship_object(obj, bhitpos.x, bhitpos.y, FALSE))
  54.                      return 1;
  55.              }
  56.          }
  57.      }
  58.  
  59.      if (flooreffects(obj, bhitpos.x, bhitpos.y, "fall"))
  60.          return 1;
  61.      if (u.dz > 0)
  62.          pline_The("gold hits the %s.", surface(bhitpos.x, bhitpos.y));
  63.      place_object(obj, bhitpos.x, bhitpos.y);
  64.      if (*u.ushops)
  65.          sellobj(obj, bhitpos.x, bhitpos.y);
  66.      stackobj(obj);
  67.      newsym(bhitpos.x, bhitpos.y);
  68.      return 1;
  69.  }
  70.  
  71.  /*dothrow.c*/