--- deliantra/server/common/map.C 2007/09/06 06:53:05 1.125
+++ deliantra/server/common/map.C 2008/04/15 14:21:04 1.134
@@ -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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
* Copyright (©) 2001-2003,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,7 +18,7 @@
* 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
*/
#include
@@ -168,11 +168,11 @@
}
/*
- * Returns true if the given object can't fit in the given spot.
- * This is meant for multi space objects - for single space objecs,
+ * Returns qthe blocking object if the given object can't fit in the given
+ * spot. This is meant for multi space objects - for single space objecs,
* just calling get_map_blocked and checking that against movement type
- * of object. This function goes through all the parts of the
- * multipart object and makes sure they can be inserted.
+ * of object. This function goes through all the parts of the multipart
+ * object and makes sure they can be inserted.
*
* While this doesn't call out of map, the get_map_flags does.
*
@@ -193,48 +193,33 @@
* code, we need to have actual object to check its move_type
* against the move_block values.
*/
-int
-ob_blocked (const object *ob, maptile *m, sint16 x, sint16 y)
+bool
+object::blocked (maptile *m, int x, int y) const
{
- archetype *tmp;
- int flag;
- maptile *m1;
- sint16 sx, sy;
-
- if (!ob)
+ for (archetype *tmp = arch; tmp; tmp = (archetype *)tmp->more)
{
- flag = get_map_flags (m, &m1, x, y, &sx, &sy);
- if (flag & P_OUT_OF_MAP)
- return P_OUT_OF_MAP;
+ mapxy pos (m, x + tmp->x, y + tmp->y);
- /* don't have object, so don't know what types would block */
- return m1->at (sx, sy).move_block;
- }
-
- for (tmp = ob->arch; tmp; tmp = (archetype *)tmp->more)
- {
- flag = get_map_flags (m, &m1, x + tmp->x, y + tmp->y, &sx, &sy);
+ if (!pos.normalise ())
+ return 1;
- if (flag & P_OUT_OF_MAP)
- return P_OUT_OF_MAP;
- if (flag & P_IS_ALIVE)
- return P_IS_ALIVE;
+ mapspace &ms = *pos;
- mapspace &ms = m1->at (sx, sy);
+ if (ms.flags () & P_IS_ALIVE)
+ return 1;
- /* find_first_free_spot() calls this function. However, often
- * ob doesn't have any move type (when used to place exits)
+ /* However, often ob doesn't have any move type
+ * (signifying non-moving objects)
* so the AND operation in OB_TYPE_MOVE_BLOCK doesn't work.
*/
-
- if (ob->move_type == 0 && ms.move_block != MOVE_ALL)
+ if (!move_type && ms.move_block != MOVE_ALL)
continue;
/* Note it is intentional that we check ob - the movement type of the
* head of the object should correspond for the entire object.
*/
- if (OB_TYPE_MOVE_BLOCK (ob, ms.move_block))
- return P_NO_PASS;
+ if (ms.blocks (move_type))
+ return 1;
}
return 0;
@@ -324,7 +309,7 @@
{
for (;;)
{
- coroapi::cede_to_tick_every (100); // cede once in a while
+ coroapi::cede_to_tick (); // cede once in a while
switch (f.kw)
{
@@ -334,7 +319,32 @@
if (op->inv)
sum_weight (op);
- insert_ob_in_map (op, this, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD);
+ if (IN_RANGE_EXC (op->x, 0, width) && IN_RANGE_EXC (op->y, 0, height))
+ {
+ // we insert manually because
+ // a) its way faster
+ // b) we remove manually, too, and there are good reasons for that
+ // c) its correct
+ mapspace &ms = at (op->x, op->y);
+
+ op->flag [FLAG_REMOVED] = false;
+
+ op->above = 0;
+ op->below = ms.top;
+
+ if (ms.top)
+ ms.top->above = op;
+ else
+ ms.bot = op;
+
+ ms.top = op;
+ ms.flags_ = 0;
+ }
+ else
+ {
+ f.parse_warn (format ("object %s out of range", op->debug_desc ()));
+ op->destroy ();
+ }
}
continue;
@@ -780,17 +790,28 @@
void
maptile::clear ()
{
- sfree (regions, size ()); regions = 0;
- delete [] regionmap; regionmap = 0;
-
if (spaces)
{
for (mapspace *ms = spaces + size (); ms-- > spaces; )
while (object *op = ms->bot)
{
- op = op->head_ ();
- op->destroy_inv (false);
- op->destroy ();
+ // manually remove, as to not trigger anything
+ if (ms->bot = op->above)
+ ms->bot->below = 0;
+
+ op->flag [FLAG_REMOVED] = true;
+
+ object *head = op->head_ ();
+ if (op == head)
+ {
+ op->destroy_inv (false);
+ op->destroy ();
+ }
+ else if (head->map != op->map)
+ {
+ LOG (llevDebug, "bad luck for object crossing map borders: %s", head->debug_desc ());
+ head->destroy ();
+ }
}
sfree (spaces, size ()), spaces = 0;
@@ -798,6 +819,9 @@
if (buttons)
free_objectlinkpt (buttons), buttons = 0;
+
+ sfree (regions, size ()); regions = 0;
+ delete [] regionmap; regionmap = 0;
}
void
@@ -1199,7 +1223,7 @@
if (!tile_path[dir])
return 0;
- if (tile_map[dir] && (!load || tile_map[dir]->in_memory == MAP_IN_MEMORY))
+ if (tile_map[dir] && (!load || tile_map[dir]->in_memory == MAP_ACTIVE))
return 1;
if ((tile_map[dir] = find_async (tile_path[dir], this, load)))
@@ -1598,7 +1622,7 @@
return;
for_all_players (pl)
- if (pl->observe->map == this)
+ if (pl->ob->map == this)
if (client *ns = pl->ns)
{
int dx = x - pl->ob->x;