Source:NetHack 3.6.1/src/mon.c

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

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

Top of file

  1.  /* NetHack 3.6	mon.c	$NHDT-Date: 1522540516 2018/03/31 23:55:16 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.250 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /*-Copyright (c) Derek S. Ray, 2015. */
  4.  /* NetHack may be freely redistributed.  See license for details. */

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

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

  1.  
  2.  /* If you're using precompiled headers, you don't want this either */
  3.  #ifdef MICROPORT_BUG
  4.  #define MKROOM_H
  5.  #endif
  6.  
  7.  #include "hack.h"
  8.  #include "mfndpos.h"
  9.  #include <ctype.h>
  10.  
  11.  STATIC_VAR boolean vamp_rise_msg, disintegested;
  12.  
  13.  STATIC_DCL void FDECL(sanity_check_single_mon, (struct monst *, BOOLEAN_P,
  14.                                                  const char *));
  15.  STATIC_DCL boolean FDECL(restrap, (struct monst *));
  16.  STATIC_DCL long FDECL(mm_aggression, (struct monst *, struct monst *));
  17.  STATIC_DCL long FDECL(mm_displacement, (struct monst *, struct monst *));
  18.  STATIC_DCL int NDECL(pick_animal);
  19.  STATIC_DCL void FDECL(kill_eggs, (struct obj *));
  20.  STATIC_DCL int FDECL(pickvampshape, (struct monst *));
  21.  STATIC_DCL boolean FDECL(isspecmon, (struct monst *));
  22.  STATIC_DCL boolean FDECL(validspecmon, (struct monst *, int));
  23.  STATIC_DCL struct permonst *FDECL(accept_newcham_form, (int));
  24.  STATIC_DCL struct obj *FDECL(make_corpse, (struct monst *, unsigned));
  25.  STATIC_DCL void FDECL(m_detach, (struct monst *, struct permonst *));
  26.  STATIC_DCL void FDECL(lifesaved_monster, (struct monst *));
  27.  
  28.  #define LEVEL_SPECIFIC_NOCORPSE(mdat) \
  29.      (Is_rogue_level(&u.uz)            \
  30.       || (level.flags.graveyard && is_undead(mdat) && rn2(3)))
  31.  
  32.  #if 0
  33.  /* part of the original warning code which was replaced in 3.3.1 */
  34.  const char *warnings[] = {
  35.      "white", "pink", "red", "ruby", "purple", "black"
  36.  };
  37.  #endif /* 0 */
  38.  
  39.  

sanity_check_single_mon

  1.  void
  2.  sanity_check_single_mon(mtmp, chk_geno, msg)
  3.  struct monst *mtmp;
  4.  boolean chk_geno;
  5.  const char *msg;
  6.  {
  7.      if (DEADMONSTER(mtmp))
  8.          return;
  9.      if (mtmp->data < &mons[LOW_PM] || mtmp->data >= &mons[NUMMONS]) {
  10.          impossible("illegal mon data %s; mnum=%d (%s)",
  11.                     fmt_ptr((genericptr_t) mtmp->data), mtmp->mnum, msg);
  12.      } else {
  13.          int mndx = monsndx(mtmp->data);
  14.  
  15.          if (mtmp->mnum != mndx) {
  16.              impossible("monster mnum=%d, monsndx=%d (%s)",
  17.                         mtmp->mnum, mndx, msg);
  18.              mtmp->mnum = mndx;
  19.          }
  20.          if (chk_geno && (mvitals[mndx].mvflags & G_GENOD) != 0)
  21.              impossible("genocided %s in play (%s)", mons[mndx].mname, msg);
  22.      }
  23.      if (mtmp->isshk && !has_eshk(mtmp))
  24.          impossible("shk without eshk (%s)", msg);
  25.      if (mtmp->ispriest && !has_epri(mtmp))
  26.          impossible("priest without epri (%s)", msg);
  27.      if (mtmp->isgd && !has_egd(mtmp))
  28.          impossible("guard without egd (%s)", msg);
  29.      if (mtmp->isminion && !has_emin(mtmp))
  30.          impossible("minion without emin (%s)", msg);
  31.      /* guardian angel on astral level is tame but has emin rather than edog */
  32.      if (mtmp->mtame && !has_edog(mtmp) && !mtmp->isminion)
  33.          impossible("pet without edog (%s)", msg);
  34.  }
  35.  

mon_sanity_check

  1.  void
  2.  mon_sanity_check()
  3.  {
  4.      int x, y;
  5.      struct monst *mtmp, *m;
  6.  
  7.      for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  8.          sanity_check_single_mon(mtmp, TRUE, "fmon");
  9.          if (DEADMONSTER(mtmp))
  10.              continue;
  11.          x = mtmp->mx, y = mtmp->my;
  12.          if (!isok(x, y) && !(mtmp->isgd && x == 0 && y == 0)) {
  13.              impossible("mon (%s) claims to be at <%d,%d>?",
  14.                         fmt_ptr((genericptr_t) mtmp), x, y);
  15.          } else if (mtmp == u.usteed) {
  16.              /* steed is in fmon list but not on the map; its
  17.                 <mx,my> coordinates should match hero's location */
  18.              if (x != u.ux || y != u.uy)
  19.                  impossible("steed (%s) claims to be at <%d,%d>?",
  20.                             fmt_ptr((genericptr_t) mtmp), x, y);
  21.          } else if (level.monsters[x][y] != mtmp) {
  22.              impossible("mon (%s) at <%d,%d> is not there!",
  23.                         fmt_ptr((genericptr_t) mtmp), x, y);
  24.          } else if (mtmp->wormno) {
  25.              sanity_check_worm(mtmp);
  26.          }
  27.      }
  28.  
  29.      for (x = 0; x < COLNO; x++)
  30.          for (y = 0; y < ROWNO; y++)
  31.              if ((mtmp = level.monsters[x][y]) != 0) {
  32.                  for (m = fmon; m; m = m->nmon)
  33.                      if (m == mtmp)
  34.                          break;
  35.                  if (!m)
  36.                      impossible("map mon (%s) at <%d,%d> not in fmon list!",
  37.                                 fmt_ptr((genericptr_t) mtmp), x, y);
  38.                  else if (mtmp == u.usteed)
  39.                      impossible("steed (%s) is on the map at <%d,%d>!",
  40.                                 fmt_ptr((genericptr_t) mtmp), x, y);
  41.                  else if ((mtmp->mx != x || mtmp->my != y)
  42.                           && mtmp->data != &mons[PM_LONG_WORM])
  43.                      impossible("map mon (%s) at <%d,%d> is found at <%d,%d>?",
  44.                                 fmt_ptr((genericptr_t) mtmp),
  45.                                 mtmp->mx, mtmp->my, x, y);
  46.              }
  47.  
  48.      for (mtmp = migrating_mons; mtmp; mtmp = mtmp->nmon) {
  49.          sanity_check_single_mon(mtmp, FALSE, "migr");
  50.      }
  51.  }
  52.  
  53.  

undead_to_corpse

  1.  /* convert the monster index of an undead to its living counterpart */
  2.  int
  3.  undead_to_corpse(mndx)
  4.  int mndx;
  5.  {
  6.      switch (mndx) {
  7.      case PM_KOBOLD_ZOMBIE:
  8.      case PM_KOBOLD_MUMMY:
  9.          mndx = PM_KOBOLD;
  10.          break;
  11.      case PM_DWARF_ZOMBIE:
  12.      case PM_DWARF_MUMMY:
  13.          mndx = PM_DWARF;
  14.          break;
  15.      case PM_GNOME_ZOMBIE:
  16.      case PM_GNOME_MUMMY:
  17.          mndx = PM_GNOME;
  18.          break;
  19.      case PM_ORC_ZOMBIE:
  20.      case PM_ORC_MUMMY:
  21.          mndx = PM_ORC;
  22.          break;
  23.      case PM_ELF_ZOMBIE:
  24.      case PM_ELF_MUMMY:
  25.          mndx = PM_ELF;
  26.          break;
  27.      case PM_VAMPIRE:
  28.      case PM_VAMPIRE_LORD:
  29.  #if 0 /* DEFERRED */
  30.      case PM_VAMPIRE_MAGE:
  31.  #endif
  32.      case PM_HUMAN_ZOMBIE:
  33.      case PM_HUMAN_MUMMY:
  34.          mndx = PM_HUMAN;
  35.          break;
  36.      case PM_GIANT_ZOMBIE:
  37.      case PM_GIANT_MUMMY:
  38.          mndx = PM_GIANT;
  39.          break;
  40.      case PM_ETTIN_ZOMBIE:
  41.      case PM_ETTIN_MUMMY:
  42.          mndx = PM_ETTIN;
  43.          break;
  44.      default:
  45.          break;
  46.      }
  47.      return mndx;
  48.  }
  49.  

genus

  1.  /* Convert the monster index of some monsters (such as quest guardians)
  2.   * to their generic species type.
  3.   *
  4.   * Return associated character class monster, rather than species
  5.   * if mode is 1.
  6.   */
  7.  int
  8.  genus(mndx, mode)
  9.  int mndx, mode;
  10.  {
  11.      switch (mndx) {
  12.      /* Quest guardians */
  13.      case PM_STUDENT:
  14.          mndx = mode ? PM_ARCHEOLOGIST : PM_HUMAN;
  15.          break;
  16.      case PM_CHIEFTAIN:
  17.          mndx = mode ? PM_BARBARIAN : PM_HUMAN;
  18.          break;
  19.      case PM_NEANDERTHAL:
  20.          mndx = mode ? PM_CAVEMAN : PM_HUMAN;
  21.          break;
  22.      case PM_ATTENDANT:
  23.          mndx = mode ? PM_HEALER : PM_HUMAN;
  24.          break;
  25.      case PM_PAGE:
  26.          mndx = mode ? PM_KNIGHT : PM_HUMAN;
  27.          break;
  28.      case PM_ABBOT:
  29.          mndx = mode ? PM_MONK : PM_HUMAN;
  30.          break;
  31.      case PM_ACOLYTE:
  32.          mndx = mode ? PM_PRIEST : PM_HUMAN;
  33.          break;
  34.      case PM_HUNTER:
  35.          mndx = mode ? PM_RANGER : PM_HUMAN;
  36.          break;
  37.      case PM_THUG:
  38.          mndx = mode ? PM_ROGUE : PM_HUMAN;
  39.          break;
  40.      case PM_ROSHI:
  41.          mndx = mode ? PM_SAMURAI : PM_HUMAN;
  42.          break;
  43.      case PM_GUIDE:
  44.          mndx = mode ? PM_TOURIST : PM_HUMAN;
  45.          break;
  46.      case PM_APPRENTICE:
  47.          mndx = mode ? PM_WIZARD : PM_HUMAN;
  48.          break;
  49.      case PM_WARRIOR:
  50.          mndx = mode ? PM_VALKYRIE : PM_HUMAN;
  51.          break;
  52.      default:
  53.          if (mndx >= LOW_PM && mndx < NUMMONS) {
  54.              struct permonst *ptr = &mons[mndx];
  55.  
  56.              if (is_human(ptr))
  57.                  mndx = PM_HUMAN;
  58.              else if (is_elf(ptr))
  59.                  mndx = PM_ELF;
  60.              else if (is_dwarf(ptr))
  61.                  mndx = PM_DWARF;
  62.              else if (is_gnome(ptr))
  63.                  mndx = PM_GNOME;
  64.              else if (is_orc(ptr))
  65.                  mndx = PM_ORC;
  66.          }
  67.          break;
  68.      }
  69.      return mndx;
  70.  }
  71.  

pm_to_cham

  1.  /* return monster index if chameleon, or NON_PM if not */
  2.  int
  3.  pm_to_cham(mndx)
  4.  int mndx;
  5.  {
  6.      int mcham = NON_PM;
  7.  
  8.      /*
  9.       * As of 3.6.0 we just check M2_SHAPESHIFTER instead of having a
  10.       * big switch statement with hardcoded shapeshifter types here.
  11.       */
  12.      if (mndx >= LOW_PM && is_shapeshifter(&mons[mndx]))
  13.          mcham = mndx;
  14.      return mcham;
  15.  }
  16.  
  17.  /* for deciding whether corpse will carry along full monster data */
  18.  #define KEEPTRAITS(mon)                                                 \
  19.      ((mon)->isshk || (mon)->mtame || unique_corpstat((mon)->data)       \
  20.       || is_reviver((mon)->data)                                         \
  21.          /* normally quest leader will be unique, */                     \
  22.          /* but he or she might have been polymorphed  */                \
  23.       || (mon)->m_id == quest_status.leader_m_id                         \
  24.          /* special cancellation handling for these */                   \
  25.       || (dmgtype((mon)->data, AD_SEDU) || dmgtype((mon)->data, AD_SSEX)))
  26.  

make_corpse

  1.  /* Creates a monster corpse, a "special" corpse, or nothing if it doesn't
  2.   * leave corpses.  Monsters which leave "special" corpses should have
  3.   * G_NOCORPSE set in order to prevent wishing for one, finding tins of one,
  4.   * etc....
  5.   */
  6.  STATIC_OVL struct obj *
  7.  make_corpse(mtmp, corpseflags)
  8.  register struct monst *mtmp;
  9.  unsigned corpseflags;
  10.  {
  11.      register struct permonst *mdat = mtmp->data;
  12.      int num;
  13.      struct obj *obj = (struct obj *) 0;
  14.      struct obj *otmp = (struct obj *) 0;
  15.      int x = mtmp->mx, y = mtmp->my;
  16.      int mndx = monsndx(mdat);
  17.      unsigned corpstatflags = corpseflags;
  18.      boolean burythem = ((corpstatflags & CORPSTAT_BURIED) != 0);
  19.  
  20.      switch (mndx) {
  21.      case PM_GRAY_DRAGON:
  22.      case PM_SILVER_DRAGON:
  23.  #if 0 /* DEFERRED */
  24.      case PM_SHIMMERING_DRAGON:
  25.  #endif
  26.      case PM_RED_DRAGON:
  27.      case PM_ORANGE_DRAGON:
  28.      case PM_WHITE_DRAGON:
  29.      case PM_BLACK_DRAGON:
  30.      case PM_BLUE_DRAGON:
  31.      case PM_GREEN_DRAGON:
  32.      case PM_YELLOW_DRAGON:
  33.          /* Make dragon scales.  This assumes that the order of the
  34.             dragons is the same as the order of the scales. */
  35.          if (!rn2(mtmp->mrevived ? 20 : 3)) {
  36.              num = GRAY_DRAGON_SCALES + monsndx(mdat) - PM_GRAY_DRAGON;
  37.              obj = mksobj_at(num, x, y, FALSE, FALSE);
  38.              obj->spe = 0;
  39.              obj->cursed = obj->blessed = FALSE;
  40.          }
  41.          goto default_1;
  42.      case PM_WHITE_UNICORN:
  43.      case PM_GRAY_UNICORN:
  44.      case PM_BLACK_UNICORN:
  45.          if (mtmp->mrevived && rn2(2)) {
  46.              if (canseemon(mtmp))
  47.                  pline("%s recently regrown horn crumbles to dust.",
  48.                        s_suffix(Monnam(mtmp)));
  49.          } else {
  50.              obj = mksobj_at(UNICORN_HORN, x, y, TRUE, FALSE);
  51.              if (obj && mtmp->mrevived)
  52.                  obj->degraded_horn = 1;
  53.          }
  54.          goto default_1;
  55.      case PM_LONG_WORM:
  56.          (void) mksobj_at(WORM_TOOTH, x, y, TRUE, FALSE);
  57.          goto default_1;
  58.      case PM_VAMPIRE:
  59.      case PM_VAMPIRE_LORD:
  60.          /* include mtmp in the mkcorpstat() call */
  61.          num = undead_to_corpse(mndx);
  62.          corpstatflags |= CORPSTAT_INIT;
  63.          obj = mkcorpstat(CORPSE, mtmp, &mons[num], x, y, corpstatflags);
  64.          obj->age -= 100; /* this is an *OLD* corpse */
  65.          break;
  66.      case PM_KOBOLD_MUMMY:
  67.      case PM_DWARF_MUMMY:
  68.      case PM_GNOME_MUMMY:
  69.      case PM_ORC_MUMMY:
  70.      case PM_ELF_MUMMY:
  71.      case PM_HUMAN_MUMMY:
  72.      case PM_GIANT_MUMMY:
  73.      case PM_ETTIN_MUMMY:
  74.      case PM_KOBOLD_ZOMBIE:
  75.      case PM_DWARF_ZOMBIE:
  76.      case PM_GNOME_ZOMBIE:
  77.      case PM_ORC_ZOMBIE:
  78.      case PM_ELF_ZOMBIE:
  79.      case PM_HUMAN_ZOMBIE:
  80.      case PM_GIANT_ZOMBIE:
  81.      case PM_ETTIN_ZOMBIE:
  82.          num = undead_to_corpse(mndx);
  83.          corpstatflags |= CORPSTAT_INIT;
  84.          obj = mkcorpstat(CORPSE, mtmp, &mons[num], x, y, corpstatflags);
  85.          obj->age -= 100; /* this is an *OLD* corpse */
  86.          break;
  87.      case PM_IRON_GOLEM:
  88.          num = d(2, 6);
  89.          while (num--)
  90.              obj = mksobj_at(IRON_CHAIN, x, y, TRUE, FALSE);
  91.          free_mname(mtmp); /* don't christen obj */
  92.          break;
  93.      case PM_GLASS_GOLEM:
  94.          num = d(2, 4); /* very low chance of creating all glass gems */
  95.          while (num--)
  96.              obj = mksobj_at((LAST_GEM + rnd(9)), x, y, TRUE, FALSE);
  97.          free_mname(mtmp);
  98.          break;
  99.      case PM_CLAY_GOLEM:
  100.          obj = mksobj_at(ROCK, x, y, FALSE, FALSE);
  101.          obj->quan = (long) (rn2(20) + 50);
  102.          obj->owt = weight(obj);
  103.          free_mname(mtmp);
  104.          break;
  105.      case PM_STONE_GOLEM:
  106.          corpstatflags &= ~CORPSTAT_INIT;
  107.          obj =
  108.              mkcorpstat(STATUE, (struct monst *) 0, mdat, x, y, corpstatflags);
  109.          break;
  110.      case PM_WOOD_GOLEM:
  111.          num = d(2, 4);
  112.          while (num--) {
  113.              obj = mksobj_at(QUARTERSTAFF, x, y, TRUE, FALSE);
  114.          }
  115.          free_mname(mtmp);
  116.          break;
  117.      case PM_LEATHER_GOLEM:
  118.          num = d(2, 4);
  119.          while (num--)
  120.              obj = mksobj_at(LEATHER_ARMOR, x, y, TRUE, FALSE);
  121.          free_mname(mtmp);
  122.          break;
  123.      case PM_GOLD_GOLEM:
  124.          /* Good luck gives more coins */
  125.          obj = mkgold((long) (200 - rnl(101)), x, y);
  126.          free_mname(mtmp);
  127.          break;
  128.      case PM_PAPER_GOLEM:
  129.          num = rnd(4);
  130.          while (num--)
  131.              obj = mksobj_at(SCR_BLANK_PAPER, x, y, TRUE, FALSE);
  132.          free_mname(mtmp);
  133.          break;
  134.      /* expired puddings will congeal into a large blob;
  135.         like dragons, relies on the order remaining consistent */
  136.      case PM_GRAY_OOZE:
  137.      case PM_BROWN_PUDDING:
  138.      case PM_GREEN_SLIME:
  139.      case PM_BLACK_PUDDING:
  140.          /* we have to do this here because most other places
  141.             expect there to be an object coming back; not this one */
  142.          obj = mksobj_at(GLOB_OF_BLACK_PUDDING - (PM_BLACK_PUDDING - mndx),
  143.                          x, y, TRUE, FALSE);
  144.  
  145.          while (obj && (otmp = obj_nexto(obj)) != (struct obj *) 0) {
  146.              pudding_merge_message(obj, otmp);
  147.              obj = obj_meld(&obj, &otmp);
  148.          }
  149.          free_mname(mtmp);
  150.          return obj;
  151.      default_1:
  152.      default:
  153.          if (mvitals[mndx].mvflags & G_NOCORPSE) {
  154.              return (struct obj *) 0;
  155.          } else {
  156.              corpstatflags |= CORPSTAT_INIT;
  157.              /* preserve the unique traits of some creatures */
  158.              obj = mkcorpstat(CORPSE, KEEPTRAITS(mtmp) ? mtmp : 0,
  159.                               mdat, x, y, corpstatflags);
  160.              if (burythem) {
  161.                  boolean dealloc;
  162.  
  163.                  (void) bury_an_obj(obj, &dealloc);
  164.                  newsym(x, y);
  165.                  return dealloc ? (struct obj *) 0 : obj;
  166.              }
  167.          }
  168.          break;
  169.      }
  170.      /* All special cases should precede the G_NOCORPSE check */
  171.  
  172.      if (!obj) return NULL;
  173.  
  174.      /* if polymorph or undead turning has killed this monster,
  175.         prevent the same attack beam from hitting its corpse */
  176.      if (context.bypasses)
  177.          bypass_obj(obj);
  178.  
  179.      if (has_mname(mtmp))
  180.          obj = oname(obj, MNAME(mtmp));
  181.  
  182.      /*  Avoid "It was hidden under a green mold corpse!"
  183.       *  during Blind combat. An unseen monster referred to as "it"
  184.       *  could be killed and leave a corpse.  If a hider then hid
  185.       *  underneath it, you could be told the corpse type of a
  186.       *  monster that you never knew was there without this.
  187.       *  The code in hitmu() substitutes the word "something"
  188.       *  if the corpses obj->dknown is 0.
  189.       */
  190.      if (Blind && !sensemon(mtmp))
  191.          obj->dknown = 0;
  192.  
  193.      stackobj(obj);
  194.      newsym(x, y);
  195.      return obj;
  196.  }
  197.  

minliquid

  1.  /* check mtmp and water/lava for compatibility, 0 (survived), 1 (died) */
  2.  int
  3.  minliquid(mtmp)
  4.  register struct monst *mtmp;
  5.  {
  6.      boolean inpool, inlava, infountain;
  7.  
  8.      /* [what about ceiling clingers?] */
  9.      inpool = (is_pool(mtmp->mx, mtmp->my)
  10.                && !(is_flyer(mtmp->data) || is_floater(mtmp->data)));
  11.      inlava = (is_lava(mtmp->mx, mtmp->my)
  12.                && !(is_flyer(mtmp->data) || is_floater(mtmp->data)));
  13.      infountain = IS_FOUNTAIN(levl[mtmp->mx][mtmp->my].typ);
  14.  
  15.      /* Flying and levitation keeps our steed out of the liquid */
  16.      /* (but not water-walking or swimming) */
  17.      if (mtmp == u.usteed && (Flying || Levitation))
  18.          return 0;
  19.  
  20.      /* Gremlin multiplying won't go on forever since the hit points
  21.       * keep going down, and when it gets to 1 hit point the clone
  22.       * function will fail.
  23.       */
  24.      if (mtmp->data == &mons[PM_GREMLIN] && (inpool || infountain) && rn2(3)) {
  25.          if (split_mon(mtmp, (struct monst *) 0))
  26.              dryup(mtmp->mx, mtmp->my, FALSE);
  27.          if (inpool)
  28.              water_damage_chain(mtmp->minvent, FALSE);
  29.          return 0;
  30.      } else if (mtmp->data == &mons[PM_IRON_GOLEM] && inpool && !rn2(5)) {
  31.          int dam = d(2, 6);
  32.  
  33.          if (cansee(mtmp->mx, mtmp->my))
  34.              pline("%s rusts.", Monnam(mtmp));
  35.          mtmp->mhp -= dam;
  36.          if (mtmp->mhpmax > dam)
  37.              mtmp->mhpmax -= dam;
  38.          if (mtmp->mhp < 1) {
  39.              mondead(mtmp);
  40.              if (mtmp->mhp < 1)
  41.                  return 1;
  42.          }
  43.          water_damage_chain(mtmp->minvent, FALSE);
  44.          return 0;
  45.      }
  46.  
  47.      if (inlava) {
  48.          /*
  49.           * Lava effects much as water effects. Lava likers are able to
  50.           * protect their stuff. Fire resistant monsters can only protect
  51.           * themselves  --ALI
  52.           */
  53.          if (!is_clinger(mtmp->data) && !likes_lava(mtmp->data)) {
  54.              if (!resists_fire(mtmp)) {
  55.                  if (cansee(mtmp->mx, mtmp->my)) {
  56.                      struct attack *dummy = &mtmp->data->mattk[0];
  57.                      const char *how = on_fire(mtmp->data, dummy);
  58.  
  59.                      pline("%s %s.", Monnam(mtmp),
  60.                            !strcmp(how, "boiling") ? "boils away"
  61.                               : !strcmp(how, "melting") ? "melts away"
  62.                                  : "burns to a crisp");
  63.                  }
  64.                  mondead(mtmp);
  65.              } else {
  66.                  mtmp->mhp -= 1;
  67.                  if (mtmp->mhp < 1) {
  68.                      if (cansee(mtmp->mx, mtmp->my))
  69.                          pline("%s surrenders to the fire.", Monnam(mtmp));
  70.                      mondead(mtmp);
  71.                  } else if (cansee(mtmp->mx, mtmp->my))
  72.                      pline("%s burns slightly.", Monnam(mtmp));
  73.              }
  74.              if (mtmp->mhp > 0) {
  75.                  (void) fire_damage_chain(mtmp->minvent, FALSE, FALSE,
  76.                                           mtmp->mx, mtmp->my);
  77.                  (void) rloc(mtmp, FALSE);
  78.                  return 0;
  79.              }
  80.              return 1;
  81.          }
  82.      } else if (inpool) {
  83.          /* Most monsters drown in pools.  flooreffects() will take care of
  84.           * water damage to dead monsters' inventory, but survivors need to
  85.           * be handled here.  Swimmers are able to protect their stuff...
  86.           */
  87.          if (!is_clinger(mtmp->data) && !is_swimmer(mtmp->data)
  88.              && !amphibious(mtmp->data)) {
  89.              if (cansee(mtmp->mx, mtmp->my)) {
  90.                  pline("%s drowns.", Monnam(mtmp));
  91.              }
  92.              if (u.ustuck && u.uswallow && u.ustuck == mtmp) {
  93.                  /* This can happen after a purple worm plucks you off a
  94.                  flying steed while you are over water. */
  95.                  pline("%s sinks as %s rushes in and flushes you out.",
  96.                        Monnam(mtmp), hliquid("water"));
  97.              }
  98.              mondead(mtmp);
  99.              if (mtmp->mhp > 0) {
  100.                  water_damage_chain(mtmp->minvent, FALSE);
  101.                  (void) rloc(mtmp, FALSE);
  102.                  return 0;
  103.              }
  104.              return 1;
  105.          }
  106.      } else {
  107.          /* but eels have a difficult time outside */
  108.          if (mtmp->data->mlet == S_EEL && !Is_waterlevel(&u.uz)) {
  109.              /* as mhp gets lower, the rate of further loss slows down */
  110.              if (mtmp->mhp > 1 && rn2(mtmp->mhp) > rn2(8))
  111.                  mtmp->mhp--;
  112.              monflee(mtmp, 2, FALSE, FALSE);
  113.          }
  114.      }
  115.      return 0;
  116.  }
  117.  

mcalcmove

  1.  int
  2.  mcalcmove(mon)
  3.  struct monst *mon;
  4.  {
  5.      int mmove = mon->data->mmove;
  6.      int mmove_adj;
  7.  
  8.      /* Note: MSLOW's `+ 1' prevents slowed speed 1 getting reduced to 0;
  9.       *       MFAST's `+ 2' prevents hasted speed 1 from becoming a no-op;
  10.       *       both adjustments have negligible effect on higher speeds.
  11.       */
  12.      if (mon->mspeed == MSLOW)
  13.          mmove = (2 * mmove + 1) / 3;
  14.      else if (mon->mspeed == MFAST)
  15.          mmove = (4 * mmove + 2) / 3;
  16.  
  17.      if (mon == u.usteed && u.ugallop && context.mv) {
  18.          /* increase movement by a factor of 1.5; also increase variance of
  19.             movement speed (if it's naturally 24, we don't want it to always
  20.             become 36) */
  21.          mmove = ((rn2(2) ? 4 : 5) * mmove) / 3;
  22.      }
  23.  
  24.      /* Randomly round the monster's speed to a multiple of NORMAL_SPEED. This
  25.         makes it impossible for the player to predict when they'll get a free
  26.         turn (thus preventing exploits like "melee kiting"), while retaining
  27.         guarantees about shopkeepers not being outsped by a normal-speed player,
  28.         normal-speed players being unable to open up a gap when fleeing a
  29.         normal-speed monster, etc.*/
  30.      mmove_adj = mmove % NORMAL_SPEED;
  31.      mmove -= mmove_adj;
  32.      if (rn2(NORMAL_SPEED) < mmove_adj)
  33.          mmove += NORMAL_SPEED;
  34.  
  35.      return mmove;
  36.  }
  37.  

mcalcdistress

  1.  /* actions that happen once per ``turn'', regardless of each
  2.     individual monster's metabolism; some of these might need to
  3.     be reclassified to occur more in proportion with movement rate */
  4.  void
  5.  mcalcdistress()
  6.  {
  7.      struct monst *mtmp;
  8.  
  9.      for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  10.          if (DEADMONSTER(mtmp))
  11.              continue;
  12.  
  13.          /* must check non-moving monsters once/turn in case
  14.           * they managed to end up in liquid */
  15.          if (mtmp->data->mmove == 0) {
  16.              if (vision_full_recalc)
  17.                  vision_recalc(0);
  18.              if (minliquid(mtmp))
  19.                  continue;
  20.          }
  21.  
  22.          /* regenerate hit points */
  23.          mon_regen(mtmp, FALSE);
  24.  
  25.          /* possibly polymorph shapechangers and lycanthropes */
  26.          if (mtmp->cham >= LOW_PM)
  27.              decide_to_shapeshift(mtmp, (canspotmon(mtmp)
  28.                                          || (u.uswallow && mtmp == u.ustuck))
  29.                                            ? SHIFT_MSG : 0);
  30.          were_change(mtmp);
  31.  
  32.          /* gradually time out temporary problems */
  33.          if (mtmp->mblinded && !--mtmp->mblinded)
  34.              mtmp->mcansee = 1;
  35.          if (mtmp->mfrozen && !--mtmp->mfrozen)
  36.              mtmp->mcanmove = 1;
  37.          if (mtmp->mfleetim && !--mtmp->mfleetim)
  38.              mtmp->mflee = 0;
  39.  
  40.          /* FIXME: mtmp->mlstmv ought to be updated here */
  41.      }
  42.  }
  43.  

movemon

  1.  int
  2.  movemon()
  3.  {
  4.      register struct monst *mtmp, *nmtmp;
  5.      register boolean somebody_can_move = FALSE;
  6.  
  7.      /*
  8.       * Some of you may remember the former assertion here that
  9.       * because of deaths and other actions, a simple one-pass
  10.       * algorithm wasn't possible for movemon.  Deaths are no longer
  11.       * removed to the separate list fdmon; they are simply left in
  12.       * the chain with hit points <= 0, to be cleaned up at the end
  13.       * of the pass.
  14.       *
  15.       * The only other actions which cause monsters to be removed from
  16.       * the chain are level migrations and losedogs().  I believe losedogs()
  17.       * is a cleanup routine not associated with monster movements, and
  18.       * monsters can only affect level migrations on themselves, not others
  19.       * (hence the fetching of nmon before moving the monster).  Currently,
  20.       * monsters can jump into traps, read cursed scrolls of teleportation,
  21.       * and drink cursed potions of raise level to change levels.  These are
  22.       * all reflexive at this point.  Should one monster be able to level
  23.       * teleport another, this scheme would have problems.
  24.       */
  25.  
  26.      for (mtmp = fmon; mtmp; mtmp = nmtmp) {
  27.          /* end monster movement early if hero is flagged to leave the level */
  28.          if (u.utotype
  29.  #ifdef SAFERHANGUP
  30.              /* or if the program has lost contact with the user */
  31.              || program_state.done_hup
  32.  #endif
  33.              ) {
  34.              somebody_can_move = FALSE;
  35.              break;
  36.          }
  37.          nmtmp = mtmp->nmon;
  38.          /* one dead monster needs to perform a move after death:
  39.             vault guard whose temporary corridor is still on the map */
  40.          if (mtmp->isgd && !mtmp->mx && mtmp->mhp <= 0)
  41.              (void) gd_move(mtmp);
  42.          if (DEADMONSTER(mtmp))
  43.              continue;
  44.  
  45.          /* Find a monster that we have not treated yet. */
  46.          if (mtmp->movement < NORMAL_SPEED)
  47.              continue;
  48.  
  49.          mtmp->movement -= NORMAL_SPEED;
  50.          if (mtmp->movement >= NORMAL_SPEED)
  51.              somebody_can_move = TRUE;
  52.  
  53.          if (vision_full_recalc)
  54.              vision_recalc(0); /* vision! */
  55.  
  56.          /* reset obj bypasses before next monster moves */
  57.          if (context.bypasses)
  58.              clear_bypasses();
  59.          clear_splitobjs();
  60.          if (minliquid(mtmp))
  61.              continue;
  62.  
  63.          if (is_hider(mtmp->data)) {
  64.              /* unwatched mimics and piercers may hide again  [MRS] */
  65.              if (restrap(mtmp))
  66.                  continue;
  67.              if (mtmp->m_ap_type == M_AP_FURNITURE
  68.                  || mtmp->m_ap_type == M_AP_OBJECT)
  69.                  continue;
  70.              if (mtmp->mundetected)
  71.                  continue;
  72.          } else if (mtmp->data->mlet == S_EEL && !mtmp->mundetected
  73.                     && (mtmp->mflee || distu(mtmp->mx, mtmp->my) > 2)
  74.                     && !canseemon(mtmp) && !rn2(4)) {
  75.              /* some eels end up stuck in isolated pools, where they
  76.                 can't--or at least won't--move, so they never reach
  77.                 their post-move chance to re-hide */
  78.              if (hideunder(mtmp))
  79.                  continue;
  80.          }
  81.  
  82.          /* continue if the monster died fighting */
  83.          if (Conflict && !mtmp->iswiz && mtmp->mcansee) {
  84.              /* Note:
  85.               *  Conflict does not take effect in the first round.
  86.               *  Therefore, A monster when stepping into the area will
  87.               *  get to swing at you.
  88.               *
  89.               *  The call to fightm() must be _last_.  The monster might
  90.               *  have died if it returns 1.
  91.               */
  92.              if (couldsee(mtmp->mx, mtmp->my)
  93.                  && (distu(mtmp->mx, mtmp->my) <= BOLT_LIM * BOLT_LIM)
  94.                  && fightm(mtmp))
  95.                  continue; /* mon might have died */
  96.          }
  97.          if (dochugw(mtmp)) /* otherwise just move the monster */
  98.              continue;
  99.      }
  100.  
  101.      if (any_light_source())
  102.          vision_full_recalc = 1; /* in case a mon moved with a light source */
  103.      /* reset obj bypasses after last monster has moved */
  104.      if (context.bypasses)
  105.          clear_bypasses();
  106.      clear_splitobjs();
  107.      /* remove dead monsters; dead vault guard will be left at <0,0>
  108.         if temporary corridor out of vault hasn't been removed yet */
  109.      dmonsfree();
  110.  
  111.      /* a monster may have levteleported player -dlc */
  112.      if (u.utotype) {
  113.          deferred_goto();
  114.          /* changed levels, so these monsters are dormant */
  115.          somebody_can_move = FALSE;
  116.      }
  117.  
  118.      return somebody_can_move;
  119.  }
  120.  
  121.  #define mstoning(obj)                                       \
  122.      (ofood(obj) && (touch_petrifies(&mons[(obj)->corpsenm]) \
  123.                      || (obj)->corpsenm == PM_MEDUSA))
  124.  

meatmetal

  1.  /*
  2.   * Maybe eat a metallic object (not just gold).
  3.   * Return value: 0 => nothing happened, 1 => monster ate something,
  4.   * 2 => monster died (it must have grown into a genocided form, but
  5.   * that can't happen at present because nothing which eats objects
  6.   * has young and old forms).
  7.   */
  8.  int
  9.  meatmetal(mtmp)
  10.  register struct monst *mtmp;
  11.  {
  12.      register struct obj *otmp;
  13.      struct permonst *ptr;
  14.      int poly, grow, heal, mstone;
  15.  
  16.      /* If a pet, eating is handled separately, in dog.c */
  17.      if (mtmp->mtame)
  18.          return 0;
  19.  
  20.      /* Eats topmost metal object if it is there */
  21.      for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp;
  22.           otmp = otmp->nexthere) {
  23.          /* Don't eat indigestible/choking/inappropriate objects */
  24.          if ((mtmp->data == &mons[PM_RUST_MONSTER] && !is_rustprone(otmp))
  25.              || (otmp->otyp == AMULET_OF_STRANGULATION)
  26.              || (otmp->otyp == RIN_SLOW_DIGESTION))
  27.              continue;
  28.          if (is_metallic(otmp) && !obj_resists(otmp, 5, 95)
  29.              && touch_artifact(otmp, mtmp)) {
  30.              if (mtmp->data == &mons[PM_RUST_MONSTER] && otmp->oerodeproof) {
  31.                  if (canseemon(mtmp) && flags.verbose) {
  32.                      pline("%s eats %s!", Monnam(mtmp),
  33.                            distant_name(otmp, doname));
  34.                  }
  35.                  /* The object's rustproofing is gone now */
  36.                  otmp->oerodeproof = 0;
  37.                  mtmp->mstun = 1;
  38.                  if (canseemon(mtmp) && flags.verbose) {
  39.                      pline("%s spits %s out in disgust!", Monnam(mtmp),
  40.                            distant_name(otmp, doname));
  41.                  }
  42.              } else {
  43.                  if (cansee(mtmp->mx, mtmp->my) && flags.verbose)
  44.                      pline("%s eats %s!", Monnam(mtmp),
  45.                            distant_name(otmp, doname));
  46.                  else if (flags.verbose)
  47.                      You_hear("a crunching sound.");
  48.                  mtmp->meating = otmp->owt / 2 + 1;
  49.                  /* Heal up to the object's weight in hp */
  50.                  if (mtmp->mhp < mtmp->mhpmax) {
  51.                      mtmp->mhp += objects[otmp->otyp].oc_weight;
  52.                      if (mtmp->mhp > mtmp->mhpmax)
  53.                          mtmp->mhp = mtmp->mhpmax;
  54.                  }
  55.                  if (otmp == uball) {
  56.                      unpunish();
  57.                      delobj(otmp);
  58.                  } else if (otmp == uchain) {
  59.                      unpunish(); /* frees uchain */
  60.                  } else {
  61.                      poly = polyfodder(otmp);
  62.                      grow = mlevelgain(otmp);
  63.                      heal = mhealup(otmp);
  64.                      mstone = mstoning(otmp);
  65.                      delobj(otmp);
  66.                      ptr = mtmp->data;
  67.                      if (poly) {
  68.                          if (newcham(mtmp, (struct permonst *) 0, FALSE, FALSE))
  69.                              ptr = mtmp->data;
  70.                      } else if (grow) {
  71.                          ptr = grow_up(mtmp, (struct monst *) 0);
  72.                      } else if (mstone) {
  73.                          if (poly_when_stoned(ptr)) {
  74.                              mon_to_stone(mtmp);
  75.                              ptr = mtmp->data;
  76.                          } else if (!resists_ston(mtmp)) {
  77.                              if (canseemon(mtmp))
  78.                                  pline("%s turns to stone!", Monnam(mtmp));
  79.                              monstone(mtmp);
  80.                              ptr = (struct permonst *) 0;
  81.                          }
  82.                      } else if (heal) {
  83.                          mtmp->mhp = mtmp->mhpmax;
  84.                      }
  85.                      if (!ptr)
  86.                          return 2; /* it died */
  87.                  }
  88.                  /* Left behind a pile? */
  89.                  if (rnd(25) < 3)
  90.                      (void) mksobj_at(ROCK, mtmp->mx, mtmp->my, TRUE, FALSE);
  91.                  newsym(mtmp->mx, mtmp->my);
  92.                  return 1;
  93.              }
  94.          }
  95.      }
  96.      return 0;
  97.  }
  98.  

meatobj

  1.  /* monster eats a pile of objects */
  2.  int
  3.  meatobj(mtmp) /* for gelatinous cubes */
  4.  struct monst *mtmp;
  5.  {
  6.      struct obj *otmp, *otmp2;
  7.      struct permonst *ptr, *original_ptr = mtmp->data;
  8.      int poly, grow, heal, eyes, count = 0, ecount = 0;
  9.      char buf[BUFSZ];
  10.  
  11.      buf[0] = '\0';
  12.      /* If a pet, eating is handled separately, in dog.c */
  13.      if (mtmp->mtame)
  14.          return 0;
  15.  
  16.      /* eat organic objects, including cloth and wood, if present;
  17.         engulf others, except huge rocks and metal attached to player
  18.         [despite comment at top, doesn't assume that eater is a g.cube] */
  19.      for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp; otmp = otmp2) {
  20.          otmp2 = otmp->nexthere;
  21.  
  22.          /* touch sensitive items */
  23.          if (otmp->otyp == CORPSE && is_rider(&mons[otmp->corpsenm])) {
  24.              /* Rider corpse isn't just inedible; can't engulf it either */
  25.              (void) revive_corpse(otmp);
  26.  
  27.          /* untouchable (or inaccessible) items */
  28.          } else if ((otmp->otyp == CORPSE
  29.                      && touch_petrifies(&mons[otmp->corpsenm])
  30.                      && !resists_ston(mtmp))
  31.                     /* don't engulf boulders and statues or ball&chain */
  32.                     || otmp->oclass == ROCK_CLASS
  33.                     || otmp == uball || otmp == uchain
  34.                     /* normally mtmp won't have stepped onto scare monster
  35.                        scroll, but if it does, don't eat or engulf that
  36.                        (note: scrolls inside eaten containers will still
  37.                        become engulfed) */
  38.                     || otmp->otyp == SCR_SCARE_MONSTER) {
  39.              /* do nothing--neither eaten nor engulfed */
  40.              continue;
  41.  
  42.          /* inedible items -- engulf these */
  43.          } else if (!is_organic(otmp) || obj_resists(otmp, 5, 95)
  44.                     || !touch_artifact(otmp, mtmp)
  45.                     /* redundant due to non-organic composition but
  46.                        included for emphasis */
  47.                     || (otmp->otyp == AMULET_OF_STRANGULATION
  48.                         || otmp->otyp == RIN_SLOW_DIGESTION)
  49.                     /* cockatrice corpses handled above; this
  50.                        touch_petrifies() check catches eggs */
  51.                     || ((otmp->otyp == CORPSE || otmp->otyp == EGG
  52.                          || otmp->globby)
  53.                         && ((touch_petrifies(&mons[otmp->corpsenm])
  54.                              && !resists_ston(mtmp))
  55.                             || (otmp->corpsenm == PM_GREEN_SLIME
  56.                                 && !slimeproof(mtmp->data))))) {
  57.              /* engulf */
  58.              ++ecount;
  59.              if (ecount == 1)
  60.                  Sprintf(buf, "%s engulfs %s.", Monnam(mtmp),
  61.                          distant_name(otmp, doname));
  62.              else if (ecount == 2)
  63.                  Sprintf(buf, "%s engulfs several objects.", Monnam(mtmp));
  64.              obj_extract_self(otmp);
  65.              (void) mpickobj(mtmp, otmp); /* slurp */
  66.  
  67.          /* lastly, edible items; yum! */
  68.          } else {
  69.              /* devour */
  70.              ++count;
  71.              if (cansee(mtmp->mx, mtmp->my)) {
  72.                  if (flags.verbose)
  73.                      pline("%s eats %s!", Monnam(mtmp),
  74.                            distant_name(otmp, doname));
  75.                  /* give this one even if !verbose */
  76.                  if (otmp->oclass == SCROLL_CLASS
  77.                      && !strcmpi(OBJ_DESCR(objects[otmp->otyp]), "YUM YUM"))
  78.                      pline("Yum%c", otmp->blessed ? '!' : '.');
  79.              } else {
  80.                  if (flags.verbose)
  81.                      You_hear("a slurping sound.");
  82.              }
  83.              /* Heal up to the object's weight in hp */
  84.              if (mtmp->mhp < mtmp->mhpmax) {
  85.                  mtmp->mhp += objects[otmp->otyp].oc_weight;
  86.                  if (mtmp->mhp > mtmp->mhpmax)
  87.                      mtmp->mhp = mtmp->mhpmax;
  88.              }
  89.              if (Has_contents(otmp)) {
  90.                  register struct obj *otmp3;
  91.  
  92.                  /* contents of eaten containers become engulfed; this
  93.                     is arbitrary, but otherwise g.cubes are too powerful */
  94.                  while ((otmp3 = otmp->cobj) != 0) {
  95.                      obj_extract_self(otmp3);
  96.                      if (otmp->otyp == ICE_BOX && otmp3->otyp == CORPSE) {
  97.                          otmp3->age = monstermoves - otmp3->age;
  98.                          start_corpse_timeout(otmp3);
  99.                      }
  100.                      (void) mpickobj(mtmp, otmp3);
  101.                  }
  102.              }
  103.              poly = polyfodder(otmp);
  104.              grow = mlevelgain(otmp);
  105.              heal = mhealup(otmp);
  106.              eyes = (otmp->otyp == CARROT);
  107.              delobj(otmp); /* munch */
  108.              ptr = mtmp->data;
  109.              if (poly) {
  110.                  if (newcham(mtmp, (struct permonst *) 0, FALSE, FALSE))
  111.                      ptr = mtmp->data;
  112.              } else if (grow) {
  113.                  ptr = grow_up(mtmp, (struct monst *) 0);
  114.              } else if (heal) {
  115.                  mtmp->mhp = mtmp->mhpmax;
  116.              }
  117.              if ((eyes || heal) && !mtmp->mcansee)
  118.                  mcureblindness(mtmp, canseemon(mtmp));
  119.              /* in case it polymorphed or died */
  120.              if (ptr != original_ptr)
  121.                  return !ptr ? 2 : 1;
  122.          }
  123.  
  124.          /* Engulf & devour is instant, so don't set meating */
  125.          if (mtmp->minvis)
  126.              newsym(mtmp->mx, mtmp->my);
  127.      }
  128.  
  129.      if (ecount > 0) {
  130.          if (cansee(mtmp->mx, mtmp->my) && flags.verbose && buf[0])
  131.              pline1(buf);
  132.          else if (flags.verbose)
  133.              You_hear("%s slurping sound%s.",
  134.                       (ecount == 1) ? "a" : "several", plur(ecount));
  135.      }
  136.      return (count > 0 || ecount > 0) ? 1 : 0;
  137.  }
  138.  

mpickgold

  1.  void
  2.  mpickgold(mtmp)
  3.  register struct monst *mtmp;
  4.  {
  5.      register struct obj *gold;
  6.      int mat_idx;
  7.  
  8.      if ((gold = g_at(mtmp->mx, mtmp->my)) != 0) {
  9.          mat_idx = objects[gold->otyp].oc_material;
  10.          obj_extract_self(gold);
  11.          add_to_minv(mtmp, gold);
  12.          if (cansee(mtmp->mx, mtmp->my)) {
  13.              if (flags.verbose && !mtmp->isgd)
  14.                  pline("%s picks up some %s.", Monnam(mtmp),
  15.                        mat_idx == GOLD ? "gold" : "money");
  16.              newsym(mtmp->mx, mtmp->my);
  17.          }
  18.      }
  19.  }
  20.  

mpickstuff

  1.  boolean
  2.  mpickstuff(mtmp, str)
  3.  register struct monst *mtmp;
  4.  register const char *str;
  5.  {
  6.      register struct obj *otmp, *otmp2, *otmp3;
  7.      int carryamt = 0;
  8.  
  9.      /* prevent shopkeepers from leaving the door of their shop */
  10.      if (mtmp->isshk && inhishop(mtmp))
  11.          return FALSE;
  12.  
  13.      for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp; otmp = otmp2) {
  14.          otmp2 = otmp->nexthere;
  15.          /* Nymphs take everything.  Most monsters don't pick up corpses. */
  16.          if (!str ? searches_for_item(mtmp, otmp)
  17.                   : !!(index(str, otmp->oclass))) {
  18.              if (otmp->otyp == CORPSE && mtmp->data->mlet != S_NYMPH
  19.                  /* let a handful of corpse types thru to can_carry() */
  20.                  && !touch_petrifies(&mons[otmp->corpsenm])
  21.                  && otmp->corpsenm != PM_LIZARD
  22.                  && !acidic(&mons[otmp->corpsenm]))
  23.                  continue;
  24.              if (!touch_artifact(otmp, mtmp))
  25.                  continue;
  26.              carryamt = can_carry(mtmp, otmp);
  27.              if (carryamt == 0)
  28.                  continue;
  29.              if (is_pool(mtmp->mx, mtmp->my))
  30.                  continue;
  31.              /* handle cases where the critter can only get some */
  32.              otmp3 = otmp;
  33.              if (carryamt != otmp->quan) {
  34.                  otmp3 = splitobj(otmp, carryamt);
  35.              }
  36.              if (cansee(mtmp->mx, mtmp->my) && flags.verbose)
  37.                  pline("%s picks up %s.", Monnam(mtmp),
  38.                        (distu(mtmp->mx, mtmp->my) <= 5)
  39.                            ? doname(otmp3)
  40.                            : distant_name(otmp3, doname));
  41.              obj_extract_self(otmp3);      /* remove from floor */
  42.              (void) mpickobj(mtmp, otmp3); /* may merge and free otmp3 */
  43.              m_dowear(mtmp, FALSE);
  44.              newsym(mtmp->mx, mtmp->my);
  45.              return TRUE; /* pick only one object */
  46.          }
  47.      }
  48.      return FALSE;
  49.  }
  50.  

curr_mon_load

  1.  int
  2.  curr_mon_load(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      int curload = 0;
  6.      struct obj *obj;
  7.  
  8.      for (obj = mtmp->minvent; obj; obj = obj->nobj) {
  9.          if (obj->otyp != BOULDER || !throws_rocks(mtmp->data))
  10.              curload += obj->owt;
  11.      }
  12.  
  13.      return curload;
  14.  }
  15.  

max_mon_load

  1.  int
  2.  max_mon_load(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      long maxload;
  6.  
  7.      /* Base monster carrying capacity is equal to human maximum
  8.       * carrying capacity, or half human maximum if not strong.
  9.       * (for a polymorphed player, the value used would be the
  10.       * non-polymorphed carrying capacity instead of max/half max).
  11.       * This is then modified by the ratio between the monster weights
  12.       * and human weights.  Corpseless monsters are given a capacity
  13.       * proportional to their size instead of weight.
  14.       */
  15.      if (!mtmp->data->cwt)
  16.          maxload = (MAX_CARR_CAP * (long) mtmp->data->msize) / MZ_HUMAN;
  17.      else if (!strongmonst(mtmp->data)
  18.               || (strongmonst(mtmp->data) && (mtmp->data->cwt > WT_HUMAN)))
  19.          maxload = (MAX_CARR_CAP * (long) mtmp->data->cwt) / WT_HUMAN;
  20.      else
  21.          maxload = MAX_CARR_CAP; /*strong monsters w/cwt <= WT_HUMAN*/
  22.  
  23.      if (!strongmonst(mtmp->data))
  24.          maxload /= 2;
  25.  
  26.      if (maxload < 1)
  27.          maxload = 1;
  28.  
  29.      return (int) maxload;
  30.  }
  31.  

can_carry

  1.  /* for restricting monsters' object-pickup.
  2.   *
  3.   * to support the new pet behavior, this now returns the max # of objects
  4.   * that a given monster could pick up from a pile. frequently this will be
  5.   * otmp->quan, but special cases for 'only one' now exist so.
  6.   *
  7.   * this will probably cause very amusing behavior with pets and gold coins.
  8.   *
  9.   * TODO: allow picking up 2-N objects from a pile of N based on weight.
  10.   *       Change from 'int' to 'long' to accomate big stacks of gold.
  11.   *       Right now we fake it by reporting a partial quantity, but the
  12.   *       likesgold handling m_move results in picking up the whole stack.
  13.   */
  14.  int
  15.  can_carry(mtmp, otmp)
  16.  struct monst *mtmp;
  17.  struct obj *otmp;
  18.  {
  19.      int iquan, otyp = otmp->otyp, newload = otmp->owt;
  20.      struct permonst *mdat = mtmp->data;
  21.      short nattk = 0;
  22.  
  23.      if (notake(mdat))
  24.          return 0; /* can't carry anything */
  25.  
  26.      if (otyp == CORPSE && touch_petrifies(&mons[otmp->corpsenm])
  27.          && !(mtmp->misc_worn_check & W_ARMG) && !resists_ston(mtmp))
  28.          return 0;
  29.      if (otyp == CORPSE && is_rider(&mons[otmp->corpsenm]))
  30.          return 0;
  31.      if (objects[otyp].oc_material == SILVER && mon_hates_silver(mtmp)
  32.          && (otyp != BELL_OF_OPENING || !is_covetous(mdat)))
  33.          return 0;
  34.  
  35.      /* hostile monsters who like gold will pick up the whole stack;
  36.         tame mosnters with hands will pick up the partial stack */
  37.      iquan = (otmp->quan > (long) LARGEST_INT)
  38.                 ? 20000 + rn2(LARGEST_INT - 20000 + 1)
  39.                 : (int) otmp->quan;
  40.  
  41.      /* monsters without hands can't pick up multiple objects at once
  42.       * unless they have an engulfing attack
  43.       *
  44.       * ...dragons, of course, can always carry gold pieces and gems somehow
  45.       */
  46.      if (iquan > 1) {
  47.          boolean glomper = FALSE;
  48.  
  49.          if (mtmp->data->mlet == S_DRAGON
  50.              && (otmp->oclass == COIN_CLASS
  51.                  || otmp->oclass == GEM_CLASS))
  52.              glomper = TRUE;
  53.          else
  54.              for (nattk = 0; nattk < NATTK; nattk++)
  55.                  if (mtmp->data->mattk[nattk].aatyp == AT_ENGL) {
  56.                      glomper = TRUE;
  57.                      break;
  58.                  }
  59.          if ((mtmp->data->mflags1 & M1_NOHANDS) && !glomper)
  60.              return 1;
  61.      }
  62.  
  63.      /* steeds don't pick up stuff (to avoid shop abuse) */
  64.      if (mtmp == u.usteed)
  65.          return 0;
  66.      if (mtmp->isshk)
  67.          return iquan; /* no limit */
  68.      if (mtmp->mpeaceful && !mtmp->mtame)
  69.          return 0;
  70.      /* otherwise players might find themselves obligated to violate
  71.       * their alignment if the monster takes something they need
  72.       */
  73.  
  74.      /* special--boulder throwers carry unlimited amounts of boulders */
  75.      if (throws_rocks(mdat) && otyp == BOULDER)
  76.          return iquan;
  77.  
  78.      /* nymphs deal in stolen merchandise, but not boulders or statues */
  79.      if (mdat->mlet == S_NYMPH)
  80.          return (otmp->oclass == ROCK_CLASS) ? 0 : iquan;
  81.  
  82.      if (curr_mon_load(mtmp) + newload > max_mon_load(mtmp))
  83.          return 0;
  84.  
  85.      return iquan;
  86.  }
  87.  

mfndpos

  1.  /* return number of acceptable neighbour positions */
  2.  int
  3.  mfndpos(mon, poss, info, flag)
  4.  struct monst *mon;
  5.  coord *poss; /* coord poss[9] */
  6.  long *info;  /* long info[9] */
  7.  long flag;
  8.  {
  9.      struct permonst *mdat = mon->data;
  10.      register struct trap *ttmp;
  11.      xchar x, y, nx, ny;
  12.      int cnt = 0;
  13.      uchar ntyp;
  14.      uchar nowtyp;
  15.      boolean wantpool, poolok, lavaok, nodiag;
  16.      boolean rockok = FALSE, treeok = FALSE, thrudoor;
  17.      int maxx, maxy;
  18.      boolean poisongas_ok, in_poisongas;
  19.      NhRegion *gas_reg;
  20.      int gas_glyph = cmap_to_glyph(S_poisoncloud);
  21.  
  22.      x = mon->mx;
  23.      y = mon->my;
  24.      nowtyp = levl[x][y].typ;
  25.  
  26.      nodiag = NODIAG(mdat - mons);
  27.      wantpool = mdat->mlet == S_EEL;
  28.      poolok = (is_flyer(mdat) || is_clinger(mdat)
  29.                || (is_swimmer(mdat) && !wantpool));
  30.      lavaok = (is_flyer(mdat) || is_clinger(mdat) || likes_lava(mdat));
  31.      thrudoor = ((flag & (ALLOW_WALL | BUSTDOOR)) != 0L);
  32.      poisongas_ok = ((nonliving(mdat) || is_vampshifter(mon)
  33.                       || breathless(mdat)) || resists_poison(mon));
  34.      in_poisongas = ((gas_reg = visible_region_at(x,y)) != 0
  35.                      && gas_reg->glyph == gas_glyph);
  36.  
  37.      if (flag & ALLOW_DIG) {
  38.          struct obj *mw_tmp;
  39.  
  40.          /* need to be specific about what can currently be dug */
  41.          if (!needspick(mdat)) {
  42.              rockok = treeok = TRUE;
  43.          } else if ((mw_tmp = MON_WEP(mon)) && mw_tmp->cursed
  44.                     && mon->weapon_check == NO_WEAPON_WANTED) {
  45.              rockok = is_pick(mw_tmp);
  46.              treeok = is_axe(mw_tmp);
  47.          } else {
  48.              rockok = (m_carrying(mon, PICK_AXE)
  49.                        || (m_carrying(mon, DWARVISH_MATTOCK)
  50.                            && !which_armor(mon, W_ARMS)));
  51.              treeok = (m_carrying(mon, AXE) || (m_carrying(mon, BATTLE_AXE)
  52.                                                 && !which_armor(mon, W_ARMS)));
  53.          }
  54.          if (rockok || treeok)
  55.              thrudoor = TRUE;
  56.      }
  57.  
  58.  nexttry: /* eels prefer the water, but if there is no water nearby,
  59.              they will crawl over land */
  60.      if (mon->mconf) {
  61.          flag |= ALLOW_ALL;
  62.          flag &= ~NOTONL;
  63.      }
  64.      if (!mon->mcansee)
  65.          flag |= ALLOW_SSM;
  66.      maxx = min(x + 1, COLNO - 1);
  67.      maxy = min(y + 1, ROWNO - 1);
  68.      for (nx = max(1, x - 1); nx <= maxx; nx++)
  69.          for (ny = max(0, y - 1); ny <= maxy; ny++) {
  70.              if (nx == x && ny == y)
  71.                  continue;
  72.              ntyp = levl[nx][ny].typ;
  73.              if (IS_ROCK(ntyp)
  74.                  && !((flag & ALLOW_WALL) && may_passwall(nx, ny))
  75.                  && !((IS_TREE(ntyp) ? treeok : rockok) && may_dig(nx, ny)))
  76.                  continue;
  77.              /* KMH -- Added iron bars */
  78.              if (ntyp == IRONBARS && !(flag & ALLOW_BARS))
  79.                  continue;
  80.              if (IS_DOOR(ntyp) && !(amorphous(mdat) || can_fog(mon))
  81.                  && (((levl[nx][ny].doormask & D_CLOSED) && !(flag & OPENDOOR))
  82.                      || ((levl[nx][ny].doormask & D_LOCKED)
  83.                          && !(flag & UNLOCKDOOR))) && !thrudoor)
  84.                  continue;
  85.              /* avoid poison gas? */
  86.              if (!poisongas_ok && !in_poisongas
  87.                  && (gas_reg = visible_region_at(nx,ny)) != 0
  88.                  && gas_reg->glyph == gas_glyph)
  89.                  continue;
  90.              /* first diagonal checks (tight squeezes handled below) */
  91.              if (nx != x && ny != y
  92.                  && (nodiag
  93.                      || (IS_DOOR(nowtyp) && (levl[x][y].doormask & ~D_BROKEN))
  94.                      || (IS_DOOR(ntyp) && (levl[nx][ny].doormask & ~D_BROKEN))
  95.                      || ((IS_DOOR(nowtyp) || IS_DOOR(ntyp))
  96.                          && Is_rogue_level(&u.uz))
  97.                      /* mustn't pass between adjacent long worm segments,
  98.                         but can attack that way */
  99.                      || (m_at(x, ny) && m_at(nx, y) && worm_cross(x, y, nx, ny)
  100.                          && !m_at(nx, ny) && (nx != u.ux || ny != u.uy))))
  101.                  continue;
  102.              if ((is_pool(nx, ny) == wantpool || poolok)
  103.                  && (lavaok || !is_lava(nx, ny))) {
  104.                  int dispx, dispy;
  105.                  boolean monseeu = (mon->mcansee
  106.                                     && (!Invis || perceives(mdat)));
  107.                  boolean checkobj = OBJ_AT(nx, ny);
  108.  
  109.                  /* Displacement also displaces the Elbereth/scare monster,
  110.                   * as long as you are visible.
  111.                   */
  112.                  if (Displaced && monseeu && mon->mux == nx && mon->muy == ny) {
  113.                      dispx = u.ux;
  114.                      dispy = u.uy;
  115.                  } else {
  116.                      dispx = nx;
  117.                      dispy = ny;
  118.                  }
  119.  
  120.                  info[cnt] = 0;
  121.                  if (onscary(dispx, dispy, mon)) {
  122.                      if (!(flag & ALLOW_SSM))
  123.                          continue;
  124.                      info[cnt] |= ALLOW_SSM;
  125.                  }
  126.                  if ((nx == u.ux && ny == u.uy)
  127.                      || (nx == mon->mux && ny == mon->muy)) {
  128.                      if (nx == u.ux && ny == u.uy) {
  129.                          /* If it's right next to you, it found you,
  130.                           * displaced or no.  We must set mux and muy
  131.                           * right now, so when we return we can tell
  132.                           * that the ALLOW_U means to attack _you_ and
  133.                           * not the image.
  134.                           */
  135.                          mon->mux = u.ux;
  136.                          mon->muy = u.uy;
  137.                      }
  138.                      if (!(flag & ALLOW_U))
  139.                          continue;
  140.                      info[cnt] |= ALLOW_U;
  141.                  } else {
  142.                      if (MON_AT(nx, ny)) {
  143.                          struct monst *mtmp2 = m_at(nx, ny);
  144.                          long mmflag = flag | mm_aggression(mon, mtmp2);
  145.  
  146.                          if (mmflag & ALLOW_M) {
  147.                              info[cnt] |= ALLOW_M;
  148.                              if (mtmp2->mtame) {
  149.                                  if (!(mmflag & ALLOW_TM))
  150.                                      continue;
  151.                                  info[cnt] |= ALLOW_TM;
  152.                              }
  153.                          } else {
  154.                              mmflag = flag | mm_displacement(mon, mtmp2);
  155.                              if (!(mmflag & ALLOW_MDISP))
  156.                                  continue;
  157.                              info[cnt] |= ALLOW_MDISP;
  158.                          }
  159.                      }
  160.                      /* Note: ALLOW_SANCT only prevents movement, not
  161.                         attack, into a temple. */
  162.                      if (level.flags.has_temple && *in_rooms(nx, ny, TEMPLE)
  163.                          && !*in_rooms(x, y, TEMPLE)
  164.                          && in_your_sanctuary((struct monst *) 0, nx, ny)) {
  165.                          if (!(flag & ALLOW_SANCT))
  166.                              continue;
  167.                          info[cnt] |= ALLOW_SANCT;
  168.                      }
  169.                  }
  170.                  if (checkobj && sobj_at(CLOVE_OF_GARLIC, nx, ny)) {
  171.                      if (flag & NOGARLIC)
  172.                          continue;
  173.                      info[cnt] |= NOGARLIC;
  174.                  }
  175.                  if (checkobj && sobj_at(BOULDER, nx, ny)) {
  176.                      if (!(flag & ALLOW_ROCK))
  177.                          continue;
  178.                      info[cnt] |= ALLOW_ROCK;
  179.                  }
  180.                  if (monseeu && onlineu(nx, ny)) {
  181.                      if (flag & NOTONL)
  182.                          continue;
  183.                      info[cnt] |= NOTONL;
  184.                  }
  185.                  /* check for diagonal tight squeeze */
  186.                  if (nx != x && ny != y && bad_rock(mdat, x, ny)
  187.                      && bad_rock(mdat, nx, y) && cant_squeeze_thru(mon))
  188.                      continue;
  189.                  /* The monster avoids a particular type of trap if it's
  190.                   * familiar with the trap type.  Pets get ALLOW_TRAPS
  191.                   * and checking is done in dogmove.c.  In either case,
  192.                   * "harmless" traps are neither avoided nor marked in info[].
  193.                   */
  194.                  if ((ttmp = t_at(nx, ny)) != 0) {
  195.                      if (ttmp->ttyp >= TRAPNUM || ttmp->ttyp == 0) {
  196.                          impossible(
  197.                           "A monster looked at a very strange trap of type %d.",
  198.                                     ttmp->ttyp);
  199.                              continue;
  200.                      }
  201.                      if ((ttmp->ttyp != RUST_TRAP
  202.                           || mdat == &mons[PM_IRON_GOLEM])
  203.                          && ttmp->ttyp != STATUE_TRAP
  204.                          && ((ttmp->ttyp != PIT && ttmp->ttyp != SPIKED_PIT
  205.                               && ttmp->ttyp != TRAPDOOR && ttmp->ttyp != HOLE)
  206.                              || (!is_flyer(mdat) && !is_floater(mdat)
  207.                                  && !is_clinger(mdat)) || Sokoban)
  208.                          && (ttmp->ttyp != SLP_GAS_TRAP || !resists_sleep(mon))
  209.                          && (ttmp->ttyp != BEAR_TRAP
  210.                              || (mdat->msize > MZ_SMALL && !amorphous(mdat)
  211.                                  && !is_flyer(mdat) && !is_floater(mdat)
  212.                                  && !is_whirly(mdat) && !unsolid(mdat)))
  213.                          && (ttmp->ttyp != FIRE_TRAP || !resists_fire(mon))
  214.                          && (ttmp->ttyp != SQKY_BOARD || !is_flyer(mdat))
  215.                          && (ttmp->ttyp != WEB
  216.                              || (!amorphous(mdat) && !webmaker(mdat)
  217.                                  && !is_whirly(mdat) && !unsolid(mdat)))
  218.                          && (ttmp->ttyp != ANTI_MAGIC || !resists_magm(mon))) {
  219.                          if (!(flag & ALLOW_TRAPS)) {
  220.                              if (mon->mtrapseen & (1L << (ttmp->ttyp - 1)))
  221.                                  continue;
  222.                          }
  223.                          info[cnt] |= ALLOW_TRAPS;
  224.                      }
  225.                  }
  226.                  poss[cnt].x = nx;
  227.                  poss[cnt].y = ny;
  228.                  cnt++;
  229.              }
  230.          }
  231.      if (!cnt && wantpool && !is_pool(x, y)) {
  232.          wantpool = FALSE;
  233.          goto nexttry;
  234.      }
  235.      return cnt;
  236.  }
  237.  

mm_aggression

  1.  /* Monster against monster special attacks; for the specified monster
  2.     combinations, this allows one monster to attack another adjacent one
  3.     in the absence of Conflict.  There is no provision for targetting
  4.     other monsters; just hand to hand fighting when they happen to be
  5.     next to each other. */
  6.  STATIC_OVL long
  7.  mm_aggression(magr, mdef)
  8.  struct monst *magr, /* monster that is currently deciding where to move */
  9.               *mdef; /* another monster which is next to it */
  10.  {
  11.      /* supposedly purple worms are attracted to shrieking because they
  12.         like to eat shriekers, so attack the latter when feasible */
  13.      if (magr->data == &mons[PM_PURPLE_WORM]
  14.          && mdef->data == &mons[PM_SHRIEKER])
  15.          return ALLOW_M | ALLOW_TM;
  16.      /* Various other combinations such as dog vs cat, cat vs rat, and
  17.         elf vs orc have been suggested.  For the time being we don't
  18.         support those. */
  19.      return 0L;
  20.  }
  21.  

mm_displacement

  1.  /* Monster displacing another monster out of the way */
  2.  STATIC_OVL long
  3.  mm_displacement(magr, mdef)
  4.  struct monst *magr, /* monster that is currently deciding where to move */
  5.               *mdef; /* another monster which is next to it */
  6.  {
  7.      struct permonst *pa = magr->data, *pd = mdef->data;
  8.  
  9.      /* if attacker can't barge through, there's nothing to do;
  10.         or if defender can barge through too, don't let attacker
  11.         do so, otherwise they might just end up swapping places
  12.         again when defender gets its chance to move */
  13.      if ((pa->mflags3 & M3_DISPLACES) != 0 && (pd->mflags3 & M3_DISPLACES) == 0
  14.          /* no displacing grid bugs diagonally */
  15.          && !(magr->mx != mdef->mx && magr->my != mdef->my
  16.               && NODIAG(monsndx(pd)))
  17.          /* no displacing trapped monsters or multi-location longworms */
  18.          && !mdef->mtrapped && (!mdef->wormno || !count_wsegs(mdef))
  19.          /* riders can move anything; others, same size or smaller only */
  20.          && (is_rider(pa) || pa->msize >= pd->msize))
  21.          return ALLOW_MDISP;
  22.      return 0L;
  23.  }
  24.  

monnear

  1.  /* Is the square close enough for the monster to move or attack into? */
  2.  boolean
  3.  monnear(mon, x, y)
  4.  struct monst *mon;
  5.  int x, y;
  6.  {
  7.      int distance = dist2(mon->mx, mon->my, x, y);
  8.  
  9.      if (distance == 2 && NODIAG(mon->data - mons))
  10.          return 0;
  11.      return (boolean) (distance < 3);
  12.  }
  13.  

dmonsfree

  1.  /* really free dead monsters */
  2.  void
  3.  dmonsfree()
  4.  {
  5.      struct monst **mtmp, *freetmp;
  6.      int count = 0;
  7.  
  8.      for (mtmp = &fmon; *mtmp;) {
  9.          freetmp = *mtmp;
  10.          if (freetmp->mhp <= 0 && !freetmp->isgd) {
  11.              *mtmp = freetmp->nmon;
  12.              freetmp->nmon = NULL;
  13.              dealloc_monst(freetmp);
  14.              count++;
  15.          } else
  16.              mtmp = &(freetmp->nmon);
  17.      }
  18.  
  19.      if (count != iflags.purge_monsters)
  20.          impossible("dmonsfree: %d removed doesn't match %d pending",
  21.                     count, iflags.purge_monsters);
  22.      iflags.purge_monsters = 0;
  23.  }
  24.  

replmon

  1.  /* called when monster is moved to larger structure */
  2.  void
  3.  replmon(mtmp, mtmp2)
  4.  struct monst *mtmp, *mtmp2;
  5.  {
  6.      struct obj *otmp;
  7.  
  8.      /* transfer the monster's inventory */
  9.      for (otmp = mtmp2->minvent; otmp; otmp = otmp->nobj) {
  10.          if (otmp->where != OBJ_MINVENT || otmp->ocarry != mtmp)
  11.              impossible("replmon: minvent inconsistency");
  12.          otmp->ocarry = mtmp2;
  13.      }
  14.      mtmp->minvent = 0;
  15.  
  16.      /* remove the old monster from the map and from `fmon' list */
  17.      relmon(mtmp, (struct monst **) 0);
  18.  
  19.      /* finish adding its replacement */
  20.      if (mtmp != u.usteed) /* don't place steed onto the map */
  21.          place_monster(mtmp2, mtmp2->mx, mtmp2->my);
  22.      if (mtmp2->wormno)      /* update level.monsters[wseg->wx][wseg->wy] */
  23.          place_wsegs(mtmp2); /* locations to mtmp2 not mtmp. */
  24.      if (emits_light(mtmp2->data)) {
  25.          /* since this is so rare, we don't have any `mon_move_light_source' */
  26.          new_light_source(mtmp2->mx, mtmp2->my, emits_light(mtmp2->data),
  27.                           LS_MONSTER, monst_to_any(mtmp2));
  28.          /* here we rely on fact that `mtmp' hasn't actually been deleted */
  29.          del_light_source(LS_MONSTER, monst_to_any(mtmp));
  30.      }
  31.      mtmp2->nmon = fmon;
  32.      fmon = mtmp2;
  33.      if (u.ustuck == mtmp)
  34.          u.ustuck = mtmp2;
  35.      if (u.usteed == mtmp)
  36.          u.usteed = mtmp2;
  37.      if (mtmp2->isshk)
  38.          replshk(mtmp, mtmp2);
  39.  
  40.      /* discard the old monster */
  41.      dealloc_monst(mtmp);
  42.  }
  43.  

relmon

  1.  /* release mon from the display and the map's monster list,
  2.     maybe transfer it to one of the other monster lists */
  3.  void
  4.  relmon(mon, monst_list)
  5.  struct monst *mon;
  6.  struct monst **monst_list; /* &migrating_mons or &mydogs or null */
  7.  {
  8.      struct monst *mtmp;
  9.      boolean unhide = (monst_list != 0);
  10.      int mx = mon->mx, my = mon->my;
  11.  
  12.      if (!fmon)
  13.          panic("relmon: no fmon available.");
  14.  
  15.      if (unhide) {
  16.          /* can't remain hidden across level changes (exception: wizard
  17.             clone can continue imitating some other monster form); also,
  18.             might be imitating a boulder so need line-of-sight unblocking */
  19.          mon->mundetected = 0;
  20.          if (mon->m_ap_type && mon->m_ap_type != M_AP_MONSTER)
  21.              seemimic(mon);
  22.      }
  23.  
  24.      if (mon->wormno)
  25.          remove_worm(mon);
  26.      else
  27.          remove_monster(mx, my);
  28.  
  29.      if (mon == fmon) {
  30.          fmon = fmon->nmon;
  31.      } else {
  32.          for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  33.              if (mtmp->nmon == mon)
  34.                  break;
  35.  
  36.          if (mtmp)
  37.              mtmp->nmon = mon->nmon;
  38.          else
  39.              panic("relmon: mon not in list.");
  40.      }
  41.  
  42.      if (unhide) {
  43.          newsym(mx, my);
  44.          /* insert into mydogs or migrating_mons */
  45.          mon->nmon = *monst_list;
  46.          *monst_list = mon;
  47.      } else {
  48.          /* orphan has no next monster */
  49.          mon->nmon = 0;
  50.      }
  51.  }
  52.  

copy_mextra

  1.  void
  2.  copy_mextra(mtmp2, mtmp1)
  3.  struct monst *mtmp2, *mtmp1;
  4.  {
  5.      if (!mtmp2 || !mtmp1 || !mtmp1->mextra)
  6.          return;
  7.  
  8.      if (!mtmp2->mextra)
  9.          mtmp2->mextra = newmextra();
  10.      if (MNAME(mtmp1)) {
  11.          new_mname(mtmp2, (int) strlen(MNAME(mtmp1)) + 1);
  12.          Strcpy(MNAME(mtmp2), MNAME(mtmp1));
  13.      }
  14.      if (EGD(mtmp1)) {
  15.          if (!EGD(mtmp2))
  16.              newegd(mtmp2);
  17.          *EGD(mtmp2) = *EGD(mtmp1);
  18.      }
  19.      if (EPRI(mtmp1)) {
  20.          if (!EPRI(mtmp2))
  21.              newepri(mtmp2);
  22.          *EPRI(mtmp2) = *EPRI(mtmp1);
  23.      }
  24.      if (ESHK(mtmp1)) {
  25.          if (!ESHK(mtmp2))
  26.              neweshk(mtmp2);
  27.          *ESHK(mtmp2) = *ESHK(mtmp1);
  28.      }
  29.      if (EMIN(mtmp1)) {
  30.          if (!EMIN(mtmp2))
  31.              newemin(mtmp2);
  32.          *EMIN(mtmp2) = *EMIN(mtmp1);
  33.      }
  34.      if (EDOG(mtmp1)) {
  35.          if (!EDOG(mtmp2))
  36.              newedog(mtmp2);
  37.          *EDOG(mtmp2) = *EDOG(mtmp1);
  38.      }
  39.      if (has_mcorpsenm(mtmp1))
  40.          MCORPSENM(mtmp2) = MCORPSENM(mtmp1);
  41.  }
  42.  

dealloc_mextra

  1.  void
  2.  dealloc_mextra(m)
  3.  struct monst *m;
  4.  {
  5.      struct mextra *x = m->mextra;
  6.  
  7.      if (x) {
  8.          if (x->mname)
  9.              free((genericptr_t) x->mname);
  10.          if (x->egd)
  11.              free((genericptr_t) x->egd);
  12.          if (x->epri)
  13.              free((genericptr_t) x->epri);
  14.          if (x->eshk)
  15.              free((genericptr_t) x->eshk);
  16.          if (x->emin)
  17.              free((genericptr_t) x->emin);
  18.          if (x->edog)
  19.              free((genericptr_t) x->edog);
  20.          /* [no action needed for x->mcorpsenm] */
  21.  
  22.          free((genericptr_t) x);
  23.          m->mextra = (struct mextra *) 0;
  24.      }
  25.  }
  26.  

dealloc_monst

  1.  void
  2.  dealloc_monst(mon)
  3.  struct monst *mon;
  4.  {
  5.      if (mon->nmon)
  6.          panic("dealloc_monst with nmon");
  7.      if (mon->mextra)
  8.          dealloc_mextra(mon);
  9.      free((genericptr_t) mon);
  10.  }
  11.  

m_detach

  1.  /* remove effects of mtmp from other data structures */
  2.  STATIC_OVL void
  3.  m_detach(mtmp, mptr)
  4.  struct monst *mtmp;
  5.  struct permonst *mptr; /* reflects mtmp->data _prior_ to mtmp's death */
  6.  {
  7.      if (mtmp == context.polearm.hitmon)
  8.          context.polearm.hitmon = 0;
  9.      if (mtmp->mleashed)
  10.          m_unleash(mtmp, FALSE);
  11.      /* to prevent an infinite relobj-flooreffects-hmon-killed loop */
  12.      mtmp->mtrapped = 0;
  13.      mtmp->mhp = 0; /* simplify some tests: force mhp to 0 */
  14.      relobj(mtmp, 0, FALSE);
  15.      remove_monster(mtmp->mx, mtmp->my);
  16.      if (emits_light(mptr))
  17.          del_light_source(LS_MONSTER, monst_to_any(mtmp));
  18.      if (mtmp->m_ap_type)
  19.          seemimic(mtmp);
  20.      newsym(mtmp->mx, mtmp->my);
  21.      unstuck(mtmp);
  22.      fill_pit(mtmp->mx, mtmp->my);
  23.  
  24.      if (mtmp->isshk)
  25.          shkgone(mtmp);
  26.      if (mtmp->wormno)
  27.          wormgone(mtmp);
  28.      iflags.purge_monsters++;
  29.  }
  30.  

mlifesaver

  1.  /* find the worn amulet of life saving which will save a monster */
  2.  struct obj *
  3.  mlifesaver(mon)
  4.  struct monst *mon;
  5.  {
  6.      if (!nonliving(mon->data) || is_vampshifter(mon)) {
  7.          struct obj *otmp = which_armor(mon, W_AMUL);
  8.  
  9.          if (otmp && otmp->otyp == AMULET_OF_LIFE_SAVING)
  10.              return otmp;
  11.      }
  12.      return (struct obj *) 0;
  13.  }
  14.  

lifesaved_monster

  1.  STATIC_OVL void
  2.  lifesaved_monster(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      boolean surviver;
  6.      struct obj *lifesave = mlifesaver(mtmp);
  7.  
  8.      if (lifesave) {
  9.          /* not canseemon; amulets are on the head, so you don't want
  10.           * to show this for a long worm with only a tail visible.
  11.           * Nor do you check invisibility, because glowing and
  12.           * disintegrating amulets are always visible. */
  13.          if (cansee(mtmp->mx, mtmp->my)) {
  14.              pline("But wait...");
  15.              pline("%s medallion begins to glow!", s_suffix(Monnam(mtmp)));
  16.              makeknown(AMULET_OF_LIFE_SAVING);
  17.              /* amulet is visible, but monster might not be */
  18.              if (canseemon(mtmp)) {
  19.                  if (attacktype(mtmp->data, AT_EXPL)
  20.                      || attacktype(mtmp->data, AT_BOOM))
  21.                      pline("%s reconstitutes!", Monnam(mtmp));
  22.                  else
  23.                      pline("%s looks much better!", Monnam(mtmp));
  24.              }
  25.              pline_The("medallion crumbles to dust!");
  26.          }
  27.          m_useup(mtmp, lifesave);
  28.  
  29.          surviver = !(mvitals[monsndx(mtmp->data)].mvflags & G_GENOD);
  30.          mtmp->mcanmove = 1;
  31.          mtmp->mfrozen = 0;
  32.          if (mtmp->mtame && !mtmp->isminion) {
  33.              wary_dog(mtmp, !surviver);
  34.          }
  35.          if (mtmp->mhpmax <= 0)
  36.              mtmp->mhpmax = 10;
  37.          mtmp->mhp = mtmp->mhpmax;
  38.          if (surviver)
  39.              return;
  40.  
  41.          /* genocided monster can't be life-saved */
  42.          if (cansee(mtmp->mx, mtmp->my))
  43.              pline("Unfortunately, %s is still genocided...", mon_nam(mtmp));
  44.          mtmp->mhp = 0;
  45.      }
  46.  }
  47.  

mondead

  1.  void
  2.  mondead(mtmp)
  3.  register struct monst *mtmp;
  4.  {
  5.      struct permonst *mptr;
  6.      int tmp;
  7.  
  8.      mtmp->mhp = 0; /* in case caller hasn't done this */
  9.      lifesaved_monster(mtmp);
  10.      if (mtmp->mhp > 0)
  11.          return;
  12.  
  13.      if (is_vampshifter(mtmp)) {
  14.          int mndx = mtmp->cham;
  15.          int x = mtmp->mx, y = mtmp->my;
  16.  
  17.          /* this only happens if shapeshifted */
  18.          if (mndx >= LOW_PM && mndx != monsndx(mtmp->data)
  19.              && !(mvitals[mndx].mvflags & G_GENOD)) {
  20.              char buf[BUFSZ];
  21.              boolean in_door = (amorphous(mtmp->data)
  22.                                 && closed_door(mtmp->mx, mtmp->my)),
  23.                  /* alternate message phrasing for some monster types */
  24.                  spec_mon = (nonliving(mtmp->data)
  25.                              || noncorporeal(mtmp->data)
  26.                              || amorphous(mtmp->data)),
  27.                  spec_death = (disintegested /* disintegrated or digested */
  28.                                || noncorporeal(mtmp->data)
  29.                                || amorphous(mtmp->data));
  30.  
  31.              /* construct a format string before transformation;
  32.                 will be capitalized when used, expects one %s arg */
  33.              Sprintf(buf, "%s suddenly %s and rises as %%s!",
  34.                      x_monnam(mtmp, ARTICLE_THE,
  35.                               spec_mon ? (char *) 0 : "seemingly dead",
  36.                               SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
  37.                                   | SUPPRESS_INVISIBLE | SUPPRESS_IT,
  38.                               FALSE),
  39.                      spec_death ? "reconstitutes" : "transforms");
  40.              mtmp->mcanmove = 1;
  41.              mtmp->mfrozen = 0;
  42.              if (mtmp->mhpmax <= 0)
  43.                  mtmp->mhpmax = 10;
  44.              mtmp->mhp = mtmp->mhpmax;
  45.              /* this can happen if previously a fog cloud */
  46.              if (u.uswallow && (mtmp == u.ustuck))
  47.                  expels(mtmp, mtmp->data, FALSE);
  48.              if (in_door) {
  49.                  coord new_xy;
  50.  
  51.                  if (enexto(&new_xy, mtmp->mx, mtmp->my, &mons[mndx])) {
  52.                      rloc_to(mtmp, new_xy.x, new_xy.y);
  53.                  }
  54.              }
  55.              newcham(mtmp, &mons[mndx], FALSE, FALSE);
  56.              if (mtmp->data == &mons[mndx])
  57.                  mtmp->cham = NON_PM;
  58.              else
  59.                  mtmp->cham = mndx;
  60.              if (canspotmon(mtmp)) {
  61.                  /* was using a_monnam(mtmp) but that's weird if mtmp is named:
  62.                     "Dracula suddenly transforms and rises as Dracula" */
  63.                  pline(upstart(buf), an(mtmp->data->mname));
  64.                  vamp_rise_msg = TRUE;
  65.              }
  66.              newsym(x, y);
  67.              return;
  68.          }
  69.      }
  70.  
  71.      /* dead vault guard is actually kept at coordinate <0,0> until
  72.         his temporary corridor to/from the vault has been removed;
  73.         need to do this after life-saving and before m_detach() */
  74.      if (mtmp->isgd && !grddead(mtmp))
  75.          return;
  76.  
  77.      /* Player is thrown from his steed when it dies */
  78.      if (mtmp == u.usteed)
  79.          dismount_steed(DISMOUNT_GENERIC);
  80.  
  81.      mptr = mtmp->data; /* save this for m_detach() */
  82.      /* restore chameleon, lycanthropes to true form at death */
  83.      if (mtmp->cham >= LOW_PM) {
  84.          set_mon_data(mtmp, &mons[mtmp->cham], -1);
  85.          mtmp->cham = NON_PM;
  86.      } else if (mtmp->data == &mons[PM_WEREJACKAL])
  87.          set_mon_data(mtmp, &mons[PM_HUMAN_WEREJACKAL], -1);
  88.      else if (mtmp->data == &mons[PM_WEREWOLF])
  89.          set_mon_data(mtmp, &mons[PM_HUMAN_WEREWOLF], -1);
  90.      else if (mtmp->data == &mons[PM_WERERAT])
  91.          set_mon_data(mtmp, &mons[PM_HUMAN_WERERAT], -1);
  92.  
  93.      /*
  94.       * mvitals[].died does double duty as total number of dead monsters
  95.       * and as experience factor for the player killing more monsters.
  96.       * this means that a dragon dying by other means reduces the
  97.       * experience the player gets for killing a dragon directly; this
  98.       * is probably not too bad, since the player likely finagled the
  99.       * first dead dragon via ring of conflict or pets, and extinguishing
  100.       * based on only player kills probably opens more avenues of abuse
  101.       * for rings of conflict and such.
  102.       */
  103.      tmp = monsndx(mtmp->data);
  104.      if (mvitals[tmp].died < 255)
  105.          mvitals[tmp].died++;
  106.  
  107.      /* if it's a (possibly polymorphed) quest leader, mark him as dead */
  108.      if (mtmp->m_id == quest_status.leader_m_id)
  109.          quest_status.leader_is_dead = TRUE;
  110.  #ifdef MAIL
  111.      /* if the mail daemon dies, no more mail delivery.  -3. */
  112.      if (tmp == PM_MAIL_DAEMON)
  113.          mvitals[tmp].mvflags |= G_GENOD;
  114.  #endif
  115.  
  116.      if (mtmp->data->mlet == S_KOP) {
  117.          /* Dead Kops may come back. */
  118.          switch (rnd(5)) {
  119.          case 1: /* returns near the stairs */
  120.              (void) makemon(mtmp->data, xdnstair, ydnstair, NO_MM_FLAGS);
  121.              break;
  122.          case 2: /* randomly */
  123.              (void) makemon(mtmp->data, 0, 0, NO_MM_FLAGS);
  124.              break;
  125.          default:
  126.              break;
  127.          }
  128.      }
  129.      if (mtmp->iswiz)
  130.          wizdead();
  131.      if (mtmp->data->msound == MS_NEMESIS)
  132.          nemdead();
  133.      if (mtmp->data == &mons[PM_MEDUSA])
  134.          u.uachieve.killed_medusa = 1;
  135.      if (glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph))
  136.          unmap_object(mtmp->mx, mtmp->my);
  137.      m_detach(mtmp, mptr);
  138.  }
  139.  

corpse_chance

  1.  /* TRUE if corpse might be dropped, magr may die if mon was swallowed */
  2.  boolean
  3.  corpse_chance(mon, magr, was_swallowed)
  4.  struct monst *mon;
  5.  struct monst *magr;    /* killer, if swallowed */
  6.  boolean was_swallowed; /* digestion */
  7.  {
  8.      struct permonst *mdat = mon->data;
  9.      int i, tmp;
  10.  
  11.      if (mdat == &mons[PM_VLAD_THE_IMPALER] || mdat->mlet == S_LICH) {
  12.          if (cansee(mon->mx, mon->my) && !was_swallowed)
  13.              pline("%s body crumbles into dust.", s_suffix(Monnam(mon)));
  14.          return FALSE;
  15.      }
  16.  
  17.      /* Gas spores always explode upon death */
  18.      for (i = 0; i < NATTK; i++) {
  19.          if (mdat->mattk[i].aatyp == AT_BOOM) {
  20.              if (mdat->mattk[i].damn)
  21.                  tmp = d((int) mdat->mattk[i].damn, (int) mdat->mattk[i].damd);
  22.              else if (mdat->mattk[i].damd)
  23.                  tmp = d((int) mdat->mlevel + 1, (int) mdat->mattk[i].damd);
  24.              else
  25.                  tmp = 0;
  26.              if (was_swallowed && magr) {
  27.                  if (magr == &youmonst) {
  28.                      There("is an explosion in your %s!", body_part(STOMACH));
  29.                      Sprintf(killer.name, "%s explosion",
  30.                              s_suffix(mdat->mname));
  31.                      losehp(Maybe_Half_Phys(tmp), killer.name, KILLED_BY_AN);
  32.                  } else {
  33.                      You_hear("an explosion.");
  34.                      magr->mhp -= tmp;
  35.                      if (magr->mhp < 1)
  36.                          mondied(magr);
  37.                      if (magr->mhp < 1) { /* maybe lifesaved */
  38.                          if (canspotmon(magr))
  39.                              pline("%s rips open!", Monnam(magr));
  40.                      } else if (canseemon(magr))
  41.                          pline("%s seems to have indigestion.", Monnam(magr));
  42.                  }
  43.  
  44.                  return FALSE;
  45.              }
  46.  
  47.              Sprintf(killer.name, "%s explosion", s_suffix(mdat->mname));
  48.              killer.format = KILLED_BY_AN;
  49.              explode(mon->mx, mon->my, -1, tmp, MON_EXPLODE, EXPL_NOXIOUS);
  50.              killer.name[0] = '\0';
  51.              killer.format = 0;
  52.              return FALSE;
  53.          }
  54.      }
  55.  
  56.      /* must duplicate this below check in xkilled() since it results in
  57.       * creating no objects as well as no corpse
  58.       */
  59.      if (LEVEL_SPECIFIC_NOCORPSE(mdat))
  60.          return FALSE;
  61.  
  62.      if (((bigmonst(mdat) || mdat == &mons[PM_LIZARD]) && !mon->mcloned)
  63.          || is_golem(mdat) || is_mplayer(mdat) || is_rider(mdat) || mon->isshk)
  64.          return TRUE;
  65.      tmp = 2 + ((mdat->geno & G_FREQ) < 2) + verysmall(mdat);
  66.      return (boolean) !rn2(tmp);
  67.  }
  68.  

mondied

  1.  /* drop (perhaps) a cadaver and remove monster */
  2.  void
  3.  mondied(mdef)
  4.  register struct monst *mdef;
  5.  {
  6.      mondead(mdef);
  7.      if (mdef->mhp > 0)
  8.          return; /* lifesaved */
  9.  
  10.      if (corpse_chance(mdef, (struct monst *) 0, FALSE)
  11.          && (accessible(mdef->mx, mdef->my) || is_pool(mdef->mx, mdef->my)))
  12.          (void) make_corpse(mdef, CORPSTAT_NONE);
  13.  }
  14.  

mongone

  1.  /* monster disappears, not dies */
  2.  void
  3.  mongone(mdef)
  4.  struct monst *mdef;
  5.  {
  6.      mdef->mhp = 0; /* can skip some inventory bookkeeping */
  7.  
  8.      /* dead vault guard is actually kept at coordinate <0,0> until
  9.         his temporary corridor to/from the vault has been removed */
  10.      if (mdef->isgd && !grddead(mdef))
  11.          return;
  12.      /* hero is thrown from his steed when it disappears */
  13.      if (mdef == u.usteed)
  14.          dismount_steed(DISMOUNT_GENERIC);
  15.      /* stuck to you? release */
  16.      unstuck(mdef);
  17.      /* drop special items like the Amulet so that a dismissed Kop or nurse
  18.         can't remove them from the game */
  19.      mdrop_special_objs(mdef);
  20.      /* release rest of monster's inventory--it is removed from game */
  21.      discard_minvent(mdef);
  22.      m_detach(mdef, mdef->data);
  23.  }
  24.  

monstone

  1.  /* drop a statue or rock and remove monster */
  2.  void
  3.  monstone(mdef)
  4.  struct monst *mdef;
  5.  {
  6.      struct obj *otmp, *obj, *oldminvent;
  7.      xchar x = mdef->mx, y = mdef->my;
  8.      boolean wasinside = FALSE;
  9.  
  10.      if (!vamp_stone(mdef)) /* vampshifter reverts to vampire */
  11.          return;
  12.  
  13.      /* we have to make the statue before calling mondead, to be able to
  14.       * put inventory in it, and we have to check for lifesaving before
  15.       * making the statue....
  16.       */
  17.      mdef->mhp = 0; /* in case caller hasn't done this */
  18.      lifesaved_monster(mdef);
  19.      if (mdef->mhp > 0)
  20.          return;
  21.  
  22.      mdef->mtrapped = 0; /* (see m_detach) */
  23.  
  24.      if ((int) mdef->data->msize > MZ_TINY
  25.          || !rn2(2 + ((int) (mdef->data->geno & G_FREQ) > 2))) {
  26.          oldminvent = 0;
  27.          /* some objects may end up outside the statue */
  28.          while ((obj = mdef->minvent) != 0) {
  29.              obj_extract_self(obj);
  30.              if (obj->owornmask)
  31.                  update_mon_intrinsics(mdef, obj, FALSE, TRUE);
  32.              obj_no_longer_held(obj);
  33.              if (obj->owornmask & W_WEP)
  34.                  setmnotwielded(mdef, obj);
  35.              obj->owornmask = 0L;
  36.              if (obj->otyp == BOULDER
  37.  #if 0 /* monsters don't carry statues */
  38.                  ||  (obj->otyp == STATUE
  39.                       && mons[obj->corpsenm].msize >= mdef->data->msize)
  40.  #endif
  41.                  /* invocation tools resist even with 0% resistance */
  42.                  || obj_resists(obj, 0, 0)) {
  43.                  if (flooreffects(obj, x, y, "fall"))
  44.                      continue;
  45.                  place_object(obj, x, y);
  46.              } else {
  47.                  if (obj->lamplit)
  48.                      end_burn(obj, TRUE);
  49.                  obj->nobj = oldminvent;
  50.                  oldminvent = obj;
  51.              }
  52.          }
  53.          /* defer statue creation until after inventory removal
  54.             so that saved monster traits won't retain any stale
  55.             item-conferred attributes */
  56.          otmp = mkcorpstat(STATUE, mdef, mdef->data, x, y, CORPSTAT_NONE);
  57.          if (has_mname(mdef))
  58.              otmp = oname(otmp, MNAME(mdef));
  59.          while ((obj = oldminvent) != 0) {
  60.              oldminvent = obj->nobj;
  61.              (void) add_to_container(otmp, obj);
  62.          }
  63.          /* Archeologists should not break unique statues */
  64.          if (mdef->data->geno & G_UNIQ)
  65.              otmp->spe = 1;
  66.          otmp->owt = weight(otmp);
  67.      } else
  68.          otmp = mksobj_at(ROCK, x, y, TRUE, FALSE);
  69.  
  70.      stackobj(otmp);
  71.      /* mondead() already does this, but we must do it before the newsym */
  72.      if (glyph_is_invisible(levl[x][y].glyph))
  73.          unmap_object(x, y);
  74.      if (cansee(x, y))
  75.          newsym(x, y);
  76.      /* We don't currently trap the hero in the statue in this case but we
  77.       * could */
  78.      if (u.uswallow && u.ustuck == mdef)
  79.          wasinside = TRUE;
  80.      mondead(mdef);
  81.      if (wasinside) {
  82.          if (is_animal(mdef->data))
  83.              You("%s through an opening in the new %s.",
  84.                  locomotion(youmonst.data, "jump"), xname(otmp));
  85.      }
  86.  }
  87.  

monkilled

  1.  /* another monster has killed the monster mdef */
  2.  void
  3.  monkilled(mdef, fltxt, how)
  4.  struct monst *mdef;
  5.  const char *fltxt;
  6.  int how;
  7.  {
  8.      boolean be_sad = FALSE; /* true if unseen pet is killed */
  9.  
  10.      if ((mdef->wormno ? worm_known(mdef) : cansee(mdef->mx, mdef->my))
  11.          && fltxt)
  12.          pline("%s is %s%s%s!", Monnam(mdef),
  13.                nonliving(mdef->data) ? "destroyed" : "killed",
  14.                *fltxt ? " by the " : "", fltxt);
  15.      else
  16.          be_sad = (mdef->mtame != 0);
  17.  
  18.      /* no corpses if digested or disintegrated */
  19.      disintegested = (how == AD_DGST || how == -AD_RBRE);
  20.      if (disintegested)
  21.          mondead(mdef);
  22.      else
  23.          mondied(mdef);
  24.  
  25.      if (be_sad && mdef->mhp <= 0)
  26.          You("have a sad feeling for a moment, then it passes.");
  27.  }
  28.  

unstuck

  1.  void
  2.  unstuck(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      if (u.ustuck == mtmp) {
  6.          if (u.uswallow) {
  7.              u.ux = mtmp->mx;
  8.              u.uy = mtmp->my;
  9.              u.uswallow = 0;
  10.              u.uswldtim = 0;
  11.              if (Punished && uchain->where != OBJ_FLOOR)
  12.                  placebc();
  13.              vision_full_recalc = 1;
  14.              docrt();
  15.              /* prevent swallower (mtmp might have just poly'd into something
  16.                 without an engulf attack) from immediately re-engulfing */
  17.              if (attacktype(mtmp->data, AT_ENGL) && !mtmp->mspec_used)
  18.                  mtmp->mspec_used = rnd(2);
  19.          }
  20.          u.ustuck = 0;
  21.      }
  22.  }
  23.  

killed

  1.  void
  2.  killed(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      xkilled(mtmp, XKILL_GIVEMSG);
  6.  }
  7.  

xkilled

  1.  /* the player has killed the monster mtmp */
  2.  void
  3.  xkilled(mtmp, xkill_flags)
  4.  struct monst *mtmp;
  5.  int xkill_flags; /* 1: suppress message, 2: suppress corpse, 4: pacifist */
  6.  {
  7.      int tmp, mndx, x = mtmp->mx, y = mtmp->my;
  8.      struct permonst *mdat;
  9.      struct obj *otmp;
  10.      struct trap *t;
  11.      boolean wasinside = u.uswallow && (u.ustuck == mtmp),
  12.              burycorpse = FALSE,
  13.              nomsg = (xkill_flags & XKILL_NOMSG) != 0,
  14.              nocorpse = (xkill_flags & XKILL_NOCORPSE) != 0,
  15.              noconduct = (xkill_flags & XKILL_NOCONDUCT) != 0;
  16.  
  17.      mtmp->mhp = 0; /* caller will usually have already done this */
  18.      if (!noconduct) /* KMH, conduct */
  19.          u.uconduct.killer++;
  20.  
  21.      if (!nomsg) {
  22.          boolean namedpet = has_mname(mtmp) && !Hallucination;
  23.  
  24.          You("%s %s!",
  25.              nonliving(mtmp->data) ? "destroy" : "kill",
  26.              !(wasinside || canspotmon(mtmp)) ? "it"
  27.                : !mtmp->mtame ? mon_nam(mtmp)
  28.                  : x_monnam(mtmp, namedpet ? ARTICLE_NONE : ARTICLE_THE,
  29.                             "poor", namedpet ? SUPPRESS_SADDLE : 0, FALSE));
  30.      }
  31.  
  32.      if (mtmp->mtrapped && (t = t_at(x, y)) != 0
  33.          && (t->ttyp == PIT || t->ttyp == SPIKED_PIT)) {
  34.          if (sobj_at(BOULDER, x, y))
  35.              nocorpse = TRUE; /* Prevent corpses/treasure being created
  36.                                  "on top" of boulder that is about to fall in.
  37.                                  This is out of order, but cannot be helped
  38.                                  unless this whole routine is rearranged. */
  39.          if (m_carrying(mtmp, BOULDER))
  40.              burycorpse = TRUE;
  41.      }
  42.  
  43.      /* your pet knows who just killed it...watch out */
  44.      if (mtmp->mtame && !mtmp->isminion)
  45.          EDOG(mtmp)->killed_by_u = 1;
  46.  
  47.      if (wasinside && thrownobj && thrownobj != uball) {
  48.          /* thrown object has killed hero's engulfer; add it to mon's
  49.             inventory now so that it will be placed with mon's other
  50.             stuff prior to lookhere/autopickup when hero is expelled
  51.             below (as a side-effect, this missile has immunity from
  52.             being consumed [for this shot/throw only]) */
  53.          mpickobj(mtmp, thrownobj);
  54.          /* let throwing code know that missile has been disposed of */
  55.          thrownobj = 0;
  56.      }
  57.  
  58.      vamp_rise_msg = FALSE; /* might get set in mondead(); only checked below */
  59.      disintegested = nocorpse; /* alternate vamp_rise message needed if true */
  60.      /* dispose of monster and make cadaver */
  61.      if (stoned)
  62.          monstone(mtmp);
  63.      else
  64.          mondead(mtmp);
  65.      disintegested = FALSE; /* reset */
  66.  
  67.      if (mtmp->mhp > 0) { /* monster lifesaved */
  68.          /* Cannot put the non-visible lifesaving message in
  69.           * lifesaved_monster() since the message appears only when _you_
  70.           * kill it (as opposed to visible lifesaving which always appears).
  71.           */
  72.          stoned = FALSE;
  73.          if (!cansee(x, y) && !vamp_rise_msg)
  74.              pline("Maybe not...");
  75.          return;
  76.      }
  77.  
  78.      mdat = mtmp->data; /* note: mondead can change mtmp->data */
  79.      mndx = monsndx(mdat);
  80.  
  81.      if (stoned) {
  82.          stoned = FALSE;
  83.          goto cleanup;
  84.      }
  85.  
  86.      if (nocorpse || LEVEL_SPECIFIC_NOCORPSE(mdat))
  87.          goto cleanup;
  88.  
  89.  #ifdef MAIL
  90.      if (mdat == &mons[PM_MAIL_DAEMON]) {
  91.          stackobj(mksobj_at(SCR_MAIL, x, y, FALSE, FALSE));
  92.      }
  93.  #endif
  94.      if (accessible(x, y) || is_pool(x, y)) {
  95.          struct obj *cadaver;
  96.          int otyp;
  97.  
  98.          /* illogical but traditional "treasure drop" */
  99.          if (!rn2(6) && !(mvitals[mndx].mvflags & G_NOCORPSE)
  100.              /* no extra item from swallower or steed */
  101.              && (x != u.ux || y != u.uy)
  102.              /* no extra item from kops--too easy to abuse */
  103.              && mdat->mlet != S_KOP
  104.              /* no items from cloned monsters */
  105.              && !mtmp->mcloned) {
  106.              otmp = mkobj(RANDOM_CLASS, TRUE);
  107.              /* don't create large objects from small monsters */
  108.              otyp = otmp->otyp;
  109.              if (mdat->msize < MZ_HUMAN && otyp != FIGURINE
  110.                  /* oc_big is also oc_bimanual and oc_bulky */
  111.                  && (otmp->owt > 30 || objects[otyp].oc_big)) {
  112.                  delobj(otmp);
  113.              } else if (!flooreffects(otmp, x, y, nomsg ? "" : "fall")) {
  114.                  place_object(otmp, x, y);
  115.                  stackobj(otmp);
  116.              }
  117.          }
  118.          /* corpse--none if hero was inside the monster */
  119.          if (!wasinside && corpse_chance(mtmp, (struct monst *) 0, FALSE)) {
  120.              cadaver = make_corpse(mtmp, burycorpse ? CORPSTAT_BURIED
  121.                                                     : CORPSTAT_NONE);
  122.              if (burycorpse && cadaver && cansee(x, y) && !mtmp->minvis
  123.                  && cadaver->where == OBJ_BURIED && !nomsg) {
  124.                  pline("%s corpse ends up buried.", s_suffix(Monnam(mtmp)));
  125.              }
  126.          }
  127.      }
  128.      if (wasinside)
  129.          spoteffects(TRUE); /* poor man's expels() */
  130.      /* monster is gone, corpse or other object might now be visible */
  131.      newsym(x, y);
  132.  
  133.  cleanup:
  134.      /* punish bad behaviour */
  135.      if (is_human(mdat)
  136.          && (!always_hostile(mdat) && mtmp->malign <= 0)
  137.          && (mndx < PM_ARCHEOLOGIST || mndx > PM_WIZARD)
  138.          && u.ualign.type != A_CHAOTIC) {
  139.          HTelepat &= ~INTRINSIC;
  140.          change_luck(-2);
  141.          You("murderer!");
  142.          if (Blind && !Blind_telepat)
  143.              see_monsters(); /* Can't sense monsters any more. */
  144.      }
  145.      if ((mtmp->mpeaceful && !rn2(2)) || mtmp->mtame)
  146.          change_luck(-1);
  147.      if (is_unicorn(mdat) && sgn(u.ualign.type) == sgn(mdat->maligntyp)) {
  148.          change_luck(-5);
  149.          You_feel("guilty...");
  150.      }
  151.  
  152.      /* give experience points */
  153.      tmp = experience(mtmp, (int) mvitals[mndx].died);
  154.      more_experienced(tmp, 0);
  155.      newexplevel(); /* will decide if you go up */
  156.  
  157.      /* adjust alignment points */
  158.      if (mtmp->m_id == quest_status.leader_m_id) { /* REAL BAD! */
  159.          adjalign(-(u.ualign.record + (int) ALIGNLIM / 2));
  160.          pline("That was %sa bad idea...",
  161.                u.uevent.qcompleted ? "probably " : "");
  162.      } else if (mdat->msound == MS_NEMESIS) { /* Real good! */
  163.          adjalign((int) (ALIGNLIM / 4));
  164.      } else if (mdat->msound == MS_GUARDIAN) { /* Bad */
  165.          adjalign(-(int) (ALIGNLIM / 8));
  166.          if (!Hallucination)
  167.              pline("That was probably a bad idea...");
  168.          else
  169.              pline("Whoopsie-daisy!");
  170.      } else if (mtmp->ispriest) {
  171.          adjalign((p_coaligned(mtmp)) ? -2 : 2);
  172.          /* cancel divine protection for killing your priest */
  173.          if (p_coaligned(mtmp))
  174.              u.ublessed = 0;
  175.          if (mdat->maligntyp == A_NONE)
  176.              adjalign((int) (ALIGNLIM / 4)); /* BIG bonus */
  177.      } else if (mtmp->mtame) {
  178.          adjalign(-15); /* bad!! */
  179.          /* your god is mighty displeased... */
  180.          if (!Hallucination)
  181.              You_hear("the rumble of distant thunder...");
  182.          else
  183.              You_hear("the studio audience applaud!");
  184.      } else if (mtmp->mpeaceful)
  185.          adjalign(-5);
  186.  
  187.      /* malign was already adjusted for u.ualign.type and randomization */
  188.      adjalign(mtmp->malign);
  189.  }
  190.  

mon_to_stone

  1.  /* changes the monster into a stone monster of the same type
  2.     this should only be called when poly_when_stoned() is true */
  3.  void
  4.  mon_to_stone(mtmp)
  5.  struct monst *mtmp;
  6.  {
  7.      if (mtmp->data->mlet == S_GOLEM) {
  8.          /* it's a golem, and not a stone golem */
  9.          if (canseemon(mtmp))
  10.              pline("%s solidifies...", Monnam(mtmp));
  11.          if (newcham(mtmp, &mons[PM_STONE_GOLEM], FALSE, FALSE)) {
  12.              if (canseemon(mtmp))
  13.                  pline("Now it's %s.", an(mtmp->data->mname));
  14.          } else {
  15.              if (canseemon(mtmp))
  16.                  pline("... and returns to normal.");
  17.          }
  18.      } else
  19.          impossible("Can't polystone %s!", a_monnam(mtmp));
  20.  }
  21.  

vamp_stone

  1.  boolean
  2.  vamp_stone(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      if (is_vampshifter(mtmp)) {
  6.          int mndx = mtmp->cham;
  7.          int x = mtmp->mx, y = mtmp->my;
  8.  
  9.          /* this only happens if shapeshifted */
  10.          if (mndx >= LOW_PM && mndx != monsndx(mtmp->data)
  11.              && !(mvitals[mndx].mvflags & G_GENOD)) {
  12.              char buf[BUFSZ];
  13.              boolean in_door = (amorphous(mtmp->data)
  14.                                 && closed_door(mtmp->mx, mtmp->my));
  15.  
  16.              /* construct a format string before transformation */
  17.              Sprintf(buf, "The lapidifying %s %s %s",
  18.                      x_monnam(mtmp, ARTICLE_NONE, (char *) 0,
  19.                               (SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION
  20.                                | SUPPRESS_INVISIBLE | SUPPRESS_IT), FALSE),
  21.                      amorphous(mtmp->data) ? "coalesces on the"
  22.                         : is_flyer(mtmp->data) ? "drops to the"
  23.                            : "writhes on the",
  24.                      surface(x,y));
  25.              mtmp->mcanmove = 1;
  26.              mtmp->mfrozen = 0;
  27.              if (mtmp->mhpmax <= 0)
  28.                  mtmp->mhpmax = 10;
  29.              mtmp->mhp = mtmp->mhpmax;
  30.              /* this can happen if previously a fog cloud */
  31.              if (u.uswallow && (mtmp == u.ustuck))
  32.                  expels(mtmp, mtmp->data, FALSE);
  33.              if (in_door) {
  34.                  coord new_xy;
  35.  
  36.                  if (enexto(&new_xy, mtmp->mx, mtmp->my, &mons[mndx])) {
  37.                      rloc_to(mtmp, new_xy.x, new_xy.y);
  38.                  }
  39.              }
  40.              if (canspotmon(mtmp)) {
  41.                  pline("%s!", buf);
  42.                  display_nhwindow(WIN_MESSAGE, FALSE);
  43.              }
  44.              newcham(mtmp, &mons[mndx], FALSE, FALSE);
  45.              if (mtmp->data == &mons[mndx])
  46.                  mtmp->cham = NON_PM;
  47.              else
  48.                  mtmp->cham = mndx;
  49.              if (canspotmon(mtmp)) {
  50.                  pline("%s rises from the %s with renewed agility!",
  51.                        Amonnam(mtmp), surface(mtmp->mx, mtmp->my));
  52.              }
  53.              newsym(mtmp->mx, mtmp->my);
  54.              return FALSE;   /* didn't petrify */
  55.          }
  56.      }
  57.      return TRUE;
  58.  }
  59.  

m_into_limbo

  1.  /* drop monster into "limbo" - that is, migrate to the current level */
  2.  void
  3.  m_into_limbo(mtmp)
  4.  struct monst *mtmp;
  5.  {
  6.      unstuck(mtmp);
  7.      mdrop_special_objs(mtmp);
  8.      migrate_to_level(mtmp, ledger_no(&u.uz), MIGR_APPROX_XY, NULL);
  9.  }
  10.  

mnexto

  1.  /* make monster mtmp next to you (if possible);
  2.     might place monst on far side of a wall or boulder */
  3.  void
  4.  mnexto(mtmp)
  5.  struct monst *mtmp;
  6.  {
  7.      coord mm;
  8.      boolean couldspot = canspotmon(mtmp);
  9.  
  10.      if (mtmp == u.usteed) {
  11.          /* Keep your steed in sync with you instead */
  12.          mtmp->mx = u.ux;
  13.          mtmp->my = u.uy;
  14.          return;
  15.      }
  16.  
  17.      if (!enexto(&mm, u.ux, u.uy, mtmp->data)) {
  18.          m_into_limbo(mtmp);
  19.          return;
  20.      }
  21.      if (!isok(mm.x, mm.y))
  22.          return;
  23.      rloc_to(mtmp, mm.x, mm.y);
  24.      if (!in_mklev && (mtmp->mstrategy & STRAT_APPEARMSG)) {
  25.          mtmp->mstrategy &= ~STRAT_APPEARMSG; /* one chance only */
  26.          if (!couldspot && canspotmon(mtmp))
  27.              pline("%s suddenly %s!", Amonnam(mtmp),
  28.                    !Blind ? "appears" : "arrives");
  29.      }
  30.      return;
  31.  }
  32.  

maybe_mnexto

  1.  /* like mnexto() but requires destination to be directly accessible */
  2.  void
  3.  maybe_mnexto(mtmp)
  4.  struct monst *mtmp;
  5.  {
  6.      coord mm;
  7.      struct permonst *ptr = mtmp->data;
  8.      boolean diagok = !NODIAG(ptr - mons);
  9.      int tryct = 20;
  10.  
  11.      do {
  12.          if (!enexto(&mm, u.ux, u.uy, ptr))
  13.              return;
  14.          if (couldsee(mm.x, mm.y)
  15.              /* don't move grid bugs diagonally */
  16.              && (diagok || mm.x == mtmp->mx || mm.y == mtmp->my)) {
  17.              rloc_to(mtmp, mm.x, mm.y);
  18.              return;
  19.          }
  20.      } while (--tryct > 0);
  21.  }
  22.  

mnearto

  1.  /* mnearto()
  2.   * Put monster near (or at) location if possible.
  3.   * Returns:
  4.   *  true if relocation was successful
  5.   *  false otherwise
  6.   */
  7.  boolean
  8.  mnearto(mtmp, x, y, move_other)
  9.  register struct monst *mtmp;
  10.  xchar x, y;
  11.  boolean move_other; /* make sure mtmp gets to x, y! so move m_at(x, y) */
  12.  {
  13.      struct monst *othermon = (struct monst *) 0;
  14.      xchar newx, newy;
  15.      coord mm;
  16.  
  17.      if (mtmp->mx == x && mtmp->my == y)
  18.          return TRUE;
  19.  
  20.      if (move_other && (othermon = m_at(x, y)) != 0) {
  21.          if (othermon->wormno)
  22.              remove_worm(othermon);
  23.          else
  24.              remove_monster(x, y);
  25.      }
  26.  
  27.      newx = x;
  28.      newy = y;
  29.      if (!goodpos(newx, newy, mtmp, 0)) {
  30.          /* Actually we have real problems if enexto ever fails.
  31.           * Migrating_mons that need to be placed will cause
  32.           * no end of trouble.
  33.           */
  34.          if (!enexto(&mm, newx, newy, mtmp->data))
  35.              return FALSE;
  36.          if (!isok(mm.x,mm.y))
  37.              return FALSE;
  38.          newx = mm.x;
  39.          newy = mm.y;
  40.      }
  41.      rloc_to(mtmp, newx, newy);
  42.  
  43.      if (move_other && othermon) {
  44.          xchar oldx = othermon->mx, oldy = othermon->my;
  45.  
  46.          othermon->mx = othermon->my = 0;
  47.          (void) mnearto(othermon, x, y, FALSE);
  48.          if (othermon->mx == 0 && othermon->my == 0) {
  49.              /* reloc failed */
  50.              othermon->mx = oldx;
  51.              othermon->my = oldy;
  52.              m_into_limbo(othermon);
  53.          }
  54.      }
  55.  
  56.      return TRUE;
  57.  }
  58.  

m_respond

  1.  /* monster responds to player action; not the same as a passive attack;
  2.     assumes reason for response has been tested, and response _must_ be made */
  3.  void
  4.  m_respond(mtmp)
  5.  struct monst *mtmp;
  6.  {
  7.      if (mtmp->data->msound == MS_SHRIEK) {
  8.          if (!Deaf) {
  9.              pline("%s shrieks.", Monnam(mtmp));
  10.              stop_occupation();
  11.          }
  12.          if (!rn2(10)) {
  13.              if (!rn2(13))
  14.                  (void) makemon(&mons[PM_PURPLE_WORM], 0, 0, NO_MM_FLAGS);
  15.              else
  16.                  (void) makemon((struct permonst *) 0, 0, 0, NO_MM_FLAGS);
  17.          }
  18.          aggravate();
  19.      }
  20.      if (mtmp->data == &mons[PM_MEDUSA]) {
  21.          register int i;
  22.  
  23.          for (i = 0; i < NATTK; i++)
  24.              if (mtmp->data->mattk[i].aatyp == AT_GAZE) {
  25.                  (void) gazemu(mtmp, &mtmp->data->mattk[i]);
  26.                  break;
  27.              }
  28.      }
  29.  }
  30.  

setmangry

  1.  /* Called whenever the player attacks mtmp; also called in other situations
  2.     where mtmp gets annoyed at the player. Handles mtmp getting annoyed at the
  3.     attack and any ramifications that might have. Useful also in situations
  4.     where mtmp was already hostile; it checks for situations where the player
  5.     shouldn't be attacking and any ramifications /that/ might have. */
  6.  void
  7.  setmangry(mtmp, via_attack)
  8.  struct monst *mtmp;
  9.  boolean via_attack;
  10.  {
  11.      if (via_attack && sengr_at("Elbereth", u.ux, u.uy, TRUE)) {
  12.          You_feel("like a hypocrite.");
  13.          /* AIS: Yes, I know alignment penalties and bonuses aren't balanced
  14.             at the moment. This is about correct relative to other "small"
  15.             penalties; it should be fairly large, as attacking while standing
  16.             on an Elbereth means that you're requesting peace and then
  17.             violating your own request. I know 5 isn't actually large, but
  18.             it's intentionally larger than the 1s and 2s that are normally
  19.             given for this sort of thing. */
  20.          adjalign(-5);
  21.  
  22.          if (!Blind)
  23.              pline("The engraving beneath you fades.");
  24.          del_engr_at(u.ux, u.uy);
  25.      }
  26.  
  27.      /* AIS: Should this be in both places, or just in wakeup()? */
  28.      mtmp->mstrategy &= ~STRAT_WAITMASK;
  29.      if (!mtmp->mpeaceful)
  30.          return;
  31.      if (mtmp->mtame)
  32.          return;
  33.      mtmp->mpeaceful = 0;
  34.      if (mtmp->ispriest) {
  35.          if (p_coaligned(mtmp))
  36.              adjalign(-5); /* very bad */
  37.          else
  38.              adjalign(2);
  39.      } else
  40.          adjalign(-1); /* attacking peaceful monsters is bad */
  41.      if (couldsee(mtmp->mx, mtmp->my)) {
  42.          if (humanoid(mtmp->data) || mtmp->isshk || mtmp->isgd)
  43.              pline("%s gets angry!", Monnam(mtmp));
  44.          else if (flags.verbose && !Deaf)
  45.              growl(mtmp);
  46.      }
  47.  
  48.      /* attacking your own quest leader will anger his or her guardians */
  49.      if (!context.mon_moving /* should always be the case here */
  50.          && mtmp->data == &mons[quest_info(MS_LEADER)]) {
  51.          struct monst *mon;
  52.          struct permonst *q_guardian = &mons[quest_info(MS_GUARDIAN)];
  53.          int got_mad = 0;
  54.  
  55.          /* guardians will sense this attack even if they can't see it */
  56.          for (mon = fmon; mon; mon = mon->nmon) {
  57.              if (DEADMONSTER(mon))
  58.                  continue;
  59.              if (mon->data == q_guardian && mon->mpeaceful) {
  60.                  mon->mpeaceful = 0;
  61.                  if (canseemon(mon))
  62.                      ++got_mad;
  63.              }
  64.          }
  65.          if (got_mad && !Hallucination) {
  66.              const char *who = q_guardian->mname;
  67.  
  68.              if (got_mad > 1)
  69.                  who = makeplural(who);
  70.              pline_The("%s %s to be angry too...",
  71.                        who, vtense(who, "appear"));
  72.          }
  73.      }
  74.  
  75.      /* make other peaceful monsters react */
  76.      if (!context.mon_moving) {
  77.          static const char *const Exclam[] = {
  78.              "Gasp!", "Uh-oh.", "Oh my!", "What?", "Why?",
  79.          };
  80.          struct monst *mon;
  81.          int mndx = monsndx(mtmp->data);
  82.  
  83.          for (mon = fmon; mon; mon = mon->nmon) {
  84.              if (DEADMONSTER(mon))
  85.                  continue;
  86.              if (mon == mtmp) /* the mpeaceful test catches this since mtmp */
  87.                  continue;    /* is no longer peaceful, but be explicit...  */
  88.  
  89.              if (!mindless(mon->data) && mon->mpeaceful
  90.                  && couldsee(mon->mx, mon->my) && !mon->msleeping
  91.                  && mon->mcansee && m_canseeu(mon)) {
  92.                  boolean exclaimed = FALSE;
  93.  
  94.                  if (humanoid(mon->data) || mon->isshk || mon->ispriest) {
  95.                      if (is_watch(mon->data)) {
  96.                          verbalize("Halt!  You're under arrest!");
  97.                          (void) angry_guards(!!Deaf);
  98.                      } else {
  99.                          if (!rn2(5)) {
  100.                              verbalize("%s", Exclam[mon->m_id % SIZE(Exclam)]);
  101.                              exclaimed = TRUE;
  102.                          }
  103.                          /* shopkeepers and temple priests might gasp in
  104.                             surprise, but they won't become angry here */
  105.                          if (mon->isshk || mon->ispriest)
  106.                              continue;
  107.  
  108.                          if (mon->data->mlevel < rn2(10)) {
  109.                              monflee(mon, rn2(50) + 25, TRUE, !exclaimed);
  110.                              exclaimed = TRUE;
  111.                          }
  112.                          if (mon->mtame) {
  113.                              /* mustn't set mpeaceful to 0 as below;
  114.                                 perhaps reduce tameness? */
  115.                          } else {
  116.                              mon->mpeaceful = 0;
  117.                              adjalign(-1);
  118.                              if (!exclaimed)
  119.                                  pline("%s gets angry!", Monnam(mon));
  120.                          }
  121.                      }
  122.                  } else if (mon->data->mlet == mtmp->data->mlet
  123.                             && big_little_match(mndx, monsndx(mon->data))
  124.                             && !rn2(3)) {
  125.                      if (!rn2(4)) {
  126.                          growl(mon);
  127.                          exclaimed = TRUE;
  128.                      }
  129.                      if (rn2(6))
  130.                          monflee(mon, rn2(25) + 15, TRUE, !exclaimed);
  131.                  }
  132.              }
  133.          }
  134.      }
  135.  }
  136.  

wakeup

  1.  /* wake up a monster, possibly making it angry in the process */
  2.  void
  3.  wakeup(mtmp, via_attack)
  4.  register struct monst *mtmp;
  5.  boolean via_attack;
  6.  {
  7.      mtmp->msleeping = 0;
  8.      if (mtmp->m_ap_type) {
  9.          seemimic(mtmp);
  10.      } else if (context.forcefight && !context.mon_moving
  11.                 && mtmp->mundetected) {
  12.          mtmp->mundetected = 0;
  13.          newsym(mtmp->mx, mtmp->my);
  14.      }
  15.      finish_meating(mtmp);
  16.      if (via_attack)
  17.          setmangry(mtmp, TRUE);
  18.  }
  19.  

wake_nearby

  1.  /* Wake up nearby monsters without angering them. */
  2.  void
  3.  wake_nearby()
  4.  {
  5.      register struct monst *mtmp;
  6.  
  7.      for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  8.          if (DEADMONSTER(mtmp))
  9.              continue;
  10.          if (distu(mtmp->mx, mtmp->my) < u.ulevel * 20) {
  11.              mtmp->msleeping = 0;
  12.              if (!unique_corpstat(mtmp->data))
  13.                  mtmp->mstrategy &= ~STRAT_WAITMASK;
  14.              if (mtmp->mtame) {
  15.                  if (!mtmp->isminion)
  16.                      EDOG(mtmp)->whistletime = moves;
  17.                  /* Clear mtrack. This is to fix up a pet who is
  18.                     stuck "fleeing" its master. */
  19.                  memset(mtmp->mtrack, 0, sizeof(mtmp->mtrack));
  20.              }
  21.          }
  22.      }
  23.  }
  24.  

wake_nearto

  1.  /* Wake up monsters near some particular location. */
  2.  void
  3.  wake_nearto(x, y, distance)
  4.  register int x, y, distance;
  5.  {
  6.      register struct monst *mtmp;
  7.  
  8.      for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  9.          if (DEADMONSTER(mtmp))
  10.              continue;
  11.          if (distance == 0 || dist2(mtmp->mx, mtmp->my, x, y) < distance) {
  12.              mtmp->msleeping = 0;
  13.              if (!unique_corpstat(mtmp->data))
  14.                  mtmp->mstrategy &= ~STRAT_WAITMASK;
  15.          }
  16.      }
  17.  }
  18.  

seemimic

  1.  /* NOTE: we must check for mimicry before calling this routine */
  2.  void
  3.  seemimic(mtmp)
  4.  register struct monst *mtmp;
  5.  {
  6.      boolean is_blocker_appear = (is_lightblocker_mappear(mtmp));
  7.  
  8.      if (has_mcorpsenm(mtmp))
  9.          freemcorpsenm(mtmp);
  10.  
  11.      mtmp->m_ap_type = M_AP_NOTHING;
  12.      mtmp->mappearance = 0;
  13.  
  14.      /*
  15.       *  Discovered mimics don't block light.
  16.       */
  17.      if (is_blocker_appear
  18.          && !does_block(mtmp->mx, mtmp->my, &levl[mtmp->mx][mtmp->my]))
  19.          unblock_point(mtmp->mx, mtmp->my);
  20.  
  21.      newsym(mtmp->mx, mtmp->my);
  22.  }
  23.  

rescham

  1.  /* force all chameleons to become normal */
  2.  void
  3.  rescham()
  4.  {
  5.      register struct monst *mtmp;
  6.      int mcham;
  7.  
  8.      for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  9.          if (DEADMONSTER(mtmp))
  10.              continue;
  11.          mcham = (int) mtmp->cham;
  12.          if (mcham >= LOW_PM) {
  13.              (void) newcham(mtmp, &mons[mcham], FALSE, FALSE);
  14.              mtmp->cham = NON_PM;
  15.          }
  16.          if (is_were(mtmp->data) && mtmp->data->mlet != S_HUMAN)
  17.              new_were(mtmp);
  18.          if (mtmp->m_ap_type && cansee(mtmp->mx, mtmp->my)) {
  19.              seemimic(mtmp);
  20.              /* we pretend that the mimic doesn't
  21.                 know that it has been unmasked */
  22.              mtmp->msleeping = 1;
  23.          }
  24.      }
  25.  }
  26.  

restartcham

  1.  /* Let the chameleons change again -dgk */
  2.  void
  3.  restartcham()
  4.  {
  5.      register struct monst *mtmp;
  6.  
  7.      for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  8.          if (DEADMONSTER(mtmp))
  9.              continue;
  10.          mtmp->cham = pm_to_cham(monsndx(mtmp->data));
  11.          if (mtmp->data->mlet == S_MIMIC && mtmp->msleeping
  12.              && cansee(mtmp->mx, mtmp->my)) {
  13.              set_mimic_sym(mtmp);
  14.              newsym(mtmp->mx, mtmp->my);
  15.          }
  16.      }
  17.  }
  18.  

restore_cham

  1.  /* called when restoring a monster from a saved level; protection
  2.     against shape-changing might be different now than it was at the
  3.     time the level was saved. */
  4.  void
  5.  restore_cham(mon)
  6.  struct monst *mon;
  7.  {
  8.      int mcham;
  9.  
  10.      if (Protection_from_shape_changers) {
  11.          mcham = (int) mon->cham;
  12.          if (mcham >= LOW_PM) {
  13.              mon->cham = NON_PM;
  14.              (void) newcham(mon, &mons[mcham], FALSE, FALSE);
  15.          } else if (is_were(mon->data) && !is_human(mon->data)) {
  16.              new_were(mon);
  17.          }
  18.      } else if (mon->cham == NON_PM) {
  19.          mon->cham = pm_to_cham(monsndx(mon->data));
  20.      }
  21.  }
  22.  

restrap

  1.  /* unwatched hiders may hide again; if so, returns True */
  2.  STATIC_OVL boolean
  3.  restrap(mtmp)
  4.  register struct monst *mtmp;
  5.  {
  6.      struct trap *t;
  7.  
  8.      if (mtmp->mcan || mtmp->m_ap_type || cansee(mtmp->mx, mtmp->my)
  9.          || rn2(3) || mtmp == u.ustuck
  10.          /* can't hide while trapped except in pits */
  11.          || (mtmp->mtrapped && (t = t_at(mtmp->mx, mtmp->my)) != 0
  12.              && !(t->ttyp == PIT || t->ttyp == SPIKED_PIT))
  13.          || (sensemon(mtmp) && distu(mtmp->mx, mtmp->my) <= 2))
  14.          return FALSE;
  15.  
  16.      if (mtmp->data->mlet == S_MIMIC) {
  17.          set_mimic_sym(mtmp);
  18.          return TRUE;
  19.      } else if (levl[mtmp->mx][mtmp->my].typ == ROOM) {
  20.          mtmp->mundetected = 1;
  21.          return TRUE;
  22.      }
  23.  
  24.      return FALSE;
  25.  }
  26.  

hideunder

  1.  /* monster/hero tries to hide under something at the current location */
  2.  boolean
  3.  hideunder(mtmp)
  4.  struct monst *mtmp;
  5.  {
  6.      struct trap *t;
  7.      boolean undetected = FALSE, is_u = (mtmp == &youmonst);
  8.      xchar x = is_u ? u.ux : mtmp->mx, y = is_u ? u.uy : mtmp->my;
  9.  
  10.      if (mtmp == u.ustuck) {
  11.          ; /* can't hide if holding you or held by you */
  12.      } else if (is_u ? (u.utrap && u.utraptype != TT_PIT)
  13.                      : (mtmp->mtrapped && (t = t_at(x, y)) != 0
  14.                         && !(t->ttyp == PIT || t->ttyp == SPIKED_PIT))) {
  15.          ; /* can't hide while stuck in a non-pit trap */
  16.      } else if (mtmp->data->mlet == S_EEL) {
  17.          undetected = (is_pool(x, y) && !Is_waterlevel(&u.uz));
  18.      } else if (hides_under(mtmp->data) && OBJ_AT(x, y)) {
  19.          struct obj *otmp = level.objects[x][y];
  20.  
  21.          /* most monsters won't hide under cockatrice corpse */
  22.          if (otmp->nexthere || otmp->otyp != CORPSE
  23.              || (mtmp == &youmonst ? Stone_resistance : resists_ston(mtmp))
  24.              || !touch_petrifies(&mons[otmp->corpsenm]))
  25.              undetected = TRUE;
  26.      }
  27.  
  28.      if (is_u)
  29.          u.uundetected = undetected;
  30.      else
  31.          mtmp->mundetected = undetected;
  32.      return undetected;
  33.  }
  34.  

hide_monst

  1.  /* called when returning to a previously visited level */
  2.  void
  3.  hide_monst(mon)
  4.  struct monst *mon;
  5.  {
  6.      boolean hider_under = hides_under(mon->data) || mon->data->mlet == S_EEL;
  7.  
  8.      if ((is_hider(mon->data) || hider_under)
  9.          && !(mon->mundetected || mon->m_ap_type)) {
  10.          xchar x = mon->mx, y = mon->my;
  11.          char save_viz = viz_array[y][x];
  12.  
  13.          /* override vision, forcing hero to be unable to see monster's spot */
  14.          viz_array[y][x] &= ~(IN_SIGHT | COULD_SEE);
  15.          if (is_hider(mon->data))
  16.              (void) restrap(mon);
  17.          /* try again if mimic missed its 1/3 chance to hide */
  18.          if (mon->data->mlet == S_MIMIC && !mon->m_ap_type)
  19.              (void) restrap(mon);
  20.          if (hider_under)
  21.              (void) hideunder(mon);
  22.          viz_array[y][x] = save_viz;
  23.      }
  24.  }
  25.  
  26.  static short *animal_list = 0; /* list of PM values for animal monsters */
  27.  static int animal_list_count;
  28.  

mon_animal_list

  1.  void
  2.  mon_animal_list(construct)
  3.  boolean construct;
  4.  {
  5.      if (construct) {
  6.          short animal_temp[SPECIAL_PM];
  7.          int i, n;
  8.  
  9.          /* if (animal_list) impossible("animal_list already exists"); */
  10.  
  11.          for (n = 0, i = LOW_PM; i < SPECIAL_PM; i++)
  12.              if (is_animal(&mons[i]))
  13.                  animal_temp[n++] = i;
  14.          /* if (n == 0) animal_temp[n++] = NON_PM; */
  15.  
  16.          animal_list = (short *) alloc(n * sizeof *animal_list);
  17.          (void) memcpy((genericptr_t) animal_list, (genericptr_t) animal_temp,
  18.                        n * sizeof *animal_list);
  19.          animal_list_count = n;
  20.      } else { /* release */
  21.          if (animal_list)
  22.              free((genericptr_t) animal_list), animal_list = 0;
  23.          animal_list_count = 0;
  24.      }
  25.  }
  26.  

pick_animal

  1.  STATIC_OVL int
  2.  pick_animal()
  3.  {
  4.      int res;
  5.  
  6.      if (!animal_list)
  7.          mon_animal_list(TRUE);
  8.  
  9.      res = animal_list[rn2(animal_list_count)];
  10.      /* rogue level should use monsters represented by uppercase letters
  11.         only, but since chameleons aren't generated there (not uppercase!)
  12.         we don't perform a lot of retries */
  13.      if (Is_rogue_level(&u.uz) && !isupper((uchar) mons[res].mlet))
  14.          res = animal_list[rn2(animal_list_count)];
  15.      return res;
  16.  }
  17.  

decide_to_shapeshift

  1.  void
  2.  decide_to_shapeshift(mon, shiftflags)
  3.  struct monst *mon;
  4.  int shiftflags;
  5.  {
  6.      struct permonst *ptr = 0;
  7.      int mndx;
  8.      unsigned was_female = mon->female;
  9.      boolean msg = FALSE, dochng = FALSE;
  10.  
  11.      if ((shiftflags & SHIFT_MSG)
  12.          || ((shiftflags & SHIFT_SEENMSG) && sensemon(mon)))
  13.          msg = TRUE;
  14.  
  15.      if (!is_vampshifter(mon)) {
  16.          /* regular shapeshifter */
  17.          if (!rn2(6))
  18.              dochng = TRUE;
  19.      } else {
  20.          /* The vampire has to be in good health (mhp) to maintain
  21.           * its shifted form.
  22.           *
  23.           * If we're shifted and getting low on hp, maybe shift back, or
  24.           * if we're a fog cloud at full hp, maybe pick a different shape.
  25.           * If we're not already shifted and in good health, maybe shift.
  26.           */
  27.          if (mon->data->mlet != S_VAMPIRE) {
  28.              if ((mon->mhp <= (mon->mhpmax + 5) / 6) && rn2(4)
  29.                  && mon->cham >= LOW_PM) {
  30.                  ptr = &mons[mon->cham];
  31.                  dochng = TRUE;
  32.              } else if (mon->data == &mons[PM_FOG_CLOUD]
  33.                       && mon->mhp == mon->mhpmax && !rn2(4)
  34.                       && (!canseemon(mon)
  35.                           || distu(mon->mx, mon->my) > BOLT_LIM * BOLT_LIM)) {
  36.                  /* if a fog cloud, maybe change to wolf or vampire bat;
  37.                     those are more likely to take damage--at least when
  38.                     tame--and then switch back to vampire; they'll also
  39.                     switch to fog cloud if they encounter a closed door */
  40.                  mndx = pickvampshape(mon);
  41.                  if (mndx >= LOW_PM) {
  42.                      ptr = &mons[mndx];
  43.                      dochng = (ptr != mon->data);
  44.                  }
  45.              }
  46.          } else {
  47.              if (mon->mhp >= 9 * mon->mhpmax / 10 && !rn2(6)
  48.                  && (!canseemon(mon)
  49.                      || distu(mon->mx, mon->my) > BOLT_LIM * BOLT_LIM))
  50.                  dochng = TRUE; /* 'ptr' stays Null */
  51.          }
  52.      }
  53.      if (dochng) {
  54.          if (newcham(mon, ptr, FALSE, msg) && is_vampshifter(mon)) {
  55.              /* for vampshift, override the 10% chance for sex change */
  56.              ptr = mon->data;
  57.              if (!is_male(ptr) && !is_female(ptr) && !is_neuter(ptr))
  58.                  mon->female = was_female;
  59.          }
  60.      }
  61.  }
  62.  

pickvampshape

  1.  STATIC_OVL int
  2.  pickvampshape(mon)
  3.  struct monst *mon;
  4.  {
  5.      int mndx = mon->cham, wolfchance = 10;
  6.      /* avoid picking monsters with lowercase display symbols ('d' for wolf
  7.         and 'v' for fog cloud) on rogue level*/
  8.      boolean uppercase_only = Is_rogue_level(&u.uz);
  9.  
  10.      switch (mndx) {
  11.      case PM_VLAD_THE_IMPALER:
  12.          /* ensure Vlad can keep carrying the Candelabrum */
  13.          if (mon_has_special(mon))
  14.              break; /* leave mndx as is */
  15.          wolfchance = 3;
  16.      /*FALLTHRU*/
  17.      case PM_VAMPIRE_LORD: /* vampire lord or Vlad can become wolf */
  18.          if (!rn2(wolfchance) && !uppercase_only) {
  19.              mndx = PM_WOLF;
  20.              break;
  21.          }
  22.      /*FALLTHRU*/
  23.      case PM_VAMPIRE: /* any vampire can become fog or bat */
  24.          mndx = (!rn2(4) && !uppercase_only) ? PM_FOG_CLOUD : PM_VAMPIRE_BAT;
  25.          break;
  26.      }
  27.      return mndx;
  28.  }
  29.  

isspecmon

  1.  /* nonshapechangers who warrant special polymorph handling */
  2.  STATIC_OVL boolean
  3.  isspecmon(mon)
  4.  struct monst *mon;
  5.  {
  6.      return (mon->isshk || mon->ispriest || mon->isgd
  7.              || mon->m_id == quest_status.leader_m_id);
  8.  }
  9.  

validspecmon

  1.  /* restrict certain special monsters (shopkeepers, aligned priests,
  2.     vault guards) to forms that allow them to behave sensibly (catching
  3.     gold, speaking?) so that they don't need too much extra code */
  4.  STATIC_OVL boolean
  5.  validspecmon(mon, mndx)
  6.  struct monst *mon;
  7.  int mndx;
  8.  {
  9.      if (mndx == NON_PM)
  10.          return TRUE; /* caller wants random */
  11.  
  12.      if (!accept_newcham_form(mndx))
  13.          return FALSE; /* geno'd or !polyok */
  14.  
  15.      if (isspecmon(mon)) {
  16.          struct permonst *ptr = &mons[mndx];
  17.  
  18.          /* reject notake because object manipulation is expected
  19.             and nohead because speech capability is expected */
  20.          if (notake(ptr) || !has_head(ptr))
  21.              return FALSE;
  22.          /* [should we check ptr->msound here too?] */
  23.      }
  24.      return TRUE; /* potential new form is ok */
  25.  }
  26.  

validvamp

  1.  /* prevent wizard mode user from specifying invalid vampshifter shape */
  2.  boolean
  3.  validvamp(mon, mndx_p, monclass)
  4.  struct monst *mon;
  5.  int *mndx_p, monclass;
  6.  {
  7.      /* simplify caller's usage */
  8.      if (!is_vampshifter(mon))
  9.          return validspecmon(mon, *mndx_p);
  10.  
  11.      if (*mndx_p == PM_VAMPIRE || *mndx_p == PM_VAMPIRE_LORD
  12.          || *mndx_p == PM_VLAD_THE_IMPALER) {
  13.          /* player picked some type of vampire; use mon's self */
  14.          *mndx_p = mon->cham;
  15.          return TRUE;
  16.      }
  17.      if (mon->cham == PM_VLAD_THE_IMPALER && mon_has_special(mon)) {
  18.          /* Vlad with Candelabrum; override choice, then accept it */
  19.          *mndx_p = PM_VLAD_THE_IMPALER;
  20.          return TRUE;
  21.      }
  22.      /* basic vampires can't become wolves; any can become fog or bat
  23.         (we don't enforce upper-case only for rogue level here) */
  24.      if (*mndx_p == PM_WOLF)
  25.          return (boolean) (mon->cham != PM_VAMPIRE);
  26.      if (*mndx_p == PM_FOG_CLOUD || *mndx_p == PM_VAMPIRE_BAT)
  27.          return TRUE;
  28.  
  29.      /* if we get here, specific type was no good; try by class */
  30.      switch (monclass) {
  31.      case S_VAMPIRE:
  32.          *mndx_p = mon->cham;
  33.          break;
  34.      case S_BAT:
  35.          *mndx_p = PM_VAMPIRE_BAT;
  36.          break;
  37.      case S_VORTEX:
  38.          *mndx_p = PM_FOG_CLOUD;
  39.          break;
  40.      case S_DOG:
  41.          if (mon->cham != PM_VAMPIRE) {
  42.              *mndx_p = PM_WOLF;
  43.              break;
  44.          }
  45.      /*FALLTHRU*/
  46.      default:
  47.          *mndx_p = NON_PM;
  48.          break;
  49.      }
  50.      return (boolean) (*mndx_p != NON_PM);
  51.  }
  52.  

select_newcham_form

  1.  int
  2.  select_newcham_form(mon)
  3.  struct monst *mon;
  4.  {
  5.      int mndx = NON_PM, tryct;
  6.  
  7.      switch (mon->cham) {
  8.      case PM_SANDESTIN:
  9.          if (rn2(7))
  10.              mndx = pick_nasty();
  11.          break;
  12.      case PM_DOPPELGANGER:
  13.          if (!rn2(7)) {
  14.              mndx = pick_nasty();
  15.          } else if (rn2(3)) { /* role monsters */
  16.              mndx = rn1(PM_WIZARD - PM_ARCHEOLOGIST + 1, PM_ARCHEOLOGIST);
  17.          } else if (!rn2(3)) { /* quest guardians */
  18.              mndx = rn1(PM_APPRENTICE - PM_STUDENT + 1, PM_STUDENT);
  19.              /* avoid own role's guardian */
  20.              if (mndx == urole.guardnum)
  21.                  mndx = NON_PM;
  22.          } else { /* general humanoids */
  23.              tryct = 5;
  24.              do {
  25.                  mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
  26.                  if (humanoid(&mons[mndx]) && polyok(&mons[mndx]))
  27.                      break;
  28.              } while (--tryct > 0);
  29.              if (!tryct)
  30.                  mndx = NON_PM;
  31.          }
  32.          break;
  33.      case PM_CHAMELEON:
  34.          if (!rn2(3))
  35.              mndx = pick_animal();
  36.          break;
  37.      case PM_VLAD_THE_IMPALER:
  38.      case PM_VAMPIRE_LORD:
  39.      case PM_VAMPIRE:
  40.          mndx = pickvampshape(mon);
  41.          break;
  42.      case NON_PM: /* ordinary */
  43.        {
  44.          struct obj *m_armr = which_armor(mon, W_ARM);
  45.  
  46.          if (m_armr && Is_dragon_scales(m_armr))
  47.              mndx = (int) (Dragon_scales_to_pm(m_armr) - mons);
  48.          else if (m_armr && Is_dragon_mail(m_armr))
  49.              mndx = (int) (Dragon_mail_to_pm(m_armr) - mons);
  50.        }
  51.          break;
  52.      }
  53.  
  54.      /* for debugging: allow control of polymorphed monster */
  55.      if (wizard && iflags.mon_polycontrol) {
  56.          char pprompt[BUFSZ], buf[BUFSZ] = DUMMY;
  57.          int monclass;
  58.  
  59.          Sprintf(pprompt, "Change %s @ %s into what kind of monster?",
  60.                  noit_mon_nam(mon),
  61.                  coord_desc((int) mon->mx, (int) mon->my, buf,
  62.                             (iflags.getpos_coords != GPCOORDS_NONE)
  63.                                ? iflags.getpos_coords : GPCOORDS_MAP));
  64.          tryct = 5;
  65.          do {
  66.              monclass = 0;
  67.              getlin(pprompt, buf);
  68.              mungspaces(buf);
  69.              /* for ESC, take form selected above (might be NON_PM) */
  70.              if (*buf == '\033')
  71.                  break;
  72.              /* for "*", use NON_PM to pick an arbitrary shape below */
  73.              if (!strcmp(buf, "*") || !strcmp(buf, "random")) {
  74.                  mndx = NON_PM;
  75.                  break;
  76.              }
  77.              mndx = name_to_mon(buf);
  78.              if (mndx == NON_PM) {
  79.                  /* didn't get a type, so check whether it's a class
  80.                     (single letter or text match with def_monsyms[]) */
  81.                  monclass = name_to_monclass(buf, &mndx);
  82.                  if (monclass && mndx == NON_PM)
  83.                      mndx = mkclass_poly(monclass);
  84.              }
  85.              if (mndx >= LOW_PM) {
  86.                  /* got a specific type of monster; use it if we can */
  87.                  if (validvamp(mon, &mndx, monclass))
  88.                      break;
  89.                  /* can't; revert to random in case we exhaust tryct */
  90.                  mndx = NON_PM;
  91.              }
  92.  
  93.              pline("It can't become that.");
  94.          } while (--tryct > 0);
  95.          if (!tryct)
  96.              pline1(thats_enough_tries);
  97.          if (is_vampshifter(mon) && !validvamp(mon, &mndx, monclass))
  98.              mndx = pickvampshape(mon); /* don't resort to arbitrary */
  99.      }
  100.  
  101.      /* if no form was specified above, pick one at random now */
  102.      if (mndx == NON_PM) {
  103.          tryct = 50;
  104.          do {
  105.              mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
  106.          } while (--tryct > 0 && !validspecmon(mon, mndx)
  107.                   /* try harder to select uppercase monster on rogue level */
  108.                   && (tryct > 40 && Is_rogue_level(&u.uz)
  109.                       && !isupper((uchar) mons[mndx].mlet)));
  110.      }
  111.      return mndx;
  112.  }
  113.  

accept_newcham_form

  1.  /* this used to be inline within newcham() but monpolycontrol needs it too */
  2.  STATIC_OVL struct permonst *
  3.  accept_newcham_form(mndx)
  4.  int mndx;
  5.  {
  6.      struct permonst *mdat;
  7.  
  8.      if (mndx == NON_PM)
  9.          return 0;
  10.      mdat = &mons[mndx];
  11.      if ((mvitals[mndx].mvflags & G_GENOD) != 0)
  12.          return 0;
  13.      if (is_placeholder(mdat))
  14.          return 0;
  15.      /* select_newcham_form() might deliberately pick a player
  16.         character type (random selection never does) which
  17.         polyok() rejects, so we need a special case here */
  18.      if (is_mplayer(mdat))
  19.          return mdat;
  20.      /* polyok() rules out M2_PNAME, M2_WERE, and all humans except Kops */
  21.      return polyok(mdat) ? mdat : 0;
  22.  }
  23.  

mgender_from_permonst

  1.  void
  2.  mgender_from_permonst(mtmp, mdat)
  3.  struct monst *mtmp;
  4.  struct permonst *mdat;
  5.  {
  6.      if (is_male(mdat)) {
  7.          if (mtmp->female)
  8.              mtmp->female = FALSE;
  9.      } else if (is_female(mdat)) {
  10.          if (!mtmp->female)
  11.              mtmp->female = TRUE;
  12.      } else if (!is_neuter(mdat)) {
  13.          if (!rn2(10))
  14.              mtmp->female = !mtmp->female;
  15.      }
  16.  }
  17.  

newcham

  1.  /* make a chameleon take on another shape, or a polymorph target
  2.     (possibly self-inflicted) become a different monster;
  3.     returns 1 if it actually changes form */
  4.  int
  5.  newcham(mtmp, mdat, polyspot, msg)
  6.  struct monst *mtmp;
  7.  struct permonst *mdat;
  8.  boolean polyspot; /* change is the result of wand or spell of polymorph */
  9.  boolean msg;      /* "The oldmon turns into a newmon!" */
  10.  {
  11.      int hpn, hpd;
  12.      int mndx, tryct;
  13.      struct permonst *olddata = mtmp->data;
  14.      char *p, oldname[BUFSZ], l_oldname[BUFSZ], newname[BUFSZ];
  15.  
  16.      /* Riders are immune to polymorph and green slime
  17.         (but apparent Rider might actually be a doppelganger) */
  18.      if (mtmp->cham == NON_PM) { /* not a shapechanger */
  19.          if (is_rider(olddata))
  20.              return 0;
  21.          /* make Nazgul and erinyes immune too, to reduce chance of
  22.             anomalous extinction feedback during final disclsoure */
  23.          if (mbirth_limit(monsndx(olddata)) < MAXMONNO)
  24.              return 0;
  25.      }
  26.  
  27.      if (msg) {
  28.          /* like Monnam() but never mention saddle */
  29.          Strcpy(oldname, x_monnam(mtmp, ARTICLE_THE, (char *) 0,
  30.                                   SUPPRESS_SADDLE, FALSE));
  31.          oldname[0] = highc(oldname[0]);
  32.      }
  33.      /* we need this one whether msg is true or not */
  34.      Strcpy(l_oldname, x_monnam(mtmp, ARTICLE_THE, (char *) 0,
  35.                                 has_mname(mtmp) ? SUPPRESS_SADDLE : 0, FALSE));
  36.  
  37.      /* mdat = 0 -> caller wants a random monster shape */
  38.      if (mdat == 0) {
  39.          /* select_newcham_form() loops when resorting to random but
  40.             it doesn't always pick that so we still retry here too */
  41.          tryct = 20;
  42.          do {
  43.              mndx = select_newcham_form(mtmp);
  44.              mdat = accept_newcham_form(mndx);
  45.              /* for the first several tries we require upper-case on
  46.                 the rogue level (after that, we take whatever we get) */
  47.              if (tryct > 15 && Is_rogue_level(&u.uz)
  48.                  && mdat && !isupper((uchar) mdat->mlet))
  49.                  mdat = 0;
  50.              if (mdat)
  51.                  break;
  52.          } while (--tryct > 0);
  53.          if (!tryct)
  54.              return 0;
  55.      } else if (mvitals[monsndx(mdat)].mvflags & G_GENOD)
  56.          return 0; /* passed in mdat is genocided */
  57.  
  58.      if (mdat == olddata)
  59.          return 0; /* still the same monster */
  60.  
  61.      mgender_from_permonst(mtmp, mdat);
  62.      /* Endgame mplayers start out as "Foo the Bar", but some of the
  63.       * titles are inappropriate when polymorphed, particularly into
  64.       * the opposite sex.  Player characters don't use ranks when
  65.       * polymorphed, so dropping rank for mplayers seems reasonable.
  66.       */
  67.      if (In_endgame(&u.uz) && is_mplayer(olddata)
  68.          && has_mname(mtmp) && (p = strstr(MNAME(mtmp), " the ")) != 0)
  69.          *p = '\0';
  70.  
  71.      if (mtmp->wormno) { /* throw tail away */
  72.          wormgone(mtmp);
  73.          place_monster(mtmp, mtmp->mx, mtmp->my);
  74.      }
  75.      if (mtmp->m_ap_type && mdat->mlet != S_MIMIC)
  76.          seemimic(mtmp); /* revert to normal monster */
  77.  
  78.      /* (this code used to try to adjust the monster's health based on
  79.         a normal one of its type but there are too many special cases
  80.         which need to handled in order to do that correctly, so just
  81.         give the new form the same proportion of HP as its old one had) */
  82.      hpn = mtmp->mhp;
  83.      hpd = mtmp->mhpmax;
  84.      /* set level and hit points */
  85.      newmonhp(mtmp, monsndx(mdat));
  86.      /* new hp: same fraction of max as before */
  87.  #ifndef LINT
  88.      mtmp->mhp = (int) (((long) hpn * (long) mtmp->mhp) / (long) hpd);
  89.  #endif
  90.      /* sanity check (potential overflow) */
  91.      if (mtmp->mhp < 0 || mtmp->mhp > mtmp->mhpmax)
  92.          mtmp->mhp = mtmp->mhpmax;
  93.      /* unlikely but not impossible; a 1HD creature with 1HP that changes
  94.         into a 0HD creature will require this statement */
  95.      if (!mtmp->mhp)
  96.          mtmp->mhp = 1;
  97.  
  98.      /* take on the new form... */
  99.      set_mon_data(mtmp, mdat, 0);
  100.  
  101.      if (emits_light(olddata) != emits_light(mtmp->data)) {
  102.          /* used to give light, now doesn't, or vice versa,
  103.             or light's range has changed */
  104.          if (emits_light(olddata))
  105.              del_light_source(LS_MONSTER, monst_to_any(mtmp));
  106.          if (emits_light(mtmp->data))
  107.              new_light_source(mtmp->mx, mtmp->my, emits_light(mtmp->data),
  108.                               LS_MONSTER, monst_to_any(mtmp));
  109.      }
  110.      if (!mtmp->perminvis || pm_invisible(olddata))
  111.          mtmp->perminvis = pm_invisible(mdat);
  112.      mtmp->minvis = mtmp->invis_blkd ? 0 : mtmp->perminvis;
  113.      if (mtmp->mundetected)
  114.          (void) hideunder(mtmp);
  115.      if (u.ustuck == mtmp) {
  116.          if (u.uswallow) {
  117.              if (!attacktype(mdat, AT_ENGL)) {
  118.                  /* Does mdat care? */
  119.                  if (!noncorporeal(mdat) && !amorphous(mdat)
  120.                      && !is_whirly(mdat) && (mdat != &mons[PM_YELLOW_LIGHT])) {
  121.                      char msgtrail[BUFSZ];
  122.  
  123.                      if (is_vampshifter(mtmp)) {
  124.                          Sprintf(msgtrail, " which was a shapeshifted %s",
  125.                                  noname_monnam(mtmp, ARTICLE_NONE));
  126.                      } else if (is_animal(mdat)) {
  127.                          Strcpy(msgtrail, "'s stomach");
  128.                      } else {
  129.                          msgtrail[0] = '\0';
  130.                      }
  131.  
  132.                      /* Do this even if msg is FALSE */
  133.                      You("%s %s%s!",
  134.                          (amorphous(olddata) || is_whirly(olddata))
  135.                              ? "emerge from" : "break out of",
  136.                          l_oldname, msgtrail);
  137.                      msg = FALSE; /* message has been given */
  138.                      mtmp->mhp = 1; /* almost dead */
  139.                  }
  140.                  expels(mtmp, olddata, FALSE);
  141.              } else {
  142.                  /* update swallow glyphs for new monster */
  143.                  swallowed(0);
  144.              }
  145.          } else if (!sticks(mdat) && !sticks(youmonst.data))
  146.              unstuck(mtmp);
  147.      }
  148.  
  149.  #ifndef DCC30_BUG
  150.      if (mdat == &mons[PM_LONG_WORM] && (mtmp->wormno = get_wormno()) != 0) {
  151.  #else
  152.      /* DICE 3.0 doesn't like assigning and comparing mtmp->wormno in the
  153.       * same expression.
  154.       */
  155.      if (mdat == &mons[PM_LONG_WORM]
  156.          && (mtmp->wormno = get_wormno(), mtmp->wormno != 0)) {
  157.  #endif
  158.          /* we can now create worms with tails - 11/91 */
  159.          initworm(mtmp, rn2(5));
  160.          if (count_wsegs(mtmp))
  161.              place_worm_tail_randomly(mtmp, mtmp->mx, mtmp->my);
  162.      }
  163.  
  164.      newsym(mtmp->mx, mtmp->my);
  165.  
  166.      if (msg) {
  167.          Strcpy(newname, noname_monnam(mtmp, ARTICLE_A));
  168.          /* oldname was capitalized above; newname will be lower case */
  169.          if (!strcmpi(newname, "it")) { /* can't see or sense it now */
  170.              if (!!strcmpi(oldname, "it")) /* could see or sense it before */
  171.                  pline("%s disappears!", oldname);
  172.              (void) usmellmon(mdat);
  173.          } else { /* can see or sense it now */
  174.              if (!strcmpi(oldname, "it")) /* couldn't see or sense it before */
  175.                  pline("%s appears!", upstart(newname));
  176.              else
  177.                  pline("%s turns into %s!", oldname, newname);
  178.          }
  179.      }
  180.  
  181.      /* when polymorph trap/wand/potion produces a vampire, turn in into
  182.         a full-fledged vampshifter unless shape-changing is blocked */
  183.      if (mtmp->cham == NON_PM && mdat->mlet == S_VAMPIRE
  184.          && !Protection_from_shape_changers)
  185.          mtmp->cham = pm_to_cham(monsndx(mdat));
  186.  
  187.      possibly_unwield(mtmp, polyspot); /* might lose use of weapon */
  188.      mon_break_armor(mtmp, polyspot);
  189.      if (!(mtmp->misc_worn_check & W_ARMG))
  190.          mselftouch(mtmp, "No longer petrify-resistant, ",
  191.                     !context.mon_moving);
  192.      m_dowear(mtmp, FALSE);
  193.  
  194.      /* This ought to re-test can_carry() on each item in the inventory
  195.       * rather than just checking ex-giants & boulders, but that'd be
  196.       * pretty expensive to perform.  If implemented, then perhaps
  197.       * minvent should be sorted in order to drop heaviest items first.
  198.       */
  199.      /* former giants can't continue carrying boulders */
  200.      if (mtmp->minvent && !throws_rocks(mdat)) {
  201.          register struct obj *otmp, *otmp2;
  202.  
  203.          for (otmp = mtmp->minvent; otmp; otmp = otmp2) {
  204.              otmp2 = otmp->nobj;
  205.              if (otmp->otyp == BOULDER) {
  206.                  /* this keeps otmp from being polymorphed in the
  207.                     same zap that the monster that held it is polymorphed */
  208.                  if (polyspot)
  209.                      bypass_obj(otmp);
  210.                  obj_extract_self(otmp);
  211.                  /* probably ought to give some "drop" message here */
  212.                  if (flooreffects(otmp, mtmp->mx, mtmp->my, ""))
  213.                      continue;
  214.                  place_object(otmp, mtmp->mx, mtmp->my);
  215.              }
  216.          }
  217.      }
  218.  
  219.      return 1;
  220.  }
  221.  
  222.  /* sometimes an egg will be special */
  223.  #define BREEDER_EGG (!rn2(77))
  224.  

can_be_hatched

  1.  /*
  2.   * Determine if the given monster number can be hatched from an egg.
  3.   * Return the monster number to use as the egg's corpsenm.  Return
  4.   * NON_PM if the given monster can't be hatched.
  5.   */
  6.  int
  7.  can_be_hatched(mnum)
  8.  int mnum;
  9.  {
  10.      /* ranger quest nemesis has the oviparous bit set, making it
  11.         be possible to wish for eggs of that unique monster; turn
  12.         such into ordinary eggs rather than forbidding them outright */
  13.      if (mnum == PM_SCORPIUS)
  14.          mnum = PM_SCORPION;
  15.  
  16.      mnum = little_to_big(mnum);
  17.      /*
  18.       * Queen bees lay killer bee eggs (usually), but killer bees don't
  19.       * grow into queen bees.  Ditto for [winged-]gargoyles.
  20.       */
  21.      if (mnum == PM_KILLER_BEE || mnum == PM_GARGOYLE
  22.          || (lays_eggs(&mons[mnum])
  23.              && (BREEDER_EGG
  24.                  || (mnum != PM_QUEEN_BEE && mnum != PM_WINGED_GARGOYLE))))
  25.          return mnum;
  26.      return NON_PM;
  27.  }
  28.  

egg_type_from_parent

  1.  /* type of egg laid by #sit; usually matches parent */
  2.  int
  3.  egg_type_from_parent(mnum, force_ordinary)
  4.  int mnum; /* parent monster; caller must handle lays_eggs() check */
  5.  boolean force_ordinary;
  6.  {
  7.      if (force_ordinary || !BREEDER_EGG) {
  8.          if (mnum == PM_QUEEN_BEE)
  9.              mnum = PM_KILLER_BEE;
  10.          else if (mnum == PM_WINGED_GARGOYLE)
  11.              mnum = PM_GARGOYLE;
  12.      }
  13.      return mnum;
  14.  }
  15.  

dead_species

  1.  /* decide whether an egg of the indicated monster type is viable;
  2.     also used to determine whether an egg or tin can be created... */
  3.  boolean
  4.  dead_species(m_idx, egg)
  5.  int m_idx;
  6.  boolean egg;
  7.  {
  8.      int alt_idx;
  9.  
  10.      /* generic eggs are unhatchable and have corpsenm of NON_PM */
  11.      if (m_idx < LOW_PM)
  12.          return TRUE;
  13.      /*
  14.       * For monsters with both baby and adult forms, genociding either
  15.       * form kills all eggs of that monster.  Monsters with more than
  16.       * two forms (small->large->giant mimics) are more or less ignored;
  17.       * fortunately, none of them have eggs.  Species extinction due to
  18.       * overpopulation does not kill eggs.
  19.       */
  20.      alt_idx = egg ? big_to_little(m_idx) : m_idx;
  21.      return (boolean) ((mvitals[m_idx].mvflags & G_GENOD) != 0
  22.                        || (mvitals[alt_idx].mvflags & G_GENOD) != 0);
  23.  }
  24.  

kill_eggs

  1.  /* kill off any eggs of genocided monsters */
  2.  STATIC_OVL void
  3.  kill_eggs(obj_list)
  4.  struct obj *obj_list;
  5.  {
  6.      struct obj *otmp;
  7.  
  8.      for (otmp = obj_list; otmp; otmp = otmp->nobj)
  9.          if (otmp->otyp == EGG) {
  10.              if (dead_species(otmp->corpsenm, TRUE)) {
  11.                  /*
  12.                   * It seems we could also just catch this when
  13.                   * it attempted to hatch, so we wouldn't have to
  14.                   * search all of the objlists.. or stop all
  15.                   * hatch timers based on a corpsenm.
  16.                   */
  17.                  kill_egg(otmp);
  18.              }
  19.  #if 0 /* not used */
  20.          } else if (otmp->otyp == TIN) {
  21.              if (dead_species(otmp->corpsenm, FALSE))
  22.                  otmp->corpsenm = NON_PM; /* empty tin */
  23.          } else if (otmp->otyp == CORPSE) {
  24.              if (dead_species(otmp->corpsenm, FALSE))
  25.                  ; /* not yet implemented... */
  26.  #endif
  27.          } else if (Has_contents(otmp)) {
  28.              kill_eggs(otmp->cobj);
  29.          }
  30.  }
  31.  

kill_genocided_monsters

  1.  /* kill all members of genocided species */
  2.  void
  3.  kill_genocided_monsters()
  4.  {
  5.      struct monst *mtmp, *mtmp2;
  6.      boolean kill_cham;
  7.      int mndx;
  8.  
  9.      /*
  10.       * Called during genocide, and again upon level change.  The latter
  11.       * catches up with any migrating monsters as they finally arrive at
  12.       * their intended destinations, so possessions get deposited there.
  13.       *
  14.       * Chameleon handling:
  15.       *  1) if chameleons have been genocided, destroy them
  16.       *     regardless of current form;
  17.       *  2) otherwise, force every chameleon which is imitating
  18.       *     any genocided species to take on a new form.
  19.       */
  20.      for (mtmp = fmon; mtmp; mtmp = mtmp2) {
  21.          mtmp2 = mtmp->nmon;
  22.          if (DEADMONSTER(mtmp))
  23.              continue;
  24.          mndx = monsndx(mtmp->data);
  25.          kill_cham = (mtmp->cham >= LOW_PM
  26.                       && (mvitals[mtmp->cham].mvflags & G_GENOD));
  27.          if ((mvitals[mndx].mvflags & G_GENOD) || kill_cham) {
  28.              if (mtmp->cham >= LOW_PM && !kill_cham)
  29.                  (void) newcham(mtmp, (struct permonst *) 0, FALSE, FALSE);
  30.              else
  31.                  mondead(mtmp);
  32.          }
  33.          if (mtmp->minvent)
  34.              kill_eggs(mtmp->minvent);
  35.      }
  36.  
  37.      kill_eggs(invent);
  38.      kill_eggs(fobj);
  39.      kill_eggs(migrating_objs);
  40.      kill_eggs(level.buriedobjlist);
  41.  }
  42.  

golemeffects

  1.  void
  2.  golemeffects(mon, damtype, dam)
  3.  register struct monst *mon;
  4.  int damtype, dam;
  5.  {
  6.      int heal = 0, slow = 0;
  7.  
  8.      if (mon->data == &mons[PM_FLESH_GOLEM]) {
  9.          if (damtype == AD_ELEC)
  10.              heal = (dam + 5) / 6;
  11.          else if (damtype == AD_FIRE || damtype == AD_COLD)
  12.              slow = 1;
  13.      } else if (mon->data == &mons[PM_IRON_GOLEM]) {
  14.          if (damtype == AD_ELEC)
  15.              slow = 1;
  16.          else if (damtype == AD_FIRE)
  17.              heal = dam;
  18.      } else {
  19.          return;
  20.      }
  21.      if (slow) {
  22.          if (mon->mspeed != MSLOW)
  23.              mon_adjust_speed(mon, -1, (struct obj *) 0);
  24.      }
  25.      if (heal) {
  26.          if (mon->mhp < mon->mhpmax) {
  27.              mon->mhp += heal;
  28.              if (mon->mhp > mon->mhpmax)
  29.                  mon->mhp = mon->mhpmax;
  30.              if (cansee(mon->mx, mon->my))
  31.                  pline("%s seems healthier.", Monnam(mon));
  32.          }
  33.      }
  34.  }
  35.  

angry_guards

  1.  boolean
  2.  angry_guards(silent)
  3.  boolean silent;
  4.  {
  5.      struct monst *mtmp;
  6.      int ct = 0, nct = 0, sct = 0, slct = 0;
  7.  
  8.      for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  9.          if (DEADMONSTER(mtmp))
  10.              continue;
  11.          if (is_watch(mtmp->data) && mtmp->mpeaceful) {
  12.              ct++;
  13.              if (cansee(mtmp->mx, mtmp->my) && mtmp->mcanmove) {
  14.                  if (distu(mtmp->mx, mtmp->my) == 2)
  15.                      nct++;
  16.                  else
  17.                      sct++;
  18.              }
  19.              if (mtmp->msleeping || mtmp->mfrozen) {
  20.                  slct++;
  21.                  mtmp->msleeping = mtmp->mfrozen = 0;
  22.              }
  23.              mtmp->mpeaceful = 0;
  24.          }
  25.      }
  26.      if (ct) {
  27.          if (!silent) { /* do we want pline msgs? */
  28.              if (slct)
  29.                  pline_The("guard%s wake%s up!", slct > 1 ? "s" : "",
  30.                            slct == 1 ? "s" : "");
  31.              if (nct || sct) {
  32.                  if (nct)
  33.                      pline_The("guard%s get%s angry!", nct == 1 ? "" : "s",
  34.                                nct == 1 ? "s" : "");
  35.                  else if (!Blind)
  36.                      You_see("%sangry guard%s approaching!",
  37.                              sct == 1 ? "an " : "", sct > 1 ? "s" : "");
  38.              } else
  39.                  You_hear("the shrill sound of a guard's whistle.");
  40.          }
  41.          return TRUE;
  42.      }
  43.      return FALSE;
  44.  }
  45.  

pacify_guards

  1.  void
  2.  pacify_guards()
  3.  {
  4.      struct monst *mtmp;
  5.  
  6.      for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  7.          if (DEADMONSTER(mtmp))
  8.              continue;
  9.          if (is_watch(mtmp->data))
  10.              mtmp->mpeaceful = 1;
  11.      }
  12.  }
  13.  

mimic_hit_msg

  1.  void
  2.  mimic_hit_msg(mtmp, otyp)
  3.  struct monst *mtmp;
  4.  short otyp;
  5.  {
  6.      short ap = mtmp->mappearance;
  7.  
  8.      switch (mtmp->m_ap_type) {
  9.      case M_AP_NOTHING:
  10.      case M_AP_FURNITURE:
  11.      case M_AP_MONSTER:
  12.          break;
  13.      case M_AP_OBJECT:
  14.          if (otyp == SPE_HEALING || otyp == SPE_EXTRA_HEALING) {
  15.              pline("%s seems a more vivid %s than before.",
  16.                    The(simple_typename(ap)),
  17.                    c_obj_colors[objects[ap].oc_color]);
  18.          }
  19.          break;
  20.      }
  21.  }
  22.  

usmellmon

  1.  boolean
  2.  usmellmon(mdat)
  3.  struct permonst *mdat;
  4.  {
  5.      int mndx;
  6.      boolean nonspecific = FALSE;
  7.      boolean msg_given = FALSE;
  8.  
  9.      if (mdat) {
  10.          if (!olfaction(youmonst.data))
  11.              return FALSE;
  12.          mndx = monsndx(mdat);
  13.          switch (mndx) {
  14.          case PM_ROTHE:
  15.          case PM_MINOTAUR:
  16.              You("notice a bovine smell.");
  17.              msg_given = TRUE;
  18.              break;
  19.          case PM_CAVEMAN:
  20.          case PM_CAVEWOMAN:
  21.          case PM_BARBARIAN:
  22.          case PM_NEANDERTHAL:
  23.              You("smell body odor.");
  24.              msg_given = TRUE;
  25.              break;
  26.          /*
  27.          case PM_PESTILENCE:
  28.          case PM_FAMINE:
  29.          case PM_DEATH:
  30.              break;
  31.          */
  32.          case PM_HORNED_DEVIL:
  33.          case PM_BALROG:
  34.          case PM_ASMODEUS:
  35.          case PM_DISPATER:
  36.          case PM_YEENOGHU:
  37.          case PM_ORCUS:
  38.              break;
  39.          case PM_HUMAN_WEREJACKAL:
  40.          case PM_HUMAN_WERERAT:
  41.          case PM_HUMAN_WEREWOLF:
  42.          case PM_WEREJACKAL:
  43.          case PM_WERERAT:
  44.          case PM_WEREWOLF:
  45.          case PM_OWLBEAR:
  46.              You("detect an odor reminiscent of an animal's den.");
  47.              msg_given = TRUE;
  48.              break;
  49.          /*
  50.          case PM_PURPLE_WORM:
  51.              break;
  52.          */
  53.          case PM_STEAM_VORTEX:
  54.              You("smell steam.");
  55.              msg_given = TRUE;
  56.              break;
  57.          case PM_GREEN_SLIME:
  58.              pline("%s stinks.", Something);
  59.              msg_given = TRUE;
  60.              break;
  61.          case PM_VIOLET_FUNGUS:
  62.          case PM_SHRIEKER:
  63.              You("smell mushrooms.");
  64.              msg_given = TRUE;
  65.              break;
  66.          /* These are here to avoid triggering the
  67.             nonspecific treatment through the default case below*/
  68.          case PM_WHITE_UNICORN:
  69.          case PM_GRAY_UNICORN:
  70.          case PM_BLACK_UNICORN:
  71.          case PM_JELLYFISH:
  72.              break;
  73.          default:
  74.              nonspecific = TRUE;
  75.              break;
  76.          }
  77.  
  78.          if (nonspecific)
  79.              switch (mdat->mlet) {
  80.              case S_DOG:
  81.                  You("notice a dog smell.");
  82.                  msg_given = TRUE;
  83.                  break;
  84.              case S_DRAGON:
  85.                  You("smell a dragon!");
  86.                  msg_given = TRUE;
  87.                  break;
  88.              case S_FUNGUS:
  89.                  pline("%s smells moldy.", Something);
  90.                  msg_given = TRUE;
  91.                  break;
  92.              case S_UNICORN:
  93.                  You("detect a%s odor reminiscent of a stable.",
  94.                      (mndx == PM_PONY) ? "n" : " strong");
  95.                  msg_given = TRUE;
  96.                  break;
  97.              case S_ZOMBIE:
  98.                  You("smell rotting flesh.");
  99.                  msg_given = TRUE;
  100.                  break;
  101.              case S_EEL:
  102.                  You("smell fish.");
  103.                  msg_given = TRUE;
  104.                  break;
  105.              case S_ORC:
  106.                  if (maybe_polyd(is_orc(youmonst.data), Race_if(PM_ORC)))
  107.                      You("notice an attractive smell.");
  108.                  else
  109.                      pline("A foul stench makes you feel a little nauseated.");
  110.                  msg_given = TRUE;
  111.                  break;
  112.              default:
  113.                  break;
  114.              }
  115.      }
  116.      return msg_given ? TRUE : FALSE;
  117.  }
  118.  
  119.  /*mon.c*/