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

Function doidtrap

src/pager.c:2335–2389  ·  view source on GitHub ↗

the #showtrap command */

Source from the content-addressed store, hash-verified

2333
2334/* the #showtrap command */
2335int
2336doidtrap(void)
2337{
2338 struct trap *trap;
2339 int tt, glyph;
2340 coordxy x, y;
2341
2342 if (!getdir("^"))
2343 return ECMD_CANCEL;
2344 x = u.ux + u.dx;
2345 y = u.uy + u.dy;
2346
2347 /* trapped doors and chests used to be shown as fake bear traps;
2348 they have their own trap types now but aren't part of the ftrap
2349 chain; usually they revert to normal door or chest when the hero
2350 sees them but player might be using '^' while the hero is blind */
2351 glyph = glyph_at(x, y);
2352 if (glyph_is_trap(glyph)
2353 && ((tt = glyph_to_trap(glyph)) == BEAR_TRAP
2354 || tt == TRAPPED_DOOR || tt == TRAPPED_CHEST)) {
2355 boolean chesttrap = trapped_chest_at(tt, x, y);
2356
2357 if (chesttrap || trapped_door_at(tt, x, y)) {
2358 pline("That is a trapped %s.", chesttrap ? "chest" : "door");
2359 return ECMD_OK; /* trap ID'd, but no time elapses */
2360 }
2361 }
2362
2363 for (trap = gf.ftrap; trap; trap = trap->ntrap)
2364 if (trap->tx == x && trap->ty == y) {
2365 if (!trap->tseen)
2366 break;
2367 tt = trap->ttyp;
2368 if (u.dz) {
2369 if (u.dz < 0 ? is_hole(tt) : tt == ROCKTRAP)
2370 break;
2371 }
2372 pline("That is %s%s%s.",
2373 an(trapname(tt, FALSE)),
2374 !trap->madeby_u
2375 ? ""
2376 : (tt == WEB)
2377 ? " woven"
2378 /* trap doors & spiked pits can't be made by
2379 player, and should be considered at least
2380 as much "set" as "dug" anyway */
2381 : (tt == HOLE || tt == PIT)
2382 ? " dug"
2383 : " set",
2384 !trap->madeby_u ? "" : " by you");
2385 return ECMD_OK;
2386 }
2387 pline("I can't see a trap there.");
2388 return ECMD_OK;
2389}
2390
2391/*
2392 Implements a rudimentary if/elif/else/endif interpreter and use

Callers

nothing calls this directly

Calls 7

getdirFunction · 0.85
glyph_atFunction · 0.85
trapped_chest_atFunction · 0.85
trapped_door_atFunction · 0.85
anFunction · 0.85
trapnameFunction · 0.85
plineFunction · 0.70

Tested by

no test coverage detected