abstract
| - Below is the full text to wizard.c from the source code of NetHack 3.1.0. To link to a particular line, write [[NetHack 3.1.0/wizard.c#line123]], for example. Warning! This is the source code from an old release. For the latest release, see Source code 1. /* SCCS Id: @(#)wizard.c 3.1 92/11/13 */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /* NetHack may be freely redistributed. See license for details. */ 4. 5. /* wizard code - inspired by rogue code from Merlyn Leroy (digi-g!brian) */ 6. /* - heavily modified to give the wiz balls. (genat!mike) */ 7. /* - dewimped and given some maledictions. -3. */ 8. /* - generalized for 3.1 (mike@bullns.on01.bull.ca) */ 9. 10. #include "hack.h" 11. #ifdef MULDGN 12. #include "qtext.h" 13. #endif 14. 15. #ifdef OVLB 16. 17. static short FDECL(which_arti, (UCHAR_P)); 18. static boolean FDECL(mon_has_arti, (struct monst *,SHORT_P)); 19. static struct monst *FDECL(other_mon_has_arti, (struct monst *,SHORT_P)); 20. static struct obj *FDECL(on_ground, (SHORT_P)); 21. static boolean FDECL(you_have, (UCHAR_P)); 22. static long FDECL(target_on, (UCHAR_P,struct monst *)); 23. static long FDECL(strategy, (struct monst *)); 24. 25. /* TODO: Expand this list. */ 26. static const int NEARDATA nasties[] = { 27. PM_COCKATRICE, PM_ETTIN, PM_STALKER, PM_MINOTAUR, PM_RED_DRAGON, 28. PM_GREEN_DRAGON, PM_OWLBEAR, PM_PURPLE_WORM, PM_ROCK_TROLL, PM_XAN, 29. PM_GREMLIN, PM_UMBER_HULK, PM_VAMPIRE_LORD, PM_XORN, PM_ZRUTY, 30. PM_ELF_LORD, PM_ELVENKING, PM_YELLOW_DRAGON, PM_LEOCROTTA, 31. PM_CARNIVOROUS_APE, PM_FIRE_GIANT, PM_COUATL, 32. #ifdef ARMY 33. PM_CAPTAIN, 34. #endif 35. }; 36. 37. static const unsigned NEARDATA wizapp[] = { 38. PM_HUMAN, PM_WATER_DEMON, PM_VAMPIRE, 39. PM_RED_DRAGON, PM_TROLL, PM_UMBER_HULK, 40. PM_XORN, PM_XAN, PM_COCKATRICE, 41. PM_FLOATING_EYE, 42. PM_GUARDIAN_NAGA, 43. PM_TRAPPER 44. }; 45. 46. #endif /* OVLB */ 47. #ifdef OVL0 48. 49. /* If you've found the Amulet, make the Wizard appear after some time */ 50. /* Also, give hints about portal locations, if amulet is worn/wielded -dlc */ 51. void 52. amulet() 53. { 54. register struct monst *mtmp; 55. struct obj *amu; 56. 57. if ((((amu = uamul) && uamul->otyp == AMULET_OF_YENDOR) || 58. ((amu = uwep) && uwep->otyp == AMULET_OF_YENDOR)) && !rn2(15)) { 59. register struct trap *ttmp; 60. for(ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) { 61. if(ttmp->ttyp == MAGIC_PORTAL) { 62. int du = distu(ttmp->tx, ttmp->ty); 63. if (du <= 9) 64. pline("%s feels hot!", The(xname(amu))); 65. else if (du <= 64) 66. pline("%s feels very warm.", The(xname(amu))); 67. else if (du <= 144) 68. pline("%s feels warm.", The(xname(amu))); 69. /* else, the amulet feels normal */ 70. break; 71. } 72. } 73. } 74. 75. if (!flags.no_of_wizards || !u.uhave.amulet) 76. return; 77. /* find Wizard, and wake him if necessary */ 78. for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) 79. if(mtmp->iswiz && mtmp->msleep && !rn2(40)) { 80. mtmp->msleep = 0; 81. if (distu(mtmp->mx,mtmp->my) > 2) 82. You( 83. "get the creepy feeling that somebody noticed your taking the Amulet." 84. ); 85. return; 86. } 87. } 88. 89. #endif /* OVL0 */ 90. #ifdef OVLB 91. 92. int 93. mon_has_amulet(mtmp) 94. register struct monst *mtmp; 95. { 96. register struct obj *otmp; 97. 98. for(otmp = mtmp->minvent; otmp; otmp = otmp->nobj) 99. if(otmp->otyp == AMULET_OF_YENDOR) return(1); 100. return(0); 101. } 102. 103. int 104. mon_has_special(mtmp) 105. register struct monst *mtmp; 106. { 107. register struct obj *otmp; 108. 109. for(otmp = mtmp->minvent; otmp; otmp = otmp->nobj) 110. if(otmp->otyp == AMULET_OF_YENDOR || 111. #ifdef MULDGN 112. is_quest_artifact(otmp) || 113. #endif 114. otmp->otyp == BELL_OF_OPENING || 115. otmp->otyp == CANDELABRUM_OF_INVOCATION || 116. otmp->otyp == SPE_BOOK_OF_THE_DEAD) return(1); 117. return(0); 118. } 119. 120. /* 121. * New for 3.1 Strategy / Tactics for the wiz, as well as other 122. * monsters that are "after" something (defined via mflag3). 123. * 124. * The strategy section decides *what* the monster is going 125. * to attempt, the tactics section implements the decision. 126. */ 127. #define STRAT(w, x, y, typ) (w | ((long)(x)<<16) | ((long)(y)<<8) | (long)typ) 128. #define ST_NONE 0L 129. #define ST_HEAL -1L 130. #define ST_GROUND 0x04000000 131. #define ST_MONSTR 0x02000000 132. #define ST_PLAYER 0x01000000 133. 134. #define M_Wants(mask) (mtmp->data->mflags3 & (mask)) 135. 136. static short 137. which_arti(mask) 138. register uchar mask; 139. { 140. switch(mask) { 141. case M3_WANTSAMUL: return(AMULET_OF_YENDOR); 142. case M3_WANTSBELL: return(BELL_OF_OPENING); 143. case M3_WANTSCAND: return(CANDELABRUM_OF_INVOCATION); 144. case M3_WANTSBOOK: return(SPE_BOOK_OF_THE_DEAD); 145. default: break; /* 0 signifies quest artifact */ 146. } 147. return(0); 148. } 149. 150. /* 151. * If "otyp" is zero, it triggers a check for the quest_artifact, 152. * since bell, book, candle, and amulet are all objects, not really 153. * artifacts right now. [MRS] 154. */ 155. static boolean 156. mon_has_arti(mtmp, otyp) 157. register struct monst *mtmp; 158. register short otyp; 159. { 160. register struct obj *otmp; 161. 162. for(otmp = mtmp->minvent; otmp; otmp = otmp->nobj) { 163. if(otyp) { 164. if(otmp->otyp == otyp) 165. return(1); 166. } 167. #ifdef MULDGN 168. else if(is_quest_artifact(otmp)) return(1); 169. #endif 170. } 171. return(0); 172. 173. } 174. 175. static struct monst * 176. other_mon_has_arti(mtmp, otyp) 177. register struct monst *mtmp; 178. register short otyp; 179. { 180. register struct monst *mtmp2; 181. 182. for(mtmp2 = fmon; mtmp2; mtmp2 = mtmp2->nmon) 183. if(mtmp2 != mtmp) 184. if(mon_has_arti(mtmp2, otyp)) return(mtmp2); 185. 186. return((struct monst *)0); 187. } 188. 189. static struct obj * 190. on_ground(otyp) 191. register short otyp; 192. { 193. register struct obj *otmp; 194. 195. for(otmp = fobj; otmp; otmp = otmp->nobj) 196. if(otyp) { 197. if(otmp->otyp == otyp) 198. return(otmp); 199. } 200. #ifdef MULDGN 201. else if(is_quest_artifact(otmp)) return(otmp); 202. #endif 203. return((struct obj *)0); 204. } 205. 206. static boolean 207. you_have(mask) 208. register uchar mask; 209. { 210. switch(mask) { 211. case M3_WANTSAMUL: return(u.uhave.amulet); 212. case M3_WANTSBELL: return(u.uhave.bell); 213. case M3_WANTSCAND: return(u.uhave.menorah); 214. case M3_WANTSBOOK: return(u.uhave.book); 215. #ifdef MULDGN 216. case M3_WANTSARTI: return(u.uhave.questart); 217. #endif 218. default: break; 219. } 220. return(0); 221. } 222. 223. static long 224. target_on(mask, mtmp) 225. register uchar mask; 226. register struct monst *mtmp; 227. { 228. register short otyp; 229. register struct obj *otmp; 230. register struct monst *mtmp2; 231. 232. if(!M_Wants(mask)) return(ST_NONE); 233. 234. otyp = which_arti(mask); 235. if(!mon_has_arti(mtmp, otyp)) { 236. if(you_have(mask)) 237. return(STRAT(ST_PLAYER, u.ux, u.uy, mask)); 238. else if((otmp = on_ground(otyp))) 239. return(STRAT(ST_GROUND, otmp->ox, otmp->oy, mask)); 240. else if((mtmp2 = other_mon_has_arti(mtmp, otyp))) 241. return(STRAT(ST_MONSTR, mtmp2->mx, mtmp2->my, mask)); 242. } 243. return(ST_NONE); 244. } 245. 246. static long 247. strategy(mtmp) 248. register struct monst *mtmp; 249. { 250. long strat, dstrat; 251. 252. if(!is_covetous(mtmp->data)) return(ST_NONE); 253. 254. switch((mtmp->mhp*3)/mtmp->mhpmax) { /* 0-3 */ 255. 256. default: 257. case 0: /* panic time - mtmp is almost snuffed */ 258. return(ST_HEAL); 259. 260. case 1: /* the wiz is less cautious */ 261. if(mtmp->data != &mons[PM_WIZARD_OF_YENDOR]) 262. return(ST_HEAL); 263. /* else fall through */ 264. 265. case 2: dstrat = ST_HEAL; 266. break; 267. 268. case 3: dstrat = ST_NONE; 269. break; 270. } 271. 272. if(flags.made_amulet) 273. if((strat = target_on(M3_WANTSAMUL, mtmp)) != ST_NONE) 274. return(strat); 275. 276. if(u.uevent.invoked) { /* priorities change once gate opened */ 277. 278. #ifdef MULDGN 279. if((strat = target_on(M3_WANTSARTI, mtmp)) != ST_NONE) 280. return(strat); 281. #endif 282. if((strat = target_on(M3_WANTSBOOK, mtmp)) != ST_NONE) 283. return(strat); 284. if((strat = target_on(M3_WANTSBELL, mtmp)) != ST_NONE) 285. return(strat); 286. if((strat = target_on(M3_WANTSCAND, mtmp)) != ST_NONE) 287. return(strat); 288. } else { 289. 290. if((strat = target_on(M3_WANTSBOOK, mtmp)) != ST_NONE) 291. return(strat); 292. if((strat = target_on(M3_WANTSBELL, mtmp)) != ST_NONE) 293. return(strat); 294. if((strat = target_on(M3_WANTSCAND, mtmp)) != ST_NONE) 295. return(strat); 296. #ifdef MULDGN 297. if((strat = target_on(M3_WANTSARTI, mtmp)) != ST_NONE) 298. return(strat); 299. #endif 300. } 301. return(dstrat); 302. } 303. 304. int 305. tactics(mtmp) 306. register struct monst *mtmp; 307. { 308. mtmp->mstrategy = strategy(mtmp); 309. 310. switch (mtmp->mstrategy) { 311. case ST_HEAL: /* hide and recover */ 312. /* if wounded, hole up on or near the stairs (to block them) */ 313. /* unless, of course, there are no stairs (e.g. endlevel */ 314. if((xupstair || yupstair)) 315. if (mtmp->mx != xupstair || mtmp->my != yupstair) 316. (void) mnearto(mtmp, xupstair, yupstair, TRUE); 317. 318. /* if you're not around, cast healing spells */ 319. if (distu(mtmp->mx,mtmp->my) > (BOLT_LIM * BOLT_LIM)) 320. if(mtmp->mhp <= mtmp->mhpmax - 8) { 321. mtmp->mhp += rnd(8); 322. return(1); 323. } 324. /* fall through :-) */ 325. 326. case ST_NONE: /* harrass */ 327. if(!rn2(5)) mnexto(mtmp); 328. return(0); 329. 330. default: /* kill, maim, pillage! */ 331. { 332. long where = (mtmp->mstrategy & 0xff000000); 333. xchar tx = (xchar)((mtmp->mstrategy >> 16) & 0xff), 334. ty = (xchar)((mtmp->mstrategy >> 8) & 0xff); 335. uchar targ = (xchar)(mtmp->mstrategy & 0xff); 336. struct obj *otmp; 337. 338. if(!targ) { /* simply wants you to close */ 339. return(0); 340. } 341. if((u.ux == tx && u.uy == ty) || where == ST_PLAYER) { 342. /* player is standing on it (or has it) */ 343. mnexto(mtmp); 344. return(0); 345. } 346. if(where == ST_GROUND) { 347. if(!MON_AT(tx, ty) || (mtmp->mx == tx && mtmp->my == ty)) { 348. 349. /* teleport to it and pick it up */ 350. rloc_to(mtmp, tx, ty); /* clean old pos */ 351. 352. if((otmp = on_ground(which_arti(targ)))) { 353. 354. if (cansee(mtmp->mx, mtmp->my)) 355. pline("%s picks up %s.", 356. Monnam(mtmp), the(xname(otmp))); 357. freeobj(otmp); 358. mpickobj(mtmp, otmp); 359. return(1); 360. } else return(0); 361. } 362. } else { /* a monster has it - 'port beside it. */ 363. (void) mnearto(mtmp, tx, ty, TRUE); 364. return(0); 365. } 366. } 367. } 368. /* NOTREACHED */ 369. return(0); 370. } 371. 372. void 373. aggravate() 374. { 375. register struct monst *mtmp; 376. 377. for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 378. mtmp->msleep = 0; 379. if(!mtmp->mcanmove && !rn2(5)) { 380. mtmp->mfrozen = 0; 381. mtmp->mcanmove = 1; 382. } 383. } 384. } 385. 386. void 387. clonewiz() 388. { 389. register struct monst *mtmp2; 390. 391. if(mtmp2 = makemon(&mons[PM_WIZARD_OF_YENDOR], u.ux, u.uy)) { 392. mtmp2->msleep = mtmp2->mtame = mtmp2->mpeaceful = 0; 393. if (!u.uhave.amulet && rn2(2)) { /* give clone a fake */ 394. mtmp2->minvent = mksobj(FAKE_AMULET_OF_YENDOR, TRUE, FALSE); 395. } 396. mtmp2->m_ap_type = M_AP_MONSTER; 397. mtmp2->mappearance = wizapp[rn2(SIZE(wizapp))]; 398. newsym(mtmp2->mx,mtmp2->my); 399. } 400. } 401. 402. /* create some nasty monsters, aligned or neutral with the caster */ 403. /* a null caster defaults to a chaotic caster (e.g. the wizard) */ 404. void 405. nasty(mcast) 406. struct monst *mcast; 407. { 408. register struct monst *mtmp; 409. register int i, j, tmp; 410. int castalign = (mcast ? mcast->data->maligntyp : -1); 411. 412. if(!rn2(10) && Inhell) msummon(&mons[PM_WIZARD_OF_YENDOR]); 413. else { 414. tmp = (u.ulevel > 3) ? u.ulevel/3 : 1; /* just in case -- rph */ 415. 416. for(i = rnd(tmp); i > 0; --i) 417. for(j=0; j<20; j++) { 418. if((mtmp = makemon(&mons[nasties[rn2(SIZE(nasties))]], 419. u.ux, u.uy))) { 420. mtmp->msleep = mtmp->mpeaceful = mtmp->mtame = 0; 421. set_malign(mtmp); 422. } else /* GENOD? */ 423. mtmp = makemon((struct permonst *)0, u.ux, u.uy); 424. if(mtmp->data->maligntyp == 0 || 425. sgn(mtmp->data->maligntyp) == sgn(castalign)) 426. break; 427. } 428. } 429. return; 430. } 431. 432. /* Let's resurrect the wizard, for some unexpected fun. */ 433. void 434. resurrect() 435. { 436. register struct monst *mtmp; 437. 438. if(mtmp = makemon(&mons[PM_WIZARD_OF_YENDOR], u.ux, u.uy)) { 439. mtmp->msleep = mtmp->mtame = mtmp->mpeaceful = 0; 440. set_malign(mtmp); 441. pline("A voice booms out..."); 442. verbalize("So thou thought thou couldst kill me, fool."); 443. } 444. 445. } 446. 447. /* Here, we make trouble for the poor shmuck who actually */ 448. /* managed to do in the Wizard. */ 449. void 450. intervene() { 451. 452. switch(rn2(6)) { 453. 454. case 0: 455. case 1: You("feel vaguely nervous."); 456. break; 457. case 2: if (!Blind) 458. You("notice a %s glow surrounding you.", 459. Hallucination ? hcolor() : Black); 460. rndcurse(); 461. break; 462. case 3: aggravate(); 463. break; 464. case 4: nasty((struct monst *)0); 465. break; 466. case 5: if (!flags.no_of_wizards) resurrect(); 467. break; 468. } 469. } 470. 471. void 472. wizdead(mtmp) 473. register struct monst *mtmp; 474. { 475. flags.no_of_wizards--; 476. if (!u.uevent.udemigod) { 477. u.uevent.udemigod = TRUE; 478. u.udg_cnt = rn1(250, 50); 479. 480. /* Make the wizard meaner the next time he appears */ 481. mtmp->data->mlevel++; 482. mtmp->data->ac--; 483. } else 484. mtmp->data->mlevel++; 485. } 486. 487. const char *random_insult[] = { 488. "antic", 489. "blackguard", 490. "caitiff", 491. "chucklehead", 492. "coistrel", 493. "craven", 494. "cretin", 495. "cur", 496. "dastard", 497. "demon fodder", 498. "dimwit", 499. "dolt", 500. "fool", 501. "footpad", 502. "imbecile", 503. "knave", 504. "maledict", 505. "miscreant", 506. "niddering", 507. "poltroon", 508. "rattlepate", 509. "reprobate", 510. "scapegrace", 511. "varlet", 512. "villein", /* (sic.) */ 513. "wittol", 514. "worm", 515. "wretch", 516. }; 517. 518. const char *random_malediction[] = { 519. "Hell shall soon claim thy remains,", 520. "I chortle at thee, thou pathetic", 521. "Prepare to die, thou", 522. "Resistance is useless,", 523. "Surrender or die, thou", 524. "There shall be no mercy, thou", 525. "Thou shalt repent of thy cunning,", 526. "Thou art as a flea to me,", 527. "Thou art doomed,", 528. "Thy fate is sealed,", 529. "Verily, thou shalt be one dead" 530. }; 531. 532. #ifdef SOUNDS 533. # ifndef MULDGN 534. /* Any %s will be filled in by the appropriate diety's name */ 535. const char *angelic_malediction[] = { 536. "Repent, and thou shalt be saved!", 537. "Thou shalt pay for thine insolence!", 538. "Very soon, my child, thou shalt meet thy maker.", 539. "%s has sent me to make you pay for your sins!", 540. "The wrath of %s is now upon you!", 541. "Thy life belongs to %s now!", 542. "Dost thou wish to receive thy final blessing?", 543. "Thou art but a godless void.", 544. "Thou art not worthy to seek the Amulet.", 545. "No one expects the Spanish Inquisition!", 546. }; 547. 548. const char *demonic_malediction[] = { 549. "I first mistook thee for a statue, when I regarded thy head of stone.", 550. "Come here often?", 551. "Dost pain excite thee? Wouldst thou prefer the whip?", 552. "Thinkest thou it shall tickle as I rip out thy lungs?", 553. "Eat slime and die!", 554. "Go ahead, fetch thy mama! I shall wait.", 555. "Go play leapfrog with a herd of unicorns!", 556. "Hast thou been drinking, or art thou always so clumsy?", 557. "This time I shall let thee off with a spanking, but let it not happen again.", 558. "I've met smarter (and prettier) acid blobs.", 559. "Look! Thy bootlace is undone!", 560. "Mercy! Dost thou wish me to die of laughter?", 561. "Run away! Live to flee another day!", 562. "Thou hadst best fight better than thou canst dress!", 563. "Twixt thy cousin and thee, Medusa is the prettier.", 564. "Methinks thou wert unnaturally interested in yon corpse back there, eh, varlet?", 565. "Up thy nose with a rubber hose!", 566. "Verily, thy corpse could not smell worse!", 567. "Wait! I shall polymorph into a grid bug to give thee a fighting chance!", 568. "Why search for the Amulet? Thou wouldst but lose it, cretin.", 569. }; 570. # endif /* MULDGN */ 571. #endif 572. 573. /* Insult or intimidate the player */ 574. void 575. cuss(mtmp) 576. register struct monst *mtmp; 577. { 578. #ifdef SOUNDS 579. if (mtmp->iswiz) { 580. #endif 581. if (!rn2(5)) /* typical bad guy action */ 582. pline("%s laughs fiendishly.", Monnam(mtmp)); 583. else 584. if (u.uhave.amulet && !rn2(SIZE(random_insult))) 585. verbalize("Relinquish the amulet, %s!", 586. random_insult[rn2(SIZE(random_insult))]); 587. else if (u.uhp < 5 && !rn2(2)) /* Panic */ 588. verbalize(rn2(2) ? 589. "Even now thy life force ebbs, %s!" : 590. "Savor thy breath, %s, it be thine last!", 591. random_insult[rn2(SIZE(random_insult))]); 592. else if (mtmp->mhp < 5 && !rn2(2)) /* Parthian shot */ 593. verbalize(rn2(2) ? 594. "I shall return." : 595. "I'll be back."); 596. else 597. verbalize("%s %s!", 598. random_malediction[rn2(SIZE(random_malediction))], 599. random_insult[rn2(SIZE(random_insult))]); 600. #ifdef SOUNDS 601. } else if(is_lminion(mtmp->data)) { 602. #ifndef MULDGN 603. verbalize(angelic_malediction[rn2(SIZE(angelic_malediction) - 1 604. + (Hallucination ? 1 : 0))], 605. align_gname(A_LAWFUL)); 606. #else 607. com_pager(rn2(QTN_ANGELIC - 1 + (Hallucination ? 1 : 0)) + 608. QT_ANGELIC); 609. #endif 610. } else { 611. if (!rn2(5)) 612. pline("%s casts aspersions on your ancestry.", Monnam(mtmp)); 613. else 614. #ifndef MULDGN 615. verbalize(demonic_malediction[rn2(SIZE(demonic_malediction))]); 616. #else 617. com_pager(rn2(QTN_DEMONIC) + QT_DEMONIC); 618. #endif 619. } 620. #endif 621. } 622. 623. #endif /* OVLB */ 624. 625. /*wizard.c*/
|