Source:NetHack 3.6.1/src/uhitm.c

From NetHackWiki
(Redirected from Source:Ref/hmon)
Jump to: navigation, search

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

Top of file

  1.  /* NetHack 3.6	uhitm.c	$NHDT-Date: 1521684760 2018/03/22 02:12:40 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.176 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /*-Copyright (c) Robert Patrick Rankin, 2012. */
  4.  /* NetHack may be freely redistributed.  See license for details. */

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.

  1.  
  2.  #include "hack.h"
  3.  
  4.  STATIC_DCL boolean FDECL(known_hitum, (struct monst *, struct obj *, int *,
  5.                                         int, int, struct attack *, int));
  6.  STATIC_DCL boolean FDECL(theft_petrifies, (struct obj *));
  7.  STATIC_DCL void FDECL(steal_it, (struct monst *, struct attack *));
  8.  STATIC_DCL boolean FDECL(hitum_cleave, (struct monst *, struct attack *));
  9.  STATIC_DCL boolean FDECL(hitum, (struct monst *, struct attack *));
  10.  STATIC_DCL boolean FDECL(hmon_hitmon, (struct monst *, struct obj *, int,
  11.                                         int));
  12.  STATIC_DCL int FDECL(joust, (struct monst *, struct obj *));
  13.  STATIC_DCL void NDECL(demonpet);
  14.  STATIC_DCL boolean FDECL(m_slips_free, (struct monst *, struct attack *));
  15.  STATIC_DCL int FDECL(explum, (struct monst *, struct attack *));
  16.  STATIC_DCL void FDECL(start_engulf, (struct monst *));
  17.  STATIC_DCL void NDECL(end_engulf);
  18.  STATIC_DCL int FDECL(gulpum, (struct monst *, struct attack *));
  19.  STATIC_DCL boolean FDECL(hmonas, (struct monst *));
  20.  STATIC_DCL void FDECL(nohandglow, (struct monst *));
  21.  STATIC_DCL boolean FDECL(shade_aware, (struct obj *));
  22.  
  23.  extern boolean notonhead; /* for long worms */
  24.  
  25.  /* Used to flag attacks caused by Stormbringer's maliciousness. */
  26.  static boolean override_confirmation = FALSE;
  27.  
  28.  #define PROJECTILE(obj) ((obj) && is_ammo(obj))
  29.  

erode_armor

  1.  void
  2.  erode_armor(mdef, hurt)
  3.  struct monst *mdef;
  4.  int hurt;
  5.  {
  6.      struct obj *target;
  7.  
  8.      /* What the following code does: it keeps looping until it
  9.       * finds a target for the rust monster.
  10.       * Head, feet, etc... not covered by metal, or covered by
  11.       * rusty metal, are not targets.  However, your body always
  12.       * is, no matter what covers it.
  13.       */
  14.      while (1) {
  15.          switch (rn2(5)) {
  16.          case 0:
  17.              target = which_armor(mdef, W_ARMH);
  18.              if (!target
  19.                  || erode_obj(target, xname(target), hurt, EF_GREASE)
  20.                         == ER_NOTHING)
  21.                  continue;
  22.              break;
  23.          case 1:
  24.              target = which_armor(mdef, W_ARMC);
  25.              if (target) {
  26.                  (void) erode_obj(target, xname(target), hurt,
  27.                                   EF_GREASE | EF_VERBOSE);
  28.                  break;
  29.              }
  30.              if ((target = which_armor(mdef, W_ARM)) != (struct obj *) 0) {
  31.                  (void) erode_obj(target, xname(target), hurt,
  32.                                   EF_GREASE | EF_VERBOSE);
  33.              } else if ((target = which_armor(mdef, W_ARMU))
  34.                         != (struct obj *) 0) {
  35.                  (void) erode_obj(target, xname(target), hurt,
  36.                                   EF_GREASE | EF_VERBOSE);
  37.              }
  38.              break;
  39.          case 2:
  40.              target = which_armor(mdef, W_ARMS);
  41.              if (!target
  42.                  || erode_obj(target, xname(target), hurt, EF_GREASE)
  43.                         == ER_NOTHING)
  44.                  continue;
  45.              break;
  46.          case 3:
  47.              target = which_armor(mdef, W_ARMG);
  48.              if (!target
  49.                  || erode_obj(target, xname(target), hurt, EF_GREASE)
  50.                         == ER_NOTHING)
  51.                  continue;
  52.              break;
  53.          case 4:
  54.              target = which_armor(mdef, W_ARMF);
  55.              if (!target
  56.                  || erode_obj(target, xname(target), hurt, EF_GREASE)
  57.                         == ER_NOTHING)
  58.                  continue;
  59.              break;
  60.          }
  61.          break; /* Out of while loop */
  62.      }
  63.  }
  64.  

attack_checks

  1.  /* FALSE means it's OK to attack */
  2.  boolean
  3.  attack_checks(mtmp, wep)
  4.  register struct monst *mtmp;
  5.  struct obj *wep; /* uwep for attack(), null for kick_monster() */
  6.  {
  7.      char qbuf[QBUFSZ];
  8.  
  9.      /* if you're close enough to attack, alert any waiting monster */
  10.      mtmp->mstrategy &= ~STRAT_WAITMASK;
  11.  
  12.      if (u.uswallow && mtmp == u.ustuck)
  13.          return FALSE;
  14.  
  15.      if (context.forcefight) {
  16.          /* Do this in the caller, after we checked that the monster
  17.           * didn't die from the blow.  Reason: putting the 'I' there
  18.           * causes the hero to forget the square's contents since
  19.           * both 'I' and remembered contents are stored in .glyph.
  20.           * If the monster dies immediately from the blow, the 'I' will
  21.           * not stay there, so the player will have suddenly forgotten
  22.           * the square's contents for no apparent reason.
  23.          if (!canspotmon(mtmp)
  24.              && !glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph))
  25.              map_invisible(bhitpos.x, bhitpos.y);
  26.           */
  27.          return FALSE;
  28.      }
  29.  
  30.      /* Put up an invisible monster marker, but with exceptions for
  31.       * monsters that hide and monsters you've been warned about.
  32.       * The former already prints a warning message and
  33.       * prevents you from hitting the monster just via the hidden monster
  34.       * code below; if we also did that here, similar behavior would be
  35.       * happening two turns in a row.  The latter shows a glyph on
  36.       * the screen, so you know something is there.
  37.       */
  38.      if (!canspotmon(mtmp) && !glyph_is_warning(glyph_at(bhitpos.x, bhitpos.y))
  39.          && !glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph)
  40.          && !(!Blind && mtmp->mundetected && hides_under(mtmp->data))) {
  41.          pline("Wait!  There's %s there you can't see!", something);
  42.          map_invisible(bhitpos.x, bhitpos.y);
  43.          /* if it was an invisible mimic, treat it as if we stumbled
  44.           * onto a visible mimic
  45.           */
  46.          if (mtmp->m_ap_type && !Protection_from_shape_changers
  47.              /* applied pole-arm attack is too far to get stuck */
  48.              && distu(mtmp->mx, mtmp->my) <= 2) {
  49.              if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK))
  50.                  u.ustuck = mtmp;
  51.          }
  52.          wakeup(mtmp, TRUE); /* always necessary; also un-mimics mimics */
  53.          return TRUE;
  54.      }
  55.  
  56.      if (mtmp->m_ap_type && !Protection_from_shape_changers && !sensemon(mtmp)
  57.          && !glyph_is_warning(glyph_at(bhitpos.x, bhitpos.y))) {
  58.          /* If a hidden mimic was in a square where a player remembers
  59.           * some (probably different) unseen monster, the player is in
  60.           * luck--he attacks it even though it's hidden.
  61.           */
  62.          if (glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph)) {
  63.              seemimic(mtmp);
  64.              return FALSE;
  65.          }
  66.          stumble_onto_mimic(mtmp);
  67.          return TRUE;
  68.      }
  69.  
  70.      if (mtmp->mundetected && !canseemon(mtmp)
  71.          && !glyph_is_warning(glyph_at(bhitpos.x, bhitpos.y))
  72.          && (hides_under(mtmp->data) || mtmp->data->mlet == S_EEL)) {
  73.          mtmp->mundetected = mtmp->msleeping = 0;
  74.          newsym(mtmp->mx, mtmp->my);
  75.          if (glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph)) {
  76.              seemimic(mtmp);
  77.              return FALSE;
  78.          }
  79.          if (!((Blind ? Blind_telepat : Unblind_telepat) || Detect_monsters)) {
  80.              struct obj *obj;
  81.  
  82.              if (Blind || (is_pool(mtmp->mx, mtmp->my) && !Underwater))
  83.                  pline("Wait!  There's a hidden monster there!");
  84.              else if ((obj = level.objects[mtmp->mx][mtmp->my]) != 0)
  85.                  pline("Wait!  There's %s hiding under %s!",
  86.                        an(l_monnam(mtmp)), doname(obj));
  87.              return TRUE;
  88.          }
  89.      }
  90.  
  91.      /*
  92.       * make sure to wake up a monster from the above cases if the
  93.       * hero can sense that the monster is there.
  94.       */
  95.      if ((mtmp->mundetected || mtmp->m_ap_type) && sensemon(mtmp)) {
  96.          mtmp->mundetected = 0;
  97.          wakeup(mtmp, TRUE);
  98.      }
  99.  
  100.      if (flags.confirm && mtmp->mpeaceful && !Confusion && !Hallucination
  101.          && !Stunned) {
  102.          /* Intelligent chaotic weapons (Stormbringer) want blood */
  103.          if (wep && wep->oartifact == ART_STORMBRINGER) {
  104.              override_confirmation = TRUE;
  105.              return FALSE;
  106.          }
  107.          if (canspotmon(mtmp)) {
  108.              Sprintf(qbuf, "Really attack %s?", mon_nam(mtmp));
  109.              if (!paranoid_query(ParanoidHit, qbuf)) {
  110.                  context.move = 0;
  111.                  return TRUE;
  112.              }
  113.          }
  114.      }
  115.  
  116.      return FALSE;
  117.  }
  118.  

check_caitiff

  1.  /*
  2.   * It is unchivalrous for a knight to attack the defenseless or from behind.
  3.   */
  4.  void
  5.  check_caitiff(mtmp)
  6.  struct monst *mtmp;
  7.  {
  8.      if (u.ualign.record <= -10)
  9.          return;
  10.  
  11.      if (Role_if(PM_KNIGHT) && u.ualign.type == A_LAWFUL
  12.          && (!mtmp->mcanmove || mtmp->msleeping
  13.              || (mtmp->mflee && !mtmp->mavenge))) {
  14.          You("caitiff!");
  15.          adjalign(-1);
  16.      } else if (Role_if(PM_SAMURAI) && mtmp->mpeaceful) {
  17.          /* attacking peaceful creatures is bad for the samurai's giri */
  18.          You("dishonorably attack the innocent!");
  19.          adjalign(-1);
  20.      }
  21.  }
  22.  

find_roll_to_hit

  1.  int
  2.  find_roll_to_hit(mtmp, aatyp, weapon, attk_count, role_roll_penalty)
  3.  register struct monst *mtmp;
  4.  uchar aatyp;        /* usually AT_WEAP or AT_KICK */
  5.  struct obj *weapon; /* uwep or uswapwep or NULL */
  6.  int *attk_count, *role_roll_penalty;
  7.  {
  8.      int tmp, tmp2;
  9.  
  10.      *role_roll_penalty = 0; /* default is `none' */
  11.  
  12.      tmp = 1 + Luck + abon() + find_mac(mtmp) + u.uhitinc
  13.            + maybe_polyd(youmonst.data->mlevel, u.ulevel);
  14.  
  15.      /* some actions should occur only once during multiple attacks */
  16.      if (!(*attk_count)++) {
  17.          /* knight's chivalry or samurai's giri */
  18.          check_caitiff(mtmp);
  19.      }
  20.  
  21.      /* adjust vs. (and possibly modify) monster state */
  22.      if (mtmp->mstun)
  23.          tmp += 2;
  24.      if (mtmp->mflee)
  25.          tmp += 2;
  26.  
  27.      if (mtmp->msleeping) {
  28.          mtmp->msleeping = 0;
  29.          tmp += 2;
  30.      }
  31.      if (!mtmp->mcanmove) {
  32.          tmp += 4;
  33.          if (!rn2(10)) {
  34.              mtmp->mcanmove = 1;
  35.              mtmp->mfrozen = 0;
  36.          }
  37.      }
  38.  
  39.      /* role/race adjustments */
  40.      if (Role_if(PM_MONK) && !Upolyd) {
  41.          if (uarm)
  42.              tmp -= (*role_roll_penalty = urole.spelarmr);
  43.          else if (!uwep && !uarms)
  44.              tmp += (u.ulevel / 3) + 2;
  45.      }
  46.      if (is_orc(mtmp->data)
  47.          && maybe_polyd(is_elf(youmonst.data), Race_if(PM_ELF)))
  48.          tmp++;
  49.  
  50.      /* encumbrance: with a lot of luggage, your agility diminishes */
  51.      if ((tmp2 = near_capacity()) != 0)
  52.          tmp -= (tmp2 * 2) - 1;
  53.      if (u.utrap)
  54.          tmp -= 3;
  55.  
  56.      /*
  57.       * hitval applies if making a weapon attack while wielding a weapon;
  58.       * weapon_hit_bonus applies if doing a weapon attack even bare-handed
  59.       * or if kicking as martial artist
  60.       */
  61.      if (aatyp == AT_WEAP || aatyp == AT_CLAW) {
  62.          if (weapon)
  63.              tmp += hitval(weapon, mtmp);
  64.          tmp += weapon_hit_bonus(weapon);
  65.      } else if (aatyp == AT_KICK && martial_bonus()) {
  66.          tmp += weapon_hit_bonus((struct obj *) 0);
  67.      }
  68.  
  69.      return tmp;
  70.  }
  71.  

attack

  1.  /* try to attack; return False if monster evaded;
  2.     u.dx and u.dy must be set */
  3.  boolean
  4.  attack(mtmp)
  5.  register struct monst *mtmp;
  6.  {
  7.      register struct permonst *mdat = mtmp->data;
  8.  
  9.      /* This section of code provides protection against accidentally
  10.       * hitting peaceful (like '@') and tame (like 'd') monsters.
  11.       * Protection is provided as long as player is not: blind, confused,
  12.       * hallucinating or stunned.
  13.       * changes by wwp 5/16/85
  14.       * More changes 12/90, -dkh-. if its tame and safepet, (and protected
  15.       * 07/92) then we assume that you're not trying to attack. Instead,
  16.       * you'll usually just swap places if this is a movement command
  17.       */
  18.      /* Intelligent chaotic weapons (Stormbringer) want blood */
  19.      if (is_safepet(mtmp) && !context.forcefight) {
  20.          if (!uwep || uwep->oartifact != ART_STORMBRINGER) {
  21.              /* there are some additional considerations: this won't work
  22.               * if in a shop or Punished or you miss a random roll or
  23.               * if you can walk thru walls and your pet cannot (KAA) or
  24.               * if your pet is a long worm (unless someone does better).
  25.               * there's also a chance of displacing a "frozen" monster.
  26.               * sleeping monsters might magically walk in their sleep.
  27.               */
  28.              boolean foo = (Punished || !rn2(7) || is_longworm(mtmp->data)),
  29.                      inshop = FALSE;
  30.              char *p;
  31.  
  32.              for (p = in_rooms(mtmp->mx, mtmp->my, SHOPBASE); *p; p++)
  33.                  if (tended_shop(&rooms[*p - ROOMOFFSET])) {
  34.                      inshop = TRUE;
  35.                      break;
  36.                  }
  37.  
  38.              if (inshop || foo || (IS_ROCK(levl[u.ux][u.uy].typ)
  39.                                    && !passes_walls(mtmp->data))) {
  40.                  char buf[BUFSZ];
  41.  
  42.                  monflee(mtmp, rnd(6), FALSE, FALSE);
  43.                  Strcpy(buf, y_monnam(mtmp));
  44.                  buf[0] = highc(buf[0]);
  45.                  You("stop.  %s is in the way!", buf);
  46.                  context.travel = context.travel1 = context.mv = context.run = 0;
  47.                  return TRUE;
  48.              } else if ((mtmp->mfrozen || (!mtmp->mcanmove)
  49.                          || (mtmp->data->mmove == 0)) && rn2(6)) {
  50.                  pline("%s doesn't seem to move!", Monnam(mtmp));
  51.                  context.travel = context.travel1 = context.mv = context.run = 0;
  52.                  return TRUE;
  53.              } else
  54.                  return FALSE;
  55.          }
  56.      }
  57.  
  58.      /* possibly set in attack_checks;
  59.         examined in known_hitum, called via hitum or hmonas below */
  60.      override_confirmation = FALSE;
  61.      /* attack_checks() used to use <u.ux+u.dx,u.uy+u.dy> directly, now
  62.         it uses bhitpos instead; it might map an invisible monster there */
  63.      bhitpos.x = u.ux + u.dx;
  64.      bhitpos.y = u.uy + u.dy;
  65.      if (attack_checks(mtmp, uwep))
  66.          return TRUE;
  67.  
  68.      if (Upolyd && noattacks(youmonst.data)) {
  69.          /* certain "pacifist" monsters don't attack */
  70.          You("have no way to attack monsters physically.");
  71.          mtmp->mstrategy &= ~STRAT_WAITMASK;
  72.          goto atk_done;
  73.      }
  74.  
  75.      if (check_capacity("You cannot fight while so heavily loaded.")
  76.          /* consume extra nutrition during combat; maybe pass out */
  77.          || overexertion())
  78.          goto atk_done;
  79.  
  80.      if (u.twoweap && !can_twoweapon())
  81.          untwoweapon();
  82.  
  83.      if (unweapon) {
  84.          unweapon = FALSE;
  85.          if (flags.verbose) {
  86.              if (uwep)
  87.                  You("begin bashing monsters with %s.", yname(uwep));
  88.              else if (!cantwield(youmonst.data))
  89.                  You("begin %s monsters with your %s %s.",
  90.                      ing_suffix(Role_if(PM_MONK) ? "strike" : "bash"),
  91.                      uarmg ? "gloved" : "bare", /* Del Lamb */
  92.                      makeplural(body_part(HAND)));
  93.          }
  94.      }
  95.      exercise(A_STR, TRUE); /* you're exercising muscles */
  96.      /* andrew@orca: prevent unlimited pick-axe attacks */
  97.      u_wipe_engr(3);
  98.  
  99.      /* Is the "it died" check actually correct? */
  100.      if (mdat->mlet == S_LEPRECHAUN && !mtmp->mfrozen && !mtmp->msleeping
  101.          && !mtmp->mconf && mtmp->mcansee && !rn2(7)
  102.          && (m_move(mtmp, 0) == 2 /* it died */
  103.              || mtmp->mx != u.ux + u.dx
  104.              || mtmp->my != u.uy + u.dy)) /* it moved */
  105.          return FALSE;
  106.  
  107.      if (Upolyd)
  108.          (void) hmonas(mtmp);
  109.      else
  110.          (void) hitum(mtmp, youmonst.data->mattk);
  111.      mtmp->mstrategy &= ~STRAT_WAITMASK;
  112.  
  113.  atk_done:
  114.      /* see comment in attack_checks() */
  115.      /* we only need to check for this if we did an attack_checks()
  116.       * and it returned 0 (it's okay to attack), and the monster didn't
  117.       * evade.
  118.       */
  119.      if (context.forcefight && mtmp->mhp > 0 && !canspotmon(mtmp)
  120.          && !glyph_is_invisible(levl[u.ux + u.dx][u.uy + u.dy].glyph)
  121.          && !(u.uswallow && mtmp == u.ustuck))
  122.          map_invisible(u.ux + u.dx, u.uy + u.dy);
  123.  
  124.      return TRUE;
  125.  }
  126.  

known_hitum

  1.  /* really hit target monster; returns TRUE if it still lives */
  2.  STATIC_OVL boolean
  3.  known_hitum(mon, weapon, mhit, rollneeded, armorpenalty, uattk, dieroll)
  4.  register struct monst *mon;
  5.  struct obj *weapon;
  6.  int *mhit;
  7.  int rollneeded, armorpenalty; /* for monks */
  8.  struct attack *uattk;
  9.  int dieroll;
  10.  {
  11.      register boolean malive = TRUE;
  12.  
  13.      if (override_confirmation) {
  14.          /* this may need to be generalized if weapons other than
  15.             Stormbringer acquire similar anti-social behavior... */
  16.          if (flags.verbose)
  17.              Your("bloodthirsty blade attacks!");
  18.      }
  19.  
  20.      if (!*mhit) {
  21.          missum(mon, uattk, (rollneeded + armorpenalty > dieroll));
  22.      } else {
  23.          int oldhp = mon->mhp, x = u.ux + u.dx, y = u.uy + u.dy;
  24.          long oldweaphit = u.uconduct.weaphit;
  25.  
  26.          /* KMH, conduct */
  27.          if (weapon && (weapon->oclass == WEAPON_CLASS || is_weptool(weapon)))
  28.              u.uconduct.weaphit++;
  29.  
  30.          /* we hit the monster; be careful: it might die or
  31.             be knocked into a different location */
  32.          notonhead = (mon->mx != x || mon->my != y);
  33.          malive = hmon(mon, weapon, HMON_MELEE, dieroll);
  34.          if (malive) {
  35.              /* monster still alive */
  36.              if (!rn2(25) && mon->mhp < mon->mhpmax / 2
  37.                  && !(u.uswallow && mon == u.ustuck)) {
  38.                  /* maybe should regurgitate if swallowed? */
  39.                  monflee(mon, !rn2(3) ? rnd(100) : 0, FALSE, TRUE);
  40.  
  41.                  if (u.ustuck == mon && !u.uswallow && !sticks(youmonst.data))
  42.                      u.ustuck = 0;
  43.              }
  44.              /* Vorpal Blade hit converted to miss */
  45.              /* could be headless monster or worm tail */
  46.              if (mon->mhp == oldhp) {
  47.                  *mhit = 0;
  48.                  /* a miss does not break conduct */
  49.                  u.uconduct.weaphit = oldweaphit;
  50.              }
  51.              if (mon->wormno && *mhit)
  52.                  cutworm(mon, x, y, weapon);
  53.          }
  54.      }
  55.      return malive;
  56.  }
  57.  

hitum_cleave

  1.  /* hit the monster next to you and the monsters to the left and right of it;
  2.     return False if the primary target is killed, True otherwise */
  3.  STATIC_OVL boolean
  4.  hitum_cleave(target, uattk)
  5.  struct monst *target; /* non-Null; forcefight at nothing doesn't cleave... */
  6.  struct attack *uattk; /* ... but we don't enforce that here; Null works ok */
  7.  {
  8.      /* swings will be delivered in alternate directions; with consecutive
  9.         attacks it will simulate normal swing and backswing; when swings
  10.         are non-consecutive, hero will sometimes start a series of attacks
  11.         with a backswing--that doesn't impact actual play, just spoils the
  12.         simulation attempt a bit */
  13.      static boolean clockwise = FALSE;
  14.      unsigned i;
  15.      int count, umort, x = u.ux, y = u.uy;
  16.  
  17.      /* find the direction toward primary target */
  18.      for (i = 0; i < 8; ++i)
  19.          if (xdir[i] == u.dx && ydir[i] == u.dy)
  20.              break;
  21.      if (i == 8) {
  22.          impossible("hitum_cleave: unknown target direction [%d,%d,%d]?",
  23.                     u.dx, u.dy, u.dz);
  24.          return TRUE; /* target hasn't been killed */
  25.      }
  26.      /* adjust direction by two so that loop's increment (for clockwise)
  27.         or decrement (for counter-clockwise) will point at the spot next
  28.         to primary target */
  29.      i = (i + (clockwise ? 6 : 2)) % 8;
  30.      umort = u.umortality; /* used to detect life-saving */
  31.  
  32.      /*
  33.       * Three attacks:  adjacent to primary, primary, adjacent on other
  34.       * side.  Primary target must be present or we wouldn't have gotten
  35.       * here (forcefight at thin air won't 'cleave').  However, the
  36.       * first attack might kill it (gas spore explosion, weak long worm
  37.       * occupying both spots) so we don't assume that it's still present
  38.       * on the second attack.
  39.       */
  40.      for (count = 3; count > 0; --count) {
  41.          struct monst *mtmp;
  42.          int tx, ty, tmp, dieroll, mhit, attknum, armorpenalty;
  43.  
  44.          /* ++i, wrap 8 to i=0 /or/ --i, wrap -1 to i=7 */
  45.          i = (i + (clockwise ? 1 : 7)) % 8;
  46.  
  47.          tx = x + xdir[i], ty = y + ydir[i]; /* current target location */
  48.          if (!isok(tx, ty))
  49.              continue;
  50.          mtmp = m_at(tx, ty);
  51.          if (!mtmp) {
  52.              if (glyph_is_invisible(levl[tx][ty].glyph))
  53.                  (void) unmap_invisible(tx, ty);
  54.              continue;
  55.          }
  56.  
  57.          tmp = find_roll_to_hit(mtmp, uattk->aatyp, uwep,
  58.                                 &attknum, &armorpenalty);
  59.          dieroll = rnd(20);
  60.          mhit = (tmp > dieroll);
  61.          (void) known_hitum(mtmp, uwep, &mhit, tmp, armorpenalty,
  62.                             uattk, dieroll);
  63.          (void) passive(mtmp, uwep, mhit, !DEADMONSTER(mtmp), AT_WEAP, !uwep);
  64.  
  65.          /* stop attacking if weapon is gone or hero got killed and
  66.             life-saved after passive counter-attack */
  67.          if (!uwep || u.umortality > umort)
  68.              break;
  69.      }
  70.      /* set up for next time */
  71.      clockwise = !clockwise; /* alternate */
  72.  
  73.      /* return False if primary target died, True otherwise; note: if 'target'
  74.         was nonNull upon entry then it's still nonNull even if *target died */
  75.      return (target && DEADMONSTER(target)) ? FALSE : TRUE;
  76.  }
  77.  

hitum

  1.  /* hit target monster; returns TRUE if it still lives */
  2.  STATIC_OVL boolean
  3.  hitum(mon, uattk)
  4.  struct monst *mon;
  5.  struct attack *uattk;
  6.  {
  7.      boolean malive, wep_was_destroyed = FALSE;
  8.      struct obj *wepbefore = uwep;
  9.      int armorpenalty, attknum = 0, x = u.ux + u.dx, y = u.uy + u.dy,
  10.                        tmp = find_roll_to_hit(mon, uattk->aatyp, uwep,
  11.                                               &attknum, &armorpenalty);
  12.      int dieroll = rnd(20);
  13.      int mhit = (tmp > dieroll || u.uswallow);
  14.  
  15.      /* Cleaver attacks three spots, 'mon' and one on either side of 'mon';
  16.         it can't be part of dual-wielding but we guard against that anyway;
  17.         cleave return value reflects status of primary target ('mon') */
  18.      if (uwep && uwep->oartifact == ART_CLEAVER && !u.twoweap
  19.          && !u.uswallow && !u.ustuck && !NODIAG(u.umonnum))
  20.          return hitum_cleave(mon, uattk);
  21.  
  22.      if (tmp > dieroll)
  23.          exercise(A_DEX, TRUE);
  24.      malive = known_hitum(mon, uwep, &mhit, tmp, armorpenalty, uattk, dieroll);
  25.      if (wepbefore && !uwep)
  26.          wep_was_destroyed = TRUE;
  27.      (void) passive(mon, uwep, mhit, malive, AT_WEAP, wep_was_destroyed);
  28.  
  29.      /* second attack for two-weapon combat; won't occur if Stormbringer
  30.         overrode confirmation (assumes Stormbringer is primary weapon)
  31.         or if the monster was killed or knocked to different location */
  32.      if (u.twoweap && !override_confirmation && malive && m_at(x, y) == mon) {
  33.          tmp = find_roll_to_hit(mon, uattk->aatyp, uswapwep, &attknum,
  34.                                 &armorpenalty);
  35.          dieroll = rnd(20);
  36.          mhit = (tmp > dieroll || u.uswallow);
  37.          malive = known_hitum(mon, uswapwep, &mhit, tmp, armorpenalty, uattk,
  38.                               dieroll);
  39.          /* second passive counter-attack only occurs if second attack hits */
  40.          if (mhit)
  41.              (void) passive(mon, uswapwep, mhit, malive, AT_WEAP, !uswapwep);
  42.      }
  43.      return malive;
  44.  }
  45.  

hmon

  1.  /* general "damage monster" routine; return True if mon still alive */
  2.  boolean
  3.  hmon(mon, obj, thrown, dieroll)
  4.  struct monst *mon;
  5.  struct obj *obj;
  6.  int thrown; /* HMON_xxx (0 => hand-to-hand, other => ranged) */
  7.  int dieroll;
  8.  {
  9.      boolean result, anger_guards;
  10.  
  11.      anger_guards = (mon->mpeaceful
  12.                      && (mon->ispriest || mon->isshk || is_watch(mon->data)));
  13.      result = hmon_hitmon(mon, obj, thrown, dieroll);
  14.      if (mon->ispriest && !rn2(2))
  15.          ghod_hitsu(mon);
  16.      if (anger_guards)
  17.          (void) angry_guards(!!Deaf);
  18.      return result;
  19.  }
  20.  

hmon_hitmon

  1.  /* guts of hmon() */
  2.  STATIC_OVL boolean
  3.  hmon_hitmon(mon, obj, thrown, dieroll)
  4.  struct monst *mon;
  5.  struct obj *obj;
  6.  int thrown; /* HMON_xxx (0 => hand-to-hand, other => ranged) */
  7.  int dieroll;
  8.  {
  9.      int tmp;
  10.      struct permonst *mdat = mon->data;
  11.      int barehand_silver_rings = 0;
  12.      /* The basic reason we need all these booleans is that we don't want
  13.       * a "hit" message when a monster dies, so we have to know how much
  14.       * damage it did _before_ outputting a hit message, but any messages
  15.       * associated with the damage don't come out until _after_ outputting
  16.       * a hit message.
  17.       */
  18.      boolean hittxt = FALSE, destroyed = FALSE, already_killed = FALSE;
  19.      boolean get_dmg_bonus = TRUE;
  20.      boolean ispoisoned = FALSE, needpoismsg = FALSE, poiskilled = FALSE,
  21.              unpoisonmsg = FALSE;
  22.      boolean silvermsg = FALSE, silverobj = FALSE;
  23.      boolean valid_weapon_attack = FALSE;
  24.      boolean unarmed = !uwep && !uarm && !uarms;
  25.      boolean hand_to_hand = (thrown == HMON_MELEE
  26.                              /* not grapnels; applied implies uwep */
  27.                              || (thrown == HMON_APPLIED && is_pole(uwep)));
  28.      int jousting = 0;
  29.      int wtype;
  30.      struct obj *monwep;
  31.      char unconventional[BUFSZ]; /* substituted for word "attack" in msg */
  32.      char saved_oname[BUFSZ];
  33.  
  34.      unconventional[0] = '\0';
  35.      saved_oname[0] = '\0';
  36.  
  37.      wakeup(mon, TRUE);
  38.      if (!obj) { /* attack with bare hands */
  39.          if (mdat == &mons[PM_SHADE])
  40.              tmp = 0;
  41.          else if (martial_bonus())
  42.              tmp = rnd(4); /* bonus for martial arts */
  43.          else
  44.              tmp = rnd(2);
  45.          valid_weapon_attack = (tmp > 1);
  46.          /* blessed gloves give bonuses when fighting 'bare-handed' */
  47.          if (uarmg && uarmg->blessed
  48.              && (is_undead(mdat) || is_demon(mdat) || is_vampshifter(mon)))
  49.              tmp += rnd(4);
  50.          /* So do silver rings.  Note: rings are worn under gloves, so you
  51.           * don't get both bonuses.
  52.           */
  53.          if (!uarmg) {
  54.              if (uleft && objects[uleft->otyp].oc_material == SILVER)
  55.                  barehand_silver_rings++;
  56.              if (uright && objects[uright->otyp].oc_material == SILVER)
  57.                  barehand_silver_rings++;
  58.              if (barehand_silver_rings && mon_hates_silver(mon)) {
  59.                  tmp += rnd(20);
  60.                  silvermsg = TRUE;
  61.              }
  62.          }
  63.      } else {
  64.          Strcpy(saved_oname, cxname(obj));
  65.          if (obj->oclass == WEAPON_CLASS || is_weptool(obj)
  66.              || obj->oclass == GEM_CLASS) {
  67.              /* is it not a melee weapon? */
  68.              if (/* if you strike with a bow... */
  69.                  is_launcher(obj)
  70.                  /* or strike with a missile in your hand... */
  71.                  || (!thrown && (is_missile(obj) || is_ammo(obj)))
  72.                  /* or use a pole at short range and not mounted... */
  73.                  || (!thrown && !u.usteed && is_pole(obj))
  74.                  /* or throw a missile without the proper bow... */
  75.                  || (is_ammo(obj) && (thrown != HMON_THROWN
  76.                                       || !ammo_and_launcher(obj, uwep)))) {
  77.                  /* then do only 1-2 points of damage */
  78.                  if (mdat == &mons[PM_SHADE] && !shade_glare(obj))
  79.                      tmp = 0;
  80.                  else
  81.                      tmp = rnd(2);
  82.                  if (objects[obj->otyp].oc_material == SILVER
  83.                      && mon_hates_silver(mon)) {
  84.                      silvermsg = TRUE;
  85.                      silverobj = TRUE;
  86.                      /* if it will already inflict dmg, make it worse */
  87.                      tmp += rnd((tmp) ? 20 : 10);
  88.                  }
  89.                  if (!thrown && obj == uwep && obj->otyp == BOOMERANG
  90.                      && rnl(4) == 4 - 1) {
  91.                      boolean more_than_1 = (obj->quan > 1L);
  92.  
  93.                      pline("As you hit %s, %s%s breaks into splinters.",
  94.                            mon_nam(mon), more_than_1 ? "one of " : "",
  95.                            yname(obj));
  96.                      if (!more_than_1)
  97.                          uwepgone(); /* set unweapon */
  98.                      useup(obj);
  99.                      if (!more_than_1)
  100.                          obj = (struct obj *) 0;
  101.                      hittxt = TRUE;
  102.                      if (mdat != &mons[PM_SHADE])
  103.                          tmp++;
  104.                  }
  105.              } else {
  106.                  tmp = dmgval(obj, mon);
  107.                  /* a minimal hit doesn't exercise proficiency */
  108.                  valid_weapon_attack = (tmp > 1);
  109.                  if (!valid_weapon_attack || mon == u.ustuck || u.twoweap
  110.                      /* Cleaver can hit up to three targets at once so don't
  111.                         let it also hit from behind or shatter foes' weapons */
  112.                      || (hand_to_hand && obj->oartifact == ART_CLEAVER)) {
  113.                      ; /* no special bonuses */
  114.                  } else if (mon->mflee && Role_if(PM_ROGUE) && !Upolyd
  115.                             /* multi-shot throwing is too powerful here */
  116.                             && hand_to_hand) {
  117.                      You("strike %s from behind!", mon_nam(mon));
  118.                      tmp += rnd(u.ulevel);
  119.                      hittxt = TRUE;
  120.                  } else if (dieroll == 2 && obj == uwep
  121.                             && obj->oclass == WEAPON_CLASS
  122.                             && (bimanual(obj)
  123.                                 || (Role_if(PM_SAMURAI) && obj->otyp == KATANA
  124.                                     && !uarms))
  125.                             && ((wtype = uwep_skill_type()) != P_NONE
  126.                                 && P_SKILL(wtype) >= P_SKILLED)
  127.                             && ((monwep = MON_WEP(mon)) != 0
  128.                                 && !is_flimsy(monwep)
  129.                                 && !obj_resists(monwep,
  130.                                         50 + 15 * (greatest_erosion(obj)
  131.                                                    - greatest_erosion(monwep)),
  132.                                                 100))) {
  133.                      /*
  134.                       * 2.5% chance of shattering defender's weapon when
  135.                       * using a two-handed weapon; less if uwep is rusted.
  136.                       * [dieroll == 2 is most successful non-beheading or
  137.                       * -bisecting hit, in case of special artifact damage;
  138.                       * the percentage chance is (1/20)*(50/100).]
  139.                       * If attacker's weapon is rustier than defender's,
  140.                       * the obj_resists chance is increased so the shatter
  141.                       * chance is decreased; if less rusty, then vice versa.
  142.                       */
  143.                      setmnotwielded(mon, monwep);
  144.                      mon->weapon_check = NEED_WEAPON;
  145.                      pline("%s from the force of your blow!",
  146.                            Yobjnam2(monwep, "shatter"));
  147.                      m_useupall(mon, monwep);
  148.                      /* If someone just shattered MY weapon, I'd flee! */
  149.                      if (rn2(4)) {
  150.                          monflee(mon, d(2, 3), TRUE, TRUE);
  151.                      }
  152.                      hittxt = TRUE;
  153.                  }
  154.  
  155.                  if (obj->oartifact
  156.                      && artifact_hit(&youmonst, mon, obj, &tmp, dieroll)) {
  157.                      if (mon->mhp <= 0) /* artifact killed monster */
  158.                          return FALSE;
  159.                      if (tmp == 0)
  160.                          return TRUE;
  161.                      hittxt = TRUE;
  162.                  }
  163.                  if (objects[obj->otyp].oc_material == SILVER
  164.                      && mon_hates_silver(mon)) {
  165.                      silvermsg = TRUE;
  166.                      silverobj = TRUE;
  167.                  }
  168.                  if (u.usteed && !thrown && tmp > 0
  169.                      && weapon_type(obj) == P_LANCE && mon != u.ustuck) {
  170.                      jousting = joust(mon, obj);
  171.                      /* exercise skill even for minimal damage hits */
  172.                      if (jousting)
  173.                          valid_weapon_attack = TRUE;
  174.                  }
  175.                  if (thrown == HMON_THROWN
  176.                      && (is_ammo(obj) || is_missile(obj))) {
  177.                      if (ammo_and_launcher(obj, uwep)) {
  178.                          /* Elves and Samurai do extra damage using
  179.                           * their bows&arrows; they're highly trained.
  180.                           */
  181.                          if (Role_if(PM_SAMURAI) && obj->otyp == YA
  182.                              && uwep->otyp == YUMI)
  183.                              tmp++;
  184.                          else if (Race_if(PM_ELF) && obj->otyp == ELVEN_ARROW
  185.                                   && uwep->otyp == ELVEN_BOW)
  186.                              tmp++;
  187.                      }
  188.                      if (obj->opoisoned && is_poisonable(obj))
  189.                          ispoisoned = TRUE;
  190.                  }
  191.              }
  192.          } else if (obj->oclass == POTION_CLASS) {
  193.              if (obj->quan > 1L)
  194.                  obj = splitobj(obj, 1L);
  195.              else
  196.                  setuwep((struct obj *) 0);
  197.              freeinv(obj);
  198.              potionhit(mon, obj,
  199.                        hand_to_hand ? POTHIT_HERO_BASH : POTHIT_HERO_THROW);
  200.              if (mon->mhp <= 0)
  201.                  return FALSE; /* killed */
  202.              hittxt = TRUE;
  203.              /* in case potion effect causes transformation */
  204.              mdat = mon->data;
  205.              tmp = (mdat == &mons[PM_SHADE]) ? 0 : 1;
  206.          } else {
  207.              if (mdat == &mons[PM_SHADE] && !shade_aware(obj)) {
  208.                  tmp = 0;
  209.                  Strcpy(unconventional, cxname(obj));
  210.              } else {
  211.                  switch (obj->otyp) {
  212.                  case BOULDER:         /* 1d20 */
  213.                  case HEAVY_IRON_BALL: /* 1d25 */
  214.                  case IRON_CHAIN:      /* 1d4+1 */
  215.                      tmp = dmgval(obj, mon);
  216.                      break;
  217.                  case MIRROR:
  218.                      if (breaktest(obj)) {
  219.                          You("break %s.  That's bad luck!", ysimple_name(obj));
  220.                          change_luck(-2);
  221.                          useup(obj);
  222.                          obj = (struct obj *) 0;
  223.                          unarmed = FALSE; /* avoid obj==0 confusion */
  224.                          get_dmg_bonus = FALSE;
  225.                          hittxt = TRUE;
  226.                      }
  227.                      tmp = 1;
  228.                      break;
  229.                  case EXPENSIVE_CAMERA:
  230.                      You("succeed in destroying %s.  Congratulations!",
  231.                          ysimple_name(obj));
  232.                      release_camera_demon(obj, u.ux, u.uy);
  233.                      useup(obj);
  234.                      return TRUE;
  235.                  case CORPSE: /* fixed by polder@cs.vu.nl */
  236.                      if (touch_petrifies(&mons[obj->corpsenm])) {
  237.                          tmp = 1;
  238.                          hittxt = TRUE;
  239.                          You("hit %s with %s.", mon_nam(mon),
  240.                              corpse_xname(obj, (const char *) 0,
  241.                                           obj->dknown ? CXN_PFX_THE
  242.                                                       : CXN_ARTICLE));
  243.                          obj->dknown = 1;
  244.                          if (!munstone(mon, TRUE))
  245.                              minstapetrify(mon, TRUE);
  246.                          if (resists_ston(mon))
  247.                              break;
  248.                          /* note: hp may be <= 0 even if munstoned==TRUE */
  249.                          return (boolean) (mon->mhp > 0);
  250.  #if 0
  251.                      } else if (touch_petrifies(mdat)) {
  252.                          ; /* maybe turn the corpse into a statue? */
  253.  #endif
  254.                      }
  255.                      tmp = (obj->corpsenm >= LOW_PM ? mons[obj->corpsenm].msize
  256.                                                     : 0) + 1;
  257.                      break;
  258.  
  259.  #define useup_eggs(o)                    \
  260.      {                                    \
  261.          if (thrown)                      \
  262.              obfree(o, (struct obj *) 0); \
  263.          else                             \
  264.              useupall(o);                 \
  265.          o = (struct obj *) 0;            \
  266.      } /* now gone */
  267.                  case EGG: {
  268.                      long cnt = obj->quan;
  269.  
  270.                      tmp = 1; /* nominal physical damage */
  271.                      get_dmg_bonus = FALSE;
  272.                      hittxt = TRUE; /* message always given */
  273.                      /* egg is always either used up or transformed, so next
  274.                         hand-to-hand attack should yield a "bashing" mesg */
  275.                      if (obj == uwep)
  276.                          unweapon = TRUE;
  277.                      if (obj->spe && obj->corpsenm >= LOW_PM) {
  278.                          if (obj->quan < 5L)
  279.                              change_luck((schar) - (obj->quan));
  280.                          else
  281.                              change_luck(-5);
  282.                      }
  283.  
  284.                      if (touch_petrifies(&mons[obj->corpsenm])) {
  285.                          /*learn_egg_type(obj->corpsenm);*/
  286.                          pline("Splat! You hit %s with %s %s egg%s!",
  287.                                mon_nam(mon),
  288.                                obj->known ? "the" : cnt > 1L ? "some" : "a",
  289.                                obj->known ? mons[obj->corpsenm].mname
  290.                                           : "petrifying",
  291.                                plur(cnt));
  292.                          obj->known = 1; /* (not much point...) */
  293.                          useup_eggs(obj);
  294.                          if (!munstone(mon, TRUE))
  295.                              minstapetrify(mon, TRUE);
  296.                          if (resists_ston(mon))
  297.                              break;
  298.                          return (boolean) (mon->mhp > 0);
  299.                      } else { /* ordinary egg(s) */
  300.                          const char *eggp =
  301.                              (obj->corpsenm != NON_PM && obj->known)
  302.                                  ? the(mons[obj->corpsenm].mname)
  303.                                  : (cnt > 1L) ? "some" : "an";
  304.                          You("hit %s with %s egg%s.", mon_nam(mon), eggp,
  305.                              plur(cnt));
  306.                          if (touch_petrifies(mdat) && !stale_egg(obj)) {
  307.                              pline_The("egg%s %s alive any more...", plur(cnt),
  308.                                        (cnt == 1L) ? "isn't" : "aren't");
  309.                              if (obj->timed)
  310.                                  obj_stop_timers(obj);
  311.                              obj->otyp = ROCK;
  312.                              obj->oclass = GEM_CLASS;
  313.                              obj->oartifact = 0;
  314.                              obj->spe = 0;
  315.                              obj->known = obj->dknown = obj->bknown = 0;
  316.                              obj->owt = weight(obj);
  317.                              if (thrown)
  318.                                  place_object(obj, mon->mx, mon->my);
  319.                          } else {
  320.                              pline("Splat!");
  321.                              useup_eggs(obj);
  322.                              exercise(A_WIS, FALSE);
  323.                          }
  324.                      }
  325.                      break;
  326.  #undef useup_eggs
  327.                  }
  328.                  case CLOVE_OF_GARLIC: /* no effect against demons */
  329.                      if (is_undead(mdat) || is_vampshifter(mon)) {
  330.                          monflee(mon, d(2, 4), FALSE, TRUE);
  331.                      }
  332.                      tmp = 1;
  333.                      break;
  334.                  case CREAM_PIE:
  335.                  case BLINDING_VENOM:
  336.                      mon->msleeping = 0;
  337.                      if (can_blnd(&youmonst, mon,
  338.                                   (uchar) (obj->otyp == BLINDING_VENOM
  339.                                               ? AT_SPIT
  340.                                               : AT_WEAP),
  341.                                   obj)) {
  342.                          if (Blind) {
  343.                              pline(obj->otyp == CREAM_PIE ? "Splat!"
  344.                                                           : "Splash!");
  345.                          } else if (obj->otyp == BLINDING_VENOM) {
  346.                              pline_The("venom blinds %s%s!", mon_nam(mon),
  347.                                        mon->mcansee ? "" : " further");
  348.                          } else {
  349.                              char *whom = mon_nam(mon);
  350.                              char *what = The(xname(obj));
  351.  
  352.                              if (!thrown && obj->quan > 1L)
  353.                                  what = An(singular(obj, xname));
  354.                              /* note: s_suffix returns a modifiable buffer */
  355.                              if (haseyes(mdat)
  356.                                  && mdat != &mons[PM_FLOATING_EYE])
  357.                                  whom = strcat(strcat(s_suffix(whom), " "),
  358.                                                mbodypart(mon, FACE));
  359.                              pline("%s %s over %s!", what,
  360.                                    vtense(what, "splash"), whom);
  361.                          }
  362.                          setmangry(mon, TRUE);
  363.                          mon->mcansee = 0;
  364.                          tmp = rn1(25, 21);
  365.                          if (((int) mon->mblinded + tmp) > 127)
  366.                              mon->mblinded = 127;
  367.                          else
  368.                              mon->mblinded += tmp;
  369.                      } else {
  370.                          pline(obj->otyp == CREAM_PIE ? "Splat!" : "Splash!");
  371.                          setmangry(mon, TRUE);
  372.                      }
  373.                      if (thrown)
  374.                          obfree(obj, (struct obj *) 0);
  375.                      else
  376.                          useup(obj);
  377.                      hittxt = TRUE;
  378.                      get_dmg_bonus = FALSE;
  379.                      tmp = 0;
  380.                      break;
  381.                  case ACID_VENOM: /* thrown (or spit) */
  382.                      if (resists_acid(mon)) {
  383.                          Your("venom hits %s harmlessly.", mon_nam(mon));
  384.                          tmp = 0;
  385.                      } else {
  386.                          Your("venom burns %s!", mon_nam(mon));
  387.                          tmp = dmgval(obj, mon);
  388.                      }
  389.                      if (thrown)
  390.                          obfree(obj, (struct obj *) 0);
  391.                      else
  392.                          useup(obj);
  393.                      hittxt = TRUE;
  394.                      get_dmg_bonus = FALSE;
  395.                      break;
  396.                  default:
  397.                      /* non-weapons can damage because of their weight */
  398.                      /* (but not too much) */
  399.                      tmp = obj->owt / 100;
  400.                      if (is_wet_towel(obj)) {
  401.                          /* wielded wet towel should probably use whip skill
  402.                             (but not by setting objects[TOWEL].oc_skill==P_WHIP
  403.                             because that would turn towel into a weptool) */
  404.                          tmp += obj->spe;
  405.                          if (rn2(obj->spe + 1)) /* usually lose some wetness */
  406.                              dry_a_towel(obj, -1, TRUE);
  407.                      }
  408.                      if (tmp < 1)
  409.                          tmp = 1;
  410.                      else
  411.                          tmp = rnd(tmp);
  412.                      if (tmp > 6)
  413.                          tmp = 6;
  414.                      /*
  415.                       * Things like silver wands can arrive here so
  416.                       * so we need another silver check.
  417.                       */
  418.                      if (objects[obj->otyp].oc_material == SILVER
  419.                          && mon_hates_silver(mon)) {
  420.                          tmp += rnd(20);
  421.                          silvermsg = TRUE;
  422.                          silverobj = TRUE;
  423.                      }
  424.                  }
  425.              }
  426.          }
  427.      }
  428.  
  429.      /****** NOTE: perhaps obj is undefined!! (if !thrown && BOOMERANG)
  430.       *      *OR* if attacking bare-handed!! */
  431.  
  432.      if (get_dmg_bonus && tmp > 0) {
  433.          tmp += u.udaminc;
  434.          /* If you throw using a propellor, you don't get a strength
  435.           * bonus but you do get an increase-damage bonus.
  436.           */
  437.          if (thrown != HMON_THROWN || !obj || !uwep
  438.              || !ammo_and_launcher(obj, uwep))
  439.              tmp += dbon();
  440.      }
  441.  
  442.      if (valid_weapon_attack) {
  443.          struct obj *wep;
  444.  
  445.          /* to be valid a projectile must have had the correct projector */
  446.          wep = PROJECTILE(obj) ? uwep : obj;
  447.          tmp += weapon_dam_bonus(wep);
  448.          /* [this assumes that `!thrown' implies wielded...] */
  449.          wtype = thrown ? weapon_type(wep) : uwep_skill_type();
  450.          use_skill(wtype, 1);
  451.      }
  452.  
  453.      if (ispoisoned) {
  454.          int nopoison = (10 - (obj->owt / 10));
  455.  
  456.          if (nopoison < 2)
  457.              nopoison = 2;
  458.          if (Role_if(PM_SAMURAI)) {
  459.              You("dishonorably use a poisoned weapon!");
  460.              adjalign(-sgn(u.ualign.type));
  461.          } else if (u.ualign.type == A_LAWFUL && u.ualign.record > -10) {
  462.              You_feel("like an evil coward for using a poisoned weapon.");
  463.              adjalign(-1);
  464.          }
  465.          if (obj && !rn2(nopoison)) {
  466.              /* remove poison now in case obj ends up in a bones file */
  467.              obj->opoisoned = FALSE;
  468.              /* defer "obj is no longer poisoned" until after hit message */
  469.              unpoisonmsg = TRUE;
  470.          }
  471.          if (resists_poison(mon))
  472.              needpoismsg = TRUE;
  473.          else if (rn2(10))
  474.              tmp += rnd(6);
  475.          else
  476.              poiskilled = TRUE;
  477.      }
  478.      if (tmp < 1) {
  479.          /* make sure that negative damage adjustment can't result
  480.             in inadvertently boosting the victim's hit points */
  481.          tmp = 0;
  482.          if (mdat == &mons[PM_SHADE]) {
  483.              if (!hittxt) {
  484.                  const char *what = *unconventional ? unconventional : "attack";
  485.  
  486.                  Your("%s %s harmlessly through %s.", what,
  487.                       vtense(what, "pass"), mon_nam(mon));
  488.                  hittxt = TRUE;
  489.              }
  490.          } else {
  491.              if (get_dmg_bonus)
  492.                  tmp = 1;
  493.          }
  494.      }
  495.  
  496.      if (jousting) {
  497.          tmp += d(2, (obj == uwep) ? 10 : 2); /* [was in dmgval()] */
  498.          You("joust %s%s", mon_nam(mon), canseemon(mon) ? exclam(tmp) : ".");
  499.          if (jousting < 0) {
  500.              pline("%s shatters on impact!", Yname2(obj));
  501.              /* (must be either primary or secondary weapon to get here) */
  502.              u.twoweap = FALSE; /* untwoweapon() is too verbose here */
  503.              if (obj == uwep)
  504.                  uwepgone(); /* set unweapon */
  505.              /* minor side-effect: broken lance won't split puddings */
  506.              useup(obj);
  507.              obj = 0;
  508.          }
  509.          /* avoid migrating a dead monster */
  510.          if (mon->mhp > tmp) {
  511.              mhurtle(mon, u.dx, u.dy, 1);
  512.              mdat = mon->data; /* in case of a polymorph trap */
  513.              if (DEADMONSTER(mon))
  514.                  already_killed = TRUE;
  515.          }
  516.          hittxt = TRUE;
  517.      } else if (unarmed && tmp > 1 && !thrown && !obj && !Upolyd) {
  518.          /* VERY small chance of stunning opponent if unarmed. */
  519.          if (rnd(100) < P_SKILL(P_BARE_HANDED_COMBAT) && !bigmonst(mdat)
  520.              && !thick_skinned(mdat)) {
  521.              if (canspotmon(mon))
  522.                  pline("%s %s from your powerful strike!", Monnam(mon),
  523.                        makeplural(stagger(mon->data, "stagger")));
  524.              /* avoid migrating a dead monster */
  525.              if (mon->mhp > tmp) {
  526.                  mhurtle(mon, u.dx, u.dy, 1);
  527.                  mdat = mon->data; /* in case of a polymorph trap */
  528.                  if (DEADMONSTER(mon))
  529.                      already_killed = TRUE;
  530.              }
  531.              hittxt = TRUE;
  532.          }
  533.      }
  534.  
  535.      if (!already_killed)
  536.          mon->mhp -= tmp;
  537.      /* adjustments might have made tmp become less than what
  538.         a level draining artifact has already done to max HP */
  539.      if (mon->mhp > mon->mhpmax)
  540.          mon->mhp = mon->mhpmax;
  541.      if (mon->mhp < 1)
  542.          destroyed = TRUE;
  543.      if (mon->mtame && tmp > 0) {
  544.          /* do this even if the pet is being killed (affects revival) */
  545.          abuse_dog(mon); /* reduces tameness */
  546.          /* flee if still alive and still tame; if already suffering from
  547.             untimed fleeing, no effect, otherwise increases timed fleeing */
  548.          if (mon->mtame && !destroyed)
  549.              monflee(mon, 10 * rnd(tmp), FALSE, FALSE);
  550.      }
  551.      if ((mdat == &mons[PM_BLACK_PUDDING] || mdat == &mons[PM_BROWN_PUDDING])
  552.          /* pudding is alive and healthy enough to split */
  553.          && mon->mhp > 1 && !mon->mcan
  554.          /* iron weapon using melee or polearm hit [3.6.1: metal weapon too;
  555.             also allow either or both weapons to cause split when twoweap] */
  556.          && obj && (obj == uwep || (u.twoweap && obj == uswapwep))
  557.          && ((objects[obj->otyp].oc_material == IRON
  558.               /* allow scalpel and tsurugi to split puddings */
  559.               || objects[obj->otyp].oc_material == METAL)
  560.              /* but not bashing with darts, arrows or ya */
  561.              && !(is_ammo(obj) || is_missile(obj)))
  562.          && hand_to_hand) {
  563.          if (clone_mon(mon, 0, 0)) {
  564.              char withwhat[BUFSZ];
  565.  
  566.              withwhat[0] = '\0';
  567.              if (u.twoweap && flags.verbose)
  568.                  Sprintf(withwhat, " with %s", yname(obj));
  569.              pline("%s divides as you hit it%s!", Monnam(mon), withwhat);
  570.              hittxt = TRUE;
  571.          }
  572.      }
  573.  
  574.      if (!hittxt /*( thrown => obj exists )*/
  575.          && (!destroyed
  576.              || (thrown && m_shot.n > 1 && m_shot.o == obj->otyp))) {
  577.          if (thrown)
  578.              hit(mshot_xname(obj), mon, exclam(tmp));
  579.          else if (!flags.verbose)
  580.              You("hit it.");
  581.          else
  582.              You("%s %s%s", Role_if(PM_BARBARIAN) ? "smite" : "hit",
  583.                  mon_nam(mon), canseemon(mon) ? exclam(tmp) : ".");
  584.      }
  585.  
  586.      if (silvermsg) {
  587.          const char *fmt;
  588.          char *whom = mon_nam(mon);
  589.          char silverobjbuf[BUFSZ];
  590.  
  591.          if (canspotmon(mon)) {
  592.              if (barehand_silver_rings == 1)
  593.                  fmt = "Your silver ring sears %s!";
  594.              else if (barehand_silver_rings == 2)
  595.                  fmt = "Your silver rings sear %s!";
  596.              else if (silverobj && saved_oname[0]) {
  597.                  /* guard constructed format string against '%' in
  598.                     saved_oname[] from xname(via cxname()) */
  599.                  Sprintf(silverobjbuf, "Your %s%s %s",
  600.                          strstri(saved_oname, "silver") ? "" : "silver ",
  601.                          saved_oname, vtense(saved_oname, "sear"));
  602.                  (void) strNsubst(silverobjbuf, "%", "%%", 0);
  603.                  Strcat(silverobjbuf, " %s!");
  604.                  fmt = silverobjbuf;
  605.              } else
  606.                  fmt = "The silver sears %s!";
  607.          } else {
  608.              *whom = highc(*whom); /* "it" -> "It" */
  609.              fmt = "%s is seared!";
  610.          }
  611.          /* note: s_suffix returns a modifiable buffer */
  612.          if (!noncorporeal(mdat) && !amorphous(mdat))
  613.              whom = strcat(s_suffix(whom), " flesh");
  614.          pline(fmt, whom);
  615.      }
  616.      /* if a "no longer poisoned" message is coming, it will be last;
  617.         obj->opoisoned was cleared above and any message referring to
  618.         "poisoned <obj>" has now been given; we want just "<obj>" for
  619.         last message, so reformat while obj is still accessible */
  620.      if (unpoisonmsg)
  621.          Strcpy(saved_oname, cxname(obj));
  622.  
  623.      /* [note: thrown obj might go away during killed/xkilled call] */
  624.  
  625.      if (needpoismsg)
  626.          pline_The("poison doesn't seem to affect %s.", mon_nam(mon));
  627.      if (poiskilled) {
  628.          pline_The("poison was deadly...");
  629.          if (!already_killed)
  630.              xkilled(mon, XKILL_NOMSG);
  631.          destroyed = TRUE; /* return FALSE; */
  632.      } else if (destroyed) {
  633.          if (!already_killed)
  634.              killed(mon); /* takes care of most messages */
  635.      } else if (u.umconf && hand_to_hand) {
  636.          nohandglow(mon);
  637.          if (!mon->mconf && !resist(mon, SPBOOK_CLASS, 0, NOTELL)) {
  638.              mon->mconf = 1;
  639.              if (!mon->mstun && mon->mcanmove && !mon->msleeping
  640.                  && canseemon(mon))
  641.                  pline("%s appears confused.", Monnam(mon));
  642.          }
  643.      }
  644.      if (unpoisonmsg)
  645.          Your("%s %s no longer poisoned.", saved_oname,
  646.               vtense(saved_oname, "are"));
  647.  
  648.      return destroyed ? FALSE : TRUE;
  649.  }
  650.  

shade_aware

  1.  STATIC_OVL boolean
  2.  shade_aware(obj)
  3.  struct obj *obj;
  4.  {
  5.      if (!obj)
  6.          return FALSE;
  7.      /*
  8.       * The things in this list either
  9.       * 1) affect shades.
  10.       *  OR
  11.       * 2) are dealt with properly by other routines
  12.       *    when it comes to shades.
  13.       */
  14.      if (obj->otyp == BOULDER
  15.          || obj->otyp == HEAVY_IRON_BALL
  16.          || obj->otyp == IRON_CHAIN      /* dmgval handles those first three */
  17.          || obj->otyp == MIRROR          /* silver in the reflective surface */
  18.          || obj->otyp == CLOVE_OF_GARLIC /* causes shades to flee */
  19.          || objects[obj->otyp].oc_material == SILVER)
  20.          return TRUE;
  21.      return FALSE;
  22.  }
  23.  

m_slips_free

  1.  /* check whether slippery clothing protects from hug or wrap attack */
  2.  /* [currently assumes that you are the attacker] */
  3.  STATIC_OVL boolean
  4.  m_slips_free(mdef, mattk)
  5.  struct monst *mdef;
  6.  struct attack *mattk;
  7.  {
  8.      struct obj *obj;
  9.  
  10.      if (mattk->adtyp == AD_DRIN) {
  11.          /* intelligence drain attacks the head */
  12.          obj = which_armor(mdef, W_ARMH);
  13.      } else {
  14.          /* grabbing attacks the body */
  15.          obj = which_armor(mdef, W_ARMC); /* cloak */
  16.          if (!obj)
  17.              obj = which_armor(mdef, W_ARM); /* suit */
  18.          if (!obj)
  19.              obj = which_armor(mdef, W_ARMU); /* shirt */
  20.      }
  21.  
  22.      /* if monster's cloak/armor is greased, your grab slips off; this
  23.         protection might fail (33% chance) when the armor is cursed */
  24.      if (obj && (obj->greased || obj->otyp == OILSKIN_CLOAK)
  25.          && (!obj->cursed || rn2(3))) {
  26.          You("%s %s %s %s!",
  27.              mattk->adtyp == AD_WRAP ? "slip off of"
  28.                                      : "grab, but cannot hold onto",
  29.              s_suffix(mon_nam(mdef)), obj->greased ? "greased" : "slippery",
  30.              /* avoid "slippery slippery cloak"
  31.                 for undiscovered oilskin cloak */
  32.              (obj->greased || objects[obj->otyp].oc_name_known)
  33.                  ? xname(obj)
  34.                  : cloak_simple_name(obj));
  35.  
  36.          if (obj->greased && !rn2(2)) {
  37.              pline_The("grease wears off.");
  38.              obj->greased = 0;
  39.          }
  40.          return TRUE;
  41.      }
  42.      return FALSE;
  43.  }
  44.  

joust

  1.  /* used when hitting a monster with a lance while mounted;
  2.     1: joust hit; 0: ordinary hit; -1: joust but break lance */
  3.  STATIC_OVL int
  4.  joust(mon, obj)
  5.  struct monst *mon; /* target */
  6.  struct obj *obj;   /* weapon */
  7.  {
  8.      int skill_rating, joust_dieroll;
  9.  
  10.      if (Fumbling || Stunned)
  11.          return 0;
  12.      /* sanity check; lance must be wielded in order to joust */
  13.      if (obj != uwep && (obj != uswapwep || !u.twoweap))
  14.          return 0;
  15.  
  16.      /* if using two weapons, use worse of lance and two-weapon skills */
  17.      skill_rating = P_SKILL(weapon_type(obj)); /* lance skill */
  18.      if (u.twoweap && P_SKILL(P_TWO_WEAPON_COMBAT) < skill_rating)
  19.          skill_rating = P_SKILL(P_TWO_WEAPON_COMBAT);
  20.      if (skill_rating == P_ISRESTRICTED)
  21.          skill_rating = P_UNSKILLED; /* 0=>1 */
  22.  
  23.      /* odds to joust are expert:80%, skilled:60%, basic:40%, unskilled:20% */
  24.      if ((joust_dieroll = rn2(5)) < skill_rating) {
  25.          if (joust_dieroll == 0 && rnl(50) == (50 - 1) && !unsolid(mon->data)
  26.              && !obj_resists(obj, 0, 100))
  27.              return -1; /* hit that breaks lance */
  28.          return 1;      /* successful joust */
  29.      }
  30.      return 0; /* no joust bonus; revert to ordinary attack */
  31.  }
  32.  

demonpet

  1.  /*
  2.   * Send in a demon pet for the hero.  Exercise wisdom.
  3.   *
  4.   * This function used to be inline to damageum(), but the Metrowerks compiler
  5.   * (DR4 and DR4.5) screws up with an internal error 5 "Expression Too
  6.   * Complex."
  7.   * Pulling it out makes it work.
  8.   */
  9.  STATIC_OVL void
  10.  demonpet()
  11.  {
  12.      int i;
  13.      struct permonst *pm;
  14.      struct monst *dtmp;
  15.  
  16.      pline("Some hell-p has arrived!");
  17.      i = !rn2(6) ? ndemon(u.ualign.type) : NON_PM;
  18.      pm = i != NON_PM ? &mons[i] : youmonst.data;
  19.      if ((dtmp = makemon(pm, u.ux, u.uy, NO_MM_FLAGS)) != 0)
  20.          (void) tamedog(dtmp, (struct obj *) 0);
  21.      exercise(A_WIS, TRUE);
  22.  }
  23.  

theft_petrifies

  1.  STATIC_OVL boolean
  2.  theft_petrifies(otmp)
  3.  struct obj *otmp;
  4.  {
  5.      if (uarmg || otmp->otyp != CORPSE
  6.          || !touch_petrifies(&mons[otmp->corpsenm]) || Stone_resistance)
  7.          return FALSE;
  8.  
  9.  #if 0   /* no poly_when_stoned() critter has theft capability */
  10.      if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM)) {
  11.          display_nhwindow(WIN_MESSAGE, FALSE);   /* --More-- */
  12.          return TRUE;
  13.      }
  14.  #endif
  15.  
  16.      /* stealing this corpse is fatal... */
  17.      instapetrify(corpse_xname(otmp, "stolen", CXN_ARTICLE));
  18.      /* apparently wasn't fatal after all... */
  19.      return TRUE;
  20.  }
  21.  

steal_it

  1.  /*
  2.   * Player uses theft attack against monster.
  3.   *
  4.   * If the target is wearing body armor, take all of its possessions;
  5.   * otherwise, take one object.  [Is this really the behavior we want?]
  6.   */
  7.  STATIC_OVL void
  8.  steal_it(mdef, mattk)
  9.  struct monst *mdef;
  10.  struct attack *mattk;
  11.  {
  12.      struct obj *otmp, *stealoid, **minvent_ptr;
  13.      long unwornmask;
  14.  
  15.      if (!mdef->minvent)
  16.          return; /* nothing to take */
  17.  
  18.      /* look for worn body armor */
  19.      stealoid = (struct obj *) 0;
  20.      if (could_seduce(&youmonst, mdef, mattk)) {
  21.          /* find armor, and move it to end of inventory in the process */
  22.          minvent_ptr = &mdef->minvent;
  23.          while ((otmp = *minvent_ptr) != 0)
  24.              if (otmp->owornmask & W_ARM) {
  25.                  if (stealoid)
  26.                      panic("steal_it: multiple worn suits");
  27.                  *minvent_ptr = otmp->nobj; /* take armor out of minvent */
  28.                  stealoid = otmp;
  29.                  stealoid->nobj = (struct obj *) 0;
  30.              } else {
  31.                  minvent_ptr = &otmp->nobj;
  32.              }
  33.          *minvent_ptr = stealoid; /* put armor back into minvent */
  34.      }
  35.  
  36.      if (stealoid) { /* we will be taking everything */
  37.          if (gender(mdef) == (int) u.mfemale && youmonst.data->mlet == S_NYMPH)
  38.              You("charm %s.  She gladly hands over her possessions.",
  39.                  mon_nam(mdef));
  40.          else
  41.              You("seduce %s and %s starts to take off %s clothes.",
  42.                  mon_nam(mdef), mhe(mdef), mhis(mdef));
  43.      }
  44.  
  45.      while ((otmp = mdef->minvent) != 0) {
  46.          if (!Upolyd)
  47.              break; /* no longer have ability to steal */
  48.          /* take the object away from the monster */
  49.          obj_extract_self(otmp);
  50.          if ((unwornmask = otmp->owornmask) != 0L) {
  51.              mdef->misc_worn_check &= ~unwornmask;
  52.              if (otmp->owornmask & W_WEP)
  53.                  setmnotwielded(mdef, otmp);
  54.              otmp->owornmask = 0L;
  55.              update_mon_intrinsics(mdef, otmp, FALSE, FALSE);
  56.  
  57.              if (otmp == stealoid) /* special message for final item */
  58.                  pline("%s finishes taking off %s suit.", Monnam(mdef),
  59.                        mhis(mdef));
  60.          }
  61.          /* give the object to the character */
  62.          otmp = hold_another_object(otmp, "You snatched but dropped %s.",
  63.                                     doname(otmp), "You steal: ");
  64.          if (otmp->where != OBJ_INVENT)
  65.              continue;
  66.          if (theft_petrifies(otmp))
  67.              break; /* stop thieving even though hero survived */
  68.          /* more take-away handling, after theft message */
  69.          if (unwornmask & W_WEP) { /* stole wielded weapon */
  70.              possibly_unwield(mdef, FALSE);
  71.          } else if (unwornmask & W_ARMG) { /* stole worn gloves */
  72.              mselftouch(mdef, (const char *) 0, TRUE);
  73.              if (mdef->mhp <= 0) /* it's now a statue */
  74.                  return;         /* can't continue stealing */
  75.          }
  76.  
  77.          if (!stealoid)
  78.              break; /* only taking one item */
  79.      }
  80.  }
  81.  

damageum

  1.  int
  2.  damageum(mdef, mattk)
  3.  register struct monst *mdef;
  4.  register struct attack *mattk;
  5.  {
  6.      register struct permonst *pd = mdef->data;
  7.      int armpro, tmp = d((int) mattk->damn, (int) mattk->damd);
  8.      boolean negated;
  9.  
  10.      armpro = magic_negation(mdef);
  11.      /* since hero can't be cancelled, only defender's armor applies */
  12.      negated = !(rn2(10) >= 3 * armpro);
  13.  
  14.      if (is_demon(youmonst.data) && !rn2(13) && !uwep
  15.          && u.umonnum != PM_SUCCUBUS && u.umonnum != PM_INCUBUS
  16.          && u.umonnum != PM_BALROG) {
  17.          demonpet();
  18.          return 0;
  19.      }
  20.      switch (mattk->adtyp) {
  21.      case AD_STUN:
  22.          if (!Blind)
  23.              pline("%s %s for a moment.", Monnam(mdef),
  24.                    makeplural(stagger(pd, "stagger")));
  25.          mdef->mstun = 1;
  26.          goto physical;
  27.      case AD_LEGS:
  28.  #if 0
  29.          if (u.ucancelled) {
  30.              tmp = 0;
  31.              break;
  32.          }
  33.  #endif
  34.          goto physical;
  35.      case AD_WERE: /* no special effect on monsters */
  36.      case AD_HEAL: /* likewise */
  37.      case AD_PHYS:
  38.      physical:
  39.          if (mattk->aatyp == AT_WEAP) {
  40.              if (uwep)
  41.                  tmp = 0;
  42.          } else if (mattk->aatyp == AT_KICK) {
  43.              if (thick_skinned(pd))
  44.                  tmp = 0;
  45.              if (pd == &mons[PM_SHADE]) {
  46.                  if (!(uarmf && uarmf->blessed)) {
  47.                      impossible("bad shade attack function flow?");
  48.                      tmp = 0;
  49.                  } else
  50.                      tmp = rnd(4); /* bless damage */
  51.              }
  52.              /* add ring(s) of increase damage */
  53.              if (u.udaminc > 0) {
  54.                  /* applies even if damage was 0 */
  55.                  tmp += u.udaminc;
  56.              } else if (tmp > 0) {
  57.                  /* ring(s) might be negative; avoid converting
  58.                     0 to non-0 or positive to non-positive */
  59.                  tmp += u.udaminc;
  60.                  if (tmp < 1)
  61.                      tmp = 1;
  62.              }
  63.          }
  64.          break;
  65.      case AD_FIRE:
  66.          if (negated) {
  67.              tmp = 0;
  68.              break;
  69.          }
  70.          if (!Blind)
  71.              pline("%s is %s!", Monnam(mdef), on_fire(pd, mattk));
  72.          if (completelyburns(pd)) { /* paper golem or straw golem */
  73.              if (!Blind)
  74.                  pline("%s burns completely!", Monnam(mdef));
  75.              else
  76.                  You("smell burning%s.",
  77.                      (pd == &mons[PM_PAPER_GOLEM]) ? " paper"
  78.                        : (pd == &mons[PM_STRAW_GOLEM]) ? " straw" : "");
  79.              xkilled(mdef, XKILL_NOMSG | XKILL_NOCORPSE);
  80.              tmp = 0;
  81.              break;
  82.              /* Don't return yet; keep hp<1 and tmp=0 for pet msg */
  83.          }
  84.          tmp += destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE);
  85.          tmp += destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE);
  86.          if (resists_fire(mdef)) {
  87.              if (!Blind)
  88.                  pline_The("fire doesn't heat %s!", mon_nam(mdef));
  89.              golemeffects(mdef, AD_FIRE, tmp);
  90.              shieldeff(mdef->mx, mdef->my);
  91.              tmp = 0;
  92.          }
  93.          /* only potions damage resistant players in destroy_item */
  94.          tmp += destroy_mitem(mdef, POTION_CLASS, AD_FIRE);
  95.          break;
  96.      case AD_COLD:
  97.          if (negated) {
  98.              tmp = 0;
  99.              break;
  100.          }
  101.          if (!Blind)
  102.              pline("%s is covered in frost!", Monnam(mdef));
  103.          if (resists_cold(mdef)) {
  104.              shieldeff(mdef->mx, mdef->my);
  105.              if (!Blind)
  106.                  pline_The("frost doesn't chill %s!", mon_nam(mdef));
  107.              golemeffects(mdef, AD_COLD, tmp);
  108.              tmp = 0;
  109.          }
  110.          tmp += destroy_mitem(mdef, POTION_CLASS, AD_COLD);
  111.          break;
  112.      case AD_ELEC:
  113.          if (negated) {
  114.              tmp = 0;
  115.              break;
  116.          }
  117.          if (!Blind)
  118.              pline("%s is zapped!", Monnam(mdef));
  119.          tmp += destroy_mitem(mdef, WAND_CLASS, AD_ELEC);
  120.          if (resists_elec(mdef)) {
  121.              if (!Blind)
  122.                  pline_The("zap doesn't shock %s!", mon_nam(mdef));
  123.              golemeffects(mdef, AD_ELEC, tmp);
  124.              shieldeff(mdef->mx, mdef->my);
  125.              tmp = 0;
  126.          }
  127.          /* only rings damage resistant players in destroy_item */
  128.          tmp += destroy_mitem(mdef, RING_CLASS, AD_ELEC);
  129.          break;
  130.      case AD_ACID:
  131.          if (resists_acid(mdef))
  132.              tmp = 0;
  133.          break;
  134.      case AD_STON:
  135.          if (!munstone(mdef, TRUE))
  136.              minstapetrify(mdef, TRUE);
  137.          tmp = 0;
  138.          break;
  139.      case AD_SSEX:
  140.      case AD_SEDU:
  141.      case AD_SITM:
  142.          steal_it(mdef, mattk);
  143.          tmp = 0;
  144.          break;
  145.      case AD_SGLD:
  146.          /* This you as a leprechaun, so steal
  147.             real gold only, no lesser coins */
  148.          {
  149.              struct obj *mongold = findgold(mdef->minvent);
  150.              if (mongold) {
  151.                  obj_extract_self(mongold);
  152.                  if (merge_choice(invent, mongold) || inv_cnt(FALSE) < 52) {
  153.                      addinv(mongold);
  154.                      Your("purse feels heavier.");
  155.                  } else {
  156.                      You("grab %s's gold, but find no room in your knapsack.",
  157.                          mon_nam(mdef));
  158.                      dropy(mongold);
  159.                  }
  160.              }
  161.          }
  162.          exercise(A_DEX, TRUE);
  163.          tmp = 0;
  164.          break;
  165.      case AD_TLPT:
  166.          if (tmp <= 0)
  167.              tmp = 1;
  168.          if (!negated && tmp < mdef->mhp) {
  169.              char nambuf[BUFSZ];
  170.              boolean u_saw_mon =
  171.                  canseemon(mdef) || (u.uswallow && u.ustuck == mdef);
  172.              /* record the name before losing sight of monster */
  173.              Strcpy(nambuf, Monnam(mdef));
  174.              if (u_teleport_mon(mdef, FALSE) && u_saw_mon
  175.                  && !(canseemon(mdef) || (u.uswallow && u.ustuck == mdef)))
  176.                  pline("%s suddenly disappears!", nambuf);
  177.          }
  178.          break;
  179.      case AD_BLND:
  180.          if (can_blnd(&youmonst, mdef, mattk->aatyp, (struct obj *) 0)) {
  181.              if (!Blind && mdef->mcansee)
  182.                  pline("%s is blinded.", Monnam(mdef));
  183.              mdef->mcansee = 0;
  184.              tmp += mdef->mblinded;
  185.              if (tmp > 127)
  186.                  tmp = 127;
  187.              mdef->mblinded = tmp;
  188.          }
  189.          tmp = 0;
  190.          break;
  191.      case AD_CURS:
  192.          if (night() && !rn2(10) && !mdef->mcan) {
  193.              if (pd == &mons[PM_CLAY_GOLEM]) {
  194.                  if (!Blind)
  195.                      pline("Some writing vanishes from %s head!",
  196.                            s_suffix(mon_nam(mdef)));
  197.                  xkilled(mdef, XKILL_NOMSG);
  198.                  /* Don't return yet; keep hp<1 and tmp=0 for pet msg */
  199.              } else {
  200.                  mdef->mcan = 1;
  201.                  You("chuckle.");
  202.              }
  203.          }
  204.          tmp = 0;
  205.          break;
  206.      case AD_DRLI:
  207.          if (!negated && !rn2(3) && !resists_drli(mdef)) {
  208.              int xtmp = d(2, 6);
  209.  
  210.              pline("%s suddenly seems weaker!", Monnam(mdef));
  211.              mdef->mhpmax -= xtmp;
  212.              mdef->mhp -= xtmp;
  213.              /* !m_lev: level 0 monster is killed regardless of hit points
  214.                 rather than drop to level -1 */
  215.              if (mdef->mhp <= 0 || !mdef->m_lev) {
  216.                  pline("%s dies!", Monnam(mdef));
  217.                  xkilled(mdef, XKILL_NOMSG);
  218.              } else
  219.                  mdef->m_lev--;
  220.              tmp = 0;
  221.          }
  222.          break;
  223.      case AD_RUST:
  224.          if (pd == &mons[PM_IRON_GOLEM]) {
  225.              pline("%s falls to pieces!", Monnam(mdef));
  226.              xkilled(mdef, XKILL_NOMSG);
  227.          }
  228.          erode_armor(mdef, ERODE_RUST);
  229.          tmp = 0;
  230.          break;
  231.      case AD_CORR:
  232.          erode_armor(mdef, ERODE_CORRODE);
  233.          tmp = 0;
  234.          break;
  235.      case AD_DCAY:
  236.          if (pd == &mons[PM_WOOD_GOLEM] || pd == &mons[PM_LEATHER_GOLEM]) {
  237.              pline("%s falls to pieces!", Monnam(mdef));
  238.              xkilled(mdef, XKILL_NOMSG);
  239.          }
  240.          erode_armor(mdef, ERODE_ROT);
  241.          tmp = 0;
  242.          break;
  243.      case AD_DREN:
  244.          if (!negated && !rn2(4))
  245.              xdrainenergym(mdef, TRUE);
  246.          tmp = 0;
  247.          break;
  248.      case AD_DRST:
  249.      case AD_DRDX:
  250.      case AD_DRCO:
  251.          if (!negated && !rn2(8)) {
  252.              Your("%s was poisoned!", mpoisons_subj(&youmonst, mattk));
  253.              if (resists_poison(mdef))
  254.                  pline_The("poison doesn't seem to affect %s.", mon_nam(mdef));
  255.              else {
  256.                  if (!rn2(10)) {
  257.                      Your("poison was deadly...");
  258.                      tmp = mdef->mhp;
  259.                  } else
  260.                      tmp += rn1(10, 6);
  261.              }
  262.          }
  263.          break;
  264.      case AD_DRIN: {
  265.          struct obj *helmet;
  266.  
  267.          if (notonhead || !has_head(pd)) {
  268.              pline("%s doesn't seem harmed.", Monnam(mdef));
  269.              tmp = 0;
  270.              if (!Unchanging && pd == &mons[PM_GREEN_SLIME]) {
  271.                  if (!Slimed) {
  272.                      You("suck in some slime and don't feel very well.");
  273.                      make_slimed(10L, (char *) 0);
  274.                  }
  275.              }
  276.              break;
  277.          }
  278.          if (m_slips_free(mdef, mattk))
  279.              break;
  280.  
  281.          if ((helmet = which_armor(mdef, W_ARMH)) != 0 && rn2(8)) {
  282.              pline("%s %s blocks your attack to %s head.",
  283.                    s_suffix(Monnam(mdef)), helm_simple_name(helmet),
  284.                    mhis(mdef));
  285.              break;
  286.          }
  287.  
  288.          (void) eat_brains(&youmonst, mdef, TRUE, &tmp);
  289.          break;
  290.      }
  291.      case AD_STCK:
  292.          if (!negated && !sticks(pd))
  293.              u.ustuck = mdef; /* it's now stuck to you */
  294.          break;
  295.      case AD_WRAP:
  296.          if (!sticks(pd)) {
  297.              if (!u.ustuck && !rn2(10)) {
  298.                  if (m_slips_free(mdef, mattk)) {
  299.                      tmp = 0;
  300.                  } else {
  301.                      You("swing yourself around %s!", mon_nam(mdef));
  302.                      u.ustuck = mdef;
  303.                  }
  304.              } else if (u.ustuck == mdef) {
  305.                  /* Monsters don't wear amulets of magical breathing */
  306.                  if (is_pool(u.ux, u.uy) && !is_swimmer(pd)
  307.                      && !amphibious(pd)) {
  308.                      You("drown %s...", mon_nam(mdef));
  309.                      tmp = mdef->mhp;
  310.                  } else if (mattk->aatyp == AT_HUGS)
  311.                      pline("%s is being crushed.", Monnam(mdef));
  312.              } else {
  313.                  tmp = 0;
  314.                  if (flags.verbose)
  315.                      You("brush against %s %s.", s_suffix(mon_nam(mdef)),
  316.                          mbodypart(mdef, LEG));
  317.              }
  318.          } else
  319.              tmp = 0;
  320.          break;
  321.      case AD_PLYS:
  322.          if (!negated && mdef->mcanmove && !rn2(3) && tmp < mdef->mhp) {
  323.              if (!Blind)
  324.                  pline("%s is frozen by you!", Monnam(mdef));
  325.              paralyze_monst(mdef, rnd(10));
  326.          }
  327.          break;
  328.      case AD_SLEE:
  329.          if (!negated && !mdef->msleeping && sleep_monst(mdef, rnd(10), -1)) {
  330.              if (!Blind)
  331.                  pline("%s is put to sleep by you!", Monnam(mdef));
  332.              slept_monst(mdef);
  333.          }
  334.          break;
  335.      case AD_SLIM:
  336.          if (negated)
  337.              break; /* physical damage only */
  338.          if (!rn2(4) && !slimeproof(pd)) {
  339.              if (!munslime(mdef, TRUE) && mdef->mhp > 0) {
  340.                  /* this assumes newcham() won't fail; since hero has
  341.                     a slime attack, green slimes haven't been geno'd */
  342.                  You("turn %s into slime.", mon_nam(mdef));
  343.                  if (newcham(mdef, &mons[PM_GREEN_SLIME], FALSE, FALSE))
  344.                      pd = mdef->data;
  345.              }
  346.              /* munslime attempt could have been fatal */
  347.              if (mdef->mhp < 1)
  348.                  return 2; /* skip death message */
  349.              tmp = 0;
  350.          }
  351.          break;
  352.      case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */
  353.          /* there's no msomearmor() function, so just do damage */
  354.          /* if (negated) break; */
  355.          break;
  356.      case AD_SLOW:
  357.          if (!negated && mdef->mspeed != MSLOW) {
  358.              unsigned int oldspeed = mdef->mspeed;
  359.  
  360.              mon_adjust_speed(mdef, -1, (struct obj *) 0);
  361.              if (mdef->mspeed != oldspeed && canseemon(mdef))
  362.                  pline("%s slows down.", Monnam(mdef));
  363.          }
  364.          break;
  365.      case AD_CONF:
  366.          if (!mdef->mconf) {
  367.              if (canseemon(mdef))
  368.                  pline("%s looks confused.", Monnam(mdef));
  369.              mdef->mconf = 1;
  370.          }
  371.          break;
  372.      default:
  373.          tmp = 0;
  374.          break;
  375.      }
  376.  
  377.      mdef->mstrategy &= ~STRAT_WAITFORU; /* in case player is very fast */
  378.      mdef->mhp -= tmp;
  379.      if (mdef->mhp < 1) {
  380.          if (mdef->mtame && !cansee(mdef->mx, mdef->my)) {
  381.              You_feel("embarrassed for a moment.");
  382.              if (tmp)
  383.                  xkilled(mdef, XKILL_NOMSG); /* !tmp but hp<1: already killed */
  384.          } else if (!flags.verbose) {
  385.              You("destroy it!");
  386.              if (tmp)
  387.                  xkilled(mdef, XKILL_NOMSG);
  388.          } else if (tmp)
  389.              killed(mdef);
  390.          return 2;
  391.      }
  392.      return 1;
  393.  }
  394.  

explum

  1.  STATIC_OVL int
  2.  explum(mdef, mattk)
  3.  register struct monst *mdef;
  4.  register struct attack *mattk;
  5.  {
  6.      register int tmp = d((int) mattk->damn, (int) mattk->damd);
  7.  
  8.      You("explode!");
  9.      switch (mattk->adtyp) {
  10.          boolean resistance; /* only for cold/fire/elec */
  11.  
  12.      case AD_BLND:
  13.          if (!resists_blnd(mdef)) {
  14.              pline("%s is blinded by your flash of light!", Monnam(mdef));
  15.              mdef->mblinded = min((int) mdef->mblinded + tmp, 127);
  16.              mdef->mcansee = 0;
  17.          }
  18.          break;
  19.      case AD_HALU:
  20.          if (haseyes(mdef->data) && mdef->mcansee) {
  21.              pline("%s is affected by your flash of light!", Monnam(mdef));
  22.              mdef->mconf = 1;
  23.          }
  24.          break;
  25.      case AD_COLD:
  26.          resistance = resists_cold(mdef);
  27.          goto common;
  28.      case AD_FIRE:
  29.          resistance = resists_fire(mdef);
  30.          goto common;
  31.      case AD_ELEC:
  32.          resistance = resists_elec(mdef);
  33.      common:
  34.          if (!resistance) {
  35.              pline("%s gets blasted!", Monnam(mdef));
  36.              mdef->mhp -= tmp;
  37.              if (mdef->mhp <= 0) {
  38.                  killed(mdef);
  39.                  return 2;
  40.              }
  41.          } else {
  42.              shieldeff(mdef->mx, mdef->my);
  43.              if (is_golem(mdef->data))
  44.                  golemeffects(mdef, (int) mattk->adtyp, tmp);
  45.              else
  46.                  pline_The("blast doesn't seem to affect %s.", mon_nam(mdef));
  47.          }
  48.          break;
  49.      default:
  50.          break;
  51.      }
  52.      return 1;
  53.  }
  54.  

start_engulf

  1.  STATIC_OVL void
  2.  start_engulf(mdef)
  3.  struct monst *mdef;
  4.  {
  5.      if (!Invisible) {
  6.          map_location(u.ux, u.uy, TRUE);
  7.          tmp_at(DISP_ALWAYS, mon_to_glyph(&youmonst));
  8.          tmp_at(mdef->mx, mdef->my);
  9.      }
  10.      You("engulf %s!", mon_nam(mdef));
  11.      delay_output();
  12.      delay_output();
  13.  }
  14.  

end_engulf

  1.  STATIC_OVL void
  2.  end_engulf()
  3.  {
  4.      if (!Invisible) {
  5.          tmp_at(DISP_END, 0);
  6.          newsym(u.ux, u.uy);
  7.      }
  8.  }
  9.  

gulpum

  1.  STATIC_OVL int
  2.  gulpum(mdef, mattk)
  3.  register struct monst *mdef;
  4.  register struct attack *mattk;
  5.  {
  6.  #ifdef LINT /* static char msgbuf[BUFSZ]; */
  7.      char msgbuf[BUFSZ];
  8.  #else
  9.      static char msgbuf[BUFSZ]; /* for nomovemsg */
  10.  #endif
  11.      register int tmp;
  12.      register int dam = d((int) mattk->damn, (int) mattk->damd);
  13.      boolean fatal_gulp;
  14.      struct obj *otmp;
  15.      struct permonst *pd = mdef->data;
  16.  
  17.      /* Not totally the same as for real monsters.  Specifically, these
  18.       * don't take multiple moves.  (It's just too hard, for too little
  19.       * result, to program monsters which attack from inside you, which
  20.       * would be necessary if done accurately.)  Instead, we arbitrarily
  21.       * kill the monster immediately for AD_DGST and we regurgitate them
  22.       * after exactly 1 round of attack otherwise.  -KAA
  23.       */
  24.  
  25.      if (!engulf_target(&youmonst, mdef))
  26.          return 0;
  27.  
  28.      if (u.uhunger < 1500 && !u.uswallow) {
  29.          for (otmp = mdef->minvent; otmp; otmp = otmp->nobj)
  30.              (void) snuff_lit(otmp);
  31.  
  32.          /* force vampire in bat, cloud, or wolf form to revert back to
  33.             vampire form now instead of dealing with that when it dies */
  34.          if (is_vampshifter(mdef)
  35.              && newcham(mdef, &mons[mdef->cham], FALSE, FALSE)) {
  36.              You("engulf it, then expel it.");
  37.              if (canspotmon(mdef))
  38.                  pline("It turns into %s.", a_monnam(mdef));
  39.              else
  40.                  map_invisible(mdef->mx, mdef->my);
  41.              return 1;
  42.          }
  43.  
  44.          /* engulfing a cockatrice or digesting a Rider or Medusa */
  45.          fatal_gulp = (touch_petrifies(pd) && !Stone_resistance)
  46.                       || (mattk->adtyp == AD_DGST
  47.                           && (is_rider(pd) || (pd == &mons[PM_MEDUSA]
  48.                                                && !Stone_resistance)));
  49.  
  50.          if ((mattk->adtyp == AD_DGST && !Slow_digestion) || fatal_gulp)
  51.              eating_conducts(pd);
  52.  
  53.          if (fatal_gulp && !is_rider(pd)) { /* petrification */
  54.              char kbuf[BUFSZ];
  55.              const char *mname = pd->mname;
  56.  
  57.              if (!type_is_pname(pd))
  58.                  mname = an(mname);
  59.              You("englut %s.", mon_nam(mdef));
  60.              Sprintf(kbuf, "swallowing %s whole", mname);
  61.              instapetrify(kbuf);
  62.          } else {
  63.              start_engulf(mdef);
  64.              switch (mattk->adtyp) {
  65.              case AD_DGST:
  66.                  /* eating a Rider or its corpse is fatal */
  67.                  if (is_rider(pd)) {
  68.                      pline("Unfortunately, digesting any of it is fatal.");
  69.                      end_engulf();
  70.                      Sprintf(killer.name, "unwisely tried to eat %s",
  71.                              pd->mname);
  72.                      killer.format = NO_KILLER_PREFIX;
  73.                      done(DIED);
  74.                      return 0; /* lifesaved */
  75.                  }
  76.  
  77.                  if (Slow_digestion) {
  78.                      dam = 0;
  79.                      break;
  80.                  }
  81.  
  82.                  /* Use up amulet of life saving */
  83.                  if (!!(otmp = mlifesaver(mdef)))
  84.                      m_useup(mdef, otmp);
  85.  
  86.                  newuhs(FALSE);
  87.                  /* start_engulf() issues "you engulf <mdef>" above; this
  88.                     used to specify XKILL_NOMSG but we need "you kill <mdef>"
  89.                     in case we're also going to get "welcome to level N+1";
  90.                     "you totally digest <mdef>" will be coming soon (after
  91.                     several turns) but the level-gain message seems out of
  92.                     order if the kill message is left implicit */
  93.                  xkilled(mdef, XKILL_GIVEMSG | XKILL_NOCORPSE);
  94.                  if (mdef->mhp > 0) { /* monster lifesaved */
  95.                      You("hurriedly regurgitate the sizzling in your %s.",
  96.                          body_part(STOMACH));
  97.                  } else {
  98.                      tmp = 1 + (pd->cwt >> 8);
  99.                      if (corpse_chance(mdef, &youmonst, TRUE)
  100.                          && !(mvitals[monsndx(pd)].mvflags & G_NOCORPSE)) {
  101.                          /* nutrition only if there can be a corpse */
  102.                          u.uhunger += (pd->cnutrit + 1) / 2;
  103.                      } else
  104.                          tmp = 0;
  105.                      Sprintf(msgbuf, "You totally digest %s.", mon_nam(mdef));
  106.                      if (tmp != 0) {
  107.                          /* setting afternmv = end_engulf is tempting,
  108.                           * but will cause problems if the player is
  109.                           * attacked (which uses his real location) or
  110.                           * if his See_invisible wears off
  111.                           */
  112.                          You("digest %s.", mon_nam(mdef));
  113.                          if (Slow_digestion)
  114.                              tmp *= 2;
  115.                          nomul(-tmp);
  116.                          multi_reason = "digesting something";
  117.                          nomovemsg = msgbuf;
  118.                      } else
  119.                          pline1(msgbuf);
  120.                      if (pd == &mons[PM_GREEN_SLIME]) {
  121.                          Sprintf(msgbuf, "%s isn't sitting well with you.",
  122.                                  The(pd->mname));
  123.                          if (!Unchanging) {
  124.                              make_slimed(5L, (char *) 0);
  125.                          }
  126.                      } else
  127.                          exercise(A_CON, TRUE);
  128.                  }
  129.                  end_engulf();
  130.                  return 2;
  131.              case AD_PHYS:
  132.                  if (youmonst.data == &mons[PM_FOG_CLOUD]) {
  133.                      pline("%s is laden with your moisture.", Monnam(mdef));
  134.                      if (amphibious(pd) && !flaming(pd)) {
  135.                          dam = 0;
  136.                          pline("%s seems unharmed.", Monnam(mdef));
  137.                      }
  138.                  } else
  139.                      pline("%s is pummeled with your debris!", Monnam(mdef));
  140.                  break;
  141.              case AD_ACID:
  142.                  pline("%s is covered with your goo!", Monnam(mdef));
  143.                  if (resists_acid(mdef)) {
  144.                      pline("It seems harmless to %s.", mon_nam(mdef));
  145.                      dam = 0;
  146.                  }
  147.                  break;
  148.              case AD_BLND:
  149.                  if (can_blnd(&youmonst, mdef, mattk->aatyp,
  150.                               (struct obj *) 0)) {
  151.                      if (mdef->mcansee)
  152.                          pline("%s can't see in there!", Monnam(mdef));
  153.                      mdef->mcansee = 0;
  154.                      dam += mdef->mblinded;
  155.                      if (dam > 127)
  156.                          dam = 127;
  157.                      mdef->mblinded = dam;
  158.                  }
  159.                  dam = 0;
  160.                  break;
  161.              case AD_ELEC:
  162.                  if (rn2(2)) {
  163.                      pline_The("air around %s crackles with electricity.",
  164.                                mon_nam(mdef));
  165.                      if (resists_elec(mdef)) {
  166.                          pline("%s seems unhurt.", Monnam(mdef));
  167.                          dam = 0;
  168.                      }
  169.                      golemeffects(mdef, (int) mattk->adtyp, dam);
  170.                  } else
  171.                      dam = 0;
  172.                  break;
  173.              case AD_COLD:
  174.                  if (rn2(2)) {
  175.                      if (resists_cold(mdef)) {
  176.                          pline("%s seems mildly chilly.", Monnam(mdef));
  177.                          dam = 0;
  178.                      } else
  179.                          pline("%s is freezing to death!", Monnam(mdef));
  180.                      golemeffects(mdef, (int) mattk->adtyp, dam);
  181.                  } else
  182.                      dam = 0;
  183.                  break;
  184.              case AD_FIRE:
  185.                  if (rn2(2)) {
  186.                      if (resists_fire(mdef)) {
  187.                          pline("%s seems mildly hot.", Monnam(mdef));
  188.                          dam = 0;
  189.                      } else
  190.                          pline("%s is burning to a crisp!", Monnam(mdef));
  191.                      golemeffects(mdef, (int) mattk->adtyp, dam);
  192.                  } else
  193.                      dam = 0;
  194.                  break;
  195.              case AD_DREN:
  196.                  if (!rn2(4))
  197.                      xdrainenergym(mdef, TRUE);
  198.                  dam = 0;
  199.                  break;
  200.              }
  201.              end_engulf();
  202.              mdef->mhp -= dam;
  203.              if (mdef->mhp <= 0) {
  204.                  killed(mdef);
  205.                  if (mdef->mhp <= 0) /* not lifesaved */
  206.                      return 2;
  207.              }
  208.              You("%s %s!", is_animal(youmonst.data) ? "regurgitate" : "expel",
  209.                  mon_nam(mdef));
  210.              if (Slow_digestion || is_animal(youmonst.data)) {
  211.                  pline("Obviously, you didn't like %s taste.",
  212.                        s_suffix(mon_nam(mdef)));
  213.              }
  214.          }
  215.      }
  216.      return 0;
  217.  }
  218.  

missum

  1.  void
  2.  missum(mdef, mattk, wouldhavehit)
  3.  register struct monst *mdef;
  4.  register struct attack *mattk;
  5.  boolean wouldhavehit;
  6.  {
  7.      if (wouldhavehit) /* monk is missing due to penalty for wearing suit */
  8.          Your("armor is rather cumbersome...");
  9.  
  10.      if (could_seduce(&youmonst, mdef, mattk))
  11.          You("pretend to be friendly to %s.", mon_nam(mdef));
  12.      else if (canspotmon(mdef) && flags.verbose)
  13.          You("miss %s.", mon_nam(mdef));
  14.      else
  15.          You("miss it.");
  16.      if (!mdef->msleeping && mdef->mcanmove)
  17.          wakeup(mdef, TRUE);
  18.  }
  19.  

hmonas

  1.  /* attack monster as a monster. */
  2.  STATIC_OVL boolean
  3.  hmonas(mon)
  4.  register struct monst *mon;
  5.  {
  6.      struct attack *mattk, alt_attk;
  7.      struct obj *weapon, **originalweapon;
  8.      boolean altwep = FALSE, weapon_used = FALSE;
  9.      int i, tmp, armorpenalty, sum[NATTK], nsum = 0, dhit = 0, attknum = 0;
  10.      int dieroll;
  11.  
  12.      for (i = 0; i < NATTK; i++) {
  13.          sum[i] = 0;
  14.          mattk = getmattk(&youmonst, mon, i, sum, &alt_attk);
  15.          weapon = 0;
  16.          switch (mattk->aatyp) {
  17.          case AT_WEAP:
  18.          use_weapon:
  19.              /* Certain monsters don't use weapons when encountered as enemies,
  20.               * but players who polymorph into them have hands or claws and
  21.               * thus should be able to use weapons.  This shouldn't prohibit
  22.               * the use of most special abilities, either.
  23.               * If monster has multiple claw attacks, only one can use weapon.
  24.               */
  25.              weapon_used = TRUE;
  26.              /* Potential problem: if the monster gets multiple weapon attacks,
  27.               * we currently allow the player to get each of these as a weapon
  28.               * attack.  Is this really desirable?
  29.               */
  30.              /* approximate two-weapon mode; known_hitum() -> hmon() -> &c
  31.                 might destroy the weapon argument, but it might also already
  32.                 be Null, and we want to track that for passive() */
  33.              originalweapon = (altwep && uswapwep) ? &uswapwep : &uwep;
  34.              if (uswapwep /* set up 'altwep' flag for next iteration */
  35.                  /* only switch to uswapwep if it's a weapon */
  36.                  && (uswapwep->oclass == WEAPON_CLASS || is_weptool(uswapwep))
  37.                  /* only switch if uswapwep is not bow, arrows, or darts */
  38.                  && !(is_launcher(uswapwep) || is_ammo(uswapwep)
  39.                       || is_missile(uswapwep))) /* dart, shuriken, boomerang */
  40.                  altwep = !altwep; /* toggle for next attack */
  41.              weapon = *originalweapon;
  42.              if (!weapon) /* no need to go beyond no-gloves to rings; not ...*/
  43.                  originalweapon = &uarmg; /*... subject to erosion damage */
  44.  
  45.              tmp = find_roll_to_hit(mon, AT_WEAP, weapon, &attknum,
  46.                                     &armorpenalty);
  47.              dieroll = rnd(20);
  48.              dhit = (tmp > dieroll || u.uswallow);
  49.              /* Enemy dead, before any special abilities used */
  50.              if (!known_hitum(mon, weapon, &dhit, tmp,
  51.                               armorpenalty, mattk, dieroll)) {
  52.                  sum[i] = 2;
  53.                  break;
  54.              } else
  55.                  sum[i] = dhit;
  56.              /* originalweapon points to an equipment slot which might
  57.                 now be empty if the weapon was destroyed during the hit;
  58.                 passive(,weapon,...) won't call passive_obj() in that case */
  59.              weapon = *originalweapon; /* might receive passive erosion */
  60.              /* might be a worm that gets cut in half */
  61.              if (m_at(u.ux + u.dx, u.uy + u.dy) != mon)
  62.                  return (boolean) (nsum != 0);
  63.              /* Do not print "You hit" message, since known_hitum
  64.               * already did it.
  65.               */
  66.              if (dhit && mattk->adtyp != AD_SPEL && mattk->adtyp != AD_PHYS)
  67.                  sum[i] = damageum(mon, mattk);
  68.              break;
  69.          case AT_CLAW:
  70.              if (uwep && !cantwield(youmonst.data) && !weapon_used)
  71.                  goto use_weapon;
  72.              /*FALLTHRU*/
  73.          case AT_TUCH:
  74.              if (uwep && youmonst.data->mlet == S_LICH && !weapon_used)
  75.                  goto use_weapon;
  76.              /*FALLTHRU*/
  77.          case AT_KICK:
  78.          case AT_BITE:
  79.          case AT_STNG:
  80.          case AT_BUTT:
  81.          case AT_TENT:
  82.              tmp = find_roll_to_hit(mon, mattk->aatyp, (struct obj *) 0,
  83.                                     &attknum, &armorpenalty);
  84.              dieroll = rnd(20);
  85.              dhit = (tmp > dieroll || u.uswallow);
  86.              if (dhit) {
  87.                  int compat;
  88.  
  89.                  if (!u.uswallow
  90.                      && (compat = could_seduce(&youmonst, mon, mattk))) {
  91.                      You("%s %s %s.",
  92.                          mon->mcansee && haseyes(mon->data) ? "smile at"
  93.                                                             : "talk to",
  94.                          mon_nam(mon),
  95.                          compat == 2 ? "engagingly" : "seductively");
  96.                      /* doesn't anger it; no wakeup() */
  97.                      sum[i] = damageum(mon, mattk);
  98.                      break;
  99.                  }
  100.                  wakeup(mon, TRUE);
  101.                  /* maybe this check should be in damageum()? */
  102.                  if (mon->data == &mons[PM_SHADE]
  103.                      && !(mattk->aatyp == AT_KICK && uarmf
  104.                           && uarmf->blessed)) {
  105.                      Your("attack passes harmlessly through %s.",
  106.                           mon_nam(mon));
  107.                      break;
  108.                  }
  109.                  if (mattk->aatyp == AT_KICK)
  110.                      You("kick %s.", mon_nam(mon));
  111.                  else if (mattk->aatyp == AT_BITE)
  112.                      You("bite %s.", mon_nam(mon));
  113.                  else if (mattk->aatyp == AT_STNG)
  114.                      You("sting %s.", mon_nam(mon));
  115.                  else if (mattk->aatyp == AT_BUTT)
  116.                      You("butt %s.", mon_nam(mon));
  117.                  else if (mattk->aatyp == AT_TUCH)
  118.                      You("touch %s.", mon_nam(mon));
  119.                  else if (mattk->aatyp == AT_TENT)
  120.                      Your("tentacles suck %s.", mon_nam(mon));
  121.                  else
  122.                      You("hit %s.", mon_nam(mon));
  123.                  sum[i] = damageum(mon, mattk);
  124.              } else {
  125.                  missum(mon, mattk, (tmp + armorpenalty > dieroll));
  126.              }
  127.              break;
  128.  
  129.          case AT_HUGS:
  130.              /* automatic if prev two attacks succeed, or if
  131.               * already grabbed in a previous attack
  132.               */
  133.              dhit = 1;
  134.              wakeup(mon, TRUE);
  135.              if (mon->data == &mons[PM_SHADE])
  136.                  Your("hug passes harmlessly through %s.", mon_nam(mon));
  137.              else if (!sticks(mon->data) && !u.uswallow) {
  138.                  if (mon == u.ustuck) {
  139.                      pline("%s is being %s.", Monnam(mon),
  140.                            u.umonnum == PM_ROPE_GOLEM ? "choked" : "crushed");
  141.                      sum[i] = damageum(mon, mattk);
  142.                  } else if (i >= 2 && sum[i - 1] && sum[i - 2]) {
  143.                      You("grab %s!", mon_nam(mon));
  144.                      u.ustuck = mon;
  145.                      sum[i] = damageum(mon, mattk);
  146.                  }
  147.              }
  148.              break;
  149.  
  150.          case AT_EXPL: /* automatic hit if next to */
  151.              dhit = -1;
  152.              wakeup(mon, TRUE);
  153.              sum[i] = explum(mon, mattk);
  154.              break;
  155.  
  156.          case AT_ENGL:
  157.              tmp = find_roll_to_hit(mon, mattk->aatyp, (struct obj *) 0,
  158.                                     &attknum, &armorpenalty);
  159.              if ((dhit = (tmp > rnd(20 + i)))) {
  160.                  wakeup(mon, TRUE);
  161.                  if (mon->data == &mons[PM_SHADE])
  162.                      Your("attempt to surround %s is harmless.", mon_nam(mon));
  163.                  else {
  164.                      sum[i] = gulpum(mon, mattk);
  165.                      if (sum[i] == 2 && (mon->data->mlet == S_ZOMBIE
  166.                                          || mon->data->mlet == S_MUMMY)
  167.                          && rn2(5) && !Sick_resistance) {
  168.                          You_feel("%ssick.", (Sick) ? "very " : "");
  169.                          mdamageu(mon, rnd(8));
  170.                      }
  171.                  }
  172.              } else {
  173.                  missum(mon, mattk, FALSE);
  174.              }
  175.              break;
  176.  
  177.          case AT_MAGC:
  178.              /* No check for uwep; if wielding nothing we want to
  179.               * do the normal 1-2 points bare hand damage...
  180.               */
  181.              if ((youmonst.data->mlet == S_KOBOLD
  182.                   || youmonst.data->mlet == S_ORC
  183.                   || youmonst.data->mlet == S_GNOME) && !weapon_used)
  184.                  goto use_weapon;
  185.              /*FALLTHRU*/
  186.  
  187.          case AT_NONE:
  188.          case AT_BOOM:
  189.              continue;
  190.          /* Not break--avoid passive attacks from enemy */
  191.  
  192.          case AT_BREA:
  193.          case AT_SPIT:
  194.          case AT_GAZE: /* all done using #monster command */
  195.              dhit = 0;
  196.              break;
  197.  
  198.          default: /* Strange... */
  199.              impossible("strange attack of yours (%d)", mattk->aatyp);
  200.          }
  201.          if (dhit == -1) {
  202.              u.mh = -1; /* dead in the current form */
  203.              rehumanize();
  204.          }
  205.          if (sum[i] == 2) {
  206.              /* defender dead */
  207.              return (boolean) passive(mon, weapon, 1, 0, mattk->aatyp, FALSE);
  208.          } else {
  209.              (void) passive(mon, weapon, sum[i], 1, mattk->aatyp, FALSE);
  210.              nsum |= sum[i];
  211.          }
  212.          if (!Upolyd)
  213.              break; /* No extra attacks if no longer a monster */
  214.          if (multi < 0)
  215.              break; /* If paralyzed while attacking, i.e. floating eye */
  216.      }
  217.      return (boolean) (nsum != 0);
  218.  }
  219.  

passive

  1.  /*      Special (passive) attacks on you by monsters done here.
  2.   */
  3.  int
  4.  passive(mon, weapon, mhit, malive, aatyp, wep_was_destroyed)
  5.  struct monst *mon;
  6.  struct obj *weapon; /* uwep or uswapwep or uarmg or uarmf or Null */
  7.  boolean mhit;
  8.  int malive;
  9.  uchar aatyp;
  10.  boolean wep_was_destroyed;
  11.  {
  12.      register struct permonst *ptr = mon->data;
  13.      register int i, tmp;
  14.  
  15.      for (i = 0;; i++) {
  16.          if (i >= NATTK)
  17.              return (malive | mhit); /* no passive attacks */
  18.          if (ptr->mattk[i].aatyp == AT_NONE)
  19.              break; /* try this one */
  20.      }
  21.      /* Note: tmp not always used */
  22.      if (ptr->mattk[i].damn)
  23.          tmp = d((int) ptr->mattk[i].damn, (int) ptr->mattk[i].damd);
  24.      else if (ptr->mattk[i].damd)
  25.          tmp = d((int) mon->m_lev + 1, (int) ptr->mattk[i].damd);
  26.      else
  27.          tmp = 0;
  28.  
  29.      /*  These affect you even if they just died.
  30.       */
  31.      switch (ptr->mattk[i].adtyp) {
  32.      case AD_FIRE:
  33.          if (mhit && !mon->mcan && weapon) {
  34.              if (aatyp == AT_KICK) {
  35.                  if (uarmf && !rn2(6))
  36.                      (void) erode_obj(uarmf, xname(uarmf), ERODE_BURN,
  37.                                       EF_GREASE | EF_VERBOSE);
  38.              } else if (aatyp == AT_WEAP || aatyp == AT_CLAW
  39.                         || aatyp == AT_MAGC || aatyp == AT_TUCH)
  40.                  passive_obj(mon, weapon, &(ptr->mattk[i]));
  41.          }
  42.          break;
  43.      case AD_ACID:
  44.          if (mhit && rn2(2)) {
  45.              if (Blind || !flags.verbose)
  46.                  You("are splashed!");
  47.              else
  48.                  You("are splashed by %s %s!", s_suffix(mon_nam(mon)),
  49.                      hliquid("acid"));
  50.  
  51.              if (!Acid_resistance)
  52.                  mdamageu(mon, tmp);
  53.              if (!rn2(30))
  54.                  erode_armor(&youmonst, ERODE_CORRODE);
  55.          }
  56.          if (mhit && weapon) {
  57.              if (aatyp == AT_KICK) {
  58.                  if (uarmf && !rn2(6))
  59.                      (void) erode_obj(uarmf, xname(uarmf), ERODE_CORRODE,
  60.                                       EF_GREASE | EF_VERBOSE);
  61.              } else if (aatyp == AT_WEAP || aatyp == AT_CLAW
  62.                         || aatyp == AT_MAGC || aatyp == AT_TUCH)
  63.                  passive_obj(mon, weapon, &(ptr->mattk[i]));
  64.          }
  65.          exercise(A_STR, FALSE);
  66.          break;
  67.      case AD_STON:
  68.          if (mhit) { /* successful attack */
  69.              long protector = attk_protection((int) aatyp);
  70.  
  71.              /* hero using monsters' AT_MAGC attack is hitting hand to
  72.                 hand rather than casting a spell */
  73.              if (aatyp == AT_MAGC)
  74.                  protector = W_ARMG;
  75.  
  76.              if (protector == 0L /* no protection */
  77.                  || (protector == W_ARMG && !uarmg
  78.                      && !uwep && !wep_was_destroyed)
  79.                  || (protector == W_ARMF && !uarmf)
  80.                  || (protector == W_ARMH && !uarmh)
  81.                  || (protector == (W_ARMC | W_ARMG) && (!uarmc || !uarmg))) {
  82.                  if (!Stone_resistance
  83.                      && !(poly_when_stoned(youmonst.data)
  84.                           && polymon(PM_STONE_GOLEM))) {
  85.                      done_in_by(mon, STONING); /* "You turn to stone..." */
  86.                      return 2;
  87.                  }
  88.              }
  89.          }
  90.          break;
  91.      case AD_RUST:
  92.          if (mhit && !mon->mcan && weapon) {
  93.              if (aatyp == AT_KICK) {
  94.                  if (uarmf)
  95.                      (void) erode_obj(uarmf, xname(uarmf), ERODE_RUST,
  96.                                       EF_GREASE | EF_VERBOSE);
  97.              } else if (aatyp == AT_WEAP || aatyp == AT_CLAW
  98.                         || aatyp == AT_MAGC || aatyp == AT_TUCH)
  99.                  passive_obj(mon, weapon, &(ptr->mattk[i]));
  100.          }
  101.          break;
  102.      case AD_CORR:
  103.          if (mhit && !mon->mcan && weapon) {
  104.              if (aatyp == AT_KICK) {
  105.                  if (uarmf)
  106.                      (void) erode_obj(uarmf, xname(uarmf), ERODE_CORRODE,
  107.                                       EF_GREASE | EF_VERBOSE);
  108.              } else if (aatyp == AT_WEAP || aatyp == AT_CLAW
  109.                         || aatyp == AT_MAGC || aatyp == AT_TUCH)
  110.                  passive_obj(mon, weapon, &(ptr->mattk[i]));
  111.          }
  112.          break;
  113.      case AD_MAGM:
  114.          /* wrath of gods for attacking Oracle */
  115.          if (Antimagic) {
  116.              shieldeff(u.ux, u.uy);
  117.              pline("A hail of magic missiles narrowly misses you!");
  118.          } else {
  119.              You("are hit by magic missiles appearing from thin air!");
  120.              mdamageu(mon, tmp);
  121.          }
  122.          break;
  123.      case AD_ENCH: /* KMH -- remove enchantment (disenchanter) */
  124.          if (mhit) {
  125.              if (aatyp == AT_KICK) {
  126.                  if (!weapon)
  127.                      break;
  128.              } else if (aatyp == AT_BITE || aatyp == AT_BUTT
  129.                         || (aatyp >= AT_STNG && aatyp < AT_WEAP)) {
  130.                  break; /* no object involved */
  131.              }
  132.              passive_obj(mon, weapon, &(ptr->mattk[i]));
  133.          }
  134.          break;
  135.      default:
  136.          break;
  137.      }
  138.  
  139.      /*  These only affect you if they still live.
  140.       */
  141.      if (malive && !mon->mcan && rn2(3)) {
  142.          switch (ptr->mattk[i].adtyp) {
  143.          case AD_PLYS:
  144.              if (ptr == &mons[PM_FLOATING_EYE]) {
  145.                  if (!canseemon(mon)) {
  146.                      break;
  147.                  }
  148.                  if (mon->mcansee) {
  149.                      if (ureflects("%s gaze is reflected by your %s.",
  150.                                    s_suffix(Monnam(mon)))) {
  151.                          ;
  152.                      } else if (Free_action) {
  153.                          You("momentarily stiffen under %s gaze!",
  154.                              s_suffix(mon_nam(mon)));
  155.                      } else if (Hallucination && rn2(4)) {
  156.                          pline("%s looks %s%s.", Monnam(mon),
  157.                                !rn2(2) ? "" : "rather ",
  158.                                !rn2(2) ? "numb" : "stupified");
  159.                      } else {
  160.                          You("are frozen by %s gaze!", s_suffix(mon_nam(mon)));
  161.                          nomul((ACURR(A_WIS) > 12 || rn2(4)) ? -tmp : -127);
  162.                          multi_reason = "frozen by a monster's gaze";
  163.                          nomovemsg = 0;
  164.                      }
  165.                  } else {
  166.                      pline("%s cannot defend itself.",
  167.                            Adjmonnam(mon, "blind"));
  168.                      if (!rn2(500))
  169.                          change_luck(-1);
  170.                  }
  171.              } else if (Free_action) {
  172.                  You("momentarily stiffen.");
  173.              } else { /* gelatinous cube */
  174.                  You("are frozen by %s!", mon_nam(mon));
  175.                  nomovemsg = You_can_move_again;
  176.                  nomul(-tmp);
  177.                  multi_reason = "frozen by a monster";
  178.                  exercise(A_DEX, FALSE);
  179.              }
  180.              break;
  181.          case AD_COLD: /* brown mold or blue jelly */
  182.              if (monnear(mon, u.ux, u.uy)) {
  183.                  if (Cold_resistance) {
  184.                      shieldeff(u.ux, u.uy);
  185.                      You_feel("a mild chill.");
  186.                      ugolemeffects(AD_COLD, tmp);
  187.                      break;
  188.                  }
  189.                  You("are suddenly very cold!");
  190.                  mdamageu(mon, tmp);
  191.                  /* monster gets stronger with your heat! */
  192.                  mon->mhp += tmp / 2;
  193.                  if (mon->mhpmax < mon->mhp)
  194.                      mon->mhpmax = mon->mhp;
  195.                  /* at a certain point, the monster will reproduce! */
  196.                  if (mon->mhpmax > ((int) (mon->m_lev + 1) * 8))
  197.                      (void) split_mon(mon, &youmonst);
  198.              }
  199.              break;
  200.          case AD_STUN: /* specifically yellow mold */
  201.              if (!Stunned)
  202.                  make_stunned((long) tmp, TRUE);
  203.              break;
  204.          case AD_FIRE:
  205.              if (monnear(mon, u.ux, u.uy)) {
  206.                  if (Fire_resistance) {
  207.                      shieldeff(u.ux, u.uy);
  208.                      You_feel("mildly warm.");
  209.                      ugolemeffects(AD_FIRE, tmp);
  210.                      break;
  211.                  }
  212.                  You("are suddenly very hot!");
  213.                  mdamageu(mon, tmp); /* fire damage */
  214.              }
  215.              break;
  216.          case AD_ELEC:
  217.              if (Shock_resistance) {
  218.                  shieldeff(u.ux, u.uy);
  219.                  You_feel("a mild tingle.");
  220.                  ugolemeffects(AD_ELEC, tmp);
  221.                  break;
  222.              }
  223.              You("are jolted with electricity!");
  224.              mdamageu(mon, tmp);
  225.              break;
  226.          default:
  227.              break;
  228.          }
  229.      }
  230.      return (malive | mhit);
  231.  }
  232.  

passive_obj

  1.  /*
  2.   * Special (passive) attacks on an attacking object by monsters done here.
  3.   * Assumes the attack was successful.
  4.   */
  5.  void
  6.  passive_obj(mon, obj, mattk)
  7.  struct monst *mon;
  8.  struct obj *obj;          /* null means pick uwep, uswapwep or uarmg */
  9.  struct attack *mattk;     /* null means we find one internally */
  10.  {
  11.      struct permonst *ptr = mon->data;
  12.      int i;
  13.  
  14.      /* [this first bit is obsolete; we're not called with Null anymore] */
  15.      /* if caller hasn't specified an object, use uwep, uswapwep or uarmg */
  16.      if (!obj) {
  17.          obj = (u.twoweap && uswapwep && !rn2(2)) ? uswapwep : uwep;
  18.          if (!obj && mattk->adtyp == AD_ENCH)
  19.              obj = uarmg; /* no weapon? then must be gloves */
  20.          if (!obj)
  21.              return; /* no object to affect */
  22.      }
  23.  
  24.      /* if caller hasn't specified an attack, find one */
  25.      if (!mattk) {
  26.          for (i = 0;; i++) {
  27.              if (i >= NATTK)
  28.                  return; /* no passive attacks */
  29.              if (ptr->mattk[i].aatyp == AT_NONE)
  30.                  break; /* try this one */
  31.          }
  32.          mattk = &(ptr->mattk[i]);
  33.      }
  34.  
  35.      switch (mattk->adtyp) {
  36.      case AD_FIRE:
  37.          if (!rn2(6) && !mon->mcan
  38.              /* steam vortex: fire resist applies, fire damage doesn't */
  39.              && mon->data != &mons[PM_STEAM_VORTEX]) {
  40.              (void) erode_obj(obj, NULL, ERODE_BURN, EF_NONE);
  41.          }
  42.          break;
  43.      case AD_ACID:
  44.          if (!rn2(6)) {
  45.              (void) erode_obj(obj, NULL, ERODE_CORRODE, EF_GREASE);
  46.          }
  47.          break;
  48.      case AD_RUST:
  49.          if (!mon->mcan) {
  50.              (void) erode_obj(obj, (char *) 0, ERODE_RUST, EF_GREASE);
  51.          }
  52.          break;
  53.      case AD_CORR:
  54.          if (!mon->mcan) {
  55.              (void) erode_obj(obj, (char *) 0, ERODE_CORRODE, EF_GREASE);
  56.          }
  57.          break;
  58.      case AD_ENCH:
  59.          if (!mon->mcan) {
  60.              if (drain_item(obj, TRUE) && carried(obj)
  61.                  && (obj->known || obj->oclass == ARMOR_CLASS)) {
  62.                  pline("%s less effective.", Yobjnam2(obj, "seem"));
  63.              }
  64.              break;
  65.          }
  66.      default:
  67.          break;
  68.      }
  69.  
  70.      if (carried(obj))
  71.          update_inventory();
  72.  }
  73.  

stumble_onto_mimic

  1.  /* Note: caller must ascertain mtmp is mimicking... */
  2.  void
  3.  stumble_onto_mimic(mtmp)
  4.  struct monst *mtmp;
  5.  {
  6.      const char *fmt = "Wait!  That's %s!", *generic = "a monster", *what = 0;
  7.  
  8.      if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK))
  9.          u.ustuck = mtmp;
  10.  
  11.      if (Blind) {
  12.          if (!Blind_telepat)
  13.              what = generic; /* with default fmt */
  14.          else if (mtmp->m_ap_type == M_AP_MONSTER)
  15.              what = a_monnam(mtmp); /* differs from what was sensed */
  16.      } else {
  17.          int glyph = levl[u.ux + u.dx][u.uy + u.dy].glyph;
  18.  
  19.          if (glyph_is_cmap(glyph) && (glyph_to_cmap(glyph) == S_hcdoor
  20.                                       || glyph_to_cmap(glyph) == S_vcdoor))
  21.              fmt = "The door actually was %s!";
  22.          else if (glyph_is_object(glyph) && glyph_to_obj(glyph) == GOLD_PIECE)
  23.              fmt = "That gold was %s!";
  24.  
  25.          /* cloned Wiz starts out mimicking some other monster and
  26.             might make himself invisible before being revealed */
  27.          if (mtmp->minvis && !See_invisible)
  28.              what = generic;
  29.          else
  30.              what = a_monnam(mtmp);
  31.      }
  32.      if (what)
  33.          pline(fmt, what);
  34.  
  35.      wakeup(mtmp, FALSE); /* clears mimicking */
  36.      /* if hero is blind, wakeup() won't display the monster even though
  37.         it's no longer concealed */
  38.      if (!canspotmon(mtmp)
  39.          && !glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph))
  40.          map_invisible(mtmp->mx, mtmp->my);
  41.  }
  42.  

nohandglow

  1.  STATIC_OVL void
  2.  nohandglow(mon)
  3.  struct monst *mon;
  4.  {
  5.      char *hands = makeplural(body_part(HAND));
  6.  
  7.      if (!u.umconf || mon->mconf)
  8.          return;
  9.      if (u.umconf == 1) {
  10.          if (Blind)
  11.              Your("%s stop tingling.", hands);
  12.          else
  13.              Your("%s stop glowing %s.", hands, hcolor(NH_RED));
  14.      } else {
  15.          if (Blind)
  16.              pline_The("tingling in your %s lessens.", hands);
  17.          else
  18.              Your("%s no longer glow so brightly %s.", hands, hcolor(NH_RED));
  19.      }
  20.      u.umconf--;
  21.  }
  22.  

flash_hits_mon

  1.  int
  2.  flash_hits_mon(mtmp, otmp)
  3.  struct monst *mtmp;
  4.  struct obj *otmp; /* source of flash */
  5.  {
  6.      int tmp, amt, res = 0, useeit = canseemon(mtmp);
  7.  
  8.      if (mtmp->msleeping) {
  9.          mtmp->msleeping = 0;
  10.          if (useeit) {
  11.              pline_The("flash awakens %s.", mon_nam(mtmp));
  12.              res = 1;
  13.          }
  14.      } else if (mtmp->data->mlet != S_LIGHT) {
  15.          if (!resists_blnd(mtmp)) {
  16.              tmp = dist2(otmp->ox, otmp->oy, mtmp->mx, mtmp->my);
  17.              if (useeit) {
  18.                  pline("%s is blinded by the flash!", Monnam(mtmp));
  19.                  res = 1;
  20.              }
  21.              if (mtmp->data == &mons[PM_GREMLIN]) {
  22.                  /* Rule #1: Keep them out of the light. */
  23.                  amt = otmp->otyp == WAN_LIGHT ? d(1 + otmp->spe, 4)
  24.                                                : rn2(min(mtmp->mhp, 4));
  25.                  light_hits_gremlin(mtmp, amt);
  26.              }
  27.              if (mtmp->mhp > 0) {
  28.                  if (!context.mon_moving)
  29.                      setmangry(mtmp, TRUE);
  30.                  if (tmp < 9 && !mtmp->isshk && rn2(4))
  31.                      monflee(mtmp, rn2(4) ? rnd(100) : 0, FALSE, TRUE);
  32.                  mtmp->mcansee = 0;
  33.                  mtmp->mblinded = (tmp < 3) ? 0 : rnd(1 + 50 / tmp);
  34.              }
  35.          }
  36.      }
  37.      return res;
  38.  }
  39.  

light_hits_gremlin

  1.  void
  2.  light_hits_gremlin(mon, dmg)
  3.  struct monst *mon;
  4.  int dmg;
  5.  {
  6.      pline("%s %s!", Monnam(mon),
  7.            (dmg > mon->mhp / 2) ? "wails in agony" : "cries out in pain");
  8.      mon->mhp -= dmg;
  9.      wake_nearto(mon->mx, mon->my, 30);
  10.      if (mon->mhp <= 0) {
  11.          if (context.mon_moving)
  12.              monkilled(mon, (char *) 0, AD_BLND);
  13.          else
  14.              killed(mon);
  15.      } else if (cansee(mon->mx, mon->my) && !canspotmon(mon)) {
  16.          map_invisible(mon->mx, mon->my);
  17.      }
  18.  }
  19.  
  20.  /*uhitm.c*/