Source:NetHack 3.6.2/src/muse.c
Jump to navigation
Jump to search
Below is the full text to muse.c from the source code of NetHack 3.6.2. To link to a particular line, write [[Source:NetHack 3.6.2/src/muse.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 muse.c $NHDT-Date: 1547025167 2019/01/09 09:12:47 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.92 $ */ 2. /* Copyright (C) 1990 by Ken Arromdee */ 3. /* NetHack may be freely redistributed. See license for details. */ 4. 5. /* 6. * Monster item usage routines. 7. */ 8. 9. #include "hack.h" 10. 11. boolean m_using = FALSE; 12. 13. /* Let monsters use magic items. Arbitrary assumptions: Monsters only use 14. * scrolls when they can see, monsters know when wands have 0 charges, 15. * monsters cannot recognize if items are cursed are not, monsters which 16. * are confused don't know not to read scrolls, etc.... 17. */ 18. 19. STATIC_DCL struct permonst *FDECL(muse_newcham_mon, (struct monst *)); 20. STATIC_DCL int FDECL(precheck, (struct monst *, struct obj *)); 21. STATIC_DCL void FDECL(mzapmsg, (struct monst *, struct obj *, BOOLEAN_P)); 22. STATIC_DCL void FDECL(mreadmsg, (struct monst *, struct obj *)); 23. STATIC_DCL void FDECL(mquaffmsg, (struct monst *, struct obj *)); 24. STATIC_DCL boolean FDECL(m_use_healing, (struct monst *)); 25. STATIC_PTR int FDECL(mbhitm, (struct monst *, struct obj *)); 26. STATIC_DCL void FDECL(mbhit, (struct monst *, int, 27. int FDECL((*), (MONST_P, OBJ_P)), 28. int FDECL((*), (OBJ_P, OBJ_P)), struct obj *)); 29. STATIC_DCL void FDECL(you_aggravate, (struct monst *)); 30. STATIC_DCL void FDECL(mon_consume_unstone, (struct monst *, struct obj *, 31. BOOLEAN_P, BOOLEAN_P)); 32. STATIC_DCL boolean FDECL(cures_stoning, (struct monst *, struct obj *, 33. BOOLEAN_P)); 34. STATIC_DCL boolean FDECL(mcould_eat_tin, (struct monst *)); 35. STATIC_DCL boolean FDECL(muse_unslime, (struct monst *, struct obj *, 36. struct trap *, BOOLEAN_P)); 37. STATIC_DCL int FDECL(cures_sliming, (struct monst *, struct obj *)); 38. STATIC_DCL boolean FDECL(green_mon, (struct monst *)); 39. 40. static struct musable { 41. struct obj *offensive; 42. struct obj *defensive; 43. struct obj *misc; 44. int has_offense, has_defense, has_misc; 45. /* =0, no capability; otherwise, different numbers. 46. * If it's an object, the object is also set (it's 0 otherwise). 47. */ 48. } m; 49. static int trapx, trapy; 50. static boolean zap_oseen; /* for wands which use mbhitm and are zapped at 51. * players. We usually want an oseen local to 52. * the function, but this is impossible since the 53. * function mbhitm has to be compatible with the 54. * normal zap routines, and those routines don't 55. * remember who zapped the wand. */ 56. 57. /* Any preliminary checks which may result in the monster being unable to use 58. * the item. Returns 0 if nothing happened, 2 if the monster can't do 59. * anything (i.e. it teleported) and 1 if it's dead. 60. */ 61. STATIC_OVL int 62. precheck(mon, obj) 63. struct monst *mon; 64. struct obj *obj; 65. { 66. boolean vis; 67. 68. if (!obj) 69. return 0; 70. vis = cansee(mon->mx, mon->my); 71. 72. if (obj->oclass == POTION_CLASS) { 73. coord cc; 74. static const char *empty = "The potion turns out to be empty."; 75. const char *potion_descr; 76. struct monst *mtmp; 77. 78. potion_descr = OBJ_DESCR(objects[obj->otyp]); 79. if (potion_descr && !strcmp(potion_descr, "milky")) { 80. if (!(mvitals[PM_GHOST].mvflags & G_GONE) 81. && !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_GHOST].born))) { 82. if (!enexto(&cc, mon->mx, mon->my, &mons[PM_GHOST])) 83. return 0; 84. mquaffmsg(mon, obj); 85. m_useup(mon, obj); 86. mtmp = makemon(&mons[PM_GHOST], cc.x, cc.y, NO_MM_FLAGS); 87. if (!mtmp) { 88. if (vis) 89. pline1(empty); 90. } else { 91. if (vis) { 92. pline( 93. "As %s opens the bottle, an enormous %s emerges!", 94. mon_nam(mon), 95. Hallucination ? rndmonnam(NULL) 96. : (const char *) "ghost"); 97. pline("%s is frightened to death, and unable to move.", 98. Monnam(mon)); 99. } 100. paralyze_monst(mon, 3); 101. } 102. return 2; 103. } 104. } 105. if (potion_descr && !strcmp(potion_descr, "smoky") 106. && !(mvitals[PM_DJINNI].mvflags & G_GONE) 107. && !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_DJINNI].born))) { 108. if (!enexto(&cc, mon->mx, mon->my, &mons[PM_DJINNI])) 109. return 0; 110. mquaffmsg(mon, obj); 111. m_useup(mon, obj); 112. mtmp = makemon(&mons[PM_DJINNI], cc.x, cc.y, NO_MM_FLAGS); 113. if (!mtmp) { 114. if (vis) 115. pline1(empty); 116. } else { 117. if (vis) 118. pline("In a cloud of smoke, %s emerges!", a_monnam(mtmp)); 119. pline("%s speaks.", vis ? Monnam(mtmp) : Something); 120. /* I suspect few players will be upset that monsters */ 121. /* can't wish for wands of death here.... */ 122. if (rn2(2)) { 123. verbalize("You freed me!"); 124. mtmp->mpeaceful = 1; 125. set_malign(mtmp); 126. } else { 127. verbalize("It is about time."); 128. if (vis) 129. pline("%s vanishes.", Monnam(mtmp)); 130. mongone(mtmp); 131. } 132. } 133. return 2; 134. } 135. } 136. if (obj->oclass == WAND_CLASS && obj->cursed 137. && !rn2(WAND_BACKFIRE_CHANCE)) { 138. int dam = d(obj->spe + 2, 6); 139. 140. /* 3.6.1: no Deaf filter; 'if' message doesn't warrant it, 'else' 141. message doesn't need it since You_hear() has one of its own */ 142. if (vis) { 143. pline("%s zaps %s, which suddenly explodes!", Monnam(mon), 144. an(xname(obj))); 145. } else { 146. /* same near/far threshold as mzapmsg() */ 147. int range = couldsee(mon->mx, mon->my) /* 9 or 5 */ 148. ? (BOLT_LIM + 1) : (BOLT_LIM - 3); 149. 150. You_hear("a zap and an explosion %s.", 151. (distu(mon->mx, mon->my) <= range * range) 152. ? "nearby" : "in the distance"); 153. } 154. m_useup(mon, obj); 155. mon->mhp -= dam; 156. if (DEADMONSTER(mon)) { 157. monkilled(mon, "", AD_RBRE); 158. return 1; 159. } 160. m.has_defense = m.has_offense = m.has_misc = 0; 161. /* Only one needed to be set to 0 but the others are harmless */ 162. } 163. return 0; 164. } 165. 166. STATIC_OVL void 167. mzapmsg(mtmp, otmp, self) 168. struct monst *mtmp; 169. struct obj *otmp; 170. boolean self; 171. { 172. if (!canseemon(mtmp)) { 173. int range = couldsee(mtmp->mx, mtmp->my) /* 9 or 5 */ 174. ? (BOLT_LIM + 1) : (BOLT_LIM - 3); 175. 176. You_hear("a %s zap.", (distu(mtmp->mx, mtmp->my) <= range * range) 177. ? "nearby" : "distant"); 178. } else if (self) { 179. pline("%s zaps %sself with %s!", Monnam(mtmp), mhim(mtmp), 180. doname(otmp)); 181. } else { 182. pline("%s zaps %s!", Monnam(mtmp), an(xname(otmp))); 183. stop_occupation(); 184. } 185. } 186. 187. STATIC_OVL void 188. mreadmsg(mtmp, otmp) 189. struct monst *mtmp; 190. struct obj *otmp; 191. { 192. boolean vismon = canseemon(mtmp); 193. char onambuf[BUFSZ]; 194. short saverole; 195. unsigned savebknown; 196. 197. if (!vismon && Deaf) 198. return; /* no feedback */ 199. 200. otmp->dknown = 1; /* seeing or hearing it read reveals its label */ 201. /* shouldn't be able to hear curse/bless status of unseen scrolls; 202. for priest characters, bknown will always be set during naming */ 203. savebknown = otmp->bknown; 204. saverole = Role_switch; 205. if (!vismon) { 206. otmp->bknown = 0; 207. if (Role_if(PM_PRIEST)) 208. Role_switch = 0; 209. } 210. Strcpy(onambuf, singular(otmp, doname)); 211. Role_switch = saverole; 212. otmp->bknown = savebknown; 213. 214. if (vismon) 215. pline("%s reads %s!", Monnam(mtmp), onambuf); 216. else 217. You_hear("%s reading %s.", 218. x_monnam(mtmp, ARTICLE_A, (char *) 0, 219. (SUPPRESS_IT | SUPPRESS_INVISIBLE | SUPPRESS_SADDLE), 220. FALSE), 221. onambuf); 222. 223. if (mtmp->mconf) 224. pline("Being confused, %s mispronounces the magic words...", 225. vismon ? mon_nam(mtmp) : mhe(mtmp)); 226. } 227. 228. STATIC_OVL void 229. mquaffmsg(mtmp, otmp) 230. struct monst *mtmp; 231. struct obj *otmp; 232. { 233. if (canseemon(mtmp)) { 234. otmp->dknown = 1; 235. pline("%s drinks %s!", Monnam(mtmp), singular(otmp, doname)); 236. } else if (!Deaf) 237. You_hear("a chugging sound."); 238. } 239. 240. /* Defines for various types of stuff. The order in which monsters prefer 241. * to use them is determined by the order of the code logic, not the 242. * numerical order in which they are defined. 243. */ 244. #define MUSE_SCR_TELEPORTATION 1 245. #define MUSE_WAN_TELEPORTATION_SELF 2 246. #define MUSE_POT_HEALING 3 247. #define MUSE_POT_EXTRA_HEALING 4 248. #define MUSE_WAN_DIGGING 5 249. #define MUSE_TRAPDOOR 6 250. #define MUSE_TELEPORT_TRAP 7 251. #define MUSE_UPSTAIRS 8 252. #define MUSE_DOWNSTAIRS 9 253. #define MUSE_WAN_CREATE_MONSTER 10 254. #define MUSE_SCR_CREATE_MONSTER 11 255. #define MUSE_UP_LADDER 12 256. #define MUSE_DN_LADDER 13 257. #define MUSE_SSTAIRS 14 258. #define MUSE_WAN_TELEPORTATION 15 259. #define MUSE_BUGLE 16 260. #define MUSE_UNICORN_HORN 17 261. #define MUSE_POT_FULL_HEALING 18 262. #define MUSE_LIZARD_CORPSE 19 263. /* 264. #define MUSE_INNATE_TPT 9999 265. * We cannot use this. Since monsters get unlimited teleportation, if they 266. * were allowed to teleport at will you could never catch them. Instead, 267. * assume they only teleport at random times, despite the inconsistency 268. * that if you polymorph into one you teleport at will. 269. */ 270. 271. STATIC_OVL boolean 272. m_use_healing(mtmp) 273. struct monst *mtmp; 274. { 275. struct obj *obj = 0; 276. if ((obj = m_carrying(mtmp, POT_FULL_HEALING)) != 0) { 277. m.defensive = obj; 278. m.has_defense = MUSE_POT_FULL_HEALING; 279. return TRUE; 280. } 281. if ((obj = m_carrying(mtmp, POT_EXTRA_HEALING)) != 0) { 282. m.defensive = obj; 283. m.has_defense = MUSE_POT_EXTRA_HEALING; 284. return TRUE; 285. } 286. if ((obj = m_carrying(mtmp, POT_HEALING)) != 0) { 287. m.defensive = obj; 288. m.has_defense = MUSE_POT_HEALING; 289. return TRUE; 290. } 291. return FALSE; 292. } 293. 294. /* Select a defensive item/action for a monster. Returns TRUE iff one is 295. found. */ 296. boolean 297. find_defensive(mtmp) 298. struct monst *mtmp; 299. { 300. register struct obj *obj = 0; 301. struct trap *t; 302. int x = mtmp->mx, y = mtmp->my; 303. boolean stuck = (mtmp == u.ustuck); 304. boolean immobile = (mtmp->data->mmove == 0); 305. int fraction; 306. 307. if (is_animal(mtmp->data) || mindless(mtmp->data)) 308. return FALSE; 309. if (dist2(x, y, mtmp->mux, mtmp->muy) > 25) 310. return FALSE; 311. if (u.uswallow && stuck) 312. return FALSE; 313. 314. m.defensive = (struct obj *) 0; 315. m.has_defense = 0; 316. 317. /* since unicorn horns don't get used up, the monster would look 318. * silly trying to use the same cursed horn round after round 319. */ 320. if (mtmp->mconf || mtmp->mstun || !mtmp->mcansee) { 321. if (!is_unicorn(mtmp->data) && !nohands(mtmp->data)) { 322. for (obj = mtmp->minvent; obj; obj = obj->nobj) 323. if (obj->otyp == UNICORN_HORN && !obj->cursed) 324. break; 325. } 326. if (obj || is_unicorn(mtmp->data)) { 327. m.defensive = obj; 328. m.has_defense = MUSE_UNICORN_HORN; 329. return TRUE; 330. } 331. } 332. 333. if (mtmp->mconf || mtmp->mstun) { 334. struct obj *liztin = 0; 335. 336. for (obj = mtmp->minvent; obj; obj = obj->nobj) { 337. if (obj->otyp == CORPSE && obj->corpsenm == PM_LIZARD) { 338. m.defensive = obj; 339. m.has_defense = MUSE_LIZARD_CORPSE; 340. return TRUE; 341. } else if (obj->otyp == TIN && obj->corpsenm == PM_LIZARD) { 342. liztin = obj; 343. } 344. } 345. /* confused or stunned monster might not be able to open tin */ 346. if (liztin && mcould_eat_tin(mtmp) && rn2(3)) { 347. m.defensive = liztin; 348. /* tin and corpse ultimately end up being handled the same */ 349. m.has_defense = MUSE_LIZARD_CORPSE; 350. return TRUE; 351. } 352. } 353. 354. /* It so happens there are two unrelated cases when we might want to 355. * check specifically for healing alone. The first is when the monster 356. * is blind (healing cures blindness). The second is when the monster 357. * is peaceful; then we don't want to flee the player, and by 358. * coincidence healing is all there is that doesn't involve fleeing. 359. * These would be hard to combine because of the control flow. 360. * Pestilence won't use healing even when blind. 361. */ 362. if (!mtmp->mcansee && !nohands(mtmp->data) 363. && mtmp->data != &mons[PM_PESTILENCE]) { 364. if (m_use_healing(mtmp)) 365. return TRUE; 366. } 367. 368. fraction = u.ulevel < 10 ? 5 : u.ulevel < 14 ? 4 : 3; 369. if (mtmp->mhp >= mtmp->mhpmax 370. || (mtmp->mhp >= 10 && mtmp->mhp * fraction >= mtmp->mhpmax)) 371. return FALSE; 372. 373. if (mtmp->mpeaceful) { 374. if (!nohands(mtmp->data)) { 375. if (m_use_healing(mtmp)) 376. return TRUE; 377. } 378. return FALSE; 379. } 380. 381. if (stuck || immobile) { 382. ; /* fleeing by stairs or traps is not possible */ 383. } else if (levl[x][y].typ == STAIRS) { 384. if (x == xdnstair && y == ydnstair) { 385. if (!is_floater(mtmp->data)) 386. m.has_defense = MUSE_DOWNSTAIRS; 387. } else if (x == xupstair && y == yupstair) { 388. m.has_defense = MUSE_UPSTAIRS; 389. } else if (sstairs.sx && x == sstairs.sx && y == sstairs.sy) { 390. if (sstairs.up || !is_floater(mtmp->data)) 391. m.has_defense = MUSE_SSTAIRS; 392. } 393. } else if (levl[x][y].typ == LADDER) { 394. if (x == xupladder && y == yupladder) { 395. m.has_defense = MUSE_UP_LADDER; 396. } else if (x == xdnladder && y == ydnladder) { 397. if (!is_floater(mtmp->data)) 398. m.has_defense = MUSE_DN_LADDER; 399. } else if (sstairs.sx && x == sstairs.sx && y == sstairs.sy) { 400. if (sstairs.up || !is_floater(mtmp->data)) 401. m.has_defense = MUSE_SSTAIRS; 402. } 403. } else { 404. /* Note: trap doors take precedence over teleport traps. */ 405. int xx, yy, i, locs[10][2]; 406. boolean ignore_boulders = (verysmall(mtmp->data) 407. || throws_rocks(mtmp->data) 408. || passes_walls(mtmp->data)), 409. diag_ok = !NODIAG(monsndx(mtmp->data)); 410. 411. for (i = 0; i < 10; ++i) /* 10: 9 spots plus sentinel */ 412. locs[i][0] = locs[i][1] = 0; 413. /* collect viable spots; monster's <mx,my> comes first */ 414. locs[0][0] = x, locs[0][1] = y; 415. i = 1; 416. for (xx = x - 1; xx <= x + 1; xx++) 417. for (yy = y - 1; yy <= y + 1; yy++) 418. if (isok(xx, yy) && (xx != x || yy != y)) { 419. locs[i][0] = xx, locs[i][1] = yy; 420. ++i; 421. } 422. /* look for a suitable trap among the viable spots */ 423. for (i = 0; i < 10; ++i) { 424. xx = locs[i][0], yy = locs[i][1]; 425. if (!xx) 426. break; /* we've run out of spots */ 427. /* skip if it's hero's location 428. or a diagonal spot and monster can't move diagonally 429. or some other monster is there */ 430. if ((xx == u.ux && yy == u.uy) 431. || (xx != x && yy != y && !diag_ok) 432. || (level.monsters[xx][yy] && !(xx == x && yy == y))) 433. continue; 434. /* skip if there's no trap or can't/won't move onto trap */ 435. if ((t = t_at(xx, yy)) == 0 436. || (!ignore_boulders && sobj_at(BOULDER, xx, yy)) 437. || onscary(xx, yy, mtmp)) 438. continue; 439. /* use trap if it's the correct type */ 440. if (is_hole(t->ttyp) 441. && !is_floater(mtmp->data) 442. && !mtmp->isshk && !mtmp->isgd && !mtmp->ispriest 443. && Can_fall_thru(&u.uz)) { 444. trapx = xx; 445. trapy = yy; 446. m.has_defense = MUSE_TRAPDOOR; 447. break; /* no need to look at any other spots */ 448. } else if (t->ttyp == TELEP_TRAP) { 449. trapx = xx; 450. trapy = yy; 451. m.has_defense = MUSE_TELEPORT_TRAP; 452. } 453. } 454. } 455. 456. if (nohands(mtmp->data)) /* can't use objects */ 457. goto botm; 458. 459. if (is_mercenary(mtmp->data) && (obj = m_carrying(mtmp, BUGLE)) != 0) { 460. int xx, yy; 461. struct monst *mon; 462. 463. /* Distance is arbitrary. What we really want to do is 464. * have the soldier play the bugle when it sees or 465. * remembers soldiers nearby... 466. */ 467. for (xx = x - 3; xx <= x + 3; xx++) { 468. for (yy = y - 3; yy <= y + 3; yy++) { 469. if (!isok(xx, yy) || (xx == x && yy == y)) 470. continue; 471. if ((mon = m_at(xx, yy)) != 0 && is_mercenary(mon->data) 472. && mon->data != &mons[PM_GUARD] 473. && (mon->msleeping || !mon->mcanmove)) { 474. m.defensive = obj; 475. m.has_defense = MUSE_BUGLE; 476. goto toot; /* double break */ 477. } 478. } 479. } 480. toot: 481. ; 482. } 483. 484. /* use immediate physical escape prior to attempting magic */ 485. if (m.has_defense) /* stairs, trap door or tele-trap, bugle alert */ 486. goto botm; 487. 488. /* kludge to cut down on trap destruction (particularly portals) */ 489. t = t_at(x, y); 490. if (t && (is_pit(t->ttyp) || t->ttyp == WEB 491. || t->ttyp == BEAR_TRAP)) 492. t = 0; /* ok for monster to dig here */ 493. 494. #define nomore(x) if (m.has_defense == x) continue; 495. /* selection could be improved by collecting all possibilities 496. into an array and then picking one at random */ 497. for (obj = mtmp->minvent; obj; obj = obj->nobj) { 498. /* don't always use the same selection pattern */ 499. if (m.has_defense && !rn2(3)) 500. break; 501. 502. /* nomore(MUSE_WAN_DIGGING); */ 503. if (m.has_defense == MUSE_WAN_DIGGING) 504. break; 505. if (obj->otyp == WAN_DIGGING && obj->spe > 0 && !stuck && !t 506. && !mtmp->isshk && !mtmp->isgd && !mtmp->ispriest 507. && !is_floater(mtmp->data) 508. /* monsters digging in Sokoban can ruin things */ 509. && !Sokoban 510. /* digging wouldn't be effective; assume they know that */ 511. && !(levl[x][y].wall_info & W_NONDIGGABLE) 512. && !(Is_botlevel(&u.uz) || In_endgame(&u.uz)) 513. && !(is_ice(x, y) || is_pool(x, y) || is_lava(x, y)) 514. && !(mtmp->data == &mons[PM_VLAD_THE_IMPALER] 515. && In_V_tower(&u.uz))) { 516. m.defensive = obj; 517. m.has_defense = MUSE_WAN_DIGGING; 518. } 519. nomore(MUSE_WAN_TELEPORTATION_SELF); 520. nomore(MUSE_WAN_TELEPORTATION); 521. if (obj->otyp == WAN_TELEPORTATION && obj->spe > 0) { 522. /* use the TELEP_TRAP bit to determine if they know 523. * about noteleport on this level or not. Avoids 524. * ineffective re-use of teleportation. This does 525. * mean if the monster leaves the level, they'll know 526. * about teleport traps. 527. */ 528. if (!level.flags.noteleport 529. || !(mtmp->mtrapseen & (1 << (TELEP_TRAP - 1)))) { 530. m.defensive = obj; 531. m.has_defense = (mon_has_amulet(mtmp)) 532. ? MUSE_WAN_TELEPORTATION 533. : MUSE_WAN_TELEPORTATION_SELF; 534. } 535. } 536. nomore(MUSE_SCR_TELEPORTATION); 537. if (obj->otyp == SCR_TELEPORTATION && mtmp->mcansee 538. && haseyes(mtmp->data) 539. && (!obj->cursed || (!(mtmp->isshk && inhishop(mtmp)) 540. && !mtmp->isgd && !mtmp->ispriest))) { 541. /* see WAN_TELEPORTATION case above */ 542. if (!level.flags.noteleport 543. || !(mtmp->mtrapseen & (1 << (TELEP_TRAP - 1)))) { 544. m.defensive = obj; 545. m.has_defense = MUSE_SCR_TELEPORTATION; 546. } 547. } 548. 549. if (mtmp->data != &mons[PM_PESTILENCE]) { 550. nomore(MUSE_POT_FULL_HEALING); 551. if (obj->otyp == POT_FULL_HEALING) { 552. m.defensive = obj; 553. m.has_defense = MUSE_POT_FULL_HEALING; 554. } 555. nomore(MUSE_POT_EXTRA_HEALING); 556. if (obj->otyp == POT_EXTRA_HEALING) { 557. m.defensive = obj; 558. m.has_defense = MUSE_POT_EXTRA_HEALING; 559. } 560. nomore(MUSE_WAN_CREATE_MONSTER); 561. if (obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) { 562. m.defensive = obj; 563. m.has_defense = MUSE_WAN_CREATE_MONSTER; 564. } 565. nomore(MUSE_POT_HEALING); 566. if (obj->otyp == POT_HEALING) { 567. m.defensive = obj; 568. m.has_defense = MUSE_POT_HEALING; 569. } 570. } else { /* Pestilence */ 571. nomore(MUSE_POT_FULL_HEALING); 572. if (obj->otyp == POT_SICKNESS) { 573. m.defensive = obj; 574. m.has_defense = MUSE_POT_FULL_HEALING; 575. } 576. nomore(MUSE_WAN_CREATE_MONSTER); 577. if (obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) { 578. m.defensive = obj; 579. m.has_defense = MUSE_WAN_CREATE_MONSTER; 580. } 581. } 582. nomore(MUSE_SCR_CREATE_MONSTER); 583. if (obj->otyp == SCR_CREATE_MONSTER) { 584. m.defensive = obj; 585. m.has_defense = MUSE_SCR_CREATE_MONSTER; 586. } 587. } 588. botm: 589. return (boolean) !!m.has_defense; 590. #undef nomore 591. } 592. 593. /* Perform a defensive action for a monster. Must be called immediately 594. * after find_defensive(). Return values are 0: did something, 1: died, 595. * 2: did something and can't attack again (i.e. teleported). 596. */ 597. int 598. use_defensive(mtmp) 599. struct monst *mtmp; 600. { 601. int i, fleetim, how = 0; 602. struct obj *otmp = m.defensive; 603. boolean vis, vismon, oseen; 604. const char *Mnam; 605. 606. if ((i = precheck(mtmp, otmp)) != 0) 607. return i; 608. vis = cansee(mtmp->mx, mtmp->my); 609. vismon = canseemon(mtmp); 610. oseen = otmp && vismon; 611. 612. /* when using defensive choice to run away, we want monster to avoid 613. rushing right straight back; don't override if already scared */ 614. fleetim = !mtmp->mflee ? (33 - (30 * mtmp->mhp / mtmp->mhpmax)) : 0; 615. #define m_flee(m) \ 616. if (fleetim && !m->iswiz) { \ 617. monflee(m, fleetim, FALSE, FALSE); \ 618. } 619. 620. switch (m.has_defense) { 621. case MUSE_UNICORN_HORN: 622. if (vismon) { 623. if (otmp) 624. pline("%s uses a unicorn horn!", Monnam(mtmp)); 625. else 626. pline_The("tip of %s's horn glows!", mon_nam(mtmp)); 627. } 628. if (!mtmp->mcansee) { 629. mcureblindness(mtmp, vismon); 630. } else if (mtmp->mconf || mtmp->mstun) { 631. mtmp->mconf = mtmp->mstun = 0; 632. if (vismon) 633. pline("%s seems steadier now.", Monnam(mtmp)); 634. } else 635. impossible("No need for unicorn horn?"); 636. return 2; 637. case MUSE_BUGLE: 638. if (vismon) 639. pline("%s plays %s!", Monnam(mtmp), doname(otmp)); 640. else if (!Deaf) 641. You_hear("a bugle playing reveille!"); 642. awaken_soldiers(mtmp); 643. return 2; 644. case MUSE_WAN_TELEPORTATION_SELF: 645. if ((mtmp->isshk && inhishop(mtmp)) || mtmp->isgd || mtmp->ispriest) 646. return 2; 647. m_flee(mtmp); 648. mzapmsg(mtmp, otmp, TRUE); 649. otmp->spe--; 650. how = WAN_TELEPORTATION; 651. mon_tele: 652. if (tele_restrict(mtmp)) { /* mysterious force... */ 653. if (vismon && how) /* mentions 'teleport' */ 654. makeknown(how); 655. /* monster learns that teleportation isn't useful here */ 656. if (level.flags.noteleport) 657. mtmp->mtrapseen |= (1 << (TELEP_TRAP - 1)); 658. return 2; 659. } 660. if ((mon_has_amulet(mtmp) || On_W_tower_level(&u.uz)) && !rn2(3)) { 661. if (vismon) 662. pline("%s seems disoriented for a moment.", Monnam(mtmp)); 663. return 2; 664. } 665. if (oseen && how) 666. makeknown(how); 667. (void) rloc(mtmp, TRUE); 668. return 2; 669. case MUSE_WAN_TELEPORTATION: 670. zap_oseen = oseen; 671. mzapmsg(mtmp, otmp, FALSE); 672. otmp->spe--; 673. m_using = TRUE; 674. mbhit(mtmp, rn1(8, 6), mbhitm, bhito, otmp); 675. /* monster learns that teleportation isn't useful here */ 676. if (level.flags.noteleport) 677. mtmp->mtrapseen |= (1 << (TELEP_TRAP - 1)); 678. m_using = FALSE; 679. return 2; 680. case MUSE_SCR_TELEPORTATION: { 681. int obj_is_cursed = otmp->cursed; 682. 683. if (mtmp->isshk || mtmp->isgd || mtmp->ispriest) 684. return 2; 685. m_flee(mtmp); 686. mreadmsg(mtmp, otmp); 687. m_useup(mtmp, otmp); /* otmp might be free'ed */ 688. how = SCR_TELEPORTATION; 689. if (obj_is_cursed || mtmp->mconf) { 690. int nlev; 691. d_level flev; 692. 693. if (mon_has_amulet(mtmp) || In_endgame(&u.uz)) { 694. if (vismon) 695. pline("%s seems very disoriented for a moment.", 696. Monnam(mtmp)); 697. return 2; 698. } 699. nlev = random_teleport_level(); 700. if (nlev == depth(&u.uz)) { 701. if (vismon) 702. pline("%s shudders for a moment.", Monnam(mtmp)); 703. return 2; 704. } 705. get_level(&flev, nlev); 706. migrate_to_level(mtmp, ledger_no(&flev), MIGR_RANDOM, 707. (coord *) 0); 708. if (oseen) 709. makeknown(SCR_TELEPORTATION); 710. } else 711. goto mon_tele; 712. return 2; 713. } 714. case MUSE_WAN_DIGGING: { 715. struct trap *ttmp; 716. 717. m_flee(mtmp); 718. mzapmsg(mtmp, otmp, FALSE); 719. otmp->spe--; 720. if (oseen) 721. makeknown(WAN_DIGGING); 722. if (IS_FURNITURE(levl[mtmp->mx][mtmp->my].typ) 723. || IS_DRAWBRIDGE(levl[mtmp->mx][mtmp->my].typ) 724. || (is_drawbridge_wall(mtmp->mx, mtmp->my) >= 0) 725. || (sstairs.sx && sstairs.sx == mtmp->mx 726. && sstairs.sy == mtmp->my)) { 727. pline_The("digging ray is ineffective."); 728. return 2; 729. } 730. if (!Can_dig_down(&u.uz) && !levl[mtmp->mx][mtmp->my].candig) { 731. if (canseemon(mtmp)) 732. pline_The("%s here is too hard to dig in.", 733. surface(mtmp->mx, mtmp->my)); 734. return 2; 735. } 736. ttmp = maketrap(mtmp->mx, mtmp->my, HOLE); 737. if (!ttmp) 738. return 2; 739. seetrap(ttmp); 740. if (vis) { 741. pline("%s has made a hole in the %s.", Monnam(mtmp), 742. surface(mtmp->mx, mtmp->my)); 743. pline("%s %s through...", Monnam(mtmp), 744. is_flyer(mtmp->data) ? "dives" : "falls"); 745. } else if (!Deaf) 746. You_hear("%s crash through the %s.", something, 747. surface(mtmp->mx, mtmp->my)); 748. /* we made sure that there is a level for mtmp to go to */ 749. migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_RANDOM, 750. (coord *) 0); 751. return 2; 752. } 753. case MUSE_WAN_CREATE_MONSTER: { 754. coord cc; 755. /* pm: 0 => random, eel => aquatic, croc => amphibious */ 756. struct permonst *pm = 757. !is_pool(mtmp->mx, mtmp->my) 758. ? 0 759. : &mons[u.uinwater ? PM_GIANT_EEL : PM_CROCODILE]; 760. struct monst *mon; 761. 762. if (!enexto(&cc, mtmp->mx, mtmp->my, pm)) 763. return 0; 764. mzapmsg(mtmp, otmp, FALSE); 765. otmp->spe--; 766. mon = makemon((struct permonst *) 0, cc.x, cc.y, NO_MM_FLAGS); 767. if (mon && canspotmon(mon) && oseen) 768. makeknown(WAN_CREATE_MONSTER); 769. return 2; 770. } 771. case MUSE_SCR_CREATE_MONSTER: { 772. coord cc; 773. struct permonst *pm = 0, *fish = 0; 774. int cnt = 1; 775. struct monst *mon; 776. boolean known = FALSE; 777. 778. if (!rn2(73)) 779. cnt += rnd(4); 780. if (mtmp->mconf || otmp->cursed) 781. cnt += 12; 782. if (mtmp->mconf) 783. pm = fish = &mons[PM_ACID_BLOB]; 784. else if (is_pool(mtmp->mx, mtmp->my)) 785. fish = &mons[u.uinwater ? PM_GIANT_EEL : PM_CROCODILE]; 786. mreadmsg(mtmp, otmp); 787. while (cnt--) { 788. /* `fish' potentially gives bias towards water locations; 789. `pm' is what to actually create (0 => random) */ 790. if (!enexto(&cc, mtmp->mx, mtmp->my, fish)) 791. break; 792. mon = makemon(pm, cc.x, cc.y, NO_MM_FLAGS); 793. if (mon && canspotmon(mon)) 794. known = TRUE; 795. } 796. /* The only case where we don't use oseen. For wands, you 797. * have to be able to see the monster zap the wand to know 798. * what type it is. For teleport scrolls, you have to see 799. * the monster to know it teleported. 800. */ 801. if (known) 802. makeknown(SCR_CREATE_MONSTER); 803. else if (!objects[SCR_CREATE_MONSTER].oc_name_known 804. && !objects[SCR_CREATE_MONSTER].oc_uname) 805. docall(otmp); 806. m_useup(mtmp, otmp); 807. return 2; 808. } 809. case MUSE_TRAPDOOR: 810. /* trap doors on "bottom" levels of dungeons are rock-drop 811. * trap doors, not holes in the floor. We check here for 812. * safety. 813. */ 814. if (Is_botlevel(&u.uz)) 815. return 0; 816. m_flee(mtmp); 817. if (vis) { 818. struct trap *t = t_at(trapx, trapy); 819. 820. Mnam = Monnam(mtmp); 821. pline("%s %s into a %s!", Mnam, 822. vtense(Mnam, locomotion(mtmp->data, "jump")), 823. (t->ttyp == TRAPDOOR) ? "trap door" : "hole"); 824. if (levl[trapx][trapy].typ == SCORR) { 825. levl[trapx][trapy].typ = CORR; 826. unblock_point(trapx, trapy); 827. } 828. seetrap(t_at(trapx, trapy)); 829. } 830. 831. /* don't use rloc_to() because worm tails must "move" */ 832. remove_monster(mtmp->mx, mtmp->my); 833. newsym(mtmp->mx, mtmp->my); /* update old location */ 834. place_monster(mtmp, trapx, trapy); 835. if (mtmp->wormno) 836. worm_move(mtmp); 837. newsym(trapx, trapy); 838. 839. migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_RANDOM, 840. (coord *) 0); 841. return 2; 842. case MUSE_UPSTAIRS: 843. m_flee(mtmp); 844. if (ledger_no(&u.uz) == 1) 845. goto escape; /* impossible; level 1 upstairs are SSTAIRS */ 846. if (Inhell && mon_has_amulet(mtmp) && !rn2(4) 847. && (dunlev(&u.uz) < dunlevs_in_dungeon(&u.uz) - 3)) { 848. if (vismon) 849. pline( 850. "As %s climbs the stairs, a mysterious force momentarily surrounds %s...", 851. mon_nam(mtmp), mhim(mtmp)); 852. /* simpler than for the player; this will usually be 853. the Wizard and he'll immediately go right to the 854. upstairs, so there's not much point in having any 855. chance for a random position on the current level */ 856. migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_RANDOM, 857. (coord *) 0); 858. } else { 859. if (vismon) 860. pline("%s escapes upstairs!", Monnam(mtmp)); 861. migrate_to_level(mtmp, ledger_no(&u.uz) - 1, MIGR_STAIRS_DOWN, 862. (coord *) 0); 863. } 864. return 2; 865. case MUSE_DOWNSTAIRS: 866. m_flee(mtmp); 867. if (vismon) 868. pline("%s escapes downstairs!", Monnam(mtmp)); 869. migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_STAIRS_UP, 870. (coord *) 0); 871. return 2; 872. case MUSE_UP_LADDER: 873. m_flee(mtmp); 874. if (vismon) 875. pline("%s escapes up the ladder!", Monnam(mtmp)); 876. migrate_to_level(mtmp, ledger_no(&u.uz) - 1, MIGR_LADDER_DOWN, 877. (coord *) 0); 878. return 2; 879. case MUSE_DN_LADDER: 880. m_flee(mtmp); 881. if (vismon) 882. pline("%s escapes down the ladder!", Monnam(mtmp)); 883. migrate_to_level(mtmp, ledger_no(&u.uz) + 1, MIGR_LADDER_UP, 884. (coord *) 0); 885. return 2; 886. case MUSE_SSTAIRS: 887. m_flee(mtmp); 888. if (ledger_no(&u.uz) == 1) { 889. escape: 890. /* Monsters without the Amulet escape the dungeon and 891. * are gone for good when they leave up the up stairs. 892. * A monster with the Amulet would leave it behind 893. * (mongone -> mdrop_special_objs) but we force any 894. * monster who manages to acquire it or the invocation 895. * tools to stick around instead of letting it escape. 896. */ 897. if (mon_has_special(mtmp)) 898. return 0; 899. if (vismon) 900. pline("%s escapes the dungeon!", Monnam(mtmp)); 901. mongone(mtmp); 902. return 2; 903. } 904. if (vismon) 905. pline("%s escapes %sstairs!", Monnam(mtmp), 906. sstairs.up ? "up" : "down"); 907. /* going from the Valley to Castle (Stronghold) has no sstairs 908. to target, but having sstairs.<sx,sy> == <0,0> will work the 909. same as specifying MIGR_RANDOM when mon_arrive() eventually 910. places the monster, so we can use MIGR_SSTAIRS unconditionally */ 911. migrate_to_level(mtmp, ledger_no(&sstairs.tolev), MIGR_SSTAIRS, 912. (coord *) 0); 913. return 2; 914. case MUSE_TELEPORT_TRAP: 915. m_flee(mtmp); 916. if (vis) { 917. Mnam = Monnam(mtmp); 918. pline("%s %s onto a teleport trap!", Mnam, 919. vtense(Mnam, locomotion(mtmp->data, "jump"))); 920. seetrap(t_at(trapx, trapy)); 921. } 922. /* don't use rloc_to() because worm tails must "move" */ 923. remove_monster(mtmp->mx, mtmp->my); 924. newsym(mtmp->mx, mtmp->my); /* update old location */ 925. place_monster(mtmp, trapx, trapy); 926. if (mtmp->wormno) 927. worm_move(mtmp); 928. newsym(trapx, trapy); 929. 930. goto mon_tele; 931. case MUSE_POT_HEALING: 932. mquaffmsg(mtmp, otmp); 933. i = d(6 + 2 * bcsign(otmp), 4); 934. mtmp->mhp += i; 935. if (mtmp->mhp > mtmp->mhpmax) 936. mtmp->mhp = ++mtmp->mhpmax; 937. if (!otmp->cursed && !mtmp->mcansee) 938. mcureblindness(mtmp, vismon); 939. if (vismon) 940. pline("%s looks better.", Monnam(mtmp)); 941. if (oseen) 942. makeknown(POT_HEALING); 943. m_useup(mtmp, otmp); 944. return 2; 945. case MUSE_POT_EXTRA_HEALING: 946. mquaffmsg(mtmp, otmp); 947. i = d(6 + 2 * bcsign(otmp), 8); 948. mtmp->mhp += i; 949. if (mtmp->mhp > mtmp->mhpmax) 950. mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 5 : 2)); 951. if (!mtmp->mcansee) 952. mcureblindness(mtmp, vismon); 953. if (vismon) 954. pline("%s looks much better.", Monnam(mtmp)); 955. if (oseen) 956. makeknown(POT_EXTRA_HEALING); 957. m_useup(mtmp, otmp); 958. return 2; 959. case MUSE_POT_FULL_HEALING: 960. mquaffmsg(mtmp, otmp); 961. if (otmp->otyp == POT_SICKNESS) 962. unbless(otmp); /* Pestilence */ 963. mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 8 : 4)); 964. if (!mtmp->mcansee && otmp->otyp != POT_SICKNESS) 965. mcureblindness(mtmp, vismon); 966. if (vismon) 967. pline("%s looks completely healed.", Monnam(mtmp)); 968. if (oseen) 969. makeknown(otmp->otyp); 970. m_useup(mtmp, otmp); 971. return 2; 972. case MUSE_LIZARD_CORPSE: 973. /* not actually called for its unstoning effect */ 974. mon_consume_unstone(mtmp, otmp, FALSE, FALSE); 975. return 2; 976. case 0: 977. return 0; /* i.e. an exploded wand */ 978. default: 979. impossible("%s wanted to perform action %d?", Monnam(mtmp), 980. m.has_defense); 981. break; 982. } 983. return 0; 984. #undef m_flee 985. } 986. 987. int 988. rnd_defensive_item(mtmp) 989. struct monst *mtmp; 990. { 991. struct permonst *pm = mtmp->data; 992. int difficulty = mons[(monsndx(pm))].difficulty; 993. int trycnt = 0; 994. 995. if (is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data) 996. || pm->mlet == S_GHOST || pm->mlet == S_KOP) 997. return 0; 998. try_again: 999. switch (rn2(8 + (difficulty > 3) + (difficulty > 6) + (difficulty > 8))) { 1000. case 6: 1001. case 9: 1002. if (level.flags.noteleport && ++trycnt < 2) 1003. goto try_again; 1004. if (!rn2(3)) 1005. return WAN_TELEPORTATION; 1006. /*FALLTHRU*/ 1007. case 0: 1008. case 1: 1009. return SCR_TELEPORTATION; 1010. case 8: 1011. case 10: 1012. if (!rn2(3)) 1013. return WAN_CREATE_MONSTER; 1014. /*FALLTHRU*/ 1015. case 2: 1016. return SCR_CREATE_MONSTER; 1017. case 3: 1018. return POT_HEALING; 1019. case 4: 1020. return POT_EXTRA_HEALING; 1021. case 5: 1022. return (mtmp->data != &mons[PM_PESTILENCE]) ? POT_FULL_HEALING 1023. : POT_SICKNESS; 1024. case 7: 1025. if (is_floater(pm) || mtmp->isshk || mtmp->isgd || mtmp->ispriest) 1026. return 0; 1027. else 1028. return WAN_DIGGING; 1029. } 1030. /*NOTREACHED*/ 1031. return 0; 1032. } 1033. 1034. #define MUSE_WAN_DEATH 1 1035. #define MUSE_WAN_SLEEP 2 1036. #define MUSE_WAN_FIRE 3 1037. #define MUSE_WAN_COLD 4 1038. #define MUSE_WAN_LIGHTNING 5 1039. #define MUSE_WAN_MAGIC_MISSILE 6 1040. #define MUSE_WAN_STRIKING 7 1041. #define MUSE_SCR_FIRE 8 1042. #define MUSE_POT_PARALYSIS 9 1043. #define MUSE_POT_BLINDNESS 10 1044. #define MUSE_POT_CONFUSION 11 1045. #define MUSE_FROST_HORN 12 1046. #define MUSE_FIRE_HORN 13 1047. #define MUSE_POT_ACID 14 1048. /*#define MUSE_WAN_TELEPORTATION 15*/ 1049. #define MUSE_POT_SLEEPING 16 1050. #define MUSE_SCR_EARTH 17 1051. 1052. /* Select an offensive item/action for a monster. Returns TRUE iff one is 1053. * found. 1054. */ 1055. boolean 1056. find_offensive(mtmp) 1057. struct monst *mtmp; 1058. { 1059. register struct obj *obj; 1060. boolean reflection_skip = (Reflecting && rn2(2)); 1061. struct obj *helmet = which_armor(mtmp, W_ARMH); 1062. 1063. m.offensive = (struct obj *) 0; 1064. m.has_offense = 0; 1065. if (mtmp->mpeaceful || is_animal(mtmp->data) || mindless(mtmp->data) 1066. || nohands(mtmp->data)) 1067. return FALSE; 1068. if (u.uswallow) 1069. return FALSE; 1070. if (in_your_sanctuary(mtmp, 0, 0)) 1071. return FALSE; 1072. if (dmgtype(mtmp->data, AD_HEAL) 1073. && !uwep && !uarmu && !uarm && !uarmh 1074. && !uarms && !uarmg && !uarmc && !uarmf) 1075. return FALSE; 1076. /* all offensive items require orthogonal or diagonal targetting */ 1077. if (!lined_up(mtmp)) 1078. return FALSE; 1079. 1080. #define nomore(x) if (m.has_offense == x) continue; 1081. /* this picks the last viable item rather than prioritizing choices */ 1082. for (obj = mtmp->minvent; obj; obj = obj->nobj) { 1083. if (!reflection_skip) { 1084. nomore(MUSE_WAN_DEATH); 1085. if (obj->otyp == WAN_DEATH && obj->spe > 0) { 1086. m.offensive = obj; 1087. m.has_offense = MUSE_WAN_DEATH; 1088. } 1089. nomore(MUSE_WAN_SLEEP); 1090. if (obj->otyp == WAN_SLEEP && obj->spe > 0 && multi >= 0) { 1091. m.offensive = obj; 1092. m.has_offense = MUSE_WAN_SLEEP; 1093. } 1094. nomore(MUSE_WAN_FIRE); 1095. if (obj->otyp == WAN_FIRE && obj->spe > 0) { 1096. m.offensive = obj; 1097. m.has_offense = MUSE_WAN_FIRE; 1098. } 1099. nomore(MUSE_FIRE_HORN); 1100. if (obj->otyp == FIRE_HORN && obj->spe > 0 && can_blow(mtmp)) { 1101. m.offensive = obj; 1102. m.has_offense = MUSE_FIRE_HORN; 1103. } 1104. nomore(MUSE_WAN_COLD); 1105. if (obj->otyp == WAN_COLD && obj->spe > 0) { 1106. m.offensive = obj; 1107. m.has_offense = MUSE_WAN_COLD; 1108. } 1109. nomore(MUSE_FROST_HORN); 1110. if (obj->otyp == FROST_HORN && obj->spe > 0 && can_blow(mtmp)) { 1111. m.offensive = obj; 1112. m.has_offense = MUSE_FROST_HORN; 1113. } 1114. nomore(MUSE_WAN_LIGHTNING); 1115. if (obj->otyp == WAN_LIGHTNING && obj->spe > 0) { 1116. m.offensive = obj; 1117. m.has_offense = MUSE_WAN_LIGHTNING; 1118. } 1119. nomore(MUSE_WAN_MAGIC_MISSILE); 1120. if (obj->otyp == WAN_MAGIC_MISSILE && obj->spe > 0) { 1121. m.offensive = obj; 1122. m.has_offense = MUSE_WAN_MAGIC_MISSILE; 1123. } 1124. } 1125. nomore(MUSE_WAN_STRIKING); 1126. if (obj->otyp == WAN_STRIKING && obj->spe > 0) { 1127. m.offensive = obj; 1128. m.has_offense = MUSE_WAN_STRIKING; 1129. } 1130. #if 0 /* use_offensive() has had some code to support wand of teleportation 1131. * for a long time, but find_offensive() never selected one; 1132. * so for the time being, this is still disabled */ 1133. nomore(MUSE_WAN_TELEPORTATION); 1134. if (obj->otyp == WAN_TELEPORTATION && obj->spe > 0 1135. /* don't give controlled hero a free teleport */ 1136. && !Teleport_control 1137. /* do try to move hero to a more vulnerable spot */ 1138. && (onscary(u.ux, u.uy, mtmp) 1139. || (u.ux == xupstair && u.uy == yupstair) 1140. || (u.ux == xdnstair && u.uy == ydnstair) 1141. || (u.ux == sstairs.sx && u.uy == sstairs.sy) 1142. || (u.ux == xupladder && u.uy == yupladder) 1143. || (u.ux == xdnladder && u.uy == ydnladder))) { 1144. m.offensive = obj; 1145. m.has_offense = MUSE_WAN_TELEPORTATION; 1146. } 1147. #endif 1148. nomore(MUSE_POT_PARALYSIS); 1149. if (obj->otyp == POT_PARALYSIS && multi >= 0) { 1150. m.offensive = obj; 1151. m.has_offense = MUSE_POT_PARALYSIS; 1152. } 1153. nomore(MUSE_POT_BLINDNESS); 1154. if (obj->otyp == POT_BLINDNESS && !attacktype(mtmp->data, AT_GAZE)) { 1155. m.offensive = obj; 1156. m.has_offense = MUSE_POT_BLINDNESS; 1157. } 1158. nomore(MUSE_POT_CONFUSION); 1159. if (obj->otyp == POT_CONFUSION) { 1160. m.offensive = obj; 1161. m.has_offense = MUSE_POT_CONFUSION; 1162. } 1163. nomore(MUSE_POT_SLEEPING); 1164. if (obj->otyp == POT_SLEEPING) { 1165. m.offensive = obj; 1166. m.has_offense = MUSE_POT_SLEEPING; 1167. } 1168. nomore(MUSE_POT_ACID); 1169. if (obj->otyp == POT_ACID) { 1170. m.offensive = obj; 1171. m.has_offense = MUSE_POT_ACID; 1172. } 1173. /* we can safely put this scroll here since the locations that 1174. * are in a 1 square radius are a subset of the locations that 1175. * are in wand or throwing range (in other words, always lined_up()) 1176. */ 1177. nomore(MUSE_SCR_EARTH); 1178. if (obj->otyp == SCR_EARTH 1179. && ((helmet && is_metallic(helmet)) || mtmp->mconf 1180. || amorphous(mtmp->data) || passes_walls(mtmp->data) 1181. || noncorporeal(mtmp->data) || unsolid(mtmp->data) 1182. || !rn2(10)) 1183. && dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 2 1184. && mtmp->mcansee && haseyes(mtmp->data) 1185. && !Is_rogue_level(&u.uz) 1186. && (!In_endgame(&u.uz) || Is_earthlevel(&u.uz))) { 1187. m.offensive = obj; 1188. m.has_offense = MUSE_SCR_EARTH; 1189. } 1190. #if 0 1191. nomore(MUSE_SCR_FIRE); 1192. if (obj->otyp == SCR_FIRE && resists_fire(mtmp) 1193. && dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 2 1194. && mtmp->mcansee && haseyes(mtmp->data)) { 1195. m.offensive = obj; 1196. m.has_offense = MUSE_SCR_FIRE; 1197. } 1198. #endif /* 0 */ 1199. } 1200. return (boolean) !!m.has_offense; 1201. #undef nomore 1202. } 1203. 1204. STATIC_PTR 1205. int 1206. mbhitm(mtmp, otmp) 1207. register struct monst *mtmp; 1208. register struct obj *otmp; 1209. { 1210. int tmp; 1211. boolean reveal_invis = FALSE; 1212. 1213. if (mtmp != &youmonst) { 1214. mtmp->msleeping = 0; 1215. if (mtmp->m_ap_type) 1216. seemimic(mtmp); 1217. } 1218. switch (otmp->otyp) { 1219. case WAN_STRIKING: 1220. reveal_invis = TRUE; 1221. if (mtmp == &youmonst) { 1222. if (zap_oseen) 1223. makeknown(WAN_STRIKING); 1224. if (Antimagic) { 1225. shieldeff(u.ux, u.uy); 1226. pline("Boing!"); 1227. } else if (rnd(20) < 10 + u.uac) { 1228. pline_The("wand hits you!"); 1229. tmp = d(2, 12); 1230. if (Half_spell_damage) 1231. tmp = (tmp + 1) / 2; 1232. losehp(tmp, "wand", KILLED_BY_AN); 1233. } else 1234. pline_The("wand misses you."); 1235. stop_occupation(); 1236. nomul(0); 1237. } else if (resists_magm(mtmp)) { 1238. shieldeff(mtmp->mx, mtmp->my); 1239. pline("Boing!"); 1240. } else if (rnd(20) < 10 + find_mac(mtmp)) { 1241. tmp = d(2, 12); 1242. hit("wand", mtmp, exclam(tmp)); 1243. (void) resist(mtmp, otmp->oclass, tmp, TELL); 1244. if (cansee(mtmp->mx, mtmp->my) && zap_oseen) 1245. makeknown(WAN_STRIKING); 1246. } else { 1247. miss("wand", mtmp); 1248. if (cansee(mtmp->mx, mtmp->my) && zap_oseen) 1249. makeknown(WAN_STRIKING); 1250. } 1251. break; 1252. #if 0 /* disabled because find_offensive() never picks WAN_TELEPORTATION */ 1253. case WAN_TELEPORTATION: 1254. if (mtmp == &youmonst) { 1255. if (zap_oseen) 1256. makeknown(WAN_TELEPORTATION); 1257. tele(); 1258. } else { 1259. /* for consistency with zap.c, don't identify */ 1260. if (mtmp->ispriest && *in_rooms(mtmp->mx, mtmp->my, TEMPLE)) { 1261. if (cansee(mtmp->mx, mtmp->my)) 1262. pline("%s resists the magic!", Monnam(mtmp)); 1263. } else if (!tele_restrict(mtmp)) 1264. (void) rloc(mtmp, TRUE); 1265. } 1266. break; 1267. #endif 1268. case WAN_CANCELLATION: 1269. case SPE_CANCELLATION: 1270. (void) cancel_monst(mtmp, otmp, FALSE, TRUE, FALSE); 1271. break; 1272. } 1273. if (reveal_invis) { 1274. if (!DEADMONSTER(mtmp) && cansee(bhitpos.x, bhitpos.y) 1275. && !canspotmon(mtmp)) 1276. map_invisible(bhitpos.x, bhitpos.y); 1277. } 1278. return 0; 1279. } 1280. 1281. /* A modified bhit() for monsters. Based on bhit() in zap.c. Unlike 1282. * buzz(), bhit() doesn't take into account the possibility of a monster 1283. * zapping you, so we need a special function for it. (Unless someone wants 1284. * to merge the two functions...) 1285. */ 1286. STATIC_OVL void 1287. mbhit(mon, range, fhitm, fhito, obj) 1288. struct monst *mon; /* monster shooting the wand */ 1289. register int range; /* direction and range */ 1290. int FDECL((*fhitm), (MONST_P, OBJ_P)); 1291. int FDECL((*fhito), (OBJ_P, OBJ_P)); /* fns called when mon/obj hit */ 1292. struct obj *obj; /* 2nd arg to fhitm/fhito */ 1293. { 1294. register struct monst *mtmp; 1295. register struct obj *otmp; 1296. register uchar typ; 1297. int ddx, ddy; 1298. 1299. bhitpos.x = mon->mx; 1300. bhitpos.y = mon->my; 1301. ddx = sgn(mon->mux - mon->mx); 1302. ddy = sgn(mon->muy - mon->my); 1303. 1304. while (range-- > 0) { 1305. int x, y; 1306. 1307. bhitpos.x += ddx; 1308. bhitpos.y += ddy; 1309. x = bhitpos.x; 1310. y = bhitpos.y; 1311. 1312. if (!isok(x, y)) { 1313. bhitpos.x -= ddx; 1314. bhitpos.y -= ddy; 1315. break; 1316. } 1317. if (find_drawbridge(&x, &y)) 1318. switch (obj->otyp) { 1319. case WAN_STRIKING: 1320. destroy_drawbridge(x, y); 1321. } 1322. if (bhitpos.x == u.ux && bhitpos.y == u.uy) { 1323. (*fhitm)(&youmonst, obj); 1324. range -= 3; 1325. } else if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) { 1326. if (cansee(bhitpos.x, bhitpos.y) && !canspotmon(mtmp)) 1327. map_invisible(bhitpos.x, bhitpos.y); 1328. (*fhitm)(mtmp, obj); 1329. range -= 3; 1330. } 1331. /* modified by GAN to hit all objects */ 1332. if (fhito) { 1333. int hitanything = 0; 1334. register struct obj *next_obj; 1335. 1336. for (otmp = level.objects[bhitpos.x][bhitpos.y]; otmp; 1337. otmp = next_obj) { 1338. /* Fix for polymorph bug, Tim Wright */ 1339. next_obj = otmp->nexthere; 1340. hitanything += (*fhito)(otmp, obj); 1341. } 1342. if (hitanything) 1343. range--; 1344. } 1345. typ = levl[bhitpos.x][bhitpos.y].typ; 1346. if (IS_DOOR(typ) || typ == SDOOR) { 1347. switch (obj->otyp) { 1348. /* note: monsters don't use opening or locking magic 1349. at present, but keep these as placeholders */ 1350. case WAN_OPENING: 1351. case WAN_LOCKING: 1352. case WAN_STRIKING: 1353. if (doorlock(obj, bhitpos.x, bhitpos.y)) { 1354. if (zap_oseen) 1355. makeknown(obj->otyp); 1356. /* if a shop door gets broken, add it to 1357. the shk's fix list (no cost to player) */ 1358. if (levl[bhitpos.x][bhitpos.y].doormask == D_BROKEN 1359. && *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE)) 1360. add_damage(bhitpos.x, bhitpos.y, 0L); 1361. } 1362. break; 1363. } 1364. } 1365. if (!ZAP_POS(typ) 1366. || (IS_DOOR(typ) && (levl[bhitpos.x][bhitpos.y].doormask 1367. & (D_LOCKED | D_CLOSED)))) { 1368. bhitpos.x -= ddx; 1369. bhitpos.y -= ddy; 1370. break; 1371. } 1372. } 1373. } 1374. 1375. /* Perform an offensive action for a monster. Must be called immediately 1376. * after find_offensive(). Return values are same as use_defensive(). 1377. */ 1378. int 1379. use_offensive(mtmp) 1380. struct monst *mtmp; 1381. { 1382. int i; 1383. struct obj *otmp = m.offensive; 1384. boolean oseen; 1385. 1386. /* offensive potions are not drunk, they're thrown */ 1387. if (otmp->oclass != POTION_CLASS && (i = precheck(mtmp, otmp)) != 0) 1388. return i; 1389. oseen = otmp && canseemon(mtmp); 1390. 1391. switch (m.has_offense) { 1392. case MUSE_WAN_DEATH: 1393. case MUSE_WAN_SLEEP: 1394. case MUSE_WAN_FIRE: 1395. case MUSE_WAN_COLD: 1396. case MUSE_WAN_LIGHTNING: 1397. case MUSE_WAN_MAGIC_MISSILE: 1398. mzapmsg(mtmp, otmp, FALSE); 1399. otmp->spe--; 1400. if (oseen) 1401. makeknown(otmp->otyp); 1402. m_using = TRUE; 1403. buzz((int) (-30 - (otmp->otyp - WAN_MAGIC_MISSILE)), 1404. (otmp->otyp == WAN_MAGIC_MISSILE) ? 2 : 6, mtmp->mx, mtmp->my, 1405. sgn(mtmp->mux - mtmp->mx), sgn(mtmp->muy - mtmp->my)); 1406. m_using = FALSE; 1407. return (DEADMONSTER(mtmp)) ? 1 : 2; 1408. case MUSE_FIRE_HORN: 1409. case MUSE_FROST_HORN: 1410. if (oseen) { 1411. makeknown(otmp->otyp); 1412. pline("%s plays a %s!", Monnam(mtmp), xname(otmp)); 1413. } else 1414. You_hear("a horn being played."); 1415. otmp->spe--; 1416. m_using = TRUE; 1417. buzz(-30 - ((otmp->otyp == FROST_HORN) ? AD_COLD - 1 : AD_FIRE - 1), 1418. rn1(6, 6), mtmp->mx, mtmp->my, sgn(mtmp->mux - mtmp->mx), 1419. sgn(mtmp->muy - mtmp->my)); 1420. m_using = FALSE; 1421. return (DEADMONSTER(mtmp)) ? 1 : 2; 1422. case MUSE_WAN_TELEPORTATION: 1423. case MUSE_WAN_STRIKING: 1424. zap_oseen = oseen; 1425. mzapmsg(mtmp, otmp, FALSE); 1426. otmp->spe--; 1427. m_using = TRUE; 1428. mbhit(mtmp, rn1(8, 6), mbhitm, bhito, otmp); 1429. m_using = FALSE; 1430. return 2; 1431. case MUSE_SCR_EARTH: { 1432. /* TODO: handle steeds */ 1433. register int x, y; 1434. /* don't use monster fields after killing it */ 1435. boolean confused = (mtmp->mconf ? TRUE : FALSE); 1436. int mmx = mtmp->mx, mmy = mtmp->my; 1437. boolean is_cursed = otmp->cursed; 1438. 1439. mreadmsg(mtmp, otmp); 1440. /* Identify the scroll */ 1441. if (canspotmon(mtmp)) { 1442. pline_The("%s rumbles %s %s!", ceiling(mtmp->mx, mtmp->my), 1443. otmp->blessed ? "around" : "above", mon_nam(mtmp)); 1444. if (oseen) 1445. makeknown(otmp->otyp); 1446. } else if (cansee(mtmp->mx, mtmp->my)) { 1447. pline_The("%s rumbles in the middle of nowhere!", 1448. ceiling(mtmp->mx, mtmp->my)); 1449. if (mtmp->minvis) 1450. map_invisible(mtmp->mx, mtmp->my); 1451. if (oseen) 1452. makeknown(otmp->otyp); 1453. } 1454. 1455. /* Loop through the surrounding squares */ 1456. for (x = mmx - 1; x <= mmx + 1; x++) { 1457. for (y = mmy - 1; y <= mmy + 1; y++) { 1458. /* Is this a suitable spot? */ 1459. if (isok(x, y) && !closed_door(x, y) 1460. && !IS_ROCK(levl[x][y].typ) && !IS_AIR(levl[x][y].typ) 1461. && (((x == mmx) && (y == mmy)) ? !otmp->blessed 1462. : !otmp->cursed) 1463. && (x != u.ux || y != u.uy)) { 1464. (void) drop_boulder_on_monster(x, y, confused, FALSE); 1465. } 1466. } 1467. } 1468. m_useup(mtmp, otmp); 1469. /* Attack the player */ 1470. if (distmin(mmx, mmy, u.ux, u.uy) == 1 && !is_cursed) { 1471. drop_boulder_on_player(confused, !is_cursed, FALSE, TRUE); 1472. } 1473. 1474. return (DEADMONSTER(mtmp)) ? 1 : 2; 1475. } 1476. #if 0 1477. case MUSE_SCR_FIRE: { 1478. boolean vis = cansee(mtmp->mx, mtmp->my); 1479. 1480. mreadmsg(mtmp, otmp); 1481. if (mtmp->mconf) { 1482. if (vis) 1483. pline("Oh, what a pretty fire!"); 1484. } else { 1485. struct monst *mtmp2; 1486. int num; 1487. 1488. if (vis) 1489. pline_The("scroll erupts in a tower of flame!"); 1490. shieldeff(mtmp->mx, mtmp->my); 1491. pline("%s is uninjured.", Monnam(mtmp)); 1492. (void) destroy_mitem(mtmp, SCROLL_CLASS, AD_FIRE); 1493. (void) destroy_mitem(mtmp, SPBOOK_CLASS, AD_FIRE); 1494. (void) destroy_mitem(mtmp, POTION_CLASS, AD_FIRE); 1495. num = (2 * (rn1(3, 3) + 2 * bcsign(otmp)) + 1) / 3; 1496. if (Fire_resistance) 1497. You("are not harmed."); 1498. burn_away_slime(); 1499. if (Half_spell_damage) 1500. num = (num + 1) / 2; 1501. else 1502. losehp(num, "scroll of fire", KILLED_BY_AN); 1503. for (mtmp2 = fmon; mtmp2; mtmp2 = mtmp2->nmon) { 1504. if (DEADMONSTER(mtmp2)) 1505. continue; 1506. if (mtmp == mtmp2) 1507. continue; 1508. if (dist2(mtmp2->mx, mtmp2->my, mtmp->mx, mtmp->my) < 3) { 1509. if (resists_fire(mtmp2)) 1510. continue; 1511. mtmp2->mhp -= num; 1512. if (resists_cold(mtmp2)) 1513. mtmp2->mhp -= 3 * num; 1514. if (DEADMONSTER(mtmp2)) { 1515. mondied(mtmp2); 1516. break; 1517. } 1518. } 1519. } 1520. } 1521. return 2; 1522. } 1523. #endif /* 0 */ 1524. case MUSE_POT_PARALYSIS: 1525. case MUSE_POT_BLINDNESS: 1526. case MUSE_POT_CONFUSION: 1527. case MUSE_POT_SLEEPING: 1528. case MUSE_POT_ACID: 1529. /* Note: this setting of dknown doesn't suffice. A monster 1530. * which is out of sight might throw and it hits something _in_ 1531. * sight, a problem not existing with wands because wand rays 1532. * are not objects. Also set dknown in mthrowu.c. 1533. */ 1534. if (cansee(mtmp->mx, mtmp->my)) { 1535. otmp->dknown = 1; 1536. pline("%s hurls %s!", Monnam(mtmp), singular(otmp, doname)); 1537. } 1538. m_throw(mtmp, mtmp->mx, mtmp->my, sgn(mtmp->mux - mtmp->mx), 1539. sgn(mtmp->muy - mtmp->my), 1540. distmin(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy), otmp); 1541. return 2; 1542. case 0: 1543. return 0; /* i.e. an exploded wand */ 1544. default: 1545. impossible("%s wanted to perform action %d?", Monnam(mtmp), 1546. m.has_offense); 1547. break; 1548. } 1549. return 0; 1550. } 1551. 1552. int 1553. rnd_offensive_item(mtmp) 1554. struct monst *mtmp; 1555. { 1556. struct permonst *pm = mtmp->data; 1557. int difficulty = mons[(monsndx(pm))].difficulty; 1558. 1559. if (is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data) 1560. || pm->mlet == S_GHOST || pm->mlet == S_KOP) 1561. return 0; 1562. if (difficulty > 7 && !rn2(35)) 1563. return WAN_DEATH; 1564. switch (rn2(9 - (difficulty < 4) + 4 * (difficulty > 6))) { 1565. case 0: { 1566. struct obj *helmet = which_armor(mtmp, W_ARMH); 1567. 1568. if ((helmet && is_metallic(helmet)) || amorphous(pm) 1569. || passes_walls(pm) || noncorporeal(pm) || unsolid(pm)) 1570. return SCR_EARTH; 1571. } /* fall through */ 1572. case 1: 1573. return WAN_STRIKING; 1574. case 2: 1575. return POT_ACID; 1576. case 3: 1577. return POT_CONFUSION; 1578. case 4: 1579. return POT_BLINDNESS; 1580. case 5: 1581. return POT_SLEEPING; 1582. case 6: 1583. return POT_PARALYSIS; 1584. case 7: 1585. case 8: 1586. return WAN_MAGIC_MISSILE; 1587. case 9: 1588. return WAN_SLEEP; 1589. case 10: 1590. return WAN_FIRE; 1591. case 11: 1592. return WAN_COLD; 1593. case 12: 1594. return WAN_LIGHTNING; 1595. } 1596. /*NOTREACHED*/ 1597. return 0; 1598. } 1599. 1600. #define MUSE_POT_GAIN_LEVEL 1 1601. #define MUSE_WAN_MAKE_INVISIBLE 2 1602. #define MUSE_POT_INVISIBILITY 3 1603. #define MUSE_POLY_TRAP 4 1604. #define MUSE_WAN_POLYMORPH 5 1605. #define MUSE_POT_SPEED 6 1606. #define MUSE_WAN_SPEED_MONSTER 7 1607. #define MUSE_BULLWHIP 8 1608. #define MUSE_POT_POLYMORPH 9 1609. 1610. boolean 1611. find_misc(mtmp) 1612. struct monst *mtmp; 1613. { 1614. register struct obj *obj; 1615. struct permonst *mdat = mtmp->data; 1616. int x = mtmp->mx, y = mtmp->my; 1617. struct trap *t; 1618. int xx, yy, pmidx = NON_PM; 1619. boolean immobile = (mdat->mmove == 0); 1620. boolean stuck = (mtmp == u.ustuck); 1621. 1622. m.misc = (struct obj *) 0; 1623. m.has_misc = 0; 1624. if (is_animal(mdat) || mindless(mdat)) 1625. return 0; 1626. if (u.uswallow && stuck) 1627. return FALSE; 1628. 1629. /* We arbitrarily limit to times when a player is nearby for the 1630. * same reason as Junior Pac-Man doesn't have energizers eaten until 1631. * you can see them... 1632. */ 1633. if (dist2(x, y, mtmp->mux, mtmp->muy) > 36) 1634. return FALSE; 1635. 1636. if (!stuck && !immobile && (mtmp->cham == NON_PM) 1637. && mons[(pmidx = monsndx(mdat))].difficulty < 6) { 1638. boolean ignore_boulders = (verysmall(mdat) || throws_rocks(mdat) 1639. || passes_walls(mdat)), 1640. diag_ok = !NODIAG(pmidx); 1641. 1642. for (xx = x - 1; xx <= x + 1; xx++) 1643. for (yy = y - 1; yy <= y + 1; yy++) 1644. if (isok(xx, yy) && (xx != u.ux || yy != u.uy) 1645. && (diag_ok || xx == x || yy == y) 1646. && ((xx == x && yy == y) || !level.monsters[xx][yy])) 1647. if ((t = t_at(xx, yy)) != 0 1648. && (ignore_boulders || !sobj_at(BOULDER, xx, yy)) 1649. && !onscary(xx, yy, mtmp)) { 1650. /* use trap if it's the correct type */ 1651. if (t->ttyp == POLY_TRAP) { 1652. trapx = xx; 1653. trapy = yy; 1654. m.has_misc = MUSE_POLY_TRAP; 1655. return TRUE; 1656. } 1657. } 1658. } 1659. if (nohands(mdat)) 1660. return 0; 1661. 1662. #define nomore(x) if (m.has_misc == x) continue 1663. /* 1664. * [bug?] Choice of item is not prioritized; the last viable one 1665. * in the monster's inventory will be chosen. 1666. * 'nomore()' is nearly worthless because it only screens checking 1667. * of duplicates when there is no alternate type in between them. 1668. */ 1669. for (obj = mtmp->minvent; obj; obj = obj->nobj) { 1670. /* Monsters shouldn't recognize cursed items; this kludge is 1671. necessary to prevent serious problems though... */ 1672. if (obj->otyp == POT_GAIN_LEVEL 1673. && (!obj->cursed 1674. || (!mtmp->isgd && !mtmp->isshk && !mtmp->ispriest))) { 1675. m.misc = obj; 1676. m.has_misc = MUSE_POT_GAIN_LEVEL; 1677. } 1678. nomore(MUSE_BULLWHIP); 1679. if (obj->otyp == BULLWHIP && !mtmp->mpeaceful 1680. /* the random test prevents whip-wielding 1681. monster from attempting disarm every turn */ 1682. && uwep && !rn2(5) && obj == MON_WEP(mtmp) 1683. /* hero's location must be known and adjacent */ 1684. && mtmp->mux == u.ux && mtmp->muy == u.uy 1685. && distu(mtmp->mx, mtmp->my) <= 2 1686. /* don't bother if it can't work (this doesn't 1687. prevent cursed weapons from being targetted) */ 1688. && (canletgo(uwep, "") 1689. || (u.twoweap && canletgo(uswapwep, "")))) { 1690. m.misc = obj; 1691. m.has_misc = MUSE_BULLWHIP; 1692. } 1693. /* Note: peaceful/tame monsters won't make themselves 1694. * invisible unless you can see them. Not really right, but... 1695. */ 1696. nomore(MUSE_WAN_MAKE_INVISIBLE); 1697. if (obj->otyp == WAN_MAKE_INVISIBLE && obj->spe > 0 && !mtmp->minvis 1698. && !mtmp->invis_blkd && (!mtmp->mpeaceful || See_invisible) 1699. && (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) { 1700. m.misc = obj; 1701. m.has_misc = MUSE_WAN_MAKE_INVISIBLE; 1702. } 1703. nomore(MUSE_POT_INVISIBILITY); 1704. if (obj->otyp == POT_INVISIBILITY && !mtmp->minvis 1705. && !mtmp->invis_blkd && (!mtmp->mpeaceful || See_invisible) 1706. && (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) { 1707. m.misc = obj; 1708. m.has_misc = MUSE_POT_INVISIBILITY; 1709. } 1710. nomore(MUSE_WAN_SPEED_MONSTER); 1711. if (obj->otyp == WAN_SPEED_MONSTER && obj->spe > 0 1712. && mtmp->mspeed != MFAST && !mtmp->isgd) { 1713. m.misc = obj; 1714. m.has_misc = MUSE_WAN_SPEED_MONSTER; 1715. } 1716. nomore(MUSE_POT_SPEED); 1717. if (obj->otyp == POT_SPEED && mtmp->mspeed != MFAST && !mtmp->isgd) { 1718. m.misc = obj; 1719. m.has_misc = MUSE_POT_SPEED; 1720. } 1721. nomore(MUSE_WAN_POLYMORPH); 1722. if (obj->otyp == WAN_POLYMORPH && obj->spe > 0 1723. && (mtmp->cham == NON_PM) && mons[monsndx(mdat)].difficulty < 6) { 1724. m.misc = obj; 1725. m.has_misc = MUSE_WAN_POLYMORPH; 1726. } 1727. nomore(MUSE_POT_POLYMORPH); 1728. if (obj->otyp == POT_POLYMORPH && (mtmp->cham == NON_PM) 1729. && mons[monsndx(mdat)].difficulty < 6) { 1730. m.misc = obj; 1731. m.has_misc = MUSE_POT_POLYMORPH; 1732. } 1733. } 1734. return (boolean) !!m.has_misc; 1735. #undef nomore 1736. } 1737. 1738. /* type of monster to polymorph into; defaults to one suitable for the 1739. current level rather than the totally arbitrary choice of newcham() */ 1740. static struct permonst * 1741. muse_newcham_mon(mon) 1742. struct monst *mon; 1743. { 1744. struct obj *m_armr; 1745. 1746. if ((m_armr = which_armor(mon, W_ARM)) != 0) { 1747. if (Is_dragon_scales(m_armr)) 1748. return Dragon_scales_to_pm(m_armr); 1749. else if (Is_dragon_mail(m_armr)) 1750. return Dragon_mail_to_pm(m_armr); 1751. } 1752. return rndmonst(); 1753. } 1754. 1755. int 1756. use_misc(mtmp) 1757. struct monst *mtmp; 1758. { 1759. int i; 1760. struct obj *otmp = m.misc; 1761. boolean vis, vismon, oseen; 1762. char nambuf[BUFSZ]; 1763. 1764. if ((i = precheck(mtmp, otmp)) != 0) 1765. return i; 1766. vis = cansee(mtmp->mx, mtmp->my); 1767. vismon = canseemon(mtmp); 1768. oseen = otmp && vismon; 1769. 1770. switch (m.has_misc) { 1771. case MUSE_POT_GAIN_LEVEL: 1772. mquaffmsg(mtmp, otmp); 1773. if (otmp->cursed) { 1774. if (Can_rise_up(mtmp->mx, mtmp->my, &u.uz)) { 1775. register int tolev = depth(&u.uz) - 1; 1776. d_level tolevel; 1777. 1778. get_level(&tolevel, tolev); 1779. /* insurance against future changes... */ 1780. if (on_level(&tolevel, &u.uz)) 1781. goto skipmsg; 1782. if (vismon) { 1783. pline("%s rises up, through the %s!", Monnam(mtmp), 1784. ceiling(mtmp->mx, mtmp->my)); 1785. if (!objects[POT_GAIN_LEVEL].oc_name_known 1786. && !objects[POT_GAIN_LEVEL].oc_uname) 1787. docall(otmp); 1788. } 1789. m_useup(mtmp, otmp); 1790. migrate_to_level(mtmp, ledger_no(&tolevel), MIGR_RANDOM, 1791. (coord *) 0); 1792. return 2; 1793. } else { 1794. skipmsg: 1795. if (vismon) { 1796. pline("%s looks uneasy.", Monnam(mtmp)); 1797. if (!objects[POT_GAIN_LEVEL].oc_name_known 1798. && !objects[POT_GAIN_LEVEL].oc_uname) 1799. docall(otmp); 1800. } 1801. m_useup(mtmp, otmp); 1802. return 2; 1803. } 1804. } 1805. if (vismon) 1806. pline("%s seems more experienced.", Monnam(mtmp)); 1807. if (oseen) 1808. makeknown(POT_GAIN_LEVEL); 1809. m_useup(mtmp, otmp); 1810. if (!grow_up(mtmp, (struct monst *) 0)) 1811. return 1; 1812. /* grew into genocided monster */ 1813. return 2; 1814. case MUSE_WAN_MAKE_INVISIBLE: 1815. case MUSE_POT_INVISIBILITY: 1816. if (otmp->otyp == WAN_MAKE_INVISIBLE) { 1817. mzapmsg(mtmp, otmp, TRUE); 1818. otmp->spe--; 1819. } else 1820. mquaffmsg(mtmp, otmp); 1821. /* format monster's name before altering its visibility */ 1822. Strcpy(nambuf, mon_nam(mtmp)); 1823. mon_set_minvis(mtmp); 1824. if (vismon && mtmp->minvis) { /* was seen, now invisible */ 1825. if (canspotmon(mtmp)) { 1826. pline("%s body takes on a %s transparency.", 1827. upstart(s_suffix(nambuf)), 1828. Hallucination ? "normal" : "strange"); 1829. } else { 1830. pline("Suddenly you cannot see %s.", nambuf); 1831. if (vis) 1832. map_invisible(mtmp->mx, mtmp->my); 1833. } 1834. if (oseen) 1835. makeknown(otmp->otyp); 1836. } 1837. if (otmp->otyp == POT_INVISIBILITY) { 1838. if (otmp->cursed) 1839. you_aggravate(mtmp); 1840. m_useup(mtmp, otmp); 1841. } 1842. return 2; 1843. case MUSE_WAN_SPEED_MONSTER: 1844. mzapmsg(mtmp, otmp, TRUE); 1845. otmp->spe--; 1846. mon_adjust_speed(mtmp, 1, otmp); 1847. return 2; 1848. case MUSE_POT_SPEED: 1849. mquaffmsg(mtmp, otmp); 1850. /* note difference in potion effect due to substantially 1851. different methods of maintaining speed ratings: 1852. player's character becomes "very fast" temporarily; 1853. monster becomes "one stage faster" permanently */ 1854. mon_adjust_speed(mtmp, 1, otmp); 1855. m_useup(mtmp, otmp); 1856. return 2; 1857. case MUSE_WAN_POLYMORPH: 1858. mzapmsg(mtmp, otmp, TRUE); 1859. otmp->spe--; 1860. (void) newcham(mtmp, muse_newcham_mon(mtmp), TRUE, FALSE); 1861. if (oseen) 1862. makeknown(WAN_POLYMORPH); 1863. return 2; 1864. case MUSE_POT_POLYMORPH: 1865. mquaffmsg(mtmp, otmp); 1866. if (vismon) 1867. pline("%s suddenly mutates!", Monnam(mtmp)); 1868. (void) newcham(mtmp, muse_newcham_mon(mtmp), FALSE, FALSE); 1869. if (oseen) 1870. makeknown(POT_POLYMORPH); 1871. m_useup(mtmp, otmp); 1872. return 2; 1873. case MUSE_POLY_TRAP: 1874. if (vismon) { 1875. const char *Mnam = Monnam(mtmp); 1876. 1877. pline("%s deliberately %s onto a polymorph trap!", Mnam, 1878. vtense(Mnam, locomotion(mtmp->data, "jump"))); 1879. } 1880. if (vis) 1881. seetrap(t_at(trapx, trapy)); 1882. 1883. /* don't use rloc() due to worms */ 1884. remove_monster(mtmp->mx, mtmp->my); 1885. newsym(mtmp->mx, mtmp->my); 1886. place_monster(mtmp, trapx, trapy); 1887. if (mtmp->wormno) 1888. worm_move(mtmp); 1889. newsym(trapx, trapy); 1890. 1891. (void) newcham(mtmp, (struct permonst *) 0, FALSE, FALSE); 1892. return 2; 1893. case MUSE_BULLWHIP: 1894. /* attempt to disarm hero */ 1895. { 1896. const char *The_whip = vismon ? "The bullwhip" : "A whip"; 1897. int where_to = rn2(4); 1898. struct obj *obj = uwep; 1899. const char *hand; 1900. char the_weapon[BUFSZ]; 1901. 1902. if (!obj || !canletgo(obj, "") 1903. || (u.twoweap && canletgo(uswapwep, "") && rn2(2))) 1904. obj = uswapwep; 1905. if (!obj) 1906. break; /* shouldn't happen after find_misc() */ 1907. 1908. Strcpy(the_weapon, the(xname(obj))); 1909. hand = body_part(HAND); 1910. if (bimanual(obj)) 1911. hand = makeplural(hand); 1912. 1913. if (vismon) 1914. pline("%s flicks a bullwhip towards your %s!", Monnam(mtmp), 1915. hand); 1916. if (obj->otyp == HEAVY_IRON_BALL) { 1917. pline("%s fails to wrap around %s.", The_whip, the_weapon); 1918. return 1; 1919. } 1920. pline("%s wraps around %s you're wielding!", The_whip, 1921. the_weapon); 1922. if (welded(obj)) { 1923. pline("%s welded to your %s%c", 1924. !is_plural(obj) ? "It is" : "They are", hand, 1925. !obj->bknown ? '!' : '.'); 1926. /* obj->bknown = 1; */ /* welded() takes care of this */ 1927. where_to = 0; 1928. } 1929. if (!where_to) { 1930. pline_The("whip slips free."); /* not `The_whip' */ 1931. return 1; 1932. } else if (where_to == 3 && mon_hates_silver(mtmp) 1933. && objects[obj->otyp].oc_material == SILVER) { 1934. /* this monster won't want to catch a silver 1935. weapon; drop it at hero's feet instead */ 1936. where_to = 2; 1937. } 1938. remove_worn_item(obj, FALSE); 1939. freeinv(obj); 1940. switch (where_to) { 1941. case 1: /* onto floor beneath mon */ 1942. pline("%s yanks %s from your %s!", Monnam(mtmp), the_weapon, 1943. hand); 1944. place_object(obj, mtmp->mx, mtmp->my); 1945. break; 1946. case 2: /* onto floor beneath you */ 1947. pline("%s yanks %s to the %s!", Monnam(mtmp), the_weapon, 1948. surface(u.ux, u.uy)); 1949. dropy(obj); 1950. break; 1951. case 3: /* into mon's inventory */ 1952. pline("%s snatches %s!", Monnam(mtmp), the_weapon); 1953. (void) mpickobj(mtmp, obj); 1954. break; 1955. } 1956. return 1; 1957. } 1958. return 0; 1959. case 0: 1960. return 0; /* i.e. an exploded wand */ 1961. default: 1962. impossible("%s wanted to perform action %d?", Monnam(mtmp), 1963. m.has_misc); 1964. break; 1965. } 1966. return 0; 1967. } 1968. 1969. STATIC_OVL void 1970. you_aggravate(mtmp) 1971. struct monst *mtmp; 1972. { 1973. pline("For some reason, %s presence is known to you.", 1974. s_suffix(noit_mon_nam(mtmp))); 1975. cls(); 1976. #ifdef CLIPPING 1977. cliparound(mtmp->mx, mtmp->my); 1978. #endif 1979. show_glyph(mtmp->mx, mtmp->my, mon_to_glyph(mtmp, rn2)); 1980. display_self(); 1981. You_feel("aggravated at %s.", noit_mon_nam(mtmp)); 1982. display_nhwindow(WIN_MAP, TRUE); 1983. docrt(); 1984. if (unconscious()) { 1985. multi = -1; 1986. nomovemsg = "Aggravated, you are jolted into full consciousness."; 1987. } 1988. newsym(mtmp->mx, mtmp->my); 1989. if (!canspotmon(mtmp)) 1990. map_invisible(mtmp->mx, mtmp->my); 1991. } 1992. 1993. int 1994. rnd_misc_item(mtmp) 1995. struct monst *mtmp; 1996. { 1997. struct permonst *pm = mtmp->data; 1998. int difficulty = mons[(monsndx(pm))].difficulty; 1999. 2000. if (is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data) 2001. || pm->mlet == S_GHOST || pm->mlet == S_KOP) 2002. return 0; 2003. /* Unlike other rnd_item functions, we only allow _weak_ monsters 2004. * to have this item; after all, the item will be used to strengthen 2005. * the monster and strong monsters won't use it at all... 2006. */ 2007. if (difficulty < 6 && !rn2(30)) 2008. return rn2(6) ? POT_POLYMORPH : WAN_POLYMORPH; 2009. 2010. if (!rn2(40) && !nonliving(pm) && !is_vampshifter(mtmp)) 2011. return AMULET_OF_LIFE_SAVING; 2012. 2013. switch (rn2(3)) { 2014. case 0: 2015. if (mtmp->isgd) 2016. return 0; 2017. return rn2(6) ? POT_SPEED : WAN_SPEED_MONSTER; 2018. case 1: 2019. if (mtmp->mpeaceful && !See_invisible) 2020. return 0; 2021. return rn2(6) ? POT_INVISIBILITY : WAN_MAKE_INVISIBLE; 2022. case 2: 2023. return POT_GAIN_LEVEL; 2024. } 2025. /*NOTREACHED*/ 2026. return 0; 2027. } 2028. 2029. boolean 2030. searches_for_item(mon, obj) 2031. struct monst *mon; 2032. struct obj *obj; 2033. { 2034. int typ = obj->otyp; 2035. 2036. if (is_animal(mon->data) || mindless(mon->data) 2037. || mon->data == &mons[PM_GHOST]) /* don't loot bones piles */ 2038. return FALSE; 2039. 2040. if (typ == WAN_MAKE_INVISIBLE || typ == POT_INVISIBILITY) 2041. return (boolean) (!mon->minvis && !mon->invis_blkd 2042. && !attacktype(mon->data, AT_GAZE)); 2043. if (typ == WAN_SPEED_MONSTER || typ == POT_SPEED) 2044. return (boolean) (mon->mspeed != MFAST); 2045. 2046. switch (obj->oclass) { 2047. case WAND_CLASS: 2048. if (obj->spe <= 0) 2049. return FALSE; 2050. if (typ == WAN_DIGGING) 2051. return (boolean) !is_floater(mon->data); 2052. if (typ == WAN_POLYMORPH) 2053. return (boolean) (mons[monsndx(mon->data)].difficulty < 6); 2054. if (objects[typ].oc_dir == RAY || typ == WAN_STRIKING 2055. || typ == WAN_TELEPORTATION || typ == WAN_CREATE_MONSTER) 2056. return TRUE; 2057. break; 2058. case POTION_CLASS: 2059. if (typ == POT_HEALING || typ == POT_EXTRA_HEALING 2060. || typ == POT_FULL_HEALING || typ == POT_POLYMORPH 2061. || typ == POT_GAIN_LEVEL || typ == POT_PARALYSIS 2062. || typ == POT_SLEEPING || typ == POT_ACID || typ == POT_CONFUSION) 2063. return TRUE; 2064. if (typ == POT_BLINDNESS && !attacktype(mon->data, AT_GAZE)) 2065. return TRUE; 2066. break; 2067. case SCROLL_CLASS: 2068. if (typ == SCR_TELEPORTATION || typ == SCR_CREATE_MONSTER 2069. || typ == SCR_EARTH || typ == SCR_FIRE) 2070. return TRUE; 2071. break; 2072. case AMULET_CLASS: 2073. if (typ == AMULET_OF_LIFE_SAVING) 2074. return (boolean) !(nonliving(mon->data) || is_vampshifter(mon)); 2075. if (typ == AMULET_OF_REFLECTION) 2076. return TRUE; 2077. break; 2078. case TOOL_CLASS: 2079. if (typ == PICK_AXE) 2080. return (boolean) needspick(mon->data); 2081. if (typ == UNICORN_HORN) 2082. return (boolean) (!obj->cursed && !is_unicorn(mon->data)); 2083. if (typ == FROST_HORN || typ == FIRE_HORN) 2084. return (obj->spe > 0 && can_blow(mon)); 2085. break; 2086. case FOOD_CLASS: 2087. if (typ == CORPSE) 2088. return (boolean) (((mon->misc_worn_check & W_ARMG) != 0L 2089. && touch_petrifies(&mons[obj->corpsenm])) 2090. || (!resists_ston(mon) 2091. && cures_stoning(mon, obj, FALSE))); 2092. if (typ == TIN) 2093. return (boolean) (mcould_eat_tin(mon) 2094. && (!resists_ston(mon) 2095. && cures_stoning(mon, obj, TRUE))); 2096. if (typ == EGG) 2097. return (boolean) touch_petrifies(&mons[obj->corpsenm]); 2098. break; 2099. default: 2100. break; 2101. } 2102. 2103. return FALSE; 2104. } 2105. 2106. boolean 2107. mon_reflects(mon, str) 2108. struct monst *mon; 2109. const char *str; 2110. { 2111. struct obj *orefl = which_armor(mon, W_ARMS); 2112. 2113. if (orefl && orefl->otyp == SHIELD_OF_REFLECTION) { 2114. if (str) { 2115. pline(str, s_suffix(mon_nam(mon)), "shield"); 2116. makeknown(SHIELD_OF_REFLECTION); 2117. } 2118. return TRUE; 2119. } else if (arti_reflects(MON_WEP(mon))) { 2120. /* due to wielded artifact weapon */ 2121. if (str) 2122. pline(str, s_suffix(mon_nam(mon)), "weapon"); 2123. return TRUE; 2124. } else if ((orefl = which_armor(mon, W_AMUL)) 2125. && orefl->otyp == AMULET_OF_REFLECTION) { 2126. if (str) { 2127. pline(str, s_suffix(mon_nam(mon)), "amulet"); 2128. makeknown(AMULET_OF_REFLECTION); 2129. } 2130. return TRUE; 2131. } else if ((orefl = which_armor(mon, W_ARM)) 2132. && (orefl->otyp == SILVER_DRAGON_SCALES 2133. || orefl->otyp == SILVER_DRAGON_SCALE_MAIL)) { 2134. if (str) 2135. pline(str, s_suffix(mon_nam(mon)), "armor"); 2136. return TRUE; 2137. } else if (mon->data == &mons[PM_SILVER_DRAGON] 2138. || mon->data == &mons[PM_CHROMATIC_DRAGON]) { 2139. /* Silver dragons only reflect when mature; babies do not */ 2140. if (str) 2141. pline(str, s_suffix(mon_nam(mon)), "scales"); 2142. return TRUE; 2143. } 2144. return FALSE; 2145. } 2146. 2147. boolean 2148. ureflects(fmt, str) 2149. const char *fmt, *str; 2150. { 2151. /* Check from outermost to innermost objects */ 2152. if (EReflecting & W_ARMS) { 2153. if (fmt && str) { 2154. pline(fmt, str, "shield"); 2155. makeknown(SHIELD_OF_REFLECTION); 2156. } 2157. return TRUE; 2158. } else if (EReflecting & W_WEP) { 2159. /* Due to wielded artifact weapon */ 2160. if (fmt && str) 2161. pline(fmt, str, "weapon"); 2162. return TRUE; 2163. } else if (EReflecting & W_AMUL) { 2164. if (fmt && str) { 2165. pline(fmt, str, "medallion"); 2166. makeknown(AMULET_OF_REFLECTION); 2167. } 2168. return TRUE; 2169. } else if (EReflecting & W_ARM) { 2170. if (fmt && str) 2171. pline(fmt, str, uskin ? "luster" : "armor"); 2172. return TRUE; 2173. } else if (youmonst.data == &mons[PM_SILVER_DRAGON]) { 2174. if (fmt && str) 2175. pline(fmt, str, "scales"); 2176. return TRUE; 2177. } 2178. return FALSE; 2179. } 2180. 2181. /* cure mon's blindness (use_defensive, dog_eat, meatobj) */ 2182. void 2183. mcureblindness(mon, verbos) 2184. struct monst *mon; 2185. boolean verbos; 2186. { 2187. if (!mon->mcansee) { 2188. mon->mcansee = 1; 2189. mon->mblinded = 0; 2190. if (verbos && haseyes(mon->data)) 2191. pline("%s can see again.", Monnam(mon)); 2192. } 2193. } 2194. 2195. /* TRUE if the monster ate something */ 2196. boolean 2197. munstone(mon, by_you) 2198. struct monst *mon; 2199. boolean by_you; 2200. { 2201. struct obj *obj; 2202. boolean tinok; 2203. 2204. if (resists_ston(mon)) 2205. return FALSE; 2206. if (mon->meating || !mon->mcanmove || mon->msleeping) 2207. return FALSE; 2208. mon->mstrategy &= ~STRAT_WAITFORU; 2209. 2210. tinok = mcould_eat_tin(mon); 2211. for (obj = mon->minvent; obj; obj = obj->nobj) { 2212. if (cures_stoning(mon, obj, tinok)) { 2213. mon_consume_unstone(mon, obj, by_you, TRUE); 2214. return TRUE; 2215. } 2216. } 2217. return FALSE; 2218. } 2219. 2220. STATIC_OVL void 2221. mon_consume_unstone(mon, obj, by_you, stoning) 2222. struct monst *mon; 2223. struct obj *obj; 2224. boolean by_you; 2225. boolean stoning; /* True: stop petrification, False: cure stun && confusion */ 2226. { 2227. boolean vis = canseemon(mon), tinned = obj->otyp == TIN, 2228. food = obj->otyp == CORPSE || tinned, 2229. acid = obj->otyp == POT_ACID 2230. || (food && acidic(&mons[obj->corpsenm])), 2231. lizard = food && obj->corpsenm == PM_LIZARD; 2232. int nutrit = food ? dog_nutrition(mon, obj) : 0; /* also sets meating */ 2233. 2234. /* give a "<mon> is slowing down" message and also remove 2235. intrinsic speed (comparable to similar effect on the hero) */ 2236. if (stoning) 2237. mon_adjust_speed(mon, -3, (struct obj *) 0); 2238. 2239. if (vis) { 2240. long save_quan = obj->quan; 2241. 2242. obj->quan = 1L; 2243. pline("%s %s %s.", Monnam(mon), 2244. (obj->oclass == POTION_CLASS) 2245. ? "quaffs" 2246. : (obj->otyp == TIN) ? "opens and eats the contents of" 2247. : "eats", 2248. distant_name(obj, doname)); 2249. obj->quan = save_quan; 2250. } else if (!Deaf) 2251. You_hear("%s.", 2252. (obj->oclass == POTION_CLASS) ? "drinking" : "chewing"); 2253. 2254. m_useup(mon, obj); 2255. /* obj is now gone */ 2256. 2257. if (acid && !tinned && !resists_acid(mon)) { 2258. mon->mhp -= rnd(15); 2259. if (vis) 2260. pline("%s has a very bad case of stomach acid.", Monnam(mon)); 2261. if (DEADMONSTER(mon)) { 2262. pline("%s dies!", Monnam(mon)); 2263. if (by_you) 2264. /* hero gets credit (experience) and blame (possible loss 2265. of alignment and/or luck and/or telepathy depending on 2266. mon) for the kill but does not break pacifism conduct */ 2267. xkilled(mon, XKILL_NOMSG | XKILL_NOCONDUCT); 2268. else 2269. mondead(mon); 2270. return; 2271. } 2272. } 2273. if (stoning && vis) { 2274. if (Hallucination) 2275. pline("What a pity - %s just ruined a future piece of art!", 2276. mon_nam(mon)); 2277. else 2278. pline("%s seems limber!", Monnam(mon)); 2279. } 2280. if (lizard && (mon->mconf || mon->mstun)) { 2281. mon->mconf = 0; 2282. mon->mstun = 0; 2283. if (vis && !is_bat(mon->data) && mon->data != &mons[PM_STALKER]) 2284. pline("%s seems steadier now.", Monnam(mon)); 2285. } 2286. if (mon->mtame && !mon->isminion && nutrit > 0) { 2287. struct edog *edog = EDOG(mon); 2288. 2289. if (edog->hungrytime < monstermoves) 2290. edog->hungrytime = monstermoves; 2291. edog->hungrytime += nutrit; 2292. mon->mconf = 0; 2293. } 2294. /* use up monster's next move */ 2295. mon->movement -= NORMAL_SPEED; 2296. mon->mlstmv = monstermoves; 2297. } 2298. 2299. /* decide whether obj can cure petrification; also used when picking up */ 2300. STATIC_OVL boolean 2301. cures_stoning(mon, obj, tinok) 2302. struct monst *mon; 2303. struct obj *obj; 2304. boolean tinok; 2305. { 2306. if (obj->otyp == POT_ACID) 2307. return TRUE; 2308. if (obj->otyp != CORPSE && (obj->otyp != TIN || !tinok)) 2309. return FALSE; 2310. /* corpse, or tin that mon can open */ 2311. return (boolean) (obj->corpsenm == PM_LIZARD 2312. || (acidic(&mons[obj->corpsenm]) 2313. && (obj->corpsenm != PM_GREEN_SLIME 2314. || slimeproof(mon->data)))); 2315. } 2316. 2317. STATIC_OVL boolean 2318. mcould_eat_tin(mon) 2319. struct monst *mon; 2320. { 2321. struct obj *obj, *mwep; 2322. boolean welded_wep; 2323. 2324. /* monkeys who manage to steal tins can't open and eat them 2325. even if they happen to also have the appropriate tool */ 2326. if (is_animal(mon->data)) 2327. return FALSE; 2328. 2329. mwep = MON_WEP(mon); 2330. welded_wep = mwep && mwelded(mwep); 2331. /* this is different from the player; tin opener or dagger doesn't 2332. have to be wielded, and knife can be used instead of dagger */ 2333. for (obj = mon->minvent; obj; obj = obj->nobj) { 2334. /* if stuck with a cursed weapon, don't check rest of inventory */ 2335. if (welded_wep && obj != mwep) 2336. continue; 2337. 2338. if (obj->otyp == TIN_OPENER 2339. || (obj->oclass == WEAPON_CLASS 2340. && (objects[obj->otyp].oc_skill == P_DAGGER 2341. || objects[obj->otyp].oc_skill == P_KNIFE))) 2342. return TRUE; 2343. } 2344. return FALSE; 2345. } 2346. 2347. /* TRUE if monster does something to avoid turning into green slime */ 2348. boolean 2349. munslime(mon, by_you) 2350. struct monst *mon; 2351. boolean by_you; 2352. { 2353. struct obj *obj, odummy; 2354. struct permonst *mptr = mon->data; 2355. 2356. /* 2357. * muse_unslime() gives "mon starts turning green", "mon zaps 2358. * itself with a wand of fire", and "mon's slime burns away" 2359. * messages. Monsters who don't get any chance at that just have 2360. * (via our caller) newcham()'s "mon turns into slime" feedback. 2361. */ 2362. 2363. if (slimeproof(mptr)) 2364. return FALSE; 2365. if (mon->meating || !mon->mcanmove || mon->msleeping) 2366. return FALSE; 2367. mon->mstrategy &= ~STRAT_WAITFORU; 2368. 2369. /* if monster can breathe fire, do so upon self; a monster who deals 2370. fire damage by biting, clawing, gazing, and especially exploding 2371. isn't able to cure itself of green slime with its own attack 2372. [possible extension: monst capable of casting high level clerical 2373. spells could toss pillar of fire at self--probably too suicidal] */ 2374. if (!mon->mcan && !mon->mspec_used 2375. && attacktype_fordmg(mptr, AT_BREA, AD_FIRE)) { 2376. odummy = zeroobj; /* otyp == STRANGE_OBJECT */ 2377. return muse_unslime(mon, &odummy, (struct trap *) 0, by_you); 2378. } 2379. 2380. /* same MUSE criteria as use_defensive() */ 2381. if (!is_animal(mptr) && !mindless(mptr)) { 2382. struct trap *t; 2383. 2384. for (obj = mon->minvent; obj; obj = obj->nobj) 2385. if (cures_sliming(mon, obj)) 2386. return muse_unslime(mon, obj, (struct trap *) 0, by_you); 2387. 2388. if (((t = t_at(mon->mx, mon->my)) == 0 || t->ttyp != FIRE_TRAP) 2389. && mptr->mmove && !mon->mtrapped) { 2390. int xy[2][8], x, y, idx, ridx, nxy = 0; 2391. 2392. for (x = mon->mx - 1; x <= mon->mx + 1; ++x) 2393. for (y = mon->my - 1; y <= mon->my + 1; ++y) 2394. if (isok(x, y) && accessible(x, y) 2395. && !m_at(x, y) && (x != u.ux || y != u.uy)) { 2396. xy[0][nxy] = x, xy[1][nxy] = y; 2397. ++nxy; 2398. } 2399. for (idx = 0; idx < nxy; ++idx) { 2400. ridx = rn1(nxy - idx, idx); 2401. if (ridx != idx) { 2402. x = xy[0][idx]; 2403. xy[0][idx] = xy[0][ridx]; 2404. xy[0][ridx] = x; 2405. y = xy[1][idx]; 2406. xy[1][idx] = xy[1][ridx]; 2407. xy[1][ridx] = y; 2408. } 2409. if ((t = t_at(xy[0][idx], xy[1][idx])) != 0 2410. && t->ttyp == FIRE_TRAP) 2411. break; 2412. } 2413. } 2414. if (t && t->ttyp == FIRE_TRAP) 2415. return muse_unslime(mon, (struct obj *) &zeroobj, t, by_you); 2416. 2417. } /* MUSE */ 2418. 2419. return FALSE; 2420. } 2421. 2422. /* mon uses an item--selected by caller--to burn away incipient slime */ 2423. STATIC_OVL boolean 2424. muse_unslime(mon, obj, trap, by_you) 2425. struct monst *mon; 2426. struct obj *obj; 2427. struct trap *trap; 2428. boolean by_you; /* true: if mon kills itself, hero gets credit/blame */ 2429. { /* [by_you not honored if 'mon' triggers fire trap]. */ 2430. struct obj *odummyp; 2431. int otyp = obj->otyp, dmg = 0; 2432. boolean vis = canseemon(mon), res = TRUE; 2433. 2434. if (vis) 2435. pline("%s starts turning %s.", Monnam(mon), 2436. green_mon(mon) ? "into ooze" : hcolor(NH_GREEN)); 2437. /* -4 => sliming, causes quiet loss of enhanced speed */ 2438. mon_adjust_speed(mon, -4, (struct obj *) 0); 2439. 2440. if (trap) { 2441. const char *Mnam = vis ? Monnam(mon) : 0; 2442. 2443. if (mon->mx == trap->tx && mon->my == trap->ty) { 2444. if (vis) 2445. pline("%s triggers %s fire trap!", Mnam, 2446. trap->tseen ? "the" : "a"); 2447. } else { 2448. remove_monster(mon->mx, mon->my); 2449. newsym(mon->mx, mon->my); 2450. place_monster(mon, trap->tx, trap->ty); 2451. if (mon->wormno) /* won't happen; worms don't MUSE to unslime */ 2452. worm_move(mon); 2453. newsym(mon->mx, mon->my); 2454. if (vis) 2455. pline("%s %s %s %s fire trap!", Mnam, 2456. vtense(Mnam, locomotion(mon->data, "move")), 2457. is_floater(mon->data) ? "over" : "onto", 2458. trap->tseen ? "the" : "a"); 2459. } 2460. /* hack to avoid mintrap()'s chance of avoiding known trap */ 2461. mon->mtrapseen &= ~(1 << (FIRE_TRAP - 1)); 2462. mintrap(mon); 2463. } else if (otyp == STRANGE_OBJECT) { 2464. /* monster is using fire breath on self */ 2465. if (vis) 2466. pline("%s breathes fire on %sself.", Monnam(mon), mhim(mon)); 2467. if (!rn2(3)) 2468. mon->mspec_used = rn1(10, 5); 2469. /* -21 => monster's fire breath; 1 => # of damage dice */ 2470. dmg = zhitm(mon, by_you ? 21 : -21, 1, &odummyp); 2471. } else if (otyp == SCR_FIRE) { 2472. mreadmsg(mon, obj); 2473. if (mon->mconf) { 2474. if (cansee(mon->mx, mon->my)) 2475. pline("Oh, what a pretty fire!"); 2476. if (vis && !objects[otyp].oc_name_known 2477. && !objects[otyp].oc_uname) 2478. docall(obj); 2479. m_useup(mon, obj); /* after docall() */ 2480. vis = FALSE; /* skip makeknown() below */ 2481. res = FALSE; /* failed to cure sliming */ 2482. } else { 2483. m_useup(mon, obj); /* before explode() */ 2484. dmg = (2 * (rn1(3, 3) + 2 * bcsign(obj)) + 1) / 3; 2485. /* -11 => monster's fireball */ 2486. explode(mon->mx, mon->my, -11, dmg, SCROLL_CLASS, 2487. /* by_you: override -11 for mon but not others */ 2488. by_you ? -EXPL_FIERY : EXPL_FIERY); 2489. dmg = 0; /* damage has been applied by explode() */ 2490. } 2491. } else { /* wand/horn of fire w/ positive charge count */ 2492. mzapmsg(mon, obj, TRUE); 2493. obj->spe--; 2494. /* -1 => monster's wand of fire; 2 => # of damage dice */ 2495. dmg = zhitm(mon, by_you ? 1 : -1, 2, &odummyp); 2496. } 2497. 2498. if (dmg) { 2499. /* zhitm() applies damage but doesn't kill creature off; 2500. for fire breath, dmg is going to be 0 (fire breathers are 2501. immune to fire damage) but for wand of fire or fire horn, 2502. 'mon' could have taken damage so might die */ 2503. if (DEADMONSTER(mon)) { 2504. if (by_you) { 2505. /* mon killed self but hero gets credit and blame (except 2506. for pacifist conduct); xkilled()'s message would say 2507. "You killed/destroyed <mon>" so give our own message */ 2508. if (vis) 2509. pline("%s is %s by the fire!", Monnam(mon), 2510. nonliving(mon->data) ? "destroyed" : "killed"); 2511. xkilled(mon, XKILL_NOMSG | XKILL_NOCONDUCT); 2512. } else 2513. monkilled(mon, "fire", AD_FIRE); 2514. } else { 2515. /* non-fatal damage occurred */ 2516. if (vis) 2517. pline("%s is burned%s", Monnam(mon), exclam(dmg)); 2518. } 2519. } 2520. if (vis) { 2521. if (res && !DEADMONSTER(mon)) 2522. pline("%s slime is burned away!", s_suffix(Monnam(mon))); 2523. if (otyp != STRANGE_OBJECT) 2524. makeknown(otyp); 2525. } 2526. /* use up monster's next move */ 2527. mon->movement -= NORMAL_SPEED; 2528. mon->mlstmv = monstermoves; 2529. return res; 2530. } 2531. 2532. /* decide whether obj can be used to cure green slime */ 2533. STATIC_OVL int 2534. cures_sliming(mon, obj) 2535. struct monst *mon; 2536. struct obj *obj; 2537. { 2538. /* scroll of fire, non-empty wand or horn of fire */ 2539. if (obj->otyp == SCR_FIRE) 2540. return (haseyes(mon->data) && mon->mcansee); 2541. /* hero doesn't need hands or even limbs to zap, so mon doesn't either */ 2542. return ((obj->otyp == WAN_FIRE 2543. || (obj->otyp == FIRE_HORN && can_blow(mon))) 2544. && obj->spe > 0); 2545. } 2546. 2547. /* TRUE if monster appears to be green; for active TEXTCOLOR, we go by 2548. the display color, otherwise we just pick things that seem plausibly 2549. green (which doesn't necessarily match the TEXTCOLOR categorization) */ 2550. STATIC_OVL boolean 2551. green_mon(mon) 2552. struct monst *mon; 2553. { 2554. struct permonst *ptr = mon->data; 2555. 2556. if (Hallucination) 2557. return FALSE; 2558. #ifdef TEXTCOLOR 2559. if (iflags.use_color) 2560. return (ptr->mcolor == CLR_GREEN || ptr->mcolor == CLR_BRIGHT_GREEN); 2561. #endif 2562. /* approximation */ 2563. if (strstri(ptr->mname, "green")) 2564. return TRUE; 2565. switch (monsndx(ptr)) { 2566. case PM_FOREST_CENTAUR: 2567. case PM_GARTER_SNAKE: 2568. case PM_GECKO: 2569. case PM_GREMLIN: 2570. case PM_HOMUNCULUS: 2571. case PM_JUIBLEX: 2572. case PM_LEPRECHAUN: 2573. case PM_LICHEN: 2574. case PM_LIZARD: 2575. case PM_WOOD_NYMPH: 2576. return TRUE; 2577. default: 2578. if (is_elf(ptr) && !is_prince(ptr) && !is_lord(ptr) 2579. && ptr != &mons[PM_GREY_ELF]) 2580. return TRUE; 2581. break; 2582. } 2583. return FALSE; 2584. } 2585. 2586. /*muse.c*/