Source:NetHack 3.4.3/src/dig.c

From NetHackWiki
(Redirected from Source:Ref/bury objs)
Jump to: navigation, search

Below is the full text to src/dig.c from NetHack 3.4.3. To link to a particular line, write [[dig.c#line123]], for example.

Top of file

  1. /*	SCCS Id: @(#)dig.c	3.4	2003/03/23	*/
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */

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. #include "hack.h"
  2. #include "edog.h"
  3. /* #define DEBUG */	/* turn on for diagnostics */
  4.  
  5. #ifdef OVLB
  6.  
  7. static NEARDATA boolean did_dig_msg;
  8.  
  9. STATIC_DCL boolean NDECL(rm_waslit);
  10. STATIC_DCL void FDECL(mkcavepos, (XCHAR_P,XCHAR_P,int,BOOLEAN_P,BOOLEAN_P));
  11. STATIC_DCL void FDECL(mkcavearea, (BOOLEAN_P));
  12. STATIC_DCL int FDECL(dig_typ, (struct obj *,XCHAR_P,XCHAR_P));
  13. STATIC_DCL int NDECL(dig);
  14. STATIC_DCL schar FDECL(fillholetyp, (int, int));
  15. STATIC_DCL void NDECL(dig_up_grave);
  16.  
  17. /* Indices returned by dig_typ() */
  18. #define DIGTYP_UNDIGGABLE 0
  19. #define DIGTYP_ROCK       1
  20. #define DIGTYP_STATUE     2
  21. #define DIGTYP_BOULDER    3
  22. #define DIGTYP_DOOR       4
  23. #define DIGTYP_TREE       5

rm_waslit

  1. STATIC_OVL boolean
  2. rm_waslit()
  3. {
  4. register xchar x, y;
  5.  
  6. if(levl[u.ux][u.uy].typ == ROOM && levl[u.ux][u.uy].waslit)
  7. 	return(TRUE);
  8. for(x = u.ux-2; x < u.ux+3; x++)
  9. 	for(y = u.uy-1; y < u.uy+2; y++)
  10. 	    if(isok(x,y) && levl[x][y].waslit) return(TRUE);
  11. return(FALSE);
  12. }

mkcavepos

  1. /* Change level topology.  Messes with vision tables and ignores things like
  2. * boulders in the name of a nice effect.  Vision will get fixed up again
  3. * immediately after the effect is complete.
  4. */
  5. STATIC_OVL void
  6. mkcavepos(x, y, dist, waslit, rockit)
  7. xchar x,y;
  8. int dist;
  9. boolean waslit, rockit;
  10. {
  11. register struct rm *lev;
  12.  
  13. if(!isok(x,y)) return;
  14. lev = &levl[x][y];
  15.  
  16. if(rockit) {
  17. 	register struct monst *mtmp;
  18.  
  19. 	if(IS_ROCK(lev->typ)) return;
  20. 	if(t_at(x, y)) return; /* don't cover the portal */
  21. 	if ((mtmp = m_at(x, y)) != 0)	/* make sure crucial monsters survive */
  22. 	    if(!passes_walls(mtmp->data)) (void) rloc(mtmp, FALSE);
  23. } else if(lev->typ == ROOM) return;
  24.  
  25. unblock_point(x,y);	/* make sure vision knows this location is open */
  26.  
  27. /* fake out saved state */
  28. lev->seenv = 0;
  29. lev->doormask = 0;
  30. if(dist < 3) lev->lit = (rockit ? FALSE : TRUE);
  31. if(waslit) lev->waslit = (rockit ? FALSE : TRUE);
  32. lev->horizontal = FALSE;
  33. viz_array[y][x] = (dist < 3 ) ?
  34. 	(IN_SIGHT|COULD_SEE) : /* short-circuit vision recalc */
  35. 	COULD_SEE;
  36. lev->typ = (rockit ? STONE : ROOM);
  37. if(dist >= 3)
  38. 	impossible("mkcavepos called with dist %d", dist);
  39. if(Blind)
  40. 	feel_location(x, y);
  41. else newsym(x,y);
  42. }

mkcavearea

  1. STATIC_OVL void
  2. mkcavearea(rockit)
  3. register boolean rockit;
  4. {
  5. int dist;
  6. xchar xmin = u.ux, xmax = u.ux;
  7. xchar ymin = u.uy, ymax = u.uy;
  8. register xchar i;
  9. register boolean waslit = rm_waslit();
  10.  
  11. if(rockit) pline("Crash!  The ceiling collapses around you!");
  12. else pline("A mysterious force %s cave around you!",
  13. 	     (levl[u.ux][u.uy].typ == CORR) ? "creates a" : "extends the");
  14. display_nhwindow(WIN_MESSAGE, TRUE);
  15.  
  16. for(dist = 1; dist <= 2; dist++) {
  17. 	xmin--; xmax++;
  18.  
  19. 	/* top and bottom */
  20. 	if(dist < 2) { /* the area is wider that it is high */
  21. 	    ymin--; ymax++;
  22. 	    for(i = xmin+1; i < xmax; i++) {
  23. 		mkcavepos(i, ymin, dist, waslit, rockit);
  24. 		mkcavepos(i, ymax, dist, waslit, rockit);
  25. 	    }
  26. 	}
  27.  
  28. 	/* left and right */
  29. 	for(i = ymin; i <= ymax; i++) {
  30. 	    mkcavepos(xmin, i, dist, waslit, rockit);
  31. 	    mkcavepos(xmax, i, dist, waslit, rockit);
  32. 	}
  33.  
  34. 	flush_screen(1);	/* make sure the new glyphs shows up */
  35. 	delay_output();
  36. }
  37.  
  38. if(!rockit && levl[u.ux][u.uy].typ == CORR) {
  39. 	levl[u.ux][u.uy].typ = ROOM;
  40. 	if(waslit) levl[u.ux][u.uy].waslit = TRUE;
  41. 	newsym(u.ux, u.uy); /* in case player is invisible */
  42. }
  43.  
  44. vision_full_recalc = 1;	/* everything changed */
  45. }

dig_typ

  1. /* When digging into location <x,y>, what are you actually digging into? */
  2. STATIC_OVL int
  3. dig_typ(otmp, x, y)
  4. struct obj *otmp;
  5. xchar x, y;
  6. {
  7. 	boolean ispick = is_pick(otmp);
  8.  
  9. 	return (ispick && sobj_at(STATUE, x, y) ? DIGTYP_STATUE :
  10. 		ispick && sobj_at(BOULDER, x, y) ? DIGTYP_BOULDER :
  11. 		closed_door(x, y) ? DIGTYP_DOOR :
  12. 		IS_TREE(levl[x][y].typ) ?
  13. 			(ispick ? DIGTYP_UNDIGGABLE : DIGTYP_TREE) :
  14. 		ispick && IS_ROCK(levl[x][y].typ) &&
  15. 			(!level.flags.arboreal || IS_WALL(levl[x][y].typ)) ?
  16. 			DIGTYP_ROCK : DIGTYP_UNDIGGABLE);
  17. }

is_digging

  1. boolean
  2. is_digging()
  3. {
  4. 	if (occupation == dig) {
  5. 	    return TRUE;
  6. 	}
  7. 	return FALSE;
  8. }

dig_check

  1. #define BY_YOU		(&youmonst)
  2. #define BY_OBJECT	((struct monst *)0)
  3.  
  4. boolean
  5. dig_check(madeby, verbose, x, y)
  6. 	struct monst	*madeby;
  7. 	boolean		verbose;
  8. 	int		x, y;
  9. {
  10. 	struct trap *ttmp = t_at(x, y);
  11. 	const char *verb = (madeby == BY_YOU && uwep && is_axe(uwep)) ? "chop" : "dig in";
  12.  
  13. 	if (On_stairs(x, y)) {
  14. 	    if (x == xdnladder || x == xupladder) {
  15. 		if(verbose) pline_The("ladder resists your effort.");
  16. 	    } else if(verbose) pline_The("stairs are too hard to %s.", verb);
  17. 	    return(FALSE);
  18. 	} else if (IS_THRONE(levl[x][y].typ) && madeby != BY_OBJECT) {
  19. 	    if(verbose) pline_The("throne is too hard to break apart.");
  20. 	    return(FALSE);
  21. 	} else if (IS_ALTAR(levl[x][y].typ) && (madeby != BY_OBJECT ||
  22. 				Is_astralevel(&u.uz) || Is_sanctum(&u.uz))) {
  23. 	    if(verbose) pline_The("altar is too hard to break apart.");
  24. 	    return(FALSE);
  25. 	} else if (Is_airlevel(&u.uz)) {
  26. 	    if(verbose) You("cannot %s thin air.", verb);
  27. 	    return(FALSE);
  28. 	} else if (Is_waterlevel(&u.uz)) {
  29. 	    if(verbose) pline_The("water splashes and subsides.");
  30. 	    return(FALSE);
  31. 	} else if ((IS_ROCK(levl[x][y].typ) && levl[x][y].typ != SDOOR &&
  32. 		      (levl[x][y].wall_info & W_NONDIGGABLE) != 0)
  33. 		|| (ttmp &&
  34. 		      (ttmp->ttyp == MAGIC_PORTAL || !Can_dig_down(&u.uz)))) {
  35. 	    if(verbose) pline_The("%s here is too hard to %s.",
  36. 				  surface(x,y), verb);
  37. 	    return(FALSE);
  38. 	} else if (sobj_at(BOULDER, x, y)) {
  39. 	    if(verbose) There("isn't enough room to %s here.", verb);
  40. 	    return(FALSE);
  41. 	} else if (madeby == BY_OBJECT &&
  42. 		    /* the block against existing traps is mainly to
  43. 		       prevent broken wands from turning holes into pits */
  44. 		    (ttmp || is_pool(x,y) || is_lava(x,y))) {
  45. 	    /* digging by player handles pools separately */
  46. 	    return FALSE;
  47. 	}
  48. 	return(TRUE);
  49. }

dig

  1. STATIC_OVL int
  2. dig()
  3. {
  4. 	register struct rm *lev;
  5. 	register xchar dpx = digging.pos.x, dpy = digging.pos.y;
  6. 	register boolean ispick = uwep && is_pick(uwep);
  7. 	const char *verb =
  8. 	    (!uwep || is_pick(uwep)) ? "dig into" : "chop through";
  9.  
  10. 	lev = &levl[dpx][dpy];
  11. 	/* perhaps a nymph stole your pick-axe while you were busy digging */
  12. 	/* or perhaps you teleported away */
  13. 	if (u.uswallow || !uwep || (!ispick && !is_axe(uwep)) ||
  14. 	    !on_level(&digging.level, &u.uz) ||
  15. 	    ((digging.down ? (dpx != u.ux || dpy != u.uy)
  16. 			   : (distu(dpx,dpy) > 2))))
  17. 		return(0);
  18.  
  19. 	if (digging.down) {
  20. 	    if(!dig_check(BY_YOU, TRUE, u.ux, u.uy)) return(0);
  21. 	} else { /* !digging.down */
  22. 	    if (IS_TREE(lev->typ) && !may_dig(dpx,dpy) &&
  23. 			dig_typ(uwep, dpx, dpy) == DIGTYP_TREE) {
  24. 		pline("This tree seems to be petrified.");
  25. 		return(0);
  26. 	    }
  27. 	    if (IS_ROCK(lev->typ) && !may_dig(dpx,dpy) &&
  28. 			dig_typ(uwep, dpx, dpy) == DIGTYP_ROCK) {
  29. 		pline("This wall is too hard to %s.", verb);
  30. 		return(0);
  31. 	    }
  32. 	}
  33. 	if(Fumbling && !rn2(3)) {
  34. 	    switch(rn2(3)) {
  35. 	    case 0:
  36. 		if(!welded(uwep)) {
  37. 		    You("fumble and drop your %s.", xname(uwep));
  38. 		    dropx(uwep);
  39. 		} else {
  40. #ifdef STEED
  41. 		    if (u.usteed)
  42. 			Your("%s %s and %s %s!",
  43. 			     xname(uwep),
  44. 			     otense(uwep, "bounce"), otense(uwep, "hit"),
  45. 			     mon_nam(u.usteed));
  46. 		    else
  47. #endif
  48. 			pline("Ouch!  Your %s %s and %s you!",
  49. 			      xname(uwep),
  50. 			      otense(uwep, "bounce"), otense(uwep, "hit"));
  51. 		    set_wounded_legs(RIGHT_SIDE, 5 + rnd(5));
  52. 		}
  53. 		break;
  54. 	    case 1:
  55. 		pline("Bang!  You hit with the broad side of %s!",
  56. 		      the(xname(uwep)));
  57. 		break;
  58. 	    default: Your("swing misses its mark.");
  59. 		break;
  60. 	    }
  61. 	    return(0);
  62. 	}
  63.  
  64. 	digging.effort += 10 + rn2(5) + abon() +
  65. 			   uwep->spe - greatest_erosion(uwep) + u.udaminc;
  66. 	if (Race_if(PM_DWARF))
  67. 	    digging.effort *= 2;
  68. 	if (digging.down) {
  69. 		register struct trap *ttmp;
  70.  
  71. 		if (digging.effort > 250) {
  72. 		    (void) dighole(FALSE);
  73. 		    (void) memset((genericptr_t)&digging, 0, sizeof digging);
  74. 		    return(0);	/* done with digging */
  75. 		}
  76.  
  77. 		if (digging.effort <= 50 ||
  78. 		    ((ttmp = t_at(dpx,dpy)) != 0 &&
  79. 			(ttmp->ttyp == PIT || ttmp->ttyp == SPIKED_PIT ||
  80. 			 ttmp->ttyp == TRAPDOOR || ttmp->ttyp == HOLE)))
  81. 		    return(1);
  82.  
  83. 		if (IS_ALTAR(lev->typ)) {
  84. 		    altar_wrath(dpx, dpy);
  85. 		    angry_priest();
  86. 		}
  87.  
  88. 		if (dighole(TRUE)) {	/* make pit at &lt;u.ux,u.uy> */
  89. 		    digging.level.dnum = 0;
  90. 		    digging.level.dlevel = -1;
  91. 		}
  92. 		return(0);
  93. 	}
  94.  
  95. 	if (digging.effort > 100) {
  96. 		register const char *digtxt, *dmgtxt = (const char*) 0;
  97. 		register struct obj *obj;
  98. 		register boolean shopedge = *in_rooms(dpx, dpy, SHOPBASE);
  99.  
  100. 		if ((obj = sobj_at(STATUE, dpx, dpy)) != 0) {
  101. 			if (break_statue(obj))
  102. 				digtxt = "The statue shatters.";
  103. 			else
  104. 				/* it was a statue trap; break_statue()
  105. 				 * printed a message and updated the screen
  106. 				 */
  107. 				digtxt = (char *)0;
  108. 		} else if ((obj = sobj_at(BOULDER, dpx, dpy)) != 0) {
  109. 			struct obj *bobj;
  110.  
  111. 			fracture_rock(obj);
  112. 			if ((bobj = sobj_at(BOULDER, dpx, dpy)) != 0) {
  113. 			    /* another boulder here, restack it to the top */
  114. 			    obj_extract_self(bobj);
  115. 			    place_object(bobj, dpx, dpy);
  116. 			}
  117. 			digtxt = "The boulder falls apart.";
  118. 		} else if (lev->typ == STONE || lev->typ == SCORR ||
  119. 				IS_TREE(lev->typ)) {
  120. 			if(Is_earthlevel(&u.uz)) {
  121. 			    if(uwep->blessed && !rn2(3)) {
  122. 				mkcavearea(FALSE);
  123. 				goto cleanup;
  124. 			    } else if((uwep->cursed && !rn2(4)) ||
  125. 					  (!uwep->blessed && !rn2(6))) {
  126. 				mkcavearea(TRUE);
  127. 				goto cleanup;
  128. 			    }
  129. 			}
  130. 			if (IS_TREE(lev->typ)) {
  131. 			    digtxt = "You cut down the tree.";
  132. 			    lev->typ = ROOM;
  133. 			    if (!rn2(5)) (void) rnd_treefruit_at(dpx, dpy);
  134. 			} else {
  135. 			    digtxt = "You succeed in cutting away some rock.";
  136. 			    lev->typ = CORR;
  137. 			}
  138. 		} else if(IS_WALL(lev->typ)) {
  139. 			if(shopedge) {
  140. 			    add_damage(dpx, dpy, 10L * ACURRSTR);
  141. 			    dmgtxt = "damage";
  142. 			}
  143. 			if (level.flags.is_maze_lev) {
  144. 			    lev->typ = ROOM;
  145. 			} else if (level.flags.is_cavernous_lev &&
  146. 				   !in_town(dpx, dpy)) {
  147. 			    lev->typ = CORR;
  148. 			} else {
  149. 			    lev->typ = DOOR;
  150. 			    lev->doormask = D_NODOOR;
  151. 			}
  152. 			digtxt = "You make an opening in the wall.";
  153. 		} else if(lev->typ == SDOOR) {
  154. 			cvt_sdoor_to_door(lev);	/* ->typ = DOOR */
  155. 			digtxt = "You break through a secret door!";
  156. 			if(!(lev->doormask & D_TRAPPED))
  157. 				lev->doormask = D_BROKEN;
  158. 		} else if(closed_door(dpx, dpy)) {
  159. 			digtxt = "You break through the door.";
  160. 			if(shopedge) {
  161. 			    add_damage(dpx, dpy, 400L);
  162. 			    dmgtxt = "break";
  163. 			}
  164. 			if(!(lev->doormask & D_TRAPPED))
  165. 				lev->doormask = D_BROKEN;
  166. 		} else return(0); /* statue or boulder got taken */
  167.  
  168. 		if(!does_block(dpx,dpy,&levl[dpx][dpy]))
  169. 		    unblock_point(dpx,dpy);	/* vision:  can see through */
  170. 		if(Blind)
  171. 		    feel_location(dpx, dpy);
  172. 		else
  173. 		    newsym(dpx, dpy);
  174. 		if(digtxt && !digging.quiet) pline(digtxt); /* after newsym */
  175. 		if(dmgtxt)
  176. 		    pay_for_damage(dmgtxt, FALSE);
  177.  
  178. 		if(Is_earthlevel(&u.uz) && !rn2(3)) {
  179. 		    register struct monst *mtmp;
  180.  
  181. 		    switch(rn2(2)) {
  182. 		      case 0:
  183. 			mtmp = makemon(&mons[PM_EARTH_ELEMENTAL],
  184. 					dpx, dpy, NO_MM_FLAGS);
  185. 			break;
  186. 		      default:
  187. 			mtmp = makemon(&mons[PM_XORN],
  188. 					dpx, dpy, NO_MM_FLAGS);
  189. 			break;
  190. 		    }
  191. 		    if(mtmp) pline_The("debris from your digging comes to life!");
  192. 		}
  193. 		if(IS_DOOR(lev->typ) && (lev->doormask & D_TRAPPED)) {
  194. 			lev->doormask = D_NODOOR;
  195. 			b_trapped("door", 0);
  196. 			newsym(dpx, dpy);
  197. 		}
  198. cleanup:
  199. 		digging.lastdigtime = moves;
  200. 		digging.quiet = FALSE;
  201. 		digging.level.dnum = 0;
  202. 		digging.level.dlevel = -1;
  203. 		return(0);
  204. 	} else {		/* not enough effort has been spent yet */
  205. 		static const char *const d_target[6] = {
  206. 			"", "rock", "statue", "boulder", "door", "tree"
  207. 		};
  208. 		int dig_target = dig_typ(uwep, dpx, dpy);
  209.  
  210. 		if (IS_WALL(lev->typ) || dig_target == DIGTYP_DOOR) {
  211. 		    if(*in_rooms(dpx, dpy, SHOPBASE)) {
  212. 			pline("This %s seems too hard to %s.",
  213. 			      IS_DOOR(lev->typ) ? "door" : "wall", verb);
  214. 			return(0);
  215. 		    }
  216. 		} else if (!IS_ROCK(lev->typ) && dig_target == DIGTYP_ROCK)
  217. 		    return(0); /* statue or boulder got taken */
  218. 		if(!did_dig_msg) {
  219. 		    You("hit the %s with all your might.",
  220. 			d_target[dig_target]);
  221. 		    did_dig_msg = TRUE;
  222. 		}
  223. 	}
  224. 	return(1);
  225. }

holetime

  1. /* When will hole be finished? Very rough indication used by shopkeeper. */
  2. int
  3. holetime()
  4. {
  5. 	if(occupation != dig || !*u.ushops) return(-1);
  6. 	return ((250 - digging.effort) / 20);
  7. }

fillholetyp

  1. /* Return typ of liquid to fill a hole with, or ROOM, if no liquid nearby */
  2. STATIC_OVL
  3. schar
  4. fillholetyp(x,y)
  5. int x, y;
  6. {
  7. register int x1, y1;
  8. int lo_x = max(1,x-1), hi_x = min(x+1,COLNO-1),
  9. 	lo_y = max(0,y-1), hi_y = min(y+1,ROWNO-1);
  10. int pool_cnt = 0, moat_cnt = 0, lava_cnt = 0;
  11.  
  12. for (x1 = lo_x; x1 <= hi_x; x1++)
  13. 	for (y1 = lo_y; y1 <= hi_y; y1++)
  14. 	    if (levl[x1][y1].typ == POOL)
  15. 		pool_cnt++;
  16. 	    else if (levl[x1][y1].typ == MOAT ||
  17. 		    (levl[x1][y1].typ == DRAWBRIDGE_UP &&
  18. 			(levl[x1][y1].drawbridgemask & DB_UNDER) == DB_MOAT))
  19. 		moat_cnt++;
  20. 	    else if (levl[x1][y1].typ == LAVAPOOL ||
  21. 		    (levl[x1][y1].typ == DRAWBRIDGE_UP &&
  22. 			(levl[x1][y1].drawbridgemask & DB_UNDER) == DB_LAVA))
  23. 		lava_cnt++;
  24. pool_cnt /= 3;		/* not as much liquid as the others */
  25.  
  26. if (lava_cnt > moat_cnt + pool_cnt && rn2(lava_cnt + 1))
  27. 	return LAVAPOOL;
  28. else if (moat_cnt > 0 && rn2(moat_cnt + 1))
  29. 	return MOAT;
  30. else if (pool_cnt > 0 && rn2(pool_cnt + 1))
  31. 	return POOL;
  32. else
  33. 	return ROOM;
  34. }

digactualhole

  1. void
  2. digactualhole(x, y, madeby, ttyp)
  3. register int	x, y;
  4. struct monst	*madeby;
  5. int ttyp;
  6. {
  7. 	struct obj *oldobjs, *newobjs;
  8. 	register struct trap *ttmp;
  9. 	char surface_type[BUFSZ];
  10. 	struct rm *lev = &levl[x][y];
  11. 	boolean shopdoor;
  12. 	struct monst *mtmp = m_at(x, y);	/* may be madeby */
  13. 	boolean madeby_u = (madeby == BY_YOU);
  14. 	boolean madeby_obj = (madeby == BY_OBJECT);
  15. 	boolean at_u = (x == u.ux) && (y == u.uy);
  16. 	boolean wont_fall = Levitation || Flying;
  17.  
  18. 	if (u.utrap && u.utraptype == TT_INFLOOR) u.utrap = 0;
  19.  
  20. 	/* these furniture checks were in dighole(), but wand
  21. 	   breaking bypasses that routine and calls us directly */
  22. 	if (IS_FOUNTAIN(lev->typ)) {
  23. 	    dogushforth(FALSE);
  24. 	    SET_FOUNTAIN_WARNED(x,y);		/* force dryup */
  25. 	    dryup(x, y, madeby_u);
  26. 	    return;
  27. #ifdef SINKS
  28. 	} else if (IS_SINK(lev->typ)) {
  29. 	    breaksink(x, y);
  30. 	    return;
  31. #endif
  32. 	} else if (lev->typ == DRAWBRIDGE_DOWN ||
  33. 		   (is_drawbridge_wall(x, y) >= 0)) {
  34. 	    int bx = x, by = y;
  35. 	    /* if under the portcullis, the bridge is adjacent */
  36. 	    (void) find_drawbridge(&bx, &by);
  37. 	    destroy_drawbridge(bx, by);
  38. 	    return;
  39. 	}
  40.  
  41. 	if (ttyp != PIT && !Can_dig_down(&u.uz)) {
  42. 	    impossible("digactualhole: can't dig %s on this level.",
  43. 		       defsyms[trap_to_defsym(ttyp)].explanation);
  44. 	    ttyp = PIT;
  45. 	}
  46.  
  47. 	/* maketrap() might change it, also, in this situation,
  48. 	   surface() returns an inappropriate string for a grave */
  49. 	if (IS_GRAVE(lev->typ))
  50. 	    Strcpy(surface_type, "grave");
  51. 	else
  52. 	    Strcpy(surface_type, surface(x,y));
  53. 	shopdoor = IS_DOOR(lev->typ) && *in_rooms(x, y, SHOPBASE);
  54. 	oldobjs = level.objects[x][y];
  55. 	ttmp = maketrap(x, y, ttyp);
  56. 	if (!ttmp) return;
  57. 	newobjs = level.objects[x][y];
  58. 	ttmp->tseen = (madeby_u || cansee(x,y));
  59. 	ttmp->madeby_u = madeby_u;
  60. 	newsym(ttmp->tx,ttmp->ty);
  61.  
  62. 	if (ttyp == PIT) {
  63.  
  64. 	    if(madeby_u) {
  65. 		You("dig a pit in the %s.", surface_type);
  66. 		if (shopdoor) pay_for_damage("ruin", FALSE);
  67. 	    } else if (!madeby_obj && canseemon(madeby))
  68. 		pline("%s digs a pit in the %s.", Monnam(madeby), surface_type);
  69. 	    else if (cansee(x, y) && flags.verbose)
  70. 		pline("A pit appears in the %s.", surface_type);
  71.  
  72. 	    if(at_u) {
  73. 		if (!wont_fall) {
  74. 		    if (!Passes_walls)
  75. 			u.utrap = rn1(4,2);
  76. 		    u.utraptype = TT_PIT;
  77. 		    vision_full_recalc = 1;	/* vision limits change */
  78. 		} else
  79. 		    u.utrap = 0;
  80. 		if (oldobjs != newobjs)	/* something unearthed */
  81. 			(void) pickup(1);	/* detects pit */
  82. 	    } else if(mtmp) {
  83. 		if(is_flyer(mtmp->data) || is_floater(mtmp->data)) {
  84. 		    if(canseemon(mtmp))
  85. 			pline("%s %s over the pit.", Monnam(mtmp),
  86. 						     (is_flyer(mtmp->data)) ?
  87. 						     "flies" : "floats");
  88. 		} else if(mtmp != madeby)
  89. 		    (void) mintrap(mtmp);
  90. 	    }
  91. 	} else {	/* was TRAPDOOR now a HOLE*/
  92.  
  93. 	    if(madeby_u)
  94. 		You("dig a hole through the %s.", surface_type);
  95. 	    else if(!madeby_obj && canseemon(madeby))
  96. 		pline("%s digs a hole through the %s.",
  97. 		      Monnam(madeby), surface_type);
  98. 	    else if(cansee(x, y) && flags.verbose)
  99. 		pline("A hole appears in the %s.", surface_type);
  100.  
  101. 	    if (at_u) {
  102. 		if (!u.ustuck && !wont_fall && !next_to_u()) {
  103. 		    You("are jerked back by your pet!");
  104. 		    wont_fall = TRUE;
  105. 		}
  106.  
  107. 		/* Floor objects get a chance of falling down.  The case where
  108. 		 * the hero does NOT fall down is treated here.  The case
  109. 		 * where the hero does fall down is treated in goto_level().
  110. 		 */
  111. 		if (u.ustuck || wont_fall) {
  112. 		    if (newobjs)
  113. 			impact_drop((struct obj *)0, x, y, 0);
  114. 		    if (oldobjs != newobjs)
  115. 			(void) pickup(1);
  116. 		    if (shopdoor && madeby_u) pay_for_damage("ruin", FALSE);
  117.  
  118. 		} else {
  119. 		    d_level newlevel;
  120.  
  121. 		    if (*u.ushops && madeby_u)
  122. 			shopdig(1); /* shk might snatch pack */
  123. 		    /* handle earlier damage, eg breaking wand of digging */
  124. 		    else if (!madeby_u) pay_for_damage("dig into", TRUE);
  125.  
  126. 		    You("fall through...");
  127. 		    /* Earlier checks must ensure that the destination
  128. 		     * level exists and is in the present dungeon.
  129. 		     */
  130. 		    newlevel.dnum = u.uz.dnum;
  131. 		    newlevel.dlevel = u.uz.dlevel + 1;
  132. 		    goto_level(&newlevel, FALSE, TRUE, FALSE);
  133. 		    /* messages for arriving in special rooms */
  134. 		    spoteffects(FALSE);
  135. 		}
  136. 	    } else {
  137. 		if (shopdoor && madeby_u) pay_for_damage("ruin", FALSE);
  138. 		if (newobjs)
  139. 		    impact_drop((struct obj *)0, x, y, 0);
  140. 		if (mtmp) {
  141. 		     /*[don't we need special sokoban handling here?]*/
  142. 		    if (is_flyer(mtmp->data) || is_floater(mtmp->data) ||
  143. 		        mtmp->data == &mons[PM_WUMPUS] ||
  144. 			(mtmp->wormno && count_wsegs(mtmp) > 5) ||
  145. 			mtmp->data->msize >= MZ_HUGE) return;
  146. 		    if (mtmp == u.ustuck)	/* probably a vortex */
  147. 			    return;		/* temporary? kludge */
  148.  
  149. 		    if (teleport_pet(mtmp, FALSE)) {
  150. 			d_level tolevel;
  151.  
  152. 			if (Is_stronghold(&u.uz)) {
  153. 			    assign_level(&tolevel, &valley_level);
  154. 			} else if (Is_botlevel(&u.uz)) {
  155. 			    if (canseemon(mtmp))
  156. 				pline("%s avoids the trap.", Monnam(mtmp));
  157. 			    return;
  158. 			} else {
  159. 			    get_level(&tolevel, depth(&u.uz) + 1);
  160. 			}
  161. 			if (mtmp->isshk) make_angry_shk(mtmp, 0, 0);
  162. 			migrate_to_level(mtmp, ledger_no(&tolevel),
  163. 					 MIGR_RANDOM, (coord *)0);
  164. 		    }
  165. 		}
  166. 	    }
  167. 	}
  168. }

dighole

  1. /* return TRUE if digging succeeded, FALSE otherwise */
  2. boolean
  3. dighole(pit_only)
  4. boolean pit_only;
  5. {
  6. 	register struct trap *ttmp = t_at(u.ux, u.uy);
  7. 	struct rm *lev = &levl[u.ux][u.uy];
  8. 	struct obj *boulder_here;
  9. 	schar typ;
  10. 	boolean nohole = !Can_dig_down(&u.uz);
  11.  
  12. 	if ((ttmp && (ttmp->ttyp == MAGIC_PORTAL || nohole)) ||
  13. 	   (IS_ROCK(lev->typ) && lev->typ != SDOOR &&
  14. 	    (lev->wall_info & W_NONDIGGABLE) != 0)) {
  15. 		pline_The("%s here is too hard to dig in.", surface(u.ux,u.uy));
  16.  
  17. 	} else if (is_pool(u.ux, u.uy) || is_lava(u.ux, u.uy)) {
  18. 		pline_The("%s sloshes furiously for a moment, then subsides.",
  19. 			is_lava(u.ux, u.uy) ? "lava" : "water");
  20. 		wake_nearby();	/* splashing */
  21.  
  22. 	} else if (lev->typ == DRAWBRIDGE_DOWN ||
  23. 		   (is_drawbridge_wall(u.ux, u.uy) >= 0)) {
  24. 		/* drawbridge_down is the platform crossing the moat when the
  25. 		   bridge is extended; drawbridge_wall is the open "doorway" or
  26. 		   closed "door" where the portcullis/mechanism is located */
  27. 		if (pit_only) {
  28. 		    pline_The("drawbridge seems too hard to dig through.");
  29. 		    return FALSE;
  30. 		} else {
  31. 		    int x = u.ux, y = u.uy;
  32. 		    /* if under the portcullis, the bridge is adjacent */
  33. 		    (void) find_drawbridge(&x, &y);
  34. 		    destroy_drawbridge(x, y);
  35. 		    return TRUE;
  36. 		}
  37.  
  38. 	} else if ((boulder_here = sobj_at(BOULDER, u.ux, u.uy)) != 0) {
  39. 		if (ttmp && (ttmp->ttyp == PIT || ttmp->ttyp == SPIKED_PIT) &&
  40. 		    rn2(2)) {
  41. 			pline_The("boulder settles into the pit.");
  42. 			ttmp->ttyp = PIT;	 /* crush spikes */
  43. 		} else {
  44. 			/*
  45. 			 * digging makes a hole, but the boulder immediately
  46. 			 * fills it.  Final outcome:  no hole, no boulder.
  47. 			 */
  48. 			pline("KADOOM! The boulder falls in!");
  49. 			(void) delfloortrap(ttmp);
  50. 		}
  51. 		delobj(boulder_here);
  52. 		return TRUE;
  53.  
  54. 	} else if (IS_GRAVE(lev->typ)) {        
  55. 	    digactualhole(u.ux, u.uy, BY_YOU, PIT);
  56. 	    dig_up_grave();
  57. 	    return TRUE;
  58. 	} else if (lev->typ == DRAWBRIDGE_UP) {
  59. 		/* must be floor or ice, other cases handled above */
  60. 		/* dig "pit" and let fluid flow in (if possible) */
  61. 		typ = fillholetyp(u.ux,u.uy);
  62.  
  63. 		if (typ == ROOM) {
  64. 			/*
  65. 			 * We can't dig a hole here since that will destroy
  66. 			 * the drawbridge.  The following is a cop-out. --dlc
  67. 			 */
  68. 			pline_The("%s here is too hard to dig in.",
  69. 			      surface(u.ux, u.uy));
  70. 			return FALSE;
  71. 		}
  72.  
  73. 		lev->drawbridgemask &= ~DB_UNDER;
  74. 		lev->drawbridgemask |= (typ == LAVAPOOL) ? DB_LAVA : DB_MOAT;
  75.  
  76. liquid_flow:
  77. 		if (ttmp) (void) delfloortrap(ttmp);
  78. 		/* if any objects were frozen here, they're released now */
  79. 		unearth_objs(u.ux, u.uy);
  80.  
  81. 		pline("As you dig, the hole fills with %s!",
  82. 		      typ == LAVAPOOL ? "lava" : "water");
  83. 		if (!Levitation && !Flying) {
  84. 		    if (typ == LAVAPOOL)
  85. 			(void) lava_effects();
  86. 		    else if (!Wwalking)
  87. 			(void) drown();
  88. 		}
  89. 		return TRUE;
  90.  
  91. 	/* the following two are here for the wand of digging */
  92. 	} else if (IS_THRONE(lev->typ)) {
  93. 		pline_The("throne is too hard to break apart.");
  94.  
  95. 	} else if (IS_ALTAR(lev->typ)) {
  96. 		pline_The("altar is too hard to break apart.");
  97.  
  98. 	} else {
  99. 		typ = fillholetyp(u.ux,u.uy);
  100.  
  101. 		if (typ != ROOM) {
  102. 			lev->typ = typ;
  103. 			goto liquid_flow;
  104. 		}
  105.  
  106. 		/* finally we get to make a hole */
  107. 		if (nohole || pit_only)
  108. 			digactualhole(u.ux, u.uy, BY_YOU, PIT);
  109. 		else
  110. 			digactualhole(u.ux, u.uy, BY_YOU, HOLE);
  111.  
  112. 		return TRUE;
  113. 	}
  114.  
  115. 	return FALSE;
  116. }

dig_up_grave

  1. STATIC_OVL void
  2. dig_up_grave()
  3. {
  4. 	struct obj *otmp;
  5.  
  6. 	/* Grave-robbing is frowned upon... */
  7. 	exercise(A_WIS, FALSE);
  8. 	if (Role_if(PM_ARCHEOLOGIST)) {
  9. 	    adjalign(-sgn(u.ualign.type)*3);
  10. 	    You_feel("like a despicable grave-robber!");
  11. 	} else if (Role_if(PM_SAMURAI)) {
  12. 	    adjalign(-sgn(u.ualign.type));
  13. 	    You("disturb the honorable dead!");
  14. 	} else if ((u.ualign.type == A_LAWFUL) && (u.ualign.record > -10)) {
  15. 	    adjalign(-sgn(u.ualign.type));
  16. 	    You("have violated the sanctity of this grave!");
  17. 	}
  18.  
  19. 	switch (rn2(5)) {
  20. 	case 0:
  21. 	case 1:
  22. 	    You("unearth a corpse.");
  23. 	    if (!!(otmp = mk_tt_object(CORPSE, u.ux, u.uy)))
  24. 	    	otmp->age -= 100;		/* this is an *OLD* corpse */;
  25. 	    break;
  26. 	case 2:
  27. 	    if (!Blind) pline(Hallucination ? "Dude!  The living dead!" :
  28. 			"The grave's owner is very upset!");
  29. 	    (void) makemon(mkclass(S_ZOMBIE,0), u.ux, u.uy, NO_MM_FLAGS);
  30. 	    break;
  31. 	case 3:
  32. 	    if (!Blind) pline(Hallucination ? "I want my mummy!" :
  33. 			"You've disturbed a tomb!");
  34. 	    (void) makemon(mkclass(S_MUMMY,0), u.ux, u.uy, NO_MM_FLAGS);
  35. 	    break;
  36. 	default:
  37. 	    /* No corpse */
  38. 	    pline_The("grave seems unused.  Strange....");
  39. 	    break;
  40. 	}
  41. 	levl[u.ux][u.uy].typ = ROOM;
  42. 	del_engr_at(u.ux, u.uy);
  43. 	newsym(u.ux,u.uy);
  44. 	return;
  45. }

use_pick_axe

  1. int
  2. use_pick_axe(obj)
  3. struct obj *obj;
  4. {
  5. 	boolean ispick;
  6. 	char dirsyms[12];
  7. 	char qbuf[QBUFSZ];
  8. 	register char *dsp = dirsyms;
  9. 	register int rx, ry;
  10. 	int res = 0;
  11. 	register const char *sdp, *verb;
  12.  
  13. 	if(iflags.num_pad) sdp = ndir; else sdp = sdir;	/* DICE workaround */
  14.  
  15. 	/* Check tool */
  16. 	if (obj != uwep) {
  17. 	    if (!wield_tool(obj, "swing")) return 0;
  18. 	    else res = 1;
  19. 	}
  20. 	ispick = is_pick(obj);
  21. 	verb = ispick ? "dig" : "chop";
  22.  
  23. 	if (u.utrap && u.utraptype == TT_WEB) {
  24. 	    pline("%s you can't %s while entangled in a web.",
  25. 		  /* res==0 => no prior message;
  26. 		     res==1 => just got "You now wield a pick-axe." message */
  27. 		  !res ? "Unfortunately," : "But", verb);
  28. 	    return res;
  29. 	}
  30.  
  31. 	while(*sdp) {
  32. 		(void) movecmd(*sdp);	/* sets u.dx and u.dy and u.dz */
  33. 		rx = u.ux + u.dx;
  34. 		ry = u.uy + u.dy;
  35. 		/* Include down even with axe, so we have at least one direction */
  36. 		if (u.dz > 0 ||
  37. 		    (u.dz == 0 && isok(rx, ry) &&
  38. 		     dig_typ(obj, rx, ry) != DIGTYP_UNDIGGABLE))
  39. 			*dsp++ = *sdp;
  40. 		sdp++;
  41. 	}
  42. 	*dsp = 0;
  43. 	Sprintf(qbuf, "In what direction do you want to %s? [%s]", verb, dirsyms);
  44. 	if(!getdir(qbuf))
  45. 		return(res);
  46.  
  47. 	return(use_pick_axe2(obj));
  48. }

use_pick_axe2

  1. /* MRKR: use_pick_axe() is split in two to allow autodig to bypass */
  2. /*       the "In what direction do you want to dig?" query.        */
  3. /*       use_pick_axe2() uses the existing u.dx, u.dy and u.dz    */
  4.  
  5. int
  6. use_pick_axe2(obj) 
  7. struct obj *obj;
  8. {
  9. 	register int rx, ry;
  10. 	register struct rm *lev;
  11. 	int dig_target;
  12. 	boolean ispick = is_pick(obj);
  13. 	const char *verbing = ispick ? "digging" : "chopping";
  14.  
  15. 	if (u.uswallow && attack(u.ustuck)) {
  16. 		;  /* return(1) */
  17. 	} else if (Underwater) {
  18. 		pline("Turbulence torpedoes your %s attempts.", verbing);
  19. 	} else if(u.dz < 0) {
  20. 		if(Levitation)
  21. 			You("don't have enough leverage.");
  22. 		else
  23. 			You_cant("reach the %s.",ceiling(u.ux,u.uy));
  24. 	} else if(!u.dx && !u.dy && !u.dz) {
  25. 		char buf[BUFSZ];
  26. 		int dam;
  27.  
  28. 		dam = rnd(2) + dbon() + obj->spe;
  29. 		if (dam <= 0) dam = 1;
  30. 		You("hit yourself with %s.", yname(uwep));
  31. 		Sprintf(buf, "%s own %s", uhis(),
  32. 				OBJ_NAME(objects[obj->otyp]));
  33. 		losehp(dam, buf, KILLED_BY);
  34. 		flags.botl=1;
  35. 		return(1);
  36. 	} else if(u.dz == 0) {
  37. 		if(Stunned || (Confusion && !rn2(5))) confdir();
  38. 		rx = u.ux + u.dx;
  39. 		ry = u.uy + u.dy;
  40. 		if(!isok(rx, ry)) {
  41. 			pline("Clash!");
  42. 			return(1);
  43. 		}
  44. 		lev = &levl[rx][ry];
  45. 		if(MON_AT(rx, ry) && attack(m_at(rx, ry)))
  46. 			return(1);
  47. 		dig_target = dig_typ(obj, rx, ry);
  48. 		if (dig_target == DIGTYP_UNDIGGABLE) {
  49. 			/* ACCESSIBLE or POOL */
  50. 			struct trap *trap = t_at(rx, ry);
  51.  
  52. 			if (trap && trap->ttyp == WEB) {
  53. 			    if (!trap->tseen) {
  54. 				seetrap(trap);
  55. 				There("is a spider web there!");
  56. 			    }
  57. 			    Your("%s entangled in the web.",
  58. 				aobjnam(obj, "become"));
  59. 			    /* you ought to be able to let go; tough luck */
  60. 			    /* (maybe `move_into_trap()' would be better) */
  61. 			    nomul(-d(2,2));
  62. 			    nomovemsg = "You pull free.";
  63. 			} else if (lev->typ == IRONBARS) {
  64. 			    pline("Clang!");
  65. 			    wake_nearby();
  66. 			} else if (IS_TREE(lev->typ))
  67. 			    You("need an axe to cut down a tree.");
  68. 			else if (IS_ROCK(lev->typ))
  69. 			    You("need a pick to dig rock.");
  70. 			else if (!ispick && (sobj_at(STATUE, rx, ry) ||
  71. 					     sobj_at(BOULDER, rx, ry))) {
  72. 			    boolean vibrate = !rn2(3);
  73. 			    pline("Sparks fly as you whack the %s.%s",
  74. 				sobj_at(STATUE, rx, ry) ? "statue" : "boulder",
  75. 				vibrate ? " The axe-handle vibrates violently!" : "");
  76. 			    if (vibrate) losehp(2, "axing a hard object", KILLED_BY);
  77. 			}
  78. 			else
  79. 			    You("swing your %s through thin air.",
  80. 				aobjnam(obj, (char *)0));
  81. 		} else {
  82. 			static const char * const d_action[6] = {
  83. 						"swinging",
  84. 						"digging",
  85. 						"chipping the statue",
  86. 						"hitting the boulder",
  87. 						"chopping at the door",
  88. 						"cutting the tree"
  89. 			};
  90. 			did_dig_msg = FALSE;
  91. 			digging.quiet = FALSE;
  92. 			if (digging.pos.x != rx || digging.pos.y != ry ||
  93. 			    !on_level(&digging.level, &u.uz) || digging.down) {
  94. 			    if (flags.autodig &&
  95. 				dig_target == DIGTYP_ROCK && !digging.down &&
  96. 				digging.pos.x == u.ux &&
  97. 				digging.pos.y == u.uy &&
  98. 				(moves <= digging.lastdigtime+2 &&
  99. 				 moves >= digging.lastdigtime)) {
  100. 				/* avoid messages if repeated autodigging */
  101. 				did_dig_msg = TRUE;
  102. 				digging.quiet = TRUE;
  103. 			    }
  104. 			    digging.down = digging.chew = FALSE;
  105. 			    digging.warned = FALSE;
  106. 			    digging.pos.x = rx;
  107. 			    digging.pos.y = ry;
  108. 			    assign_level(&digging.level, &u.uz);
  109. 			    digging.effort = 0;
  110. 			    if (!digging.quiet)
  111. 				You("start %s.", d_action[dig_target]);
  112. 			} else {
  113. 			    You("%s %s.", digging.chew ? "begin" : "continue",
  114. 					d_action[dig_target]);
  115. 			    digging.chew = FALSE;
  116. 			}
  117. 			set_occupation(dig, verbing, 0);
  118. 		}
  119. 	} else if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) {
  120. 		/* it must be air -- water checked above */
  121. 		You("swing your %s through thin air.", aobjnam(obj, (char *)0));
  122. 	} else if (!can_reach_floor()) {
  123. 		You_cant("reach the %s.", surface(u.ux,u.uy));
  124. 	} else if (is_pool(u.ux, u.uy) || is_lava(u.ux, u.uy)) {
  125. 		/* Monsters which swim also happen not to be able to dig */
  126. 		You("cannot stay under%s long enough.",
  127. 				is_pool(u.ux, u.uy) ? "water" : " the lava");
  128. 	} else if (!ispick) {
  129. 		Your("%s merely scratches the %s.",
  130. 				aobjnam(obj, (char *)0), surface(u.ux,u.uy));
  131. 		u_wipe_engr(3);
  132. 	} else {
  133. 		if (digging.pos.x != u.ux || digging.pos.y != u.uy ||
  134. 			!on_level(&digging.level, &u.uz) || !digging.down) {
  135. 		    digging.chew = FALSE;
  136. 		    digging.down = TRUE;
  137. 		    digging.warned = FALSE;
  138. 		    digging.pos.x = u.ux;
  139. 		    digging.pos.y = u.uy;
  140. 		    assign_level(&digging.level, &u.uz);
  141. 		    digging.effort = 0;
  142. 		    You("start %s downward.", verbing);
  143. 		    if (*u.ushops) shopdig(0);
  144. 		} else
  145. 		    You("continue %s downward.", verbing);
  146. 		did_dig_msg = FALSE;
  147. 		set_occupation(dig, verbing, 0);
  148. 	}
  149. 	return(1);
  150. }

watch_dig

  1. /*
  2. * Town Watchmen frown on damage to the town walls, trees or fountains.
  3. * It's OK to dig holes in the ground, however.
  4. * If mtmp is assumed to be a watchman, a watchman is found if mtmp == 0
  5. * zap == TRUE if wand/spell of digging, FALSE otherwise (chewing)
  6. */
  7. void
  8. watch_dig(mtmp, x, y, zap)
  9. struct monst *mtmp;
  10. xchar x, y;
  11. boolean zap;
  12. {
  13. 	struct rm *lev = &levl[x][y];
  14.  
  15. 	if (in_town(x, y) &&
  16. 	    (closed_door(x, y) || lev->typ == SDOOR ||
  17. 	     IS_WALL(lev->typ) || IS_FOUNTAIN(lev->typ) || IS_TREE(lev->typ))) {
  18. 	    if (!mtmp) {
  19. 		for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  20. 		    if (DEADMONSTER(mtmp)) continue;
  21. 		    if ((mtmp->data == &mons[PM_WATCHMAN] ||
  22. 			 mtmp->data == &mons[PM_WATCH_CAPTAIN]) &&
  23. 			mtmp->mcansee && m_canseeu(mtmp) &&
  24. 			couldsee(mtmp->mx, mtmp->my) && mtmp->mpeaceful)
  25. 			break;
  26. 		}
  27. 	    }
  28.  
  29. 	    if (mtmp) {
  30. 		if(zap || digging.warned) {
  31. 		    verbalize("Halt, vandal!  You're under arrest!");
  32. 		    (void) angry_guards(!(flags.soundok));
  33. 		} else {
  34. 		    const char *str;
  35.  
  36. 		    if (IS_DOOR(lev->typ))
  37. 			str = "door";
  38. 		    else if (IS_TREE(lev->typ))
  39. 			str = "tree";
  40. 		    else if (IS_ROCK(lev->typ))
  41. 			str = "wall";
  42. 		    else
  43. 			str = "fountain";
  44. 		    verbalize("Hey, stop damaging that %s!", str);
  45. 		    digging.warned = TRUE;
  46. 		}
  47. 		if (is_digging())
  48. 		    stop_occupation();
  49. 	    }
  50. 	}
  51. }
  52.  
  53. #endif /* OVLB */

mdig_tunnel

  1. #ifdef OVL0
  2.  
  3. /* Return TRUE if monster died, FALSE otherwise.  Called from m_move(). */
  4. boolean
  5. mdig_tunnel(mtmp)
  6. register struct monst *mtmp;
  7. {
  8. 	register struct rm *here;
  9. 	int pile = rnd(12);
  10.  
  11. 	here = &levl[mtmp->mx][mtmp->my];
  12. 	if (here->typ == SDOOR)
  13. 	    cvt_sdoor_to_door(here);	/* ->typ = DOOR */
  14.  
  15. 	/* Eats away door if present & closed or locked */
  16. 	if (closed_door(mtmp->mx, mtmp->my)) {
  17. 	    if (*in_rooms(mtmp->mx, mtmp->my, SHOPBASE))
  18. 		add_damage(mtmp->mx, mtmp->my, 0L);
  19. 	    unblock_point(mtmp->mx, mtmp->my);	/* vision */
  20. 	    if (here->doormask & D_TRAPPED) {
  21. 		here->doormask = D_NODOOR;
  22. 		if (mb_trapped(mtmp)) {	/* mtmp is killed */
  23. 		    newsym(mtmp->mx, mtmp->my);
  24. 		    return TRUE;
  25. 		}
  26. 	    } else {
  27. 		if (!rn2(3) && flags.verbose)	/* not too often.. */
  28. 		    You_feel("an unexpected draft.");
  29. 		here->doormask = D_BROKEN;
  30. 	    }
  31. 	    newsym(mtmp->mx, mtmp->my);
  32. 	    return FALSE;
  33. 	} else if (!IS_ROCK(here->typ) && !IS_TREE(here->typ)) /* no dig */
  34. 	    return FALSE;
  35.  
  36. 	/* Only rock, trees, and walls fall through to this point. */
  37. 	if ((here->wall_info & W_NONDIGGABLE) != 0) {
  38. 	    impossible("mdig_tunnel:  %s at (%d,%d) is undiggable",
  39. 		       (IS_WALL(here->typ) ? "wall" : "stone"),
  40. 		       (int) mtmp->mx, (int) mtmp->my);
  41. 	    return FALSE;	/* still alive */
  42. 	}
  43.  
  44. 	if (IS_WALL(here->typ)) {
  45. 	    /* KMH -- Okay on arboreal levels (room walls are still stone) */
  46. 	    if (flags.soundok && flags.verbose && !rn2(5))
  47. 		You_hear("crashing rock.");
  48. 	    if (*in_rooms(mtmp->mx, mtmp->my, SHOPBASE))
  49. 		add_damage(mtmp->mx, mtmp->my, 0L);
  50. 	    if (level.flags.is_maze_lev) {
  51. 		here->typ = ROOM;
  52. 	    } else if (level.flags.is_cavernous_lev &&
  53. 		       !in_town(mtmp->mx, mtmp->my)) {
  54. 		here->typ = CORR;
  55. 	    } else {
  56. 		here->typ = DOOR;
  57. 		here->doormask = D_NODOOR;
  58. 	    }
  59. 	} else if (IS_TREE(here->typ)) {
  60. 	    here->typ = ROOM;
  61. 	    if (pile && pile < 5)
  62. 		(void) rnd_treefruit_at(mtmp->mx, mtmp->my);
  63. 	} else {
  64. 	    here->typ = CORR;
  65. 	    if (pile && pile < 5)
  66. 		(void) mksobj_at((pile == 1) ? BOULDER : ROCK,
  67. 			     mtmp->mx, mtmp->my, TRUE, FALSE);
  68. 	}
  69. 	newsym(mtmp->mx, mtmp->my);
  70. 	if (!sobj_at(BOULDER, mtmp->mx, mtmp->my))
  71. 	    unblock_point(mtmp->mx, mtmp->my);	/* vision */
  72.  
  73. 	return FALSE;
  74. }
  75.  
  76. #endif /* OVL0 */

zap_dig

  1. #ifdef OVL3
  2.  
  3. /* digging via wand zap or spell cast */
  4. void
  5. zap_dig()
  6. {
  7. 	struct rm *room;
  8. 	struct monst *mtmp;
  9. 	struct obj *otmp;
  10. 	int zx, zy, digdepth;
  11. 	boolean shopdoor, shopwall, maze_dig;
  12. 	/*
  13. 	 * Original effect (approximately):
  14. 	 * from CORR: dig until we pierce a wall
  15. 	 * from ROOM: pierce wall and dig until we reach
  16. 	 * an ACCESSIBLE place.
  17. 	 * Currently: dig for digdepth positions;
  18. 	 * also down on request of Lennart Augustsson.
  19. 	 */
  20.  
  21. 	if (u.uswallow) {
  22. 	    mtmp = u.ustuck;
  23.  
  24. 	    if (!is_whirly(mtmp->data)) {
  25. 		if (is_animal(mtmp->data))
  26. 		    You("pierce %s %s wall!",
  27. 			s_suffix(mon_nam(mtmp)), mbodypart(mtmp, STOMACH));
  28. 		mtmp->mhp = 1;		/* almost dead */
  29. 		expels(mtmp, mtmp->data, !is_animal(mtmp->data));
  30. 	    }
  31. 	    return;
  32. 	} /* swallowed */
  33.  
  34. 	if (u.dz) {
  35. 	    if (!Is_airlevel(&u.uz) && !Is_waterlevel(&u.uz) && !Underwater) {
  36. 		if (u.dz < 0 || On_stairs(u.ux, u.uy)) {
  37. 		    if (On_stairs(u.ux, u.uy))
  38. 			pline_The("beam bounces off the %s and hits the %s.",
  39. 			      (u.ux == xdnladder || u.ux == xupladder) ?
  40. 			      "ladder" : "stairs", ceiling(u.ux, u.uy));
  41. 		    You("loosen a rock from the %s.", ceiling(u.ux, u.uy));
  42. 		    pline("It falls on your %s!", body_part(HEAD));
  43. 		    losehp(rnd((uarmh && is_metallic(uarmh)) ? 2 : 6),
  44. 			   "falling rock", KILLED_BY_AN);
  45. 		    otmp = mksobj_at(ROCK, u.ux, u.uy, FALSE, FALSE);
  46. 		    if (otmp) {
  47. 			(void)xname(otmp);	/* set dknown, maybe bknown */
  48. 			stackobj(otmp);
  49. 		    }
  50. 		    newsym(u.ux, u.uy);
  51. 		} else {
  52. 		    watch_dig((struct monst *)0, u.ux, u.uy, TRUE);
  53. 		    (void) dighole(FALSE);
  54. 		}
  55. 	    }
  56. 	    return;
  57. 	} /* up or down */
  58.  
  59. 	/* normal case: digging across the level */
  60. 	shopdoor = shopwall = FALSE;
  61. 	maze_dig = level.flags.is_maze_lev && !Is_earthlevel(&u.uz);
  62. 	zx = u.ux + u.dx;
  63. 	zy = u.uy + u.dy;
  64. 	digdepth = rn1(18, 8);
  65. 	tmp_at(DISP_BEAM, cmap_to_glyph(S_digbeam));
  66. 	while (--digdepth >= 0) {
  67. 	    if (!isok(zx,zy)) break;
  68. 	    room = &levl[zx][zy];
  69. 	    tmp_at(zx,zy);
  70. 	    delay_output();	/* wait a little bit */
  71. 	    if (closed_door(zx, zy) || room->typ == SDOOR) {
  72. 		if (*in_rooms(zx,zy,SHOPBASE)) {
  73. 		    add_damage(zx, zy, 400L);
  74. 		    shopdoor = TRUE;
  75. 		}
  76. 		if (room->typ == SDOOR)
  77. 		    room->typ = DOOR;
  78. 		else if (cansee(zx, zy))
  79. 		    pline_The("door is razed!");
  80. 		watch_dig((struct monst *)0, zx, zy, TRUE);
  81. 		room->doormask = D_NODOOR;
  82. 		unblock_point(zx,zy); /* vision */
  83. 		digdepth -= 2;
  84. 		if (maze_dig) break;
  85. 	    } else if (maze_dig) {
  86. 		if (IS_WALL(room->typ)) {
  87. 		    if (!(room->wall_info & W_NONDIGGABLE)) {
  88. 			if (*in_rooms(zx,zy,SHOPBASE)) {
  89. 			    add_damage(zx, zy, 200L);
  90. 			    shopwall = TRUE;
  91. 			}
  92. 			room->typ = ROOM;
  93. 			unblock_point(zx,zy); /* vision */
  94. 		    } else if (!Blind)
  95. 			pline_The("wall glows then fades.");
  96. 		    break;
  97. 		} else if (IS_TREE(room->typ)) { /* check trees before stone */
  98. 		    if (!(room->wall_info & W_NONDIGGABLE)) {
  99. 			room->typ = ROOM;
  100. 			unblock_point(zx,zy); /* vision */
  101. 		    } else if (!Blind)
  102. 			pline_The("tree shudders but is unharmed.");
  103. 		    break;
  104. 		} else if (room->typ == STONE || room->typ == SCORR) {
  105. 		    if (!(room->wall_info & W_NONDIGGABLE)) {
  106. 			room->typ = CORR;
  107. 			unblock_point(zx,zy); /* vision */
  108. 		    } else if (!Blind)
  109. 			pline_The("rock glows then fades.");
  110. 		    break;
  111. 		}
  112. 	    } else if (IS_ROCK(room->typ)) {
  113. 		if (!may_dig(zx,zy)) break;
  114. 		if (IS_WALL(room->typ) || room->typ == SDOOR) {
  115. 		    if (*in_rooms(zx,zy,SHOPBASE)) {
  116. 			add_damage(zx, zy, 200L);
  117. 			shopwall = TRUE;
  118. 		    }
  119. 		    watch_dig((struct monst *)0, zx, zy, TRUE);
  120. 		    if (level.flags.is_cavernous_lev && !in_town(zx, zy)) {
  121. 			room->typ = CORR;
  122. 		    } else {
  123. 			room->typ = DOOR;
  124. 			room->doormask = D_NODOOR;
  125. 		    }
  126. 		    digdepth -= 2;
  127. 		} else if (IS_TREE(room->typ)) {
  128. 		    room->typ = ROOM;
  129. 		    digdepth -= 2;
  130. 		} else {	/* IS_ROCK but not IS_WALL or SDOOR */
  131. 		    room->typ = CORR;
  132. 		    digdepth--;
  133. 		}
  134. 		unblock_point(zx,zy); /* vision */
  135. 	    }
  136. 	    zx += u.dx;
  137. 	    zy += u.dy;
  138. 	} /* while */
  139. 	tmp_at(DISP_END,0);	/* closing call */
  140. 	if (shopdoor || shopwall)
  141. 	    pay_for_damage(shopdoor ? "destroy" : "dig into", FALSE);
  142. 	return;
  143. }

bury_an_obj

  1. /* move objects from fobj/nexthere lists to buriedobjlist, keeping position */
  2. /* information */
  3. struct obj *
  4. bury_an_obj(otmp)
  5. 	struct obj *otmp;
  6. {
  7. 	struct obj *otmp2;
  8. 	boolean under_ice;
  9.  
  10. #ifdef DEBUG
  11. 	pline("bury_an_obj: %s", xname(otmp));
  12. #endif
  13. 	if (otmp == uball)
  14. 		unpunish();
  15. 	/* after unpunish(), or might get deallocated chain */
  16. 	otmp2 = otmp->nexthere;
  17. 	/*
  18. 	 * obj_resists(,0,0) prevents Rider corpses from being buried.
  19. 	 * It also prevents The Amulet and invocation tools from being
  20. 	 * buried.  Since they can't be confined to bags and statues,
  21. 	 * it makes sense that they can't be buried either, even though
  22. 	 * the real reason there (direct accessibility when carried) is
  23. 	 * completely different.
  24. 	 */
  25. 	if (otmp == uchain || obj_resists(otmp, 0, 0))
  26. 		return(otmp2);
  27.  
  28. 	if (otmp->otyp == LEASH && otmp->leashmon != 0)
  29. 		o_unleash(otmp);
  30.  
  31. 	if (otmp->lamplit && otmp->otyp != POT_OIL)
  32. 		end_burn(otmp, TRUE);
  33.  
  34. 	obj_extract_self(otmp);
  35.  
  36. 	under_ice = is_ice(otmp->ox, otmp->oy);
  37. 	if (otmp->otyp == ROCK && !under_ice) {
  38. 		/* merges into burying material */
  39. 		obfree(otmp, (struct obj *)0);
  40. 		return(otmp2);
  41. 	}
  42. 	/*
  43. 	 * Start a rot on organic material.  Not corpses -- they
  44. 	 * are already handled.
  45. 	 */
  46. 	if (otmp->otyp == CORPSE) {
  47. 	    ;		/* should cancel timer if under_ice */
  48. 	} else if ((under_ice ? otmp->oclass == POTION_CLASS : is_organic(otmp))
  49. 		&& !obj_resists(otmp, 5, 95)) {
  50. 	    (void) start_timer((under_ice ? 0L : 250L) + (long)rnd(250),
  51. 			       TIMER_OBJECT, ROT_ORGANIC, (genericptr_t)otmp);
  52. 	}
  53. 	add_to_buried(otmp);
  54. 	return(otmp2);
  55. }

bury_objs

bury_objs() takes two parameters, an x,y coordinate, and buries all objects on the floor at the location.

  1. void
  2. bury_objs(x, y)
  3. int x, y;
  4. {
  5. 	struct obj *otmp, *otmp2;
  6.  
  7. #ifdef DEBUG
  8. 	if(level.objects[x][y] != (struct obj *)0)
  9. 		pline("bury_objs: at %d, %d", x, y);
  10. #endif
  11. 	for (otmp = level.objects[x][y]; otmp; otmp = otmp2)
  12. 		otmp2 = bury_an_obj(otmp);
  13.  
  14. 	/* don't expect any engravings here, but just in case */
  15. 	del_engr_at(x, y);
  16. 	newsym(x, y);
  17. }

unearth_objs

unearth_objs() takes two parameters, an x,y coordinate, and unearths all objects buried at that location.

  1. /* move objects from buriedobjlist to fobj/nexthere lists */
  2. void
  3. unearth_objs(x, y)
  4. int x, y;
  5. {
  6. 	struct obj *otmp, *otmp2;
  7.  
  8. #ifdef DEBUG
  9. 	pline("unearth_objs: at %d, %d", x, y);
  10. #endif
  11. 	for (otmp = level.buriedobjlist; otmp; otmp = otmp2) {
  12. 		otmp2 = otmp->nobj;
  13. 		if (otmp->ox == x && otmp->oy == y) {
  14. 		    obj_extract_self(otmp);
  15. 		    if (otmp->timed)
  16. 			(void) stop_timer(ROT_ORGANIC, (genericptr_t)otmp);
  17. 		    place_object(otmp, x, y);
  18. 		    stackobj(otmp);
  19. 		}
  20. 	}
  21. 	del_engr_at(x, y);
  22. 	newsym(x, y);
  23. }

rot_organic

  1. /*
  2. * The organic material has rotted away while buried.  As an expansion,
  3. * we could add add partial damage.  A damage count is kept in the object
  4. * and every time we are called we increment the count and reschedule another
  5. * timeout.  Eventually the object rots away.
  6. *
  7. * This is used by buried objects other than corpses.  When a container rots
  8. * away, any contents become newly buried objects.
  9. */
  10. /* ARGSUSED */
  11. void
  12. rot_organic(arg, timeout)
  13. genericptr_t arg;
  14. long timeout;	/* unused */
  15. {
  16. 	struct obj *obj = (struct obj *) arg;
  17.  
  18. 	while (Has_contents(obj)) {
  19. 	    /* We don't need to place contained object on the floor
  20. 	       first, but we do need to update its map coordinates. */
  21. 	    obj->cobj->ox = obj->ox,  obj->cobj->oy = obj->oy;
  22. 	    /* Everything which can be held in a container can also be
  23. 	       buried, so bury_an_obj's use of obj_extract_self insures
  24. 	       that Has_contents(obj) will eventually become false. */
  25. 	    (void)bury_an_obj(obj->cobj);
  26. 	}
  27. 	obj_extract_self(obj);
  28. 	obfree(obj, (struct obj *) 0);
  29. }

rot_corpse

  1. /*
  2. * Called when a corpse has rotted completely away.
  3. */
  4. void
  5. rot_corpse(arg, timeout)
  6. genericptr_t arg;
  7. long timeout;	/* unused */
  8. {
  9. 	xchar x = 0, y = 0;
  10. 	struct obj *obj = (struct obj *) arg;
  11. 	boolean on_floor = obj->where == OBJ_FLOOR,
  12. 		in_invent = obj->where == OBJ_INVENT;
  13.  
  14. 	if (on_floor) {
  15. 	    x = obj->ox;
  16. 	    y = obj->oy;
  17. 	} else if (in_invent) {
  18. 	    if (flags.verbose) {
  19. 		char *cname = corpse_xname(obj, FALSE);
  20. 		Your("%s%s %s away%c",
  21. 		     obj == uwep ? "wielded " : nul, cname,
  22. 		     otense(obj, "rot"), obj == uwep ? '!' : '.');
  23. 	    }
  24. 	    if (obj == uwep) {
  25. 		uwepgone();	/* now bare handed */
  26. 		stop_occupation();
  27. 	    } else if (obj == uswapwep) {
  28. 		uswapwepgone();
  29. 		stop_occupation();
  30. 	    } else if (obj == uquiver) {
  31. 		uqwepgone();
  32. 		stop_occupation();
  33. 	    }
  34. 	} else if (obj->where == OBJ_MINVENT && obj->owornmask) {
  35. 	    if (obj == MON_WEP(obj->ocarry)) {
  36. 		setmnotwielded(obj->ocarry,obj);
  37. 		MON_NOWEP(obj->ocarry);
  38. 	    }
  39. 	}
  40. 	rot_organic(arg, timeout);
  41. 	if (on_floor) newsym(x, y);
  42. 	else if (in_invent) update_inventory();
  43. }

bury_monst

  1. #if 0
  2. void
  3. bury_monst(mtmp)
  4. struct monst *mtmp;
  5. {
  6. #ifdef DEBUG
  7. 	pline("bury_monst: %s", mon_nam(mtmp));
  8. #endif
  9. 	if(canseemon(mtmp)) {
  10. 	    if(is_flyer(mtmp->data) || is_floater(mtmp->data)) {
  11. 		pline_The("%s opens up, but %s is not swallowed!",
  12. 			surface(mtmp->mx, mtmp->my), mon_nam(mtmp));
  13. 		return;
  14. 	    } else
  15. 	        pline_The("%s opens up and swallows %s!",
  16. 			surface(mtmp->mx, mtmp->my), mon_nam(mtmp));
  17. 	}
  18.  
  19. 	mtmp->mburied = TRUE;
  20. 	wakeup(mtmp);			/* at least give it a chance :-) */
  21. 	newsym(mtmp->mx, mtmp->my);
  22. }

bury_you

  1. void
  2. bury_you()
  3. {
  4. #ifdef DEBUG
  5. 	pline("bury_you");
  6. #endif
  7. if (!Levitation && !Flying) {
  8. 	if(u.uswallow)
  9. 	    You_feel("a sensation like falling into a trap!");
  10. 	else
  11. 	    pline_The("%s opens beneath you and you fall in!",
  12. 		  surface(u.ux, u.uy));
  13.  
  14. 	u.uburied = TRUE;
  15. 	if(!Strangled && !Breathless) Strangled = 6;
  16. 	under_ground(1);
  17. }
  18. }

unearth_you

  1. void
  2. unearth_you()
  3. {
  4. #ifdef DEBUG
  5. 	pline("unearth_you");
  6. #endif
  7. 	u.uburied = FALSE;
  8. 	under_ground(0);
  9. 	if(!uamul || uamul->otyp != AMULET_OF_STRANGULATION)
  10. 		Strangled = 0;
  11. 	vision_recalc(0);
  12. }

escape_tomb

  1. void
  2. escape_tomb()
  3. {
  4. #ifdef DEBUG
  5. 	pline("escape_tomb");
  6. #endif
  7. 	if ((Teleportation || can_teleport(youmonst.data)) &&
  8. 	    (Teleport_control || rn2(3) < Luck+2)) {
  9. 		You("attempt a teleport spell.");
  10. 		(void) dotele();	/* calls unearth_you() */
  11. 	} else if(u.uburied) { /* still buried after 'port attempt */
  12. 		boolean good;
  13.  
  14. 		if(amorphous(youmonst.data) || Passes_walls ||
  15. 		   noncorporeal(youmonst.data) || unsolid(youmonst.data) ||
  16. 		   (tunnels(youmonst.data) && !needspick(youmonst.data))) {
  17.  
  18. 		    You("%s up through the %s.",
  19. 			(tunnels(youmonst.data) && !needspick(youmonst.data)) ?
  20. 			 "try to tunnel" : (amorphous(youmonst.data)) ?
  21. 			 "ooze" : "phase", surface(u.ux, u.uy));
  22.  
  23. 		    if(tunnels(youmonst.data) && !needspick(youmonst.data))
  24. 			good = dighole(TRUE);
  25. 		    else good = TRUE;
  26. 		    if(good) unearth_you();
  27. 		}
  28. 	}
  29. }

bury_obj

  1. void
  2. bury_obj(otmp)
  3. struct obj *otmp;
  4. {
  5.  
  6. #ifdef DEBUG
  7. 	pline("bury_obj");
  8. #endif
  9. 	if(cansee(otmp->ox, otmp->oy))
  10. 	   pline_The("objects on the %s tumble into a hole!",
  11. 		surface(otmp->ox, otmp->oy));
  12.  
  13. 	bury_objs(otmp->ox, otmp->oy);
  14. }
  15. #endif

wiz_debug_cmd

  1. #ifdef DEBUG
  2. int
  3. wiz_debug_cmd() /* in this case, bury everything at your loc and around */
  4. {
  5. 	int x, y;
  6.  
  7. 	for (x = u.ux - 1; x <= u.ux + 1; x++)
  8. 	    for (y = u.uy - 1; y <= u.uy + 1; y++)
  9. 		if (isok(x,y)) bury_objs(x,y);
  10. 	return 0;
  11. }
  12.  
  13. #endif /* DEBUG */
  14. #endif /* OVL3 */
  15.  
  16. /*dig.c*/