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

Function try_disarm

src/trap.c:5440–5527  ·  view source on GitHub ↗

0: doesn't even try; 1: tries and fails; 2: succeeds */

Source from the content-addressed store, hash-verified

5438
5439/* 0: doesn't even try; 1: tries and fails; 2: succeeds */
5440staticfn int
5441try_disarm(
5442 struct trap *ttmp,
5443 boolean force_failure)
5444{
5445 struct monst *mtmp = m_at(ttmp->tx, ttmp->ty);
5446 int ttype = ttmp->ttyp;
5447 boolean under_u = (!u.dx && !u.dy);
5448 boolean holdingtrap = (ttype == BEAR_TRAP || ttype == WEB);
5449
5450 /* Test for monster first, monsters are displayed instead of trap. */
5451 if (mtmp && (!mtmp->mtrapped || !holdingtrap)) {
5452 pline("%s is in the way.", Monnam(mtmp));
5453 return 0;
5454 }
5455 /* We might be forced to move onto the trap's location. */
5456 if (sobj_at(BOULDER, ttmp->tx, ttmp->ty) && !Passes_walls && !under_u) {
5457 There("is a boulder in your way.");
5458 return 0;
5459 }
5460 /* duplicate tight-space checks from test_move */
5461 if (u.dx && u.dy && bad_rock(gy.youmonst.data, u.ux, ttmp->ty)
5462 && bad_rock(gy.youmonst.data, ttmp->tx, u.uy)) {
5463 if ((gi.invent && (inv_weight() + weight_cap() > WT_TOOMUCH_DIAGONAL))
5464 || bigmonst(gy.youmonst.data)) {
5465 /* don't allow untrap if they can't get thru to it */
5466 You("are unable to reach the %s!", trapname(ttype, FALSE));
5467 return 0;
5468 }
5469 }
5470 /* untrappable traps are located on the ground. */
5471 if (!can_reach_floor(under_u)) {
5472 if (u.usteed && P_SKILL(P_RIDING) < P_BASIC)
5473 rider_cant_reach();
5474 else
5475 You("are unable to reach the %s!", trapname(ttype, FALSE));
5476 return 0;
5477 }
5478
5479 /* Will our hero succeed? */
5480 if (force_failure || untrap_prob(ttmp)) {
5481 if (rnl(5)) {
5482 pline("Whoops...");
5483 if (mtmp) { /* must be a trap that holds monsters */
5484 if (ttype == BEAR_TRAP) {
5485 if (mtmp->mtame)
5486 abuse_dog(mtmp);
5487 mtmp->mhp -= rnd(4);
5488 if (DEADMONSTER(mtmp))
5489 killed(mtmp);
5490 } else if (ttype == WEB) {
5491 struct trap *ttmp2 = t_at(u.ux, u.uy);
5492
5493 if (!webmaker(gy.youmonst.data)
5494 /* don't always try to spread the web */
5495 && !rn2(3)
5496 /* is there already a trap at hero's spot?
5497 if so, don't clobber it with spreading web */

Callers 4

disarm_holdingtrapFunction · 0.85
disarm_landmineFunction · 0.85
disarm_squeaky_boardFunction · 0.85
disarm_shooting_trapFunction · 0.85

Calls 15

MonnamFunction · 0.85
sobj_atFunction · 0.85
ThereFunction · 0.85
bad_rockFunction · 0.85
inv_weightFunction · 0.85
weight_capFunction · 0.85
YouFunction · 0.85
trapnameFunction · 0.85
can_reach_floorFunction · 0.85
rider_cant_reachFunction · 0.85
untrap_probFunction · 0.85
rnlFunction · 0.85

Tested by

no test coverage detected