Source:NetHack 3.6.0/src/muse.c

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

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

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

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

Top of file

  1.  /* NetHack 3.6	muse.c	$NHDT-Date: 1447987786 2015/11/20 02:49:46 $  $NHDT-Branch: master $:$NHDT-Revision: 1.68 $ */
  2.  /*      Copyright (C) 1990 by Ken Arromdee                         */
  3.  /* NetHack may be freely redistributed.  See license for details.  */
  4.  
  5.  /*
  6.   * Monster item usage routines.
  7.   */
  8.  
  9.  #include "hack.h"
  10.  
  11.  extern const int monstr[];
  12.  
  13.  boolean m_using = FALSE;
  14.  
  15.  /* Let monsters use magic items.  Arbitrary assumptions: Monsters only use
  16.   * scrolls when they can see, monsters know when wands have 0 charges,
  17.   * monsters cannot recognize if items are cursed are not, monsters which
  18.   * are confused don't know not to read scrolls, etc....
  19.   */
  20.  
  21.  STATIC_DCL struct permonst *FDECL(muse_newcham_mon, (struct monst *));
  22.  STATIC_DCL int FDECL(precheck, (struct monst *, struct obj *));
  23.  STATIC_DCL void FDECL(mzapmsg, (struct monst *, struct obj *, BOOLEAN_P));
  24.  STATIC_DCL void FDECL(mreadmsg, (struct monst *, struct obj *));
  25.  STATIC_DCL void FDECL(mquaffmsg, (struct monst *, struct obj *));
  26.  STATIC_PTR int FDECL(mbhitm, (struct monst *, struct obj *));
  27.  STATIC_DCL void FDECL(mbhit, (struct monst *, int,
  28.                                int FDECL((*), (MONST_P, OBJ_P)),
  29.                                int FDECL((*), (OBJ_P, OBJ_P)), struct obj *));
  30.  STATIC_DCL void FDECL(you_aggravate, (struct monst *));
  31.  STATIC_DCL void FDECL(mon_consume_unstone, (struct monst *, struct obj *,
  32.                                              BOOLEAN_P, BOOLEAN_P));
  33.  STATIC_DCL boolean FDECL(cures_stoning, (struct monst *, struct obj *,
  34.                                           BOOLEAN_P));
  35.  STATIC_DCL boolean FDECL(mcould_eat_tin, (struct monst *));
  36.  STATIC_DCL boolean FDECL(muse_unslime, (struct monst *, struct obj *,
  37.                                          BOOLEAN_P));
  38.  STATIC_DCL int FDECL(cures_sliming, (struct monst *, struct obj *));
  39.  STATIC_DCL boolean FDECL(green_mon, (struct monst *));
  40.  
  41.  static struct musable {
  42.      struct obj *offensive;
  43.      struct obj *defensive;
  44.      struct obj *misc;
  45.      int has_offense, has_defense, has_misc;
  46.      /* =0, no capability; otherwise, different numbers.
  47.       * If it's an object, the object is also set (it's 0 otherwise).
  48.       */
  49.  } m;
  50.  static int trapx, trapy;
  51.  static boolean zap_oseen; /* for wands which use mbhitm and are zapped at
  52.                             * players.  We usually want an oseen local to
  53.                             * the function, but this is impossible since the
  54.                             * function mbhitm has to be compatible with the
  55.                             * normal zap routines, and those routines don't
  56.                             * remember who zapped the wand. */
  57.  

precheck

  1.  /* Any preliminary checks which may result in the monster being unable to use
  2.   * the item.  Returns 0 if nothing happened, 2 if the monster can't do
  3.   * anything (i.e. it teleported) and 1 if it's dead.
  4.   */
  5.  STATIC_OVL int
  6.  precheck(mon, obj)
  7.  struct monst *mon;
  8.  struct obj *obj;
  9.  {
  10.      boolean vis;
  11.  
  12.      if (!obj)
  13.          return 0;
  14.      vis = cansee(mon->mx, mon->my);
  15.  
  16.      if (obj->oclass == POTION_CLASS) {
  17.          coord cc;
  18.          static const char *empty = "The potion turns out to be empty.";
  19.          const char *potion_descr;
  20.          struct monst *mtmp;
  21.  
  22.          potion_descr = OBJ_DESCR(objects[obj->otyp]);
  23.          if (potion_descr && !strcmp(potion_descr, "milky")) {
  24.              if (!(mvitals[PM_GHOST].mvflags & G_GONE)
  25.                  && !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_GHOST].born))) {
  26.                  if (!enexto(&cc, mon->mx, mon->my, &mons[PM_GHOST]))
  27.                      return 0;
  28.                  mquaffmsg(mon, obj);
  29.                  m_useup(mon, obj);
  30.                  mtmp = makemon(&mons[PM_GHOST], cc.x, cc.y, NO_MM_FLAGS);
  31.                  if (!mtmp) {
  32.                      if (vis)
  33.                          pline1(empty);
  34.                  } else {
  35.                      if (vis) {
  36.                          pline(
  37.                              "As %s opens the bottle, an enormous %s emerges!",
  38.                                mon_nam(mon),
  39.                                Hallucination ? rndmonnam(NULL)
  40.                                              : (const char *) "ghost");
  41.                          pline("%s is frightened to death, and unable to move.",
  42.                                Monnam(mon));
  43.                      }
  44.                      paralyze_monst(mon, 3);
  45.                  }
  46.                  return 2;
  47.              }
  48.          }
  49.          if (potion_descr && !strcmp(potion_descr, "smoky")
  50.              && !(mvitals[PM_DJINNI].mvflags & G_GONE)
  51.              && !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_DJINNI].born))) {
  52.              if (!enexto(&cc, mon->mx, mon->my, &mons[PM_DJINNI]))
  53.                  return 0;
  54.              mquaffmsg(mon, obj);
  55.              m_useup(mon, obj);
  56.              mtmp = makemon(&mons[PM_DJINNI], cc.x, cc.y, NO_MM_FLAGS);
  57.              if (!mtmp) {
  58.                  if (vis)
  59.                      pline1(empty);
  60.              } else {
  61.                  if (vis)
  62.                      pline("In a cloud of smoke, %s emerges!", a_monnam(mtmp));
  63.                  pline("%s speaks.", vis ? Monnam(mtmp) : Something);
  64.                  /* I suspect few players will be upset that monsters */
  65.                  /* can't wish for wands of death here.... */
  66.                  if (rn2(2)) {
  67.                      verbalize("You freed me!");
  68.                      mtmp->mpeaceful = 1;
  69.                      set_malign(mtmp);
  70.                  } else {
  71.                      verbalize("It is about time.");
  72.                      if (vis)
  73.                          pline("%s vanishes.", Monnam(mtmp));
  74.                      mongone(mtmp);
  75.                  }
  76.              }
  77.              return 2;
  78.          }
  79.      }
  80.      if (obj->oclass == WAND_CLASS && obj->cursed
  81.          && !rn2(WAND_BACKFIRE_CHANCE)) {
  82.          int dam = d(obj->spe + 2, 6);
  83.  
  84.          if (!Deaf) {
  85.              if (vis)
  86.                  pline("%s zaps %s, which suddenly explodes!", Monnam(mon),
  87.                        an(xname(obj)));
  88.              else
  89.                  You_hear("a zap and an explosion in the distance.");
  90.          }
  91.          m_useup(mon, obj);
  92.          if (mon->mhp <= dam) {
  93.              monkilled(mon, "", AD_RBRE);
  94.              return 1;
  95.          } else
  96.              mon->mhp -= dam;
  97.          m.has_defense = m.has_offense = m.has_misc = 0;
  98.          /* Only one needed to be set to 0 but the others are harmless */
  99.      }
  100.      return 0;
  101.  }
  102.  

Monster use messages

mzapmsg

  1.  STATIC_OVL void
  2.  mzapmsg(mtmp, otmp, self)
  3.  struct monst *mtmp;
  4.  struct obj *otmp;
  5.  boolean self;
  6.  {
  7.      if (!canseemon(mtmp)) {
  8.          if (!Deaf)
  9.              You_hear("a %s zap.", (distu(mtmp->mx, mtmp->my)
  10.                                     <= (BOLT_LIM + 1) * (BOLT_LIM + 1))
  11.                                        ? "nearby"
  12.                                        : "distant");
  13.      } else if (self) {
  14.          pline("%s zaps %sself with %s!", Monnam(mtmp), mhim(mtmp),
  15.                doname(otmp));
  16.      } else {
  17.          pline("%s zaps %s!", Monnam(mtmp), an(xname(otmp)));
  18.          stop_occupation();
  19.      }
  20.  }
  21.  

mreadmsg

  1.  STATIC_OVL void
  2.  mreadmsg(mtmp, otmp)
  3.  struct monst *mtmp;
  4.  struct obj *otmp;
  5.  {
  6.      boolean vismon = canseemon(mtmp);
  7.      char onambuf[BUFSZ];
  8.      short saverole;
  9.      unsigned savebknown;
  10.  
  11.      if (!vismon && Deaf)
  12.          return; /* no feedback */
  13.  
  14.      otmp->dknown = 1; /* seeing or hearing it read reveals its label */
  15.      /* shouldn't be able to hear curse/bless status of unseen scrolls;
  16.         for priest characters, bknown will always be set during naming */
  17.      savebknown = otmp->bknown;
  18.      saverole = Role_switch;
  19.      if (!vismon) {
  20.          otmp->bknown = 0;
  21.          if (Role_if(PM_PRIEST))
  22.              Role_switch = 0;
  23.      }
  24.      Strcpy(onambuf, singular(otmp, doname));
  25.      Role_switch = saverole;
  26.      otmp->bknown = savebknown;
  27.  
  28.      if (vismon)
  29.          pline("%s reads %s!", Monnam(mtmp), onambuf);
  30.      else
  31.          You_hear("%s reading %s.",
  32.                   x_monnam(mtmp, ARTICLE_A, (char *) 0,
  33.                            (SUPPRESS_IT | SUPPRESS_INVISIBLE | SUPPRESS_SADDLE),
  34.                            FALSE),
  35.                   onambuf);
  36.  
  37.      if (mtmp->mconf)
  38.          pline("Being confused, %s mispronounces the magic words...",
  39.                vismon ? mon_nam(mtmp) : mhe(mtmp));
  40.  }
  41.  

mquaffmsg

  1.  STATIC_OVL void
  2.  mquaffmsg(mtmp, otmp)
  3.  struct monst *mtmp;
  4.  struct obj *otmp;
  5.  {
  6.      if (canseemon(mtmp)) {
  7.          otmp->dknown = 1;
  8.          pline("%s drinks %s!", Monnam(mtmp), singular(otmp, doname));
  9.      } else if (!Deaf)
  10.          You_hear("a chugging sound.");
  11.  }
  12.  

Monster defense

  1.  /* Defines for various types of stuff.  The order in which monsters prefer
  2.   * to use them is determined by the order of the code logic, not the
  3.   * numerical order in which they are defined.
  4.   */
  5.  #define MUSE_SCR_TELEPORTATION 1
  6.  #define MUSE_WAN_TELEPORTATION_SELF 2
  7.  #define MUSE_POT_HEALING 3
  8.  #define MUSE_POT_EXTRA_HEALING 4
  9.  #define MUSE_WAN_DIGGING 5
  10.  #define MUSE_TRAPDOOR 6
  11.  #define MUSE_TELEPORT_TRAP 7
  12.  #define MUSE_UPSTAIRS 8
  13.  #define MUSE_DOWNSTAIRS 9
  14.  #define MUSE_WAN_CREATE_MONSTER 10
  15.  #define MUSE_SCR_CREATE_MONSTER 11
  16.  #define MUSE_UP_LADDER 12
  17.  #define MUSE_DN_LADDER 13
  18.  #define MUSE_SSTAIRS 14
  19.  #define MUSE_WAN_TELEPORTATION 15
  20.  #define MUSE_BUGLE 16
  21.  #define MUSE_UNICORN_HORN 17
  22.  #define MUSE_POT_FULL_HEALING 18
  23.  #define MUSE_LIZARD_CORPSE 19
  24.  /*
  25.  #define MUSE_INNATE_TPT 9999
  26.   * We cannot use this.  Since monsters get unlimited teleportation, if they
  27.   * were allowed to teleport at will you could never catch them.  Instead,
  28.   * assume they only teleport at random times, despite the inconsistency
  29.   * that if you polymorph into one you teleport at will.
  30.   */

find_defensive

  1.  
  2.  /* Select a defensive item/action for a monster.  Returns TRUE iff one is
  3.     found. */
  4.  boolean
  5.  find_defensive(mtmp)
  6.  struct monst *mtmp;
  7.  {
  8.      register struct obj *obj = 0;
  9.      struct trap *t;
  10.      int x = mtmp->mx, y = mtmp->my;
  11.      boolean stuck = (mtmp == u.ustuck);
  12.      boolean immobile = (mtmp->data->mmove == 0);
  13.      int fraction;
  14.  
  15.      if (is_animal(mtmp->data) || mindless(mtmp->data))
  16.          return FALSE;
  17.      if (dist2(x, y, mtmp->mux, mtmp->muy) > 25)
  18.          return FALSE;
  19.      if (u.uswallow && stuck)
  20.          return FALSE;
  21.  
  22.      m.defensive = (struct obj *) 0;
  23.      m.has_defense = 0;
  24.  
  25.      /* since unicorn horns don't get used up, the monster would look
  26.       * silly trying to use the same cursed horn round after round
  27.       */
  28.      if (mtmp->mconf || mtmp->mstun || !mtmp->mcansee) {
  29.          if (!is_unicorn(mtmp->data) && !nohands(mtmp->data)) {
  30.              for (obj = mtmp->minvent; obj; obj = obj->nobj)
  31.                  if (obj->otyp == UNICORN_HORN && !obj->cursed)
  32.                      break;
  33.          }
  34.          if (obj || is_unicorn(mtmp->data)) {
  35.              m.defensive = obj;
  36.              m.has_defense = MUSE_UNICORN_HORN;
  37.              return TRUE;
  38.          }
  39.      }
  40.  
  41.      if (mtmp->mconf || mtmp->mstun) {
  42.          struct obj *liztin = 0;
  43.  
  44.          for (obj = mtmp->minvent; obj; obj = obj->nobj) {
  45.              if (obj->otyp == CORPSE && obj->corpsenm == PM_LIZARD) {
  46.                  m.defensive = obj;
  47.                  m.has_defense = MUSE_LIZARD_CORPSE;
  48.                  return TRUE;
  49.              } else if (obj->otyp == TIN && obj->corpsenm == PM_LIZARD) {
  50.                  liztin = obj;
  51.              }
  52.          }
  53.          /* confused or stunned monster might not be able to open tin */
  54.          if (liztin && mcould_eat_tin(mtmp) && rn2(3)) {
  55.              m.defensive = liztin;
  56.              /* tin and corpse ultimately end up being handled the same */
  57.              m.has_defense = MUSE_LIZARD_CORPSE;
  58.              return TRUE;
  59.          }
  60.      }
  61.  
  62.      /* It so happens there are two unrelated cases when we might want to
  63.       * check specifically for healing alone.  The first is when the monster
  64.       * is blind (healing cures blindness).  The second is when the monster
  65.       * is peaceful; then we don't want to flee the player, and by
  66.       * coincidence healing is all there is that doesn't involve fleeing.
  67.       * These would be hard to combine because of the control flow.
  68.       * Pestilence won't use healing even when blind.
  69.       */
  70.      if (!mtmp->mcansee && !nohands(mtmp->data)
  71.          && mtmp->data != &mons[PM_PESTILENCE]) {
  72.          if ((obj = m_carrying(mtmp, POT_FULL_HEALING)) != 0) {
  73.              m.defensive = obj;
  74.              m.has_defense = MUSE_POT_FULL_HEALING;
  75.              return TRUE;
  76.          }
  77.          if ((obj = m_carrying(mtmp, POT_EXTRA_HEALING)) != 0) {
  78.              m.defensive = obj;
  79.              m.has_defense = MUSE_POT_EXTRA_HEALING;
  80.              return TRUE;
  81.          }
  82.          if ((obj = m_carrying(mtmp, POT_HEALING)) != 0) {
  83.              m.defensive = obj;
  84.              m.has_defense = MUSE_POT_HEALING;
  85.              return TRUE;
  86.          }
  87.      }
  88.  
  89.      fraction = u.ulevel < 10 ? 5 : u.ulevel < 14 ? 4 : 3;
  90.      if (mtmp->mhp >= mtmp->mhpmax
  91.          || (mtmp->mhp >= 10 && mtmp->mhp * fraction >= mtmp->mhpmax))
  92.          return FALSE;
  93.  
  94.      if (mtmp->mpeaceful) {
  95.          if (!nohands(mtmp->data)) {
  96.              if ((obj = m_carrying(mtmp, POT_FULL_HEALING)) != 0) {
  97.                  m.defensive = obj;
  98.                  m.has_defense = MUSE_POT_FULL_HEALING;
  99.                  return TRUE;
  100.              }
  101.              if ((obj = m_carrying(mtmp, POT_EXTRA_HEALING)) != 0) {
  102.                  m.defensive = obj;
  103.                  m.has_defense = MUSE_POT_EXTRA_HEALING;
  104.                  return TRUE;
  105.              }
  106.              if ((obj = m_carrying(mtmp, POT_HEALING)) != 0) {
  107.                  m.defensive = obj;
  108.                  m.has_defense = MUSE_POT_HEALING;
  109.                  return TRUE;
  110.              }
  111.          }
  112.          return FALSE;
  113.      }
  114.  
  115.      if (stuck || immobile) {
  116.          ; /* fleeing by stairs or traps is not possible */
  117.      } else if (levl[x][y].typ == STAIRS) {
  118.          if (x == xdnstair && y == ydnstair) {
  119.              if (!is_floater(mtmp->data))
  120.                  m.has_defense = MUSE_DOWNSTAIRS;
  121.          } else if (x == xupstair && y == yupstair) {
  122.              /* don't let monster leave the dungeon with the Amulet */
  123.              if (ledger_no(&u.uz) != 1)
  124.                  m.has_defense = MUSE_UPSTAIRS;
  125.          } else if (sstairs.sx && x == sstairs.sx && y == sstairs.sy) {
  126.              if (sstairs.up || !is_floater(mtmp->data))
  127.                  m.has_defense = MUSE_SSTAIRS;
  128.          }
  129.      } else if (levl[x][y].typ == LADDER) {
  130.          if (x == xupladder && y == yupladder) {
  131.              m.has_defense = MUSE_UP_LADDER;
  132.          } else if (x == xdnladder && y == ydnladder) {
  133.              if (!is_floater(mtmp->data))
  134.                  m.has_defense = MUSE_DN_LADDER;
  135.          } else if (sstairs.sx && x == sstairs.sx && y == sstairs.sy) {
  136.              if (sstairs.up || !is_floater(mtmp->data))
  137.                  m.has_defense = MUSE_SSTAIRS;
  138.          }
  139.      } else {
  140.          /* Note: trap doors take precedence over teleport traps. */
  141.          int xx, yy, i, locs[10][2];
  142.          boolean ignore_boulders = (verysmall(mtmp->data)
  143.                                     || throws_rocks(mtmp->data)
  144.                                     || passes_walls(mtmp->data)),
  145.              diag_ok = !NODIAG(monsndx(mtmp->data));
  146.  
  147.          for (i = 0; i < 10; ++i) /* 10: 9 spots plus sentinel */
  148.              locs[i][0] = locs[i][1] = 0;
  149.          /* collect viable spots; monster's <mx,my> comes first */
  150.          locs[0][0] = x, locs[0][1] = y;
  151.          i = 1;
  152.          for (xx = x - 1; xx <= x + 1; xx++)
  153.              for (yy = y - 1; yy <= y + 1; yy++)
  154.                  if (isok(xx, yy) && (xx != x || yy != y)) {
  155.                      locs[i][0] = xx, locs[i][1] = yy;
  156.                      ++i;
  157.                  }
  158.          /* look for a suitable trap among the viable spots */
  159.          for (i = 0; i < 10; ++i) {
  160.              xx = locs[i][0], yy = locs[i][1];
  161.              if (!xx)
  162.                  break; /* we've run out of spots */
  163.              /* skip if it's hero's location
  164.                 or a diagonal spot and monster can't move diagonally
  165.                 or some other monster is there */
  166.              if ((xx == u.ux && yy == u.uy)
  167.                  || (xx != x && yy != y && !diag_ok)
  168.                  || (level.monsters[xx][yy] && !(xx == x && yy == y)))
  169.                  continue;
  170.              /* skip if there's no trap or can't/won't move onto trap */
  171.              if ((t = t_at(xx, yy)) == 0
  172.                  || (!ignore_boulders && sobj_at(BOULDER, xx, yy))
  173.                  || onscary(xx, yy, mtmp))
  174.                  continue;
  175.              /* use trap if it's the correct type */
  176.              if ((t->ttyp == TRAPDOOR || t->ttyp == HOLE)
  177.                  && !is_floater(mtmp->data)
  178.                  && !mtmp->isshk && !mtmp->isgd && !mtmp->ispriest
  179.                  && Can_fall_thru(&u.uz)) {
  180.                  trapx = xx;
  181.                  trapy = yy;
  182.                  m.has_defense = MUSE_TRAPDOOR;
  183.                  break; /* no need to look at any other spots */
  184.              } else if (t->ttyp == TELEP_TRAP) {
  185.                  trapx = xx;
  186.                  trapy = yy;
  187.                  m.has_defense = MUSE_TELEPORT_TRAP;
  188.              }
  189.          }
  190.      }
  191.  
  192.      if (nohands(mtmp->data)) /* can't use objects */
  193.          goto botm;
  194.  
  195.      if (is_mercenary(mtmp->data) && (obj = m_carrying(mtmp, BUGLE)) != 0) {
  196.          int xx, yy;
  197.          struct monst *mon;
  198.  
  199.          /* Distance is arbitrary.  What we really want to do is
  200.           * have the soldier play the bugle when it sees or
  201.           * remembers soldiers nearby...
  202.           */
  203.          for (xx = x - 3; xx <= x + 3; xx++) {
  204.              for (yy = y - 3; yy <= y + 3; yy++) {
  205.                  if (!isok(xx, yy) || (xx == x && yy == y))
  206.                      continue;
  207.                  if ((mon = m_at(xx, yy)) != 0 && is_mercenary(mon->data)
  208.                      && mon->data != &mons[PM_GUARD]
  209.                      && (mon->msleeping || !mon->mcanmove)) {
  210.                      m.defensive = obj;
  211.                      m.has_defense = MUSE_BUGLE;
  212.                      goto toot; /* double break */
  213.                  }
  214.              }
  215.          }
  216.      toot:
  217.          ;
  218.      }
  219.  
  220.      /* use immediate physical escape prior to attempting magic */
  221.      if (m.has_defense) /* stairs, trap door or tele-trap, bugle alert */
  222.          goto botm;
  223.  
  224.      /* kludge to cut down on trap destruction (particularly portals) */
  225.      t = t_at(x, y);
  226.      if (t && (t->ttyp == PIT || t->ttyp == SPIKED_PIT || t->ttyp == WEB
  227.                || t->ttyp == BEAR_TRAP))
  228.          t = 0; /* ok for monster to dig here */
  229.  
  230.  #define nomore(x)       if (m.has_defense == x) continue;
  231.      /* selection could be improved by collecting all possibilities
  232.         into an array and then picking one at random */
  233.      for (obj = mtmp->minvent; obj; obj = obj->nobj) {
  234.          /* don't always use the same selection pattern */
  235.          if (m.has_defense && !rn2(3))
  236.              break;
  237.  
  238.          /* nomore(MUSE_WAN_DIGGING); */
  239.          if (m.has_defense == MUSE_WAN_DIGGING)
  240.              break;
  241.          if (obj->otyp == WAN_DIGGING && obj->spe > 0 && !stuck && !t
  242.              && !mtmp->isshk && !mtmp->isgd && !mtmp->ispriest
  243.              && !is_floater(mtmp->data)
  244.              /* monsters digging in Sokoban can ruin things */
  245.              && !Sokoban
  246.              /* digging wouldn't be effective; assume they know that */
  247.              && !(levl[x][y].wall_info & W_NONDIGGABLE)
  248.              && !(Is_botlevel(&u.uz) || In_endgame(&u.uz))
  249.              && !(is_ice(x, y) || is_pool(x, y) || is_lava(x, y))
  250.              && !(mtmp->data == &mons[PM_VLAD_THE_IMPALER]
  251.                   && In_V_tower(&u.uz))) {
  252.              m.defensive = obj;
  253.              m.has_defense = MUSE_WAN_DIGGING;
  254.          }
  255.          nomore(MUSE_WAN_TELEPORTATION_SELF);
  256.          nomore(MUSE_WAN_TELEPORTATION);
  257.          if (obj->otyp == WAN_TELEPORTATION && obj->spe > 0) {
  258.              /* use the TELEP_TRAP bit to determine if they know
  259.               * about noteleport on this level or not.  Avoids
  260.               * ineffective re-use of teleportation.  This does
  261.               * mean if the monster leaves the level, they'll know
  262.               * about teleport traps.
  263.               */
  264.              if (!level.flags.noteleport
  265.                  || !(mtmp->mtrapseen & (1 << (TELEP_TRAP - 1)))) {
  266.                  m.defensive = obj;
  267.                  m.has_defense = (mon_has_amulet(mtmp))
  268.                                      ? MUSE_WAN_TELEPORTATION
  269.                                      : MUSE_WAN_TELEPORTATION_SELF;
  270.              }
  271.          }
  272.          nomore(MUSE_SCR_TELEPORTATION);
  273.          if (obj->otyp == SCR_TELEPORTATION && mtmp->mcansee
  274.              && haseyes(mtmp->data)
  275.              && (!obj->cursed || (!(mtmp->isshk && inhishop(mtmp))
  276.                                   && !mtmp->isgd && !mtmp->ispriest))) {
  277.              /* see WAN_TELEPORTATION case above */
  278.              if (!level.flags.noteleport
  279.                  || !(mtmp->mtrapseen & (1 << (TELEP_TRAP - 1)))) {
  280.                  m.defensive = obj;
  281.                  m.has_defense = MUSE_SCR_TELEPORTATION;
  282.              }
  283.          }
  284.  
  285.          if (mtmp->data != &mons[PM_PESTILENCE]) {
  286.              nomore(MUSE_POT_FULL_HEALING);
  287.              if (obj->otyp == POT_FULL_HEALING) {
  288.                  m.defensive = obj;
  289.                  m.has_defense = MUSE_POT_FULL_HEALING;
  290.              }
  291.              nomore(MUSE_POT_EXTRA_HEALING);
  292.              if (obj->otyp == POT_EXTRA_HEALING) {
  293.                  m.defensive = obj;
  294.                  m.has_defense = MUSE_POT_EXTRA_HEALING;
  295.              }
  296.              nomore(MUSE_WAN_CREATE_MONSTER);
  297.              if (obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) {
  298.                  m.defensive = obj;
  299.                  m.has_defense = MUSE_WAN_CREATE_MONSTER;
  300.              }
  301.              nomore(MUSE_POT_HEALING);
  302.              if (obj->otyp == POT_HEALING) {
  303.                  m.defensive = obj;
  304.                  m.has_defense = MUSE_POT_HEALING;
  305.              }
  306.          } else { /* Pestilence */
  307.              nomore(MUSE_POT_FULL_HEALING);
  308.              if (obj->otyp == POT_SICKNESS) {
  309.                  m.defensive = obj;
  310.                  m.has_defense = MUSE_POT_FULL_HEALING;
  311.              }
  312.              nomore(MUSE_WAN_CREATE_MONSTER);
  313.              if (obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) {
  314.                  m.defensive = obj;
  315.                  m.has_defense = MUSE_WAN_CREATE_MONSTER;
  316.              }
  317.          }
  318.          nomore(MUSE_SCR_CREATE_MONSTER);
  319.          if (obj->otyp == SCR_CREATE_MONSTER) {
  320.              m.defensive = obj;
  321.              m.has_defense = MUSE_SCR_CREATE_MONSTER;
  322.          }
  323.      }
  324.  botm:
  325.      return (boolean) !!m.has_defense;
  326.  #undef nomore
  327.  }
  328.  

use_defensive

  1.  /* Perform a defensive action for a monster.  Must be called immediately
  2.   * after find_defensive().  Return values are 0: did something, 1: died,
  3.   * 2: did something and can't attack again (i.e. teleported).
  4.   */
  5.  int
  6.  use_defensive(mtmp)
  7.  struct monst *mtmp;
  8.  {
  9.      int i, fleetim, how = 0;
  10.      struct obj *otmp = m.defensive;
  11.      boolean vis, vismon, oseen;
  12.      const char *mcsa = "%s can see again.";
  13.  
  14.      if ((i = precheck(mtmp, otmp)) != 0)
  15.          return i;
  16.      vis = cansee(mtmp->mx, mtmp->my);
  17.      vismon = canseemon(mtmp);
  18.      oseen = otmp && vismon;
  19.  
  20.      /* when using defensive choice to run away, we want monster to avoid
  21.         rushing right straight back; don't override if already scared */
  22.      fleetim = !mtmp->mflee ? (33 - (30 * mtmp->mhp / mtmp->mhpmax)) : 0;
  23.  #define m_flee(m)                          \
  24.      if (fleetim && !m->iswiz) {            \
  25.          monflee(m, fleetim, FALSE, FALSE); \
  26.      }
  27.  
  28.      switch (m.has_defense) {
  29.      case MUSE_UNICORN_HORN:
  30.          if (vismon) {
  31.              if (otmp)
  32.                  pline("%s uses a unicorn horn!", Monnam(mtmp));
  33.              else
  34.                  pline_The("tip of %s's horn glows!", mon_nam(mtmp));
  35.          }
  36.          if (!mtmp->mcansee) {
  37.              mtmp->mcansee = 1;
  38.              mtmp->mblinded = 0;
  39.              if (vismon)
  40.                  pline(mcsa, Monnam(mtmp));
  41.          } else if (mtmp->mconf || mtmp->mstun) {
  42.              mtmp->mconf = mtmp->mstun = 0;
  43.              if (vismon)
  44.                  pline("%s seems steadier now.", Monnam(mtmp));
  45.          } else
  46.              impossible("No need for unicorn horn?");
  47.          return 2;
  48.      case MUSE_BUGLE:
  49.          if (vismon)
  50.              pline("%s plays %s!", Monnam(mtmp), doname(otmp));
  51.          else if (!Deaf)
  52.              You_hear("a bugle playing reveille!");
  53.          awaken_soldiers(mtmp);
  54.          return 2;
  55.      case MUSE_WAN_TELEPORTATION_SELF:
  56.          if ((mtmp->isshk && inhishop(mtmp)) || mtmp->isgd || mtmp->ispriest)
  57.              return 2;
  58.          m_flee(mtmp);
  59.          mzapmsg(mtmp, otmp, TRUE);
  60.          otmp->spe--;
  61.          how = WAN_TELEPORTATION;
  62.      mon_tele:
  63.          if (tele_restrict(mtmp)) { /* mysterious force... */
  64.              if (vismon && how)     /* mentions 'teleport' */
  65.                  makeknown(how);
  66.              /* monster learns that teleportation isn't useful here */
  67.              if (level.flags.noteleport)
  68.                  mtmp->mtrapseen |= (1 << (TELEP_TRAP - 1));
  69.              return 2;
  70.          }
  71.          if ((mon_has_amulet(mtmp) || On_W_tower_level(&u.uz)) && !rn2(3)) {
  72.              if (vismon)
  73.                  pline("%s seems disoriented for a moment.", Monnam(mtmp));
  74.              return 2;
  75.          }
  76.          if (oseen && how)
  77.              makeknown(how);
  78.          (void) rloc(mtmp, TRUE);
  79.          return 2;
  80.      case MUSE_WAN_TELEPORTATION:
  81.          zap_oseen = oseen;
  82.          mzapmsg(mtmp, otmp, FALSE);
  83.          otmp->spe--;
  84.          m_using = TRUE;
  85.          mbhit(mtmp, rn1(8, 6), mbhitm, bhito, otmp);
  86.          /* monster learns that teleportation isn't useful here */
  87.          if (level.flags.noteleport)
  88.              mtmp->mtrapseen |= (1 << (TELEP_TRAP - 1));
  89.          m_using = FALSE;
  90.          return 2;
  91.      case MUSE_SCR_TELEPORTATION: {
  92.          int obj_is_cursed = otmp->cursed;
  93.  
  94.          if (mtmp->isshk || mtmp->isgd || mtmp->ispriest)
  95.              return 2;
  96.          m_flee(mtmp);
  97.          mreadmsg(mtmp, otmp);
  98.          m_useup(mtmp, otmp); /* otmp might be free'ed */
  99.          how = SCR_TELEPORTATION;
  100.          if (obj_is_cursed || mtmp->mconf) {
  101.              int nlev;
  102.              d_level flev;
  103.  
  104.              if (mon_has_amulet(mtmp) || In_endgame(&u.uz)) {
  105.                  if (vismon)
  106.                      pline("%s seems very disoriented for a moment.",
  107.                            Monnam(mtmp));
  108.                  return 2;
  109.              }
  110.              nlev = random_teleport_level();
  111.              if (nlev == depth(&u.uz)) {
  112.                  if (vismon)
  113.                      pline("%s shudders for a moment.", Monnam(mtmp));
  114.                  return 2;
  115.              }
  116.              get_level(&flev, nlev);
  117.              migrate_to_level(mtmp, ledger_no(&flev), MIGR_RANDOM,
  118.                               (coord *) 0);
  119.              if (oseen)
  120.                  makeknown(SCR_TELEPORTATION);
  121.          } else
  122.              goto mon_tele;
  123.          return 2;
  124.      }
  125.      case MUSE_WAN_DIGGING: {
  126.          struct trap *ttmp;
  127.  
  128.          m_flee(mtmp);
  129.          mzapmsg(mtmp, otmp, FALSE);
  130.          otmp->spe--;
  131.          if (oseen)
  132.              makeknown(WAN_DIGGING);
  133.          if (IS_FURNITURE(levl[mtmp->mx][mtmp->my].typ)
  134.              || IS_DRAWBRIDGE(levl[mtmp->mx][mtmp->my].typ)
  135.              || (is_drawbridge_wall(mtmp->mx, mtmp->my) >= 0)
  136.              || (sstairs.sx && sstairs.sx == mtmp->mx
  137.                  && sstairs.sy == mtmp->my)) {
  138.              pline_The("digging ray is ineffective.");
  139.              return 2;
  140.          }
  141.          if (!Can_dig_down(&u.uz) && !levl[mtmp->mx][mtmp->my].candig) {
  142.              if (canseemon(mtmp))
  143.                  pline_The("%s here is too hard to dig in.",
  144.                            surface(mtmp->mx, mtmp->my));
  145.              return 2;
  146.          }
  147.          ttmp = maketrap(mtmp->mx, mtmp->my, HOLE);
  148.          if (!ttmp)
  149.              return 2;
  150.          seetrap(ttmp);
  151.          if (vis) {
  152.              pline("%s has made a hole in the %s.", Monnam(mtmp),
  153.                    surface(mtmp->mx, mtmp->my));
  154.              pline("%s %s through...", Monnam(mtmp),
  155.                    is_flyer(mtmp->data) ? "dives" : "falls");
  156.          } else if (!Deaf)
  157.              You_hear("%s crash through the %s.", something,
  158.                       surface(mtmp->mx, mtmp->my));
  159.          /* we made sure that there is a level for mtmp to go to */
  160.          migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_RANDOM,
  161.                           (coord *) 0);
  162.          return 2;
  163.      }
  164.      case MUSE_WAN_CREATE_MONSTER: {
  165.          coord cc;
  166.          /* pm: 0 => random, eel => aquatic, croc => amphibious */
  167.          struct permonst *pm =
  168.              !is_pool(mtmp->mx, mtmp->my)
  169.                  ? 0
  170.                  : &mons[u.uinwater ? PM_GIANT_EEL : PM_CROCODILE];
  171.          struct monst *mon;
  172.  
  173.          if (!enexto(&cc, mtmp->mx, mtmp->my, pm))
  174.              return 0;
  175.          mzapmsg(mtmp, otmp, FALSE);
  176.          otmp->spe--;
  177.          mon = makemon((struct permonst *) 0, cc.x, cc.y, NO_MM_FLAGS);
  178.          if (mon && canspotmon(mon) && oseen)
  179.              makeknown(WAN_CREATE_MONSTER);
  180.          return 2;
  181.      }
  182.      case MUSE_SCR_CREATE_MONSTER: {
  183.          coord cc;
  184.          struct permonst *pm = 0, *fish = 0;
  185.          int cnt = 1;
  186.          struct monst *mon;
  187.          boolean known = FALSE;
  188.  
  189.          if (!rn2(73))
  190.              cnt += rnd(4);
  191.          if (mtmp->mconf || otmp->cursed)
  192.              cnt += 12;
  193.          if (mtmp->mconf)
  194.              pm = fish = &mons[PM_ACID_BLOB];
  195.          else if (is_pool(mtmp->mx, mtmp->my))
  196.              fish = &mons[u.uinwater ? PM_GIANT_EEL : PM_CROCODILE];
  197.          mreadmsg(mtmp, otmp);
  198.          while (cnt--) {
  199.              /* `fish' potentially gives bias towards water locations;
  200.                 `pm' is what to actually create (0 => random) */
  201.              if (!enexto(&cc, mtmp->mx, mtmp->my, fish))
  202.                  break;
  203.              mon = makemon(pm, cc.x, cc.y, NO_MM_FLAGS);
  204.              if (mon && canspotmon(mon))
  205.                  known = TRUE;
  206.          }
  207.          /* The only case where we don't use oseen.  For wands, you
  208.           * have to be able to see the monster zap the wand to know
  209.           * what type it is.  For teleport scrolls, you have to see
  210.           * the monster to know it teleported.
  211.           */
  212.          if (known)
  213.              makeknown(SCR_CREATE_MONSTER);
  214.          else if (!objects[SCR_CREATE_MONSTER].oc_name_known
  215.                   && !objects[SCR_CREATE_MONSTER].oc_uname)
  216.              docall(otmp);
  217.          m_useup(mtmp, otmp);
  218.          return 2;
  219.      }
  220.      case MUSE_TRAPDOOR:
  221.          /* trap doors on "bottom" levels of dungeons are rock-drop
  222.           * trap doors, not holes in the floor.  We check here for
  223.           * safety.
  224.           */
  225.          if (Is_botlevel(&u.uz))
  226.              return 0;
  227.          m_flee(mtmp);
  228.          if (vis) {
  229.              struct trap *t = t_at(trapx, trapy);
  230.  
  231.              pline("%s %s into a %s!", Monnam(mtmp),
  232.                    makeplural(locomotion(mtmp->data, "jump")),
  233.                    t->ttyp == TRAPDOOR ? "trap door" : "hole");
  234.              if (levl[trapx][trapy].typ == SCORR) {
  235.                  levl[trapx][trapy].typ = CORR;
  236.                  unblock_point(trapx, trapy);
  237.              }
  238.              seetrap(t_at(trapx, trapy));
  239.          }
  240.  
  241.          /*  don't use rloc_to() because worm tails must "move" */
  242.          remove_monster(mtmp->mx, mtmp->my);
  243.          newsym(mtmp->mx, mtmp->my); /* update old location */
  244.          place_monster(mtmp, trapx, trapy);
  245.          if (mtmp->wormno)
  246.              worm_move(mtmp);
  247.          newsym(trapx, trapy);
  248.  
  249.          migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_RANDOM,
  250.                           (coord *) 0);
  251.          return 2;
  252.      case MUSE_UPSTAIRS:
  253.          /* Monsters without amulets escape the dungeon and are
  254.           * gone for good when they leave up the up stairs.
  255.           * Monsters with amulets would reach the endlevel,
  256.           * which we cannot allow since that would leave the
  257.           * player stranded.
  258.           */
  259.          if (ledger_no(&u.uz) == 1) {
  260.              if (mon_has_special(mtmp))
  261.                  return 0;
  262.              if (vismon)
  263.                  pline("%s escapes the dungeon!", Monnam(mtmp));
  264.              mongone(mtmp);
  265.              return 2;
  266.          }
  267.          m_flee(mtmp);
  268.          if (Inhell && mon_has_amulet(mtmp) && !rn2(4)
  269.              && (dunlev(&u.uz) < dunlevs_in_dungeon(&u.uz) - 3)) {
  270.              if (vismon)
  271.                  pline(
  272.      "As %s climbs the stairs, a mysterious force momentarily surrounds %s...",
  273.                        mon_nam(mtmp), mhim(mtmp));
  274.              /* simpler than for the player; this will usually be
  275.                 the Wizard and he'll immediately go right to the
  276.                 upstairs, so there's not much point in having any
  277.                 chance for a random position on the current level */
  278.              migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_RANDOM,
  279.                               (coord *) 0);
  280.          } else {
  281.              if (vismon)
  282.                  pline("%s escapes upstairs!", Monnam(mtmp));
  283.              migrate_to_level(mtmp, ledger_no(&u.uz) - 1, MIGR_STAIRS_DOWN,
  284.                               (coord *) 0);
  285.          }
  286.          return 2;
  287.      case MUSE_DOWNSTAIRS:
  288.          m_flee(mtmp);
  289.          if (vismon)
  290.              pline("%s escapes downstairs!", Monnam(mtmp));
  291.          migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_STAIRS_UP,
  292.                           (coord *) 0);
  293.          return 2;
  294.      case MUSE_UP_LADDER:
  295.          m_flee(mtmp);
  296.          if (vismon)
  297.              pline("%s escapes up the ladder!", Monnam(mtmp));
  298.          migrate_to_level(mtmp, ledger_no(&u.uz) - 1, MIGR_LADDER_DOWN,
  299.                           (coord *) 0);
  300.          return 2;
  301.      case MUSE_DN_LADDER:
  302.          m_flee(mtmp);
  303.          if (vismon)
  304.              pline("%s escapes down the ladder!", Monnam(mtmp));
  305.          migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_LADDER_UP,
  306.                           (coord *) 0);
  307.          return 2;
  308.      case MUSE_SSTAIRS:
  309.          m_flee(mtmp);
  310.          if (vismon)
  311.              pline("%s escapes %sstairs!", Monnam(mtmp),
  312.                    sstairs.up ? "up" : "down");
  313.          /* going from the Valley to Castle (Stronghold) has no sstairs
  314.             to target, but having sstairs.<sx,sy> == <0,0> will work the
  315.             same as specifying MIGR_RANDOM when mon_arrive() eventually
  316.             places the monster, so we can use MIGR_SSTAIRS unconditionally */
  317.          migrate_to_level(mtmp, ledger_no(&sstairs.tolev), MIGR_SSTAIRS,
  318.                           (coord *) 0);
  319.          return 2;
  320.      case MUSE_TELEPORT_TRAP:
  321.          m_flee(mtmp);
  322.          if (vis) {
  323.              pline("%s %s onto a teleport trap!", Monnam(mtmp),
  324.                    makeplural(locomotion(mtmp->data, "jump")));
  325.              seetrap(t_at(trapx, trapy));
  326.          }
  327.          /*  don't use rloc_to() because worm tails must "move" */
  328.          remove_monster(mtmp->mx, mtmp->my);
  329.          newsym(mtmp->mx, mtmp->my); /* update old location */
  330.          place_monster(mtmp, trapx, trapy);
  331.          if (mtmp->wormno)
  332.              worm_move(mtmp);
  333.          newsym(trapx, trapy);
  334.  
  335.          goto mon_tele;
  336.      case MUSE_POT_HEALING:
  337.          mquaffmsg(mtmp, otmp);
  338.          i = d(6 + 2 * bcsign(otmp), 4);
  339.          mtmp->mhp += i;
  340.          if (mtmp->mhp > mtmp->mhpmax)
  341.              mtmp->mhp = ++mtmp->mhpmax;
  342.          if (!otmp->cursed && !mtmp->mcansee) {
  343.              mtmp->mcansee = 1;
  344.              mtmp->mblinded = 0;
  345.              if (vismon)
  346.                  pline(mcsa, Monnam(mtmp));
  347.          }
  348.          if (vismon)
  349.              pline("%s looks better.", Monnam(mtmp));
  350.          if (oseen)
  351.              makeknown(POT_HEALING);
  352.          m_useup(mtmp, otmp);
  353.          return 2;
  354.      case MUSE_POT_EXTRA_HEALING:
  355.          mquaffmsg(mtmp, otmp);
  356.          i = d(6 + 2 * bcsign(otmp), 8);
  357.          mtmp->mhp += i;
  358.          if (mtmp->mhp > mtmp->mhpmax)
  359.              mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 5 : 2));
  360.          if (!mtmp->mcansee) {
  361.              mtmp->mcansee = 1;
  362.              mtmp->mblinded = 0;
  363.              if (vismon)
  364.                  pline(mcsa, Monnam(mtmp));
  365.          }
  366.          if (vismon)
  367.              pline("%s looks much better.", Monnam(mtmp));
  368.          if (oseen)
  369.              makeknown(POT_EXTRA_HEALING);
  370.          m_useup(mtmp, otmp);
  371.          return 2;
  372.      case MUSE_POT_FULL_HEALING:
  373.          mquaffmsg(mtmp, otmp);
  374.          if (otmp->otyp == POT_SICKNESS)
  375.              unbless(otmp); /* Pestilence */
  376.          mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 8 : 4));
  377.          if (!mtmp->mcansee && otmp->otyp != POT_SICKNESS) {
  378.              mtmp->mcansee = 1;
  379.              mtmp->mblinded = 0;
  380.              if (vismon)
  381.                  pline(mcsa, Monnam(mtmp));
  382.          }
  383.          if (vismon)
  384.              pline("%s looks completely healed.", Monnam(mtmp));
  385.          if (oseen)
  386.              makeknown(otmp->otyp);
  387.          m_useup(mtmp, otmp);
  388.          return 2;
  389.      case MUSE_LIZARD_CORPSE:
  390.          /* not actually called for its unstoning effect */
  391.          mon_consume_unstone(mtmp, otmp, FALSE, FALSE);
  392.          return 2;
  393.      case 0:
  394.          return 0; /* i.e. an exploded wand */
  395.      default:
  396.          impossible("%s wanted to perform action %d?", Monnam(mtmp),
  397.                     m.has_defense);
  398.          break;
  399.      }
  400.      return 0;
  401.  #undef m_flee
  402.  }
  403.  

rnd_defensive_item

  1.  int
  2.  rnd_defensive_item(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      struct permonst *pm = mtmp->data;
  6.      int difficulty = monstr[(monsndx(pm))];
  7.      int trycnt = 0;
  8.  
  9.      if (is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data)
  10.          || pm->mlet == S_GHOST || pm->mlet == S_KOP)
  11.          return 0;
  12.  try_again:
  13.      switch (rn2(8 + (difficulty > 3) + (difficulty > 6) + (difficulty > 8))) {
  14.      case 6:
  15.      case 9:
  16.          if (level.flags.noteleport && ++trycnt < 2)
  17.              goto try_again;
  18.          if (!rn2(3))
  19.              return WAN_TELEPORTATION;
  20.      /* else FALLTHRU */
  21.      case 0:
  22.      case 1:
  23.          return SCR_TELEPORTATION;
  24.      case 8:
  25.      case 10:
  26.          if (!rn2(3))
  27.              return WAN_CREATE_MONSTER;
  28.      /* else FALLTHRU */
  29.      case 2:
  30.          return SCR_CREATE_MONSTER;
  31.      case 3:
  32.          return POT_HEALING;
  33.      case 4:
  34.          return POT_EXTRA_HEALING;
  35.      case 5:
  36.          return (mtmp->data != &mons[PM_PESTILENCE]) ? POT_FULL_HEALING
  37.                                                      : POT_SICKNESS;
  38.      case 7:
  39.          if (is_floater(pm) || mtmp->isshk || mtmp->isgd || mtmp->ispriest)
  40.              return 0;
  41.          else
  42.              return WAN_DIGGING;
  43.      }
  44.      /*NOTREACHED*/
  45.      return 0;
  46.  }
  47.  

Monster offensive

  1.  #define MUSE_WAN_DEATH 1
  2.  #define MUSE_WAN_SLEEP 2
  3.  #define MUSE_WAN_FIRE 3
  4.  #define MUSE_WAN_COLD 4
  5.  #define MUSE_WAN_LIGHTNING 5
  6.  #define MUSE_WAN_MAGIC_MISSILE 6
  7.  #define MUSE_WAN_STRIKING 7
  8.  #define MUSE_SCR_FIRE 8
  9.  #define MUSE_POT_PARALYSIS 9
  10.  #define MUSE_POT_BLINDNESS 10
  11.  #define MUSE_POT_CONFUSION 11
  12.  #define MUSE_FROST_HORN 12
  13.  #define MUSE_FIRE_HORN 13
  14.  #define MUSE_POT_ACID 14
  15.  /*#define MUSE_WAN_TELEPORTATION 15*/
  16.  #define MUSE_POT_SLEEPING 16
  17.  #define MUSE_SCR_EARTH 17
  18.  

find_offensive

  1.  /* Select an offensive item/action for a monster.  Returns TRUE iff one is
  2.   * found.
  3.   */
  4.  boolean
  5.  find_offensive(mtmp)
  6.  struct monst *mtmp;
  7.  {
  8.      register struct obj *obj;
  9.      boolean reflection_skip = (Reflecting && rn2(2));
  10.      struct obj *helmet = which_armor(mtmp, W_ARMH);
  11.  
  12.      m.offensive = (struct obj *) 0;
  13.      m.has_offense = 0;
  14.      if (mtmp->mpeaceful || is_animal(mtmp->data) || mindless(mtmp->data)
  15.          || nohands(mtmp->data))
  16.          return FALSE;
  17.      if (u.uswallow)
  18.          return FALSE;
  19.      if (in_your_sanctuary(mtmp, 0, 0))
  20.          return FALSE;
  21.      if (dmgtype(mtmp->data, AD_HEAL)
  22.          && !uwep && !uarmu && !uarm && !uarmh
  23.          && !uarms && !uarmg && !uarmc && !uarmf)
  24.          return FALSE;
  25.      /* all offensive items require orthogonal or diagonal targetting */
  26.      if (!lined_up(mtmp))
  27.          return FALSE;
  28.  
  29.  #define nomore(x)       if (m.has_offense == x) continue;
  30.      /* this picks the last viable item rather than prioritizing choices */
  31.      for (obj = mtmp->minvent; obj; obj = obj->nobj) {
  32.          if (!reflection_skip) {
  33.              nomore(MUSE_WAN_DEATH);
  34.              if (obj->otyp == WAN_DEATH && obj->spe > 0) {
  35.                  m.offensive = obj;
  36.                  m.has_offense = MUSE_WAN_DEATH;
  37.              }
  38.              nomore(MUSE_WAN_SLEEP);
  39.              if (obj->otyp == WAN_SLEEP && obj->spe > 0 && multi >= 0) {
  40.                  m.offensive = obj;
  41.                  m.has_offense = MUSE_WAN_SLEEP;
  42.              }
  43.              nomore(MUSE_WAN_FIRE);
  44.              if (obj->otyp == WAN_FIRE && obj->spe > 0) {
  45.                  m.offensive = obj;
  46.                  m.has_offense = MUSE_WAN_FIRE;
  47.              }
  48.              nomore(MUSE_FIRE_HORN);
  49.              if (obj->otyp == FIRE_HORN && obj->spe > 0) {
  50.                  m.offensive = obj;
  51.                  m.has_offense = MUSE_FIRE_HORN;
  52.              }
  53.              nomore(MUSE_WAN_COLD);
  54.              if (obj->otyp == WAN_COLD && obj->spe > 0) {
  55.                  m.offensive = obj;
  56.                  m.has_offense = MUSE_WAN_COLD;
  57.              }
  58.              nomore(MUSE_FROST_HORN);
  59.              if (obj->otyp == FROST_HORN && obj->spe > 0) {
  60.                  m.offensive = obj;
  61.                  m.has_offense = MUSE_FROST_HORN;
  62.              }
  63.              nomore(MUSE_WAN_LIGHTNING);
  64.              if (obj->otyp == WAN_LIGHTNING && obj->spe > 0) {
  65.                  m.offensive = obj;
  66.                  m.has_offense = MUSE_WAN_LIGHTNING;
  67.              }
  68.              nomore(MUSE_WAN_MAGIC_MISSILE);
  69.              if (obj->otyp == WAN_MAGIC_MISSILE && obj->spe > 0) {
  70.                  m.offensive = obj;
  71.                  m.has_offense = MUSE_WAN_MAGIC_MISSILE;
  72.              }
  73.          }
  74.          nomore(MUSE_WAN_STRIKING);
  75.          if (obj->otyp == WAN_STRIKING && obj->spe > 0) {
  76.              m.offensive = obj;
  77.              m.has_offense = MUSE_WAN_STRIKING;
  78.          }
  79.          nomore(MUSE_POT_PARALYSIS);
  80.          if (obj->otyp == POT_PARALYSIS && multi >= 0) {
  81.              m.offensive = obj;
  82.              m.has_offense = MUSE_POT_PARALYSIS;
  83.          }
  84.          nomore(MUSE_POT_BLINDNESS);
  85.          if (obj->otyp == POT_BLINDNESS && !attacktype(mtmp->data, AT_GAZE)) {
  86.              m.offensive = obj;
  87.              m.has_offense = MUSE_POT_BLINDNESS;
  88.          }
  89.          nomore(MUSE_POT_CONFUSION);
  90.          if (obj->otyp == POT_CONFUSION) {
  91.              m.offensive = obj;
  92.              m.has_offense = MUSE_POT_CONFUSION;
  93.          }
  94.          nomore(MUSE_POT_SLEEPING);
  95.          if (obj->otyp == POT_SLEEPING) {
  96.              m.offensive = obj;
  97.              m.has_offense = MUSE_POT_SLEEPING;
  98.          }
  99.          nomore(MUSE_POT_ACID);
  100.          if (obj->otyp == POT_ACID) {
  101.              m.offensive = obj;
  102.              m.has_offense = MUSE_POT_ACID;
  103.          }
  104.          /* we can safely put this scroll here since the locations that
  105.           * are in a 1 square radius are a subset of the locations that
  106.           * are in wand or throwing range (in other words, always lined_up())
  107.           */
  108.          nomore(MUSE_SCR_EARTH);
  109.          if (obj->otyp == SCR_EARTH
  110.              && ((helmet && is_metallic(helmet)) || mtmp->mconf
  111.                  || amorphous(mtmp->data) || passes_walls(mtmp->data)
  112.                  || noncorporeal(mtmp->data) || unsolid(mtmp->data)
  113.                  || !rn2(10))
  114.              && dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 2
  115.              && mtmp->mcansee && haseyes(mtmp->data)
  116.              && !Is_rogue_level(&u.uz)
  117.              && (!In_endgame(&u.uz) || Is_earthlevel(&u.uz))) {
  118.              m.offensive = obj;
  119.              m.has_offense = MUSE_SCR_EARTH;
  120.          }
  121.  #if 0
  122.          nomore(MUSE_SCR_FIRE);
  123.          if (obj->otyp == SCR_FIRE && resists_fire(mtmp)
  124.              && dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 2
  125.              && mtmp->mcansee && haseyes(mtmp->data)) {
  126.              m.offensive = obj;
  127.              m.has_offense = MUSE_SCR_FIRE;
  128.          }
  129.  #endif /* 0 */
  130.      }
  131.      return (boolean) !!m.has_offense;
  132.  #undef nomore
  133.  }
  134.  

mbhitm

  1.  STATIC_PTR
  2.  int
  3.  mbhitm(mtmp, otmp)
  4.  register struct monst *mtmp;
  5.  register struct obj *otmp;
  6.  {
  7.      int tmp;
  8.  
  9.      boolean reveal_invis = FALSE;
  10.      if (mtmp != &youmonst) {
  11.          mtmp->msleeping = 0;
  12.          if (mtmp->m_ap_type)
  13.              seemimic(mtmp);
  14.      }
  15.      switch (otmp->otyp) {
  16.      case WAN_STRIKING:
  17.          reveal_invis = TRUE;
  18.          if (mtmp == &youmonst) {
  19.              if (zap_oseen)
  20.                  makeknown(WAN_STRIKING);
  21.              if (Antimagic) {
  22.                  shieldeff(u.ux, u.uy);
  23.                  pline("Boing!");
  24.              } else if (rnd(20) < 10 + u.uac) {
  25.                  pline_The("wand hits you!");
  26.                  tmp = d(2, 12);
  27.                  if (Half_spell_damage)
  28.                      tmp = (tmp + 1) / 2;
  29.                  losehp(tmp, "wand", KILLED_BY_AN);
  30.              } else
  31.                  pline_The("wand misses you.");
  32.              stop_occupation();
  33.              nomul(0);
  34.          } else if (resists_magm(mtmp)) {
  35.              shieldeff(mtmp->mx, mtmp->my);
  36.              pline("Boing!");
  37.          } else if (rnd(20) < 10 + find_mac(mtmp)) {
  38.              tmp = d(2, 12);
  39.              hit("wand", mtmp, exclam(tmp));
  40.              (void) resist(mtmp, otmp->oclass, tmp, TELL);
  41.              if (cansee(mtmp->mx, mtmp->my) && zap_oseen)
  42.                  makeknown(WAN_STRIKING);
  43.          } else {
  44.              miss("wand", mtmp);
  45.              if (cansee(mtmp->mx, mtmp->my) && zap_oseen)
  46.                  makeknown(WAN_STRIKING);
  47.          }
  48.          break;
  49.      case WAN_TELEPORTATION:
  50.          if (mtmp == &youmonst) {
  51.              if (zap_oseen)
  52.                  makeknown(WAN_TELEPORTATION);
  53.              tele();
  54.          } else {
  55.              /* for consistency with zap.c, don't identify */
  56.              if (mtmp->ispriest && *in_rooms(mtmp->mx, mtmp->my, TEMPLE)) {
  57.                  if (cansee(mtmp->mx, mtmp->my))
  58.                      pline("%s resists the magic!", Monnam(mtmp));
  59.              } else if (!tele_restrict(mtmp))
  60.                  (void) rloc(mtmp, TRUE);
  61.          }
  62.          break;
  63.      case WAN_CANCELLATION:
  64.      case SPE_CANCELLATION:
  65.          (void) cancel_monst(mtmp, otmp, FALSE, TRUE, FALSE);
  66.          break;
  67.      }
  68.      if (reveal_invis) {
  69.          if (mtmp->mhp > 0 && cansee(bhitpos.x, bhitpos.y)
  70.              && !canspotmon(mtmp))
  71.              map_invisible(bhitpos.x, bhitpos.y);
  72.      }
  73.      return 0;
  74.  }
  75.  

mbhit

  1.  /* A modified bhit() for monsters.  Based on bhit() in zap.c.  Unlike
  2.   * buzz(), bhit() doesn't take into account the possibility of a monster
  3.   * zapping you, so we need a special function for it.  (Unless someone wants
  4.   * to merge the two functions...)
  5.   */
  6.  STATIC_OVL void
  7.  mbhit(mon, range, fhitm, fhito, obj)
  8.  struct monst *mon;  /* monster shooting the wand */
  9.  register int range; /* direction and range */
  10.  int FDECL((*fhitm), (MONST_P, OBJ_P));
  11.  int FDECL((*fhito), (OBJ_P, OBJ_P)); /* fns called when mon/obj hit */
  12.  struct obj *obj;                     /* 2nd arg to fhitm/fhito */
  13.  {
  14.      register struct monst *mtmp;
  15.      register struct obj *otmp;
  16.      register uchar typ;
  17.      int ddx, ddy;
  18.  
  19.      bhitpos.x = mon->mx;
  20.      bhitpos.y = mon->my;
  21.      ddx = sgn(mon->mux - mon->mx);
  22.      ddy = sgn(mon->muy - mon->my);
  23.  
  24.      while (range-- > 0) {
  25.          int x, y;
  26.  
  27.          bhitpos.x += ddx;
  28.          bhitpos.y += ddy;
  29.          x = bhitpos.x;
  30.          y = bhitpos.y;
  31.  
  32.          if (!isok(x, y)) {
  33.              bhitpos.x -= ddx;
  34.              bhitpos.y -= ddy;
  35.              break;
  36.          }
  37.          if (find_drawbridge(&x, &y))
  38.              switch (obj->otyp) {
  39.              case WAN_STRIKING:
  40.                  destroy_drawbridge(x, y);
  41.              }
  42.          if (bhitpos.x == u.ux && bhitpos.y == u.uy) {
  43.              (*fhitm)(&youmonst, obj);
  44.              range -= 3;
  45.          } else if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) {
  46.              if (cansee(bhitpos.x, bhitpos.y) && !canspotmon(mtmp))
  47.                  map_invisible(bhitpos.x, bhitpos.y);
  48.              (*fhitm)(mtmp, obj);
  49.              range -= 3;
  50.          }
  51.          /* modified by GAN to hit all objects */
  52.          if (fhito) {
  53.              int hitanything = 0;
  54.              register struct obj *next_obj;
  55.  
  56.              for (otmp = level.objects[bhitpos.x][bhitpos.y]; otmp;
  57.                   otmp = next_obj) {
  58.                  /* Fix for polymorph bug, Tim Wright */
  59.                  next_obj = otmp->nexthere;
  60.                  hitanything += (*fhito)(otmp, obj);
  61.              }
  62.              if (hitanything)
  63.                  range--;
  64.          }
  65.          typ = levl[bhitpos.x][bhitpos.y].typ;
  66.          if (IS_DOOR(typ) || typ == SDOOR) {
  67.              switch (obj->otyp) {
  68.              /* note: monsters don't use opening or locking magic
  69.                 at present, but keep these as placeholders */
  70.              case WAN_OPENING:
  71.              case WAN_LOCKING:
  72.              case WAN_STRIKING:
  73.                  if (doorlock(obj, bhitpos.x, bhitpos.y)) {
  74.                      if (zap_oseen)
  75.                          makeknown(obj->otyp);
  76.                      /* if a shop door gets broken, add it to
  77.                         the shk's fix list (no cost to player) */
  78.                      if (levl[bhitpos.x][bhitpos.y].doormask == D_BROKEN
  79.                          && *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE))
  80.                          add_damage(bhitpos.x, bhitpos.y, 0L);
  81.                  }
  82.                  break;
  83.              }
  84.          }
  85.          if (!ZAP_POS(typ)
  86.              || (IS_DOOR(typ) && (levl[bhitpos.x][bhitpos.y].doormask
  87.                                   & (D_LOCKED | D_CLOSED)))) {
  88.              bhitpos.x -= ddx;
  89.              bhitpos.y -= ddy;
  90.              break;
  91.          }
  92.      }
  93.  }
  94.  

use_offensive

  1.  /* Perform an offensive action for a monster.  Must be called immediately
  2.   * after find_offensive().  Return values are same as use_defensive().
  3.   */
  4.  int
  5.  use_offensive(mtmp)
  6.  struct monst *mtmp;
  7.  {
  8.      int i;
  9.      struct obj *otmp = m.offensive;
  10.      boolean oseen;
  11.  
  12.      /* offensive potions are not drunk, they're thrown */
  13.      if (otmp->oclass != POTION_CLASS && (i = precheck(mtmp, otmp)) != 0)
  14.          return i;
  15.      oseen = otmp && canseemon(mtmp);
  16.  
  17.      switch (m.has_offense) {
  18.      case MUSE_WAN_DEATH:
  19.      case MUSE_WAN_SLEEP:
  20.      case MUSE_WAN_FIRE:
  21.      case MUSE_WAN_COLD:
  22.      case MUSE_WAN_LIGHTNING:
  23.      case MUSE_WAN_MAGIC_MISSILE:
  24.          mzapmsg(mtmp, otmp, FALSE);
  25.          otmp->spe--;
  26.          if (oseen)
  27.              makeknown(otmp->otyp);
  28.          m_using = TRUE;
  29.          buzz((int) (-30 - (otmp->otyp - WAN_MAGIC_MISSILE)),
  30.               (otmp->otyp == WAN_MAGIC_MISSILE) ? 2 : 6, mtmp->mx, mtmp->my,
  31.               sgn(mtmp->mux - mtmp->mx), sgn(mtmp->muy - mtmp->my));
  32.          m_using = FALSE;
  33.          return (mtmp->mhp <= 0) ? 1 : 2;
  34.      case MUSE_FIRE_HORN:
  35.      case MUSE_FROST_HORN:
  36.          if (oseen) {
  37.              makeknown(otmp->otyp);
  38.              pline("%s plays a %s!", Monnam(mtmp), xname(otmp));
  39.          } else
  40.              You_hear("a horn being played.");
  41.          otmp->spe--;
  42.          m_using = TRUE;
  43.          buzz(-30 - ((otmp->otyp == FROST_HORN) ? AD_COLD - 1 : AD_FIRE - 1),
  44.               rn1(6, 6), mtmp->mx, mtmp->my, sgn(mtmp->mux - mtmp->mx),
  45.               sgn(mtmp->muy - mtmp->my));
  46.          m_using = FALSE;
  47.          return (mtmp->mhp <= 0) ? 1 : 2;
  48.      case MUSE_WAN_TELEPORTATION:
  49.      case MUSE_WAN_STRIKING:
  50.          zap_oseen = oseen;
  51.          mzapmsg(mtmp, otmp, FALSE);
  52.          otmp->spe--;
  53.          m_using = TRUE;
  54.          mbhit(mtmp, rn1(8, 6), mbhitm, bhito, otmp);
  55.          m_using = FALSE;
  56.          return 2;
  57.      case MUSE_SCR_EARTH: {
  58.          /* TODO: handle steeds */
  59.          register int x, y;
  60.          /* don't use monster fields after killing it */
  61.          boolean confused = (mtmp->mconf ? TRUE : FALSE);
  62.          int mmx = mtmp->mx, mmy = mtmp->my;
  63.          boolean is_cursed = otmp->cursed;
  64.  
  65.          mreadmsg(mtmp, otmp);
  66.          /* Identify the scroll */
  67.          if (canspotmon(mtmp)) {
  68.              pline_The("%s rumbles %s %s!", ceiling(mtmp->mx, mtmp->my),
  69.                        otmp->blessed ? "around" : "above", mon_nam(mtmp));
  70.              if (oseen)
  71.                  makeknown(otmp->otyp);
  72.          } else if (cansee(mtmp->mx, mtmp->my)) {
  73.              pline_The("%s rumbles in the middle of nowhere!",
  74.                        ceiling(mtmp->mx, mtmp->my));
  75.              if (mtmp->minvis)
  76.                  map_invisible(mtmp->mx, mtmp->my);
  77.              if (oseen)
  78.                  makeknown(otmp->otyp);
  79.          }
  80.  
  81.          /* Loop through the surrounding squares */
  82.          for (x = mmx - 1; x <= mmx + 1; x++) {
  83.              for (y = mmy - 1; y <= mmy + 1; y++) {
  84.                  /* Is this a suitable spot? */
  85.                  if (isok(x, y) && !closed_door(x, y)
  86.                      && !IS_ROCK(levl[x][y].typ) && !IS_AIR(levl[x][y].typ)
  87.                      && (((x == mmx) && (y == mmy)) ? !otmp->blessed
  88.                                                     : !otmp->cursed)
  89.                      && (x != u.ux || y != u.uy)) {
  90.                      (void) drop_boulder_on_monster(x, y, confused, FALSE);
  91.                  }
  92.              }
  93.          }
  94.          m_useup(mtmp, otmp);
  95.          /* Attack the player */
  96.          if (distmin(mmx, mmy, u.ux, u.uy) == 1 && !is_cursed) {
  97.              drop_boulder_on_player(confused, !is_cursed, FALSE, TRUE);
  98.          }
  99.  
  100.          return (mtmp->mhp <= 0) ? 1 : 2;
  101.      }
  102.  #if 0
  103.      case MUSE_SCR_FIRE: {
  104.          boolean vis = cansee(mtmp->mx, mtmp->my);
  105.  
  106.          mreadmsg(mtmp, otmp);
  107.          if (mtmp->mconf) {
  108.              if (vis)
  109.                  pline("Oh, what a pretty fire!");
  110.          } else {
  111.              struct monst *mtmp2;
  112.              int num;
  113.  
  114.              if (vis)
  115.                  pline_The("scroll erupts in a tower of flame!");
  116.              shieldeff(mtmp->mx, mtmp->my);
  117.              pline("%s is uninjured.", Monnam(mtmp));
  118.              (void) destroy_mitem(mtmp, SCROLL_CLASS, AD_FIRE);
  119.              (void) destroy_mitem(mtmp, SPBOOK_CLASS, AD_FIRE);
  120.              (void) destroy_mitem(mtmp, POTION_CLASS, AD_FIRE);
  121.              num = (2 * (rn1(3, 3) + 2 * bcsign(otmp)) + 1) / 3;
  122.              if (Fire_resistance)
  123.                  You("are not harmed.");
  124.              burn_away_slime();
  125.              if (Half_spell_damage)
  126.                  num = (num + 1) / 2;
  127.              else
  128.                  losehp(num, "scroll of fire", KILLED_BY_AN);
  129.              for (mtmp2 = fmon; mtmp2; mtmp2 = mtmp2->nmon) {
  130.                  if (DEADMONSTER(mtmp2)) continue;
  131.                  if (mtmp == mtmp2) continue;
  132.                  if (dist2(mtmp2->mx, mtmp2->my, mtmp->mx, mtmp->my) < 3) {
  133.                      if (resists_fire(mtmp2)) continue;
  134.                      mtmp2->mhp -= num;
  135.                      if (resists_cold(mtmp2))
  136.                          mtmp2->mhp -= 3 * num;
  137.                      if (mtmp2->mhp < 1) {
  138.                          mondied(mtmp2);
  139.                          break;
  140.                      }
  141.                  }
  142.              }
  143.          }
  144.          return 2;
  145.      }
  146.  #endif /* 0 */
  147.      case MUSE_POT_PARALYSIS:
  148.      case MUSE_POT_BLINDNESS:
  149.      case MUSE_POT_CONFUSION:
  150.      case MUSE_POT_SLEEPING:
  151.      case MUSE_POT_ACID:
  152.          /* Note: this setting of dknown doesn't suffice.  A monster
  153.           * which is out of sight might throw and it hits something _in_
  154.           * sight, a problem not existing with wands because wand rays
  155.           * are not objects.  Also set dknown in mthrowu.c.
  156.           */
  157.          if (cansee(mtmp->mx, mtmp->my)) {
  158.              otmp->dknown = 1;
  159.              pline("%s hurls %s!", Monnam(mtmp), singular(otmp, doname));
  160.          }
  161.          m_throw(mtmp, mtmp->mx, mtmp->my, sgn(mtmp->mux - mtmp->mx),
  162.                  sgn(mtmp->muy - mtmp->my),
  163.                  distmin(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy), otmp);
  164.          return 2;
  165.      case 0:
  166.          return 0; /* i.e. an exploded wand */
  167.      default:
  168.          impossible("%s wanted to perform action %d?", Monnam(mtmp),
  169.                     m.has_offense);
  170.          break;
  171.      }
  172.      return 0;
  173.  }
  174.  

rnd_offensive_item

  1.  int
  2.  rnd_offensive_item(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      struct permonst *pm = mtmp->data;
  6.      int difficulty = monstr[(monsndx(pm))];
  7.  
  8.      if (is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data)
  9.          || pm->mlet == S_GHOST || pm->mlet == S_KOP)
  10.          return 0;
  11.      if (difficulty > 7 && !rn2(35))
  12.          return WAN_DEATH;
  13.      switch (rn2(9 - (difficulty < 4) + 4 * (difficulty > 6))) {
  14.      case 0: {
  15.          struct obj *helmet = which_armor(mtmp, W_ARMH);
  16.  
  17.          if ((helmet && is_metallic(helmet)) || amorphous(pm)
  18.              || passes_walls(pm) || noncorporeal(pm) || unsolid(pm))
  19.              return SCR_EARTH;
  20.      } /* fall through */
  21.      case 1:
  22.          return WAN_STRIKING;
  23.      case 2:
  24.          return POT_ACID;
  25.      case 3:
  26.          return POT_CONFUSION;
  27.      case 4:
  28.          return POT_BLINDNESS;
  29.      case 5:
  30.          return POT_SLEEPING;
  31.      case 6:
  32.          return POT_PARALYSIS;
  33.      case 7:
  34.      case 8:
  35.          return WAN_MAGIC_MISSILE;
  36.      case 9:
  37.          return WAN_SLEEP;
  38.      case 10:
  39.          return WAN_FIRE;
  40.      case 11:
  41.          return WAN_COLD;
  42.      case 12:
  43.          return WAN_LIGHTNING;
  44.      }
  45.      /*NOTREACHED*/
  46.      return 0;
  47.  }
  48.  

Miscellaenous

  1.  #define MUSE_POT_GAIN_LEVEL 1
  2.  #define MUSE_WAN_MAKE_INVISIBLE 2
  3.  #define MUSE_POT_INVISIBILITY 3
  4.  #define MUSE_POLY_TRAP 4
  5.  #define MUSE_WAN_POLYMORPH 5
  6.  #define MUSE_POT_SPEED 6
  7.  #define MUSE_WAN_SPEED_MONSTER 7
  8.  #define MUSE_BULLWHIP 8
  9.  #define MUSE_POT_POLYMORPH 9
  10.  

find_misc

  1.  boolean
  2.  find_misc(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      register struct obj *obj;
  6.      struct permonst *mdat = mtmp->data;
  7.      int x = mtmp->mx, y = mtmp->my;
  8.      struct trap *t;
  9.      int xx, yy, pmidx = NON_PM;
  10.      boolean immobile = (mdat->mmove == 0);
  11.      boolean stuck = (mtmp == u.ustuck);
  12.  
  13.      m.misc = (struct obj *) 0;
  14.      m.has_misc = 0;
  15.      if (is_animal(mdat) || mindless(mdat))
  16.          return 0;
  17.      if (u.uswallow && stuck)
  18.          return FALSE;
  19.  
  20.      /* We arbitrarily limit to times when a player is nearby for the
  21.       * same reason as Junior Pac-Man doesn't have energizers eaten until
  22.       * you can see them...
  23.       */
  24.      if (dist2(x, y, mtmp->mux, mtmp->muy) > 36)
  25.          return FALSE;
  26.  
  27.      if (!stuck && !immobile && (mtmp->cham == NON_PM)
  28.          && monstr[(pmidx = monsndx(mdat))] < 6) {
  29.          boolean ignore_boulders = (verysmall(mdat) || throws_rocks(mdat)
  30.                                     || passes_walls(mdat)),
  31.              diag_ok = !NODIAG(pmidx);
  32.  
  33.          for (xx = x - 1; xx <= x + 1; xx++)
  34.              for (yy = y - 1; yy <= y + 1; yy++)
  35.                  if (isok(xx, yy) && (xx != u.ux || yy != u.uy)
  36.                      && (diag_ok || xx == x || yy == y)
  37.                      && ((xx == x && yy == y) || !level.monsters[xx][yy]))
  38.                      if ((t = t_at(xx, yy)) != 0
  39.                          && (ignore_boulders || !sobj_at(BOULDER, xx, yy))
  40.                          && !onscary(xx, yy, mtmp)) {
  41.                          /* use trap if it's the correct type */
  42.                          if (t->ttyp == POLY_TRAP) {
  43.                              trapx = xx;
  44.                              trapy = yy;
  45.                              m.has_misc = MUSE_POLY_TRAP;
  46.                              return TRUE;
  47.                          }
  48.                      }
  49.      }
  50.      if (nohands(mdat))
  51.          return 0;
  52.  
  53.  #define nomore(x)       if (m.has_misc == x) continue
  54.      /*
  55.       * [bug?]  Choice of item is not prioritized; the last viable one
  56.       * in the monster's inventory will be chosen.
  57.       * 'nomore()' is nearly worthless because it only screens checking
  58.       * of duplicates when there is no alternate type in between them.
  59.       */
  60.      for (obj = mtmp->minvent; obj; obj = obj->nobj) {
  61.          /* Monsters shouldn't recognize cursed items; this kludge is
  62.             necessary to prevent serious problems though... */
  63.          if (obj->otyp == POT_GAIN_LEVEL
  64.              && (!obj->cursed
  65.                  || (!mtmp->isgd && !mtmp->isshk && !mtmp->ispriest))) {
  66.              m.misc = obj;
  67.              m.has_misc = MUSE_POT_GAIN_LEVEL;
  68.          }
  69.          nomore(MUSE_BULLWHIP);
  70.          if (obj->otyp == BULLWHIP && !mtmp->mpeaceful
  71.              /* the random test prevents whip-wielding
  72.                 monster from attempting disarm every turn */
  73.              && uwep && !rn2(5) && obj == MON_WEP(mtmp)
  74.              /* hero's location must be known and adjacent */
  75.              && mtmp->mux == u.ux && mtmp->muy == u.uy
  76.              && distu(mtmp->mx, mtmp->my) <= 2
  77.              /* don't bother if it can't work (this doesn't
  78.                 prevent cursed weapons from being targetted) */
  79.              && (canletgo(uwep, "")
  80.                  || (u.twoweap && canletgo(uswapwep, "")))) {
  81.              m.misc = obj;
  82.              m.has_misc = MUSE_BULLWHIP;
  83.          }
  84.          /* Note: peaceful/tame monsters won't make themselves
  85.           * invisible unless you can see them.  Not really right, but...
  86.           */
  87.          nomore(MUSE_WAN_MAKE_INVISIBLE);
  88.          if (obj->otyp == WAN_MAKE_INVISIBLE && obj->spe > 0 && !mtmp->minvis
  89.              && !mtmp->invis_blkd && (!mtmp->mpeaceful || See_invisible)
  90.              && (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) {
  91.              m.misc = obj;
  92.              m.has_misc = MUSE_WAN_MAKE_INVISIBLE;
  93.          }
  94.          nomore(MUSE_POT_INVISIBILITY);
  95.          if (obj->otyp == POT_INVISIBILITY && !mtmp->minvis
  96.              && !mtmp->invis_blkd && (!mtmp->mpeaceful || See_invisible)
  97.              && (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) {
  98.              m.misc = obj;
  99.              m.has_misc = MUSE_POT_INVISIBILITY;
  100.          }
  101.          nomore(MUSE_WAN_SPEED_MONSTER);
  102.          if (obj->otyp == WAN_SPEED_MONSTER && obj->spe > 0
  103.              && mtmp->mspeed != MFAST && !mtmp->isgd) {
  104.              m.misc = obj;
  105.              m.has_misc = MUSE_WAN_SPEED_MONSTER;
  106.          }
  107.          nomore(MUSE_POT_SPEED);
  108.          if (obj->otyp == POT_SPEED && mtmp->mspeed != MFAST && !mtmp->isgd) {
  109.              m.misc = obj;
  110.              m.has_misc = MUSE_POT_SPEED;
  111.          }
  112.          nomore(MUSE_WAN_POLYMORPH);
  113.          if (obj->otyp == WAN_POLYMORPH && obj->spe > 0
  114.              && (mtmp->cham == NON_PM) && monstr[monsndx(mdat)] < 6) {
  115.              m.misc = obj;
  116.              m.has_misc = MUSE_WAN_POLYMORPH;
  117.          }
  118.          nomore(MUSE_POT_POLYMORPH);
  119.          if (obj->otyp == POT_POLYMORPH && (mtmp->cham == NON_PM)
  120.              && monstr[monsndx(mdat)] < 6) {
  121.              m.misc = obj;
  122.              m.has_misc = MUSE_POT_POLYMORPH;
  123.          }
  124.      }
  125.      return (boolean) !!m.has_misc;
  126.  #undef nomore
  127.  }
  128.  

muse_newcham_mon

  1.  /* type of monster to polymorph into; defaults to one suitable for the
  2.     current level rather than the totally arbitrary choice of newcham() */
  3.  static struct permonst *
  4.  muse_newcham_mon(mon)
  5.  struct monst *mon;
  6.  {
  7.      struct obj *m_armr;
  8.  
  9.      if ((m_armr = which_armor(mon, W_ARM)) != 0) {
  10.          if (Is_dragon_scales(m_armr))
  11.              return Dragon_scales_to_pm(m_armr);
  12.          else if (Is_dragon_mail(m_armr))
  13.              return Dragon_mail_to_pm(m_armr);
  14.      }
  15.      return rndmonst();
  16.  }
  17.  

use_misc

  1.  int
  2.  use_misc(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      int i;
  6.      struct obj *otmp = m.misc;
  7.      boolean vis, vismon, oseen;
  8.      char nambuf[BUFSZ];
  9.  
  10.      if ((i = precheck(mtmp, otmp)) != 0)
  11.          return i;
  12.      vis = cansee(mtmp->mx, mtmp->my);
  13.      vismon = canseemon(mtmp);
  14.      oseen = otmp && vismon;
  15.  
  16.      switch (m.has_misc) {
  17.      case MUSE_POT_GAIN_LEVEL:
  18.          mquaffmsg(mtmp, otmp);
  19.          if (otmp->cursed) {
  20.              if (Can_rise_up(mtmp->mx, mtmp->my, &u.uz)) {
  21.                  register int tolev = depth(&u.uz) - 1;
  22.                  d_level tolevel;
  23.  
  24.                  get_level(&tolevel, tolev);
  25.                  /* insurance against future changes... */
  26.                  if (on_level(&tolevel, &u.uz))
  27.                      goto skipmsg;
  28.                  if (vismon) {
  29.                      pline("%s rises up, through the %s!", Monnam(mtmp),
  30.                            ceiling(mtmp->mx, mtmp->my));
  31.                      if (!objects[POT_GAIN_LEVEL].oc_name_known
  32.                          && !objects[POT_GAIN_LEVEL].oc_uname)
  33.                          docall(otmp);
  34.                  }
  35.                  m_useup(mtmp, otmp);
  36.                  migrate_to_level(mtmp, ledger_no(&tolevel), MIGR_RANDOM,
  37.                                   (coord *) 0);
  38.                  return 2;
  39.              } else {
  40.              skipmsg:
  41.                  if (vismon) {
  42.                      pline("%s looks uneasy.", Monnam(mtmp));
  43.                      if (!objects[POT_GAIN_LEVEL].oc_name_known
  44.                          && !objects[POT_GAIN_LEVEL].oc_uname)
  45.                          docall(otmp);
  46.                  }
  47.                  m_useup(mtmp, otmp);
  48.                  return 2;
  49.              }
  50.          }
  51.          if (vismon)
  52.              pline("%s seems more experienced.", Monnam(mtmp));
  53.          if (oseen)
  54.              makeknown(POT_GAIN_LEVEL);
  55.          m_useup(mtmp, otmp);
  56.          if (!grow_up(mtmp, (struct monst *) 0))
  57.              return 1;
  58.          /* grew into genocided monster */
  59.          return 2;
  60.      case MUSE_WAN_MAKE_INVISIBLE:
  61.      case MUSE_POT_INVISIBILITY:
  62.          if (otmp->otyp == WAN_MAKE_INVISIBLE) {
  63.              mzapmsg(mtmp, otmp, TRUE);
  64.              otmp->spe--;
  65.          } else
  66.              mquaffmsg(mtmp, otmp);
  67.          /* format monster's name before altering its visibility */
  68.          Strcpy(nambuf, mon_nam(mtmp));
  69.          mon_set_minvis(mtmp);
  70.          if (vismon && mtmp->minvis) { /* was seen, now invisible */
  71.              if (canspotmon(mtmp))
  72.                  pline("%s body takes on a %s transparency.",
  73.                        upstart(s_suffix(nambuf)),
  74.                        Hallucination ? "normal" : "strange");
  75.              else
  76.                  pline("Suddenly you cannot see %s.", nambuf);
  77.              if (oseen)
  78.                  makeknown(otmp->otyp);
  79.          }
  80.          if (otmp->otyp == POT_INVISIBILITY) {
  81.              if (otmp->cursed)
  82.                  you_aggravate(mtmp);
  83.              m_useup(mtmp, otmp);
  84.          }
  85.          return 2;
  86.      case MUSE_WAN_SPEED_MONSTER:
  87.          mzapmsg(mtmp, otmp, TRUE);
  88.          otmp->spe--;
  89.          mon_adjust_speed(mtmp, 1, otmp);
  90.          return 2;
  91.      case MUSE_POT_SPEED:
  92.          mquaffmsg(mtmp, otmp);
  93.          /* note difference in potion effect due to substantially
  94.             different methods of maintaining speed ratings:
  95.             player's character becomes "very fast" temporarily;
  96.             monster becomes "one stage faster" permanently */
  97.          mon_adjust_speed(mtmp, 1, otmp);
  98.          m_useup(mtmp, otmp);
  99.          return 2;
  100.      case MUSE_WAN_POLYMORPH:
  101.          mzapmsg(mtmp, otmp, TRUE);
  102.          otmp->spe--;
  103.          (void) newcham(mtmp, muse_newcham_mon(mtmp), TRUE, FALSE);
  104.          if (oseen)
  105.              makeknown(WAN_POLYMORPH);
  106.          return 2;
  107.      case MUSE_POT_POLYMORPH:
  108.          mquaffmsg(mtmp, otmp);
  109.          if (vismon)
  110.              pline("%s suddenly mutates!", Monnam(mtmp));
  111.          (void) newcham(mtmp, muse_newcham_mon(mtmp), FALSE, FALSE);
  112.          if (oseen)
  113.              makeknown(POT_POLYMORPH);
  114.          m_useup(mtmp, otmp);
  115.          return 2;
  116.      case MUSE_POLY_TRAP:
  117.          if (vismon)
  118.              pline("%s deliberately %s onto a polymorph trap!", Monnam(mtmp),
  119.                    makeplural(locomotion(mtmp->data, "jump")));
  120.          if (vis)
  121.              seetrap(t_at(trapx, trapy));
  122.  
  123.          /*  don't use rloc() due to worms */
  124.          remove_monster(mtmp->mx, mtmp->my);
  125.          newsym(mtmp->mx, mtmp->my);
  126.          place_monster(mtmp, trapx, trapy);
  127.          if (mtmp->wormno)
  128.              worm_move(mtmp);
  129.          newsym(trapx, trapy);
  130.  
  131.          (void) newcham(mtmp, (struct permonst *) 0, FALSE, FALSE);
  132.          return 2;
  133.      case MUSE_BULLWHIP:
  134.          /* attempt to disarm hero */
  135.          {
  136.              const char *The_whip = vismon ? "The bullwhip" : "A whip";
  137.              int where_to = rn2(4);
  138.              struct obj *obj = uwep;
  139.              const char *hand;
  140.              char the_weapon[BUFSZ];
  141.  
  142.              if (!obj || !canletgo(obj, "")
  143.                  || (u.twoweap && canletgo(uswapwep, "") && rn2(2)))
  144.                  obj = uswapwep;
  145.              if (!obj)
  146.                  break; /* shouldn't happen after find_misc() */
  147.  
  148.              Strcpy(the_weapon, the(xname(obj)));
  149.              hand = body_part(HAND);
  150.              if (bimanual(obj))
  151.                  hand = makeplural(hand);
  152.  
  153.              if (vismon)
  154.                  pline("%s flicks a bullwhip towards your %s!", Monnam(mtmp),
  155.                        hand);
  156.              if (obj->otyp == HEAVY_IRON_BALL) {
  157.                  pline("%s fails to wrap around %s.", The_whip, the_weapon);
  158.                  return 1;
  159.              }
  160.              pline("%s wraps around %s you're wielding!", The_whip,
  161.                    the_weapon);
  162.              if (welded(obj)) {
  163.                  pline("%s welded to your %s%c",
  164.                        !is_plural(obj) ? "It is" : "They are", hand,
  165.                        !obj->bknown ? '!' : '.');
  166.                  /* obj->bknown = 1; */ /* welded() takes care of this */
  167.                  where_to = 0;
  168.              }
  169.              if (!where_to) {
  170.                  pline_The("whip slips free."); /* not `The_whip' */
  171.                  return 1;
  172.              } else if (where_to == 3 && mon_hates_silver(mtmp)
  173.                         && objects[obj->otyp].oc_material == SILVER) {
  174.                  /* this monster won't want to catch a silver
  175.                     weapon; drop it at hero's feet instead */
  176.                  where_to = 2;
  177.              }
  178.              remove_worn_item(obj, FALSE);
  179.              freeinv(obj);
  180.              switch (where_to) {
  181.              case 1: /* onto floor beneath mon */
  182.                  pline("%s yanks %s from your %s!", Monnam(mtmp), the_weapon,
  183.                        hand);
  184.                  place_object(obj, mtmp->mx, mtmp->my);
  185.                  break;
  186.              case 2: /* onto floor beneath you */
  187.                  pline("%s yanks %s to the %s!", Monnam(mtmp), the_weapon,
  188.                        surface(u.ux, u.uy));
  189.                  dropy(obj);
  190.                  break;
  191.              case 3: /* into mon's inventory */
  192.                  pline("%s snatches %s!", Monnam(mtmp), the_weapon);
  193.                  (void) mpickobj(mtmp, obj);
  194.                  break;
  195.              }
  196.              return 1;
  197.          }
  198.          return 0;
  199.      case 0:
  200.          return 0; /* i.e. an exploded wand */
  201.      default:
  202.          impossible("%s wanted to perform action %d?", Monnam(mtmp),
  203.                     m.has_misc);
  204.          break;
  205.      }
  206.      return 0;
  207.  }
  208.  

you_aggravate

  1.  STATIC_OVL void
  2.  you_aggravate(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      pline("For some reason, %s presence is known to you.",
  6.            s_suffix(noit_mon_nam(mtmp)));
  7.      cls();
  8.  #ifdef CLIPPING
  9.      cliparound(mtmp->mx, mtmp->my);
  10.  #endif
  11.      show_glyph(mtmp->mx, mtmp->my, mon_to_glyph(mtmp));
  12.      display_self();
  13.      You_feel("aggravated at %s.", noit_mon_nam(mtmp));
  14.      display_nhwindow(WIN_MAP, TRUE);
  15.      docrt();
  16.      if (unconscious()) {
  17.          multi = -1;
  18.          nomovemsg = "Aggravated, you are jolted into full consciousness.";
  19.      }
  20.      newsym(mtmp->mx, mtmp->my);
  21.      if (!canspotmon(mtmp))
  22.          map_invisible(mtmp->mx, mtmp->my);
  23.  }
  24.  

rnd_misc_item

  1.  int
  2.  rnd_misc_item(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      struct permonst *pm = mtmp->data;
  6.      int difficulty = monstr[(monsndx(pm))];
  7.  
  8.      if (is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data)
  9.          || pm->mlet == S_GHOST || pm->mlet == S_KOP)
  10.          return 0;
  11.      /* Unlike other rnd_item functions, we only allow _weak_ monsters
  12.       * to have this item; after all, the item will be used to strengthen
  13.       * the monster and strong monsters won't use it at all...
  14.       */
  15.      if (difficulty < 6 && !rn2(30))
  16.          return rn2(6) ? POT_POLYMORPH : WAN_POLYMORPH;
  17.  
  18.      if (!rn2(40) && !nonliving(pm) && !is_vampshifter(mtmp))
  19.          return AMULET_OF_LIFE_SAVING;
  20.  
  21.      switch (rn2(3)) {
  22.      case 0:
  23.          if (mtmp->isgd)
  24.              return 0;
  25.          return rn2(6) ? POT_SPEED : WAN_SPEED_MONSTER;
  26.      case 1:
  27.          if (mtmp->mpeaceful && !See_invisible)
  28.              return 0;
  29.          return rn2(6) ? POT_INVISIBILITY : WAN_MAKE_INVISIBLE;
  30.      case 2:
  31.          return POT_GAIN_LEVEL;
  32.      }
  33.      /*NOTREACHED*/
  34.      return 0;
  35.  }
  36.  

searches_for_item

  1.  boolean
  2.  searches_for_item(mon, obj)
  3.  struct monst *mon;
  4.  struct obj *obj;
  5.  {
  6.      int typ = obj->otyp;
  7.  
  8.      if (is_animal(mon->data) || mindless(mon->data)
  9.          || mon->data == &mons[PM_GHOST]) /* don't loot bones piles */
  10.          return FALSE;
  11.  
  12.      if (typ == WAN_MAKE_INVISIBLE || typ == POT_INVISIBILITY)
  13.          return (boolean) (!mon->minvis && !mon->invis_blkd
  14.                            && !attacktype(mon->data, AT_GAZE));
  15.      if (typ == WAN_SPEED_MONSTER || typ == POT_SPEED)
  16.          return (boolean) (mon->mspeed != MFAST);
  17.  
  18.      switch (obj->oclass) {
  19.      case WAND_CLASS:
  20.          if (obj->spe <= 0)
  21.              return FALSE;
  22.          if (typ == WAN_DIGGING)
  23.              return (boolean) !is_floater(mon->data);
  24.          if (typ == WAN_POLYMORPH)
  25.              return (boolean) (monstr[monsndx(mon->data)] < 6);
  26.          if (objects[typ].oc_dir == RAY || typ == WAN_STRIKING
  27.              || typ == WAN_TELEPORTATION || typ == WAN_CREATE_MONSTER)
  28.              return TRUE;
  29.          break;
  30.      case POTION_CLASS:
  31.          if (typ == POT_HEALING || typ == POT_EXTRA_HEALING
  32.              || typ == POT_FULL_HEALING || typ == POT_POLYMORPH
  33.              || typ == POT_GAIN_LEVEL || typ == POT_PARALYSIS
  34.              || typ == POT_SLEEPING || typ == POT_ACID || typ == POT_CONFUSION)
  35.              return TRUE;
  36.          if (typ == POT_BLINDNESS && !attacktype(mon->data, AT_GAZE))
  37.              return TRUE;
  38.          break;
  39.      case SCROLL_CLASS:
  40.          if (typ == SCR_TELEPORTATION || typ == SCR_CREATE_MONSTER
  41.              || typ == SCR_EARTH || typ == SCR_FIRE)
  42.              return TRUE;
  43.          break;
  44.      case AMULET_CLASS:
  45.          if (typ == AMULET_OF_LIFE_SAVING)
  46.              return (boolean) !(nonliving(mon->data) || is_vampshifter(mon));
  47.          if (typ == AMULET_OF_REFLECTION)
  48.              return TRUE;
  49.          break;
  50.      case TOOL_CLASS:
  51.          if (typ == PICK_AXE)
  52.              return (boolean) needspick(mon->data);
  53.          if (typ == UNICORN_HORN)
  54.              return (boolean) (!obj->cursed && !is_unicorn(mon->data));
  55.          if (typ == FROST_HORN || typ == FIRE_HORN)
  56.              return (obj->spe > 0);
  57.          break;
  58.      case FOOD_CLASS:
  59.          if (typ == CORPSE)
  60.              return (boolean) (((mon->misc_worn_check & W_ARMG) != 0L
  61.                                 && touch_petrifies(&mons[obj->corpsenm]))
  62.                                || (!resists_ston(mon)
  63.                                    && cures_stoning(mon, obj, FALSE)));
  64.          if (typ == TIN)
  65.              return (boolean) (mcould_eat_tin(mon)
  66.                                && (!resists_ston(mon)
  67.                                    && cures_stoning(mon, obj, TRUE)));
  68.          if (typ == EGG)
  69.              return (boolean) touch_petrifies(&mons[obj->corpsenm]);
  70.          break;
  71.      default:
  72.          break;
  73.      }
  74.  
  75.      return FALSE;
  76.  }
  77.  

mon_reflects

  1.  boolean
  2.  mon_reflects(mon, str)
  3.  struct monst *mon;
  4.  const char *str;
  5.  {
  6.      struct obj *orefl = which_armor(mon, W_ARMS);
  7.  
  8.      if (orefl && orefl->otyp == SHIELD_OF_REFLECTION) {
  9.          if (str) {
  10.              pline(str, s_suffix(mon_nam(mon)), "shield");
  11.              makeknown(SHIELD_OF_REFLECTION);
  12.          }
  13.          return TRUE;
  14.      } else if (arti_reflects(MON_WEP(mon))) {
  15.          /* due to wielded artifact weapon */
  16.          if (str)
  17.              pline(str, s_suffix(mon_nam(mon)), "weapon");
  18.          return TRUE;
  19.      } else if ((orefl = which_armor(mon, W_AMUL))
  20.                 && orefl->otyp == AMULET_OF_REFLECTION) {
  21.          if (str) {
  22.              pline(str, s_suffix(mon_nam(mon)), "amulet");
  23.              makeknown(AMULET_OF_REFLECTION);
  24.          }
  25.          return TRUE;
  26.      } else if ((orefl = which_armor(mon, W_ARM))
  27.                 && (orefl->otyp == SILVER_DRAGON_SCALES
  28.                     || orefl->otyp == SILVER_DRAGON_SCALE_MAIL)) {
  29.          if (str)
  30.              pline(str, s_suffix(mon_nam(mon)), "armor");
  31.          return TRUE;
  32.      } else if (mon->data == &mons[PM_SILVER_DRAGON]
  33.                 || mon->data == &mons[PM_CHROMATIC_DRAGON]) {
  34.          /* Silver dragons only reflect when mature; babies do not */
  35.          if (str)
  36.              pline(str, s_suffix(mon_nam(mon)), "scales");
  37.          return TRUE;
  38.      }
  39.      return FALSE;
  40.  }
  41.  

ureflects

  1.  boolean
  2.  ureflects(fmt, str)
  3.  const char *fmt, *str;
  4.  {
  5.      /* Check from outermost to innermost objects */
  6.      if (EReflecting & W_ARMS) {
  7.          if (fmt && str) {
  8.              pline(fmt, str, "shield");
  9.              makeknown(SHIELD_OF_REFLECTION);
  10.          }
  11.          return TRUE;
  12.      } else if (EReflecting & W_WEP) {
  13.          /* Due to wielded artifact weapon */
  14.          if (fmt && str)
  15.              pline(fmt, str, "weapon");
  16.          return TRUE;
  17.      } else if (EReflecting & W_AMUL) {
  18.          if (fmt && str) {
  19.              pline(fmt, str, "medallion");
  20.              makeknown(AMULET_OF_REFLECTION);
  21.          }
  22.          return TRUE;
  23.      } else if (EReflecting & W_ARM) {
  24.          if (fmt && str)
  25.              pline(fmt, str, uskin ? "luster" : "armor");
  26.          return TRUE;
  27.      } else if (youmonst.data == &mons[PM_SILVER_DRAGON]) {
  28.          if (fmt && str)
  29.              pline(fmt, str, "scales");
  30.          return TRUE;
  31.      }
  32.      return FALSE;
  33.  }
  34.  

munstone

  1.  /* TRUE if the monster ate something */
  2.  boolean
  3.  munstone(mon, by_you)
  4.  struct monst *mon;
  5.  boolean by_you;
  6.  {
  7.      struct obj *obj;
  8.      boolean tinok;
  9.  
  10.      if (resists_ston(mon))
  11.          return FALSE;
  12.      if (mon->meating || !mon->mcanmove || mon->msleeping)
  13.          return FALSE;
  14.      mon->mstrategy &= ~STRAT_WAITFORU;
  15.  
  16.      tinok = mcould_eat_tin(mon);
  17.      for (obj = mon->minvent; obj; obj = obj->nobj) {
  18.          if (cures_stoning(mon, obj, tinok)) {
  19.              mon_consume_unstone(mon, obj, by_you, TRUE);
  20.              return TRUE;
  21.          }
  22.      }
  23.      return FALSE;
  24.  }
  25.  

mon_consume_unstone

  1.  STATIC_OVL void
  2.  mon_consume_unstone(mon, obj, by_you, stoning)
  3.  struct monst *mon;
  4.  struct obj *obj;
  5.  boolean by_you;
  6.  boolean stoning;
  7.  {
  8.      boolean vis = canseemon(mon), tinned = obj->otyp == TIN,
  9.              food = obj->otyp == CORPSE || tinned,
  10.              acid = obj->otyp == POT_ACID
  11.                     || (food && acidic(&mons[obj->corpsenm])),
  12.              lizard = food && obj->corpsenm == PM_LIZARD;
  13.      int nutrit = food ? dog_nutrition(mon, obj) : 0; /* also sets meating */
  14.  
  15.      /* give a "<mon> is slowing down" message and also remove
  16.         intrinsic speed (comparable to similar effect on the hero) */
  17.      if (stoning)
  18.          mon_adjust_speed(mon, -3, (struct obj *) 0);
  19.  
  20.      if (vis) {
  21.          long save_quan = obj->quan;
  22.  
  23.          obj->quan = 1L;
  24.          pline("%s %s %s.", Monnam(mon),
  25.                (obj->oclass == POTION_CLASS)
  26.                    ? "quaffs"
  27.                    : (obj->otyp == TIN) ? "opens and eats the contents of"
  28.                                         : "eats",
  29.                distant_name(obj, doname));
  30.          obj->quan = save_quan;
  31.      } else if (!Deaf)
  32.          You_hear("%s.",
  33.                   (obj->oclass == POTION_CLASS) ? "drinking" : "chewing");
  34.  
  35.      m_useup(mon, obj);
  36.      /* obj is now gone */
  37.  
  38.      if (acid && !tinned && !resists_acid(mon)) {
  39.          mon->mhp -= rnd(15);
  40.          if (vis)
  41.              pline("%s has a very bad case of stomach acid.", Monnam(mon));
  42.          if (mon->mhp <= 0) {
  43.              pline("%s dies!", Monnam(mon));
  44.              if (by_you)
  45.                  xkilled(mon, 0);
  46.              else
  47.                  mondead(mon);
  48.              return;
  49.          }
  50.      }
  51.      if (stoning && vis) {
  52.          if (Hallucination)
  53.              pline("What a pity - %s just ruined a future piece of art!",
  54.                    mon_nam(mon));
  55.          else
  56.              pline("%s seems limber!", Monnam(mon));
  57.      }
  58.      if (lizard && (mon->mconf || mon->mstun)) {
  59.          mon->mconf = 0;
  60.          mon->mstun = 0;
  61.          if (vis && !is_bat(mon->data) && mon->data != &mons[PM_STALKER])
  62.              pline("%s seems steadier now.", Monnam(mon));
  63.      }
  64.      if (mon->mtame && !mon->isminion && nutrit > 0) {
  65.          struct edog *edog = EDOG(mon);
  66.  
  67.          if (edog->hungrytime < monstermoves)
  68.              edog->hungrytime = monstermoves;
  69.          edog->hungrytime += nutrit;
  70.          mon->mconf = 0;
  71.      }
  72.      /* use up monster's next move */
  73.      mon->movement -= NORMAL_SPEED;
  74.      mon->mlstmv = monstermoves;
  75.  }
  76.  

cures_stoning

  1.  /* decide whether obj can cure petrification; also used when picking up */
  2.  STATIC_OVL boolean
  3.  cures_stoning(mon, obj, tinok)
  4.  struct monst *mon;
  5.  struct obj *obj;
  6.  boolean tinok;
  7.  {
  8.      if (obj->otyp == POT_ACID)
  9.          return TRUE;
  10.      if (obj->otyp != CORPSE && (obj->otyp != TIN || !tinok))
  11.          return FALSE;
  12.      /* corpse, or tin that mon can open */
  13.      return (boolean) (obj->corpsenm == PM_LIZARD
  14.                        || (acidic(&mons[obj->corpsenm])
  15.                            && (obj->corpsenm != PM_GREEN_SLIME
  16.                                || slimeproof(mon->data))));
  17.  }
  18.  

mcould_eat_tin

  1.  STATIC_OVL boolean
  2.  mcould_eat_tin(mon)
  3.  struct monst *mon;
  4.  {
  5.      struct obj *obj, *mwep;
  6.      boolean welded_wep;
  7.  
  8.      /* monkeys who manage to steal tins can't open and eat them
  9.         even if they happen to also have the appropriate tool */
  10.      if (is_animal(mon->data))
  11.          return FALSE;
  12.  
  13.      mwep = MON_WEP(mon);
  14.      welded_wep = mwep && mwelded(mwep);
  15.      /* this is different from the player; tin opener or dagger doesn't
  16.         have to be wielded, and knife can be used instead of dagger */
  17.      for (obj = mon->minvent; obj; obj = obj->nobj) {
  18.          /* if stuck with a cursed weapon, don't check rest of inventory */
  19.          if (welded_wep && obj != mwep)
  20.              continue;
  21.  
  22.          if (obj->otyp == TIN_OPENER
  23.              || (obj->oclass == WEAPON_CLASS
  24.                  && (objects[obj->otyp].oc_skill == P_DAGGER
  25.                      || objects[obj->otyp].oc_skill == P_KNIFE)))
  26.              return TRUE;
  27.      }
  28.      return FALSE;
  29.  }
  30.  

munslime

  1.  /* TRUE if monster does something to avoid turning into green slime */
  2.  boolean
  3.  munslime(mon, by_you)
  4.  struct monst *mon;
  5.  boolean by_you;
  6.  {
  7.      struct obj *obj, odummy;
  8.  
  9.      /*
  10.       * muse_unslime() gives "mon starts turning green", "mon zaps
  11.       * itself with a wand of fire", and "mon's slime burns away"
  12.       * messages.  Monsters who don't get any chance at that just have
  13.       * (via our caller) newcham()'s "mon turns into slime" feedback.
  14.       */
  15.  
  16.      if (slimeproof(mon->data))
  17.          return FALSE;
  18.      if (mon->meating || !mon->mcanmove || mon->msleeping)
  19.          return FALSE;
  20.      mon->mstrategy &= ~STRAT_WAITFORU;
  21.  
  22.      /* if monster can breathe fire, do so upon self; a monster who deals
  23.         fire damage by biting, clawing, gazing, and especially exploding
  24.         isn't able to cure itself of green slime with its own attack
  25.         [possible extension: monst capable of casting high level clerical
  26.         spells could toss pillar of fire at self--probably too suicidal] */
  27.      if (!mon->mcan && !mon->mspec_used
  28.          && attacktype_fordmg(mon->data, AT_BREA, AD_FIRE)) {
  29.          odummy = zeroobj; /* otyp == STRANGE_OBJECT */
  30.          return muse_unslime(mon, &odummy, by_you);
  31.      }
  32.  
  33.      for (obj = mon->minvent; obj; obj = obj->nobj)
  34.          if (cures_sliming(mon, obj))
  35.              return muse_unslime(mon, obj, by_you);
  36.  
  37.      /* TODO: check for and move onto an adjacent fire trap */
  38.  
  39.      return FALSE;
  40.  }
  41.  

muse_unslime

  1.  /* mon uses an item--selected by caller--to burn away incipient slime */
  2.  STATIC_OVL boolean
  3.  muse_unslime(mon, obj, by_you)
  4.  struct monst *mon;
  5.  struct obj *obj;
  6.  boolean by_you; /* true: if mon kills itself, hero gets credit/blame */
  7.  {
  8.      struct obj *odummyp;
  9.      int otyp = obj->otyp, dmg;
  10.      boolean vis = canseemon(mon), res = TRUE;
  11.  
  12.      if (vis)
  13.          pline("%s starts turning %s.", Monnam(mon),
  14.                green_mon(mon) ? "into ooze" : hcolor(NH_GREEN));
  15.      /* -4 => sliming, causes quiet loss of enhanced speed */
  16.      mon_adjust_speed(mon, -4, (struct obj *) 0);
  17.  
  18.      if (otyp == STRANGE_OBJECT) {
  19.          /* monster is using fire breath on self */
  20.          if (vis)
  21.              pline("%s breathes fire on %sself.", Monnam(mon), mhim(mon));
  22.          if (!rn2(3))
  23.              mon->mspec_used = rn1(10, 5);
  24.          /* -21 => monster's fire breath; 1 => # of damage dice */
  25.          (void) zhitm(mon, by_you ? 21 : -21, 1, &odummyp);
  26.      } else if (otyp == SCR_FIRE) {
  27.          mreadmsg(mon, obj);
  28.          if (mon->mconf) {
  29.              if (cansee(mon->mx, mon->my))
  30.                  pline("Oh, what a pretty fire!");
  31.              if (vis && !objects[otyp].oc_name_known
  32.                  && !objects[otyp].oc_uname)
  33.                  docall(obj);
  34.              m_useup(mon, obj); /* after docall() */
  35.              vis = FALSE;       /* skip makeknown() below */
  36.              res = FALSE;       /* failed to cure sliming */
  37.          } else {
  38.              m_useup(mon, obj); /* before explode() */
  39.              dmg = (2 * (rn1(3, 3) + 2 * bcsign(obj)) + 1) / 3;
  40.              /* -11 => monster's fireball */
  41.              explode(mon->mx, mon->my, -11, dmg, SCROLL_CLASS,
  42.                      /* by_you: override -11 for mon but not others */
  43.                      by_you ? -EXPL_FIERY : EXPL_FIERY);
  44.          }
  45.      } else { /* wand/horn of fire w/ positive charge count */
  46.          mzapmsg(mon, obj, TRUE);
  47.          obj->spe--;
  48.          /* -1 => monster's wand of fire; 2 => # of damage dice */
  49.          (void) zhitm(mon, by_you ? 1 : -1, 2, &odummyp);
  50.      }
  51.  
  52.      if (vis) {
  53.          if (res && mon->mhp > 0)
  54.              pline("%s slime is burned away!", s_suffix(Monnam(mon)));
  55.          if (otyp != STRANGE_OBJECT)
  56.              makeknown(otyp);
  57.      }
  58.      /* use up monster's next move */
  59.      mon->movement -= NORMAL_SPEED;
  60.      mon->mlstmv = monstermoves;
  61.      return res;
  62.  }
  63.  

cures_sliming

  1.  /* decide whether obj can be used to cure green slime */
  2.  STATIC_OVL int
  3.  cures_sliming(mon, obj)
  4.  struct monst *mon;
  5.  struct obj *obj;
  6.  {
  7.      /* scroll of fire, non-empty wand or horn of fire */
  8.      if (obj->otyp == SCR_FIRE)
  9.          return (haseyes(mon->data) && mon->mcansee);
  10.      /* hero doesn't need hands or even limbs to zap, so mon doesn't either */
  11.      return ((obj->otyp == WAN_FIRE || obj->otyp == FIRE_HORN)
  12.              && obj->spe > 0);
  13.  }
  14.  

green_mon

  1.  /* TRUE if monster appears to be green; for active TEXTCOLOR, we go by
  2.     the display color, otherwise we just pick things that seem plausibly
  3.     green (which doesn't necessarily match the TEXTCOLOR categorization) */
  4.  STATIC_OVL boolean
  5.  green_mon(mon)
  6.  struct monst *mon;
  7.  {
  8.      struct permonst *ptr = mon->data;
  9.  
  10.      if (Hallucination)
  11.          return FALSE;
  12.  #ifdef TEXTCOLOR
  13.      if (iflags.use_color)
  14.          return (ptr->mcolor == CLR_GREEN || ptr->mcolor == CLR_BRIGHT_GREEN);
  15.  #endif
  16.      /* approximation */
  17.      if (strstri(ptr->mname, "green"))
  18.          return TRUE;
  19.      switch (monsndx(ptr)) {
  20.      case PM_FOREST_CENTAUR:
  21.      case PM_GARTER_SNAKE:
  22.      case PM_GECKO:
  23.      case PM_GREMLIN:
  24.      case PM_HOMUNCULUS:
  25.      case PM_JUIBLEX:
  26.      case PM_LEPRECHAUN:
  27.      case PM_LICHEN:
  28.      case PM_LIZARD:
  29.      case PM_WOOD_NYMPH:
  30.          return TRUE;
  31.      default:
  32.          if (is_elf(ptr) && !is_prince(ptr) && !is_lord(ptr)
  33.              && ptr != &mons[PM_GREY_ELF])
  34.              return TRUE;
  35.          break;
  36.      }
  37.      return FALSE;
  38.  }
  39.  
  40.  /*muse.c*/