MCPcopy Index your code
hub / github.com/NetHack/NetHack / dig

Function dig

src/dig.c:299–568  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

297}
298
299staticfn int
300dig(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);

Callers

nothing calls this directly

Calls 15

on_levelFunction · 0.85
dig_checkFunction · 0.85
digcheck_fail_messageFunction · 0.85
may_digFunction · 0.85
dig_typFunction · 0.85
is_db_wallFunction · 0.85
rn2Function · 0.85
weldedFunction · 0.85
YouFunction · 0.85
ynameFunction · 0.85
dropxFunction · 0.85
Yobjnam2Function · 0.85

Tested by

no test coverage detected