ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/move.C
(Generate patch)

Comparing deliantra/server/server/move.C (file contents):
Revision 1.20 by root, Mon Jun 4 13:04:00 2007 UTC vs.
Revision 1.29 by root, Sun Dec 28 06:59:27 2008 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Crossfire TRT is free software; you can redistribute it and/or modify it 8 * Deliantra is free software: you can redistribute it and/or modify
9 * under the terms of the GNU General Public License as published by the Free 9 * it under the terms of the GNU General Public License as published by
10 * Software Foundation; either version 2 of the License, or (at your option) 10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version. 11 * (at your option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, but 13 * This program is distributed in the hope that it will be useful,
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License along 18 * You should have received a copy of the GNU General Public License
19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * 20 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 22 */
24 23
25#include <global.h> 24#include <global.h>
26#ifndef __CEXTRACT__ 25#ifndef __CEXTRACT__
27# include <sproto.h> 26# include <sproto.h>
36 */ 35 */
37 36
38int 37int
39move_object (object *op, int dir) 38move_object (object *op, int dir)
40{ 39{
41 return move_ob (op, dir, op); 40 return op->move (dir);
42} 41}
43 42
44/* object op is trying to move in direction dir. 43/* object op is trying to move in direction dir.
45 * originator is typically the same as op, but 44 * originator is typically the same as op, but
46 * can be different if originator is causing op to 45 * can be different if originator is causing op to
51 * very similiar to move_object. 50 * very similiar to move_object.
52 */ 51 */
53int 52int
54move_ob (object *op, int dir, object *originator) 53move_ob (object *op, int dir, object *originator)
55{ 54{
55 return op->move (dir, originator);
56}
57
58int
59object::move (int dir, object *originator)
60{
56 sint16 newx = op->x + freearr_x[dir]; 61 sint16 newx = x + freearr_x[dir];
57 sint16 newy = op->y + freearr_y[dir]; 62 sint16 newy = y + freearr_y[dir];
58 object *tmp; 63 object *tmp;
59 maptile *m; 64 maptile *m;
60 int mflags; 65 int mflags;
61 66
62 if (op == NULL)
63 {
64 LOG (llevError, "Trying to move NULL.\n");
65 return 0;
66 }
67
68 m = op->map; 67 m = map;
69 mflags = get_map_flags (m, &m, newx, newy, &newx, &newy); 68 mflags = get_map_flags (m, &m, newx, newy, &newx, &newy);
70 69
71 /* If the space the player is trying to is out of the map, 70 /* If the space the player is trying to is out of the map,
72 * bail now - we know it can't work. 71 * bail now - we know it can't work.
73 */ 72 */
75 return 0; 74 return 0;
76 75
77 /* Is this space blocked? Players with wizpass are immune to 76 /* Is this space blocked? Players with wizpass are immune to
78 * this condition. 77 * this condition.
79 */ 78 */
80 if (blocked_link (op, m, newx, newy) && !QUERY_FLAG (op, FLAG_WIZPASS)) 79 if (blocked_link (this, m, newx, newy) && !flag [FLAG_WIZPASS])
81 return 0; 80 return 0;
82 81
83 /* 0.94.2 - we need to set the direction for the new animation code. 82 /* 0.94.2 - we need to set the direction for the new animation code.
84 * it uses it to figure out face to use - I can't see it 83 * it uses it to figure out face to use - I can't see it
85 * breaking anything, but it might. 84 * breaking anything, but it might.
86 */ 85 */
87 if (op->more && !move_ob (op->more, dir, op->more->head)) 86 if (more && !more->move (dir, more->head))
88 return 0; 87 return 0;
89 88
90 op->direction = dir; 89 direction = dir;
91 90
92 if (op->will_apply & 4) 91 if (will_apply & 4)
93 check_earthwalls (op, m, newx, newy); 92 check_earthwalls (this, m, newx, newy);
94 93
95 if (op->will_apply & 8) 94 if (will_apply & 8)
96 check_doors (op, m, newx, newy); 95 check_doors (this, m, newx, newy);
97 96
98 /* 0.94.1 - I got a stack trace that showed it crash with remove_ob trying 97 /* 0.94.1 - I got a stack trace that showed it crash with remove_ob trying
99 * to remove a removed object, and this function was the culprit. A possible 98 * to remove a removed object, and this function was the culprit. A possible
100 * guess I have is that check_doors above ran into a trap, killing the 99 * guess I have is that check_doors above ran into a trap, killing the
101 * monster. 100 * monster.
102 * 101 *
103 * Unfortunately, it doesn't appear that the calling functions of move_object 102 * Unfortunately, it doesn't appear that the calling functions of move_object
104 * deal very well with op being killed, so all this might do is just 103 * deal very well with op being killed, so all this might do is just
105 * migrate the problem someplace else. 104 * migrate the problem someplace else.
106 */ 105 */
107 106 if (flag [FLAG_REMOVED])//D remove or fix?
108 if (QUERY_FLAG (op, FLAG_REMOVED))
109 { 107 {
110 LOG (llevDebug, "move_object: monster has been removed - will not process further\n"); 108 LOG (llevDebug, "move_object: monster has been removed - will not process further\n");
111 /* Was not successful, but don't want to try and move again */ 109 /* Was not successful, but don't want to try and move again */
112 return 1; 110 return 1;
113 } 111 }
114 112
115 /* If this is a tail portion, just want to tell caller that move is 113 /* If this is a tail portion, just want to tell caller that move is
116 * ok - the caller will deal with actual object removal/insertion 114 * ok - the caller will deal with actual object removal/insertion
117 */ 115 */
118 if (op->head) 116 if (head)
119 return 1; 117 return 1;
120 118
121 if (m != op->map && op->contr) 119 if (m != map && contr)
122 { 120 {
123 if (INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr))) 121 if (INVOKE_MAP (LEAVE, map, ARG_PLAYER (contr)))
124 return 0; 122 return 0;
125 123
126 op->remove (); 124 remove ();
127 125
128 if (INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (m), ARG_INT (newx), ARG_INT (newy))) 126 if (INVOKE_PLAYER (MAP_CHANGE, contr, ARG_MAP (m), ARG_INT (newx), ARG_INT (newy)))
129 return 0; 127 return 0;
130 128
131 if (INVOKE_MAP (ENTER, m, ARG_PLAYER (op->contr), ARG_INT (newx), ARG_INT (newy))) 129 if (INVOKE_MAP (ENTER, m, ARG_PLAYER (contr), ARG_INT (newx), ARG_INT (newy)))
132 return 0; 130 return 0;
133 } 131 }
134 else 132 else
135 op->remove (); 133 remove ();
136 134
137 /* we already have newx, newy, and m, so lets use them.
138 * In addition, this fixes potential crashes, because multipart object was
139 * on edge of map, +=x, +=y doesn't make correct coordinates.
140 */
141 for (tmp = op; tmp != NULL; tmp = tmp->more) 135 for (tmp = this; tmp; tmp = tmp->more)
142 { 136 {
143 tmp->x += freearr_x[dir]; 137 tmp->x += freearr_x[dir];
144 tmp->y += freearr_y[dir]; 138 tmp->y += freearr_y[dir];
145 tmp->map = get_map_from_coord (tmp->map, &tmp->x, &tmp->y); 139 xy_normalise (tmp->map, tmp->x, tmp->y);
146 } 140 }
147 141
148 /* insert_ob_in_map will deal with any tiling issues */ 142 /* insert_ob_in_map will deal with any tiling issues */
149 insert_ob_in_map (op, m, originator, 0); 143 insert_ob_in_map (this, map, originator, 0);
150 144
151 return 1; 145 return 1;
152} 146}
153 147
154 148
176 i = find_first_free_spot (op, op->map, x, y); 170 i = find_first_free_spot (op, op->map, x, y);
177 171
178 if (i == -1) 172 if (i == -1)
179 return 0; /* No free spot */ 173 return 0; /* No free spot */
180 174
181 if (op->head != NULL)
182 op = op->head; 175 op = op->head_ ();
183 op->remove (); 176 op->remove ();
177
184 for (tmp = op; tmp != NULL; tmp = tmp->more) 178 for (object *tmp = op; tmp; tmp = tmp->more)
179 {
185 tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->x), 180 tmp->x = x + freearr_x[i] + (!tmp->arch ? 0 : tmp->arch->x);
186 tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->y); 181 tmp->y = y + freearr_y[i] + (!tmp->arch ? 0 : tmp->arch->y);
182 }
187 183
188 tmp = insert_ob_in_map (op, op->map, originator, 0); 184 op = insert_ob_in_map (op, op->map, originator, 0);
189 if (tmp) 185
190 return 0; 186 return !op;
191 else
192 return 1;
193} 187}
194 188
195/* 189/*
196 * Return value: 1 if object was destroyed, 0 otherwise. 190 * Return value: 1 if object was destroyed, 0 otherwise.
197 * Modified so that instead of passing the 'originator' that had no 191 * Modified so that instead of passing the 'originator' that had no
225 for (i = -5; i < 6; i++) 219 for (i = -5; i < 6; i++)
226 for (j = -5; j < 6; j++) 220 for (j = -5; j < 6; j++)
227 { 221 {
228 if (i == 0 && j == 0) 222 if (i == 0 && j == 0)
229 continue; 223 continue;
224
230 /* Perhaps this should be extended to support tiled maps */ 225 /* Perhaps this should be extended to support tiled maps */
231 if (OUT_OF_REAL_MAP (teleporter->map, teleporter->x + i, teleporter->y + j)) 226 if (OUT_OF_REAL_MAP (teleporter->map, teleporter->x + i, teleporter->y + j))
232 continue; 227 continue;
228
233 other_teleporter = GET_MAP_OB (teleporter->map, teleporter->x + i, teleporter->y + j); 229 other_teleporter = GET_MAP_OB (teleporter->map, teleporter->x + i, teleporter->y + j);
234 230
235 while (other_teleporter) 231 while (other_teleporter)
236 { 232 {
237 if (other_teleporter->type == tele_type) 233 if (other_teleporter->type == tele_type)
238 break; 234 break;
239 other_teleporter = other_teleporter->above; 235 other_teleporter = other_teleporter->above;
240 } 236 }
237
241 if (other_teleporter && !(RANDOM () % ++nrofalt)) 238 if (other_teleporter && !rndm (++nrofalt))
242 altern = other_teleporter; 239 altern = other_teleporter;
243 } 240 }
244 241
245 if (!nrofalt) 242 if (!nrofalt)
246 { 243 {
247 LOG (llevError, "No alternative teleporters around!\n"); 244 LOG (llevError, "%s: no alternative teleporters around (user %s).\n",
245 teleporter->debug_desc (), user->debug_desc ());
248 return 0; 246 return 0;
249 } 247 }
250 248
251 other_teleporter = altern; 249 other_teleporter = altern;
252 k = find_free_spot (user, other_teleporter->map, other_teleporter->x, other_teleporter->y, 1, 9); 250 k = find_free_spot (user, other_teleporter->map, other_teleporter->x, other_teleporter->y, 1, 9);
284 } 282 }
285 283
286 user->remove (); 284 user->remove ();
287 285
288 /* Update location for the object */ 286 /* Update location for the object */
289 for (tmp = user; tmp != NULL; tmp = tmp->more) 287 for (tmp = user; tmp; tmp = tmp->more)
290 { 288 {
291 tmp->x = other_teleporter->x + freearr_x[k] + (tmp->arch == NULL ? 0 : tmp->arch->x); 289 tmp->x = other_teleporter->x + freearr_x[k] + (tmp->arch ? tmp->arch->x : 0);
292 tmp->y = other_teleporter->y + freearr_y[k] + (tmp->arch == NULL ? 0 : tmp->arch->y); 290 tmp->y = other_teleporter->y + freearr_y[k] + (tmp->arch ? tmp->arch->y : 0);
293 } 291 }
292
294 tmp = insert_ob_in_map (user, other_teleporter->map, NULL, 0); 293 tmp = insert_ob_in_map (user, other_teleporter->map, NULL, 0);
295 return (tmp == NULL); 294 return !tmp;
296} 295}
297 296
298void 297void
299recursive_roll (object *op, int dir, object *pusher) 298recursive_roll (object *op, int dir, object *pusher)
300{ 299{
373 op = op->head; 372 op = op->head;
374 373
375 x = op->x + freearr_x[dir]; 374 x = op->x + freearr_x[dir];
376 y = op->y + freearr_y[dir]; 375 y = op->y + freearr_y[dir];
377 376
378 if (!QUERY_FLAG (op, FLAG_CAN_ROLL) || (op->weight && random_roll (0, op->weight / 50000 - 1, pusher, PREFER_LOW) > pusher->stats.Str)) 377 if (!QUERY_FLAG (op, FLAG_CAN_ROLL)
378 || (op->weight && random_roll (0, op->weight / 50000 - 1, pusher, PREFER_LOW)
379 > pusher->stats.Str))
379 return 0; 380 return 0;
380 381
381 m = op->map; 382 m = op->map;
382 flags = get_map_flags (m, &m, x, y, &x, &y); 383 flags = get_map_flags (m, &m, x, y, &x, &y);
383 384

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines