--- deliantra/server/server/move.C 2007/05/28 21:28:36 1.19
+++ deliantra/server/server/move.C 2008/12/28 06:59:27 1.29
@@ -1,25 +1,24 @@
/*
- * 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 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.
+ * 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.
*
- * 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.
+ * 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 Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * 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
@@ -38,7 +37,7 @@
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.
@@ -53,19 +52,19 @@
int
move_ob (object *op, int dir, object *originator)
{
- sint16 newx = op->x + freearr_x[dir];
- sint16 newy = op->y + freearr_y[dir];
+ return op->move (dir, originator);
+}
+
+int
+object::move (int dir, object *originator)
+{
+ sint16 newx = x + freearr_x[dir];
+ sint16 newy = y + freearr_y[dir];
object *tmp;
maptile *m;
int mflags;
- if (op == NULL)
- {
- LOG (llevError, "Trying to move NULL.\n");
- return 0;
- }
-
- m = op->map;
+ m = map;
mflags = get_map_flags (m, &m, newx, newy, &newx, &newy);
/* If the space the player is trying to is out of the map,
@@ -77,23 +76,23 @@
/* 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, m, newx, newy) && !flag [FLAG_WIZPASS])
return 0;
/* 0.94.2 - 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))
+ if (more && !more->move (dir, 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, m, newx, newy);
- if (op->will_apply & 8)
- check_doors (op, m, newx, newy);
+ if (will_apply & 8)
+ check_doors (this, 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
@@ -104,8 +103,7 @@
* 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))
+ if (flag [FLAG_REMOVED])//D remove or fix?
{
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 */
@@ -115,38 +113,34 @@
/* 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 (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 (m), ARG_INT (newx), ARG_INT (newy)))
return 0;
- if (INVOKE_MAP (ENTER, m, ARG_PLAYER (op->contr), ARG_INT (newx), ARG_INT (newy)))
+ if (INVOKE_MAP (ENTER, m, ARG_PLAYER (contr), ARG_INT (newx), ARG_INT (newy)))
return 0;
}
else
- op->remove ();
+ 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)
+ for (tmp = this; tmp; 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);
+ xy_normalise (tmp->map, tmp->x, tmp->y);
}
/* insert_ob_in_map will deal with any tiling issues */
- insert_ob_in_map (op, m, originator, 0);
+ insert_ob_in_map (this, map, originator, 0);
return 1;
}
@@ -178,18 +172,18 @@
if (i == -1)
return 0; /* No free spot */
- if (op->head != NULL)
- op = op->head;
+ op = op->head_ ();
op->remove ();
- for (tmp = op; tmp != NULL; tmp = tmp->more)
- tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x),
- tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y);
- tmp = insert_ob_in_map (op, op->map, originator, 0);
- if (tmp)
- return 0;
- else
- return 1;
+ 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);
+ }
+
+ op = insert_ob_in_map (op, op->map, originator, 0);
+
+ return !op;
}
/*
@@ -227,9 +221,11 @@
{
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);
while (other_teleporter)
@@ -238,13 +234,15 @@
break;
other_teleporter = other_teleporter->above;
}
- if (other_teleporter && !(RANDOM () % ++nrofalt))
+
+ if (other_teleporter && !rndm (++nrofalt))
altern = other_teleporter;
}
if (!nrofalt)
{
- LOG (llevError, "No alternative teleporters around!\n");
+ LOG (llevError, "%s: no alternative teleporters around (user %s).\n",
+ teleporter->debug_desc (), user->debug_desc ());
return 0;
}
@@ -286,13 +284,14 @@
user->remove ();
/* Update location for the object */
- for (tmp = user; tmp != NULL; tmp = tmp->more)
+ for (tmp = user; tmp; tmp = tmp->more)
{
- tmp->x = other_teleporter->x + freearr_x[k] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x);
- tmp->y = other_teleporter->y + freearr_y[k] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y);
+ tmp->x = other_teleporter->x + freearr_x[k] + (tmp->arch ? tmp->arch->x : 0);
+ tmp->y = other_teleporter->y + freearr_y[k] + (tmp->arch ? tmp->arch->y : 0);
}
+
tmp = insert_ob_in_map (user, other_teleporter->map, NULL, 0);
- return (tmp == NULL);
+ return !tmp;
}
void
@@ -375,7 +374,9 @@
x = op->x + freearr_x[dir];
y = op->y + freearr_y[dir];
- if (!QUERY_FLAG (op, FLAG_CAN_ROLL) || (op->weight && random_roll (0, op->weight / 50000 - 1, pusher, PREFER_LOW) > pusher->stats.Str))
+ if (!QUERY_FLAG (op, FLAG_CAN_ROLL)
+ || (op->weight && random_roll (0, op->weight / 50000 - 1, pusher, PREFER_LOW)
+ > pusher->stats.Str))
return 0;
m = op->map;