MCPcopy Create free account
hub / github.com/NetHack/NetHack / trapmove

Function trapmove

src/hack.c:1549–1691  ·  view source on GitHub ↗

try to escape being stuck in a trapped state by walking out of it; return true iff moving should continue to intended destination (all failures and most successful escapes leave hero at original spot) */

Source from the content-addressed store, hash-verified

1547 return true iff moving should continue to intended destination
1548 (all failures and most successful escapes leave hero at original spot) */
1549staticfn boolean
1550trapmove(
1551 coordxy x, coordxy y, /* targeted destination, <u.ux+u.dx,u.uy+u.dy> */
1552 struct trap *desttrap) /* nonnull if another trap at <x,y> */
1553{
1554 boolean anchored = FALSE;
1555 const char *predicament, *culprit;
1556 char *steedname = !u.usteed ? (char *) 0 : y_monnam(u.usteed);
1557
1558 if (!u.utrap)
1559 return TRUE; /* sanity check */
1560
1561 /*
1562 * Note: caller should call reset_utrap() when we set u.utrap to 0.
1563 */
1564
1565 switch (u.utraptype) {
1566 case TT_BEARTRAP:
1567 if (flags.verbose) {
1568 predicament = "caught in a bear trap";
1569 if (u.usteed)
1570 Norep("%s is %s.", upstart(steedname), predicament);
1571 else
1572 Norep("You are %s.", predicament);
1573 }
1574 /* [why does diagonal movement give quickest escape?] */
1575 if ((u.dx && u.dy) || !rn2(5))
1576 u.utrap--;
1577 if (!u.utrap)
1578 goto wriggle_free;
1579 break;
1580 case TT_PIT:
1581 if (desttrap && desttrap->tseen
1582 && is_pit(desttrap->ttyp))
1583 return TRUE; /* move into adjacent pit */
1584 /* try to escape; position stays same regardless of success */
1585 climb_pit();
1586 break;
1587 case TT_WEB:
1588 if (u_wield_art(ART_STING)) {
1589 /* escape trap but don't move and don't destroy it */
1590 u.utrap = 0; /* caller will call reset_utrap() */
1591 pline("Sting cuts through the web!");
1592 break;
1593 }
1594 if (--u.utrap) {
1595 if (flags.verbose) {
1596 predicament = "stuck to the web";
1597 if (u.usteed)
1598 Norep("%s is %s.", upstart(steedname), predicament);
1599 else
1600 Norep("You are %s.", predicament);
1601 }
1602 } else {
1603 if (u.usteed)
1604 pline("%s breaks out of the web.", upstart(steedname));
1605 else
1606 You("disentangle yourself.");

Callers 1

domove_coreFunction · 0.85

Calls 14

y_monnamFunction · 0.85
NorepFunction · 0.85
upstartFunction · 0.85
rn2Function · 0.85
climb_pitFunction · 0.85
YouFunction · 0.85
is_lavaFunction · 0.85
hliquidFunction · 0.85
buried_ballFunction · 0.85
dist2Function · 0.85
surfaceFunction · 0.85

Tested by

no test coverage detected