Source:NetHack 5.0.0/src/wizard.c
Jump to navigation
Jump to search
Below is the full text to wizard.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/wizard.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 5.0 wizard.c $NHDT-Date: 1741407262 2025/03/07 20:14:22 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.116 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Robert Patrick Rankin, 2016. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. /* wizard code - inspired by rogue code from Merlyn Leroy (digi-g!brian) */ 7. /* - heavily modified to give the wiz balls. (genat!mike) */ 8. /* - dewimped and given some maledictions. -3. */ 9. /* - generalized for 3.1 (mike@bullns.on01.bull.ca) */ 10. 11. #include "hack.h" 12. 13. staticfn short which_arti(int); 14. staticfn boolean mon_has_arti(struct monst *, short) NONNULLARG1; 15. /* other_mon_has_arti() won't blow up if passed a NULL monst, 16. * but its caller target_on() passes it a nonnull monst; 17. * it may return a NULL monst pointer */ 18. staticfn struct monst *other_mon_has_arti(struct monst *, short) NONNULLARG1; 19. staticfn struct obj *on_ground(short); /* might return NULL obj pointer */ 20. staticfn boolean you_have(int); 21. staticfn unsigned long target_on(int, struct monst *) NONNULLARG2; 22. staticfn unsigned long strategy(struct monst *) NONNULLARG1; 23. 24. /* adding more neutral creatures will tend to reduce the number of monsters 25. summoned by nasty(); adding more lawful creatures will reduce the number 26. of monsters summoned by lawfuls; adding more chaotic creatures will reduce 27. the number of monsters summoned by chaotics; prior to 3.6.1, there were 28. only four lawful candidates, so lawful summoners tended to summon more 29. (trying to get lawful or neutral but obtaining chaotic instead) than 30. their chaotic counterparts */ 31. static NEARDATA const int nasties[] = { 32. /* neutral */ 33. PM_COCKATRICE, PM_ETTIN, PM_STALKER, PM_MINOTAUR, 34. PM_OWLBEAR, PM_PURPLE_WORM, PM_XAN, PM_UMBER_HULK, 35. PM_XORN, PM_ZRUTY, PM_LEOCROTTA, PM_BALUCHITHERIUM, 36. PM_CARNIVOROUS_APE, PM_FIRE_ELEMENTAL, PM_JABBERWOCK, 37. PM_IRON_GOLEM, PM_OCHRE_JELLY, PM_GREEN_SLIME, 38. PM_DISPLACER_BEAST, PM_GENETIC_ENGINEER, 39. /* chaotic */ 40. PM_BLACK_DRAGON, PM_RED_DRAGON, PM_ARCH_LICH, PM_VAMPIRE_LEADER, 41. PM_MASTER_MIND_FLAYER, PM_DISENCHANTER, PM_WINGED_GARGOYLE, 42. PM_STORM_GIANT, PM_OLOG_HAI, PM_ELF_NOBLE, PM_ELVEN_MONARCH, 43. PM_OGRE_TYRANT, PM_CAPTAIN, PM_GREMLIN, 44. /* lawful */ 45. PM_SILVER_DRAGON, PM_ORANGE_DRAGON, PM_GREEN_DRAGON, 46. PM_YELLOW_DRAGON, PM_GUARDIAN_NAGA, PM_FIRE_GIANT, 47. PM_ALEAX, PM_COUATL, PM_HORNED_DEVIL, PM_BARBED_DEVIL, 48. /* (Archons, titans, ki-rin, and golden nagas are suitably nasty, but 49. they're summoners so would aggravate excessive summoning) */ 50. }; 51. 52. static NEARDATA const unsigned wizapp[] = { 53. PM_HUMAN, PM_WATER_DEMON, PM_VAMPIRE, PM_RED_DRAGON, 54. PM_TROLL, PM_UMBER_HULK, PM_XORN, PM_XAN, 55. PM_COCKATRICE, PM_FLOATING_EYE, PM_GUARDIAN_NAGA, PM_TRAPPER, 56. }; 57. 58. /* If you've found the Amulet, make the Wizard appear after some time */ 59. /* Also, give hints about portal locations, if amulet is worn/wielded -dlc */ 60. void 61. amulet(void) 62. { 63. struct monst *mtmp; 64. struct trap *ttmp; 65. struct obj *amu; 66. 67. #if 0 /* caller takes care of this check */ 68. if (!u.uhave.amulet) 69. return; 70. #endif 71. if ((((amu = uamul) != 0 && amu->otyp == AMULET_OF_YENDOR) 72. || ((amu = uwep) != 0 && amu->otyp == AMULET_OF_YENDOR)) 73. && !rn2(15)) { 74. for (ttmp = gf.ftrap; ttmp; ttmp = ttmp->ntrap) { 75. if (ttmp->ttyp == MAGIC_PORTAL) { 76. int du = distu(ttmp->tx, ttmp->ty); 77. if (du <= 9) 78. pline("%s hot!", Tobjnam(amu, "feel")); 79. else if (du <= 64) 80. pline("%s very warm.", Tobjnam(amu, "feel")); 81. else if (du <= 144) 82. pline("%s warm.", Tobjnam(amu, "feel")); 83. /* else, the amulet feels normal */ 84. break; 85. } 86. } 87. } 88. 89. if (!svc.context.no_of_wizards) 90. return; 91. /* find Wizard, and wake him if necessary */ 92. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 93. if (DEADMONSTER(mtmp)) 94. continue; 95. if (mtmp->iswiz && mtmp->msleeping && !rn2(40)) { 96. mtmp->msleeping = 0; 97. if (!m_next2u(mtmp)) 98. You( 99. "get the creepy feeling that somebody noticed your taking the Amulet."); 100. return; 101. } 102. } 103. } 104. 105. int 106. mon_has_amulet(struct monst *mtmp) 107. { 108. struct obj *otmp; 109. 110. for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) 111. if (otmp->otyp == AMULET_OF_YENDOR) 112. return 1; 113. return 0; 114. } 115. 116. int 117. mon_has_special(struct monst *mtmp) 118. { 119. struct obj *otmp; 120. 121. for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) 122. if (otmp->otyp == AMULET_OF_YENDOR 123. || any_quest_artifact(otmp) 124. || otmp->otyp == BELL_OF_OPENING 125. || otmp->otyp == CANDELABRUM_OF_INVOCATION 126. || otmp->otyp == SPE_BOOK_OF_THE_DEAD) 127. return 1; 128. return 0; 129. } 130. 131. /* 132. * New for 3.1 Strategy / Tactics for the wiz, as well as other 133. * monsters that are "after" something (defined via mflag3). 134. * 135. * The strategy section decides *what* the monster is going 136. * to attempt, the tactics section implements the decision. 137. */ 138. 139. #define M_Wants(mask) (mtmp->data->mflags3 & (mask)) 140. 141. staticfn short 142. which_arti(int mask) 143. { 144. switch (mask) { 145. case M3_WANTSAMUL: 146. return AMULET_OF_YENDOR; 147. case M3_WANTSBELL: 148. return BELL_OF_OPENING; 149. case M3_WANTSCAND: 150. return CANDELABRUM_OF_INVOCATION; 151. case M3_WANTSBOOK: 152. return SPE_BOOK_OF_THE_DEAD; 153. default: 154. break; /* 0 signifies quest artifact */ 155. } 156. return 0; 157. } 158. 159. /* 160. * If "otyp" is zero, it triggers a check for the quest_artifact, 161. * since bell, book, candle, and amulet are all objects, not really 162. * artifacts right now. [MRS] 163. */ 164. staticfn boolean 165. mon_has_arti(struct monst *mtmp, short otyp) 166. { 167. struct obj *otmp; 168. 169. for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) { 170. if (otyp) { 171. if (otmp->otyp == otyp) 172. return 1; 173. } else if (any_quest_artifact(otmp)) 174. return 1; 175. } 176. return 0; 177. } 178. 179. /* 180. * Returns some monster other than mtmp that 181. * has artifact, or NULL monst pointer. 182. */ 183. staticfn struct monst * 184. other_mon_has_arti(struct monst *mtmp, short otyp) 185. { 186. struct monst *mtmp2; 187. 188. for (mtmp2 = fmon; mtmp2; mtmp2 = mtmp2->nmon) 189. /* no need for !DEADMONSTER check here since they have no inventory */ 190. if (mtmp2 != mtmp) 191. if (mon_has_arti(mtmp2, otyp)) 192. return mtmp2; 193. 194. return (struct monst *) 0; 195. } 196. 197. /* 198. * Returns obj of type specified if there is one 199. * on the ground, otherwise returns NULL obj pointer. 200. */ 201. staticfn struct obj * 202. on_ground(short otyp) 203. { 204. struct obj *otmp; 205. 206. for (otmp = fobj; otmp; otmp = otmp->nobj) 207. if (otyp) { 208. if (otmp->otyp == otyp) 209. return otmp; 210. } else if (any_quest_artifact(otmp)) 211. return otmp; 212. return (struct obj *) 0; 213. } 214. 215. staticfn boolean 216. you_have(int mask) 217. { 218. switch (mask) { 219. case M3_WANTSAMUL: 220. return (boolean) u.uhave.amulet; 221. case M3_WANTSBELL: 222. return (boolean) u.uhave.bell; 223. case M3_WANTSCAND: 224. return (boolean) u.uhave.menorah; 225. case M3_WANTSBOOK: 226. return (boolean) u.uhave.book; 227. case M3_WANTSARTI: 228. return (boolean) u.uhave.questart; 229. default: 230. break; 231. } 232. return 0; 233. } 234. 235. staticfn unsigned long 236. target_on(int mask, struct monst *mtmp) 237. { 238. short otyp; 239. struct obj *otmp; 240. struct monst *mtmp2; 241. 242. if (!M_Wants(mask)) 243. return (unsigned long) STRAT_NONE; 244. 245. otyp = which_arti(mask); 246. if (!mon_has_arti(mtmp, otyp)) { 247. if (you_have(mask)) { 248. mtmp->mgoal.x = u.ux; 249. mtmp->mgoal.y = u.uy; 250. return (STRAT_PLAYER | mask); 251. } else if ((otmp = on_ground(otyp))) { 252. mtmp->mgoal.x = otmp->ox; 253. mtmp->mgoal.y = otmp->oy; 254. return (STRAT_GROUND | mask); 255. } else if ((mtmp2 = other_mon_has_arti(mtmp, otyp)) != 0 256. /* when seeking the Amulet, avoid targeting the Wizard 257. or temple priests (to protect Moloch's high priest) */ 258. && (otyp != AMULET_OF_YENDOR 259. || (!mtmp2->iswiz && !inhistemple(mtmp2)))) { 260. mtmp->mgoal.x = mtmp2->mx; 261. mtmp->mgoal.y = mtmp2->my; 262. return (STRAT_MONSTR | mask); 263. } 264. } 265. mtmp->mgoal.x = mtmp->mgoal.y = 0; 266. return (unsigned long) STRAT_NONE; 267. } 268. 269. staticfn unsigned long 270. strategy(struct monst *mtmp) 271. { 272. unsigned long strat, dstrat; 273. 274. if (!is_covetous(mtmp->data) 275. /* perhaps a shopkeeper has been polymorphed into a master 276. lich; we don't want it teleporting to the stairs to heal 277. because that will leave its shop untended */ 278. || (mtmp->isshk && inhishop(mtmp)) 279. /* likewise for temple priests */ 280. || (mtmp->ispriest && inhistemple(mtmp))) 281. return (unsigned long) STRAT_NONE; 282. 283. switch ((mtmp->mhp * 3) / mtmp->mhpmax) { /* 0-3 */ 284. 285. default: 286. case 0: /* panic time - mtmp is almost snuffed */ 287. return (unsigned long) STRAT_HEAL; 288. 289. case 1: /* the wiz is less cautious */ 290. if (mtmp->data != &mons[PM_WIZARD_OF_YENDOR]) 291. return (unsigned long) STRAT_HEAL; 292. FALLTHROUGH; 293. /* FALLTHRU */ 294. case 2: 295. dstrat = STRAT_HEAL; 296. break; 297. 298. case 3: 299. dstrat = STRAT_NONE; 300. break; 301. } 302. 303. if (svc.context.made_amulet) 304. if ((strat = target_on(M3_WANTSAMUL, mtmp)) != STRAT_NONE) 305. return strat; 306. 307. if (u.uevent.invoked) { /* priorities change once gate opened */ 308. if ((strat = target_on(M3_WANTSARTI, mtmp)) != STRAT_NONE) 309. return strat; 310. if ((strat = target_on(M3_WANTSBOOK, mtmp)) != STRAT_NONE) 311. return strat; 312. if ((strat = target_on(M3_WANTSBELL, mtmp)) != STRAT_NONE) 313. return strat; 314. if ((strat = target_on(M3_WANTSCAND, mtmp)) != STRAT_NONE) 315. return strat; 316. } else { 317. if ((strat = target_on(M3_WANTSBOOK, mtmp)) != STRAT_NONE) 318. return strat; 319. if ((strat = target_on(M3_WANTSBELL, mtmp)) != STRAT_NONE) 320. return strat; 321. if ((strat = target_on(M3_WANTSCAND, mtmp)) != STRAT_NONE) 322. return strat; 323. if ((strat = target_on(M3_WANTSARTI, mtmp)) != STRAT_NONE) 324. return strat; 325. } 326. return dstrat; 327. } 328. 329. /* pick a destination for a covetous monster to flee to so that it can 330. heal or for guardians (Kops) to congregate at to block hero's progress */ 331. void 332. choose_stairs( 333. coordxy *sx, coordxy *sy, /* output; left as-is if no spot found */ 334. boolean dir) /* True: forward, False: backtrack (usually up) */ 335. { 336. stairway *stway; 337. boolean stdir = builds_up(&u.uz) ? dir : !dir; 338. 339. /* look for stairs in direction 'stdir' (True: up, False: down) */ 340. stway = stairway_find_type_dir(FALSE, stdir); 341. if (!stway) { 342. /* no stairs; look for ladder it that direction */ 343. stway = stairway_find_type_dir(TRUE, stdir); 344. if (!stway) { 345. /* no ladder either; look for branch stairs or ladder in any 346. direction */ 347. for (stway = gs.stairs; stway; stway = stway->next) 348. if (stway->tolev.dnum != u.uz.dnum) 349. break; 350. /* if no branch stairs/ladder, check for regular stairs in 351. opposite direction, then for regular ladder if necessary */ 352. if (!stway) { 353. stway = stairway_find_type_dir(FALSE, !stdir); 354. if (!stway) 355. stway = stairway_find_type_dir(TRUE, !stdir); 356. } 357. } 358. /* [note: 'stway' could still be Null if the only access to this 359. level is via magic portal] */ 360. } 361. 362. if (stway) 363. *sx = stway->sx, *sy = stway->sy; 364. } 365. 366. DISABLE_WARNING_UNREACHABLE_CODE 367. 368. int 369. tactics(struct monst *mtmp) 370. { 371. unsigned long strat = strategy(mtmp); 372. coordxy sx = 0, sy = 0, mx, my; 373. 374. mtmp->mstrategy = 375. (mtmp->mstrategy & (STRAT_WAITMASK | STRAT_APPEARMSG)) | strat; 376. 377. switch (strat) { 378. case STRAT_HEAL: /* hide and recover */ 379. mx = mtmp->mx, my = mtmp->my; 380. 381. if (u.uswallow && u.ustuck == mtmp) 382. expels(mtmp, mtmp->data, TRUE); 383. 384. /* if wounded, hole up on or near the stairs (to block them) */ 385. choose_stairs(&sx, &sy, (mtmp->m_id % 2)); 386. mtmp->mavenge = 1; /* covetous monsters attack while fleeing */ 387. if (In_W_tower(mx, my, &u.uz) 388. || (mtmp->iswiz && !sx && !mon_has_amulet(mtmp))) { 389. if (!noteleport_level(mtmp) && 390. !rn2(3 + mtmp->mhp / 10)) 391. (void) rloc(mtmp, RLOC_MSG); 392. } else if (sx && (mx != sx || my != sy)) { 393. if (!noteleport_level(mtmp) && 394. !mnearto(mtmp, sx, sy, TRUE, RLOC_MSG)) { 395. /* couldn't move to the target spot for some reason, 396. so stay where we are (don't actually need rloc_to() 397. because mtmp is still on the map at <mx,my>... */ 398. rloc_to(mtmp, mx, my); 399. return 0; 400. } 401. mx = mtmp->mx, my = mtmp->my; /* update cached location */ 402. } 403. /* if you're not around, cast healing spells */ 404. if (distu(mx, my) > (BOLT_LIM * BOLT_LIM)) 405. if (mtmp->mhp <= mtmp->mhpmax - 8) { 406. healmon(mtmp, rnd(8), 0); 407. return 1; 408. } 409. FALLTHROUGH; 410. /*FALLTHRU*/ 411. 412. case STRAT_NONE: /* harass */ 413. if (!noteleport_level(mtmp) && !rn2(!mtmp->mflee ? 5 : 33)) 414. mnexto(mtmp, RLOC_MSG); 415. return 0; 416. 417. default: /* kill, maim, pillage! */ 418. { 419. long where = (strat & STRAT_STRATMASK); 420. coordxy tx = mtmp->mgoal.x, ty = mtmp->mgoal.y; 421. int targ = (int) (strat & STRAT_GOAL); 422. struct obj *otmp; 423. 424. if (!targ || !isok(tx, ty)) { /* simply wants you to close */ 425. return 0; 426. } 427. if (noteleport_level(mtmp) && !monnear(mtmp, tx, ty)) 428. return 0; 429. if (u_at(tx, ty) || where == STRAT_PLAYER) { 430. /* player is standing on it (or has it) */ 431. mx = mtmp->mx, my = mtmp->my; 432. if (noteleport_level(mtmp) || 433. !mnearto(mtmp, tx, ty, FALSE, RLOC_MSG)) 434. rloc_to(mtmp, mx, my); /* no room? stay put */ 435. return 0; 436. } 437. if (where == STRAT_GROUND) { 438. if (!MON_AT(tx, ty) || (mtmp->mx == tx && mtmp->my == ty)) { 439. /* teleport to it and pick it up */ 440. rloc_to(mtmp, tx, ty); /* clean old pos */ 441. 442. if ((otmp = on_ground(which_arti(targ))) != 0) { 443. if (cansee(mtmp->mx, mtmp->my)) 444. pline("%s picks up %s.", Monnam(mtmp), 445. distant_name(otmp, doname)); 446. obj_extract_self(otmp); 447. (void) mpickobj(mtmp, otmp); 448. return 1; 449. } else 450. return 0; 451. } else { 452. /* a monster is standing on it - cause some trouble */ 453. if (!rn2(5) && !noteleport_level(mtmp)) 454. mnexto(mtmp, RLOC_MSG); 455. return 0; 456. } 457. } else { /* a monster has it - 'port beside it. */ 458. mx = mtmp->mx, my = mtmp->my; 459. if (!noteleport_level(mtmp) && 460. !mnearto(mtmp, tx, ty, FALSE, RLOC_MSG)) 461. rloc_to(mtmp, mx, my); /* no room? stay put */ 462. return 0; 463. } 464. } /* default case */ 465. } /* switch */ 466. /*NOTREACHED*/ 467. return 0; 468. } 469. 470. RESTORE_WARNINGS 471. 472. /* are there any monsters mon could aggravate? */ 473. boolean 474. has_aggravatables(struct monst *mon) 475. { 476. struct monst *mtmp; 477. boolean in_w_tower = In_W_tower(mon->mx, mon->my, &u.uz); 478. 479. if (in_w_tower != In_W_tower(u.ux, u.uy, &u.uz)) 480. return FALSE; 481. 482. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 483. if (DEADMONSTER(mtmp)) 484. continue; 485. if (in_w_tower != In_W_tower(mtmp->mx, mtmp->my, &u.uz)) 486. continue; 487. if ((mtmp->mstrategy & STRAT_WAITFORU) != 0 || helpless(mtmp)) 488. return TRUE; 489. } 490. return FALSE; 491. } 492. 493. void 494. aggravate(void) 495. { 496. struct monst *mtmp; 497. boolean in_w_tower = In_W_tower(u.ux, u.uy, &u.uz); 498. 499. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 500. if (DEADMONSTER(mtmp)) 501. continue; 502. if (in_w_tower != In_W_tower(mtmp->mx, mtmp->my, &u.uz)) 503. continue; 504. mtmp->mstrategy &= ~(STRAT_WAITFORU | STRAT_APPEARMSG); 505. mtmp->msleeping = 0; 506. if (!mtmp->mcanmove && !rn2(5)) { 507. mtmp->mfrozen = 0; 508. mtmp->mcanmove = 1; 509. } 510. } 511. } 512. 513. /* "Double Trouble" spell cast by the Wizard; caller is responsible for 514. only casting this when there is currently one wizard in existence; 515. the clone can't use it unless/until its creator has been killed off */ 516. void 517. clonewiz(void) 518. { 519. struct monst *mtmp2; 520. 521. if ((mtmp2 = makemon(&mons[PM_WIZARD_OF_YENDOR], u.ux, u.uy, MM_NOWAIT)) 522. != 0) { 523. mtmp2->msleeping = mtmp2->mtame = mtmp2->mpeaceful = 0; 524. if (!u.uhave.amulet && rn2(2)) { /* give clone a fake */ 525. (void) add_to_minv(mtmp2, 526. mksobj(FAKE_AMULET_OF_YENDOR, TRUE, FALSE)); 527. } 528. if (!Protection_from_shape_changers) { 529. mtmp2->m_ap_type = M_AP_MONSTER; 530. mtmp2->mappearance = ROLL_FROM(wizapp); 531. } 532. newsym(mtmp2->mx, mtmp2->my); 533. } 534. } 535. 536. /* also used by newcham() */ 537. int 538. pick_nasty( 539. int difcap) /* if non-zero, try to make difficulty be lower than this */ 540. { 541. int alt, res = ROLL_FROM(nasties); 542. 543. /* To do? Possibly should filter for appropriate forms when 544. * in the elemental planes or surrounded by water or lava. 545. * 546. * We want monsters represented by uppercase on rogue level, 547. * but we don't try very hard. 548. */ 549. if (Is_rogue_level(&u.uz) 550. && !('A' <= monsym(&mons[res]) && monsym(&mons[res]) <= 'Z')) 551. res = ROLL_FROM(nasties); 552. 553. /* if genocided or too difficult or out of place, try a substitute 554. when a suitable one exists 555. arch-lich -> master lich, 556. master mind flayer -> mind flayer, 557. but the substitutes are likely to be genocided too */ 558. alt = res; 559. if ((svm.mvitals[res].mvflags & G_GENOD) != 0 560. || (difcap > 0 && mons[res].difficulty >= difcap) 561. /* note: nasty() -> makemon() ignores G_HELL|G_NOHELL; 562. arch-lich and master lich are both flagged as hell-only; 563. this filtering demotes arch-lich to master lich when 564. outside of Gehennom (unless the latter has been genocided) */ 565. || (mons[res].geno & (Inhell ? G_NOHELL : G_HELL)) != 0) 566. alt = big_to_little(res); 567. if (alt != res && (svm.mvitals[alt].mvflags & G_GENOD) == 0) { 568. const char *mnam = mons[alt].pmnames[NEUTRAL], 569. *lastspace = strrchr(mnam, ' '); 570. 571. /* only non-juveniles can become alternate choice */ 572. if (strncmp(mnam, "baby ", 5) 573. && (!lastspace 574. || (strcmp(lastspace, " hatchling") 575. && strcmp(lastspace, " pup") 576. && strcmp(lastspace, " cub")))) 577. res = alt; 578. } 579. 580. return res; 581. } 582. 583. /* create some nasty monsters, aligned with the caster or neutral; chaotic 584. and unaligned are treated as equivalent; if summoner is Null, this is 585. for late-game harassment (after the Wizard has been killed at least once 586. or the invocation ritual has been performed), in which case we treat 587. 'summoner' as neutral, since that will produce the greatest number of 588. creatures on average (in 3.6.0 and earlier, Null was treated as chaotic); 589. returns the number of monsters created */ 590. int 591. nasty(struct monst *summoner) 592. { 593. struct monst *mtmp; 594. coord bypos; 595. int i, j, count, census, tmp, makeindex, 596. s_cls, m_cls, difcap, trylimit, castalign; 597. /* when a monster casts the "summon nasties" spell, it gives feedback; 598. when random post-Wizard harassment casts that, we give feedback */ 599. unsigned mmflags = summoner ? MM_NOMSG : NO_MM_FLAGS; 600. 601. #define MAXNASTIES 10 /* more than this can be created */ 602. 603. /* some candidates may be created in groups, so simple count 604. of non-null makemon() return is inadequate */ 605. census = monster_census(FALSE); 606. 607. if (!rn2(10) && Inhell) { 608. /* this might summon a demon prince or lord */ 609. count = msummon((struct monst *) 0); /* summons like WoY */ 610. } else { 611. count = 0; 612. s_cls = summoner ? summoner->data->mlet : 0; 613. difcap = summoner ? summoner->data->difficulty : 0; /* spellcasters */ 614. castalign = summoner ? sgn(summoner->data->maligntyp) : 0; 615. tmp = (u.ulevel > 3) ? u.ulevel / 3 : 1; 616. /* if we don't have a casting monster, nasties appear around hero, 617. otherwise they'll appear around spot summoner thinks she's at */ 618. bypos.x = u.ux; 619. bypos.y = u.uy; 620. for (i = rnd(tmp); i > 0 && count < MAXNASTIES; --i) { 621. /* Of the 44 nasties[], 10 are lawful, 14 are chaotic, 622. * and 20 are neutral. [These numbers are up date for 623. * 5.0.0; the ones in the next paragraph are not....] 624. * 625. * Neutral caster, used for late-game harassment, 626. * has 18/42 chance to stop the inner loop on each 627. * critter, 24/42 chance for another iteration. 628. * Lawful caster has 28/42 chance to stop unless the 629. * summoner is an angel or demon, in which case the 630. * chance is 26/42. 631. * Chaotic or unaligned caster has 32/42 chance to 632. * stop, so will summon fewer creatures on average. 633. * 634. * The outer loop potentially gives chaotic/unaligned 635. * a chance to even things up since others will hit 636. * MAXNASTIES sooner, but its number of iterations is 637. * randomized so it won't always do so. 638. */ 639. for (j = 0; j < 20; j++) { 640. /* Don't create more spellcasters of the monster's level or 641. * higher--avoids chain summoners filling up the level. 642. */ 643. trylimit = 10 + 1; /* 10 tries */ 644. do { 645. if (!--trylimit) 646. goto nextj; /* break this loop, continue outer one */ 647. makeindex = pick_nasty(difcap); 648. m_cls = mons[makeindex].mlet; 649. } while ((difcap > 0 && mons[makeindex].difficulty >= difcap 650. && attacktype(&mons[makeindex], AT_MAGC)) 651. || (s_cls == S_DEMON && m_cls == S_ANGEL) 652. || (s_cls == S_ANGEL && m_cls == S_DEMON)); 653. /* do this after picking the monster to place */ 654. if (summoner && !enexto(&bypos, summoner->mux, summoner->muy, 655. &mons[makeindex])) 656. continue; 657. /* this honors genocide but overrides extinction; it ignores 658. inside-hell-only (G_HELL) & outside-hell-only (G_NOHELL) */ 659. if ((mtmp = makemon(&mons[makeindex], bypos.x, bypos.y, 660. mmflags)) != 0) { 661. mtmp->msleeping = mtmp->mpeaceful = mtmp->mtame = 0; 662. set_malign(mtmp); 663. } else { 664. /* random monster to substitute for geno'd selection; 665. unlike direct choice, not forced to be hostile [why?]; 666. limit spellcasters to inhibit chain summoning */ 667. if ((mtmp = makemon((struct permonst *) 0, 668. bypos.x, bypos.y, mmflags)) != 0) { 669. m_cls = mtmp->data->mlet; 670. if ((difcap > 0 && mtmp->data->difficulty >= difcap 671. /* always capping for substitutes made wanton 672. genocide become too strong in the endgame */ 673. && rn2(In_endgame(&u.uz) ? 3 : 7) /* usually */ 674. && attacktype(mtmp->data, AT_MAGC)) 675. || (s_cls == S_DEMON && m_cls == S_ANGEL) 676. || (s_cls == S_ANGEL && m_cls == S_DEMON)) 677. mtmp = unmakemon(mtmp, NO_MM_FLAGS); /* Null */ 678. } 679. } 680. 681. if (mtmp) { 682. /* if creating an arch-lich or Archon, further directly 683. selected nasties will have to be less difficult, and 684. substitues for geno victims will usually be less 685. (note: Archon is not in nasties[] but could be chosen 686. as random replacement for a genocided selection) */ 687. if (mtmp->data == &mons[PM_ARCH_LICH] 688. || mtmp->data == &mons[PM_ARCHON]) { 689. tmp = min(mons[PM_ARCHON].difficulty, /* A:26 */ 690. mons[PM_ARCH_LICH].difficulty); /* L:31 */ 691. if (!difcap || difcap > tmp) 692. difcap = tmp; /* rest must be lower difficulty */ 693. } 694. /* delay first use of spell or breath attack */ 695. mtmp->mspec_used = rnd(4); 696. 697. if (++count >= MAXNASTIES 698. || mtmp->data->maligntyp == 0 699. || sgn(mtmp->data->maligntyp) == castalign) 700. break; 701. } 702. nextj: 703. ; /* empty; label must be followed by a statement */ 704. } /* for j */ 705. } /* for i */ 706. } 707. 708. if (count) 709. count = monster_census(FALSE) - census; 710. return count; 711. } 712. 713. /* Let's resurrect the Wizard, for some unexpected fun. */ 714. void 715. resurrect(void) 716. { 717. struct monst *mtmp, **mmtmp; 718. long elapsed; 719. const char *verb; 720. 721. if (!svc.context.no_of_wizards) { 722. /* make a new Wizard */ 723. verb = "kill"; 724. mtmp = makemon(&mons[PM_WIZARD_OF_YENDOR], u.ux, u.uy, MM_NOWAIT); 725. /* affects experience; he's not coming back from a corpse 726. but is subject to repeated killing like a revived corpse */ 727. if (mtmp) 728. mtmp->mrevived = 1; 729. } else { 730. /* look for a migrating Wizard */ 731. verb = "elude"; 732. mmtmp = &gm.migrating_mons; 733. while ((mtmp = *mmtmp) != 0) { 734. if (mtmp->iswiz 735. /* if he has the Amulet, he won't bring it to you */ 736. && !mon_has_amulet(mtmp) 737. && (elapsed = svm.moves - mtmp->mlstmv) > 0L) { 738. mon_catchup_elapsed_time(mtmp, elapsed); 739. if (elapsed >= LARGEST_INT) 740. elapsed = LARGEST_INT - 1; 741. elapsed /= 50L; 742. if (mtmp->msleeping && rn2((int) elapsed + 1)) 743. mtmp->msleeping = 0; 744. if (mtmp->mfrozen == 1) /* would unfreeze on next move */ 745. mtmp->mfrozen = 0, mtmp->mcanmove = 1; 746. if (!helpless(mtmp)) { 747. *mmtmp = mtmp->nmon; 748. mon_arrive(mtmp, -1); /* -1: Wiz_arrive (dog.c) */ 749. /* mx: mon_arrive() might have sent mtmp into limbo */ 750. if (!mtmp->mx) 751. mtmp = 0; 752. /* note: there might be a second Wizard; if so, 753. he'll have to wait until the next resurrection */ 754. break; 755. } 756. } 757. mmtmp = &mtmp->nmon; 758. } 759. } 760. 761. if (mtmp) { 762. /* FIXME: when a new wizard is created by makemon(), it gives 763. a "<mon> appears" message, delivered after he's been placed 764. on the map; however, when an existing wizard comes off 765. migrating_mons, he ends up triggering "<mon> vanishes and 766. reappears" on his first move (tactics when hero is carrying 767. the Amulet); setting STRAT_WAITMASK suppresses that but then 768. he just sits wherever he is, "meditating", contradicting the 769. threatening message below */ 770. mtmp->mstrategy &= ~STRAT_WAITMASK; 771. 772. mtmp->mtame = 0, mtmp->mpeaceful = 0; /* paranoia */ 773. set_malign(mtmp); 774. if (!Deaf) { 775. pline("A voice booms out..."); 776. SetVoice(mtmp, 0, 80, 0); 777. verbalize("So thou thought thou couldst %s me, fool.", verb); 778. } 779. } 780. } 781. 782. /* Here, we make trouble for the poor shmuck who actually 783. managed to do in the Wizard. */ 784. void 785. intervene(void) 786. { 787. int which = Is_astralevel(&u.uz) ? rnd(4) : rn2(6); 788. 789. /* cases 0 and 5 don't apply on the Astral level */ 790. switch (which) { 791. case 0: 792. case 1: 793. You_feel("vaguely nervous."); 794. break; 795. case 2: 796. if (!Blind) 797. You("notice a %s glow surrounding you.", hcolor(NH_BLACK)); 798. rndcurse(); 799. break; 800. case 3: 801. aggravate(); 802. break; 803. case 4: 804. (void) nasty((struct monst *) 0); 805. break; 806. case 5: 807. resurrect(); 808. break; 809. } 810. } 811. 812. /* Wizard of Yendor is being removed from play (dead or escaped the dungeon); 813. keep the bookkeeping for him up to date */ 814. void 815. wizdeadorgone(void) 816. { 817. svc.context.no_of_wizards--; 818. if (!u.uevent.udemigod) { 819. u.uevent.udemigod = TRUE; 820. u.udg_cnt = rn1(250, 50); 821. } 822. } 823. 824. static const char *const random_insult[] = { 825. "antic", "blackguard", "caitiff", "chucklehead", 826. "coistrel", "craven", "cretin", "cur", 827. "dastard", "demon fodder", "dimwit", "dolt", 828. "fool", "footpad", "imbecile", "knave", 829. "maledict", "miscreant", "niddering", "poltroon", 830. "rattlepate", "reprobate", "scapegrace", "varlet", 831. "villein", /* (sic.) */ 832. "wittol", "worm", "wretch", 833. }; 834. 835. static const char *const random_malediction[] = { 836. "Hell shall soon claim thy remains,", "I chortle at thee, thou pathetic", 837. "Prepare to die, thou", "Resistance is useless,", 838. "Surrender or die, thou", "There shall be no mercy, thou", 839. "Thou shalt repent of thy cunning,", "Thou art as a flea to me,", 840. "Thou art doomed,", "Thy fate is sealed,", 841. "Verily, thou shalt be one dead" 842. }; 843. 844. /* Insult or intimidate the player */ 845. void 846. cuss(struct monst *mtmp) 847. { 848. if (Deaf) 849. return; 850. if (mtmp->iswiz) { 851. if (!rn2(5)) { /* typical bad guy action */ 852. pline("%s laughs fiendishly.", Monnam(mtmp)); 853. } else if (u.uhave.amulet && !rn2(SIZE(random_insult))) { 854. SetVoice(mtmp, 0, 80, 0); 855. verbalize("Relinquish the amulet, %s!", 856. ROLL_FROM(random_insult)); 857. } else if (u.uhp < 5 && !rn2(2)) { /* Panic */ 858. SetVoice(mtmp, 0, 80, 0); 859. verbalize(rn2(2) ? "Even now thy life force ebbs, %s!" 860. : "Savor thy breath, %s, it be thy last!", 861. ROLL_FROM(random_insult)); 862. } else if (mtmp->mhp < 5 && !rn2(2)) { /* Parthian shot */ 863. SetVoice(mtmp, 0, 80, 0); 864. verbalize(rn2(2) ? "I shall return." : "I'll be back."); 865. } else { 866. SetVoice(mtmp, 0, 80, 0); 867. verbalize("%s %s!", 868. ROLL_FROM(random_malediction), 869. ROLL_FROM(random_insult)); 870. } 871. } else if (is_lminion(mtmp) 872. && !(mtmp->isminion && EMIN(mtmp)->renegade)) { 873. com_pager("angel_cuss"); /* TODO: the Hallucination msg */ 874. /*com_pager(rn2(QTN_ANGELIC - 1 + (Hallucination ? 1 : 0)) 875. + QT_ANGELIC);*/ 876. } else { 877. if (!rn2(is_minion(mtmp->data) ? 100 : 5)) 878. pline("%s casts aspersions on your ancestry.", Monnam(mtmp)); 879. else 880. com_pager("demon_cuss"); 881. } 882. wake_nearto(mtmp->mx, mtmp->my, 5 * 5); 883. } 884. 885. /*wizard.c*/