--- deliantra/server/common/los.C 2008/12/04 22:32:41 1.35 +++ deliantra/server/common/los.C 2008/12/18 05:13:38 1.38 @@ -32,9 +32,7 @@ * block view in our tables. * .4 or less lets you see through walls. .5 is about right. */ - #define SPACE_BLOCK 0.5 -#define MAX_DARKNESS_LOS 4 /* 4 == totally dark */ typedef struct blstr { @@ -90,30 +88,27 @@ * are the only ones further out that are still possibly in the * sightline. */ - void init_block (void) { - int x, y, dx, dy, i; static int block_x[3] = { -1, -1, 0 }, block_y[3] = { -1, 0, -1 }; - for (x = 0; x < MAP_CLIENT_X; x++) - for (y = 0; y < MAP_CLIENT_Y; y++) + for (int x = 0; x < MAP_CLIENT_X; x++) + for (int y = 0; y < MAP_CLIENT_Y; y++) block[x][y].index = 0; - /* 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 (int x = 1; x <= MAP_CLIENT_X / 2; x++) { - for (y = 1; y <= MAP_CLIENT_Y / 2; y++) + for (int y = 1; y <= MAP_CLIENT_Y / 2; y++) { - for (i = 0; i < 3; i++) + for (int i = 0; i < 3; i++) { - dx = x + block_x[i]; - dy = y + block_y[i]; + int dx = x + block_x[i]; + int dy = y + block_y[i]; /* center space never blocks */ if (x == MAP_CLIENT_X / 2 && y == MAP_CLIENT_Y / 2) @@ -135,17 +130,17 @@ { float d1, r, s, l; - /* We use the algorihm that found out how close the point + /* We use the algorithm 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. + * 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); + d1 = (powf (MAP_CLIENT_X / 2 - dx, 2.f) + powf (MAP_CLIENT_Y / 2 - dy, 2.f)); + r = ((dy - y) * (dy - MAP_CLIENT_Y / 2) - (dx - x) * (MAP_CLIENT_X / 2 - dx)) / d1; + s = ((dy - y) * (MAP_CLIENT_X / 2 - dx) - (dx - x) * (MAP_CLIENT_Y / 2 - dy)) / d1; + l = fabs (sqrtf (d1) * s); if (l <= SPACE_BLOCK) { @@ -176,9 +171,7 @@ static void set_wall (object *op, int x, int y) { - int i; - - for (i = 0; i < block[x][y].index; i++) + for (int i = 0; i < block[x][y].index; i++) { int dx = block[x][y].x[i], dy = block[x][y].y[i], ax, ay; @@ -197,7 +190,7 @@ * 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] = 100; + op->contr->blocked_los[ax][ay] = LOS_BLOCKED; set_wall (op, dx, dy); } } @@ -207,7 +200,6 @@ * op is the object, x and y values based on MAP_CLIENT_X and Y. * this is because they index the blocked[][] arrays. */ - static void check_wall (object *op, int x, int y) { @@ -235,10 +227,9 @@ * 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] == 100) + if (op->contr->blocked_los[ax][ay] == LOS_BLOCKED) return; - 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); } @@ -265,37 +256,32 @@ * to a certain degree, be able to see into corners. * This is somewhat suboptimal, would be better to improve the formula. */ - static void expand_sight (object *op) { - int i, x, y, dx, dy; + for (int x = 1; x < op->contr->ns->mapx - 1; x++) /* loop over inner squares */ + for (int 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))) + { + for (int i = 1; i <= 8; i += 1) + { /* mark all directions */ + int dx = x + freearr_x[i]; + int dy = y + freearr_y[i]; - 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))) - { - - 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; - } - } - } + if (op->contr->blocked_los[dx][dy] > 0) /* for any square blocked */ + op->contr->blocked_los[dx][dy] = -1; + } + } 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++) + for (int x = 0; x < op->contr->ns->mapx; x++) + for (int y = 0; y < op->contr->ns->mapy; y++) if (op->contr->blocked_los[x][y] < 0) op->contr->blocked_los[x][y] = 0; } @@ -305,7 +291,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) { @@ -327,14 +312,14 @@ for (int distance = 0; distance <= MAX_LIGHT_RADIUS * 3 / 2; ++distance) { // max intensity - int intensity = min (MAX_DARKNESS_LOS, abs (radius) + 1); + int intensity = min (LOS_MAX, abs (radius) + 1); // actual intensity intensity = max (0, lerp_rd (distance, 0, abs (radius) + 1, intensity, 0)); darkness [radius + MAX_LIGHT_RADIUS][distance] = radius < 0 ? min (3, intensity) - : MAX_DARKNESS_LOS - intensity; + : LOS_MAX - intensity; } } } darkness_init; @@ -350,7 +335,7 @@ /* If the player can see in the dark, lower the darklevel for him */ if (QUERY_FLAG (op, FLAG_SEE_IN_DARK)) - darklevel -= MAX_DARKNESS_LOS / 2; + 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 @@ -372,8 +357,8 @@ /* 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] != 100) - op->contr->blocked_los[x][y] = MAX_DARKNESS_LOS; + 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; @@ -417,12 +402,12 @@ 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] != 100) + if (op->contr->blocked_los[ax][ay] != LOS_BLOCKED) min_it (op->contr->blocked_los[ax][ay], darkness_table [idistance (ax - basex, ay - basey)]); } } - // psosibly do 2nd pass for rare negative glow radii + // possibly 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++) @@ -444,7 +429,7 @@ 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] != 100) + if (op->contr->blocked_los[ax][ay] != LOS_BLOCKED) max_it (op->contr->blocked_los[ax][ay], darkness_table [idistance (ax - basex, ay - basey)]); } } @@ -454,21 +439,19 @@ */ if (op->map->outdoor && darklevel > MAX_DARKNESS - 3) { - if (op->contr->blocked_los[op->contr->ns->mapx / 2][op->contr->ns->mapy / 2] > (MAX_DARKNESS - 3)) - op->contr->blocked_los[op->contr->ns->mapx / 2][op->contr->ns->mapy / 2] = 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] > (MAX_DARKNESS - 2)) - op->contr->blocked_los[x + op->contr->ns->mapx / 2][y + op->contr->ns->mapy / 2] = MAX_DARKNESS - 2; - } + 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] == 100)) + 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))); } @@ -485,7 +468,7 @@ for (x = 0; x < op->contr->ns->mapx; x++) for (y = 0; y < op->contr->ns->mapy; y++) - op->contr->blocked_los[x][y] = 100; + op->contr->blocked_los[x][y] = LOS_BLOCKED; op->contr->blocked_los[op->contr->ns->mapx / 2][op->contr->ns->mapy / 2] = 0; }