--- deliantra/server/common/los.C 2006/09/10 16:00:23 1.4 +++ deliantra/server/common/los.C 2007/01/06 14:42:29 1.16 @@ -1,12 +1,7 @@ - -/* - * static char *rcsid_los_c = - * "$Id: los.C,v 1.4 2006/09/10 16:00:23 root Exp $"; - */ - /* CrossFire, A Multiplayer game for X-windows + Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team Copyright (C) 2002 Mark Wedel & Crossfire Development Team Copyright (C) 1992 Frank Tore Johansen @@ -24,7 +19,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - The authors can be reached via e-mail at crossfire-devel@real-time.com + The authors can be reached via e-mail at */ /* Nov 95 - inserted USE_LIGHTING code stuff in here - b.t. */ @@ -152,7 +147,7 @@ * the line is off */ - d1 = (float) (pow (MAP_CLIENT_X / 2 - dx, 2) + pow (MAP_CLIENT_Y / 2 - dy, 2)); + 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); @@ -196,10 +191,10 @@ /* ax, ay are the values as adjusted to be in the * socket look structure. */ - ax = dx - (MAP_CLIENT_X - op->contr->socket.mapx) / 2; - ay = dy - (MAP_CLIENT_Y - op->contr->socket.mapy) / 2; + ax = dx - (MAP_CLIENT_X - op->contr->ns->mapx) / 2; + ay = dy - (MAP_CLIENT_Y - op->contr->ns->mapy) / 2; - if (ax < 0 || ax >= op->contr->socket.mapx || ay < 0 || ay >= op->contr->socket.mapy) + 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); @@ -228,13 +223,13 @@ return; /* ax, ay are coordinates as indexed into the look window */ - ax = x - (MAP_CLIENT_X - op->contr->socket.mapx) / 2; - ay = y - (MAP_CLIENT_Y - op->contr->socket.mapy) / 2; + ax = x - (MAP_CLIENT_X - op->contr->ns->mapx) / 2; + ay = y - (MAP_CLIENT_Y - op->contr->ns->mapy) / 2; /* If the converted coordinates are outside the viewable * area for the client, return now. */ - if (ax < 0 || ay < 0 || ax >= op->contr->socket.mapx || ay >= op->contr->socket.mapy) + if (ax < 0 || ay < 0 || ax >= op->contr->ns->mapx || ay >= op->contr->ns->mapy) return; #if 0 @@ -262,7 +257,7 @@ void clear_los (object *op) { - /* This is safer than using the socket->mapx, mapy because + /* 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 @@ -282,13 +277,13 @@ { int i, x, y, dx, dy; - for (x = 1; x < op->contr->socket.mapx - 1; x++) /* loop over inner squares */ - for (y = 1; y < op->contr->socket.mapy - 1; y++) + 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->socket.mapx / 2 + x, - op->y - op->contr->socket.mapy / 2 + y, NULL, NULL) & (P_BLOCKSVIEW | P_OUT_OF_MAP))) + 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) @@ -301,13 +296,13 @@ } } - if (MAP_DARKNESS (op->map) > 0) /* player is on a dark map */ + if (op->map->darkness > 0) /* player is on a dark map */ expand_lighted_sight (op); /* clear mark squares */ - for (x = 0; x < op->contr->socket.mapx; x++) - for (y = 0; y < op->contr->socket.mapy; y++) + 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; } @@ -335,10 +330,10 @@ expand_lighted_sight (object *op) { int x, y, darklevel, ax, ay, basex, basey, mflags, light, x1, y1; - mapstruct *m = op->map; + maptile *m = op->map; sint16 nx, ny; - darklevel = MAP_DARKNESS (m); + darklevel = m->darkness; /* If the player can see in the dark, lower the darklevel for him */ if (QUERY_FLAG (op, FLAG_SEE_IN_DARK)) @@ -357,13 +352,13 @@ */ if (darklevel > MAX_DARKNESS) { - LOG (llevError, "Map darkness for %s on %s is too high (%d)\n", &op->name, op->map->path, darklevel); + LOG (llevError, "Map darkness for %s on %s is too high (%d)\n", &op->name, &op->map->path, darklevel); darklevel = MAX_DARKNESS; } /* First, limit player furthest (unlighted) vision */ - for (x = 0; x < op->contr->socket.mapx; x++) - for (y = 0; y < op->contr->socket.mapy; y++) + 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_LIGHT_RADII; @@ -373,12 +368,12 @@ * array. Its easier to just increment them here (and start with the right * value) than to recalculate them down below. */ - for (x = (op->x - op->contr->socket.mapx / 2 - MAX_LIGHT_RADII), basex = -MAX_LIGHT_RADII; - x <= (op->x + op->contr->socket.mapx / 2 + MAX_LIGHT_RADII); x++, basex++) + for (x = (op->x - op->contr->ns->mapx / 2 - MAX_LIGHT_RADII), basex = -MAX_LIGHT_RADII; + x <= (op->x + op->contr->ns->mapx / 2 + MAX_LIGHT_RADII); x++, basex++) { - for (y = (op->y - op->contr->socket.mapy / 2 - MAX_LIGHT_RADII), basey = -MAX_LIGHT_RADII; - y <= (op->y + op->contr->socket.mapy / 2 + MAX_LIGHT_RADII); y++, basey++) + for (y = (op->y - op->contr->ns->mapy / 2 - MAX_LIGHT_RADII), basey = -MAX_LIGHT_RADII; + y <= (op->y + op->contr->ns->mapy / 2 + MAX_LIGHT_RADII); y++, basey++) { m = op->map; nx = x; @@ -400,11 +395,11 @@ #endif for (ax = basex - light; ax <= basex + light; ax++) { - if (ax < 0 || ax >= op->contr->socket.mapx) + if (ax < 0 || ax >= op->contr->ns->mapx) continue; for (ay = basey - light; ay <= basey + light; ay++) { - if (ay < 0 || ay >= op->contr->socket.mapy) + if (ay < 0 || ay >= op->contr->ns->mapy) continue; /* If the space is fully blocked, do nothing. Otherwise, we @@ -434,21 +429,21 @@ */ if (op->map->outdoor && darklevel > (MAX_DARKNESS - 3)) { - if (op->contr->blocked_los[op->contr->socket.mapx / 2][op->contr->socket.mapy / 2] > (MAX_DARKNESS - 3)) - op->contr->blocked_los[op->contr->socket.mapx / 2][op->contr->socket.mapy / 2] = 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; for (x = -1; x <= 1; x++) for (y = -1; y <= 1; y++) { - if (op->contr->blocked_los[x + op->contr->socket.mapx / 2][y + op->contr->socket.mapy / 2] > (MAX_DARKNESS - 2)) - op->contr->blocked_los[x + op->contr->socket.mapx / 2][y + op->contr->socket.mapy / 2] = MAX_DARKNESS - 2; + 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; } } /* 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->socket.mapx / 2][y + op->contr->socket.mapy / 2] == 100)) - op->contr->blocked_los[x + op->contr->socket.mapx / 2][y + op->contr->socket.mapy / 2] -= + if (!(op->contr->blocked_los[x + op->contr->ns->mapx / 2][y + op->contr->ns->mapy / 2] == 100)) + 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))); } @@ -463,11 +458,11 @@ { int x, y; - for (x = 0; x < op->contr->socket.mapx; x++) - for (y = 0; y < op->contr->socket.mapy; 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] = 100; - op->contr->blocked_los[op->contr->socket.mapx / 2][op->contr->socket.mapy / 2] = 0; + op->contr->blocked_los[op->contr->ns->mapx / 2][op->contr->ns->mapy / 2] = 0; } /* @@ -478,7 +473,7 @@ void update_los (object *op) { - int dx = op->contr->socket.mapx / 2, dy = op->contr->socket.mapy / 2, x, y; + int dx = op->contr->ns->mapx / 2, dy = op->contr->ns->mapy / 2, x, y; if (QUERY_FLAG (op, FLAG_REMOVED)) return; @@ -492,8 +487,8 @@ * 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->socket.mapx) / 2 - 1; x < (MAP_CLIENT_X + op->contr->socket.mapx) / 2 + 1; x++) - for (y = (MAP_CLIENT_Y - op->contr->socket.mapy) / 2 - 1; y < (MAP_CLIENT_Y + op->contr->socket.mapy) / 2 + 1; y++) + 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); @@ -515,7 +510,7 @@ /* update all_map_los is like update_all_los below, * but updates everyone on the map, no matter where they - * are. This generally should not be used, as a per + * are. This generally should not be used, as a per * specific map change doesn't make much sense when tiling * is considered (lowering darkness would certainly be a * strange effect if done on a tile map, as it makes @@ -525,18 +520,13 @@ * change_map_light function */ void -update_all_map_los (mapstruct *map) +update_all_map_los (maptile *map) { - player *pl; - - for (pl = first_player; pl != NULL; pl = pl->next) - { - if (pl->ob->map == map) - pl->do_los = 1; - } + for_all_players (pl) + if (pl->ob && pl->ob->map == map) + pl->do_los = 1; } - /* * This function makes sure that update_los() will be called for all * players on the given map within the next frame. @@ -549,18 +539,15 @@ * * map is the map that changed, x and y are the coordinates. */ - void -update_all_los (const mapstruct *map, int x, int y) +update_all_los (const maptile *map, int x, int y) { - player *pl; - - for (pl = first_player; pl != NULL; pl = pl->next) + for_all_players (pl) { /* Player should not have a null map, but do this * check as a safety */ - if (!pl->ob->map) + if (!pl->ob || !pl->ob->map || !pl->ns) continue; /* Same map is simple case - see if pl is close enough. @@ -574,17 +561,17 @@ */ if (pl->ob->map == map) { - if ((abs (pl->ob->x - x) <= pl->socket.mapx / 2) && (abs (pl->ob->y - y) <= pl->socket.mapy / 2)) + if ((abs (pl->ob->x - x) <= pl->ns->mapx / 2) && (abs (pl->ob->y - y) <= pl->ns->mapy / 2)) pl->do_los = 1; } + /* Now we check to see if player is on adjacent * maps to the one that changed and also within * view. The tile_maps[] could be null, but in that * case it should never match the pl->ob->map, so * we want ever try to dereference any of the data in it. - */ - - /* The logic for 0 and 3 is to see how far the player is + * + * The logic for 0 and 3 is to see how far the player is * from the edge of the map (height/width) - pl->ob->(x,y) * and to add current position on this map - that gives a * distance. @@ -595,22 +582,22 @@ */ else if (pl->ob->map == map->tile_map[0]) { - if ((abs (pl->ob->x - x) <= pl->socket.mapx / 2) && (abs (y + MAP_HEIGHT (map->tile_map[0]) - pl->ob->y) <= pl->socket.mapy / 2)) + if ((abs (pl->ob->x - x) <= pl->ns->mapx / 2) && (abs (y + map->tile_map[0]->height - pl->ob->y) <= pl->ns->mapy / 2)) pl->do_los = 1; } else if (pl->ob->map == map->tile_map[2]) { - if ((abs (pl->ob->x - x) <= pl->socket.mapx / 2) && (abs (pl->ob->y + MAP_HEIGHT (map) - y) <= pl->socket.mapy / 2)) + if ((abs (pl->ob->x - x) <= pl->ns->mapx / 2) && (abs (pl->ob->y + map->height - y) <= pl->ns->mapy / 2)) pl->do_los = 1; } else if (pl->ob->map == map->tile_map[1]) { - if ((abs (pl->ob->x + MAP_WIDTH (map) - x) <= pl->socket.mapx / 2) && (abs (pl->ob->y - y) <= pl->socket.mapy / 2)) + if ((abs (pl->ob->x + map->width - x) <= pl->ns->mapx / 2) && (abs (pl->ob->y - y) <= pl->ns->mapy / 2)) pl->do_los = 1; } else if (pl->ob->map == map->tile_map[3]) { - if ((abs (x + MAP_WIDTH (map->tile_map[3]) - pl->ob->x) <= pl->socket.mapx / 2) && (abs (pl->ob->y - y) <= pl->socket.mapy / 2)) + if ((abs (x + map->tile_map[3]->width - pl->ob->x) <= pl->ns->mapx / 2) && (abs (pl->ob->y - y) <= pl->ns->mapy / 2)) pl->do_los = 1; } } @@ -620,7 +607,6 @@ * 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) { @@ -628,20 +614,25 @@ char buf[50], buf2[10]; strcpy (buf, " "); - for (x = 0; x < op->contr->socket.mapx; x++) + + 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->socket.mapy; y++) + + for (y = 0; y < op->contr->ns->mapy; y++) { sprintf (buf, "%2d:", y); - for (x = 0; x < op->contr->socket.mapx; x++) + + 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); } } @@ -654,13 +645,11 @@ void make_sure_seen (const object *op) { - player *pl; - - for (pl = first_player; pl; pl = pl->next) + for_all_players (pl) if (pl->ob->map == op->map && - pl->ob->y - pl->socket.mapy / 2 <= op->y && - pl->ob->y + pl->socket.mapy / 2 >= op->y && pl->ob->x - pl->socket.mapx / 2 <= op->x && pl->ob->x + pl->socket.mapx / 2 >= op->x) - pl->blocked_los[pl->socket.mapx / 2 + op->x - pl->ob->x][pl->socket.mapy / 2 + op->y - pl->ob->y] = 0; + 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; } /* @@ -672,11 +661,9 @@ void make_sure_not_seen (const object *op) { - player *pl; - - for (pl = first_player; pl; pl = pl->next) + for_all_players (pl) if (pl->ob->map == op->map && - pl->ob->y - pl->socket.mapy / 2 <= op->y && - pl->ob->y + pl->socket.mapy / 2 >= op->y && pl->ob->x - pl->socket.mapx / 2 <= op->x && pl->ob->x + pl->socket.mapx / 2 >= op->x) + 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->do_los = 1; }