--- deliantra/server/common/los.C 2007/02/16 21:38:18 1.22 +++ deliantra/server/common/los.C 2008/12/04 01:07:35 1.31 @@ -1,31 +1,29 @@ /* - * CrossFire, A Multiplayer game for X-windows + * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team - * Copyright (C) 2002 Mark Wedel & Crossfire Development Team - * Copyright (C) 1992 Frank Tore Johansen + * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team + * Copyright (©) 1992,2007 Frank Tore Johansen * - * This program is free software; you can redistribute it and/or modify + * Deliantra 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 + * the Free Software Foundation, either version 3 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 + * 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 + * along with this program. If not, see . + * + * The authors can be reached via e-mail to */ /* Nov 95 - inserted USE_LIGHTING code stuff in here - b.t. */ #include -#include #include /* Distance must be less than this for the object to be blocked. @@ -36,6 +34,7 @@ */ #define SPACE_BLOCK 0.5 +#define MAX_UNLIGHTED_VISION 4 typedef struct blstr { @@ -43,7 +42,11 @@ int index; } blocks; -blocks block[(MAP_CLIENT_X | 1) + 1][(MAP_CLIENT_Y | 1) + 1]; // still a speed hack +// 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]; static void expand_lighted_sight (object *op); @@ -92,15 +95,12 @@ init_block (void) { int x, y, dx, dy, i; - static int block_x[3] = { -1, -1, 0 }, block_y[3] = - { - -1, 0, -1}; + 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++) - { - block[x][y].index = 0; - } + block[x][y].index = 0; /* The table should be symmetric, so only do the upper left @@ -127,13 +127,9 @@ */ 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); - } + 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); - } + set_block (MAP_CLIENT_X - x - 1, y, MAP_CLIENT_X - dx - 1, dy); } else { @@ -177,7 +173,6 @@ * spaces behind it may block other spaces, etc. * In this way, the chain of visibility is set. */ - static void set_wall (object *op, int x, int y) { @@ -254,14 +249,14 @@ */ void -clear_los (object *op) +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 */ - (void) memset ((void *) op->contr->blocked_los, 0, MAP_CLIENT_X * MAP_CLIENT_Y); + memset (pl->blocked_los, 0, MAP_CLIENT_X * MAP_CLIENT_Y); } /* @@ -355,7 +350,7 @@ 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; + op->contr->blocked_los[x][y] = MAX_UNLIGHTED_VISION; /* the spaces[] darkness value contains the information we need. * Only process the area of interest. @@ -363,12 +358,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->ns->mapx / 2 - MAX_LIGHT_RADII), basex = -MAX_LIGHT_RADII; - x <= (op->x + op->contr->ns->mapx / 2 + MAX_LIGHT_RADII); x++, basex++) + for (x = (op->x - op->contr->ns->mapx / 2 - MAX_LIGHT_RADIUS), basex = -MAX_LIGHT_RADIUS; + x <= (op->x + op->contr->ns->mapx / 2 + MAX_LIGHT_RADIUS); x++, basex++) { - 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++) + for (y = (op->y - op->contr->ns->mapy / 2 - MAX_LIGHT_RADIUS), basey = -MAX_LIGHT_RADIUS; + y <= (op->y + op->contr->ns->mapy / 2 + MAX_LIGHT_RADIUS); y++, basey++) { m = op->map; nx = x; @@ -383,7 +378,7 @@ * spaces around here. */ light = GET_MAP_LIGHT (m, nx, ny); - if (light != 0) + if (light) { #if 0 LOG (llevDebug, "expand_lighted_sight: Found light at x=%d, y=%d, basex=%d, basey=%d\n", x, y, basex, basey); @@ -393,6 +388,8 @@ if (ax < 0 || ax >= op->contr->ns->mapx) continue; + x1 = (basex - ax) * (basex - ax); + for (ay = basey - light; ay <= basey + light; ay++) { if (ay < 0 || ay >= op->contr->ns->mapy) @@ -401,17 +398,16 @@ /* If the space is fully blocked, do nothing. Otherwise, we * brighten the space. The further the light is away from the * source (basex-x), the less effect it has. Though light used - * to dim in a square manner, it now dims in a circular manner - * using the the pythagorean theorem. glow_radius still - * represents the radius + * to dim in a square manner, it now dims in a roughly circular + * manner. glow_radius still represents the radius. */ if (op->contr->blocked_los[ax][ay] != 100) { - x1 = abs (basex - ax) * abs (basex - ax); - y1 = abs (basey - ay) * abs (basey - ay); + y1 = (basey - ay) * (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); + op->contr->blocked_los[ax][ay] -= light > 0 + ? max (light - isqrt (x1 + y1), 0) + : min (light + isqrt (x1 + y1), 0); } } } @@ -422,7 +418,7 @@ /* 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->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; @@ -443,7 +439,7 @@ MAX (0, 6 - darklevel - MAX (abs (x), abs (y))); } -/* blinded_sight() - sets all veiwable squares to blocked except +/* blinded_sight() - sets all viewable squares to blocked except * for the one the central one that the player occupies. A little * odd that you can see yourself (and what your standing on), but * really need for any reasonable game play. @@ -464,7 +460,6 @@ * update_los() recalculates the array which specifies what is * visible for the given player-object. */ - void update_los (object *op) { @@ -473,7 +468,8 @@ if (QUERY_FLAG (op, FLAG_REMOVED)) return; - clear_los (op); + clear_los (op->contr); + if (QUERY_FLAG (op, FLAG_WIZ) /* ||XRAYS(op) */ ) return;