Source:NetHack 3.4.3/src/mcastu.c

From NetHackWiki
Jump to: navigation, search

Below is the full text to src/mcastu.c from NetHack 3.4.3. To link to a particular line, write [[mcastu.c#line123]], for example.

Top of file[edit]

  1. /*	SCCS Id: @(#)mcastu.c	3.4	2003/01/08	*/
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */

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

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

  1. #include "hack.h"

Monster mage spells[edit]

  1. /* monster mage spells */
  2. #define MGC_PSI_BOLT	 0
  3. #define MGC_CURE_SELF	 1
  4. #define MGC_HASTE_SELF	 2
  5. #define MGC_STUN_YOU	 3
  6. #define MGC_DISAPPEAR	 4
  7. #define MGC_WEAKEN_YOU	 5
  8. #define MGC_DESTRY_ARMR	 6
  9. #define MGC_CURSE_ITEMS	 7
  10. #define MGC_AGGRAVATION	 8
  11. #define MGC_SUMMON_MONS	 9
  12. #define MGC_CLONE_WIZ	10
  13. #define MGC_DEATH_TOUCH	11

Monster cleric spells[edit]

  1. /* monster cleric spells */
  2. #define CLC_OPEN_WOUNDS	 0
  3. #define CLC_CURE_SELF	 1
  4. #define CLC_CONFUSE_YOU	 2
  5. #define CLC_PARALYZE	 3
  6. #define CLC_BLIND_YOU	 4
  7. #define CLC_INSECTS	 5
  8. #define CLC_CURSE_ITEMS	 6
  9. #define CLC_LIGHTNING	 7
  10. #define CLC_FIRE_PILLAR	 8
  11. #define CLC_GEYSER	 9
  1. STATIC_DCL void FDECL(cursetxt,(struct monst *,BOOLEAN_P));
  2. STATIC_DCL int FDECL(choose_magic_spell, (int));
  3. STATIC_DCL int FDECL(choose_clerical_spell, (int));
  4. STATIC_DCL void FDECL(cast_wizard_spell,(struct monst *, int,int));
  5. STATIC_DCL void FDECL(cast_cleric_spell,(struct monst *, int,int));
  6. STATIC_DCL boolean FDECL(is_undirected_spell,(unsigned int,int));
  7. STATIC_DCL boolean FDECL(spell_would_be_useless,(struct monst *,unsigned int,int));
  8.  
  9. #ifdef OVL0
  10.  
  11. extern const char * const flash_types[];	/* from zap.c */

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. 		    (youmonst.m_ap_type == M_AP_OBJECT &&
  16. 			youmonst.mappearance == STRANGE_OBJECT) ||
  17. 		    u.uundetected)
  18. 		point_msg = "and curses in your general direction";
  19. 	    else if (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy))
  20. 		point_msg = "and curses at your displaced image";
  21. 	    else
  22. 		point_msg = "at you, then curses";
  23.  
  24. 	    pline("%s points %s.", Monnam(mtmp), point_msg);
  25. 	} else if ((!(moves % 4) || !rn2(4))) {
  26. 	    if (flags.soundok) Norep("You hear a mumbled curse.");
  27. 	}
  28. }
  29.  
  30. #endif /* OVL0 */

choose_magic_spell[edit]

  1. #ifdef OVLB
  2.  
  3. /* convert a level based random selection into a specific mage spell;
  4. inappropriate choices will be screened out by spell_would_be_useless() */
  5. STATIC_OVL int
  6. choose_magic_spell(spellval)
  7. int spellval;
  8. {
  9. switch (spellval) {
  10. case 22:
  11. case 21:
  12. case 20:
  13. 	return MGC_DEATH_TOUCH;
  14. case 19:
  15. case 18:
  16. 	return MGC_CLONE_WIZ;
  17. case 17:
  18. case 16:
  19. case 15:
  20. 	return MGC_SUMMON_MONS;
  21. case 14:
  22. case 13:
  23. 	return MGC_AGGRAVATION;
  24. case 12:
  25. case 11:
  26. case 10:
  27. 	return MGC_CURSE_ITEMS;
  28. case 9:
  29. case 8:
  30. 	return MGC_DESTRY_ARMR;
  31. case 7:
  32. case 6:
  33. 	return MGC_WEAKEN_YOU;
  34. case 5:
  35. case 4:
  36. 	return MGC_DISAPPEAR;
  37. case 3:
  38. 	return MGC_STUN_YOU;
  39. case 2:
  40. 	return MGC_HASTE_SELF;
  41. case 1:
  42. 	return MGC_CURE_SELF;
  43. case 0:
  44. default:
  45. 	return MGC_PSI_BOLT;
  46. }
  47. }

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. switch (spellnum) {
  7. case 13:
  8. 	return CLC_GEYSER;
  9. case 12:
  10. 	return CLC_FIRE_PILLAR;
  11. case 11:
  12. 	return CLC_LIGHTNING;
  13. case 10:
  14. case 9:
  15. 	return CLC_CURSE_ITEMS;
  16. case 8:
  17. 	return CLC_INSECTS;
  18. case 7:
  19. case 6:
  20. 	return CLC_BLIND_YOU;
  21. case 5:
  22. case 4:
  23. 	return CLC_PARALYZE;
  24. case 3:
  25. case 2:
  26. 	return CLC_CONFUSE_YOU;
  27. case 1:
  28. 	return CLC_CURE_SELF;
  29. case 0:
  30. default:
  31. 	return CLC_OPEN_WOUNDS;
  32. }
  33. }

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("spellcasting monster found you and doesn't know it?");
  43. 			return 0;
  44. 		    }
  45. 		    break;
  46. 		}
  47. 	    } while(--cnt > 0 &&
  48. 		    spell_would_be_useless(mtmp, mattk->adtyp, spellnum));
  49. 	    if (cnt == 0) return 0;
  50. 	}
  51.  
  52. 	/* monster unable to cast spells? */
  53. 	if(mtmp->mcan || mtmp->mspec_used || !ml) {
  54. 	    cursetxt(mtmp, is_undirected_spell(mattk->adtyp, spellnum));
  55. 	    return(0);
  56. 	}
  57.  
  58. 	if (mattk->adtyp == AD_SPEL || mattk->adtyp == AD_CLRC) {
  59. 	    mtmp->mspec_used = 10 - mtmp->m_lev;
  60. 	    if (mtmp->mspec_used < 2) mtmp->mspec_used = 2;
  61. 	}
  62.  
  63. 	/* monster can cast spells, but is casting a directed spell at the
  64. 	   wrong place?  If so, give a message, and return.  Do this *after*
  65. 	   penalizing mspec_used. */
  66. 	if (!foundyou && thinks_it_foundyou &&
  67. 		!is_undirected_spell(mattk->adtyp, spellnum)) {
  68. 	    pline("%s casts a spell at %s!",
  69. 		canseemon(mtmp) ? Monnam(mtmp) : "Something",
  70. 		levl[mtmp->mux][mtmp->muy].typ == WATER
  71. 		    ? "empty water" : "thin air");
  72. 	    return(0);
  73. 	}
  74.  
  75. 	nomul(0);
  76. 	if(rn2(ml*10) < (mtmp->mconf ? 100 : 20)) {	/* fumbled attack */
  77. 	    if (canseemon(mtmp) && flags.soundok)
  78. 		pline_The("air crackles around %s.", mon_nam(mtmp));
  79. 	    return(0);
  80. 	}
  81. 	if (canspotmon(mtmp) || !is_undirected_spell(mattk->adtyp, spellnum)) {
  82. 	    pline("%s casts a spell%s!",
  83. 		  canspotmon(mtmp) ? Monnam(mtmp) : "Something",
  84. 		  is_undirected_spell(mattk->adtyp, spellnum) ? "" :
  85. 		  (Invisible && !perceives(mtmp->data) && 
  86. 		   (mtmp->mux != u.ux || mtmp->muy != u.uy)) ?
  87. 		  " at a spot near you" :
  88. 		  (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy)) ?
  89. 		  " at your displaced image" :
  90. 		  " at you");
  91. 	}
  92.  
  93. /*
  94. *	As these are spells, the damage is related to the level
  95. *	of the monster casting the spell.
  96. */
  97. 	if (!foundyou) {
  98. 	    dmg = 0;
  99. 	    if (mattk->adtyp != AD_SPEL && mattk->adtyp != AD_CLRC) {
  100. 		impossible(
  101. 	      "%s casting non-hand-to-hand version of hand-to-hand spell %d?",
  102. 			   Monnam(mtmp), mattk->adtyp);
  103. 		return(0);
  104. 	    }
  105. 	} else if (mattk->damd)
  106. 	    dmg = d((int)((ml/2) + mattk->damn), (int)mattk->damd);
  107. 	else dmg = d((int)((ml/2) + 1), 6);
  108. 	if (Half_spell_damage) dmg = (dmg+1) / 2;
  109.  
  110. 	ret = 1;
  111.  
  112. 	switch (mattk->adtyp) {
  113.  
  114. 	    case AD_FIRE:
  115. 		pline("You're enveloped in flames.");
  116. 		if(Fire_resistance) {
  117. 			shieldeff(u.ux, u.uy);
  118. 			pline("But you resist the effects.");
  119. 			dmg = 0;
  120. 		}
  121. 		burn_away_slime();
  122. 		break;
  123. 	    case AD_COLD:
  124. 		pline("You're covered in frost.");
  125. 		if(Cold_resistance) {
  126. 			shieldeff(u.ux, u.uy);
  127. 			pline("But you resist the effects.");
  128. 			dmg = 0;
  129. 		}
  130. 		break;
  131. 	    case AD_MAGM:
  132. 		You("are hit by a shower of missiles!");
  133. 		if(Antimagic) {
  134. 			shieldeff(u.ux, u.uy);
  135. 			pline_The("missiles bounce off!");
  136. 			dmg = 0;
  137. 		} else dmg = d((int)mtmp->m_lev/2 + 1,6);
  138. 		break;
  139. 	    case AD_SPEL:	/* wizard spell */
  140. 	    case AD_CLRC:       /* clerical spell */
  141. 	    {
  142. 		if (mattk->adtyp == AD_SPEL)
  143. 		    cast_wizard_spell(mtmp, dmg, spellnum);
  144. 		else
  145. 		    cast_cleric_spell(mtmp, dmg, spellnum);
  146. 		dmg = 0; /* done by the spell casting functions */
  147. 		break;
  148. 	    }
  149. 	}
  150. 	if(dmg) mdamageu(mtmp, dmg);
  151. 	return(ret);
  152. }

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. 		killer = "touch of death";
  33. 		done(DIED);
  34. 	    }
  35. 	} else {
  36. 	    if (Antimagic) shieldeff(u.ux, u.uy);
  37. 	    pline("Lucky for you, it didn't work!");
  38. 	}
  39. 	dmg = 0;
  40. 	break;
  41. case MGC_CLONE_WIZ:
  42. 	if (mtmp->iswiz && flags.no_of_wizards == 1) {
  43. 	    pline("Double Trouble...");
  44. 	    clonewiz();
  45. 	    dmg = 0;
  46. 	} else
  47. 	    impossible("bad wizard cloning?");
  48. 	break;
  49. case MGC_SUMMON_MONS:
  50. {
  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) dmg = (dmg + 1) / 2;
  100. 	    losestr(rnd(dmg));
  101. 	    if (u.uhp < 1)
  102. 		done_in_by(mtmp);
  103. 	}
  104. 	dmg = 0;
  105. 	break;
  106. case MGC_DISAPPEAR:		/* makes self invisible */
  107. 	if (!mtmp->minvis && !mtmp->invis_blkd) {
  108. 	    if (canseemon(mtmp))
  109. 		pline("%s suddenly %s!", Monnam(mtmp),
  110. 		      !See_invisible ? "disappears" : "becomes transparent");
  111. 	    mon_set_minvis(mtmp);
  112. 	    dmg = 0;
  113. 	} else
  114. 	    impossible("no reason for monster to cast disappear spell?");
  115. 	break;
  116. case MGC_STUN_YOU:
  117. 	if (Antimagic || Free_action) {
  118. 	    shieldeff(u.ux, u.uy);
  119. 	    if (!Stunned)
  120. 		You_feel("momentarily disoriented.");
  121. 	    make_stunned(1L, FALSE);
  122. 	} else {
  123. 	    You(Stunned ? "struggle to keep your balance." : "reel...");
  124. 	    dmg = d(ACURR(A_DEX) < 12 ? 6 : 4, 4);
  125. 	    if (Half_spell_damage) dmg = (dmg + 1) / 2;
  126. 	    make_stunned(HStun + dmg, FALSE);
  127. 	}
  128. 	dmg = 0;
  129. 	break;
  130. case MGC_HASTE_SELF:
  131. 	mon_adjust_speed(mtmp, 1, (struct obj *)0);
  132. 	dmg = 0;
  133. 	break;
  134. case MGC_CURE_SELF:
  135. 	if (mtmp->mhp < mtmp->mhpmax) {
  136. 	    if (canseemon(mtmp))
  137. 		pline("%s looks better.", Monnam(mtmp));
  138. 	    /* note: player healing does 6d4; this used to do 1d8 */
  139. 	    if ((mtmp->mhp += d(3,6)) > mtmp->mhpmax)
  140. 		mtmp->mhp = mtmp->mhpmax;
  141. 	    dmg = 0;
  142. 	}
  143. 	break;
  144. case MGC_PSI_BOLT:
  145. 	/* prior to 3.4.0 Antimagic was setting the damage to 1--this
  146. 	   made the spell virtually harmless to players with magic res. */
  147. 	if (Antimagic) {
  148. 	    shieldeff(u.ux, u.uy);
  149. 	    dmg = (dmg + 1) / 2;
  150. 	}
  151. 	if (dmg <= 5)
  152. 	    You("get a slight %sache.", body_part(HEAD));
  153. 	else if (dmg <= 10)
  154. 	    Your("brain is on fire!");
  155. 	else if (dmg <= 20)
  156. 	    Your("%s suddenly aches painfully!", body_part(HEAD));
  157. 	else
  158. 	    Your("%s suddenly aches very painfully!", body_part(HEAD));
  159. 	break;
  160. default:
  161. 	impossible("mcastu: invalid magic spell (%d)", spellnum);
  162. 	dmg = 0;
  163. 	break;
  164. }
  165.  
  166. if (dmg) mdamageu(mtmp, dmg);
  167. }

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, not magical damage */
  16. 	pline("A sudden geyser slams into you from nowhere!");
  17. 	dmg = d(8, 6);
  18. 	if (Half_physical_damage) dmg = (dmg + 1) / 2;
  19. 	break;
  20. case CLC_FIRE_PILLAR:
  21. 	pline("A pillar of fire strikes all around you!");
  22. 	if (Fire_resistance) {
  23. 	    shieldeff(u.ux, u.uy);
  24. 	    dmg = 0;
  25. 	} else
  26. 	    dmg = d(8, 6);
  27. 	if (Half_spell_damage) dmg = (dmg + 1) / 2;
  28. 	burn_away_slime();
  29. 	(void) burnarmor(&youmonst);
  30. 	destroy_item(SCROLL_CLASS, AD_FIRE);
  31. 	destroy_item(POTION_CLASS, AD_FIRE);
  32. 	destroy_item(SPBOOK_CLASS, AD_FIRE);
  33. 	(void) burn_floor_paper(u.ux, u.uy, TRUE, FALSE);
  34. 	break;
  35. case CLC_LIGHTNING:
  36. {
  37. 	boolean reflects;
  38.  
  39. 	pline("A bolt of lightning strikes down at you from above!");
  40. 	reflects = ureflects("It bounces off your %s%s.", "");
  41. 	if (reflects || Shock_resistance) {
  42. 	    shieldeff(u.ux, u.uy);
  43. 	    dmg = 0;
  44. 	    if (reflects)
  45. 		break;
  46. 	} else
  47. 	    dmg = d(8, 6);
  48. 	if (Half_spell_damage) dmg = (dmg + 1) / 2;
  49. 	destroy_item(WAND_CLASS, AD_ELEC);
  50. 	destroy_item(RING_CLASS, AD_ELEC);
  51. 	break;
  52. }
  53. case CLC_CURSE_ITEMS:
  54. 	You_feel("as if you need some help.");
  55. 	rndcurse();
  56. 	dmg = 0;
  57. 	break;
  58. case CLC_INSECTS:
  59. {
  60. 	/* Try for insects, and if there are none
  61. 	   left, go for (sticks to) snakes.  -3. */
  62. 	struct permonst *pm = mkclass(S_ANT,0);
  63. 	struct monst *mtmp2 = (struct monst *)0;
  64. 	char let = (pm ? S_ANT : S_SNAKE);
  65. 	boolean success;
  66. 	int i;
  67. 	coord bypos;
  68. 	int quan;
  69.  
  70. 	quan = (mtmp->m_lev < 2) ? 1 : rnd((int)mtmp->m_lev / 2);
  71. 	if (quan < 3) quan = 3;
  72. 	success = pm ? TRUE : FALSE;
  73. 	for (i = 0; i <= quan; i++) {
  74. 	    if (!enexto(&bypos, mtmp->mux, mtmp->muy, mtmp->data))
  75. 		break;
  76. 	    if ((pm = mkclass(let,0)) != 0 &&
  77. 		    (mtmp2 = makemon(pm, bypos.x, bypos.y, NO_MM_FLAGS)) != 0) {
  78. 		success = TRUE;
  79. 		mtmp2->msleeping = mtmp2->mpeaceful = mtmp2->mtame = 0;
  80. 		set_malign(mtmp2);
  81. 	    }
  82. 	}
  83. 	/* Not quite right:
  84. * -- message doesn't always make sense for unseen caster (particularly
  85. 	 *    the first message)
  86. * -- message assumes plural monsters summoned (non-plural should be
  87. *    very rare, unlike in nasty())
  88. * -- message assumes plural monsters seen
  89. */
  90. 	if (!success)
  91. 	    pline("%s casts at a clump of sticks, but nothing happens.",
  92. 		Monnam(mtmp));
  93. 	else if (let == S_SNAKE)
  94. 	    pline("%s transforms a clump of sticks into snakes!",
  95. 		Monnam(mtmp));
  96. 	else if (Invisible && !perceives(mtmp->data) &&
  97. 				(mtmp->mux != u.ux || mtmp->muy != u.uy))
  98. 	    pline("%s summons insects around a spot near you!",
  99. 		Monnam(mtmp));
  100. 	else if (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy))
  101. 	    pline("%s summons insects around your displaced image!",
  102. 		Monnam(mtmp));
  103. 	else
  104. 	    pline("%s summons insects!", Monnam(mtmp));
  105. 	dmg = 0;
  106. 	break;
  107. }
  108. case CLC_BLIND_YOU:
  109. 	/* note: resists_blnd() doesn't apply here */
  110. 	if (!Blinded) {
  111. 	    int num_eyes = eyecount(youmonst.data);
  112. 	    pline("Scales cover your %s!",
  113. 		  (num_eyes == 1) ?
  114. 		  body_part(EYE) : makeplural(body_part(EYE)));
  115. 	    make_blinded(Half_spell_damage ? 100L : 200L, FALSE);
  116. 	    if (!Blind) Your(vision_clears);
  117. 	    dmg = 0;
  118. 	} else
  119. 	    impossible("no reason for monster to cast blindness spell?");
  120. 	break;
  121. case CLC_PARALYZE:
  122. 	if (Antimagic || Free_action) {
  123. 	    shieldeff(u.ux, u.uy);
  124. 	    if (multi >= 0)
  125. 		You("stiffen briefly.");
  126. 	    nomul(-1);
  127. 	} else {
  128. 	    if (multi >= 0)
  129. 		You("are frozen in place!");
  130. 	    dmg = 4 + (int)mtmp->m_lev;
  131. 	    if (Half_spell_damage) dmg = (dmg + 1) / 2;
  132. 	    nomul(-dmg);
  133. 	}
  134. 	dmg = 0;
  135. 	break;
  136. case CLC_CONFUSE_YOU:
  137. 	if (Antimagic) {
  138. 	    shieldeff(u.ux, u.uy);
  139. 	    You_feel("momentarily dizzy.");
  140. 	} else {
  141. 	    boolean oldprop = !!Confusion;
  142.  
  143. 	    dmg = (int)mtmp->m_lev;
  144. 	    if (Half_spell_damage) dmg = (dmg + 1) / 2;
  145. 	    make_confused(HConfusion + dmg, TRUE);
  146. 	    if (Hallucination)
  147. 		You_feel("%s!", oldprop ? "trippier" : "trippy");
  148. 	    else
  149. 		You_feel("%sconfused!", oldprop ? "more " : "");
  150. 	}
  151. 	dmg = 0;
  152. 	break;
  153. case CLC_CURE_SELF:
  154. 	if (mtmp->mhp < mtmp->mhpmax) {
  155. 	    if (canseemon(mtmp))
  156. 		pline("%s looks better.", Monnam(mtmp));
  157. 	    /* note: player healing does 6d4; this used to do 1d8 */
  158. 	    if ((mtmp->mhp += d(3,6)) > mtmp->mhpmax)
  159. 		mtmp->mhp = mtmp->mhpmax;
  160. 	    dmg = 0;
  161. 	}
  162. 	break;
  163. case CLC_OPEN_WOUNDS:
  164. 	if (Antimagic) {
  165. 	    shieldeff(u.ux, u.uy);
  166. 	    dmg = (dmg + 1) / 2;
  167. 	}
  168. 	if (dmg <= 5)
  169. 	    Your("skin itches badly for a moment.");
  170. 	else if (dmg <= 10)
  171. 	    pline("Wounds appear on your body!");
  172. 	else if (dmg <= 20)
  173. 	    pline("Severe wounds appear on your body!");
  174. 	else
  175. 	    Your("body is covered with painful wounds!");
  176. 	break;
  177. default:
  178. 	impossible("mcastu: invalid clerical spell (%d)", spellnum);
  179. 	dmg = 0;
  180. 	break;
  181. }
  182.  
  183. if (dmg) mdamageu(mtmp, dmg);
  184. }

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. }

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 && (spellnum == MGC_AGGRAVATION ||
  20. 		spellnum == MGC_SUMMON_MONS || spellnum == MGC_CLONE_WIZ))
  21. 	    return TRUE;
  22. 	/* haste self when already fast */
  23. 	if (mtmp->permspeed == MFAST && spellnum == MGC_HASTE_SELF)
  24. 	    return TRUE;
  25. 	/* invisibility when already invisible */
  26. 	if ((mtmp->minvis || mtmp->invis_blkd) && spellnum == MGC_DISAPPEAR)
  27. 	    return TRUE;
  28. 	/* peaceful monster won't cast invisibility if you can't see invisible,
  29. 	   same as when monsters drink potions of invisibility.  This doesn't
  30. 	   really make a lot of sense, but lets the player avoid hitting
  31. 	   peaceful monsters by mistake */
  32. 	if (mtmp->mpeaceful && !See_invisible && spellnum == MGC_DISAPPEAR)
  33. 	    return TRUE;
  34. 	/* healing when already healed */
  35. 	if (mtmp->mhp == mtmp->mhpmax && spellnum == MGC_CURE_SELF)
  36. 	    return TRUE;
  37. 	/* don't summon monsters if it doesn't think you're around */
  38. 	if (!mcouldseeu && (spellnum == MGC_SUMMON_MONS ||
  39. 		(!mtmp->iswiz && spellnum == MGC_CLONE_WIZ)))
  40. 	    return TRUE;
  41. 	if ((!mtmp->iswiz || flags.no_of_wizards > 1)
  42. 						&& spellnum == MGC_CLONE_WIZ)
  43. 	    return TRUE;
  44. } else if (adtyp == AD_CLRC) {
  45. 	/* summon insects/sticks to snakes won't be cast by peaceful monsters */
  46. 	if (mtmp->mpeaceful && spellnum == CLC_INSECTS)
  47. 	    return TRUE;
  48. 	/* healing when already healed */
  49. 	if (mtmp->mhp == mtmp->mhpmax && spellnum == CLC_CURE_SELF)
  50. 	    return TRUE;
  51. 	/* don't summon insects if it doesn't think you're around */
  52. 	if (!mcouldseeu && spellnum == CLC_INSECTS)
  53. 	    return TRUE;
  54. 	/* blindness spell on blinded player */
  55. 	if (Blinded && spellnum == CLC_BLIND_YOU)
  56. 	    return TRUE;
  57. }
  58. return FALSE;
  59. }
  60.  
  61. #endif /* OVLB */

buzzmu[edit]

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