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

Function do_clear_area

src/vision.c:2106–2148  ·  view source on GitHub ↗

* AREA OF EFFECT "ENGINE" * * Calculate all possible visible locations as viewed from the given location * (srow,scol) within the range specified. Perform "func" with (x, y) args and * additional argument "arg" for each square. * * If not centered on the hero, just forward arguments to view_from(); it * will call "func" when necessary. If the hero is the center, use the * vision matrix an

Source from the content-addressed store, hash-verified

2104 * vision matrix and reduce extra work.
2105 */
2106void
2107do_clear_area(
2108 coordxy scol, coordxy srow,
2109 int range,
2110 void (*func)(coordxy, coordxy, genericptr_t),
2111 genericptr_t arg)
2112{
2113 /* If not centered on hero, do the hard work of figuring the area */
2114 if (scol != u.ux || srow != u.uy) {
2115 view_from(srow, scol, (seenV **) 0, (coordxy *) 0, (coordxy *) 0,
2116 range, func, arg);
2117 } else {
2118 int x;
2119 int y, min_x, max_x, max_y, offset;
2120 const coordxy *limits;
2121 boolean override_vision;
2122
2123 /* vision doesn't pass through water or clouds, detection should
2124 [this probably ought to be an arg supplied by our caller...] */
2125 override_vision = (detecting(func)
2126 && (Is_waterlevel(&u.uz) || Is_airlevel(&u.uz)));
2127
2128 if (range > MAX_RADIUS || range < 1)
2129 panic("do_clear_area: illegal range %d", range);
2130 if (gv.vision_full_recalc)
2131 vision_recalc(0); /* recalc vision if dirty */
2132 limits = circle_ptr(range);
2133 if ((max_y = (srow + range)) >= ROWNO)
2134 max_y = ROWNO - 1;
2135 if ((y = (srow - range)) < 0)
2136 y = 0;
2137 for (; y <= max_y; y++) {
2138 offset = limits[v_abs(y - srow)];
2139 if ((min_x = (scol - offset)) < 1)
2140 min_x = 1;
2141 if ((max_x = (scol + offset)) >= COLNO)
2142 max_x = COLNO - 1;
2143 for (x = min_x; x <= max_x; x++)
2144 if (couldsee(x, y) || override_vision)
2145 (*func)(x, y, arg);
2146 }
2147 }
2148}
2149
2150/* bitmask indicating ways mon is seen; extracted from lookat(pager.c) */
2151unsigned

Callers 5

finditFunction · 0.85
openitFunction · 0.85
dog_goalFunction · 0.85
litroomFunction · 0.85
dogushforthFunction · 0.85

Calls 4

view_fromFunction · 0.85
detectingFunction · 0.85
vision_recalcFunction · 0.85
panicFunction · 0.50

Tested by

no test coverage detected