--- deliantra/server/common/los.C 2008/12/08 15:40:13 1.36 +++ deliantra/server/common/los.C 2008/12/21 21:20:35 1.44 @@ -24,278 +24,233 @@ /* Nov 95 - inserted USE_LIGHTING code stuff in here - b.t. */ #include -#include - -/* Distance must be less than this for the object to be blocked. - * An object is 1.0 wide, so if set to 0.5, it means the object - * that blocks half the view (0.0 is complete block) will - * block view in our tables. - * .4 or less lets you see through walls. .5 is about right. - */ - -#define SPACE_BLOCK 0.5 - -typedef struct blstr -{ - int x[4], y[4]; - int index; -} blocks; - -// 31/32 == a speed hack -// we would like to use 32 for speed, but the code loops endlessly -// then, reason not yet identified, so only make the array use 32, -// not the define's. -blocks block[MAP_CLIENT_X][MAP_CLIENT_Y == 31 ? 32 : MAP_CLIENT_Y]; +#include static void expand_lighted_sight (object *op); +enum { + LOS_XI = 0x01, + LOS_YI = 0x02, +}; + +struct los_info +{ + sint8 xo, yo; // obscure angle + sint8 xe, ye; // angle deviation + uint8 culled; // culled from "tree" + uint8 queued; // already queued + uint8 visible; + uint8 flags; // LOS_XI/YI +}; + +// temporary storage for the los algorithm, +// one los_info for each lightable map space +static los_info los[MAP_CLIENT_X][MAP_CLIENT_Y]; + +struct point +{ + sint8 x, y; +}; + +// minimum size, but must be a power of two +#define QUEUE_LENGTH ((MAP_CLIENT_X + MAP_CLIENT_Y) * 2) + +// a queue of spaces to calculate +static point queue [QUEUE_LENGTH]; +static int q1, q2; // queue start, end + /* - * Used to initialise the array used by the LOS routines. - * What this sets if that x,y blocks the view of bx,by - * This then sets up a relation - for example, something - * at 5,4 blocks view at 5,3 which blocks view at 5,2 - * etc. So when we check 5,4 and find it block, we have - * the data to know that 5,3 and 5,2 and 5,1 should also - * be blocked. + * Clears/initialises the los-array associated to the player + * controlling the object. */ - -static void -set_block (int x, int y, int bx, int by) +void +player::clear_los (sint8 value) { - int index = block[x][y].index, i; - - /* Due to flipping, we may get duplicates - better safe than sorry. - */ - for (i = 0; i < index; i++) - { - if (block[x][y].x[i] == bx && block[x][y].y[i] == by) - return; - } - - block[x][y].x[index] = bx; - block[x][y].y[index] = by; - block[x][y].index++; -#ifdef LOS_DEBUG - LOG (llevDebug, "setblock: added %d %d -> %d %d (%d)\n", x, y, bx, by, block[x][y].index); -#endif + memset (los, value, sizeof (los)); } -/* - * initialises the array used by the LOS routines. - */ - -/* since we are only doing the upper left quadrant, only - * these spaces could possibly get blocked, since these - * are the only ones further out that are still possibly in the - * sightline. - */ - -void -init_block (void) +// enqueue a single mapspace, but only if it hasn't +// been enqueued yet. +static void +enqueue (sint8 dx, sint8 dy, uint8 flags = 0) { - int x, y, dx, dy, i; - static int block_x[3] = { -1, -1, 0 }, - block_y[3] = { -1, 0, -1 }; + sint8 x = LOS_X0 + dx; + sint8 y = LOS_Y0 + dy; - for (x = 0; x < MAP_CLIENT_X; x++) - for (y = 0; y < MAP_CLIENT_Y; y++) - block[x][y].index = 0; + if (x < 0 || x >= MAP_CLIENT_X) return; + if (y < 0 || y >= MAP_CLIENT_Y) return; + los_info &l = los[x][y]; - /* The table should be symmetric, so only do the upper left - * quadrant - makes the processing easier. - */ - for (x = 1; x <= MAP_CLIENT_X / 2; x++) - { - for (y = 1; y <= MAP_CLIENT_Y / 2; y++) - { - for (i = 0; i < 3; i++) - { - dx = x + block_x[i]; - dy = y + block_y[i]; + l.flags |= flags; - /* center space never blocks */ - if (x == MAP_CLIENT_X / 2 && y == MAP_CLIENT_Y / 2) - continue; + if (l.queued) + return; - /* If its a straight line, its blocked */ - if ((dx == x && x == MAP_CLIENT_X / 2) || (dy == y && y == MAP_CLIENT_Y / 2)) - { - /* For simplicity, we mirror the coordinates to block the other - * quadrants. - */ - set_block (x, y, dx, dy); - if (x == MAP_CLIENT_X / 2) - set_block (x, MAP_CLIENT_Y - y - 1, dx, MAP_CLIENT_Y - dy - 1); - else if (y == MAP_CLIENT_Y / 2) - set_block (MAP_CLIENT_X - x - 1, y, MAP_CLIENT_X - dx - 1, dy); - } - else - { - float d1, r, s, l; + l.queued = 1; - /* We use the algorihm that found out how close the point - * (x,y) is to the line from dx,dy to the center of the viewable - * area. l is the distance from x,y to the line. - * r is more a curiosity - it lets us know what direction (left/right) - * the line is off - */ - - d1 = (float) (pow (MAP_CLIENT_X / 2 - dx, 2.f) + pow (MAP_CLIENT_Y / 2 - dy, 2.f)); - r = (float) ((dy - y) * (dy - MAP_CLIENT_Y / 2) - (dx - x) * (MAP_CLIENT_X / 2 - dx)) / d1; - s = (float) ((dy - y) * (MAP_CLIENT_X / 2 - dx) - (dx - x) * (MAP_CLIENT_Y / 2 - dy)) / d1; - l = FABS (sqrt (d1) * s); + queue[q1].x = dx; + queue[q1].y = dy; - if (l <= SPACE_BLOCK) - { - /* For simplicity, we mirror the coordinates to block the other - * quadrants. - */ - set_block (x, y, dx, dy); - set_block (MAP_CLIENT_X - x - 1, y, MAP_CLIENT_X - dx - 1, dy); - set_block (x, MAP_CLIENT_Y - y - 1, dx, MAP_CLIENT_Y - dy - 1); - set_block (MAP_CLIENT_X - x - 1, MAP_CLIENT_Y - y - 1, MAP_CLIENT_X - dx - 1, MAP_CLIENT_Y - dy - 1); - } - } - } - } - } + q1 = (q1 + 1) & (QUEUE_LENGTH - 1); } -/* - * Used to initialise the array used by the LOS routines. - * x,y are indexes into the blocked[][] array. - * This recursively sets the blocked line of sight view. - * From the blocked[][] array, we know for example - * that if some particular space is blocked, it blocks - * the view of the spaces 'behind' it, and those blocked - * spaces behind it may block other spaces, etc. - * In this way, the chain of visibility is set. - */ +// run the los algorithm +// this is a variant of a spiral los algorithm taken from +// http://www.geocities.com/temerra/los_rays.html +// which has been simplified and changed considerably, but +// still is basically the same algorithm. static void -set_wall (object *op, int x, int y) +do_los (object *op) { - int i; + player *pl = op->contr; + + int max_radius = max (pl->ns->mapx, pl->ns->mapy) / 2; + + memset (los, 0, sizeof (los)); + + q1 = 0; q2 = 0; // initialise queue, not strictly required + enqueue (0, 0); // enqueue center + + // treat the origin specially + los[LOS_X0][LOS_Y0].visible = 1; + pl->los[LOS_X0][LOS_Y0] = 0; - for (i = 0; i < block[x][y].index; i++) + // loop over all enqueued points until the queue is empty + // the order in which this is done ensures that we + // never touch a mapspace whose input spaces we haven't checked + // yet. + while (q1 != q2) { - int dx = block[x][y].x[i], dy = block[x][y].y[i], ax, ay; + sint8 dx = queue[q2].x; + sint8 dy = queue[q2].y; - /* ax, ay are the values as adjusted to be in the - * socket look structure. - */ - ax = dx - (MAP_CLIENT_X - op->contr->ns->mapx) / 2; - ay = dy - (MAP_CLIENT_Y - op->contr->ns->mapy) / 2; + q2 = (q2 + 1) & (QUEUE_LENGTH - 1); - if (ax < 0 || ax >= op->contr->ns->mapx || ay < 0 || ay >= op->contr->ns->mapy) - continue; -#if 0 - LOG (llevDebug, "blocked %d %d -> %d %d\n", dx, dy, ax, ay); -#endif - /* we need to adjust to the fact that the socket - * code wants the los to start from the 0,0 - * and not be relative to middle of los array. - */ - op->contr->blocked_los[ax][ay] = LOS_BLOCKED; - set_wall (op, dx, dy); - } -} + sint8 x = LOS_X0 + dx; + sint8 y = LOS_Y0 + dy; -/* - * Used to initialise the array used by the LOS routines. - * op is the object, x and y values based on MAP_CLIENT_X and Y. - * this is because they index the blocked[][] arrays. - */ + //int distance = idistance (dx, dy); if (distance > max_radius) continue;//D + int distance = 0;//D -static void -check_wall (object *op, int x, int y) -{ - int ax, ay; + los_info &l = los[x][y]; - if (!block[x][y].index) - return; + if (expect_true (l.flags & (LOS_XI | LOS_YI))) + { + l.culled = 1; - /* ax, ay are coordinates as indexed into the look window */ - ax = x - (MAP_CLIENT_X - op->contr->ns->mapx) / 2; - ay = y - (MAP_CLIENT_Y - op->contr->ns->mapy) / 2; + // check contributing spaces, first horizontal + if (expect_true (l.flags & LOS_XI)) + { + los_info *xi = &los[x - sign (dx)][y]; - /* If the converted coordinates are outside the viewable - * area for the client, return now. - */ - if (ax < 0 || ay < 0 || ax >= op->contr->ns->mapx || ay >= op->contr->ns->mapy) - return; + // don't cull unless obscured + l.culled &= !xi->visible; -#if 0 - LOG (llevDebug, "check_wall, ax,ay=%d, %d x,y = %d, %d blocksview = %d, %d\n", - ax, ay, x, y, op->x + x - MAP_CLIENT_X / 2, op->y + y - MAP_CLIENT_Y / 2); -#endif - - /* If this space is already blocked, prune the processing - presumably - * whatever has set this space to be blocked has done the work and already - * done the dependency chain. - */ - if (op->contr->blocked_los[ax][ay] == LOS_BLOCKED) - return; + /* merge input space */ + if (expect_false (xi->xo || xi->yo)) + { + // The X input can provide two main pieces of information: + // 1. Progressive X obscurity. + // 2. Recessive Y obscurity. + + // Progressive X obscurity, favouring recessive input angle + if (xi->xe > 0 && l.xo == 0) + { + l.xe = xi->xe - xi->yo; + l.ye = xi->ye + xi->yo; + l.xo = xi->xo; + l.yo = xi->yo; + } - if (get_map_flags (op->map, NULL, op->x + x - MAP_CLIENT_X / 2, op->y + y - MAP_CLIENT_Y / 2, NULL, NULL) & (P_BLOCKSVIEW | P_OUT_OF_MAP)) - set_wall (op, x, y); -} + // Recessive Y obscurity + if (xi->ye <= 0 && xi->yo > 0 && xi->xe > 0) + { + l.ye = xi->yo + xi->ye; + l.xe = xi->xe - xi->yo; + l.xo = xi->xo; + l.yo = xi->yo; + } + } + } + + // check contributing spaces, last vertical, identical structure + if (expect_true (l.flags & LOS_YI)) + { + los_info *yi = &los[x][y - sign (dy)]; -/* - * Clears/initialises the los-array associated to the player - * controlling the object. - */ + // don't cull unless obscured + l.culled &= !yi->visible; -void -clear_los (player *pl) -{ - /* This is safer than using the ns->mapx, mapy because - * we index the blocked_los as a 2 way array, so clearing - * the first z spaces may not not cover the spaces we are - * actually going to use - */ - memset (pl->blocked_los, 0, MAP_CLIENT_X * MAP_CLIENT_Y); -} + /* merge input space */ + if (expect_false (yi->yo || yi->xo)) + { + // The Y input can provide two main pieces of information: + // 1. Progressive Y obscurity. + // 2. Recessive X obscurity. + + // Progressive Y obscurity, favouring recessive input angle + if (yi->ye > 0 && l.yo == 0) + { + l.ye = yi->ye - yi->xo; + l.xe = yi->xe + yi->xo; + l.yo = yi->yo; + l.xo = yi->xo; + } -/* - * expand_sight goes through the array of what the given player is - * able to see, and expands the visible area a bit, so the player will, - * to a certain degree, be able to see into corners. - * This is somewhat suboptimal, would be better to improve the formula. - */ + // Recessive X obscurity + if (yi->xe <= 0 && yi->xo > 0 && yi->ye > 0) + { + l.xe = yi->xo + yi->xe; + l.ye = yi->ye - yi->xo; + l.yo = yi->yo; + l.xo = yi->xo; + } + } + } -static void -expand_sight (object *op) -{ - int i, x, y, dx, dy; + // check whether this space blocks the view + maptile *m = op->map; + sint16 nx = op->x + dx; + sint16 ny = op->y + dy; - for (x = 1; x < op->contr->ns->mapx - 1; x++) /* loop over inner squares */ - for (y = 1; y < op->contr->ns->mapy - 1; y++) - { - if (!op->contr->blocked_los[x][y] && - !(get_map_flags (op->map, NULL, - op->x - op->contr->ns->mapx / 2 + x, - op->y - op->contr->ns->mapy / 2 + y, NULL, NULL) & (P_BLOCKSVIEW | P_OUT_OF_MAP))) - { + if (expect_true (!xy_normalise (m, nx, ny)) + || expect_false (m->at (nx, ny).flags () & P_BLOCKSVIEW)) + { + l.xo = l.xe = abs (dx); + l.yo = l.ye = abs (dy); - for (i = 1; i <= 8; i += 1) - { /* mark all directions */ - dx = x + freearr_x[i]; - dy = y + freearr_y[i]; - if (op->contr->blocked_los[dx][dy] > 0) /* for any square blocked */ - op->contr->blocked_los[dx][dy] = -1; - } - } - } + // we obscure dependents, but might be visible + // copy the los from the square towards the player, + // so outward diagonal corners are lit. + pl->los[x][y] = los[x - sign0 (dx)][y - sign0 (dy)].visible ? 0 : LOS_BLOCKED; + l.visible = false; + } + else + { + // we are not blocked, so calculate visibility, by checking + // whether we are inside or outside the shadow + l.visible = (l.xe <= 0 || l.xe > l.xo) + && (l.ye <= 0 || l.ye > l.yo); + + pl->los[x][y] = l.culled ? LOS_BLOCKED + : l.visible ? max (0, 2 - max_radius + distance) + : 3; + } - if (op->map->darkness > 0) /* player is on a dark map */ - expand_lighted_sight (op); + } - /* clear mark squares */ - for (x = 0; x < op->contr->ns->mapx; x++) - for (y = 0; y < op->contr->ns->mapy; y++) - if (op->contr->blocked_los[x][y] < 0) - op->contr->blocked_los[x][y] = 0; + // Expands by the unit length in each component's current direction. + // If a component has no direction, then it is expanded in both of its + // positive and negative directions. + if (!l.culled) + { + if (dx >= 0) enqueue (dx + 1, dy, LOS_XI); + if (dx <= 0) enqueue (dx - 1, dy, LOS_XI); + if (dy >= 0) enqueue (dx, dy + 1, LOS_YI); + if (dy <= 0) enqueue (dx, dy - 1, LOS_YI); + } + } } /* returns true if op carries one or more lights @@ -303,7 +258,6 @@ * be a bit longer. Probably better for callers to just * check the op->glow_radius instead of calling this. */ - int has_carried_lights (const object *op) { @@ -315,11 +269,11 @@ } /* radius, distance => lightness adjust */ -static sint8 darkness[MAX_LIGHT_RADIUS * 2 + 1][MAX_LIGHT_RADIUS * 3 / 2 + 1]; +static sint8 light_atten[MAX_LIGHT_RADIUS * 2 + 1][MAX_LIGHT_RADIUS * 3 / 2 + 1]; -static struct darkness_init +static struct los_init { - darkness_init () + los_init () { for (int radius = -MAX_LIGHT_RADIUS; radius <= MAX_LIGHT_RADIUS; ++radius) for (int distance = 0; distance <= MAX_LIGHT_RADIUS * 3 / 2; ++distance) @@ -330,17 +284,56 @@ // actual intensity intensity = max (0, lerp_rd (distance, 0, abs (radius) + 1, intensity, 0)); - darkness [radius + MAX_LIGHT_RADIUS][distance] = radius < 0 + light_atten [radius + MAX_LIGHT_RADIUS][distance] = radius < 0 ? min (3, intensity) : LOS_MAX - intensity; } } -} darkness_init; +} los_init; + +sint8 +los_brighten (sint8 b, sint8 l) +{ + return b == LOS_BLOCKED ? b : min (b, l); +} +sint8 +los_darken (sint8 b, sint8 l) +{ + return max (b, l); +} + +template static void -expand_lighted_sight (object *op) +apply_light (object *op, int dx, int dy, int light, const sint8 *atten_table) { - int x, y, darklevel, basex, basey, mflags, light, x1, y1; + // min or max the circular area around basex, basey + player *pl = op->contr; + + dx += LOS_X0; + dy += LOS_Y0; + + int hx = op->contr->ns->mapx / 2; + int hy = op->contr->ns->mapy / 2; + + int ax0 = max (LOS_X0 - hx, dx - light); + int ay0 = max (LOS_Y0 - hy, dy - light); + int ax1 = min (dx + light, LOS_X0 + hx); + int ay1 = min (dy + light, LOS_Y0 + hy); + + for (int ax = ax0; ax <= ax1; ax++) + for (int ay = ay0; ay <= ay1; ay++) + pl->los[ax][ay] = + change_it (pl->los[ax][ay], atten_table [idistance (ax - dx, ay - dy)]); +} + +/* add light, by finding all (non-null) nearby light sources, then + * mark those squares specially. + */ +static void +apply_lights (object *op) +{ + int darklevel, mflags, light, x1, y1; maptile *m = op->map; sint16 nx, ny; @@ -350,14 +343,6 @@ if (QUERY_FLAG (op, FLAG_SEE_IN_DARK)) darklevel -= LOS_MAX / 2; - /* add light, by finding all (non-null) nearby light sources, then - * mark those squares specially. If the darklevel<1, there is no - * reason to do this, so we skip this function - */ - - if (darklevel < 1) - return; - /* Do a sanity check. If not valid, some code below may do odd * things. */ @@ -367,12 +352,6 @@ darklevel = MAX_DARKNESS; } - /* first, make everything totally dark */ - for (x = 0; x < op->contr->ns->mapx; x++) - for (y = 0; y < op->contr->ns->mapy; y++) - if (op->contr->blocked_los[x][y] != LOS_BLOCKED) - op->contr->blocked_los[x][y] = LOS_MAX; - int half_x = op->contr->ns->mapx / 2; int half_y = op->contr->ns->mapy / 2; @@ -383,47 +362,57 @@ int pass2 = 0; // negative lights have an extra pass - /* - * Only process the area of interest. - * the basex, basey values represent the position in the op->contr->blocked_los - * array. Its easier to just increment them here (and start with the right - * value) than to recalculate them down below. - */ - for (int x = min_x, basex = -MAX_LIGHT_RADIUS; x <= max_x; x++, basex++) - for (int y = min_y, basey = -MAX_LIGHT_RADIUS; y <= max_y; y++, basey++) + if (darklevel < 1) + pass2 = 1; + else + { + /* first, make everything totally dark */ + for (int dx = -half_x; dx <= half_x; dx++) + for (int dy = -half_x; dy <= half_y; dy++) + if (op->contr->los[dx + LOS_X0][dy + LOS_Y0] != LOS_BLOCKED) + op->contr->los[dx + LOS_X0][dy + LOS_Y0] = LOS_MAX; + + /* + * Only process the area of interest. + * the basex, basey values represent the position in the op->contr->los + * array. Its easier to just increment them here (and start with the right + * value) than to recalculate them down below. + */ + for (int x = min_x; x <= max_x; x++) + for (int y = min_y; y <= max_y; y++) + { + maptile *m = op->map; + sint16 nx = x; + sint16 ny = y; + + if (!xy_normalise (m, nx, ny)) + continue; + + mapspace &ms = m->at (nx, ny); + ms.update (); + sint8 light = ms.light; + + if (expect_false (light)) + if (light < 0) + pass2 = 1; + else + apply_light (op, x - op->x, y - op->y, light, light_atten [light + MAX_LIGHT_RADIUS]); + } + + /* grant some vision to the player, based on the darklevel */ { - maptile *m = op->map; - sint16 nx = x; - sint16 ny = y; - - if (!xy_normalise (m, nx, ny)) - continue; - - mapspace &ms = m->at (nx, ny); - ms.update (); - sint8 light = ms.light; - - if (expect_false (light)) - if (light < 0) - pass2 = 1; - else - { - /* This space is providing light, so we need to brighten up the - * spaces around here. - */ - const sint8 *darkness_table = darkness [light + MAX_LIGHT_RADIUS]; - - for (int ax = max (0, basex - light); ax <= min (basex + light, op->contr->ns->mapx - 1); ax++) - for (int ay = max (0, basey - light); ay <= min (basey + light, op->contr->ns->mapy - 1); ay++) - if (op->contr->blocked_los[ax][ay] != LOS_BLOCKED) - min_it (op->contr->blocked_los[ax][ay], darkness_table [idistance (ax - basex, ay - basey)]); - } + int light = clamp (MAX_DARKNESS - darklevel, 0, MAX_LIGHT_RADIUS); + + apply_light (op, 0, 0, light, light_atten [light + MAX_LIGHT_RADIUS]); } + } - // psosibly do 2nd pass for rare negative glow radii - if (expect_false (pass2)) - for (x = min_x, basex = -MAX_LIGHT_RADIUS; x <= max_x; x++, basex++) - for (y = min_y, basey = -MAX_LIGHT_RADIUS; y <= max_y; y++, basey++) + // possibly do 2nd pass for rare negative glow radii + // for effect, those are always considered to be stronger than anything else + // but they can't darken a place completely + if (pass2) + for (int x = min_x; x <= max_x; x++) + for (int y = min_y; y <= max_y; y++) { maptile *m = op->map; sint16 nx = x; @@ -437,36 +426,8 @@ sint8 light = ms.light; if (expect_false (light < 0)) - { - const sint8 *darkness_table = darkness [light + MAX_LIGHT_RADIUS]; - - for (int ax = max (0, basex + light); ax <= min (basex - light, op->contr->ns->mapx - 1); ax++) - for (int ay = max (0, basey + light); ay <= min (basey - light, op->contr->ns->mapy - 1); ay++) - if (op->contr->blocked_los[ax][ay] != LOS_BLOCKED) - max_it (op->contr->blocked_los[ax][ay], darkness_table [idistance (ax - basex, ay - basey)]); - } + apply_light (op, x - op->x, y - op->y, -light, light_atten [light + MAX_LIGHT_RADIUS]); } - - /* Outdoor should never really be completely pitch black dark like - * a dungeon, so let the player at least see a little around themselves - */ - if (op->map->outdoor && darklevel > MAX_DARKNESS - 3) - { - if (op->contr->blocked_los[op->contr->ns->mapx / 2][op->contr->ns->mapy / 2] > (LOS_MAX - 3)) - op->contr->blocked_los[op->contr->ns->mapx / 2][op->contr->ns->mapy / 2] = LOS_MAX - 3; - - for (x = -1; x <= 1; x++) - for (y = -1; y <= 1; y++) - if (op->contr->blocked_los[x + op->contr->ns->mapx / 2][y + op->contr->ns->mapy / 2] > (LOS_MAX - 2)) - op->contr->blocked_los[x + op->contr->ns->mapx / 2][y + op->contr->ns->mapy / 2] = LOS_MAX - 2; - } - - /* grant some vision to the player, based on the darklevel */ - for (x = darklevel - MAX_DARKNESS; x < MAX_DARKNESS + 1 - darklevel; x++) - for (y = darklevel - MAX_DARKNESS; y < MAX_DARKNESS + 1 - darklevel; y++) - if (!(op->contr->blocked_los[x + op->contr->ns->mapx / 2][y + op->contr->ns->mapy / 2] == LOS_BLOCKED)) - op->contr->blocked_los[x + op->contr->ns->mapx / 2][y + op->contr->ns->mapy / 2] -= - max (0, 6 - darklevel - max (abs (x), abs (y))); } /* blinded_sight() - sets all viewable squares to blocked except @@ -477,13 +438,7 @@ static void blinded_sight (object *op) { - int x, y; - - for (x = 0; x < op->contr->ns->mapx; x++) - for (y = 0; y < op->contr->ns->mapy; y++) - op->contr->blocked_los[x][y] = LOS_BLOCKED; - - op->contr->blocked_los[op->contr->ns->mapx / 2][op->contr->ns->mapy / 2] = 0; + op->contr->los[LOS_X0][LOS_Y0] = 3; } /* @@ -493,36 +448,25 @@ void update_los (object *op) { - int dx = op->contr->ns->mapx / 2, dy = op->contr->ns->mapy / 2, x, y; - if (QUERY_FLAG (op, FLAG_REMOVED)) return; - clear_los (op->contr); + op->contr->clear_los (); if (QUERY_FLAG (op, FLAG_WIZ) /* ||XRAYS(op) */ ) - return; - - /* For larger maps, this is more efficient than the old way which - * used the chaining of the block array. Since many space views could - * be blocked by different spaces in front, this mean that a lot of spaces - * could be examined multile times, as each path would be looked at. - */ - for (x = (MAP_CLIENT_X - op->contr->ns->mapx) / 2 - 1; x < (MAP_CLIENT_X + op->contr->ns->mapx) / 2 + 1; x++) - for (y = (MAP_CLIENT_Y - op->contr->ns->mapy) / 2 - 1; y < (MAP_CLIENT_Y + op->contr->ns->mapy) / 2 + 1; y++) - check_wall (op, x, y); - - /* do the los of the player. 3 (potential) cases */ - if (QUERY_FLAG (op, FLAG_BLIND)) /* player is blind */ + memset (op->contr->los, 0, sizeof (op->contr->los)); + else if (QUERY_FLAG (op, FLAG_BLIND)) /* player is blind */ blinded_sight (op); else - expand_sight (op); + { + do_los (op); + apply_lights (op); + } - //TODO: no range-checking whatsoever :( if (QUERY_FLAG (op, FLAG_XRAYS)) - for (int x = -2; x <= 2; x++) - for (int y = -2; y <= 2; y++) - op->contr->blocked_los[dx + x][dy + y] = 0; + for (int dx = -2; dx <= 2; dx++) + for (int dy = -2; dy <= 2; dy++) + op->contr->los[dx + LOS_X0][dy + LOS_X0] = 0; } /* update all_map_los is like update_all_los below, @@ -621,44 +565,9 @@ } /* - * Debug-routine which dumps the array which specifies the visible - * area of a player. Triggered by the z key in DM mode. - */ -void -print_los (object *op) -{ - int x, y; - char buf[50], buf2[10]; - - strcpy (buf, " "); - - for (x = 0; x < op->contr->ns->mapx; x++) - { - sprintf (buf2, "%2d", x); - strcat (buf, buf2); - } - - new_draw_info (NDI_UNIQUE, 0, op, buf); - - for (y = 0; y < op->contr->ns->mapy; y++) - { - sprintf (buf, "%2d:", y); - - for (x = 0; x < op->contr->ns->mapx; x++) - { - sprintf (buf2, " %1d", op->contr->blocked_los[x][y]); - strcat (buf, buf2); - } - - new_draw_info (NDI_UNIQUE, 0, op, buf); - } -} - -/* * make_sure_seen: The object is supposed to be visible through walls, thus * check if any players are nearby, and edit their LOS array. */ - void make_sure_seen (const object *op) { @@ -666,7 +575,7 @@ if (pl->ob->map == op->map && pl->ob->y - pl->ns->mapy / 2 <= op->y && pl->ob->y + pl->ns->mapy / 2 >= op->y && pl->ob->x - pl->ns->mapx / 2 <= op->x && pl->ob->x + pl->ns->mapx / 2 >= op->x) - pl->blocked_los[pl->ns->mapx / 2 + op->x - pl->ob->x][pl->ns->mapy / 2 + op->y - pl->ob->y] = 0; + pl->los[op->x - pl->ob->x + LOS_X0][op->y - pl->ob->y + LOS_X0] = 0; } /* @@ -674,7 +583,6 @@ * walls has just been removed from the map, so update the los of any * players within its range */ - void make_sure_not_seen (const object *op) {