Source:NetHack 3.6.2/src/zap.c
Jump to navigation
Jump to search
Below is the full text to zap.c from the source code of NetHack 3.6.2. To link to a particular line, write [[Source:NetHack 3.6.2/src/zap.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 zap.c $NHDT-Date: 1551395521 2019/02/28 23:12:01 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.307 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Robert Patrick Rankin, 2013. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #include "hack.h" 7. 8. /* Disintegration rays have special treatment; corpses are never left. 9. * But the routine which calculates the damage is separate from the routine 10. * which kills the monster. The damage routine returns this cookie to 11. * indicate that the monster should be disintegrated. 12. */ 13. #define MAGIC_COOKIE 1000 14. 15. static NEARDATA boolean obj_zapped; 16. static NEARDATA int poly_zapped; 17. 18. extern boolean notonhead; /* for long worms */ 19. 20. /* kludge to use mondied instead of killed */ 21. extern boolean m_using; 22. 23. STATIC_DCL void FDECL(polyuse, (struct obj *, int, int)); 24. STATIC_DCL void FDECL(create_polymon, (struct obj *, int)); 25. STATIC_DCL int FDECL(stone_to_flesh_obj, (struct obj *)); 26. STATIC_DCL boolean FDECL(zap_updown, (struct obj *)); 27. STATIC_DCL void FDECL(zhitu, (int, int, const char *, XCHAR_P, XCHAR_P)); 28. STATIC_DCL void FDECL(revive_egg, (struct obj *)); 29. STATIC_DCL boolean FDECL(zap_steed, (struct obj *)); 30. STATIC_DCL void FDECL(skiprange, (int, int *, int *)); 31. STATIC_DCL int FDECL(zap_hit, (int, int)); 32. STATIC_OVL void FDECL(disintegrate_mon, (struct monst *, int, const char *)); 33. STATIC_DCL void FDECL(backfire, (struct obj *)); 34. STATIC_DCL int FDECL(spell_hit_bonus, (int)); 35. STATIC_DCL void FDECL(destroy_one_item, (struct obj *, int, int)); 36. STATIC_DCL void FDECL(wishcmdassist, (int)); 37. 38. #define ZT_MAGIC_MISSILE (AD_MAGM - 1) 39. #define ZT_FIRE (AD_FIRE - 1) 40. #define ZT_COLD (AD_COLD - 1) 41. #define ZT_SLEEP (AD_SLEE - 1) 42. #define ZT_DEATH (AD_DISN - 1) /* or disintegration */ 43. #define ZT_LIGHTNING (AD_ELEC - 1) 44. #define ZT_POISON_GAS (AD_DRST - 1) 45. #define ZT_ACID (AD_ACID - 1) 46. /* 8 and 9 are currently unassigned */ 47. 48. #define ZT_WAND(x) (x) 49. #define ZT_SPELL(x) (10 + (x)) 50. #define ZT_BREATH(x) (20 + (x)) 51. 52. #define is_hero_spell(type) ((type) >= 10 && (type) < 20) 53. 54. #define M_IN_WATER(ptr) \ 55. ((ptr)->mlet == S_EEL || amphibious(ptr) || is_swimmer(ptr)) 56. 57. STATIC_VAR const char are_blinded_by_the_flash[] = 58. "are blinded by the flash!"; 59. 60. const char *const flash_types[] = /* also used in buzzmu(mcastu.c) */ 61. { 62. "magic missile", /* Wands must be 0-9 */ 63. "bolt of fire", "bolt of cold", "sleep ray", "death ray", 64. "bolt of lightning", "", "", "", "", 65. 66. "magic missile", /* Spell equivalents must be 10-19 */ 67. "fireball", "cone of cold", "sleep ray", "finger of death", 68. "bolt of lightning", /* there is no spell, used for retribution */ 69. "", "", "", "", 70. 71. "blast of missiles", /* Dragon breath equivalents 20-29*/ 72. "blast of fire", "blast of frost", "blast of sleep gas", 73. "blast of disintegration", "blast of lightning", 74. "blast of poison gas", "blast of acid", "", "" 75. }; 76. 77. /* 78. * Recognizing unseen wands by zapping: in 3.4.3 and earlier, zapping 79. * most wand types while blind would add that type to the discoveries 80. * list even if it had never been seen (ie, picked up while blinded 81. * and shown in inventory as simply "a wand"). This behavior has been 82. * changed; now such wands won't be discovered. But if the type is 83. * already discovered, then the individual wand whose effect was just 84. * observed will be flagged as if seen. [You already know wands of 85. * striking; you zap "a wand" and observe striking effect (presumably 86. * by sound or touch); it'll become shown in inventory as "a wand of 87. * striking".] 88. * 89. * Unfortunately, the new behavior isn't really correct either. There 90. * should be an `eknown' bit for "effect known" added for wands (and 91. * for potions since quaffing one of a stack is similar) so that the 92. * particular wand which has been zapped would have its type become 93. * known (it would change from "a wand" to "a wand of striking", for 94. * example) without the type becoming discovered or other unknown wands 95. * of that type showing additional information. When blindness ends, 96. * all objects in inventory with the eknown bit set would be discovered 97. * and other items of the same type would become known as such. 98. */ 99. 100. /* wand discovery gets special handling when hero is blinded */ 101. void 102. learnwand(obj) 103. struct obj *obj; 104. { 105. /* For a wand (or wand-like tool) zapped by the player, if the 106. effect was observable (determined by caller; usually seen, but 107. possibly heard or felt if the hero is blinded) then discover the 108. object type provided that the object itself is known (as more 109. than just "a wand"). If object type is already discovered and 110. we observed the effect, mark the individual wand as having been 111. seen. Suppress spells (which use fake spellbook object for `obj') 112. so that casting a spell won't re-discover its forgotten book. */ 113. if (obj->oclass != SPBOOK_CLASS) { 114. /* if type already discovered, treat this item has having been seen 115. even if hero is currently blinded (skips redundant makeknown) */ 116. if (objects[obj->otyp].oc_name_known) { 117. obj->dknown = 1; /* will usually be set already */ 118. 119. /* otherwise discover it if item itself has been or can be seen */ 120. } else { 121. /* in case it was picked up while blind and then zapped without 122. examining inventory after regaining sight (bypassing xname) */ 123. if (!Blind) 124. obj->dknown = 1; 125. /* make the discovery iff we know what we're manipulating */ 126. if (obj->dknown) 127. makeknown(obj->otyp); 128. } 129. } 130. } 131. 132. /* Routines for IMMEDIATE wands and spells. */ 133. /* bhitm: monster mtmp was hit by the effect of wand or spell otmp */ 134. int 135. bhitm(mtmp, otmp) 136. struct monst *mtmp; 137. struct obj *otmp; 138. { 139. boolean wake = TRUE; /* Most 'zaps' should wake monster */ 140. boolean reveal_invis = FALSE, learn_it = FALSE; 141. boolean dbldam = Role_if(PM_KNIGHT) && u.uhave.questart; 142. boolean skilled_spell, helpful_gesture = FALSE; 143. int dmg, otyp = otmp->otyp; 144. const char *zap_type_text = "spell"; 145. struct obj *obj; 146. boolean disguised_mimic = (mtmp->data->mlet == S_MIMIC 147. && M_AP_TYPE(mtmp) != M_AP_NOTHING); 148. 149. if (u.uswallow && mtmp == u.ustuck) 150. reveal_invis = FALSE; 151. 152. notonhead = (mtmp->mx != bhitpos.x || mtmp->my != bhitpos.y); 153. skilled_spell = (otmp && otmp->oclass == SPBOOK_CLASS && otmp->blessed); 154. 155. switch (otyp) { 156. case WAN_STRIKING: 157. zap_type_text = "wand"; 158. /*FALLTHRU*/ 159. case SPE_FORCE_BOLT: 160. reveal_invis = TRUE; 161. if (disguised_mimic) 162. seemimic(mtmp); 163. if (resists_magm(mtmp)) { /* match effect on player */ 164. shieldeff(mtmp->mx, mtmp->my); 165. pline("Boing!"); 166. break; /* skip makeknown */ 167. } else if (u.uswallow || rnd(20) < 10 + find_mac(mtmp)) { 168. dmg = d(2, 12); 169. if (dbldam) 170. dmg *= 2; 171. if (otyp == SPE_FORCE_BOLT) 172. dmg = spell_damage_bonus(dmg); 173. hit(zap_type_text, mtmp, exclam(dmg)); 174. (void) resist(mtmp, otmp->oclass, dmg, TELL); 175. } else 176. miss(zap_type_text, mtmp); 177. learn_it = TRUE; 178. break; 179. case WAN_SLOW_MONSTER: 180. case SPE_SLOW_MONSTER: 181. if (!resist(mtmp, otmp->oclass, 0, NOTELL)) { 182. if (disguised_mimic) 183. seemimic(mtmp); 184. mon_adjust_speed(mtmp, -1, otmp); 185. m_dowear(mtmp, FALSE); /* might want speed boots */ 186. if (u.uswallow && (mtmp == u.ustuck) && is_whirly(mtmp->data)) { 187. You("disrupt %s!", mon_nam(mtmp)); 188. pline("A huge hole opens up..."); 189. expels(mtmp, mtmp->data, TRUE); 190. } 191. } 192. break; 193. case WAN_SPEED_MONSTER: 194. if (!resist(mtmp, otmp->oclass, 0, NOTELL)) { 195. if (disguised_mimic) 196. seemimic(mtmp); 197. mon_adjust_speed(mtmp, 1, otmp); 198. m_dowear(mtmp, FALSE); /* might want speed boots */ 199. } 200. if (mtmp->mtame) 201. helpful_gesture = TRUE; 202. break; 203. case WAN_UNDEAD_TURNING: 204. case SPE_TURN_UNDEAD: 205. wake = FALSE; 206. if (unturn_dead(mtmp)) 207. wake = TRUE; 208. if (is_undead(mtmp->data) || is_vampshifter(mtmp)) { 209. reveal_invis = TRUE; 210. wake = TRUE; 211. dmg = rnd(8); 212. if (dbldam) 213. dmg *= 2; 214. if (otyp == SPE_TURN_UNDEAD) 215. dmg = spell_damage_bonus(dmg); 216. context.bypasses = TRUE; /* for make_corpse() */ 217. if (!resist(mtmp, otmp->oclass, dmg, NOTELL)) { 218. if (!DEADMONSTER(mtmp)) 219. monflee(mtmp, 0, FALSE, TRUE); 220. } 221. } 222. break; 223. case WAN_POLYMORPH: 224. case SPE_POLYMORPH: 225. case POT_POLYMORPH: 226. if (mtmp->data == &mons[PM_LONG_WORM] && has_mcorpsenm(mtmp)) { 227. /* if a long worm has mcorpsenm set, it was polymophed by 228. the current zap and shouldn't be affected if hit again */ 229. ; 230. } else if (resists_magm(mtmp)) { 231. /* magic resistance protects from polymorph traps, so make 232. it guard against involuntary polymorph attacks too... */ 233. shieldeff(mtmp->mx, mtmp->my); 234. } else if (!resist(mtmp, otmp->oclass, 0, NOTELL)) { 235. boolean polyspot = (otyp != POT_POLYMORPH), 236. give_msg = (!Hallucination 237. && (canseemon(mtmp) 238. || (u.uswallow && mtmp == u.ustuck))); 239. 240. /* dropped inventory (due to death by system shock, 241. or loss of wielded weapon and/or worn armor due to 242. limitations of new shape) won't be hit by this zap */ 243. if (polyspot) 244. for (obj = mtmp->minvent; obj; obj = obj->nobj) 245. bypass_obj(obj); 246. 247. /* natural shapechangers aren't affected by system shock 248. (unless protection from shapechangers is interfering 249. with their metabolism...) */ 250. if (mtmp->cham == NON_PM && !rn2(25)) { 251. if (canseemon(mtmp)) { 252. pline("%s shudders!", Monnam(mtmp)); 253. learn_it = TRUE; 254. } 255. /* context.bypasses = TRUE; ## for make_corpse() */ 256. /* no corpse after system shock */ 257. xkilled(mtmp, XKILL_GIVEMSG | XKILL_NOCORPSE); 258. } else if (newcham(mtmp, (struct permonst *) 0, 259. polyspot, give_msg) != 0 260. /* if shapechange failed because there aren't 261. enough eligible candidates (most likely for 262. vampshifter), try reverting to original form */ 263. || (mtmp->cham >= LOW_PM 264. && newcham(mtmp, &mons[mtmp->cham], 265. polyspot, give_msg) != 0)) { 266. if (give_msg && (canspotmon(mtmp) 267. || (u.uswallow && mtmp == u.ustuck))) 268. learn_it = TRUE; 269. } 270. 271. /* do this even if polymorphed failed (otherwise using 272. flags.mon_polycontrol prompting to force mtmp to remain 273. 'long worm' would prompt again if zap hit another segment) */ 274. if (!DEADMONSTER(mtmp) && mtmp->data == &mons[PM_LONG_WORM]) { 275. if (!has_mcorpsenm(mtmp)) 276. newmcorpsenm(mtmp); 277. /* flag to indicate that mtmp became a long worm 278. on current zap, so further hits (on mtmp's new 279. tail) don't do further transforms */ 280. MCORPSENM(mtmp) = PM_LONG_WORM; 281. /* flag to indicate that cleanup is needed; object 282. bypass cleanup also clears mon->mextra->mcorpsenm 283. for all long worms on the level */ 284. context.bypasses = TRUE; 285. } 286. } 287. break; 288. case WAN_CANCELLATION: 289. case SPE_CANCELLATION: 290. if (disguised_mimic) 291. seemimic(mtmp); 292. (void) cancel_monst(mtmp, otmp, TRUE, TRUE, FALSE); 293. break; 294. case WAN_TELEPORTATION: 295. case SPE_TELEPORT_AWAY: 296. if (disguised_mimic) 297. seemimic(mtmp); 298. reveal_invis = !u_teleport_mon(mtmp, TRUE); 299. break; 300. case WAN_MAKE_INVISIBLE: { 301. int oldinvis = mtmp->minvis; 302. char nambuf[BUFSZ]; 303. 304. if (disguised_mimic) 305. seemimic(mtmp); 306. /* format monster's name before altering its visibility */ 307. Strcpy(nambuf, Monnam(mtmp)); 308. mon_set_minvis(mtmp); 309. if (!oldinvis && knowninvisible(mtmp)) { 310. pline("%s turns transparent!", nambuf); 311. reveal_invis = TRUE; 312. learn_it = TRUE; 313. } 314. break; 315. } 316. case WAN_LOCKING: 317. case SPE_WIZARD_LOCK: 318. wake = closeholdingtrap(mtmp, &learn_it); 319. break; 320. case WAN_PROBING: 321. wake = FALSE; 322. reveal_invis = TRUE; 323. probe_monster(mtmp); 324. learn_it = TRUE; 325. break; 326. case WAN_OPENING: 327. case SPE_KNOCK: 328. wake = FALSE; /* don't want immediate counterattack */ 329. if (u.uswallow && mtmp == u.ustuck) { 330. if (is_animal(mtmp->data)) { 331. if (Blind) 332. You_feel("a sudden rush of air!"); 333. else 334. pline("%s opens its mouth!", Monnam(mtmp)); 335. } 336. expels(mtmp, mtmp->data, TRUE); 337. /* zap which hits steed will only release saddle if it 338. doesn't hit a holding or falling trap; playability 339. here overrides the more logical target ordering */ 340. } else if (openholdingtrap(mtmp, &learn_it)) { 341. break; 342. } else if (openfallingtrap(mtmp, TRUE, &learn_it)) { 343. /* mtmp might now be on the migrating monsters list */ 344. break; 345. } else if ((obj = which_armor(mtmp, W_SADDLE)) != 0) { 346. char buf[BUFSZ]; 347. 348. Sprintf(buf, "%s %s", s_suffix(Monnam(mtmp)), 349. distant_name(obj, xname)); 350. if (cansee(mtmp->mx, mtmp->my)) { 351. if (!canspotmon(mtmp)) 352. Strcpy(buf, An(distant_name(obj, xname))); 353. pline("%s falls to the %s.", buf, 354. surface(mtmp->mx, mtmp->my)); 355. } else if (canspotmon(mtmp)) { 356. pline("%s falls off.", buf); 357. } 358. obj_extract_self(obj); 359. mdrop_obj(mtmp, obj, FALSE); 360. } 361. break; 362. case SPE_HEALING: 363. case SPE_EXTRA_HEALING: 364. reveal_invis = TRUE; 365. if (mtmp->data != &mons[PM_PESTILENCE]) { 366. wake = FALSE; /* wakeup() makes the target angry */ 367. mtmp->mhp += d(6, otyp == SPE_EXTRA_HEALING ? 8 : 4); 368. if (mtmp->mhp > mtmp->mhpmax) 369. mtmp->mhp = mtmp->mhpmax; 370. /* plain healing must be blessed to cure blindness; extra 371. healing only needs to not be cursed, so spell always cures 372. [potions quaffed by monsters behave slightly differently; 373. we use the rules for the hero here...] */ 374. if (skilled_spell || otyp == SPE_EXTRA_HEALING) 375. mcureblindness(mtmp, canseemon(mtmp)); 376. if (canseemon(mtmp)) { 377. if (disguised_mimic) { 378. if (is_obj_mappear(mtmp,STRANGE_OBJECT)) { 379. /* it can do better now */ 380. set_mimic_sym(mtmp); 381. newsym(mtmp->mx, mtmp->my); 382. } else 383. mimic_hit_msg(mtmp, otyp); 384. } else 385. pline("%s looks%s better.", Monnam(mtmp), 386. otyp == SPE_EXTRA_HEALING ? " much" : ""); 387. } 388. if (mtmp->mtame || mtmp->mpeaceful) { 389. adjalign(Role_if(PM_HEALER) ? 1 : sgn(u.ualign.type)); 390. } 391. } else { /* Pestilence */ 392. /* Pestilence will always resist; damage is half of 3d{4,8} */ 393. (void) resist(mtmp, otmp->oclass, 394. d(3, otyp == SPE_EXTRA_HEALING ? 8 : 4), TELL); 395. } 396. break; 397. case WAN_LIGHT: /* (broken wand) */ 398. if (flash_hits_mon(mtmp, otmp)) { 399. learn_it = TRUE; 400. reveal_invis = TRUE; 401. } 402. break; 403. case WAN_SLEEP: /* (broken wand) */ 404. /* [wakeup() doesn't rouse victims of temporary sleep, 405. so it's okay to leave `wake' set to TRUE here] */ 406. reveal_invis = TRUE; 407. if (sleep_monst(mtmp, d(1 + otmp->spe, 12), WAND_CLASS)) 408. slept_monst(mtmp); 409. if (!Blind) 410. learn_it = TRUE; 411. break; 412. case SPE_STONE_TO_FLESH: 413. if (monsndx(mtmp->data) == PM_STONE_GOLEM) { 414. char *name = Monnam(mtmp); 415. 416. /* turn into flesh golem */ 417. if (newcham(mtmp, &mons[PM_FLESH_GOLEM], FALSE, FALSE)) { 418. if (canseemon(mtmp)) 419. pline("%s turns to flesh!", name); 420. } else { 421. if (canseemon(mtmp)) 422. pline("%s looks rather fleshy for a moment.", name); 423. } 424. } else 425. wake = FALSE; 426. break; 427. case SPE_DRAIN_LIFE: 428. if (disguised_mimic) 429. seemimic(mtmp); 430. dmg = monhp_per_lvl(mtmp); 431. if (dbldam) 432. dmg *= 2; 433. if (otyp == SPE_DRAIN_LIFE) 434. dmg = spell_damage_bonus(dmg); 435. if (resists_drli(mtmp)) { 436. shieldeff(mtmp->mx, mtmp->my); 437. } else if (!resist(mtmp, otmp->oclass, dmg, NOTELL) 438. && !DEADMONSTER(mtmp)) { 439. mtmp->mhp -= dmg; 440. mtmp->mhpmax -= dmg; 441. /* die if already level 0, regardless of hit points */ 442. if (DEADMONSTER(mtmp) || mtmp->mhpmax <= 0 || mtmp->m_lev < 1) { 443. killed(mtmp); 444. } else { 445. mtmp->m_lev--; 446. if (canseemon(mtmp)) 447. pline("%s suddenly seems weaker!", Monnam(mtmp)); 448. } 449. } 450. break; 451. case WAN_NOTHING: 452. wake = FALSE; 453. break; 454. default: 455. impossible("What an interesting effect (%d)", otyp); 456. break; 457. } 458. if (wake) { 459. if (!DEADMONSTER(mtmp)) { 460. wakeup(mtmp, helpful_gesture ? FALSE : TRUE); 461. m_respond(mtmp); 462. if (mtmp->isshk && !*u.ushops) 463. hot_pursuit(mtmp); 464. } else if (M_AP_TYPE(mtmp)) 465. seemimic(mtmp); /* might unblock if mimicing a boulder/door */ 466. } 467. /* note: bhitpos won't be set if swallowed, but that's okay since 468. * reveal_invis will be false. We can't use mtmp->mx, my since it 469. * might be an invisible worm hit on the tail. 470. */ 471. if (reveal_invis) { 472. if (!DEADMONSTER(mtmp) && cansee(bhitpos.x, bhitpos.y) 473. && !canspotmon(mtmp)) 474. map_invisible(bhitpos.x, bhitpos.y); 475. } 476. /* if effect was observable then discover the wand type provided 477. that the wand itself has been seen */ 478. if (learn_it) 479. learnwand(otmp); 480. return 0; 481. } 482. 483. void 484. probe_monster(mtmp) 485. struct monst *mtmp; 486. { 487. struct obj *otmp; 488. 489. mstatusline(mtmp); 490. if (notonhead) 491. return; /* don't show minvent for long worm tail */ 492. 493. if (mtmp->minvent) { 494. for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) { 495. otmp->dknown = 1; /* treat as "seen" */ 496. if (Is_container(otmp) || otmp->otyp == STATUE) { 497. otmp->lknown = 1; 498. if (!SchroedingersBox(otmp)) 499. otmp->cknown = 1; 500. } 501. } 502. (void) display_minventory(mtmp, MINV_ALL | MINV_NOLET | PICK_NONE, 503. (char *) 0); 504. } else { 505. pline("%s is not carrying anything%s.", noit_Monnam(mtmp), 506. (u.uswallow && mtmp == u.ustuck) ? " besides you" : ""); 507. } 508. } 509. 510. /* 511. * Return the object's physical location. This only makes sense for 512. * objects that are currently on the level (i.e. migrating objects 513. * are nowhere). By default, only things that can be seen (in hero's 514. * inventory, monster's inventory, or on the ground) are reported. 515. * By adding BURIED_TOO and/or CONTAINED_TOO flags, you can also get 516. * the location of buried and contained objects. Note that if an 517. * object is carried by a monster, its reported position may change 518. * from turn to turn. This function returns FALSE if the position 519. * is not available or subject to the constraints above. 520. */ 521. boolean 522. get_obj_location(obj, xp, yp, locflags) 523. struct obj *obj; 524. xchar *xp, *yp; 525. int locflags; 526. { 527. switch (obj->where) { 528. case OBJ_INVENT: 529. *xp = u.ux; 530. *yp = u.uy; 531. return TRUE; 532. case OBJ_FLOOR: 533. *xp = obj->ox; 534. *yp = obj->oy; 535. return TRUE; 536. case OBJ_MINVENT: 537. if (obj->ocarry->mx) { 538. *xp = obj->ocarry->mx; 539. *yp = obj->ocarry->my; 540. return TRUE; 541. } 542. break; /* !mx => migrating monster */ 543. case OBJ_BURIED: 544. if (locflags & BURIED_TOO) { 545. *xp = obj->ox; 546. *yp = obj->oy; 547. return TRUE; 548. } 549. break; 550. case OBJ_CONTAINED: 551. if (locflags & CONTAINED_TOO) 552. return get_obj_location(obj->ocontainer, xp, yp, locflags); 553. break; 554. } 555. *xp = *yp = 0; 556. return FALSE; 557. } 558. 559. boolean 560. get_mon_location(mon, xp, yp, locflags) 561. struct monst *mon; 562. xchar *xp, *yp; 563. int locflags; /* non-zero means get location even if monster is buried */ 564. { 565. if (mon == &youmonst) { 566. *xp = u.ux; 567. *yp = u.uy; 568. return TRUE; 569. } else if (mon->mx > 0 && (!mon->mburied || locflags)) { 570. *xp = mon->mx; 571. *yp = mon->my; 572. return TRUE; 573. } else { /* migrating or buried */ 574. *xp = *yp = 0; 575. return FALSE; 576. } 577. } 578. 579. /* used by revive() and animate_statue() */ 580. struct monst * 581. montraits(obj, cc, adjacentok) 582. struct obj *obj; 583. coord *cc; 584. boolean adjacentok; /* False: at obj's spot only, True: nearby is allowed */ 585. { 586. struct monst *mtmp = (struct monst *) 0; 587. struct monst *mtmp2 = (struct monst *) 0; 588. 589. if (has_omonst(obj)) 590. mtmp2 = get_mtraits(obj, TRUE); 591. if (mtmp2) { 592. /* save_mtraits() validated mtmp2->mnum */ 593. mtmp2->data = &mons[mtmp2->mnum]; 594. if (mtmp2->mhpmax <= 0 && !is_rider(mtmp2->data)) 595. return (struct monst *) 0; 596. mtmp = makemon(mtmp2->data, cc->x, cc->y, 597. (NO_MINVENT | MM_NOWAIT | MM_NOCOUNTBIRTH 598. | (adjacentok ? MM_ADJACENTOK : 0))); 599. if (!mtmp) 600. return mtmp; 601. 602. /* heal the monster */ 603. if (mtmp->mhpmax > mtmp2->mhpmax && is_rider(mtmp2->data)) 604. mtmp2->mhpmax = mtmp->mhpmax; 605. mtmp2->mhp = mtmp2->mhpmax; 606. /* Get these ones from mtmp */ 607. mtmp2->minvent = mtmp->minvent; /*redundant*/ 608. /* monster ID is available if the monster died in the current 609. game, but will be zero if the corpse was in a bones level 610. (we cleared it when loading bones) */ 611. if (mtmp->m_id) { 612. mtmp2->m_id = mtmp->m_id; 613. /* might be bringing quest leader back to life */ 614. if (quest_status.leader_is_dead 615. /* leader_is_dead implies leader_m_id is valid */ 616. && mtmp2->m_id == quest_status.leader_m_id) 617. quest_status.leader_is_dead = FALSE; 618. } 619. mtmp2->mx = mtmp->mx; 620. mtmp2->my = mtmp->my; 621. mtmp2->mux = mtmp->mux; 622. mtmp2->muy = mtmp->muy; 623. mtmp2->mw = mtmp->mw; 624. mtmp2->wormno = mtmp->wormno; 625. mtmp2->misc_worn_check = mtmp->misc_worn_check; 626. mtmp2->weapon_check = mtmp->weapon_check; 627. mtmp2->mtrapseen = mtmp->mtrapseen; 628. mtmp2->mflee = mtmp->mflee; 629. mtmp2->mburied = mtmp->mburied; 630. mtmp2->mundetected = mtmp->mundetected; 631. mtmp2->mfleetim = mtmp->mfleetim; 632. mtmp2->mlstmv = mtmp->mlstmv; 633. mtmp2->m_ap_type = mtmp->m_ap_type; 634. /* set these ones explicitly */ 635. mtmp2->mrevived = 1; 636. mtmp2->mavenge = 0; 637. mtmp2->meating = 0; 638. mtmp2->mleashed = 0; 639. mtmp2->mtrapped = 0; 640. mtmp2->msleeping = 0; 641. mtmp2->mfrozen = 0; 642. mtmp2->mcanmove = 1; 643. /* most cancelled monsters return to normal, 644. but some need to stay cancelled */ 645. if (!dmgtype(mtmp2->data, AD_SEDU) 646. && (!SYSOPT_SEDUCE || !dmgtype(mtmp2->data, AD_SSEX))) 647. mtmp2->mcan = 0; 648. mtmp2->mcansee = 1; /* set like in makemon */ 649. mtmp2->mblinded = 0; 650. mtmp2->mstun = 0; 651. mtmp2->mconf = 0; 652. /* when traits are for a shopeekper, dummy monster 'mtmp' won't 653. have necessary eshk data for replmon() -> replshk() */ 654. if (mtmp2->isshk) { 655. neweshk(mtmp); 656. *ESHK(mtmp) = *ESHK(mtmp2); 657. if (ESHK(mtmp2)->bill_p != 0 658. && ESHK(mtmp2)->bill_p != (struct bill_x *) -1000) 659. ESHK(mtmp)->bill_p = &(ESHK(mtmp)->bill[0]); 660. mtmp->isshk = 1; 661. } 662. replmon(mtmp, mtmp2); 663. newsym(mtmp2->mx, mtmp2->my); /* Might now be invisible */ 664. 665. /* in case Protection_from_shape_changers is different 666. now than it was when the traits were stored */ 667. restore_cham(mtmp2); 668. } 669. return mtmp2; 670. } 671. 672. /* 673. * get_container_location() returns the following information 674. * about the outermost container: 675. * loc argument gets set to: 676. * OBJ_INVENT if in hero's inventory; return 0. 677. * OBJ_FLOOR if on the floor; return 0. 678. * OBJ_BURIED if buried; return 0. 679. * OBJ_MINVENT if in monster's inventory; return monster. 680. * container_nesting is updated with the nesting depth of the containers 681. * if applicable. 682. */ 683. struct monst * 684. get_container_location(obj, loc, container_nesting) 685. struct obj *obj; 686. int *loc; 687. int *container_nesting; 688. { 689. if (!obj || !loc) 690. return 0; 691. 692. if (container_nesting) 693. *container_nesting = 0; 694. while (obj && obj->where == OBJ_CONTAINED) { 695. if (container_nesting) 696. *container_nesting += 1; 697. obj = obj->ocontainer; 698. } 699. if (obj) { 700. *loc = obj->where; /* outermost container's location */ 701. if (obj->where == OBJ_MINVENT) 702. return obj->ocarry; 703. } 704. return (struct monst *) 0; 705. } 706. 707. /* 708. * Attempt to revive the given corpse, return the revived monster if 709. * successful. Note: this does NOT use up the corpse if it fails. 710. * If corpse->quan is more than 1, only one corpse will be affected 711. * and only one monster will be resurrected. 712. */ 713. struct monst * 714. revive(corpse, by_hero) 715. struct obj *corpse; 716. boolean by_hero; 717. { 718. struct monst *mtmp = 0; 719. struct permonst *mptr; 720. struct obj *container; 721. coord xy; 722. xchar x, y; 723. boolean one_of; 724. int montype, container_nesting = 0; 725. 726. if (corpse->otyp != CORPSE) { 727. impossible("Attempting to revive %s?", xname(corpse)); 728. return (struct monst *) 0; 729. } 730. 731. x = y = 0; 732. if (corpse->where != OBJ_CONTAINED) { 733. /* only for invent, minvent, or floor */ 734. container = 0; 735. (void) get_obj_location(corpse, &x, &y, 0); 736. } else { 737. /* deal with corpses in [possibly nested] containers */ 738. struct monst *carrier; 739. int holder = OBJ_FREE; 740. 741. container = corpse->ocontainer; 742. carrier = 743. get_container_location(container, &holder, &container_nesting); 744. switch (holder) { 745. case OBJ_MINVENT: 746. x = carrier->mx, y = carrier->my; 747. break; 748. case OBJ_INVENT: 749. x = u.ux, y = u.uy; 750. break; 751. case OBJ_FLOOR: 752. (void) get_obj_location(corpse, &x, &y, CONTAINED_TOO); 753. break; 754. default: 755. break; /* x,y are 0 */ 756. } 757. } 758. if (!x || !y 759. /* Rules for revival from containers: 760. * - the container cannot be locked 761. * - the container cannot be heavily nested (>2 is arbitrary) 762. * - the container cannot be a statue or bag of holding 763. * (except in very rare cases for the latter) 764. */ 765. || (container && (container->olocked || container_nesting > 2 766. || container->otyp == STATUE 767. || (container->otyp == BAG_OF_HOLDING && rn2(40))))) 768. return (struct monst *) 0; 769. 770. /* record the object's location now that we're sure where it is */ 771. corpse->ox = x, corpse->oy = y; 772. 773. /* prepare for the monster */ 774. montype = corpse->corpsenm; 775. mptr = &mons[montype]; 776. /* [should probably handle recorporealization first; if corpse and 777. ghost are at same location, revived creature shouldn't be bumped 778. to an adjacent spot by ghost which joins with it] */ 779. if (MON_AT(x, y)) { 780. if (enexto(&xy, x, y, mptr)) 781. x = xy.x, y = xy.y; 782. } 783. 784. if ((mons[montype].mlet == S_EEL && !IS_POOL(levl[x][y].typ)) 785. || (mons[montype].mlet == S_TROLL 786. && uwep && uwep->oartifact == ART_TROLLSBANE)) { 787. if (by_hero && cansee(x, y)) 788. pline("%s twitches feebly.", 789. upstart(corpse_xname(corpse, (const char *) 0, CXN_PFX_THE))); 790. return (struct monst *) 0; 791. } 792. 793. if (cant_revive(&montype, TRUE, corpse)) { 794. /* make a zombie or doppelganger instead */ 795. /* note: montype has changed; mptr keeps old value for newcham() */ 796. mtmp = makemon(&mons[montype], x, y, NO_MINVENT | MM_NOWAIT); 797. if (mtmp) { 798. /* skip ghost handling */ 799. if (has_omid(corpse)) 800. free_omid(corpse); 801. if (has_omonst(corpse)) 802. free_omonst(corpse); 803. if (mtmp->cham == PM_DOPPELGANGER) { 804. /* change shape to match the corpse */ 805. (void) newcham(mtmp, mptr, FALSE, FALSE); 806. } else if (mtmp->data->mlet == S_ZOMBIE) { 807. mtmp->mhp = mtmp->mhpmax = 100; 808. mon_adjust_speed(mtmp, 2, (struct obj *) 0); /* MFAST */ 809. } 810. } 811. } else if (has_omonst(corpse)) { 812. /* use saved traits */ 813. xy.x = x, xy.y = y; 814. mtmp = montraits(corpse, &xy, FALSE); 815. if (mtmp && mtmp->mtame && !mtmp->isminion) 816. wary_dog(mtmp, TRUE); 817. } else { 818. /* make a new monster */ 819. mtmp = makemon(mptr, x, y, NO_MINVENT | MM_NOWAIT | MM_NOCOUNTBIRTH); 820. } 821. if (!mtmp) 822. return (struct monst *) 0; 823. 824. /* hiders shouldn't already be re-hidden when they revive */ 825. if (mtmp->mundetected) { 826. mtmp->mundetected = 0; 827. newsym(mtmp->mx, mtmp->my); 828. } 829. if (M_AP_TYPE(mtmp)) 830. seemimic(mtmp); 831. 832. one_of = (corpse->quan > 1L); 833. if (one_of) 834. corpse = splitobj(corpse, 1L); 835. 836. /* if this is caused by the hero there might be a shop charge */ 837. if (by_hero) { 838. struct monst *shkp = 0; 839. 840. x = corpse->ox, y = corpse->oy; 841. if (costly_spot(x, y) 842. && (carried(corpse) ? corpse->unpaid : !corpse->no_charge)) 843. shkp = shop_keeper(*in_rooms(x, y, SHOPBASE)); 844. 845. if (cansee(x, y)) { 846. char buf[BUFSZ]; 847. 848. Strcpy(buf, one_of ? "one of " : ""); 849. /* shk_your: "the " or "your " or "<mon>'s " or "<Shk>'s ". 850. If the result is "Shk's " then it will be ambiguous: 851. is Shk the mon carrying it, or does Shk's shop own it? 852. Let's not worry about that... */ 853. (void) shk_your(eos(buf), corpse); 854. if (one_of) 855. corpse->quan++; /* force plural */ 856. Strcat(buf, corpse_xname(corpse, (const char *) 0, CXN_NO_PFX)); 857. if (one_of) /* could be simplified to corpse->quan = 1L; */ 858. corpse->quan--; 859. pline("%s glows iridescently.", upstart(buf)); 860. } else if (shkp) { 861. /* need some prior description of the corpse since 862. stolen_value() will refer to the object as "it" */ 863. pline("A corpse is resuscitated."); 864. } 865. /* don't charge for shopkeeper's own corpse if we just revived him */ 866. if (shkp && mtmp != shkp) 867. (void) stolen_value(corpse, x, y, (boolean) shkp->mpeaceful, 868. FALSE); 869. 870. /* [we don't give any comparable message about the corpse for 871. the !by_hero case because caller might have already done so] */ 872. } 873. 874. /* handle recorporealization of an active ghost */ 875. if (has_omid(corpse)) { 876. unsigned m_id; 877. struct monst *ghost; 878. struct obj *otmp; 879. 880. (void) memcpy((genericptr_t) &m_id, (genericptr_t) OMID(corpse), 881. sizeof m_id); 882. ghost = find_mid(m_id, FM_FMON); 883. if (ghost && ghost->data == &mons[PM_GHOST]) { 884. if (canseemon(ghost)) 885. pline("%s is suddenly drawn into its former body!", 886. Monnam(ghost)); 887. /* transfer the ghost's inventory along with it */ 888. while ((otmp = ghost->minvent) != 0) { 889. obj_extract_self(otmp); 890. add_to_minv(mtmp, otmp); 891. } 892. /* tame the revived monster if its ghost was tame */ 893. if (ghost->mtame && !mtmp->mtame) { 894. if (tamedog(mtmp, (struct obj *) 0)) { 895. /* ghost's edog data is ignored */ 896. mtmp->mtame = ghost->mtame; 897. } 898. } 899. /* was ghost, now alive, it's all very confusing */ 900. mtmp->mconf = 1; 901. /* separate ghost monster no longer exists */ 902. mongone(ghost); 903. } 904. free_omid(corpse); 905. } 906. 907. /* monster retains its name */ 908. if (has_oname(corpse) && !unique_corpstat(mtmp->data)) 909. mtmp = christen_monst(mtmp, ONAME(corpse)); 910. /* partially eaten corpse yields wounded monster */ 911. if (corpse->oeaten) 912. mtmp->mhp = eaten_stat(mtmp->mhp, corpse); 913. /* track that this monster was revived at least once */ 914. mtmp->mrevived = 1; 915. 916. /* finally, get rid of the corpse--it's gone now */ 917. switch (corpse->where) { 918. case OBJ_INVENT: 919. useup(corpse); 920. break; 921. case OBJ_FLOOR: 922. /* in case MON_AT+enexto for invisible mon */ 923. x = corpse->ox, y = corpse->oy; 924. /* not useupf(), which charges */ 925. if (corpse->quan > 1L) 926. corpse = splitobj(corpse, 1L); 927. delobj(corpse); 928. newsym(x, y); 929. break; 930. case OBJ_MINVENT: 931. m_useup(corpse->ocarry, corpse); 932. break; 933. case OBJ_CONTAINED: 934. obj_extract_self(corpse); 935. obfree(corpse, (struct obj *) 0); 936. break; 937. default: 938. panic("revive"); 939. } 940. 941. return mtmp; 942. } 943. 944. STATIC_OVL void 945. revive_egg(obj) 946. struct obj *obj; 947. { 948. /* 949. * Note: generic eggs with corpsenm set to NON_PM will never hatch. 950. */ 951. if (obj->otyp != EGG) 952. return; 953. if (obj->corpsenm != NON_PM && !dead_species(obj->corpsenm, TRUE)) 954. attach_egg_hatch_timeout(obj, 0L); 955. } 956. 957. /* try to revive all corpses and eggs carried by `mon' */ 958. int 959. unturn_dead(mon) 960. struct monst *mon; 961. { 962. struct obj *otmp, *otmp2; 963. struct monst *mtmp2; 964. char owner[BUFSZ], corpse[BUFSZ]; 965. boolean youseeit; 966. int res = 0; 967. 968. youseeit = (mon == &youmonst) ? TRUE : canseemon(mon); 969. otmp2 = (mon == &youmonst) ? invent : mon->minvent; 970. owner[0] = corpse[0] = '\0'; /* lint suppression */ 971. 972. while ((otmp = otmp2) != 0) { 973. otmp2 = otmp->nobj; 974. if (otmp->otyp == EGG) 975. revive_egg(otmp); 976. if (otmp->otyp != CORPSE) 977. continue; 978. /* save the name; the object is liable to go away */ 979. if (youseeit) { 980. Strcpy(corpse, 981. corpse_xname(otmp, (const char *) 0, CXN_SINGULAR)); 982. Shk_Your(owner, otmp); /* includes a trailing space */ 983. } 984. 985. /* for a stack, only one is revived */ 986. if ((mtmp2 = revive(otmp, !context.mon_moving)) != 0) { 987. ++res; 988. if (youseeit) 989. pline("%s%s suddenly comes alive!", owner, corpse); 990. else if (canseemon(mtmp2)) 991. pline("%s suddenly appears!", Amonnam(mtmp2)); 992. } 993. } 994. return res; 995. } 996. 997. /* cancel obj, possibly carried by you or a monster */ 998. void 999. cancel_item(obj) 1000. register struct obj *obj; 1001. { 1002. boolean u_ring = (obj == uleft || obj == uright); 1003. int otyp = obj->otyp; 1004. 1005. switch (otyp) { 1006. case RIN_GAIN_STRENGTH: 1007. if ((obj->owornmask & W_RING) && u_ring) { 1008. ABON(A_STR) -= obj->spe; 1009. context.botl = 1; 1010. } 1011. break; 1012. case RIN_GAIN_CONSTITUTION: 1013. if ((obj->owornmask & W_RING) && u_ring) { 1014. ABON(A_CON) -= obj->spe; 1015. context.botl = 1; 1016. } 1017. break; 1018. case RIN_ADORNMENT: 1019. if ((obj->owornmask & W_RING) && u_ring) { 1020. ABON(A_CHA) -= obj->spe; 1021. context.botl = 1; 1022. } 1023. break; 1024. case RIN_INCREASE_ACCURACY: 1025. if ((obj->owornmask & W_RING) && u_ring) 1026. u.uhitinc -= obj->spe; 1027. break; 1028. case RIN_INCREASE_DAMAGE: 1029. if ((obj->owornmask & W_RING) && u_ring) 1030. u.udaminc -= obj->spe; 1031. break; 1032. case GAUNTLETS_OF_DEXTERITY: 1033. if ((obj->owornmask & W_ARMG) && (obj == uarmg)) { 1034. ABON(A_DEX) -= obj->spe; 1035. context.botl = 1; 1036. } 1037. break; 1038. case HELM_OF_BRILLIANCE: 1039. if ((obj->owornmask & W_ARMH) && (obj == uarmh)) { 1040. ABON(A_INT) -= obj->spe; 1041. ABON(A_WIS) -= obj->spe; 1042. context.botl = 1; 1043. } 1044. break; 1045. /* case RIN_PROTECTION: not needed */ 1046. } 1047. if (objects[otyp].oc_magic 1048. || (obj->spe && (obj->oclass == ARMOR_CLASS 1049. || obj->oclass == WEAPON_CLASS || is_weptool(obj))) 1050. || otyp == POT_ACID 1051. || otyp == POT_SICKNESS 1052. || (otyp == POT_WATER && (obj->blessed || obj->cursed))) { 1053. if (obj->spe != ((obj->oclass == WAND_CLASS) ? -1 : 0) 1054. && otyp != WAN_CANCELLATION /* can't cancel cancellation */ 1055. && otyp != MAGIC_LAMP /* cancelling doesn't remove djinni */ 1056. && otyp != CANDELABRUM_OF_INVOCATION) { 1057. costly_alteration(obj, COST_CANCEL); 1058. obj->spe = (obj->oclass == WAND_CLASS) ? -1 : 0; 1059. } 1060. switch (obj->oclass) { 1061. case SCROLL_CLASS: 1062. costly_alteration(obj, COST_CANCEL); 1063. obj->otyp = SCR_BLANK_PAPER; 1064. obj->spe = 0; 1065. break; 1066. case SPBOOK_CLASS: 1067. if (otyp != SPE_CANCELLATION && otyp != SPE_NOVEL 1068. && otyp != SPE_BOOK_OF_THE_DEAD) { 1069. costly_alteration(obj, COST_CANCEL); 1070. obj->otyp = SPE_BLANK_PAPER; 1071. } 1072. break; 1073. case POTION_CLASS: 1074. costly_alteration(obj, 1075. (otyp != POT_WATER) 1076. ? COST_CANCEL 1077. : obj->cursed ? COST_UNCURS : COST_UNBLSS); 1078. if (otyp == POT_SICKNESS || otyp == POT_SEE_INVISIBLE) { 1079. /* sickness is "biologically contaminated" fruit juice; 1080. cancel it and it just becomes fruit juice... 1081. whereas see invisible tastes like "enchanted" fruit 1082. juice, it similarly cancels */ 1083. obj->otyp = POT_FRUIT_JUICE; 1084. } else { 1085. obj->otyp = POT_WATER; 1086. obj->odiluted = 0; /* same as any other water */ 1087. } 1088. break; 1089. } 1090. } 1091. unbless(obj); 1092. uncurse(obj); 1093. return; 1094. } 1095. 1096. /* Remove a positive enchantment or charge from obj, 1097. * possibly carried by you or a monster 1098. */ 1099. boolean 1100. drain_item(obj, by_you) 1101. struct obj *obj; 1102. boolean by_you; 1103. { 1104. boolean u_ring; 1105. 1106. /* Is this a charged/enchanted object? */ 1107. if (!obj 1108. || (!objects[obj->otyp].oc_charged && obj->oclass != WEAPON_CLASS 1109. && obj->oclass != ARMOR_CLASS && !is_weptool(obj)) 1110. || obj->spe <= 0) 1111. return FALSE; 1112. if (defends(AD_DRLI, obj) || defends_when_carried(AD_DRLI, obj) 1113. || obj_resists(obj, 10, 90)) 1114. return FALSE; 1115. 1116. /* Charge for the cost of the object */ 1117. if (by_you) 1118. costly_alteration(obj, COST_DRAIN); 1119. 1120. /* Drain the object and any implied effects */ 1121. obj->spe--; 1122. u_ring = (obj == uleft) || (obj == uright); 1123. switch (obj->otyp) { 1124. case RIN_GAIN_STRENGTH: 1125. if ((obj->owornmask & W_RING) && u_ring) { 1126. ABON(A_STR)--; 1127. context.botl = 1; 1128. } 1129. break; 1130. case RIN_GAIN_CONSTITUTION: 1131. if ((obj->owornmask & W_RING) && u_ring) { 1132. ABON(A_CON)--; 1133. context.botl = 1; 1134. } 1135. break; 1136. case RIN_ADORNMENT: 1137. if ((obj->owornmask & W_RING) && u_ring) { 1138. ABON(A_CHA)--; 1139. context.botl = 1; 1140. } 1141. break; 1142. case RIN_INCREASE_ACCURACY: 1143. if ((obj->owornmask & W_RING) && u_ring) 1144. u.uhitinc--; 1145. break; 1146. case RIN_INCREASE_DAMAGE: 1147. if ((obj->owornmask & W_RING) && u_ring) 1148. u.udaminc--; 1149. break; 1150. case RIN_PROTECTION: 1151. if (u_ring) 1152. context.botl = 1; /* bot() will recalc u.uac */ 1153. break; 1154. case HELM_OF_BRILLIANCE: 1155. if ((obj->owornmask & W_ARMH) && (obj == uarmh)) { 1156. ABON(A_INT)--; 1157. ABON(A_WIS)--; 1158. context.botl = 1; 1159. } 1160. break; 1161. case GAUNTLETS_OF_DEXTERITY: 1162. if ((obj->owornmask & W_ARMG) && (obj == uarmg)) { 1163. ABON(A_DEX)--; 1164. context.botl = 1; 1165. } 1166. break; 1167. default: 1168. break; 1169. } 1170. if (context.botl) 1171. bot(); 1172. if (carried(obj)) 1173. update_inventory(); 1174. return TRUE; 1175. } 1176. 1177. boolean 1178. obj_resists(obj, ochance, achance) 1179. struct obj *obj; 1180. int ochance, achance; /* percent chance for ordinary objects, artifacts */ 1181. { 1182. if (obj->otyp == AMULET_OF_YENDOR 1183. || obj->otyp == SPE_BOOK_OF_THE_DEAD 1184. || obj->otyp == CANDELABRUM_OF_INVOCATION 1185. || obj->otyp == BELL_OF_OPENING 1186. || (obj->otyp == CORPSE && is_rider(&mons[obj->corpsenm]))) { 1187. return TRUE; 1188. } else { 1189. int chance = rn2(100); 1190. 1191. return (boolean) (chance < (obj->oartifact ? achance : ochance)); 1192. } 1193. } 1194. 1195. boolean 1196. obj_shudders(obj) 1197. struct obj *obj; 1198. { 1199. int zap_odds; 1200. 1201. if (context.bypasses && obj->bypass) 1202. return FALSE; 1203. 1204. if (obj->oclass == WAND_CLASS) 1205. zap_odds = 3; /* half-life = 2 zaps */ 1206. else if (obj->cursed) 1207. zap_odds = 3; /* half-life = 2 zaps */ 1208. else if (obj->blessed) 1209. zap_odds = 12; /* half-life = 8 zaps */ 1210. else 1211. zap_odds = 8; /* half-life = 6 zaps */ 1212. 1213. /* adjust for "large" quantities of identical things */ 1214. if (obj->quan > 4L) 1215. zap_odds /= 2; 1216. 1217. return (boolean) !rn2(zap_odds); 1218. } 1219. 1220. /* Use up at least minwt number of things made of material mat. 1221. * There's also a chance that other stuff will be used up. Finally, 1222. * there's a random factor here to keep from always using the stuff 1223. * at the top of the pile. 1224. */ 1225. STATIC_OVL void 1226. polyuse(objhdr, mat, minwt) 1227. struct obj *objhdr; 1228. int mat, minwt; 1229. { 1230. register struct obj *otmp, *otmp2; 1231. 1232. for (otmp = objhdr; minwt > 0 && otmp; otmp = otmp2) { 1233. otmp2 = otmp->nexthere; 1234. if (context.bypasses && otmp->bypass) 1235. continue; 1236. if (otmp == uball || otmp == uchain) 1237. continue; 1238. if (obj_resists(otmp, 0, 0)) 1239. continue; /* preserve unique objects */ 1240. #ifdef MAIL 1241. if (otmp->otyp == SCR_MAIL) 1242. continue; 1243. #endif 1244. 1245. if (((int) objects[otmp->otyp].oc_material == mat) 1246. == (rn2(minwt + 1) != 0)) { 1247. /* appropriately add damage to bill */ 1248. if (costly_spot(otmp->ox, otmp->oy)) { 1249. if (*u.ushops) 1250. addtobill(otmp, FALSE, FALSE, FALSE); 1251. else 1252. (void) stolen_value(otmp, otmp->ox, otmp->oy, FALSE, 1253. FALSE); 1254. } 1255. if (otmp->quan < LARGEST_INT) 1256. minwt -= (int) otmp->quan; 1257. else 1258. minwt = 0; 1259. delobj(otmp); 1260. } 1261. } 1262. } 1263. 1264. /* 1265. * Polymorph some of the stuff in this pile into a monster, preferably 1266. * a golem of the kind okind. 1267. */ 1268. STATIC_OVL void 1269. create_polymon(obj, okind) 1270. struct obj *obj; 1271. int okind; 1272. { 1273. struct permonst *mdat = (struct permonst *) 0; 1274. struct monst *mtmp; 1275. const char *material; 1276. int pm_index; 1277. 1278. if (context.bypasses) { 1279. /* this is approximate because the "no golems" !obj->nexthere 1280. check below doesn't understand bypassed objects; but it 1281. should suffice since bypassed objects always end up as a 1282. consecutive group at the top of their pile */ 1283. while (obj && obj->bypass) 1284. obj = obj->nexthere; 1285. } 1286. 1287. /* no golems if you zap only one object -- not enough stuff */ 1288. if (!obj || (!obj->nexthere && obj->quan == 1L)) 1289. return; 1290. 1291. /* some of these choices are arbitrary */ 1292. switch (okind) { 1293. case IRON: 1294. case METAL: 1295. case MITHRIL: 1296. pm_index = PM_IRON_GOLEM; 1297. material = "metal "; 1298. break; 1299. case COPPER: 1300. case SILVER: 1301. case PLATINUM: 1302. case GEMSTONE: 1303. case MINERAL: 1304. pm_index = rn2(2) ? PM_STONE_GOLEM : PM_CLAY_GOLEM; 1305. material = "lithic "; 1306. break; 1307. case 0: 1308. case FLESH: 1309. /* there is no flesh type, but all food is type 0, so we use it */ 1310. pm_index = PM_FLESH_GOLEM; 1311. material = "organic "; 1312. break; 1313. case WOOD: 1314. pm_index = PM_WOOD_GOLEM; 1315. material = "wood "; 1316. break; 1317. case LEATHER: 1318. pm_index = PM_LEATHER_GOLEM; 1319. material = "leather "; 1320. break; 1321. case CLOTH: 1322. pm_index = PM_ROPE_GOLEM; 1323. material = "cloth "; 1324. break; 1325. case BONE: 1326. pm_index = PM_SKELETON; /* nearest thing to "bone golem" */ 1327. material = "bony "; 1328. break; 1329. case GOLD: 1330. pm_index = PM_GOLD_GOLEM; 1331. material = "gold "; 1332. break; 1333. case GLASS: 1334. pm_index = PM_GLASS_GOLEM; 1335. material = "glassy "; 1336. break; 1337. case PAPER: 1338. pm_index = PM_PAPER_GOLEM; 1339. material = "paper "; 1340. break; 1341. default: 1342. /* if all else fails... */ 1343. pm_index = PM_STRAW_GOLEM; 1344. material = ""; 1345. break; 1346. } 1347. 1348. if (!(mvitals[pm_index].mvflags & G_GENOD)) 1349. mdat = &mons[pm_index]; 1350. 1351. mtmp = makemon(mdat, obj->ox, obj->oy, NO_MM_FLAGS); 1352. polyuse(obj, okind, (int) mons[pm_index].cwt); 1353. 1354. if (mtmp && cansee(mtmp->mx, mtmp->my)) { 1355. pline("Some %sobjects meld, and %s arises from the pile!", material, 1356. a_monnam(mtmp)); 1357. } 1358. } 1359. 1360. /* Assumes obj is on the floor. */ 1361. void 1362. do_osshock(obj) 1363. struct obj *obj; 1364. { 1365. long i; 1366. 1367. #ifdef MAIL 1368. if (obj->otyp == SCR_MAIL) 1369. return; 1370. #endif 1371. obj_zapped = TRUE; 1372. 1373. if (poly_zapped < 0) { 1374. /* some may metamorphosize */ 1375. for (i = obj->quan; i; i--) 1376. if (!rn2(Luck + 45)) { 1377. poly_zapped = objects[obj->otyp].oc_material; 1378. break; 1379. } 1380. } 1381. 1382. /* if quan > 1 then some will survive intact */ 1383. if (obj->quan > 1L) { 1384. if (obj->quan > LARGEST_INT) 1385. obj = splitobj(obj, (long) rnd(30000)); 1386. else 1387. obj = splitobj(obj, (long) rnd((int) obj->quan - 1)); 1388. } 1389. 1390. /* appropriately add damage to bill */ 1391. if (costly_spot(obj->ox, obj->oy)) { 1392. if (*u.ushops) 1393. addtobill(obj, FALSE, FALSE, FALSE); 1394. else 1395. (void) stolen_value(obj, obj->ox, obj->oy, FALSE, FALSE); 1396. } 1397. 1398. /* zap the object */ 1399. delobj(obj); 1400. } 1401. 1402. /* classes of items whose current charge count carries over across polymorph 1403. */ 1404. static const char charged_objs[] = { WAND_CLASS, WEAPON_CLASS, ARMOR_CLASS, 1405. '\0' }; 1406. 1407. /* 1408. * Polymorph the object to the given object ID. If the ID is STRANGE_OBJECT 1409. * then pick random object from the source's class (this is the standard 1410. * "polymorph" case). If ID is set to a specific object, inhibit fusing 1411. * n objects into 1. This could have been added as a flag, but currently 1412. * it is tied to not being the standard polymorph case. The new polymorphed 1413. * object replaces obj in its link chains. Return value is a pointer to 1414. * the new object. 1415. * 1416. * This should be safe to call for an object anywhere. 1417. */ 1418. struct obj * 1419. poly_obj(obj, id) 1420. struct obj *obj; 1421. int id; 1422. { 1423. struct obj *otmp; 1424. xchar ox = 0, oy = 0; 1425. long old_wornmask, new_wornmask = 0L; 1426. boolean can_merge = (id == STRANGE_OBJECT); 1427. int obj_location = obj->where; 1428. 1429. if (obj->otyp == BOULDER) 1430. sokoban_guilt(); 1431. if (id == STRANGE_OBJECT) { /* preserve symbol */ 1432. int try_limit = 3; 1433. unsigned magic_obj = objects[obj->otyp].oc_magic; 1434. 1435. if (obj->otyp == UNICORN_HORN && obj->degraded_horn) 1436. magic_obj = 0; 1437. /* Try up to 3 times to make the magic-or-not status of 1438. the new item be the same as it was for the old one. */ 1439. otmp = (struct obj *) 0; 1440. do { 1441. if (otmp) 1442. delobj(otmp); 1443. otmp = mkobj(obj->oclass, FALSE); 1444. } while (--try_limit > 0 1445. && objects[otmp->otyp].oc_magic != magic_obj); 1446. } else { 1447. /* literally replace obj with this new thing */ 1448. otmp = mksobj(id, FALSE, FALSE); 1449. /* Actually more things use corpsenm but they polymorph differently */ 1450. #define USES_CORPSENM(typ) \ 1451. ((typ) == CORPSE || (typ) == STATUE || (typ) == FIGURINE) 1452. 1453. if (USES_CORPSENM(obj->otyp) && USES_CORPSENM(id)) 1454. set_corpsenm(otmp, obj->corpsenm); 1455. #undef USES_CORPSENM 1456. } 1457. 1458. /* preserve quantity */ 1459. otmp->quan = obj->quan; 1460. /* preserve the shopkeepers (lack of) interest */ 1461. otmp->no_charge = obj->no_charge; 1462. /* preserve inventory letter if in inventory */ 1463. if (obj_location == OBJ_INVENT) 1464. otmp->invlet = obj->invlet; 1465. #ifdef MAIL 1466. /* You can't send yourself 100 mail messages and then 1467. * polymorph them into useful scrolls 1468. */ 1469. if (obj->otyp == SCR_MAIL) { 1470. otmp->otyp = SCR_MAIL; 1471. otmp->spe = 1; 1472. } 1473. #endif 1474. 1475. /* avoid abusing eggs laid by you */ 1476. if (obj->otyp == EGG && obj->spe) { 1477. int mnum, tryct = 100; 1478. 1479. /* first, turn into a generic egg */ 1480. if (otmp->otyp == EGG) 1481. kill_egg(otmp); 1482. else { 1483. otmp->otyp = EGG; 1484. otmp->owt = weight(otmp); 1485. } 1486. otmp->corpsenm = NON_PM; 1487. otmp->spe = 0; 1488. 1489. /* now change it into something laid by the hero */ 1490. while (tryct--) { 1491. mnum = can_be_hatched(random_monster(rn2)); 1492. if (mnum != NON_PM && !dead_species(mnum, TRUE)) { 1493. otmp->spe = 1; /* laid by hero */ 1494. set_corpsenm(otmp, mnum); /* also sets hatch timer */ 1495. break; 1496. } 1497. } 1498. } 1499. 1500. /* keep special fields (including charges on wands) */ 1501. if (index(charged_objs, otmp->oclass)) 1502. otmp->spe = obj->spe; 1503. otmp->recharged = obj->recharged; 1504. 1505. otmp->cursed = obj->cursed; 1506. otmp->blessed = obj->blessed; 1507. 1508. if (erosion_matters(otmp)) { 1509. if (is_flammable(otmp) || is_rustprone(otmp)) 1510. otmp->oeroded = obj->oeroded; 1511. if (is_corrodeable(otmp) || is_rottable(otmp)) 1512. otmp->oeroded2 = obj->oeroded2; 1513. if (is_damageable(otmp)) 1514. otmp->oerodeproof = obj->oerodeproof; 1515. } 1516. 1517. /* Keep chest/box traps and poisoned ammo if we may */ 1518. if (obj->otrapped && Is_box(otmp)) 1519. otmp->otrapped = TRUE; 1520. 1521. if (obj->opoisoned && is_poisonable(otmp)) 1522. otmp->opoisoned = TRUE; 1523. 1524. if (id == STRANGE_OBJECT && obj->otyp == CORPSE) { 1525. /* turn crocodile corpses into shoes */ 1526. if (obj->corpsenm == PM_CROCODILE) { 1527. otmp->otyp = LOW_BOOTS; 1528. otmp->oclass = ARMOR_CLASS; 1529. otmp->spe = 0; 1530. otmp->oeroded = 0; 1531. otmp->oerodeproof = TRUE; 1532. otmp->quan = 1L; 1533. otmp->cursed = FALSE; 1534. } 1535. } 1536. 1537. /* no box contents --KAA */ 1538. if (Has_contents(otmp)) 1539. delete_contents(otmp); 1540. 1541. /* 'n' merged objects may be fused into 1 object */ 1542. if (otmp->quan > 1L && (!objects[otmp->otyp].oc_merge 1543. || (can_merge && otmp->quan > (long) rn2(1000)))) 1544. otmp->quan = 1L; 1545. 1546. switch (otmp->oclass) { 1547. case TOOL_CLASS: 1548. if (otmp->otyp == MAGIC_LAMP) { 1549. otmp->otyp = OIL_LAMP; 1550. otmp->age = 1500L; /* "best" oil lamp possible */ 1551. } else if (otmp->otyp == MAGIC_MARKER) { 1552. otmp->recharged = 1; /* degraded quality */ 1553. } 1554. /* don't care about the recharge count of other tools */ 1555. break; 1556. 1557. case WAND_CLASS: 1558. while (otmp->otyp == WAN_WISHING || otmp->otyp == WAN_POLYMORPH) 1559. otmp->otyp = rnd_class(WAN_LIGHT, WAN_LIGHTNING); 1560. /* altering the object tends to degrade its quality 1561. (analogous to spellbook `read count' handling) */ 1562. if ((int) otmp->recharged < rn2(7)) /* recharge_limit */ 1563. otmp->recharged++; 1564. break; 1565. 1566. case POTION_CLASS: 1567. while (otmp->otyp == POT_POLYMORPH) 1568. otmp->otyp = rnd_class(POT_GAIN_ABILITY, POT_WATER); 1569. break; 1570. 1571. case SPBOOK_CLASS: 1572. while (otmp->otyp == SPE_POLYMORPH) 1573. otmp->otyp = rnd_class(SPE_DIG, SPE_BLANK_PAPER); 1574. /* reduce spellbook abuse; non-blank books degrade */ 1575. if (otmp->otyp != SPE_BLANK_PAPER) { 1576. otmp->spestudied = obj->spestudied + 1; 1577. if (otmp->spestudied > MAX_SPELL_STUDY) { 1578. otmp->otyp = SPE_BLANK_PAPER; 1579. /* writing a new book over it will yield an unstudied 1580. one; re-polymorphing this one as-is may or may not 1581. get something non-blank */ 1582. otmp->spestudied = rn2(otmp->spestudied); 1583. } 1584. } 1585. break; 1586. 1587. case GEM_CLASS: 1588. if (otmp->quan > (long) rnd(4) 1589. && objects[obj->otyp].oc_material == MINERAL 1590. && objects[otmp->otyp].oc_material != MINERAL) { 1591. otmp->otyp = ROCK; /* transmutation backfired */ 1592. otmp->quan /= 2L; /* some material has been lost */ 1593. } 1594. break; 1595. } 1596. 1597. /* update the weight */ 1598. otmp->owt = weight(otmp); 1599. 1600. /* 1601. * ** we are now done adjusting the object (except possibly wearing it) ** 1602. */ 1603. 1604. (void) get_obj_location(obj, &ox, &oy, BURIED_TOO | CONTAINED_TOO); 1605. old_wornmask = obj->owornmask & ~(W_ART | W_ARTI); 1606. /* swap otmp for obj */ 1607. replace_object(obj, otmp); 1608. if (obj_location == OBJ_INVENT) { 1609. /* 1610. * We may need to do extra adjustments for the hero if we're 1611. * messing with the hero's inventory. The following calls are 1612. * equivalent to calling freeinv on obj and addinv on otmp, 1613. * while doing an in-place swap of the actual objects. 1614. */ 1615. freeinv_core(obj); 1616. addinv_core1(otmp); 1617. addinv_core2(otmp); 1618. /* 1619. * Handle polymorph of worn item. Stone-to-flesh cast on self can 1620. * affect multiple objects at once, but their new forms won't 1621. * produce any side-effects. A single worn item dipped into potion 1622. * of polymorph can produce side-effects but those won't yield out 1623. * of sequence messages because current polymorph is finished. 1624. */ 1625. if (old_wornmask) { 1626. boolean was_twohanded = bimanual(obj), was_twoweap = u.twoweap; 1627. 1628. /* wearslot() returns a mask which might have multiple bits set; 1629. narrow that down to the bit(s) currently in use */ 1630. new_wornmask = wearslot(otmp) & old_wornmask; 1631. remove_worn_item(obj, TRUE); 1632. /* if the new form can be worn in the same slot, make it so */ 1633. if ((new_wornmask & W_WEP) != 0L) { 1634. if (was_twohanded || !bimanual(otmp) || !uarms) 1635. setuwep(otmp); 1636. if (was_twoweap && uwep && !bimanual(uwep)) 1637. u.twoweap = TRUE; 1638. } else if ((new_wornmask & W_SWAPWEP) != 0L) { 1639. if (was_twohanded || !bimanual(otmp)) 1640. setuswapwep(otmp); 1641. if (was_twoweap && uswapwep) 1642. u.twoweap = TRUE; 1643. } else if ((new_wornmask & W_QUIVER) != 0L) { 1644. setuqwep(otmp); 1645. } else if (new_wornmask) { 1646. setworn(otmp, new_wornmask); 1647. /* set_wear() might result in otmp being destroyed if 1648. worn amulet has been turned into an amulet of change */ 1649. set_wear(otmp); 1650. otmp = wearmask_to_obj(new_wornmask); /* might be Null */ 1651. } 1652. } /* old_wornmask */ 1653. } else if (obj_location == OBJ_FLOOR) { 1654. if (obj->otyp == BOULDER && otmp->otyp != BOULDER 1655. && !does_block(ox, oy, &levl[ox][oy])) 1656. unblock_point(ox, oy); 1657. else if (obj->otyp != BOULDER && otmp->otyp == BOULDER) 1658. /* (checking does_block() here would be redundant) */ 1659. block_point(ox, oy); 1660. } 1661. 1662. /* note: if otmp is gone, billing for it was handled by useup() */ 1663. if (((otmp && !carried(otmp)) || obj->unpaid) && costly_spot(ox, oy)) { 1664. struct monst *shkp = shop_keeper(*in_rooms(ox, oy, SHOPBASE)); 1665. 1666. if ((!obj->no_charge 1667. || (Has_contents(obj) 1668. && (contained_cost(obj, shkp, 0L, FALSE, FALSE) != 0L))) 1669. && inhishop(shkp)) { 1670. if (shkp->mpeaceful) { 1671. if (*u.ushops 1672. && (*in_rooms(u.ux, u.uy, 0) 1673. == *in_rooms(shkp->mx, shkp->my, 0)) 1674. && !costly_spot(u.ux, u.uy)) { 1675. make_angry_shk(shkp, ox, oy); 1676. } else { 1677. pline("%s gets angry!", Monnam(shkp)); 1678. hot_pursuit(shkp); 1679. } 1680. } else 1681. Norep("%s is furious!", Monnam(shkp)); 1682. } 1683. } 1684. delobj(obj); 1685. return otmp; 1686. } 1687. 1688. /* stone-to-flesh spell hits and maybe transforms or animates obj */ 1689. STATIC_OVL int 1690. stone_to_flesh_obj(obj) 1691. struct obj *obj; 1692. { 1693. int res = 1; /* affected object by default */ 1694. struct permonst *ptr; 1695. struct monst *mon, *shkp; 1696. struct obj *item; 1697. xchar oox, ooy; 1698. boolean smell = FALSE, golem_xform = FALSE; 1699. 1700. if (objects[obj->otyp].oc_material != MINERAL 1701. && objects[obj->otyp].oc_material != GEMSTONE) 1702. return 0; 1703. /* Heart of Ahriman usually resists; ordinary items rarely do */ 1704. if (obj_resists(obj, 2, 98)) 1705. return 0; 1706. 1707. (void) get_obj_location(obj, &oox, &ooy, 0); 1708. /* add more if stone objects are added.. */ 1709. switch (objects[obj->otyp].oc_class) { 1710. case ROCK_CLASS: /* boulders and statues */ 1711. case TOOL_CLASS: /* figurines */ 1712. if (obj->otyp == BOULDER) { 1713. obj = poly_obj(obj, HUGE_CHUNK_OF_MEAT); 1714. smell = TRUE; 1715. } else if (obj->otyp == STATUE || obj->otyp == FIGURINE) { 1716. ptr = &mons[obj->corpsenm]; 1717. if (is_golem(ptr)) { 1718. golem_xform = (ptr != &mons[PM_FLESH_GOLEM]); 1719. } else if (vegetarian(ptr)) { 1720. /* Don't animate monsters that aren't flesh */ 1721. obj = poly_obj(obj, MEATBALL); 1722. smell = TRUE; 1723. break; 1724. } 1725. if (obj->otyp == STATUE) { 1726. /* animate_statue() forces all golems to become flesh golems */ 1727. mon = animate_statue(obj, oox, ooy, ANIMATE_SPELL, (int *) 0); 1728. } else { /* (obj->otyp == FIGURINE) */ 1729. if (golem_xform) 1730. ptr = &mons[PM_FLESH_GOLEM]; 1731. mon = makemon(ptr, oox, ooy, NO_MINVENT); 1732. if (mon) { 1733. if (costly_spot(oox, ooy) 1734. && (carried(obj) ? obj->unpaid : !obj->no_charge)) { 1735. shkp = shop_keeper(*in_rooms(oox, ooy, SHOPBASE)); 1736. stolen_value(obj, oox, ooy, 1737. (shkp && shkp->mpeaceful), FALSE); 1738. } 1739. if (obj->timed) 1740. obj_stop_timers(obj); 1741. if (carried(obj)) 1742. useup(obj); 1743. else 1744. delobj(obj); 1745. if (cansee(mon->mx, mon->my)) 1746. pline_The("figurine %sanimates!", 1747. golem_xform ? "turns to flesh and " : ""); 1748. } 1749. } 1750. if (mon) { 1751. ptr = mon->data; 1752. /* this golem handling is redundant... */ 1753. if (is_golem(ptr) && ptr != &mons[PM_FLESH_GOLEM]) 1754. (void) newcham(mon, &mons[PM_FLESH_GOLEM], TRUE, FALSE); 1755. } else if ((ptr->geno & (G_NOCORPSE | G_UNIQ)) != 0) { 1756. /* didn't revive but can't leave corpse either */ 1757. res = 0; 1758. } else { 1759. /* unlikely to get here since genociding monsters also 1760. sets the G_NOCORPSE flag; drop statue's contents */ 1761. while ((item = obj->cobj) != 0) { 1762. bypass_obj(item); /* make stone-to-flesh miss it */ 1763. obj_extract_self(item); 1764. place_object(item, oox, ooy); 1765. } 1766. obj = poly_obj(obj, CORPSE); 1767. } 1768. } else { /* miscellaneous tool or unexpected rock... */ 1769. res = 0; 1770. } 1771. break; 1772. /* maybe add weird things to become? */ 1773. case RING_CLASS: /* some of the rings are stone */ 1774. obj = poly_obj(obj, MEAT_RING); 1775. smell = TRUE; 1776. break; 1777. case WAND_CLASS: /* marble wand */ 1778. obj = poly_obj(obj, MEAT_STICK); 1779. smell = TRUE; 1780. break; 1781. case GEM_CLASS: /* stones & gems */ 1782. obj = poly_obj(obj, MEATBALL); 1783. smell = TRUE; 1784. break; 1785. case WEAPON_CLASS: /* crysknife */ 1786. /*FALLTHRU*/ 1787. default: 1788. res = 0; 1789. break; 1790. } 1791. 1792. if (smell) { 1793. /* non-meat eaters smell meat, meat eaters smell its flavor; 1794. monks are considered non-meat eaters regardless of behavior; 1795. other roles are non-meat eaters if they haven't broken 1796. vegetarian conduct yet (or if poly'd into non-carnivorous/ 1797. non-omnivorous form, regardless of whether it's herbivorous, 1798. non-eating, or something stranger) */ 1799. if (Role_if(PM_MONK) || !u.uconduct.unvegetarian 1800. || !carnivorous(youmonst.data)) 1801. Norep("You smell the odor of meat."); 1802. else 1803. Norep("You smell a delicious smell."); 1804. } 1805. newsym(oox, ooy); 1806. return res; 1807. } 1808. 1809. /* 1810. * Object obj was hit by the effect of the wand/spell otmp. Return 1811. * non-zero if the wand/spell had any effect. 1812. */ 1813. int 1814. bhito(obj, otmp) 1815. struct obj *obj, *otmp; 1816. { 1817. int res = 1; /* affected object by default */ 1818. boolean learn_it = FALSE, maybelearnit; 1819. 1820. /* fundamental: a wand effect hitting itself doesn't do anything; 1821. otherwise we need to guard against accessing otmp after something 1822. strange has happened to it (along the lines of polymorph or 1823. stone-to-flesh [which aren't good examples since polymorph wands 1824. aren't affected by polymorph zaps and stone-to-flesh isn't 1825. available in wand form, but the concept still applies...]) */ 1826. if (obj == otmp) 1827. return 0; 1828. 1829. if (obj->bypass) { 1830. /* The bypass bit is currently only used as follows: 1831. * 1832. * POLYMORPH - When a monster being polymorphed drops something 1833. * from its inventory as a result of the change. 1834. * If the items fall to the floor, they are not 1835. * subject to direct subsequent polymorphing 1836. * themselves on that same zap. This makes it 1837. * consistent with items that remain in the monster's 1838. * inventory. They are not polymorphed either. 1839. * UNDEAD_TURNING - When an undead creature gets killed via 1840. * undead turning, prevent its corpse from being 1841. * immediately revived by the same effect. 1842. * STONE_TO_FLESH - If a statue can't be revived, its 1843. * contents get dropped before turning it into 1844. * meat; prevent those contents from being hit. 1845. * retouch_equipment() - bypass flag is used to track which 1846. * items have been handled (bhito isn't involved). 1847. * menu_drop(), askchain() - inventory traversal where multiple 1848. * Drop can alter the invent chain while traversal 1849. * is in progress (bhito isn't involved). 1850. * destroy_item(), destroy_mitem() - inventory traversal where 1851. * item destruction can trigger drop or destruction of 1852. * other item(s) and alter the invent or mon->minvent 1853. * chain, possibly recursively. 1854. * 1855. * The bypass bit on all objects is reset each turn, whenever 1856. * context.bypasses is set. 1857. * 1858. * We check the obj->bypass bit above AND context.bypasses 1859. * as a safeguard against any stray occurrence left in an obj 1860. * struct someplace, although that should never happen. 1861. */ 1862. if (context.bypasses) { 1863. return 0; 1864. } else { 1865. debugpline1("%s for a moment.", Tobjnam(obj, "pulsate")); 1866. obj->bypass = 0; 1867. } 1868. } 1869. 1870. /* 1871. * Some parts of this function expect the object to be on the floor 1872. * obj->{ox,oy} to be valid. The exception to this (so far) is 1873. * for the STONE_TO_FLESH spell. 1874. */ 1875. if (!(obj->where == OBJ_FLOOR || otmp->otyp == SPE_STONE_TO_FLESH)) 1876. impossible("bhito: obj is not floor or Stone To Flesh spell"); 1877. 1878. if (obj == uball) { 1879. res = 0; 1880. } else if (obj == uchain) { 1881. if (otmp->otyp == WAN_OPENING || otmp->otyp == SPE_KNOCK) { 1882. learn_it = TRUE; 1883. unpunish(); 1884. } else 1885. res = 0; 1886. } else 1887. switch (otmp->otyp) { 1888. case WAN_POLYMORPH: 1889. case SPE_POLYMORPH: 1890. if (obj->otyp == WAN_POLYMORPH || obj->otyp == SPE_POLYMORPH 1891. || obj->otyp == POT_POLYMORPH || obj_resists(obj, 5, 95)) { 1892. res = 0; 1893. break; 1894. } 1895. /* KMH, conduct */ 1896. u.uconduct.polypiles++; 1897. /* any saved lock context will be dangerously obsolete */ 1898. if (Is_box(obj)) 1899. (void) boxlock(obj, otmp); 1900. 1901. if (obj_shudders(obj)) { 1902. boolean cover = 1903. ((obj == level.objects[u.ux][u.uy]) && u.uundetected 1904. && hides_under(youmonst.data)); 1905. 1906. if (cansee(obj->ox, obj->oy)) 1907. learn_it = TRUE; 1908. do_osshock(obj); 1909. /* eek - your cover might have been blown */ 1910. if (cover) 1911. (void) hideunder(&youmonst); 1912. break; 1913. } 1914. obj = poly_obj(obj, STRANGE_OBJECT); 1915. newsym(obj->ox, obj->oy); 1916. break; 1917. case WAN_PROBING: 1918. res = !obj->dknown; 1919. /* target object has now been "seen (up close)" */ 1920. obj->dknown = 1; 1921. if (Is_container(obj) || obj->otyp == STATUE) { 1922. obj->cknown = obj->lknown = 1; 1923. if (!obj->cobj) { 1924. pline("%s empty.", Tobjnam(obj, "are")); 1925. } else if (SchroedingersBox(obj)) { 1926. /* we don't want to force alive vs dead 1927. determination for Schroedinger's Cat here, 1928. so just make probing be inconclusive for it */ 1929. You("aren't sure whether %s has %s or its corpse inside.", 1930. the(xname(obj)), 1931. /* unfortunately, we can't tell whether rndmonnam() 1932. picks a form which can't leave a corpse */ 1933. an(Hallucination ? rndmonnam((char *) 0) : "cat")); 1934. obj->cknown = 0; 1935. } else { 1936. struct obj *o; 1937. /* view contents (not recursively) */ 1938. for (o = obj->cobj; o; o = o->nobj) 1939. o->dknown = 1; /* "seen", even if blind */ 1940. (void) display_cinventory(obj); 1941. } 1942. res = 1; 1943. } 1944. if (res) 1945. learn_it = TRUE; 1946. break; 1947. case WAN_STRIKING: 1948. case SPE_FORCE_BOLT: 1949. /* learn the type if you see or hear something break 1950. (the sound could be implicit) */ 1951. maybelearnit = cansee(obj->ox, obj->oy) || !Deaf; 1952. if (obj->otyp == BOULDER) { 1953. if (cansee(obj->ox, obj->oy)) 1954. pline_The("boulder falls apart."); 1955. else 1956. You_hear("a crumbling sound."); 1957. fracture_rock(obj); 1958. } else if (obj->otyp == STATUE) { 1959. if (break_statue(obj)) { 1960. if (cansee(obj->ox, obj->oy)) { 1961. if (Hallucination) 1962. pline_The("%s shatters.", rndmonnam(NULL)); 1963. else 1964. pline_The("statue shatters."); 1965. } else 1966. You_hear("a crumbling sound."); 1967. } 1968. } else { 1969. int oox = obj->ox; 1970. int ooy = obj->oy; 1971. if (context.mon_moving 1972. ? !breaks(obj, obj->ox, obj->oy) 1973. : !hero_breaks(obj, obj->ox, obj->oy, FALSE)) 1974. maybelearnit = FALSE; /* nothing broke */ 1975. else 1976. newsym_force(oox,ooy); 1977. res = 0; 1978. } 1979. if (maybelearnit) 1980. learn_it = TRUE; 1981. break; 1982. case WAN_CANCELLATION: 1983. case SPE_CANCELLATION: 1984. cancel_item(obj); 1985. #ifdef TEXTCOLOR 1986. newsym(obj->ox, obj->oy); /* might change color */ 1987. #endif 1988. break; 1989. case SPE_DRAIN_LIFE: 1990. (void) drain_item(obj, TRUE); 1991. break; 1992. case WAN_TELEPORTATION: 1993. case SPE_TELEPORT_AWAY: 1994. (void) rloco(obj); 1995. break; 1996. case WAN_MAKE_INVISIBLE: 1997. break; 1998. case WAN_UNDEAD_TURNING: 1999. case SPE_TURN_UNDEAD: 2000. if (obj->otyp == EGG) { 2001. revive_egg(obj); 2002. } else if (obj->otyp == CORPSE) { 2003. struct monst *mtmp; 2004. xchar ox, oy; 2005. int corpsenm = corpse_revive_type(obj); 2006. char *corpsname = cxname_singular(obj); 2007. 2008. /* get corpse's location before revive() uses it up */ 2009. if (!get_obj_location(obj, &ox, &oy, 0)) 2010. ox = obj->ox, oy = obj->oy; /* won't happen */ 2011. 2012. mtmp = revive(obj, TRUE); 2013. if (!mtmp) { 2014. res = 0; /* no monster implies corpse was left intact */ 2015. } else { 2016. if (cansee(ox, oy)) { 2017. if (canspotmon(mtmp)) { 2018. pline("%s is resurrected!", 2019. upstart(noname_monnam(mtmp, ARTICLE_THE))); 2020. learn_it = TRUE; 2021. } else { 2022. /* saw corpse but don't see monster: maybe 2023. mtmp is invisible, or has been placed at 2024. a different spot than <ox,oy> */ 2025. if (!type_is_pname(&mons[corpsenm])) 2026. corpsname = The(corpsname); 2027. pline("%s disappears.", corpsname); 2028. } 2029. } else { 2030. /* couldn't see corpse's location */ 2031. if (Role_if(PM_HEALER) && !Deaf 2032. && !nonliving(&mons[corpsenm])) { 2033. if (!type_is_pname(&mons[corpsenm])) 2034. corpsname = an(corpsname); 2035. if (!Hallucination) 2036. You_hear("%s reviving.", corpsname); 2037. else 2038. You_hear("a defibrillator."); 2039. learn_it = TRUE; 2040. } 2041. if (canspotmon(mtmp)) 2042. /* didn't see corpse but do see monster: it 2043. has been placed somewhere other than <ox,oy> 2044. or blind hero spots it with ESP */ 2045. pline("%s appears.", Monnam(mtmp)); 2046. } 2047. if (learn_it) 2048. exercise(A_WIS, TRUE); 2049. } 2050. } 2051. break; 2052. case WAN_OPENING: 2053. case SPE_KNOCK: 2054. case WAN_LOCKING: 2055. case SPE_WIZARD_LOCK: 2056. if (Is_box(obj)) 2057. res = boxlock(obj, otmp); 2058. else 2059. res = 0; 2060. if (res) 2061. learn_it = TRUE; 2062. break; 2063. case WAN_SLOW_MONSTER: /* no effect on objects */ 2064. case SPE_SLOW_MONSTER: 2065. case WAN_SPEED_MONSTER: 2066. case WAN_NOTHING: 2067. case SPE_HEALING: 2068. case SPE_EXTRA_HEALING: 2069. res = 0; 2070. break; 2071. case SPE_STONE_TO_FLESH: 2072. res = stone_to_flesh_obj(obj); 2073. break; 2074. default: 2075. impossible("What an interesting effect (%d)", otmp->otyp); 2076. break; 2077. } 2078. /* if effect was observable then discover the wand type provided 2079. that the wand itself has been seen */ 2080. if (learn_it) 2081. learnwand(otmp); 2082. return res; 2083. } 2084. 2085. /* returns nonzero if something was hit */ 2086. int 2087. bhitpile(obj, fhito, tx, ty, zz) 2088. struct obj *obj; 2089. int FDECL((*fhito), (OBJ_P, OBJ_P)); 2090. int tx, ty; 2091. schar zz; 2092. { 2093. int hitanything = 0; 2094. register struct obj *otmp, *next_obj; 2095. 2096. if (obj->otyp == SPE_FORCE_BOLT || obj->otyp == WAN_STRIKING) { 2097. struct trap *t = t_at(tx, ty); 2098. 2099. /* We can't settle for the default calling sequence of 2100. bhito(otmp) -> break_statue(otmp) -> activate_statue_trap(ox,oy) 2101. because that last call might end up operating on our `next_obj' 2102. (below), rather than on the current object, if it happens to 2103. encounter a statue which mustn't become animated. */ 2104. if (t && t->ttyp == STATUE_TRAP 2105. && activate_statue_trap(t, tx, ty, TRUE)) 2106. learnwand(obj); 2107. } 2108. 2109. poly_zapped = -1; 2110. for (otmp = level.objects[tx][ty]; otmp; otmp = next_obj) { 2111. next_obj = otmp->nexthere; 2112. /* for zap downwards, don't hit object poly'd hero is hiding under */ 2113. if (zz > 0 && u.uundetected && otmp == level.objects[u.ux][u.uy] 2114. && hides_under(youmonst.data)) 2115. continue; 2116. 2117. hitanything += (*fhito)(otmp, obj); 2118. } 2119. if (poly_zapped >= 0) 2120. create_polymon(level.objects[tx][ty], poly_zapped); 2121. 2122. return hitanything; 2123. } 2124. 2125. /* 2126. * zappable - returns 1 if zap is available, 0 otherwise. 2127. * it removes a charge from the wand if zappable. 2128. * added by GAN 11/03/86 2129. */ 2130. int 2131. zappable(wand) 2132. register struct obj *wand; 2133. { 2134. if (wand->spe < 0 || (wand->spe == 0 && rn2(121))) 2135. return 0; 2136. if (wand->spe == 0) 2137. You("wrest one last charge from the worn-out wand."); 2138. wand->spe--; 2139. return 1; 2140. } 2141. 2142. /* 2143. * zapnodir - zaps a NODIR wand/spell. 2144. * added by GAN 11/03/86 2145. */ 2146. void 2147. zapnodir(obj) 2148. register struct obj *obj; 2149. { 2150. boolean known = FALSE; 2151. 2152. switch (obj->otyp) { 2153. case WAN_LIGHT: 2154. case SPE_LIGHT: 2155. litroom(TRUE, obj); 2156. if (!Blind) 2157. known = TRUE; 2158. if (lightdamage(obj, TRUE, 5)) 2159. known = TRUE; 2160. break; 2161. case WAN_SECRET_DOOR_DETECTION: 2162. case SPE_DETECT_UNSEEN: 2163. if (!findit()) 2164. return; 2165. if (!Blind) 2166. known = TRUE; 2167. break; 2168. case WAN_CREATE_MONSTER: 2169. known = create_critters(rn2(23) ? 1 : rn1(7, 2), 2170. (struct permonst *) 0, FALSE); 2171. break; 2172. case WAN_WISHING: 2173. known = TRUE; 2174. if (Luck + rn2(5) < 0) { 2175. pline("Unfortunately, nothing happens."); 2176. break; 2177. } 2178. makewish(); 2179. break; 2180. case WAN_ENLIGHTENMENT: 2181. known = TRUE; 2182. You_feel("self-knowledgeable..."); 2183. display_nhwindow(WIN_MESSAGE, FALSE); 2184. enlightenment(MAGICENLIGHTENMENT, ENL_GAMEINPROGRESS); 2185. pline_The("feeling subsides."); 2186. exercise(A_WIS, TRUE); 2187. break; 2188. } 2189. if (known) { 2190. if (!objects[obj->otyp].oc_name_known) 2191. more_experienced(0, 10); 2192. /* effect was observable; discover the wand type provided 2193. that the wand itself has been seen */ 2194. learnwand(obj); 2195. } 2196. } 2197. 2198. STATIC_OVL void 2199. backfire(otmp) 2200. struct obj *otmp; 2201. { 2202. int dmg; 2203. 2204. otmp->in_use = TRUE; /* in case losehp() is fatal */ 2205. pline("%s suddenly explodes!", The(xname(otmp))); 2206. dmg = d(otmp->spe + 2, 6); 2207. losehp(Maybe_Half_Phys(dmg), "exploding wand", KILLED_BY_AN); 2208. useup(otmp); 2209. } 2210. 2211. static NEARDATA const char zap_syms[] = { WAND_CLASS, 0 }; 2212. 2213. /* 'z' command (or 'y' if numbed_pad==-1) */ 2214. int 2215. dozap() 2216. { 2217. register struct obj *obj; 2218. int damage; 2219. 2220. if (check_capacity((char *) 0)) 2221. return 0; 2222. obj = getobj(zap_syms, "zap"); 2223. if (!obj) 2224. return 0; 2225. 2226. check_unpaid(obj); 2227. 2228. /* zappable addition done by GAN 11/03/86 */ 2229. if (!zappable(obj)) 2230. pline1(nothing_happens); 2231. else if (obj->cursed && !rn2(WAND_BACKFIRE_CHANCE)) { 2232. backfire(obj); /* the wand blows up in your face! */ 2233. exercise(A_STR, FALSE); 2234. return 1; 2235. } else if (!(objects[obj->otyp].oc_dir == NODIR) && !getdir((char *) 0)) { 2236. if (!Blind) 2237. pline("%s glows and fades.", The(xname(obj))); 2238. /* make him pay for knowing !NODIR */ 2239. } else if (!u.dx && !u.dy && !u.dz 2240. && !(objects[obj->otyp].oc_dir == NODIR)) { 2241. if ((damage = zapyourself(obj, TRUE)) != 0) { 2242. char buf[BUFSZ]; 2243. 2244. Sprintf(buf, "zapped %sself with a wand", uhim()); 2245. losehp(Maybe_Half_Phys(damage), buf, NO_KILLER_PREFIX); 2246. } 2247. } else { 2248. /* Are we having fun yet? 2249. * weffects -> buzz(obj->otyp) -> zhitm (temple priest) -> 2250. * attack -> hitum -> known_hitum -> ghod_hitsu -> 2251. * buzz(AD_ELEC) -> destroy_item(WAND_CLASS) -> 2252. * useup -> obfree -> dealloc_obj -> free(obj) 2253. */ 2254. current_wand = obj; 2255. weffects(obj); 2256. obj = current_wand; 2257. current_wand = 0; 2258. } 2259. if (obj && obj->spe < 0) { 2260. pline("%s to dust.", Tobjnam(obj, "turn")); 2261. useup(obj); 2262. } 2263. update_inventory(); /* maybe used a charge */ 2264. return 1; 2265. } 2266. 2267. int 2268. zapyourself(obj, ordinary) 2269. struct obj *obj; 2270. boolean ordinary; 2271. { 2272. boolean learn_it = FALSE; 2273. int damage = 0; 2274. 2275. switch (obj->otyp) { 2276. case WAN_STRIKING: 2277. case SPE_FORCE_BOLT: 2278. learn_it = TRUE; 2279. if (Antimagic) { 2280. shieldeff(u.ux, u.uy); 2281. pline("Boing!"); 2282. } else { 2283. if (ordinary) { 2284. You("bash yourself!"); 2285. damage = d(2, 12); 2286. } else 2287. damage = d(1 + obj->spe, 6); 2288. exercise(A_STR, FALSE); 2289. } 2290. break; 2291. 2292. case WAN_LIGHTNING: 2293. learn_it = TRUE; 2294. if (!Shock_resistance) { 2295. You("shock yourself!"); 2296. damage = d(12, 6); 2297. exercise(A_CON, FALSE); 2298. } else { 2299. shieldeff(u.ux, u.uy); 2300. You("zap yourself, but seem unharmed."); 2301. ugolemeffects(AD_ELEC, d(12, 6)); 2302. } 2303. destroy_item(WAND_CLASS, AD_ELEC); 2304. destroy_item(RING_CLASS, AD_ELEC); 2305. (void) flashburn((long) rnd(100)); 2306. break; 2307. 2308. case SPE_FIREBALL: 2309. You("explode a fireball on top of yourself!"); 2310. explode(u.ux, u.uy, 11, d(6, 6), WAND_CLASS, EXPL_FIERY); 2311. break; 2312. case WAN_FIRE: 2313. case FIRE_HORN: 2314. learn_it = TRUE; 2315. if (Fire_resistance) { 2316. shieldeff(u.ux, u.uy); 2317. You_feel("rather warm."); 2318. ugolemeffects(AD_FIRE, d(12, 6)); 2319. } else { 2320. pline("You've set yourself afire!"); 2321. damage = d(12, 6); 2322. } 2323. burn_away_slime(); 2324. (void) burnarmor(&youmonst); 2325. destroy_item(SCROLL_CLASS, AD_FIRE); 2326. destroy_item(POTION_CLASS, AD_FIRE); 2327. destroy_item(SPBOOK_CLASS, AD_FIRE); 2328. destroy_item(FOOD_CLASS, AD_FIRE); /* only slime for now */ 2329. break; 2330. 2331. case WAN_COLD: 2332. case SPE_CONE_OF_COLD: 2333. case FROST_HORN: 2334. learn_it = TRUE; 2335. if (Cold_resistance) { 2336. shieldeff(u.ux, u.uy); 2337. You_feel("a little chill."); 2338. ugolemeffects(AD_COLD, d(12, 6)); 2339. } else { 2340. You("imitate a popsicle!"); 2341. damage = d(12, 6); 2342. } 2343. destroy_item(POTION_CLASS, AD_COLD); 2344. break; 2345. 2346. case WAN_MAGIC_MISSILE: 2347. case SPE_MAGIC_MISSILE: 2348. learn_it = TRUE; 2349. if (Antimagic) { 2350. shieldeff(u.ux, u.uy); 2351. pline_The("missiles bounce!"); 2352. } else { 2353. damage = d(4, 6); 2354. pline("Idiot! You've shot yourself!"); 2355. } 2356. break; 2357. 2358. case WAN_POLYMORPH: 2359. case SPE_POLYMORPH: 2360. if (!Unchanging) { 2361. learn_it = TRUE; 2362. polyself(0); 2363. } 2364. break; 2365. 2366. case WAN_CANCELLATION: 2367. case SPE_CANCELLATION: 2368. (void) cancel_monst(&youmonst, obj, TRUE, TRUE, TRUE); 2369. break; 2370. 2371. case SPE_DRAIN_LIFE: 2372. if (!Drain_resistance) { 2373. learn_it = TRUE; /* (no effect for spells...) */ 2374. losexp("life drainage"); 2375. } 2376. damage = 0; /* No additional damage */ 2377. break; 2378. 2379. case WAN_MAKE_INVISIBLE: { 2380. /* have to test before changing HInvis but must change 2381. * HInvis before doing newsym(). 2382. */ 2383. int msg = !Invis && !Blind && !BInvis; 2384. 2385. if (BInvis && uarmc->otyp == MUMMY_WRAPPING) { 2386. /* A mummy wrapping absorbs it and protects you */ 2387. You_feel("rather itchy under %s.", yname(uarmc)); 2388. break; 2389. } 2390. if (ordinary || !rn2(10)) { /* permanent */ 2391. HInvis |= FROMOUTSIDE; 2392. } else { /* temporary */ 2393. incr_itimeout(&HInvis, d(obj->spe, 250)); 2394. } 2395. if (msg) { 2396. learn_it = TRUE; 2397. newsym(u.ux, u.uy); 2398. self_invis_message(); 2399. } 2400. break; 2401. } 2402. 2403. case WAN_SPEED_MONSTER: 2404. if (!(HFast & INTRINSIC)) { 2405. learn_it = TRUE; 2406. if (!Fast) 2407. You("speed up."); 2408. else 2409. Your("quickness feels more natural."); 2410. exercise(A_DEX, TRUE); 2411. } 2412. HFast |= FROMOUTSIDE; 2413. break; 2414. 2415. case WAN_SLEEP: 2416. case SPE_SLEEP: 2417. learn_it = TRUE; 2418. if (Sleep_resistance) { 2419. shieldeff(u.ux, u.uy); 2420. You("don't feel sleepy!"); 2421. } else { 2422. pline_The("sleep ray hits you!"); 2423. fall_asleep(-rnd(50), TRUE); 2424. } 2425. break; 2426. 2427. case WAN_SLOW_MONSTER: 2428. case SPE_SLOW_MONSTER: 2429. if (HFast & (TIMEOUT | INTRINSIC)) { 2430. learn_it = TRUE; 2431. u_slow_down(); 2432. } 2433. break; 2434. 2435. case WAN_TELEPORTATION: 2436. case SPE_TELEPORT_AWAY: 2437. tele(); 2438. /* same criteria as when mounted (zap_steed) */ 2439. if ((Teleport_control && !Stunned) || !couldsee(u.ux0, u.uy0) 2440. || distu(u.ux0, u.uy0) >= 16) 2441. learn_it = TRUE; 2442. break; 2443. 2444. case WAN_DEATH: 2445. case SPE_FINGER_OF_DEATH: 2446. if (nonliving(youmonst.data) || is_demon(youmonst.data)) { 2447. pline((obj->otyp == WAN_DEATH) 2448. ? "The wand shoots an apparently harmless beam at you." 2449. : "You seem no deader than before."); 2450. break; 2451. } 2452. learn_it = TRUE; 2453. Sprintf(killer.name, "shot %sself with a death ray", uhim()); 2454. killer.format = NO_KILLER_PREFIX; 2455. You("irradiate yourself with pure energy!"); 2456. You("die."); 2457. /* They might survive with an amulet of life saving */ 2458. done(DIED); 2459. break; 2460. case WAN_UNDEAD_TURNING: 2461. case SPE_TURN_UNDEAD: 2462. learn_it = TRUE; 2463. (void) unturn_dead(&youmonst); 2464. if (is_undead(youmonst.data)) { 2465. You_feel("frightened and %sstunned.", 2466. Stunned ? "even more " : ""); 2467. make_stunned((HStun & TIMEOUT) + (long) rnd(30), FALSE); 2468. } else 2469. You("shudder in dread."); 2470. break; 2471. case SPE_HEALING: 2472. case SPE_EXTRA_HEALING: 2473. learn_it = TRUE; /* (no effect for spells...) */ 2474. healup(d(6, obj->otyp == SPE_EXTRA_HEALING ? 8 : 4), 0, FALSE, 2475. (obj->blessed || obj->otyp == SPE_EXTRA_HEALING)); 2476. You_feel("%sbetter.", obj->otyp == SPE_EXTRA_HEALING ? "much " : ""); 2477. break; 2478. case WAN_LIGHT: /* (broken wand) */ 2479. /* assert( !ordinary ); */ 2480. damage = d(obj->spe, 25); 2481. /*FALLTHRU*/ 2482. case EXPENSIVE_CAMERA: 2483. if (!damage) 2484. damage = 5; 2485. damage = lightdamage(obj, ordinary, damage); 2486. damage += rnd(25); 2487. if (flashburn((long) damage)) 2488. learn_it = TRUE; 2489. damage = 0; /* reset */ 2490. break; 2491. case WAN_OPENING: 2492. case SPE_KNOCK: 2493. if (Punished) { 2494. learn_it = TRUE; 2495. unpunish(); 2496. } 2497. if (u.utrap) { /* escape web or bear trap */ 2498. (void) openholdingtrap(&youmonst, &learn_it); 2499. } else { 2500. struct obj *otmp; 2501. /* unlock carried boxes */ 2502. for (otmp = invent; otmp; otmp = otmp->nobj) 2503. if (Is_box(otmp)) 2504. (void) boxlock(otmp, obj); 2505. /* trigger previously escaped trapdoor */ 2506. (void) openfallingtrap(&youmonst, TRUE, &learn_it); 2507. } 2508. break; 2509. case WAN_LOCKING: 2510. case SPE_WIZARD_LOCK: 2511. if (!u.utrap) { 2512. (void) closeholdingtrap(&youmonst, &learn_it); 2513. } 2514. break; 2515. case WAN_DIGGING: 2516. case SPE_DIG: 2517. case SPE_DETECT_UNSEEN: 2518. case WAN_NOTHING: 2519. break; 2520. case WAN_PROBING: { 2521. struct obj *otmp; 2522. 2523. for (otmp = invent; otmp; otmp = otmp->nobj) { 2524. otmp->dknown = 1; 2525. if (Is_container(otmp) || otmp->otyp == STATUE) { 2526. otmp->lknown = 1; 2527. if (!SchroedingersBox(otmp)) 2528. otmp->cknown = 1; 2529. } 2530. } 2531. learn_it = TRUE; 2532. ustatusline(); 2533. break; 2534. } 2535. case SPE_STONE_TO_FLESH: { 2536. struct obj *otmp, *onxt; 2537. boolean didmerge; 2538. 2539. if (u.umonnum == PM_STONE_GOLEM) { 2540. learn_it = TRUE; 2541. (void) polymon(PM_FLESH_GOLEM); 2542. } 2543. if (Stoned) { 2544. learn_it = TRUE; 2545. fix_petrification(); /* saved! */ 2546. } 2547. /* but at a cost.. */ 2548. for (otmp = invent; otmp; otmp = onxt) { 2549. onxt = otmp->nobj; 2550. if (bhito(otmp, obj)) 2551. learn_it = TRUE; 2552. } 2553. /* 2554. * It is possible that we can now merge some inventory. 2555. * Do a highly paranoid merge. Restart from the beginning 2556. * until no merges. 2557. */ 2558. do { 2559. didmerge = FALSE; 2560. for (otmp = invent; !didmerge && otmp; otmp = otmp->nobj) 2561. for (onxt = otmp->nobj; onxt; onxt = onxt->nobj) 2562. if (merged(&otmp, &onxt)) { 2563. didmerge = TRUE; 2564. break; 2565. } 2566. } while (didmerge); 2567. break; 2568. } 2569. default: 2570. impossible("zapyourself: object %d used?", obj->otyp); 2571. break; 2572. } 2573. /* if effect was observable then discover the wand type provided 2574. that the wand itself has been seen */ 2575. if (learn_it) 2576. learnwand(obj); 2577. return damage; 2578. } 2579. 2580. /* called when poly'd hero uses breath attack against self */ 2581. void 2582. ubreatheu(mattk) 2583. struct attack *mattk; 2584. { 2585. int dtyp = 20 + mattk->adtyp - 1; /* breath by hero */ 2586. const char *fltxt = flash_types[dtyp]; /* blast of <something> */ 2587. 2588. zhitu(dtyp, mattk->damn, fltxt, u.ux, u.uy); 2589. } 2590. 2591. /* light damages hero in gremlin form */ 2592. int 2593. lightdamage(obj, ordinary, amt) 2594. struct obj *obj; /* item making light (fake book if spell) */ 2595. boolean ordinary; /* wand/camera zap vs wand destruction */ 2596. int amt; /* pseudo-damage used to determine blindness duration */ 2597. { 2598. char buf[BUFSZ]; 2599. const char *how; 2600. int dmg = amt; 2601. 2602. if (dmg && youmonst.data == &mons[PM_GREMLIN]) { 2603. /* reduce high values (from destruction of wand with many charges) */ 2604. dmg = rnd(dmg); 2605. if (dmg > 10) 2606. dmg = 10 + rnd(dmg - 10); 2607. if (dmg > 20) 2608. dmg = 20; 2609. pline("Ow, that light hurts%c", (dmg > 2 || u.mh <= 5) ? '!' : '.'); 2610. /* [composing killer/reason is superfluous here; if fatal, cause 2611. of death will always be "killed while stuck in creature form"] */ 2612. if (obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS) 2613. ordinary = FALSE; /* say blasted rather than zapped */ 2614. how = (obj->oclass != SPBOOK_CLASS) 2615. ? (const char *) ansimpleoname(obj) 2616. : "spell of light"; 2617. Sprintf(buf, "%s %sself with %s", ordinary ? "zapped" : "blasted", 2618. uhim(), how); 2619. /* might rehumanize(); could be fatal, but only for Unchanging */ 2620. losehp(Maybe_Half_Phys(dmg), buf, NO_KILLER_PREFIX); 2621. } 2622. return dmg; 2623. } 2624. 2625. /* light[ning] causes blindness */ 2626. boolean 2627. flashburn(duration) 2628. long duration; 2629. { 2630. if (!resists_blnd(&youmonst)) { 2631. You(are_blinded_by_the_flash); 2632. make_blinded(duration, FALSE); 2633. if (!Blind) 2634. Your1(vision_clears); 2635. return TRUE; 2636. } 2637. return FALSE; 2638. } 2639. 2640. /* you've zapped a wand downwards while riding 2641. * Return TRUE if the steed was hit by the wand. 2642. * Return FALSE if the steed was not hit by the wand. 2643. */ 2644. STATIC_OVL boolean 2645. zap_steed(obj) 2646. struct obj *obj; /* wand or spell */ 2647. { 2648. int steedhit = FALSE; 2649. 2650. bhitpos.x = u.usteed->mx, bhitpos.y = u.usteed->my; 2651. notonhead = FALSE; 2652. switch (obj->otyp) { 2653. /* 2654. * Wands that are allowed to hit the steed 2655. * Carefully test the results of any that are 2656. * moved here from the bottom section. 2657. */ 2658. case WAN_PROBING: 2659. probe_monster(u.usteed); 2660. learnwand(obj); 2661. steedhit = TRUE; 2662. break; 2663. case WAN_TELEPORTATION: 2664. case SPE_TELEPORT_AWAY: 2665. /* you go together */ 2666. tele(); 2667. /* same criteria as when unmounted (zapyourself) */ 2668. if ((Teleport_control && !Stunned) || !couldsee(u.ux0, u.uy0) 2669. || distu(u.ux0, u.uy0) >= 16) 2670. learnwand(obj); 2671. steedhit = TRUE; 2672. break; 2673. 2674. /* Default processing via bhitm() for these */ 2675. case SPE_CURE_SICKNESS: 2676. case WAN_MAKE_INVISIBLE: 2677. case WAN_CANCELLATION: 2678. case SPE_CANCELLATION: 2679. case WAN_POLYMORPH: 2680. case SPE_POLYMORPH: 2681. case WAN_STRIKING: 2682. case SPE_FORCE_BOLT: 2683. case WAN_SLOW_MONSTER: 2684. case SPE_SLOW_MONSTER: 2685. case WAN_SPEED_MONSTER: 2686. case SPE_HEALING: 2687. case SPE_EXTRA_HEALING: 2688. case SPE_DRAIN_LIFE: 2689. case WAN_OPENING: 2690. case SPE_KNOCK: 2691. (void) bhitm(u.usteed, obj); 2692. steedhit = TRUE; 2693. break; 2694. 2695. default: 2696. steedhit = FALSE; 2697. break; 2698. } 2699. return steedhit; 2700. } 2701. 2702. /* 2703. * cancel a monster (possibly the hero). inventory is cancelled only 2704. * if the monster is zapping itself directly, since otherwise the 2705. * effect is too strong. currently non-hero monsters do not zap 2706. * themselves with cancellation. 2707. */ 2708. boolean 2709. cancel_monst(mdef, obj, youattack, allow_cancel_kill, self_cancel) 2710. register struct monst *mdef; 2711. register struct obj *obj; 2712. boolean youattack, allow_cancel_kill, self_cancel; 2713. { 2714. boolean youdefend = (mdef == &youmonst); 2715. static const char writing_vanishes[] = 2716. "Some writing vanishes from %s head!"; 2717. static const char your[] = "your"; /* should be extern */ 2718. 2719. if (youdefend ? (!youattack && Antimagic) 2720. : resist(mdef, obj->oclass, 0, NOTELL)) 2721. return FALSE; /* resisted cancellation */ 2722. 2723. if (self_cancel) { /* 1st cancel inventory */ 2724. struct obj *otmp; 2725. 2726. for (otmp = (youdefend ? invent : mdef->minvent); otmp; 2727. otmp = otmp->nobj) 2728. cancel_item(otmp); 2729. if (youdefend) { 2730. context.botl = 1; /* potential AC change */ 2731. find_ac(); 2732. } 2733. } 2734. 2735. /* now handle special cases */ 2736. if (youdefend) { 2737. if (Upolyd) { /* includes lycanthrope in creature form */ 2738. /* 2739. * Return to normal form unless Unchanging. 2740. * Hero in clay golem form dies if Unchanging. 2741. * Does not cure lycanthropy or stop timed random polymorph. 2742. */ 2743. if (u.umonnum == PM_CLAY_GOLEM) { 2744. if (!Blind) 2745. pline(writing_vanishes, your); 2746. else /* note: "dark" rather than "heavy" is intentional... */ 2747. You_feel("%s headed.", Hallucination ? "dark" : "light"); 2748. u.mh = 0; /* fatal; death handled by rehumanize() */ 2749. } 2750. if (Unchanging && u.mh > 0) 2751. Your("amulet grows hot for a moment, then cools."); 2752. else 2753. rehumanize(); 2754. } 2755. } else { 2756. mdef->mcan = 1; 2757. /* force shapeshifter into its base form */ 2758. if (M_AP_TYPE(mdef) != M_AP_NOTHING) 2759. seemimic(mdef); 2760. /* [not 'else if'; chameleon might have been hiding as a mimic] */ 2761. if (mdef->cham >= LOW_PM) { 2762. /* note: newcham() uncancels shapechangers (resets m->mcan 2763. to 0), but only for shapechangers whose m->cham is already 2764. NON_PM and we just verified that it's LOW_PM or higher */ 2765. newcham(mdef, &mons[mdef->cham], FALSE, FALSE); 2766. mdef->cham = NON_PM; /* cancelled shapeshifter can't shift */ 2767. } 2768. if (is_were(mdef->data) && !is_human(mdef->data)) 2769. were_change(mdef); 2770. 2771. if (mdef->data == &mons[PM_CLAY_GOLEM]) { 2772. if (canseemon(mdef)) 2773. pline(writing_vanishes, s_suffix(mon_nam(mdef))); 2774. /* !allow_cancel_kill is for Magicbane, where clay golem 2775. will be killed somewhere back up the call/return chain... */ 2776. if (allow_cancel_kill) { 2777. if (youattack) 2778. killed(mdef); 2779. else 2780. monkilled(mdef, "", AD_SPEL); 2781. } 2782. } 2783. } 2784. return TRUE; 2785. } 2786. 2787. /* you've zapped an immediate type wand up or down */ 2788. STATIC_OVL boolean 2789. zap_updown(obj) 2790. struct obj *obj; /* wand or spell */ 2791. { 2792. boolean striking = FALSE, disclose = FALSE; 2793. int x, y, xx, yy, ptmp; 2794. struct obj *otmp; 2795. struct engr *e; 2796. struct trap *ttmp; 2797. char buf[BUFSZ]; 2798. 2799. /* some wands have special effects other than normal bhitpile */ 2800. /* drawbridge might change <u.ux,u.uy> */ 2801. x = xx = u.ux; /* <x,y> is zap location */ 2802. y = yy = u.uy; /* <xx,yy> is drawbridge (portcullis) position */ 2803. ttmp = t_at(x, y); /* trap if there is one */ 2804. 2805. switch (obj->otyp) { 2806. case WAN_PROBING: 2807. ptmp = 0; 2808. if (u.dz < 0) { 2809. You("probe towards the %s.", ceiling(x, y)); 2810. } else { 2811. ptmp += bhitpile(obj, bhito, x, y, u.dz); 2812. You("probe beneath the %s.", surface(x, y)); 2813. ptmp += display_binventory(x, y, TRUE); 2814. } 2815. if (!ptmp) 2816. Your("probe reveals nothing."); 2817. return TRUE; /* we've done our own bhitpile */ 2818. case WAN_OPENING: 2819. case SPE_KNOCK: 2820. /* up or down, but at closed portcullis only */ 2821. if (is_db_wall(x, y) && find_drawbridge(&xx, &yy)) { 2822. open_drawbridge(xx, yy); 2823. disclose = TRUE; 2824. } else if (u.dz > 0 && (x == xdnstair && y == ydnstair) 2825. /* can't use the stairs down to quest level 2 until 2826. leader "unlocks" them; give feedback if you try */ 2827. && on_level(&u.uz, &qstart_level) && !ok_to_quest()) { 2828. pline_The("stairs seem to ripple momentarily."); 2829. disclose = TRUE; 2830. } 2831. /* down will release you from bear trap or web */ 2832. if (u.dz > 0 && u.utrap) { 2833. (void) openholdingtrap(&youmonst, &disclose); 2834. /* down will trigger trapdoor, hole, or [spiked-] pit */ 2835. } else if (u.dz > 0 && !u.utrap) { 2836. (void) openfallingtrap(&youmonst, FALSE, &disclose); 2837. } 2838. break; 2839. case WAN_STRIKING: 2840. case SPE_FORCE_BOLT: 2841. striking = TRUE; 2842. /*FALLTHRU*/ 2843. case WAN_LOCKING: 2844. case SPE_WIZARD_LOCK: 2845. /* down at open bridge or up or down at open portcullis */ 2846. if (((levl[x][y].typ == DRAWBRIDGE_DOWN) 2847. ? (u.dz > 0) 2848. : (is_drawbridge_wall(x, y) >= 0 && !is_db_wall(x, y))) 2849. && find_drawbridge(&xx, &yy)) { 2850. if (!striking) 2851. close_drawbridge(xx, yy); 2852. else 2853. destroy_drawbridge(xx, yy); 2854. disclose = TRUE; 2855. } else if (striking && u.dz < 0 && rn2(3) && !Is_airlevel(&u.uz) 2856. && !Is_waterlevel(&u.uz) && !Underwater 2857. && !Is_qstart(&u.uz)) { 2858. int dmg; 2859. /* similar to zap_dig() */ 2860. pline("A rock is dislodged from the %s and falls on your %s.", 2861. ceiling(x, y), body_part(HEAD)); 2862. dmg = rnd((uarmh && is_metallic(uarmh)) ? 2 : 6); 2863. losehp(Maybe_Half_Phys(dmg), "falling rock", KILLED_BY_AN); 2864. if ((otmp = mksobj_at(ROCK, x, y, FALSE, FALSE)) != 0) { 2865. (void) xname(otmp); /* set dknown, maybe bknown */ 2866. stackobj(otmp); 2867. } 2868. newsym(x, y); 2869. } else if (u.dz > 0 && ttmp) { 2870. if (!striking && closeholdingtrap(&youmonst, &disclose)) { 2871. ; /* now stuck in web or bear trap */ 2872. } else if (striking && ttmp->ttyp == TRAPDOOR) { 2873. /* striking transforms trapdoor into hole */ 2874. if (Blind && !ttmp->tseen) { 2875. pline("%s beneath you shatters.", Something); 2876. } else if (!ttmp->tseen) { /* => !Blind */ 2877. pline("There's a trapdoor beneath you; it shatters."); 2878. } else { 2879. pline("The trapdoor beneath you shatters."); 2880. disclose = TRUE; 2881. } 2882. ttmp->ttyp = HOLE; 2883. ttmp->tseen = 1; 2884. newsym(x, y); 2885. /* might fall down hole */ 2886. dotrap(ttmp, 0); 2887. } else if (!striking && ttmp->ttyp == HOLE) { 2888. /* locking transforms hole into trapdoor */ 2889. ttmp->ttyp = TRAPDOOR; 2890. if (Blind || !ttmp->tseen) { 2891. pline("Some %s swirls beneath you.", 2892. is_ice(x, y) ? "frost" : "dust"); 2893. } else { 2894. ttmp->tseen = 1; 2895. newsym(x, y); 2896. pline("A trapdoor appears beneath you."); 2897. disclose = TRUE; 2898. } 2899. /* hadn't fallen down hole; won't fall now */ 2900. } 2901. } 2902. break; 2903. case SPE_STONE_TO_FLESH: 2904. if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz) || Underwater 2905. || (Is_qstart(&u.uz) && u.dz < 0)) { 2906. pline1(nothing_happens); 2907. } else if (u.dz < 0) { /* we should do more... */ 2908. pline("Blood drips on your %s.", body_part(FACE)); 2909. } else if (u.dz > 0 && !OBJ_AT(u.ux, u.uy)) { 2910. /* 2911. Print this message only if there wasn't an engraving 2912. affected here. If water or ice, act like waterlevel case. 2913. */ 2914. e = engr_at(u.ux, u.uy); 2915. if (!(e && e->engr_type == ENGRAVE)) { 2916. if (is_pool(u.ux, u.uy) || is_ice(u.ux, u.uy)) 2917. pline1(nothing_happens); 2918. else 2919. pline("Blood %ss %s your %s.", 2920. is_lava(u.ux, u.uy) ? "boil" : "pool", 2921. Levitation ? "beneath" : "at", 2922. makeplural(body_part(FOOT))); 2923. } 2924. } 2925. break; 2926. default: 2927. break; 2928. } 2929. 2930. if (u.dz > 0) { 2931. /* zapping downward */ 2932. (void) bhitpile(obj, bhito, x, y, u.dz); 2933. 2934. /* subset of engraving effects; none sets `disclose' */ 2935. if ((e = engr_at(x, y)) != 0 && e->engr_type != HEADSTONE) { 2936. switch (obj->otyp) { 2937. case WAN_POLYMORPH: 2938. case SPE_POLYMORPH: 2939. del_engr(e); 2940. make_engr_at(x, y, random_engraving(buf), moves, (xchar) 0); 2941. break; 2942. case WAN_CANCELLATION: 2943. case SPE_CANCELLATION: 2944. case WAN_MAKE_INVISIBLE: 2945. del_engr(e); 2946. break; 2947. case WAN_TELEPORTATION: 2948. case SPE_TELEPORT_AWAY: 2949. rloc_engr(e); 2950. break; 2951. case SPE_STONE_TO_FLESH: 2952. if (e->engr_type == ENGRAVE) { 2953. /* only affects things in stone */ 2954. pline_The(Hallucination 2955. ? "floor runs like butter!" 2956. : "edges on the floor get smoother."); 2957. wipe_engr_at(x, y, d(2, 4), TRUE); 2958. } 2959. break; 2960. case WAN_STRIKING: 2961. case SPE_FORCE_BOLT: 2962. wipe_engr_at(x, y, d(2, 4), TRUE); 2963. break; 2964. default: 2965. break; 2966. } 2967. } 2968. } else if (u.dz < 0) { 2969. /* zapping upward */ 2970. 2971. /* game flavor: if you're hiding under "something" 2972. * a zap upward should hit that "something". 2973. */ 2974. if (u.uundetected && hides_under(youmonst.data)) { 2975. int hitit = 0; 2976. otmp = level.objects[u.ux][u.uy]; 2977. 2978. if (otmp) 2979. hitit = bhito(otmp, obj); 2980. if (hitit) { 2981. (void) hideunder(&youmonst); 2982. disclose = TRUE; 2983. } 2984. } 2985. } 2986. 2987. return disclose; 2988. } 2989. 2990. /* used by do_break_wand() was well as by weffects() */ 2991. void 2992. zapsetup() 2993. { 2994. obj_zapped = FALSE; 2995. } 2996. 2997. void 2998. zapwrapup() 2999. { 3000. /* if do_osshock() set obj_zapped while polying, give a message now */ 3001. if (obj_zapped) 3002. You_feel("shuddering vibrations."); 3003. obj_zapped = FALSE; 3004. } 3005. 3006. /* called for various wand and spell effects - M. Stephenson */ 3007. void 3008. weffects(obj) 3009. struct obj *obj; 3010. { 3011. int otyp = obj->otyp; 3012. boolean disclose = FALSE, was_unkn = !objects[otyp].oc_name_known; 3013. 3014. exercise(A_WIS, TRUE); 3015. if (u.usteed && (objects[otyp].oc_dir != NODIR) && !u.dx && !u.dy 3016. && (u.dz > 0) && zap_steed(obj)) { 3017. disclose = TRUE; 3018. } else if (objects[otyp].oc_dir == IMMEDIATE) { 3019. zapsetup(); /* reset obj_zapped */ 3020. if (u.uswallow) { 3021. (void) bhitm(u.ustuck, obj); 3022. /* [how about `bhitpile(u.ustuck->minvent)' effect?] */ 3023. } else if (u.dz) { 3024. disclose = zap_updown(obj); 3025. } else { 3026. (void) bhit(u.dx, u.dy, rn1(8, 6), ZAPPED_WAND, bhitm, bhito, 3027. &obj); 3028. } 3029. zapwrapup(); /* give feedback for obj_zapped */ 3030. 3031. } else if (objects[otyp].oc_dir == NODIR) { 3032. zapnodir(obj); 3033. 3034. } else { 3035. /* neither immediate nor directionless */ 3036. 3037. if (otyp == WAN_DIGGING || otyp == SPE_DIG) 3038. zap_dig(); 3039. else if (otyp >= SPE_MAGIC_MISSILE && otyp <= SPE_FINGER_OF_DEATH) 3040. buzz(otyp - SPE_MAGIC_MISSILE + 10, u.ulevel / 2 + 1, u.ux, u.uy, 3041. u.dx, u.dy); 3042. else if (otyp >= WAN_MAGIC_MISSILE && otyp <= WAN_LIGHTNING) 3043. buzz(otyp - WAN_MAGIC_MISSILE, 3044. (otyp == WAN_MAGIC_MISSILE) ? 2 : 6, u.ux, u.uy, u.dx, u.dy); 3045. else 3046. impossible("weffects: unexpected spell or wand"); 3047. disclose = TRUE; 3048. } 3049. if (disclose) { 3050. learnwand(obj); 3051. if (was_unkn) 3052. more_experienced(0, 10); 3053. } 3054. return; 3055. } 3056. 3057. /* augment damage for a spell dased on the hero's intelligence (and level) */ 3058. int 3059. spell_damage_bonus(dmg) 3060. int dmg; /* base amount to be adjusted by bonus or penalty */ 3061. { 3062. int intell = ACURR(A_INT); 3063. 3064. /* Punish low intelligence before low level else low intelligence 3065. gets punished only when high level */ 3066. if (intell <= 9) { 3067. /* -3 penalty, but never reduce combined amount below 1 3068. (if dmg is 0 for some reason, we're careful to leave it there) */ 3069. if (dmg > 1) 3070. dmg = (dmg <= 3) ? 1 : dmg - 3; 3071. } else if (intell <= 13 || u.ulevel < 5) 3072. ; /* no bonus or penalty; dmg remains same */ 3073. else if (intell <= 18) 3074. dmg += 1; 3075. else if (intell <= 24 || u.ulevel < 14) 3076. dmg += 2; 3077. else 3078. dmg += 3; /* Int 25 */ 3079. 3080. return dmg; 3081. } 3082. 3083. /* 3084. * Generate the to hit bonus for a spell. Based on the hero's skill in 3085. * spell class and dexterity. 3086. */ 3087. STATIC_OVL int 3088. spell_hit_bonus(skill) 3089. int skill; 3090. { 3091. int hit_bon = 0; 3092. int dex = ACURR(A_DEX); 3093. 3094. switch (P_SKILL(spell_skilltype(skill))) { 3095. case P_ISRESTRICTED: 3096. case P_UNSKILLED: 3097. hit_bon = -4; 3098. break; 3099. case P_BASIC: 3100. hit_bon = 0; 3101. break; 3102. case P_SKILLED: 3103. hit_bon = 2; 3104. break; 3105. case P_EXPERT: 3106. hit_bon = 3; 3107. break; 3108. } 3109. 3110. if (dex < 4) 3111. hit_bon -= 3; 3112. else if (dex < 6) 3113. hit_bon -= 2; 3114. else if (dex < 8) 3115. hit_bon -= 1; 3116. else if (dex < 14) 3117. /* Will change when print stuff below removed */ 3118. hit_bon -= 0; 3119. else 3120. /* Even increment for dextrous heroes (see weapon.c abon) */ 3121. hit_bon += dex - 14; 3122. 3123. return hit_bon; 3124. } 3125. 3126. const char * 3127. exclam(force) 3128. int force; 3129. { 3130. /* force == 0 occurs e.g. with sleep ray */ 3131. /* note that large force is usual with wands so that !! would 3132. require information about hand/weapon/wand */ 3133. return (const char *) ((force < 0) ? "?" : (force <= 4) ? "." : "!"); 3134. } 3135. 3136. void 3137. hit(str, mtmp, force) 3138. const char *str; 3139. struct monst *mtmp; 3140. const char *force; /* usually either "." or "!" */ 3141. { 3142. if ((!cansee(bhitpos.x, bhitpos.y) && !canspotmon(mtmp) 3143. && !(u.uswallow && mtmp == u.ustuck)) || !flags.verbose) 3144. pline("%s %s it.", The(str), vtense(str, "hit")); 3145. else 3146. pline("%s %s %s%s", The(str), vtense(str, "hit"), 3147. mon_nam(mtmp), force); 3148. } 3149. 3150. void 3151. miss(str, mtmp) 3152. register const char *str; 3153. register struct monst *mtmp; 3154. { 3155. pline( 3156. "%s %s %s.", The(str), vtense(str, "miss"), 3157. ((cansee(bhitpos.x, bhitpos.y) || canspotmon(mtmp)) && flags.verbose) 3158. ? mon_nam(mtmp) 3159. : "it"); 3160. } 3161. 3162. STATIC_OVL void 3163. skiprange(range, skipstart, skipend) 3164. int range, *skipstart, *skipend; 3165. { 3166. int tr = (range / 4); 3167. int tmp = range - ((tr > 0) ? rnd(tr) : 0); 3168. 3169. *skipstart = tmp; 3170. *skipend = tmp - ((tmp / 4) * rnd(3)); 3171. if (*skipend >= tmp) 3172. *skipend = tmp - 1; 3173. } 3174. 3175. /* 3176. * Called for the following distance effects: 3177. * when a weapon is thrown (weapon == THROWN_WEAPON) 3178. * when an object is kicked (KICKED_WEAPON) 3179. * when an IMMEDIATE wand is zapped (ZAPPED_WAND) 3180. * when a light beam is flashed (FLASHED_LIGHT) 3181. * when a mirror is applied (INVIS_BEAM) 3182. * A thrown/kicked object falls down at end of its range or when a monster 3183. * is hit. The variable 'bhitpos' is set to the final position of the weapon 3184. * thrown/zapped. The ray of a wand may affect (by calling a provided 3185. * function) several objects and monsters on its path. The return value 3186. * is the monster hit (weapon != ZAPPED_WAND), or a null monster pointer. 3187. * 3188. * Thrown and kicked objects (THROWN_WEAPON or KICKED_WEAPON) may be 3189. * destroyed and *pobj set to NULL to indicate this. 3190. * 3191. * Check !u.uswallow before calling bhit(). 3192. * This function reveals the absence of a remembered invisible monster in 3193. * necessary cases (throwing or kicking weapons). The presence of a real 3194. * one is revealed for a weapon, but if not a weapon is left up to fhitm(). 3195. */ 3196. struct monst * 3197. bhit(ddx, ddy, range, weapon, fhitm, fhito, pobj) 3198. register int ddx, ddy, range; /* direction and range */ 3199. enum bhit_call_types weapon; /* defined in hack.h */ 3200. int FDECL((*fhitm), (MONST_P, OBJ_P)), /* fns called when mon/obj hit */ 3201. FDECL((*fhito), (OBJ_P, OBJ_P)); 3202. struct obj **pobj; /* object tossed/used, set to NULL 3203. * if object is destroyed */ 3204. { 3205. struct monst *mtmp; 3206. struct obj *obj = *pobj; 3207. uchar typ; 3208. boolean shopdoor = FALSE, point_blank = TRUE; 3209. boolean in_skip = FALSE, allow_skip = FALSE; 3210. boolean tethered_weapon = FALSE; 3211. int skiprange_start = 0, skiprange_end = 0, skipcount = 0; 3212. 3213. if (weapon == KICKED_WEAPON) { 3214. /* object starts one square in front of player */ 3215. bhitpos.x = u.ux + ddx; 3216. bhitpos.y = u.uy + ddy; 3217. range--; 3218. } else { 3219. bhitpos.x = u.ux; 3220. bhitpos.y = u.uy; 3221. } 3222. 3223. if (weapon == THROWN_WEAPON && obj && obj->otyp == ROCK) { 3224. skiprange(range, &skiprange_start, &skiprange_end); 3225. allow_skip = !rn2(3); 3226. } 3227. 3228. if (weapon == FLASHED_LIGHT) { 3229. tmp_at(DISP_BEAM, cmap_to_glyph(S_flashbeam)); 3230. } else if (weapon == THROWN_TETHERED_WEAPON && obj) { 3231. tethered_weapon = TRUE; 3232. weapon = THROWN_WEAPON; /* simplify if's that follow below */ 3233. tmp_at(DISP_TETHER, obj_to_glyph(obj, rn2_on_display_rng)); 3234. } else if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM) 3235. tmp_at(DISP_FLASH, obj_to_glyph(obj, rn2_on_display_rng)); 3236. 3237. while (range-- > 0) { 3238. int x, y; 3239. 3240. bhitpos.x += ddx; 3241. bhitpos.y += ddy; 3242. x = bhitpos.x; 3243. y = bhitpos.y; 3244. 3245. if (!isok(x, y)) { 3246. bhitpos.x -= ddx; 3247. bhitpos.y -= ddy; 3248. break; 3249. } 3250. 3251. if (is_pick(obj) && inside_shop(x, y) 3252. && (mtmp = shkcatch(obj, x, y)) != 0) { 3253. tmp_at(DISP_END, 0); 3254. return mtmp; 3255. } 3256. 3257. typ = levl[bhitpos.x][bhitpos.y].typ; 3258. 3259. /* iron bars will block anything big enough */ 3260. if ((weapon == THROWN_WEAPON || weapon == KICKED_WEAPON) 3261. && typ == IRONBARS 3262. && hits_bars(pobj, x - ddx, y - ddy, bhitpos.x, bhitpos.y, 3263. point_blank ? 0 : !rn2(5), 1)) { 3264. /* caveat: obj might now be null... */ 3265. obj = *pobj; 3266. bhitpos.x -= ddx; 3267. bhitpos.y -= ddy; 3268. break; 3269. } 3270. 3271. if (weapon == ZAPPED_WAND && find_drawbridge(&x, &y)) { 3272. boolean learn_it = FALSE; 3273. 3274. switch (obj->otyp) { 3275. case WAN_OPENING: 3276. case SPE_KNOCK: 3277. if (is_db_wall(bhitpos.x, bhitpos.y)) { 3278. if (cansee(x, y) || cansee(bhitpos.x, bhitpos.y)) 3279. learn_it = TRUE; 3280. open_drawbridge(x, y); 3281. } 3282. break; 3283. case WAN_LOCKING: 3284. case SPE_WIZARD_LOCK: 3285. if ((cansee(x, y) || cansee(bhitpos.x, bhitpos.y)) 3286. && levl[x][y].typ == DRAWBRIDGE_DOWN) 3287. learn_it = TRUE; 3288. close_drawbridge(x, y); 3289. break; 3290. case WAN_STRIKING: 3291. case SPE_FORCE_BOLT: 3292. if (typ != DRAWBRIDGE_UP) 3293. destroy_drawbridge(x, y); 3294. learn_it = TRUE; 3295. break; 3296. } 3297. if (learn_it) 3298. learnwand(obj); 3299. } 3300. 3301. mtmp = m_at(bhitpos.x, bhitpos.y); 3302. 3303. /* 3304. * skipping rocks 3305. * 3306. * skiprange_start is only set if this is a thrown rock 3307. */ 3308. if (skiprange_start && (range == skiprange_start) && allow_skip) { 3309. if (is_pool(bhitpos.x, bhitpos.y) && !mtmp) { 3310. in_skip = TRUE; 3311. if (!Blind) 3312. pline("%s %s%s.", Yname2(obj), otense(obj, "skip"), 3313. skipcount ? " again" : ""); 3314. else 3315. You_hear("%s skip.", yname(obj)); 3316. skipcount++; 3317. } else if (skiprange_start > skiprange_end + 1) { 3318. --skiprange_start; 3319. } 3320. } 3321. if (in_skip) { 3322. if (range <= skiprange_end) { 3323. in_skip = FALSE; 3324. if (range > 3) /* another bounce? */ 3325. skiprange(range, &skiprange_start, &skiprange_end); 3326. } else if (mtmp && M_IN_WATER(mtmp->data)) { 3327. if ((!Blind && canseemon(mtmp)) || sensemon(mtmp)) 3328. pline("%s %s over %s.", Yname2(obj), otense(obj, "pass"), 3329. mon_nam(mtmp)); 3330. } 3331. } 3332. 3333. if (mtmp && !(in_skip && M_IN_WATER(mtmp->data))) { 3334. notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my); 3335. if (weapon == FLASHED_LIGHT) { 3336. /* FLASHED_LIGHT hitting invisible monster should 3337. pass through instead of stop so we call 3338. flash_hits_mon() directly rather than returning 3339. mtmp back to caller. That allows the flash to 3340. keep on going. Note that we use mtmp->minvis 3341. not canspotmon() because it makes no difference 3342. whether the hero can see the monster or not. */ 3343. if (mtmp->minvis) { 3344. obj->ox = u.ux, obj->oy = u.uy; 3345. (void) flash_hits_mon(mtmp, obj); 3346. } else { 3347. tmp_at(DISP_END, 0); 3348. return mtmp; /* caller will call flash_hits_mon */ 3349. } 3350. } else if (weapon == INVIS_BEAM) { 3351. /* Like FLASHED_LIGHT, INVIS_BEAM should continue 3352. through invisible targets; unlike it, we aren't 3353. prepared for multiple hits so just get first one 3354. that's either visible or could see its invisible 3355. self. [No tmp_at() cleanup is needed here.] */ 3356. if (!mtmp->minvis || perceives(mtmp->data)) 3357. return mtmp; 3358. } else if (weapon != ZAPPED_WAND) { 3359. 3360. /* THROWN_WEAPON, KICKED_WEAPON */ 3361. if (!tethered_weapon) 3362. tmp_at(DISP_END, 0); 3363. 3364. if (cansee(bhitpos.x, bhitpos.y) && !canspotmon(mtmp)) 3365. map_invisible(bhitpos.x, bhitpos.y); 3366. return mtmp; 3367. } else { 3368. /* ZAPPED_WAND */ 3369. (*fhitm)(mtmp, obj); 3370. range -= 3; 3371. } 3372. } else { 3373. if (weapon == ZAPPED_WAND && obj->otyp == WAN_PROBING 3374. && glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph)) { 3375. unmap_object(bhitpos.x, bhitpos.y); 3376. newsym(x, y); 3377. } 3378. } 3379. if (fhito) { 3380. if (bhitpile(obj, fhito, bhitpos.x, bhitpos.y, 0)) 3381. range--; 3382. } else { 3383. if (weapon == KICKED_WEAPON 3384. && ((obj->oclass == COIN_CLASS 3385. && OBJ_AT(bhitpos.x, bhitpos.y)) 3386. || ship_object(obj, bhitpos.x, bhitpos.y, 3387. costly_spot(bhitpos.x, bhitpos.y)))) { 3388. tmp_at(DISP_END, 0); 3389. return (struct monst *) 0; 3390. } 3391. } 3392. if (weapon == ZAPPED_WAND && (IS_DOOR(typ) || typ == SDOOR)) { 3393. switch (obj->otyp) { 3394. case WAN_OPENING: 3395. case WAN_LOCKING: 3396. case WAN_STRIKING: 3397. case SPE_KNOCK: 3398. case SPE_WIZARD_LOCK: 3399. case SPE_FORCE_BOLT: 3400. if (doorlock(obj, bhitpos.x, bhitpos.y)) { 3401. if (cansee(bhitpos.x, bhitpos.y) 3402. || (obj->otyp == WAN_STRIKING && !Deaf)) 3403. learnwand(obj); 3404. if (levl[bhitpos.x][bhitpos.y].doormask == D_BROKEN 3405. && *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE)) { 3406. shopdoor = TRUE; 3407. add_damage(bhitpos.x, bhitpos.y, SHOP_DOOR_COST); 3408. } 3409. } 3410. break; 3411. } 3412. } 3413. if (!ZAP_POS(typ) || closed_door(bhitpos.x, bhitpos.y)) { 3414. bhitpos.x -= ddx; 3415. bhitpos.y -= ddy; 3416. break; 3417. } 3418. if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM) { 3419. /* 'I' present but no monster: erase */ 3420. /* do this before the tmp_at() */ 3421. if (glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph) 3422. && cansee(x, y)) { 3423. unmap_object(bhitpos.x, bhitpos.y); 3424. newsym(x, y); 3425. } 3426. tmp_at(bhitpos.x, bhitpos.y); 3427. delay_output(); 3428. /* kicked objects fall in pools */ 3429. if ((weapon == KICKED_WEAPON) 3430. && (is_pool(bhitpos.x, bhitpos.y) 3431. || is_lava(bhitpos.x, bhitpos.y))) 3432. break; 3433. if (IS_SINK(typ) && weapon != FLASHED_LIGHT) 3434. break; /* physical objects fall onto sink */ 3435. } 3436. /* limit range of ball so hero won't make an invalid move */ 3437. if (weapon == THROWN_WEAPON && range > 0 3438. && obj->otyp == HEAVY_IRON_BALL) { 3439. struct obj *bobj; 3440. struct trap *t; 3441. 3442. if ((bobj = sobj_at(BOULDER, x, y)) != 0) { 3443. if (cansee(x, y)) 3444. pline("%s hits %s.", The(distant_name(obj, xname)), 3445. an(xname(bobj))); 3446. range = 0; 3447. } else if (obj == uball) { 3448. if (!test_move(x - ddx, y - ddy, ddx, ddy, TEST_MOVE)) { 3449. /* nb: it didn't hit anything directly */ 3450. if (cansee(x, y)) 3451. pline("%s jerks to an abrupt halt.", 3452. The(distant_name(obj, xname))); /* lame */ 3453. range = 0; 3454. } else if (Sokoban && (t = t_at(x, y)) != 0 3455. && (is_pit(t->ttyp) || is_hole(t->ttyp))) { 3456. /* hero falls into the trap, so ball stops */ 3457. range = 0; 3458. } 3459. } 3460. } 3461. 3462. /* thrown/kicked missile has moved away from its starting spot */ 3463. point_blank = FALSE; /* affects passing through iron bars */ 3464. } 3465. 3466. if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM && !tethered_weapon) 3467. tmp_at(DISP_END, 0); 3468. 3469. if (shopdoor) 3470. pay_for_damage("destroy", FALSE); 3471. 3472. return (struct monst *) 0; 3473. } 3474. 3475. /* process thrown boomerang, which travels a curving path... 3476. * A multi-shot volley ought to have all missiles in flight at once, 3477. * but we're called separately for each one. We terminate the volley 3478. * early on a failed catch since continuing to throw after being hit 3479. * is too obviously silly. 3480. */ 3481. struct monst * 3482. boomhit(obj, dx, dy) 3483. struct obj *obj; 3484. int dx, dy; 3485. { 3486. register int i, ct; 3487. int boom; /* showsym[] index */ 3488. struct monst *mtmp; 3489. boolean counterclockwise = TRUE; /* right-handed throw */ 3490. 3491. /* counterclockwise traversal patterns: 3492. * ..........................54................................. 3493. * ..................43.....6..3....765......................... 3494. * ..........32.....5..2...7...2...8...4....87.................. 3495. * .........4..1....6..1...8..1....9...3...9..6.....98.......... 3496. * ..21@....5...@...7..@....9@......@12....@...5...@..7.....@9.. 3497. * .3...9....6..9....89.....................1..4...1..6....1..8. 3498. * .4...8.....78.............................23....2..5...2...7. 3499. * ..567............................................34....3..6.. 3500. * ........................................................45... 3501. * (invert rows for corresponding clockwise patterns) 3502. */ 3503. 3504. bhitpos.x = u.ux; 3505. bhitpos.y = u.uy; 3506. boom = counterclockwise ? S_boomleft : S_boomright; 3507. for (i = 0; i < 8; i++) 3508. if (xdir[i] == dx && ydir[i] == dy) 3509. break; 3510. tmp_at(DISP_FLASH, cmap_to_glyph(boom)); 3511. for (ct = 0; ct < 10; ct++) { 3512. i = (i + 8) % 8; /* 0..7 (8 -> 0, -1 -> 7) */ 3513. boom = (S_boomleft + S_boomright - boom); /* toggle */ 3514. tmp_at(DISP_CHANGE, cmap_to_glyph(boom)); /* change glyph */ 3515. dx = xdir[i]; 3516. dy = ydir[i]; 3517. bhitpos.x += dx; 3518. bhitpos.y += dy; 3519. if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) { 3520. m_respond(mtmp); 3521. tmp_at(DISP_END, 0); 3522. return mtmp; 3523. } 3524. if (!ZAP_POS(levl[bhitpos.x][bhitpos.y].typ) 3525. || closed_door(bhitpos.x, bhitpos.y)) { 3526. bhitpos.x -= dx; 3527. bhitpos.y -= dy; 3528. break; 3529. } 3530. if (bhitpos.x == u.ux && bhitpos.y == u.uy) { /* ct == 9 */ 3531. if (Fumbling || rn2(20) >= ACURR(A_DEX)) { 3532. /* we hit ourselves */ 3533. (void) thitu(10 + obj->spe, dmgval(obj, &youmonst), &obj, 3534. "boomerang"); 3535. endmultishot(TRUE); 3536. break; 3537. } else { /* we catch it */ 3538. tmp_at(DISP_END, 0); 3539. You("skillfully catch the boomerang."); 3540. return &youmonst; 3541. } 3542. } 3543. tmp_at(bhitpos.x, bhitpos.y); 3544. delay_output(); 3545. if (IS_SINK(levl[bhitpos.x][bhitpos.y].typ)) { 3546. if (!Deaf) 3547. pline("Klonk!"); 3548. break; /* boomerang falls on sink */ 3549. } 3550. /* ct==0, initial position, we want next delta to be same; 3551. ct==5, opposite position, repeat delta undoes first one */ 3552. if (ct % 5 != 0) 3553. i += (counterclockwise ? -1 : 1); 3554. } 3555. tmp_at(DISP_END, 0); /* do not leave last symbol */ 3556. return (struct monst *) 0; 3557. } 3558. 3559. /* used by buzz(); also used by munslime(muse.c); returns damage applied 3560. to mon; note: caller is responsible for killing mon if damage is fatal */ 3561. int 3562. zhitm(mon, type, nd, ootmp) 3563. register struct monst *mon; 3564. register int type, nd; 3565. struct obj **ootmp; /* to return worn armor for caller to disintegrate */ 3566. { 3567. register int tmp = 0; 3568. register int abstype = abs(type) % 10; 3569. boolean sho_shieldeff = FALSE; 3570. boolean spellcaster = is_hero_spell(type); /* maybe get a bonus! */ 3571. 3572. *ootmp = (struct obj *) 0; 3573. switch (abstype) { 3574. case ZT_MAGIC_MISSILE: 3575. if (resists_magm(mon)) { 3576. sho_shieldeff = TRUE; 3577. break; 3578. } 3579. tmp = d(nd, 6); 3580. if (spellcaster) 3581. tmp = spell_damage_bonus(tmp); 3582. break; 3583. case ZT_FIRE: 3584. if (resists_fire(mon)) { 3585. sho_shieldeff = TRUE; 3586. break; 3587. } 3588. tmp = d(nd, 6); 3589. if (resists_cold(mon)) 3590. tmp += 7; 3591. if (spellcaster) 3592. tmp = spell_damage_bonus(tmp); 3593. if (burnarmor(mon)) { 3594. if (!rn2(3)) 3595. (void) destroy_mitem(mon, POTION_CLASS, AD_FIRE); 3596. if (!rn2(3)) 3597. (void) destroy_mitem(mon, SCROLL_CLASS, AD_FIRE); 3598. if (!rn2(5)) 3599. (void) destroy_mitem(mon, SPBOOK_CLASS, AD_FIRE); 3600. destroy_mitem(mon, FOOD_CLASS, AD_FIRE); /* carried slime */ 3601. } 3602. break; 3603. case ZT_COLD: 3604. if (resists_cold(mon)) { 3605. sho_shieldeff = TRUE; 3606. break; 3607. } 3608. tmp = d(nd, 6); 3609. if (resists_fire(mon)) 3610. tmp += d(nd, 3); 3611. if (spellcaster) 3612. tmp = spell_damage_bonus(tmp); 3613. if (!rn2(3)) 3614. (void) destroy_mitem(mon, POTION_CLASS, AD_COLD); 3615. break; 3616. case ZT_SLEEP: 3617. tmp = 0; 3618. (void) sleep_monst(mon, d(nd, 25), 3619. type == ZT_WAND(ZT_SLEEP) ? WAND_CLASS : '\0'); 3620. break; 3621. case ZT_DEATH: /* death/disintegration */ 3622. if (abs(type) != ZT_BREATH(ZT_DEATH)) { /* death */ 3623. if (mon->data == &mons[PM_DEATH]) { 3624. mon->mhpmax += mon->mhpmax / 2; 3625. if (mon->mhpmax >= MAGIC_COOKIE) 3626. mon->mhpmax = MAGIC_COOKIE - 1; 3627. mon->mhp = mon->mhpmax; 3628. tmp = 0; 3629. break; 3630. } 3631. if (nonliving(mon->data) || is_demon(mon->data) 3632. || is_vampshifter(mon) || resists_magm(mon)) { 3633. /* similar to player */ 3634. sho_shieldeff = TRUE; 3635. break; 3636. } 3637. type = -1; /* so they don't get saving throws */ 3638. } else { 3639. struct obj *otmp2; 3640. 3641. if (resists_disint(mon)) { 3642. sho_shieldeff = TRUE; 3643. } else if (mon->misc_worn_check & W_ARMS) { 3644. /* destroy shield; victim survives */ 3645. *ootmp = which_armor(mon, W_ARMS); 3646. } else if (mon->misc_worn_check & W_ARM) { 3647. /* destroy body armor, also cloak if present */ 3648. *ootmp = which_armor(mon, W_ARM); 3649. if ((otmp2 = which_armor(mon, W_ARMC)) != 0) 3650. m_useup(mon, otmp2); 3651. } else { 3652. /* no body armor, victim dies; destroy cloak 3653. and shirt now in case target gets life-saved */ 3654. tmp = MAGIC_COOKIE; 3655. if ((otmp2 = which_armor(mon, W_ARMC)) != 0) 3656. m_useup(mon, otmp2); 3657. if ((otmp2 = which_armor(mon, W_ARMU)) != 0) 3658. m_useup(mon, otmp2); 3659. } 3660. type = -1; /* no saving throw wanted */ 3661. break; /* not ordinary damage */ 3662. } 3663. tmp = mon->mhp + 1; 3664. break; 3665. case ZT_LIGHTNING: 3666. if (resists_elec(mon)) { 3667. sho_shieldeff = TRUE; 3668. tmp = 0; 3669. /* can still blind the monster */ 3670. } else 3671. tmp = d(nd, 6); 3672. if (spellcaster) 3673. tmp = spell_damage_bonus(tmp); 3674. if (!resists_blnd(mon) 3675. && !(type > 0 && u.uswallow && mon == u.ustuck)) { 3676. register unsigned rnd_tmp = rnd(50); 3677. mon->mcansee = 0; 3678. if ((mon->mblinded + rnd_tmp) > 127) 3679. mon->mblinded = 127; 3680. else 3681. mon->mblinded += rnd_tmp; 3682. } 3683. if (!rn2(3)) 3684. (void) destroy_mitem(mon, WAND_CLASS, AD_ELEC); 3685. /* not actually possible yet */ 3686. if (!rn2(3)) 3687. (void) destroy_mitem(mon, RING_CLASS, AD_ELEC); 3688. break; 3689. case ZT_POISON_GAS: 3690. if (resists_poison(mon)) { 3691. sho_shieldeff = TRUE; 3692. break; 3693. } 3694. tmp = d(nd, 6); 3695. break; 3696. case ZT_ACID: 3697. if (resists_acid(mon)) { 3698. sho_shieldeff = TRUE; 3699. break; 3700. } 3701. tmp = d(nd, 6); 3702. if (!rn2(6)) 3703. acid_damage(MON_WEP(mon)); 3704. if (!rn2(6)) 3705. erode_armor(mon, ERODE_CORRODE); 3706. break; 3707. } 3708. if (sho_shieldeff) 3709. shieldeff(mon->mx, mon->my); 3710. if (is_hero_spell(type) && (Role_if(PM_KNIGHT) && u.uhave.questart)) 3711. tmp *= 2; 3712. if (tmp > 0 && type >= 0 3713. && resist(mon, type < ZT_SPELL(0) ? WAND_CLASS : '\0', 0, NOTELL)) 3714. tmp /= 2; 3715. if (tmp < 0) 3716. tmp = 0; /* don't allow negative damage */ 3717. debugpline3("zapped monster hp = %d (= %d - %d)", mon->mhp - tmp, 3718. mon->mhp, tmp); 3719. mon->mhp -= tmp; 3720. return tmp; 3721. } 3722. 3723. STATIC_OVL void 3724. zhitu(type, nd, fltxt, sx, sy) 3725. int type, nd; 3726. const char *fltxt; 3727. xchar sx, sy; 3728. { 3729. int dam = 0, abstyp = abs(type); 3730. 3731. switch (abstyp % 10) { 3732. case ZT_MAGIC_MISSILE: 3733. if (Antimagic) { 3734. shieldeff(sx, sy); 3735. pline_The("missiles bounce off!"); 3736. } else { 3737. dam = d(nd, 6); 3738. exercise(A_STR, FALSE); 3739. } 3740. break; 3741. case ZT_FIRE: 3742. if (Fire_resistance) { 3743. shieldeff(sx, sy); 3744. You("don't feel hot!"); 3745. ugolemeffects(AD_FIRE, d(nd, 6)); 3746. } else { 3747. dam = d(nd, 6); 3748. } 3749. burn_away_slime(); 3750. if (burnarmor(&youmonst)) { /* "body hit" */ 3751. if (!rn2(3)) 3752. destroy_item(POTION_CLASS, AD_FIRE); 3753. if (!rn2(3)) 3754. destroy_item(SCROLL_CLASS, AD_FIRE); 3755. if (!rn2(5)) 3756. destroy_item(SPBOOK_CLASS, AD_FIRE); 3757. destroy_item(FOOD_CLASS, AD_FIRE); 3758. } 3759. break; 3760. case ZT_COLD: 3761. if (Cold_resistance) { 3762. shieldeff(sx, sy); 3763. You("don't feel cold."); 3764. ugolemeffects(AD_COLD, d(nd, 6)); 3765. } else { 3766. dam = d(nd, 6); 3767. } 3768. if (!rn2(3)) 3769. destroy_item(POTION_CLASS, AD_COLD); 3770. break; 3771. case ZT_SLEEP: 3772. if (Sleep_resistance) { 3773. shieldeff(u.ux, u.uy); 3774. You("don't feel sleepy."); 3775. } else { 3776. fall_asleep(-d(nd, 25), TRUE); /* sleep ray */ 3777. } 3778. break; 3779. case ZT_DEATH: 3780. if (abstyp == ZT_BREATH(ZT_DEATH)) { 3781. if (Disint_resistance) { 3782. You("are not disintegrated."); 3783. break; 3784. } else if (uarms) { 3785. /* destroy shield; other possessions are safe */ 3786. (void) destroy_arm(uarms); 3787. break; 3788. } else if (uarm) { 3789. /* destroy suit; if present, cloak goes too */ 3790. if (uarmc) 3791. (void) destroy_arm(uarmc); 3792. (void) destroy_arm(uarm); 3793. break; 3794. } 3795. /* no shield or suit, you're dead; wipe out cloak 3796. and/or shirt in case of life-saving or bones */ 3797. if (uarmc) 3798. (void) destroy_arm(uarmc); 3799. if (uarmu) 3800. (void) destroy_arm(uarmu); 3801. } else if (nonliving(youmonst.data) || is_demon(youmonst.data)) { 3802. shieldeff(sx, sy); 3803. You("seem unaffected."); 3804. break; 3805. } else if (Antimagic) { 3806. shieldeff(sx, sy); 3807. You("aren't affected."); 3808. break; 3809. } 3810. killer.format = KILLED_BY_AN; 3811. Strcpy(killer.name, fltxt ? fltxt : ""); 3812. /* when killed by disintegration breath, don't leave corpse */ 3813. u.ugrave_arise = (type == -ZT_BREATH(ZT_DEATH)) ? -3 : NON_PM; 3814. done(DIED); 3815. return; /* lifesaved */ 3816. case ZT_LIGHTNING: 3817. if (Shock_resistance) { 3818. shieldeff(sx, sy); 3819. You("aren't affected."); 3820. ugolemeffects(AD_ELEC, d(nd, 6)); 3821. } else { 3822. dam = d(nd, 6); 3823. exercise(A_CON, FALSE); 3824. } 3825. if (!rn2(3)) 3826. destroy_item(WAND_CLASS, AD_ELEC); 3827. if (!rn2(3)) 3828. destroy_item(RING_CLASS, AD_ELEC); 3829. break; 3830. case ZT_POISON_GAS: 3831. poisoned("blast", A_DEX, "poisoned blast", 15, FALSE); 3832. break; 3833. case ZT_ACID: 3834. if (Acid_resistance) { 3835. pline_The("%s doesn't hurt.", hliquid("acid")); 3836. dam = 0; 3837. } else { 3838. pline_The("%s burns!", hliquid("acid")); 3839. dam = d(nd, 6); 3840. exercise(A_STR, FALSE); 3841. } 3842. /* using two weapons at once makes both of them more vulnerable */ 3843. if (!rn2(u.twoweap ? 3 : 6)) 3844. acid_damage(uwep); 3845. if (u.twoweap && !rn2(3)) 3846. acid_damage(uswapwep); 3847. if (!rn2(6)) 3848. erode_armor(&youmonst, ERODE_CORRODE); 3849. break; 3850. } 3851. 3852. /* Half_spell_damage protection yields half-damage for wands & spells, 3853. including hero's own ricochets; breath attacks do full damage */ 3854. if (dam && Half_spell_damage && !(abstyp >= 20 && abstyp <= 29)) 3855. dam = (dam + 1) / 2; 3856. losehp(dam, fltxt, KILLED_BY_AN); 3857. return; 3858. } 3859. 3860. /* 3861. * burn objects (such as scrolls and spellbooks) on floor 3862. * at position x,y; return the number of objects burned 3863. */ 3864. int 3865. burn_floor_objects(x, y, give_feedback, u_caused) 3866. int x, y; 3867. boolean give_feedback; /* caller needs to decide about visibility checks */ 3868. boolean u_caused; 3869. { 3870. struct obj *obj, *obj2; 3871. long i, scrquan, delquan; 3872. char buf1[BUFSZ], buf2[BUFSZ]; 3873. int cnt = 0; 3874. 3875. for (obj = level.objects[x][y]; obj; obj = obj2) { 3876. obj2 = obj->nexthere; 3877. if (obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS 3878. || (obj->oclass == FOOD_CLASS 3879. && obj->otyp == GLOB_OF_GREEN_SLIME)) { 3880. if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL 3881. || obj_resists(obj, 2, 100)) 3882. continue; 3883. scrquan = obj->quan; /* number present */ 3884. delquan = 0L; /* number to destroy */ 3885. for (i = scrquan; i > 0L; i--) 3886. if (!rn2(3)) 3887. delquan++; 3888. if (delquan) { 3889. /* save name before potential delobj() */ 3890. if (give_feedback) { 3891. obj->quan = 1L; 3892. Strcpy(buf1, (x == u.ux && y == u.uy) 3893. ? xname(obj) 3894. : distant_name(obj, xname)); 3895. obj->quan = 2L; 3896. Strcpy(buf2, (x == u.ux && y == u.uy) 3897. ? xname(obj) 3898. : distant_name(obj, xname)); 3899. obj->quan = scrquan; 3900. } 3901. /* useupf(), which charges, only if hero caused damage */ 3902. if (u_caused) 3903. useupf(obj, delquan); 3904. else if (delquan < scrquan) 3905. obj->quan -= delquan; 3906. else 3907. delobj(obj); 3908. cnt += delquan; 3909. if (give_feedback) { 3910. if (delquan > 1L) 3911. pline("%ld %s burn.", delquan, buf2); 3912. else 3913. pline("%s burns.", An(buf1)); 3914. } 3915. } 3916. } 3917. } 3918. return cnt; 3919. } 3920. 3921. /* will zap/spell/breath attack score a hit against armor class `ac'? */ 3922. STATIC_OVL int 3923. zap_hit(ac, type) 3924. int ac; 3925. int type; /* either hero cast spell type or 0 */ 3926. { 3927. int chance = rn2(20); 3928. int spell_bonus = type ? spell_hit_bonus(type) : 0; 3929. 3930. /* small chance for naked target to avoid being hit */ 3931. if (!chance) 3932. return rnd(10) < ac + spell_bonus; 3933. 3934. /* very high armor protection does not achieve invulnerability */ 3935. ac = AC_VALUE(ac); 3936. 3937. return (3 - chance < ac + spell_bonus); 3938. } 3939. 3940. STATIC_OVL void 3941. disintegrate_mon(mon, type, fltxt) 3942. struct monst *mon; 3943. int type; /* hero vs other */ 3944. const char *fltxt; 3945. { 3946. struct obj *otmp, *otmp2, *m_amulet = mlifesaver(mon); 3947. 3948. if (canseemon(mon)) { 3949. if (!m_amulet) 3950. pline("%s is disintegrated!", Monnam(mon)); 3951. else 3952. hit(fltxt, mon, "!"); 3953. } 3954. 3955. /* note: worn amulet of life saving must be preserved in order to operate */ 3956. #define oresist_disintegration(obj) \ 3957. (objects[obj->otyp].oc_oprop == DISINT_RES || obj_resists(obj, 5, 50) \ 3958. || is_quest_artifact(obj) || obj == m_amulet) 3959. 3960. for (otmp = mon->minvent; otmp; otmp = otmp2) { 3961. otmp2 = otmp->nobj; 3962. if (!oresist_disintegration(otmp)) { 3963. if (otmp->owornmask) { 3964. /* in case monster's life gets saved */ 3965. mon->misc_worn_check &= ~otmp->owornmask; 3966. if (otmp->owornmask & W_WEP) 3967. setmnotwielded(mon, otmp); 3968. /* also dismounts hero if this object is steed's saddle */ 3969. update_mon_intrinsics(mon, otmp, FALSE, TRUE); 3970. otmp->owornmask = 0L; 3971. } 3972. obj_extract_self(otmp); 3973. obfree(otmp, (struct obj *) 0); 3974. } 3975. } 3976. 3977. #undef oresist_disintegration 3978. 3979. if (type < 0) 3980. monkilled(mon, (char *) 0, -AD_RBRE); 3981. else 3982. xkilled(mon, XKILL_NOMSG | XKILL_NOCORPSE); 3983. } 3984. 3985. void 3986. buzz(type, nd, sx, sy, dx, dy) 3987. int type, nd; 3988. xchar sx, sy; 3989. int dx, dy; 3990. { 3991. dobuzz(type, nd, sx, sy, dx, dy, TRUE); 3992. } 3993. 3994. /* 3995. * type == 0 to 9 : you shooting a wand 3996. * type == 10 to 19 : you casting a spell 3997. * type == 20 to 29 : you breathing as a monster 3998. * type == -10 to -19 : monster casting spell 3999. * type == -20 to -29 : monster breathing at you 4000. * type == -30 to -39 : monster shooting a wand 4001. * called with dx = dy = 0 with vertical bolts 4002. */ 4003. void 4004. dobuzz(type, nd, sx, sy, dx, dy, say) 4005. register int type, nd; 4006. register xchar sx, sy; 4007. register int dx, dy; 4008. boolean say; /* Announce out of sight hit/miss events if true */ 4009. { 4010. int range, abstype = abs(type) % 10; 4011. register xchar lsx, lsy; 4012. struct monst *mon; 4013. coord save_bhitpos; 4014. boolean shopdamage = FALSE; 4015. const char *fltxt; 4016. struct obj *otmp; 4017. int spell_type; 4018. 4019. /* if its a Hero Spell then get its SPE_TYPE */ 4020. spell_type = is_hero_spell(type) ? SPE_MAGIC_MISSILE + abstype : 0; 4021. 4022. fltxt = flash_types[(type <= -30) ? abstype : abs(type)]; 4023. if (u.uswallow) { 4024. register int tmp; 4025. 4026. if (type < 0) 4027. return; 4028. tmp = zhitm(u.ustuck, type, nd, &otmp); 4029. if (!u.ustuck) 4030. u.uswallow = 0; 4031. else 4032. pline("%s rips into %s%s", The(fltxt), mon_nam(u.ustuck), 4033. exclam(tmp)); 4034. /* Using disintegration from the inside only makes a hole... */ 4035. if (tmp == MAGIC_COOKIE) 4036. u.ustuck->mhp = 0; 4037. if (DEADMONSTER(u.ustuck)) 4038. killed(u.ustuck); 4039. return; 4040. } 4041. if (type < 0) 4042. newsym(u.ux, u.uy); 4043. range = rn1(7, 7); 4044. if (dx == 0 && dy == 0) 4045. range = 1; 4046. save_bhitpos = bhitpos; 4047. 4048. tmp_at(DISP_BEAM, zapdir_to_glyph(dx, dy, abstype)); 4049. while (range-- > 0) { 4050. lsx = sx; 4051. sx += dx; 4052. lsy = sy; 4053. sy += dy; 4054. if (!isok(sx, sy) || levl[sx][sy].typ == STONE) 4055. goto make_bounce; 4056. 4057. mon = m_at(sx, sy); 4058. if (cansee(sx, sy)) { 4059. /* reveal/unreveal invisible monsters before tmp_at() */ 4060. if (mon && !canspotmon(mon)) 4061. map_invisible(sx, sy); 4062. else if (!mon) 4063. (void) unmap_invisible(sx, sy); 4064. if (ZAP_POS(levl[sx][sy].typ) 4065. || (isok(lsx, lsy) && cansee(lsx, lsy))) 4066. tmp_at(sx, sy); 4067. delay_output(); /* wait a little */ 4068. } 4069. 4070. /* hit() and miss() need bhitpos to match the target */ 4071. bhitpos.x = sx, bhitpos.y = sy; 4072. /* Fireballs only damage when they explode */ 4073. if (type != ZT_SPELL(ZT_FIRE)) { 4074. range += zap_over_floor(sx, sy, type, &shopdamage, 0); 4075. /* zap with fire -> melt ice -> drown monster, so monster 4076. found and cached above might not be here any more */ 4077. mon = m_at(sx, sy); 4078. } 4079. 4080. if (mon) { 4081. if (type == ZT_SPELL(ZT_FIRE)) 4082. break; 4083. if (type >= 0) 4084. mon->mstrategy &= ~STRAT_WAITMASK; 4085. buzzmonst: 4086. notonhead = (mon->mx != bhitpos.x || mon->my != bhitpos.y); 4087. if (zap_hit(find_mac(mon), spell_type)) { 4088. if (mon_reflects(mon, (char *) 0)) { 4089. if (cansee(mon->mx, mon->my)) { 4090. hit(fltxt, mon, exclam(0)); 4091. shieldeff(mon->mx, mon->my); 4092. (void) mon_reflects(mon, 4093. "But it reflects from %s %s!"); 4094. } 4095. dx = -dx; 4096. dy = -dy; 4097. } else { 4098. boolean mon_could_move = mon->mcanmove; 4099. int tmp = zhitm(mon, type, nd, &otmp); 4100. 4101. if (is_rider(mon->data) 4102. && abs(type) == ZT_BREATH(ZT_DEATH)) { 4103. if (canseemon(mon)) { 4104. hit(fltxt, mon, "."); 4105. pline("%s disintegrates.", Monnam(mon)); 4106. pline("%s body reintegrates before your %s!", 4107. s_suffix(Monnam(mon)), 4108. (eyecount(youmonst.data) == 1) 4109. ? body_part(EYE) 4110. : makeplural(body_part(EYE))); 4111. pline("%s resurrects!", Monnam(mon)); 4112. } 4113. mon->mhp = mon->mhpmax; 4114. break; /* Out of while loop */ 4115. } 4116. if (mon->data == &mons[PM_DEATH] && abstype == ZT_DEATH) { 4117. if (canseemon(mon)) { 4118. hit(fltxt, mon, "."); 4119. pline("%s absorbs the deadly %s!", Monnam(mon), 4120. type == ZT_BREATH(ZT_DEATH) ? "blast" 4121. : "ray"); 4122. pline("It seems even stronger than before."); 4123. } 4124. break; /* Out of while loop */ 4125. } 4126. 4127. if (tmp == MAGIC_COOKIE) { /* disintegration */ 4128. disintegrate_mon(mon, type, fltxt); 4129. } else if (DEADMONSTER(mon)) { 4130. if (type < 0) { 4131. /* mon has just been killed by another monster */ 4132. monkilled(mon, fltxt, AD_RBRE); 4133. } else { 4134. int xkflags = XKILL_GIVEMSG; /* killed(mon); */ 4135. 4136. /* killed by hero; we know 'type' isn't negative; 4137. if it's fire, highly flammable monsters leave 4138. no corpse; don't bother reporting that they 4139. "burn completely" -- unnecessary verbosity */ 4140. if ((type % 10 == ZT_FIRE) 4141. /* paper golem or straw golem */ 4142. && completelyburns(mon->data)) 4143. xkflags |= XKILL_NOCORPSE; 4144. xkilled(mon, xkflags); 4145. } 4146. } else { 4147. if (!otmp) { 4148. /* normal non-fatal hit */ 4149. if (say || canseemon(mon)) 4150. hit(fltxt, mon, exclam(tmp)); 4151. } else { 4152. /* some armor was destroyed; no damage done */ 4153. if (canseemon(mon)) 4154. pline("%s %s is disintegrated!", 4155. s_suffix(Monnam(mon)), 4156. distant_name(otmp, xname)); 4157. m_useup(mon, otmp); 4158. } 4159. if (mon_could_move && !mon->mcanmove) /* ZT_SLEEP */ 4160. slept_monst(mon); 4161. } 4162. } 4163. range -= 2; 4164. } else { 4165. if (say || canseemon(mon)) 4166. miss(fltxt, mon); 4167. } 4168. } else if (sx == u.ux && sy == u.uy && range >= 0) { 4169. nomul(0); 4170. if (u.usteed && !rn2(3) && !mon_reflects(u.usteed, (char *) 0)) { 4171. mon = u.usteed; 4172. goto buzzmonst; 4173. } else if (zap_hit((int) u.uac, 0)) { 4174. range -= 2; 4175. pline("%s hits you!", The(fltxt)); 4176. if (Reflecting) { 4177. if (!Blind) { 4178. (void) ureflects("But %s reflects from your %s!", 4179. "it"); 4180. } else 4181. pline("For some reason you are not affected."); 4182. dx = -dx; 4183. dy = -dy; 4184. shieldeff(sx, sy); 4185. } else { 4186. zhitu(type, nd, fltxt, sx, sy); 4187. } 4188. } else if (!Blind) { 4189. pline("%s whizzes by you!", The(fltxt)); 4190. } else if (abstype == ZT_LIGHTNING) { 4191. Your("%s tingles.", body_part(ARM)); 4192. } 4193. if (abstype == ZT_LIGHTNING) 4194. (void) flashburn((long) d(nd, 50)); 4195. stop_occupation(); 4196. nomul(0); 4197. } 4198. 4199. if (!ZAP_POS(levl[sx][sy].typ) 4200. || (closed_door(sx, sy) && range >= 0)) { 4201. int bounce, bchance; 4202. uchar rmn; 4203. boolean fireball; 4204. 4205. make_bounce: 4206. bchance = (levl[sx][sy].typ == STONE) ? 10 4207. : (In_mines(&u.uz) && IS_WALL(levl[sx][sy].typ)) ? 20 4208. : 75; 4209. bounce = 0; 4210. fireball = (type == ZT_SPELL(ZT_FIRE)); 4211. if ((--range > 0 && isok(lsx, lsy) && cansee(lsx, lsy)) 4212. || fireball) { 4213. if (Is_airlevel(&u.uz)) { /* nothing to bounce off of */ 4214. pline_The("%s vanishes into the aether!", fltxt); 4215. if (fireball) 4216. type = ZT_WAND(ZT_FIRE); /* skip pending fireball */ 4217. break; 4218. } else if (fireball) { 4219. sx = lsx; 4220. sy = lsy; 4221. break; /* fireballs explode before the obstacle */ 4222. } else 4223. pline_The("%s bounces!", fltxt); 4224. } 4225. if (!dx || !dy || !rn2(bchance)) { 4226. dx = -dx; 4227. dy = -dy; 4228. } else { 4229. if (isok(sx, lsy) && ZAP_POS(rmn = levl[sx][lsy].typ) 4230. && !closed_door(sx, lsy) 4231. && (IS_ROOM(rmn) || (isok(sx + dx, lsy) 4232. && ZAP_POS(levl[sx + dx][lsy].typ)))) 4233. bounce = 1; 4234. if (isok(lsx, sy) && ZAP_POS(rmn = levl[lsx][sy].typ) 4235. && !closed_door(lsx, sy) 4236. && (IS_ROOM(rmn) || (isok(lsx, sy + dy) 4237. && ZAP_POS(levl[lsx][sy + dy].typ)))) 4238. if (!bounce || rn2(2)) 4239. bounce = 2; 4240. 4241. switch (bounce) { 4242. case 0: 4243. dx = -dx; 4244. /*FALLTHRU*/ 4245. case 1: 4246. dy = -dy; 4247. break; 4248. case 2: 4249. dx = -dx; 4250. break; 4251. } 4252. tmp_at(DISP_CHANGE, zapdir_to_glyph(dx, dy, abstype)); 4253. } 4254. } 4255. } 4256. tmp_at(DISP_END, 0); 4257. if (type == ZT_SPELL(ZT_FIRE)) 4258. explode(sx, sy, type, d(12, 6), 0, EXPL_FIERY); 4259. if (shopdamage) 4260. pay_for_damage(abstype == ZT_FIRE 4261. ? "burn away" 4262. : abstype == ZT_COLD 4263. ? "shatter" 4264. /* "damage" indicates wall rather than door */ 4265. : abstype == ZT_ACID 4266. ? "damage" 4267. : abstype == ZT_DEATH 4268. ? "disintegrate" 4269. : "destroy", 4270. FALSE); 4271. bhitpos = save_bhitpos; 4272. } 4273. 4274. void 4275. melt_ice(x, y, msg) 4276. xchar x, y; 4277. const char *msg; 4278. { 4279. struct rm *lev = &levl[x][y]; 4280. struct obj *otmp; 4281. struct monst *mtmp; 4282. 4283. if (!msg) 4284. msg = "The ice crackles and melts."; 4285. if (lev->typ == DRAWBRIDGE_UP || lev->typ == DRAWBRIDGE_DOWN) { 4286. lev->drawbridgemask &= ~DB_ICE; /* revert to DB_MOAT */ 4287. } else { /* lev->typ == ICE */ 4288. #ifdef STUPID 4289. if (lev->icedpool == ICED_POOL) 4290. lev->typ = POOL; 4291. else 4292. lev->typ = MOAT; 4293. #else 4294. lev->typ = (lev->icedpool == ICED_POOL ? POOL : MOAT); 4295. #endif 4296. lev->icedpool = 0; 4297. } 4298. spot_stop_timers(x, y, MELT_ICE_AWAY); /* no more ice to melt away */ 4299. obj_ice_effects(x, y, FALSE); 4300. unearth_objs(x, y); 4301. if (Underwater) 4302. vision_recalc(1); 4303. newsym(x, y); 4304. if (cansee(x, y)) 4305. Norep("%s", msg); 4306. if ((otmp = sobj_at(BOULDER, x, y)) != 0) { 4307. if (cansee(x, y)) 4308. pline("%s settles...", An(xname(otmp))); 4309. do { 4310. obj_extract_self(otmp); /* boulder isn't being pushed */ 4311. if (!boulder_hits_pool(otmp, x, y, FALSE)) 4312. impossible("melt_ice: no pool?"); 4313. /* try again if there's another boulder and pool didn't fill */ 4314. } while (is_pool(x, y) && (otmp = sobj_at(BOULDER, x, y)) != 0); 4315. newsym(x, y); 4316. } 4317. if (x == u.ux && y == u.uy) 4318. spoteffects(TRUE); /* possibly drown, notice objects */ 4319. else if (is_pool(x, y) && (mtmp = m_at(x, y)) != 0) 4320. (void) minliquid(mtmp); 4321. } 4322. 4323. #define MIN_ICE_TIME 50 4324. #define MAX_ICE_TIME 2000 4325. /* 4326. * Usually start a melt_ice timer; sometimes the ice will become 4327. * permanent instead. 4328. */ 4329. void 4330. start_melt_ice_timeout(x, y, min_time) 4331. xchar x, y; 4332. long min_time; /* <x,y>'s old melt timeout (deleted by time we get here) */ 4333. { 4334. int when; 4335. long where; 4336. 4337. when = (int) min_time; 4338. if (when < MIN_ICE_TIME - 1) 4339. when = MIN_ICE_TIME - 1; 4340. 4341. /* random timeout; surrounding ice locations ought to be a factor... */ 4342. while (++when <= MAX_ICE_TIME) 4343. if (!rn2((MAX_ICE_TIME - when) + MIN_ICE_TIME)) 4344. break; 4345. 4346. /* if we're within MAX_ICE_TIME, install a melt timer; 4347. otherwise, omit it to leave this ice permanent */ 4348. if (when <= MAX_ICE_TIME) { 4349. where = ((long) x << 16) | (long) y; 4350. (void) start_timer((long) when, TIMER_LEVEL, MELT_ICE_AWAY, 4351. long_to_any(where)); 4352. } 4353. } 4354. #undef MIN_ICE_TIME 4355. #undef MAX_ICE_TIME 4356. 4357. /* 4358. * Called when ice has melted completely away. 4359. */ 4360. void 4361. melt_ice_away(arg, timeout) 4362. anything *arg; 4363. long timeout UNUSED; 4364. { 4365. xchar x, y; 4366. long where = arg->a_long; 4367. boolean save_mon_moving = context.mon_moving; /* will be False */ 4368. 4369. /* melt_ice -> minliquid -> mondead|xkilled shouldn't credit/blame hero */ 4370. context.mon_moving = TRUE; /* hero isn't causing this ice to melt */ 4371. y = (xchar) (where & 0xFFFF); 4372. x = (xchar) ((where >> 16) & 0xFFFF); 4373. /* melt_ice does newsym when appropriate */ 4374. melt_ice(x, y, "Some ice melts away."); 4375. context.mon_moving = save_mon_moving; 4376. } 4377. 4378. /* Burn floor scrolls, evaporate pools, etc... in a single square. 4379. * Used both for normal bolts of fire, cold, etc... and for fireballs. 4380. * Sets shopdamage to TRUE if a shop door is destroyed, and returns the 4381. * amount by which range is reduced (the latter is just ignored by fireballs) 4382. */ 4383. int 4384. zap_over_floor(x, y, type, shopdamage, exploding_wand_typ) 4385. xchar x, y; 4386. int type; 4387. boolean *shopdamage; 4388. short exploding_wand_typ; 4389. { 4390. const char *zapverb; 4391. struct monst *mon; 4392. struct trap *t; 4393. struct rm *lev = &levl[x][y]; 4394. boolean see_it = cansee(x, y), yourzap; 4395. int rangemod = 0, abstype = abs(type) % 10; 4396. 4397. switch (abstype) { 4398. case ZT_FIRE: 4399. t = t_at(x, y); 4400. if (t && t->ttyp == WEB) { 4401. /* a burning web is too flimsy to notice if you can't see it */ 4402. if (see_it) 4403. Norep("A web bursts into flames!"); 4404. (void) delfloortrap(t); 4405. if (see_it) 4406. newsym(x, y); 4407. } 4408. if (is_ice(x, y)) { 4409. melt_ice(x, y, (char *) 0); 4410. } else if (is_pool(x, y)) { 4411. const char *msgtxt = "You hear hissing gas."; 4412. 4413. if (lev->typ != POOL) { /* MOAT or DRAWBRIDGE_UP */ 4414. if (see_it) 4415. msgtxt = "Some water evaporates."; 4416. } else { 4417. rangemod -= 3; 4418. lev->typ = ROOM, lev->flags = 0; 4419. t = maketrap(x, y, PIT); 4420. if (t) 4421. t->tseen = 1; 4422. if (see_it) 4423. msgtxt = "The water evaporates."; 4424. } 4425. Norep("%s", msgtxt); 4426. if (lev->typ == ROOM) 4427. newsym(x, y); 4428. } else if (IS_FOUNTAIN(lev->typ)) { 4429. if (see_it) 4430. pline("Steam billows from the fountain."); 4431. rangemod -= 1; 4432. dryup(x, y, type > 0); 4433. } 4434. break; /* ZT_FIRE */ 4435. 4436. case ZT_COLD: 4437. if (is_pool(x, y) || is_lava(x, y)) { 4438. boolean lava = is_lava(x, y), 4439. moat = is_moat(x, y); 4440. 4441. if (lev->typ == WATER) { 4442. /* For now, don't let WATER freeze. */ 4443. if (see_it) 4444. pline_The("%s freezes for a moment.", hliquid("water")); 4445. else 4446. You_hear("a soft crackling."); 4447. rangemod -= 1000; /* stop */ 4448. } else { 4449. char buf[BUFSZ]; 4450. 4451. Strcpy(buf, waterbody_name(x, y)); /* for MOAT */ 4452. rangemod -= 3; 4453. if (lev->typ == DRAWBRIDGE_UP) { 4454. lev->drawbridgemask &= ~DB_UNDER; /* clear lava */ 4455. lev->drawbridgemask |= (lava ? DB_FLOOR : DB_ICE); 4456. } else { 4457. lev->icedpool = lava ? 0 4458. : (lev->typ == POOL) ? ICED_POOL 4459. : ICED_MOAT; 4460. lev->typ = lava ? ROOM : ICE; 4461. } 4462. bury_objs(x, y); 4463. if (see_it) { 4464. if (lava) 4465. Norep("The %s cools and solidifies.", hliquid("lava")); 4466. else if (moat) 4467. Norep("The %s is bridged with ice!", buf); 4468. else 4469. Norep("The %s freezes.", hliquid("water")); 4470. newsym(x, y); 4471. } else if (!lava) 4472. You_hear("a crackling sound."); 4473. 4474. if (x == u.ux && y == u.uy) { 4475. if (u.uinwater) { /* not just `if (Underwater)' */ 4476. /* leave the no longer existent water */ 4477. u.uinwater = 0; 4478. u.uundetected = 0; 4479. docrt(); 4480. vision_full_recalc = 1; 4481. } else if (u.utrap && u.utraptype == TT_LAVA) { 4482. if (Passes_walls) { 4483. You("pass through the now-solid rock."); 4484. reset_utrap(TRUE); 4485. } else { 4486. set_utrap(rn1(50, 20), TT_INFLOOR); 4487. You("are firmly stuck in the cooling rock."); 4488. } 4489. } 4490. } else if ((mon = m_at(x, y)) != 0) { 4491. /* probably ought to do some hefty damage to any 4492. non-ice creature caught in freezing water; 4493. at a minimum, eels are forced out of hiding */ 4494. if (is_swimmer(mon->data) && mon->mundetected) { 4495. mon->mundetected = 0; 4496. newsym(x, y); 4497. } 4498. } 4499. if (!lava) { 4500. start_melt_ice_timeout(x, y, 0L); 4501. obj_ice_effects(x, y, TRUE); 4502. } 4503. } /* ?WATER */ 4504. 4505. } else if (is_ice(x, y)) { 4506. long melt_time; 4507. 4508. /* Already ice here, so just firm it up. */ 4509. /* Now ensure that only ice that is already timed is affected */ 4510. if ((melt_time = spot_time_left(x, y, MELT_ICE_AWAY)) != 0L) { 4511. spot_stop_timers(x, y, MELT_ICE_AWAY); 4512. start_melt_ice_timeout(x, y, melt_time); 4513. } 4514. } 4515. break; /* ZT_COLD */ 4516. 4517. case ZT_POISON_GAS: 4518. (void) create_gas_cloud(x, y, 1, 8); 4519. break; 4520. 4521. case ZT_ACID: 4522. if (lev->typ == IRONBARS) { 4523. if ((lev->wall_info & W_NONDIGGABLE) != 0) { 4524. if (see_it) 4525. Norep("The %s corrode somewhat but remain intact.", 4526. defsyms[S_bars].explanation); 4527. /* but nothing actually happens... */ 4528. } else { 4529. rangemod -= 3; 4530. if (see_it) 4531. Norep("The %s melt.", defsyms[S_bars].explanation); 4532. if (*in_rooms(x, y, SHOPBASE)) { 4533. /* in case we ever have a shop bounded by bars */ 4534. lev->typ = ROOM, lev->flags = 0; 4535. if (see_it) 4536. newsym(x, y); 4537. add_damage(x, y, (type >= 0) ? SHOP_BARS_COST : 0L); 4538. if (type >= 0) 4539. *shopdamage = TRUE; 4540. } else { 4541. lev->typ = DOOR, lev->doormask = D_NODOOR; 4542. if (see_it) 4543. newsym(x, y); 4544. } 4545. } 4546. } 4547. break; /* ZT_ACID */ 4548. 4549. default: 4550. break; 4551. } 4552. 4553. /* set up zap text for possible door feedback; for exploding wand, we 4554. want "the blast" rather than "your blast" even if hero caused it */ 4555. yourzap = (type >= 0 && !exploding_wand_typ); 4556. zapverb = "blast"; /* breath attack or wand explosion */ 4557. if (!exploding_wand_typ) { 4558. if (abs(type) < ZT_SPELL(0)) 4559. zapverb = "bolt"; /* wand zap */ 4560. else if (abs(type) < ZT_BREATH(0)) 4561. zapverb = "spell"; 4562. } 4563. 4564. /* secret door gets revealed, converted into regular door */ 4565. if (levl[x][y].typ == SDOOR) { 4566. cvt_sdoor_to_door(&levl[x][y]); /* .typ = DOOR */ 4567. /* target spot will now pass closed_door() test below 4568. (except on rogue level) */ 4569. newsym(x, y); 4570. if (see_it) 4571. pline("%s %s reveals a secret door.", 4572. yourzap ? "Your" : "The", zapverb); 4573. else if (Is_rogue_level(&u.uz)) 4574. draft_message(FALSE); /* "You feel a draft." (open doorway) */ 4575. } 4576. 4577. /* regular door absorbs remaining zap range, possibly gets destroyed */ 4578. if (closed_door(x, y)) { 4579. int new_doormask = -1; 4580. const char *see_txt = 0, *sense_txt = 0, *hear_txt = 0; 4581. 4582. rangemod = -1000; 4583. switch (abstype) { 4584. case ZT_FIRE: 4585. new_doormask = D_NODOOR; 4586. see_txt = "The door is consumed in flames!"; 4587. sense_txt = "smell smoke."; 4588. break; 4589. case ZT_COLD: 4590. new_doormask = D_NODOOR; 4591. see_txt = "The door freezes and shatters!"; 4592. sense_txt = "feel cold."; 4593. break; 4594. case ZT_DEATH: 4595. /* death spells/wands don't disintegrate */ 4596. if (abs(type) != ZT_BREATH(ZT_DEATH)) 4597. goto def_case; 4598. new_doormask = D_NODOOR; 4599. see_txt = "The door disintegrates!"; 4600. hear_txt = "crashing wood."; 4601. break; 4602. case ZT_LIGHTNING: 4603. new_doormask = D_BROKEN; 4604. see_txt = "The door splinters!"; 4605. hear_txt = "crackling."; 4606. break; 4607. default: 4608. def_case: 4609. if (exploding_wand_typ > 0) { 4610. /* Magical explosion from misc exploding wand */ 4611. if (exploding_wand_typ == WAN_STRIKING) { 4612. new_doormask = D_BROKEN; 4613. see_txt = "The door crashes open!"; 4614. sense_txt = "feel a burst of cool air."; 4615. break; 4616. } 4617. } 4618. if (see_it) { 4619. /* "the door absorbs the blast" would be 4620. inaccurate for an exploding wand since 4621. other adjacent locations still get hit */ 4622. if (exploding_wand_typ) 4623. pline_The("door remains intact."); 4624. else 4625. pline_The("door absorbs %s %s!", yourzap ? "your" : "the", 4626. zapverb); 4627. } else 4628. You_feel("vibrations."); 4629. break; 4630. } 4631. if (new_doormask >= 0) { /* door gets broken */ 4632. if (*in_rooms(x, y, SHOPBASE)) { 4633. if (type >= 0) { 4634. add_damage(x, y, SHOP_DOOR_COST); 4635. *shopdamage = TRUE; 4636. } else /* caused by monster */ 4637. add_damage(x, y, 0L); 4638. } 4639. lev->doormask = new_doormask; 4640. unblock_point(x, y); /* vision */ 4641. if (see_it) { 4642. pline1(see_txt); 4643. newsym(x, y); 4644. } else if (sense_txt) { 4645. You1(sense_txt); 4646. } else if (hear_txt) 4647. You_hear1(hear_txt); 4648. if (picking_at(x, y)) { 4649. stop_occupation(); 4650. reset_pick(); 4651. } 4652. } 4653. } 4654. 4655. if (OBJ_AT(x, y) && abstype == ZT_FIRE) 4656. if (burn_floor_objects(x, y, FALSE, type > 0) && couldsee(x, y)) { 4657. newsym(x, y); 4658. You("%s of smoke.", !Blind ? "see a puff" : "smell a whiff"); 4659. } 4660. if ((mon = m_at(x, y)) != 0) { 4661. wakeup(mon, FALSE); 4662. if (type >= 0) { 4663. setmangry(mon, TRUE); 4664. if (mon->ispriest && *in_rooms(mon->mx, mon->my, TEMPLE)) 4665. ghod_hitsu(mon); 4666. if (mon->isshk && !*u.ushops) 4667. hot_pursuit(mon); 4668. } 4669. } 4670. return rangemod; 4671. } 4672. 4673. /* fractured by pick-axe or wand of striking */ 4674. void 4675. fracture_rock(obj) 4676. register struct obj *obj; /* no texts here! */ 4677. { 4678. xchar x, y; 4679. boolean by_you = !context.mon_moving; 4680. 4681. if (by_you && get_obj_location(obj, &x, &y, 0) && costly_spot(x, y)) { 4682. struct monst *shkp = 0; 4683. char objroom = *in_rooms(x, y, SHOPBASE); 4684. 4685. if (billable(&shkp, obj, objroom, FALSE)) { 4686. /* shop message says "you owe <shk> <$> for it!" so we need 4687. to precede that with a message explaining what "it" is */ 4688. You("fracture %s %s.", s_suffix(shkname(shkp)), xname(obj)); 4689. breakobj(obj, x, y, TRUE, FALSE); /* charges for shop goods */ 4690. } 4691. } 4692. if (by_you && obj->otyp == BOULDER) 4693. sokoban_guilt(); 4694. 4695. obj->otyp = ROCK; 4696. obj->oclass = GEM_CLASS; 4697. obj->quan = (long) rn1(60, 7); 4698. obj->owt = weight(obj); 4699. obj->dknown = obj->bknown = obj->rknown = 0; 4700. obj->known = objects[obj->otyp].oc_uses_known ? 0 : 1; 4701. dealloc_oextra(obj); 4702. 4703. if (obj->where == OBJ_FLOOR) { 4704. obj_extract_self(obj); /* move rocks back on top */ 4705. place_object(obj, obj->ox, obj->oy); 4706. if (!does_block(obj->ox, obj->oy, &levl[obj->ox][obj->oy])) 4707. unblock_point(obj->ox, obj->oy); 4708. if (cansee(obj->ox, obj->oy)) 4709. newsym(obj->ox, obj->oy); 4710. } 4711. } 4712. 4713. /* handle statue hit by striking/force bolt/pick-axe */ 4714. boolean 4715. break_statue(obj) 4716. register struct obj *obj; 4717. { 4718. /* [obj is assumed to be on floor, so no get_obj_location() needed] */ 4719. struct trap *trap = t_at(obj->ox, obj->oy); 4720. struct obj *item; 4721. boolean by_you = !context.mon_moving; 4722. 4723. if (trap && trap->ttyp == STATUE_TRAP 4724. && activate_statue_trap(trap, obj->ox, obj->oy, TRUE)) 4725. return FALSE; 4726. /* drop any objects contained inside the statue */ 4727. while ((item = obj->cobj) != 0) { 4728. obj_extract_self(item); 4729. place_object(item, obj->ox, obj->oy); 4730. } 4731. if (by_you && Role_if(PM_ARCHEOLOGIST) && (obj->spe & STATUE_HISTORIC)) { 4732. You_feel("guilty about damaging such a historic statue."); 4733. adjalign(-1); 4734. } 4735. obj->spe = 0; 4736. fracture_rock(obj); 4737. return TRUE; 4738. } 4739. 4740. /* 4741. * destroy_strings[dindx][0:singular,1:plural,2:killer_reason] 4742. * [0] freezing potion 4743. * [1] boiling potion other than oil 4744. * [2] boiling potion of oil 4745. * [3] burning scroll 4746. * [4] burning spellbook 4747. * [5] shocked ring 4748. * [6] shocked wand 4749. * (books, rings, and wands don't stack so don't need plural form; 4750. * crumbling ring doesn't do damage so doesn't need killer reason) 4751. */ 4752. const char *const destroy_strings[][3] = { 4753. /* also used in trap.c */ 4754. { "freezes and shatters", "freeze and shatter", "shattered potion" }, 4755. { "boils and explodes", "boil and explode", "boiling potion" }, 4756. { "ignites and explodes", "ignite and explode", "exploding potion" }, 4757. { "catches fire and burns", "catch fire and burn", "burning scroll" }, 4758. { "catches fire and burns", "", "burning book" }, 4759. { "turns to dust and vanishes", "", "" }, 4760. { "breaks apart and explodes", "", "exploding wand" }, 4761. }; 4762. 4763. /* guts of destroy_item(), which ought to be called maybe_destroy_items(); 4764. caller must decide whether obj is eligible */ 4765. STATIC_OVL void 4766. destroy_one_item(obj, osym, dmgtyp) 4767. struct obj *obj; 4768. int osym, dmgtyp; 4769. { 4770. long i, cnt, quan; 4771. int dmg, xresist, skip, dindx; 4772. const char *mult; 4773. boolean physical_damage; 4774. 4775. physical_damage = FALSE; 4776. xresist = skip = 0; 4777. /* lint suppression */ 4778. dmg = dindx = 0; 4779. quan = 0L; 4780. 4781. switch (dmgtyp) { 4782. case AD_COLD: 4783. if (osym == POTION_CLASS && obj->otyp != POT_OIL) { 4784. quan = obj->quan; 4785. dindx = 0; 4786. dmg = rnd(4); 4787. } else 4788. skip++; 4789. break; 4790. case AD_FIRE: 4791. xresist = (Fire_resistance && obj->oclass != POTION_CLASS 4792. && obj->otyp != GLOB_OF_GREEN_SLIME); 4793. if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL) 4794. skip++; 4795. if (obj->otyp == SPE_BOOK_OF_THE_DEAD) { 4796. skip++; 4797. if (!Blind) 4798. pline("%s glows a strange %s, but remains intact.", 4799. The(xname(obj)), hcolor("dark red")); 4800. } 4801. quan = obj->quan; 4802. switch (osym) { 4803. case POTION_CLASS: 4804. dindx = (obj->otyp != POT_OIL) ? 1 : 2; 4805. dmg = rnd(6); 4806. break; 4807. case SCROLL_CLASS: 4808. dindx = 3; 4809. dmg = 1; 4810. break; 4811. case SPBOOK_CLASS: 4812. dindx = 4; 4813. dmg = 1; 4814. break; 4815. case FOOD_CLASS: 4816. if (obj->otyp == GLOB_OF_GREEN_SLIME) { 4817. dindx = 1; /* boil and explode */ 4818. dmg = (obj->owt + 19) / 20; 4819. } else { 4820. skip++; 4821. } 4822. break; 4823. default: 4824. skip++; 4825. break; 4826. } 4827. break; 4828. case AD_ELEC: 4829. xresist = (Shock_resistance && obj->oclass != RING_CLASS); 4830. quan = obj->quan; 4831. switch (osym) { 4832. case RING_CLASS: 4833. if (obj->otyp == RIN_SHOCK_RESISTANCE) { 4834. skip++; 4835. break; 4836. } 4837. dindx = 5; 4838. dmg = 0; 4839. break; 4840. case WAND_CLASS: 4841. if (obj->otyp == WAN_LIGHTNING) { 4842. skip++; 4843. break; 4844. } 4845. #if 0 4846. if (obj == current_wand) { skip++; break; } 4847. #endif 4848. dindx = 6; 4849. dmg = rnd(10); 4850. break; 4851. default: 4852. skip++; 4853. break; 4854. } 4855. break; 4856. default: 4857. skip++; 4858. break; 4859. } 4860. 4861. if (!skip) { 4862. if (obj->in_use) 4863. --quan; /* one will be used up elsewhere */ 4864. for (i = cnt = 0L; i < quan; i++) 4865. if (!rn2(3)) 4866. cnt++; 4867. 4868. if (!cnt) 4869. return; 4870. mult = (cnt == 1L) 4871. ? ((quan == 1L) ? "Your" /* 1 of 1 */ 4872. : "One of your") /* 1 of N */ 4873. : ((cnt < quan) ? "Some of your" /* n of N */ 4874. : (quan == 2L) ? "Both of your" /* 2 of 2 */ 4875. : "All of your"); /* N of N */ 4876. pline("%s %s %s!", mult, xname(obj), 4877. destroy_strings[dindx][(cnt > 1L)]); 4878. if (osym == POTION_CLASS && dmgtyp != AD_COLD) { 4879. if (!breathless(youmonst.data) || haseyes(youmonst.data)) 4880. potionbreathe(obj); 4881. } 4882. if (obj->owornmask) { 4883. if (obj->owornmask & W_RING) /* ring being worn */ 4884. Ring_gone(obj); 4885. else 4886. setnotworn(obj); 4887. } 4888. if (obj == current_wand) 4889. current_wand = 0; /* destroyed */ 4890. for (i = 0; i < cnt; i++) 4891. useup(obj); 4892. if (dmg) { 4893. if (xresist) { 4894. You("aren't hurt!"); 4895. } else { 4896. const char *how = destroy_strings[dindx][2]; 4897. boolean one = (cnt == 1L); 4898. 4899. if (dmgtyp == AD_FIRE && osym == FOOD_CLASS) 4900. how = "exploding glob of slime"; 4901. if (physical_damage) 4902. dmg = Maybe_Half_Phys(dmg); 4903. losehp(dmg, one ? how : (const char *) makeplural(how), 4904. one ? KILLED_BY_AN : KILLED_BY); 4905. exercise(A_STR, FALSE); 4906. } 4907. } 4908. } 4909. } 4910. 4911. /* target items of specified class for possible destruction */ 4912. void 4913. destroy_item(osym, dmgtyp) 4914. int osym, dmgtyp; 4915. { 4916. register struct obj *obj; 4917. int i, deferral_indx = 0; 4918. /* 1+52+1: try to handle a full inventory; it doesn't matter if 4919. inventory actually has more, even if everything should be deferred */ 4920. unsigned short deferrals[1 + 52 + 1]; /* +1: gold, overflow */ 4921. 4922. (void) memset((genericptr_t) deferrals, 0, sizeof deferrals); 4923. /* 4924. * Sometimes destroying an item can change inventory aside from 4925. * the item itself (cited case was a potion of unholy water; when 4926. * boiled, potionbreathe() caused hero to transform into were-beast 4927. * form and that resulted in dropping or destroying some worn armor). 4928. * 4929. * Unlike other uses of the object bybass mechanism, destroy_item() 4930. * can be called multiple times for the same event. So we have to 4931. * explicitly clear it before each use and hope no other section of 4932. * code expects it to retain previous value. 4933. * 4934. * Destruction of a ring of levitation or form change which pushes 4935. * off levitation boots could drop hero onto a fire trap that 4936. * could destroy other items and we'll get called recursively. Or 4937. * onto a trap which transports hero elsewhere, which won't disrupt 4938. * traversal but could yield message sequencing issues. So we 4939. * defer handling such things until after rest of inventory has 4940. * been processed. If some other combination of items and events 4941. * triggers a recursive call, rest of inventory after the triggering 4942. * item will be skipped by the outer call since the inner one will 4943. * have set the bypass bits of the whole list. 4944. * 4945. * [Unfortunately, death while poly'd into flyer and subsequent 4946. * rehumanization could also drop hero onto a trap, and there's no 4947. * straightforward way to defer that. Things could be improved by 4948. * redoing this to use two passes, first to collect a list or array 4949. * of o_id and quantity of what is targetted for destruction, 4950. * second pass to handle the destruction.] 4951. */ 4952. bypass_objlist(invent, FALSE); /* clear bypass bit for invent */ 4953. 4954. while ((obj = nxt_unbypassed_obj(invent)) != 0) { 4955. if (obj->oclass != osym) 4956. continue; /* test only objs of type osym */ 4957. if (obj->oartifact) 4958. continue; /* don't destroy artifacts */ 4959. if (obj->in_use && obj->quan == 1L) 4960. continue; /* not available */ 4961. 4962. /* if loss of this item might dump us onto a trap, hold off 4963. until later because potential recursive destroy_item() will 4964. result in setting bypass bits on whole chain--we would skip 4965. the rest as already processed once control returns here */ 4966. if (deferral_indx < SIZE(deferrals) 4967. && ((obj->owornmask != 0L 4968. && (objects[obj->otyp].oc_oprop == LEVITATION 4969. || objects[obj->otyp].oc_oprop == FLYING)) 4970. /* destroyed wands and potions of polymorph don't trigger 4971. polymorph so don't need to be deferred */ 4972. || (obj->otyp == POT_WATER && u.ulycn >= LOW_PM 4973. && (Upolyd ? obj->blessed : obj->cursed)))) { 4974. deferrals[deferral_indx++] = obj->o_id; 4975. continue; 4976. } 4977. /* obj is eligible; maybe destroy it */ 4978. destroy_one_item(obj, osym, dmgtyp); 4979. } 4980. /* if we saved some items for later (most likely just a worn ring 4981. of levitation) and they're still in inventory, handle them now */ 4982. for (i = 0; i < deferral_indx; ++i) { 4983. /* note: obj->nobj is only referenced when obj is skipped; 4984. having obj be dropped or destroyed won't affect traversal */ 4985. for (obj = invent; obj; obj = obj->nobj) 4986. if (obj->o_id == deferrals[i]) { 4987. destroy_one_item(obj, osym, dmgtyp); 4988. break; 4989. } 4990. } 4991. return; 4992. } 4993. 4994. int 4995. destroy_mitem(mtmp, osym, dmgtyp) 4996. struct monst *mtmp; 4997. int osym, dmgtyp; 4998. { 4999. struct obj *obj; 5000. int skip, tmp = 0; 5001. long i, cnt, quan; 5002. int dindx; 5003. boolean vis; 5004. 5005. if (mtmp == &youmonst) { /* this simplifies artifact_hit() */ 5006. destroy_item(osym, dmgtyp); 5007. return 0; /* arbitrary; value doesn't matter to artifact_hit() */ 5008. } 5009. 5010. vis = canseemon(mtmp); 5011. 5012. /* see destroy_item(); object destruction could disrupt inventory list */ 5013. bypass_objlist(mtmp->minvent, FALSE); /* clear bypass bit for minvent */ 5014. 5015. while ((obj = nxt_unbypassed_obj(mtmp->minvent)) != 0) { 5016. if (obj->oclass != osym) 5017. continue; /* test only objs of type osym */ 5018. skip = 0; 5019. quan = 0L; 5020. dindx = 0; 5021. 5022. switch (dmgtyp) { 5023. case AD_COLD: 5024. if (osym == POTION_CLASS && obj->otyp != POT_OIL) { 5025. quan = obj->quan; 5026. dindx = 0; 5027. tmp++; 5028. } else 5029. skip++; 5030. break; 5031. case AD_FIRE: 5032. if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL) 5033. skip++; 5034. if (obj->otyp == SPE_BOOK_OF_THE_DEAD) { 5035. skip++; 5036. if (vis) 5037. pline("%s glows a strange %s, but remains intact.", 5038. The(distant_name(obj, xname)), hcolor("dark red")); 5039. } 5040. quan = obj->quan; 5041. switch (osym) { 5042. case POTION_CLASS: 5043. dindx = (obj->otyp != POT_OIL) ? 1 : 2; 5044. tmp++; 5045. break; 5046. case SCROLL_CLASS: 5047. dindx = 3; 5048. tmp++; 5049. break; 5050. case SPBOOK_CLASS: 5051. dindx = 4; 5052. tmp++; 5053. break; 5054. case FOOD_CLASS: 5055. if (obj->otyp == GLOB_OF_GREEN_SLIME) { 5056. dindx = 1; /* boil and explode */ 5057. tmp += (obj->owt + 19) / 20; 5058. } else { 5059. skip++; 5060. } 5061. break; 5062. default: 5063. skip++; 5064. break; 5065. } 5066. break; 5067. case AD_ELEC: 5068. quan = obj->quan; 5069. switch (osym) { 5070. case RING_CLASS: 5071. if (obj->otyp == RIN_SHOCK_RESISTANCE) { 5072. skip++; 5073. break; 5074. } 5075. dindx = 5; 5076. break; 5077. case WAND_CLASS: 5078. if (obj->otyp == WAN_LIGHTNING) { 5079. skip++; 5080. break; 5081. } 5082. dindx = 6; 5083. tmp++; 5084. break; 5085. default: 5086. skip++; 5087. break; 5088. } 5089. break; 5090. default: 5091. skip++; 5092. break; 5093. } 5094. if (!skip) { 5095. for (i = cnt = 0L; i < quan; i++) 5096. if (!rn2(3)) 5097. cnt++; 5098. 5099. if (!cnt) 5100. continue; 5101. if (vis) 5102. pline("%s%s %s!", 5103. (cnt == obj->quan) ? "" : (cnt > 1L) ? "Some of " 5104. : "One of ", 5105. (cnt == obj->quan) ? Yname2(obj) : yname(obj), 5106. destroy_strings[dindx][(cnt > 1L)]); 5107. for (i = 0; i < cnt; i++) 5108. m_useup(mtmp, obj); 5109. } 5110. } 5111. return tmp; 5112. } 5113. 5114. int 5115. resist(mtmp, oclass, damage, tell) 5116. struct monst *mtmp; 5117. char oclass; 5118. int damage, tell; 5119. { 5120. int resisted; 5121. int alev, dlev; 5122. 5123. /* fake players always pass resistance test against Conflict 5124. (this doesn't guarantee that they're never affected by it) */ 5125. if (oclass == RING_CLASS && !damage && !tell && is_mplayer(mtmp->data)) 5126. return 1; 5127. 5128. /* attack level */ 5129. switch (oclass) { 5130. case WAND_CLASS: 5131. alev = 12; 5132. break; 5133. case TOOL_CLASS: 5134. alev = 10; 5135. break; /* instrument */ 5136. case WEAPON_CLASS: 5137. alev = 10; 5138. break; /* artifact */ 5139. case SCROLL_CLASS: 5140. alev = 9; 5141. break; 5142. case POTION_CLASS: 5143. alev = 6; 5144. break; 5145. case RING_CLASS: 5146. alev = 5; 5147. break; 5148. default: 5149. alev = u.ulevel; 5150. break; /* spell */ 5151. } 5152. /* defense level */ 5153. dlev = (int) mtmp->m_lev; 5154. if (dlev > 50) 5155. dlev = 50; 5156. else if (dlev < 1) 5157. dlev = is_mplayer(mtmp->data) ? u.ulevel : 1; 5158. 5159. resisted = rn2(100 + alev - dlev) < mtmp->data->mr; 5160. if (resisted) { 5161. if (tell) { 5162. shieldeff(mtmp->mx, mtmp->my); 5163. pline("%s resists!", Monnam(mtmp)); 5164. } 5165. damage = (damage + 1) / 2; 5166. } 5167. 5168. if (damage) { 5169. mtmp->mhp -= damage; 5170. if (DEADMONSTER(mtmp)) { 5171. if (m_using) 5172. monkilled(mtmp, "", AD_RBRE); 5173. else 5174. killed(mtmp); 5175. } 5176. } 5177. return resisted; 5178. } 5179. 5180. #define MAXWISHTRY 5 5181. 5182. STATIC_OVL void 5183. wishcmdassist(triesleft) 5184. int triesleft; 5185. { 5186. static NEARDATA const char * 5187. wishinfo[] = { 5188. "Wish details:", 5189. "", 5190. "Enter the name of an object, such as \"potion of monster detection\",", 5191. "\"scroll labeled README\", \"elven mithril-coat\", or \"Grimtooth\"", 5192. "(without the quotes).", 5193. "", 5194. "For object types which come in stacks, you may specify a plural name", 5195. "such as \"potions of healing\", or specify a count, such as \"1000 gold", 5196. "pieces\", although that aspect of your wish might not be granted.", 5197. "", 5198. "You may also specify various prefix values which might be used to", 5199. "modify the item, such as \"uncursed\" or \"rustproof\" or \"+1\".", 5200. "Most modifiers shown when viewing your inventory can be specified.", 5201. "", 5202. "You may specify 'nothing' to explicitly decline this wish.", 5203. 0, 5204. }, 5205. preserve_wishless[] = "Doing so will preserve 'wishless' conduct.", 5206. retry_info[] = 5207. "If you specify an unrecognized object name %s%s time%s,", 5208. retry_too[] = "a randomly chosen item will be granted.", 5209. suppress_cmdassist[] = 5210. "(Suppress this assistance with !cmdassist in your config file.)", 5211. *cardinals[] = { "zero", "one", "two", "three", "four", "five" }, 5212. too_many[] = "too many"; 5213. int i; 5214. winid win; 5215. char buf[BUFSZ]; 5216. 5217. win = create_nhwindow(NHW_TEXT); 5218. if (!win) 5219. return; 5220. for (i = 0; i < SIZE(wishinfo) - 1; ++i) 5221. putstr(win, 0, wishinfo[i]); 5222. if (!u.uconduct.wishes) 5223. putstr(win, 0, preserve_wishless); 5224. putstr(win, 0, ""); 5225. Sprintf(buf, retry_info, 5226. (triesleft >= 0 && triesleft < SIZE(cardinals)) 5227. ? cardinals[triesleft] 5228. : too_many, 5229. (triesleft < MAXWISHTRY) ? " more" : "", 5230. plur(triesleft)); 5231. putstr(win, 0, buf); 5232. putstr(win, 0, retry_too); 5233. putstr(win, 0, ""); 5234. if (iflags.cmdassist) 5235. putstr(win, 0, suppress_cmdassist); 5236. display_nhwindow(win, FALSE); 5237. destroy_nhwindow(win); 5238. } 5239. 5240. void 5241. makewish() 5242. { 5243. char buf[BUFSZ] = DUMMY; 5244. char promptbuf[BUFSZ]; 5245. struct obj *otmp, nothing; 5246. int tries = 0; 5247. 5248. promptbuf[0] = '\0'; 5249. nothing = zeroobj; /* lint suppression; only its address matters */ 5250. if (flags.verbose) 5251. You("may wish for an object."); 5252. retry: 5253. Strcpy(promptbuf, "For what do you wish"); 5254. if (iflags.cmdassist && tries > 0) 5255. Strcat(promptbuf, " (enter 'help' for assistance)"); 5256. Strcat(promptbuf, "?"); 5257. getlin(promptbuf, buf); 5258. (void) mungspaces(buf); 5259. if (buf[0] == '\033') { 5260. buf[0] = '\0'; 5261. } else if (!strcmpi(buf, "help")) { 5262. wishcmdassist(MAXWISHTRY - tries); 5263. goto retry; 5264. } 5265. /* 5266. * Note: if they wished for and got a non-object successfully, 5267. * otmp == &zeroobj. That includes gold, or an artifact that 5268. * has been denied. Wishing for "nothing" requires a separate 5269. * value to remain distinct. 5270. */ 5271. otmp = readobjnam(buf, ¬hing); 5272. if (!otmp) { 5273. pline("Nothing fitting that description exists in the game."); 5274. if (++tries < MAXWISHTRY) 5275. goto retry; 5276. pline1(thats_enough_tries); 5277. otmp = readobjnam((char *) 0, (struct obj *) 0); 5278. if (!otmp) 5279. return; /* for safety; should never happen */ 5280. } else if (otmp == ¬hing) { 5281. /* explicitly wished for "nothing", presumably attempting 5282. to retain wishless conduct */ 5283. return; 5284. } 5285. 5286. /* KMH, conduct */ 5287. u.uconduct.wishes++; 5288. 5289. if (otmp != &zeroobj) { 5290. const char 5291. *verb = ((Is_airlevel(&u.uz) || u.uinwater) ? "slip" : "drop"), 5292. *oops_msg = (u.uswallow 5293. ? "Oops! %s out of your reach!" 5294. : (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz) 5295. || levl[u.ux][u.uy].typ < IRONBARS 5296. || levl[u.ux][u.uy].typ >= ICE) 5297. ? "Oops! %s away from you!" 5298. : "Oops! %s to the floor!"); 5299. 5300. /* The(aobjnam()) is safe since otmp is unidentified -dlc */ 5301. (void) hold_another_object(otmp, oops_msg, 5302. The(aobjnam(otmp, verb)), 5303. (const char *) 0); 5304. u.ublesscnt += rn1(100, 50); /* the gods take notice */ 5305. } 5306. } 5307. 5308. /*zap.c*/