Source:NetHack 3.6.4/src/dig.c
Jump to navigation
Jump to search
Below is the full text to dig.c from the source code of NetHack 3.6.4. To link to a particular line, write [[Source:NetHack 3.6.4/src/dig.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 dig.c $NHDT-Date: 1547421446 2019/01/13 23:17:26 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.117 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Michael Allison, 2012. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #include "hack.h" 7. 8. static NEARDATA boolean did_dig_msg; 9. 10. STATIC_DCL boolean NDECL(rm_waslit); 11. STATIC_DCL void FDECL(mkcavepos, 12. (XCHAR_P, XCHAR_P, int, BOOLEAN_P, BOOLEAN_P)); 13. STATIC_DCL void FDECL(mkcavearea, (BOOLEAN_P)); 14. STATIC_DCL int NDECL(dig); 15. STATIC_DCL void FDECL(dig_up_grave, (coord *)); 16. STATIC_DCL int FDECL(adj_pit_checks, (coord *, char *)); 17. STATIC_DCL void FDECL(pit_flow, (struct trap *, SCHAR_P)); 18. 19. /* Indices returned by dig_typ() */ 20. enum dig_types { 21. DIGTYP_UNDIGGABLE = 0, 22. DIGTYP_ROCK, 23. DIGTYP_STATUE, 24. DIGTYP_BOULDER, 25. DIGTYP_DOOR, 26. DIGTYP_TREE 27. }; 28. 29. STATIC_OVL boolean 30. rm_waslit() 31. { 32. register xchar x, y; 33. 34. if (levl[u.ux][u.uy].typ == ROOM && levl[u.ux][u.uy].waslit) 35. return TRUE; 36. for (x = u.ux - 2; x < u.ux + 3; x++) 37. for (y = u.uy - 1; y < u.uy + 2; y++) 38. if (isok(x, y) && levl[x][y].waslit) 39. return TRUE; 40. return FALSE; 41. } 42. 43. /* Change level topology. Messes with vision tables and ignores things like 44. * boulders in the name of a nice effect. Vision will get fixed up again 45. * immediately after the effect is complete. 46. */ 47. STATIC_OVL void 48. mkcavepos(x, y, dist, waslit, rockit) 49. xchar x, y; 50. int dist; 51. boolean waslit, rockit; 52. { 53. register struct rm *lev; 54. 55. if (!isok(x, y)) 56. return; 57. lev = &levl[x][y]; 58. 59. if (rockit) { 60. register struct monst *mtmp; 61. 62. if (IS_ROCK(lev->typ)) 63. return; 64. if (t_at(x, y)) 65. return; /* don't cover the portal */ 66. if ((mtmp = m_at(x, y)) != 0) /* make sure crucial monsters survive */ 67. if (!passes_walls(mtmp->data)) 68. (void) rloc(mtmp, TRUE); 69. } else if (lev->typ == ROOM) 70. return; 71. 72. unblock_point(x, y); /* make sure vision knows this location is open */ 73. 74. /* fake out saved state */ 75. lev->seenv = 0; 76. lev->doormask = 0; 77. if (dist < 3) 78. lev->lit = (rockit ? FALSE : TRUE); 79. if (waslit) 80. lev->waslit = (rockit ? FALSE : TRUE); 81. lev->horizontal = FALSE; 82. /* short-circuit vision recalc */ 83. viz_array[y][x] = (dist < 3) ? (IN_SIGHT | COULD_SEE) : COULD_SEE; 84. lev->typ = (rockit ? STONE : ROOM); /* flags set via doormask above */ 85. if (dist >= 3) 86. impossible("mkcavepos called with dist %d", dist); 87. feel_newsym(x, y); 88. } 89. 90. STATIC_OVL void 91. mkcavearea(rockit) 92. register boolean rockit; 93. { 94. int dist; 95. xchar xmin = u.ux, xmax = u.ux; 96. xchar ymin = u.uy, ymax = u.uy; 97. register xchar i; 98. register boolean waslit = rm_waslit(); 99. 100. if (rockit) 101. pline("Crash! The ceiling collapses around you!"); 102. else 103. pline("A mysterious force %s cave around you!", 104. (levl[u.ux][u.uy].typ == CORR) ? "creates a" : "extends the"); 105. display_nhwindow(WIN_MESSAGE, TRUE); 106. 107. for (dist = 1; dist <= 2; dist++) { 108. xmin--; 109. xmax++; 110. 111. /* top and bottom */ 112. if (dist < 2) { /* the area is wider that it is high */ 113. ymin--; 114. ymax++; 115. for (i = xmin + 1; i < xmax; i++) { 116. mkcavepos(i, ymin, dist, waslit, rockit); 117. mkcavepos(i, ymax, dist, waslit, rockit); 118. } 119. } 120. 121. /* left and right */ 122. for (i = ymin; i <= ymax; i++) { 123. mkcavepos(xmin, i, dist, waslit, rockit); 124. mkcavepos(xmax, i, dist, waslit, rockit); 125. } 126. 127. flush_screen(1); /* make sure the new glyphs shows up */ 128. delay_output(); 129. } 130. 131. if (!rockit && levl[u.ux][u.uy].typ == CORR) { 132. levl[u.ux][u.uy].typ = ROOM; /* flags for CORR already 0 */ 133. if (waslit) 134. levl[u.ux][u.uy].waslit = TRUE; 135. newsym(u.ux, u.uy); /* in case player is invisible */ 136. } 137. 138. vision_full_recalc = 1; /* everything changed */ 139. } 140. 141. /* When digging into location <x,y>, what are you actually digging into? */ 142. int 143. dig_typ(otmp, x, y) 144. struct obj *otmp; 145. xchar x, y; 146. { 147. boolean ispick; 148. 149. if (!otmp) 150. return DIGTYP_UNDIGGABLE; 151. ispick = is_pick(otmp); 152. if (!ispick && !is_axe(otmp)) 153. return DIGTYP_UNDIGGABLE; 154. 155. return ((ispick && sobj_at(STATUE, x, y)) 156. ? DIGTYP_STATUE 157. : (ispick && sobj_at(BOULDER, x, y)) 158. ? DIGTYP_BOULDER 159. : closed_door(x, y) 160. ? DIGTYP_DOOR 161. : IS_TREE(levl[x][y].typ) 162. ? (ispick ? DIGTYP_UNDIGGABLE : DIGTYP_TREE) 163. : (ispick && IS_ROCK(levl[x][y].typ) 164. && (!level.flags.arboreal 165. || IS_WALL(levl[x][y].typ))) 166. ? DIGTYP_ROCK 167. : DIGTYP_UNDIGGABLE); 168. } 169. 170. boolean 171. is_digging() 172. { 173. if (occupation == dig) { 174. return TRUE; 175. } 176. return FALSE; 177. } 178. 179. #define BY_YOU (&youmonst) 180. #define BY_OBJECT ((struct monst *) 0) 181. 182. boolean 183. dig_check(madeby, verbose, x, y) 184. struct monst *madeby; 185. boolean verbose; 186. int x, y; 187. { 188. struct trap *ttmp = t_at(x, y); 189. const char *verb = 190. (madeby == BY_YOU && uwep && is_axe(uwep)) ? "chop" : "dig in"; 191. 192. if (On_stairs(x, y)) { 193. if (x == xdnladder || x == xupladder) { 194. if (verbose) 195. pline_The("ladder resists your effort."); 196. } else if (verbose) 197. pline_The("stairs are too hard to %s.", verb); 198. return FALSE; 199. } else if (IS_THRONE(levl[x][y].typ) && madeby != BY_OBJECT) { 200. if (verbose) 201. pline_The("throne is too hard to break apart."); 202. return FALSE; 203. } else if (IS_ALTAR(levl[x][y].typ) 204. && (madeby != BY_OBJECT || Is_astralevel(&u.uz) 205. || Is_sanctum(&u.uz))) { 206. if (verbose) 207. pline_The("altar is too hard to break apart."); 208. return FALSE; 209. } else if (Is_airlevel(&u.uz)) { 210. if (verbose) 211. You("cannot %s thin air.", verb); 212. return FALSE; 213. } else if (Is_waterlevel(&u.uz)) { 214. if (verbose) 215. pline_The("%s splashes and subsides.", hliquid("water")); 216. return FALSE; 217. } else if ((IS_ROCK(levl[x][y].typ) && levl[x][y].typ != SDOOR 218. && (levl[x][y].wall_info & W_NONDIGGABLE) != 0) 219. || (ttmp 220. && (ttmp->ttyp == MAGIC_PORTAL 221. || ttmp->ttyp == VIBRATING_SQUARE 222. || (!Can_dig_down(&u.uz) && !levl[x][y].candig)))) { 223. if (verbose) 224. pline_The("%s here is too hard to %s.", surface(x, y), verb); 225. return FALSE; 226. } else if (sobj_at(BOULDER, x, y)) { 227. if (verbose) 228. There("isn't enough room to %s here.", verb); 229. return FALSE; 230. } else if (madeby == BY_OBJECT 231. /* the block against existing traps is mainly to 232. prevent broken wands from turning holes into pits */ 233. && (ttmp || is_pool_or_lava(x, y))) { 234. /* digging by player handles pools separately */ 235. return FALSE; 236. } 237. return TRUE; 238. } 239. 240. STATIC_OVL int 241. dig(VOID_ARGS) 242. { 243. register struct rm *lev; 244. register xchar dpx = context.digging.pos.x, dpy = context.digging.pos.y; 245. register boolean ispick = uwep && is_pick(uwep); 246. const char *verb = (!uwep || is_pick(uwep)) ? "dig into" : "chop through"; 247. 248. lev = &levl[dpx][dpy]; 249. /* perhaps a nymph stole your pick-axe while you were busy digging */ 250. /* or perhaps you teleported away */ 251. if (u.uswallow || !uwep || (!ispick && !is_axe(uwep)) 252. || !on_level(&context.digging.level, &u.uz) 253. || ((context.digging.down ? (dpx != u.ux || dpy != u.uy) 254. : (distu(dpx, dpy) > 2)))) 255. return 0; 256. 257. if (context.digging.down) { 258. if (!dig_check(BY_YOU, TRUE, u.ux, u.uy)) 259. return 0; 260. } else { /* !context.digging.down */ 261. if (IS_TREE(lev->typ) && !may_dig(dpx, dpy) 262. && dig_typ(uwep, dpx, dpy) == DIGTYP_TREE) { 263. pline("This tree seems to be petrified."); 264. return 0; 265. } 266. if (IS_ROCK(lev->typ) && !may_dig(dpx, dpy) 267. && dig_typ(uwep, dpx, dpy) == DIGTYP_ROCK) { 268. pline("This %s is too hard to %s.", 269. is_db_wall(dpx, dpy) ? "drawbridge" : "wall", verb); 270. return 0; 271. } 272. } 273. if (Fumbling && !rn2(3)) { 274. switch (rn2(3)) { 275. case 0: 276. if (!welded(uwep)) { 277. You("fumble and drop %s.", yname(uwep)); 278. dropx(uwep); 279. } else { 280. if (u.usteed) 281. pline("%s and %s %s!", Yobjnam2(uwep, "bounce"), 282. otense(uwep, "hit"), mon_nam(u.usteed)); 283. else 284. pline("Ouch! %s and %s you!", Yobjnam2(uwep, "bounce"), 285. otense(uwep, "hit")); 286. set_wounded_legs(RIGHT_SIDE, 5 + rnd(5)); 287. } 288. break; 289. case 1: 290. pline("Bang! You hit with the broad side of %s!", 291. the(xname(uwep))); 292. break; 293. default: 294. Your("swing misses its mark."); 295. break; 296. } 297. return 0; 298. } 299. 300. context.digging.effort += 301. 10 + rn2(5) + abon() + uwep->spe - greatest_erosion(uwep) + u.udaminc; 302. if (Race_if(PM_DWARF)) 303. context.digging.effort *= 2; 304. if (context.digging.down) { 305. struct trap *ttmp = t_at(dpx, dpy); 306. 307. if (context.digging.effort > 250 || (ttmp && ttmp->ttyp == HOLE)) { 308. (void) dighole(FALSE, FALSE, (coord *) 0); 309. (void) memset((genericptr_t) &context.digging, 0, 310. sizeof context.digging); 311. return 0; /* done with digging */ 312. } 313. 314. if (context.digging.effort <= 50 315. || (ttmp && (ttmp->ttyp == TRAPDOOR || is_pit(ttmp->ttyp)))) { 316. return 1; 317. } else if (ttmp && (ttmp->ttyp == LANDMINE 318. || (ttmp->ttyp == BEAR_TRAP && !u.utrap))) { 319. /* digging onto a set object trap triggers it; 320. hero should have used #untrap first */ 321. dotrap(ttmp, FORCETRAP); 322. /* restart completely from scratch if we resume digging */ 323. (void) memset((genericptr_t) &context.digging, 0, 324. sizeof context.digging); 325. return 0; 326. } else if (ttmp && ttmp->ttyp == BEAR_TRAP && u.utrap) { 327. if (rnl(7) > (Fumbling ? 1 : 4)) { 328. char kbuf[BUFSZ]; 329. int dmg = dmgval(uwep, &youmonst) + dbon(); 330. 331. if (dmg < 1) 332. dmg = 1; 333. else if (uarmf) 334. dmg = (dmg + 1) / 2; 335. You("hit yourself in the %s.", body_part(FOOT)); 336. Sprintf(kbuf, "chopping off %s own %s", uhis(), 337. body_part(FOOT)); 338. losehp(Maybe_Half_Phys(dmg), kbuf, KILLED_BY); 339. } else { 340. You("destroy the bear trap with %s.", 341. yobjnam(uwep, (const char *) 0)); 342. deltrap(ttmp); 343. reset_utrap(TRUE); /* release from trap, maybe Lev or Fly */ 344. } 345. /* we haven't made any progress toward a pit yet */ 346. context.digging.effort = 0; 347. return 0; 348. } 349. 350. if (IS_ALTAR(lev->typ)) { 351. altar_wrath(dpx, dpy); 352. angry_priest(); 353. } 354. 355. /* make pit at <u.ux,u.uy> */ 356. if (dighole(TRUE, FALSE, (coord *) 0)) { 357. context.digging.level.dnum = 0; 358. context.digging.level.dlevel = -1; 359. } 360. return 0; 361. } 362. 363. if (context.digging.effort > 100) { 364. const char *digtxt, *dmgtxt = (const char *) 0; 365. struct obj *obj; 366. boolean shopedge = *in_rooms(dpx, dpy, SHOPBASE); 367. 368. if ((obj = sobj_at(STATUE, dpx, dpy)) != 0) { 369. if (break_statue(obj)) 370. digtxt = "The statue shatters."; 371. else 372. /* it was a statue trap; break_statue() 373. * printed a message and updated the screen 374. */ 375. digtxt = (char *) 0; 376. } else if ((obj = sobj_at(BOULDER, dpx, dpy)) != 0) { 377. struct obj *bobj; 378. 379. fracture_rock(obj); 380. if ((bobj = sobj_at(BOULDER, dpx, dpy)) != 0) { 381. /* another boulder here, restack it to the top */ 382. obj_extract_self(bobj); 383. place_object(bobj, dpx, dpy); 384. } 385. digtxt = "The boulder falls apart."; 386. } else if (lev->typ == STONE || lev->typ == SCORR 387. || IS_TREE(lev->typ)) { 388. if (Is_earthlevel(&u.uz)) { 389. if (uwep->blessed && !rn2(3)) { 390. mkcavearea(FALSE); 391. goto cleanup; 392. } else if ((uwep->cursed && !rn2(4)) 393. || (!uwep->blessed && !rn2(6))) { 394. mkcavearea(TRUE); 395. goto cleanup; 396. } 397. } 398. if (IS_TREE(lev->typ)) { 399. digtxt = "You cut down the tree."; 400. lev->typ = ROOM, lev->flags = 0; 401. if (!rn2(5)) 402. (void) rnd_treefruit_at(dpx, dpy); 403. } else { 404. digtxt = "You succeed in cutting away some rock."; 405. lev->typ = CORR, lev->flags = 0; 406. } 407. } else if (IS_WALL(lev->typ)) { 408. if (shopedge) { 409. add_damage(dpx, dpy, SHOP_WALL_DMG); 410. dmgtxt = "damage"; 411. } 412. if (level.flags.is_maze_lev) { 413. lev->typ = ROOM, lev->flags = 0; 414. } else if (level.flags.is_cavernous_lev && !in_town(dpx, dpy)) { 415. lev->typ = CORR, lev->flags = 0; 416. } else { 417. lev->typ = DOOR, lev->doormask = D_NODOOR; 418. } 419. digtxt = "You make an opening in the wall."; 420. } else if (lev->typ == SDOOR) { 421. cvt_sdoor_to_door(lev); /* ->typ = DOOR */ 422. digtxt = "You break through a secret door!"; 423. if (!(lev->doormask & D_TRAPPED)) 424. lev->doormask = D_BROKEN; 425. } else if (closed_door(dpx, dpy)) { 426. digtxt = "You break through the door."; 427. if (shopedge) { 428. add_damage(dpx, dpy, SHOP_DOOR_COST); 429. dmgtxt = "break"; 430. } 431. if (!(lev->doormask & D_TRAPPED)) 432. lev->doormask = D_BROKEN; 433. } else 434. return 0; /* statue or boulder got taken */ 435. 436. if (!does_block(dpx, dpy, &levl[dpx][dpy])) 437. unblock_point(dpx, dpy); /* vision: can see through */ 438. feel_newsym(dpx, dpy); 439. if (digtxt && !context.digging.quiet) 440. pline1(digtxt); /* after newsym */ 441. if (dmgtxt) 442. pay_for_damage(dmgtxt, FALSE); 443. 444. if (Is_earthlevel(&u.uz) && !rn2(3)) { 445. register struct monst *mtmp; 446. 447. switch (rn2(2)) { 448. case 0: 449. mtmp = makemon(&mons[PM_EARTH_ELEMENTAL], dpx, dpy, 450. NO_MM_FLAGS); 451. break; 452. default: 453. mtmp = makemon(&mons[PM_XORN], dpx, dpy, NO_MM_FLAGS); 454. break; 455. } 456. if (mtmp) 457. pline_The("debris from your digging comes to life!"); 458. } 459. if (IS_DOOR(lev->typ) && (lev->doormask & D_TRAPPED)) { 460. lev->doormask = D_NODOOR; 461. b_trapped("door", 0); 462. newsym(dpx, dpy); 463. } 464. cleanup: 465. context.digging.lastdigtime = moves; 466. context.digging.quiet = FALSE; 467. context.digging.level.dnum = 0; 468. context.digging.level.dlevel = -1; 469. return 0; 470. } else { /* not enough effort has been spent yet */ 471. static const char *const d_target[6] = { "", "rock", "statue", 472. "boulder", "door", "tree" }; 473. int dig_target = dig_typ(uwep, dpx, dpy); 474. 475. if (IS_WALL(lev->typ) || dig_target == DIGTYP_DOOR) { 476. if (*in_rooms(dpx, dpy, SHOPBASE)) { 477. pline("This %s seems too hard to %s.", 478. IS_DOOR(lev->typ) ? "door" : "wall", verb); 479. return 0; 480. } 481. } else if (dig_target == DIGTYP_UNDIGGABLE 482. || (dig_target == DIGTYP_ROCK && !IS_ROCK(lev->typ))) 483. return 0; /* statue or boulder got taken */ 484. 485. if (!did_dig_msg) { 486. You("hit the %s with all your might.", d_target[dig_target]); 487. did_dig_msg = TRUE; 488. } 489. } 490. return 1; 491. } 492. 493. /* When will hole be finished? Very rough indication used by shopkeeper. */ 494. int 495. holetime() 496. { 497. if (occupation != dig || !*u.ushops) 498. return -1; 499. return ((250 - context.digging.effort) / 20); 500. } 501. 502. /* Return typ of liquid to fill a hole with, or ROOM, if no liquid nearby */ 503. schar 504. fillholetyp(x, y, fill_if_any) 505. int x, y; 506. boolean fill_if_any; /* force filling if it exists at all */ 507. { 508. register int x1, y1; 509. int lo_x = max(1, x - 1), hi_x = min(x + 1, COLNO - 1), 510. lo_y = max(0, y - 1), hi_y = min(y + 1, ROWNO - 1); 511. int pool_cnt = 0, moat_cnt = 0, lava_cnt = 0; 512. 513. for (x1 = lo_x; x1 <= hi_x; x1++) 514. for (y1 = lo_y; y1 <= hi_y; y1++) 515. if (is_moat(x1, y1)) 516. moat_cnt++; 517. else if (is_pool(x1, y1)) 518. /* This must come after is_moat since moats are pools 519. * but not vice-versa. */ 520. pool_cnt++; 521. else if (is_lava(x1, y1)) 522. lava_cnt++; 523. 524. if (!fill_if_any) 525. pool_cnt /= 3; /* not as much liquid as the others */ 526. 527. if ((lava_cnt > moat_cnt + pool_cnt && rn2(lava_cnt + 1)) 528. || (lava_cnt && fill_if_any)) 529. return LAVAPOOL; 530. else if ((moat_cnt > 0 && rn2(moat_cnt + 1)) || (moat_cnt && fill_if_any)) 531. return MOAT; 532. else if ((pool_cnt > 0 && rn2(pool_cnt + 1)) || (pool_cnt && fill_if_any)) 533. return POOL; 534. else 535. return ROOM; 536. } 537. 538. void 539. digactualhole(x, y, madeby, ttyp) 540. register int x, y; 541. struct monst *madeby; 542. int ttyp; 543. { 544. struct obj *oldobjs, *newobjs; 545. register struct trap *ttmp; 546. char surface_type[BUFSZ]; 547. struct rm *lev = &levl[x][y]; 548. boolean shopdoor; 549. struct monst *mtmp = m_at(x, y); /* may be madeby */ 550. boolean madeby_u = (madeby == BY_YOU); 551. boolean madeby_obj = (madeby == BY_OBJECT); 552. boolean at_u = (x == u.ux) && (y == u.uy); 553. boolean wont_fall = Levitation || Flying; 554. 555. if (at_u && u.utrap) { 556. if (u.utraptype == TT_BURIEDBALL) 557. buried_ball_to_punishment(); 558. else if (u.utraptype == TT_INFLOOR) 559. reset_utrap(FALSE); 560. } 561. 562. /* these furniture checks were in dighole(), but wand 563. breaking bypasses that routine and calls us directly */ 564. if (IS_FOUNTAIN(lev->typ)) { 565. dogushforth(FALSE); 566. SET_FOUNTAIN_WARNED(x, y); /* force dryup */ 567. dryup(x, y, madeby_u); 568. return; 569. } else if (IS_SINK(lev->typ)) { 570. breaksink(x, y); 571. return; 572. } else if (lev->typ == DRAWBRIDGE_DOWN 573. || (is_drawbridge_wall(x, y) >= 0)) { 574. int bx = x, by = y; 575. 576. /* if under the portcullis, the bridge is adjacent */ 577. (void) find_drawbridge(&bx, &by); 578. destroy_drawbridge(bx, by); 579. return; 580. } 581. 582. if (ttyp != PIT && (!Can_dig_down(&u.uz) && !lev->candig)) { 583. impossible("digactualhole: can't dig %s on this level.", 584. defsyms[trap_to_defsym(ttyp)].explanation); 585. ttyp = PIT; 586. } 587. 588. /* maketrap() might change it, also, in this situation, 589. surface() returns an inappropriate string for a grave */ 590. if (IS_GRAVE(lev->typ)) 591. Strcpy(surface_type, "grave"); 592. else 593. Strcpy(surface_type, surface(x, y)); 594. shopdoor = IS_DOOR(lev->typ) && *in_rooms(x, y, SHOPBASE); 595. oldobjs = level.objects[x][y]; 596. ttmp = maketrap(x, y, ttyp); 597. if (!ttmp) 598. return; 599. newobjs = level.objects[x][y]; 600. ttmp->madeby_u = madeby_u; 601. ttmp->tseen = 0; 602. if (cansee(x, y)) 603. seetrap(ttmp); 604. else if (madeby_u) 605. feeltrap(ttmp); 606. 607. if (ttyp == PIT) { 608. if (madeby_u) { 609. if (x != u.ux || y != u.uy) 610. You("dig an adjacent pit."); 611. else 612. You("dig a pit in the %s.", surface_type); 613. if (shopdoor) 614. pay_for_damage("ruin", FALSE); 615. } else if (!madeby_obj && canseemon(madeby)) { 616. pline("%s digs a pit in the %s.", Monnam(madeby), surface_type); 617. } else if (cansee(x, y) && flags.verbose) { 618. pline("A pit appears in the %s.", surface_type); 619. } 620. /* in case we're digging down while encased in solid rock 621. which is blocking levitation or flight */ 622. switch_terrain(); 623. if (Levitation || Flying) 624. wont_fall = TRUE; 625. 626. if (at_u) { 627. if (!wont_fall) { 628. set_utrap(rn1(4, 2), TT_PIT); 629. vision_full_recalc = 1; /* vision limits change */ 630. } else 631. reset_utrap(TRUE); 632. if (oldobjs != newobjs) /* something unearthed */ 633. (void) pickup(1); /* detects pit */ 634. } else if (mtmp) { 635. if (is_flyer(mtmp->data) || is_floater(mtmp->data)) { 636. if (canseemon(mtmp)) 637. pline("%s %s over the pit.", Monnam(mtmp), 638. (is_flyer(mtmp->data)) ? "flies" : "floats"); 639. } else if (mtmp != madeby) 640. (void) mintrap(mtmp); 641. } 642. } else { /* was TRAPDOOR now a HOLE*/ 643. 644. if (madeby_u) 645. You("dig a hole through the %s.", surface_type); 646. else if (!madeby_obj && canseemon(madeby)) 647. pline("%s digs a hole through the %s.", Monnam(madeby), 648. surface_type); 649. else if (cansee(x, y) && flags.verbose) 650. pline("A hole appears in the %s.", surface_type); 651. 652. if (at_u) { 653. /* in case we're digging down while encased in solid rock 654. which is blocking levitation or flight */ 655. switch_terrain(); 656. if (Levitation || Flying) 657. wont_fall = TRUE; 658. 659. /* check for leashed pet that can't fall right now */ 660. if (!u.ustuck && !wont_fall && !next_to_u()) { 661. You("are jerked back by your pet!"); 662. wont_fall = TRUE; 663. } 664. 665. /* Floor objects get a chance of falling down. The case where 666. * the hero does NOT fall down is treated here. The case 667. * where the hero does fall down is treated in goto_level(). 668. */ 669. if (u.ustuck || wont_fall) { 670. if (newobjs) 671. impact_drop((struct obj *) 0, x, y, 0); 672. if (oldobjs != newobjs) 673. (void) pickup(1); 674. if (shopdoor && madeby_u) 675. pay_for_damage("ruin", FALSE); 676. 677. } else { 678. d_level newlevel; 679. 680. if (*u.ushops && madeby_u) 681. shopdig(1); /* shk might snatch pack */ 682. /* handle earlier damage, eg breaking wand of digging */ 683. else if (!madeby_u) 684. pay_for_damage("dig into", TRUE); 685. 686. You("fall through..."); 687. /* Earlier checks must ensure that the destination 688. * level exists and is in the present dungeon. 689. */ 690. newlevel.dnum = u.uz.dnum; 691. newlevel.dlevel = u.uz.dlevel + 1; 692. goto_level(&newlevel, FALSE, TRUE, FALSE); 693. /* messages for arriving in special rooms */ 694. spoteffects(FALSE); 695. } 696. } else { 697. if (shopdoor && madeby_u) 698. pay_for_damage("ruin", FALSE); 699. if (newobjs) 700. impact_drop((struct obj *) 0, x, y, 0); 701. if (mtmp) { 702. /*[don't we need special sokoban handling here?]*/ 703. if (is_flyer(mtmp->data) || is_floater(mtmp->data) 704. || mtmp->data == &mons[PM_WUMPUS] 705. || (mtmp->wormno && count_wsegs(mtmp) > 5) 706. || mtmp->data->msize >= MZ_HUGE) 707. return; 708. if (mtmp == u.ustuck) /* probably a vortex */ 709. return; /* temporary? kludge */ 710. 711. if (teleport_pet(mtmp, FALSE)) { 712. d_level tolevel; 713. 714. if (Is_stronghold(&u.uz)) { 715. assign_level(&tolevel, &valley_level); 716. } else if (Is_botlevel(&u.uz)) { 717. if (canseemon(mtmp)) 718. pline("%s avoids the trap.", Monnam(mtmp)); 719. return; 720. } else { 721. get_level(&tolevel, depth(&u.uz) + 1); 722. } 723. if (mtmp->isshk) 724. make_angry_shk(mtmp, 0, 0); 725. migrate_to_level(mtmp, ledger_no(&tolevel), 726. MIGR_RANDOM, (coord *) 0); 727. } 728. } 729. } 730. } 731. } 732. 733. /* 734. * Called from dighole(), but also from do_break_wand() 735. * in apply.c. 736. */ 737. void 738. liquid_flow(x, y, typ, ttmp, fillmsg) 739. xchar x, y; 740. schar typ; 741. struct trap *ttmp; 742. const char *fillmsg; 743. { 744. boolean u_spot = (x == u.ux && y == u.uy); 745. 746. if (ttmp) 747. (void) delfloortrap(ttmp); 748. /* if any objects were frozen here, they're released now */ 749. unearth_objs(x, y); 750. 751. if (fillmsg) 752. pline(fillmsg, hliquid(typ == LAVAPOOL ? "lava" : "water")); 753. if (u_spot && !(Levitation || Flying)) { 754. if (typ == LAVAPOOL) 755. (void) lava_effects(); 756. else if (!Wwalking) 757. (void) drown(); 758. } 759. } 760. 761. /* return TRUE if digging succeeded, FALSE otherwise */ 762. boolean 763. dighole(pit_only, by_magic, cc) 764. boolean pit_only, by_magic; 765. coord *cc; 766. { 767. register struct trap *ttmp; 768. struct rm *lev; 769. struct obj *boulder_here; 770. schar typ; 771. xchar dig_x, dig_y; 772. boolean nohole; 773. 774. if (!cc) { 775. dig_x = u.ux; 776. dig_y = u.uy; 777. } else { 778. dig_x = cc->x; 779. dig_y = cc->y; 780. if (!isok(dig_x, dig_y)) 781. return FALSE; 782. } 783. 784. ttmp = t_at(dig_x, dig_y); 785. lev = &levl[dig_x][dig_y]; 786. nohole = (!Can_dig_down(&u.uz) && !lev->candig); 787. 788. if ((ttmp && (ttmp->ttyp == MAGIC_PORTAL 789. || ttmp->ttyp == VIBRATING_SQUARE || nohole)) 790. || (IS_ROCK(lev->typ) && lev->typ != SDOOR 791. && (lev->wall_info & W_NONDIGGABLE) != 0)) { 792. pline_The("%s %shere is too hard to dig in.", surface(dig_x, dig_y), 793. (dig_x != u.ux || dig_y != u.uy) ? "t" : ""); 794. 795. } else if (is_pool_or_lava(dig_x, dig_y)) { 796. pline_The("%s sloshes furiously for a moment, then subsides.", 797. hliquid(is_lava(dig_x, dig_y) ? "lava" : "water")); 798. wake_nearby(); /* splashing */ 799. 800. } else if (lev->typ == DRAWBRIDGE_DOWN 801. || (is_drawbridge_wall(dig_x, dig_y) >= 0)) { 802. /* drawbridge_down is the platform crossing the moat when the 803. bridge is extended; drawbridge_wall is the open "doorway" or 804. closed "door" where the portcullis/mechanism is located */ 805. if (pit_only) { 806. pline_The("drawbridge seems too hard to dig through."); 807. return FALSE; 808. } else { 809. int x = dig_x, y = dig_y; 810. /* if under the portcullis, the bridge is adjacent */ 811. (void) find_drawbridge(&x, &y); 812. destroy_drawbridge(x, y); 813. return TRUE; 814. } 815. 816. } else if ((boulder_here = sobj_at(BOULDER, dig_x, dig_y)) != 0) { 817. if (ttmp && is_pit(ttmp->ttyp) 818. && rn2(2)) { 819. pline_The("boulder settles into the %spit.", 820. (dig_x != u.ux || dig_y != u.uy) ? "adjacent " : ""); 821. ttmp->ttyp = PIT; /* crush spikes */ 822. } else { 823. /* 824. * digging makes a hole, but the boulder immediately 825. * fills it. Final outcome: no hole, no boulder. 826. */ 827. pline("KADOOM! The boulder falls in!"); 828. (void) delfloortrap(ttmp); 829. } 830. delobj(boulder_here); 831. return TRUE; 832. 833. } else if (IS_GRAVE(lev->typ)) { 834. digactualhole(dig_x, dig_y, BY_YOU, PIT); 835. dig_up_grave(cc); 836. return TRUE; 837. } else if (lev->typ == DRAWBRIDGE_UP) { 838. /* must be floor or ice, other cases handled above */ 839. /* dig "pit" and let fluid flow in (if possible) */ 840. typ = fillholetyp(dig_x, dig_y, FALSE); 841. 842. if (typ == ROOM) { 843. /* 844. * We can't dig a hole here since that will destroy 845. * the drawbridge. The following is a cop-out. --dlc 846. */ 847. pline_The("%s %shere is too hard to dig in.", 848. surface(dig_x, dig_y), 849. (dig_x != u.ux || dig_y != u.uy) ? "t" : ""); 850. return FALSE; 851. } 852. 853. lev->drawbridgemask &= ~DB_UNDER; 854. lev->drawbridgemask |= (typ == LAVAPOOL) ? DB_LAVA : DB_MOAT; 855. liquid_flow(dig_x, dig_y, typ, ttmp, 856. "As you dig, the hole fills with %s!"); 857. return TRUE; 858. 859. /* the following two are here for the wand of digging */ 860. } else if (IS_THRONE(lev->typ)) { 861. pline_The("throne is too hard to break apart."); 862. 863. } else if (IS_ALTAR(lev->typ)) { 864. pline_The("altar is too hard to break apart."); 865. 866. } else { 867. typ = fillholetyp(dig_x, dig_y, FALSE); 868. 869. lev->flags = 0; 870. if (typ != ROOM) { 871. lev->typ = typ; 872. liquid_flow(dig_x, dig_y, typ, ttmp, 873. "As you dig, the hole fills with %s!"); 874. return TRUE; 875. } 876. 877. /* magical digging disarms settable traps */ 878. if (by_magic && ttmp 879. && (ttmp->ttyp == LANDMINE || ttmp->ttyp == BEAR_TRAP)) { 880. int otyp = (ttmp->ttyp == LANDMINE) ? LAND_MINE : BEARTRAP; 881. 882. /* convert trap into buried object (deletes trap) */ 883. cnv_trap_obj(otyp, 1, ttmp, TRUE); 884. } 885. 886. /* finally we get to make a hole */ 887. if (nohole || pit_only) 888. digactualhole(dig_x, dig_y, BY_YOU, PIT); 889. else 890. digactualhole(dig_x, dig_y, BY_YOU, HOLE); 891. 892. return TRUE; 893. } 894. 895. return FALSE; 896. } 897. 898. STATIC_OVL void 899. dig_up_grave(cc) 900. coord *cc; 901. { 902. struct obj *otmp; 903. xchar dig_x, dig_y; 904. 905. if (!cc) { 906. dig_x = u.ux; 907. dig_y = u.uy; 908. } else { 909. dig_x = cc->x; 910. dig_y = cc->y; 911. if (!isok(dig_x, dig_y)) 912. return; 913. } 914. 915. /* Grave-robbing is frowned upon... */ 916. exercise(A_WIS, FALSE); 917. if (Role_if(PM_ARCHEOLOGIST)) { 918. adjalign(-sgn(u.ualign.type) * 3); 919. You_feel("like a despicable grave-robber!"); 920. } else if (Role_if(PM_SAMURAI)) { 921. adjalign(-sgn(u.ualign.type)); 922. You("disturb the honorable dead!"); 923. } else if ((u.ualign.type == A_LAWFUL) && (u.ualign.record > -10)) { 924. adjalign(-sgn(u.ualign.type)); 925. You("have violated the sanctity of this grave!"); 926. } 927. 928. switch (rn2(5)) { 929. case 0: 930. case 1: 931. You("unearth a corpse."); 932. if ((otmp = mk_tt_object(CORPSE, dig_x, dig_y)) != 0) 933. otmp->age -= 100; /* this is an *OLD* corpse */ 934. break; 935. case 2: 936. if (!Blind) 937. pline(Hallucination ? "Dude! The living dead!" 938. : "The grave's owner is very upset!"); 939. (void) makemon(mkclass(S_ZOMBIE, 0), dig_x, dig_y, NO_MM_FLAGS); 940. break; 941. case 3: 942. if (!Blind) 943. pline(Hallucination ? "I want my mummy!" 944. : "You've disturbed a tomb!"); 945. (void) makemon(mkclass(S_MUMMY, 0), dig_x, dig_y, NO_MM_FLAGS); 946. break; 947. default: 948. /* No corpse */ 949. pline_The("grave seems unused. Strange...."); 950. break; 951. } 952. levl[dig_x][dig_y].typ = ROOM, levl[dig_x][dig_y].flags = 0; 953. del_engr_at(dig_x, dig_y); 954. newsym(dig_x, dig_y); 955. return; 956. } 957. 958. int 959. use_pick_axe(obj) 960. struct obj *obj; 961. { 962. const char *sdp, *verb; 963. char *dsp, dirsyms[12], qbuf[BUFSZ]; 964. boolean ispick; 965. int rx, ry, downok, res = 0; 966. 967. /* Check tool */ 968. if (obj != uwep) { 969. if (!wield_tool(obj, "swing")) 970. return 0; 971. else 972. res = 1; 973. } 974. ispick = is_pick(obj); 975. verb = ispick ? "dig" : "chop"; 976. 977. if (u.utrap && u.utraptype == TT_WEB) { 978. pline("%s you can't %s while entangled in a web.", 979. /* res==0 => no prior message; 980. res==1 => just got "You now wield a pick-axe." message */ 981. !res ? "Unfortunately," : "But", verb); 982. return res; 983. } 984. 985. /* construct list of directions to show player for likely choices */ 986. downok = !!can_reach_floor(FALSE); 987. dsp = dirsyms; 988. for (sdp = Cmd.dirchars; *sdp; ++sdp) { 989. /* filter out useless directions */ 990. if (u.uswallow) { 991. ; /* all directions are viable when swallowed */ 992. } else if (movecmd(*sdp)) { 993. /* normal direction, within plane of the level map; 994. movecmd() sets u.dx, u.dy, u.dz and returns !u.dz */ 995. if (!dxdy_moveok()) 996. continue; /* handle NODIAG */ 997. rx = u.ux + u.dx; 998. ry = u.uy + u.dy; 999. if (!isok(rx, ry) || dig_typ(obj, rx, ry) == DIGTYP_UNDIGGABLE) 1000. continue; 1001. } else { 1002. /* up or down; we used to always include down, so that 1003. there would always be at least one choice shown, but 1004. it shouldn't be a likely candidate when floating high 1005. above the floor; include up instead in that situation 1006. (as a silly candidate rather than a likely one...) */ 1007. if ((u.dz > 0) ^ downok) 1008. continue; 1009. } 1010. /* include this direction */ 1011. *dsp++ = *sdp; 1012. } 1013. *dsp = 0; 1014. Sprintf(qbuf, "In what direction do you want to %s? [%s]", verb, dirsyms); 1015. if (!getdir(qbuf)) 1016. return res; 1017. 1018. return use_pick_axe2(obj); 1019. } 1020. 1021. /* MRKR: use_pick_axe() is split in two to allow autodig to bypass */ 1022. /* the "In what direction do you want to dig?" query. */ 1023. /* use_pick_axe2() uses the existing u.dx, u.dy and u.dz */ 1024. int 1025. use_pick_axe2(obj) 1026. struct obj *obj; 1027. { 1028. register int rx, ry; 1029. register struct rm *lev; 1030. struct trap *trap, *trap_with_u; 1031. int dig_target; 1032. boolean ispick = is_pick(obj); 1033. const char *verbing = ispick ? "digging" : "chopping"; 1034. 1035. if (u.uswallow && attack(u.ustuck)) { 1036. ; /* return 1 */ 1037. } else if (Underwater) { 1038. pline("Turbulence torpedoes your %s attempts.", verbing); 1039. } else if (u.dz < 0) { 1040. if (Levitation) 1041. You("don't have enough leverage."); 1042. else 1043. You_cant("reach the %s.", ceiling(u.ux, u.uy)); 1044. } else if (!u.dx && !u.dy && !u.dz) { 1045. char buf[BUFSZ]; 1046. int dam; 1047. 1048. dam = rnd(2) + dbon() + obj->spe; 1049. if (dam <= 0) 1050. dam = 1; 1051. You("hit yourself with %s.", yname(uwep)); 1052. Sprintf(buf, "%s own %s", uhis(), OBJ_NAME(objects[obj->otyp])); 1053. losehp(Maybe_Half_Phys(dam), buf, KILLED_BY); 1054. context.botl = 1; 1055. return 1; 1056. } else if (u.dz == 0) { 1057. if (Stunned || (Confusion && !rn2(5))) 1058. confdir(); 1059. rx = u.ux + u.dx; 1060. ry = u.uy + u.dy; 1061. if (!isok(rx, ry)) { 1062. pline("Clash!"); 1063. return 1; 1064. } 1065. lev = &levl[rx][ry]; 1066. if (MON_AT(rx, ry) && attack(m_at(rx, ry))) 1067. return 1; 1068. dig_target = dig_typ(obj, rx, ry); 1069. if (dig_target == DIGTYP_UNDIGGABLE) { 1070. /* ACCESSIBLE or POOL */ 1071. trap = t_at(rx, ry); 1072. if (trap && trap->ttyp == WEB) { 1073. if (!trap->tseen) { 1074. seetrap(trap); 1075. There("is a spider web there!"); 1076. } 1077. pline("%s entangled in the web.", Yobjnam2(obj, "become")); 1078. /* you ought to be able to let go; tough luck */ 1079. /* (maybe `move_into_trap()' would be better) */ 1080. nomul(-d(2, 2)); 1081. multi_reason = "stuck in a spider web"; 1082. nomovemsg = "You pull free."; 1083. } else if (lev->typ == IRONBARS) { 1084. pline("Clang!"); 1085. wake_nearby(); 1086. } else if (IS_TREE(lev->typ)) { 1087. You("need an axe to cut down a tree."); 1088. } else if (IS_ROCK(lev->typ)) { 1089. You("need a pick to dig rock."); 1090. } else if (!ispick && (sobj_at(STATUE, rx, ry) 1091. || sobj_at(BOULDER, rx, ry))) { 1092. boolean vibrate = !rn2(3); 1093. 1094. pline("Sparks fly as you whack the %s.%s", 1095. sobj_at(STATUE, rx, ry) ? "statue" : "boulder", 1096. vibrate ? " The axe-handle vibrates violently!" : ""); 1097. if (vibrate) 1098. losehp(Maybe_Half_Phys(2), "axing a hard object", 1099. KILLED_BY); 1100. } else if (u.utrap && u.utraptype == TT_PIT && trap 1101. && (trap_with_u = t_at(u.ux, u.uy)) 1102. && is_pit(trap->ttyp) 1103. && !conjoined_pits(trap, trap_with_u, FALSE)) { 1104. int idx; 1105. 1106. for (idx = 0; idx < 8; idx++) { 1107. if (xdir[idx] == u.dx && ydir[idx] == u.dy) 1108. break; 1109. } 1110. /* idx is valid if < 8 */ 1111. if (idx < 8) { 1112. int adjidx = (idx + 4) % 8; 1113. 1114. trap_with_u->conjoined |= (1 << idx); 1115. trap->conjoined |= (1 << adjidx); 1116. pline("You clear some debris from between the pits."); 1117. } 1118. } else if (u.utrap && u.utraptype == TT_PIT 1119. && (trap_with_u = t_at(u.ux, u.uy)) != 0) { 1120. You("swing %s, but the rubble has no place to go.", 1121. yobjnam(obj, (char *) 0)); 1122. } else { 1123. You("swing %s through thin air.", yobjnam(obj, (char *) 0)); 1124. } 1125. } else { 1126. static const char *const d_action[6] = { "swinging", "digging", 1127. "chipping the statue", 1128. "hitting the boulder", 1129. "chopping at the door", 1130. "cutting the tree" }; 1131. 1132. did_dig_msg = FALSE; 1133. context.digging.quiet = FALSE; 1134. if (context.digging.pos.x != rx || context.digging.pos.y != ry 1135. || !on_level(&context.digging.level, &u.uz) 1136. || context.digging.down) { 1137. if (flags.autodig && dig_target == DIGTYP_ROCK 1138. && !context.digging.down 1139. && context.digging.pos.x == u.ux 1140. && context.digging.pos.y == u.uy 1141. && (moves <= context.digging.lastdigtime + 2 1142. && moves >= context.digging.lastdigtime)) { 1143. /* avoid messages if repeated autodigging */ 1144. did_dig_msg = TRUE; 1145. context.digging.quiet = TRUE; 1146. } 1147. context.digging.down = context.digging.chew = FALSE; 1148. context.digging.warned = FALSE; 1149. context.digging.pos.x = rx; 1150. context.digging.pos.y = ry; 1151. assign_level(&context.digging.level, &u.uz); 1152. context.digging.effort = 0; 1153. if (!context.digging.quiet) 1154. You("start %s.", d_action[dig_target]); 1155. } else { 1156. You("%s %s.", context.digging.chew ? "begin" : "continue", 1157. d_action[dig_target]); 1158. context.digging.chew = FALSE; 1159. } 1160. set_occupation(dig, verbing, 0); 1161. } 1162. } else if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) { 1163. /* it must be air -- water checked above */ 1164. You("swing %s through thin air.", yobjnam(obj, (char *) 0)); 1165. } else if (!can_reach_floor(FALSE)) { 1166. cant_reach_floor(u.ux, u.uy, FALSE, FALSE); 1167. } else if (is_pool_or_lava(u.ux, u.uy)) { 1168. /* Monsters which swim also happen not to be able to dig */ 1169. You("cannot stay under%s long enough.", 1170. is_pool(u.ux, u.uy) ? "water" : " the lava"); 1171. } else if ((trap = t_at(u.ux, u.uy)) != 0 1172. && (uteetering_at_seen_pit(trap) || uescaped_shaft(trap))) { 1173. dotrap(trap, FORCEBUNGLE); 1174. /* might escape trap and still be teetering at brink */ 1175. if (!u.utrap) 1176. cant_reach_floor(u.ux, u.uy, FALSE, TRUE); 1177. } else if (!ispick 1178. /* can only dig down with an axe when doing so will 1179. trigger or disarm a trap here */ 1180. && (!trap || (trap->ttyp != LANDMINE 1181. && trap->ttyp != BEAR_TRAP))) { 1182. pline("%s merely scratches the %s.", Yobjnam2(obj, (char *) 0), 1183. surface(u.ux, u.uy)); 1184. u_wipe_engr(3); 1185. } else { 1186. if (context.digging.pos.x != u.ux || context.digging.pos.y != u.uy 1187. || !on_level(&context.digging.level, &u.uz) 1188. || !context.digging.down) { 1189. context.digging.chew = FALSE; 1190. context.digging.down = TRUE; 1191. context.digging.warned = FALSE; 1192. context.digging.pos.x = u.ux; 1193. context.digging.pos.y = u.uy; 1194. assign_level(&context.digging.level, &u.uz); 1195. context.digging.effort = 0; 1196. You("start %s downward.", verbing); 1197. if (*u.ushops) 1198. shopdig(0); 1199. } else 1200. You("continue %s downward.", verbing); 1201. did_dig_msg = FALSE; 1202. set_occupation(dig, verbing, 0); 1203. } 1204. return 1; 1205. } 1206. 1207. /* 1208. * Town Watchmen frown on damage to the town walls, trees or fountains. 1209. * It's OK to dig holes in the ground, however. 1210. * If mtmp is assumed to be a watchman, a watchman is found if mtmp == 0 1211. * zap == TRUE if wand/spell of digging, FALSE otherwise (chewing) 1212. */ 1213. void 1214. watch_dig(mtmp, x, y, zap) 1215. struct monst *mtmp; 1216. xchar x, y; 1217. boolean zap; 1218. { 1219. struct rm *lev = &levl[x][y]; 1220. 1221. if (in_town(x, y) 1222. && (closed_door(x, y) || lev->typ == SDOOR || IS_WALL(lev->typ) 1223. || IS_FOUNTAIN(lev->typ) || IS_TREE(lev->typ))) { 1224. if (!mtmp) { 1225. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 1226. if (DEADMONSTER(mtmp)) 1227. continue; 1228. if (is_watch(mtmp->data) && mtmp->mcansee && m_canseeu(mtmp) 1229. && couldsee(mtmp->mx, mtmp->my) && mtmp->mpeaceful) 1230. break; 1231. } 1232. } 1233. 1234. if (mtmp) { 1235. if (zap || context.digging.warned) { 1236. verbalize("Halt, vandal! You're under arrest!"); 1237. (void) angry_guards(!!Deaf); 1238. } else { 1239. const char *str; 1240. 1241. if (IS_DOOR(lev->typ)) 1242. str = "door"; 1243. else if (IS_TREE(lev->typ)) 1244. str = "tree"; 1245. else if (IS_ROCK(lev->typ)) 1246. str = "wall"; 1247. else 1248. str = "fountain"; 1249. verbalize("Hey, stop damaging that %s!", str); 1250. context.digging.warned = TRUE; 1251. } 1252. if (is_digging()) 1253. stop_occupation(); 1254. } 1255. } 1256. } 1257. 1258. /* Return TRUE if monster died, FALSE otherwise. Called from m_move(). */ 1259. boolean 1260. mdig_tunnel(mtmp) 1261. register struct monst *mtmp; 1262. { 1263. register struct rm *here; 1264. int pile = rnd(12); 1265. 1266. here = &levl[mtmp->mx][mtmp->my]; 1267. if (here->typ == SDOOR) 1268. cvt_sdoor_to_door(here); /* ->typ = DOOR */ 1269. 1270. /* Eats away door if present & closed or locked */ 1271. if (closed_door(mtmp->mx, mtmp->my)) { 1272. if (*in_rooms(mtmp->mx, mtmp->my, SHOPBASE)) 1273. add_damage(mtmp->mx, mtmp->my, 0L); 1274. unblock_point(mtmp->mx, mtmp->my); /* vision */ 1275. if (here->doormask & D_TRAPPED) { 1276. here->doormask = D_NODOOR; 1277. if (mb_trapped(mtmp)) { /* mtmp is killed */ 1278. newsym(mtmp->mx, mtmp->my); 1279. return TRUE; 1280. } 1281. } else { 1282. if (!rn2(3) && flags.verbose) /* not too often.. */ 1283. draft_message(TRUE); /* "You feel an unexpected draft." */ 1284. here->doormask = D_BROKEN; 1285. } 1286. newsym(mtmp->mx, mtmp->my); 1287. return FALSE; 1288. } else if (here->typ == SCORR) { 1289. here->typ = CORR, here->flags = 0; 1290. unblock_point(mtmp->mx, mtmp->my); 1291. newsym(mtmp->mx, mtmp->my); 1292. draft_message(FALSE); /* "You feel a draft." */ 1293. return FALSE; 1294. } else if (!IS_ROCK(here->typ) && !IS_TREE(here->typ)) { /* no dig */ 1295. return FALSE; 1296. } 1297. 1298. /* Only rock, trees, and walls fall through to this point. */ 1299. if ((here->wall_info & W_NONDIGGABLE) != 0) { 1300. impossible("mdig_tunnel: %s at (%d,%d) is undiggable", 1301. (IS_WALL(here->typ) ? "wall" 1302. : IS_TREE(here->typ) ? "tree" : "stone"), 1303. (int) mtmp->mx, (int) mtmp->my); 1304. return FALSE; /* still alive */ 1305. } 1306. 1307. if (IS_WALL(here->typ)) { 1308. /* KMH -- Okay on arboreal levels (room walls are still stone) */ 1309. if (flags.verbose && !rn2(5)) 1310. You_hear("crashing rock."); 1311. if (*in_rooms(mtmp->mx, mtmp->my, SHOPBASE)) 1312. add_damage(mtmp->mx, mtmp->my, 0L); 1313. if (level.flags.is_maze_lev) { 1314. here->typ = ROOM, here->flags = 0; 1315. } else if (level.flags.is_cavernous_lev 1316. && !in_town(mtmp->mx, mtmp->my)) { 1317. here->typ = CORR, here->flags = 0; 1318. } else { 1319. here->typ = DOOR, here->doormask = D_NODOOR; 1320. } 1321. } else if (IS_TREE(here->typ)) { 1322. here->typ = ROOM, here->flags = 0; 1323. if (pile && pile < 5) 1324. (void) rnd_treefruit_at(mtmp->mx, mtmp->my); 1325. } else { 1326. here->typ = CORR, here->flags = 0; 1327. if (pile && pile < 5) 1328. (void) mksobj_at((pile == 1) ? BOULDER : ROCK, mtmp->mx, mtmp->my, 1329. TRUE, FALSE); 1330. } 1331. newsym(mtmp->mx, mtmp->my); 1332. if (!sobj_at(BOULDER, mtmp->mx, mtmp->my)) 1333. unblock_point(mtmp->mx, mtmp->my); /* vision */ 1334. 1335. return FALSE; 1336. } 1337. 1338. #define STRIDENT 4 /* from pray.c */ 1339. 1340. /* draft refers to air currents, but can be a pun on "draft" as conscription 1341. for military service (probably not a good pun if it has to be explained) */ 1342. void 1343. draft_message(unexpected) 1344. boolean unexpected; 1345. { 1346. /* 1347. * [Bug or TODO? Have caller pass coordinates and use the travel 1348. * mechanism to determine whether there is a path between 1349. * destroyed door (or exposed secret corridor) and hero's location. 1350. * When there is no such path, no draft should be felt.] 1351. */ 1352. 1353. if (unexpected) { 1354. if (!Hallucination) 1355. You_feel("an unexpected draft."); 1356. else 1357. /* U.S. classification system uses 1-A for eligible to serve 1358. and 4-F for ineligible due to physical or mental defect; 1359. some intermediate values exist but are rarely seen */ 1360. You_feel("like you are %s.", 1361. (ACURR(A_STR) < 6 || ACURR(A_DEX) < 6 1362. || ACURR(A_CON) < 6 || ACURR(A_CHA) < 6 1363. || ACURR(A_INT) < 6 || ACURR(A_WIS) < 6) ? "4-F" 1364. : "1-A"); 1365. } else { 1366. if (!Hallucination) { 1367. You_feel("a draft."); 1368. } else { 1369. /* "marching" is deliberately ambiguous; it might mean drills 1370. after entering military service or mean engaging in protests */ 1371. static const char *draft_reaction[] = { 1372. "enlisting", "marching", "protesting", "fleeing", 1373. }; 1374. int dridx; 1375. 1376. /* Lawful: 0..1, Neutral: 1..2, Chaotic: 2..3 */ 1377. dridx = rn1(2, 1 - sgn(u.ualign.type)); 1378. if (u.ualign.record < STRIDENT) 1379. /* L: +(0..2), N: +(-1..1), C: +(-2..0); all: 0..3 */ 1380. dridx += rn1(3, sgn(u.ualign.type) - 1); 1381. You_feel("like %s.", draft_reaction[dridx]); 1382. } 1383. } 1384. } 1385. 1386. /* digging via wand zap or spell cast */ 1387. void 1388. zap_dig() 1389. { 1390. struct rm *room; 1391. struct monst *mtmp; 1392. struct obj *otmp; 1393. struct trap *trap_with_u = (struct trap *) 0; 1394. int zx, zy, diridx = 8, digdepth, flow_x = -1, flow_y = -1; 1395. boolean shopdoor, shopwall, maze_dig, pitdig = FALSE, pitflow = FALSE; 1396. 1397. /* 1398. * Original effect (approximately): 1399. * from CORR: dig until we pierce a wall 1400. * from ROOM: pierce wall and dig until we reach 1401. * an ACCESSIBLE place. 1402. * Currently: dig for digdepth positions; 1403. * also down on request of Lennart Augustsson. 1404. * 3.6.0: from a PIT: dig one adjacent pit. 1405. */ 1406. 1407. if (u.uswallow) { 1408. mtmp = u.ustuck; 1409. 1410. if (!is_whirly(mtmp->data)) { 1411. if (is_animal(mtmp->data)) 1412. You("pierce %s %s wall!", s_suffix(mon_nam(mtmp)), 1413. mbodypart(mtmp, STOMACH)); 1414. mtmp->mhp = 1; /* almost dead */ 1415. expels(mtmp, mtmp->data, !is_animal(mtmp->data)); 1416. } 1417. return; 1418. } /* swallowed */ 1419. 1420. if (u.dz) { 1421. if (!Is_airlevel(&u.uz) && !Is_waterlevel(&u.uz) && !Underwater) { 1422. if (u.dz < 0 || On_stairs(u.ux, u.uy)) { 1423. int dmg; 1424. if (On_stairs(u.ux, u.uy)) 1425. pline_The("beam bounces off the %s and hits the %s.", 1426. (u.ux == xdnladder || u.ux == xupladder) 1427. ? "ladder" 1428. : "stairs", 1429. ceiling(u.ux, u.uy)); 1430. You("loosen a rock from the %s.", ceiling(u.ux, u.uy)); 1431. pline("It falls on your %s!", body_part(HEAD)); 1432. dmg = rnd((uarmh && is_metallic(uarmh)) ? 2 : 6); 1433. losehp(Maybe_Half_Phys(dmg), "falling rock", KILLED_BY_AN); 1434. otmp = mksobj_at(ROCK, u.ux, u.uy, FALSE, FALSE); 1435. if (otmp) { 1436. (void) xname(otmp); /* set dknown, maybe bknown */ 1437. stackobj(otmp); 1438. } 1439. newsym(u.ux, u.uy); 1440. } else { 1441. watch_dig((struct monst *) 0, u.ux, u.uy, TRUE); 1442. (void) dighole(FALSE, TRUE, (coord *) 0); 1443. } 1444. } 1445. return; 1446. } /* up or down */ 1447. 1448. /* normal case: digging across the level */ 1449. shopdoor = shopwall = FALSE; 1450. maze_dig = level.flags.is_maze_lev && !Is_earthlevel(&u.uz); 1451. zx = u.ux + u.dx; 1452. zy = u.uy + u.dy; 1453. if (u.utrap && u.utraptype == TT_PIT 1454. && (trap_with_u = t_at(u.ux, u.uy))) { 1455. pitdig = TRUE; 1456. for (diridx = 0; diridx < 8; diridx++) { 1457. if (xdir[diridx] == u.dx && ydir[diridx] == u.dy) 1458. break; 1459. /* diridx is valid if < 8 */ 1460. } 1461. } 1462. digdepth = rn1(18, 8); 1463. tmp_at(DISP_BEAM, cmap_to_glyph(S_digbeam)); 1464. while (--digdepth >= 0) { 1465. if (!isok(zx, zy)) 1466. break; 1467. room = &levl[zx][zy]; 1468. tmp_at(zx, zy); 1469. delay_output(); /* wait a little bit */ 1470. 1471. if (pitdig) { /* we are already in a pit if this is true */ 1472. coord cc; 1473. struct trap *adjpit = t_at(zx, zy); 1474. if ((diridx < 8) && !conjoined_pits(adjpit, trap_with_u, FALSE)) { 1475. digdepth = 0; /* limited to the adjacent location only */ 1476. if (!(adjpit && is_pit(adjpit->ttyp))) { 1477. char buf[BUFSZ]; 1478. cc.x = zx; 1479. cc.y = zy; 1480. if (!adj_pit_checks(&cc, buf)) { 1481. if (buf[0]) 1482. pline1(buf); 1483. } else { 1484. /* this can also result in a pool at zx,zy */ 1485. dighole(TRUE, TRUE, &cc); 1486. adjpit = t_at(zx, zy); 1487. } 1488. } 1489. if (adjpit 1490. && is_pit(adjpit->ttyp)) { 1491. int adjidx = (diridx + 4) % 8; 1492. trap_with_u->conjoined |= (1 << diridx); 1493. adjpit->conjoined |= (1 << adjidx); 1494. flow_x = zx; 1495. flow_y = zy; 1496. pitflow = TRUE; 1497. } 1498. if (is_pool(zx, zy) || is_lava(zx, zy)) { 1499. flow_x = zx - u.dx; 1500. flow_y = zy - u.dy; 1501. pitflow = TRUE; 1502. } 1503. break; 1504. } 1505. } else if (closed_door(zx, zy) || room->typ == SDOOR) { 1506. if (*in_rooms(zx, zy, SHOPBASE)) { 1507. add_damage(zx, zy, SHOP_DOOR_COST); 1508. shopdoor = TRUE; 1509. } 1510. if (room->typ == SDOOR) 1511. room->typ = DOOR; /* doormask set below */ 1512. else if (cansee(zx, zy)) 1513. pline_The("door is razed!"); 1514. watch_dig((struct monst *) 0, zx, zy, TRUE); 1515. room->doormask = D_NODOOR; 1516. unblock_point(zx, zy); /* vision */ 1517. digdepth -= 2; 1518. if (maze_dig) 1519. break; 1520. } else if (maze_dig) { 1521. if (IS_WALL(room->typ)) { 1522. if (!(room->wall_info & W_NONDIGGABLE)) { 1523. if (*in_rooms(zx, zy, SHOPBASE)) { 1524. add_damage(zx, zy, SHOP_WALL_COST); 1525. shopwall = TRUE; 1526. } 1527. room->typ = ROOM, room->flags = 0; 1528. unblock_point(zx, zy); /* vision */ 1529. } else if (!Blind) 1530. pline_The("wall glows then fades."); 1531. break; 1532. } else if (IS_TREE(room->typ)) { /* check trees before stone */ 1533. if (!(room->wall_info & W_NONDIGGABLE)) { 1534. room->typ = ROOM, room->flags = 0; 1535. unblock_point(zx, zy); /* vision */ 1536. } else if (!Blind) 1537. pline_The("tree shudders but is unharmed."); 1538. break; 1539. } else if (room->typ == STONE || room->typ == SCORR) { 1540. if (!(room->wall_info & W_NONDIGGABLE)) { 1541. room->typ = CORR, room->flags = 0; 1542. unblock_point(zx, zy); /* vision */ 1543. } else if (!Blind) 1544. pline_The("rock glows then fades."); 1545. break; 1546. } 1547. } else if (IS_ROCK(room->typ)) { 1548. if (!may_dig(zx, zy)) 1549. break; 1550. if (IS_WALL(room->typ) || room->typ == SDOOR) { 1551. if (*in_rooms(zx, zy, SHOPBASE)) { 1552. add_damage(zx, zy, SHOP_WALL_COST); 1553. shopwall = TRUE; 1554. } 1555. watch_dig((struct monst *) 0, zx, zy, TRUE); 1556. if (level.flags.is_cavernous_lev && !in_town(zx, zy)) { 1557. room->typ = CORR, room->flags = 0; 1558. } else { 1559. room->typ = DOOR, room->doormask = D_NODOOR; 1560. } 1561. digdepth -= 2; 1562. } else if (IS_TREE(room->typ)) { 1563. room->typ = ROOM, room->flags = 0; 1564. digdepth -= 2; 1565. } else { /* IS_ROCK but not IS_WALL or SDOOR */ 1566. room->typ = CORR, room->flags = 0; 1567. digdepth--; 1568. } 1569. unblock_point(zx, zy); /* vision */ 1570. } 1571. zx += u.dx; 1572. zy += u.dy; 1573. } /* while */ 1574. tmp_at(DISP_END, 0); /* closing call */ 1575. 1576. if (pitflow && isok(flow_x, flow_y)) { 1577. struct trap *ttmp = t_at(flow_x, flow_y); 1578. 1579. if (ttmp && is_pit(ttmp->ttyp)) { 1580. schar filltyp = fillholetyp(ttmp->tx, ttmp->ty, TRUE); 1581. 1582. if (filltyp != ROOM) 1583. pit_flow(ttmp, filltyp); 1584. } 1585. } 1586. 1587. if (shopdoor || shopwall) 1588. pay_for_damage(shopdoor ? "destroy" : "dig into", FALSE); 1589. return; 1590. } 1591. 1592. /* 1593. * This checks what is on the surface above the 1594. * location where an adjacent pit might be created if 1595. * you're zapping a wand of digging laterally while 1596. * down in the pit. 1597. */ 1598. STATIC_OVL int 1599. adj_pit_checks(cc, msg) 1600. coord *cc; 1601. char *msg; 1602. { 1603. int ltyp; 1604. struct rm *room; 1605. const char *foundation_msg = 1606. "The foundation is too hard to dig through from this angle."; 1607. 1608. if (!cc) 1609. return FALSE; 1610. if (!isok(cc->x, cc->y)) 1611. return FALSE; 1612. *msg = '\0'; 1613. room = &levl[cc->x][cc->y]; 1614. ltyp = room->typ, room->flags = 0; 1615. 1616. if (is_pool(cc->x, cc->y) || is_lava(cc->x, cc->y)) { 1617. /* this is handled by the caller after we return FALSE */ 1618. return FALSE; 1619. } else if (closed_door(cc->x, cc->y) || room->typ == SDOOR) { 1620. /* We reject this here because dighole() isn't 1621. prepared to deal with this case */ 1622. Strcpy(msg, foundation_msg); 1623. return FALSE; 1624. } else if (IS_WALL(ltyp)) { 1625. /* if (room->wall_info & W_NONDIGGABLE) */ 1626. Strcpy(msg, foundation_msg); 1627. return FALSE; 1628. } else if (IS_TREE(ltyp)) { /* check trees before stone */ 1629. /* if (room->wall_info & W_NONDIGGABLE) */ 1630. Strcpy(msg, "The tree's roots glow then fade."); 1631. return FALSE; 1632. } else if (ltyp == STONE || ltyp == SCORR) { 1633. if (room->wall_info & W_NONDIGGABLE) { 1634. Strcpy(msg, "The rock glows then fades."); 1635. return FALSE; 1636. } 1637. } else if (ltyp == IRONBARS) { 1638. /* "set of iron bars" */ 1639. Strcpy(msg, "The bars go much deeper than your pit."); 1640. #if 0 1641. } else if (is_lava(cc->x, cc->y)) { 1642. } else if (is_ice(cc->x, cc->y)) { 1643. } else if (is_pool(cc->x, cc->y)) { 1644. } else if (IS_GRAVE(ltyp)) { 1645. #endif 1646. } else if (IS_SINK(ltyp)) { 1647. Strcpy(msg, "A tangled mass of plumbing remains below the sink."); 1648. return FALSE; 1649. } else if ((cc->x == xupladder && cc->y == yupladder) /* ladder up */ 1650. || (cc->x == xdnladder && cc->y == ydnladder)) { /* " down */ 1651. Strcpy(msg, "The ladder is unaffected."); 1652. return FALSE; 1653. } else { 1654. const char *supporting = (const char *) 0; 1655. 1656. if (IS_FOUNTAIN(ltyp)) 1657. supporting = "fountain"; 1658. else if (IS_THRONE(ltyp)) 1659. supporting = "throne"; 1660. else if (IS_ALTAR(ltyp)) 1661. supporting = "altar"; 1662. else if ((cc->x == xupstair && cc->y == yupstair) 1663. || (cc->x == sstairs.sx && cc->y == sstairs.sy 1664. && sstairs.up)) 1665. /* "staircase up" */ 1666. supporting = "stairs"; 1667. else if ((cc->x == xdnstair && cc->y == ydnstair) 1668. || (cc->x == sstairs.sx && cc->y == sstairs.sy 1669. && !sstairs.up)) 1670. /* "staircase down" */ 1671. supporting = "stairs"; 1672. else if (ltyp == DRAWBRIDGE_DOWN /* "lowered drawbridge" */ 1673. || ltyp == DBWALL) /* "raised drawbridge" */ 1674. supporting = "drawbridge"; 1675. 1676. if (supporting) { 1677. Sprintf(msg, "The %s%ssupporting structures remain intact.", 1678. supporting ? s_suffix(supporting) : "", 1679. supporting ? " " : ""); 1680. return FALSE; 1681. } 1682. } 1683. return TRUE; 1684. } 1685. 1686. /* 1687. * Ensure that all conjoined pits fill up. 1688. */ 1689. STATIC_OVL void 1690. pit_flow(trap, filltyp) 1691. struct trap *trap; 1692. schar filltyp; 1693. { 1694. if (trap && filltyp != ROOM && is_pit(trap->ttyp)) { 1695. struct trap t; 1696. int idx; 1697. 1698. t = *trap; 1699. levl[t.tx][t.ty].typ = filltyp, levl[t.tx][t.ty].flags = 0; 1700. liquid_flow(t.tx, t.ty, filltyp, trap, 1701. (t.tx == u.ux && t.ty == u.uy) 1702. ? "Suddenly %s flows in from the adjacent pit!" 1703. : (char *) 0); 1704. for (idx = 0; idx < 8; ++idx) { 1705. if (t.conjoined & (1 << idx)) { 1706. int x, y; 1707. struct trap *t2; 1708. 1709. x = t.tx + xdir[idx]; 1710. y = t.ty + ydir[idx]; 1711. t2 = t_at(x, y); 1712. #if 0 1713. /* cannot do this back-check; liquid_flow() 1714. * called deltrap() which cleaned up the 1715. * conjoined fields on both pits. 1716. */ 1717. if (t2 && (t2->conjoined & (1 << ((idx + 4) % 8)))) 1718. #endif 1719. /* recursion */ 1720. pit_flow(t2, filltyp); 1721. } 1722. } 1723. } 1724. } 1725. 1726. struct obj * 1727. buried_ball(cc) 1728. coord *cc; 1729. { 1730. int odist, bdist = COLNO; 1731. struct obj *otmp, *ball = 0; 1732. 1733. /* FIXME: 1734. * This is just approximate; if multiple buried balls meet the 1735. * criterium (within 2 steps of tethered hero's present location) 1736. * it will find an arbitrary one rather than the one which used 1737. * to be uball. Once 3.6.{0,1} save file compatibility is broken, 1738. * we should add context.buriedball_oid and then we can find the 1739. * actual former uball, which might be extra heavy or christened 1740. * or not the one buried directly underneath the target spot. 1741. * 1742. * [Why does this search within a radius of two when trapmove() 1743. * only lets hero get one step away from the buried ball?] 1744. */ 1745. 1746. if (u.utrap && u.utraptype == TT_BURIEDBALL) 1747. for (otmp = level.buriedobjlist; otmp; otmp = otmp->nobj) { 1748. if (otmp->otyp != HEAVY_IRON_BALL) 1749. continue; 1750. /* if found at the target spot, we're done */ 1751. if (otmp->ox == cc->x && otmp->oy == cc->y) 1752. return otmp; 1753. /* find nearest within allowable vicinity: +/-2 1754. * 4 5 8 1755. * 1 2 5 1756. * 0 1 4 1757. */ 1758. odist = dist2(otmp->ox, otmp->oy, cc->x, cc->y); 1759. if (odist <= 8 && (!ball || odist < bdist)) { 1760. /* remember nearest buried ball but keep checking others */ 1761. ball = otmp; 1762. bdist = odist; 1763. } 1764. } 1765. if (ball) { 1766. /* found, but not at < cc->x, cc->y > */ 1767. cc->x = ball->ox; 1768. cc->y = ball->oy; 1769. } 1770. return ball; 1771. } 1772. 1773. void 1774. buried_ball_to_punishment() 1775. { 1776. coord cc; 1777. struct obj *ball; 1778. 1779. cc.x = u.ux; 1780. cc.y = u.uy; 1781. ball = buried_ball(&cc); 1782. if (ball) { 1783. obj_extract_self(ball); 1784. #if 0 1785. /* rusting buried metallic objects is not implemented yet */ 1786. if (ball->timed) 1787. (void) stop_timer(RUST_METAL, obj_to_any(ball)); 1788. #endif 1789. punish(ball); /* use ball as flag for unearthed buried ball */ 1790. reset_utrap(FALSE); 1791. del_engr_at(cc.x, cc.y); 1792. newsym(cc.x, cc.y); 1793. } 1794. } 1795. 1796. void 1797. buried_ball_to_freedom() 1798. { 1799. coord cc; 1800. struct obj *ball; 1801. 1802. cc.x = u.ux; 1803. cc.y = u.uy; 1804. ball = buried_ball(&cc); 1805. if (ball) { 1806. obj_extract_self(ball); 1807. #if 0 1808. /* rusting buried metallic objects is not implemented yet */ 1809. if (ball->timed) 1810. (void) stop_timer(RUST_METAL, obj_to_any(ball)); 1811. #endif 1812. place_object(ball, cc.x, cc.y); 1813. stackobj(ball); 1814. reset_utrap(TRUE); 1815. del_engr_at(cc.x, cc.y); 1816. newsym(cc.x, cc.y); 1817. } 1818. } 1819. 1820. /* move objects from fobj/nexthere lists to buriedobjlist, keeping position 1821. information */ 1822. struct obj * 1823. bury_an_obj(otmp, dealloced) 1824. struct obj *otmp; 1825. boolean *dealloced; 1826. { 1827. struct obj *otmp2; 1828. boolean under_ice; 1829. 1830. debugpline1("bury_an_obj: %s", xname(otmp)); 1831. if (dealloced) 1832. *dealloced = FALSE; 1833. if (otmp == uball) { 1834. unpunish(); 1835. u.utrap = rn1(50, 20); 1836. u.utraptype = TT_BURIEDBALL; 1837. pline_The("iron ball gets buried!"); 1838. } 1839. /* after unpunish(), or might get deallocated chain */ 1840. otmp2 = otmp->nexthere; 1841. /* 1842. * obj_resists(,0,0) prevents Rider corpses from being buried. 1843. * It also prevents The Amulet and invocation tools from being 1844. * buried. Since they can't be confined to bags and statues, 1845. * it makes sense that they can't be buried either, even though 1846. * the real reason there (direct accessibility when carried) is 1847. * completely different. 1848. */ 1849. if (otmp == uchain || obj_resists(otmp, 0, 0)) 1850. return otmp2; 1851. 1852. if (otmp->otyp == LEASH && otmp->leashmon != 0) 1853. o_unleash(otmp); 1854. 1855. if (otmp->lamplit && otmp->otyp != POT_OIL) 1856. end_burn(otmp, TRUE); 1857. 1858. obj_extract_self(otmp); 1859. 1860. under_ice = is_ice(otmp->ox, otmp->oy); 1861. if (otmp->otyp == ROCK && !under_ice) { 1862. /* merges into burying material */ 1863. if (dealloced) 1864. *dealloced = TRUE; 1865. obfree(otmp, (struct obj *) 0); 1866. return otmp2; 1867. } 1868. /* 1869. * Start a rot on organic material. Not corpses -- they 1870. * are already handled. 1871. */ 1872. if (otmp->otyp == CORPSE) { 1873. ; /* should cancel timer if under_ice */ 1874. } else if ((under_ice ? otmp->oclass == POTION_CLASS : is_organic(otmp)) 1875. && !obj_resists(otmp, 5, 95)) { 1876. (void) start_timer((under_ice ? 0L : 250L) + (long) rnd(250), 1877. TIMER_OBJECT, ROT_ORGANIC, obj_to_any(otmp)); 1878. #if 0 1879. /* rusting of buried metal not yet implemented */ 1880. } else if (is_rustprone(otmp)) { 1881. (void) start_timer((long) rnd((otmp->otyp == HEAVY_IRON_BALL) 1882. ? 1500 1883. : 250), 1884. TIMER_OBJECT, RUST_METAL, obj_to_any(otmp)); 1885. #endif 1886. } 1887. add_to_buried(otmp); 1888. return otmp2; 1889. } 1890. 1891. void 1892. bury_objs(x, y) 1893. int x, y; 1894. { 1895. struct obj *otmp, *otmp2; 1896. struct monst *shkp; 1897. long loss = 0L; 1898. boolean costly; 1899. 1900. costly = ((shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) 1901. && costly_spot(x, y)); 1902. 1903. if (level.objects[x][y] != (struct obj *) 0) { 1904. debugpline2("bury_objs: at <%d,%d>", x, y); 1905. } 1906. for (otmp = level.objects[x][y]; otmp; otmp = otmp2) { 1907. if (costly) { 1908. loss += stolen_value(otmp, x, y, (boolean) shkp->mpeaceful, TRUE); 1909. if (otmp->oclass != COIN_CLASS) 1910. otmp->no_charge = 1; 1911. } 1912. otmp2 = bury_an_obj(otmp, (boolean *) 0); 1913. } 1914. 1915. /* don't expect any engravings here, but just in case */ 1916. del_engr_at(x, y); 1917. newsym(x, y); 1918. 1919. if (costly && loss) { 1920. You("owe %s %ld %s for burying merchandise.", mon_nam(shkp), loss, 1921. currency(loss)); 1922. } 1923. } 1924. 1925. /* move objects from buriedobjlist to fobj/nexthere lists */ 1926. void 1927. unearth_objs(x, y) 1928. int x, y; 1929. { 1930. struct obj *otmp, *otmp2, *bball; 1931. coord cc; 1932. 1933. debugpline2("unearth_objs: at <%d,%d>", x, y); 1934. cc.x = x; 1935. cc.y = y; 1936. bball = buried_ball(&cc); 1937. for (otmp = level.buriedobjlist; otmp; otmp = otmp2) { 1938. otmp2 = otmp->nobj; 1939. if (otmp->ox == x && otmp->oy == y) { 1940. if (bball && otmp == bball 1941. && u.utrap && u.utraptype == TT_BURIEDBALL) { 1942. buried_ball_to_punishment(); 1943. } else { 1944. obj_extract_self(otmp); 1945. if (otmp->timed) 1946. (void) stop_timer(ROT_ORGANIC, obj_to_any(otmp)); 1947. place_object(otmp, x, y); 1948. stackobj(otmp); 1949. } 1950. } 1951. } 1952. del_engr_at(x, y); 1953. newsym(x, y); 1954. } 1955. 1956. /* 1957. * The organic material has rotted away while buried. As an expansion, 1958. * we could add add partial damage. A damage count is kept in the object 1959. * and every time we are called we increment the count and reschedule another 1960. * timeout. Eventually the object rots away. 1961. * 1962. * This is used by buried objects other than corpses. When a container rots 1963. * away, any contents become newly buried objects. 1964. */ 1965. /* ARGSUSED */ 1966. void 1967. rot_organic(arg, timeout) 1968. anything *arg; 1969. long timeout UNUSED; 1970. { 1971. struct obj *obj = arg->a_obj; 1972. 1973. while (Has_contents(obj)) { 1974. /* We don't need to place contained object on the floor 1975. first, but we do need to update its map coordinates. */ 1976. obj->cobj->ox = obj->ox, obj->cobj->oy = obj->oy; 1977. /* Everything which can be held in a container can also be 1978. buried, so bury_an_obj's use of obj_extract_self insures 1979. that Has_contents(obj) will eventually become false. */ 1980. (void) bury_an_obj(obj->cobj, (boolean *) 0); 1981. } 1982. obj_extract_self(obj); 1983. obfree(obj, (struct obj *) 0); 1984. } 1985. 1986. /* 1987. * Called when a corpse has rotted completely away. 1988. */ 1989. void 1990. rot_corpse(arg, timeout) 1991. anything *arg; 1992. long timeout; 1993. { 1994. xchar x = 0, y = 0; 1995. struct obj *obj = arg->a_obj; 1996. boolean on_floor = obj->where == OBJ_FLOOR, 1997. in_invent = obj->where == OBJ_INVENT; 1998. 1999. if (on_floor) { 2000. x = obj->ox; 2001. y = obj->oy; 2002. } else if (in_invent) { 2003. if (flags.verbose) { 2004. char *cname = corpse_xname(obj, (const char *) 0, CXN_NO_PFX); 2005. 2006. Your("%s%s %s away%c", obj == uwep ? "wielded " : "", cname, 2007. otense(obj, "rot"), obj == uwep ? '!' : '.'); 2008. } 2009. if (obj == uwep) { 2010. uwepgone(); /* now bare handed */ 2011. stop_occupation(); 2012. } else if (obj == uswapwep) { 2013. uswapwepgone(); 2014. stop_occupation(); 2015. } else if (obj == uquiver) { 2016. uqwepgone(); 2017. stop_occupation(); 2018. } 2019. } else if (obj->where == OBJ_MINVENT && obj->owornmask) { 2020. if (obj == MON_WEP(obj->ocarry)) 2021. setmnotwielded(obj->ocarry, obj); 2022. } else if (obj->where == OBJ_MIGRATING) { 2023. /* clear destination flag so that obfree()'s check for 2024. freeing a worn object doesn't get a false hit */ 2025. obj->owornmask = 0L; 2026. } 2027. rot_organic(arg, timeout); 2028. if (on_floor) { 2029. struct monst *mtmp = m_at(x, y); 2030. 2031. /* a hiding monster may be exposed */ 2032. if (mtmp && !OBJ_AT(x, y) && mtmp->mundetected 2033. && hides_under(mtmp->data)) { 2034. mtmp->mundetected = 0; 2035. } else if (x == u.ux && y == u.uy && u.uundetected && hides_under(youmonst.data)) 2036. (void) hideunder(&youmonst); 2037. newsym(x, y); 2038. } else if (in_invent) 2039. update_inventory(); 2040. } 2041. 2042. #if 0 2043. void 2044. bury_monst(mtmp) 2045. struct monst *mtmp; 2046. { 2047. debugpline1("bury_monst: %s", mon_nam(mtmp)); 2048. if (canseemon(mtmp)) { 2049. if (is_flyer(mtmp->data) || is_floater(mtmp->data)) { 2050. pline_The("%s opens up, but %s is not swallowed!", 2051. surface(mtmp->mx, mtmp->my), mon_nam(mtmp)); 2052. return; 2053. } else 2054. pline_The("%s opens up and swallows %s!", 2055. surface(mtmp->mx, mtmp->my), mon_nam(mtmp)); 2056. } 2057. 2058. mtmp->mburied = TRUE; 2059. wakeup(mtmp, FALSE); /* at least give it a chance :-) */ 2060. newsym(mtmp->mx, mtmp->my); 2061. } 2062. 2063. void 2064. bury_you() 2065. { 2066. debugpline0("bury_you"); 2067. if (!Levitation && !Flying) { 2068. if (u.uswallow) 2069. You_feel("a sensation like falling into a trap!"); 2070. else 2071. pline_The("%s opens beneath you and you fall in!", 2072. surface(u.ux, u.uy)); 2073. 2074. u.uburied = TRUE; 2075. if (!Strangled && !Breathless) 2076. Strangled = 6; 2077. under_ground(1); 2078. } 2079. } 2080. 2081. void 2082. unearth_you() 2083. { 2084. debugpline0("unearth_you"); 2085. u.uburied = FALSE; 2086. under_ground(0); 2087. if (!uamul || uamul->otyp != AMULET_OF_STRANGULATION) 2088. Strangled = 0; 2089. vision_recalc(0); 2090. } 2091. 2092. void 2093. escape_tomb() 2094. { 2095. debugpline0("escape_tomb"); 2096. if ((Teleportation || can_teleport(youmonst.data)) 2097. && (Teleport_control || rn2(3) < Luck+2)) { 2098. You("attempt a teleport spell."); 2099. (void) dotele(FALSE); /* calls unearth_you() */ 2100. } else if (u.uburied) { /* still buried after 'port attempt */ 2101. boolean good; 2102. 2103. if (amorphous(youmonst.data) || Passes_walls 2104. || noncorporeal(youmonst.data) 2105. || (unsolid(youmonst.data) 2106. && youmonst.data != &mons[PM_WATER_ELEMENTAL]) 2107. || (tunnels(youmonst.data) && !needspick(youmonst.data))) { 2108. You("%s up through the %s.", 2109. (tunnels(youmonst.data) && !needspick(youmonst.data)) 2110. ? "try to tunnel" 2111. : (amorphous(youmonst.data)) 2112. ? "ooze" 2113. : "phase", 2114. surface(u.ux, u.uy)); 2115. 2116. good = (tunnels(youmonst.data) && !needspick(youmonst.data)) 2117. ? dighole(TRUE, FALSE, (coord *)0) : TRUE; 2118. if (good) 2119. unearth_you(); 2120. } 2121. } 2122. } 2123. 2124. void 2125. bury_obj(otmp) 2126. struct obj *otmp; 2127. { 2128. debugpline0("bury_obj"); 2129. if (cansee(otmp->ox, otmp->oy)) 2130. pline_The("objects on the %s tumble into a hole!", 2131. surface(otmp->ox, otmp->oy)); 2132. 2133. bury_objs(otmp->ox, otmp->oy); 2134. } 2135. #endif /*0*/ 2136. 2137. #ifdef DEBUG 2138. /* bury everything at your loc and around */ 2139. int 2140. wiz_debug_cmd_bury() 2141. { 2142. int x, y; 2143. 2144. for (x = u.ux - 1; x <= u.ux + 1; x++) 2145. for (y = u.uy - 1; y <= u.uy + 1; y++) 2146. if (isok(x, y)) 2147. bury_objs(x, y); 2148. return 0; 2149. } 2150. #endif /* DEBUG */ 2151. 2152. /*dig.c*/