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