Source:NetHack 3.6.0/src/mcastu.c

From NetHackWiki
Jump to: navigation, search

Below is the full text to mcastu.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/mcastu.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[edit]

  1.  /* NetHack 3.6	mcastu.c	$NHDT-Date: 1436753517 2015/07/13 02:11:57 $  $NHDT-Branch: master $:$NHDT-Revision: 1.44 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5.  #include "hack.h"
  6.  
  7.  /* monster mage spells */
  8.  #define MGC_PSI_BOLT 0
  9.  #define MGC_CURE_SELF 1
  10.  #define MGC_HASTE_SELF 2
  11.  #define MGC_STUN_YOU 3
  12.  #define MGC_DISAPPEAR 4
  13.  #define MGC_WEAKEN_YOU 5
  14.  #define MGC_DESTRY_ARMR 6
  15.  #define MGC_CURSE_ITEMS 7
  16.  #define MGC_AGGRAVATION 8
  17.  #define MGC_SUMMON_MONS 9
  18.  #define MGC_CLONE_WIZ 10
  19.  #define MGC_DEATH_TOUCH 11
  20.  
  21.  /* monster cleric spells */
  22.  #define CLC_OPEN_WOUNDS 0
  23.  #define CLC_CURE_SELF 1
  24.  #define CLC_CONFUSE_YOU 2
  25.  #define CLC_PARALYZE 3
  26.  #define CLC_BLIND_YOU 4
  27.  #define CLC_INSECTS 5
  28.  #define CLC_CURSE_ITEMS 6
  29.  #define CLC_LIGHTNING 7
  30.  #define CLC_FIRE_PILLAR 8
  31.  #define CLC_GEYSER 9
  32.  
  33.  STATIC_DCL void FDECL(cursetxt, (struct monst *, BOOLEAN_P));
  34.  STATIC_DCL int FDECL(choose_magic_spell, (int));
  35.  STATIC_DCL int FDECL(choose_clerical_spell, (int));
  36.  STATIC_DCL void FDECL(cast_wizard_spell, (struct monst *, int, int));
  37.  STATIC_DCL void FDECL(cast_cleric_spell, (struct monst *, int, int));
  38.  STATIC_DCL boolean FDECL(is_undirected_spell, (unsigned int, int));
  39.  STATIC_DCL boolean
  40.  FDECL(spell_would_be_useless, (struct monst *, unsigned int, int));
  41.  
  42.  extern const char *const flash_types[]; /* from zap.c */
  43.  

cursetxt[edit]

  1.  /* feedback when frustrated monster couldn't cast a spell */
  2.  STATIC_OVL
  3.  void
  4.  cursetxt(mtmp, undirected)
  5.  struct monst *mtmp;
  6.  boolean undirected;
  7.  {
  8.      if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my)) {
  9.          const char *point_msg; /* spellcasting monsters are impolite */
  10.  
  11.          if (undirected)
  12.              point_msg = "all around, then curses";
  13.          else if ((Invis && !perceives(mtmp->data)
  14.                    && (mtmp->mux != u.ux || mtmp->muy != u.uy))
  15.                   || is_obj_mappear(&youmonst, STRANGE_OBJECT)
  16.                   || u.uundetected)
  17.              point_msg = "and curses in your general direction";
  18.          else if (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy))
  19.              point_msg = "and curses at your displaced image";
  20.          else
  21.              point_msg = "at you, then curses";
  22.  
  23.          pline("%s points %s.", Monnam(mtmp), point_msg);
  24.      } else if ((!(moves % 4) || !rn2(4))) {
  25.          if (!Deaf)
  26.              Norep("You hear a mumbled curse.");
  27.      }
  28.  }
  29.  

choose_magic_spell[edit]

  1.  /* convert a level based random selection into a specific mage spell;
  2.     inappropriate choices will be screened out by spell_would_be_useless() */
  3.  STATIC_OVL int
  4.  choose_magic_spell(spellval)
  5.  int spellval;
  6.  {
  7.      /* for 3.4.3 and earlier, val greater than 22 selected the default spell
  8.       */
  9.      while (spellval > 24 && rn2(25))
  10.          spellval = rn2(spellval);
  11.  
  12.      switch (spellval) {
  13.      case 24:
  14.      case 23:
  15.          if (Antimagic || Hallucination)
  16.              return MGC_PSI_BOLT;
  17.      /* else FALL THROUGH */
  18.      case 22:
  19.      case 21:
  20.      case 20:
  21.          return MGC_DEATH_TOUCH;
  22.      case 19:
  23.      case 18:
  24.          return MGC_CLONE_WIZ;
  25.      case 17:
  26.      case 16:
  27.      case 15:
  28.          return MGC_SUMMON_MONS;
  29.      case 14:
  30.      case 13:
  31.          return MGC_AGGRAVATION;
  32.      case 12:
  33.      case 11:
  34.      case 10:
  35.          return MGC_CURSE_ITEMS;
  36.      case 9:
  37.      case 8:
  38.          return MGC_DESTRY_ARMR;
  39.      case 7:
  40.      case 6:
  41.          return MGC_WEAKEN_YOU;
  42.      case 5:
  43.      case 4:
  44.          return MGC_DISAPPEAR;
  45.      case 3:
  46.          return MGC_STUN_YOU;
  47.      case 2:
  48.          return MGC_HASTE_SELF;
  49.      case 1:
  50.          return MGC_CURE_SELF;
  51.      case 0:
  52.      default:
  53.          return MGC_PSI_BOLT;
  54.      }
  55.  }
  56.  

choose_clerical_spell[edit]

  1.  /* convert a level based random selection into a specific cleric spell */
  2.  STATIC_OVL int
  3.  choose_clerical_spell(spellnum)
  4.  int spellnum;
  5.  {
  6.      /* for 3.4.3 and earlier, num greater than 13 selected the default spell
  7.       */
  8.      while (spellnum > 15 && rn2(16))
  9.          spellnum = rn2(spellnum);
  10.  
  11.      switch (spellnum) {
  12.      case 15:
  13.      case 14:
  14.          if (rn2(3))
  15.              return CLC_OPEN_WOUNDS;
  16.      /* else FALL THROUGH */
  17.      case 13:
  18.          return CLC_GEYSER;
  19.      case 12:
  20.          return CLC_FIRE_PILLAR;
  21.      case 11:
  22.          return CLC_LIGHTNING;
  23.      case 10:
  24.      case 9:
  25.          return CLC_CURSE_ITEMS;
  26.      case 8:
  27.          return CLC_INSECTS;
  28.      case 7:
  29.      case 6:
  30.          return CLC_BLIND_YOU;
  31.      case 5:
  32.      case 4:
  33.          return CLC_PARALYZE;
  34.      case 3:
  35.      case 2:
  36.          return CLC_CONFUSE_YOU;
  37.      case 1:
  38.          return CLC_CURE_SELF;
  39.      case 0:
  40.      default:
  41.          return CLC_OPEN_WOUNDS;
  42.      }
  43.  }
  44.  

castmu[edit]

  1.  /* return values:
  2.   * 1: successful spell
  3.   * 0: unsuccessful spell
  4.   */
  5.  int
  6.  castmu(mtmp, mattk, thinks_it_foundyou, foundyou)
  7.  register struct monst *mtmp;
  8.  register struct attack *mattk;
  9.  boolean thinks_it_foundyou;
  10.  boolean foundyou;
  11.  {
  12.      int dmg, ml = mtmp->m_lev;
  13.      int ret;
  14.      int spellnum = 0;
  15.  
  16.      /* Three cases:
  17.       * -- monster is attacking you.  Search for a useful spell.
  18.       * -- monster thinks it's attacking you.  Search for a useful spell,
  19.       *    without checking for undirected.  If the spell found is directed,
  20.       *    it fails with cursetxt() and loss of mspec_used.
  21.       * -- monster isn't trying to attack.  Select a spell once.  Don't keep
  22.       *    searching; if that spell is not useful (or if it's directed),
  23.       *    return and do something else.
  24.       * Since most spells are directed, this means that a monster that isn't
  25.       * attacking casts spells only a small portion of the time that an
  26.       * attacking monster does.
  27.       */
  28.      if ((mattk->adtyp == AD_SPEL || mattk->adtyp == AD_CLRC) && ml) {
  29.          int cnt = 40;
  30.  
  31.          do {
  32.              spellnum = rn2(ml);
  33.              if (mattk->adtyp == AD_SPEL)
  34.                  spellnum = choose_magic_spell(spellnum);
  35.              else
  36.                  spellnum = choose_clerical_spell(spellnum);
  37.              /* not trying to attack?  don't allow directed spells */
  38.              if (!thinks_it_foundyou) {
  39.                  if (!is_undirected_spell(mattk->adtyp, spellnum)
  40.                      || spell_would_be_useless(mtmp, mattk->adtyp, spellnum)) {
  41.                      if (foundyou)
  42.                          impossible(
  43.                         "spellcasting monster found you and doesn't know it?");
  44.                      return 0;
  45.                  }
  46.                  break;
  47.              }
  48.          } while (--cnt > 0
  49.                   && spell_would_be_useless(mtmp, mattk->adtyp, spellnum));
  50.          if (cnt == 0)
  51.              return 0;
  52.      }
  53.  
  54.      /* monster unable to cast spells? */
  55.      if (mtmp->mcan || mtmp->mspec_used || !ml) {
  56.          cursetxt(mtmp, is_undirected_spell(mattk->adtyp, spellnum));
  57.          return (0);
  58.      }
  59.  
  60.      if (mattk->adtyp == AD_SPEL || mattk->adtyp == AD_CLRC) {
  61.          mtmp->mspec_used = 10 - mtmp->m_lev;
  62.          if (mtmp->mspec_used < 2)
  63.              mtmp->mspec_used = 2;
  64.      }
  65.  
  66.      /* monster can cast spells, but is casting a directed spell at the
  67.         wrong place?  If so, give a message, and return.  Do this *after*
  68.         penalizing mspec_used. */
  69.      if (!foundyou && thinks_it_foundyou
  70.          && !is_undirected_spell(mattk->adtyp, spellnum)) {
  71.          pline("%s casts a spell at %s!",
  72.                canseemon(mtmp) ? Monnam(mtmp) : "Something",
  73.                levl[mtmp->mux][mtmp->muy].typ == WATER ? "empty water"
  74.                                                        : "thin air");
  75.          return (0);
  76.      }
  77.  
  78.      nomul(0);
  79.      if (rn2(ml * 10) < (mtmp->mconf ? 100 : 20)) { /* fumbled attack */
  80.          if (canseemon(mtmp) && !Deaf)
  81.              pline_The("air crackles around %s.", mon_nam(mtmp));
  82.          return (0);
  83.      }
  84.      if (canspotmon(mtmp) || !is_undirected_spell(mattk->adtyp, spellnum)) {
  85.          pline("%s casts a spell%s!",
  86.                canspotmon(mtmp) ? Monnam(mtmp) : "Something",
  87.                is_undirected_spell(mattk->adtyp, spellnum)
  88.                    ? ""
  89.                    : (Invisible && !perceives(mtmp->data)
  90.                       && (mtmp->mux != u.ux || mtmp->muy != u.uy))
  91.                          ? " at a spot near you"
  92.                          : (Displaced
  93.                             && (mtmp->mux != u.ux || mtmp->muy != u.uy))
  94.                                ? " at your displaced image"
  95.                                : " at you");
  96.      }
  97.  
  98.      /*
  99.       *	As these are spells, the damage is related to the level
  100.       *	of the monster casting the spell.
  101.       */
  102.      if (!foundyou) {
  103.          dmg = 0;
  104.          if (mattk->adtyp != AD_SPEL && mattk->adtyp != AD_CLRC) {
  105.              impossible(
  106.                "%s casting non-hand-to-hand version of hand-to-hand spell %d?",
  107.                         Monnam(mtmp), mattk->adtyp);
  108.              return (0);
  109.          }
  110.      } else if (mattk->damd)
  111.          dmg = d((int) ((ml / 2) + mattk->damn), (int) mattk->damd);
  112.      else
  113.          dmg = d((int) ((ml / 2) + 1), 6);
  114.      if (Half_spell_damage)
  115.          dmg = (dmg + 1) / 2;
  116.  
  117.      ret = 1;
  118.  
  119.      switch (mattk->adtyp) {
  120.      case AD_FIRE:
  121.          pline("You're enveloped in flames.");
  122.          if (Fire_resistance) {
  123.              shieldeff(u.ux, u.uy);
  124.              pline("But you resist the effects.");
  125.              dmg = 0;
  126.          }
  127.          burn_away_slime();
  128.          break;
  129.      case AD_COLD:
  130.          pline("You're covered in frost.");
  131.          if (Cold_resistance) {
  132.              shieldeff(u.ux, u.uy);
  133.              pline("But you resist the effects.");
  134.              dmg = 0;
  135.          }
  136.          break;
  137.      case AD_MAGM:
  138.          You("are hit by a shower of missiles!");
  139.          if (Antimagic) {
  140.              shieldeff(u.ux, u.uy);
  141.              pline_The("missiles bounce off!");
  142.              dmg = 0;
  143.          } else
  144.              dmg = d((int) mtmp->m_lev / 2 + 1, 6);
  145.          break;
  146.      case AD_SPEL: /* wizard spell */
  147.      case AD_CLRC: /* clerical spell */
  148.      {
  149.          if (mattk->adtyp == AD_SPEL)
  150.              cast_wizard_spell(mtmp, dmg, spellnum);
  151.          else
  152.              cast_cleric_spell(mtmp, dmg, spellnum);
  153.          dmg = 0; /* done by the spell casting functions */
  154.          break;
  155.      }
  156.      }
  157.      if (dmg)
  158.          mdamageu(mtmp, dmg);
  159.      return (ret);
  160.  }
  161.  

cast_wizard_spell[edit]

  1.  /* monster wizard and cleric spellcasting functions */
  2.  /*
  3.     If dmg is zero, then the monster is not casting at you.
  4.     If the monster is intentionally not casting at you, we have previously
  5.     called spell_would_be_useless() and spellnum should always be a valid
  6.     undirected spell.
  7.     If you modify either of these, be sure to change is_undirected_spell()
  8.     and spell_would_be_useless().
  9.   */
  10.  STATIC_OVL
  11.  void
  12.  cast_wizard_spell(mtmp, dmg, spellnum)
  13.  struct monst *mtmp;
  14.  int dmg;
  15.  int spellnum;
  16.  {
  17.      if (dmg == 0 && !is_undirected_spell(AD_SPEL, spellnum)) {
  18.          impossible("cast directed wizard spell (%d) with dmg=0?", spellnum);
  19.          return;
  20.      }
  21.  
  22.      switch (spellnum) {
  23.      case MGC_DEATH_TOUCH:
  24.          pline("Oh no, %s's using the touch of death!", mhe(mtmp));
  25.          if (nonliving(youmonst.data) || is_demon(youmonst.data)) {
  26.              You("seem no deader than before.");
  27.          } else if (!Antimagic && rn2(mtmp->m_lev) > 12) {
  28.              if (Hallucination) {
  29.                  You("have an out of body experience.");
  30.              } else {
  31.                  killer.format = KILLED_BY_AN;
  32.                  Strcpy(killer.name, "touch of death");
  33.                  done(DIED);
  34.              }
  35.          } else {
  36.              if (Antimagic)
  37.                  shieldeff(u.ux, u.uy);
  38.              pline("Lucky for you, it didn't work!");
  39.          }
  40.          dmg = 0;
  41.          break;
  42.      case MGC_CLONE_WIZ:
  43.          if (mtmp->iswiz && context.no_of_wizards == 1) {
  44.              pline("Double Trouble...");
  45.              clonewiz();
  46.              dmg = 0;
  47.          } else
  48.              impossible("bad wizard cloning?");
  49.          break;
  50.      case MGC_SUMMON_MONS: {
  51.          int count;
  52.  
  53.          count = nasty(mtmp); /* summon something nasty */
  54.          if (mtmp->iswiz)
  55.              verbalize("Destroy the thief, my pet%s!", plur(count));
  56.          else {
  57.              const char *mappear =
  58.                  (count == 1) ? "A monster appears" : "Monsters appear";
  59.  
  60.              /* messages not quite right if plural monsters created but
  61.                 only a single monster is seen */
  62.              if (Invisible && !perceives(mtmp->data)
  63.                  && (mtmp->mux != u.ux || mtmp->muy != u.uy))
  64.                  pline("%s around a spot near you!", mappear);
  65.              else if (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy))
  66.                  pline("%s around your displaced image!", mappear);
  67.              else
  68.                  pline("%s from nowhere!", mappear);
  69.          }
  70.          dmg = 0;
  71.          break;
  72.      }
  73.      case MGC_AGGRAVATION:
  74.          You_feel("that monsters are aware of your presence.");
  75.          aggravate();
  76.          dmg = 0;
  77.          break;
  78.      case MGC_CURSE_ITEMS:
  79.          You_feel("as if you need some help.");
  80.          rndcurse();
  81.          dmg = 0;
  82.          break;
  83.      case MGC_DESTRY_ARMR:
  84.          if (Antimagic) {
  85.              shieldeff(u.ux, u.uy);
  86.              pline("A field of force surrounds you!");
  87.          } else if (!destroy_arm(some_armor(&youmonst))) {
  88.              Your("skin itches.");
  89.          }
  90.          dmg = 0;
  91.          break;
  92.      case MGC_WEAKEN_YOU: /* drain strength */
  93.          if (Antimagic) {
  94.              shieldeff(u.ux, u.uy);
  95.              You_feel("momentarily weakened.");
  96.          } else {
  97.              You("suddenly feel weaker!");
  98.              dmg = mtmp->m_lev - 6;
  99.              if (Half_spell_damage)
  100.                  dmg = (dmg + 1) / 2;
  101.              losestr(rnd(dmg));
  102.              if (u.uhp < 1)
  103.                  done_in_by(mtmp, DIED);
  104.          }
  105.          dmg = 0;
  106.          break;
  107.      case MGC_DISAPPEAR: /* makes self invisible */
  108.          if (!mtmp->minvis && !mtmp->invis_blkd) {
  109.              if (canseemon(mtmp))
  110.                  pline("%s suddenly %s!", Monnam(mtmp),
  111.                        !See_invisible ? "disappears" : "becomes transparent");
  112.              mon_set_minvis(mtmp);
  113.              dmg = 0;
  114.          } else
  115.              impossible("no reason for monster to cast disappear spell?");
  116.          break;
  117.      case MGC_STUN_YOU:
  118.          if (Antimagic || Free_action) {
  119.              shieldeff(u.ux, u.uy);
  120.              if (!Stunned)
  121.                  You_feel("momentarily disoriented.");
  122.              make_stunned(1L, FALSE);
  123.          } else {
  124.              You(Stunned ? "struggle to keep your balance." : "reel...");
  125.              dmg = d(ACURR(A_DEX) < 12 ? 6 : 4, 4);
  126.              if (Half_spell_damage)
  127.                  dmg = (dmg + 1) / 2;
  128.              make_stunned((HStun & TIMEOUT) + (long) dmg, FALSE);
  129.          }
  130.          dmg = 0;
  131.          break;
  132.      case MGC_HASTE_SELF:
  133.          mon_adjust_speed(mtmp, 1, (struct obj *) 0);
  134.          dmg = 0;
  135.          break;
  136.      case MGC_CURE_SELF:
  137.          if (mtmp->mhp < mtmp->mhpmax) {
  138.              if (canseemon(mtmp))
  139.                  pline("%s looks better.", Monnam(mtmp));
  140.              /* note: player healing does 6d4; this used to do 1d8 */
  141.              if ((mtmp->mhp += d(3, 6)) > mtmp->mhpmax)
  142.                  mtmp->mhp = mtmp->mhpmax;
  143.              dmg = 0;
  144.          }
  145.          break;
  146.      case MGC_PSI_BOLT:
  147.          /* prior to 3.4.0 Antimagic was setting the damage to 1--this
  148.             made the spell virtually harmless to players with magic res. */
  149.          if (Antimagic) {
  150.              shieldeff(u.ux, u.uy);
  151.              dmg = (dmg + 1) / 2;
  152.          }
  153.          if (dmg <= 5)
  154.              You("get a slight %sache.", body_part(HEAD));
  155.          else if (dmg <= 10)
  156.              Your("brain is on fire!");
  157.          else if (dmg <= 20)
  158.              Your("%s suddenly aches painfully!", body_part(HEAD));
  159.          else
  160.              Your("%s suddenly aches very painfully!", body_part(HEAD));
  161.          break;
  162.      default:
  163.          impossible("mcastu: invalid magic spell (%d)", spellnum);
  164.          dmg = 0;
  165.          break;
  166.      }
  167.  
  168.      if (dmg)
  169.          mdamageu(mtmp, dmg);
  170.  }
  171.  

cast_cleric_spell[edit]

  1.  STATIC_OVL
  2.  void
  3.  cast_cleric_spell(mtmp, dmg, spellnum)
  4.  struct monst *mtmp;
  5.  int dmg;
  6.  int spellnum;
  7.  {
  8.      if (dmg == 0 && !is_undirected_spell(AD_CLRC, spellnum)) {
  9.          impossible("cast directed cleric spell (%d) with dmg=0?", spellnum);
  10.          return;
  11.      }
  12.  
  13.      switch (spellnum) {
  14.      case CLC_GEYSER:
  15.          /* this is physical damage (force not heat),
  16.           * not magical damage or fire damage
  17.           */
  18.          pline("A sudden geyser slams into you from nowhere!");
  19.          dmg = d(8, 6);
  20.          if (Half_physical_damage)
  21.              dmg = (dmg + 1) / 2;
  22.          break;
  23.      case CLC_FIRE_PILLAR:
  24.          pline("A pillar of fire strikes all around you!");
  25.          if (Fire_resistance) {
  26.              shieldeff(u.ux, u.uy);
  27.              dmg = 0;
  28.          } else
  29.              dmg = d(8, 6);
  30.          if (Half_spell_damage)
  31.              dmg = (dmg + 1) / 2;
  32.          burn_away_slime();
  33.          (void) burnarmor(&youmonst);
  34.          destroy_item(SCROLL_CLASS, AD_FIRE);
  35.          destroy_item(POTION_CLASS, AD_FIRE);
  36.          destroy_item(SPBOOK_CLASS, AD_FIRE);
  37.          (void) burn_floor_objects(u.ux, u.uy, TRUE, FALSE);
  38.          break;
  39.      case CLC_LIGHTNING: {
  40.          boolean reflects;
  41.  
  42.          pline("A bolt of lightning strikes down at you from above!");
  43.          reflects = ureflects("It bounces off your %s%s.", "");
  44.          if (reflects || Shock_resistance) {
  45.              shieldeff(u.ux, u.uy);
  46.              dmg = 0;
  47.              if (reflects)
  48.                  break;
  49.          } else
  50.              dmg = d(8, 6);
  51.          if (Half_spell_damage)
  52.              dmg = (dmg + 1) / 2;
  53.          destroy_item(WAND_CLASS, AD_ELEC);
  54.          destroy_item(RING_CLASS, AD_ELEC);
  55.          (void) flashburn((long) rnd(100));
  56.          break;
  57.      }
  58.      case CLC_CURSE_ITEMS:
  59.          You_feel("as if you need some help.");
  60.          rndcurse();
  61.          dmg = 0;
  62.          break;
  63.      case CLC_INSECTS: {
  64.          /* Try for insects, and if there are none
  65.             left, go for (sticks to) snakes.  -3. */
  66.          struct permonst *pm = mkclass(S_ANT, 0);
  67.          struct monst *mtmp2 = (struct monst *) 0;
  68.          char let = (pm ? S_ANT : S_SNAKE);
  69.          boolean success = FALSE, seecaster;
  70.          int i, quan, oldseen, newseen;
  71.          coord bypos;
  72.          const char *fmt;
  73.  
  74.          oldseen = monster_census(TRUE);
  75.          quan = (mtmp->m_lev < 2) ? 1 : rnd((int) mtmp->m_lev / 2);
  76.          if (quan < 3)
  77.              quan = 3;
  78.          for (i = 0; i <= quan; i++) {
  79.              if (!enexto(&bypos, mtmp->mux, mtmp->muy, mtmp->data))
  80.                  break;
  81.              if ((pm = mkclass(let, 0)) != 0
  82.                  && (mtmp2 = makemon(pm, bypos.x, bypos.y, MM_ANGRY)) != 0) {
  83.                  success = TRUE;
  84.                  mtmp2->msleeping = mtmp2->mpeaceful = mtmp2->mtame = 0;
  85.                  set_malign(mtmp2);
  86.              }
  87.          }
  88.          newseen = monster_census(TRUE);
  89.  
  90.          /* not canspotmon(), which includes unseen things sensed via warning
  91.           */
  92.          seecaster = canseemon(mtmp) || tp_sensemon(mtmp) || Detect_monsters;
  93.  
  94.          fmt = 0;
  95.          if (!seecaster) {
  96.              char *arg; /* [not const: upstart(N==1 ? an() : makeplural())] */
  97.              const char *what = (let == S_SNAKE) ? "snake" : "insect";
  98.  
  99.              if (newseen <= oldseen || Unaware) {
  100.                  /* unseen caster fails or summons unseen critters,
  101.                     or unconscious hero ("You dream that you hear...") */
  102.                  You_hear("someone summoning %s.", makeplural(what));
  103.              } else {
  104.                  /* unseen caster summoned seen critter(s) */
  105.                  arg = (newseen == oldseen + 1) ? an(what) : makeplural(what);
  106.                  if (!Deaf)
  107.                      You_hear("someone summoning something, and %s %s.", arg,
  108.                               vtense(arg, "appear"));
  109.                  else
  110.                      pline("%s %s.", upstart(arg), vtense(arg, "appear"));
  111.              }
  112.  
  113.              /* seen caster, possibly producing unseen--or just one--critters;
  114.                 hero is told what the caster is doing and doesn't necessarily
  115.                 observe complete accuracy of that caster's results (in other
  116.                 words, no need to fuss with visibility or singularization;
  117.                 player is told what's happening even if hero is unconscious) */
  118.          } else if (!success)
  119.              fmt = "%s casts at a clump of sticks, but nothing happens.";
  120.          else if (let == S_SNAKE)
  121.              fmt = "%s transforms a clump of sticks into snakes!";
  122.          else if (Invisible && !perceives(mtmp->data)
  123.                   && (mtmp->mux != u.ux || mtmp->muy != u.uy))
  124.              fmt = "%s summons insects around a spot near you!";
  125.          else if (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy))
  126.              fmt = "%s summons insects around your displaced image!";
  127.          else
  128.              fmt = "%s summons insects!";
  129.          if (fmt)
  130.              pline(fmt, Monnam(mtmp));
  131.  
  132.          dmg = 0;
  133.          break;
  134.      }
  135.      case CLC_BLIND_YOU:
  136.          /* note: resists_blnd() doesn't apply here */
  137.          if (!Blinded) {
  138.              int num_eyes = eyecount(youmonst.data);
  139.              pline("Scales cover your %s!", (num_eyes == 1)
  140.                                                 ? body_part(EYE)
  141.                                                 : makeplural(body_part(EYE)));
  142.              make_blinded(Half_spell_damage ? 100L : 200L, FALSE);
  143.              if (!Blind)
  144.                  Your1(vision_clears);
  145.              dmg = 0;
  146.          } else
  147.              impossible("no reason for monster to cast blindness spell?");
  148.          break;
  149.      case CLC_PARALYZE:
  150.          if (Antimagic || Free_action) {
  151.              shieldeff(u.ux, u.uy);
  152.              if (multi >= 0)
  153.                  You("stiffen briefly.");
  154.              nomul(-1);
  155.              multi_reason = "paralyzed by a monster";
  156.          } else {
  157.              if (multi >= 0)
  158.                  You("are frozen in place!");
  159.              dmg = 4 + (int) mtmp->m_lev;
  160.              if (Half_spell_damage)
  161.                  dmg = (dmg + 1) / 2;
  162.              nomul(-dmg);
  163.              multi_reason = "paralyzed by a monster";
  164.          }
  165.          nomovemsg = 0;
  166.          dmg = 0;
  167.          break;
  168.      case CLC_CONFUSE_YOU:
  169.          if (Antimagic) {
  170.              shieldeff(u.ux, u.uy);
  171.              You_feel("momentarily dizzy.");
  172.          } else {
  173.              boolean oldprop = !!Confusion;
  174.  
  175.              dmg = (int) mtmp->m_lev;
  176.              if (Half_spell_damage)
  177.                  dmg = (dmg + 1) / 2;
  178.              make_confused(HConfusion + dmg, TRUE);
  179.              if (Hallucination)
  180.                  You_feel("%s!", oldprop ? "trippier" : "trippy");
  181.              else
  182.                  You_feel("%sconfused!", oldprop ? "more " : "");
  183.          }
  184.          dmg = 0;
  185.          break;
  186.      case CLC_CURE_SELF:
  187.          if (mtmp->mhp < mtmp->mhpmax) {
  188.              if (canseemon(mtmp))
  189.                  pline("%s looks better.", Monnam(mtmp));
  190.              /* note: player healing does 6d4; this used to do 1d8 */
  191.              if ((mtmp->mhp += d(3, 6)) > mtmp->mhpmax)
  192.                  mtmp->mhp = mtmp->mhpmax;
  193.              dmg = 0;
  194.          }
  195.          break;
  196.      case CLC_OPEN_WOUNDS:
  197.          if (Antimagic) {
  198.              shieldeff(u.ux, u.uy);
  199.              dmg = (dmg + 1) / 2;
  200.          }
  201.          if (dmg <= 5)
  202.              Your("skin itches badly for a moment.");
  203.          else if (dmg <= 10)
  204.              pline("Wounds appear on your body!");
  205.          else if (dmg <= 20)
  206.              pline("Severe wounds appear on your body!");
  207.          else
  208.              Your("body is covered with painful wounds!");
  209.          break;
  210.      default:
  211.          impossible("mcastu: invalid clerical spell (%d)", spellnum);
  212.          dmg = 0;
  213.          break;
  214.      }
  215.  
  216.      if (dmg)
  217.          mdamageu(mtmp, dmg);
  218.  }
  219.  

is_undirected_spell[edit]

  1.  STATIC_DCL
  2.  boolean
  3.  is_undirected_spell(adtyp, spellnum)
  4.  unsigned int adtyp;
  5.  int spellnum;
  6.  {
  7.      if (adtyp == AD_SPEL) {
  8.          switch (spellnum) {
  9.          case MGC_CLONE_WIZ:
  10.          case MGC_SUMMON_MONS:
  11.          case MGC_AGGRAVATION:
  12.          case MGC_DISAPPEAR:
  13.          case MGC_HASTE_SELF:
  14.          case MGC_CURE_SELF:
  15.              return TRUE;
  16.          default:
  17.              break;
  18.          }
  19.      } else if (adtyp == AD_CLRC) {
  20.          switch (spellnum) {
  21.          case CLC_INSECTS:
  22.          case CLC_CURE_SELF:
  23.              return TRUE;
  24.          default:
  25.              break;
  26.          }
  27.      }
  28.      return FALSE;
  29.  }
  30.  

spell_would_be_useless[edit]

  1.  /* Some spells are useless under some circumstances. */
  2.  STATIC_DCL
  3.  boolean
  4.  spell_would_be_useless(mtmp, adtyp, spellnum)
  5.  struct monst *mtmp;
  6.  unsigned int adtyp;
  7.  int spellnum;
  8.  {
  9.      /* Some spells don't require the player to really be there and can be cast
  10.       * by the monster when you're invisible, yet still shouldn't be cast when
  11.       * the monster doesn't even think you're there.
  12.       * This check isn't quite right because it always uses your real position.
  13.       * We really want something like "if the monster could see mux, muy".
  14.       */
  15.      boolean mcouldseeu = couldsee(mtmp->mx, mtmp->my);
  16.  
  17.      if (adtyp == AD_SPEL) {
  18.          /* aggravate monsters, etc. won't be cast by peaceful monsters */
  19.          if (mtmp->mpeaceful
  20.              && (spellnum == MGC_AGGRAVATION || spellnum == MGC_SUMMON_MONS
  21.                  || spellnum == MGC_CLONE_WIZ))
  22.              return TRUE;
  23.          /* haste self when already fast */
  24.          if (mtmp->permspeed == MFAST && spellnum == MGC_HASTE_SELF)
  25.              return TRUE;
  26.          /* invisibility when already invisible */
  27.          if ((mtmp->minvis || mtmp->invis_blkd) && spellnum == MGC_DISAPPEAR)
  28.              return TRUE;
  29.          /* peaceful monster won't cast invisibility if you can't see
  30.             invisible,
  31.             same as when monsters drink potions of invisibility.  This doesn't
  32.             really make a lot of sense, but lets the player avoid hitting
  33.             peaceful monsters by mistake */
  34.          if (mtmp->mpeaceful && !See_invisible && spellnum == MGC_DISAPPEAR)
  35.              return TRUE;
  36.          /* healing when already healed */
  37.          if (mtmp->mhp == mtmp->mhpmax && spellnum == MGC_CURE_SELF)
  38.              return TRUE;
  39.          /* don't summon monsters if it doesn't think you're around */
  40.          if (!mcouldseeu && (spellnum == MGC_SUMMON_MONS
  41.                              || (!mtmp->iswiz && spellnum == MGC_CLONE_WIZ)))
  42.              return TRUE;
  43.          if ((!mtmp->iswiz || context.no_of_wizards > 1)
  44.              && spellnum == MGC_CLONE_WIZ)
  45.              return TRUE;
  46.          /* aggravation (global wakeup) when everyone is already active */
  47.          if (spellnum == MGC_AGGRAVATION) {
  48.              struct monst *nxtmon;
  49.  
  50.              for (nxtmon = fmon; nxtmon; nxtmon = nxtmon->nmon) {
  51.                  if (DEADMONSTER(nxtmon))
  52.                      continue;
  53.                  if ((nxtmon->mstrategy & STRAT_WAITFORU) != 0
  54.                      || nxtmon->msleeping || !nxtmon->mcanmove)
  55.                      break;
  56.              }
  57.              /* if nothing needs to be awakened then this spell is useless
  58.                 but caster might not realize that [chance to pick it then
  59.                 must be very small otherwise caller's many retry attempts
  60.                 will eventually end up picking it too often] */
  61.              if (!nxtmon)
  62.                  return rn2(100) ? TRUE : FALSE;
  63.          }
  64.      } else if (adtyp == AD_CLRC) {
  65.          /* summon insects/sticks to snakes won't be cast by peaceful monsters
  66.           */
  67.          if (mtmp->mpeaceful && spellnum == CLC_INSECTS)
  68.              return TRUE;
  69.          /* healing when already healed */
  70.          if (mtmp->mhp == mtmp->mhpmax && spellnum == CLC_CURE_SELF)
  71.              return TRUE;
  72.          /* don't summon insects if it doesn't think you're around */
  73.          if (!mcouldseeu && spellnum == CLC_INSECTS)
  74.              return TRUE;
  75.          /* blindness spell on blinded player */
  76.          if (Blinded && spellnum == CLC_BLIND_YOU)
  77.              return TRUE;
  78.      }
  79.      return FALSE;
  80.  }
  81.  

buzzmu[edit]

  1.  /* convert 1..10 to 0..9; add 10 for second group (spell casting) */
  2.  #define ad_to_typ(k) (10 + (int) k - 1)
  3.  
  4.  /* monster uses spell (ranged) */
  5.  int
  6.  buzzmu(mtmp, mattk)
  7.  register struct monst *mtmp;
  8.  register struct attack *mattk;
  9.  {
  10.      /* don't print constant stream of curse messages for 'normal'
  11.         spellcasting monsters at range */
  12.      if (mattk->adtyp > AD_SPC2)
  13.          return (0);
  14.  
  15.      if (mtmp->mcan) {
  16.          cursetxt(mtmp, FALSE);
  17.          return (0);
  18.      }
  19.      if (lined_up(mtmp) && rn2(3)) {
  20.          nomul(0);
  21.          if (mattk->adtyp && (mattk->adtyp < 11)) { /* no cf unsigned >0 */
  22.              if (canseemon(mtmp))
  23.                  pline("%s zaps you with a %s!", Monnam(mtmp),
  24.                        flash_types[ad_to_typ(mattk->adtyp)]);
  25.              buzz(-ad_to_typ(mattk->adtyp), (int) mattk->damn, mtmp->mx,
  26.                   mtmp->my, sgn(tbx), sgn(tby));
  27.          } else
  28.              impossible("Monster spell %d cast", mattk->adtyp - 1);
  29.      }
  30.      return (1);
  31.  }
  32.  
  33.  /*mcastu.c*/