--- deliantra/server/server/move.C 2006/09/10 15:59:57 1.7
+++ deliantra/server/server/move.C 2008/12/28 06:59:27 1.29
@@ -1,42 +1,31 @@
-
/*
- * static char *rcsid_move_c =
- * "$Id: move.C,v 1.7 2006/09/10 15:59:57 root Exp $";
+ * This file is part of Deliantra, the Roguelike Realtime MMORPG.
+ *
+ * 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
+ *
+ * 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.
+ *
+ * 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
*/
-/*
- CrossFire, A Multiplayer game for X-windows
-
- 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 author can be reached via e-mail to crossfire-devel@real-time.com
-*/
-
#include
#ifndef __CEXTRACT__
# include
#endif
-#ifdef COZY_SERVER
-// use a ptotoype
-extern int same_party (partylist *a, partylist *b);
-#endif
-
/*
* move_object() tries to move object op in the direction "dir".
* If it fails (something blocks the passage), it returns 0,
@@ -48,10 +37,9 @@
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.
* originator is typically the same as op, but
* can be different if originator is causing op to
@@ -64,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;
- mapstruct *m;
+ 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,
@@ -85,26 +73,26 @@
if (mflags & P_OUT_OF_MAP)
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, 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 != NULL && !move_ob (op->more, dir, op->more->head))
+ if (more && !more->move (dir, more->head))
return 0;
- op->direction = dir;
+ direction = dir;
+
+ if (will_apply & 4)
+ check_earthwalls (this, m, newx, newy);
- if (op->will_apply & 4)
- check_earthwalls (op, 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
@@ -115,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 */
@@ -126,24 +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;
- remove_ob (op);
+ if (m != map && contr)
+ {
+ if (INVOKE_MAP (LEAVE, map, ARG_PLAYER (contr)))
+ return 0;
+
+ 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)
+ if (INVOKE_PLAYER (MAP_CHANGE, contr, ARG_MAP (m), ARG_INT (newx), ARG_INT (newy)))
+ return 0;
+
+ if (INVOKE_MAP (ENTER, m, ARG_PLAYER (contr), ARG_INT (newx), ARG_INT (newy)))
+ return 0;
+ }
+ else
+ remove ();
+
+ 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;
}
@@ -175,18 +172,18 @@
if (i == -1)
return 0; /* No free spot */
- if (op->head != NULL)
- op = op->head;
- remove_ob (op);
- 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);
+ op = op->head_ ();
+ op->remove ();
- 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;
}
/*
@@ -207,7 +204,7 @@
object *altern;
int i, j, k, nrofalt = 0;
object *other_teleporter, *tmp;
- mapstruct *m;
+ maptile *m;
sint16 sx, sy;
if (user == NULL)
@@ -224,10 +221,12 @@
{
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);
+
+ other_teleporter = GET_MAP_OB (teleporter->map, teleporter->x + i, teleporter->y + j);
while (other_teleporter)
{
@@ -235,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;
}
@@ -280,16 +281,17 @@
return 0;
}
- remove_ob (user);
+ 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
@@ -315,12 +317,12 @@
*/
int
-try_fit (object *op, mapstruct *m, int x, int y)
+try_fit (object *op, maptile *m, int x, int y)
{
object *tmp, *more;
sint16 tx, ty;
int mflags;
- mapstruct *m2;
+ maptile *m2;
if (op->head)
op = op->head;
@@ -335,7 +337,7 @@
if (mflags & P_OUT_OF_MAP)
return 1;
- for (tmp = get_map_ob (m2, tx, ty); tmp; tmp = tmp->above)
+ for (tmp = GET_MAP_OB (m2, tx, ty); tmp; tmp = tmp->above)
{
if (tmp->head == op || tmp == op)
continue;
@@ -363,7 +365,7 @@
object *tmp;
sint16 x, y;
int flags;
- mapstruct *m;
+ maptile *m;
MoveType move_block;
if (op->head)
@@ -372,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;
@@ -386,7 +390,7 @@
/* 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 (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above)
{
if (tmp->head == op)
continue;
@@ -397,7 +401,7 @@
if (try_fit (op, m, x, y))
return 0;
- remove_ob (op);
+ 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);
@@ -413,7 +417,7 @@
if (who->head != NULL)
who = who->head;
- owner = get_owner (who);
+ owner = who->owner;
/* Wake up sleeping monsters that may be pushed */
CLEAR_FLAG (who, FLAG_SLEEP);
@@ -421,18 +425,15 @@
/* player change place with his pets or summoned creature */
/* TODO: allow multi arch pushing. Can't be very difficult */
if (who->more == NULL
-#ifdef COZY_SERVER
- && ((owner && owner->contr && pusher->contr && same_party (owner->contr->party, pusher->contr->party)) || owner == pusher)
-#else
- && owner == pusher
-#endif
+ && ((owner && owner->contr && pusher->contr && same_party (owner->contr->party, pusher->contr->party))
+ || owner == pusher)
)
{
int temp;
- mapstruct *m;
+ maptile *m;
- remove_ob (who);
- remove_ob (pusher);
+ who->remove ();
+ pusher->remove ();
temp = pusher->x;
pusher->x = who->x;
who->x = temp;
@@ -450,26 +451,22 @@
return 0;
}
-
/* We want ONLY become enemy of evil, unaggressive monster. We must RUN in them */
/* In original we have here a unaggressive check only - that was the reason why */
/* we so often become an enemy of friendly monsters... */
/* funny: was they set to unaggressive 0 (= not so nice) they don't attack */
-
if (owner != pusher && pusher->type == PLAYER && who->type != PLAYER &&
!QUERY_FLAG (who, FLAG_FRIENDLY) && !QUERY_FLAG (who, FLAG_NEUTRAL))
{
if (pusher->contr->run_on) /* only when we run */
{
- new_draw_info_format (NDI_UNIQUE, 0, pusher, "You start to attack %s !!", &who->name);
+ new_draw_info_format (NDI_UNIQUE, 0, pusher, "You start to attack %s!!", &who->name);
CLEAR_FLAG (who, FLAG_UNAGGRESSIVE); /* the sucker don't like you anymore */
who->enemy = pusher;
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.", &who->name);
}
/* now, lets test stand still. we NEVER can push stand_still monsters. */
@@ -489,13 +486,12 @@
str1 = (who->stats.Str > 0 ? who->stats.Str : who->level);
str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level);
if (QUERY_FLAG (who, FLAG_WIZ) ||
- random_roll (str1, str1 / 2 + str1 * 2, who, PREFER_HIGH) >=
- random_roll (str2, str2 / 2 + str2 * 2, pusher, PREFER_HIGH) || !move_object (who, dir))
+ random_roll (str1, str1 * 5 / 2, who, PREFER_HIGH) >=
+ random_roll (str2, str2 * 5 / 2, pusher, PREFER_HIGH) || !move_object (who, dir))
{
if (who->type == PLAYER)
- {
- new_draw_info_format (NDI_UNIQUE, 0, who, "%s tried to push you.", &pusher->name);
- }
+ new_draw_info_format (NDI_UNIQUE, 0, who, "%s tried to push you.", &pusher->name);
+
return 0;
}