--- deliantra/server/common/los.C 2007/07/01 05:00:17 1.28
+++ deliantra/server/common/los.C 2008/12/04 01:07:35 1.31
@@ -1,11 +1,11 @@
/*
- * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
+ * This file is part of Deliantra, the Roguelike Realtime MMORPG.
*
- * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
+ * 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
*
- * Crossfire TRT 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 3 of the License, or
* (at your option) any later version.
@@ -18,13 +18,12 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
- * The authors can be reached via e-mail to
+ * 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.
@@ -35,6 +34,7 @@
*/
#define SPACE_BLOCK 0.5
+#define MAX_UNLIGHTED_VISION 4
typedef struct blstr
{
@@ -350,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.
@@ -358,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;
@@ -378,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);
@@ -388,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)
@@ -396,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);
}
}
}
@@ -417,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;
@@ -438,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.