Source:NetHack 3.6.0/src/mhitm.c

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

Below is the full text to mhitm.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/mhitm.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	mhitm.c	$NHDT-Date: 1446854229 2015/11/06 23:57:09 $  $NHDT-Branch: master $:$NHDT-Revision: 1.83 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5.  #include "hack.h"
  6.  #include "artifact.h"
  7.  
  8.  extern boolean notonhead;
  9.  
  10.  static NEARDATA boolean vis, far_noise;
  11.  static NEARDATA long noisetime;
  12.  static NEARDATA struct obj *otmp;
  13.  
  14.  static const char brief_feeling[] =
  15.      "have a %s feeling for a moment, then it passes.";
  16.  
  17.  STATIC_DCL char *FDECL(mon_nam_too, (char *, struct monst *, struct monst *));
  18.  STATIC_DCL int FDECL(hitmm, (struct monst *, struct monst *,
  19.                               struct attack *));
  20.  STATIC_DCL int FDECL(gazemm, (struct monst *, struct monst *,
  21.                                struct attack *));
  22.  STATIC_DCL int FDECL(gulpmm, (struct monst *, struct monst *,
  23.                                struct attack *));
  24.  STATIC_DCL int FDECL(explmm, (struct monst *, struct monst *,
  25.                                struct attack *));
  26.  STATIC_DCL int FDECL(mdamagem, (struct monst *, struct monst *,
  27.                                  struct attack *));
  28.  STATIC_DCL void FDECL(mswingsm, (struct monst *, struct monst *,
  29.                                   struct obj *));
  30.  STATIC_DCL void FDECL(noises, (struct monst *, struct attack *));
  31.  STATIC_DCL void FDECL(missmm, (struct monst *, struct monst *,
  32.                                 struct attack *));
  33.  STATIC_DCL int FDECL(passivemm, (struct monst *, struct monst *,
  34.                                   BOOLEAN_P, int));
  35.  
  36.  /* Needed for the special case of monsters wielding vorpal blades (rare).
  37.   * If we use this a lot it should probably be a parameter to mdamagem()
  38.   * instead of a global variable.
  39.   */
  40.  static int dieroll;
  41.  

mon_nam_too

  1.  /* returns mon_nam(mon) relative to other_mon; normal name unless they're
  2.     the same, in which case the reference is to {him|her|it} self */
  3.  STATIC_OVL char *
  4.  mon_nam_too(outbuf, mon, other_mon)
  5.  char *outbuf;
  6.  struct monst *mon, *other_mon;
  7.  {
  8.      Strcpy(outbuf, mon_nam(mon));
  9.      if (mon == other_mon)
  10.          switch (pronoun_gender(mon)) {
  11.          case 0:
  12.              Strcpy(outbuf, "himself");
  13.              break;
  14.          case 1:
  15.              Strcpy(outbuf, "herself");
  16.              break;
  17.          default:
  18.              Strcpy(outbuf, "itself");
  19.              break;
  20.          }
  21.      return outbuf;
  22.  }
  23.  

noises

  1.  STATIC_OVL void
  2.  noises(magr, mattk)
  3.  register struct monst *magr;
  4.  register struct attack *mattk;
  5.  {
  6.      boolean farq = (distu(magr->mx, magr->my) > 15);
  7.  
  8.      if (!Deaf && (farq != far_noise || moves - noisetime > 10)) {
  9.          far_noise = farq;
  10.          noisetime = moves;
  11.          You_hear("%s%s.",
  12.                   (mattk->aatyp == AT_EXPL) ? "an explosion" : "some noises",
  13.                   farq ? " in the distance" : "");
  14.      }
  15.  }
  16.  

missmm

  1.  STATIC_OVL
  2.  void
  3.  missmm(magr, mdef, mattk)
  4.  register struct monst *magr, *mdef;
  5.  struct attack *mattk;
  6.  {
  7.      const char *fmt;
  8.      char buf[BUFSZ], mdef_name[BUFSZ];
  9.  
  10.      if (vis) {
  11.          if (!canspotmon(magr))
  12.              map_invisible(magr->mx, magr->my);
  13.          if (!canspotmon(mdef))
  14.              map_invisible(mdef->mx, mdef->my);
  15.          if (mdef->m_ap_type)
  16.              seemimic(mdef);
  17.          if (magr->m_ap_type)
  18.              seemimic(magr);
  19.          fmt = (could_seduce(magr, mdef, mattk) && !magr->mcan)
  20.                    ? "%s pretends to be friendly to"
  21.                    : "%s misses";
  22.          Sprintf(buf, fmt, Monnam(magr));
  23.          pline("%s %s.", buf, mon_nam_too(mdef_name, mdef, magr));
  24.      } else
  25.          noises(magr, mattk);
  26.  }
  27.  

fightm

  1.  /*
  2.   *  fightm()  -- fight some other monster
  3.   *
  4.   *  Returns:
  5.   *      0 - Monster did nothing.
  6.   *      1 - If the monster made an attack.  The monster might have died.
  7.   *
  8.   *  There is an exception to the above.  If mtmp has the hero swallowed,
  9.   *  then we report that the monster did nothing so it will continue to
  10.   *  digest the hero.
  11.   */
  12.   /* have monsters fight each other */
  13.  int
  14.  fightm(mtmp)
  15.  register struct monst *mtmp;
  16.  {
  17.      register struct monst *mon, *nmon;
  18.      int result, has_u_swallowed;
  19.  #ifdef LINT
  20.      nmon = 0;
  21.  #endif
  22.      /* perhaps the monster will resist Conflict */
  23.      if (resist(mtmp, RING_CLASS, 0, 0))
  24.          return 0;
  25.  
  26.      if (u.ustuck == mtmp) {
  27.          /* perhaps we're holding it... */
  28.          if (itsstuck(mtmp))
  29.              return 0;
  30.      }
  31.      has_u_swallowed = (u.uswallow && (mtmp == u.ustuck));
  32.  
  33.      for (mon = fmon; mon; mon = nmon) {
  34.          nmon = mon->nmon;
  35.          if (nmon == mtmp)
  36.              nmon = mtmp->nmon;
  37.          /* Be careful to ignore monsters that are already dead, since we
  38.           * might be calling this before we've cleaned them up.  This can
  39.           * happen if the monster attacked a cockatrice bare-handedly, for
  40.           * instance.
  41.           */
  42.          if (mon != mtmp && !DEADMONSTER(mon)) {
  43.              if (monnear(mtmp, mon->mx, mon->my)) {
  44.                  if (!u.uswallow && (mtmp == u.ustuck)) {
  45.                      if (!rn2(4)) {
  46.                          pline("%s releases you!", Monnam(mtmp));
  47.                          u.ustuck = 0;
  48.                      } else
  49.                          break;
  50.                  }
  51.  
  52.                  /* mtmp can be killed */
  53.                  bhitpos.x = mon->mx;
  54.                  bhitpos.y = mon->my;
  55.                  notonhead = 0;
  56.                  result = mattackm(mtmp, mon);
  57.  
  58.                  if (result & MM_AGR_DIED)
  59.                      return 1; /* mtmp died */
  60.                  /*
  61.                   * If mtmp has the hero swallowed, lie and say there
  62.                   * was no attack (this allows mtmp to digest the hero).
  63.                   */
  64.                  if (has_u_swallowed)
  65.                      return 0;
  66.  
  67.                  /* Allow attacked monsters a chance to hit back. Primarily
  68.                   * to allow monsters that resist conflict to respond.
  69.                   */
  70.                  if ((result & MM_HIT) && !(result & MM_DEF_DIED) && rn2(4)
  71.                      && mon->movement >= NORMAL_SPEED) {
  72.                      mon->movement -= NORMAL_SPEED;
  73.                      notonhead = 0;
  74.                      (void) mattackm(mon, mtmp); /* return attack */
  75.                  }
  76.  
  77.                  return (result & MM_HIT) ? 1 : 0;
  78.              }
  79.          }
  80.      }
  81.      return 0;
  82.  }
  83.  

mdisplacem

  1.  /*
  2.   * mdisplacem() -- attacker moves defender out of the way;
  3.   *                 returns same results as mattackm().
  4.   */
  5.  int
  6.  mdisplacem(magr, mdef, quietly)
  7.  register struct monst *magr, *mdef;
  8.  boolean quietly;
  9.  {
  10.      struct permonst *pa, *pd;
  11.      int tx, ty, fx, fy;
  12.  
  13.      /* sanity checks; could matter if we unexpectedly get a long worm */
  14.      if (!magr || !mdef || magr == mdef)
  15.          return MM_MISS;
  16.      pa = magr->data, pd = mdef->data;
  17.      tx = mdef->mx, ty = mdef->my; /* destination */
  18.      fx = magr->mx, fy = magr->my; /* current location */
  19.      if (m_at(fx, fy) != magr || m_at(tx, ty) != mdef)
  20.          return MM_MISS;
  21.  
  22.      /* The 1 in 7 failure below matches the chance in attack()
  23.       * for pet displacement.
  24.       */
  25.      if (!rn2(7))
  26.          return MM_MISS;
  27.  
  28.      /* Grid bugs cannot displace at an angle. */
  29.      if (pa == &mons[PM_GRID_BUG] && magr->mx != mdef->mx
  30.          && magr->my != mdef->my)
  31.          return MM_MISS;
  32.  
  33.      /* undetected monster becomes un-hidden if it is displaced */
  34.      if (mdef->mundetected)
  35.          mdef->mundetected = 0;
  36.      if (mdef->m_ap_type && mdef->m_ap_type != M_AP_MONSTER)
  37.          seemimic(mdef);
  38.      /* wake up the displaced defender */
  39.      mdef->msleeping = 0;
  40.      mdef->mstrategy &= ~STRAT_WAITMASK;
  41.      finish_meating(mdef);
  42.  
  43.      /*
  44.       * Set up the visibility of action.
  45.       * You can observe monster displacement if you can see both of
  46.       * the monsters involved.
  47.       */
  48.      vis = (canspotmon(magr) && canspotmon(mdef));
  49.  
  50.      if (touch_petrifies(pd) && !resists_ston(magr)) {
  51.          if (which_armor(magr, W_ARMG) != 0) {
  52.              if (poly_when_stoned(pa)) {
  53.                  mon_to_stone(magr);
  54.                  return MM_HIT; /* no damage during the polymorph */
  55.              }
  56.              if (!quietly && canspotmon(magr))
  57.                  pline("%s turns to stone!", Monnam(magr));
  58.              monstone(magr);
  59.              if (magr->mhp > 0)
  60.                  return MM_HIT; /* lifesaved */
  61.              else if (magr->mtame && !vis)
  62.                  You(brief_feeling, "peculiarly sad");
  63.              return MM_AGR_DIED;
  64.          }
  65.      }
  66.  
  67.      remove_monster(fx, fy); /* pick up from orig position */
  68.      remove_monster(tx, ty);
  69.      place_monster(magr, tx, ty); /* put down at target spot */
  70.      place_monster(mdef, fx, fy);
  71.      if (vis && !quietly)
  72.          pline("%s moves %s out of %s way!", Monnam(magr), mon_nam(mdef),
  73.                is_rider(pa) ? "the" : mhis(magr));
  74.      newsym(fx, fy);  /* see it */
  75.      newsym(tx, ty);  /*   all happen */
  76.      flush_screen(0); /* make sure it shows up */
  77.  
  78.      return MM_HIT;
  79.  }
  80.  

mattackm

  1.  /*
  2.   * mattackm() -- a monster attacks another monster.
  3.   *
  4.   *          --------- aggressor died
  5.   *         /  ------- defender died
  6.   *        /  /  ----- defender was hit
  7.   *       /  /  /
  8.   *      x  x  x
  9.   *
  10.   *      0x4     MM_AGR_DIED
  11.   *      0x2     MM_DEF_DIED
  12.   *      0x1     MM_HIT
  13.   *      0x0     MM_MISS
  14.   *
  15.   * Each successive attack has a lower probability of hitting.  Some rely on
  16.   * success of previous attacks.  ** this doen't seem to be implemented -dl **
  17.   *
  18.   * In the case of exploding monsters, the monster dies as well.
  19.   */
  20.  int
  21.  mattackm(magr, mdef)
  22.  register struct monst *magr, *mdef;
  23.  {
  24.      int i,          /* loop counter */
  25.          tmp,        /* amour class difference */
  26.          strike,     /* hit this attack */
  27.          attk,       /* attack attempted this time */
  28.          struck = 0, /* hit at least once */
  29.          res[NATTK]; /* results of all attacks */
  30.      struct attack *mattk, alt_attk;
  31.      struct permonst *pa, *pd;
  32.  
  33.      if (!magr || !mdef)
  34.          return MM_MISS; /* mike@genat */
  35.      if (!magr->mcanmove || magr->msleeping)
  36.          return MM_MISS;
  37.      pa = magr->data;
  38.      pd = mdef->data;
  39.  
  40.      /* Grid bugs cannot attack at an angle. */
  41.      if (pa == &mons[PM_GRID_BUG] && magr->mx != mdef->mx
  42.          && magr->my != mdef->my)
  43.          return MM_MISS;
  44.  
  45.      /* Calculate the armour class differential. */
  46.      tmp = find_mac(mdef) + magr->m_lev;
  47.      if (mdef->mconf || !mdef->mcanmove || mdef->msleeping) {
  48.          tmp += 4;
  49.          mdef->msleeping = 0;
  50.      }
  51.  
  52.      /* undetect monsters become un-hidden if they are attacked */
  53.      if (mdef->mundetected) {
  54.          mdef->mundetected = 0;
  55.          newsym(mdef->mx, mdef->my);
  56.          if (canseemon(mdef) && !sensemon(mdef)) {
  57.              if (Unaware)
  58.                  You("dream of %s.", (mdef->data->geno & G_UNIQ)
  59.                                          ? a_monnam(mdef)
  60.                                          : makeplural(m_monnam(mdef)));
  61.              else
  62.                  pline("Suddenly, you notice %s.", a_monnam(mdef));
  63.          }
  64.      }
  65.  
  66.      /* Elves hate orcs. */
  67.      if (is_elf(pa) && is_orc(pd))
  68.          tmp++;
  69.  
  70.      /* Set up the visibility of action */
  71.      vis = (cansee(magr->mx, magr->my) && cansee(mdef->mx, mdef->my)
  72.             && (canspotmon(magr) || canspotmon(mdef)));
  73.  
  74.      /* Set flag indicating monster has moved this turn.  Necessary since a
  75.       * monster might get an attack out of sequence (i.e. before its move) in
  76.       * some cases, in which case this still counts as its move for the round
  77.       * and it shouldn't move again.
  78.       */
  79.      magr->mlstmv = monstermoves;
  80.  
  81.      /* Now perform all attacks for the monster. */
  82.      for (i = 0; i < NATTK; i++) {
  83.          res[i] = MM_MISS;
  84.          mattk = getmattk(pa, i, res, &alt_attk);
  85.          otmp = (struct obj *) 0;
  86.          attk = 1;
  87.          switch (mattk->aatyp) {
  88.          case AT_WEAP: /* "hand to hand" attacks */
  89.              if (magr->weapon_check == NEED_WEAPON || !MON_WEP(magr)) {
  90.                  magr->weapon_check = NEED_HTH_WEAPON;
  91.                  if (mon_wield_item(magr) != 0)
  92.                      return 0;
  93.              }
  94.              possibly_unwield(magr, FALSE);
  95.              otmp = MON_WEP(magr);
  96.  
  97.              if (otmp) {
  98.                  if (vis)
  99.                      mswingsm(magr, mdef, otmp);
  100.                  tmp += hitval(otmp, mdef);
  101.              }
  102.              /*FALLTHRU*/
  103.          case AT_CLAW:
  104.          case AT_KICK:
  105.          case AT_BITE:
  106.          case AT_STNG:
  107.          case AT_TUCH:
  108.          case AT_BUTT:
  109.          case AT_TENT:
  110.              /* Nymph that teleported away on first attack? */
  111.              if (distmin(magr->mx, magr->my, mdef->mx, mdef->my) > 1)
  112.                  return MM_MISS;
  113.              /* Monsters won't attack cockatrices physically if they
  114.               * have a weapon instead.  This instinct doesn't work for
  115.               * players, or under conflict or confusion.
  116.               */
  117.              if (!magr->mconf && !Conflict && otmp && mattk->aatyp != AT_WEAP
  118.                  && touch_petrifies(mdef->data)) {
  119.                  strike = 0;
  120.                  break;
  121.              }
  122.              dieroll = rnd(20 + i);
  123.              strike = (tmp > dieroll);
  124.              /* KMH -- don't accumulate to-hit bonuses */
  125.              if (otmp)
  126.                  tmp -= hitval(otmp, mdef);
  127.              if (strike) {
  128.                  res[i] = hitmm(magr, mdef, mattk);
  129.                  if ((mdef->data == &mons[PM_BLACK_PUDDING]
  130.                       || mdef->data == &mons[PM_BROWN_PUDDING]) && otmp
  131.                      && objects[otmp->otyp].oc_material == IRON
  132.                      && mdef->mhp > 1
  133.                      && !mdef->mcan) {
  134.                      if (clone_mon(mdef, 0, 0)) {
  135.                          if (vis) {
  136.                              char buf[BUFSZ];
  137.  
  138.                              Strcpy(buf, Monnam(mdef));
  139.                              pline("%s divides as %s hits it!", buf,
  140.                                    mon_nam(magr));
  141.                          }
  142.                      }
  143.                  }
  144.              } else
  145.                  missmm(magr, mdef, mattk);
  146.              break;
  147.  
  148.          case AT_HUGS: /* automatic if prev two attacks succeed */
  149.              strike = (i >= 2 && res[i - 1] == MM_HIT && res[i - 2] == MM_HIT);
  150.              if (strike)
  151.                  res[i] = hitmm(magr, mdef, mattk);
  152.  
  153.              break;
  154.  
  155.          case AT_GAZE:
  156.              strike = 0;
  157.              res[i] = gazemm(magr, mdef, mattk);
  158.              break;
  159.  
  160.          case AT_EXPL:
  161.              res[i] = explmm(magr, mdef, mattk);
  162.              if (res[i] == MM_MISS) { /* cancelled--no attack */
  163.                  strike = 0;
  164.                  attk = 0;
  165.              } else
  166.                  strike = 1; /* automatic hit */
  167.              break;
  168.  
  169.          case AT_ENGL:
  170.              if (u.usteed && (mdef == u.usteed)) {
  171.                  strike = 0;
  172.                  break;
  173.              }
  174.              /* Engulfing attacks are directed at the hero if
  175.               * possible. -dlc
  176.               */
  177.              if (u.uswallow && magr == u.ustuck)
  178.                  strike = 0;
  179.              else {
  180.                  if ((strike = (tmp > rnd(20 + i))))
  181.                      res[i] = gulpmm(magr, mdef, mattk);
  182.                  else
  183.                      missmm(magr, mdef, mattk);
  184.              }
  185.              break;
  186.  
  187.          default: /* no attack */
  188.              strike = 0;
  189.              attk = 0;
  190.              break;
  191.          }
  192.  
  193.          if (attk && !(res[i] & MM_AGR_DIED))
  194.              res[i] = passivemm(magr, mdef, strike, res[i] & MM_DEF_DIED);
  195.  
  196.          if (res[i] & MM_DEF_DIED)
  197.              return res[i];
  198.  
  199.          if (res[i] & MM_AGR_DIED)
  200.              return res[i];
  201.          /* return if aggressor can no longer attack */
  202.          if (!magr->mcanmove || magr->msleeping)
  203.              return res[i];
  204.          if (res[i] & MM_HIT)
  205.              struck = 1; /* at least one hit */
  206.      }
  207.  
  208.      return (struck ? MM_HIT : MM_MISS);
  209.  }
  210.  

hitmm

  1.  /* Returns the result of mdamagem(). */
  2.  STATIC_OVL int
  3.  hitmm(magr, mdef, mattk)
  4.  register struct monst *magr, *mdef;
  5.  struct attack *mattk;
  6.  {
  7.      if (vis) {
  8.          int compat;
  9.          char buf[BUFSZ], mdef_name[BUFSZ];
  10.  
  11.          if (!canspotmon(magr))
  12.              map_invisible(magr->mx, magr->my);
  13.          if (!canspotmon(mdef))
  14.              map_invisible(mdef->mx, mdef->my);
  15.          if (mdef->m_ap_type)
  16.              seemimic(mdef);
  17.          if (magr->m_ap_type)
  18.              seemimic(magr);
  19.          if ((compat = could_seduce(magr, mdef, mattk)) && !magr->mcan) {
  20.              Sprintf(buf, "%s %s", Monnam(magr),
  21.                      mdef->mcansee ? "smiles at" : "talks to");
  22.              pline("%s %s %s.", buf, mon_nam(mdef),
  23.                    compat == 2 ? "engagingly" : "seductively");
  24.          } else {
  25.              char magr_name[BUFSZ];
  26.  
  27.              Strcpy(magr_name, Monnam(magr));
  28.              switch (mattk->aatyp) {
  29.              case AT_BITE:
  30.                  Sprintf(buf, "%s bites", magr_name);
  31.                  break;
  32.              case AT_STNG:
  33.                  Sprintf(buf, "%s stings", magr_name);
  34.                  break;
  35.              case AT_BUTT:
  36.                  Sprintf(buf, "%s butts", magr_name);
  37.                  break;
  38.              case AT_TUCH:
  39.                  Sprintf(buf, "%s touches", magr_name);
  40.                  break;
  41.              case AT_TENT:
  42.                  Sprintf(buf, "%s tentacles suck", s_suffix(magr_name));
  43.                  break;
  44.              case AT_HUGS:
  45.                  if (magr != u.ustuck) {
  46.                      Sprintf(buf, "%s squeezes", magr_name);
  47.                      break;
  48.                  }
  49.              default:
  50.                  Sprintf(buf, "%s hits", magr_name);
  51.              }
  52.              pline("%s %s.", buf, mon_nam_too(mdef_name, mdef, magr));
  53.          }
  54.      } else
  55.          noises(magr, mattk);
  56.  
  57.      return mdamagem(magr, mdef, mattk);
  58.  }
  59.  

gazemm

  1.  /* Returns the same values as mdamagem(). */
  2.  STATIC_OVL int
  3.  gazemm(magr, mdef, mattk)
  4.  register struct monst *magr, *mdef;
  5.  struct attack *mattk;
  6.  {
  7.      char buf[BUFSZ];
  8.  
  9.      if (vis) {
  10.          Sprintf(buf, "%s gazes at", Monnam(magr));
  11.          pline("%s %s...", buf, mon_nam(mdef));
  12.      }
  13.  
  14.      if (magr->mcan || !magr->mcansee
  15.          || (magr->minvis && !perceives(mdef->data)) || !mdef->mcansee
  16.          || mdef->msleeping) {
  17.          if (vis)
  18.              pline("but nothing happens.");
  19.          return MM_MISS;
  20.      }
  21.      /* call mon_reflects 2x, first test, then, if visible, print message */
  22.      if (magr->data == &mons[PM_MEDUSA] && mon_reflects(mdef, (char *) 0)) {
  23.          if (canseemon(mdef))
  24.              (void) mon_reflects(mdef, "The gaze is reflected away by %s %s.");
  25.          if (mdef->mcansee) {
  26.              if (mon_reflects(magr, (char *) 0)) {
  27.                  if (canseemon(magr))
  28.                      (void) mon_reflects(
  29.                          magr, "The gaze is reflected away by %s %s.");
  30.                  return MM_MISS;
  31.              }
  32.              if (mdef->minvis && !perceives(magr->data)) {
  33.                  if (canseemon(magr)) {
  34.                      pline(
  35.                        "%s doesn't seem to notice that %s gaze was reflected.",
  36.                            Monnam(magr), mhis(magr));
  37.                  }
  38.                  return MM_MISS;
  39.              }
  40.              if (canseemon(magr))
  41.                  pline("%s is turned to stone!", Monnam(magr));
  42.              monstone(magr);
  43.              if (magr->mhp > 0)
  44.                  return MM_MISS;
  45.              return MM_AGR_DIED;
  46.          }
  47.      }
  48.  
  49.      return mdamagem(magr, mdef, mattk);
  50.  }
  51.  

engulf_target

  1.  /* return True if magr is allowed to swallow mdef, False otherwise */
  2.  boolean
  3.  engulf_target(magr, mdef)
  4.  struct monst *magr, *mdef;
  5.  {
  6.      struct rm *lev;
  7.      int dx, dy;
  8.  
  9.      /* can't swallow something that's too big */
  10.      if (mdef->data->msize >= MZ_HUGE)
  11.          return FALSE;
  12.  
  13.      /* (hypothetical) engulfers who can pass through walls aren't
  14.       limited by rock|trees|bars */
  15.      if ((magr == &youmonst) ? Passes_walls : passes_walls(magr->data))
  16.          return TRUE;
  17.  
  18.      /* don't swallow something in a spot where attacker wouldn't
  19.         otherwise be able to move onto; we don't want to engulf
  20.         a wall-phaser and end up with a non-phaser inside a wall */
  21.      dx = mdef->mx, dy = mdef->my;
  22.      if (mdef == &youmonst)
  23.          dx = u.ux, dy = u.uy;
  24.      lev = &levl[dx][dy];
  25.      if (IS_ROCK(lev->typ) || closed_door(dx, dy) || IS_TREE(lev->typ)
  26.          /* not passes_bars(); engulfer isn't squeezing through */
  27.          || (lev->typ == IRONBARS && !is_whirly(magr->data)))
  28.          return FALSE;
  29.  
  30.      return TRUE;
  31.  }
  32.  

gulpmm

  1.  /* Returns the same values as mattackm(). */
  2.  STATIC_OVL int
  3.  gulpmm(magr, mdef, mattk)
  4.  register struct monst *magr, *mdef;
  5.  register struct attack *mattk;
  6.  {
  7.      xchar ax, ay, dx, dy;
  8.      int status;
  9.      char buf[BUFSZ];
  10.      struct obj *obj;
  11.  
  12.      if (!engulf_target(magr, mdef))
  13.          return MM_MISS;
  14.  
  15.      if (vis) {
  16.          Sprintf(buf, "%s swallows", Monnam(magr));
  17.          pline("%s %s.", buf, mon_nam(mdef));
  18.      }
  19.      for (obj = mdef->minvent; obj; obj = obj->nobj)
  20.          (void) snuff_lit(obj);
  21.  
  22.      /*
  23.       *  All of this manipulation is needed to keep the display correct.
  24.       *  There is a flush at the next pline().
  25.       */
  26.      ax = magr->mx;
  27.      ay = magr->my;
  28.      dx = mdef->mx;
  29.      dy = mdef->my;
  30.      /*
  31.       *  Leave the defender in the monster chain at it's current position,
  32.       *  but don't leave it on the screen.  Move the aggressor to the
  33.       *  defender's position.
  34.       */
  35.      remove_monster(ax, ay);
  36.      place_monster(magr, dx, dy);
  37.      newsym(ax, ay); /* erase old position */
  38.      newsym(dx, dy); /* update new position */
  39.  
  40.      status = mdamagem(magr, mdef, mattk);
  41.  
  42.      if ((status & (MM_AGR_DIED | MM_DEF_DIED))
  43.          == (MM_AGR_DIED | MM_DEF_DIED)) {
  44.          ;                              /* both died -- do nothing  */
  45.      } else if (status & MM_DEF_DIED) { /* defender died */
  46.          /*
  47.           *  Note:  remove_monster() was called in relmon(), wiping out
  48.           *  magr from level.monsters[mdef->mx][mdef->my].  We need to
  49.           *  put it back and display it.  -kd
  50.           */
  51.          place_monster(magr, dx, dy);
  52.          newsym(dx, dy);
  53.          /* aggressor moves to <dx,dy> and might encounter trouble there */
  54.          if (minliquid(magr) || (t_at(dx, dy) && mintrap(magr) == 2))
  55.              status |= MM_AGR_DIED;
  56.      } else if (status & MM_AGR_DIED) { /* aggressor died */
  57.          place_monster(mdef, dx, dy);
  58.          newsym(dx, dy);
  59.      } else { /* both alive, put them back */
  60.          if (cansee(dx, dy))
  61.              pline("%s is regurgitated!", Monnam(mdef));
  62.  
  63.          place_monster(magr, ax, ay);
  64.          place_monster(mdef, dx, dy);
  65.          newsym(ax, ay);
  66.          newsym(dx, dy);
  67.      }
  68.  
  69.      return status;
  70.  }
  71.  

explmm

  1.  STATIC_OVL int
  2.  explmm(magr, mdef, mattk)
  3.  struct monst *magr, *mdef;
  4.  struct attack *mattk;
  5.  {
  6.      int result;
  7.  
  8.      if (magr->mcan)
  9.          return MM_MISS;
  10.  
  11.      if (cansee(magr->mx, magr->my))
  12.          pline("%s explodes!", Monnam(magr));
  13.      else
  14.          noises(magr, mattk);
  15.  
  16.      result = mdamagem(magr, mdef, mattk);
  17.  
  18.      /* Kill off aggressor if it didn't die. */
  19.      if (!(result & MM_AGR_DIED)) {
  20.          mondead(magr);
  21.          if (magr->mhp > 0)
  22.              return result; /* life saved */
  23.          result |= MM_AGR_DIED;
  24.      }
  25.      if (magr->mtame) /* give this one even if it was visible */
  26.          You(brief_feeling, "melancholy");
  27.  
  28.      return result;
  29.  }
  30.  

mdamagem

  1.  /*
  2.   *  See comment at top of mattackm(), for return values.
  3.   */
  4.  STATIC_OVL int
  5.  mdamagem(magr, mdef, mattk)
  6.  register struct monst *magr, *mdef;
  7.  register struct attack *mattk;
  8.  {
  9.      struct obj *obj;
  10.      char buf[BUFSZ];
  11.      struct permonst *pa = magr->data, *pd = mdef->data;
  12.      int armpro, num, tmp = d((int) mattk->damn, (int) mattk->damd),
  13.                       res = MM_MISS;
  14.      boolean cancelled;
  15.  
  16.      if ((touch_petrifies(pd) /* or flesh_petrifies() */
  17.           || (mattk->adtyp == AD_DGST && pd == &mons[PM_MEDUSA]))
  18.          && !resists_ston(magr)) {
  19.          long protector = attk_protection((int) mattk->aatyp),
  20.               wornitems = magr->misc_worn_check;
  21.  
  22.          /* wielded weapon gives same protection as gloves here */
  23.          if (otmp != 0)
  24.              wornitems |= W_ARMG;
  25.  
  26.          if (protector == 0L
  27.              || (protector != ~0L && (wornitems & protector) != protector)) {
  28.              if (poly_when_stoned(pa)) {
  29.                  mon_to_stone(magr);
  30.                  return MM_HIT; /* no damage during the polymorph */
  31.              }
  32.              if (vis)
  33.                  pline("%s turns to stone!", Monnam(magr));
  34.              monstone(magr);
  35.              if (magr->mhp > 0)
  36.                  return MM_HIT; /* lifesaved */
  37.              else if (magr->mtame && !vis)
  38.                  You(brief_feeling, "peculiarly sad");
  39.              return MM_AGR_DIED;
  40.          }
  41.      }
  42.  
  43.      /* cancellation factor is the same as when attacking the hero */
  44.      armpro = magic_negation(mdef);
  45.      cancelled = magr->mcan || !(rn2(10) >= 3 * armpro);
  46.  
  47.      switch (mattk->adtyp) {
  48.      case AD_DGST:
  49.          /* eating a Rider or its corpse is fatal */
  50.          if (is_rider(pd)) {
  51.              if (vis)
  52.                  pline("%s %s!", Monnam(magr),
  53.                        (pd == &mons[PM_FAMINE])
  54.                            ? "belches feebly, shrivels up and dies"
  55.                            : (pd == &mons[PM_PESTILENCE])
  56.                                  ? "coughs spasmodically and collapses"
  57.                                  : "vomits violently and drops dead");
  58.              mondied(magr);
  59.              if (magr->mhp > 0)
  60.                  return 0; /* lifesaved */
  61.              else if (magr->mtame && !vis)
  62.                  You(brief_feeling, "queasy");
  63.              return MM_AGR_DIED;
  64.          }
  65.          if (flags.verbose && !Deaf)
  66.              verbalize("Burrrrp!");
  67.          tmp = mdef->mhp;
  68.          /* Use up amulet of life saving */
  69.          if (!!(obj = mlifesaver(mdef)))
  70.              m_useup(mdef, obj);
  71.  
  72.          /* Is a corpse for nutrition possible?  It may kill magr */
  73.          if (!corpse_chance(mdef, magr, TRUE) || magr->mhp < 1)
  74.              break;
  75.  
  76.          /* Pets get nutrition from swallowing monster whole.
  77.           * No nutrition from G_NOCORPSE monster, eg, undead.
  78.           * DGST monsters don't die from undead corpses
  79.           */
  80.          num = monsndx(pd);
  81.          if (magr->mtame && !magr->isminion
  82.              && !(mvitals[num].mvflags & G_NOCORPSE)) {
  83.              struct obj *virtualcorpse = mksobj(CORPSE, FALSE, FALSE);
  84.              int nutrit;
  85.  
  86.              set_corpsenm(virtualcorpse, num);
  87.              nutrit = dog_nutrition(magr, virtualcorpse);
  88.              dealloc_obj(virtualcorpse);
  89.  
  90.              /* only 50% nutrition, 25% of normal eating time */
  91.              if (magr->meating > 1)
  92.                  magr->meating = (magr->meating + 3) / 4;
  93.              if (nutrit > 1)
  94.                  nutrit /= 2;
  95.              EDOG(magr)->hungrytime += nutrit;
  96.          }
  97.          break;
  98.      case AD_STUN:
  99.          if (magr->mcan)
  100.              break;
  101.          if (canseemon(mdef))
  102.              pline("%s %s for a moment.", Monnam(mdef),
  103.                    makeplural(stagger(pd, "stagger")));
  104.          mdef->mstun = 1;
  105.          goto physical;
  106.      case AD_LEGS:
  107.          if (magr->mcan) {
  108.              tmp = 0;
  109.              break;
  110.          }
  111.          goto physical;
  112.      case AD_WERE:
  113.      case AD_HEAL:
  114.      case AD_PHYS:
  115.      physical:
  116.          if (mattk->aatyp == AT_KICK && thick_skinned(pd)) {
  117.              tmp = 0;
  118.          } else if (mattk->aatyp == AT_WEAP) {
  119.              if (otmp) {
  120.                  if (otmp->otyp == CORPSE
  121.                      && touch_petrifies(&mons[otmp->corpsenm]))
  122.                      goto do_stone;
  123.                  tmp += dmgval(otmp, mdef);
  124.                  if (otmp->oartifact) {
  125.                      (void) artifact_hit(magr, mdef, otmp, &tmp, dieroll);
  126.                      if (mdef->mhp <= 0)
  127.                          return (MM_DEF_DIED
  128.                                  | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED));
  129.                  }
  130.                  if (tmp)
  131.                      rustm(mdef, otmp);
  132.              }
  133.          } else if (pa == &mons[PM_PURPLE_WORM] && pd == &mons[PM_SHRIEKER]) {
  134.              /* hack to enhance mm_aggression(); we don't want purple
  135.                 worm's bite attack to kill a shrieker because then it
  136.                 won't swallow the corpse; but if the target survives,
  137.                 the subsequent engulf attack should accomplish that */
  138.              if (tmp >= mdef->mhp && mdef->mhp > 1)
  139.                  tmp = mdef->mhp - 1;
  140.          }
  141.          break;
  142.      case AD_FIRE:
  143.          if (cancelled) {
  144.              tmp = 0;
  145.              break;
  146.          }
  147.          if (vis)
  148.              pline("%s is %s!", Monnam(mdef), on_fire(pd, mattk));
  149.          if (pd == &mons[PM_STRAW_GOLEM] || pd == &mons[PM_PAPER_GOLEM]) {
  150.              if (vis)
  151.                  pline("%s burns completely!", Monnam(mdef));
  152.              mondied(mdef);
  153.              if (mdef->mhp > 0)
  154.                  return 0;
  155.              else if (mdef->mtame && !vis)
  156.                  pline("May %s roast in peace.", mon_nam(mdef));
  157.              return (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED));
  158.          }
  159.          tmp += destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE);
  160.          tmp += destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE);
  161.          if (resists_fire(mdef)) {
  162.              if (vis)
  163.                  pline_The("fire doesn't seem to burn %s!", mon_nam(mdef));
  164.              shieldeff(mdef->mx, mdef->my);
  165.              golemeffects(mdef, AD_FIRE, tmp);
  166.              tmp = 0;
  167.          }
  168.          /* only potions damage resistant players in destroy_item */
  169.          tmp += destroy_mitem(mdef, POTION_CLASS, AD_FIRE);
  170.          break;
  171.      case AD_COLD:
  172.          if (cancelled) {
  173.              tmp = 0;
  174.              break;
  175.          }
  176.          if (vis)
  177.              pline("%s is covered in frost!", Monnam(mdef));
  178.          if (resists_cold(mdef)) {
  179.              if (vis)
  180.                  pline_The("frost doesn't seem to chill %s!", mon_nam(mdef));
  181.              shieldeff(mdef->mx, mdef->my);
  182.              golemeffects(mdef, AD_COLD, tmp);
  183.              tmp = 0;
  184.          }
  185.          tmp += destroy_mitem(mdef, POTION_CLASS, AD_COLD);
  186.          break;
  187.      case AD_ELEC:
  188.          if (cancelled) {
  189.              tmp = 0;
  190.              break;
  191.          }
  192.          if (vis)
  193.              pline("%s gets zapped!", Monnam(mdef));
  194.          tmp += destroy_mitem(mdef, WAND_CLASS, AD_ELEC);
  195.          if (resists_elec(mdef)) {
  196.              if (vis)
  197.                  pline_The("zap doesn't shock %s!", mon_nam(mdef));
  198.              shieldeff(mdef->mx, mdef->my);
  199.              golemeffects(mdef, AD_ELEC, tmp);
  200.              tmp = 0;
  201.          }
  202.          /* only rings damage resistant players in destroy_item */
  203.          tmp += destroy_mitem(mdef, RING_CLASS, AD_ELEC);
  204.          break;
  205.      case AD_ACID:
  206.          if (magr->mcan) {
  207.              tmp = 0;
  208.              break;
  209.          }
  210.          if (resists_acid(mdef)) {
  211.              if (vis)
  212.                  pline("%s is covered in acid, but it seems harmless.",
  213.                        Monnam(mdef));
  214.              tmp = 0;
  215.          } else if (vis) {
  216.              pline("%s is covered in acid!", Monnam(mdef));
  217.              pline("It burns %s!", mon_nam(mdef));
  218.          }
  219.          if (!rn2(30))
  220.              erode_armor(mdef, ERODE_CORRODE);
  221.          if (!rn2(6))
  222.              acid_damage(MON_WEP(mdef));
  223.          break;
  224.      case AD_RUST:
  225.          if (magr->mcan)
  226.              break;
  227.          if (pd == &mons[PM_IRON_GOLEM]) {
  228.              if (vis)
  229.                  pline("%s falls to pieces!", Monnam(mdef));
  230.              mondied(mdef);
  231.              if (mdef->mhp > 0)
  232.                  return 0;
  233.              else if (mdef->mtame && !vis)
  234.                  pline("May %s rust in peace.", mon_nam(mdef));
  235.              return (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED));
  236.          }
  237.          erode_armor(mdef, ERODE_RUST);
  238.          mdef->mstrategy &= ~STRAT_WAITFORU;
  239.          tmp = 0;
  240.          break;
  241.      case AD_CORR:
  242.          if (magr->mcan)
  243.              break;
  244.          erode_armor(mdef, ERODE_CORRODE);
  245.          mdef->mstrategy &= ~STRAT_WAITFORU;
  246.          tmp = 0;
  247.          break;
  248.      case AD_DCAY:
  249.          if (magr->mcan)
  250.              break;
  251.          if (pd == &mons[PM_WOOD_GOLEM] || pd == &mons[PM_LEATHER_GOLEM]) {
  252.              if (vis)
  253.                  pline("%s falls to pieces!", Monnam(mdef));
  254.              mondied(mdef);
  255.              if (mdef->mhp > 0)
  256.                  return 0;
  257.              else if (mdef->mtame && !vis)
  258.                  pline("May %s rot in peace.", mon_nam(mdef));
  259.              return (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED));
  260.          }
  261.          erode_armor(mdef, ERODE_CORRODE);
  262.          mdef->mstrategy &= ~STRAT_WAITFORU;
  263.          tmp = 0;
  264.          break;
  265.      case AD_STON:
  266.          if (magr->mcan)
  267.              break;
  268.      do_stone:
  269.          /* may die from the acid if it eats a stone-curing corpse */
  270.          if (munstone(mdef, FALSE))
  271.              goto post_stone;
  272.          if (poly_when_stoned(pd)) {
  273.              mon_to_stone(mdef);
  274.              tmp = 0;
  275.              break;
  276.          }
  277.          if (!resists_ston(mdef)) {
  278.              if (vis)
  279.                  pline("%s turns to stone!", Monnam(mdef));
  280.              monstone(mdef);
  281.          post_stone:
  282.              if (mdef->mhp > 0)
  283.                  return 0;
  284.              else if (mdef->mtame && !vis)
  285.                  You(brief_feeling, "peculiarly sad");
  286.              return (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED));
  287.          }
  288.          tmp = (mattk->adtyp == AD_STON ? 0 : 1);
  289.          break;
  290.      case AD_TLPT:
  291.          if (!cancelled && tmp < mdef->mhp && !tele_restrict(mdef)) {
  292.              char mdef_Monnam[BUFSZ];
  293.              /* save the name before monster teleports, otherwise
  294.                 we'll get "it" in the suddenly disappears message */
  295.              if (vis)
  296.                  Strcpy(mdef_Monnam, Monnam(mdef));
  297.              mdef->mstrategy &= ~STRAT_WAITFORU;
  298.              (void) rloc(mdef, TRUE);
  299.              if (vis && !canspotmon(mdef) && mdef != u.usteed)
  300.                  pline("%s suddenly disappears!", mdef_Monnam);
  301.          }
  302.          break;
  303.      case AD_SLEE:
  304.          if (!cancelled && !mdef->msleeping
  305.              && sleep_monst(mdef, rnd(10), -1)) {
  306.              if (vis) {
  307.                  Strcpy(buf, Monnam(mdef));
  308.                  pline("%s is put to sleep by %s.", buf, mon_nam(magr));
  309.              }
  310.              mdef->mstrategy &= ~STRAT_WAITFORU;
  311.              slept_monst(mdef);
  312.          }
  313.          break;
  314.      case AD_PLYS:
  315.          if (!cancelled && mdef->mcanmove) {
  316.              if (vis) {
  317.                  Strcpy(buf, Monnam(mdef));
  318.                  pline("%s is frozen by %s.", buf, mon_nam(magr));
  319.              }
  320.              paralyze_monst(mdef, rnd(10));
  321.          }
  322.          break;
  323.      case AD_SLOW:
  324.          if (!cancelled && mdef->mspeed != MSLOW) {
  325.              unsigned int oldspeed = mdef->mspeed;
  326.  
  327.              mon_adjust_speed(mdef, -1, (struct obj *) 0);
  328.              mdef->mstrategy &= ~STRAT_WAITFORU;
  329.              if (mdef->mspeed != oldspeed && vis)
  330.                  pline("%s slows down.", Monnam(mdef));
  331.          }
  332.          break;
  333.      case AD_CONF:
  334.          /* Since confusing another monster doesn't have a real time
  335.           * limit, setting spec_used would not really be right (though
  336.           * we still should check for it).
  337.           */
  338.          if (!magr->mcan && !mdef->mconf && !magr->mspec_used) {
  339.              if (vis)
  340.                  pline("%s looks confused.", Monnam(mdef));
  341.              mdef->mconf = 1;
  342.              mdef->mstrategy &= ~STRAT_WAITFORU;
  343.          }
  344.          break;
  345.      case AD_BLND:
  346.          if (can_blnd(magr, mdef, mattk->aatyp, (struct obj *) 0)) {
  347.              register unsigned rnd_tmp;
  348.  
  349.              if (vis && mdef->mcansee)
  350.                  pline("%s is blinded.", Monnam(mdef));
  351.              rnd_tmp = d((int) mattk->damn, (int) mattk->damd);
  352.              if ((rnd_tmp += mdef->mblinded) > 127)
  353.                  rnd_tmp = 127;
  354.              mdef->mblinded = rnd_tmp;
  355.              mdef->mcansee = 0;
  356.              mdef->mstrategy &= ~STRAT_WAITFORU;
  357.          }
  358.          tmp = 0;
  359.          break;
  360.      case AD_HALU:
  361.          if (!magr->mcan && haseyes(pd) && mdef->mcansee) {
  362.              if (vis)
  363.                  pline("%s looks %sconfused.", Monnam(mdef),
  364.                        mdef->mconf ? "more " : "");
  365.              mdef->mconf = 1;
  366.              mdef->mstrategy &= ~STRAT_WAITFORU;
  367.          }
  368.          tmp = 0;
  369.          break;
  370.      case AD_CURS:
  371.          if (!night() && (pa == &mons[PM_GREMLIN]))
  372.              break;
  373.          if (!magr->mcan && !rn2(10)) {
  374.              mdef->mcan = 1; /* cancelled regardless of lifesave */
  375.              mdef->mstrategy &= ~STRAT_WAITFORU;
  376.              if (is_were(pd) && pd->mlet != S_HUMAN)
  377.                  were_change(mdef);
  378.              if (pd == &mons[PM_CLAY_GOLEM]) {
  379.                  if (vis) {
  380.                      pline("Some writing vanishes from %s head!",
  381.                            s_suffix(mon_nam(mdef)));
  382.                      pline("%s is destroyed!", Monnam(mdef));
  383.                  }
  384.                  mondied(mdef);
  385.                  if (mdef->mhp > 0)
  386.                      return 0;
  387.                  else if (mdef->mtame && !vis)
  388.                      You(brief_feeling, "strangely sad");
  389.                  return (MM_DEF_DIED
  390.                          | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED));
  391.              }
  392.              if (!Deaf) {
  393.                  if (!vis)
  394.                      You_hear("laughter.");
  395.                  else
  396.                      pline("%s chuckles.", Monnam(magr));
  397.              }
  398.          }
  399.          break;
  400.      case AD_SGLD:
  401.          tmp = 0;
  402.          if (magr->mcan)
  403.              break;
  404.          /* technically incorrect; no check for stealing gold from
  405.           * between mdef's feet...
  406.           */
  407.          {
  408.              struct obj *gold = findgold(mdef->minvent);
  409.              if (!gold)
  410.                  break;
  411.              obj_extract_self(gold);
  412.              add_to_minv(magr, gold);
  413.          }
  414.          mdef->mstrategy &= ~STRAT_WAITFORU;
  415.          if (vis) {
  416.              Strcpy(buf, Monnam(magr));
  417.              pline("%s steals some gold from %s.", buf, mon_nam(mdef));
  418.          }
  419.          if (!tele_restrict(magr)) {
  420.              (void) rloc(magr, TRUE);
  421.              if (vis && !canspotmon(magr))
  422.                  pline("%s suddenly disappears!", buf);
  423.          }
  424.          break;
  425.      case AD_DRLI:
  426.          if (!cancelled && !rn2(3) && !resists_drli(mdef)) {
  427.              tmp = d(2, 6);
  428.              if (vis)
  429.                  pline("%s suddenly seems weaker!", Monnam(mdef));
  430.              mdef->mhpmax -= tmp;
  431.              if (mdef->m_lev == 0)
  432.                  tmp = mdef->mhp;
  433.              else
  434.                  mdef->m_lev--;
  435.              /* Automatic kill if drained past level 0 */
  436.          }
  437.          break;
  438.      case AD_SSEX:
  439.      case AD_SITM: /* for now these are the same */
  440.      case AD_SEDU:
  441.          if (magr->mcan)
  442.              break;
  443.          /* find an object to steal, non-cursed if magr is tame */
  444.          for (obj = mdef->minvent; obj; obj = obj->nobj)
  445.              if (!magr->mtame || !obj->cursed)
  446.                  break;
  447.  
  448.          if (obj) {
  449.              char onambuf[BUFSZ], mdefnambuf[BUFSZ];
  450.  
  451.              /* make a special x_monnam() call that never omits
  452.                 the saddle, and save it for later messages */
  453.              Strcpy(mdefnambuf,
  454.                     x_monnam(mdef, ARTICLE_THE, (char *) 0, 0, FALSE));
  455.  
  456.              otmp = obj;
  457.              if (u.usteed == mdef && otmp == which_armor(mdef, W_SADDLE))
  458.                  /* "You can no longer ride <steed>." */
  459.                  dismount_steed(DISMOUNT_POLY);
  460.              obj_extract_self(otmp);
  461.              if (otmp->owornmask) {
  462.                  mdef->misc_worn_check &= ~otmp->owornmask;
  463.                  if (otmp->owornmask & W_WEP)
  464.                      mwepgone(mdef);
  465.                  otmp->owornmask = 0L;
  466.                  update_mon_intrinsics(mdef, otmp, FALSE, FALSE);
  467.              }
  468.              /* add_to_minv() might free otmp [if it merges] */
  469.              if (vis)
  470.                  Strcpy(onambuf, doname(otmp));
  471.              (void) add_to_minv(magr, otmp);
  472.              if (vis) {
  473.                  Strcpy(buf, Monnam(magr));
  474.                  pline("%s steals %s from %s!", buf, onambuf, mdefnambuf);
  475.              }
  476.              possibly_unwield(mdef, FALSE);
  477.              mdef->mstrategy &= ~STRAT_WAITFORU;
  478.              mselftouch(mdef, (const char *) 0, FALSE);
  479.              if (mdef->mhp <= 0)
  480.                  return (MM_DEF_DIED
  481.                          | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED));
  482.              if (pa->mlet == S_NYMPH && !tele_restrict(magr)) {
  483.                  (void) rloc(magr, TRUE);
  484.                  if (vis && !canspotmon(magr))
  485.                      pline("%s suddenly disappears!", buf);
  486.              }
  487.          }
  488.          tmp = 0;
  489.          break;
  490.      case AD_DREN:
  491.          if (!cancelled && !rn2(4))
  492.              xdrainenergym(mdef, vis && mattk->aatyp != AT_ENGL);
  493.          tmp = 0;
  494.          break;
  495.      case AD_DRST:
  496.      case AD_DRDX:
  497.      case AD_DRCO:
  498.          if (!cancelled && !rn2(8)) {
  499.              if (vis)
  500.                  pline("%s %s was poisoned!", s_suffix(Monnam(magr)),
  501.                        mpoisons_subj(magr, mattk));
  502.              if (resists_poison(mdef)) {
  503.                  if (vis)
  504.                      pline_The("poison doesn't seem to affect %s.",
  505.                                mon_nam(mdef));
  506.              } else {
  507.                  if (rn2(10))
  508.                      tmp += rn1(10, 6);
  509.                  else {
  510.                      if (vis)
  511.                          pline_The("poison was deadly...");
  512.                      tmp = mdef->mhp;
  513.                  }
  514.              }
  515.          }
  516.          break;
  517.      case AD_DRIN:
  518.          if (notonhead || !has_head(pd)) {
  519.              if (vis)
  520.                  pline("%s doesn't seem harmed.", Monnam(mdef));
  521.              /* Not clear what to do for green slimes */
  522.              tmp = 0;
  523.              break;
  524.          }
  525.          if ((mdef->misc_worn_check & W_ARMH) && rn2(8)) {
  526.              if (vis) {
  527.                  Strcpy(buf, s_suffix(Monnam(mdef)));
  528.                  pline("%s helmet blocks %s attack to %s head.", buf,
  529.                        s_suffix(mon_nam(magr)), mhis(mdef));
  530.              }
  531.              break;
  532.          }
  533.          res = eat_brains(magr, mdef, vis, &tmp);
  534.          break;
  535.      case AD_SLIM:
  536.          if (cancelled)
  537.              break; /* physical damage only */
  538.          if (!rn2(4) && !slimeproof(pd)) {
  539.              if (!munslime(mdef, FALSE) && mdef->mhp > 0) {
  540.                  if (newcham(mdef, &mons[PM_GREEN_SLIME], FALSE, vis))
  541.                      pd = mdef->data;
  542.                  mdef->mstrategy &= ~STRAT_WAITFORU;
  543.                  res = MM_HIT;
  544.              }
  545.              /* munslime attempt could have been fatal,
  546.                 potentially to multiple monsters (SCR_FIRE) */
  547.              if (magr->mhp < 1)
  548.                  res |= MM_AGR_DIED;
  549.              if (mdef->mhp < 1)
  550.                  res |= MM_DEF_DIED;
  551.              tmp = 0;
  552.          }
  553.          break;
  554.      case AD_STCK:
  555.          if (cancelled)
  556.              tmp = 0;
  557.          break;
  558.      case AD_WRAP: /* monsters cannot grab one another, it's too hard */
  559.          if (magr->mcan)
  560.              tmp = 0;
  561.          break;
  562.      case AD_ENCH:
  563.          /* there's no msomearmor() function, so just do damage */
  564.          /* if (cancelled) break; */
  565.          break;
  566.      default:
  567.          tmp = 0;
  568.          break;
  569.      }
  570.      if (!tmp)
  571.          return res;
  572.  
  573.      if ((mdef->mhp -= tmp) < 1) {
  574.          if (m_at(mdef->mx, mdef->my) == magr) { /* see gulpmm() */
  575.              remove_monster(mdef->mx, mdef->my);
  576.              mdef->mhp = 1; /* otherwise place_monster will complain */
  577.              place_monster(mdef, mdef->mx, mdef->my);
  578.              mdef->mhp = 0;
  579.          }
  580.          monkilled(mdef, "", (int) mattk->adtyp);
  581.          if (mdef->mhp > 0)
  582.              return res; /* mdef lifesaved */
  583.          else if (res == MM_AGR_DIED)
  584.              return (MM_DEF_DIED | MM_AGR_DIED);
  585.  
  586.          if (mattk->adtyp == AD_DGST) {
  587.              /* various checks similar to dog_eat and meatobj.
  588.               * after monkilled() to provide better message ordering */
  589.              if (mdef->cham >= LOW_PM) {
  590.                  (void) newcham(magr, (struct permonst *) 0, FALSE, TRUE);
  591.              } else if (pd == &mons[PM_GREEN_SLIME] && !slimeproof(pa)) {
  592.                  (void) newcham(magr, &mons[PM_GREEN_SLIME], FALSE, TRUE);
  593.              } else if (pd == &mons[PM_WRAITH]) {
  594.                  (void) grow_up(magr, (struct monst *) 0);
  595.                  /* don't grow up twice */
  596.                  return (MM_DEF_DIED | (magr->mhp > 0 ? 0 : MM_AGR_DIED));
  597.              } else if (pd == &mons[PM_NURSE]) {
  598.                  magr->mhp = magr->mhpmax;
  599.              }
  600.          }
  601.          /* caveat: above digestion handling doesn't keep `pa' up to date */
  602.  
  603.          return (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED));
  604.      }
  605.      return (res == MM_AGR_DIED) ? MM_AGR_DIED : MM_HIT;
  606.  }
  607.  

paralyze_monst

  1.  void
  2.  paralyze_monst(mon, amt)
  3.  struct monst *mon;
  4.  int amt;
  5.  {
  6.      if (amt > 127)
  7.          amt = 127;
  8.  
  9.      mon->mcanmove = 0;
  10.      mon->mfrozen = amt;
  11.      mon->meating = 0; /* terminate any meal-in-progress */
  12.      mon->mstrategy &= ~STRAT_WAITFORU;
  13.  }
  14.  

sleep_monst

  1.  /* `mon' is hit by a sleep attack; return 1 if it's affected, 0 otherwise */
  2.  int
  3.  sleep_monst(mon, amt, how)
  4.  struct monst *mon;
  5.  int amt, how;
  6.  {
  7.      if (resists_sleep(mon)
  8.          || (how >= 0 && resist(mon, (char) how, 0, NOTELL))) {
  9.          shieldeff(mon->mx, mon->my);
  10.      } else if (mon->mcanmove) {
  11.          finish_meating(mon); /* terminate any meal-in-progress */
  12.          amt += (int) mon->mfrozen;
  13.          if (amt > 0) { /* sleep for N turns */
  14.              mon->mcanmove = 0;
  15.              mon->mfrozen = min(amt, 127);
  16.          } else { /* sleep until awakened */
  17.              mon->msleeping = 1;
  18.          }
  19.          return 1;
  20.      }
  21.      return 0;
  22.  }
  23.  

slept_monst

  1.  /* sleeping grabber releases, engulfer doesn't; don't use for paralysis! */
  2.  void
  3.  slept_monst(mon)
  4.  struct monst *mon;
  5.  {
  6.      if ((mon->msleeping || !mon->mcanmove) && mon == u.ustuck
  7.          && !sticks(youmonst.data) && !u.uswallow) {
  8.          pline("%s grip relaxes.", s_suffix(Monnam(mon)));
  9.          unstuck(mon);
  10.      }
  11.  }
  12.  

rustm

  1.  void
  2.  rustm(mdef, obj)
  3.  struct monst *mdef;
  4.  struct obj *obj;
  5.  {
  6.      int dmgtyp;
  7.  
  8.      if (!mdef || !obj)
  9.          return; /* just in case */
  10.      /* AD_ACID is handled in passivemm */
  11.      if (dmgtype(mdef->data, AD_CORR))
  12.          dmgtyp = ERODE_CORRODE;
  13.      else if (dmgtype(mdef->data, AD_RUST))
  14.          dmgtyp = ERODE_RUST;
  15.      else if (dmgtype(mdef->data, AD_FIRE))
  16.          dmgtyp = ERODE_BURN;
  17.      else
  18.          return;
  19.      (void) erode_obj(obj, NULL, dmgtyp, EF_GREASE | EF_VERBOSE);
  20.  }
  21.  

mswingsm

  1.  STATIC_OVL void
  2.  mswingsm(magr, mdef, otemp)
  3.  struct monst *magr, *mdef;
  4.  struct obj *otemp;
  5.  {
  6.      if (flags.verbose && !Blind && mon_visible(magr)) {
  7.          pline("%s %s %s%s %s at %s.", Monnam(magr),
  8.                (objects[otemp->otyp].oc_dir & PIERCE) ? "thrusts" : "swings",
  9.                (otemp->quan > 1L) ? "one of " : "", mhis(magr), xname(otemp),
  10.                mon_nam(mdef));
  11.      }
  12.  }
  13.  

passivemm

  1.  /*
  2.   * Passive responses by defenders.  Does not replicate responses already
  3.   * handled above.  Returns same values as mattackm.
  4.   */
  5.  STATIC_OVL int
  6.  passivemm(magr, mdef, mhit, mdead)
  7.  register struct monst *magr, *mdef;
  8.  boolean mhit;
  9.  int mdead;
  10.  {
  11.      register struct permonst *mddat = mdef->data;
  12.      register struct permonst *madat = magr->data;
  13.      char buf[BUFSZ];
  14.      int i, tmp;
  15.  
  16.      for (i = 0;; i++) {
  17.          if (i >= NATTK)
  18.              return (mdead | mhit); /* no passive attacks */
  19.          if (mddat->mattk[i].aatyp == AT_NONE)
  20.              break;
  21.      }
  22.      if (mddat->mattk[i].damn)
  23.          tmp = d((int) mddat->mattk[i].damn, (int) mddat->mattk[i].damd);
  24.      else if (mddat->mattk[i].damd)
  25.          tmp = d((int) mddat->mlevel + 1, (int) mddat->mattk[i].damd);
  26.      else
  27.          tmp = 0;
  28.  
  29.      /* These affect the enemy even if defender killed */
  30.      switch (mddat->mattk[i].adtyp) {
  31.      case AD_ACID:
  32.          if (mhit && !rn2(2)) {
  33.              Strcpy(buf, Monnam(magr));
  34.              if (canseemon(magr))
  35.                  pline("%s is splashed by %s acid!", buf,
  36.                        s_suffix(mon_nam(mdef)));
  37.              if (resists_acid(magr)) {
  38.                  if (canseemon(magr))
  39.                      pline("%s is not affected.", Monnam(magr));
  40.                  tmp = 0;
  41.              }
  42.          } else
  43.              tmp = 0;
  44.          if (!rn2(30))
  45.              erode_armor(magr, ERODE_CORRODE);
  46.          if (!rn2(6))
  47.              acid_damage(MON_WEP(magr));
  48.          goto assess_dmg;
  49.      case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */
  50.          if (mhit && !mdef->mcan && otmp) {
  51.              (void) drain_item(otmp);
  52.              /* No message */
  53.          }
  54.          break;
  55.      default:
  56.          break;
  57.      }
  58.      if (mdead || mdef->mcan)
  59.          return (mdead | mhit);
  60.  
  61.      /* These affect the enemy only if defender is still alive */
  62.      if (rn2(3))
  63.          switch (mddat->mattk[i].adtyp) {
  64.          case AD_PLYS: /* Floating eye */
  65.              if (tmp > 127)
  66.                  tmp = 127;
  67.              if (mddat == &mons[PM_FLOATING_EYE]) {
  68.                  if (!rn2(4))
  69.                      tmp = 127;
  70.                  if (magr->mcansee && haseyes(madat) && mdef->mcansee
  71.                      && (perceives(madat) || !mdef->minvis)) {
  72.                      Sprintf(buf, "%s gaze is reflected by %%s %%s.",
  73.                              s_suffix(Monnam(mdef)));
  74.                      if (mon_reflects(magr,
  75.                                       canseemon(magr) ? buf : (char *) 0))
  76.                          return (mdead | mhit);
  77.                      Strcpy(buf, Monnam(magr));
  78.                      if (canseemon(magr))
  79.                          pline("%s is frozen by %s gaze!", buf,
  80.                                s_suffix(mon_nam(mdef)));
  81.                      paralyze_monst(magr, tmp);
  82.                      return (mdead | mhit);
  83.                  }
  84.              } else { /* gelatinous cube */
  85.                  Strcpy(buf, Monnam(magr));
  86.                  if (canseemon(magr))
  87.                      pline("%s is frozen by %s.", buf, mon_nam(mdef));
  88.                  paralyze_monst(magr, tmp);
  89.                  return (mdead | mhit);
  90.              }
  91.              return 1;
  92.          case AD_COLD:
  93.              if (resists_cold(magr)) {
  94.                  if (canseemon(magr)) {
  95.                      pline("%s is mildly chilly.", Monnam(magr));
  96.                      golemeffects(magr, AD_COLD, tmp);
  97.                  }
  98.                  tmp = 0;
  99.                  break;
  100.              }
  101.              if (canseemon(magr))
  102.                  pline("%s is suddenly very cold!", Monnam(magr));
  103.              mdef->mhp += tmp / 2;
  104.              if (mdef->mhpmax < mdef->mhp)
  105.                  mdef->mhpmax = mdef->mhp;
  106.              if (mdef->mhpmax > ((int) (mdef->m_lev + 1) * 8))
  107.                  (void) split_mon(mdef, magr);
  108.              break;
  109.          case AD_STUN:
  110.              if (!magr->mstun) {
  111.                  magr->mstun = 1;
  112.                  if (canseemon(magr))
  113.                      pline("%s %s...", Monnam(magr),
  114.                            makeplural(stagger(magr->data, "stagger")));
  115.              }
  116.              tmp = 0;
  117.              break;
  118.          case AD_FIRE:
  119.              if (resists_fire(magr)) {
  120.                  if (canseemon(magr)) {
  121.                      pline("%s is mildly warmed.", Monnam(magr));
  122.                      golemeffects(magr, AD_FIRE, tmp);
  123.                  }
  124.                  tmp = 0;
  125.                  break;
  126.              }
  127.              if (canseemon(magr))
  128.                  pline("%s is suddenly very hot!", Monnam(magr));
  129.              break;
  130.          case AD_ELEC:
  131.              if (resists_elec(magr)) {
  132.                  if (canseemon(magr)) {
  133.                      pline("%s is mildly tingled.", Monnam(magr));
  134.                      golemeffects(magr, AD_ELEC, tmp);
  135.                  }
  136.                  tmp = 0;
  137.                  break;
  138.              }
  139.              if (canseemon(magr))
  140.                  pline("%s is jolted with electricity!", Monnam(magr));
  141.              break;
  142.          default:
  143.              tmp = 0;
  144.              break;
  145.          }
  146.      else
  147.          tmp = 0;
  148.  
  149.  assess_dmg:
  150.      if ((magr->mhp -= tmp) <= 0) {
  151.          monkilled(magr, "", (int) mddat->mattk[i].adtyp);
  152.          return (mdead | mhit | MM_AGR_DIED);
  153.      }
  154.      return (mdead | mhit);
  155.  }
  156.  

xdrainenergym

  1.  /* hero or monster has successfully hit target mon with drain energy attack */
  2.  void
  3.  xdrainenergym(mon, givemsg)
  4.  struct monst *mon;
  5.  boolean givemsg;
  6.  {
  7.      if (mon->mspec_used < 20 /* limit draining */
  8.          && (attacktype(mon->data, AT_MAGC)
  9.              || attacktype(mon->data, AT_BREA))) {
  10.          mon->mspec_used += d(2, 2);
  11.          if (givemsg)
  12.              pline("%s seems lethargic.", Monnam(mon));
  13.      }
  14.  }
  15.  

attk_protection

  1.  /* "aggressive defense"; what type of armor prevents specified attack
  2.     from touching its target? */
  3.  long
  4.  attk_protection(aatyp)
  5.  int aatyp;
  6.  {
  7.      long w_mask = 0L;
  8.  
  9.      switch (aatyp) {
  10.      case AT_NONE:
  11.      case AT_SPIT:
  12.      case AT_EXPL:
  13.      case AT_BOOM:
  14.      case AT_GAZE:
  15.      case AT_BREA:
  16.      case AT_MAGC:
  17.          w_mask = ~0L; /* special case; no defense needed */
  18.          break;
  19.      case AT_CLAW:
  20.      case AT_TUCH:
  21.      case AT_WEAP:
  22.          w_mask = W_ARMG; /* caller needs to check for weapon */
  23.          break;
  24.      case AT_KICK:
  25.          w_mask = W_ARMF;
  26.          break;
  27.      case AT_BUTT:
  28.          w_mask = W_ARMH;
  29.          break;
  30.      case AT_HUGS:
  31.          w_mask = (W_ARMC | W_ARMG); /* attacker needs both to be protected */
  32.          break;
  33.      case AT_BITE:
  34.      case AT_STNG:
  35.      case AT_ENGL:
  36.      case AT_TENT:
  37.      default:
  38.          w_mask = 0L; /* no defense available */
  39.          break;
  40.      }
  41.      return w_mask;
  42.  }
  43.  
  44.  /*mhitm.c*/