Source:NetHack 3.1.0/zap.c
Jump to navigation
Jump to search
Below is the full text to zap.c from the source code of NetHack 3.1.0. To link to a particular line, write [[NetHack 3.1.0/zap.c#line123]], for example.
Warning! This is the source code from an old release. For the latest release, see Source code
The NetHack General Public License applies to screenshots, source code and other content from NetHack.
This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.
1. /* SCCS Id: @(#)zap.c 3.1 92/10/21 */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /* NetHack may be freely redistributed. See license for details. */ 4. 5. #include "hack.h" 6. 7. /* Disintegration rays have special treatment; corpses are never left. 8. * But the routine which calculates the damage is separate from the routine 9. * which kills the monster. The damage routine returns this cookie to 10. * indicate that the monster should be disintegrated. 11. */ 12. #define MAGIC_COOKIE 1000 13. 14. static boolean NEARDATA obj_zapped; 15. static int NEARDATA poly_zapped; 16. 17. #ifdef MUSE 18. /* kludge to use mondied instead of killed */ 19. extern boolean m_using; 20. #endif 21. 22. static boolean FDECL(obj_resists, (struct obj *)); 23. static boolean FDECL(obj_shudders, (struct obj *)); 24. static void FDECL(polyuse,(struct obj*, int, int)); 25. static void FDECL(do_osshock, (struct obj *)); 26. static void FDECL(create_polymon, (struct obj *)); 27. static int FDECL(burn_floor_paper,(int,int)); 28. static void FDECL(cancel_item,(struct obj *)); 29. static int FDECL(bhitm, (struct monst *,struct obj *)); 30. #ifndef MUSE 31. STATIC_PTR int FDECL(bhito,(struct obj *,struct obj *)); 32. #endif 33. STATIC_PTR int FDECL(bhitpile,(struct obj *,int (*)(OBJ_P,OBJ_P),int,int)); 34. static void FDECL(backfire,(struct obj *)); 35. static int FDECL(zhit,(struct monst *,int,int)); 36. 37. #define ZT_MAGIC_MISSILE (AD_MAGM-1) 38. #define ZT_FIRE (AD_FIRE-1) 39. #define ZT_COLD (AD_COLD-1) 40. #define ZT_SLEEP (AD_SLEE-1) 41. #define ZT_DEATH (AD_DISN-1) /* or disintegration */ 42. #define ZT_LIGHTNING (AD_ELEC-1) 43. #define ZT_POISON_GAS (AD_DRST-1) 44. #define ZT_ACID (AD_ACID-1) 45. /* 8 and 9 are currently unassigned */ 46. 47. #define ZT_WAND(x) (x) 48. #define ZT_SPELL(x) (10+(x)) 49. #define ZT_BREATH(x) (20+(x)) 50. 51. const char *fl[]= { 52. "magic missile", /* Wands must be 0-9 */ 53. "bolt of fire", 54. "bolt of cold", 55. "sleep ray", 56. "death ray", 57. "bolt of lightning", 58. "", 59. "", 60. "", 61. "", 62. 63. "magic missile", /* Spell equivalents must be 10-19 */ 64. "fireball", 65. "cone of cold", 66. "sleep ray", 67. "finger of death", 68. "bolt of lightning", 69. "", 70. "", 71. "", 72. "", 73. 74. "blast of missiles", /* Dragon breath equivalents 20-29*/ 75. "blast of fire", 76. "blast of frost", 77. "blast of sleep gas", 78. "blast of disintegration", 79. "blast of lightning", 80. "blast of poison gas", 81. "blast of acid", 82. "", 83. "" 84. }; 85. 86. 87. /* Routines for IMMEDIATE wands and spells. */ 88. /* bhitm: monster mtmp was hit by the effect of wand or spell otmp */ 89. static int 90. bhitm(mtmp, otmp) 91. register struct monst *mtmp; 92. register struct obj *otmp; 93. { 94. register boolean wake = FALSE; 95. #ifdef MULDGN 96. boolean dbldam = (pl_character[0] == 'K') && u.uhave.questart; 97. #endif 98. register int dmg; 99. 100. switch(otmp->otyp) { 101. case WAN_STRIKING: 102. case SPE_FORCE_BOLT: 103. wake = TRUE; 104. if (u.uswallow || rnd(20) < 10 + find_mac(mtmp)) { 105. dmg = d(2,12); 106. #ifdef MULDGN 107. if(dbldam) dmg *= 2; 108. #endif 109. hit((otmp->otyp == WAN_STRIKING) ? "wand" : 110. "spell", mtmp, exclam(dmg)); 111. (void) resist(mtmp, otmp->oclass, dmg, TELL); 112. } else miss((otmp->otyp == WAN_STRIKING) ? "wand" : 113. "spell", mtmp); 114. makeknown(otmp->otyp); 115. break; 116. case WAN_SLOW_MONSTER: 117. case SPE_SLOW_MONSTER: 118. wake = TRUE; 119. if (!resist(mtmp, otmp->oclass, 0, NOTELL)) { 120. if (mtmp->mspeed == MFAST) mtmp->mspeed = 0; 121. else mtmp->mspeed = MSLOW; 122. if (u.uswallow && (mtmp == u.ustuck) && 123. is_whirly(mtmp->data)) { 124. You("disrupt %s!", mon_nam(mtmp)); 125. pline("A huge hole opens up..."); 126. expels(mtmp, mtmp->data, TRUE); 127. } 128. } 129. break; 130. case WAN_SPEED_MONSTER: 131. if (!resist(mtmp, otmp->oclass, 0, NOTELL)) 132. if (mtmp->mspeed == MSLOW) mtmp->mspeed = 0; 133. else mtmp->mspeed = MFAST; 134. wake = TRUE; 135. break; 136. case WAN_UNDEAD_TURNING: 137. case SPE_TURN_UNDEAD: 138. if (is_undead(mtmp->data)) { 139. dmg = rnd(8); 140. #ifdef MULDGN 141. if(dbldam) dmg *= 2; 142. #endif 143. if(!resist(mtmp, otmp->oclass, dmg, NOTELL)) 144. mtmp->mflee = TRUE; 145. wake = TRUE; 146. } 147. break; 148. case WAN_POLYMORPH: 149. case SPE_POLYMORPH: 150. wake = TRUE; 151. if(!resist(mtmp, otmp->oclass, 0, NOTELL)) { 152. if (!rn2(25)) { 153. if (canseemon(mtmp)) { 154. pline("%s shudders!", Monnam(mtmp)); 155. makeknown(otmp->otyp); 156. } 157. /* no corpse after system shock */ 158. xkilled(mtmp, 3); 159. } 160. else if (newcham(mtmp, (struct permonst *)0) ) 161. if (!Hallucination && (!Blind || sensemon(mtmp))) 162. makeknown(otmp->otyp); 163. } 164. break; 165. case WAN_CANCELLATION: 166. case SPE_CANCELLATION: 167. wake = TRUE; 168. cancel_monst(mtmp, otmp, TRUE, TRUE, FALSE); 169. break; 170. case WAN_TELEPORTATION: 171. case SPE_TELEPORT_AWAY: 172. if(mtmp->ispriest && *in_rooms(mtmp->mx, mtmp->my, TEMPLE)) { 173. pline("%s resists your magic!", Monnam(mtmp)); 174. wake = TRUE; 175. break; 176. } 177. wake = TRUE; 178. if(mtmp->isshk) rloc_shk(mtmp); 179. else rloc(mtmp); 180. break; 181. case WAN_MAKE_INVISIBLE: 182. mtmp->minvis = TRUE; 183. newsym(mtmp->mx,mtmp->my); /* make monster disappear */ 184. if (mtmp->wormno) see_wsegs(mtmp); /* and tail too */ 185. wake = TRUE; 186. break; 187. case WAN_NOTHING: 188. break; 189. case WAN_PROBING: 190. makeknown(otmp->otyp); 191. mstatusline(mtmp); 192. break; 193. case WAN_OPENING: 194. if(u.uswallow && mtmp == u.ustuck) { 195. if (is_animal(mtmp->data)) { 196. if (Blind) pline("Its mouth opens!"); 197. else pline("%s opens its mouth!", Monnam(mtmp)); 198. } 199. expels(mtmp, mtmp->data, TRUE); 200. break; 201. } 202. case WAN_LOCKING: 203. case SPE_KNOCK: 204. case SPE_WIZARD_LOCK: 205. break; 206. default: 207. impossible("What an interesting effect (%u)", otmp->otyp); 208. } 209. if(wake) { 210. if(mtmp->mhp > 0) { 211. wakeup(mtmp); 212. m_respond(mtmp); 213. if(mtmp->isshk && !*u.ushops) hot_pursuit(mtmp); 214. } else if(mtmp->m_ap_type) 215. seemimic(mtmp); /* might unblock if mimicing a boulder/door */ 216. } 217. return 0; 218. } 219. 220. struct monst * 221. revive(obj,ininv) 222. register struct obj *obj; 223. boolean ininv; 224. { 225. register struct monst *mtmp = (struct monst *)0; 226. 227. if(obj->otyp == CORPSE) { 228. int montype = obj->corpsenm; 229. int x = ininv ? u.ux : obj->ox; 230. int y = ininv ? u.uy : obj->oy; 231. 232. if (cant_create(&montype)) { /* will make zombie instead */ 233. mtmp = makemon(&mons[PM_HUMAN_ZOMBIE], x, y); 234. if (mtmp) { 235. mtmp->mhp = mtmp->mhpmax = 100; 236. mtmp->mspeed = MFAST; 237. } 238. } else { 239. struct obj *otmp; 240. #if defined(ARMY) && !defined(MUSE) 241. if (is_mercenary(&mons[montype])) 242. montype = PM_UNARMORED_SOLDIER; 243. #endif 244. mtmp = makemon(&mons[montype], x, y); 245. if (mtmp) { 246. /* Monster retains its name */ 247. if (obj->onamelth) 248. mtmp = christen_monst(mtmp, ONAME(obj)); 249. /* No inventory for newly revived monsters */ 250. while ((otmp = (mtmp->minvent)) != 0) { 251. mtmp->minvent = otmp->nobj; 252. dealloc_obj(otmp); 253. } 254. } 255. } 256. if (mtmp && obj->oeaten) 257. mtmp->mhp = eaten_stat(mtmp->mhp, obj); 258. if (ininv) useup(obj); 259. else { 260. /* not useupf(), which charges */ 261. if (obj->quan > 1L) obj->quan--; 262. else delobj(obj); 263. } 264. if (x != u.ux || y != u.uy || Invisible) 265. newsym(x, y); 266. } 267. return mtmp; 268. } 269. 270. static const char NEARDATA charged_objs[] = { WAND_CLASS, WEAPON_CLASS, ARMOR_CLASS, 0 }; 271. 272. /* cancel obj, possibly carried by you or a monster */ 273. static void 274. cancel_item(obj) 275. register struct obj *obj; 276. { 277. boolean u_ring = (obj == uleft) || (obj == uright); 278. 279. switch(obj->otyp) { 280. case RIN_GAIN_STRENGTH: 281. if ((obj->owornmask & W_RING) && u_ring) { 282. ABON(A_STR) -= obj->spe; 283. flags.botl = 1; 284. } 285. break; 286. case RIN_ADORNMENT: 287. if ((obj->owornmask & W_RING) && u_ring) { 288. ABON(A_CHA) -= obj->spe; 289. flags.botl = 1; 290. } 291. break; 292. case RIN_INCREASE_DAMAGE: 293. if ((obj->owornmask & W_RING) && u_ring) 294. u.udaminc -= obj->spe; 295. break; 296. case GAUNTLETS_OF_DEXTERITY: 297. if ((obj->owornmask & W_ARMG) && (obj == uarmg)) { 298. ABON(A_DEX) -= obj->spe; 299. flags.botl = 1; 300. } 301. break; 302. case HELM_OF_BRILLIANCE: 303. if ((obj->owornmask & W_ARMH) && (obj == uarmh)) { 304. ABON(A_INT) -= obj->spe; 305. ABON(A_WIS) -= obj->spe; 306. flags.botl = 1; 307. } 308. break; 309. /* case RIN_PROTECTION: /* not needed */ 310. } 311. if(obj->spe && 312. !(obj->otyp == WAN_CANCELLATION || /* can't cancel cancellation */ 313. obj->otyp == TIN || obj->otyp == EGG || 314. obj->otyp == STATUE || 315. obj->otyp == MAGIC_LAMP || 316. #ifdef MAIL 317. obj->otyp == SCR_MAIL || 318. #endif 319. #ifdef TUTTI_FRUTTI 320. obj->otyp == SLIME_MOLD || 321. #endif 322. obj->otyp == SKELETON_KEY || 323. obj->otyp == LARGE_BOX || obj->otyp == CHEST)) 324. obj->spe = (obj->oclass == WAND_CLASS) ? -1 : 0; 325. 326. if (obj->otyp == OIL_LAMP || obj->otyp == BRASS_LANTERN 327. || Is_candle(obj) || obj->otyp == CANDELABRUM_OF_INVOCATION) { 328. 329. /* reducing a candle's age to 0 is */ 330. /* the same as destroying it. */ 331. if (!Is_candle(obj)) obj->age = 0; 332. 333. /* reducing a candelabrum age to 0 */ 334. /* is the same as de-candling it. */ 335. if(obj->otyp == CANDELABRUM_OF_INVOCATION) obj->spe = 0; 336. 337. obj->lamplit = 0; 338. check_lamps(); 339. } 340. 341. if (obj->oclass == SCROLL_CLASS 342. #ifdef MAIL 343. && obj->otyp != SCR_MAIL 344. #endif 345. ) 346. obj->otyp = SCR_BLANK_PAPER; 347. 348. if (obj->oclass == SPBOOK_CLASS && obj->otyp != SPE_BOOK_OF_THE_DEAD) 349. obj->otyp = SPE_BLANK_PAPER; 350. 351. if (obj->oclass == POTION_CLASS && obj->otyp != POT_BOOZE) 352. obj->otyp = (obj->otyp==POT_SICKNESS || obj->otyp==POT_SEE_INVISIBLE || obj->otyp==POT_FRUIT_JUICE) ? POT_FRUIT_JUICE : POT_WATER; 353. /* sickness is "biologically contaminated" fruit juice; cancel it 354. * and it just becomes fruit juice... whereas see invisible 355. * tastes like "enchanted" fruit juice, it similarly cancels. 356. */ 357. unbless(obj); 358. uncurse(obj); 359. } 360. 361. static boolean 362. obj_resists(obj) 363. struct obj *obj; 364. { 365. if (obj->otyp == AMULET_OF_YENDOR || 366. obj->otyp == SPE_BOOK_OF_THE_DEAD || 367. obj->otyp == CANDELABRUM_OF_INVOCATION || 368. obj->otyp == BELL_OF_OPENING || 369. (obj->otyp == CORPSE && is_rider(&mons[obj->corpsenm]))) { 370. return TRUE; 371. } else { 372. int chance = rn2(20); 373. /* artifacts resist 95% of the time; normal objects 5% */ 374. return (obj->oartifact ? !!chance : !chance); 375. } 376. } 377. 378. static boolean 379. obj_shudders(obj) 380. struct obj *obj; 381. { 382. int zap_odds; 383. 384. if (obj->oclass == WAND_CLASS) 385. zap_odds = 3; /* half-life = 2 zaps */ 386. else if (obj->cursed) 387. zap_odds = 3; /* half-life = 2 zaps */ 388. else if (obj->blessed) 389. zap_odds = 12; /* half-life = 8 zaps */ 390. else 391. zap_odds = 8; /* half-life = 6 zaps */ 392. 393. /* adjust for "large" quantities of identical things */ 394. if(obj->quan > 4L) zap_odds /= 2; 395. 396. return (! rn2(zap_odds)); 397. } 398. 399. /* Use up at least minwt number of things made of material mat. 400. * There's also a chance that other stuff will be used up. Finally, 401. * there's a random factor here to keep from always using the stuff 402. * at the top of the pile. 403. */ 404. static void 405. polyuse(objhdr, mat, minwt) 406. struct obj *objhdr; 407. int mat, minwt; 408. { 409. register struct obj *otmp, *otmp2; 410. 411. for(otmp = objhdr; minwt > 0 && otmp; otmp = otmp2) { 412. otmp2 = otmp->nexthere; 413. if((objects[otmp->otyp].oc_material == mat) == (rn2(minwt+1) != 0)) { 414. /* appropriately add damage to bill */ 415. if (costly_spot(otmp->ox, otmp->oy)) 416. if (*u.ushops) 417. addtobill(otmp, FALSE, FALSE, FALSE); 418. else 419. (void)stolen_value(otmp, 420. otmp->ox, otmp->oy, FALSE, FALSE); 421. minwt -= (int)otmp->quan; 422. delobj(otmp); 423. } 424. } 425. } 426. 427. /* 428. * Polymorph some of the stuff in this pile into a monster, preferably 429. * a golem of some sort. 430. */ 431. static void 432. create_polymon(obj) 433. struct obj *obj; 434. { 435. struct permonst *mdat = (struct permonst *)0; 436. struct monst *mtmp; 437. int pm_index; 438. 439. /* no golems if you zap only one object -- not enough stuff */ 440. if(!obj || (!obj->nexthere && obj->quan == 1L)) return; 441. 442. /* some of these choices are arbitrary */ 443. switch(poly_zapped) { 444. case IRON: 445. case METAL: 446. case MITHRIL: 447. pm_index = PM_IRON_GOLEM; 448. break; 449. case COPPER: 450. case SILVER: 451. case GOLD: 452. case PLATINUM: 453. case GEMSTONE: 454. case GLASS: 455. case MINERAL: 456. pm_index = rn2(2) ? PM_STONE_GOLEM : PM_CLAY_GOLEM; 457. break; 458. case 0: 459. /* there is no flesh type, but all food is type 0, so we use it */ 460. pm_index = PM_FLESH_GOLEM; 461. break; 462. case WOOD: 463. pm_index = PM_WOOD_GOLEM; 464. break; 465. case LEATHER: 466. pm_index = PM_LEATHER_GOLEM; 467. break; 468. case CLOTH: 469. pm_index = PM_ROPE_GOLEM; 470. break; 471. default: 472. /* if all else fails... */ 473. pm_index = PM_STRAW_GOLEM; 474. break; 475. } 476. 477. if (! (mons[pm_index].geno & G_GENOD)) 478. mdat = &mons[pm_index]; 479. 480. mtmp = makemon(mdat, obj->ox, obj->oy); 481. polyuse(obj, poly_zapped, (int)mons[pm_index].cwt); 482. 483. if(!Blind && mtmp) { 484. pline("Some objects in the pile merge."); 485. pline("%s rises from the pile!", Amonnam(mtmp)); 486. } 487. } 488. 489. static void 490. do_osshock(obj) 491. struct obj *obj; 492. { 493. long i; 494. obj_zapped = TRUE; 495. 496. if(poly_zapped < 0) { 497. /* some may metamorphosize */ 498. for(i=obj->quan; i; i--) 499. if (! rn2(Luck + 45)) { 500. poly_zapped = objects[obj->otyp].oc_material; 501. break; 502. } 503. } 504. 505. /* if quan > 1 then some will survive intact */ 506. if (obj->quan > 1L) { 507. struct obj *obj2; 508. 509. obj2 = splitobj(obj, (long)rnd((int)obj->quan - 1)); 510. move_object(obj2, obj->ox, obj->oy); 511. } 512. 513. /* appropriately add damage to bill */ 514. if (costly_spot(obj->ox, obj->oy)) 515. if (*u.ushops) 516. addtobill(obj, FALSE, FALSE, FALSE); 517. else 518. (void)stolen_value(obj, 519. obj->ox, obj->oy, FALSE, FALSE); 520. 521. /* zap the object */ 522. delobj(obj); 523. } 524. 525. #ifndef MUSE 526. STATIC_PTR 527. #endif 528. int 529. bhito(obj, otmp) /* object obj was hit by the effect of wand otmp */ 530. register struct obj *obj, *otmp; /* returns TRUE if sth was done */ 531. { 532. register int res = 1; 533. struct obj *otmp2; 534. 535. if(obj == uball || obj == uchain) 536. res = 0; 537. else 538. switch(otmp->otyp) { 539. case WAN_POLYMORPH: 540. case SPE_POLYMORPH: 541. if (obj_resists(obj)) { 542. res = 0; 543. break; 544. } else if (obj_shudders(obj)) { 545. if (cansee(obj->ox, obj->oy)) 546. makeknown(otmp->otyp); 547. do_osshock(obj); 548. break; 549. } 550. 551. /* preserve symbol and quantity */ 552. otmp2 = mkobj_at(obj->oclass, obj->ox, obj->oy, FALSE); 553. otmp2->quan = obj->quan; 554. /* preserve the shopkeepers (lack of) interest */ 555. otmp2->no_charge = obj->no_charge; 556. #ifdef MAIL 557. /* You can't send yourself 100 mail messages and then 558. * polymorph them into useful scrolls 559. */ 560. if (obj->otyp == SCR_MAIL) { 561. otmp2->otyp = SCR_MAIL; 562. otmp2->spe = 1; 563. } 564. #endif 565. 566. /* avoid abusing eggs laid by you */ 567. if (obj->otyp == EGG && obj->spe) { 568. otmp2->otyp = EGG; 569. otmp2->spe = 1; 570. otmp2->corpsenm = random_monster(); 571. while (!lays_eggs(&mons[otmp2->corpsenm])) 572. otmp2->corpsenm = random_monster(); 573. } 574. 575. /* keep special fields (including charges on wands) */ 576. if (index(charged_objs, otmp2->oclass)) otmp2->spe = obj->spe; 577. 578. otmp2->cursed = obj->cursed; 579. otmp2->blessed = obj->blessed; 580. otmp2->oeroded = obj->oeroded; 581. otmp2->oerodeproof = obj->oerodeproof; 582. 583. /* Keep chest/box traps and poisoned ammo if we may */ 584. if (obj->otrapped && Is_box(otmp2)) 585. otmp2->otrapped = TRUE; 586. if (obj->opoisoned && 587. (otmp2->oclass == WEAPON_CLASS && otmp2->otyp <= SHURIKEN)) 588. otmp2->opoisoned = TRUE; 589. 590. if (obj->otyp == CORPSE) { 591. /* turn crocodile corpses into shoes */ 592. if (obj->corpsenm == PM_CROCODILE) { 593. otmp2->otyp = LOW_BOOTS; 594. otmp2->oclass = ARMOR_CLASS; 595. otmp2->spe = 0; 596. otmp2->oerodeproof = TRUE; 597. otmp2->quan = 1L; 598. otmp2->cursed = FALSE; 599. } 600. } 601. 602. /* no box contents --KAA */ 603. if (Is_container(otmp2) || otmp2->otyp == STATUE) 604. delete_contents(otmp2); 605. 606. /* 'n' merged objects may be fused into 1 object */ 607. if (otmp2->quan > 1L && 608. (!objects[otmp2->otyp].oc_merge || 609. otmp2->quan > (long)rn2(1000))) 610. otmp2->quan = 1L; 611. 612. if(otmp2->otyp == MAGIC_LAMP) otmp2->otyp = OIL_LAMP; 613. 614. while(otmp2->otyp == WAN_WISHING || 615. otmp2->otyp == WAN_POLYMORPH) 616. otmp2->otyp = rnd_class(WAN_LIGHT, WAN_LIGHTNING); 617. 618. /* update the weight */ 619. otmp2->owt = weight(otmp2); 620. 621. if(costly_spot(obj->ox, obj->oy)) { 622. register struct monst *shkp = 623. shop_keeper(*in_rooms(obj->ox, obj->oy, SHOPBASE)); 624. 625. if ((!obj->no_charge || 626. (Is_container(obj) && 627. (contained_cost(obj, shkp, 0L, FALSE) != 0L))) 628. && inhishop(shkp)) { 629. if(shkp->mpeaceful) { 630. if(*u.ushops && *in_rooms(u.ux, u.uy, 0) == 631. *in_rooms(shkp->mx, shkp->my, 0) && 632. !costly_spot(u.ux, u.uy)) 633. make_angry_shk(shkp, obj->ox, obj->oy); 634. else { 635. pline("%s gets angry!", Monnam(shkp)); 636. hot_pursuit(shkp); 637. } 638. } else Norep("%s is furious!", Monnam(shkp)); 639. } 640. } 641. delobj(obj); 642. break; 643. case WAN_STRIKING: 644. case SPE_FORCE_BOLT: 645. if (obj->otyp == BOULDER) 646. fracture_rock(obj); 647. else if (obj->otyp == STATUE) 648. (void) break_statue(obj); 649. else 650. res = 0; 651. makeknown(otmp->otyp); 652. break; 653. case WAN_CANCELLATION: 654. case SPE_CANCELLATION: 655. cancel_item(obj); 656. break; 657. case WAN_TELEPORTATION: 658. case SPE_TELEPORT_AWAY: 659. rloco(obj); 660. break; 661. case WAN_MAKE_INVISIBLE: 662. obj->oinvis = TRUE; 663. newsym(obj->ox,obj->oy); /* make object disappear */ 664. break; 665. case WAN_UNDEAD_TURNING: 666. case SPE_TURN_UNDEAD: 667. res = !!revive(obj,FALSE); 668. break; 669. case WAN_OPENING: 670. case SPE_KNOCK: 671. /* Zap it at the chain, not the ball */ 672. if (obj == uchain) { 673. unpunish(); 674. res = 1; 675. makeknown(obj->otyp); 676. break; 677. } 678. /* fall through */ 679. case WAN_LOCKING: 680. case SPE_WIZARD_LOCK: 681. if(Is_box(obj)) 682. res = boxlock(obj, otmp); 683. else 684. res = 0; 685. if (res /* && obj->oclass == WAND_CLASS */) 686. makeknown(obj->otyp); 687. break; 688. case WAN_SLOW_MONSTER: /* no effect on objects */ 689. case SPE_SLOW_MONSTER: 690. case WAN_SPEED_MONSTER: 691. case WAN_NOTHING: 692. case WAN_PROBING: 693. res = 0; 694. break; 695. default: 696. impossible("What an interesting effect (%u)", otmp->otyp); 697. } 698. return(res); 699. } 700. 701. STATIC_PTR 702. int 703. bhitpile(obj,fhito,tx,ty) 704. register struct obj *obj; /* returns nonzero of something was hit */ 705. int FDECL((*fhito), (OBJ_P, OBJ_P)); 706. int tx, ty; 707. { 708. int hitanything = 0; 709. register struct obj *otmp, *next_obj = (struct obj *)0; 710. 711. /* modified by GAN to hit all objects */ 712. /* pre-reverse the polymorph pile, -dave- 3/90 */ 713. poly_zapped = -1; 714. if(obj->otyp == SPE_POLYMORPH || obj->otyp == WAN_POLYMORPH) { 715. otmp = level.objects[tx][ty]; 716. level.objects[tx][ty] = next_obj; 717. while(otmp) { 718. next_obj = otmp->nexthere; 719. otmp->nexthere = level.objects[tx][ty]; 720. level.objects[tx][ty] = otmp; 721. otmp = next_obj; 722. } 723. } 724. for(otmp = level.objects[tx][ty]; otmp; otmp = next_obj) { 725. /* Fix for polymorph bug, Tim Wright */ 726. next_obj = otmp->nexthere; 727. hitanything += (*fhito)(otmp, obj); 728. } 729. if(poly_zapped >= 0) 730. create_polymon(level.objects[tx][ty]); 731. 732. return hitanything; 733. } 734. 735. /* 736. * zappable - returns 1 if zap is available, 0 otherwise. 737. * it removes a charge from the wand if zappable. 738. * added by GAN 11/03/86 739. */ 740. int 741. zappable(wand) 742. register struct obj *wand; 743. { 744. if(wand->spe < 0 || (wand->spe == 0 && rn2(121))) 745. return 0; 746. if(wand->spe == 0) 747. You("wrest one more spell from the worn-out wand."); 748. wand->spe--; 749. return 1; 750. } 751. 752. /* 753. * zapnodir - zaps a NODIR wand/spell. 754. * added by GAN 11/03/86 755. */ 756. void 757. zapnodir(obj) 758. register struct obj *obj; 759. { 760. switch(obj->otyp) { 761. case WAN_LIGHT: 762. case SPE_LIGHT: 763. litroom(TRUE,obj); 764. break; 765. case WAN_SECRET_DOOR_DETECTION: 766. case SPE_DETECT_UNSEEN: 767. if(!findit()) return; 768. break; 769. case WAN_CREATE_MONSTER: 770. { register int cnt = 1; 771. if(!rn2(23)) cnt += rn2(7) + 1; 772. while(cnt--) 773. (void) makemon((struct permonst *) 0, u.ux, u.uy); 774. } 775. break; 776. case WAN_WISHING: 777. if(Luck + rn2(5) < 0) { 778. pline("Unfortunately, nothing happens."); 779. break; 780. } 781. makewish(); 782. break; 783. } 784. if (!objects[obj->otyp].oc_name_known && 785. (!Blind || obj->otyp == WAN_WISHING)) { 786. makeknown(obj->otyp); 787. more_experienced(0,10); 788. } 789. } 790. 791. static void 792. backfire(otmp) 793. 794. register struct obj * otmp; 795. { 796. pline("%s suddenly explodes!", The(xname(otmp))); 797. losehp(d(otmp->spe+2,6), "exploding wand", KILLED_BY_AN); 798. useup(otmp); 799. } 800. 801. static const char NEARDATA zap_syms[] = { WAND_CLASS, 0 }; 802. 803. int 804. dozap() 805. { 806. register struct obj *obj; 807. int damage; 808. 809. if(check_capacity(NULL)) return(0); 810. obj = getobj(zap_syms, "zap"); 811. if(!obj) return(0); 812. 813. check_unpaid(obj); 814. 815. /* zappable addition done by GAN 11/03/86 */ 816. if(!zappable(obj)) pline(nothing_happens); 817. else if(obj->cursed && !rn2(100)) { 818. backfire(obj); /* the wand blows up in your face! */ 819. exercise(A_STR, FALSE); 820. return(1); 821. } else if(!(objects[obj->otyp].oc_dir == NODIR) && !getdir(NULL)) { 822. if (!Blind) 823. pline("%s glows and fades.", The(xname(obj))); 824. /* make him pay for knowing !NODIR */ 825. } else if(!u.dx && !u.dy && !u.dz && !(objects[obj->otyp].oc_dir == NODIR)) { 826. if((damage = zapyourself(obj))) 827. losehp(damage, self_pronoun("zapped %sself with a wand", "him"), 828. NO_KILLER_PREFIX); 829. } else { 830. weffects(obj); 831. } 832. if (obj->spe < 0) { 833. pline ("%s %sturns to dust.", 834. The(xname(obj)), Blind ? "" : "glows violently, then "); 835. useup(obj); 836. } 837. return(1); 838. } 839. 840. int 841. zapyourself(obj) 842. register struct obj *obj; 843. { 844. int damage = 0; 845. 846. switch(obj->otyp) { 847. case WAN_STRIKING: 848. case SPE_FORCE_BOLT: 849. if(Antimagic) { 850. shieldeff(u.ux, u.uy); 851. pline("Boing!"); 852. } else { 853. You("magically bash yourself!"); 854. damage=d(8,6); 855. exercise(A_STR, FALSE); 856. } 857. makeknown(obj->otyp); 858. break; 859. case WAN_LIGHTNING: 860. makeknown(WAN_LIGHTNING); 861. if (!Shock_resistance) { 862. pline("Idiot! You've shocked yourself!"); 863. damage = d(12,6); 864. exercise(A_CON, FALSE); 865. } else { 866. shieldeff(u.ux, u.uy); 867. You("zap yourself, but seem unharmed."); 868. #ifdef POLYSELF 869. ugolemeffects(AD_ELEC, d(12,6)); 870. #endif 871. } 872. destroy_item(WAND_CLASS, AD_ELEC); 873. destroy_item(RING_CLASS, AD_ELEC); 874. if(!Blind) { 875. You("are blinded by the flash!"); 876. make_blinded((long)rnd(100),FALSE); 877. } 878. break; 879. case SPE_FIREBALL: 880. You("explode a fireball on top of yourself!"); 881. explode(u.ux, u.uy, 11, d(6,6), WAND_CLASS); 882. break; 883. case WAN_FIRE: 884. makeknown(WAN_FIRE); 885. case FIRE_HORN: 886. pline("You've set light to yourself!"); 887. if (Fire_resistance) { 888. shieldeff(u.ux, u.uy); 889. You("feel mildly hot."); 890. #ifdef POLYSELF 891. ugolemeffects(AD_FIRE, d(12,6)); 892. #endif 893. } else 894. damage = d(12,6); 895. destroy_item(SCROLL_CLASS, AD_FIRE); 896. destroy_item(POTION_CLASS, AD_FIRE); 897. destroy_item(SPBOOK_CLASS, AD_FIRE); 898. break; 899. case WAN_COLD: 900. makeknown(WAN_COLD); 901. case SPE_CONE_OF_COLD: 902. case FROST_HORN: 903. if (Cold_resistance) { 904. shieldeff(u.ux, u.uy); 905. You("feel mildly chilly."); 906. #ifdef POLYSELF 907. ugolemeffects(AD_COLD, d(12,6)); 908. #endif 909. } else { 910. You("imitate a popsicle!"); 911. damage = d(12,6); 912. } 913. destroy_item(POTION_CLASS, AD_COLD); 914. break; 915. case WAN_MAGIC_MISSILE: 916. makeknown(WAN_MAGIC_MISSILE); 917. case SPE_MAGIC_MISSILE: 918. if(Antimagic) { 919. shieldeff(u.ux, u.uy); 920. pline("The missiles bounce!"); 921. } else { 922. damage = d(4,6); 923. pline("Idiot! You've shot yourself!"); 924. } 925. break; 926. case WAN_POLYMORPH: 927. #ifdef POLYSELF 928. makeknown(WAN_POLYMORPH); 929. #endif 930. case SPE_POLYMORPH: 931. #ifdef POLYSELF 932. polyself(); 933. #else 934. newman(); 935. #endif 936. break; 937. case WAN_CANCELLATION: 938. case SPE_CANCELLATION: 939. cancel_monst(&youmonst, obj, TRUE, FALSE, TRUE); 940. break; 941. case WAN_MAKE_INVISIBLE: { 942. /* have to test before changing HInvis but must change 943. * HInvis before doing newsym(). 944. */ 945. int msg = (!Blind && !Invis && !See_invisible); 946. 947. HInvis |= FROMOUTSIDE; 948. if (msg) { 949. makeknown(WAN_MAKE_INVISIBLE); 950. newsym(u.ux, u.uy); 951. pline(Hallucination ? 952. "Far out, man! You can see right through yourself!" : 953. "Gee! All of a sudden, you can't see yourself."); 954. } 955. break; 956. } 957. case WAN_SPEED_MONSTER: 958. if (!(Fast & INTRINSIC)) { 959. You("seem to be moving faster."); 960. makeknown(WAN_SPEED_MONSTER); 961. exercise(A_DEX, TRUE); 962. } 963. Fast |= FROMOUTSIDE; 964. break; 965. case WAN_SLEEP: 966. makeknown(WAN_SLEEP); 967. case SPE_SLEEP: 968. if(Sleep_resistance) { 969. shieldeff(u.ux, u.uy); 970. You("don't feel sleepy!"); 971. } else { 972. pline("The sleep ray hits you!"); 973. nomul(-rn2(50)); 974. u.usleep = 1; 975. nomovemsg = "You wake up."; 976. } 977. break; 978. case WAN_SLOW_MONSTER: 979. case SPE_SLOW_MONSTER: 980. if(Fast & (TIMEOUT | INTRINSIC)) { 981. Fast &= ~(TIMEOUT | INTRINSIC); 982. You("seem to be moving slower."); 983. exercise(A_DEX, FALSE); 984. } 985. break; 986. case WAN_TELEPORTATION: 987. case SPE_TELEPORT_AWAY: 988. tele(); 989. break; 990. case WAN_DEATH: 991. case SPE_FINGER_OF_DEATH: 992. #ifdef POLYSELF 993. if (is_undead(uasmon)) { 994. pline((obj->otyp == WAN_DEATH) ? 995. "The wand shoots an apparently harmless beam at you." 996. : "You seem no deader than before."); 997. break; 998. } 999. #endif 1000. killer_format = NO_KILLER_PREFIX; 1001. killer = self_pronoun("shot %sself with a death ray","him"); 1002. You("irradiate yourself with pure energy!"); 1003. You("die."); 1004. makeknown(WAN_DEATH); 1005. /* They might survive with an amulet of life saving */ 1006. done(DIED); 1007. break; 1008. case SPE_TURN_UNDEAD: 1009. case WAN_UNDEAD_TURNING: 1010. #ifdef POLYSELF 1011. if (is_undead(uasmon)) { 1012. You("feel frightened and %sstunned.", 1013. Stunned ? "even more " : ""); 1014. make_stunned(HStun + rnd(30), FALSE); 1015. } 1016. #endif 1017. break; 1018. case SPE_DIG: 1019. case SPE_DETECT_UNSEEN: 1020. case WAN_DIGGING: 1021. case WAN_NOTHING: 1022. case WAN_OPENING: 1023. case WAN_LOCKING: 1024. case SPE_KNOCK: 1025. case SPE_WIZARD_LOCK: 1026. break; 1027. case WAN_PROBING: 1028. makeknown(WAN_PROBING); 1029. ustatusline(); 1030. break; 1031. default: impossible("object %d used?",obj->otyp); 1032. } 1033. return(damage); 1034. } 1035. 1036. /* 1037. * cancel a monster (possibly the hero). inventory is cancelled only 1038. * if the monster is zapping itself directly, since otherwise the 1039. * effect is too strong. currently non-hero monsters do not zap 1040. * themselves with cancellation. 1041. */ 1042. void 1043. cancel_monst(mdef, obj, youattack, allow_cancel_kill, self_cancel) 1044. register struct monst *mdef; 1045. register struct obj *obj; 1046. boolean youattack, allow_cancel_kill, self_cancel; 1047. { 1048. boolean youdefend = (mdef == &youmonst); 1049. static const char writing_vanishes[] = 1050. "Some writing vanishes from %s head!"; 1051. static const char your[] = "your"; /* should be extern */ 1052. 1053. if (youdefend ? (!youattack && Antimagic) 1054. : resist(mdef, obj->oclass, 0, NOTELL)) 1055. return; /* resisted cancellation */ 1056. 1057. if (self_cancel) { /* 1st cancel inventory */ 1058. struct obj *otmp; 1059. 1060. for (otmp = (youdefend ? invent : mdef->minvent); 1061. otmp; otmp = otmp->nobj) 1062. cancel_item(otmp); 1063. if (youdefend) { 1064. flags.botl = 1; /* potential AC change */ 1065. find_ac(); 1066. } 1067. } 1068. 1069. /* now handle special cases */ 1070. if (youdefend) { 1071. #ifdef POLYSELF 1072. if (u.mtimedone) { 1073. if ((u.umonnum == PM_CLAY_GOLEM) && !Blind) 1074. pline(writing_vanishes, your); 1075. rehumanize(); 1076. } 1077. #endif 1078. } else { 1079. mdef->mcan = TRUE; 1080. 1081. if (is_were(mdef->data) && mdef->data->mlet != S_HUMAN) 1082. were_change(mdef); 1083. 1084. if (mdef->data == &mons[PM_CLAY_GOLEM]) { 1085. if (canseemon(mdef)) 1086. pline(writing_vanishes, s_suffix(mon_nam(mdef))); 1087. 1088. if (allow_cancel_kill) { 1089. if (youattack) 1090. killed(mdef); 1091. else 1092. monkilled(mdef, "", AD_SPEL); 1093. } 1094. } 1095. } 1096. } 1097. 1098. /* called for various wand and spell effects - M. Stephenson */ 1099. void 1100. weffects(obj) 1101. register struct obj *obj; 1102. { 1103. xchar zx,zy; 1104. 1105. exercise(A_WIS, TRUE); 1106. if(objects[obj->otyp].oc_dir == IMMEDIATE) { 1107. obj_zapped = FALSE; 1108. 1109. if(u.uswallow) (void)bhitm(u.ustuck, obj); 1110. else if(u.dz) { 1111. if(u.dz > 0) { 1112. if(levl[u.ux][u.uy].typ == DRAWBRIDGE_DOWN && 1113. (obj->otyp == WAN_LOCKING 1114. || obj->otyp == SPE_WIZARD_LOCK)) 1115. close_drawbridge(u.ux, u.uy); 1116. else 1117. (void) bhitpile(obj, bhito, u.ux, u.uy); 1118. } 1119. } else (void) bhit(u.dx,u.dy,rn1(8,6),ZAPPED_WAND,bhitm,bhito,obj); 1120. 1121. /* give a clue if obj_zapped */ 1122. if (obj_zapped) 1123. You("feel shuddering vibrations."); 1124. 1125. } else if(objects[obj->otyp].oc_dir == NODIR) { 1126. zapnodir(obj); 1127. } else { 1128. switch(obj->otyp) { 1129. case WAN_DIGGING: 1130. case SPE_DIG: 1131. /* Original effect (approximately): 1132. * from CORR: dig until we pierce a wall 1133. * from ROOM: piece wall and dig until we reach 1134. * an ACCESSIBLE place. 1135. * Currently: dig for digdepth positions; 1136. * also down on request of Lennart Augustsson. 1137. */ 1138. { register struct rm *room; 1139. register int digdepth; 1140. register boolean shopdoor, shopwall; 1141. 1142. shopdoor = shopwall = FALSE; 1143. if(u.uswallow) { 1144. register struct monst *mtmp = u.ustuck; 1145. 1146. if (!is_whirly(mtmp->data)) { 1147. if (is_animal(mtmp->data)) 1148. You("pierce %s stomach wall!", 1149. s_suffix(mon_nam(mtmp))); 1150. mtmp->mhp = 1; /* almost dead */ 1151. expels(mtmp, mtmp->data, 1152. !is_animal(mtmp->data)); 1153. } 1154. break; 1155. } 1156. if(u.dz) { 1157. if(!Is_airlevel(&u.uz) && !Is_waterlevel(&u.uz) && 1158. !Underwater) { 1159. if(u.dz < 0 || On_stairs(u.ux, u.uy)) { 1160. if(On_stairs(u.ux, u.uy)) 1161. pline( 1162. "The beam bounces off the %s and hits the ceiling.", 1163. (u.ux == xdnladder || 1164. u.ux == xupladder) ? 1165. "ladder" : "stairs"); 1166. You("loosen a rock from the ceiling."); 1167. pline("It falls on your %s!", 1168. body_part(HEAD)); 1169. losehp(1, "falling rock", KILLED_BY_AN); 1170. (void) mksobj_at((int)ROCK, u.ux, u.uy, FALSE); 1171. stackobj(fobj); 1172. if(Invisible) newsym(u.ux, u.uy); 1173. } else { 1174. dighole(); 1175. } 1176. } 1177. break; 1178. } 1179. zx = u.ux+u.dx; 1180. zy = u.uy+u.dy; 1181. digdepth = 8 + rn2(18); 1182. tmp_at(DISP_BEAM, cmap_to_glyph(S_digbeam)); 1183. while(--digdepth >= 0) { 1184. if(!isok(zx,zy)) break; 1185. room = &levl[zx][zy]; 1186. tmp_at(zx,zy); 1187. delay_output(); /* wait a little bit */ 1188. if(level.flags.is_maze_lev && 1189. !Is_earthlevel(&u.uz)) { 1190. if(IS_WALL(room->typ)) { 1191. if(!(room->diggable & W_NONDIGGABLE)) { 1192. if(*in_rooms(zx,zy,SHOPBASE)) { 1193. add_damage(zx, zy, 200L); 1194. shopwall = TRUE; 1195. } 1196. room->typ = ROOM; 1197. unblock_point(zx,zy); /* vision */ 1198. } else if(!Blind) 1199. pline("The wall glows then fades."); 1200. break; 1201. } 1202. if(room->typ == STONE) { 1203. if(!(room->diggable & W_NONDIGGABLE)) { 1204. room->typ = CORR; 1205. unblock_point(zx,zy); /* vision */ 1206. }else if (!Blind && !Is_airlevel(&u.uz)) 1207. pline("The rock glows then fades."); 1208. break; 1209. } 1210. } else if(IS_ROCK(room->typ)) { 1211. if(may_dig(zx,zy)) { 1212. if(IS_WALL(room->typ) || 1213. room->typ == SDOOR) { 1214. if(*in_rooms(zx,zy,SHOPBASE)) { 1215. add_damage(zx, zy, 200L); 1216. shopwall = TRUE; 1217. } 1218. if (level.flags.is_cavernous_lev) { 1219. room->typ = CORR; 1220. } else { 1221. room->typ = DOOR; 1222. room->doormask = D_NODOOR; 1223. } 1224. digdepth -= 2; 1225. } else { 1226. room->typ = CORR; 1227. digdepth--; 1228. } 1229. unblock_point(zx,zy); /* vision */ 1230. } else 1231. break; 1232. } else if(closed_door(zx, zy)) { 1233. if(*in_rooms(zx,zy,SHOPBASE)) { 1234. shopdoor = TRUE; 1235. add_damage(zx, zy, 400L); 1236. } 1237. room->doormask = D_NODOOR; 1238. unblock_point(zx,zy); /* vision */ 1239. digdepth -= 2; 1240. } 1241. zx += u.dx; 1242. zy += u.dy; 1243. } /* while */ 1244. tmp_at(DISP_END,0); /* closing call */ 1245. if(shopdoor || shopwall) 1246. pay_for_damage(shopdoor? "destroy" : "dig into"); 1247. break; 1248. } 1249. default: 1250. if((int) obj->otyp >= SPE_MAGIC_MISSILE && 1251. (int) obj->otyp <= SPE_FINGER_OF_DEATH) { 1252. 1253. buzz((int) obj->otyp - SPE_MAGIC_MISSILE + 10, 1254. (int)u.ulevel / 2 + 1, u.ux, u.uy, u.dx, u.dy); 1255. 1256. } else if((int) obj->otyp >= WAN_MAGIC_MISSILE && 1257. (int) obj->otyp <= WAN_LIGHTNING) { 1258. 1259. buzz((int) obj->otyp - WAN_MAGIC_MISSILE, 1260. (obj->otyp == WAN_MAGIC_MISSILE) ? 2 : 6, 1261. u.ux, u.uy, u.dx, u.dy); 1262. } else 1263. impossible("weffects: unexpected spell or wand"); 1264. break; 1265. } 1266. if(!objects[obj->otyp].oc_name_known) { 1267. makeknown(obj->otyp); 1268. more_experienced(0,10); 1269. } 1270. } 1271. return; 1272. } 1273. 1274. const char * 1275. exclam(force) 1276. register int force; 1277. { 1278. /* force == 0 occurs e.g. with sleep ray */ 1279. /* note that large force is usual with wands so that !! would 1280. require information about hand/weapon/wand */ 1281. return (const char *)((force < 0) ? "?" : (force <= 4) ? "." : "!"); 1282. } 1283. 1284. void 1285. hit(str,mtmp,force) 1286. register const char *str; 1287. register struct monst *mtmp; 1288. register const char *force; /* usually either "." or "!" */ 1289. { 1290. if(!cansee(bhitpos.x,bhitpos.y) || !flags.verbose) 1291. pline("%s hits it.", The(str)); 1292. else pline("%s hits %s%s", The(str), mon_nam(mtmp), force); 1293. } 1294. 1295. void 1296. miss(str,mtmp) 1297. register const char *str; 1298. register struct monst *mtmp; 1299. { 1300. pline("%s misses %s.", The(str), 1301. (cansee(bhitpos.x,bhitpos.y) && flags.verbose) ? 1302. mon_nam(mtmp) : "it"); 1303. } 1304. 1305. /* 1306. * Called for the following distance effects: 1307. * when a weapon is thrown (weapon == THROWN_WEAPON) 1308. * when an object is kicked (KICKED_WEAPON) 1309. * when an IMMEDIATE wand is zapped (ZAPPED_WAND) 1310. * when a light beam is flashed (FLASHED_LIGHT) 1311. * for some invisible effect on a monster (INVIS_BEAM) 1312. * A thrown/kicked object falls down at the end of its range or when a monster 1313. * is hit. The variable 'bhitpos' is set to the final position of the weapon 1314. * thrown/zapped. The ray of a wand may affect (by calling a provided 1315. * function) several objects and monsters on its path. The return value 1316. * is the monster hit (weapon != ZAPPED_WAND), or a null monster pointer. 1317. * 1318. * Check !u.uswallow before calling bhit(). 1319. */ 1320. struct monst * 1321. bhit(ddx,ddy,range,weapon,fhitm,fhito,obj) 1322. register int ddx,ddy,range; /* direction and range */ 1323. int weapon; /* see values in hack.h */ 1324. /* fns called when mon/obj hit */ 1325. int FDECL((*fhitm), (MONST_P, OBJ_P)), 1326. FDECL((*fhito), (OBJ_P, OBJ_P)); 1327. struct obj *obj; /* object tossed/used */ 1328. { 1329. register struct monst *mtmp; 1330. register uchar typ; 1331. register boolean shopdoor = FALSE; 1332. 1333. if (weapon == KICKED_WEAPON) { 1334. /* object starts one square in front of player */ 1335. bhitpos.x = u.ux + ddx; 1336. bhitpos.y = u.uy + ddy; 1337. range--; 1338. } else { 1339. bhitpos.x = u.ux; 1340. bhitpos.y = u.uy; 1341. } 1342. 1343. if (weapon == FLASHED_LIGHT) { 1344. tmp_at(DISP_BEAM, cmap_to_glyph(S_flashbeam)); 1345. } else if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM) 1346. tmp_at(DISP_FLASH, obj_to_glyph(obj)); 1347. while(range-- > 0) { 1348. int x,y; 1349. 1350. bhitpos.x += ddx; 1351. bhitpos.y += ddy; 1352. x = bhitpos.x; y = bhitpos.y; 1353. 1354. if(!isok(x, y)) { 1355. bhitpos.x -= ddx; 1356. bhitpos.y -= ddy; 1357. break; 1358. } 1359. if(obj->otyp == PICK_AXE && inside_shop(x, y) && 1360. shkcatch(obj, x, y)) { 1361. tmp_at(DISP_END, 0); 1362. return(m_at(x, y)); 1363. } 1364. 1365. typ = levl[bhitpos.x][bhitpos.y].typ; 1366. 1367. if (weapon == ZAPPED_WAND && find_drawbridge(&x,&y)) 1368. switch (obj->otyp) { 1369. case WAN_OPENING: 1370. case SPE_KNOCK: 1371. if (is_db_wall(bhitpos.x, bhitpos.y)) { 1372. if (cansee(x,y) || cansee(bhitpos.x,bhitpos.y)) 1373. makeknown(obj->otyp); 1374. open_drawbridge(x,y); 1375. } 1376. break; 1377. case WAN_LOCKING: 1378. case SPE_WIZARD_LOCK: 1379. if ((cansee(x,y) || cansee(bhitpos.x, bhitpos.y)) 1380. && levl[x][y].typ == DRAWBRIDGE_DOWN) 1381. makeknown(obj->otyp); 1382. close_drawbridge(x,y); 1383. break; 1384. case WAN_STRIKING: 1385. case SPE_FORCE_BOLT: 1386. if (typ != DRAWBRIDGE_UP) 1387. destroy_drawbridge(x,y); 1388. makeknown(obj->otyp); 1389. break; 1390. } 1391. 1392. if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) { 1393. if(weapon != ZAPPED_WAND) { 1394. if(weapon != INVIS_BEAM) tmp_at(DISP_END, 0); 1395. return(mtmp); 1396. } 1397. (*fhitm)(mtmp, obj); 1398. range -= 3; 1399. } 1400. if(fhito) { 1401. if(bhitpile(obj,fhito,bhitpos.x,bhitpos.y)) 1402. range--; 1403. } else if(weapon == KICKED_WEAPON && 1404. ((obj->otyp == GOLD_PIECE && 1405. OBJ_AT(bhitpos.x, bhitpos.y)) || 1406. down_gate(bhitpos.x, bhitpos.y) != -1)) { 1407. tmp_at(DISP_END, 0); 1408. return (struct monst *)0; 1409. } 1410. if(weapon == ZAPPED_WAND && (IS_DOOR(typ) || typ == SDOOR)) { 1411. switch (obj->otyp) { 1412. case WAN_OPENING: 1413. case WAN_LOCKING: 1414. case WAN_STRIKING: 1415. case SPE_KNOCK: 1416. case SPE_WIZARD_LOCK: 1417. case SPE_FORCE_BOLT: 1418. if (doorlock(obj, bhitpos.x, bhitpos.y)) { 1419. if (cansee(bhitpos.x, bhitpos.y) || 1420. (obj->otyp == WAN_STRIKING)) 1421. makeknown(obj->otyp); 1422. if (levl[bhitpos.x][bhitpos.y].doormask == D_BROKEN 1423. && *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE)) { 1424. shopdoor = TRUE; 1425. } 1426. } 1427. break; 1428. } 1429. } 1430. if(!ZAP_POS(typ) || closed_door(bhitpos.x, bhitpos.y)) { 1431. bhitpos.x -= ddx; 1432. bhitpos.y -= ddy; 1433. break; 1434. } 1435. if(weapon != ZAPPED_WAND && weapon != INVIS_BEAM) { 1436. tmp_at(bhitpos.x, bhitpos.y); 1437. delay_output(); 1438. /* kicked objects fall in pools */ 1439. if((weapon == KICKED_WEAPON) && 1440. is_pool(bhitpos.x, bhitpos.y)) 1441. break; 1442. #ifdef SINKS 1443. if(IS_SINK(typ) && weapon != FLASHED_LIGHT) 1444. break; /* physical objects fall onto sink */ 1445. #endif 1446. } 1447. } 1448. 1449. if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM) tmp_at(DISP_END, 0); 1450. 1451. if(shopdoor) 1452. pay_for_damage("destroy"); 1453. 1454. return (struct monst *)0; 1455. } 1456. 1457. struct monst * 1458. boomhit(dx, dy) 1459. int dx, dy; 1460. { 1461. register int i, ct; 1462. int boom = S_boomleft; /* showsym[] index */ 1463. struct monst *mtmp; 1464. 1465. bhitpos.x = u.ux; 1466. bhitpos.y = u.uy; 1467. 1468. for(i=0; i<8; i++) if(xdir[i] == dx && ydir[i] == dy) break; 1469. tmp_at(DISP_FLASH, cmap_to_glyph(boom)); 1470. for(ct=0; ct<10; ct++) { 1471. if(i == 8) i = 0; 1472. boom = (boom == S_boomleft) ? S_boomright : S_boomleft; 1473. tmp_at(DISP_CHANGE, cmap_to_glyph(boom));/* change glyph */ 1474. dx = xdir[i]; 1475. dy = ydir[i]; 1476. bhitpos.x += dx; 1477. bhitpos.y += dy; 1478. if(MON_AT(bhitpos.x, bhitpos.y)) { 1479. mtmp = m_at(bhitpos.x,bhitpos.y); 1480. m_respond(mtmp); 1481. tmp_at(DISP_END, 0); 1482. return(mtmp); 1483. } 1484. if(!ZAP_POS(levl[bhitpos.x][bhitpos.y].typ) || 1485. closed_door(bhitpos.x, bhitpos.y)) { 1486. bhitpos.x -= dx; 1487. bhitpos.y -= dy; 1488. break; 1489. } 1490. if(bhitpos.x == u.ux && bhitpos.y == u.uy) { /* ct == 9 */ 1491. if(Fumbling || rn2(20) >= ACURR(A_DEX)) { 1492. /* we hit ourselves */ 1493. (void) thitu(10, rnd(10), (struct obj *)0, 1494. "boomerang"); 1495. break; 1496. } else { /* we catch it */ 1497. tmp_at(DISP_END, 0); 1498. pline("Skillfully, you catch the boomerang."); 1499. return(&youmonst); 1500. } 1501. } 1502. tmp_at(bhitpos.x, bhitpos.y); 1503. delay_output(); 1504. if(ct % 5 != 0) i++; 1505. #ifdef SINKS 1506. if(IS_SINK(levl[bhitpos.x][bhitpos.y].typ)) 1507. break; /* boomerang falls on sink */ 1508. #endif 1509. } 1510. tmp_at(DISP_END, 0); /* do not leave last symbol */ 1511. return (struct monst *)0; 1512. } 1513. 1514. static int 1515. zhit(mon, type, nd) /* returns damage to mon */ 1516. register struct monst *mon; 1517. register int type, nd; 1518. { 1519. register int tmp = 0; 1520. register int abstype = abs(type) % 10; 1521. 1522. switch(abstype) { 1523. case ZT_MAGIC_MISSILE: 1524. tmp = d(nd,6); 1525. break; 1526. case ZT_FIRE: 1527. if(resists_fire(mon->data)) { 1528. shieldeff(mon->mx, mon->my); 1529. break; 1530. } 1531. tmp = d(nd,6); 1532. if(resists_cold(mon->data)) tmp += 7; 1533. break; 1534. case ZT_COLD: 1535. if(resists_cold(mon->data)) { 1536. shieldeff(mon->mx, mon->my); 1537. break; 1538. } 1539. tmp = d(nd,6); 1540. if(resists_fire(mon->data)) tmp += d(nd, 3); 1541. break; 1542. case ZT_SLEEP: 1543. tmp = 0; 1544. if(resists_sleep(mon->data) || 1545. resist(mon, (type == ZT_WAND(ZT_SLEEP)) ? 1546. WAND_CLASS : '\0', 0, NOTELL)) 1547. shieldeff(mon->mx, mon->my); 1548. else if (mon->mcanmove) { 1549. int tmp2 = d(nd,25); 1550. mon->mcanmove = 0; 1551. if ((unsigned)mon->mfrozen + tmp2 > 127) 1552. mon->mfrozen = 127; 1553. else mon->mfrozen += tmp2; 1554. } 1555. break; 1556. case ZT_DEATH: /* death/disintegration */ 1557. if(abs(type) != ZT_BREATH(ZT_DEATH)) { /* death */ 1558. if(mon->data == &mons[PM_DEATH]) { 1559. mon->mhpmax += mon->mhpmax/2; 1560. mon->mhp = mon->mhpmax; 1561. tmp = 0; 1562. break; 1563. } 1564. if(is_undead(mon->data)) { 1565. shieldeff(mon->mx, mon->my); 1566. break; 1567. } 1568. type = -1; /* so they don't get saving throws */ 1569. } else { 1570. if (resists_disint(mon->data)) { 1571. shieldeff(mon->mx, mon->my); 1572. break; 1573. } else { 1574. tmp = MAGIC_COOKIE; 1575. break; 1576. } 1577. } 1578. tmp = mon->mhp+1; 1579. break; 1580. case ZT_LIGHTNING: 1581. if(resists_elec(mon->data)) { 1582. shieldeff(mon->mx, mon->my); 1583. break; 1584. } 1585. tmp = d(nd,6); 1586. if (haseyes(mon->data)) { 1587. register unsigned rnd_tmp = rnd(50); 1588. mon->mcansee = 0; 1589. if((mon->mblinded + rnd_tmp) > 127) 1590. mon->mblinded = 127; 1591. else mon->mblinded += rnd_tmp; 1592. } 1593. break; 1594. case ZT_POISON_GAS: 1595. if(resists_poison(mon->data)) { 1596. shieldeff(mon->mx, mon->my); 1597. break; 1598. } 1599. tmp = d(nd,6); 1600. break; 1601. case ZT_ACID: 1602. if(resists_acid(mon->data)) { 1603. shieldeff(mon->mx, mon->my); 1604. break; 1605. } 1606. tmp = d(nd,6); 1607. break; 1608. } 1609. #ifdef MULDGN 1610. if(pl_character[0] == 'K' && type >= 10 && type <= 19 && 1611. u.uhave.questart) tmp *= 2; 1612. #endif 1613. if (type >= 0) 1614. if (resist(mon, (type < ZT_SPELL(0)) ? WAND_CLASS : '\0', 1615. 0, NOTELL)) tmp /= 2; 1616. mon->mhp -= tmp; 1617. return(tmp); 1618. } 1619. 1620. /* 1621. * burn scrolls and spell books on floor at position x,y 1622. * return the number of scrolls and spell books burned 1623. */ 1624. static int 1625. burn_floor_paper(x, y) 1626. int x, y; 1627. { 1628. register struct obj *obj, *obj2; 1629. register int cnt = 0; 1630. register long i, scrquan; 1631. 1632. for(obj = level.objects[x][y]; obj; obj = obj2) { 1633. obj2 = obj->nexthere; 1634. /* Bug fix - KAA */ 1635. if(obj->oclass == SCROLL_CLASS 1636. || obj->oclass == SPBOOK_CLASS) { 1637. if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL) 1638. continue; 1639. scrquan = obj->quan; 1640. for(i = 1; i <= scrquan ; i++) 1641. if(!rn2(3)) { 1642. cnt++; 1643. /* not useupf(), which charges */ 1644. if (obj->quan > 1L) obj->quan--; 1645. else delobj(obj); 1646. } 1647. } 1648. } 1649. return(cnt); 1650. } 1651. 1652. /* type == 0 to 9 : you shooting a wand */ 1653. /* type == 10 to 19 : you casting a spell */ 1654. /* type == 20 to 29 : you breathing as a monster */ 1655. /* type == -10 to -19 : monster casting spell */ 1656. /* type == -20 to -29 : monster breathing at you */ 1657. /* type == -30 to -39 : monster shooting a wand (MUSE only) */ 1658. /* called with dx = dy = 0 with vertical bolts */ 1659. void 1660. buzz(type,nd,sx,sy,dx,dy) 1661. register int type, nd; 1662. register xchar sx,sy; 1663. register int dx,dy; 1664. { 1665. int range, abstype = abs(type) % 10; 1666. struct rm *lev; 1667. register xchar lsx, lsy; 1668. struct monst *mon; 1669. boolean bodyhit = FALSE, shopdamage = FALSE; 1670. #ifdef MUSE 1671. register const char *fltxt = fl[(type <= -30) ? abstype : abs(type)]; 1672. #else 1673. register const char *fltxt = fl[abs(type)]; 1674. #endif 1675. if(u.uswallow) { 1676. register int tmp; 1677. 1678. if(type < 0) return; 1679. tmp = zhit(u.ustuck, type, nd); 1680. if(!u.ustuck) u.uswallow = 0; 1681. else pline("%s rips into %s%s", 1682. The(fltxt), mon_nam(u.ustuck), exclam(tmp)); 1683. /* Using disintegration from the inside only makes a hole... */ 1684. if (tmp == MAGIC_COOKIE) 1685. u.ustuck->mhp = 0; 1686. if (u.ustuck->mhp < 1) 1687. killed(u.ustuck); 1688. return; 1689. } 1690. if(type < 0) newsym(u.ux,u.uy); 1691. range = rn1(7,7); 1692. if(dx == 0 && dy == 0) range = 1; 1693. tmp_at(DISP_BEAM, zapdir_to_glyph(dx, dy, abstype)); 1694. while(range-- > 0) { 1695. lsx = sx; sx += dx; 1696. lsy = sy; sy += dy; 1697. if(isok(sx,sy) && (lev = &levl[sx][sy])->typ) { 1698. if(cansee(sx,sy)) { 1699. if(ZAP_POS(lev->typ) || cansee(lsx,lsy)) 1700. tmp_at(sx,sy); 1701. delay_output(); /* wait a little */ 1702. } 1703. } else 1704. goto make_bounce; 1705. 1706. if (type != ZT_SPELL(ZT_FIRE)) 1707. /* Fireballs only damage when they explode */ 1708. range += zap_over_floor(sx, sy, type, &shopdamage); 1709. if ((mon = m_at(sx, sy)) != 0) { 1710. if (type == ZT_SPELL(ZT_FIRE)) break; 1711. if (type >= 0) mon->data->mflags3 &= ~M3_WAITMASK; 1712. if (rnd(20) < 18 + find_mac(mon)) { 1713. #ifdef MUSE 1714. struct obj *oshld = which_armor(mon, W_ARMS); 1715. 1716. if (oshld && oshld->otyp == SHIELD_OF_REFLECTION) { 1717. if(cansee(mon->mx,mon->my)) { 1718. hit(fltxt, mon, exclam(0)); 1719. pline("But it reflects from %s shield!", 1720. s_suffix(mon_nam(mon))); 1721. makeknown(SHIELD_OF_REFLECTION); 1722. shieldeff(sx, sy); 1723. } 1724. 1725. dx = -dx; 1726. dy = -dy; 1727. } else 1728. #endif 1729. { 1730. register int tmp = zhit(mon, type, nd); 1731. 1732. if (is_rider(mon->data) && type == ZT_BREATH(ZT_DEATH)) { 1733. if(cansee(mon->mx, mon->my)) { 1734. hit(fltxt, mon, exclam(tmp)); 1735. pline("%s disintegrates.", Monnam(mon)); 1736. if(Blind) 1737. You("sense the fragments of %s body reassembling!", 1738. s_suffix(mon_nam(mon))); 1739. else 1740. pline("%s body fragments reassemble before your %s!", 1741. s_suffix(Monnam(mon)), 1742. makeplural(body_part(EYE))); 1743. pline("%s resurrects!", Monnam(mon)); 1744. } 1745. mon->mhp = mon->mhpmax; 1746. break; /* Out of while loop */ 1747. } 1748. if(mon->data == &mons[PM_DEATH] && 1749. abs(type)%10 == ZT_DEATH) { 1750. if(cansee(mon->mx,mon->my)) { 1751. hit(fltxt, mon, exclam(tmp)); 1752. pline("Death absorbs the deadly %s!", 1753. type == ZT_BREATH(ZT_DEATH) ? 1754. "blast" : "ray"); 1755. pline("It seems even stronger than before."); 1756. } 1757. break; /* Out of while loop */ 1758. } 1759. if (tmp == MAGIC_COOKIE) { /* disintegration */ 1760. struct obj *otmp, *otmp2; 1761. pline("%s is disintegrated!", Monnam(mon)); 1762. mon->mgold = 0; 1763. otmp = mon->minvent; 1764. while(otmp) { 1765. #ifdef MULDGN 1766. if (is_quest_artifact(otmp)) 1767. otmp = otmp->nobj; 1768. else { 1769. #endif 1770. otmp2 = otmp; 1771. if (otmp == mon->minvent) 1772. mon->minvent = otmp->nobj; 1773. otmp = otmp->nobj; 1774. obfree(otmp2, (struct obj *)0); 1775. #ifdef MULDGN 1776. } 1777. #endif 1778. } 1779. if (type < 0) 1780. monkilled(mon, (char *)0, AD_RBRE); 1781. else 1782. xkilled(mon, 2); 1783. } else if(mon->mhp < 1) { 1784. if(type < 0) 1785. monkilled(mon, fltxt, AD_RBRE); 1786. else 1787. killed(mon); 1788. } else 1789. hit(fltxt, mon, exclam(tmp)); 1790. } 1791. range -= 2; 1792. } else 1793. miss(fltxt,mon); 1794. } else if(sx == u.ux && sy == u.uy) { 1795. nomul(0); 1796. if(rnd(20) < 18+u.uac) { 1797. register int dam = 0; 1798. range -= 2; 1799. pline("%s hits you!", The(fltxt)); 1800. if (Reflecting) { 1801. if (!Blind) { 1802. if(Reflecting & WORN_AMUL) 1803. makeknown(AMULET_OF_REFLECTION); 1804. else 1805. makeknown(SHIELD_OF_REFLECTION); 1806. pline("But it reflects from your %s!", 1807. (Reflecting & W_AMUL) ? "amulet" : "shield"); 1808. } else 1809. pline("For some reason you are not affected."); 1810. dx = -dx; 1811. dy = -dy; 1812. shieldeff(sx, sy); 1813. } 1814. else switch(abstype) { 1815. case ZT_MAGIC_MISSILE: 1816. if(Antimagic) { 1817. shieldeff(sx, sy); 1818. pline("The missiles bounce off!"); 1819. } else { 1820. dam = d(nd,6); 1821. exercise(A_STR, FALSE); 1822. } 1823. break; 1824. case ZT_FIRE: 1825. if(Fire_resistance) { 1826. shieldeff(sx, sy); 1827. You("don't feel hot!"); 1828. #ifdef POLYSELF 1829. ugolemeffects(AD_FIRE, d(nd, 6)); 1830. #endif 1831. } else dam = d(nd, 6); 1832. while (1) { 1833. switch(rn2(5)) { 1834. case 0: 1835. if (!rust_dmg(uarmh, "leather helmet", 0, FALSE)) 1836. continue; 1837. break; 1838. case 1: 1839. bodyhit = TRUE; 1840. if (uarmc) break; 1841. if (uarm) 1842. (void)(rust_dmg(uarm, xname(uarm), 0, FALSE)); 1843. break; 1844. case 2: 1845. if (!rust_dmg(uarms, "wooden shield", 0, FALSE)) 1846. continue; 1847. break; 1848. case 3: 1849. if (!rust_dmg(uarmg, "gloves", 0, FALSE)) continue; 1850. break; 1851. case 4: 1852. if (!rust_dmg(uarmf, "boots", 0, FALSE)) continue; 1853. break; 1854. } 1855. break; /* Out of while loop */ 1856. } 1857. if(!rn2(3) && bodyhit) 1858. destroy_item(POTION_CLASS, AD_FIRE); 1859. if(!rn2(3) && bodyhit) 1860. destroy_item(SCROLL_CLASS, AD_FIRE); 1861. if(!rn2(5) && bodyhit) 1862. destroy_item(SPBOOK_CLASS, AD_FIRE); 1863. break; 1864. case ZT_COLD: 1865. if(Cold_resistance) { 1866. shieldeff(sx, sy); 1867. You("don't feel cold."); 1868. #ifdef POLYSELF 1869. ugolemeffects(AD_COLD, d(nd, 6)); 1870. #endif 1871. } else 1872. dam = d(nd, 6); 1873. if(!rn2(3)) 1874. destroy_item(POTION_CLASS, AD_COLD); 1875. break; 1876. case ZT_SLEEP: 1877. if(Sleep_resistance) { 1878. shieldeff(u.ux, u.uy); 1879. You("don't feel sleepy."); 1880. } else { 1881. /* have to do this _before_ we reset multi */ 1882. stop_occupation(); 1883. nomul(-d(nd,25)); /* sleep ray */ 1884. u.usleep = 1; 1885. nomovemsg = "You wake up."; 1886. } 1887. break; 1888. case ZT_DEATH: 1889. if(abs(type) == ZT_BREATH(ZT_DEATH)) { 1890. if (Disint_resistance) { 1891. You("are not disintegrated."); 1892. break; 1893. } else if(uarms) { 1894. (void) destroy_arm(uarms); 1895. break; 1896. } else if (uarm) { 1897. (void) destroy_arm(uarm); 1898. break; 1899. } 1900. } 1901. #ifdef POLYSELF 1902. else if(is_undead(uasmon)) { 1903. shieldeff(sx, sy); 1904. You("seem unaffected."); 1905. break; 1906. } 1907. #endif 1908. else if(Antimagic) { 1909. shieldeff(sx, sy); 1910. You("aren't affected."); 1911. } else 1912. u.uhp = -1; 1913. break; 1914. case ZT_LIGHTNING: 1915. if (Shock_resistance) { 1916. shieldeff(sx, sy); 1917. You("aren't affected."); 1918. #ifdef POLYSELF 1919. ugolemeffects(AD_ELEC, d(nd, 6)); 1920. #endif 1921. } else { 1922. dam = d(nd, 6); 1923. exercise(A_CON, FALSE); 1924. } 1925. if(!rn2(3)) 1926. destroy_item(WAND_CLASS, AD_ELEC); 1927. if(!rn2(3)) 1928. destroy_item(RING_CLASS, AD_ELEC); 1929. break; 1930. case ZT_POISON_GAS: 1931. poisoned("blast", A_DEX, "poisoned blast", 15); 1932. break; 1933. case ZT_ACID: 1934. #ifdef POLYSELF 1935. if (resists_acid(uasmon)) 1936. dam = 0; 1937. else 1938. #endif 1939. { 1940. pline("The acid burns!"); 1941. dam = d(nd,6); 1942. exercise(A_STR, FALSE); 1943. } 1944. if(!rn2(6)) erode_weapon(TRUE); 1945. if(!rn2(6)) erode_armor(TRUE); 1946. break; 1947. } 1948. if(Half_spell_damage && dam && 1949. type < 0 && (type > -20 || type < -29)) /* !Breath */ 1950. dam = (dam+1) / 2; 1951. losehp(dam, fltxt, KILLED_BY_AN); 1952. } else pline("%s whizzes by you!", The(fltxt)); 1953. if (abstype == ZT_LIGHTNING && !Blind) { 1954. You("are blinded by the flash!"); 1955. make_blinded((long)d(nd,50),FALSE); 1956. } 1957. stop_occupation(); 1958. nomul(0); 1959. } 1960. if(!ZAP_POS(lev->typ) || (closed_door(sx, sy) && (range >= 0))) { 1961. int bounce; 1962. uchar rmn; 1963. 1964. make_bounce: 1965. if (type == ZT_SPELL(ZT_FIRE)) { 1966. sx = lsx; 1967. sy = lsy; 1968. break; /* fireballs explode before the wall */ 1969. } 1970. bounce = 0; 1971. range--; 1972. if(range && cansee(lsx,lsy)) 1973. pline("%s bounces!", The(fltxt)); 1974. if(!dx || !dy || !rn2(20)) { 1975. dx = -dx; 1976. dy = -dy; 1977. } else { 1978. if(isok(sx,lsy) && ZAP_POS(rmn = levl[sx][lsy].typ) && 1979. (IS_ROOM(rmn) || (isok(sx+dx,lsy) && 1980. ZAP_POS(levl[sx+dx][lsy].typ)))) 1981. bounce = 1; 1982. if(isok(lsx,sy) && ZAP_POS(rmn = levl[lsx][sy].typ) && 1983. (IS_ROOM(rmn) || (isok(lsx,sy+dy) && 1984. ZAP_POS(levl[lsx][sy+dy].typ)))) 1985. if(!bounce || rn2(2)) 1986. bounce = 2; 1987. 1988. switch(bounce) { 1989. case 0: dx = -dx; /* fall into... */ 1990. case 1: dy = -dy; break; 1991. case 2: dx = -dx; break; 1992. } 1993. tmp_at(DISP_CHANGE, zapdir_to_glyph(dx,dy,abstype)); 1994. } 1995. } 1996. } 1997. tmp_at(DISP_END,0); 1998. if (type == ZT_SPELL(ZT_FIRE)) 1999. explode(sx, sy, type, d(12,6), 0); 2000. if (shopdamage) 2001. pay_for_damage(abstype == ZT_FIRE ? "burn away" : 2002. abstype == ZT_COLD ? "shatter" : 2003. abstype == ZT_DEATH ? "disintegrate" : "destroy"); 2004. } 2005. 2006. /* Burn floor scrolls, evaporate pools, etc... in a single square. Used 2007. * both for normal bolts of fire, cold, etc... and for fireballs. 2008. * Sets shopdamage to TRUE if a shop door is destroyed, and returns the 2009. * amount by which range is reduced (the latter is just ignored by fireballs) 2010. */ 2011. int 2012. zap_over_floor(x, y, type, shopdamage) 2013. xchar x, y; 2014. int type; 2015. boolean *shopdamage; 2016. { 2017. struct monst *mon; 2018. int abstype = abs(type) % 10; 2019. struct rm *lev = &levl[x][y]; 2020. int rangemod = 0; 2021. 2022. if(abstype == ZT_FIRE) { 2023. if(is_ice(x, y)) { 2024. if (lev->typ == DRAWBRIDGE_UP) 2025. lev->drawbridgemask &= ~DB_ICE; /* revert to DB_MOAT */ 2026. else { /* lev->typ == ICE */ 2027. #ifdef STUPID 2028. if (lev->icedpool == ICED_POOL) lev->typ = POOL; 2029. else lev->typ = MOAT; 2030. #else 2031. lev->typ = (lev->icedpool == ICED_POOL ? POOL : MOAT); 2032. #endif 2033. lev->icedpool = 0; 2034. } 2035. newsym(x,y); 2036. Norep("The ice crackles and melts."); 2037. if (x == u.ux && y == u.uy) 2038. spoteffects(); /* possibly drown */ 2039. } else if(is_pool(x,y)) { 2040. const char *msgtxt = "You hear a hissing sound."; 2041. if(lev->typ != POOL) { /* MOAT or DRAWBRIDGE_UP */ 2042. if (cansee(x,y)) msgtxt = "Some water evaporates."; 2043. } else { 2044. register struct trap *ttmp; 2045. 2046. rangemod -= 3; 2047. lev->typ = ROOM; 2048. ttmp = maketrap(x, y, PIT); 2049. ttmp->tseen = 1; 2050. if (cansee(x,y)) msgtxt = "The water evaporates."; 2051. } 2052. Norep(msgtxt); 2053. if (lev->typ == ROOM) newsym(x,y); 2054. } 2055. } 2056. else if(abstype == ZT_COLD && (is_pool(x,y) || is_lava(x,y))) { 2057. boolean lava = is_lava(x,y); 2058. boolean moat = (!lava && (lev->typ != POOL) && 2059. (lev->typ != WATER) && 2060. !Is_medusa_level(&u.uz) && 2061. !Is_waterlevel(&u.uz)); 2062. 2063. if (lev->typ == WATER) { 2064. /* For now, don't let WATER freeze. */ 2065. if (cansee(x,y)) 2066. pline("The water freezes for a moment."); 2067. else 2068. You("hear a soft crackling sound"); 2069. rangemod -= 1000; /* stop */ 2070. } else { 2071. rangemod -= 3; 2072. if (lev->typ == DRAWBRIDGE_UP) { 2073. lev->drawbridgemask |= (lava ? DB_FLOOR : DB_ICE); 2074. } else { 2075. if (!lava) 2076. lev->icedpool = 2077. (lev->typ == POOL ? ICED_POOL : ICED_MOAT); 2078. lev->typ = (lava ? ROOM : ICE); 2079. } 2080. /* 2081. * Not perfect: There could be stuff on the bottom. If 2082. * we leave it here, it'll pop to the surface which is 2083. * strange, so just destroy all the objects at this location. 2084. * A better solution requires major changes (as usual). 2085. */ 2086. if(OBJ_AT(x,y)) 2087. delallobj(x,y); 2088. if(cansee(x,y)) { 2089. if(moat) 2090. Norep("The moat is bridged with ice!"); 2091. else if(lava) 2092. Norep("The lava cools and solidifies."); 2093. else 2094. Norep("The water freezes."); 2095. newsym(x,y); 2096. } else if(flags.soundok && !lava) 2097. You("hear a crackling sound."); 2098. if(x == u.ux && y == u.uy && 2099. u.utrap && u.utraptype == TT_LAVA) { 2100. #ifdef POLYSELF 2101. if (passes_walls(uasmon)) 2102. You("pass through the now-solid rock."); 2103. else { 2104. #endif 2105. u.utrap = rn1(50,20); 2106. u.utraptype = TT_INFLOOR; 2107. You("are firmly stuck in the cooling rock."); 2108. #ifdef POLYSELF 2109. } 2110. #endif 2111. } 2112. } 2113. } 2114. if(closed_door(x, y)) { 2115. rangemod = -1000; 2116. switch(abstype) { 2117. case ZT_FIRE: 2118. if(type >= 0 && *in_rooms(x, y, SHOPBASE)) { 2119. add_damage(x, y, 400L); 2120. *shopdamage = TRUE; 2121. } 2122. lev->doormask = D_NODOOR; 2123. unblock_point(x,y); /* vision */ 2124. if(cansee(x,y)) { 2125. pline("The door is consumed in flames!"); 2126. newsym(x,y); 2127. } 2128. else You("smell smoke."); 2129. break; 2130. case ZT_COLD: 2131. if(type >= 0 && *in_rooms(x, y, SHOPBASE)) { 2132. add_damage(x, y, 400L); 2133. *shopdamage = TRUE; 2134. } 2135. lev->doormask = D_NODOOR; 2136. unblock_point(x,y); /* vision */ 2137. if(cansee(x,y)) { 2138. pline("The door freezes and shatters!"); 2139. newsym(x,y); 2140. } 2141. else You("feel cold."); 2142. break; 2143. case ZT_DEATH: 2144. /* death spells/wands don't disintegrate */ 2145. if(abs(type) != ZT_BREATH(ZT_DEATH)) 2146. goto def_case; 2147. if(type >= 0 && *in_rooms(x, y, SHOPBASE)) { 2148. add_damage(x, y, 400L); 2149. *shopdamage = TRUE; 2150. } 2151. lev->doormask = D_NODOOR; 2152. unblock_point(x,y); /* vision */ 2153. if(cansee(x,y)) { 2154. pline("The door disintegrates!"); 2155. newsym(x,y); 2156. } 2157. else if(flags.soundok) 2158. You("hear a crashing sound."); 2159. break; 2160. case ZT_LIGHTNING: 2161. if(type >= 0 && *in_rooms(x, y, SHOPBASE)) { 2162. add_damage(x, y, 400L); 2163. *shopdamage = TRUE; 2164. } 2165. lev->doormask = D_BROKEN; 2166. unblock_point(x,y); /* vision */ 2167. if(cansee(x,y)) { 2168. pline("The door splinters!"); 2169. newsym(x,y); 2170. } 2171. else if(flags.soundok) 2172. You("hear a crackling sound."); 2173. break; 2174. default: 2175. def_case: 2176. if(cansee(x,y)) { 2177. pline("The door absorbs %s %s!", 2178. (type < 0) ? "the" : "your", 2179. abs(type) < ZT_SPELL(0) ? "bolt" : 2180. abs(type) < ZT_BREATH(0) ? "spell" : 2181. "blast"); 2182. } else You("feel vibrations."); 2183. break; 2184. } 2185. } 2186. if(OBJ_AT(x, y) && abstype == ZT_FIRE) 2187. if(burn_floor_paper(x,y) && cansee(x,y)) { 2188. newsym(x,y); 2189. if(!Blind) 2190. You("see a puff of smoke."); 2191. } 2192. if ((mon = m_at(x,y)) != 0) { 2193. /* Cannot use wakeup() which also angers the monster */ 2194. mon->msleep = 0; 2195. if(mon->m_ap_type) seemimic(mon); 2196. if(type >= 0) { 2197. setmangry(mon); 2198. if(mon->ispriest && *in_rooms(mon->mx, mon->my, TEMPLE)) 2199. ghod_hitsu(mon); 2200. if(mon->isshk && !*u.ushops) 2201. hot_pursuit(mon); 2202. } 2203. } 2204. return rangemod; 2205. } 2206. 2207. void 2208. rloco(obj) 2209. register struct obj *obj; 2210. { 2211. register xchar tx, ty, otx, oty; 2212. 2213. otx = obj->ox; 2214. oty = obj->oy; 2215. do { 2216. tx = rn1(COLNO-3,2); 2217. ty = rn2(ROWNO); 2218. } while(!goodpos(tx,ty,(struct monst *)0, (struct permonst *)0)); 2219. freeobj(obj); 2220. if (flooreffects(obj, tx, ty, "fall")) 2221. return; 2222. if(costly_spot(otx, oty) && (!costly_spot(tx, ty) || 2223. !index(in_rooms(tx, ty, 0), 2224. *in_rooms(otx, oty, 0)))) { 2225. if(costly_spot(u.ux, u.uy) && 2226. index(u.urooms, *in_rooms(otx, oty, 0))) 2227. addtobill(obj, FALSE, FALSE, FALSE); 2228. else (void)stolen_value(obj, otx, oty, FALSE, FALSE); 2229. } 2230. obj->nobj = fobj; 2231. fobj = obj; 2232. place_object(obj, tx, ty); 2233. newsym(otx, oty); 2234. newsym(tx,ty); 2235. } 2236. 2237. void 2238. fracture_rock(obj) /* fractured by pick-axe or wand of striking */ 2239. register struct obj *obj; /* no texts here! */ 2240. { 2241. obj->otyp = ROCK; 2242. obj->quan = (long) rn1(60, 7); 2243. obj->owt = weight(obj); 2244. obj->oclass = GEM_CLASS; 2245. obj->known = FALSE; 2246. obj->onamelth = 0; /* no names */ 2247. if(!does_block(obj->ox,obj->oy,&levl[obj->ox][obj->oy])) 2248. unblock_point(obj->ox,obj->oy); 2249. if(cansee(obj->ox,obj->oy)) 2250. newsym(obj->ox,obj->oy); 2251. } 2252. 2253. boolean 2254. break_statue(obj) 2255. register struct obj *obj; 2256. { 2257. struct trap *trap; 2258. struct obj *item, *nitem; 2259. 2260. if((trap = t_at(obj->ox,obj->oy)) && trap->ttyp == STATUE_TRAP) 2261. if(makemon(&mons[obj->corpsenm], obj->ox, obj->oy)) { 2262. pline("Instead of shattering, the statue suddenly comes alive!"); 2263. delobj(obj); 2264. deltrap(trap); 2265. return FALSE; 2266. } 2267. for(item = obj->cobj; item; item = nitem) { 2268. nitem = item->nobj; 2269. item->nobj = fobj; 2270. fobj = item; 2271. place_object(item, obj->ox, obj->oy); 2272. } 2273. obj->cobj = (struct obj *)0; 2274. fracture_rock(obj); 2275. return TRUE; 2276. } 2277. 2278. const char *destroy_strings[] = { 2279. "freezes and shatters", "freeze and shatter", "shattered potion", 2280. "boils and explodes", "boil and explode", "boiling potion", 2281. "catches fire and burns", "catch fire and burn", "burning scroll", 2282. "catches fire and burns", "catch fire and burn", "burning book", 2283. "turns to dust and vanishes", "turn to dust and vanish", "", 2284. "breaks apart and explodes", "break apart and explode", "exploding wand" 2285. }; 2286. 2287. void 2288. destroy_item(osym, dmgtyp) 2289. register int osym, dmgtyp; 2290. { 2291. register struct obj *obj, *obj2; 2292. register int dmg, xresist, skip; 2293. register long i, cnt, quan; 2294. register int dindx; 2295. const char *mult; 2296. 2297. for(obj = invent; obj; obj = obj2) { 2298. 2299. obj2 = obj->nobj; 2300. if(obj->oclass != osym) continue; /* test only objs of type osym */ 2301. if(obj->oartifact) continue; /* don't destroy artifacts */ 2302. xresist = skip = 0; 2303. #ifdef GCC_WARN 2304. dmg = dindx = 0; 2305. quan = 0L; 2306. #endif 2307. switch(dmgtyp) { 2308. case AD_COLD: 2309. if(osym == POTION_CLASS) { 2310. quan = obj->quan; 2311. dindx = 0; 2312. dmg = rnd(4); 2313. } else skip++; 2314. break; 2315. case AD_FIRE: 2316. xresist = (Fire_resistance && obj->oclass != POTION_CLASS); 2317. 2318. if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL) 2319. skip++; 2320. if (obj->otyp == SPE_BOOK_OF_THE_DEAD) { 2321. skip++; 2322. if (!Blind) 2323. pline("%s glows a strange %s, but remains intact.", 2324. The(xname(obj)), 2325. Hallucination ? hcolor() : "dark red"); 2326. } 2327. quan = obj->quan; 2328. switch(osym) { 2329. case POTION_CLASS: 2330. dindx = 1; 2331. dmg = rnd(6); 2332. break; 2333. case SCROLL_CLASS: 2334. dindx = 2; 2335. dmg = 1; 2336. break; 2337. case SPBOOK_CLASS: 2338. dindx = 3; 2339. dmg = 1; 2340. break; 2341. default: 2342. skip++; 2343. break; 2344. } 2345. break; 2346. case AD_ELEC: 2347. xresist = (Shock_resistance && obj->oclass != RING_CLASS); 2348. quan = obj->quan; 2349. switch(osym) { 2350. case RING_CLASS: 2351. if(obj->otyp == RIN_SHOCK_RESISTANCE) 2352. { skip++; break; } 2353. dindx = 4; 2354. dmg = 0; 2355. break; 2356. case WAND_CLASS: 2357. if(obj->otyp == WAN_LIGHTNING) { skip++; break; } 2358. dindx = 5; 2359. dmg = rnd(10); 2360. break; 2361. default: 2362. skip++; 2363. break; 2364. } 2365. break; 2366. default: 2367. skip++; 2368. break; 2369. } 2370. if(!skip) { 2371. for(i = cnt = 0L; i < quan; i++) 2372. if(!rn2(3)) cnt++; 2373. 2374. if(!cnt) continue; 2375. if(cnt == quan) mult = "Your"; 2376. else mult = (cnt == 1L) ? "One of your" : "Some of your"; 2377. pline("%s %s %s!", mult, xname(obj), 2378. (cnt > 1L) ? destroy_strings[dindx*3 + 1] 2379. : destroy_strings[dindx*3]); 2380. if(osym == POTION_CLASS && dmgtyp != AD_COLD) 2381. potionbreathe(obj); 2382. for(i = 0; i < cnt; i++) { 2383. if (obj->owornmask) { 2384. if (obj->owornmask & W_RING) /* ring being worn */ 2385. Ring_gone(obj); 2386. else 2387. setnotworn(obj); 2388. } 2389. useup(obj); 2390. } 2391. if(dmg) { 2392. if(xresist) You("aren't hurt!"); 2393. else { 2394. losehp(dmg, (cnt==1L) ? destroy_strings[dindx*3 + 2] : 2395. (const char *)makeplural(destroy_strings[dindx*3 + 2]), 2396. (cnt==1L) ? KILLED_BY_AN : KILLED_BY); 2397. exercise(A_STR, FALSE); 2398. } 2399. } 2400. } 2401. } 2402. return; 2403. } 2404. 2405. int 2406. destroy_mitem(mtmp, osym, dmgtyp) 2407. register struct monst *mtmp; 2408. register int osym, dmgtyp; 2409. { 2410. register struct obj *obj, *obj2; 2411. register int skip, tmp = 0; 2412. register long i, cnt, quan; 2413. register int dindx; 2414. boolean vis=canseemon(mtmp); 2415. 2416. for(obj = mtmp->minvent; obj; obj = obj2) { 2417. 2418. obj2 = obj->nobj; 2419. if(obj->oclass != osym) continue; /* test only objs of type osym */ 2420. skip = 0; 2421. #ifdef GCC_WARN 2422. quan = 0L; 2423. dindx = 0; 2424. #endif 2425. switch(dmgtyp) { 2426. case AD_COLD: 2427. if(osym == POTION_CLASS) { 2428. quan = obj->quan; 2429. dindx = 0; 2430. tmp++; 2431. } else skip++; 2432. break; 2433. case AD_FIRE: 2434. if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL) 2435. skip++; 2436. if (obj->otyp == SPE_BOOK_OF_THE_DEAD) { 2437. skip++; 2438. if (vis) 2439. pline("%s glows a strange %s, but remains intact.", 2440. The(distant_name(obj, xname)), 2441. Hallucination ? hcolor() : "dark red"); 2442. } 2443. quan = obj->quan; 2444. switch(osym) { 2445. case POTION_CLASS: 2446. dindx = 1; 2447. tmp++; 2448. break; 2449. case SCROLL_CLASS: 2450. dindx = 2; 2451. tmp++; 2452. break; 2453. case SPBOOK_CLASS: 2454. dindx = 3; 2455. tmp++; 2456. break; 2457. default: 2458. skip++; 2459. break; 2460. } 2461. break; 2462. case AD_ELEC: 2463. quan = obj->quan; 2464. switch(osym) { 2465. case RING_CLASS: 2466. if(obj->otyp == RIN_SHOCK_RESISTANCE) 2467. { skip++; break; } 2468. dindx = 4; 2469. break; 2470. case WAND_CLASS: 2471. if(obj->otyp == WAN_LIGHTNING) { skip++; break; } 2472. dindx = 5; 2473. tmp++; 2474. break; 2475. default: 2476. skip++; 2477. break; 2478. } 2479. break; 2480. default: 2481. skip++; 2482. break; 2483. } 2484. if(!skip) { 2485. for(i = cnt = 0L; i < quan; i++) 2486. if(!rn2(3)) cnt++; 2487. 2488. if(!cnt) continue; 2489. if (vis) pline("%s %s %s!", 2490. s_suffix(Monnam(mtmp)), xname(obj), 2491. (cnt > 1L) ? destroy_strings[dindx*3 + 1] 2492. : destroy_strings[dindx*3]); 2493. for(i = 0; i < cnt; i++) m_useup(mtmp, obj); 2494. } 2495. } 2496. return(tmp); 2497. } 2498. 2499. /*ARGSUSED*/ 2500. int 2501. resist(mtmp, class, damage, tell) 2502. register struct monst *mtmp; 2503. register char class; 2504. register int damage, tell; 2505. { 2506. register int resisted; 2507. register int lev; 2508. 2509. switch(class) { 2510. 2511. case WAND_CLASS: 2512. lev = 8; 2513. break; 2514. 2515. case SCROLL_CLASS: 2516. lev = 6; 2517. break; 2518. 2519. case POTION_CLASS: 2520. lev = 5; 2521. break; 2522. 2523. default: lev = u.ulevel; 2524. break; 2525. } 2526. 2527. resisted = (rn2(100) - (unsigned)mtmp->m_lev + lev) < mtmp->data->mr; 2528. if(resisted) { 2529. 2530. if(tell) { 2531. shieldeff(mtmp->mx, mtmp->my); 2532. pline("%s resists!", Monnam(mtmp)); 2533. } 2534. mtmp->mhp -= damage/2; 2535. } else mtmp->mhp -= damage; 2536. 2537. #ifdef MUSE 2538. if(mtmp->mhp < 1) { 2539. if(m_using) monkilled(mtmp, "", AD_RBRE); 2540. else killed(mtmp); 2541. } 2542. #else 2543. if(mtmp->mhp < 1) killed(mtmp); 2544. #endif 2545. return(resisted); 2546. } 2547. 2548. void 2549. makewish() 2550. { 2551. char buf[BUFSZ]; 2552. register struct obj *otmp; 2553. int tries = 0; 2554. 2555. if (flags.verbose) You("may wish for an object."); 2556. retry: 2557. getlin("For what do you wish?", buf); 2558. if(buf[0] == '\033') buf[0] = 0; 2559. /* 2560. * Note: if they wished for and got a non-object successfully, 2561. * otmp == &zeroobj 2562. */ 2563. otmp = readobjnam(buf); 2564. if (!otmp) { 2565. pline("Nothing fitting that description exists in the game."); 2566. if (++tries < 5) goto retry; 2567. pline(thats_enough_tries); 2568. if (!(otmp = readobjnam((char *)0))) 2569. return; /* for safety; should never happen */ 2570. } 2571. if (otmp != &zeroobj) { 2572. if(otmp->oartifact && !touch_artifact(otmp,&youmonst)) 2573. dropy(otmp); 2574. else 2575. /* The(aobjnam()) is safe since otmp is unidentified -dlc */ 2576. (void) hold_another_object(otmp, u.uswallow ? 2577. "Oops! %s out of your reach!" : 2578. Is_airlevel(&u.uz) ? 2579. "Oops! %s out of your grasp!" : 2580. "Oops! %s to the floor!", 2581. The(aobjnam(otmp, Is_airlevel(&u.uz) ? 2582. "slip" : "drop")), 2583. (const char *)0); 2584. u.ublesscnt += rn1(100,50); /* the gods take notice */ 2585. } 2586. } 2587. 2588. /*zap.c*/