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

Function look_traps

src/pager.c:2077–2139  ·  view source on GitHub ↗

give a /M style display of discovered traps, even when they're covered */

Source from the content-addressed store, hash-verified

2075
2076/* give a /M style display of discovered traps, even when they're covered */
2077staticfn void
2078look_traps(boolean nearby)
2079{
2080 winid win;
2081 struct trap *t;
2082 int glyph, tnum, count = 0;
2083 coordxy x, y, lo_x, lo_y, hi_x, hi_y;
2084 char lookbuf[BUFSZ], outbuf[BUFSZ];
2085
2086 win = create_nhwindow(NHW_TEXT);
2087 look_region_nearby(&lo_x, &lo_y, &hi_x, &hi_y, nearby);
2088 for (y = lo_y; y <= hi_y; y++) {
2089 for (x = lo_x; x <= hi_x; x++) {
2090 lookbuf[0] = '\0';
2091 glyph = glyph_at(x, y);
2092 if (glyph_is_trap(glyph)) {
2093 tnum = glyph_to_trap(glyph);
2094 trap_description(lookbuf, tnum, x, y);
2095 ++count;
2096 } else if ((t = t_at(x, y)) != 0 && t->tseen
2097 /* can't use /" to track traps moved by bubbles or
2098 clouds except when hero has direct line of sight */
2099 && ((!Is_waterlevel(&u.uz) && !Is_airlevel(&u.uz))
2100 || couldsee(x, y))) {
2101 Strcpy(lookbuf, trapname(t->ttyp, FALSE));
2102 Sprintf(eos(lookbuf), ", obscured by %s", encglyph(glyph));
2103 glyph = trap_to_glyph(t);
2104 ++count;
2105 }
2106 if (*lookbuf) {
2107 char coordbuf[20], cmode;
2108
2109 cmode = (iflags.getpos_coords != GPCOORDS_NONE)
2110 ? iflags.getpos_coords : GPCOORDS_MAP;
2111 if (count == 1) {
2112 Sprintf(outbuf, "%sseen or remembered traps%s:",
2113 nearby ? "nearby " : "",
2114 nearby ? "" : " on this level");
2115 putstr(win, 0, upstart(outbuf));
2116 /* hack alert! Qt watches a text window for any line
2117 with 4 consecutive spaces and renders the window
2118 in a fixed-width font it if finds at least one */
2119 putstr(win, 0, " "); /* separator */
2120 }
2121 /* prefix: "coords C " where 'C' is trap symbol */
2122 Sprintf(outbuf, (cmode == GPCOORDS_SCREEN) ? "%s "
2123 : (cmode == GPCOORDS_MAP) ? "%8s "
2124 : "%12s ",
2125 coord_desc(x, y, coordbuf, cmode));
2126 Sprintf(eos(outbuf), "%s ", encglyph(glyph));
2127 /* guard against potential overflow */
2128 lookbuf[sizeof lookbuf - 1 - strlen(outbuf)] = '\0';
2129 Strcat(outbuf, lookbuf);
2130 putmixed(win, 0, outbuf);
2131 }
2132 }
2133 }
2134 if (count)

Callers 1

do_lookFunction · 0.85

Calls 10

look_region_nearbyFunction · 0.85
glyph_atFunction · 0.85
trap_descriptionFunction · 0.85
t_atFunction · 0.85
trapnameFunction · 0.85
eosFunction · 0.85
encglyphFunction · 0.85
upstartFunction · 0.85
coord_descFunction · 0.85
plineFunction · 0.70

Tested by

no test coverage detected