Source:NetHack 3.6.0/src/mthrowu.c

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

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

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

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

Top of file[edit]

  1.  /* NetHack 3.6	mthrowu.c	$NHDT-Date: 1446887531 2015/11/07 09:12:11 $  $NHDT-Branch: master $:$NHDT-Revision: 1.63 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5.  #include "hack.h"
  6.  
  7.  STATIC_DCL int FDECL(drop_throw, (struct obj *, BOOLEAN_P, int, int));
  8.  
  9.  #define URETREATING(x, y) \
  10.      (distmin(u.ux, u.uy, x, y) > distmin(u.ux0, u.uy0, x, y))
  11.  
  12.  #define POLE_LIM 5 /* How far monsters can use pole-weapons */
  13.  
  14.  /*
  15.   * Keep consistent with breath weapons in zap.c, and AD_* in monattk.h.
  16.   */
  17.  STATIC_OVL NEARDATA const char *breathwep[] = {
  18.      "fragments", "fire", "frost", "sleep gas", "a disintegration blast",
  19.      "lightning", "poison gas", "acid", "strange breath #8",
  20.      "strange breath #9"
  21.  };
  22.  
  23.  extern boolean notonhead; /* for long worms */
  24.  

thitu[edit]

  1.  /* hero is hit by something other than a monster */
  2.  int
  3.  thitu(tlev, dam, obj, name)
  4.  int tlev, dam;
  5.  struct obj *obj;
  6.  const char *name; /* if null, then format `obj' */
  7.  {
  8.      const char *onm, *knm;
  9.      boolean is_acid;
  10.      int kprefix = KILLED_BY_AN;
  11.      char onmbuf[BUFSZ], knmbuf[BUFSZ];
  12.  
  13.      if (!name) {
  14.          if (!obj)
  15.              panic("thitu: name & obj both null?");
  16.          name =
  17.              strcpy(onmbuf, (obj->quan > 1L) ? doname(obj) : mshot_xname(obj));
  18.          knm = strcpy(knmbuf, killer_xname(obj));
  19.          kprefix = KILLED_BY; /* killer_name supplies "an" if warranted */
  20.      } else {
  21.          knm = name;
  22.          /* [perhaps ought to check for plural here to] */
  23.          if (!strncmpi(name, "the ", 4) || !strncmpi(name, "an ", 3)
  24.              || !strncmpi(name, "a ", 2))
  25.              kprefix = KILLED_BY;
  26.      }
  27.      onm = (obj && obj_is_pname(obj)) ? the(name) : (obj && obj->quan > 1L)
  28.                                                         ? name
  29.                                                         : an(name);
  30.      is_acid = (obj && obj->otyp == ACID_VENOM);
  31.  
  32.      if (u.uac + tlev <= rnd(20)) {
  33.          if (Blind || !flags.verbose)
  34.              pline("It misses.");
  35.          else
  36.              You("are almost hit by %s.", onm);
  37.          return 0;
  38.      } else {
  39.          if (Blind || !flags.verbose)
  40.              You("are hit%s", exclam(dam));
  41.          else
  42.              You("are hit by %s%s", onm, exclam(dam));
  43.  
  44.          if (obj && objects[obj->otyp].oc_material == SILVER && Hate_silver) {
  45.              /* extra damage already applied by dmgval() */
  46.              pline_The("silver sears your flesh!");
  47.              exercise(A_CON, FALSE);
  48.          }
  49.          if (is_acid && Acid_resistance)
  50.              pline("It doesn't seem to hurt you.");
  51.          else {
  52.              if (is_acid)
  53.                  pline("It burns!");
  54.              losehp(dam, knm, kprefix); /* acid damage */
  55.              exercise(A_STR, FALSE);
  56.          }
  57.          return 1;
  58.      }
  59.  }
  60.  

drop_throw[edit]

  1.  /* Be sure this corresponds with what happens to player-thrown objects in
  2.   * dothrow.c (for consistency). --KAA
  3.   * Returns 0 if object still exists (not destroyed).
  4.   */
  5.  STATIC_OVL int
  6.  drop_throw(obj, ohit, x, y)
  7.  register struct obj *obj;
  8.  boolean ohit;
  9.  int x, y;
  10.  {
  11.      int retvalu = 1;
  12.      int create;
  13.      struct monst *mtmp;
  14.      struct trap *t;
  15.  
  16.      if (obj->otyp == CREAM_PIE || obj->oclass == VENOM_CLASS
  17.          || (ohit && obj->otyp == EGG))
  18.          create = 0;
  19.      else if (ohit && (is_multigen(obj) || obj->otyp == ROCK))
  20.          create = !rn2(3);
  21.      else
  22.          create = 1;
  23.  
  24.      if (create
  25.          && !((mtmp = m_at(x, y)) && (mtmp->mtrapped) && (t = t_at(x, y))
  26.               && ((t->ttyp == PIT) || (t->ttyp == SPIKED_PIT)))) {
  27.          int objgone = 0;
  28.  
  29.          if (down_gate(x, y) != -1)
  30.              objgone = ship_object(obj, x, y, FALSE);
  31.          if (!objgone) {
  32.              if (!flooreffects(obj, x, y,
  33.                                "fall")) { /* don't double-dip on damage */
  34.                  place_object(obj, x, y);
  35.                  if (!mtmp && x == u.ux && y == u.uy)
  36.                      mtmp = &youmonst;
  37.                  if (mtmp && ohit)
  38.                      passive_obj(mtmp, obj, (struct attack *) 0);
  39.                  stackobj(obj);
  40.                  retvalu = 0;
  41.              }
  42.          }
  43.      } else
  44.          obfree(obj, (struct obj *) 0);
  45.      return retvalu;
  46.  }
  47.  

ohitmon[edit]

  1.  /* an object launched by someone/thing other than player attacks a monster;
  2.     return 1 if the object has stopped moving (hit or its range used up) */
  3.  int
  4.  ohitmon(mtmp, otmp, range, verbose)
  5.  struct monst *mtmp; /* accidental target, located at <bhitpos.x,.y> */
  6.  struct obj *otmp;   /* missile; might be destroyed by drop_throw */
  7.  int range;          /* how much farther will object travel if it misses;
  8.                         use -1 to signify to keep going even after hit,
  9.                         unless it's gone (used for rolling_boulder_traps) */
  10.  boolean verbose;    /* give message(s) even when you can't see what happened */
  11.  {
  12.      int damage, tmp;
  13.      boolean vis, ismimic;
  14.      int objgone = 1;
  15.  
  16.      notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my);
  17.      ismimic = mtmp->m_ap_type && mtmp->m_ap_type != M_AP_MONSTER;
  18.      vis = cansee(bhitpos.x, bhitpos.y);
  19.  
  20.      tmp = 5 + find_mac(mtmp) + omon_adj(mtmp, otmp, FALSE);
  21.      if (tmp < rnd(20)) {
  22.          if (!ismimic) {
  23.              if (vis)
  24.                  miss(distant_name(otmp, mshot_xname), mtmp);
  25.              else if (verbose)
  26.                  pline("It is missed.");
  27.          }
  28.          if (!range) { /* Last position; object drops */
  29.              (void) drop_throw(otmp, 0, mtmp->mx, mtmp->my);
  30.              return 1;
  31.          }
  32.      } else if (otmp->oclass == POTION_CLASS) {
  33.          if (ismimic)
  34.              seemimic(mtmp);
  35.          mtmp->msleeping = 0;
  36.          if (vis)
  37.              otmp->dknown = 1;
  38.          potionhit(mtmp, otmp, FALSE);
  39.          return 1;
  40.      } else {
  41.          damage = dmgval(otmp, mtmp);
  42.          if (otmp->otyp == ACID_VENOM && resists_acid(mtmp))
  43.              damage = 0;
  44.          if (ismimic)
  45.              seemimic(mtmp);
  46.          mtmp->msleeping = 0;
  47.          if (vis)
  48.              hit(distant_name(otmp, mshot_xname), mtmp, exclam(damage));
  49.          else if (verbose)
  50.              pline("%s is hit%s", Monnam(mtmp), exclam(damage));
  51.  
  52.          if (otmp->opoisoned && is_poisonable(otmp)) {
  53.              if (resists_poison(mtmp)) {
  54.                  if (vis)
  55.                      pline_The("poison doesn't seem to affect %s.",
  56.                                mon_nam(mtmp));
  57.              } else {
  58.                  if (rn2(30)) {
  59.                      damage += rnd(6);
  60.                  } else {
  61.                      if (vis)
  62.                          pline_The("poison was deadly...");
  63.                      damage = mtmp->mhp;
  64.                  }
  65.              }
  66.          }
  67.          if (objects[otmp->otyp].oc_material == SILVER
  68.              && mon_hates_silver(mtmp)) {
  69.              if (vis)
  70.                  pline_The("silver sears %s flesh!", s_suffix(mon_nam(mtmp)));
  71.              else if (verbose)
  72.                  pline("Its flesh is seared!");
  73.          }
  74.          if (otmp->otyp == ACID_VENOM && cansee(mtmp->mx, mtmp->my)) {
  75.              if (resists_acid(mtmp)) {
  76.                  if (vis || verbose)
  77.                      pline("%s is unaffected.", Monnam(mtmp));
  78.                  damage = 0;
  79.              } else {
  80.                  if (vis)
  81.                      pline_The("acid burns %s!", mon_nam(mtmp));
  82.                  else if (verbose)
  83.                      pline("It is burned!");
  84.              }
  85.          }
  86.          mtmp->mhp -= damage;
  87.          if (mtmp->mhp < 1) {
  88.              if (vis || verbose)
  89.                  pline("%s is %s!", Monnam(mtmp),
  90.                        (nonliving(mtmp->data) || is_vampshifter(mtmp)
  91.                         || !canspotmon(mtmp))
  92.                            ? "destroyed"
  93.                            : "killed");
  94.              /* don't blame hero for unknown rolling boulder trap */
  95.              if (!context.mon_moving
  96.                  && (otmp->otyp != BOULDER || range >= 0 || otmp->otrapped))
  97.                  xkilled(mtmp, 0);
  98.              else
  99.                  mondied(mtmp);
  100.          }
  101.  
  102.          if (can_blnd((struct monst *) 0, mtmp,
  103.                       (uchar) (otmp->otyp == BLINDING_VENOM ? AT_SPIT
  104.                                                             : AT_WEAP),
  105.                       otmp)) {
  106.              if (vis && mtmp->mcansee)
  107.                  pline("%s is blinded by %s.", Monnam(mtmp), the(xname(otmp)));
  108.              mtmp->mcansee = 0;
  109.              tmp = (int) mtmp->mblinded + rnd(25) + 20;
  110.              if (tmp > 127)
  111.                  tmp = 127;
  112.              mtmp->mblinded = tmp;
  113.          }
  114.  
  115.          objgone = drop_throw(otmp, 1, bhitpos.x, bhitpos.y);
  116.          if (!objgone && range == -1) { /* special case */
  117.              obj_extract_self(otmp);    /* free it for motion again */
  118.              return 0;
  119.          }
  120.          return 1;
  121.      }
  122.      return 0;
  123.  }
  124.  

m_throw[edit]

  1.  void
  2.  m_throw(mon, x, y, dx, dy, range, obj)
  3.  struct monst *mon;       /* launching monster */
  4.  int x, y, dx, dy, range; /* launch point, direction, and range */
  5.  struct obj *obj;         /* missile (or stack providing it) */
  6.  {
  7.      struct monst *mtmp;
  8.      struct obj *singleobj;
  9.      char sym = obj->oclass;
  10.      int hitu, oldumort, blindinc = 0;
  11.  
  12.      bhitpos.x = x;
  13.      bhitpos.y = y;
  14.      notonhead = FALSE; /* reset potentially stale value */
  15.  
  16.      if (obj->quan == 1L) {
  17.          /*
  18.           * Remove object from minvent.  This cannot be done later on;
  19.           * what if the player dies before then, leaving the monster
  20.           * with 0 daggers?  (This caused the infamous 2^32-1 orcish
  21.           * dagger bug).
  22.           *
  23.           * VENOM is not in minvent - it should already be OBJ_FREE.
  24.           * The extract below does nothing.
  25.           */
  26.  
  27.          /* not possibly_unwield, which checks the object's */
  28.          /* location, not its existence */
  29.          if (MON_WEP(mon) == obj)
  30.              setmnotwielded(mon, obj);
  31.          obj_extract_self(obj);
  32.          singleobj = obj;
  33.          obj = (struct obj *) 0;
  34.      } else {
  35.          singleobj = splitobj(obj, 1L);
  36.          obj_extract_self(singleobj);
  37.      }
  38.  
  39.      singleobj->owornmask = 0; /* threw one of multiple weapons in hand? */
  40.  
  41.      if ((singleobj->cursed || singleobj->greased) && (dx || dy) && !rn2(7)) {
  42.          if (canseemon(mon) && flags.verbose) {
  43.              if (is_ammo(singleobj))
  44.                  pline("%s misfires!", Monnam(mon));
  45.              else
  46.                  pline("%s as %s throws it!", Tobjnam(singleobj, "slip"),
  47.                        mon_nam(mon));
  48.          }
  49.          dx = rn2(3) - 1;
  50.          dy = rn2(3) - 1;
  51.          /* check validity of new direction */
  52.          if (!dx && !dy) {
  53.              (void) drop_throw(singleobj, 0, bhitpos.x, bhitpos.y);
  54.              return;
  55.          }
  56.      }
  57.  
  58.      /* pre-check for doors, walls and boundaries.
  59.         Also need to pre-check for bars regardless of direction;
  60.         the random chance for small objects hitting bars is
  61.         skipped when reaching them at point blank range */
  62.      if (!isok(bhitpos.x + dx, bhitpos.y + dy)
  63.          || IS_ROCK(levl[bhitpos.x + dx][bhitpos.y + dy].typ)
  64.          || closed_door(bhitpos.x + dx, bhitpos.y + dy)
  65.          || (levl[bhitpos.x + dx][bhitpos.y + dy].typ == IRONBARS
  66.              && hits_bars(&singleobj, bhitpos.x, bhitpos.y, 0, 0))) {
  67.          (void) drop_throw(singleobj, 0, bhitpos.x, bhitpos.y);
  68.          return;
  69.      }
  70.  
  71.      /* Note: drop_throw may destroy singleobj.  Since obj must be destroyed
  72.       * early to avoid the dagger bug, anyone who modifies this code should
  73.       * be careful not to use either one after it's been freed.
  74.       */
  75.      if (sym)
  76.          tmp_at(DISP_FLASH, obj_to_glyph(singleobj));
  77.      while (range-- > 0) { /* Actually the loop is always exited by break */
  78.          bhitpos.x += dx;
  79.          bhitpos.y += dy;
  80.          if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) {
  81.              if (ohitmon(mtmp, singleobj, range, TRUE))
  82.                  break;
  83.          } else if (bhitpos.x == u.ux && bhitpos.y == u.uy) {
  84.              if (multi)
  85.                  nomul(0);
  86.  
  87.              if (singleobj->oclass == GEM_CLASS
  88.                  && singleobj->otyp <= LAST_GEM + 9 /* 9 glass colors */
  89.                  && is_unicorn(youmonst.data)) {
  90.                  if (singleobj->otyp > LAST_GEM) {
  91.                      You("catch the %s.", xname(singleobj));
  92.                      You("are not interested in %s junk.",
  93.                          s_suffix(mon_nam(mon)));
  94.                      makeknown(singleobj->otyp);
  95.                      dropy(singleobj);
  96.                  } else {
  97.                      You(
  98.                       "accept %s gift in the spirit in which it was intended.",
  99.                          s_suffix(mon_nam(mon)));
  100.                      (void) hold_another_object(
  101.                          singleobj, "You catch, but drop, %s.",
  102.                          xname(singleobj), "You catch:");
  103.                  }
  104.                  break;
  105.              }
  106.              if (singleobj->oclass == POTION_CLASS) {
  107.                  if (!Blind)
  108.                      singleobj->dknown = 1;
  109.                  potionhit(&youmonst, singleobj, FALSE);
  110.                  break;
  111.              }
  112.              oldumort = u.umortality;
  113.              switch (singleobj->otyp) {
  114.                  int dam, hitv;
  115.              case EGG:
  116.                  if (!touch_petrifies(&mons[singleobj->corpsenm])) {
  117.                      impossible("monster throwing egg type %d",
  118.                                 singleobj->corpsenm);
  119.                      hitu = 0;
  120.                      break;
  121.                  }
  122.              /* fall through */
  123.              case CREAM_PIE:
  124.              case BLINDING_VENOM:
  125.                  hitu = thitu(8, 0, singleobj, (char *) 0);
  126.                  break;
  127.              default:
  128.                  dam = dmgval(singleobj, &youmonst);
  129.                  hitv = 3 - distmin(u.ux, u.uy, mon->mx, mon->my);
  130.                  if (hitv < -4)
  131.                      hitv = -4;
  132.                  if (is_elf(mon->data)
  133.                      && objects[singleobj->otyp].oc_skill == P_BOW) {
  134.                      hitv++;
  135.                      if (MON_WEP(mon) && MON_WEP(mon)->otyp == ELVEN_BOW)
  136.                          hitv++;
  137.                      if (singleobj->otyp == ELVEN_ARROW)
  138.                          dam++;
  139.                  }
  140.                  if (bigmonst(youmonst.data))
  141.                      hitv++;
  142.                  hitv += 8 + singleobj->spe;
  143.                  if (dam < 1)
  144.                      dam = 1;
  145.                  hitu = thitu(hitv, dam, singleobj, (char *) 0);
  146.              }
  147.              if (hitu && singleobj->opoisoned && is_poisonable(singleobj)) {
  148.                  char onmbuf[BUFSZ], knmbuf[BUFSZ];
  149.  
  150.                  Strcpy(onmbuf, xname(singleobj));
  151.                  Strcpy(knmbuf, killer_xname(singleobj));
  152.                  poisoned(onmbuf, A_STR, knmbuf,
  153.                           /* if damage triggered life-saving,
  154.                              poison is limited to attrib loss */
  155.                           (u.umortality > oldumort) ? 0 : 10, TRUE);
  156.              }
  157.              if (hitu && can_blnd((struct monst *) 0, &youmonst,
  158.                                   (uchar) (singleobj->otyp == BLINDING_VENOM
  159.                                               ? AT_SPIT
  160.                                               : AT_WEAP),
  161.                                   singleobj)) {
  162.                  blindinc = rnd(25);
  163.                  if (singleobj->otyp == CREAM_PIE) {
  164.                      if (!Blind)
  165.                          pline("Yecch!  You've been creamed.");
  166.                      else
  167.                          pline("There's %s sticky all over your %s.",
  168.                                something, body_part(FACE));
  169.                  } else if (singleobj->otyp == BLINDING_VENOM) {
  170.                      const char *eyes = body_part(EYE);
  171.  
  172.                      if (eyecount(youmonst.data) != 1)
  173.                          eyes = makeplural(eyes);
  174.                      /* venom in the eyes */
  175.                      if (!Blind)
  176.                          pline_The("venom blinds you.");
  177.                      else
  178.                          Your("%s %s.", eyes, vtense(eyes, "sting"));
  179.                  }
  180.              }
  181.              if (hitu && singleobj->otyp == EGG) {
  182.                  if (!Stoned && !Stone_resistance
  183.                      && !(poly_when_stoned(youmonst.data)
  184.                           && polymon(PM_STONE_GOLEM))) {
  185.                      make_stoned(5L, (char *) 0, KILLED_BY, "");
  186.                  }
  187.              }
  188.              stop_occupation();
  189.              if (hitu || !range) {
  190.                  (void) drop_throw(singleobj, hitu, u.ux, u.uy);
  191.                  break;
  192.              }
  193.          }
  194.          if (!range /* reached end of path */
  195.              /* missile hits edge of screen */
  196.              || !isok(bhitpos.x + dx, bhitpos.y + dy)
  197.              /* missile hits the wall */
  198.              || IS_ROCK(levl[bhitpos.x + dx][bhitpos.y + dy].typ)
  199.              /* missile hit closed door */
  200.              || closed_door(bhitpos.x + dx, bhitpos.y + dy)
  201.              /* missile might hit iron bars */
  202.              || (levl[bhitpos.x + dx][bhitpos.y + dy].typ == IRONBARS
  203.                  && hits_bars(&singleobj, bhitpos.x, bhitpos.y, !rn2(5), 0))
  204.              /* Thrown objects "sink" */
  205.              || IS_SINK(levl[bhitpos.x][bhitpos.y].typ)) {
  206.              if (singleobj) /* hits_bars might have destroyed it */
  207.                  (void) drop_throw(singleobj, 0, bhitpos.x, bhitpos.y);
  208.              break;
  209.          }
  210.          tmp_at(bhitpos.x, bhitpos.y);
  211.          delay_output();
  212.      }
  213.      tmp_at(bhitpos.x, bhitpos.y);
  214.      delay_output();
  215.      tmp_at(DISP_END, 0);
  216.  
  217.      if (blindinc) {
  218.          u.ucreamed += blindinc;
  219.          make_blinded(Blinded + (long) blindinc, FALSE);
  220.          if (!Blind)
  221.              Your1(vision_clears);
  222.      }
  223.  }
  224.  

m_useupall[edit]

  1.  /* remove an entire item from a monster's inventory; destroy that item */
  2.  void
  3.  m_useupall(mon, obj)
  4.  struct monst *mon;
  5.  struct obj *obj;
  6.  {
  7.      obj_extract_self(obj);
  8.      if (obj->owornmask) {
  9.          if (obj == MON_WEP(mon))
  10.              mwepgone(mon);
  11.          mon->misc_worn_check &= ~obj->owornmask;
  12.          update_mon_intrinsics(mon, obj, FALSE, FALSE);
  13.          obj->owornmask = 0L;
  14.      }
  15.      obfree(obj, (struct obj *) 0);
  16.  }
  17.  

m_useup[edit]

  1.  /* remove one instance of an item from a monster's inventory */
  2.  void
  3.  m_useup(mon, obj)
  4.  struct monst *mon;
  5.  struct obj *obj;
  6.  {
  7.      if (obj->quan > 1L) {
  8.          obj->quan--;
  9.          obj->owt = weight(obj);
  10.      } else {
  11.          m_useupall(mon, obj);
  12.      }
  13.  }
  14.  

thrwmu[edit]

  1.  /* monster attempts ranged weapon attack against player */
  2.  void
  3.  thrwmu(mtmp)
  4.  struct monst *mtmp;
  5.  {
  6.      struct obj *otmp, *mwep;
  7.      xchar x, y;
  8.      int multishot;
  9.      const char *onm;
  10.  
  11.      /* Rearranged beginning so monsters can use polearms not in a line */
  12.      if (mtmp->weapon_check == NEED_WEAPON || !MON_WEP(mtmp)) {
  13.          mtmp->weapon_check = NEED_RANGED_WEAPON;
  14.          /* mon_wield_item resets weapon_check as appropriate */
  15.          if (mon_wield_item(mtmp) != 0)
  16.              return;
  17.      }
  18.  
  19.      /* Pick a weapon */
  20.      otmp = select_rwep(mtmp);
  21.      if (!otmp)
  22.          return;
  23.  
  24.      if (is_pole(otmp)) {
  25.          int dam, hitv;
  26.  
  27.          if (otmp != MON_WEP(mtmp))
  28.              return; /* polearm must be wielded */
  29.          if (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) > POLE_LIM
  30.              || !couldsee(mtmp->mx, mtmp->my))
  31.              return; /* Out of range, or intervening wall */
  32.  
  33.          if (canseemon(mtmp)) {
  34.              onm = xname(otmp);
  35.              pline("%s thrusts %s.", Monnam(mtmp),
  36.                    obj_is_pname(otmp) ? the(onm) : an(onm));
  37.          }
  38.  
  39.          dam = dmgval(otmp, &youmonst);
  40.          hitv = 3 - distmin(u.ux, u.uy, mtmp->mx, mtmp->my);
  41.          if (hitv < -4)
  42.              hitv = -4;
  43.          if (bigmonst(youmonst.data))
  44.              hitv++;
  45.          hitv += 8 + otmp->spe;
  46.          if (dam < 1)
  47.              dam = 1;
  48.  
  49.          (void) thitu(hitv, dam, otmp, (char *) 0);
  50.          stop_occupation();
  51.          return;
  52.      }
  53.  
  54.      x = mtmp->mx;
  55.      y = mtmp->my;
  56.      /* If you are coming toward the monster, the monster
  57.       * should try to soften you up with missiles.  If you are
  58.       * going away, you are probably hurt or running.  Give
  59.       * chase, but if you are getting too far away, throw.
  60.       */
  61.      if (!lined_up(mtmp)
  62.          || (URETREATING(x, y)
  63.              && rn2(BOLT_LIM - distmin(x, y, mtmp->mux, mtmp->muy))))
  64.          return;
  65.  
  66.      mwep = MON_WEP(mtmp); /* wielded weapon */
  67.  
  68.      /* Multishot calculations */
  69.      multishot = 1;
  70.      if (otmp->quan > 1L /* no point checking if there's only 1 */
  71.          /* ammo requires corresponding launcher be wielded */
  72.          && (is_ammo(otmp)
  73.                 ? matching_launcher(otmp, mwep)
  74.                 /* otherwise any stackable (non-ammo) weapon */
  75.                 : otmp->oclass == WEAPON_CLASS)
  76.          && !mtmp->mconf) {
  77.          int skill = (int) objects[otmp->otyp].oc_skill;
  78.  
  79.          /* Assumes lords are skilled, princes are expert */
  80.          if (is_prince(mtmp->data))
  81.              multishot += 2;
  82.          else if (is_lord(mtmp->data))
  83.              multishot++;
  84.          /* fake players treated as skilled (regardless of role limits) */
  85.          else if (is_mplayer(mtmp->data))
  86.              multishot++;
  87.  
  88.          /* class bonus */
  89.          switch (monsndx(mtmp->data)) {
  90.          case PM_MONK:
  91.              if (skill == -P_SHURIKEN)
  92.                  multishot++;
  93.              break;
  94.          case PM_RANGER:
  95.              multishot++;
  96.              break;
  97.          case PM_ROGUE:
  98.              if (skill == P_DAGGER)
  99.                  multishot++;
  100.              break;
  101.          case PM_NINJA:
  102.              if (skill == -P_SHURIKEN || skill == -P_DART)
  103.                  multishot++;
  104.              /*FALLTHRU*/
  105.          case PM_SAMURAI:
  106.              if (otmp->otyp == YA && mwep && mwep->otyp == YUMI)
  107.                  multishot++;
  108.              break;
  109.          default:
  110.              break;
  111.          }
  112.          /* racial bonus */
  113.          if ((is_elf(mtmp->data) && otmp->otyp == ELVEN_ARROW && mwep
  114.               && mwep->otyp == ELVEN_BOW)
  115.              || (is_orc(mtmp->data) && otmp->otyp == ORCISH_ARROW && mwep
  116.                  && mwep->otyp == ORCISH_BOW))
  117.              multishot++;
  118.  
  119.          multishot = rnd(multishot);
  120.          if ((long) multishot > otmp->quan)
  121.              multishot = (int) otmp->quan;
  122.      }
  123.  
  124.      if (canseemon(mtmp)) {
  125.          char onmbuf[BUFSZ];
  126.  
  127.          if (multishot > 1) {
  128.              /* "N arrows"; multishot > 1 implies otmp->quan > 1, so
  129.                 xname()'s result will already be pluralized */
  130.              Sprintf(onmbuf, "%d %s", multishot, xname(otmp));
  131.              onm = onmbuf;
  132.          } else {
  133.              /* "an arrow" */
  134.              onm = singular(otmp, xname);
  135.              onm = obj_is_pname(otmp) ? the(onm) : an(onm);
  136.          }
  137.          m_shot.s = ammo_and_launcher(otmp, mwep) ? TRUE : FALSE;
  138.          pline("%s %s %s!", Monnam(mtmp), m_shot.s ? "shoots" : "throws", onm);
  139.          m_shot.o = otmp->otyp;
  140.      } else {
  141.          m_shot.o = STRANGE_OBJECT; /* don't give multishot feedback */
  142.      }
  143.  
  144.      m_shot.n = multishot;
  145.      for (m_shot.i = 1; m_shot.i <= m_shot.n; m_shot.i++) {
  146.          m_throw(mtmp, mtmp->mx, mtmp->my, sgn(tbx), sgn(tby),
  147.                  distmin(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy), otmp);
  148.          /* conceptually all N missiles are in flight at once, but
  149.             if mtmp gets killed (shot kills adjacent gas spore and
  150.             triggers explosion, perhaps), inventory will be dropped
  151.             and otmp might go away via merging into another stack */
  152.          if (mtmp->mhp <= 0 && m_shot.i < m_shot.n) {
  153.              /* cancel pending shots (ought to give a message here since
  154.                 we gave one above about throwing/shooting N missiles) */
  155.              break; /* endmultishot(FALSE); */
  156.          }
  157.      }
  158.      m_shot.n = m_shot.i = 0;
  159.      m_shot.o = STRANGE_OBJECT;
  160.      m_shot.s = FALSE;
  161.  
  162.      nomul(0);
  163.  }
  164.  

spitmu[edit]

  1.  /* monster spits substance at you */
  2.  int
  3.  spitmu(mtmp, mattk)
  4.  struct monst *mtmp;
  5.  struct attack *mattk;
  6.  {
  7.      struct obj *otmp;
  8.  
  9.      if (mtmp->mcan) {
  10.          if (!Deaf)
  11.              pline("A dry rattle comes from %s throat.",
  12.                    s_suffix(mon_nam(mtmp)));
  13.          return 0;
  14.      }
  15.      if (lined_up(mtmp)) {
  16.          switch (mattk->adtyp) {
  17.          case AD_BLND:
  18.          case AD_DRST:
  19.              otmp = mksobj(BLINDING_VENOM, TRUE, FALSE);
  20.              break;
  21.          default:
  22.              impossible("bad attack type in spitmu");
  23.          /* fall through */
  24.          case AD_ACID:
  25.              otmp = mksobj(ACID_VENOM, TRUE, FALSE);
  26.              break;
  27.          }
  28.          if (!rn2(BOLT_LIM
  29.                   - distmin(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy))) {
  30.              if (canseemon(mtmp))
  31.                  pline("%s spits venom!", Monnam(mtmp));
  32.              m_throw(mtmp, mtmp->mx, mtmp->my, sgn(tbx), sgn(tby),
  33.                      distmin(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy), otmp);
  34.              nomul(0);
  35.              return 0;
  36.          } else {
  37.              obj_extract_self(otmp);
  38.              obfree(otmp, (struct obj *) 0);
  39.          }
  40.      }
  41.      return 0;
  42.  }
  43.  

breamu[edit]

  1.  /* monster breathes at you (ranged) */
  2.  int
  3.  breamu(mtmp, mattk)
  4.  struct monst *mtmp;
  5.  struct attack *mattk;
  6.  {
  7.      /* if new breath types are added, change AD_ACID to max type */
  8.      int typ = (mattk->adtyp == AD_RBRE) ? rnd(AD_ACID) : mattk->adtyp;
  9.  
  10.      if (lined_up(mtmp)) {
  11.          if (mtmp->mcan) {
  12.              if (!Deaf) {
  13.                  if (canseemon(mtmp))
  14.                      pline("%s coughs.", Monnam(mtmp));
  15.                  else
  16.                      You_hear("a cough.");
  17.              }
  18.              return 0;
  19.          }
  20.          if (!mtmp->mspec_used && rn2(3)) {
  21.              if ((typ >= AD_MAGM) && (typ <= AD_ACID)) {
  22.                  if (canseemon(mtmp))
  23.                      pline("%s breathes %s!", Monnam(mtmp),
  24.                            breathwep[typ - 1]);
  25.                  buzz((int) (-20 - (typ - 1)), (int) mattk->damn, mtmp->mx,
  26.                       mtmp->my, sgn(tbx), sgn(tby));
  27.                  nomul(0);
  28.                  /* breath runs out sometimes. Also, give monster some
  29.                   * cunning; don't breath if the player fell asleep.
  30.                   */
  31.                  if (!rn2(3))
  32.                      mtmp->mspec_used = 10 + rn2(20);
  33.                  if (typ == AD_SLEE && !Sleep_resistance)
  34.                      mtmp->mspec_used += rnd(20);
  35.              } else
  36.                  impossible("Breath weapon %d used", typ - 1);
  37.          }
  38.      }
  39.      return 1;
  40.  }
  41.  

linedup[edit]

  1.  boolean
  2.  linedup(ax, ay, bx, by, boulderhandling)
  3.  register xchar ax, ay, bx, by;
  4.  int boulderhandling; /* 0=block, 1=ignore, 2=conditionally block */
  5.  {
  6.      int dx, dy, boulderspots;
  7.  
  8.      /* These two values are set for use after successful return. */
  9.      tbx = ax - bx;
  10.      tby = ay - by;
  11.  
  12.      /* sometimes displacement makes a monster think that you're at its
  13.         own location; prevent it from throwing and zapping in that case */
  14.      if (!tbx && !tby)
  15.          return FALSE;
  16.  
  17.      if ((!tbx || !tby || abs(tbx) == abs(tby)) /* straight line or diagonal */
  18.          && distmin(tbx, tby, 0, 0) < BOLT_LIM) {
  19.          if ((ax == u.ux && ay == u.uy) ? (boolean) couldsee(bx, by)
  20.                                         : clear_path(ax, ay, bx, by))
  21.              return TRUE;
  22.          /* don't have line of sight, but might still be lined up
  23.             if that lack of sight is due solely to boulders */
  24.          if (boulderhandling == 0)
  25.              return FALSE;
  26.          dx = sgn(ax - bx), dy = sgn(ay - by);
  27.          boulderspots = 0;
  28.          do {
  29.              /* <bx,by> is guaranteed to eventually converge with <ax,ay> */
  30.              bx += dx, by += dy;
  31.              if (IS_ROCK(levl[bx][by].typ) || closed_door(bx, by))
  32.                  return FALSE;
  33.              if (sobj_at(BOULDER, bx, by))
  34.                  ++boulderspots;
  35.          } while (bx != ax || by != ay);
  36.          /* reached target position without encountering obstacle */
  37.          if (boulderhandling == 1 || rn2(2 + boulderspots) < 2)
  38.              return TRUE;
  39.      }
  40.      return FALSE;
  41.  }
  42.  

lined_up[edit]

  1.  /* is mtmp in position to use ranged attack? */
  2.  boolean
  3.  lined_up(mtmp)
  4.  register struct monst *mtmp;
  5.  {
  6.      boolean ignore_boulders;
  7.  
  8.      /* hero concealment usually trumps monst awareness of being lined up */
  9.      if (Upolyd && rn2(25)
  10.          && (u.uundetected || (youmonst.m_ap_type != M_AP_NOTHING
  11.                                && youmonst.m_ap_type != M_AP_MONSTER)))
  12.          return FALSE;
  13.  
  14.      ignore_boulders = (throws_rocks(mtmp->data)
  15.                         || m_carrying(mtmp, WAN_STRIKING));
  16.      return linedup(mtmp->mux, mtmp->muy, mtmp->mx, mtmp->my,
  17.                     ignore_boulders ? 1 : 2);
  18.  }
  19.  

m_carrying[edit]

  1.  /* check if a monster is carrying a particular item */
  2.  struct obj *
  3.  m_carrying(mtmp, type)
  4.  struct monst *mtmp;
  5.  int type;
  6.  {
  7.      register struct obj *otmp;
  8.  
  9.      for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj)
  10.          if (otmp->otyp == type)
  11.              return otmp;
  12.      return (struct obj *) 0;
  13.  }
  14.  

hits_bars[edit]

  1.  /* TRUE iff thrown/kicked/rolled object doesn't pass through iron bars */
  2.  boolean
  3.  hits_bars(obj_p, x, y, always_hit, whodidit)
  4.  struct obj **obj_p; /* *obj_p will be set to NULL if object breaks */
  5.  int x, y;
  6.  int always_hit; /* caller can force a hit for items which would fit through */
  7.  int whodidit;   /* 1==hero, 0=other, -1==just check whether it'll pass thru */
  8.  {
  9.      struct obj *otmp = *obj_p;
  10.      int obj_type = otmp->otyp;
  11.      boolean hits = always_hit;
  12.  
  13.      if (!hits)
  14.          switch (otmp->oclass) {
  15.          case WEAPON_CLASS: {
  16.              int oskill = objects[obj_type].oc_skill;
  17.  
  18.              hits = (oskill != -P_BOW && oskill != -P_CROSSBOW
  19.                      && oskill != -P_DART && oskill != -P_SHURIKEN
  20.                      && oskill != P_SPEAR
  21.                      && oskill != P_KNIFE); /* but not dagger */
  22.              break;
  23.          }
  24.          case ARMOR_CLASS:
  25.              hits = (objects[obj_type].oc_armcat != ARM_GLOVES);
  26.              break;
  27.          case TOOL_CLASS:
  28.              hits = (obj_type != SKELETON_KEY && obj_type != LOCK_PICK
  29.                      && obj_type != CREDIT_CARD && obj_type != TALLOW_CANDLE
  30.                      && obj_type != WAX_CANDLE && obj_type != LENSES
  31.                      && obj_type != TIN_WHISTLE && obj_type != MAGIC_WHISTLE);
  32.              break;
  33.          case ROCK_CLASS: /* includes boulder */
  34.              if (obj_type != STATUE || mons[otmp->corpsenm].msize > MZ_TINY)
  35.                  hits = TRUE;
  36.              break;
  37.          case FOOD_CLASS:
  38.              if (obj_type == CORPSE && mons[otmp->corpsenm].msize > MZ_TINY)
  39.                  hits = TRUE;
  40.              else
  41.                  hits = (obj_type == MEAT_STICK
  42.                          || obj_type == HUGE_CHUNK_OF_MEAT);
  43.              break;
  44.          case SPBOOK_CLASS:
  45.          case WAND_CLASS:
  46.          case BALL_CLASS:
  47.          case CHAIN_CLASS:
  48.              hits = TRUE;
  49.              break;
  50.          default:
  51.              break;
  52.          }
  53.  
  54.      if (hits && whodidit != -1) {
  55.          if (whodidit ? hero_breaks(otmp, x, y, FALSE) : breaks(otmp, x, y))
  56.              *obj_p = otmp = 0; /* object is now gone */
  57.          /* breakage makes its own noises */
  58.          else if (obj_type == BOULDER || obj_type == HEAVY_IRON_BALL)
  59.              pline("Whang!");
  60.          else if (otmp->oclass == COIN_CLASS
  61.                   || objects[obj_type].oc_material == GOLD
  62.                   || objects[obj_type].oc_material == SILVER)
  63.              pline("Clink!");
  64.          else
  65.              pline("Clonk!");
  66.      }
  67.  
  68.      return hits;
  69.  }
  70.  
  71.  /*mthrowu.c*/