--- deliantra/server/server/move.C 2008/08/26 02:35:05 1.26
+++ deliantra/server/server/move.C 2009/11/15 19:13:01 1.34
@@ -5,18 +5,19 @@
* Copyright (©) 2002,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
*/
@@ -33,11 +34,10 @@
* This is an improvement from the previous move_ob(), which
* removed and inserted objects even if they were unable to move.
*/
-
int
move_object (object *op, int dir)
{
- return move_ob (op, dir, op);
+ return op->move (dir);
}
/* object op is trying to move in direction dir.
@@ -52,105 +52,72 @@
int
move_ob (object *op, int dir, object *originator)
{
- sint16 newx = op->x + freearr_x[dir];
- sint16 newy = op->y + freearr_y[dir];
- object *tmp;
- maptile *m;
- int mflags;
+ return op->move (dir, originator);
+}
- if (op == NULL)
- {
- LOG (llevError, "Trying to move NULL.\n");
- return 0;
- }
+int
+object::move (int dir, object *originator)
+{
+ sint16 newx = x + freearr_x[dir];
+ sint16 newy = y + freearr_y[dir];
- m = op->map;
- mflags = get_map_flags (m, &m, newx, newy, &newx, &newy);
+ mapxy pos (this);
+ pos.move (dir);
- /* If the space the player is trying to is out of the map,
+ /* If the space the object is moving to is out of the map,
* bail now - we know it can't work.
*/
- if (mflags & P_OUT_OF_MAP)
+ if (!pos.normalise ())
return 0;
/* Is this space blocked? Players with wizpass are immune to
* this condition.
*/
- if (blocked_link (op, m, newx, newy) && !QUERY_FLAG (op, FLAG_WIZPASS))
+ if (blocked_link (this, pos.m, pos.x, pos.y) && !flag [FLAG_WIZPASS])
+ return 0;
+
+ // check tail movability
+ if (more && !more->move (dir, more->head))
return 0;
- /* 0.94.2 - we need to set the direction for the new animation code.
+ /* we need to set the direction for the new animation code.
* it uses it to figure out face to use - I can't see it
* breaking anything, but it might.
*/
- if (op->more && !move_ob (op->more, dir, op->more->head))
- return 0;
-
- op->direction = dir;
+ direction = dir;
- if (op->will_apply & 4)
- check_earthwalls (op, m, newx, newy);
+ if (will_apply & 4)
+ check_earthwalls (this, pos.m, pos.x, pos.y);
- if (op->will_apply & 8)
- check_doors (op, m, newx, newy);
-
- /* 0.94.1 - I got a stack trace that showed it crash with remove_ob trying
- * to remove a removed object, and this function was the culprit. A possible
- * guess I have is that check_doors above ran into a trap, killing the
- * monster.
- *
- * Unfortunately, it doesn't appear that the calling functions of move_object
- * deal very well with op being killed, so all this might do is just
- * migrate the problem someplace else.
- */
-
- if (QUERY_FLAG (op, FLAG_REMOVED))
- {
- LOG (llevDebug, "move_object: monster has been removed - will not process further\n");
- /* Was not successful, but don't want to try and move again */
- return 1;
- }
+ if (will_apply & 8)
+ check_doors (this, pos.m, pos.x, pos.y);
/* If this is a tail portion, just want to tell caller that move is
* ok - the caller will deal with actual object removal/insertion
*/
- if (op->head)
+ if (head)
return 1;
- if (m != op->map && op->contr)
+ if (pos.m != map && contr)
{
- if (INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr)))
+ if (INVOKE_MAP (LEAVE, map, ARG_PLAYER (contr)))
return 0;
- op->remove ();
+ remove ();
- if (INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (m), ARG_INT (newx), ARG_INT (newy)))
+ if (INVOKE_PLAYER (MAP_CHANGE, contr, ARG_MAP (pos.m), ARG_INT (pos.x), ARG_INT (pos.y)))
return 0;
- if (INVOKE_MAP (ENTER, m, ARG_PLAYER (op->contr), ARG_INT (newx), ARG_INT (newy)))
+ if (INVOKE_MAP (ENTER, pos.m, ARG_PLAYER (contr), ARG_INT (pos.x), ARG_INT (pos.y)))
return 0;
}
- else
- op->remove ();
-
- /* we already have newx, newy, and m, so lets use them.
- * In addition, this fixes potential crashes, because multipart object was
- * on edge of map, +=x, +=y doesn't make correct coordinates.
- */
- for (tmp = op; tmp != NULL; tmp = tmp->more)
- {
- tmp->x += freearr_x[dir];
- tmp->y += freearr_y[dir];
- tmp->map = get_map_from_coord (tmp->map, &tmp->x, &tmp->y);
- }
/* insert_ob_in_map will deal with any tiling issues */
- insert_ob_in_map (op, m, originator, 0);
+ pos.insert (this, originator);
return 1;
}
-
/*
* transfer_ob(): Move an object (even linked objects) to another spot
* on the same map.
@@ -182,8 +149,8 @@
for (object *tmp = op; tmp; tmp = tmp->more)
{
- tmp->x = x + freearr_x[i] + (!tmp->arch ? 0 : tmp->arch->x);
- tmp->y = y + freearr_y[i] + (!tmp->arch ? 0 : tmp->arch->y);
+ tmp->x = x + freearr_x[i] + tmp->arch->x;
+ tmp->y = y + freearr_y[i] + tmp->arch->y;
}
op = insert_ob_in_map (op, op->map, originator, 0);
@@ -206,39 +173,30 @@
int
teleport (object *teleporter, uint8 tele_type, object *user)
{
- object *altern;
- int i, j, k, nrofalt = 0;
- object *other_teleporter, *tmp;
- maptile *m;
- sint16 sx, sy;
-
- if (user == NULL)
+ if (!user)
return 0;
- if (user->head != NULL)
- user = user->head;
+
+ object *other_teleporter = 0;
+ int nrofalt = 0;
+
+ user = user->head_ ();
/* Find all other teleporters within range. This range
* should really be setable by some object attribute instead of
* using hard coded values.
*/
- for (i = -5; i < 6; i++)
- for (j = -5; j < 6; j++)
- {
- if (i == 0 && j == 0)
- continue;
- /* Perhaps this should be extended to support tiled maps */
- if (OUT_OF_REAL_MAP (teleporter->map, teleporter->x + i, teleporter->y + j))
- continue;
- other_teleporter = GET_MAP_OB (teleporter->map, teleporter->x + i, teleporter->y + j);
+ unordered_mapwalk (teleporter, -5, -5, 5, 5)
+ {
+ mapspace &ms = m->at (nx, ny);
- while (other_teleporter)
+ for (object *tmp = ms.top; tmp; tmp = tmp->below)
+ if (tmp->type == tele_type)
{
- if (other_teleporter->type == tele_type)
- break;
- other_teleporter = other_teleporter->above;
+ if ((dx || dy) && !rndm (++nrofalt))
+ other_teleporter = tmp;
+
+ break;
}
- if (other_teleporter && !(RANDOM () % ++nrofalt))
- altern = other_teleporter;
}
if (!nrofalt)
@@ -248,8 +206,7 @@
return 0;
}
- other_teleporter = altern;
- k = find_free_spot (user, other_teleporter->map, other_teleporter->x, other_teleporter->y, 1, 9);
+ int k = find_free_spot (user, other_teleporter->map, other_teleporter->x, other_teleporter->y, 1, 9);
/* if k==-1, unable to find a free spot. If this is shop
* mat that the player is using, find someplace to move
@@ -260,18 +217,21 @@
*/
if (k == -1)
{
- if (tele_type == SHOP_MAT && user->type == PLAYER)
+ if (tele_type == SHOP_MAT && user->is_player ())
{
for (k = 1; k < 9; k++)
{
+ maptile *m;
+ sint16 sx, sy;
+
if (get_map_flags (other_teleporter->map, &m,
other_teleporter->x + freearr_x[k], other_teleporter->y + freearr_y[k], &sx, &sy) & P_OUT_OF_MAP)
continue;
if (!OB_TYPE_MOVE_BLOCK (user, GET_MAP_MOVE_BLOCK (m, sx, sy)))
break;
-
}
+
if (k == 9)
{
LOG (llevError, "Shop mat %s (%d, %d) is in solid rock?\n",
@@ -283,29 +243,9 @@
return 0;
}
- user->remove ();
-
- /* Update location for the object */
- for (tmp = user; tmp != NULL; tmp = tmp->more)
- {
- tmp->x = other_teleporter->x + freearr_x[k] + (tmp->arch == NULL ? 0 : tmp->arch->x);
- tmp->y = other_teleporter->y + freearr_y[k] + (tmp->arch == NULL ? 0 : tmp->arch->y);
- }
- tmp = insert_ob_in_map (user, other_teleporter->map, NULL, 0);
- return (tmp == NULL);
-}
-
-void
-recursive_roll (object *op, int dir, object *pusher)
-{
- if (!roll_ob (op, dir, pusher))
- {
- new_draw_info_format (NDI_UNIQUE, 0, pusher, "You fail to push the %s.", query_name (op));
- return;
- }
- (void) move_ob (pusher, dir, pusher);
- new_draw_info_format (NDI_BLACK, 0, pusher, "You move the %s.", query_name (op));
- return;
+ return !other_teleporter->map->insert (
+ user, other_teleporter->x + freearr_x[k], other_teleporter->y + freearr_y[k]
+ );
}
/*
@@ -316,8 +256,7 @@
* This is currently only used for the boulder roll code.
* Returns 1 if object does not fit, 0 if it does.
*/
-
-int
+static int
try_fit (object *op, maptile *m, int x, int y)
{
object *tmp, *more;
@@ -359,11 +298,9 @@
* it does not roll objects behind multipart objects properly.
* Support for rolling multipart objects is questionable.
*/
-
-int
+static int
roll_ob (object *op, int dir, object *pusher)
{
- object *tmp;
sint16 x, y;
int flags;
maptile *m;
@@ -391,24 +328,38 @@
/* If the target space is not blocked, no need to look at the objects on it */
if ((op->move_type & move_block) == op->move_type)
{
- for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above)
+ for (object *tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
{
if (tmp->head == op)
continue;
+
if (OB_MOVE_BLOCK (op, tmp) && !roll_ob (tmp, dir, pusher))
return 0;
}
}
+
if (try_fit (op, m, x, y))
return 0;
- op->remove ();
- for (tmp = op; tmp != NULL; tmp = tmp->more)
- tmp->x += freearr_x[dir], tmp->y += freearr_y[dir];
- insert_ob_in_map (op, op->map, pusher, 0);
+ op->move (dir);
+
return 1;
}
+void
+recursive_roll (object *op, int dir, object *pusher)
+{
+ if (!roll_ob (op, dir, pusher))
+ {
+ new_draw_info_format (NDI_UNIQUE, 0, pusher, "You fail to push the %s.", query_name (op));
+ return;
+ }
+
+ move_ob (pusher, dir, pusher);
+ new_draw_info_format (NDI_BLACK, 0, pusher, "You move the %s.", query_name (op));
+ return;
+}
+
/* returns 1 if pushing invokes a attack, 0 when not */
int
push_ob (object *who, int dir, object *pusher)
@@ -449,6 +400,7 @@
insert_ob_in_map (who, who->map, pusher, 0);
insert_ob_in_map (pusher, pusher->map, pusher, 0);
+
return 0;
}
@@ -467,13 +419,13 @@
return 1;
}
else
- new_draw_info_format (NDI_UNIQUE, 0, pusher, "You avoid attacking %s.", &who->name);
+ new_draw_info_format (NDI_UNIQUE, 0, pusher, "You avoid attacking %s. H", &who->name);
}
- /* now, lets test stand still. we NEVER can push stand_still monsters. */
+ /* now, let's test stand still. we NEVER can push stand_still monsters. */
if (QUERY_FLAG (who, FLAG_STAND_STILL))
{
- new_draw_info_format (NDI_UNIQUE, 0, pusher, "You can't push %s.", &who->name);
+ new_draw_info_format (NDI_UNIQUE, 0, pusher, "You can't push %s. H", &who->name);
return 0;
}