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

Function untrap

src/trap.c:5847–6096  ·  view source on GitHub ↗

hero is able to attempt untrap, so do so */

Source from the content-addressed store, hash-verified

5845
5846/* hero is able to attempt untrap, so do so */
5847int
5848untrap(
5849 boolean force,
5850 coordxy rx, coordxy ry,
5851 struct obj *container)
5852{
5853 struct obj *otmp;
5854 coordxy x, y;
5855 int ch;
5856 struct trap *ttmp;
5857 struct monst *mtmp;
5858 const char *trapdescr;
5859 boolean here, useplural, deal_with_floor_trap,
5860 confused = (Confusion || Hallucination),
5861 trap_skipped = FALSE, autounlock_door = FALSE;
5862 int boxcnt = 0;
5863 char the_trap[BUFSZ], qbuf[QBUFSZ];
5864
5865 /* 'force' is true for #invoke; if carrying MKoT, make it be true
5866 for #untrap or autounlock */
5867 if (!force && has_magic_key(&gy.youmonst))
5868 force = TRUE;
5869
5870 if (!rx && !container) {
5871 /* usual case */
5872 if (!getdir((char *) 0))
5873 return 0;
5874 x = u.ux + u.dx;
5875 y = u.uy + u.dy;
5876 } else {
5877 /* autounlock's untrap; skip most prompting */
5878 if (container) {
5879 untrap_box(container, force, confused);
5880 return 1;
5881 }
5882 /* levl[rx][ry] is a locked or trapped door */
5883 x = rx, y = ry;
5884 autounlock_door = TRUE;
5885 }
5886 if (!isok(x, y)) {
5887 pline_The("perils lurking there are beyond your grasp.");
5888 return 0;
5889 }
5890
5891 ttmp = t_at(x, y);
5892 if (ttmp && !ttmp->tseen)
5893 ttmp = 0;
5894 trapdescr = ttmp ? trapname(ttmp->ttyp, FALSE) : 0;
5895 here = u_at(x, y); /* !u.dx && !u.dy */
5896
5897 if (here) /* are there are one or more containers here? */
5898 for (otmp = svl.level.objects[x][y]; otmp; otmp = otmp->nexthere)
5899 if (Is_box(otmp)) {
5900 if (++boxcnt > 1)
5901 break;
5902 }
5903
5904 deal_with_floor_trap = can_reach_floor(FALSE);

Callers 3

invoke_untrapFunction · 0.85
pick_lockFunction · 0.85
dountrapFunction · 0.85

Calls 15

has_magic_keyFunction · 0.85
getdirFunction · 0.85
untrap_boxFunction · 0.85
isokFunction · 0.85
pline_TheFunction · 0.85
t_atFunction · 0.85
trapnameFunction · 0.85
can_reach_floorFunction · 0.85
anFunction · 0.85
ThereFunction · 0.85
theFunction · 0.85
You_cantFunction · 0.85

Tested by

no test coverage detected