Source:NetHack 3.6.0/src/uhitm.c

From NetHackWiki
Jump to: navigation, search

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

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

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

Top of file

  1.  /* NetHack 3.6	uhitm.c	$NHDT-Date: 1446887537 2015/11/07 09:12:17 $  $NHDT-Branch: master $:$NHDT-Revision: 1.151 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5.  #include "hack.h"
  6.  
  7.  STATIC_DCL boolean FDECL(known_hitum, (struct monst *, struct obj *, int *,
  8.                                         int, int, struct attack *));
  9.  STATIC_DCL boolean FDECL(theft_petrifies, (struct obj *));
  10.  STATIC_DCL void FDECL(steal_it, (struct monst *, struct attack *));
  11.  STATIC_DCL boolean FDECL(hitum, (struct monst *, struct attack *));
  12.  STATIC_DCL boolean FDECL(hmon_hitmon, (struct monst *, struct obj *, int));
  13.  STATIC_DCL int FDECL(joust, (struct monst *, struct obj *));
  14.  STATIC_DCL void NDECL(demonpet);
  15.  STATIC_DCL boolean FDECL(m_slips_free, (struct monst * mtmp,
  16.                                          struct attack *mattk));
  17.  STATIC_DCL int FDECL(explum, (struct monst *, struct attack *));
  18.  STATIC_DCL void FDECL(start_engulf, (struct monst *));
  19.  STATIC_DCL void NDECL(end_engulf);
  20.  STATIC_DCL int FDECL(gulpum, (struct monst *, struct attack *));
  21.  STATIC_DCL boolean FDECL(hmonas, (struct monst *));
  22.  STATIC_DCL void FDECL(nohandglow, (struct monst *));
  23.  STATIC_DCL boolean FDECL(shade_aware, (struct obj *));
  24.  
  25.  extern boolean notonhead; /* for long worms */
  26.  /* The below might become a parameter instead if we use it a lot */
  27.  static int dieroll;
  28.  /* Used to flag attacks caused by Stormbringer's maliciousness. */
  29.  static boolean override_confirmation = FALSE;
  30.  
  31.  #define PROJECTILE(obj) ((obj) && is_ammo(obj))
  32.  

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); /* 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);
  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.                  return TRUE;
  47.              } else if ((mtmp->mfrozen || (!mtmp->mcanmove)
  48.                          || (mtmp->data->mmove == 0)) && rn2(6)) {
  49.                  pline("%s doesn't seem to move!", Monnam(mtmp));
  50.                  return TRUE;
  51.              } else
  52.                  return FALSE;
  53.          }
  54.      }
  55.  
  56.      /* possibly set in attack_checks;
  57.         examined in known_hitum, called via hitum or hmonas below */
  58.      override_confirmation = FALSE;
  59.      /* attack_checks() used to use <u.ux+u.dx,u.uy+u.dy> directly, now
  60.         it uses bhitpos instead; it might map an invisible monster there */
  61.      bhitpos.x = u.ux + u.dx;
  62.      bhitpos.y = u.uy + u.dy;
  63.      if (attack_checks(mtmp, uwep))
  64.          return TRUE;
  65.  
  66.      if (Upolyd && noattacks(youmonst.data)) {
  67.          /* certain "pacifist" monsters don't attack */
  68.          You("have no way to attack monsters physically.");
  69.          mtmp->mstrategy &= ~STRAT_WAITMASK;
  70.          goto atk_done;
  71.      }
  72.  
  73.      if (check_capacity("You cannot fight while so heavily loaded.")
  74.          /* consume extra nutrition during combat; maybe pass out */
  75.          || overexertion())
  76.          goto atk_done;
  77.  
  78.      if (u.twoweap && !can_twoweapon())
  79.          untwoweapon();
  80.  
  81.      if (unweapon) {
  82.          unweapon = FALSE;
  83.          if (flags.verbose) {
  84.              if (uwep)
  85.                  You("begin bashing monsters with %s.",
  86.                      yobjnam(uwep, (char *) 0));
  87.              else if (!cantwield(youmonst.data))
  88.                  You("begin %sing monsters with your %s %s.",
  89.                      Role_if(PM_MONK) ? "strik" : "bash",
  90.                      uarmg ? "gloved" : "bare", /* Del Lamb */
  91.                      makeplural(body_part(HAND)));
  92.          }
  93.      }
  94.      exercise(A_STR, TRUE); /* you're exercising muscles */
  95.      /* andrew@orca: prevent unlimited pick-axe attacks */
  96.      u_wipe_engr(3);
  97.  
  98.      /* Is the "it died" check actually correct? */
  99.      if (mdat->mlet == S_LEPRECHAUN && !mtmp->mfrozen && !mtmp->msleeping
  100.          && !mtmp->mconf && mtmp->mcansee && !rn2(7)
  101.          && (m_move(mtmp, 0) == 2 /* it died */
  102.              || mtmp->mx != u.ux + u.dx
  103.              || mtmp->my != u.uy + u.dy)) /* it moved */
  104.          return FALSE;
  105.  
  106.      if (Upolyd)
  107.          (void) hmonas(mtmp);
  108.      else
  109.          (void) hitum(mtmp, youmonst.data->mattk);
  110.      mtmp->mstrategy &= ~STRAT_WAITMASK;
  111.  
  112.  atk_done:
  113.      /* see comment in attack_checks() */
  114.      /* we only need to check for this if we did an attack_checks()
  115.       * and it returned 0 (it's okay to attack), and the monster didn't
  116.       * evade.
  117.       */
  118.      if (context.forcefight && mtmp->mhp > 0 && !canspotmon(mtmp)
  119.          && !glyph_is_invisible(levl[u.ux + u.dx][u.uy + u.dy].glyph)
  120.          && !(u.uswallow && mtmp == u.ustuck))
  121.          map_invisible(u.ux + u.dx, u.uy + u.dy);
  122.  
  123.      return TRUE;
  124.  }
  125.  

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

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 mhit = (tmp > (dieroll = rnd(20)) || u.uswallow);
  13.  
  14.      if (tmp > dieroll)
  15.          exercise(A_DEX, TRUE);
  16.      malive = known_hitum(mon, uwep, &mhit, tmp, armorpenalty, uattk);
  17.      /* second attack for two-weapon combat; won't occur if Stormbringer
  18.         overrode confirmation (assumes Stormbringer is primary weapon)
  19.         or if the monster was killed or knocked to different location */
  20.      if (u.twoweap && !override_confirmation && malive && m_at(x, y) == mon) {
  21.          tmp = find_roll_to_hit(mon, uattk->aatyp, uswapwep, &attknum,
  22.                                 &armorpenalty);
  23.          mhit = (tmp > (dieroll = rnd(20)) || u.uswallow);
  24.          malive = known_hitum(mon, uswapwep, &mhit, tmp, armorpenalty, uattk);
  25.      }
  26.      if (wepbefore && !uwep)
  27.          wep_was_destroyed = TRUE;
  28.      (void) passive(mon, mhit, malive, AT_WEAP, wep_was_destroyed);
  29.      return malive;
  30.  }
  31.  

hmon

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

hmon_hitmon

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

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

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.          /* engulfing a cockatrice or digesting a Rider or Medusa */
  33.          fatal_gulp = (touch_petrifies(pd) && !Stone_resistance)
  34.                       || (mattk->adtyp == AD_DGST
  35.                           && (is_rider(pd) || (pd == &mons[PM_MEDUSA]
  36.                                                && !Stone_resistance)));
  37.  
  38.          if ((mattk->adtyp == AD_DGST && !Slow_digestion) || fatal_gulp)
  39.              eating_conducts(pd);
  40.  
  41.          if (fatal_gulp && !is_rider(pd)) { /* petrification */
  42.              char kbuf[BUFSZ];
  43.              const char *mname = pd->mname;
  44.  
  45.              if (!type_is_pname(pd))
  46.                  mname = an(mname);
  47.              You("englut %s.", mon_nam(mdef));
  48.              Sprintf(kbuf, "swallowing %s whole", mname);
  49.              instapetrify(kbuf);
  50.          } else {
  51.              start_engulf(mdef);
  52.              switch (mattk->adtyp) {
  53.              case AD_DGST:
  54.                  /* eating a Rider or its corpse is fatal */
  55.                  if (is_rider(pd)) {
  56.                      pline("Unfortunately, digesting any of it is fatal.");
  57.                      end_engulf();
  58.                      Sprintf(killer.name, "unwisely tried to eat %s",
  59.                              pd->mname);
  60.                      killer.format = NO_KILLER_PREFIX;
  61.                      done(DIED);
  62.                      return 0; /* lifesaved */
  63.                  }
  64.  
  65.                  if (Slow_digestion) {
  66.                      dam = 0;
  67.                      break;
  68.                  }
  69.  
  70.                  /* Use up amulet of life saving */
  71.                  if (!!(otmp = mlifesaver(mdef)))
  72.                      m_useup(mdef, otmp);
  73.  
  74.                  newuhs(FALSE);
  75.                  xkilled(mdef, 2);
  76.                  if (mdef->mhp > 0) { /* monster lifesaved */
  77.                      You("hurriedly regurgitate the sizzling in your %s.",
  78.                          body_part(STOMACH));
  79.                  } else {
  80.                      tmp = 1 + (pd->cwt >> 8);
  81.                      if (corpse_chance(mdef, &youmonst, TRUE)
  82.                          && !(mvitals[monsndx(pd)].mvflags & G_NOCORPSE)) {
  83.                          /* nutrition only if there can be a corpse */
  84.                          u.uhunger += (pd->cnutrit + 1) / 2;
  85.                      } else
  86.                          tmp = 0;
  87.                      Sprintf(msgbuf, "You totally digest %s.", mon_nam(mdef));
  88.                      if (tmp != 0) {
  89.                          /* setting afternmv = end_engulf is tempting,
  90.                           * but will cause problems if the player is
  91.                           * attacked (which uses his real location) or
  92.                           * if his See_invisible wears off
  93.                           */
  94.                          You("digest %s.", mon_nam(mdef));
  95.                          if (Slow_digestion)
  96.                              tmp *= 2;
  97.                          nomul(-tmp);
  98.                          multi_reason = "digesting something";
  99.                          nomovemsg = msgbuf;
  100.                      } else
  101.                          pline1(msgbuf);
  102.                      if (pd == &mons[PM_GREEN_SLIME]) {
  103.                          Sprintf(msgbuf, "%s isn't sitting well with you.",
  104.                                  The(pd->mname));
  105.                          if (!Unchanging) {
  106.                              make_slimed(5L, (char *) 0);
  107.                          }
  108.                      } else
  109.                          exercise(A_CON, TRUE);
  110.                  }
  111.                  end_engulf();
  112.                  return 2;
  113.              case AD_PHYS:
  114.                  if (youmonst.data == &mons[PM_FOG_CLOUD]) {
  115.                      pline("%s is laden with your moisture.", Monnam(mdef));
  116.                      if (amphibious(pd) && !flaming(pd)) {
  117.                          dam = 0;
  118.                          pline("%s seems unharmed.", Monnam(mdef));
  119.                      }
  120.                  } else
  121.                      pline("%s is pummeled with your debris!", Monnam(mdef));
  122.                  break;
  123.              case AD_ACID:
  124.                  pline("%s is covered with your goo!", Monnam(mdef));
  125.                  if (resists_acid(mdef)) {
  126.                      pline("It seems harmless to %s.", mon_nam(mdef));
  127.                      dam = 0;
  128.                  }
  129.                  break;
  130.              case AD_BLND:
  131.                  if (can_blnd(&youmonst, mdef, mattk->aatyp,
  132.                               (struct obj *) 0)) {
  133.                      if (mdef->mcansee)
  134.                          pline("%s can't see in there!", Monnam(mdef));
  135.                      mdef->mcansee = 0;
  136.                      dam += mdef->mblinded;
  137.                      if (dam > 127)
  138.                          dam = 127;
  139.                      mdef->mblinded = dam;
  140.                  }
  141.                  dam = 0;
  142.                  break;
  143.              case AD_ELEC:
  144.                  if (rn2(2)) {
  145.                      pline_The("air around %s crackles with electricity.",
  146.                                mon_nam(mdef));
  147.                      if (resists_elec(mdef)) {
  148.                          pline("%s seems unhurt.", Monnam(mdef));
  149.                          dam = 0;
  150.                      }
  151.                      golemeffects(mdef, (int) mattk->adtyp, dam);
  152.                  } else
  153.                      dam = 0;
  154.                  break;
  155.              case AD_COLD:
  156.                  if (rn2(2)) {
  157.                      if (resists_cold(mdef)) {
  158.                          pline("%s seems mildly chilly.", Monnam(mdef));
  159.                          dam = 0;
  160.                      } else
  161.                          pline("%s is freezing to death!", Monnam(mdef));
  162.                      golemeffects(mdef, (int) mattk->adtyp, dam);
  163.                  } else
  164.                      dam = 0;
  165.                  break;
  166.              case AD_FIRE:
  167.                  if (rn2(2)) {
  168.                      if (resists_fire(mdef)) {
  169.                          pline("%s seems mildly hot.", Monnam(mdef));
  170.                          dam = 0;
  171.                      } else
  172.                          pline("%s is burning to a crisp!", Monnam(mdef));
  173.                      golemeffects(mdef, (int) mattk->adtyp, dam);
  174.                  } else
  175.                      dam = 0;
  176.                  break;
  177.              case AD_DREN:
  178.                  if (!rn2(4))
  179.                      xdrainenergym(mdef, TRUE);
  180.                  dam = 0;
  181.                  break;
  182.              }
  183.              end_engulf();
  184.              if ((mdef->mhp -= dam) <= 0) {
  185.                  killed(mdef);
  186.                  if (mdef->mhp <= 0) /* not lifesaved */
  187.                      return 2;
  188.              }
  189.              You("%s %s!", is_animal(youmonst.data) ? "regurgitate" : "expel",
  190.                  mon_nam(mdef));
  191.              if (Slow_digestion || is_animal(youmonst.data)) {
  192.                  pline("Obviously, you didn't like %s taste.",
  193.                        s_suffix(mon_nam(mdef)));
  194.              }
  195.          }
  196.      }
  197.      return 0;
  198.  }
  199.  

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

passive

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

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.  register struct monst *mon;
  8.  register 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.      register int i;
  13.  
  14.      /* if caller hasn't specified an object, use uwep, uswapwep or uarmg */
  15.      if (!obj) {
  16.          obj = (u.twoweap && uswapwep && !rn2(2)) ? uswapwep : uwep;
  17.          if (!obj && mattk->adtyp == AD_ENCH)
  18.              obj = uarmg; /* no weapon? then must be gloves */
  19.          if (!obj)
  20.              return; /* no object to affect */
  21.      }
  22.  
  23.      /* if caller hasn't specified an attack, find one */
  24.      if (!mattk) {
  25.          for (i = 0;; i++) {
  26.              if (i >= NATTK)
  27.                  return; /* no passive attacks */
  28.              if (ptr->mattk[i].aatyp == AT_NONE)
  29.                  break; /* try this one */
  30.          }
  31.          mattk = &(ptr->mattk[i]);
  32.      }
  33.  
  34.      switch (mattk->adtyp) {
  35.      case AD_FIRE:
  36.          if (!rn2(6) && !mon->mcan) {
  37.              (void) erode_obj(obj, NULL, ERODE_BURN, EF_NONE);
  38.          }
  39.          break;
  40.      case AD_ACID:
  41.          if (!rn2(6)) {
  42.              (void) erode_obj(obj, NULL, ERODE_CORRODE, EF_NONE);
  43.          }
  44.          break;
  45.      case AD_RUST:
  46.          if (!mon->mcan) {
  47.              (void) erode_obj(obj, NULL, ERODE_RUST, EF_NONE);
  48.          }
  49.          break;
  50.      case AD_CORR:
  51.          if (!mon->mcan) {
  52.              (void) erode_obj(obj, NULL, ERODE_CORRODE, EF_NONE);
  53.          }
  54.          break;
  55.      case AD_ENCH:
  56.          if (!mon->mcan) {
  57.              if (drain_item(obj) && carried(obj)
  58.                  && (obj->known || obj->oclass == ARMOR_CLASS)) {
  59.                  pline("%s less effective.", Yobjnam2(obj, "seem"));
  60.              }
  61.              break;
  62.          }
  63.      default:
  64.          break;
  65.      }
  66.  
  67.      if (carried(obj))
  68.          update_inventory();
  69.  }
  70.  

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); /* 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);
  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.      if ((mon->mhp -= dmg) <= 0) {
  9.          if (context.mon_moving)
  10.              monkilled(mon, (char *) 0, AD_BLND);
  11.          else
  12.              killed(mon);
  13.      } else if (cansee(mon->mx, mon->my) && !canspotmon(mon)) {
  14.          map_invisible(mon->mx, mon->my);
  15.      }
  16.  }
  17.  
  18.  /*uhitm.c*/