--- deliantra/server/common/map.C 2008/12/23 01:51:27 1.152
+++ deliantra/server/common/map.C 2009/10/12 14:00:57 1.160
@@ -5,18 +5,19 @@
* Copyright (©) 2001-2003,2007 Mark Wedel & Crossfire Development Team
* Copyright (©) 1992,2007 Frank Tore Johansen
*
- * 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.
+ * Deliantra is free software: you can redistribute it and/or modify it under
+ * the terms of the Affero GNU General Public License as published by 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
* 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, see .
+ * You should have received a copy of the Affero GNU General Public License
+ * and the GNU General Public License along with this program. If not, see
+ * .
*
* The authors can be reached via e-mail to
*/
@@ -336,7 +337,7 @@
// we insert manually because
// a) its way faster
// b) we remove manually, too, and there are good reasons for that
- // c) its correct
+ // c) it's correct
mapspace &ms = at (op->x, op->y);
op->flag [FLAG_REMOVED] = false;
@@ -344,10 +345,7 @@
op->above = 0;
op->below = ms.top;
- if (ms.top)
- ms.top->above = op;
- else
- ms.bot = op;
+ *(ms.top ? &ms.top->above : &ms.bot) = op;
ms.top = op;
ms.flags_ = 0;
@@ -939,38 +937,14 @@
}
/*
- * Updates every button on the map (by calling update_button() for them).
- */
-void
-maptile::update_buttons ()
-{
- for (oblinkpt *obp = buttons; obp; obp = obp->next)
- for (objectlink *ol = obp->link; ol; ol = ol->next)
- {
- if (!ol->ob)
- {
- LOG (llevError, "Internal error in update_button (%s (%dx%d), connected %ld).\n",
- ol->ob ? (const char *) ol->ob->name : "null", ol->ob ? ol->ob->x : -1, ol->ob ? ol->ob->y : -1, obp->value);
- continue;
- }
-
- if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL)
- {
- update_button (ol->ob);
- break;
- }
- }
-}
-
-/*
* This routine is supposed to find out the difficulty of the map.
* difficulty does not have a lot to do with character level,
* but does have a lot to do with treasure on the map.
*
- * Difficulty can now be set by the map creature. If the value stored
- * in the map is zero, then use this routine. Maps should really
- * have a difficulty set than using this function - human calculation
- * is much better than this functions guesswork.
+ * Difficulty can now be set by the map creator. If the value stored
+ * in the map is zero, then use this routine. Maps should really
+ * have a difficulty set rather than using this function - human calculation
+ * is much better than this function's guesswork.
*/
int
maptile::estimate_difficulty () const
@@ -1025,10 +999,8 @@
int
maptile::change_map_light (int change)
{
- int new_level = darkness + change;
-
/* Nothing to do */
- if (!change || (new_level <= 0 && darkness == 0) || (new_level >= MAX_DARKNESS && darkness >= MAX_DARKNESS))
+ if (!change)
return 0;
/* inform all players on the map */
@@ -1037,17 +1009,7 @@
else
new_info_map (NDI_BLACK | NDI_UNIQUE, this, "It becomes brighter.");
- /* Do extra checking. since darkness is a unsigned value,
- * we need to be extra careful about negative values.
- * In general, the checks below are only needed if change
- * is not +/-1
- */
- if (new_level < 0)
- darkness = 0;
- else if (new_level >= MAX_DARKNESS)
- darkness = MAX_DARKNESS;
- else
- darkness = new_level;
+ darkness = clamp (darkness + change, -MAX_DARKNESS, MAX_DARKNESS);
/* All clients need to get re-updated for the change */
update_all_map_los (this);
@@ -1230,17 +1192,17 @@
return vol;
}
-bool
+maptile *
maptile::tile_available (int dir, bool load)
{
- if (!tile_path[dir])
- return 0;
-
- if (tile_map[dir] && (!load || tile_map[dir]->in_memory == MAP_ACTIVE))
- return 1;
+ if (tile_path[dir])
+ {
+ if (tile_map[dir] && (!load || tile_map[dir]->in_memory == MAP_ACTIVE))
+ return tile_map[dir];
- if ((tile_map[dir] = find_async (tile_path[dir], this, load)))
- return 1;
+ if ((tile_map[dir] = find_async (tile_path[dir], this, load)))
+ return tile_map[dir];
+ }
return 0;
}
@@ -1556,8 +1518,8 @@
retval->distance_x += op2->x - x;
retval->distance_y += op2->y - y;
- retval->part = NULL;
- retval->distance = idistance (retval->distance_x, retval->distance_y);
+ retval->part = 0;
+ retval->distance = upos_max (abs (retval->distance_x), abs (retval->distance_y));
retval->direction = find_dir_2 (-retval->distance_x, -retval->distance_y);
}
}
@@ -1642,3 +1604,97 @@
}
}
+void
+maptile::say_msg (const char *msg, int x, int y) const
+{
+ for_all_players (pl)
+ if (client *ns = pl->ns)
+ {
+ int dx = x - pl->ob->x;
+ int dy = y - pl->ob->y;
+
+ int distance = idistance (dx, dy);
+
+ if (distance <= MAX_SOUND_DISTANCE)
+ ns->send_msg (NDI_GREY | NDI_DEF, SAY_CHANNEL, msg);
+ }
+}
+
+static void
+split_to_tiles (dynbuf &buf, maptile *m, int x0, int y0, int x1, int y1, int dx, int dy)
+{
+ // clip to map to the left
+ if (x0 < 0)
+ {
+ if (maptile *tile = m->tile_available (TILE_LEFT, 1))
+ split_to_tiles (buf, tile, x0 + tile->width, y0, min (x1 + tile->width, tile->width), y1, dx - tile->width, dy);
+
+ if (x1 < 0) // entirely to the left
+ return;
+
+ x0 = 0;
+ }
+
+ // clip to map to the right
+ if (x1 > m->width)
+ {
+ if (maptile *tile = m->tile_available (TILE_RIGHT, 1))
+ split_to_tiles (buf, tile, max (x0 - m->width, 0), y0, x1 - m->width, y1, dx + m->width, dy);
+
+ if (x0 > m->width) // entirely to the right
+ return;
+
+ x1 = m->width;
+ }
+
+ // clip to map above
+ if (y0 < 0)
+ {
+ if (maptile *tile = m->tile_available (TILE_UP, 1))
+ split_to_tiles (buf, tile, x0, y0 + tile->height, x1, min (y1 + tile->height, tile->height), dx, dy - tile->height);
+
+ if (y1 < 0) // entirely above
+ return;
+
+ y0 = 0;
+ }
+
+ // clip to map below
+ if (y1 > m->height)
+ {
+ if (maptile *tile = m->tile_available (TILE_DOWN, 1))
+ split_to_tiles (buf, tile, x0, max (y0 - m->height, 0), x1, y1 - m->height, dx, dy + m->height);
+
+ if (y0 > m->height) // entirely below
+ return;
+
+ y1 = m->height;
+ }
+
+ // if we get here, the rect is within the current map
+ maprect *r = (maprect *)buf.alloc (sizeof (maprect));
+
+ r->m = m;
+ r->x0 = x0;
+ r->y0 = y0;
+ r->x1 = x1;
+ r->y1 = y1;
+ r->dx = dx;
+ r->dy = dy;
+}
+
+maprect *
+maptile::split_to_tiles (int x0, int y0, int x1, int y1)
+{
+ static dynbuf buf (sizeof (maprect) * 8, sizeof (maprect) * 8);
+ buf.clear ();
+
+ ::split_to_tiles (buf, this, x0, y0, x1, y1, 0, 0);
+
+ // add end marker
+ maprect *r = (maprect *)buf.alloc (sizeof (maprect));
+ r->m = 0;
+
+ return (maprect *)buf.linearise ();
+}
+