Source:NetHack 3.6.3/src/trap.c
Jump to navigation
Jump to search
Below is the full text to trap.c from the source code of NetHack 3.6.3. To link to a particular line, write [[Source:NetHack 3.6.3/src/trap.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 trap.c $NHDT-Date: 1569189770 2019/09/22 22:02:50 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.317 $ */ 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. extern const char *const destroy_strings[][3]; /* from zap.c */ 9. 10. STATIC_DCL boolean FDECL(keep_saddle_with_steedcorpse, (unsigned, struct obj *, 11. struct obj *)); 12. STATIC_DCL struct obj *FDECL(t_missile, (int, struct trap *)); 13. STATIC_DCL char *FDECL(trapnote, (struct trap *, BOOLEAN_P)); 14. STATIC_DCL int FDECL(steedintrap, (struct trap *, struct obj *)); 15. STATIC_DCL void FDECL(launch_drop_spot, (struct obj *, XCHAR_P, XCHAR_P)); 16. STATIC_DCL int FDECL(mkroll_launch, (struct trap *, XCHAR_P, XCHAR_P, 17. SHORT_P, long)); 18. STATIC_DCL boolean FDECL(isclearpath, (coord *, int, SCHAR_P, SCHAR_P)); 19. STATIC_DCL void FDECL(dofiretrap, (struct obj *)); 20. STATIC_DCL void NDECL(domagictrap); 21. STATIC_DCL boolean FDECL(emergency_disrobe, (boolean *)); 22. STATIC_DCL int FDECL(untrap_prob, (struct trap *)); 23. STATIC_DCL void FDECL(move_into_trap, (struct trap *)); 24. STATIC_DCL int FDECL(try_disarm, (struct trap *, BOOLEAN_P)); 25. STATIC_DCL void FDECL(reward_untrap, (struct trap *, struct monst *)); 26. STATIC_DCL int FDECL(disarm_holdingtrap, (struct trap *)); 27. STATIC_DCL int FDECL(disarm_landmine, (struct trap *)); 28. STATIC_DCL int FDECL(disarm_squeaky_board, (struct trap *)); 29. STATIC_DCL int FDECL(disarm_shooting_trap, (struct trap *, int)); 30. STATIC_DCL void FDECL(clear_conjoined_pits, (struct trap *)); 31. STATIC_DCL boolean FDECL(adj_nonconjoined_pit, (struct trap *)); 32. STATIC_DCL int FDECL(try_lift, (struct monst *, struct trap *, int, 33. BOOLEAN_P)); 34. STATIC_DCL int FDECL(help_monster_out, (struct monst *, struct trap *)); 35. #if 0 36. STATIC_DCL void FDECL(join_adjacent_pits, (struct trap *)); 37. #endif 38. STATIC_DCL boolean FDECL(thitm, (int, struct monst *, struct obj *, int, 39. BOOLEAN_P)); 40. STATIC_DCL void NDECL(maybe_finish_sokoban); 41. 42. /* mintrap() should take a flags argument, but for time being we use this */ 43. STATIC_VAR int force_mintrap = 0; 44. 45. STATIC_VAR const char *const a_your[2] = { "a", "your" }; 46. STATIC_VAR const char *const A_Your[2] = { "A", "Your" }; 47. STATIC_VAR const char tower_of_flame[] = "tower of flame"; 48. STATIC_VAR const char *const A_gush_of_water_hits = "A gush of water hits"; 49. STATIC_VAR const char *const blindgas[6] = { "humid", "odorless", 50. "pungent", "chilling", 51. "acrid", "biting" }; 52. 53. /* called when you're hit by fire (dofiretrap,buzz,zapyourself,explode); 54. returns TRUE if hit on torso */ 55. boolean 56. burnarmor(victim) 57. struct monst *victim; 58. { 59. struct obj *item; 60. char buf[BUFSZ]; 61. int mat_idx, oldspe; 62. boolean hitting_u; 63. 64. if (!victim) 65. return 0; 66. hitting_u = (victim == &youmonst); 67. 68. /* burning damage may dry wet towel */ 69. item = hitting_u ? carrying(TOWEL) : m_carrying(victim, TOWEL); 70. while (item) { 71. if (is_wet_towel(item)) { 72. oldspe = item->spe; 73. dry_a_towel(item, rn2(oldspe + 1), TRUE); 74. if (item->spe != oldspe) 75. break; /* stop once one towel has been affected */ 76. } 77. item = item->nobj; 78. } 79. 80. #define burn_dmg(obj, descr) erode_obj(obj, descr, ERODE_BURN, EF_GREASE) 81. while (1) { 82. switch (rn2(5)) { 83. case 0: 84. item = hitting_u ? uarmh : which_armor(victim, W_ARMH); 85. if (item) { 86. mat_idx = objects[item->otyp].oc_material; 87. Sprintf(buf, "%s %s", materialnm[mat_idx], 88. helm_simple_name(item)); 89. } 90. if (!burn_dmg(item, item ? buf : "helmet")) 91. continue; 92. break; 93. case 1: 94. item = hitting_u ? uarmc : which_armor(victim, W_ARMC); 95. if (item) { 96. (void) burn_dmg(item, cloak_simple_name(item)); 97. return TRUE; 98. } 99. item = hitting_u ? uarm : which_armor(victim, W_ARM); 100. if (item) { 101. (void) burn_dmg(item, xname(item)); 102. return TRUE; 103. } 104. item = hitting_u ? uarmu : which_armor(victim, W_ARMU); 105. if (item) 106. (void) burn_dmg(item, "shirt"); 107. return TRUE; 108. case 2: 109. item = hitting_u ? uarms : which_armor(victim, W_ARMS); 110. if (!burn_dmg(item, "wooden shield")) 111. continue; 112. break; 113. case 3: 114. item = hitting_u ? uarmg : which_armor(victim, W_ARMG); 115. if (!burn_dmg(item, "gloves")) 116. continue; 117. break; 118. case 4: 119. item = hitting_u ? uarmf : which_armor(victim, W_ARMF); 120. if (!burn_dmg(item, "boots")) 121. continue; 122. break; 123. } 124. break; /* Out of while loop */ 125. } 126. #undef burn_dmg 127. 128. return FALSE; 129. } 130. 131. /* Generic erode-item function. 132. * "ostr", if non-null, is an alternate string to print instead of the 133. * object's name. 134. * "type" is an ERODE_* value for the erosion type 135. * "flags" is an or-ed list of EF_* flags 136. * 137. * Returns an erosion return value (ER_*) 138. */ 139. int 140. erode_obj(otmp, ostr, type, ef_flags) 141. register struct obj *otmp; 142. const char *ostr; 143. int type; 144. int ef_flags; 145. { 146. static NEARDATA const char 147. *const action[] = { "smoulder", "rust", "rot", "corrode" }, 148. *const msg[] = { "burnt", "rusted", "rotten", "corroded" }, 149. *const bythe[] = { "heat", "oxidation", "decay", "corrosion" }; 150. boolean vulnerable = FALSE, is_primary = TRUE, 151. check_grease = (ef_flags & EF_GREASE) ? TRUE : FALSE, 152. print = (ef_flags & EF_VERBOSE) ? TRUE : FALSE, 153. uvictim, vismon, visobj; 154. int erosion, cost_type; 155. struct monst *victim; 156. 157. if (!otmp) 158. return ER_NOTHING; 159. 160. victim = carried(otmp) ? &youmonst : mcarried(otmp) ? otmp->ocarry : NULL; 161. uvictim = (victim == &youmonst); 162. vismon = victim && (victim != &youmonst) && canseemon(victim); 163. /* Is bhitpos correct here? Ugh. */ 164. visobj = !victim && cansee(bhitpos.x, bhitpos.y); 165. 166. switch (type) { 167. case ERODE_BURN: 168. vulnerable = is_flammable(otmp); 169. check_grease = FALSE; 170. cost_type = COST_BURN; 171. break; 172. case ERODE_RUST: 173. vulnerable = is_rustprone(otmp); 174. cost_type = COST_RUST; 175. break; 176. case ERODE_ROT: 177. vulnerable = is_rottable(otmp); 178. check_grease = FALSE; 179. is_primary = FALSE; 180. cost_type = COST_ROT; 181. break; 182. case ERODE_CORRODE: 183. vulnerable = is_corrodeable(otmp); 184. is_primary = FALSE; 185. cost_type = COST_CORRODE; 186. break; 187. default: 188. impossible("Invalid erosion type in erode_obj"); 189. return ER_NOTHING; 190. } 191. erosion = is_primary ? otmp->oeroded : otmp->oeroded2; 192. 193. if (!ostr) 194. ostr = cxname(otmp); 195. /* 'visobj' messages insert "the"; probably ought to switch to the() */ 196. if (visobj && !(uvictim || vismon) && !strncmpi(ostr, "the ", 4)) 197. ostr += 4; 198. 199. if (check_grease && otmp->greased) { 200. grease_protect(otmp, ostr, victim); 201. return ER_GREASED; 202. } else if (!erosion_matters(otmp)) { 203. return ER_NOTHING; 204. } else if (!vulnerable || (otmp->oerodeproof && otmp->rknown)) { 205. if (flags.verbose && print && (uvictim || vismon)) 206. pline("%s %s %s not affected by %s.", 207. uvictim ? "Your" : s_suffix(Monnam(victim)), 208. ostr, vtense(ostr, "are"), bythe[type]); 209. return ER_NOTHING; 210. } else if (otmp->oerodeproof || (otmp->blessed && !rnl(4))) { 211. if (flags.verbose && (print || otmp->oerodeproof) 212. && (uvictim || vismon || visobj)) 213. pline("Somehow, %s %s %s not affected by the %s.", 214. uvictim ? "your" 215. : !vismon ? "the" /* visobj */ 216. : s_suffix(mon_nam(victim)), 217. ostr, vtense(ostr, "are"), bythe[type]); 218. /* We assume here that if the object is protected because it 219. * is blessed, it still shows some minor signs of wear, and 220. * the hero can distinguish this from an object that is 221. * actually proof against damage. 222. */ 223. if (otmp->oerodeproof) { 224. otmp->rknown = TRUE; 225. if (victim == &youmonst) 226. update_inventory(); 227. } 228. 229. return ER_NOTHING; 230. } else if (erosion < MAX_ERODE) { 231. const char *adverb = (erosion + 1 == MAX_ERODE) 232. ? " completely" 233. : erosion ? " further" : ""; 234. 235. if (uvictim || vismon || visobj) 236. pline("%s %s %s%s!", 237. uvictim ? "Your" 238. : !vismon ? "The" /* visobj */ 239. : s_suffix(Monnam(victim)), 240. ostr, vtense(ostr, action[type]), adverb); 241. 242. if (ef_flags & EF_PAY) 243. costly_alteration(otmp, cost_type); 244. 245. if (is_primary) 246. otmp->oeroded++; 247. else 248. otmp->oeroded2++; 249. 250. if (victim == &youmonst) 251. update_inventory(); 252. 253. return ER_DAMAGED; 254. } else if (ef_flags & EF_DESTROY) { 255. if (uvictim || vismon || visobj) 256. pline("%s %s %s away!", 257. uvictim ? "Your" 258. : !vismon ? "The" /* visobj */ 259. : s_suffix(Monnam(victim)), 260. ostr, vtense(ostr, action[type])); 261. 262. if (ef_flags & EF_PAY) 263. costly_alteration(otmp, cost_type); 264. 265. setnotworn(otmp); 266. delobj(otmp); 267. return ER_DESTROYED; 268. } else { 269. if (flags.verbose && print) { 270. if (uvictim) 271. Your("%s %s completely %s.", 272. ostr, vtense(ostr, Blind ? "feel" : "look"), msg[type]); 273. else if (vismon || visobj) 274. pline("%s %s %s completely %s.", 275. !vismon ? "The" : s_suffix(Monnam(victim)), 276. ostr, vtense(ostr, "look"), msg[type]); 277. } 278. return ER_NOTHING; 279. } 280. } 281. 282. /* Protect an item from erosion with grease. Returns TRUE if the grease 283. * wears off. 284. */ 285. boolean 286. grease_protect(otmp, ostr, victim) 287. register struct obj *otmp; 288. const char *ostr; 289. struct monst *victim; 290. { 291. static const char txt[] = "protected by the layer of grease!"; 292. boolean vismon = victim && (victim != &youmonst) && canseemon(victim); 293. 294. if (ostr) { 295. if (victim == &youmonst) 296. Your("%s %s %s", ostr, vtense(ostr, "are"), txt); 297. else if (vismon) 298. pline("%s's %s %s %s", Monnam(victim), 299. ostr, vtense(ostr, "are"), txt); 300. } else if (victim == &youmonst || vismon) { 301. pline("%s %s", Yobjnam2(otmp, "are"), txt); 302. } 303. if (!rn2(2)) { 304. otmp->greased = 0; 305. if (carried(otmp)) { 306. pline_The("grease dissolves."); 307. update_inventory(); 308. } 309. return TRUE; 310. } 311. return FALSE; 312. } 313. 314. struct trap * 315. maketrap(x, y, typ) 316. int x, y, typ; 317. { 318. static union vlaunchinfo zero_vl; 319. boolean oldplace; 320. struct trap *ttmp; 321. struct rm *lev = &levl[x][y]; 322. 323. if ((ttmp = t_at(x, y)) != 0) { 324. if (ttmp->ttyp == MAGIC_PORTAL || ttmp->ttyp == VIBRATING_SQUARE) 325. return (struct trap *) 0; 326. oldplace = TRUE; 327. if (u.utrap && x == u.ux && y == u.uy 328. && ((u.utraptype == TT_BEARTRAP && typ != BEAR_TRAP) 329. || (u.utraptype == TT_WEB && typ != WEB) 330. || (u.utraptype == TT_PIT && !is_pit(typ)))) 331. u.utrap = 0; 332. /* old <tx,ty> remain valid */ 333. } else if (IS_FURNITURE(lev->typ) 334. && (!IS_GRAVE(lev->typ) || (typ != PIT && typ != HOLE))) { 335. /* no trap on top of furniture (caller usually screens the 336. location to inhibit this, but wizard mode wishing doesn't) */ 337. return (struct trap *) 0; 338. } else { 339. oldplace = FALSE; 340. ttmp = newtrap(); 341. (void) memset((genericptr_t)ttmp, 0, sizeof(struct trap)); 342. ttmp->ntrap = 0; 343. ttmp->tx = x; 344. ttmp->ty = y; 345. } 346. /* [re-]initialize all fields except ntrap (handled below) and <tx,ty> */ 347. ttmp->vl = zero_vl; 348. ttmp->launch.x = ttmp->launch.y = -1; /* force error if used before set */ 349. ttmp->dst.dnum = ttmp->dst.dlevel = -1; 350. ttmp->madeby_u = 0; 351. ttmp->once = 0; 352. ttmp->tseen = (typ == HOLE); /* hide non-holes */ 353. ttmp->ttyp = typ; 354. 355. switch (typ) { 356. case SQKY_BOARD: { 357. int tavail[12], tpick[12], tcnt = 0, k; 358. struct trap *t; 359. 360. for (k = 0; k < 12; ++k) 361. tavail[k] = tpick[k] = 0; 362. for (t = ftrap; t; t = t->ntrap) 363. if (t->ttyp == SQKY_BOARD && t != ttmp) 364. tavail[t->tnote] = 1; 365. /* now populate tpick[] with the available indices */ 366. for (k = 0; k < 12; ++k) 367. if (tavail[k] == 0) 368. tpick[tcnt++] = k; 369. /* choose an unused note; if all are in use, pick a random one */ 370. ttmp->tnote = (short) ((tcnt > 0) ? tpick[rn2(tcnt)] : rn2(12)); 371. break; 372. } 373. case STATUE_TRAP: { /* create a "living" statue */ 374. struct monst *mtmp; 375. struct obj *otmp, *statue; 376. struct permonst *mptr; 377. int trycount = 10; 378. 379. do { /* avoid ultimately hostile co-aligned unicorn */ 380. mptr = &mons[rndmonnum()]; 381. } while (--trycount > 0 && is_unicorn(mptr) 382. && sgn(u.ualign.type) == sgn(mptr->maligntyp)); 383. statue = mkcorpstat(STATUE, (struct monst *) 0, mptr, x, y, 384. CORPSTAT_NONE); 385. mtmp = makemon(&mons[statue->corpsenm], 0, 0, MM_NOCOUNTBIRTH); 386. if (!mtmp) 387. break; /* should never happen */ 388. while (mtmp->minvent) { 389. otmp = mtmp->minvent; 390. otmp->owornmask = 0; 391. obj_extract_self(otmp); 392. (void) add_to_container(statue, otmp); 393. } 394. statue->owt = weight(statue); 395. mongone(mtmp); 396. break; 397. } 398. case ROLLING_BOULDER_TRAP: /* boulder will roll towards trigger */ 399. (void) mkroll_launch(ttmp, x, y, BOULDER, 1L); 400. break; 401. case PIT: 402. case SPIKED_PIT: 403. ttmp->conjoined = 0; 404. /*FALLTHRU*/ 405. case HOLE: 406. case TRAPDOOR: 407. if (*in_rooms(x, y, SHOPBASE) 408. && (is_hole(typ) || IS_DOOR(lev->typ) || IS_WALL(lev->typ))) 409. add_damage(x, y, /* schedule repair */ 410. ((IS_DOOR(lev->typ) || IS_WALL(lev->typ)) 411. && !context.mon_moving) 412. ? SHOP_HOLE_COST 413. : 0L); 414. lev->doormask = 0; /* subsumes altarmask, icedpool... */ 415. if (IS_ROOM(lev->typ)) /* && !IS_AIR(lev->typ) */ 416. lev->typ = ROOM; 417. /* 418. * some cases which can happen when digging 419. * down while phazing thru solid areas 420. */ 421. else if (lev->typ == STONE || lev->typ == SCORR) 422. lev->typ = CORR; 423. else if (IS_WALL(lev->typ) || lev->typ == SDOOR) 424. lev->typ = level.flags.is_maze_lev 425. ? ROOM 426. : level.flags.is_cavernous_lev ? CORR : DOOR; 427. 428. unearth_objs(x, y); 429. break; 430. } 431. 432. if (!oldplace) { 433. ttmp->ntrap = ftrap; 434. ftrap = ttmp; 435. } else { 436. /* oldplace; 437. it shouldn't be possible to override a sokoban pit or hole 438. with some other trap, but we'll check just to be safe */ 439. if (Sokoban) 440. maybe_finish_sokoban(); 441. } 442. return ttmp; 443. } 444. 445. void 446. fall_through(td) 447. boolean td; /* td == TRUE : trap door or hole */ 448. { 449. d_level dtmp; 450. char msgbuf[BUFSZ]; 451. const char *dont_fall = 0; 452. int newlevel, bottom; 453. 454. /* we'll fall even while levitating in Sokoban; otherwise, if we 455. won't fall and won't be told that we aren't falling, give up now */ 456. if (Blind && Levitation && !Sokoban) 457. return; 458. 459. bottom = dunlevs_in_dungeon(&u.uz); 460. /* when in the upper half of the quest, don't fall past the 461. middle "quest locate" level if hero hasn't been there yet */ 462. if (In_quest(&u.uz)) { 463. int qlocate_depth = qlocate_level.dlevel; 464. 465. /* deepest reached < qlocate implies current < qlocate */ 466. if (dunlev_reached(&u.uz) < qlocate_depth) 467. bottom = qlocate_depth; /* early cut-off */ 468. } 469. newlevel = dunlev(&u.uz); /* current level */ 470. do { 471. newlevel++; 472. } while (!rn2(4) && newlevel < bottom); 473. 474. if (td) { 475. struct trap *t = t_at(u.ux, u.uy); 476. 477. feeltrap(t); 478. if (!Sokoban) { 479. if (t->ttyp == TRAPDOOR) 480. pline("A trap door opens up under you!"); 481. else 482. pline("There's a gaping hole under you!"); 483. } 484. } else 485. pline_The("%s opens up under you!", surface(u.ux, u.uy)); 486. 487. if (Sokoban && Can_fall_thru(&u.uz)) 488. ; /* KMH -- You can't escape the Sokoban level traps */ 489. else if (Levitation || u.ustuck 490. || (!Can_fall_thru(&u.uz) && !levl[u.ux][u.uy].candig) || Flying 491. || is_clinger(youmonst.data) 492. || (Inhell && !u.uevent.invoked && newlevel == bottom)) { 493. dont_fall = "don't fall in."; 494. } else if (youmonst.data->msize >= MZ_HUGE) { 495. dont_fall = "don't fit through."; 496. } else if (!next_to_u()) { 497. dont_fall = "are jerked back by your pet!"; 498. } 499. if (dont_fall) { 500. You1(dont_fall); 501. /* hero didn't fall through, but any objects here might */ 502. impact_drop((struct obj *) 0, u.ux, u.uy, 0); 503. if (!td) { 504. display_nhwindow(WIN_MESSAGE, FALSE); 505. pline_The("opening under you closes up."); 506. } 507. return; 508. } 509. 510. if (*u.ushops) 511. shopdig(1); 512. if (Is_stronghold(&u.uz)) { 513. find_hell(&dtmp); 514. } else { 515. int dist = newlevel - dunlev(&u.uz); 516. dtmp.dnum = u.uz.dnum; 517. dtmp.dlevel = newlevel; 518. if (dist > 1) 519. You("fall down a %s%sshaft!", dist > 3 ? "very " : "", 520. dist > 2 ? "deep " : ""); 521. } 522. if (!td) 523. Sprintf(msgbuf, "The hole in the %s above you closes up.", 524. ceiling(u.ux, u.uy)); 525. 526. schedule_goto(&dtmp, FALSE, TRUE, 0, (char *) 0, 527. !td ? msgbuf : (char *) 0); 528. } 529. 530. /* 531. * Animate the given statue. May have been via shatter attempt, trap, 532. * or stone to flesh spell. Return a monster if successfully animated. 533. * If the monster is animated, the object is deleted. If fail_reason 534. * is non-null, then fill in the reason for failure (or success). 535. * 536. * The cause of animation is: 537. * 538. * ANIMATE_NORMAL - hero "finds" the monster 539. * ANIMATE_SHATTER - hero tries to destroy the statue 540. * ANIMATE_SPELL - stone to flesh spell hits the statue 541. * 542. * Perhaps x, y is not needed if we can use get_obj_location() to find 543. * the statue's location... ??? 544. * 545. * Sequencing matters: 546. * create monster; if it fails, give up with statue intact; 547. * give "statue comes to life" message; 548. * if statue belongs to shop, have shk give "you owe" message; 549. * transfer statue contents to monster (after stolen_value()); 550. * delete statue. 551. * [This ordering means that if the statue ends up wearing a cloak of 552. * invisibility or a mummy wrapping, the visibility checks might be 553. * wrong, but to avoid that we'd have to clone the statue contents 554. * first in order to give them to the monster before checking their 555. * shop status--it's not worth the hassle.] 556. */ 557. struct monst * 558. animate_statue(statue, x, y, cause, fail_reason) 559. struct obj *statue; 560. xchar x, y; 561. int cause; 562. int *fail_reason; 563. { 564. int mnum = statue->corpsenm; 565. struct permonst *mptr = &mons[mnum]; 566. struct monst *mon = 0, *shkp; 567. struct obj *item; 568. coord cc; 569. boolean historic = (Role_if(PM_ARCHEOLOGIST) 570. && (statue->spe & STATUE_HISTORIC) != 0), 571. golem_xform = FALSE, use_saved_traits; 572. const char *comes_to_life; 573. char statuename[BUFSZ], tmpbuf[BUFSZ]; 574. static const char historic_statue_is_gone[] = 575. "that the historic statue is now gone"; 576. 577. if (cant_revive(&mnum, TRUE, statue)) { 578. /* mnum has changed; we won't be animating this statue as itself */ 579. if (mnum != PM_DOPPELGANGER) 580. mptr = &mons[mnum]; 581. use_saved_traits = FALSE; 582. } else if (is_golem(mptr) && cause == ANIMATE_SPELL) { 583. /* statue of any golem hit by stone-to-flesh becomes flesh golem */ 584. golem_xform = (mptr != &mons[PM_FLESH_GOLEM]); 585. mnum = PM_FLESH_GOLEM; 586. mptr = &mons[PM_FLESH_GOLEM]; 587. use_saved_traits = (has_omonst(statue) && !golem_xform); 588. } else { 589. use_saved_traits = has_omonst(statue); 590. } 591. 592. if (use_saved_traits) { 593. /* restore a petrified monster */ 594. cc.x = x, cc.y = y; 595. mon = montraits(statue, &cc, (cause == ANIMATE_SPELL)); 596. if (mon && mon->mtame && !mon->isminion) 597. wary_dog(mon, TRUE); 598. } else { 599. /* statues of unique monsters from bones or wishing end 600. up here (cant_revive() sets mnum to be doppelganger; 601. mptr reflects the original form for use by newcham()) */ 602. if ((mnum == PM_DOPPELGANGER && mptr != &mons[PM_DOPPELGANGER]) 603. /* block quest guards from other roles */ 604. || (mptr->msound == MS_GUARDIAN 605. && quest_info(MS_GUARDIAN) != mnum)) { 606. mon = makemon(&mons[PM_DOPPELGANGER], x, y, 607. NO_MINVENT | MM_NOCOUNTBIRTH | MM_ADJACENTOK); 608. /* if hero has protection from shape changers, cham field will 609. be NON_PM; otherwise, set form to match the statue */ 610. if (mon && mon->cham >= LOW_PM) 611. (void) newcham(mon, mptr, FALSE, FALSE); 612. } else 613. mon = makemon(mptr, x, y, (cause == ANIMATE_SPELL) 614. ? (NO_MINVENT | MM_ADJACENTOK) 615. : NO_MINVENT); 616. } 617. 618. if (!mon) { 619. if (fail_reason) 620. *fail_reason = unique_corpstat(&mons[statue->corpsenm]) 621. ? AS_MON_IS_UNIQUE 622. : AS_NO_MON; 623. return (struct monst *) 0; 624. } 625. 626. /* a non-montraits() statue might specify gender */ 627. if (statue->spe & STATUE_MALE) 628. mon->female = FALSE; 629. else if (statue->spe & STATUE_FEMALE) 630. mon->female = TRUE; 631. /* if statue has been named, give same name to the monster */ 632. if (has_oname(statue) && !unique_corpstat(mon->data)) 633. mon = christen_monst(mon, ONAME(statue)); 634. /* mimic statue becomes seen mimic; other hiders won't be hidden */ 635. if (M_AP_TYPE(mon)) 636. seemimic(mon); 637. else 638. mon->mundetected = FALSE; 639. mon->msleeping = 0; 640. if (cause == ANIMATE_NORMAL || cause == ANIMATE_SHATTER) { 641. /* trap always releases hostile monster */ 642. mon->mtame = 0; /* (might be petrified pet tossed onto trap) */ 643. mon->mpeaceful = 0; 644. set_malign(mon); 645. } 646. 647. comes_to_life = !canspotmon(mon) 648. ? "disappears" 649. : golem_xform 650. ? "turns into flesh" 651. : (nonliving(mon->data) || is_vampshifter(mon)) 652. ? "moves" 653. : "comes to life"; 654. if ((x == u.ux && y == u.uy) || cause == ANIMATE_SPELL) { 655. /* "the|your|Manlobbi's statue [of a wombat]" */ 656. shkp = shop_keeper(*in_rooms(mon->mx, mon->my, SHOPBASE)); 657. Sprintf(statuename, "%s%s", shk_your(tmpbuf, statue), 658. (cause == ANIMATE_SPELL 659. /* avoid "of a shopkeeper" if it's Manlobbi himself 660. (if carried, it can't be unpaid--hence won't be 661. described as "Manlobbi's statue"--because there 662. wasn't any living shk when statue was picked up) */ 663. && (mon != shkp || carried(statue))) 664. ? xname(statue) 665. : "statue"); 666. pline("%s %s!", upstart(statuename), comes_to_life); 667. } else if (Hallucination) { /* They don't know it's a statue */ 668. pline_The("%s suddenly seems more animated.", rndmonnam((char *) 0)); 669. } else if (cause == ANIMATE_SHATTER) { 670. if (cansee(x, y)) 671. Sprintf(statuename, "%s%s", shk_your(tmpbuf, statue), 672. xname(statue)); 673. else 674. Strcpy(statuename, "a statue"); 675. pline("Instead of shattering, %s suddenly %s!", statuename, 676. comes_to_life); 677. } else { /* cause == ANIMATE_NORMAL */ 678. You("find %s posing as a statue.", 679. canspotmon(mon) ? a_monnam(mon) : something); 680. if (!canspotmon(mon) && Blind) 681. map_invisible(x, y); 682. stop_occupation(); 683. } 684. 685. /* if this isn't caused by a monster using a wand of striking, 686. there might be consequences for the hero */ 687. if (!context.mon_moving) { 688. /* if statue is owned by a shop, hero will have to pay for it; 689. stolen_value gives a message (about debt or use of credit) 690. which refers to "it" so needs to follow a message describing 691. the object ("the statue comes to life" one above) */ 692. if (cause != ANIMATE_NORMAL && costly_spot(x, y) 693. && (carried(statue) ? statue->unpaid : !statue->no_charge) 694. && (shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) != 0 695. /* avoid charging for Manlobbi's statue of Manlobbi 696. if stone-to-flesh is used on petrified shopkeep */ 697. && mon != shkp) 698. (void) stolen_value(statue, x, y, (boolean) shkp->mpeaceful, 699. FALSE); 700. 701. if (historic) { 702. You_feel("guilty %s.", historic_statue_is_gone); 703. adjalign(-1); 704. } 705. } else { 706. if (historic && cansee(x, y)) 707. You_feel("regret %s.", historic_statue_is_gone); 708. /* no alignment penalty */ 709. } 710. 711. /* transfer any statue contents to monster's inventory */ 712. while ((item = statue->cobj) != 0) { 713. obj_extract_self(item); 714. (void) mpickobj(mon, item); 715. } 716. m_dowear(mon, TRUE); 717. /* in case statue is wielded and hero zaps stone-to-flesh at self */ 718. if (statue->owornmask) 719. remove_worn_item(statue, TRUE); 720. /* statue no longer exists */ 721. delobj(statue); 722. 723. /* avoid hiding under nothing */ 724. if (x == u.ux && y == u.uy && Upolyd && hides_under(youmonst.data) 725. && !OBJ_AT(x, y)) 726. u.uundetected = 0; 727. 728. if (fail_reason) 729. *fail_reason = AS_OK; 730. return mon; 731. } 732. 733. /* 734. * You've either stepped onto a statue trap's location or you've triggered a 735. * statue trap by searching next to it or by trying to break it with a wand 736. * or pick-axe. 737. */ 738. struct monst * 739. activate_statue_trap(trap, x, y, shatter) 740. struct trap *trap; 741. xchar x, y; 742. boolean shatter; 743. { 744. struct monst *mtmp = (struct monst *) 0; 745. struct obj *otmp = sobj_at(STATUE, x, y); 746. int fail_reason; 747. 748. /* 749. * Try to animate the first valid statue. Stop the loop when we 750. * actually create something or the failure cause is not because 751. * the mon was unique. 752. */ 753. deltrap(trap); 754. while (otmp) { 755. mtmp = animate_statue(otmp, x, y, 756. shatter ? ANIMATE_SHATTER : ANIMATE_NORMAL, 757. &fail_reason); 758. if (mtmp || fail_reason != AS_MON_IS_UNIQUE) 759. break; 760. 761. otmp = nxtobj(otmp, STATUE, TRUE); 762. } 763. 764. feel_newsym(x, y); 765. return mtmp; 766. } 767. 768. STATIC_OVL boolean 769. keep_saddle_with_steedcorpse(steed_mid, objchn, saddle) 770. unsigned steed_mid; 771. struct obj *objchn, *saddle; 772. { 773. if (!saddle) 774. return FALSE; 775. while (objchn) { 776. if (objchn->otyp == CORPSE && has_omonst(objchn)) { 777. struct monst *mtmp = OMONST(objchn); 778. 779. if (mtmp->m_id == steed_mid) { 780. /* move saddle */ 781. xchar x, y; 782. if (get_obj_location(objchn, &x, &y, 0)) { 783. obj_extract_self(saddle); 784. place_object(saddle, x, y); 785. stackobj(saddle); 786. } 787. return TRUE; 788. } 789. } 790. if (Has_contents(objchn) 791. && keep_saddle_with_steedcorpse(steed_mid, objchn->cobj, saddle)) 792. return TRUE; 793. objchn = objchn->nobj; 794. } 795. return FALSE; 796. } 797. 798. /* monster or you go through and possibly destroy a web. 799. return TRUE if could go through. */ 800. boolean 801. mu_maybe_destroy_web(mtmp, domsg, trap) 802. struct monst *mtmp; 803. boolean domsg; 804. struct trap *trap; 805. { 806. boolean isyou = (mtmp == &youmonst); 807. struct permonst *mptr = mtmp->data; 808. 809. if (amorphous(mptr) || is_whirly(mptr) || flaming(mptr) 810. || unsolid(mptr) || mptr == &mons[PM_GELATINOUS_CUBE]) { 811. xchar x = trap->tx; 812. xchar y = trap->ty; 813. 814. if (flaming(mptr) || acidic(mptr)) { 815. if (domsg) { 816. if (isyou) 817. You("%s %s spider web!", 818. (flaming(mptr)) ? "burn" : "dissolve", 819. a_your[trap->madeby_u]); 820. else 821. pline("%s %s %s spider web!", Monnam(mtmp), 822. (flaming(mptr)) ? "burns" : "dissolves", 823. a_your[trap->madeby_u]); 824. } 825. deltrap(trap); 826. newsym(x, y); 827. return TRUE; 828. } 829. if (domsg) { 830. if (isyou) { 831. You("flow through %s spider web.", a_your[trap->madeby_u]); 832. } else { 833. pline("%s flows through %s spider web.", Monnam(mtmp), 834. a_your[trap->madeby_u]); 835. seetrap(trap); 836. } 837. } 838. return TRUE; 839. } 840. return FALSE; 841. } 842. 843. /* make a single arrow/dart/rock for a trap to shoot or drop */ 844. STATIC_OVL struct obj * 845. t_missile(otyp, trap) 846. int otyp; 847. struct trap *trap; 848. { 849. struct obj *otmp = mksobj(otyp, TRUE, FALSE); 850. 851. otmp->quan = 1L; 852. otmp->owt = weight(otmp); 853. otmp->opoisoned = 0; 854. otmp->ox = trap->tx, otmp->oy = trap->ty; 855. return otmp; 856. } 857. 858. void 859. set_utrap(tim, typ) 860. unsigned tim, typ; 861. { 862. u.utrap = tim; 863. /* FIXME: 864. * utraptype==0 is bear trap rather than 'none'; we probably ought 865. * to change that but can't do so until save file compatability is 866. * able to be broken. 867. */ 868. u.utraptype = tim ? typ : 0; 869. 870. float_vs_flight(); /* maybe block Lev and/or Fly */ 871. } 872. 873. void 874. reset_utrap(msg) 875. boolean msg; 876. { 877. boolean was_Lev = (Levitation != 0), was_Fly = (Flying != 0); 878. 879. set_utrap(0, 0); 880. 881. if (msg) { 882. if (!was_Lev && Levitation) 883. float_up(); 884. if (!was_Fly && Flying) 885. You("can fly."); 886. } 887. } 888. 889. void 890. dotrap(trap, trflags) 891. register struct trap *trap; 892. unsigned trflags; 893. { 894. register int ttype = trap->ttyp; 895. struct obj *otmp; 896. boolean already_seen = trap->tseen, 897. forcetrap = ((trflags & FORCETRAP) != 0 898. || (trflags & FAILEDUNTRAP) != 0), 899. webmsgok = (trflags & NOWEBMSG) == 0, 900. forcebungle = (trflags & FORCEBUNGLE) != 0, 901. plunged = (trflags & TOOKPLUNGE) != 0, 902. viasitting = (trflags & VIASITTING) != 0, 903. conj_pit = conjoined_pits(trap, t_at(u.ux0, u.uy0), TRUE), 904. adj_pit = adj_nonconjoined_pit(trap); 905. int oldumort; 906. int steed_article = ARTICLE_THE; 907. 908. nomul(0); 909. 910. /* KMH -- You can't escape the Sokoban level traps */ 911. if (Sokoban && (is_pit(ttype) || is_hole(ttype))) { 912. /* The "air currents" message is still appropriate -- even when 913. * the hero isn't flying or levitating -- because it conveys the 914. * reason why the player cannot escape the trap with a dexterity 915. * check, clinging to the ceiling, etc. 916. */ 917. pline("Air currents pull you down into %s %s!", 918. a_your[trap->madeby_u], 919. defsyms[trap_to_defsym(ttype)].explanation); 920. /* then proceed to normal trap effect */ 921. } else if (already_seen && !forcetrap) { 922. if ((Levitation || (Flying && !plunged)) 923. && (is_pit(ttype) || ttype == HOLE || ttype == BEAR_TRAP)) { 924. You("%s over %s %s.", Levitation ? "float" : "fly", 925. a_your[trap->madeby_u], 926. defsyms[trap_to_defsym(ttype)].explanation); 927. return; 928. } 929. if (!Fumbling && ttype != MAGIC_PORTAL && ttype != VIBRATING_SQUARE 930. && ttype != ANTI_MAGIC && !forcebungle && !plunged 931. && !conj_pit && !adj_pit 932. && (!rn2(5) || (is_pit(ttype) 933. && is_clinger(youmonst.data)))) { 934. You("escape %s %s.", (ttype == ARROW_TRAP && !trap->madeby_u) 935. ? "an" 936. : a_your[trap->madeby_u], 937. defsyms[trap_to_defsym(ttype)].explanation); 938. return; 939. } 940. } 941. 942. if (u.usteed) { 943. u.usteed->mtrapseen |= (1 << (ttype - 1)); 944. /* suppress article in various steed messages when using its 945. name (which won't occur when hallucinating) */ 946. if (has_mname(u.usteed) && !Hallucination) 947. steed_article = ARTICLE_NONE; 948. } 949. 950. switch (ttype) { 951. case ARROW_TRAP: 952. if (trap->once && trap->tseen && !rn2(15)) { 953. You_hear("a loud click!"); 954. deltrap(trap); 955. newsym(u.ux, u.uy); 956. break; 957. } 958. trap->once = 1; 959. seetrap(trap); 960. pline("An arrow shoots out at you!"); 961. otmp = t_missile(ARROW, trap); 962. if (u.usteed && !rn2(2) && steedintrap(trap, otmp)) { 963. ; /* nothing */ 964. } else if (thitu(8, dmgval(otmp, &youmonst), &otmp, "arrow")) { 965. if (otmp) 966. obfree(otmp, (struct obj *) 0); 967. } else { 968. place_object(otmp, u.ux, u.uy); 969. if (!Blind) 970. otmp->dknown = 1; 971. stackobj(otmp); 972. newsym(u.ux, u.uy); 973. } 974. break; 975. 976. case DART_TRAP: 977. if (trap->once && trap->tseen && !rn2(15)) { 978. You_hear("a soft click."); 979. deltrap(trap); 980. newsym(u.ux, u.uy); 981. break; 982. } 983. trap->once = 1; 984. seetrap(trap); 985. pline("A little dart shoots out at you!"); 986. otmp = t_missile(DART, trap); 987. if (!rn2(6)) 988. otmp->opoisoned = 1; 989. oldumort = u.umortality; 990. if (u.usteed && !rn2(2) && steedintrap(trap, otmp)) { 991. ; /* nothing */ 992. } else if (thitu(7, dmgval(otmp, &youmonst), &otmp, "little dart")) { 993. if (otmp) { 994. if (otmp->opoisoned) 995. poisoned("dart", A_CON, "little dart", 996. /* if damage triggered life-saving, 997. poison is limited to attrib loss */ 998. (u.umortality > oldumort) ? 0 : 10, TRUE); 999. obfree(otmp, (struct obj *) 0); 1000. } 1001. } else { 1002. place_object(otmp, u.ux, u.uy); 1003. if (!Blind) 1004. otmp->dknown = 1; 1005. stackobj(otmp); 1006. newsym(u.ux, u.uy); 1007. } 1008. break; 1009. 1010. case ROCKTRAP: 1011. if (trap->once && trap->tseen && !rn2(15)) { 1012. pline("A trap door in %s opens, but nothing falls out!", 1013. the(ceiling(u.ux, u.uy))); 1014. deltrap(trap); 1015. newsym(u.ux, u.uy); 1016. } else { 1017. int dmg = d(2, 6); /* should be std ROCK dmg? */ 1018. 1019. trap->once = 1; 1020. feeltrap(trap); 1021. otmp = t_missile(ROCK, trap); 1022. place_object(otmp, u.ux, u.uy); 1023. 1024. pline("A trap door in %s opens and %s falls on your %s!", 1025. the(ceiling(u.ux, u.uy)), an(xname(otmp)), body_part(HEAD)); 1026. if (uarmh) { 1027. if (is_metallic(uarmh)) { 1028. pline("Fortunately, you are wearing a hard helmet."); 1029. dmg = 2; 1030. } else if (flags.verbose) { 1031. pline("%s does not protect you.", Yname2(uarmh)); 1032. } 1033. } 1034. if (!Blind) 1035. otmp->dknown = 1; 1036. stackobj(otmp); 1037. newsym(u.ux, u.uy); /* map the rock */ 1038. 1039. losehp(Maybe_Half_Phys(dmg), "falling rock", KILLED_BY_AN); 1040. exercise(A_STR, FALSE); 1041. } 1042. break; 1043. 1044. case SQKY_BOARD: /* stepped on a squeaky board */ 1045. if ((Levitation || Flying) && !forcetrap) { 1046. if (!Blind) { 1047. seetrap(trap); 1048. if (Hallucination) 1049. You("notice a crease in the linoleum."); 1050. else 1051. You("notice a loose board below you."); 1052. } 1053. } else { 1054. seetrap(trap); 1055. pline("A board beneath you %s%s%s.", 1056. Deaf ? "vibrates" : "squeaks ", 1057. Deaf ? "" : trapnote(trap, 0), Deaf ? "" : " loudly"); 1058. wake_nearby(); 1059. } 1060. break; 1061. 1062. case BEAR_TRAP: { 1063. int dmg = d(2, 4); 1064. 1065. if ((Levitation || Flying) && !forcetrap) 1066. break; 1067. feeltrap(trap); 1068. if (amorphous(youmonst.data) || is_whirly(youmonst.data) 1069. || unsolid(youmonst.data)) { 1070. pline("%s bear trap closes harmlessly through you.", 1071. A_Your[trap->madeby_u]); 1072. break; 1073. } 1074. if (!u.usteed && youmonst.data->msize <= MZ_SMALL) { 1075. pline("%s bear trap closes harmlessly over you.", 1076. A_Your[trap->madeby_u]); 1077. break; 1078. } 1079. set_utrap((unsigned) rn1(4, 4), TT_BEARTRAP); 1080. if (u.usteed) { 1081. pline("%s bear trap closes on %s %s!", A_Your[trap->madeby_u], 1082. s_suffix(mon_nam(u.usteed)), mbodypart(u.usteed, FOOT)); 1083. if (thitm(0, u.usteed, (struct obj *) 0, dmg, FALSE)) 1084. reset_utrap(TRUE); /* steed died, hero not trapped */ 1085. } else { 1086. pline("%s bear trap closes on your %s!", A_Your[trap->madeby_u], 1087. body_part(FOOT)); 1088. set_wounded_legs(rn2(2) ? RIGHT_SIDE : LEFT_SIDE, rn1(10, 10)); 1089. if (u.umonnum == PM_OWLBEAR || u.umonnum == PM_BUGBEAR) 1090. You("howl in anger!"); 1091. losehp(Maybe_Half_Phys(dmg), "bear trap", KILLED_BY_AN); 1092. } 1093. exercise(A_DEX, FALSE); 1094. break; 1095. } 1096. 1097. case SLP_GAS_TRAP: 1098. seetrap(trap); 1099. if (Sleep_resistance || breathless(youmonst.data)) { 1100. You("are enveloped in a cloud of gas!"); 1101. } else { 1102. pline("A cloud of gas puts you to sleep!"); 1103. fall_asleep(-rnd(25), TRUE); 1104. } 1105. (void) steedintrap(trap, (struct obj *) 0); 1106. break; 1107. 1108. case RUST_TRAP: 1109. seetrap(trap); 1110. 1111. /* Unlike monsters, traps cannot aim their rust attacks at 1112. * you, so instead of looping through and taking either the 1113. * first rustable one or the body, we take whatever we get, 1114. * even if it is not rustable. 1115. */ 1116. switch (rn2(5)) { 1117. case 0: 1118. pline("%s you on the %s!", A_gush_of_water_hits, body_part(HEAD)); 1119. (void) water_damage(uarmh, helm_simple_name(uarmh), TRUE); 1120. break; 1121. case 1: 1122. pline("%s your left %s!", A_gush_of_water_hits, body_part(ARM)); 1123. if (water_damage(uarms, "shield", TRUE) != ER_NOTHING) 1124. break; 1125. if (u.twoweap || (uwep && bimanual(uwep))) 1126. (void) water_damage(u.twoweap ? uswapwep : uwep, 0, TRUE); 1127. glovecheck: 1128. (void) water_damage(uarmg, "gauntlets", TRUE); 1129. /* Not "metal gauntlets" since it gets called 1130. * even if it's leather for the message 1131. */ 1132. break; 1133. case 2: 1134. pline("%s your right %s!", A_gush_of_water_hits, body_part(ARM)); 1135. (void) water_damage(uwep, 0, TRUE); 1136. goto glovecheck; 1137. default: 1138. pline("%s you!", A_gush_of_water_hits); 1139. for (otmp = invent; otmp; otmp = otmp->nobj) 1140. if (otmp->lamplit && otmp != uwep 1141. && (otmp != uswapwep || !u.twoweap)) 1142. (void) snuff_lit(otmp); 1143. if (uarmc) 1144. (void) water_damage(uarmc, cloak_simple_name(uarmc), TRUE); 1145. else if (uarm) 1146. (void) water_damage(uarm, suit_simple_name(uarm), TRUE); 1147. else if (uarmu) 1148. (void) water_damage(uarmu, "shirt", TRUE); 1149. } 1150. update_inventory(); 1151. 1152. if (u.umonnum == PM_IRON_GOLEM) { 1153. int dam = u.mhmax; 1154. 1155. You("are covered with rust!"); 1156. losehp(Maybe_Half_Phys(dam), "rusting away", KILLED_BY); 1157. } else if (u.umonnum == PM_GREMLIN && rn2(3)) { 1158. (void) split_mon(&youmonst, (struct monst *) 0); 1159. } 1160. 1161. break; 1162. 1163. case FIRE_TRAP: 1164. seetrap(trap); 1165. dofiretrap((struct obj *) 0); 1166. break; 1167. 1168. case PIT: 1169. case SPIKED_PIT: 1170. /* KMH -- You can't escape the Sokoban level traps */ 1171. if (!Sokoban && (Levitation || (Flying && !plunged))) 1172. break; 1173. feeltrap(trap); 1174. if (!Sokoban && is_clinger(youmonst.data) && !plunged) { 1175. if (trap->tseen) { 1176. You_see("%s %spit below you.", a_your[trap->madeby_u], 1177. ttype == SPIKED_PIT ? "spiked " : ""); 1178. } else { 1179. pline("%s pit %sopens up under you!", A_Your[trap->madeby_u], 1180. ttype == SPIKED_PIT ? "full of spikes " : ""); 1181. You("don't fall in!"); 1182. } 1183. break; 1184. } 1185. if (!Sokoban) { 1186. char verbbuf[BUFSZ]; 1187. 1188. *verbbuf = '\0'; 1189. if (u.usteed) { 1190. if ((trflags & RECURSIVETRAP) != 0) 1191. Sprintf(verbbuf, "and %s fall", 1192. x_monnam(u.usteed, steed_article, (char *) 0, 1193. SUPPRESS_SADDLE, FALSE)); 1194. else 1195. Sprintf(verbbuf, "lead %s", 1196. x_monnam(u.usteed, steed_article, "poor", 1197. SUPPRESS_SADDLE, FALSE)); 1198. } else if (conj_pit) { 1199. You("move into an adjacent pit."); 1200. } else if (adj_pit) { 1201. You("stumble over debris%s.", 1202. !rn2(5) ? " between the pits" : ""); 1203. } else { 1204. Strcpy(verbbuf, 1205. !plunged ? "fall" : (Flying ? "dive" : "plunge")); 1206. } 1207. if (*verbbuf) 1208. You("%s into %s pit!", verbbuf, a_your[trap->madeby_u]); 1209. } 1210. /* wumpus reference */ 1211. if (Role_if(PM_RANGER) && !trap->madeby_u && !trap->once 1212. && In_quest(&u.uz) && Is_qlocate(&u.uz)) { 1213. pline("Fortunately it has a bottom after all..."); 1214. trap->once = 1; 1215. } else if (u.umonnum == PM_PIT_VIPER || u.umonnum == PM_PIT_FIEND) { 1216. pline("How pitiful. Isn't that the pits?"); 1217. } 1218. if (ttype == SPIKED_PIT) { 1219. const char *predicament = "on a set of sharp iron spikes"; 1220. 1221. if (u.usteed) { 1222. pline("%s %s %s!", 1223. upstart(x_monnam(u.usteed, steed_article, "poor", 1224. SUPPRESS_SADDLE, FALSE)), 1225. conj_pit ? "steps" : "lands", predicament); 1226. } else 1227. You("%s %s!", conj_pit ? "step" : "land", predicament); 1228. } 1229. /* FIXME: 1230. * if hero gets killed here, setting u.utrap in advance will 1231. * show "you were trapped in a pit" during disclosure's display 1232. * of enlightenment, but hero is dying *before* becoming trapped. 1233. */ 1234. set_utrap((unsigned) rn1(6, 2), TT_PIT); 1235. if (!steedintrap(trap, (struct obj *) 0)) { 1236. if (ttype == SPIKED_PIT) { 1237. oldumort = u.umortality; 1238. losehp(Maybe_Half_Phys(rnd(conj_pit ? 4 : adj_pit ? 6 : 10)), 1239. /* note: these don't need locomotion() handling; 1240. if fatal while poly'd and Unchanging, the 1241. death reason will be overridden with 1242. "killed while stuck in creature form" */ 1243. plunged 1244. ? "deliberately plunged into a pit of iron spikes" 1245. : conj_pit 1246. ? "stepped into a pit of iron spikes" 1247. : adj_pit 1248. ? "stumbled into a pit of iron spikes" 1249. : "fell into a pit of iron spikes", 1250. NO_KILLER_PREFIX); 1251. if (!rn2(6)) 1252. poisoned("spikes", A_STR, 1253. (conj_pit || adj_pit) 1254. ? "stepping on poison spikes" 1255. : "fall onto poison spikes", 1256. /* if damage triggered life-saving, 1257. poison is limited to attrib loss */ 1258. (u.umortality > oldumort) ? 0 : 8, FALSE); 1259. } else { 1260. /* plunging flyers take spike damage but not pit damage */ 1261. if (!conj_pit 1262. && !(plunged && (Flying || is_clinger(youmonst.data)))) 1263. losehp(Maybe_Half_Phys(rnd(adj_pit ? 3 : 6)), 1264. plunged ? "deliberately plunged into a pit" 1265. : "fell into a pit", 1266. NO_KILLER_PREFIX); 1267. } 1268. if (Punished && !carried(uball)) { 1269. unplacebc(); 1270. ballfall(); 1271. placebc(); 1272. } 1273. if (!conj_pit) 1274. selftouch("Falling, you"); 1275. vision_full_recalc = 1; /* vision limits change */ 1276. exercise(A_STR, FALSE); 1277. exercise(A_DEX, FALSE); 1278. } 1279. break; 1280. 1281. case HOLE: 1282. case TRAPDOOR: 1283. if (!Can_fall_thru(&u.uz)) { 1284. seetrap(trap); /* normally done in fall_through */ 1285. impossible("dotrap: %ss cannot exist on this level.", 1286. defsyms[trap_to_defsym(ttype)].explanation); 1287. break; /* don't activate it after all */ 1288. } 1289. fall_through(TRUE); 1290. break; 1291. 1292. case TELEP_TRAP: 1293. seetrap(trap); 1294. tele_trap(trap); 1295. break; 1296. 1297. case LEVEL_TELEP: 1298. seetrap(trap); 1299. level_tele_trap(trap, trflags); 1300. break; 1301. 1302. case WEB: /* Our luckless player has stumbled into a web. */ 1303. feeltrap(trap); 1304. if (mu_maybe_destroy_web(&youmonst, webmsgok, trap)) 1305. break; 1306. if (webmaker(youmonst.data)) { 1307. if (webmsgok) 1308. pline(trap->madeby_u ? "You take a walk on your web." 1309. : "There is a spider web here."); 1310. break; 1311. } 1312. if (webmsgok) { 1313. char verbbuf[BUFSZ]; 1314. 1315. if (forcetrap || viasitting) { 1316. Strcpy(verbbuf, "are caught by"); 1317. } else if (u.usteed) { 1318. Sprintf(verbbuf, "lead %s into", 1319. x_monnam(u.usteed, steed_article, "poor", 1320. SUPPRESS_SADDLE, FALSE)); 1321. } else { 1322. Sprintf(verbbuf, "%s into", 1323. Levitation ? (const char *) "float" 1324. : locomotion(youmonst.data, "stumble")); 1325. } 1326. You("%s %s spider web!", verbbuf, a_your[trap->madeby_u]); 1327. } 1328. 1329. /* time will be adjusted below */ 1330. set_utrap(1, TT_WEB); 1331. 1332. /* Time stuck in the web depends on your/steed strength. */ 1333. { 1334. int tim, str = ACURR(A_STR); 1335. 1336. /* If mounted, the steed gets trapped. Use mintrap 1337. * to do all the work. If mtrapped is set as a result, 1338. * unset it and set utrap instead. In the case of a 1339. * strongmonst and mintrap said it's trapped, use a 1340. * short but non-zero trap time. Otherwise, monsters 1341. * have no specific strength, so use player strength. 1342. * This gets skipped for webmsgok, which implies that 1343. * the steed isn't a factor. 1344. */ 1345. if (u.usteed && webmsgok) { 1346. /* mtmp location might not be up to date */ 1347. u.usteed->mx = u.ux; 1348. u.usteed->my = u.uy; 1349. 1350. /* mintrap currently does not return 2(died) for webs */ 1351. if (mintrap(u.usteed)) { 1352. u.usteed->mtrapped = 0; 1353. if (strongmonst(u.usteed->data)) 1354. str = 17; 1355. } else { 1356. reset_utrap(FALSE); 1357. break; 1358. } 1359. 1360. webmsgok = FALSE; /* mintrap printed the messages */ 1361. } 1362. if (str <= 3) 1363. tim = rn1(6, 6); 1364. else if (str < 6) 1365. tim = rn1(6, 4); 1366. else if (str < 9) 1367. tim = rn1(4, 4); 1368. else if (str < 12) 1369. tim = rn1(4, 2); 1370. else if (str < 15) 1371. tim = rn1(2, 2); 1372. else if (str < 18) 1373. tim = rnd(2); 1374. else if (str < 69) 1375. tim = 1; 1376. else { 1377. tim = 0; 1378. if (webmsgok) 1379. You("tear through %s web!", a_your[trap->madeby_u]); 1380. deltrap(trap); 1381. newsym(u.ux, u.uy); /* get rid of trap symbol */ 1382. } 1383. set_utrap((unsigned) tim, TT_WEB); 1384. } 1385. break; 1386. 1387. case STATUE_TRAP: 1388. (void) activate_statue_trap(trap, u.ux, u.uy, FALSE); 1389. break; 1390. 1391. case MAGIC_TRAP: /* A magic trap. */ 1392. seetrap(trap); 1393. if (!rn2(30)) { 1394. deltrap(trap); 1395. newsym(u.ux, u.uy); /* update position */ 1396. You("are caught in a magical explosion!"); 1397. losehp(rnd(10), "magical explosion", KILLED_BY_AN); 1398. Your("body absorbs some of the magical energy!"); 1399. u.uen = (u.uenmax += 2); 1400. break; 1401. } else { 1402. domagictrap(); 1403. } 1404. (void) steedintrap(trap, (struct obj *) 0); 1405. break; 1406. 1407. case ANTI_MAGIC: 1408. seetrap(trap); 1409. /* hero without magic resistance loses spell energy, 1410. hero with magic resistance takes damage instead; 1411. possibly non-intuitive but useful for play balance */ 1412. if (!Antimagic) { 1413. drain_en(rnd(u.ulevel) + 1); 1414. } else { 1415. int dmgval2 = rnd(4), hp = Upolyd ? u.mh : u.uhp; 1416. 1417. /* Half_XXX_damage has opposite its usual effect (approx) 1418. but isn't cumulative if hero has more than one */ 1419. if (Half_physical_damage || Half_spell_damage) 1420. dmgval2 += rnd(4); 1421. /* give Magicbane wielder dose of own medicine */ 1422. if (uwep && uwep->oartifact == ART_MAGICBANE) 1423. dmgval2 += rnd(4); 1424. /* having an artifact--other than own quest one--which 1425. confers magic resistance simply by being carried 1426. also increases the effect */ 1427. for (otmp = invent; otmp; otmp = otmp->nobj) 1428. if (otmp->oartifact && !is_quest_artifact(otmp) 1429. && defends_when_carried(AD_MAGM, otmp)) 1430. break; 1431. if (otmp) 1432. dmgval2 += rnd(4); 1433. if (Passes_walls) 1434. dmgval2 = (dmgval2 + 3) / 4; 1435. 1436. You_feel((dmgval2 >= hp) ? "unbearably torpid!" 1437. : (dmgval2 >= hp / 4) ? "very lethargic." 1438. : "sluggish."); 1439. /* opposite of magical explosion */ 1440. losehp(dmgval2, "anti-magic implosion", KILLED_BY_AN); 1441. } 1442. break; 1443. 1444. case POLY_TRAP: { 1445. char verbbuf[BUFSZ]; 1446. 1447. seetrap(trap); 1448. if (viasitting) 1449. Strcpy(verbbuf, "trigger"); /* follows "You sit down." */ 1450. else if (u.usteed) 1451. Sprintf(verbbuf, "lead %s onto", 1452. x_monnam(u.usteed, steed_article, (char *) 0, 1453. SUPPRESS_SADDLE, FALSE)); 1454. else 1455. Sprintf(verbbuf, "%s onto", 1456. Levitation ? (const char *) "float" 1457. : locomotion(youmonst.data, "step")); 1458. You("%s a polymorph trap!", verbbuf); 1459. if (Antimagic || Unchanging) { 1460. shieldeff(u.ux, u.uy); 1461. You_feel("momentarily different."); 1462. /* Trap did nothing; don't remove it --KAA */ 1463. } else { 1464. (void) steedintrap(trap, (struct obj *) 0); 1465. deltrap(trap); /* delete trap before polymorph */ 1466. newsym(u.ux, u.uy); /* get rid of trap symbol */ 1467. You_feel("a change coming over you."); 1468. polyself(0); 1469. } 1470. break; 1471. } 1472. case LANDMINE: { 1473. unsigned steed_mid = 0; 1474. struct obj *saddle = 0; 1475. 1476. if ((Levitation || Flying) && !forcetrap) { 1477. if (!already_seen && rn2(3)) 1478. break; 1479. feeltrap(trap); 1480. pline("%s %s in a pile of soil below you.", 1481. already_seen ? "There is" : "You discover", 1482. trap->madeby_u ? "the trigger of your mine" : "a trigger"); 1483. if (already_seen && rn2(3)) 1484. break; 1485. pline("KAABLAMM!!! %s %s%s off!", 1486. forcebungle ? "Your inept attempt sets" 1487. : "The air currents set", 1488. already_seen ? a_your[trap->madeby_u] : "", 1489. already_seen ? " land mine" : "it"); 1490. } else { 1491. /* prevent landmine from killing steed, throwing you to 1492. * the ground, and you being affected again by the same 1493. * mine because it hasn't been deleted yet 1494. */ 1495. static boolean recursive_mine = FALSE; 1496. 1497. if (recursive_mine) 1498. break; 1499. feeltrap(trap); 1500. pline("KAABLAMM!!! You triggered %s land mine!", 1501. a_your[trap->madeby_u]); 1502. if (u.usteed) 1503. steed_mid = u.usteed->m_id; 1504. recursive_mine = TRUE; 1505. (void) steedintrap(trap, (struct obj *) 0); 1506. recursive_mine = FALSE; 1507. saddle = sobj_at(SADDLE, u.ux, u.uy); 1508. set_wounded_legs(LEFT_SIDE, rn1(35, 41)); 1509. set_wounded_legs(RIGHT_SIDE, rn1(35, 41)); 1510. exercise(A_DEX, FALSE); 1511. } 1512. blow_up_landmine(trap); 1513. if (steed_mid && saddle && !u.usteed) 1514. (void) keep_saddle_with_steedcorpse(steed_mid, fobj, saddle); 1515. newsym(u.ux, u.uy); /* update trap symbol */ 1516. losehp(Maybe_Half_Phys(rnd(16)), "land mine", KILLED_BY_AN); 1517. /* fall recursively into the pit... */ 1518. if ((trap = t_at(u.ux, u.uy)) != 0) 1519. dotrap(trap, RECURSIVETRAP); 1520. fill_pit(u.ux, u.uy); 1521. break; 1522. } 1523. 1524. case ROLLING_BOULDER_TRAP: { 1525. int style = ROLL | (trap->tseen ? LAUNCH_KNOWN : 0); 1526. 1527. feeltrap(trap); 1528. pline("Click! You trigger a rolling boulder trap!"); 1529. if (!launch_obj(BOULDER, trap->launch.x, trap->launch.y, 1530. trap->launch2.x, trap->launch2.y, style)) { 1531. deltrap(trap); 1532. newsym(u.ux, u.uy); /* get rid of trap symbol */ 1533. pline("Fortunately for you, no boulder was released."); 1534. } 1535. break; 1536. } 1537. 1538. case MAGIC_PORTAL: 1539. feeltrap(trap); 1540. domagicportal(trap); 1541. break; 1542. 1543. case VIBRATING_SQUARE: 1544. feeltrap(trap); 1545. /* messages handled elsewhere; the trap symbol is merely to mark the 1546. * square for future reference */ 1547. break; 1548. 1549. default: 1550. feeltrap(trap); 1551. impossible("You hit a trap of type %u", trap->ttyp); 1552. } 1553. } 1554. 1555. STATIC_OVL char * 1556. trapnote(trap, noprefix) 1557. struct trap *trap; 1558. boolean noprefix; 1559. { 1560. static char tnbuf[12]; 1561. const char *tn, 1562. *tnnames[12] = { "C note", "D flat", "D note", "E flat", 1563. "E note", "F note", "F sharp", "G note", 1564. "G sharp", "A note", "B flat", "B note" }; 1565. 1566. tnbuf[0] = '\0'; 1567. tn = tnnames[trap->tnote]; 1568. if (!noprefix) 1569. Sprintf(tnbuf, "%s ", 1570. (*tn == 'A' || *tn == 'E' || *tn == 'F') ? "an" : "a"); 1571. Sprintf(eos(tnbuf), "%s", tn); 1572. return tnbuf; 1573. } 1574. 1575. STATIC_OVL int 1576. steedintrap(trap, otmp) 1577. struct trap *trap; 1578. struct obj *otmp; 1579. { 1580. struct monst *steed = u.usteed; 1581. int tt; 1582. boolean trapkilled, steedhit; 1583. 1584. if (!steed || !trap) 1585. return 0; 1586. tt = trap->ttyp; 1587. steed->mx = u.ux; 1588. steed->my = u.uy; 1589. trapkilled = steedhit = FALSE; 1590. 1591. switch (tt) { 1592. case ARROW_TRAP: 1593. if (!otmp) { 1594. impossible("steed hit by non-existant arrow?"); 1595. return 0; 1596. } 1597. trapkilled = thitm(8, steed, otmp, 0, FALSE); 1598. steedhit = TRUE; 1599. break; 1600. case DART_TRAP: 1601. if (!otmp) { 1602. impossible("steed hit by non-existant dart?"); 1603. return 0; 1604. } 1605. trapkilled = thitm(7, steed, otmp, 0, FALSE); 1606. steedhit = TRUE; 1607. break; 1608. case SLP_GAS_TRAP: 1609. if (!resists_sleep(steed) && !breathless(steed->data) 1610. && !steed->msleeping && steed->mcanmove) { 1611. if (sleep_monst(steed, rnd(25), -1)) 1612. /* no in_sight check here; you can feel it even if blind */ 1613. pline("%s suddenly falls asleep!", Monnam(steed)); 1614. } 1615. steedhit = TRUE; 1616. break; 1617. case LANDMINE: 1618. trapkilled = thitm(0, steed, (struct obj *) 0, rnd(16), FALSE); 1619. steedhit = TRUE; 1620. break; 1621. case PIT: 1622. case SPIKED_PIT: 1623. trapkilled = (DEADMONSTER(steed) 1624. || thitm(0, steed, (struct obj *) 0, 1625. rnd((tt == PIT) ? 6 : 10), FALSE)); 1626. steedhit = TRUE; 1627. break; 1628. case POLY_TRAP: 1629. if (!resists_magm(steed) && !resist(steed, WAND_CLASS, 0, NOTELL)) { 1630. (void) newcham(steed, (struct permonst *) 0, FALSE, FALSE); 1631. if (!can_saddle(steed) || !can_ride(steed)) 1632. dismount_steed(DISMOUNT_POLY); 1633. else 1634. You("have to adjust yourself in the saddle on %s.", 1635. x_monnam(steed, ARTICLE_A, (char *) 0, SUPPRESS_SADDLE, 1636. FALSE)); 1637. } 1638. steedhit = TRUE; 1639. break; 1640. default: 1641. break; 1642. } 1643. 1644. if (trapkilled) { 1645. dismount_steed(DISMOUNT_POLY); 1646. return 2; 1647. } 1648. return steedhit ? 1 : 0; 1649. } 1650. 1651. /* some actions common to both player and monsters for triggered landmine */ 1652. void 1653. blow_up_landmine(trap) 1654. struct trap *trap; 1655. { 1656. int x = trap->tx, y = trap->ty, dbx, dby; 1657. struct rm *lev = &levl[x][y]; 1658. 1659. (void) scatter(x, y, 4, 1660. MAY_DESTROY | MAY_HIT | MAY_FRACTURE | VIS_EFFECTS, 1661. (struct obj *) 0); 1662. del_engr_at(x, y); 1663. wake_nearto(x, y, 400); 1664. if (IS_DOOR(lev->typ)) 1665. lev->doormask = D_BROKEN; 1666. /* destroy drawbridge if present */ 1667. if (lev->typ == DRAWBRIDGE_DOWN || is_drawbridge_wall(x, y) >= 0) { 1668. dbx = x, dby = y; 1669. /* if under the portcullis, the bridge is adjacent */ 1670. if (find_drawbridge(&dbx, &dby)) 1671. destroy_drawbridge(dbx, dby); 1672. trap = t_at(x, y); /* expected to be null after destruction */ 1673. } 1674. /* convert landmine into pit */ 1675. if (trap) { 1676. if (Is_waterlevel(&u.uz) || Is_airlevel(&u.uz)) { 1677. /* no pits here */ 1678. deltrap(trap); 1679. } else { 1680. trap->ttyp = PIT; /* explosion creates a pit */ 1681. trap->madeby_u = FALSE; /* resulting pit isn't yours */ 1682. seetrap(trap); /* and it isn't concealed */ 1683. } 1684. } 1685. } 1686. 1687. /* 1688. * The following are used to track launched objects to 1689. * prevent them from vanishing if you are killed. They 1690. * will reappear at the launchplace in bones files. 1691. */ 1692. static struct { 1693. struct obj *obj; 1694. xchar x, y; 1695. } launchplace; 1696. 1697. STATIC_OVL void 1698. launch_drop_spot(obj, x, y) 1699. struct obj *obj; 1700. xchar x, y; 1701. { 1702. if (!obj) { 1703. launchplace.obj = (struct obj *) 0; 1704. launchplace.x = 0; 1705. launchplace.y = 0; 1706. } else { 1707. launchplace.obj = obj; 1708. launchplace.x = x; 1709. launchplace.y = y; 1710. } 1711. } 1712. 1713. boolean 1714. launch_in_progress() 1715. { 1716. if (launchplace.obj) 1717. return TRUE; 1718. return FALSE; 1719. } 1720. 1721. void 1722. force_launch_placement() 1723. { 1724. if (launchplace.obj) { 1725. launchplace.obj->otrapped = 0; 1726. place_object(launchplace.obj, launchplace.x, launchplace.y); 1727. } 1728. } 1729. 1730. /* 1731. * Move obj from (x1,y1) to (x2,y2) 1732. * 1733. * Return 0 if no object was launched. 1734. * 1 if an object was launched and placed somewhere. 1735. * 2 if an object was launched, but used up. 1736. */ 1737. int 1738. launch_obj(otyp, x1, y1, x2, y2, style) 1739. short otyp; 1740. register int x1, y1, x2, y2; 1741. int style; 1742. { 1743. register struct monst *mtmp; 1744. register struct obj *otmp, *otmp2; 1745. register int dx, dy; 1746. struct obj *singleobj; 1747. boolean used_up = FALSE; 1748. boolean otherside = FALSE; 1749. int dist; 1750. int tmp; 1751. int delaycnt = 0; 1752. 1753. otmp = sobj_at(otyp, x1, y1); 1754. /* Try the other side too, for rolling boulder traps */ 1755. if (!otmp && otyp == BOULDER) { 1756. otherside = TRUE; 1757. otmp = sobj_at(otyp, x2, y2); 1758. } 1759. if (!otmp) 1760. return 0; 1761. if (otherside) { /* swap 'em */ 1762. int tx, ty; 1763. 1764. tx = x1; 1765. ty = y1; 1766. x1 = x2; 1767. y1 = y2; 1768. x2 = tx; 1769. y2 = ty; 1770. } 1771. 1772. if (otmp->quan == 1L) { 1773. obj_extract_self(otmp); 1774. singleobj = otmp; 1775. otmp = (struct obj *) 0; 1776. } else { 1777. singleobj = splitobj(otmp, 1L); 1778. obj_extract_self(singleobj); 1779. } 1780. newsym(x1, y1); 1781. /* in case you're using a pick-axe to chop the boulder that's being 1782. launched (perhaps a monster triggered it), destroy context so that 1783. next dig attempt never thinks you're resuming previous effort */ 1784. if ((otyp == BOULDER || otyp == STATUE) 1785. && singleobj->ox == context.digging.pos.x 1786. && singleobj->oy == context.digging.pos.y) 1787. (void) memset((genericptr_t) &context.digging, 0, 1788. sizeof(struct dig_info)); 1789. 1790. dist = distmin(x1, y1, x2, y2); 1791. bhitpos.x = x1; 1792. bhitpos.y = y1; 1793. dx = sgn(x2 - x1); 1794. dy = sgn(y2 - y1); 1795. switch (style) { 1796. case ROLL | LAUNCH_UNSEEN: 1797. if (otyp == BOULDER) { 1798. You_hear(Hallucination ? "someone bowling." 1799. : "rumbling in the distance."); 1800. } 1801. style &= ~LAUNCH_UNSEEN; 1802. goto roll; 1803. case ROLL | LAUNCH_KNOWN: 1804. /* use otrapped as a flag to ohitmon */ 1805. singleobj->otrapped = 1; 1806. style &= ~LAUNCH_KNOWN; 1807. /* fall through */ 1808. roll: 1809. case ROLL: 1810. delaycnt = 2; 1811. /* fall through */ 1812. default: 1813. if (!delaycnt) 1814. delaycnt = 1; 1815. if (!cansee(bhitpos.x, bhitpos.y)) 1816. curs_on_u(); 1817. tmp_at(DISP_FLASH, obj_to_glyph(singleobj, rn2_on_display_rng)); 1818. tmp_at(bhitpos.x, bhitpos.y); 1819. } 1820. /* Mark a spot to place object in bones files to prevent 1821. * loss of object. Use the starting spot to ensure that 1822. * a rolling boulder will still launch, which it wouldn't 1823. * do if left midstream. Unfortunately we can't use the 1824. * target resting spot, because there are some things/situations 1825. * that would prevent it from ever getting there (bars), and we 1826. * can't tell that yet. 1827. */ 1828. launch_drop_spot(singleobj, bhitpos.x, bhitpos.y); 1829. 1830. /* Set the object in motion */ 1831. while (dist-- > 0 && !used_up) { 1832. struct trap *t; 1833. tmp_at(bhitpos.x, bhitpos.y); 1834. tmp = delaycnt; 1835. 1836. /* dstage@u.washington.edu -- Delay only if hero sees it */ 1837. if (cansee(bhitpos.x, bhitpos.y)) 1838. while (tmp-- > 0) 1839. delay_output(); 1840. 1841. bhitpos.x += dx; 1842. bhitpos.y += dy; 1843. 1844. if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) { 1845. if (otyp == BOULDER && throws_rocks(mtmp->data)) { 1846. if (rn2(3)) { 1847. if (cansee(bhitpos.x, bhitpos.y)) 1848. pline("%s snatches the boulder.", Monnam(mtmp)); 1849. singleobj->otrapped = 0; 1850. (void) mpickobj(mtmp, singleobj); 1851. used_up = TRUE; 1852. launch_drop_spot((struct obj *) 0, 0, 0); 1853. break; 1854. } 1855. } 1856. if (ohitmon(mtmp, singleobj, (style == ROLL) ? -1 : dist, 1857. FALSE)) { 1858. used_up = TRUE; 1859. launch_drop_spot((struct obj *) 0, 0, 0); 1860. break; 1861. } 1862. } else if (bhitpos.x == u.ux && bhitpos.y == u.uy) { 1863. if (multi) 1864. nomul(0); 1865. if (thitu(9 + singleobj->spe, dmgval(singleobj, &youmonst), 1866. &singleobj, (char *) 0)) 1867. stop_occupation(); 1868. } 1869. if (style == ROLL) { 1870. if (down_gate(bhitpos.x, bhitpos.y) != -1) { 1871. if (ship_object(singleobj, bhitpos.x, bhitpos.y, FALSE)) { 1872. used_up = TRUE; 1873. launch_drop_spot((struct obj *) 0, 0, 0); 1874. break; 1875. } 1876. } 1877. if ((t = t_at(bhitpos.x, bhitpos.y)) != 0 && otyp == BOULDER) { 1878. switch (t->ttyp) { 1879. case LANDMINE: 1880. if (rn2(10) > 2) { 1881. pline( 1882. "KAABLAMM!!!%s", 1883. cansee(bhitpos.x, bhitpos.y) 1884. ? " The rolling boulder triggers a land mine." 1885. : ""); 1886. deltrap(t); 1887. del_engr_at(bhitpos.x, bhitpos.y); 1888. place_object(singleobj, bhitpos.x, bhitpos.y); 1889. singleobj->otrapped = 0; 1890. fracture_rock(singleobj); 1891. (void) scatter(bhitpos.x, bhitpos.y, 4, 1892. MAY_DESTROY | MAY_HIT | MAY_FRACTURE 1893. | VIS_EFFECTS, 1894. (struct obj *) 0); 1895. if (cansee(bhitpos.x, bhitpos.y)) 1896. newsym(bhitpos.x, bhitpos.y); 1897. used_up = TRUE; 1898. launch_drop_spot((struct obj *) 0, 0, 0); 1899. } 1900. break; 1901. case LEVEL_TELEP: 1902. case TELEP_TRAP: 1903. if (cansee(bhitpos.x, bhitpos.y)) 1904. pline("Suddenly the rolling boulder disappears!"); 1905. else 1906. You_hear("a rumbling stop abruptly."); 1907. singleobj->otrapped = 0; 1908. if (t->ttyp == TELEP_TRAP) 1909. (void) rloco(singleobj); 1910. else { 1911. int newlev = random_teleport_level(); 1912. d_level dest; 1913. 1914. if (newlev == depth(&u.uz) || In_endgame(&u.uz)) 1915. continue; 1916. add_to_migration(singleobj); 1917. get_level(&dest, newlev); 1918. singleobj->ox = dest.dnum; 1919. singleobj->oy = dest.dlevel; 1920. singleobj->owornmask = (long) MIGR_RANDOM; 1921. } 1922. seetrap(t); 1923. used_up = TRUE; 1924. launch_drop_spot((struct obj *) 0, 0, 0); 1925. break; 1926. case PIT: 1927. case SPIKED_PIT: 1928. case HOLE: 1929. case TRAPDOOR: 1930. /* the boulder won't be used up if there is a 1931. monster in the trap; stop rolling anyway */ 1932. x2 = bhitpos.x, y2 = bhitpos.y; /* stops here */ 1933. if (flooreffects(singleobj, x2, y2, "fall")) { 1934. used_up = TRUE; 1935. launch_drop_spot((struct obj *) 0, 0, 0); 1936. } 1937. dist = -1; /* stop rolling immediately */ 1938. break; 1939. } 1940. if (used_up || dist == -1) 1941. break; 1942. } 1943. if (flooreffects(singleobj, bhitpos.x, bhitpos.y, "fall")) { 1944. used_up = TRUE; 1945. launch_drop_spot((struct obj *) 0, 0, 0); 1946. break; 1947. } 1948. if (otyp == BOULDER 1949. && (otmp2 = sobj_at(BOULDER, bhitpos.x, bhitpos.y)) != 0) { 1950. const char *bmsg = " as one boulder sets another in motion"; 1951. 1952. if (!isok(bhitpos.x + dx, bhitpos.y + dy) || !dist 1953. || IS_ROCK(levl[bhitpos.x + dx][bhitpos.y + dy].typ)) 1954. bmsg = " as one boulder hits another"; 1955. 1956. You_hear("a loud crash%s!", 1957. cansee(bhitpos.x, bhitpos.y) ? bmsg : ""); 1958. obj_extract_self(otmp2); 1959. /* pass off the otrapped flag to the next boulder */ 1960. otmp2->otrapped = singleobj->otrapped; 1961. singleobj->otrapped = 0; 1962. place_object(singleobj, bhitpos.x, bhitpos.y); 1963. singleobj = otmp2; 1964. otmp2 = (struct obj *) 0; 1965. wake_nearto(bhitpos.x, bhitpos.y, 10 * 10); 1966. } 1967. } 1968. if (otyp == BOULDER && closed_door(bhitpos.x, bhitpos.y)) { 1969. if (cansee(bhitpos.x, bhitpos.y)) 1970. pline_The("boulder crashes through a door."); 1971. levl[bhitpos.x][bhitpos.y].doormask = D_BROKEN; 1972. if (dist) 1973. unblock_point(bhitpos.x, bhitpos.y); 1974. } 1975. 1976. /* if about to hit iron bars, do so now */ 1977. if (dist > 0 && isok(bhitpos.x + dx, bhitpos.y + dy) 1978. && levl[bhitpos.x + dx][bhitpos.y + dy].typ == IRONBARS) { 1979. x2 = bhitpos.x, y2 = bhitpos.y; /* object stops here */ 1980. if (hits_bars(&singleobj, 1981. x2, y2, x2+dx, y2+dy, 1982. !rn2(20), 0)) { 1983. if (!singleobj) { 1984. used_up = TRUE; 1985. launch_drop_spot((struct obj *) 0, 0, 0); 1986. } 1987. break; 1988. } 1989. } 1990. } 1991. tmp_at(DISP_END, 0); 1992. launch_drop_spot((struct obj *) 0, 0, 0); 1993. if (!used_up) { 1994. singleobj->otrapped = 0; 1995. place_object(singleobj, x2, y2); 1996. newsym(x2, y2); 1997. return 1; 1998. } else 1999. return 2; 2000. } 2001. 2002. void 2003. seetrap(trap) 2004. struct trap *trap; 2005. { 2006. if (!trap->tseen) { 2007. trap->tseen = 1; 2008. newsym(trap->tx, trap->ty); 2009. } 2010. } 2011. 2012. /* like seetrap() but overrides vision */ 2013. void 2014. feeltrap(trap) 2015. struct trap *trap; 2016. { 2017. trap->tseen = 1; 2018. map_trap(trap, 1); 2019. /* in case it's beneath something, redisplay the something */ 2020. newsym(trap->tx, trap->ty); 2021. } 2022. 2023. STATIC_OVL int 2024. mkroll_launch(ttmp, x, y, otyp, ocount) 2025. struct trap *ttmp; 2026. xchar x, y; 2027. short otyp; 2028. long ocount; 2029. { 2030. struct obj *otmp; 2031. register int tmp; 2032. schar dx, dy; 2033. int distance; 2034. coord cc; 2035. coord bcc; 2036. int trycount = 0; 2037. boolean success = FALSE; 2038. int mindist = 4; 2039. 2040. if (ttmp->ttyp == ROLLING_BOULDER_TRAP) 2041. mindist = 2; 2042. distance = rn1(5, 4); /* 4..8 away */ 2043. tmp = rn2(8); /* randomly pick a direction to try first */ 2044. while (distance >= mindist) { 2045. dx = xdir[tmp]; 2046. dy = ydir[tmp]; 2047. cc.x = x; 2048. cc.y = y; 2049. /* Prevent boulder from being placed on water */ 2050. if (ttmp->ttyp == ROLLING_BOULDER_TRAP 2051. && is_pool_or_lava(x + distance * dx, y + distance * dy)) 2052. success = FALSE; 2053. else 2054. success = isclearpath(&cc, distance, dx, dy); 2055. if (ttmp->ttyp == ROLLING_BOULDER_TRAP) { 2056. boolean success_otherway; 2057. 2058. bcc.x = x; 2059. bcc.y = y; 2060. success_otherway = isclearpath(&bcc, distance, -(dx), -(dy)); 2061. if (!success_otherway) 2062. success = FALSE; 2063. } 2064. if (success) 2065. break; 2066. if (++tmp > 7) 2067. tmp = 0; 2068. if ((++trycount % 8) == 0) 2069. --distance; 2070. } 2071. if (!success) { 2072. /* create the trap without any ammo, launch pt at trap location */ 2073. cc.x = bcc.x = x; 2074. cc.y = bcc.y = y; 2075. } else { 2076. otmp = mksobj(otyp, TRUE, FALSE); 2077. otmp->quan = ocount; 2078. otmp->owt = weight(otmp); 2079. place_object(otmp, cc.x, cc.y); 2080. stackobj(otmp); 2081. } 2082. ttmp->launch.x = cc.x; 2083. ttmp->launch.y = cc.y; 2084. if (ttmp->ttyp == ROLLING_BOULDER_TRAP) { 2085. ttmp->launch2.x = bcc.x; 2086. ttmp->launch2.y = bcc.y; 2087. } else 2088. ttmp->launch_otyp = otyp; 2089. newsym(ttmp->launch.x, ttmp->launch.y); 2090. return 1; 2091. } 2092. 2093. STATIC_OVL boolean 2094. isclearpath(cc, distance, dx, dy) 2095. coord *cc; 2096. int distance; 2097. schar dx, dy; 2098. { 2099. uchar typ; 2100. xchar x, y; 2101. 2102. x = cc->x; 2103. y = cc->y; 2104. while (distance-- > 0) { 2105. x += dx; 2106. y += dy; 2107. typ = levl[x][y].typ; 2108. if (!isok(x, y) || !ZAP_POS(typ) || closed_door(x, y)) 2109. return FALSE; 2110. } 2111. cc->x = x; 2112. cc->y = y; 2113. return TRUE; 2114. } 2115. 2116. int 2117. mintrap(mtmp) 2118. register struct monst *mtmp; 2119. { 2120. register struct trap *trap = t_at(mtmp->mx, mtmp->my); 2121. boolean trapkilled = FALSE; 2122. struct permonst *mptr = mtmp->data; 2123. struct obj *otmp; 2124. 2125. if (!trap) { 2126. mtmp->mtrapped = 0; /* perhaps teleported? */ 2127. } else if (mtmp->mtrapped) { /* is currently in the trap */ 2128. if (!trap->tseen && cansee(mtmp->mx, mtmp->my) && canseemon(mtmp) 2129. && (is_pit(trap->ttyp) || trap->ttyp == BEAR_TRAP 2130. || trap->ttyp == HOLE 2131. || trap->ttyp == WEB)) { 2132. /* If you come upon an obviously trapped monster, then 2133. * you must be able to see the trap it's in too. 2134. */ 2135. seetrap(trap); 2136. } 2137. 2138. if (!rn2(40)) { 2139. if (sobj_at(BOULDER, mtmp->mx, mtmp->my) 2140. && is_pit(trap->ttyp)) { 2141. if (!rn2(2)) { 2142. mtmp->mtrapped = 0; 2143. if (canseemon(mtmp)) 2144. pline("%s pulls free...", Monnam(mtmp)); 2145. fill_pit(mtmp->mx, mtmp->my); 2146. } 2147. } else { 2148. mtmp->mtrapped = 0; 2149. } 2150. } else if (metallivorous(mptr)) { 2151. if (trap->ttyp == BEAR_TRAP) { 2152. if (canseemon(mtmp)) 2153. pline("%s eats a bear trap!", Monnam(mtmp)); 2154. deltrap(trap); 2155. mtmp->meating = 5; 2156. mtmp->mtrapped = 0; 2157. } else if (trap->ttyp == SPIKED_PIT) { 2158. if (canseemon(mtmp)) 2159. pline("%s munches on some spikes!", Monnam(mtmp)); 2160. trap->ttyp = PIT; 2161. mtmp->meating = 5; 2162. } 2163. } 2164. } else { 2165. register int tt = trap->ttyp; 2166. boolean in_sight, tear_web, see_it, 2167. inescapable = force_mintrap || ((tt == HOLE || tt == PIT) 2168. && Sokoban && !trap->madeby_u); 2169. const char *fallverb; 2170. xchar tx = trap->tx, ty = trap->ty; 2171. 2172. /* true when called from dotrap, inescapable is not an option */ 2173. if (mtmp == u.usteed) 2174. inescapable = TRUE; 2175. if (!inescapable && ((mtmp->mtrapseen & (1 << (tt - 1))) != 0 2176. || (tt == HOLE && !mindless(mptr)))) { 2177. /* it has been in such a trap - perhaps it escapes */ 2178. if (rn2(4)) 2179. return 0; 2180. } else { 2181. mtmp->mtrapseen |= (1 << (tt - 1)); 2182. } 2183. /* Monster is aggravated by being trapped by you. 2184. Recognizing who made the trap isn't completely 2185. unreasonable; everybody has their own style. */ 2186. if (trap->madeby_u && rnl(5)) 2187. setmangry(mtmp, TRUE); 2188. 2189. in_sight = canseemon(mtmp); 2190. see_it = cansee(mtmp->mx, mtmp->my); 2191. /* assume hero can tell what's going on for the steed */ 2192. if (mtmp == u.usteed) 2193. in_sight = TRUE; 2194. switch (tt) { 2195. case ARROW_TRAP: 2196. if (trap->once && trap->tseen && !rn2(15)) { 2197. if (in_sight && see_it) 2198. pline("%s triggers a trap but nothing happens.", 2199. Monnam(mtmp)); 2200. deltrap(trap); 2201. newsym(mtmp->mx, mtmp->my); 2202. break; 2203. } 2204. trap->once = 1; 2205. otmp = t_missile(ARROW, trap); 2206. if (in_sight) 2207. seetrap(trap); 2208. if (thitm(8, mtmp, otmp, 0, FALSE)) 2209. trapkilled = TRUE; 2210. break; 2211. case DART_TRAP: 2212. if (trap->once && trap->tseen && !rn2(15)) { 2213. if (in_sight && see_it) 2214. pline("%s triggers a trap but nothing happens.", 2215. Monnam(mtmp)); 2216. deltrap(trap); 2217. newsym(mtmp->mx, mtmp->my); 2218. break; 2219. } 2220. trap->once = 1; 2221. otmp = t_missile(DART, trap); 2222. if (!rn2(6)) 2223. otmp->opoisoned = 1; 2224. if (in_sight) 2225. seetrap(trap); 2226. if (thitm(7, mtmp, otmp, 0, FALSE)) 2227. trapkilled = TRUE; 2228. break; 2229. case ROCKTRAP: 2230. if (trap->once && trap->tseen && !rn2(15)) { 2231. if (in_sight && see_it) 2232. pline( 2233. "A trap door above %s opens, but nothing falls out!", 2234. mon_nam(mtmp)); 2235. deltrap(trap); 2236. newsym(mtmp->mx, mtmp->my); 2237. break; 2238. } 2239. trap->once = 1; 2240. otmp = t_missile(ROCK, trap); 2241. if (in_sight) 2242. seetrap(trap); 2243. if (thitm(0, mtmp, otmp, d(2, 6), FALSE)) 2244. trapkilled = TRUE; 2245. break; 2246. case SQKY_BOARD: 2247. if (is_flyer(mptr)) 2248. break; 2249. /* stepped on a squeaky board */ 2250. if (in_sight) { 2251. if (!Deaf) { 2252. pline("A board beneath %s squeaks %s loudly.", 2253. mon_nam(mtmp), trapnote(trap, 0)); 2254. seetrap(trap); 2255. } else { 2256. pline("%s stops momentarily and appears to cringe.", 2257. Monnam(mtmp)); 2258. } 2259. } else { 2260. /* same near/far threshold as mzapmsg() */ 2261. int range = couldsee(mtmp->mx, mtmp->my) /* 9 or 5 */ 2262. ? (BOLT_LIM + 1) : (BOLT_LIM - 3); 2263. 2264. You_hear("a %s squeak %s.", trapnote(trap, 1), 2265. (distu(mtmp->mx, mtmp->my) <= range * range) 2266. ? "nearby" : "in the distance"); 2267. } 2268. /* wake up nearby monsters */ 2269. wake_nearto(mtmp->mx, mtmp->my, 40); 2270. break; 2271. case BEAR_TRAP: 2272. if (mptr->msize > MZ_SMALL && !amorphous(mptr) && !is_flyer(mptr) 2273. && !is_whirly(mptr) && !unsolid(mptr)) { 2274. mtmp->mtrapped = 1; 2275. if (in_sight) { 2276. pline("%s is caught in %s bear trap!", Monnam(mtmp), 2277. a_your[trap->madeby_u]); 2278. seetrap(trap); 2279. } else { 2280. if (mptr == &mons[PM_OWLBEAR] 2281. || mptr == &mons[PM_BUGBEAR]) 2282. You_hear("the roaring of an angry bear!"); 2283. } 2284. } else if (force_mintrap) { 2285. if (in_sight) { 2286. pline("%s evades %s bear trap!", Monnam(mtmp), 2287. a_your[trap->madeby_u]); 2288. seetrap(trap); 2289. } 2290. } 2291. if (mtmp->mtrapped) 2292. trapkilled = thitm(0, mtmp, (struct obj *) 0, d(2, 4), FALSE); 2293. break; 2294. case SLP_GAS_TRAP: 2295. if (!resists_sleep(mtmp) && !breathless(mptr) && !mtmp->msleeping 2296. && mtmp->mcanmove) { 2297. if (sleep_monst(mtmp, rnd(25), -1) && in_sight) { 2298. pline("%s suddenly falls asleep!", Monnam(mtmp)); 2299. seetrap(trap); 2300. } 2301. } 2302. break; 2303. case RUST_TRAP: { 2304. struct obj *target; 2305. 2306. if (in_sight) 2307. seetrap(trap); 2308. switch (rn2(5)) { 2309. case 0: 2310. if (in_sight) 2311. pline("%s %s on the %s!", A_gush_of_water_hits, 2312. mon_nam(mtmp), mbodypart(mtmp, HEAD)); 2313. target = which_armor(mtmp, W_ARMH); 2314. (void) water_damage(target, helm_simple_name(target), TRUE); 2315. break; 2316. case 1: 2317. if (in_sight) 2318. pline("%s %s's left %s!", A_gush_of_water_hits, 2319. mon_nam(mtmp), mbodypart(mtmp, ARM)); 2320. target = which_armor(mtmp, W_ARMS); 2321. if (water_damage(target, "shield", TRUE) != ER_NOTHING) 2322. break; 2323. target = MON_WEP(mtmp); 2324. if (target && bimanual(target)) 2325. (void) water_damage(target, 0, TRUE); 2326. glovecheck: 2327. target = which_armor(mtmp, W_ARMG); 2328. (void) water_damage(target, "gauntlets", TRUE); 2329. break; 2330. case 2: 2331. if (in_sight) 2332. pline("%s %s's right %s!", A_gush_of_water_hits, 2333. mon_nam(mtmp), mbodypart(mtmp, ARM)); 2334. (void) water_damage(MON_WEP(mtmp), 0, TRUE); 2335. goto glovecheck; 2336. default: 2337. if (in_sight) 2338. pline("%s %s!", A_gush_of_water_hits, mon_nam(mtmp)); 2339. for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) 2340. if (otmp->lamplit 2341. && (otmp->owornmask & (W_WEP | W_SWAPWEP)) == 0) 2342. (void) snuff_lit(otmp); 2343. if ((target = which_armor(mtmp, W_ARMC)) != 0) 2344. (void) water_damage(target, cloak_simple_name(target), 2345. TRUE); 2346. else if ((target = which_armor(mtmp, W_ARM)) != 0) 2347. (void) water_damage(target, suit_simple_name(target), 2348. TRUE); 2349. else if ((target = which_armor(mtmp, W_ARMU)) != 0) 2350. (void) water_damage(target, "shirt", TRUE); 2351. } 2352. 2353. if (mptr == &mons[PM_IRON_GOLEM]) { 2354. if (in_sight) 2355. pline("%s falls to pieces!", Monnam(mtmp)); 2356. else if (mtmp->mtame) 2357. pline("May %s rust in peace.", mon_nam(mtmp)); 2358. mondied(mtmp); 2359. if (DEADMONSTER(mtmp)) 2360. trapkilled = TRUE; 2361. } else if (mptr == &mons[PM_GREMLIN] && rn2(3)) { 2362. (void) split_mon(mtmp, (struct monst *) 0); 2363. } 2364. break; 2365. } /* RUST_TRAP */ 2366. case FIRE_TRAP: 2367. mfiretrap: 2368. if (in_sight) 2369. pline("A %s erupts from the %s under %s!", tower_of_flame, 2370. surface(mtmp->mx, mtmp->my), mon_nam(mtmp)); 2371. else if (see_it) /* evidently `mtmp' is invisible */ 2372. You_see("a %s erupt from the %s!", tower_of_flame, 2373. surface(mtmp->mx, mtmp->my)); 2374. 2375. if (resists_fire(mtmp)) { 2376. if (in_sight) { 2377. shieldeff(mtmp->mx, mtmp->my); 2378. pline("%s is uninjured.", Monnam(mtmp)); 2379. } 2380. } else { 2381. int num = d(2, 4), alt; 2382. boolean immolate = FALSE; 2383. 2384. /* paper burns very fast, assume straw is tightly 2385. * packed and burns a bit slower */ 2386. switch (monsndx(mptr)) { 2387. case PM_PAPER_GOLEM: 2388. immolate = TRUE; 2389. alt = mtmp->mhpmax; 2390. break; 2391. case PM_STRAW_GOLEM: 2392. alt = mtmp->mhpmax / 2; 2393. break; 2394. case PM_WOOD_GOLEM: 2395. alt = mtmp->mhpmax / 4; 2396. break; 2397. case PM_LEATHER_GOLEM: 2398. alt = mtmp->mhpmax / 8; 2399. break; 2400. default: 2401. alt = 0; 2402. break; 2403. } 2404. if (alt > num) 2405. num = alt; 2406. 2407. if (thitm(0, mtmp, (struct obj *) 0, num, immolate)) 2408. trapkilled = TRUE; 2409. else 2410. /* we know mhp is at least `num' below mhpmax, 2411. so no (mhp > mhpmax) check is needed here */ 2412. mtmp->mhpmax -= rn2(num + 1); 2413. } 2414. if (burnarmor(mtmp) || rn2(3)) { 2415. (void) destroy_mitem(mtmp, SCROLL_CLASS, AD_FIRE); 2416. (void) destroy_mitem(mtmp, SPBOOK_CLASS, AD_FIRE); 2417. (void) destroy_mitem(mtmp, POTION_CLASS, AD_FIRE); 2418. } 2419. if (burn_floor_objects(mtmp->mx, mtmp->my, see_it, FALSE) 2420. && !see_it && distu(mtmp->mx, mtmp->my) <= 3 * 3) 2421. You("smell smoke."); 2422. if (is_ice(mtmp->mx, mtmp->my)) 2423. melt_ice(mtmp->mx, mtmp->my, (char *) 0); 2424. if (see_it && t_at(mtmp->mx, mtmp->my)) 2425. seetrap(trap); 2426. break; 2427. case PIT: 2428. case SPIKED_PIT: 2429. fallverb = "falls"; 2430. if (is_flyer(mptr) || is_floater(mptr) 2431. || (mtmp->wormno && count_wsegs(mtmp) > 5) 2432. || is_clinger(mptr)) { 2433. if (force_mintrap && !Sokoban) { 2434. /* openfallingtrap; not inescapable here */ 2435. if (in_sight) { 2436. seetrap(trap); 2437. pline("%s doesn't fall into the pit.", Monnam(mtmp)); 2438. } 2439. break; /* inescapable = FALSE; */ 2440. } 2441. if (!inescapable) 2442. break; /* avoids trap */ 2443. fallverb = "is dragged"; /* sokoban pit */ 2444. } 2445. if (!passes_walls(mptr)) 2446. mtmp->mtrapped = 1; 2447. if (in_sight) { 2448. pline("%s %s into %s pit!", Monnam(mtmp), fallverb, 2449. a_your[trap->madeby_u]); 2450. if (mptr == &mons[PM_PIT_VIPER] 2451. || mptr == &mons[PM_PIT_FIEND]) 2452. pline("How pitiful. Isn't that the pits?"); 2453. seetrap(trap); 2454. } 2455. mselftouch(mtmp, "Falling, ", FALSE); 2456. if (DEADMONSTER(mtmp) || thitm(0, mtmp, (struct obj *) 0, 2457. rnd((tt == PIT) ? 6 : 10), FALSE)) 2458. trapkilled = TRUE; 2459. break; 2460. case HOLE: 2461. case TRAPDOOR: 2462. if (!Can_fall_thru(&u.uz)) { 2463. impossible("mintrap: %ss cannot exist on this level.", 2464. defsyms[trap_to_defsym(tt)].explanation); 2465. break; /* don't activate it after all */ 2466. } 2467. if (is_flyer(mptr) || is_floater(mptr) || mptr == &mons[PM_WUMPUS] 2468. || (mtmp->wormno && count_wsegs(mtmp) > 5) 2469. || mptr->msize >= MZ_HUGE) { 2470. if (force_mintrap && !Sokoban) { 2471. /* openfallingtrap; not inescapable here */ 2472. if (in_sight) { 2473. seetrap(trap); 2474. if (tt == TRAPDOOR) 2475. pline( 2476. "A trap door opens, but %s doesn't fall through.", 2477. mon_nam(mtmp)); 2478. else /* (tt == HOLE) */ 2479. pline("%s doesn't fall through the hole.", 2480. Monnam(mtmp)); 2481. } 2482. break; /* inescapable = FALSE; */ 2483. } 2484. if (inescapable) { /* sokoban hole */ 2485. if (in_sight) { 2486. pline("%s seems to be yanked down!", Monnam(mtmp)); 2487. /* suppress message in mlevel_tele_trap() */ 2488. in_sight = FALSE; 2489. seetrap(trap); 2490. } 2491. } else 2492. break; 2493. } 2494. /*FALLTHRU*/ 2495. case LEVEL_TELEP: 2496. case MAGIC_PORTAL: { 2497. int mlev_res; 2498. 2499. mlev_res = mlevel_tele_trap(mtmp, trap, inescapable, in_sight); 2500. if (mlev_res) 2501. return mlev_res; 2502. break; 2503. } 2504. case TELEP_TRAP: 2505. mtele_trap(mtmp, trap, in_sight); 2506. break; 2507. case WEB: 2508. /* Monster in a web. */ 2509. if (webmaker(mptr)) 2510. break; 2511. if (mu_maybe_destroy_web(mtmp, in_sight, trap)) 2512. break; 2513. tear_web = FALSE; 2514. switch (monsndx(mptr)) { 2515. case PM_OWLBEAR: /* Eric Backus */ 2516. case PM_BUGBEAR: 2517. if (!in_sight) { 2518. You_hear("the roaring of a confused bear!"); 2519. mtmp->mtrapped = 1; 2520. break; 2521. } 2522. /*FALLTHRU*/ 2523. default: 2524. if (mptr->mlet == S_GIANT 2525. /* exclude baby dragons and relatively short worms */ 2526. || (mptr->mlet == S_DRAGON && extra_nasty(mptr)) 2527. || (mtmp->wormno && count_wsegs(mtmp) > 5)) { 2528. tear_web = TRUE; 2529. } else if (in_sight) { 2530. pline("%s is caught in %s spider web.", Monnam(mtmp), 2531. a_your[trap->madeby_u]); 2532. seetrap(trap); 2533. } 2534. mtmp->mtrapped = tear_web ? 0 : 1; 2535. break; 2536. /* this list is fairly arbitrary; it deliberately 2537. excludes wumpus & giant/ettin zombies/mummies */ 2538. case PM_TITANOTHERE: 2539. case PM_BALUCHITHERIUM: 2540. case PM_PURPLE_WORM: 2541. case PM_JABBERWOCK: 2542. case PM_IRON_GOLEM: 2543. case PM_BALROG: 2544. case PM_KRAKEN: 2545. case PM_MASTODON: 2546. case PM_ORION: 2547. case PM_NORN: 2548. case PM_CYCLOPS: 2549. case PM_LORD_SURTUR: 2550. tear_web = TRUE; 2551. break; 2552. } 2553. if (tear_web) { 2554. if (in_sight) 2555. pline("%s tears through %s spider web!", Monnam(mtmp), 2556. a_your[trap->madeby_u]); 2557. deltrap(trap); 2558. newsym(mtmp->mx, mtmp->my); 2559. } else if (force_mintrap && !mtmp->mtrapped) { 2560. if (in_sight) { 2561. pline("%s avoids %s spider web!", Monnam(mtmp), 2562. a_your[trap->madeby_u]); 2563. seetrap(trap); 2564. } 2565. } 2566. break; 2567. case STATUE_TRAP: 2568. break; 2569. case MAGIC_TRAP: 2570. /* A magic trap. Monsters usually immune. */ 2571. if (!rn2(21)) 2572. goto mfiretrap; 2573. break; 2574. case ANTI_MAGIC: 2575. /* similar to hero's case, more or less */ 2576. if (!resists_magm(mtmp)) { /* lose spell energy */ 2577. if (!mtmp->mcan && (attacktype(mptr, AT_MAGC) 2578. || attacktype(mptr, AT_BREA))) { 2579. mtmp->mspec_used += d(2, 2); 2580. if (in_sight) { 2581. seetrap(trap); 2582. pline("%s seems lethargic.", Monnam(mtmp)); 2583. } 2584. } 2585. } else { /* take some damage */ 2586. int dmgval2 = rnd(4); 2587. 2588. if ((otmp = MON_WEP(mtmp)) != 0 2589. && otmp->oartifact == ART_MAGICBANE) 2590. dmgval2 += rnd(4); 2591. for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) 2592. if (otmp->oartifact 2593. && defends_when_carried(AD_MAGM, otmp)) 2594. break; 2595. if (otmp) 2596. dmgval2 += rnd(4); 2597. if (passes_walls(mptr)) 2598. dmgval2 = (dmgval2 + 3) / 4; 2599. 2600. if (in_sight) 2601. seetrap(trap); 2602. mtmp->mhp -= dmgval2; 2603. if (DEADMONSTER(mtmp)) 2604. monkilled(mtmp, 2605. in_sight 2606. ? "compression from an anti-magic field" 2607. : (const char *) 0, 2608. -AD_MAGM); 2609. if (DEADMONSTER(mtmp)) 2610. trapkilled = TRUE; 2611. if (see_it) 2612. newsym(trap->tx, trap->ty); 2613. } 2614. break; 2615. case LANDMINE: 2616. if (rn2(3)) 2617. break; /* monsters usually don't set it off */ 2618. if (is_flyer(mptr)) { 2619. boolean already_seen = trap->tseen; 2620. 2621. if (in_sight && !already_seen) { 2622. pline("A trigger appears in a pile of soil below %s.", 2623. mon_nam(mtmp)); 2624. seetrap(trap); 2625. } 2626. if (rn2(3)) 2627. break; 2628. if (in_sight) { 2629. newsym(mtmp->mx, mtmp->my); 2630. pline_The("air currents set %s off!", 2631. already_seen ? "a land mine" : "it"); 2632. } 2633. } else if (in_sight) { 2634. newsym(mtmp->mx, mtmp->my); 2635. pline("%s%s triggers %s land mine!", 2636. !Deaf ? "KAABLAMM!!! " : "", Monnam(mtmp), 2637. a_your[trap->madeby_u]); 2638. } 2639. if (!in_sight && !Deaf) 2640. pline("Kaablamm! %s an explosion in the distance!", 2641. "You hear"); /* Deaf-aware */ 2642. blow_up_landmine(trap); 2643. /* explosion might have destroyed a drawbridge; don't 2644. dish out more damage if monster is already dead */ 2645. if (DEADMONSTER(mtmp) 2646. || thitm(0, mtmp, (struct obj *) 0, rnd(16), FALSE)) { 2647. trapkilled = TRUE; 2648. } else { 2649. /* monsters recursively fall into new pit */ 2650. if (mintrap(mtmp) == 2) 2651. trapkilled = TRUE; 2652. } 2653. /* a boulder may fill the new pit, crushing monster */ 2654. fill_pit(tx, ty); /* thitm may have already destroyed the trap */ 2655. if (DEADMONSTER(mtmp)) 2656. trapkilled = TRUE; 2657. if (unconscious()) { 2658. multi = -1; 2659. nomovemsg = "The explosion awakens you!"; 2660. } 2661. break; 2662. case POLY_TRAP: 2663. if (resists_magm(mtmp)) { 2664. shieldeff(mtmp->mx, mtmp->my); 2665. } else if (!resist(mtmp, WAND_CLASS, 0, NOTELL)) { 2666. if (newcham(mtmp, (struct permonst *) 0, FALSE, FALSE)) 2667. /* we're done with mptr but keep it up to date */ 2668. mptr = mtmp->data; 2669. if (in_sight) 2670. seetrap(trap); 2671. } 2672. break; 2673. case ROLLING_BOULDER_TRAP: 2674. if (!is_flyer(mptr)) { 2675. int style = ROLL | (in_sight ? 0 : LAUNCH_UNSEEN); 2676. 2677. newsym(mtmp->mx, mtmp->my); 2678. if (in_sight) 2679. pline("Click! %s triggers %s.", Monnam(mtmp), 2680. trap->tseen ? "a rolling boulder trap" : something); 2681. if (launch_obj(BOULDER, trap->launch.x, trap->launch.y, 2682. trap->launch2.x, trap->launch2.y, style)) { 2683. if (in_sight) 2684. trap->tseen = TRUE; 2685. if (DEADMONSTER(mtmp)) 2686. trapkilled = TRUE; 2687. } else { 2688. deltrap(trap); 2689. newsym(mtmp->mx, mtmp->my); 2690. } 2691. } 2692. break; 2693. case VIBRATING_SQUARE: 2694. if (see_it && !Blind) { 2695. seetrap(trap); /* before messages */ 2696. if (in_sight) { 2697. char buf[BUFSZ], *p, *monnm = mon_nam(mtmp); 2698. 2699. if (nolimbs(mtmp->data) 2700. || is_floater(mtmp->data) || is_flyer(mtmp->data)) { 2701. /* just "beneath <mon>" */ 2702. Strcpy(buf, monnm); 2703. } else { 2704. Strcpy(buf, s_suffix(monnm)); 2705. p = eos(strcat(buf, " ")); 2706. Strcpy(p, makeplural(mbodypart(mtmp, FOOT))); 2707. /* avoid "beneath 'rear paws'" or 'rear hooves' */ 2708. (void) strsubst(p, "rear ", ""); 2709. } 2710. You_see("a strange vibration beneath %s.", buf); 2711. } else { 2712. /* notice something (hearing uses a larger threshold 2713. for 'nearby') */ 2714. You_see("the ground vibrate %s.", 2715. (distu(mtmp->mx, mtmp->my) <= 2 * 2) 2716. ? "nearby" : "in the distance"); 2717. } 2718. } 2719. break; 2720. default: 2721. impossible("Some monster encountered a strange trap of type %d.", 2722. tt); 2723. } 2724. } 2725. if (trapkilled) 2726. return 2; 2727. return mtmp->mtrapped; 2728. } 2729. 2730. /* Combine cockatrice checks into single functions to avoid repeating code. */ 2731. void 2732. instapetrify(str) 2733. const char *str; 2734. { 2735. if (Stone_resistance) 2736. return; 2737. if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM)) 2738. return; 2739. You("turn to stone..."); 2740. killer.format = KILLED_BY; 2741. if (str != killer.name) 2742. Strcpy(killer.name, str ? str : ""); 2743. done(STONING); 2744. } 2745. 2746. void 2747. minstapetrify(mon, byplayer) 2748. struct monst *mon; 2749. boolean byplayer; 2750. { 2751. if (resists_ston(mon)) 2752. return; 2753. if (poly_when_stoned(mon->data)) { 2754. mon_to_stone(mon); 2755. return; 2756. } 2757. if (!vamp_stone(mon)) 2758. return; 2759. 2760. /* give a "<mon> is slowing down" message and also remove 2761. intrinsic speed (comparable to similar effect on the hero) */ 2762. mon_adjust_speed(mon, -3, (struct obj *) 0); 2763. 2764. if (cansee(mon->mx, mon->my)) 2765. pline("%s turns to stone.", Monnam(mon)); 2766. if (byplayer) { 2767. stoned = TRUE; 2768. xkilled(mon, XKILL_NOMSG); 2769. } else 2770. monstone(mon); 2771. } 2772. 2773. void 2774. selftouch(arg) 2775. const char *arg; 2776. { 2777. char kbuf[BUFSZ]; 2778. 2779. if (uwep && uwep->otyp == CORPSE && touch_petrifies(&mons[uwep->corpsenm]) 2780. && !Stone_resistance) { 2781. pline("%s touch the %s corpse.", arg, mons[uwep->corpsenm].mname); 2782. Sprintf(kbuf, "%s corpse", an(mons[uwep->corpsenm].mname)); 2783. instapetrify(kbuf); 2784. /* life-saved; unwield the corpse if we can't handle it */ 2785. if (!uarmg && !Stone_resistance) 2786. uwepgone(); 2787. } 2788. /* Or your secondary weapon, if wielded [hypothetical; we don't 2789. allow two-weapon combat when either weapon is a corpse] */ 2790. if (u.twoweap && uswapwep && uswapwep->otyp == CORPSE 2791. && touch_petrifies(&mons[uswapwep->corpsenm]) && !Stone_resistance) { 2792. pline("%s touch the %s corpse.", arg, mons[uswapwep->corpsenm].mname); 2793. Sprintf(kbuf, "%s corpse", an(mons[uswapwep->corpsenm].mname)); 2794. instapetrify(kbuf); 2795. /* life-saved; unwield the corpse */ 2796. if (!uarmg && !Stone_resistance) 2797. uswapwepgone(); 2798. } 2799. } 2800. 2801. void 2802. mselftouch(mon, arg, byplayer) 2803. struct monst *mon; 2804. const char *arg; 2805. boolean byplayer; 2806. { 2807. struct obj *mwep = MON_WEP(mon); 2808. 2809. if (mwep && mwep->otyp == CORPSE && touch_petrifies(&mons[mwep->corpsenm]) 2810. && !resists_ston(mon)) { 2811. if (cansee(mon->mx, mon->my)) { 2812. pline("%s%s touches %s.", arg ? arg : "", 2813. arg ? mon_nam(mon) : Monnam(mon), 2814. corpse_xname(mwep, (const char *) 0, CXN_PFX_THE)); 2815. } 2816. minstapetrify(mon, byplayer); 2817. /* if life-saved, might not be able to continue wielding */ 2818. if (!DEADMONSTER(mon) && !which_armor(mon, W_ARMG) && !resists_ston(mon)) 2819. mwepgone(mon); 2820. } 2821. } 2822. 2823. /* start levitating */ 2824. void 2825. float_up() 2826. { 2827. context.botl = TRUE; 2828. if (u.utrap) { 2829. if (u.utraptype == TT_PIT) { 2830. reset_utrap(FALSE); 2831. You("float up, out of the pit!"); 2832. vision_full_recalc = 1; /* vision limits change */ 2833. fill_pit(u.ux, u.uy); 2834. } else if (u.utraptype == TT_LAVA /* molten lava */ 2835. || u.utraptype == TT_INFLOOR) { /* solidified lava */ 2836. Your("body pulls upward, but your %s are still stuck.", 2837. makeplural(body_part(LEG))); 2838. } else if (u.utraptype == TT_BURIEDBALL) { /* tethered */ 2839. coord cc; 2840. 2841. cc.x = u.ux, cc.y = u.uy; 2842. /* caveat: this finds the first buried iron ball within 2843. one step of the specified location, not necessarily the 2844. buried [former] uball at the original anchor point */ 2845. (void) buried_ball(&cc); 2846. /* being chained to the floor blocks levitation from floating 2847. above that floor but not from enhancing carrying capacity */ 2848. You("feel lighter, but your %s is still chained to the %s.", 2849. body_part(LEG), 2850. IS_ROOM(levl[cc.x][cc.y].typ) ? "floor" : "ground"); 2851. } else if (u.utraptype == WEB) { 2852. You("float up slightly, but you are still stuck in the web."); 2853. } else { /* bear trap */ 2854. You("float up slightly, but your %s is still stuck.", 2855. body_part(LEG)); 2856. } 2857. /* when still trapped, float_vs_flight() below will block levitation */ 2858. #if 0 2859. } else if (Is_waterlevel(&u.uz)) { 2860. pline("It feels as though you've lost some weight."); 2861. #endif 2862. } else if (u.uinwater) { 2863. spoteffects(TRUE); 2864. } else if (u.uswallow) { 2865. You(is_animal(u.ustuck->data) ? "float away from the %s." 2866. : "spiral up into %s.", 2867. is_animal(u.ustuck->data) ? surface(u.ux, u.uy) 2868. : mon_nam(u.ustuck)); 2869. } else if (Hallucination) { 2870. pline("Up, up, and awaaaay! You're walking on air!"); 2871. } else if (Is_airlevel(&u.uz)) { 2872. You("gain control over your movements."); 2873. } else { 2874. You("start to float in the air!"); 2875. } 2876. if (u.usteed && !is_floater(u.usteed->data) && !is_flyer(u.usteed->data)) { 2877. if (Lev_at_will) { 2878. pline("%s magically floats up!", Monnam(u.usteed)); 2879. } else { 2880. You("cannot stay on %s.", mon_nam(u.usteed)); 2881. dismount_steed(DISMOUNT_GENERIC); 2882. } 2883. } 2884. if (Flying) 2885. You("are no longer able to control your flight."); 2886. float_vs_flight(); /* set BFlying, also BLevitation if still trapped */ 2887. /* levitation gives maximum carrying capacity, so encumbrance 2888. state might be reduced */ 2889. (void) encumber_msg(); 2890. return; 2891. } 2892. 2893. void 2894. fill_pit(x, y) 2895. int x, y; 2896. { 2897. struct obj *otmp; 2898. struct trap *t; 2899. 2900. if ((t = t_at(x, y)) && is_pit(t->ttyp) 2901. && (otmp = sobj_at(BOULDER, x, y))) { 2902. obj_extract_self(otmp); 2903. (void) flooreffects(otmp, x, y, "settle"); 2904. } 2905. } 2906. 2907. /* stop levitating */ 2908. int 2909. float_down(hmask, emask) 2910. long hmask, emask; /* might cancel timeout */ 2911. { 2912. register struct trap *trap = (struct trap *) 0; 2913. d_level current_dungeon_level; 2914. boolean no_msg = FALSE; 2915. 2916. HLevitation &= ~hmask; 2917. ELevitation &= ~emask; 2918. if (Levitation) 2919. return 0; /* maybe another ring/potion/boots */ 2920. if (BLevitation) { 2921. /* if blocked by terrain, we haven't actually been levitating so 2922. we don't give any end-of-levitation feedback or side-effects, 2923. but if blocking is solely due to being trapped in/on floor, 2924. do give some feedback but skip other float_down() effects */ 2925. boolean trapped = (BLevitation == I_SPECIAL); 2926. 2927. float_vs_flight(); 2928. if (trapped && u.utrap) /* u.utrap => paranoia */ 2929. You("are no longer trying to float up from the %s.", 2930. (u.utraptype == TT_BEARTRAP) ? "trap's jaws" 2931. : (u.utraptype == TT_WEB) ? "web" 2932. : (u.utraptype == TT_BURIEDBALL) ? "chain" 2933. : (u.utraptype == TT_LAVA) ? "lava" 2934. : "ground"); /* TT_INFLOOR */ 2935. (void) encumber_msg(); /* carrying capacity might have changed */ 2936. return 0; 2937. } 2938. context.botl = TRUE; 2939. nomul(0); /* stop running or resting */ 2940. if (BFlying) { 2941. /* controlled flight no longer overridden by levitation */ 2942. float_vs_flight(); /* clears BFlying & I_SPECIAL 2943. * unless hero is stuck in floor */ 2944. if (Flying) { 2945. You("have stopped levitating and are now flying."); 2946. (void) encumber_msg(); /* carrying capacity might have changed */ 2947. return 1; 2948. } 2949. } 2950. if (u.uswallow) { 2951. You("float down, but you are still %s.", 2952. is_animal(u.ustuck->data) ? "swallowed" : "engulfed"); 2953. (void) encumber_msg(); 2954. return 1; 2955. } 2956. 2957. if (Punished && !carried(uball) 2958. && (is_pool(uball->ox, uball->oy) 2959. || ((trap = t_at(uball->ox, uball->oy)) 2960. && (is_pit(trap->ttyp) || is_hole(trap->ttyp))))) { 2961. u.ux0 = u.ux; 2962. u.uy0 = u.uy; 2963. u.ux = uball->ox; 2964. u.uy = uball->oy; 2965. movobj(uchain, uball->ox, uball->oy); 2966. newsym(u.ux0, u.uy0); 2967. vision_full_recalc = 1; /* in case the hero moved. */ 2968. } 2969. /* check for falling into pool - added by GAN 10/20/86 */ 2970. if (!Flying) { 2971. if (!u.uswallow && u.ustuck) { 2972. if (sticks(youmonst.data)) 2973. You("aren't able to maintain your hold on %s.", 2974. mon_nam(u.ustuck)); 2975. else 2976. pline("Startled, %s can no longer hold you!", 2977. mon_nam(u.ustuck)); 2978. u.ustuck = 0; 2979. } 2980. /* kludge alert: 2981. * drown() and lava_effects() print various messages almost 2982. * every time they're called which conflict with the "fall 2983. * into" message below. Thus, we want to avoid printing 2984. * confusing, duplicate or out-of-order messages. 2985. * Use knowledge of the two routines as a hack -- this 2986. * should really be handled differently -dlc 2987. */ 2988. if (is_pool(u.ux, u.uy) && !Wwalking && !Swimming && !u.uinwater) 2989. no_msg = drown(); 2990. 2991. if (is_lava(u.ux, u.uy)) { 2992. (void) lava_effects(); 2993. no_msg = TRUE; 2994. } 2995. } 2996. if (!trap) { 2997. trap = t_at(u.ux, u.uy); 2998. if (Is_airlevel(&u.uz)) { 2999. You("begin to tumble in place."); 3000. } else if (Is_waterlevel(&u.uz) && !no_msg) { 3001. You_feel("heavier."); 3002. /* u.uinwater msgs already in spoteffects()/drown() */ 3003. } else if (!u.uinwater && !no_msg) { 3004. if (!(emask & W_SADDLE)) { 3005. if (Sokoban && trap) { 3006. /* Justification elsewhere for Sokoban traps is based 3007. * on air currents. This is consistent with that. 3008. * The unexpected additional force of the air currents 3009. * once levitation ceases knocks you off your feet. 3010. */ 3011. if (Hallucination) 3012. pline("Bummer! You've crashed."); 3013. else 3014. You("fall over."); 3015. losehp(rnd(2), "dangerous winds", KILLED_BY); 3016. if (u.usteed) 3017. dismount_steed(DISMOUNT_FELL); 3018. selftouch("As you fall, you"); 3019. } else if (u.usteed && (is_floater(u.usteed->data) 3020. || is_flyer(u.usteed->data))) { 3021. You("settle more firmly in the saddle."); 3022. } else if (Hallucination) { 3023. pline("Bummer! You've %s.", 3024. is_pool(u.ux, u.uy) 3025. ? "splashed down" 3026. : "hit the ground"); 3027. } else { 3028. You("float gently to the %s.", surface(u.ux, u.uy)); 3029. } 3030. } 3031. } 3032. } 3033. 3034. /* levitation gives maximum carrying capacity, so having it end 3035. potentially triggers greater encumbrance; do this after 3036. 'come down' messages, before trap activation or autopickup */ 3037. (void) encumber_msg(); 3038. 3039. /* can't rely on u.uz0 for detecting trap door-induced level change; 3040. it gets changed to reflect the new level before we can check it */ 3041. assign_level(¤t_dungeon_level, &u.uz); 3042. if (trap) { 3043. switch (trap->ttyp) { 3044. case STATUE_TRAP: 3045. break; 3046. case HOLE: 3047. case TRAPDOOR: 3048. if (!Can_fall_thru(&u.uz) || u.ustuck) 3049. break; 3050. /*FALLTHRU*/ 3051. default: 3052. if (!u.utrap) /* not already in the trap */ 3053. dotrap(trap, 0); 3054. } 3055. } 3056. if (!Is_airlevel(&u.uz) && !Is_waterlevel(&u.uz) && !u.uswallow 3057. /* falling through trap door calls goto_level, 3058. and goto_level does its own pickup() call */ 3059. && on_level(&u.uz, ¤t_dungeon_level)) 3060. (void) pickup(1); 3061. return 1; 3062. } 3063. 3064. /* shared code for climbing out of a pit */ 3065. void 3066. climb_pit() 3067. { 3068. if (!u.utrap || u.utraptype != TT_PIT) 3069. return; 3070. 3071. if (Passes_walls) { 3072. /* marked as trapped so they can pick things up */ 3073. You("ascend from the pit."); 3074. reset_utrap(FALSE); 3075. fill_pit(u.ux, u.uy); 3076. vision_full_recalc = 1; /* vision limits change */ 3077. } else if (!rn2(2) && sobj_at(BOULDER, u.ux, u.uy)) { 3078. Your("%s gets stuck in a crevice.", body_part(LEG)); 3079. display_nhwindow(WIN_MESSAGE, FALSE); 3080. clear_nhwindow(WIN_MESSAGE); 3081. You("free your %s.", body_part(LEG)); 3082. } else if ((Flying || is_clinger(youmonst.data)) && !Sokoban) { 3083. /* eg fell in pit, then poly'd to a flying monster; 3084. or used '>' to deliberately enter it */ 3085. You("%s from the pit.", Flying ? "fly" : "climb"); 3086. reset_utrap(FALSE); 3087. fill_pit(u.ux, u.uy); 3088. vision_full_recalc = 1; /* vision limits change */ 3089. } else if (!(--u.utrap)) { 3090. reset_utrap(FALSE); 3091. You("%s to the edge of the pit.", 3092. (Sokoban && Levitation) 3093. ? "struggle against the air currents and float" 3094. : u.usteed ? "ride" : "crawl"); 3095. fill_pit(u.ux, u.uy); 3096. vision_full_recalc = 1; /* vision limits change */ 3097. } else if (u.dz || flags.verbose) { 3098. if (u.usteed) 3099. Norep("%s is still in a pit.", upstart(y_monnam(u.usteed))); 3100. else 3101. Norep((Hallucination && !rn2(5)) 3102. ? "You've fallen, and you can't get up." 3103. : "You are still in a pit."); 3104. } 3105. } 3106. 3107. STATIC_OVL void 3108. dofiretrap(box) 3109. struct obj *box; /* null for floor trap */ 3110. { 3111. boolean see_it = !Blind; 3112. int num, alt; 3113. 3114. /* Bug: for box case, the equivalent of burn_floor_objects() ought 3115. * to be done upon its contents. 3116. */ 3117. 3118. if ((box && !carried(box)) ? is_pool(box->ox, box->oy) : Underwater) { 3119. pline("A cascade of steamy bubbles erupts from %s!", 3120. the(box ? xname(box) : surface(u.ux, u.uy))); 3121. if (Fire_resistance) 3122. You("are uninjured."); 3123. else 3124. losehp(rnd(3), "boiling water", KILLED_BY); 3125. return; 3126. } 3127. pline("A %s %s from %s!", tower_of_flame, box ? "bursts" : "erupts", 3128. the(box ? xname(box) : surface(u.ux, u.uy))); 3129. if (Fire_resistance) { 3130. shieldeff(u.ux, u.uy); 3131. num = rn2(2); 3132. } else if (Upolyd) { 3133. num = d(2, 4); 3134. switch (u.umonnum) { 3135. case PM_PAPER_GOLEM: 3136. alt = u.mhmax; 3137. break; 3138. case PM_STRAW_GOLEM: 3139. alt = u.mhmax / 2; 3140. break; 3141. case PM_WOOD_GOLEM: 3142. alt = u.mhmax / 4; 3143. break; 3144. case PM_LEATHER_GOLEM: 3145. alt = u.mhmax / 8; 3146. break; 3147. default: 3148. alt = 0; 3149. break; 3150. } 3151. if (alt > num) 3152. num = alt; 3153. if (u.mhmax > mons[u.umonnum].mlevel) 3154. u.mhmax -= rn2(min(u.mhmax, num + 1)), context.botl = 1; 3155. } else { 3156. num = d(2, 4); 3157. if (u.uhpmax > u.ulevel) 3158. u.uhpmax -= rn2(min(u.uhpmax, num + 1)), context.botl = 1; 3159. } 3160. if (!num) 3161. You("are uninjured."); 3162. else 3163. losehp(num, tower_of_flame, KILLED_BY_AN); /* fire damage */ 3164. burn_away_slime(); 3165. 3166. if (burnarmor(&youmonst) || rn2(3)) { 3167. destroy_item(SCROLL_CLASS, AD_FIRE); 3168. destroy_item(SPBOOK_CLASS, AD_FIRE); 3169. destroy_item(POTION_CLASS, AD_FIRE); 3170. } 3171. if (!box && burn_floor_objects(u.ux, u.uy, see_it, TRUE) && !see_it) 3172. You("smell paper burning."); 3173. if (is_ice(u.ux, u.uy)) 3174. melt_ice(u.ux, u.uy, (char *) 0); 3175. } 3176. 3177. STATIC_OVL void 3178. domagictrap() 3179. { 3180. register int fate = rnd(20); 3181. 3182. /* What happened to the poor sucker? */ 3183. 3184. if (fate < 10) { 3185. /* Most of the time, it creates some monsters. */ 3186. int cnt = rnd(4); 3187. 3188. /* blindness effects */ 3189. if (!resists_blnd(&youmonst)) { 3190. You("are momentarily blinded by a flash of light!"); 3191. make_blinded((long) rn1(5, 10), FALSE); 3192. if (!Blind) 3193. Your1(vision_clears); 3194. } else if (!Blind) { 3195. You_see("a flash of light!"); 3196. } 3197. 3198. /* deafness effects */ 3199. if (!Deaf) { 3200. You_hear("a deafening roar!"); 3201. incr_itimeout(&HDeaf, rn1(20, 30)); 3202. context.botl = TRUE; 3203. } else { 3204. /* magic vibrations still hit you */ 3205. You_feel("rankled."); 3206. incr_itimeout(&HDeaf, rn1(5, 15)); 3207. context.botl = TRUE; 3208. } 3209. while (cnt--) 3210. (void) makemon((struct permonst *) 0, u.ux, u.uy, NO_MM_FLAGS); 3211. /* roar: wake monsters in vicinity, after placing trap-created ones */ 3212. wake_nearto(u.ux, u.uy, 7 * 7); 3213. /* [flash: should probably also hit nearby gremlins with light] */ 3214. } else 3215. switch (fate) { 3216. case 10: 3217. case 11: 3218. /* sometimes nothing happens */ 3219. break; 3220. case 12: /* a flash of fire */ 3221. dofiretrap((struct obj *) 0); 3222. break; 3223. 3224. /* odd feelings */ 3225. case 13: 3226. pline("A shiver runs up and down your %s!", body_part(SPINE)); 3227. break; 3228. case 14: 3229. You_hear(Hallucination ? "the moon howling at you." 3230. : "distant howling."); 3231. break; 3232. case 15: 3233. if (on_level(&u.uz, &qstart_level)) 3234. You_feel( 3235. "%slike the prodigal son.", 3236. (flags.female || (Upolyd && is_neuter(youmonst.data))) 3237. ? "oddly " 3238. : ""); 3239. else 3240. You("suddenly yearn for %s.", 3241. Hallucination 3242. ? "Cleveland" 3243. : (In_quest(&u.uz) || at_dgn_entrance("The Quest")) 3244. ? "your nearby homeland" 3245. : "your distant homeland"); 3246. break; 3247. case 16: 3248. Your("pack shakes violently!"); 3249. break; 3250. case 17: 3251. You(Hallucination ? "smell hamburgers." : "smell charred flesh."); 3252. break; 3253. case 18: 3254. You_feel("tired."); 3255. break; 3256. 3257. /* very occasionally something nice happens. */ 3258. case 19: { /* tame nearby monsters */ 3259. int i, j; 3260. struct monst *mtmp; 3261. 3262. (void) adjattrib(A_CHA, 1, FALSE); 3263. for (i = -1; i <= 1; i++) 3264. for (j = -1; j <= 1; j++) { 3265. if (!isok(u.ux + i, u.uy + j)) 3266. continue; 3267. mtmp = m_at(u.ux + i, u.uy + j); 3268. if (mtmp) 3269. (void) tamedog(mtmp, (struct obj *) 0); 3270. } 3271. break; 3272. } 3273. case 20: { /* uncurse stuff */ 3274. struct obj pseudo; 3275. long save_conf = HConfusion; 3276. 3277. pseudo = zeroobj; /* neither cursed nor blessed, 3278. and zero out oextra */ 3279. pseudo.otyp = SCR_REMOVE_CURSE; 3280. HConfusion = 0L; 3281. (void) seffects(&pseudo); 3282. HConfusion = save_conf; 3283. break; 3284. } 3285. default: 3286. break; 3287. } 3288. } 3289. 3290. /* Set an item on fire. 3291. * "force" means not to roll a luck-based protection check for the 3292. * item. 3293. * "x" and "y" are the coordinates to dump the contents of a 3294. * container, if it burns up. 3295. * 3296. * Return whether the object was destroyed. 3297. */ 3298. boolean 3299. fire_damage(obj, force, x, y) 3300. struct obj *obj; 3301. boolean force; 3302. xchar x, y; 3303. { 3304. int chance; 3305. struct obj *otmp, *ncobj; 3306. int in_sight = !Blind && couldsee(x, y); /* Don't care if it's lit */ 3307. int dindx; 3308. 3309. /* object might light in a controlled manner */ 3310. if (catch_lit(obj)) 3311. return FALSE; 3312. 3313. if (Is_container(obj)) { 3314. switch (obj->otyp) { 3315. case ICE_BOX: 3316. return FALSE; /* Immune */ 3317. case CHEST: 3318. chance = 40; 3319. break; 3320. case LARGE_BOX: 3321. chance = 30; 3322. break; 3323. default: 3324. chance = 20; 3325. break; 3326. } 3327. if ((!force && (Luck + 5) > rn2(chance)) 3328. || (is_flammable(obj) && obj->oerodeproof)) 3329. return FALSE; 3330. /* Container is burnt up - dump contents out */ 3331. if (in_sight) 3332. pline("%s catches fire and burns.", Yname2(obj)); 3333. if (Has_contents(obj)) { 3334. if (in_sight) 3335. pline("Its contents fall out."); 3336. for (otmp = obj->cobj; otmp; otmp = ncobj) { 3337. ncobj = otmp->nobj; 3338. obj_extract_self(otmp); 3339. if (!flooreffects(otmp, x, y, "")) 3340. place_object(otmp, x, y); 3341. } 3342. } 3343. setnotworn(obj); 3344. delobj(obj); 3345. return TRUE; 3346. } else if (!force && (Luck + 5) > rn2(20)) { 3347. /* chance per item of sustaining damage: 3348. * max luck (Luck==13): 10% 3349. * avg luck (Luck==0): 75% 3350. * awful luck (Luck<-4): 100% 3351. */ 3352. return FALSE; 3353. } else if (obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS) { 3354. if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL) 3355. return FALSE; 3356. if (obj->otyp == SPE_BOOK_OF_THE_DEAD) { 3357. if (in_sight) 3358. pline("Smoke rises from %s.", the(xname(obj))); 3359. return FALSE; 3360. } 3361. dindx = (obj->oclass == SCROLL_CLASS) ? 3 : 4; 3362. if (in_sight) 3363. pline("%s %s.", Yname2(obj), 3364. destroy_strings[dindx][(obj->quan > 1L)]); 3365. setnotworn(obj); 3366. delobj(obj); 3367. return TRUE; 3368. } else if (obj->oclass == POTION_CLASS) { 3369. dindx = (obj->otyp != POT_OIL) ? 1 : 2; 3370. if (in_sight) 3371. pline("%s %s.", Yname2(obj), 3372. destroy_strings[dindx][(obj->quan > 1L)]); 3373. setnotworn(obj); 3374. delobj(obj); 3375. return TRUE; 3376. } else if (erode_obj(obj, (char *) 0, ERODE_BURN, EF_DESTROY) 3377. == ER_DESTROYED) { 3378. return TRUE; 3379. } 3380. return FALSE; 3381. } 3382. 3383. /* 3384. * Apply fire_damage() to an entire chain. 3385. * 3386. * Return number of objects destroyed. --ALI 3387. */ 3388. int 3389. fire_damage_chain(chain, force, here, x, y) 3390. struct obj *chain; 3391. boolean force, here; 3392. xchar x, y; 3393. { 3394. struct obj *obj, *nobj; 3395. int num = 0; 3396. 3397. for (obj = chain; obj; obj = nobj) { 3398. nobj = here ? obj->nexthere : obj->nobj; 3399. if (fire_damage(obj, force, x, y)) 3400. ++num; 3401. } 3402. 3403. if (num && (Blind && !couldsee(x, y))) 3404. You("smell smoke."); 3405. return num; 3406. } 3407. 3408. /* obj has been thrown or dropped into lava; damage is worse than mere fire */ 3409. boolean 3410. lava_damage(obj, x, y) 3411. struct obj *obj; 3412. xchar x, y; 3413. { 3414. int otyp = obj->otyp, ocls = obj->oclass; 3415. 3416. /* the Amulet, invocation items, and Rider corpses are never destroyed 3417. (let Book of the Dead fall through to fire_damage() to get feedback) */ 3418. if (obj_resists(obj, 0, 0) && otyp != SPE_BOOK_OF_THE_DEAD) 3419. return FALSE; 3420. /* destroy liquid (venom), wax, veggy, flesh, paper (except for scrolls 3421. and books--let fire damage deal with them), cloth, leather, wood, bone 3422. unless it's inherently or explicitly fireproof or contains something; 3423. note: potions are glass so fall through to fire_damage() and boil */ 3424. if (objects[otyp].oc_material < DRAGON_HIDE 3425. && ocls != SCROLL_CLASS && ocls != SPBOOK_CLASS 3426. && objects[otyp].oc_oprop != FIRE_RES 3427. && otyp != WAN_FIRE && otyp != FIRE_HORN 3428. /* assumes oerodeproof isn't overloaded for some other purpose on 3429. non-eroding items */ 3430. && !obj->oerodeproof 3431. /* fire_damage() knows how to deal with containers and contents */ 3432. && !Has_contents(obj)) { 3433. if (cansee(x, y)) { 3434. /* this feedback is pretty clunky and can become very verbose 3435. when former contents of a burned container get here via 3436. flooreffects() */ 3437. if (obj == thrownobj || obj == kickedobj) 3438. pline("%s %s up!", is_plural(obj) ? "They" : "It", 3439. otense(obj, "burn")); 3440. else 3441. You_see("%s hit lava and burn up!", doname(obj)); 3442. } 3443. if (carried(obj)) { /* shouldn't happen */ 3444. remove_worn_item(obj, TRUE); 3445. useupall(obj); 3446. } else 3447. delobj(obj); 3448. return TRUE; 3449. } 3450. return fire_damage(obj, TRUE, x, y); 3451. } 3452. 3453. void 3454. acid_damage(obj) 3455. struct obj *obj; 3456. { 3457. /* Scrolls but not spellbooks can be erased by acid. */ 3458. struct monst *victim; 3459. boolean vismon; 3460. 3461. if (!obj) 3462. return; 3463. 3464. victim = carried(obj) ? &youmonst : mcarried(obj) ? obj->ocarry : NULL; 3465. vismon = victim && (victim != &youmonst) && canseemon(victim); 3466. 3467. if (obj->greased) { 3468. grease_protect(obj, (char *) 0, victim); 3469. } else if (obj->oclass == SCROLL_CLASS && obj->otyp != SCR_BLANK_PAPER) { 3470. if (obj->otyp != SCR_BLANK_PAPER 3471. #ifdef MAIL 3472. && obj->otyp != SCR_MAIL 3473. #endif 3474. ) { 3475. if (!Blind) { 3476. if (victim == &youmonst) 3477. pline("Your %s.", aobjnam(obj, "fade")); 3478. else if (vismon) 3479. pline("%s %s.", s_suffix(Monnam(victim)), 3480. aobjnam(obj, "fade")); 3481. } 3482. } 3483. obj->otyp = SCR_BLANK_PAPER; 3484. obj->spe = 0; 3485. obj->dknown = 0; 3486. } else 3487. erode_obj(obj, (char *) 0, ERODE_CORRODE, EF_GREASE | EF_VERBOSE); 3488. } 3489. 3490. /* context for water_damage(), managed by water_damage_chain(); 3491. when more than one stack of potions of acid explode while processing 3492. a chain of objects, use alternate phrasing after the first message */ 3493. static struct h2o_ctx { 3494. int dkn_boom, unk_boom; /* track dknown, !dknown separately */ 3495. boolean ctx_valid; 3496. } acid_ctx = { 0, 0, FALSE }; 3497. 3498. /* Get an object wet and damage it appropriately. 3499. * "ostr", if present, is used instead of the object name in some 3500. * messages. 3501. * "force" means not to roll luck to protect some objects. 3502. * Returns an erosion return value (ER_*) 3503. */ 3504. int 3505. water_damage(obj, ostr, force) 3506. struct obj *obj; 3507. const char *ostr; 3508. boolean force; 3509. { 3510. if (!obj) 3511. return ER_NOTHING; 3512. 3513. if (snuff_lit(obj)) 3514. return ER_DAMAGED; 3515. 3516. if (!ostr) 3517. ostr = cxname(obj); 3518. 3519. if (obj->otyp == CAN_OF_GREASE && obj->spe > 0) { 3520. return ER_NOTHING; 3521. } else if (obj->otyp == TOWEL && obj->spe < 7) { 3522. wet_a_towel(obj, rnd(7), TRUE); 3523. return ER_NOTHING; 3524. } else if (obj->greased) { 3525. if (!rn2(2)) 3526. obj->greased = 0; 3527. if (carried(obj)) 3528. update_inventory(); 3529. return ER_GREASED; 3530. } else if (Is_container(obj) && !Is_box(obj) 3531. && (obj->otyp != OILSKIN_SACK || (obj->cursed && !rn2(3)))) { 3532. if (carried(obj)) 3533. pline("Water gets into your %s!", ostr); 3534. 3535. water_damage_chain(obj->cobj, FALSE); 3536. return ER_DAMAGED; /* contents were damaged */ 3537. } else if (obj->otyp == OILSKIN_SACK) { 3538. if (carried(obj)) 3539. pline("Some water slides right off your %s.", ostr); 3540. makeknown(OILSKIN_SACK); 3541. /* not actually damaged, but because we /didn't/ get the "water 3542. gets into!" message, the player now has more information and 3543. thus we need to waste any potion they may have used (also, 3544. flavourwise the water is now on the floor) */ 3545. return ER_DAMAGED; 3546. } else if (!force && (Luck + 5) > rn2(20)) { 3547. /* chance per item of sustaining damage: 3548. * max luck: 10% 3549. * avg luck (Luck==0): 75% 3550. * awful luck (Luck<-4): 100% 3551. */ 3552. return ER_NOTHING; 3553. } else if (obj->oclass == SCROLL_CLASS) { 3554. if (obj->otyp == SCR_BLANK_PAPER 3555. #ifdef MAIL 3556. || obj->otyp == SCR_MAIL 3557. #endif 3558. ) return 0; 3559. if (carried(obj)) 3560. pline("Your %s %s.", ostr, vtense(ostr, "fade")); 3561. 3562. obj->otyp = SCR_BLANK_PAPER; 3563. obj->dknown = 0; 3564. obj->spe = 0; 3565. if (carried(obj)) 3566. update_inventory(); 3567. return ER_DAMAGED; 3568. } else if (obj->oclass == SPBOOK_CLASS) { 3569. if (obj->otyp == SPE_BOOK_OF_THE_DEAD) { 3570. pline("Steam rises from %s.", the(xname(obj))); 3571. return 0; 3572. } else if (obj->otyp == SPE_BLANK_PAPER) { 3573. return 0; 3574. } 3575. if (carried(obj)) 3576. pline("Your %s %s.", ostr, vtense(ostr, "fade")); 3577. 3578. if (obj->otyp == SPE_NOVEL) { 3579. obj->novelidx = 0; 3580. free_oname(obj); 3581. } 3582. 3583. obj->otyp = SPE_BLANK_PAPER; 3584. obj->dknown = 0; 3585. if (carried(obj)) 3586. update_inventory(); 3587. return ER_DAMAGED; 3588. } else if (obj->oclass == POTION_CLASS) { 3589. if (obj->otyp == POT_ACID) { 3590. char *bufp; 3591. boolean one = (obj->quan == 1L), update = carried(obj), 3592. exploded = FALSE; 3593. 3594. if (Blind && !carried(obj)) 3595. obj->dknown = 0; 3596. if (acid_ctx.ctx_valid) 3597. exploded = ((obj->dknown ? acid_ctx.dkn_boom 3598. : acid_ctx.unk_boom) > 0); 3599. /* First message is 3600. * "a [potion|<color> potion|potion of acid] explodes" 3601. * depending on obj->dknown (potion has been seen) and 3602. * objects[POT_ACID].oc_name_known (fully discovered), 3603. * or "some {plural version} explode" when relevant. 3604. * Second and subsequent messages for same chain and 3605. * matching dknown status are 3606. * "another [potion|<color> &c] explodes" or plural 3607. * variant. 3608. */ 3609. bufp = simpleonames(obj); 3610. pline("%s %s %s!", /* "A potion explodes!" */ 3611. !exploded ? (one ? "A" : "Some") 3612. : (one ? "Another" : "More"), 3613. bufp, vtense(bufp, "explode")); 3614. if (acid_ctx.ctx_valid) { 3615. if (obj->dknown) 3616. acid_ctx.dkn_boom++; 3617. else 3618. acid_ctx.unk_boom++; 3619. } 3620. setnotworn(obj); 3621. delobj(obj); 3622. if (update) 3623. update_inventory(); 3624. return ER_DESTROYED; 3625. } else if (obj->odiluted) { 3626. if (carried(obj)) 3627. pline("Your %s %s further.", ostr, vtense(ostr, "dilute")); 3628. 3629. obj->otyp = POT_WATER; 3630. obj->dknown = 0; 3631. obj->blessed = obj->cursed = 0; 3632. obj->odiluted = 0; 3633. if (carried(obj)) 3634. update_inventory(); 3635. return ER_DAMAGED; 3636. } else if (obj->otyp != POT_WATER) { 3637. if (carried(obj)) 3638. pline("Your %s %s.", ostr, vtense(ostr, "dilute")); 3639. 3640. obj->odiluted++; 3641. if (carried(obj)) 3642. update_inventory(); 3643. return ER_DAMAGED; 3644. } 3645. } else { 3646. return erode_obj(obj, ostr, ERODE_RUST, EF_NONE); 3647. } 3648. return ER_NOTHING; 3649. } 3650. 3651. void 3652. water_damage_chain(obj, here) 3653. struct obj *obj; 3654. boolean here; 3655. { 3656. struct obj *otmp; 3657. 3658. /* initialize acid context: so far, neither seen (dknown) potions of 3659. acid nor unseen have exploded during this water damage sequence */ 3660. acid_ctx.dkn_boom = acid_ctx.unk_boom = 0; 3661. acid_ctx.ctx_valid = TRUE; 3662. 3663. for (; obj; obj = otmp) { 3664. otmp = here ? obj->nexthere : obj->nobj; 3665. water_damage(obj, (char *) 0, FALSE); 3666. } 3667. 3668. /* reset acid context */ 3669. acid_ctx.dkn_boom = acid_ctx.unk_boom = 0; 3670. acid_ctx.ctx_valid = FALSE; 3671. } 3672. 3673. /* 3674. * This function is potentially expensive - rolling 3675. * inventory list multiple times. Luckily it's seldom needed. 3676. * Returns TRUE if disrobing made player unencumbered enough to 3677. * crawl out of the current predicament. 3678. */ 3679. STATIC_OVL boolean 3680. emergency_disrobe(lostsome) 3681. boolean *lostsome; 3682. { 3683. int invc = inv_cnt(TRUE); 3684. 3685. while (near_capacity() > (Punished ? UNENCUMBERED : SLT_ENCUMBER)) { 3686. register struct obj *obj, *otmp = (struct obj *) 0; 3687. register int i; 3688. 3689. /* Pick a random object */ 3690. if (invc > 0) { 3691. i = rn2(invc); 3692. for (obj = invent; obj; obj = obj->nobj) { 3693. /* 3694. * Undroppables are: body armor, boots, gloves, 3695. * amulets, and rings because of the time and effort 3696. * in removing them + loadstone and other cursed stuff 3697. * for obvious reasons. 3698. */ 3699. if (!((obj->otyp == LOADSTONE && obj->cursed) || obj == uamul 3700. || obj == uleft || obj == uright || obj == ublindf 3701. || obj == uarm || obj == uarmc || obj == uarmg 3702. || obj == uarmf || obj == uarmu 3703. || (obj->cursed && (obj == uarmh || obj == uarms)) 3704. || welded(obj))) 3705. otmp = obj; 3706. /* reached the mark and found some stuff to drop? */ 3707. if (--i < 0 && otmp) 3708. break; 3709. 3710. /* else continue */ 3711. } 3712. } 3713. if (!otmp) 3714. return FALSE; /* nothing to drop! */ 3715. if (otmp->owornmask) 3716. remove_worn_item(otmp, FALSE); 3717. *lostsome = TRUE; 3718. dropx(otmp); 3719. invc--; 3720. } 3721. return TRUE; 3722. } 3723. 3724. 3725. /* return TRUE iff player relocated */ 3726. boolean 3727. drown() 3728. { 3729. const char *pool_of_water; 3730. boolean inpool_ok = FALSE, crawl_ok; 3731. int i, x, y; 3732. 3733. /* happily wading in the same contiguous pool */ 3734. if (u.uinwater && is_pool(u.ux - u.dx, u.uy - u.dy) 3735. && (Swimming || Amphibious)) { 3736. /* water effects on objects every now and then */ 3737. if (!rn2(5)) 3738. inpool_ok = TRUE; 3739. else 3740. return FALSE; 3741. } 3742. 3743. if (!u.uinwater) { 3744. You("%s into the %s%c", Is_waterlevel(&u.uz) ? "plunge" : "fall", 3745. hliquid("water"), 3746. Amphibious || Swimming ? '.' : '!'); 3747. if (!Swimming && !Is_waterlevel(&u.uz)) 3748. You("sink like %s.", Hallucination ? "the Titanic" : "a rock"); 3749. } 3750. 3751. water_damage_chain(invent, FALSE); 3752. 3753. if (u.umonnum == PM_GREMLIN && rn2(3)) 3754. (void) split_mon(&youmonst, (struct monst *) 0); 3755. else if (u.umonnum == PM_IRON_GOLEM) { 3756. You("rust!"); 3757. i = Maybe_Half_Phys(d(2, 6)); 3758. if (u.mhmax > i) 3759. u.mhmax -= i; 3760. losehp(i, "rusting away", KILLED_BY); 3761. } 3762. if (inpool_ok) 3763. return FALSE; 3764. 3765. if ((i = number_leashed()) > 0) { 3766. pline_The("leash%s slip%s loose.", (i > 1) ? "es" : "", 3767. (i > 1) ? "" : "s"); 3768. unleash_all(); 3769. } 3770. 3771. if (Amphibious || Swimming) { 3772. if (Amphibious) { 3773. if (flags.verbose) 3774. pline("But you aren't drowning."); 3775. if (!Is_waterlevel(&u.uz)) { 3776. if (Hallucination) 3777. Your("keel hits the bottom."); 3778. else 3779. You("touch bottom."); 3780. } 3781. } 3782. if (Punished) { 3783. unplacebc(); 3784. placebc(); 3785. } 3786. vision_recalc(2); /* unsee old position */ 3787. u.uinwater = 1; 3788. under_water(1); 3789. vision_full_recalc = 1; 3790. return FALSE; 3791. } 3792. if ((Teleportation || can_teleport(youmonst.data)) && !Unaware 3793. && (Teleport_control || rn2(3) < Luck + 2)) { 3794. You("attempt a teleport spell."); /* utcsri!carroll */ 3795. if (!level.flags.noteleport) { 3796. (void) dotele(FALSE); 3797. if (!is_pool(u.ux, u.uy)) 3798. return TRUE; 3799. } else 3800. pline_The("attempted teleport spell fails."); 3801. } 3802. if (u.usteed) { 3803. dismount_steed(DISMOUNT_GENERIC); 3804. if (!is_pool(u.ux, u.uy)) 3805. return TRUE; 3806. } 3807. crawl_ok = FALSE; 3808. x = y = 0; /* lint suppression */ 3809. /* if sleeping, wake up now so that we don't crawl out of water 3810. while still asleep; we can't do that the same way that waking 3811. due to combat is handled; note unmul() clears u.usleep */ 3812. if (u.usleep) 3813. unmul("Suddenly you wake up!"); 3814. /* being doused will revive from fainting */ 3815. if (is_fainted()) 3816. reset_faint(); 3817. /* can't crawl if unable to move (crawl_ok flag stays false) */ 3818. if (multi < 0 || (Upolyd && !youmonst.data->mmove)) 3819. goto crawl; 3820. /* look around for a place to crawl to */ 3821. for (i = 0; i < 100; i++) { 3822. x = rn1(3, u.ux - 1); 3823. y = rn1(3, u.uy - 1); 3824. if (crawl_destination(x, y)) { 3825. crawl_ok = TRUE; 3826. goto crawl; 3827. } 3828. } 3829. /* one more scan */ 3830. for (x = u.ux - 1; x <= u.ux + 1; x++) 3831. for (y = u.uy - 1; y <= u.uy + 1; y++) 3832. if (crawl_destination(x, y)) { 3833. crawl_ok = TRUE; 3834. goto crawl; 3835. } 3836. crawl: 3837. if (crawl_ok) { 3838. boolean lost = FALSE; 3839. /* time to do some strip-tease... */ 3840. boolean succ = Is_waterlevel(&u.uz) ? TRUE : emergency_disrobe(&lost); 3841. 3842. You("try to crawl out of the %s.", hliquid("water")); 3843. if (lost) 3844. You("dump some of your gear to lose weight..."); 3845. if (succ) { 3846. pline("Pheew! That was close."); 3847. teleds(x, y, TRUE); 3848. return TRUE; 3849. } 3850. /* still too much weight */ 3851. pline("But in vain."); 3852. } 3853. u.uinwater = 1; 3854. You("drown."); 3855. for (i = 0; i < 5; i++) { /* arbitrary number of loops */ 3856. /* killer format and name are reconstructed every iteration 3857. because lifesaving resets them */ 3858. pool_of_water = waterbody_name(u.ux, u.uy); 3859. killer.format = KILLED_BY_AN; 3860. /* avoid "drowned in [a] water" */ 3861. if (!strcmp(pool_of_water, "water")) 3862. pool_of_water = "deep water", killer.format = KILLED_BY; 3863. Strcpy(killer.name, pool_of_water); 3864. done(DROWNING); 3865. /* oops, we're still alive. better get out of the water. */ 3866. if (safe_teleds(TRUE)) 3867. break; /* successful life-save */ 3868. /* nowhere safe to land; repeat drowning loop... */ 3869. pline("You're still drowning."); 3870. } 3871. if (u.uinwater) { 3872. u.uinwater = 0; 3873. You("find yourself back %s.", 3874. Is_waterlevel(&u.uz) ? "in an air bubble" : "on land"); 3875. } 3876. return TRUE; 3877. } 3878. 3879. void 3880. drain_en(n) 3881. int n; 3882. { 3883. if (!u.uenmax) { 3884. /* energy is completely gone */ 3885. You_feel("momentarily lethargic."); 3886. } else { 3887. /* throttle further loss a bit when there's not much left to lose */ 3888. if (n > u.uenmax || n > u.ulevel) 3889. n = rnd(n); 3890. 3891. You_feel("your magical energy drain away%c", (n > u.uen) ? '!' : '.'); 3892. u.uen -= n; 3893. if (u.uen < 0) { 3894. u.uenmax -= rnd(-u.uen); 3895. if (u.uenmax < 0) 3896. u.uenmax = 0; 3897. u.uen = 0; 3898. } 3899. context.botl = 1; 3900. } 3901. } 3902. 3903. /* disarm a trap */ 3904. int 3905. dountrap() 3906. { 3907. if (near_capacity() >= HVY_ENCUMBER) { 3908. pline("You're too strained to do that."); 3909. return 0; 3910. } 3911. if ((nohands(youmonst.data) && !webmaker(youmonst.data)) 3912. || !youmonst.data->mmove) { 3913. pline("And just how do you expect to do that?"); 3914. return 0; 3915. } else if (u.ustuck && sticks(youmonst.data)) { 3916. pline("You'll have to let go of %s first.", mon_nam(u.ustuck)); 3917. return 0; 3918. } 3919. if (u.ustuck || (welded(uwep) && bimanual(uwep))) { 3920. Your("%s seem to be too busy for that.", makeplural(body_part(HAND))); 3921. return 0; 3922. } 3923. return untrap(FALSE); 3924. } 3925. 3926. /* Probability of disabling a trap. Helge Hafting */ 3927. STATIC_OVL int 3928. untrap_prob(ttmp) 3929. struct trap *ttmp; 3930. { 3931. int chance = 3; 3932. 3933. /* Only spiders know how to deal with webs reliably */ 3934. if (ttmp->ttyp == WEB && !webmaker(youmonst.data)) 3935. chance = 30; 3936. if (Confusion || Hallucination) 3937. chance++; 3938. if (Blind) 3939. chance++; 3940. if (Stunned) 3941. chance += 2; 3942. if (Fumbling) 3943. chance *= 2; 3944. /* Your own traps are better known than others. */ 3945. if (ttmp && ttmp->madeby_u) 3946. chance--; 3947. if (Role_if(PM_ROGUE)) { 3948. if (rn2(2 * MAXULEV) < u.ulevel) 3949. chance--; 3950. if (u.uhave.questart && chance > 1) 3951. chance--; 3952. } else if (Role_if(PM_RANGER) && chance > 1) 3953. chance--; 3954. return rn2(chance); 3955. } 3956. 3957. /* Replace trap with object(s). Helge Hafting */ 3958. void 3959. cnv_trap_obj(otyp, cnt, ttmp, bury_it) 3960. int otyp; 3961. int cnt; 3962. struct trap *ttmp; 3963. boolean bury_it; 3964. { 3965. struct obj *otmp = mksobj(otyp, TRUE, FALSE); 3966. 3967. otmp->quan = cnt; 3968. otmp->owt = weight(otmp); 3969. /* Only dart traps are capable of being poisonous */ 3970. if (otyp != DART) 3971. otmp->opoisoned = 0; 3972. place_object(otmp, ttmp->tx, ttmp->ty); 3973. if (bury_it) { 3974. /* magical digging first disarms this trap, then will unearth it */ 3975. (void) bury_an_obj(otmp, (boolean *) 0); 3976. } else { 3977. /* Sell your own traps only... */ 3978. if (ttmp->madeby_u) 3979. sellobj(otmp, ttmp->tx, ttmp->ty); 3980. stackobj(otmp); 3981. } 3982. newsym(ttmp->tx, ttmp->ty); 3983. if (u.utrap && ttmp->tx == u.ux && ttmp->ty == u.uy) 3984. reset_utrap(TRUE); 3985. deltrap(ttmp); 3986. } 3987. 3988. /* while attempting to disarm an adjacent trap, we've fallen into it */ 3989. STATIC_OVL void 3990. move_into_trap(ttmp) 3991. struct trap *ttmp; 3992. { 3993. int bc = 0; 3994. xchar x = ttmp->tx, y = ttmp->ty, bx, by, cx, cy; 3995. boolean unused; 3996. 3997. bx = by = cx = cy = 0; /* lint suppression */ 3998. /* we know there's no monster in the way, and we're not trapped */ 3999. if (!Punished 4000. || drag_ball(x, y, &bc, &bx, &by, &cx, &cy, &unused, TRUE)) { 4001. u.ux0 = u.ux, u.uy0 = u.uy; 4002. u.ux = x, u.uy = y; 4003. u.umoved = TRUE; 4004. newsym(u.ux0, u.uy0); 4005. vision_recalc(1); 4006. check_leash(u.ux0, u.uy0); 4007. if (Punished) 4008. move_bc(0, bc, bx, by, cx, cy); 4009. /* marking the trap unseen forces dotrap() to treat it like a new 4010. discovery and prevents pickup() -> look_here() -> check_here() 4011. from giving a redundant "there is a <trap> here" message when 4012. there are objects covering this trap */ 4013. ttmp->tseen = 0; /* hack for check_here() */ 4014. /* trigger the trap */ 4015. iflags.failing_untrap++; /* spoteffects() -> dotrap(,FAILEDUNTRAP) */ 4016. spoteffects(TRUE); /* pickup() + dotrap() */ 4017. iflags.failing_untrap--; 4018. /* this should no longer be necessary; before the failing_untrap 4019. hack, Flying hero would not trigger an unseen bear trap and 4020. setting it not-yet-seen above resulted in leaving it hidden */ 4021. if ((ttmp = t_at(u.ux, u.uy)) != 0) 4022. ttmp->tseen = 1; 4023. exercise(A_WIS, FALSE); 4024. } 4025. } 4026. 4027. /* 0: doesn't even try 4028. * 1: tries and fails 4029. * 2: succeeds 4030. */ 4031. STATIC_OVL int 4032. try_disarm(ttmp, force_failure) 4033. struct trap *ttmp; 4034. boolean force_failure; 4035. { 4036. struct monst *mtmp = m_at(ttmp->tx, ttmp->ty); 4037. int ttype = ttmp->ttyp; 4038. boolean under_u = (!u.dx && !u.dy); 4039. boolean holdingtrap = (ttype == BEAR_TRAP || ttype == WEB); 4040. 4041. /* Test for monster first, monsters are displayed instead of trap. */ 4042. if (mtmp && (!mtmp->mtrapped || !holdingtrap)) { 4043. pline("%s is in the way.", Monnam(mtmp)); 4044. return 0; 4045. } 4046. /* We might be forced to move onto the trap's location. */ 4047. if (sobj_at(BOULDER, ttmp->tx, ttmp->ty) && !Passes_walls && !under_u) { 4048. There("is a boulder in your way."); 4049. return 0; 4050. } 4051. /* duplicate tight-space checks from test_move */ 4052. if (u.dx && u.dy && bad_rock(youmonst.data, u.ux, ttmp->ty) 4053. && bad_rock(youmonst.data, ttmp->tx, u.uy)) { 4054. if ((invent && (inv_weight() + weight_cap() > 600)) 4055. || bigmonst(youmonst.data)) { 4056. /* don't allow untrap if they can't get thru to it */ 4057. You("are unable to reach the %s!", 4058. defsyms[trap_to_defsym(ttype)].explanation); 4059. return 0; 4060. } 4061. } 4062. /* untrappable traps are located on the ground. */ 4063. if (!can_reach_floor(under_u)) { 4064. if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) 4065. rider_cant_reach(); 4066. else 4067. You("are unable to reach the %s!", 4068. defsyms[trap_to_defsym(ttype)].explanation); 4069. return 0; 4070. } 4071. 4072. /* Will our hero succeed? */ 4073. if (force_failure || untrap_prob(ttmp)) { 4074. if (rnl(5)) { 4075. pline("Whoops..."); 4076. if (mtmp) { /* must be a trap that holds monsters */ 4077. if (ttype == BEAR_TRAP) { 4078. if (mtmp->mtame) 4079. abuse_dog(mtmp); 4080. mtmp->mhp -= rnd(4); 4081. if (DEADMONSTER(mtmp)) 4082. killed(mtmp); 4083. } else if (ttype == WEB) { 4084. if (!webmaker(youmonst.data)) { 4085. struct trap *ttmp2 = maketrap(u.ux, u.uy, WEB); 4086. 4087. if (ttmp2) { 4088. pline_The( 4089. "webbing sticks to you. You're caught too!"); 4090. dotrap(ttmp2, NOWEBMSG); 4091. if (u.usteed && u.utrap) { 4092. /* you, not steed, are trapped */ 4093. dismount_steed(DISMOUNT_FELL); 4094. } 4095. } 4096. } else 4097. pline("%s remains entangled.", Monnam(mtmp)); 4098. } 4099. } else if (under_u) { 4100. /* [don't need the iflags.failing_untrap hack here] */ 4101. dotrap(ttmp, FAILEDUNTRAP); 4102. } else { 4103. move_into_trap(ttmp); 4104. } 4105. } else { 4106. pline("%s %s is difficult to %s.", 4107. ttmp->madeby_u ? "Your" : under_u ? "This" : "That", 4108. defsyms[trap_to_defsym(ttype)].explanation, 4109. (ttype == WEB) ? "remove" : "disarm"); 4110. } 4111. return 1; 4112. } 4113. return 2; 4114. } 4115. 4116. STATIC_OVL void 4117. reward_untrap(ttmp, mtmp) 4118. struct trap *ttmp; 4119. struct monst *mtmp; 4120. { 4121. if (!ttmp->madeby_u) { 4122. if (rnl(10) < 8 && !mtmp->mpeaceful && !mtmp->msleeping 4123. && !mtmp->mfrozen && !mindless(mtmp->data) 4124. && mtmp->data->mlet != S_HUMAN) { 4125. mtmp->mpeaceful = 1; 4126. set_malign(mtmp); /* reset alignment */ 4127. pline("%s is grateful.", Monnam(mtmp)); 4128. } 4129. /* Helping someone out of a trap is a nice thing to do, 4130. * A lawful may be rewarded, but not too often. */ 4131. if (!rn2(3) && !rnl(8) && u.ualign.type == A_LAWFUL) { 4132. adjalign(1); 4133. You_feel("that you did the right thing."); 4134. } 4135. } 4136. } 4137. 4138. STATIC_OVL int 4139. disarm_holdingtrap(ttmp) /* Helge Hafting */ 4140. struct trap *ttmp; 4141. { 4142. struct monst *mtmp; 4143. int fails = try_disarm(ttmp, FALSE); 4144. 4145. if (fails < 2) 4146. return fails; 4147. 4148. /* ok, disarm it. */ 4149. 4150. /* untrap the monster, if any. 4151. There's no need for a cockatrice test, only the trap is touched */ 4152. if ((mtmp = m_at(ttmp->tx, ttmp->ty)) != 0) { 4153. mtmp->mtrapped = 0; 4154. You("remove %s %s from %s.", the_your[ttmp->madeby_u], 4155. (ttmp->ttyp == BEAR_TRAP) ? "bear trap" : "webbing", 4156. mon_nam(mtmp)); 4157. reward_untrap(ttmp, mtmp); 4158. } else { 4159. if (ttmp->ttyp == BEAR_TRAP) { 4160. You("disarm %s bear trap.", the_your[ttmp->madeby_u]); 4161. cnv_trap_obj(BEARTRAP, 1, ttmp, FALSE); 4162. } else /* if (ttmp->ttyp == WEB) */ { 4163. You("succeed in removing %s web.", the_your[ttmp->madeby_u]); 4164. deltrap(ttmp); 4165. } 4166. } 4167. newsym(u.ux + u.dx, u.uy + u.dy); 4168. return 1; 4169. } 4170. 4171. STATIC_OVL int 4172. disarm_landmine(ttmp) /* Helge Hafting */ 4173. struct trap *ttmp; 4174. { 4175. int fails = try_disarm(ttmp, FALSE); 4176. 4177. if (fails < 2) 4178. return fails; 4179. You("disarm %s land mine.", the_your[ttmp->madeby_u]); 4180. cnv_trap_obj(LAND_MINE, 1, ttmp, FALSE); 4181. return 1; 4182. } 4183. 4184. /* getobj will filter down to cans of grease and known potions of oil */ 4185. static NEARDATA const char oil[] = { ALL_CLASSES, TOOL_CLASS, POTION_CLASS, 4186. 0 }; 4187. 4188. /* it may not make much sense to use grease on floor boards, but so what? */ 4189. STATIC_OVL int 4190. disarm_squeaky_board(ttmp) 4191. struct trap *ttmp; 4192. { 4193. struct obj *obj; 4194. boolean bad_tool; 4195. int fails; 4196. 4197. obj = getobj(oil, "untrap with"); 4198. if (!obj) 4199. return 0; 4200. 4201. bad_tool = (obj->cursed 4202. || ((obj->otyp != POT_OIL || obj->lamplit) 4203. && (obj->otyp != CAN_OF_GREASE || !obj->spe))); 4204. fails = try_disarm(ttmp, bad_tool); 4205. if (fails < 2) 4206. return fails; 4207. 4208. /* successfully used oil or grease to fix squeaky board */ 4209. if (obj->otyp == CAN_OF_GREASE) { 4210. consume_obj_charge(obj, TRUE); 4211. } else { 4212. useup(obj); /* oil */ 4213. makeknown(POT_OIL); 4214. } 4215. You("repair the squeaky board."); /* no madeby_u */ 4216. deltrap(ttmp); 4217. newsym(u.ux + u.dx, u.uy + u.dy); 4218. more_experienced(1, 5); 4219. newexplevel(); 4220. return 1; 4221. } 4222. 4223. /* removes traps that shoot arrows, darts, etc. */ 4224. STATIC_OVL int 4225. disarm_shooting_trap(ttmp, otyp) 4226. struct trap *ttmp; 4227. int otyp; 4228. { 4229. int fails = try_disarm(ttmp, FALSE); 4230. 4231. if (fails < 2) 4232. return fails; 4233. You("disarm %s trap.", the_your[ttmp->madeby_u]); 4234. cnv_trap_obj(otyp, 50 - rnl(50), ttmp, FALSE); 4235. return 1; 4236. } 4237. 4238. /* Is the weight too heavy? 4239. * Formula as in near_capacity() & check_capacity() */ 4240. STATIC_OVL int 4241. try_lift(mtmp, ttmp, wt, stuff) 4242. struct monst *mtmp; 4243. struct trap *ttmp; 4244. int wt; 4245. boolean stuff; 4246. { 4247. int wc = weight_cap(); 4248. 4249. if (((wt * 2) / wc) >= HVY_ENCUMBER) { 4250. pline("%s is %s for you to lift.", Monnam(mtmp), 4251. stuff ? "carrying too much" : "too heavy"); 4252. if (!ttmp->madeby_u && !mtmp->mpeaceful && mtmp->mcanmove 4253. && !mindless(mtmp->data) && mtmp->data->mlet != S_HUMAN 4254. && rnl(10) < 3) { 4255. mtmp->mpeaceful = 1; 4256. set_malign(mtmp); /* reset alignment */ 4257. pline("%s thinks it was nice of you to try.", Monnam(mtmp)); 4258. } 4259. return 0; 4260. } 4261. return 1; 4262. } 4263. 4264. /* Help trapped monster (out of a (spiked) pit) */ 4265. STATIC_OVL int 4266. help_monster_out(mtmp, ttmp) 4267. struct monst *mtmp; 4268. struct trap *ttmp; 4269. { 4270. int wt; 4271. struct obj *otmp; 4272. boolean uprob; 4273. 4274. /* 4275. * This works when levitating too -- consistent with the ability 4276. * to hit monsters while levitating. 4277. * 4278. * Should perhaps check that our hero has arms/hands at the 4279. * moment. Helping can also be done by engulfing... 4280. * 4281. * Test the monster first - monsters are displayed before traps. 4282. */ 4283. if (!mtmp->mtrapped) { 4284. pline("%s isn't trapped.", Monnam(mtmp)); 4285. return 0; 4286. } 4287. /* Do you have the necessary capacity to lift anything? */ 4288. if (check_capacity((char *) 0)) 4289. return 1; 4290. 4291. /* Will our hero succeed? */ 4292. if ((uprob = untrap_prob(ttmp)) && !mtmp->msleeping && mtmp->mcanmove) { 4293. You("try to reach out your %s, but %s backs away skeptically.", 4294. makeplural(body_part(ARM)), mon_nam(mtmp)); 4295. return 1; 4296. } 4297. 4298. /* is it a cockatrice?... */ 4299. if (touch_petrifies(mtmp->data) && !uarmg && !Stone_resistance) { 4300. You("grab the trapped %s using your bare %s.", mtmp->data->mname, 4301. makeplural(body_part(HAND))); 4302. 4303. if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM)) { 4304. display_nhwindow(WIN_MESSAGE, FALSE); 4305. } else { 4306. char kbuf[BUFSZ]; 4307. 4308. Sprintf(kbuf, "trying to help %s out of a pit", 4309. an(mtmp->data->mname)); 4310. instapetrify(kbuf); 4311. return 1; 4312. } 4313. } 4314. /* need to do cockatrice check first if sleeping or paralyzed */ 4315. if (uprob) { 4316. You("try to grab %s, but cannot get a firm grasp.", mon_nam(mtmp)); 4317. if (mtmp->msleeping) { 4318. mtmp->msleeping = 0; 4319. pline("%s awakens.", Monnam(mtmp)); 4320. } 4321. return 1; 4322. } 4323. 4324. You("reach out your %s and grab %s.", makeplural(body_part(ARM)), 4325. mon_nam(mtmp)); 4326. 4327. if (mtmp->msleeping) { 4328. mtmp->msleeping = 0; 4329. pline("%s awakens.", Monnam(mtmp)); 4330. } else if (mtmp->mfrozen && !rn2(mtmp->mfrozen)) { 4331. /* After such manhandling, perhaps the effect wears off */ 4332. mtmp->mcanmove = 1; 4333. mtmp->mfrozen = 0; 4334. pline("%s stirs.", Monnam(mtmp)); 4335. } 4336. 4337. /* is the monster too heavy? */ 4338. wt = inv_weight() + mtmp->data->cwt; 4339. if (!try_lift(mtmp, ttmp, wt, FALSE)) 4340. return 1; 4341. 4342. /* is the monster with inventory too heavy? */ 4343. for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) 4344. wt += otmp->owt; 4345. if (!try_lift(mtmp, ttmp, wt, TRUE)) 4346. return 1; 4347. 4348. You("pull %s out of the pit.", mon_nam(mtmp)); 4349. mtmp->mtrapped = 0; 4350. reward_untrap(ttmp, mtmp); 4351. fill_pit(mtmp->mx, mtmp->my); 4352. return 1; 4353. } 4354. 4355. int 4356. untrap(force) 4357. boolean force; 4358. { 4359. register struct obj *otmp; 4360. register int x, y; 4361. int ch; 4362. struct trap *ttmp; 4363. struct monst *mtmp; 4364. const char *trapdescr; 4365. boolean here, useplural, deal_with_floor_trap, 4366. confused = (Confusion || Hallucination), 4367. trap_skipped = FALSE; 4368. int boxcnt = 0; 4369. char the_trap[BUFSZ], qbuf[QBUFSZ]; 4370. 4371. if (!getdir((char *) 0)) 4372. return 0; 4373. x = u.ux + u.dx; 4374. y = u.uy + u.dy; 4375. if (!isok(x, y)) { 4376. pline_The("perils lurking there are beyond your grasp."); 4377. return 0; 4378. } 4379. /* 'force' is true for #invoke; make it be true for #untrap if 4380. carrying MKoT */ 4381. if (!force && has_magic_key(&youmonst)) 4382. force = TRUE; 4383. 4384. ttmp = t_at(x, y); 4385. if (ttmp && !ttmp->tseen) 4386. ttmp = 0; 4387. trapdescr = ttmp ? defsyms[trap_to_defsym(ttmp->ttyp)].explanation : 0; 4388. here = (x == u.ux && y == u.uy); /* !u.dx && !u.dy */ 4389. 4390. if (here) /* are there are one or more containers here? */ 4391. for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) 4392. if (Is_box(otmp)) { 4393. if (++boxcnt > 1) 4394. break; 4395. } 4396. 4397. deal_with_floor_trap = can_reach_floor(FALSE); 4398. if (!deal_with_floor_trap) { 4399. *the_trap = '\0'; 4400. if (ttmp) 4401. Strcat(the_trap, an(trapdescr)); 4402. if (ttmp && boxcnt) 4403. Strcat(the_trap, " and "); 4404. if (boxcnt) 4405. Strcat(the_trap, (boxcnt == 1) ? "a container" : "containers"); 4406. useplural = ((ttmp && boxcnt > 0) || boxcnt > 1); 4407. /* note: boxcnt and useplural will always be 0 for !here case */ 4408. if (ttmp || boxcnt) 4409. There("%s %s %s but you can't reach %s%s.", 4410. useplural ? "are" : "is", the_trap, here ? "here" : "there", 4411. useplural ? "them" : "it", 4412. u.usteed ? " while mounted" : ""); 4413. trap_skipped = (ttmp != 0); 4414. } else { /* deal_with_floor_trap */ 4415. 4416. if (ttmp) { 4417. Strcpy(the_trap, the(trapdescr)); 4418. if (boxcnt) { 4419. if (is_pit(ttmp->ttyp)) { 4420. You_cant("do much about %s%s.", the_trap, 4421. u.utrap ? " that you're stuck in" 4422. : " while standing on the edge of it"); 4423. trap_skipped = TRUE; 4424. deal_with_floor_trap = FALSE; 4425. } else { 4426. Sprintf( 4427. qbuf, "There %s and %s here. %s %s?", 4428. (boxcnt == 1) ? "is a container" : "are containers", 4429. an(trapdescr), 4430. (ttmp->ttyp == WEB) ? "Remove" : "Disarm", the_trap); 4431. switch (ynq(qbuf)) { 4432. case 'q': 4433. return 0; 4434. case 'n': 4435. trap_skipped = TRUE; 4436. deal_with_floor_trap = FALSE; 4437. break; 4438. } 4439. } 4440. } 4441. if (deal_with_floor_trap) { 4442. if (u.utrap) { 4443. You("cannot deal with %s while trapped%s!", the_trap, 4444. (x == u.ux && y == u.uy) ? " in it" : ""); 4445. return 1; 4446. } 4447. if ((mtmp = m_at(x, y)) != 0 4448. && (M_AP_TYPE(mtmp) == M_AP_FURNITURE 4449. || M_AP_TYPE(mtmp) == M_AP_OBJECT)) { 4450. stumble_onto_mimic(mtmp); 4451. return 1; 4452. } 4453. switch (ttmp->ttyp) { 4454. case BEAR_TRAP: 4455. case WEB: 4456. return disarm_holdingtrap(ttmp); 4457. case LANDMINE: 4458. return disarm_landmine(ttmp); 4459. case SQKY_BOARD: 4460. return disarm_squeaky_board(ttmp); 4461. case DART_TRAP: 4462. return disarm_shooting_trap(ttmp, DART); 4463. case ARROW_TRAP: 4464. return disarm_shooting_trap(ttmp, ARROW); 4465. case PIT: 4466. case SPIKED_PIT: 4467. if (here) { 4468. You("are already on the edge of the pit."); 4469. return 0; 4470. } 4471. if (!mtmp) { 4472. pline("Try filling the pit instead."); 4473. return 0; 4474. } 4475. return help_monster_out(mtmp, ttmp); 4476. default: 4477. You("cannot disable %s trap.", !here ? "that" : "this"); 4478. return 0; 4479. } 4480. } 4481. } /* end if */ 4482. 4483. if (boxcnt) { 4484. for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) 4485. if (Is_box(otmp)) { 4486. (void) safe_qbuf(qbuf, "There is ", 4487. " here. Check it for traps?", otmp, 4488. doname, ansimpleoname, "a box"); 4489. switch (ynq(qbuf)) { 4490. case 'q': 4491. return 0; 4492. case 'n': 4493. continue; 4494. } 4495. 4496. if ((otmp->otrapped 4497. && (force || (!confused 4498. && rn2(MAXULEV + 1 - u.ulevel) < 10))) 4499. || (!force && confused && !rn2(3))) { 4500. You("find a trap on %s!", the(xname(otmp))); 4501. if (!confused) 4502. exercise(A_WIS, TRUE); 4503. 4504. switch (ynq("Disarm it?")) { 4505. case 'q': 4506. return 1; 4507. case 'n': 4508. trap_skipped = TRUE; 4509. continue; 4510. } 4511. 4512. if (otmp->otrapped) { 4513. exercise(A_DEX, TRUE); 4514. ch = ACURR(A_DEX) + u.ulevel; 4515. if (Role_if(PM_ROGUE)) 4516. ch *= 2; 4517. if (!force && (confused || Fumbling 4518. || rnd(75 + level_difficulty() / 2) 4519. > ch)) { 4520. (void) chest_trap(otmp, FINGER, TRUE); 4521. } else { 4522. You("disarm it!"); 4523. otmp->otrapped = 0; 4524. } 4525. } else 4526. pline("That %s was not trapped.", xname(otmp)); 4527. return 1; 4528. } else { 4529. You("find no traps on %s.", the(xname(otmp))); 4530. return 1; 4531. } 4532. } 4533. 4534. You(trap_skipped ? "find no other traps here." 4535. : "know of no traps here."); 4536. return 0; 4537. } 4538. 4539. if (stumble_on_door_mimic(x, y)) 4540. return 1; 4541. 4542. } /* deal_with_floor_trap */ 4543. /* doors can be manipulated even while levitating/unskilled riding */ 4544. 4545. if (!IS_DOOR(levl[x][y].typ)) { 4546. if (!trap_skipped) 4547. You("know of no traps there."); 4548. return 0; 4549. } 4550. 4551. switch (levl[x][y].doormask) { 4552. case D_NODOOR: 4553. You("%s no door there.", Blind ? "feel" : "see"); 4554. return 0; 4555. case D_ISOPEN: 4556. pline("This door is safely open."); 4557. return 0; 4558. case D_BROKEN: 4559. pline("This door is broken."); 4560. return 0; 4561. } 4562. 4563. if (((levl[x][y].doormask & D_TRAPPED) != 0 4564. && (force || (!confused && rn2(MAXULEV - u.ulevel + 11) < 10))) 4565. || (!force && confused && !rn2(3))) { 4566. You("find a trap on the door!"); 4567. exercise(A_WIS, TRUE); 4568. if (ynq("Disarm it?") != 'y') 4569. return 1; 4570. if (levl[x][y].doormask & D_TRAPPED) { 4571. ch = 15 + (Role_if(PM_ROGUE) ? u.ulevel * 3 : u.ulevel); 4572. exercise(A_DEX, TRUE); 4573. if (!force && (confused || Fumbling 4574. || rnd(75 + level_difficulty() / 2) > ch)) { 4575. You("set it off!"); 4576. b_trapped("door", FINGER); 4577. levl[x][y].doormask = D_NODOOR; 4578. unblock_point(x, y); 4579. newsym(x, y); 4580. /* (probably ought to charge for this damage...) */ 4581. if (*in_rooms(x, y, SHOPBASE)) 4582. add_damage(x, y, 0L); 4583. } else { 4584. You("disarm it!"); 4585. levl[x][y].doormask &= ~D_TRAPPED; 4586. } 4587. } else 4588. pline("This door was not trapped."); 4589. return 1; 4590. } else { 4591. You("find no traps on the door."); 4592. return 1; 4593. } 4594. } 4595. 4596. /* for magic unlocking; returns true if targetted monster (which might 4597. be hero) gets untrapped; the trap remains intact */ 4598. boolean 4599. openholdingtrap(mon, noticed) 4600. struct monst *mon; 4601. boolean *noticed; /* set to true iff hero notices the effect; */ 4602. { /* otherwise left with its previous value intact */ 4603. struct trap *t; 4604. char buf[BUFSZ], whichbuf[20]; 4605. const char *trapdescr = 0, *which = 0; 4606. boolean ishero = (mon == &youmonst); 4607. 4608. if (!mon) 4609. return FALSE; 4610. if (mon == u.usteed) 4611. ishero = TRUE; 4612. 4613. t = t_at(ishero ? u.ux : mon->mx, ishero ? u.uy : mon->my); 4614. 4615. if (ishero && u.utrap) { /* all u.utraptype values are holding traps */ 4616. which = the_your[(!t || !t->tseen || !t->madeby_u) ? 0 : 1]; 4617. switch (u.utraptype) { 4618. case TT_LAVA: 4619. trapdescr = "molten lava"; 4620. break; 4621. case TT_INFLOOR: 4622. /* solidified lava, so not "floor" even if within a room */ 4623. trapdescr = "ground"; 4624. break; 4625. case TT_BURIEDBALL: 4626. trapdescr = "your anchor"; 4627. which = ""; 4628. break; 4629. case TT_BEARTRAP: 4630. case TT_PIT: 4631. case TT_WEB: 4632. trapdescr = 0; /* use defsyms[].explanation */ 4633. break; 4634. default: 4635. /* lint suppression in case 't' is unexpectedly Null 4636. or u.utraptype has new value we don't know about yet */ 4637. trapdescr = "trap"; 4638. break; 4639. } 4640. } else { 4641. /* if no trap here or it's not a holding trap, we're done */ 4642. if (!t || (t->ttyp != BEAR_TRAP && t->ttyp != WEB)) 4643. return FALSE; 4644. } 4645. 4646. if (!trapdescr) 4647. trapdescr = defsyms[trap_to_defsym(t->ttyp)].explanation; 4648. if (!which) 4649. which = t->tseen ? the_your[t->madeby_u] 4650. : index(vowels, *trapdescr) ? "an" : "a"; 4651. if (*which) 4652. which = strcat(strcpy(whichbuf, which), " "); 4653. 4654. if (ishero) { 4655. if (!u.utrap) 4656. return FALSE; 4657. *noticed = TRUE; 4658. if (u.usteed) 4659. Sprintf(buf, "%s is", noit_Monnam(u.usteed)); 4660. else 4661. Strcpy(buf, "You are"); 4662. reset_utrap(TRUE); 4663. vision_full_recalc = 1; /* vision limits can change (pit escape) */ 4664. pline("%s released from %s%s.", buf, which, trapdescr); 4665. } else { 4666. if (!mon->mtrapped) 4667. return FALSE; 4668. mon->mtrapped = 0; 4669. if (canspotmon(mon)) { 4670. *noticed = TRUE; 4671. pline("%s is released from %s%s.", Monnam(mon), which, 4672. trapdescr); 4673. } else if (cansee(t->tx, t->ty) && t->tseen) { 4674. *noticed = TRUE; 4675. if (t->ttyp == WEB) 4676. pline("%s is released from %s%s.", Something, which, 4677. trapdescr); 4678. else /* BEAR_TRAP */ 4679. pline("%s%s opens.", upstart(strcpy(buf, which)), trapdescr); 4680. } 4681. /* might pacify monster if adjacent */ 4682. if (rn2(2) && distu(mon->mx, mon->my) <= 2) 4683. reward_untrap(t, mon); 4684. } 4685. return TRUE; 4686. } 4687. 4688. /* for magic locking; returns true if targetted monster (which might 4689. be hero) gets hit by a trap (might avoid actually becoming trapped) */ 4690. boolean 4691. closeholdingtrap(mon, noticed) 4692. struct monst *mon; 4693. boolean *noticed; /* set to true iff hero notices the effect; */ 4694. { /* otherwise left with its previous value intact */ 4695. struct trap *t; 4696. unsigned dotrapflags; 4697. boolean ishero = (mon == &youmonst), result; 4698. 4699. if (!mon) 4700. return FALSE; 4701. if (mon == u.usteed) 4702. ishero = TRUE; 4703. t = t_at(ishero ? u.ux : mon->mx, ishero ? u.uy : mon->my); 4704. /* if no trap here or it's not a holding trap, we're done */ 4705. if (!t || (t->ttyp != BEAR_TRAP && t->ttyp != WEB)) 4706. return FALSE; 4707. 4708. if (ishero) { 4709. if (u.utrap) 4710. return FALSE; /* already trapped */ 4711. *noticed = TRUE; 4712. dotrapflags = FORCETRAP; 4713. /* dotrap calls mintrap when mounted hero encounters a web */ 4714. if (u.usteed) 4715. dotrapflags |= NOWEBMSG; 4716. ++force_mintrap; 4717. dotrap(t, dotrapflags); 4718. --force_mintrap; 4719. result = (u.utrap != 0); 4720. } else { 4721. if (mon->mtrapped) 4722. return FALSE; /* already trapped */ 4723. /* you notice it if you see the trap close/tremble/whatever 4724. or if you sense the monster who becomes trapped */ 4725. *noticed = cansee(t->tx, t->ty) || canspotmon(mon); 4726. ++force_mintrap; 4727. result = (mintrap(mon) != 0); 4728. --force_mintrap; 4729. } 4730. return result; 4731. } 4732. 4733. /* for magic unlocking; returns true if targetted monster (which might 4734. be hero) gets hit by a trap (target might avoid its effect) */ 4735. boolean 4736. openfallingtrap(mon, trapdoor_only, noticed) 4737. struct monst *mon; 4738. boolean trapdoor_only; 4739. boolean *noticed; /* set to true iff hero notices the effect; */ 4740. { /* otherwise left with its previous value intact */ 4741. struct trap *t; 4742. boolean ishero = (mon == &youmonst), result; 4743. 4744. if (!mon) 4745. return FALSE; 4746. if (mon == u.usteed) 4747. ishero = TRUE; 4748. t = t_at(ishero ? u.ux : mon->mx, ishero ? u.uy : mon->my); 4749. /* if no trap here or it's not a falling trap, we're done 4750. (note: falling rock traps have a trapdoor in the ceiling) */ 4751. if (!t || ((t->ttyp != TRAPDOOR && t->ttyp != ROCKTRAP) 4752. && (trapdoor_only || (t->ttyp != HOLE && !is_pit(t->ttyp))))) 4753. return FALSE; 4754. 4755. if (ishero) { 4756. if (u.utrap) 4757. return FALSE; /* already trapped */ 4758. *noticed = TRUE; 4759. dotrap(t, FORCETRAP); 4760. result = (u.utrap != 0); 4761. } else { 4762. if (mon->mtrapped) 4763. return FALSE; /* already trapped */ 4764. /* you notice it if you see the trap close/tremble/whatever 4765. or if you sense the monster who becomes trapped */ 4766. *noticed = cansee(t->tx, t->ty) || canspotmon(mon); 4767. /* monster will be angered; mintrap doesn't handle that */ 4768. wakeup(mon, TRUE); 4769. ++force_mintrap; 4770. result = (mintrap(mon) != 0); 4771. --force_mintrap; 4772. /* mon might now be on the migrating monsters list */ 4773. } 4774. return result; 4775. } 4776. 4777. /* only called when the player is doing something to the chest directly */ 4778. boolean 4779. chest_trap(obj, bodypart, disarm) 4780. register struct obj *obj; 4781. register int bodypart; 4782. boolean disarm; 4783. { 4784. register struct obj *otmp = obj, *otmp2; 4785. char buf[80]; 4786. const char *msg; 4787. coord cc; 4788. 4789. if (get_obj_location(obj, &cc.x, &cc.y, 0)) /* might be carried */ 4790. obj->ox = cc.x, obj->oy = cc.y; 4791. 4792. otmp->otrapped = 0; /* trap is one-shot; clear flag first in case 4793. chest kills you and ends up in bones file */ 4794. You(disarm ? "set it off!" : "trigger a trap!"); 4795. display_nhwindow(WIN_MESSAGE, FALSE); 4796. if (Luck > -13 && rn2(13 + Luck) > 7) { /* saved by luck */ 4797. /* trap went off, but good luck prevents damage */ 4798. switch (rn2(13)) { 4799. case 12: 4800. case 11: 4801. msg = "explosive charge is a dud"; 4802. break; 4803. case 10: 4804. case 9: 4805. msg = "electric charge is grounded"; 4806. break; 4807. case 8: 4808. case 7: 4809. msg = "flame fizzles out"; 4810. break; 4811. case 6: 4812. case 5: 4813. case 4: 4814. msg = "poisoned needle misses"; 4815. break; 4816. case 3: 4817. case 2: 4818. case 1: 4819. case 0: 4820. msg = "gas cloud blows away"; 4821. break; 4822. default: 4823. impossible("chest disarm bug"); 4824. msg = (char *) 0; 4825. break; 4826. } 4827. if (msg) 4828. pline("But luckily the %s!", msg); 4829. } else { 4830. switch (rn2(20) ? ((Luck >= 13) ? 0 : rn2(13 - Luck)) : rn2(26)) { 4831. case 25: 4832. case 24: 4833. case 23: 4834. case 22: 4835. case 21: { 4836. struct monst *shkp = 0; 4837. long loss = 0L; 4838. boolean costly, insider; 4839. register xchar ox = obj->ox, oy = obj->oy; 4840. 4841. /* the obj location need not be that of player */ 4842. costly = (costly_spot(ox, oy) 4843. && (shkp = shop_keeper(*in_rooms(ox, oy, SHOPBASE))) 4844. != (struct monst *) 0); 4845. insider = (*u.ushops && inside_shop(u.ux, u.uy) 4846. && *in_rooms(ox, oy, SHOPBASE) == *u.ushops); 4847. 4848. pline("%s!", Tobjnam(obj, "explode")); 4849. Sprintf(buf, "exploding %s", xname(obj)); 4850. 4851. if (costly) 4852. loss += stolen_value(obj, ox, oy, (boolean) shkp->mpeaceful, 4853. TRUE); 4854. delete_contents(obj); 4855. /* unpunish() in advance if either ball or chain (or both) 4856. is going to be destroyed */ 4857. if (Punished && ((uchain->ox == u.ux && uchain->oy == u.uy) 4858. || (uball->where == OBJ_FLOOR 4859. && uball->ox == u.ux && uball->oy == u.uy))) 4860. unpunish(); 4861. 4862. for (otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp2) { 4863. otmp2 = otmp->nexthere; 4864. if (costly) 4865. loss += stolen_value(otmp, otmp->ox, otmp->oy, 4866. (boolean) shkp->mpeaceful, TRUE); 4867. delobj(otmp); 4868. } 4869. wake_nearby(); 4870. losehp(Maybe_Half_Phys(d(6, 6)), buf, KILLED_BY_AN); 4871. exercise(A_STR, FALSE); 4872. if (costly && loss) { 4873. if (insider) 4874. You("owe %ld %s for objects destroyed.", loss, 4875. currency(loss)); 4876. else { 4877. You("caused %ld %s worth of damage!", loss, 4878. currency(loss)); 4879. make_angry_shk(shkp, ox, oy); 4880. } 4881. } 4882. return TRUE; 4883. } /* case 21 */ 4884. case 20: 4885. case 19: 4886. case 18: 4887. case 17: 4888. pline("A cloud of noxious gas billows from %s.", the(xname(obj))); 4889. poisoned("gas cloud", A_STR, "cloud of poison gas", 15, FALSE); 4890. exercise(A_CON, FALSE); 4891. break; 4892. case 16: 4893. case 15: 4894. case 14: 4895. case 13: 4896. You_feel("a needle prick your %s.", body_part(bodypart)); 4897. poisoned("needle", A_CON, "poisoned needle", 10, FALSE); 4898. exercise(A_CON, FALSE); 4899. break; 4900. case 12: 4901. case 11: 4902. case 10: 4903. case 9: 4904. dofiretrap(obj); 4905. break; 4906. case 8: 4907. case 7: 4908. case 6: { 4909. int dmg; 4910. 4911. You("are jolted by a surge of electricity!"); 4912. if (Shock_resistance) { 4913. shieldeff(u.ux, u.uy); 4914. You("don't seem to be affected."); 4915. dmg = 0; 4916. } else 4917. dmg = d(4, 4); 4918. destroy_item(RING_CLASS, AD_ELEC); 4919. destroy_item(WAND_CLASS, AD_ELEC); 4920. if (dmg) 4921. losehp(dmg, "electric shock", KILLED_BY_AN); 4922. break; 4923. } /* case 6 */ 4924. case 5: 4925. case 4: 4926. case 3: 4927. if (!Free_action) { 4928. pline("Suddenly you are frozen in place!"); 4929. nomul(-d(5, 6)); 4930. multi_reason = "frozen by a trap"; 4931. exercise(A_DEX, FALSE); 4932. nomovemsg = You_can_move_again; 4933. } else 4934. You("momentarily stiffen."); 4935. break; 4936. case 2: 4937. case 1: 4938. case 0: 4939. pline("A cloud of %s gas billows from %s.", 4940. Blind ? blindgas[rn2(SIZE(blindgas))] : rndcolor(), 4941. the(xname(obj))); 4942. if (!Stunned) { 4943. if (Hallucination) 4944. pline("What a groovy feeling!"); 4945. else 4946. You("%s%s...", stagger(youmonst.data, "stagger"), 4947. Halluc_resistance ? "" 4948. : Blind ? " and get dizzy" 4949. : " and your vision blurs"); 4950. } 4951. make_stunned((HStun & TIMEOUT) + (long) rn1(7, 16), FALSE); 4952. (void) make_hallucinated( 4953. (HHallucination & TIMEOUT) + (long) rn1(5, 16), FALSE, 0L); 4954. break; 4955. default: 4956. impossible("bad chest trap"); 4957. break; 4958. } 4959. bot(); /* to get immediate botl re-display */ 4960. } 4961. 4962. return FALSE; 4963. } 4964. 4965. struct trap * 4966. t_at(x, y) 4967. register int x, y; 4968. { 4969. register struct trap *trap = ftrap; 4970. 4971. while (trap) { 4972. if (trap->tx == x && trap->ty == y) 4973. return trap; 4974. trap = trap->ntrap; 4975. } 4976. return (struct trap *) 0; 4977. } 4978. 4979. void 4980. deltrap(trap) 4981. register struct trap *trap; 4982. { 4983. register struct trap *ttmp; 4984. 4985. clear_conjoined_pits(trap); 4986. if (trap == ftrap) { 4987. ftrap = ftrap->ntrap; 4988. } else { 4989. for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) 4990. if (ttmp->ntrap == trap) 4991. break; 4992. if (!ttmp) 4993. panic("deltrap: no preceding trap!"); 4994. ttmp->ntrap = trap->ntrap; 4995. } 4996. if (Sokoban && (trap->ttyp == PIT || trap->ttyp == HOLE)) 4997. maybe_finish_sokoban(); 4998. dealloc_trap(trap); 4999. } 5000. 5001. boolean 5002. conjoined_pits(trap2, trap1, u_entering_trap2) 5003. struct trap *trap2, *trap1; 5004. boolean u_entering_trap2; 5005. { 5006. int dx, dy, diridx, adjidx; 5007. 5008. if (!trap1 || !trap2) 5009. return FALSE; 5010. if (!isok(trap2->tx, trap2->ty) || !isok(trap1->tx, trap1->ty) 5011. || !is_pit(trap2->ttyp) 5012. || !is_pit(trap1->ttyp) 5013. || (u_entering_trap2 && !(u.utrap && u.utraptype == TT_PIT))) 5014. return FALSE; 5015. dx = sgn(trap2->tx - trap1->tx); 5016. dy = sgn(trap2->ty - trap1->ty); 5017. for (diridx = 0; diridx < 8; diridx++) 5018. if (xdir[diridx] == dx && ydir[diridx] == dy) 5019. break; 5020. /* diridx is valid if < 8 */ 5021. if (diridx < 8) { 5022. adjidx = (diridx + 4) % 8; 5023. if ((trap1->conjoined & (1 << diridx)) 5024. && (trap2->conjoined & (1 << adjidx))) 5025. return TRUE; 5026. } 5027. return FALSE; 5028. } 5029. 5030. STATIC_OVL void 5031. clear_conjoined_pits(trap) 5032. struct trap *trap; 5033. { 5034. int diridx, adjidx, x, y; 5035. struct trap *t; 5036. 5037. if (trap && is_pit(trap->ttyp)) { 5038. for (diridx = 0; diridx < 8; ++diridx) { 5039. if (trap->conjoined & (1 << diridx)) { 5040. x = trap->tx + xdir[diridx]; 5041. y = trap->ty + ydir[diridx]; 5042. if (isok(x, y) 5043. && (t = t_at(x, y)) != 0 5044. && is_pit(t->ttyp)) { 5045. adjidx = (diridx + 4) % 8; 5046. t->conjoined &= ~(1 << adjidx); 5047. } 5048. trap->conjoined &= ~(1 << diridx); 5049. } 5050. } 5051. } 5052. } 5053. 5054. STATIC_OVL boolean 5055. adj_nonconjoined_pit(adjtrap) 5056. struct trap *adjtrap; 5057. { 5058. struct trap *trap_with_u = t_at(u.ux0, u.uy0); 5059. 5060. if (trap_with_u && adjtrap && u.utrap && u.utraptype == TT_PIT 5061. && is_pit(trap_with_u->ttyp) && is_pit(adjtrap->ttyp)) { 5062. int idx; 5063. 5064. for (idx = 0; idx < 8; idx++) { 5065. if (xdir[idx] == u.dx && ydir[idx] == u.dy) 5066. return TRUE; 5067. } 5068. } 5069. return FALSE; 5070. } 5071. 5072. #if 0 5073. /* 5074. * Mark all neighboring pits as conjoined pits. 5075. * (currently not called from anywhere) 5076. */ 5077. STATIC_OVL void 5078. join_adjacent_pits(trap) 5079. struct trap *trap; 5080. { 5081. struct trap *t; 5082. int diridx, x, y; 5083. 5084. if (!trap) 5085. return; 5086. for (diridx = 0; diridx < 8; ++diridx) { 5087. x = trap->tx + xdir[diridx]; 5088. y = trap->ty + ydir[diridx]; 5089. if (isok(x, y)) { 5090. if ((t = t_at(x, y)) != 0 && is_pit(t->ttyp)) { 5091. trap->conjoined |= (1 << diridx); 5092. join_adjacent_pits(t); 5093. } else 5094. trap->conjoined &= ~(1 << diridx); 5095. } 5096. } 5097. } 5098. #endif /*0*/ 5099. 5100. /* 5101. * Returns TRUE if you escaped a pit and are standing on the precipice. 5102. */ 5103. boolean 5104. uteetering_at_seen_pit(trap) 5105. struct trap *trap; 5106. { 5107. return (trap && is_pit(trap->ttyp) && trap->tseen 5108. && trap->tx == u.ux && trap->ty == u.uy 5109. && !(u.utrap && u.utraptype == TT_PIT)); 5110. } 5111. 5112. /* 5113. * Returns TRUE if you didn't fall through a hole or didn't 5114. * release a trap door 5115. */ 5116. boolean 5117. uescaped_shaft(trap) 5118. struct trap *trap; 5119. { 5120. return (trap && is_hole(trap->ttyp) && trap->tseen 5121. && trap->tx == u.ux && trap->ty == u.uy); 5122. } 5123. 5124. /* Destroy a trap that emanates from the floor. */ 5125. boolean 5126. delfloortrap(ttmp) 5127. register struct trap *ttmp; 5128. { 5129. /* some of these are arbitrary -dlc */ 5130. if (ttmp && ((ttmp->ttyp == SQKY_BOARD) || (ttmp->ttyp == BEAR_TRAP) 5131. || (ttmp->ttyp == LANDMINE) || (ttmp->ttyp == FIRE_TRAP) 5132. || is_pit(ttmp->ttyp) 5133. || is_hole(ttmp->ttyp) 5134. || (ttmp->ttyp == TELEP_TRAP) || (ttmp->ttyp == LEVEL_TELEP) 5135. || (ttmp->ttyp == WEB) || (ttmp->ttyp == MAGIC_TRAP) 5136. || (ttmp->ttyp == ANTI_MAGIC))) { 5137. register struct monst *mtmp; 5138. 5139. if (ttmp->tx == u.ux && ttmp->ty == u.uy) { 5140. if (u.utraptype != TT_BURIEDBALL) 5141. reset_utrap(TRUE); 5142. } else if ((mtmp = m_at(ttmp->tx, ttmp->ty)) != 0) { 5143. mtmp->mtrapped = 0; 5144. } 5145. deltrap(ttmp); 5146. return TRUE; 5147. } 5148. return FALSE; 5149. } 5150. 5151. /* used for doors (also tins). can be used for anything else that opens. */ 5152. void 5153. b_trapped(item, bodypart) 5154. const char *item; 5155. int bodypart; 5156. { 5157. int lvl = level_difficulty(), 5158. dmg = rnd(5 + (lvl < 5 ? lvl : 2 + lvl / 2)); 5159. 5160. pline("KABOOM!! %s was booby-trapped!", The(item)); 5161. wake_nearby(); 5162. losehp(Maybe_Half_Phys(dmg), "explosion", KILLED_BY_AN); 5163. exercise(A_STR, FALSE); 5164. if (bodypart) 5165. exercise(A_CON, FALSE); 5166. make_stunned((HStun & TIMEOUT) + (long) dmg, TRUE); 5167. } 5168. 5169. /* Monster is hit by trap. */ 5170. /* Note: doesn't work if both obj and d_override are null */ 5171. STATIC_OVL boolean 5172. thitm(tlev, mon, obj, d_override, nocorpse) 5173. int tlev; 5174. struct monst *mon; 5175. struct obj *obj; 5176. int d_override; 5177. boolean nocorpse; 5178. { 5179. int strike; 5180. boolean trapkilled = FALSE; 5181. 5182. if (d_override) 5183. strike = 1; 5184. else if (obj) 5185. strike = (find_mac(mon) + tlev + obj->spe <= rnd(20)); 5186. else 5187. strike = (find_mac(mon) + tlev <= rnd(20)); 5188. 5189. /* Actually more accurate than thitu, which doesn't take 5190. * obj->spe into account. 5191. */ 5192. if (!strike) { 5193. if (obj && cansee(mon->mx, mon->my)) 5194. pline("%s is almost hit by %s!", Monnam(mon), doname(obj)); 5195. } else { 5196. int dam = 1; 5197. 5198. if (obj && cansee(mon->mx, mon->my)) 5199. pline("%s is hit by %s!", Monnam(mon), doname(obj)); 5200. if (d_override) 5201. dam = d_override; 5202. else if (obj) { 5203. dam = dmgval(obj, mon); 5204. if (dam < 1) 5205. dam = 1; 5206. } 5207. mon->mhp -= dam; 5208. if (DEADMONSTER(mon)) { 5209. int xx = mon->mx, yy = mon->my; 5210. 5211. monkilled(mon, "", nocorpse ? -AD_RBRE : AD_PHYS); 5212. if (DEADMONSTER(mon)) { 5213. newsym(xx, yy); 5214. trapkilled = TRUE; 5215. } 5216. } 5217. } 5218. if (obj && (!strike || d_override)) { 5219. place_object(obj, mon->mx, mon->my); 5220. stackobj(obj); 5221. } else if (obj) 5222. dealloc_obj(obj); 5223. 5224. return trapkilled; 5225. } 5226. 5227. boolean 5228. unconscious() 5229. { 5230. if (multi >= 0) 5231. return FALSE; 5232. 5233. return (boolean) (u.usleep 5234. || (nomovemsg 5235. && (!strncmp(nomovemsg, "You awake", 9) 5236. || !strncmp(nomovemsg, "You regain con", 14) 5237. || !strncmp(nomovemsg, "You are consci", 14)))); 5238. } 5239. 5240. static const char lava_killer[] = "molten lava"; 5241. 5242. boolean 5243. lava_effects() 5244. { 5245. register struct obj *obj, *obj2; 5246. int dmg = d(6, 6); /* only applicable for water walking */ 5247. boolean usurvive, boil_away; 5248. 5249. burn_away_slime(); 5250. if (likes_lava(youmonst.data)) 5251. return FALSE; 5252. 5253. usurvive = Fire_resistance || (Wwalking && dmg < u.uhp); 5254. /* 5255. * A timely interrupt might manage to salvage your life 5256. * but not your gear. For scrolls and potions this 5257. * will destroy whole stacks, where fire resistant hero 5258. * survivor only loses partial stacks via destroy_item(). 5259. * 5260. * Flag items to be destroyed before any messages so 5261. * that player causing hangup at --More-- won't get an 5262. * emergency save file created before item destruction. 5263. */ 5264. if (!usurvive) 5265. for (obj = invent; obj; obj = obj->nobj) 5266. if ((is_organic(obj) || obj->oclass == POTION_CLASS) 5267. && !obj->oerodeproof 5268. && objects[obj->otyp].oc_oprop != FIRE_RES 5269. && obj->otyp != SCR_FIRE && obj->otyp != SPE_FIREBALL 5270. && !obj_resists(obj, 0, 0)) /* for invocation items */ 5271. obj->in_use = 1; 5272. 5273. /* Check whether we should burn away boots *first* so we know whether to 5274. * make the player sink into the lava. Assumption: water walking only 5275. * comes from boots. 5276. */ 5277. if (uarmf && is_organic(uarmf) && !uarmf->oerodeproof) { 5278. obj = uarmf; 5279. pline("%s into flame!", Yobjnam2(obj, "burst")); 5280. iflags.in_lava_effects++; /* (see above) */ 5281. (void) Boots_off(); 5282. useup(obj); 5283. iflags.in_lava_effects--; 5284. } 5285. 5286. if (!Fire_resistance) { 5287. if (Wwalking) { 5288. pline_The("%s here burns you!", hliquid("lava")); 5289. if (usurvive) { 5290. losehp(dmg, lava_killer, KILLED_BY); /* lava damage */ 5291. goto burn_stuff; 5292. } 5293. } else 5294. You("fall into the %s!", hliquid("lava")); 5295. 5296. usurvive = Lifesaved || discover; 5297. if (wizard) 5298. usurvive = TRUE; 5299. 5300. /* prevent remove_worn_item() -> Boots_off(WATER_WALKING_BOOTS) -> 5301. spoteffects() -> lava_effects() recursion which would 5302. successfully delete (via useupall) the no-longer-worn boots; 5303. once recursive call returned, we would try to delete them again 5304. here in the outer call (and access stale memory, probably panic) */ 5305. iflags.in_lava_effects++; 5306. 5307. for (obj = invent; obj; obj = obj2) { 5308. obj2 = obj->nobj; 5309. /* above, we set in_use for objects which are to be destroyed */ 5310. if (obj->otyp == SPE_BOOK_OF_THE_DEAD && !Blind) { 5311. if (usurvive) 5312. pline("%s glows a strange %s, but remains intact.", 5313. The(xname(obj)), hcolor("dark red")); 5314. } else if (obj->in_use) { 5315. if (obj->owornmask) { 5316. if (usurvive) 5317. pline("%s into flame!", Yobjnam2(obj, "burst")); 5318. remove_worn_item(obj, TRUE); 5319. } 5320. useupall(obj); 5321. } 5322. } 5323. 5324. iflags.in_lava_effects--; 5325. 5326. /* s/he died... */ 5327. boil_away = (u.umonnum == PM_WATER_ELEMENTAL 5328. || u.umonnum == PM_STEAM_VORTEX 5329. || u.umonnum == PM_FOG_CLOUD); 5330. for (;;) { 5331. u.uhp = -1; 5332. /* killer format and name are reconstructed every iteration 5333. because lifesaving resets them */ 5334. killer.format = KILLED_BY; 5335. Strcpy(killer.name, lava_killer); 5336. You("%s...", boil_away ? "boil away" : "burn to a crisp"); 5337. done(BURNING); 5338. if (safe_teleds(TRUE)) 5339. break; /* successful life-save */ 5340. /* nowhere safe to land; repeat burning loop */ 5341. pline("You're still burning."); 5342. } 5343. You("find yourself back on solid %s.", surface(u.ux, u.uy)); 5344. return TRUE; 5345. } else if (!Wwalking && (!u.utrap || u.utraptype != TT_LAVA)) { 5346. boil_away = !Fire_resistance; 5347. /* if not fire resistant, sink_into_lava() will quickly be fatal; 5348. hero needs to escape immediately */ 5349. set_utrap((unsigned) (rn1(4, 4) + ((boil_away ? 2 : rn1(4, 12)) << 8)), 5350. TT_LAVA); 5351. You("sink into the %s%s!", hliquid("lava"), 5352. !boil_away ? ", but it only burns slightly" 5353. : " and are about to be immolated"); 5354. if (u.uhp > 1) 5355. losehp(!boil_away ? 1 : (u.uhp / 2), lava_killer, 5356. KILLED_BY); /* lava damage */ 5357. } 5358. 5359. burn_stuff: 5360. destroy_item(SCROLL_CLASS, AD_FIRE); 5361. destroy_item(SPBOOK_CLASS, AD_FIRE); 5362. destroy_item(POTION_CLASS, AD_FIRE); 5363. return FALSE; 5364. } 5365. 5366. /* called each turn when trapped in lava */ 5367. void 5368. sink_into_lava() 5369. { 5370. static const char sink_deeper[] = "You sink deeper into the lava."; 5371. 5372. if (!u.utrap || u.utraptype != TT_LAVA) { 5373. ; /* do nothing; this shouldn't happen */ 5374. } else if (!is_lava(u.ux, u.uy)) { 5375. reset_utrap(FALSE); /* this shouldn't happen either */ 5376. } else if (!u.uinvulnerable) { 5377. /* ordinarily we'd have to be fire resistant to survive long 5378. enough to become stuck in lava, but it can happen without 5379. resistance if water walking boots allow survival and then 5380. get burned up; u.utrap time will be quite short in that case */ 5381. if (!Fire_resistance) 5382. u.uhp = (u.uhp + 2) / 3; 5383. 5384. u.utrap -= (1 << 8); 5385. if (u.utrap < (1 << 8)) { 5386. killer.format = KILLED_BY; 5387. Strcpy(killer.name, "molten lava"); 5388. You("sink below the surface and die."); 5389. burn_away_slime(); /* add insult to injury? */ 5390. done(DISSOLVED); 5391. /* can only get here via life-saving; try to get away from lava */ 5392. reset_utrap(TRUE); 5393. /* levitation or flight have become unblocked, otherwise Tport */ 5394. if (!Levitation && !Flying) 5395. (void) safe_teleds(TRUE); 5396. } else if (!u.umoved) { 5397. /* can't fully turn into slime while in lava, but might not 5398. have it be burned away until you've come awfully close */ 5399. if (Slimed && rnd(10 - 1) >= (int) (Slimed & TIMEOUT)) { 5400. pline(sink_deeper); 5401. burn_away_slime(); 5402. } else { 5403. Norep(sink_deeper); 5404. } 5405. u.utrap += rnd(4); 5406. } 5407. } 5408. } 5409. 5410. /* called when something has been done (breaking a boulder, for instance) 5411. which entails a luck penalty if performed on a sokoban level */ 5412. void 5413. sokoban_guilt() 5414. { 5415. if (Sokoban) { 5416. change_luck(-1); 5417. /* TODO: issue some feedback so that player can learn that whatever 5418. he/she just did is a naughty thing to do in sokoban and should 5419. probably be avoided in future.... 5420. Caveat: doing this might introduce message sequencing issues, 5421. depending upon feedback during the various actions which trigger 5422. Sokoban luck penalties. */ 5423. } 5424. } 5425. 5426. /* called when a trap has been deleted or had its ttyp replaced */ 5427. STATIC_OVL void 5428. maybe_finish_sokoban() 5429. { 5430. struct trap *t; 5431. 5432. if (Sokoban && !in_mklev) { 5433. /* scan all remaining traps, ignoring any created by the hero; 5434. if this level has no more pits or holes, the current sokoban 5435. puzzle has been solved */ 5436. for (t = ftrap; t; t = t->ntrap) { 5437. if (t->madeby_u) 5438. continue; 5439. if (t->ttyp == PIT || t->ttyp == HOLE) 5440. break; 5441. } 5442. if (!t) { 5443. /* we've passed the last trap without finding a pit or hole; 5444. clear the sokoban_rules flag so that luck penalties for 5445. things like breaking boulders or jumping will no longer 5446. be given, and restrictions on diagonal moves are lifted */ 5447. Sokoban = 0; /* clear level.flags.sokoban_rules */ 5448. /* TODO: give some feedback about solving the sokoban puzzle 5449. (perhaps say "congratulations" in Japanese?) */ 5450. } 5451. } 5452. } 5453. 5454. /*trap.c*/