--- deliantra/server/common/los.C 2007/01/07 02:39:13 1.17 +++ deliantra/server/common/los.C 2007/05/17 21:32:08 1.25 @@ -1,26 +1,26 @@ /* - 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 -*/ + * CrossFire, A Multiplayer game + * + * 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. */ @@ -43,7 +43,11 @@ int index; } blocks; -blocks block[MAP_CLIENT_X][MAP_CLIENT_Y]; +// 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 +96,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 +128,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 +174,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) { @@ -298,7 +294,6 @@ 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 +301,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 @@ -396,6 +388,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 +405,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 +430,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 +444,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,21 +482,17 @@ 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,