Source:NetHack 3.6.7/src/mcastu.c
Jump to navigation
Jump to search
Below is the full text to mcastu.c from the source code of NetHack 3.6.7. To link to a particular line, write [[Source:NetHack 3.6.7/src/mcastu.c#line12]], 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.
1. /* NetHack 3.6 mcastu.c $NHDT-Date: 1567418129 2019/09/02 09:55:29 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.55 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Robert Patrick Rankin, 2011. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #include "hack.h" 7. 8. /* monster mage spells */ 9. enum mcast_mage_spells { 10. MGC_PSI_BOLT = 0, 11. MGC_CURE_SELF, 12. MGC_HASTE_SELF, 13. MGC_STUN_YOU, 14. MGC_DISAPPEAR, 15. MGC_WEAKEN_YOU, 16. MGC_DESTRY_ARMR, 17. MGC_CURSE_ITEMS, 18. MGC_AGGRAVATION, 19. MGC_SUMMON_MONS, 20. MGC_CLONE_WIZ, 21. MGC_DEATH_TOUCH 22. }; 23. 24. /* monster cleric spells */ 25. enum mcast_cleric_spells { 26. CLC_OPEN_WOUNDS = 0, 27. CLC_CURE_SELF, 28. CLC_CONFUSE_YOU, 29. CLC_PARALYZE, 30. CLC_BLIND_YOU, 31. CLC_INSECTS, 32. CLC_CURSE_ITEMS, 33. CLC_LIGHTNING, 34. CLC_FIRE_PILLAR, 35. CLC_GEYSER 36. }; 37. 38. STATIC_DCL void FDECL(cursetxt, (struct monst *, BOOLEAN_P)); 39. STATIC_DCL int FDECL(choose_magic_spell, (int)); 40. STATIC_DCL int FDECL(choose_clerical_spell, (int)); 41. STATIC_DCL int FDECL(m_cure_self, (struct monst *, int)); 42. STATIC_DCL void FDECL(cast_wizard_spell, (struct monst *, int, int)); 43. STATIC_DCL void FDECL(cast_cleric_spell, (struct monst *, int, int)); 44. STATIC_DCL boolean FDECL(is_undirected_spell, (unsigned int, int)); 45. STATIC_DCL boolean 46. FDECL(spell_would_be_useless, (struct monst *, unsigned int, int)); 47. 48. extern const char *const flash_types[]; /* from zap.c */ 49. 50. /* feedback when frustrated monster couldn't cast a spell */ 51. STATIC_OVL 52. void 53. cursetxt(mtmp, undirected) 54. struct monst *mtmp; 55. boolean undirected; 56. { 57. if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my)) { 58. const char *point_msg; /* spellcasting monsters are impolite */ 59. 60. if (undirected) 61. point_msg = "all around, then curses"; 62. else if ((Invis && !perceives(mtmp->data) 63. && (mtmp->mux != u.ux || mtmp->muy != u.uy)) 64. || is_obj_mappear(&youmonst, STRANGE_OBJECT) 65. || u.uundetected) 66. point_msg = "and curses in your general direction"; 67. else if (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy)) 68. point_msg = "and curses at your displaced image"; 69. else 70. point_msg = "at you, then curses"; 71. 72. pline("%s points %s.", Monnam(mtmp), point_msg); 73. } else if ((!(moves % 4) || !rn2(4))) { 74. if (!Deaf) 75. Norep("You hear a mumbled curse."); /* Deaf-aware */ 76. } 77. } 78. 79. /* convert a level based random selection into a specific mage spell; 80. inappropriate choices will be screened out by spell_would_be_useless() */ 81. STATIC_OVL int 82. choose_magic_spell(spellval) 83. int spellval; 84. { 85. /* for 3.4.3 and earlier, val greater than 22 selected the default spell 86. */ 87. while (spellval > 24 && rn2(25)) 88. spellval = rn2(spellval); 89. 90. switch (spellval) { 91. case 24: 92. case 23: 93. if (Antimagic || Hallucination) 94. return MGC_PSI_BOLT; 95. /*FALLTHRU*/ 96. case 22: 97. case 21: 98. case 20: 99. return MGC_DEATH_TOUCH; 100. case 19: 101. case 18: 102. return MGC_CLONE_WIZ; 103. case 17: 104. case 16: 105. case 15: 106. return MGC_SUMMON_MONS; 107. case 14: 108. case 13: 109. return MGC_AGGRAVATION; 110. case 12: 111. case 11: 112. case 10: 113. return MGC_CURSE_ITEMS; 114. case 9: 115. case 8: 116. return MGC_DESTRY_ARMR; 117. case 7: 118. case 6: 119. return MGC_WEAKEN_YOU; 120. case 5: 121. case 4: 122. return MGC_DISAPPEAR; 123. case 3: 124. return MGC_STUN_YOU; 125. case 2: 126. return MGC_HASTE_SELF; 127. case 1: 128. return MGC_CURE_SELF; 129. case 0: 130. default: 131. return MGC_PSI_BOLT; 132. } 133. } 134. 135. /* convert a level based random selection into a specific cleric spell */ 136. STATIC_OVL int 137. choose_clerical_spell(spellnum) 138. int spellnum; 139. { 140. /* for 3.4.3 and earlier, num greater than 13 selected the default spell 141. */ 142. while (spellnum > 15 && rn2(16)) 143. spellnum = rn2(spellnum); 144. 145. switch (spellnum) { 146. case 15: 147. case 14: 148. if (rn2(3)) 149. return CLC_OPEN_WOUNDS; 150. /*FALLTHRU*/ 151. case 13: 152. return CLC_GEYSER; 153. case 12: 154. return CLC_FIRE_PILLAR; 155. case 11: 156. return CLC_LIGHTNING; 157. case 10: 158. case 9: 159. return CLC_CURSE_ITEMS; 160. case 8: 161. return CLC_INSECTS; 162. case 7: 163. case 6: 164. return CLC_BLIND_YOU; 165. case 5: 166. case 4: 167. return CLC_PARALYZE; 168. case 3: 169. case 2: 170. return CLC_CONFUSE_YOU; 171. case 1: 172. return CLC_CURE_SELF; 173. case 0: 174. default: 175. return CLC_OPEN_WOUNDS; 176. } 177. } 178. 179. /* return values: 180. * 1: successful spell 181. * 0: unsuccessful spell 182. */ 183. int 184. castmu(mtmp, mattk, thinks_it_foundyou, foundyou) 185. register struct monst *mtmp; 186. register struct attack *mattk; 187. boolean thinks_it_foundyou; 188. boolean foundyou; 189. { 190. int dmg, ml = mtmp->m_lev; 191. int ret; 192. int spellnum = 0; 193. 194. /* Three cases: 195. * -- monster is attacking you. Search for a useful spell. 196. * -- monster thinks it's attacking you. Search for a useful spell, 197. * without checking for undirected. If the spell found is directed, 198. * it fails with cursetxt() and loss of mspec_used. 199. * -- monster isn't trying to attack. Select a spell once. Don't keep 200. * searching; if that spell is not useful (or if it's directed), 201. * return and do something else. 202. * Since most spells are directed, this means that a monster that isn't 203. * attacking casts spells only a small portion of the time that an 204. * attacking monster does. 205. */ 206. if ((mattk->adtyp == AD_SPEL || mattk->adtyp == AD_CLRC) && ml) { 207. int cnt = 40; 208. 209. do { 210. spellnum = rn2(ml); 211. if (mattk->adtyp == AD_SPEL) 212. spellnum = choose_magic_spell(spellnum); 213. else 214. spellnum = choose_clerical_spell(spellnum); 215. /* not trying to attack? don't allow directed spells */ 216. if (!thinks_it_foundyou) { 217. if (!is_undirected_spell(mattk->adtyp, spellnum) 218. || spell_would_be_useless(mtmp, mattk->adtyp, spellnum)) { 219. if (foundyou) 220. impossible( 221. "spellcasting monster found you and doesn't know it?"); 222. return 0; 223. } 224. break; 225. } 226. } while (--cnt > 0 227. && spell_would_be_useless(mtmp, mattk->adtyp, spellnum)); 228. if (cnt == 0) 229. return 0; 230. } 231. 232. /* monster unable to cast spells? */ 233. if (mtmp->mcan || mtmp->mspec_used || !ml) { 234. cursetxt(mtmp, is_undirected_spell(mattk->adtyp, spellnum)); 235. return (0); 236. } 237. 238. if (mattk->adtyp == AD_SPEL || mattk->adtyp == AD_CLRC) { 239. mtmp->mspec_used = 10 - mtmp->m_lev; 240. if (mtmp->mspec_used < 2) 241. mtmp->mspec_used = 2; 242. } 243. 244. /* monster can cast spells, but is casting a directed spell at the 245. wrong place? If so, give a message, and return. Do this *after* 246. penalizing mspec_used. */ 247. if (!foundyou && thinks_it_foundyou 248. && !is_undirected_spell(mattk->adtyp, spellnum)) { 249. pline("%s casts a spell at %s!", 250. canseemon(mtmp) ? Monnam(mtmp) : "Something", 251. levl[mtmp->mux][mtmp->muy].typ == WATER ? "empty water" 252. : "thin air"); 253. return (0); 254. } 255. 256. nomul(0); 257. if (rn2(ml * 10) < (mtmp->mconf ? 100 : 20)) { /* fumbled attack */ 258. if (canseemon(mtmp) && !Deaf) 259. pline_The("air crackles around %s.", mon_nam(mtmp)); 260. return (0); 261. } 262. if (canspotmon(mtmp) || !is_undirected_spell(mattk->adtyp, spellnum)) { 263. pline("%s casts a spell%s!", 264. canspotmon(mtmp) ? Monnam(mtmp) : "Something", 265. is_undirected_spell(mattk->adtyp, spellnum) 266. ? "" 267. : (Invis && !perceives(mtmp->data) 268. && (mtmp->mux != u.ux || mtmp->muy != u.uy)) 269. ? " at a spot near you" 270. : (Displaced 271. && (mtmp->mux != u.ux || mtmp->muy != u.uy)) 272. ? " at your displaced image" 273. : " at you"); 274. } 275. 276. /* 277. * As these are spells, the damage is related to the level 278. * of the monster casting the spell. 279. */ 280. if (!foundyou) { 281. dmg = 0; 282. if (mattk->adtyp != AD_SPEL && mattk->adtyp != AD_CLRC) { 283. impossible( 284. "%s casting non-hand-to-hand version of hand-to-hand spell %d?", 285. Monnam(mtmp), mattk->adtyp); 286. return (0); 287. } 288. } else if (mattk->damd) 289. dmg = d((int) ((ml / 2) + mattk->damn), (int) mattk->damd); 290. else 291. dmg = d((int) ((ml / 2) + 1), 6); 292. if (Half_spell_damage) 293. dmg = (dmg + 1) / 2; 294. 295. ret = 1; 296. 297. switch (mattk->adtyp) { 298. case AD_FIRE: 299. pline("You're enveloped in flames."); 300. if (Fire_resistance) { 301. shieldeff(u.ux, u.uy); 302. pline("But you resist the effects."); 303. dmg = 0; 304. } 305. burn_away_slime(); 306. break; 307. case AD_COLD: 308. pline("You're covered in frost."); 309. if (Cold_resistance) { 310. shieldeff(u.ux, u.uy); 311. pline("But you resist the effects."); 312. dmg = 0; 313. } 314. break; 315. case AD_MAGM: 316. You("are hit by a shower of missiles!"); 317. if (Antimagic) { 318. shieldeff(u.ux, u.uy); 319. pline_The("missiles bounce off!"); 320. dmg = 0; 321. } else 322. dmg = d((int) mtmp->m_lev / 2 + 1, 6); 323. break; 324. case AD_SPEL: /* wizard spell */ 325. case AD_CLRC: /* clerical spell */ 326. { 327. if (mattk->adtyp == AD_SPEL) 328. cast_wizard_spell(mtmp, dmg, spellnum); 329. else 330. cast_cleric_spell(mtmp, dmg, spellnum); 331. dmg = 0; /* done by the spell casting functions */ 332. break; 333. } 334. } 335. if (dmg) 336. mdamageu(mtmp, dmg); 337. return (ret); 338. } 339. 340. STATIC_OVL int 341. m_cure_self(mtmp, dmg) 342. struct monst *mtmp; 343. int dmg; 344. { 345. if (mtmp->mhp < mtmp->mhpmax) { 346. if (canseemon(mtmp)) 347. pline("%s looks better.", Monnam(mtmp)); 348. /* note: player healing does 6d4; this used to do 1d8 */ 349. if ((mtmp->mhp += d(3, 6)) > mtmp->mhpmax) 350. mtmp->mhp = mtmp->mhpmax; 351. dmg = 0; 352. } 353. return dmg; 354. } 355. 356. /* monster wizard and cleric spellcasting functions */ 357. /* 358. If dmg is zero, then the monster is not casting at you. 359. If the monster is intentionally not casting at you, we have previously 360. called spell_would_be_useless() and spellnum should always be a valid 361. undirected spell. 362. If you modify either of these, be sure to change is_undirected_spell() 363. and spell_would_be_useless(). 364. */ 365. STATIC_OVL 366. void 367. cast_wizard_spell(mtmp, dmg, spellnum) 368. struct monst *mtmp; 369. int dmg; 370. int spellnum; 371. { 372. if (dmg == 0 && !is_undirected_spell(AD_SPEL, spellnum)) { 373. impossible("cast directed wizard spell (%d) with dmg=0?", spellnum); 374. return; 375. } 376. 377. switch (spellnum) { 378. case MGC_DEATH_TOUCH: 379. pline("Oh no, %s's using the touch of death!", mhe(mtmp)); 380. if (nonliving(youmonst.data) || is_demon(youmonst.data)) { 381. You("seem no deader than before."); 382. } else if (!Antimagic && rn2(mtmp->m_lev) > 12) { 383. if (Hallucination) { 384. You("have an out of body experience."); 385. } else { 386. killer.format = KILLED_BY_AN; 387. Strcpy(killer.name, "touch of death"); 388. done(DIED); 389. } 390. } else { 391. if (Antimagic) 392. shieldeff(u.ux, u.uy); 393. pline("Lucky for you, it didn't work!"); 394. } 395. dmg = 0; 396. break; 397. case MGC_CLONE_WIZ: 398. if (mtmp->iswiz && context.no_of_wizards == 1) { 399. pline("Double Trouble..."); 400. clonewiz(); 401. dmg = 0; 402. } else 403. impossible("bad wizard cloning?"); 404. break; 405. case MGC_SUMMON_MONS: { 406. int count; 407. 408. count = nasty(mtmp); /* summon something nasty */ 409. if (mtmp->iswiz) { 410. verbalize("Destroy the thief, my pet%s!", plur(count)); 411. } else { 412. const char *mappear = (count == 1) ? "A monster appears" 413. : "Monsters appear"; 414. 415. /* messages not quite right if plural monsters created but 416. only a single monster is seen */ 417. if (Invis && !perceives(mtmp->data) 418. && (mtmp->mux != u.ux || mtmp->muy != u.uy)) 419. pline("%s around a spot near you!", mappear); 420. else if (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy)) 421. pline("%s around your displaced image!", mappear); 422. else 423. pline("%s from nowhere!", mappear); 424. } 425. dmg = 0; 426. break; 427. } 428. case MGC_AGGRAVATION: 429. You_feel("that monsters are aware of your presence."); 430. aggravate(); 431. dmg = 0; 432. break; 433. case MGC_CURSE_ITEMS: 434. You_feel("as if you need some help."); 435. rndcurse(); 436. dmg = 0; 437. break; 438. case MGC_DESTRY_ARMR: 439. if (Antimagic) { 440. shieldeff(u.ux, u.uy); 441. pline("A field of force surrounds you!"); 442. } else if (!destroy_arm(some_armor(&youmonst))) { 443. Your("skin itches."); 444. } 445. dmg = 0; 446. break; 447. case MGC_WEAKEN_YOU: /* drain strength */ 448. if (Antimagic) { 449. shieldeff(u.ux, u.uy); 450. You_feel("momentarily weakened."); 451. } else { 452. You("suddenly feel weaker!"); 453. dmg = mtmp->m_lev - 6; 454. if (Half_spell_damage) 455. dmg = (dmg + 1) / 2; 456. losestr(rnd(dmg)); 457. if (u.uhp < 1) 458. done_in_by(mtmp, DIED); 459. } 460. dmg = 0; 461. break; 462. case MGC_DISAPPEAR: /* makes self invisible */ 463. if (!mtmp->minvis && !mtmp->invis_blkd) { 464. if (canseemon(mtmp)) 465. pline("%s suddenly %s!", Monnam(mtmp), 466. !See_invisible ? "disappears" : "becomes transparent"); 467. mon_set_minvis(mtmp); 468. if (cansee(mtmp->mx, mtmp->my) && !canspotmon(mtmp)) 469. map_invisible(mtmp->mx, mtmp->my); 470. dmg = 0; 471. } else 472. impossible("no reason for monster to cast disappear spell?"); 473. break; 474. case MGC_STUN_YOU: 475. if (Antimagic || Free_action) { 476. shieldeff(u.ux, u.uy); 477. if (!Stunned) 478. You_feel("momentarily disoriented."); 479. make_stunned(1L, FALSE); 480. } else { 481. You(Stunned ? "struggle to keep your balance." : "reel..."); 482. dmg = d(ACURR(A_DEX) < 12 ? 6 : 4, 4); 483. if (Half_spell_damage) 484. dmg = (dmg + 1) / 2; 485. make_stunned((HStun & TIMEOUT) + (long) dmg, FALSE); 486. } 487. dmg = 0; 488. break; 489. case MGC_HASTE_SELF: 490. mon_adjust_speed(mtmp, 1, (struct obj *) 0); 491. dmg = 0; 492. break; 493. case MGC_CURE_SELF: 494. dmg = m_cure_self(mtmp, dmg); 495. break; 496. case MGC_PSI_BOLT: 497. /* prior to 3.4.0 Antimagic was setting the damage to 1--this 498. made the spell virtually harmless to players with magic res. */ 499. if (Antimagic) { 500. shieldeff(u.ux, u.uy); 501. dmg = (dmg + 1) / 2; 502. } 503. if (dmg <= 5) 504. You("get a slight %sache.", body_part(HEAD)); 505. else if (dmg <= 10) 506. Your("brain is on fire!"); 507. else if (dmg <= 20) 508. Your("%s suddenly aches painfully!", body_part(HEAD)); 509. else 510. Your("%s suddenly aches very painfully!", body_part(HEAD)); 511. break; 512. default: 513. impossible("mcastu: invalid magic spell (%d)", spellnum); 514. dmg = 0; 515. break; 516. } 517. 518. if (dmg) 519. mdamageu(mtmp, dmg); 520. } 521. 522. STATIC_OVL 523. void 524. cast_cleric_spell(mtmp, dmg, spellnum) 525. struct monst *mtmp; 526. int dmg; 527. int spellnum; 528. { 529. if (dmg == 0 && !is_undirected_spell(AD_CLRC, spellnum)) { 530. impossible("cast directed cleric spell (%d) with dmg=0?", spellnum); 531. return; 532. } 533. 534. switch (spellnum) { 535. case CLC_GEYSER: 536. /* this is physical damage (force not heat), 537. * not magical damage or fire damage 538. */ 539. pline("A sudden geyser slams into you from nowhere!"); 540. dmg = d(8, 6); 541. if (Half_physical_damage) 542. dmg = (dmg + 1) / 2; 543. break; 544. case CLC_FIRE_PILLAR: 545. pline("A pillar of fire strikes all around you!"); 546. if (Fire_resistance) { 547. shieldeff(u.ux, u.uy); 548. dmg = 0; 549. } else 550. dmg = d(8, 6); 551. if (Half_spell_damage) 552. dmg = (dmg + 1) / 2; 553. burn_away_slime(); 554. (void) burnarmor(&youmonst); 555. destroy_item(SCROLL_CLASS, AD_FIRE); 556. destroy_item(POTION_CLASS, AD_FIRE); 557. destroy_item(SPBOOK_CLASS, AD_FIRE); 558. (void) burn_floor_objects(u.ux, u.uy, TRUE, FALSE); 559. break; 560. case CLC_LIGHTNING: { 561. boolean reflects; 562. 563. pline("A bolt of lightning strikes down at you from above!"); 564. reflects = ureflects("It bounces off your %s%s.", ""); 565. if (reflects || Shock_resistance) { 566. shieldeff(u.ux, u.uy); 567. dmg = 0; 568. if (reflects) 569. break; 570. } else 571. dmg = d(8, 6); 572. if (Half_spell_damage) 573. dmg = (dmg + 1) / 2; 574. destroy_item(WAND_CLASS, AD_ELEC); 575. destroy_item(RING_CLASS, AD_ELEC); 576. (void) flashburn((long) rnd(100)); 577. break; 578. } 579. case CLC_CURSE_ITEMS: 580. You_feel("as if you need some help."); 581. rndcurse(); 582. dmg = 0; 583. break; 584. case CLC_INSECTS: { 585. /* Try for insects, and if there are none 586. left, go for (sticks to) snakes. -3. */ 587. struct permonst *pm = mkclass(S_ANT, 0); 588. struct monst *mtmp2 = (struct monst *) 0; 589. char let = (pm ? S_ANT : S_SNAKE); 590. boolean success = FALSE, seecaster; 591. int i, quan, oldseen, newseen; 592. coord bypos; 593. const char *fmt; 594. 595. oldseen = monster_census(TRUE); 596. quan = (mtmp->m_lev < 2) ? 1 : rnd((int) mtmp->m_lev / 2); 597. if (quan < 3) 598. quan = 3; 599. for (i = 0; i <= quan; i++) { 600. if (!enexto(&bypos, mtmp->mux, mtmp->muy, mtmp->data)) 601. break; 602. if ((pm = mkclass(let, 0)) != 0 603. && (mtmp2 = makemon(pm, bypos.x, bypos.y, MM_ANGRY)) != 0) { 604. success = TRUE; 605. mtmp2->msleeping = mtmp2->mpeaceful = mtmp2->mtame = 0; 606. set_malign(mtmp2); 607. } 608. } 609. newseen = monster_census(TRUE); 610. 611. /* not canspotmon(), which includes unseen things sensed via warning 612. */ 613. seecaster = canseemon(mtmp) || tp_sensemon(mtmp) || Detect_monsters; 614. 615. fmt = 0; 616. if (!seecaster) { 617. char *arg; /* [not const: upstart(N==1 ? an() : makeplural())] */ 618. const char *what = (let == S_SNAKE) ? "snake" : "insect"; 619. 620. if (newseen <= oldseen || Unaware) { 621. /* unseen caster fails or summons unseen critters, 622. or unconscious hero ("You dream that you hear...") */ 623. You_hear("someone summoning %s.", makeplural(what)); 624. } else { 625. /* unseen caster summoned seen critter(s) */ 626. arg = (newseen == oldseen + 1) ? an(what) : makeplural(what); 627. if (!Deaf) 628. You_hear("someone summoning something, and %s %s.", arg, 629. vtense(arg, "appear")); 630. else 631. pline("%s %s.", upstart(arg), vtense(arg, "appear")); 632. } 633. 634. /* seen caster, possibly producing unseen--or just one--critters; 635. hero is told what the caster is doing and doesn't necessarily 636. observe complete accuracy of that caster's results (in other 637. words, no need to fuss with visibility or singularization; 638. player is told what's happening even if hero is unconscious) */ 639. } else if (!success) 640. fmt = "%s casts at a clump of sticks, but nothing happens."; 641. else if (let == S_SNAKE) 642. fmt = "%s transforms a clump of sticks into snakes!"; 643. else if (Invis && !perceives(mtmp->data) 644. && (mtmp->mux != u.ux || mtmp->muy != u.uy)) 645. fmt = "%s summons insects around a spot near you!"; 646. else if (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy)) 647. fmt = "%s summons insects around your displaced image!"; 648. else 649. fmt = "%s summons insects!"; 650. if (fmt) 651. pline(fmt, Monnam(mtmp)); 652. 653. dmg = 0; 654. break; 655. } 656. case CLC_BLIND_YOU: 657. /* note: resists_blnd() doesn't apply here */ 658. if (!Blinded) { 659. int num_eyes = eyecount(youmonst.data); 660. pline("Scales cover your %s!", (num_eyes == 1) 661. ? body_part(EYE) 662. : makeplural(body_part(EYE))); 663. make_blinded(Half_spell_damage ? 100L : 200L, FALSE); 664. if (!Blind) 665. Your1(vision_clears); 666. dmg = 0; 667. } else 668. impossible("no reason for monster to cast blindness spell?"); 669. break; 670. case CLC_PARALYZE: 671. if (Antimagic || Free_action) { 672. shieldeff(u.ux, u.uy); 673. if (multi >= 0) 674. You("stiffen briefly."); 675. nomul(-1); 676. multi_reason = "paralyzed by a monster"; 677. } else { 678. if (multi >= 0) 679. You("are frozen in place!"); 680. dmg = 4 + (int) mtmp->m_lev; 681. if (Half_spell_damage) 682. dmg = (dmg + 1) / 2; 683. nomul(-dmg); 684. multi_reason = "paralyzed by a monster"; 685. } 686. nomovemsg = 0; 687. dmg = 0; 688. break; 689. case CLC_CONFUSE_YOU: 690. if (Antimagic) { 691. shieldeff(u.ux, u.uy); 692. You_feel("momentarily dizzy."); 693. } else { 694. boolean oldprop = !!Confusion; 695. 696. dmg = (int) mtmp->m_lev; 697. if (Half_spell_damage) 698. dmg = (dmg + 1) / 2; 699. make_confused(HConfusion + dmg, TRUE); 700. if (Hallucination) 701. You_feel("%s!", oldprop ? "trippier" : "trippy"); 702. else 703. You_feel("%sconfused!", oldprop ? "more " : ""); 704. } 705. dmg = 0; 706. break; 707. case CLC_CURE_SELF: 708. dmg = m_cure_self(mtmp, dmg); 709. break; 710. case CLC_OPEN_WOUNDS: 711. if (Antimagic) { 712. shieldeff(u.ux, u.uy); 713. dmg = (dmg + 1) / 2; 714. } 715. if (dmg <= 5) 716. Your("skin itches badly for a moment."); 717. else if (dmg <= 10) 718. pline("Wounds appear on your body!"); 719. else if (dmg <= 20) 720. pline("Severe wounds appear on your body!"); 721. else 722. Your("body is covered with painful wounds!"); 723. break; 724. default: 725. impossible("mcastu: invalid clerical spell (%d)", spellnum); 726. dmg = 0; 727. break; 728. } 729. 730. if (dmg) 731. mdamageu(mtmp, dmg); 732. } 733. 734. STATIC_DCL 735. boolean 736. is_undirected_spell(adtyp, spellnum) 737. unsigned int adtyp; 738. int spellnum; 739. { 740. if (adtyp == AD_SPEL) { 741. switch (spellnum) { 742. case MGC_CLONE_WIZ: 743. case MGC_SUMMON_MONS: 744. case MGC_AGGRAVATION: 745. case MGC_DISAPPEAR: 746. case MGC_HASTE_SELF: 747. case MGC_CURE_SELF: 748. return TRUE; 749. default: 750. break; 751. } 752. } else if (adtyp == AD_CLRC) { 753. switch (spellnum) { 754. case CLC_INSECTS: 755. case CLC_CURE_SELF: 756. return TRUE; 757. default: 758. break; 759. } 760. } 761. return FALSE; 762. } 763. 764. /* Some spells are useless under some circumstances. */ 765. STATIC_DCL 766. boolean 767. spell_would_be_useless(mtmp, adtyp, spellnum) 768. struct monst *mtmp; 769. unsigned int adtyp; 770. int spellnum; 771. { 772. /* Some spells don't require the player to really be there and can be cast 773. * by the monster when you're invisible, yet still shouldn't be cast when 774. * the monster doesn't even think you're there. 775. * This check isn't quite right because it always uses your real position. 776. * We really want something like "if the monster could see mux, muy". 777. */ 778. boolean mcouldseeu = couldsee(mtmp->mx, mtmp->my); 779. 780. if (adtyp == AD_SPEL) { 781. /* aggravate monsters, etc. won't be cast by peaceful monsters */ 782. if (mtmp->mpeaceful 783. && (spellnum == MGC_AGGRAVATION || spellnum == MGC_SUMMON_MONS 784. || spellnum == MGC_CLONE_WIZ)) 785. return TRUE; 786. /* haste self when already fast */ 787. if (mtmp->permspeed == MFAST && spellnum == MGC_HASTE_SELF) 788. return TRUE; 789. /* invisibility when already invisible */ 790. if ((mtmp->minvis || mtmp->invis_blkd) && spellnum == MGC_DISAPPEAR) 791. return TRUE; 792. /* peaceful monster won't cast invisibility if you can't see 793. invisible, 794. same as when monsters drink potions of invisibility. This doesn't 795. really make a lot of sense, but lets the player avoid hitting 796. peaceful monsters by mistake */ 797. if (mtmp->mpeaceful && !See_invisible && spellnum == MGC_DISAPPEAR) 798. return TRUE; 799. /* healing when already healed */ 800. if (mtmp->mhp == mtmp->mhpmax && spellnum == MGC_CURE_SELF) 801. return TRUE; 802. /* don't summon monsters if it doesn't think you're around */ 803. if (!mcouldseeu && (spellnum == MGC_SUMMON_MONS 804. || (!mtmp->iswiz && spellnum == MGC_CLONE_WIZ))) 805. return TRUE; 806. if ((!mtmp->iswiz || context.no_of_wizards > 1) 807. && spellnum == MGC_CLONE_WIZ) 808. return TRUE; 809. /* aggravation (global wakeup) when everyone is already active */ 810. if (spellnum == MGC_AGGRAVATION) { 811. /* if nothing needs to be awakened then this spell is useless 812. but caster might not realize that [chance to pick it then 813. must be very small otherwise caller's many retry attempts 814. will eventually end up picking it too often] */ 815. if (!has_aggravatables(mtmp)) 816. return rn2(100) ? TRUE : FALSE; 817. } 818. } else if (adtyp == AD_CLRC) { 819. /* summon insects/sticks to snakes won't be cast by peaceful monsters 820. */ 821. if (mtmp->mpeaceful && spellnum == CLC_INSECTS) 822. return TRUE; 823. /* healing when already healed */ 824. if (mtmp->mhp == mtmp->mhpmax && spellnum == CLC_CURE_SELF) 825. return TRUE; 826. /* don't summon insects if it doesn't think you're around */ 827. if (!mcouldseeu && spellnum == CLC_INSECTS) 828. return TRUE; 829. /* blindness spell on blinded player */ 830. if (Blinded && spellnum == CLC_BLIND_YOU) 831. return TRUE; 832. } 833. return FALSE; 834. } 835. 836. /* convert 1..10 to 0..9; add 10 for second group (spell casting) */ 837. #define ad_to_typ(k) (10 + (int) k - 1) 838. 839. /* monster uses spell (ranged) */ 840. int 841. buzzmu(mtmp, mattk) 842. register struct monst *mtmp; 843. register struct attack *mattk; 844. { 845. /* don't print constant stream of curse messages for 'normal' 846. spellcasting monsters at range */ 847. if (mattk->adtyp > AD_SPC2) 848. return (0); 849. 850. if (mtmp->mcan) { 851. cursetxt(mtmp, FALSE); 852. return (0); 853. } 854. if (lined_up(mtmp) && rn2(3)) { 855. nomul(0); 856. if (mattk->adtyp && (mattk->adtyp < 11)) { /* no cf unsigned >0 */ 857. if (canseemon(mtmp)) 858. pline("%s zaps you with a %s!", Monnam(mtmp), 859. flash_types[ad_to_typ(mattk->adtyp)]); 860. buzz(-ad_to_typ(mattk->adtyp), (int) mattk->damn, mtmp->mx, 861. mtmp->my, sgn(tbx), sgn(tby)); 862. } else 863. impossible("Monster spell %d cast", mattk->adtyp - 1); 864. } 865. return (1); 866. } 867. 868. /*mcastu.c*/