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

Function rogue_vision

src/vision.c:313–364  ·  view source on GitHub ↗

* rogue_vision() * * Set the "could see" and in sight bits so vision acts just like the old * rogue game: * * + If in a room, the hero can see to the room boundaries. * + The hero can always see adjacent squares. * * We set the in_sight bit here as well to escape a bug that shows up * due to the one-sided lit wall hack. */

Source from the content-addressed store, hash-verified

311 * due to the one-sided lit wall hack.
312 */
313staticfn void
314rogue_vision(seenV **next, coordxy *rmin, coordxy *rmax)
315{
316 int rnum = levl[u.ux][u.uy].roomno - ROOMOFFSET; /* no SHARED... */
317 int start, stop, in_door, xhi, xlo, yhi, ylo;
318 int zx, zy;
319
320 /* If in a lit room, we are able to see to its boundaries. */
321 /* If dark, set COULD_SEE so various spells work -dlc */
322 if (rnum >= 0) {
323 for (zy = svr.rooms[rnum].ly - 1; zy <= svr.rooms[rnum].hy + 1; zy++) {
324 rmin[zy] = start = svr.rooms[rnum].lx - 1;
325 rmax[zy] = stop = svr.rooms[rnum].hx + 1;
326
327 for (zx = start; zx <= stop; zx++) {
328 if (svr.rooms[rnum].rlit) {
329 next[zy][zx] = COULD_SEE | IN_SIGHT;
330 levl[zx][zy].seenv = SVALL; /* see the walls */
331 } else
332 next[zy][zx] = COULD_SEE;
333 }
334 }
335 }
336
337 in_door = levl[u.ux][u.uy].typ == DOOR;
338
339 /* Can always see adjacent. */
340 ylo = max(u.uy - 1, 0);
341 yhi = min(u.uy + 1, ROWNO - 1);
342 xlo = max(u.ux - 1, 1);
343 xhi = min(u.ux + 1, COLNO - 1);
344 for (zy = ylo; zy <= yhi; zy++) {
345 if (xlo < rmin[zy])
346 rmin[zy] = xlo;
347 if (xhi > rmax[zy])
348 rmax[zy] = xhi;
349
350 for (zx = xlo; zx <= xhi; zx++) {
351 next[zy][zx] = COULD_SEE | IN_SIGHT;
352 /*
353 * Yuck, update adjacent non-diagonal positions when in a doorway.
354 * We need to do this to catch the case when we first step into
355 * a room. The room's walls were not seen from the outside, but
356 * now are seen (the seen bits are set just above). However, the
357 * positions are not updated because they were already in sight.
358 * So, we have to do it here.
359 */
360 if (in_door && (zx == u.ux || zy == u.uy))
361 newsym(zx, zy);
362 }
363 }
364}
365
366/*#define EXTEND_SPINE*/ /* possibly better looking wall-angle */
367

Callers 1

vision_recalcFunction · 0.85

Calls 1

newsymFunction · 0.85

Tested by

no test coverage detected