--- deliantra/server/common/los.C 2006/12/23 13:56:25 1.11 +++ deliantra/server/common/los.C 2007/02/15 03:19:02 1.21 @@ -1,25 +1,26 @@ /* - CrossFire, A Multiplayer game for X-windows - - Copyright (C) 2002 Mark Wedel & Crossfire Development Team - Copyright (C) 1992 Frank Tore Johansen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - 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, 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 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * 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 + */ /* Nov 95 - inserted USE_LIGHTING code stuff in here - b.t. */ @@ -27,7 +28,6 @@ #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 @@ -295,10 +295,9 @@ } } - 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->ns->mapx; x++) for (y = 0; y < op->contr->ns->mapy; y++) @@ -306,9 +305,6 @@ op->contr->blocked_los[x][y] = 0; } - - - /* returns true if op carries one or more lights * This is a trivial function now days, but it used to * be a bit longer. Probably better for callers to just @@ -332,7 +328,7 @@ 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)) @@ -351,7 +347,7 @@ */ 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; } @@ -396,6 +392,7 @@ { if (ax < 0 || ax >= op->contr->ns->mapx) continue; + for (ay = basey - light; ay <= basey + light; ay++) { if (ay < 0 || ay >= op->contr->ns->mapy) @@ -412,16 +409,15 @@ { x1 = abs (basex - ax) * abs (basex - ax); y1 = abs (basey - ay) * abs (basey - ay); - if (light > 0) - op->contr->blocked_los[ax][ay] -= MAX ((light - isqrt (x1 + y1)), 0); - if (light < 0) - op->contr->blocked_los[ax][ay] -= MIN ((light + isqrt (x1 + y1)), 0); + + if (light > 0) op->contr->blocked_los[ax][ay] -= max (light - isqrt (x1 + y1), 0); + if (light < 0) op->contr->blocked_los[ax][ay] -= min (light + isqrt (x1 + y1), 0); } - } /* for ay */ - } /* for ax */ - } /* if this space is providing light */ - } /* for y */ - } /* for x */ + } + } + } + } + } /* Outdoor should never really be completely pitch black dark like * a dungeon, so let the player at least see a little around themselves @@ -438,6 +434,7 @@ 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++) @@ -451,7 +448,6 @@ * odd that you can see yourself (and what your standing on), but * really need for any reasonable game play. */ - static void blinded_sight (object *op) { @@ -490,26 +486,22 @@ 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 */ blinded_sight (op); else expand_sight (op); + //TODO: no range-checking whatsoever :( if (QUERY_FLAG (op, FLAG_XRAYS)) - { - int x, y; - - for (x = -2; x <= 2; x++) - for (y = -2; y <= 2; y++) - op->contr->blocked_los[dx + x][dy + y] = 0; - } + for (int x = -2; x <= 2; x++) + for (int y = -2; y <= 2; y++) + op->contr->blocked_los[dx + x][dy + y] = 0; } /* 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 @@ -522,11 +514,10 @@ update_all_map_los (maptile *map) { for_all_players (pl) - if (pl->ob->map == map) + 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. @@ -539,7 +530,6 @@ * * map is the map that changed, x and y are the coordinates. */ - void update_all_los (const maptile *map, int x, int y) { @@ -548,7 +538,7 @@ /* 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. @@ -565,14 +555,14 @@ 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. @@ -583,22 +573,22 @@ */ else if (pl->ob->map == map->tile_map[0]) { - if ((abs (pl->ob->x - x) <= pl->ns->mapx / 2) && (abs (y + MAP_HEIGHT (map->tile_map[0]) - pl->ob->y) <= pl->ns->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->ns->mapx / 2) && (abs (pl->ob->y + MAP_HEIGHT (map) - y) <= pl->ns->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->ns->mapx / 2) && (abs (pl->ob->y - y) <= pl->ns->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->ns->mapx / 2) && (abs (pl->ob->y - y) <= pl->ns->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; } }