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

Function view_from

src/vision.c:2001–2091  ·  view source on GitHub ↗

* Calculate all possible visible locations from the given location * (srow,scol). NOTE this is (y,x)! Mark the visible locations in the * array provided. * * Arguments * srow, scol starting row and column * loc_cs_rows pointers to the rows of the could_see array * left_most min mark on each row * right_most max mark on each row * range 0 if unlimited

Source from the content-addressed store, hash-verified

1999 * arg argument for func
2000 */
2001staticfn void
2002view_from(
2003 coordxy srow, coordxy scol,
2004 seenV **loc_cs_rows,
2005 coordxy *left_most, coordxy *right_most,
2006 int range,
2007 void (*func)(coordxy, coordxy, genericptr_t),
2008 genericptr_t arg)
2009{
2010 int i; /* loop counter */
2011 seenV *rowp; /* optimization for setting could_see */
2012 int nrow; /* the next row */
2013 int left; /* the left-most visible column */
2014 int right; /* the right-most visible column */
2015 const coordxy *limits; /* range limit for next row */
2016
2017 /* Set globals for q?_path(), left_side(), and right_side() to use. */
2018 start_col = scol;
2019 start_row = srow;
2020 cs_rows = loc_cs_rows; /* 'could see' rows */
2021 cs_left = left_most;
2022 cs_right = right_most;
2023 vis_func = func;
2024 varg = arg;
2025
2026 /*
2027 * Determine extent of sight on the starting row.
2028 */
2029 if (is_clear(srow, scol)) {
2030 left = left_ptrs[srow][scol];
2031 right = right_ptrs[srow][scol];
2032 } else {
2033 /*
2034 * When in stone, you can only see your adjacent squares, unless
2035 * you are on an array boundary or a stone/clear boundary.
2036 */
2037 left = (!scol) ? 0
2038 : (is_clear(srow, scol - 1) ? left_ptrs[srow][scol - 1]
2039 : scol - 1);
2040 right = (scol == COLNO - 1)
2041 ? COLNO - 1
2042 : (is_clear(srow, scol + 1) ? right_ptrs[srow][scol + 1]
2043 : scol + 1);
2044 }
2045
2046 if (range) {
2047 if (range > MAX_RADIUS || range < 1)
2048 panic("view_from called with range %d", range);
2049 limits = circle_ptr(range) + 1; /* start at next row */
2050 if (left < scol - range)
2051 left = scol - range;
2052 if (right > scol + range)
2053 right = scol + range;
2054 } else
2055 limits = (coordxy *) 0;
2056
2057 if (func) {
2058 for (i = left; i <= right; i++)

Callers 2

vision_recalcFunction · 0.85
do_clear_areaFunction · 0.85

Calls 3

right_sideFunction · 0.85
left_sideFunction · 0.85
panicFunction · 0.50

Tested by

no test coverage detected