Source:NetHack 3.3.0/wizard.c
Jump to navigation
Jump to search
Below is the full text to wizard.c from the source code of NetHack 3.3.0. To link to a particular line, write [[NetHack 3.3.0/wizard.c#line123]], for example.
Warning! This is the source code from an old release. For the latest release, see Source code
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. /* SCCS Id: @(#)wizard.c 3.3 99/03/29 */ 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. #include "qtext.h" 12. 13. #ifdef OVLB 14. 15. STATIC_DCL short FDECL(which_arti, (int)); 16. STATIC_DCL boolean FDECL(mon_has_arti, (struct monst *,SHORT_P)); 17. STATIC_DCL struct monst *FDECL(other_mon_has_arti, (struct monst *,SHORT_P)); 18. STATIC_DCL struct obj *FDECL(on_ground, (SHORT_P)); 19. STATIC_DCL boolean FDECL(you_have, (int)); 20. STATIC_DCL long FDECL(target_on, (int,struct monst *)); 21. STATIC_DCL long FDECL(strategy, (struct monst *)); 22. 23. static NEARDATA const int nasties[] = { 24. PM_COCKATRICE, PM_ETTIN, PM_STALKER, PM_MINOTAUR, PM_RED_DRAGON, 25. PM_BLACK_DRAGON, PM_GREEN_DRAGON, PM_OWLBEAR, PM_PURPLE_WORM, 26. PM_ROCK_TROLL, PM_XAN, PM_GREMLIN, PM_UMBER_HULK, PM_VAMPIRE_LORD, 27. PM_XORN, PM_ZRUTY, PM_ELF_LORD, PM_ELVENKING, PM_YELLOW_DRAGON, 28. PM_LEOCROTTA, PM_BALUCHITHERIUM, PM_CARNIVOROUS_APE, PM_FIRE_GIANT, 29. PM_COUATL, PM_CAPTAIN, PM_WINGED_GARGOYLE, PM_MASTER_MIND_FLAYER, 30. PM_FIRE_ELEMENTAL, PM_JABBERWOCK, PM_ARCH_LICH, PM_OGRE_KING, 31. PM_OLOG_HAI, PM_IRON_GOLEM, PM_OCHRE_JELLY, PM_GREEN_SLIME, 32. PM_DISENCHANTER 33. }; 34. 35. static NEARDATA const unsigned wizapp[] = { 36. PM_HUMAN, PM_WATER_DEMON, PM_VAMPIRE, 37. PM_RED_DRAGON, PM_TROLL, PM_UMBER_HULK, 38. PM_XORN, PM_XAN, PM_COCKATRICE, 39. PM_FLOATING_EYE, 40. PM_GUARDIAN_NAGA, 41. PM_TRAPPER 42. }; 43. 44. #endif /* OVLB */ 45. #ifdef OVL0 46. 47. /* If you've found the Amulet, make the Wizard appear after some time */ 48. /* Also, give hints about portal locations, if amulet is worn/wielded -dlc */ 49. void 50. amulet() 51. { 52. struct monst *mtmp; 53. struct trap *ttmp; 54. struct obj *amu; 55. 56. #if 0 /* caller takes care of this check */ 57. if (!u.uhave.amulet) 58. return; 59. #endif 60. if ((((amu = uamul) != 0 && amu->otyp == AMULET_OF_YENDOR) || 61. ((amu = uwep) != 0 && amu->otyp == AMULET_OF_YENDOR)) 62. && !rn2(15)) { 63. for(ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) { 64. if(ttmp->ttyp == MAGIC_PORTAL) { 65. int du = distu(ttmp->tx, ttmp->ty); 66. if (du <= 9) 67. pline("%s feels hot!", The(xname(amu))); 68. else if (du <= 64) 69. pline("%s feels very warm.", The(xname(amu))); 70. else if (du <= 144) 71. pline("%s feels warm.", The(xname(amu))); 72. /* else, the amulet feels normal */ 73. break; 74. } 75. } 76. } 77. 78. if (!flags.no_of_wizards) 79. return; 80. /* find Wizard, and wake him if necessary */ 81. for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) 82. if (mtmp->iswiz && mtmp->msleeping && !rn2(40)) { 83. mtmp->msleeping = 0; 84. if (distu(mtmp->mx,mtmp->my) > 2) 85. You( 86. "get the creepy feeling that somebody noticed your taking the Amulet." 87. ); 88. return; 89. } 90. } 91. 92. #endif /* OVL0 */ 93. #ifdef OVLB 94. 95. int 96. mon_has_amulet(mtmp) 97. register struct monst *mtmp; 98. { 99. register struct obj *otmp; 100. 101. for(otmp = mtmp->minvent; otmp; otmp = otmp->nobj) 102. if(otmp->otyp == AMULET_OF_YENDOR) return(1); 103. return(0); 104. } 105. 106. int 107. mon_has_special(mtmp) 108. register struct monst *mtmp; 109. { 110. register struct obj *otmp; 111. 112. for(otmp = mtmp->minvent; otmp; otmp = otmp->nobj) 113. if(otmp->otyp == AMULET_OF_YENDOR || 114. is_quest_artifact(otmp) || 115. otmp->otyp == BELL_OF_OPENING || 116. otmp->otyp == CANDELABRUM_OF_INVOCATION || 117. otmp->otyp == SPE_BOOK_OF_THE_DEAD) return(1); 118. return(0); 119. } 120. 121. /* 122. * New for 3.1 Strategy / Tactics for the wiz, as well as other 123. * monsters that are "after" something (defined via mflag3). 124. * 125. * The strategy section decides *what* the monster is going 126. * to attempt, the tactics section implements the decision. 127. */ 128. #define STRAT(w, x, y, typ) (w | ((long)(x)<<16) | ((long)(y)<<8) | (long)typ) 129. 130. #define M_Wants(mask) (mtmp->data->mflags3 & (mask)) 131. 132. STATIC_OVL short 133. which_arti(mask) 134. register int mask; 135. { 136. switch(mask) { 137. case M3_WANTSAMUL: return(AMULET_OF_YENDOR); 138. case M3_WANTSBELL: return(BELL_OF_OPENING); 139. case M3_WANTSCAND: return(CANDELABRUM_OF_INVOCATION); 140. case M3_WANTSBOOK: return(SPE_BOOK_OF_THE_DEAD); 141. default: break; /* 0 signifies quest artifact */ 142. } 143. return(0); 144. } 145. 146. /* 147. * If "otyp" is zero, it triggers a check for the quest_artifact, 148. * since bell, book, candle, and amulet are all objects, not really 149. * artifacts right now. [MRS] 150. */ 151. STATIC_OVL boolean 152. mon_has_arti(mtmp, otyp) 153. register struct monst *mtmp; 154. register short otyp; 155. { 156. register struct obj *otmp; 157. 158. for(otmp = mtmp->minvent; otmp; otmp = otmp->nobj) { 159. if(otyp) { 160. if(otmp->otyp == otyp) 161. return(1); 162. } 163. else if(is_quest_artifact(otmp)) return(1); 164. } 165. return(0); 166. 167. } 168. 169. STATIC_OVL struct monst * 170. other_mon_has_arti(mtmp, otyp) 171. register struct monst *mtmp; 172. register short otyp; 173. { 174. register struct monst *mtmp2; 175. 176. for(mtmp2 = fmon; mtmp2; mtmp2 = mtmp2->nmon) 177. if(mtmp2 != mtmp) 178. if(mon_has_arti(mtmp2, otyp)) return(mtmp2); 179. 180. return((struct monst *)0); 181. } 182. 183. STATIC_OVL struct obj * 184. on_ground(otyp) 185. register short otyp; 186. { 187. register struct obj *otmp; 188. 189. for (otmp = fobj; otmp; otmp = otmp->nobj) 190. if (otyp) { 191. if (otmp->otyp == otyp) 192. return(otmp); 193. } else if (is_quest_artifact(otmp)) 194. return(otmp); 195. return((struct obj *)0); 196. } 197. 198. STATIC_OVL boolean 199. you_have(mask) 200. register int mask; 201. { 202. switch(mask) { 203. case M3_WANTSAMUL: return(boolean)(u.uhave.amulet); 204. case M3_WANTSBELL: return(boolean)(u.uhave.bell); 205. case M3_WANTSCAND: return(boolean)(u.uhave.menorah); 206. case M3_WANTSBOOK: return(boolean)(u.uhave.book); 207. case M3_WANTSARTI: return(boolean)(u.uhave.questart); 208. default: break; 209. } 210. return(0); 211. } 212. 213. STATIC_OVL long 214. target_on(mask, mtmp) 215. register int mask; 216. register struct monst *mtmp; 217. { 218. register short otyp; 219. register struct obj *otmp; 220. register struct monst *mtmp2; 221. 222. if(!M_Wants(mask)) return(STRAT_NONE); 223. 224. otyp = which_arti(mask); 225. if(!mon_has_arti(mtmp, otyp)) { 226. if(you_have(mask)) 227. return(STRAT(STRAT_PLAYER, u.ux, u.uy, mask)); 228. else if((otmp = on_ground(otyp))) 229. return(STRAT(STRAT_GROUND, otmp->ox, otmp->oy, mask)); 230. else if((mtmp2 = other_mon_has_arti(mtmp, otyp))) 231. return(STRAT(STRAT_MONSTR, mtmp2->mx, mtmp2->my, mask)); 232. } 233. return(STRAT_NONE); 234. } 235. 236. STATIC_OVL long 237. strategy(mtmp) 238. register struct monst *mtmp; 239. { 240. long strat, dstrat; 241. 242. if(!is_covetous(mtmp->data)) return(STRAT_NONE); 243. 244. switch((mtmp->mhp*3)/mtmp->mhpmax) { /* 0-3 */ 245. 246. default: 247. case 0: /* panic time - mtmp is almost snuffed */ 248. return(STRAT_HEAL); 249. 250. case 1: /* the wiz is less cautious */ 251. if(mtmp->data != &mons[PM_WIZARD_OF_YENDOR]) 252. return(STRAT_HEAL); 253. /* else fall through */ 254. 255. case 2: dstrat = STRAT_HEAL; 256. break; 257. 258. case 3: dstrat = STRAT_NONE; 259. break; 260. } 261. 262. if(flags.made_amulet) 263. if((strat = target_on(M3_WANTSAMUL, mtmp)) != STRAT_NONE) 264. return(strat); 265. 266. if(u.uevent.invoked) { /* priorities change once gate opened */ 267. 268. if((strat = target_on(M3_WANTSARTI, mtmp)) != STRAT_NONE) 269. return(strat); 270. if((strat = target_on(M3_WANTSBOOK, mtmp)) != STRAT_NONE) 271. return(strat); 272. if((strat = target_on(M3_WANTSBELL, mtmp)) != STRAT_NONE) 273. return(strat); 274. if((strat = target_on(M3_WANTSCAND, mtmp)) != STRAT_NONE) 275. return(strat); 276. } else { 277. 278. if((strat = target_on(M3_WANTSBOOK, mtmp)) != STRAT_NONE) 279. return(strat); 280. if((strat = target_on(M3_WANTSBELL, mtmp)) != STRAT_NONE) 281. return(strat); 282. if((strat = target_on(M3_WANTSCAND, mtmp)) != STRAT_NONE) 283. return(strat); 284. if((strat = target_on(M3_WANTSARTI, mtmp)) != STRAT_NONE) 285. return(strat); 286. } 287. return(dstrat); 288. } 289. 290. int 291. tactics(mtmp) 292. register struct monst *mtmp; 293. { 294. long strat = strategy(mtmp); 295. 296. mtmp->mstrategy = (mtmp->mstrategy & STRAT_WAITMASK) | strat; 297. 298. switch (strat) { 299. case STRAT_HEAL: /* hide and recover */ 300. /* if wounded, hole up on or near the stairs (to block them) */ 301. /* unless, of course, there are no stairs (e.g. endlevel) */ 302. if (In_W_tower(mtmp->mx, mtmp->my, &u.uz) || 303. (mtmp->iswiz && !xupstair && !mon_has_amulet(mtmp))) { 304. if (!rn2(3 + mtmp->mhp/10)) rloc(mtmp); 305. } else if (xupstair && 306. (mtmp->mx != xupstair || mtmp->my != yupstair)) { 307. (void) mnearto(mtmp, xupstair, yupstair, TRUE); 308. } 309. /* if you're not around, cast healing spells */ 310. if (distu(mtmp->mx,mtmp->my) > (BOLT_LIM * BOLT_LIM)) 311. if(mtmp->mhp <= mtmp->mhpmax - 8) { 312. mtmp->mhp += rnd(8); 313. return(1); 314. } 315. /* fall through :-) */ 316. 317. case STRAT_NONE: /* harrass */ 318. if(!rn2(5)) mnexto(mtmp); 319. return(0); 320. 321. default: /* kill, maim, pillage! */ 322. { 323. long where = (strat & STRAT_STRATMASK); 324. xchar tx = STRAT_GOALX(strat), 325. ty = STRAT_GOALY(strat); 326. int targ = strat & STRAT_GOAL; 327. struct obj *otmp; 328. 329. if(!targ) { /* simply wants you to close */ 330. return(0); 331. } 332. if((u.ux == tx && u.uy == ty) || where == STRAT_PLAYER) { 333. /* player is standing on it (or has it) */ 334. mnexto(mtmp); 335. return(0); 336. } 337. if(where == STRAT_GROUND) { 338. if(!MON_AT(tx, ty) || (mtmp->mx == tx && mtmp->my == ty)) { 339. /* teleport to it and pick it up */ 340. rloc_to(mtmp, tx, ty); /* clean old pos */ 341. 342. if ((otmp = on_ground(which_arti(targ))) != 0) { 343. if (cansee(mtmp->mx, mtmp->my)) 344. pline("%s picks up %s.", 345. Monnam(mtmp), 346. (distu(mtmp->my, mtmp->my) <= 5) ? 347. doname(otmp) : distant_name(otmp, doname)); 348. obj_extract_self(otmp); 349. mpickobj(mtmp, otmp); 350. return(1); 351. } else return(0); 352. } 353. } else { /* a monster has it - 'port beside it. */ 354. (void) mnearto(mtmp, tx, ty, TRUE); 355. return(0); 356. } 357. } 358. } 359. /* NOTREACHED */ 360. return(0); 361. } 362. 363. void 364. aggravate() 365. { 366. register struct monst *mtmp; 367. 368. for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 369. mtmp->msleeping = 0; 370. if(!mtmp->mcanmove && !rn2(5)) { 371. mtmp->mfrozen = 0; 372. mtmp->mcanmove = 1; 373. } 374. } 375. } 376. 377. void 378. clonewiz() 379. { 380. register struct monst *mtmp2; 381. 382. if ((mtmp2 = makemon(&mons[PM_WIZARD_OF_YENDOR], 383. u.ux, u.uy, NO_MM_FLAGS)) != 0) { 384. mtmp2->msleeping = mtmp2->mtame = mtmp2->mpeaceful = 0; 385. if (!u.uhave.amulet && rn2(2)) { /* give clone a fake */ 386. add_to_minv(mtmp2, mksobj(FAKE_AMULET_OF_YENDOR, TRUE, FALSE)); 387. } 388. mtmp2->m_ap_type = M_AP_MONSTER; 389. mtmp2->mappearance = wizapp[rn2(SIZE(wizapp))]; 390. newsym(mtmp2->mx,mtmp2->my); 391. } 392. } 393. 394. /* also used by newcham() */ 395. int 396. pick_nasty() 397. { 398. /* To do? Possibly should filter for appropriate forms when 399. in the elemental planes or surrounded by water or lava. */ 400. return nasties[rn2(SIZE(nasties))]; 401. } 402. 403. /* create some nasty monsters, aligned or neutral with the caster */ 404. /* a null caster defaults to a chaotic caster (e.g. the wizard) */ 405. void 406. nasty(mcast) 407. struct monst *mcast; 408. { 409. register struct monst *mtmp; 410. register int i, j, tmp; 411. int castalign = (mcast ? mcast->data->maligntyp : -1); 412. 413. if(!rn2(10) && Inhell) msummon(&mons[PM_WIZARD_OF_YENDOR]); 414. else { 415. tmp = (u.ulevel > 3) ? u.ulevel/3 : 1; /* just in case -- rph */ 416. 417. for(i = rnd(tmp); i > 0; --i) 418. for(j=0; j<20; j++) { 419. if ((mtmp = makemon(&mons[pick_nasty()], 420. u.ux, u.uy, NO_MM_FLAGS)) != 0) { 421. mtmp->msleeping = mtmp->mpeaceful = mtmp->mtame = 0; 422. set_malign(mtmp); 423. } else /* GENOD? */ 424. mtmp = makemon((struct permonst *)0, 425. u.ux, u.uy, NO_MM_FLAGS); 426. if(mtmp && (mtmp->data->maligntyp == 0 || 427. sgn(mtmp->data->maligntyp) == sgn(castalign)) ) 428. break; 429. } 430. } 431. return; 432. } 433. 434. /* Let's resurrect the wizard, for some unexpected fun. */ 435. void 436. resurrect() 437. { 438. struct monst *mtmp, **mmtmp; 439. long elapsed; 440. const char *verb; 441. 442. if (!flags.no_of_wizards) { 443. /* make a new Wizard */ 444. verb = "kill"; 445. mtmp = makemon(&mons[PM_WIZARD_OF_YENDOR], u.ux, u.uy, MM_NOWAIT); 446. } else { 447. /* look for a migrating Wizard */ 448. verb = "elude"; 449. mmtmp = &migrating_mons; 450. while ((mtmp = *mmtmp) != 0) { 451. if (mtmp->iswiz && 452. /* if he has the Amulet, he won't bring it to you */ 453. !mon_has_amulet(mtmp) && 454. (elapsed = monstermoves - mtmp->mlstmv) > 0L) { 455. mon_catchup_elapsed_time(mtmp, elapsed); 456. if (elapsed >= LARGEST_INT) elapsed = LARGEST_INT - 1; 457. elapsed /= 50L; 458. if (mtmp->msleeping && rn2((int)elapsed + 1)) 459. mtmp->msleeping = 0; 460. if (mtmp->mfrozen == 1) /* would unfreeze on next move */ 461. mtmp->mfrozen = 0, mtmp->mcanmove = 1; 462. if (mtmp->mcanmove && !mtmp->msleeping) { 463. *mmtmp = mtmp->nmon; 464. mon_arrive(mtmp, TRUE); 465. /* note: there might be a second Wizard; if so, 466. he'll have to wait til the next resurrection */ 467. break; 468. } 469. } 470. mmtmp = &mtmp->nmon; 471. } 472. } 473. 474. if (mtmp) { 475. mtmp->msleeping = mtmp->mtame = mtmp->mpeaceful = 0; 476. set_malign(mtmp); 477. pline("A voice booms out..."); 478. verbalize("So thou thought thou couldst %s me, fool.", verb); 479. } 480. 481. } 482. 483. /* Here, we make trouble for the poor shmuck who actually */ 484. /* managed to do in the Wizard. */ 485. void 486. intervene() 487. { 488. int which = Is_astralevel(&u.uz) ? rnd(4) : rn2(6); 489. /* cases 0 and 5 don't apply on the Astral level */ 490. switch (which) { 491. case 0: 492. case 1: You_feel("vaguely nervous."); 493. break; 494. case 2: if (!Blind) 495. You("notice a %s glow surrounding you.", 496. hcolor(Black)); 497. rndcurse(); 498. break; 499. case 3: aggravate(); 500. break; 501. case 4: nasty((struct monst *)0); 502. break; 503. case 5: resurrect(); 504. break; 505. } 506. } 507. 508. void 509. wizdead() 510. { 511. flags.no_of_wizards--; 512. if (!u.uevent.udemigod) { 513. u.uevent.udemigod = TRUE; 514. u.udg_cnt = rn1(250, 50); 515. } 516. } 517. 518. const char *random_insult[] = { 519. "antic", 520. "blackguard", 521. "caitiff", 522. "chucklehead", 523. "coistrel", 524. "craven", 525. "cretin", 526. "cur", 527. "dastard", 528. "demon fodder", 529. "dimwit", 530. "dolt", 531. "fool", 532. "footpad", 533. "imbecile", 534. "knave", 535. "maledict", 536. "miscreant", 537. "niddering", 538. "poltroon", 539. "rattlepate", 540. "reprobate", 541. "scapegrace", 542. "varlet", 543. "villein", /* (sic.) */ 544. "wittol", 545. "worm", 546. "wretch", 547. }; 548. 549. const char *random_malediction[] = { 550. "Hell shall soon claim thy remains,", 551. "I chortle at thee, thou pathetic", 552. "Prepare to die, thou", 553. "Resistance is useless,", 554. "Surrender or die, thou", 555. "There shall be no mercy, thou", 556. "Thou shalt repent of thy cunning,", 557. "Thou art as a flea to me,", 558. "Thou art doomed,", 559. "Thy fate is sealed,", 560. "Verily, thou shalt be one dead" 561. }; 562. 563. /* Insult or intimidate the player */ 564. void 565. cuss(mtmp) 566. register struct monst *mtmp; 567. { 568. if (mtmp->iswiz) { 569. if (!rn2(5)) /* typical bad guy action */ 570. pline("%s laughs fiendishly.", Monnam(mtmp)); 571. else 572. if (u.uhave.amulet && !rn2(SIZE(random_insult))) 573. verbalize("Relinquish the amulet, %s!", 574. random_insult[rn2(SIZE(random_insult))]); 575. else if (u.uhp < 5 && !rn2(2)) /* Panic */ 576. verbalize(rn2(2) ? 577. "Even now thy life force ebbs, %s!" : 578. "Savor thy breath, %s, it be thine last!", 579. random_insult[rn2(SIZE(random_insult))]); 580. else if (mtmp->mhp < 5 && !rn2(2)) /* Parthian shot */ 581. verbalize(rn2(2) ? 582. "I shall return." : 583. "I'll be back."); 584. else 585. verbalize("%s %s!", 586. random_malediction[rn2(SIZE(random_malediction))], 587. random_insult[rn2(SIZE(random_insult))]); 588. } else if(is_lminion(mtmp->data)) { 589. com_pager(rn2(QTN_ANGELIC - 1 + (Hallucination ? 1 : 0)) + 590. QT_ANGELIC); 591. } else { 592. if (!rn2(5)) 593. pline("%s casts aspersions on your ancestry.", Monnam(mtmp)); 594. else 595. com_pager(rn2(QTN_DEMONIC) + QT_DEMONIC); 596. } 597. } 598. 599. #endif /* OVLB */ 600. 601. /*wizard.c*/