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

Function do_light_sources

src/light.c:168–250  ·  view source on GitHub ↗

Mark locations that are temporarily lit via mobile light sources. */

Source from the content-addressed store, hash-verified

166
167/* Mark locations that are temporarily lit via mobile light sources. */
168void
169do_light_sources(seenV **cs_rows)
170{
171 coordxy x, y, min_x, max_x, max_y;
172 int offset;
173 const coordxy *limits;
174 short at_hero_range = 0;
175 light_source *ls;
176 seenV *row;
177
178 for (ls = gl.light_base; ls; ls = ls->next) {
179 ls->flags &= ~LSF_SHOW;
180
181 /*
182 * Check for moved light sources. It may be possible to
183 * save some effort if an object has not moved, but not in
184 * the current setup -- we need to recalculate for every
185 * vision recalc.
186 */
187 if (ls->type == LS_OBJECT) {
188 if (ls->range == 0 /* camera flash; caller has set ls->{x,y} */
189 || get_obj_location(ls->id.a_obj, &ls->x, &ls->y, 0))
190 ls->flags |= LSF_SHOW;
191 } else if (ls->type == LS_MONSTER) {
192 if (get_mon_location(ls->id.a_monst, &ls->x, &ls->y, 0))
193 ls->flags |= LSF_SHOW;
194 }
195
196 /* minor optimization: don't bother with duplicate light sources
197 at hero */
198 if (u_at(ls->x, ls->y)) {
199 if (at_hero_range >= ls->range)
200 ls->flags &= ~LSF_SHOW;
201 else
202 at_hero_range = ls->range;
203 }
204
205 if (ls->flags & LSF_SHOW) {
206 /*
207 * Walk the points in the circle and see if they are
208 * visible from the center. If so, mark'em.
209 *
210 * Kevin's tests indicated that doing this brute-force
211 * method is faster for radius <= 3 (or so).
212 */
213 limits = circle_ptr(ls->range);
214 if ((max_y = (ls->y + ls->range)) >= ROWNO)
215 max_y = ROWNO - 1;
216 if ((y = (ls->y - ls->range)) < 0)
217 y = 0;
218 for (; y <= max_y; y++) {
219 row = cs_rows[y];
220 offset = limits[abs(y - ls->y)];
221 if ((min_x = (ls->x - offset)) < 1)
222 min_x = 1;
223 if ((max_x = (ls->x + offset)) >= COLNO)
224 max_x = COLNO - 1;
225

Callers 1

vision_recalcFunction · 0.85

Calls 3

get_obj_locationFunction · 0.85
get_mon_locationFunction · 0.85
clear_pathFunction · 0.85

Tested by

no test coverage detected