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.7 by root, Sun Sep 10 15:59:57 2006 UTC vs.
Revision 1.13 by root, Thu Jan 4 16:19:32 2007 UTC

1
2/*
3 * static char *rcsid_move_c =
4 * "$Id: move.C,v 1.7 2006/09/10 15:59:57 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The author can be reached via e-mail to crossfire-devel@real-time.com 21 The author can be reached via e-mail to <crossfire@schmorp.de>
28*/ 22*/
29 23
30#include <global.h> 24#include <global.h>
31#ifndef __CEXTRACT__ 25#ifndef __CEXTRACT__
32# include <sproto.h> 26# include <sproto.h>
65move_ob (object *op, int dir, object *originator) 59move_ob (object *op, int dir, object *originator)
66{ 60{
67 sint16 newx = op->x + freearr_x[dir]; 61 sint16 newx = op->x + freearr_x[dir];
68 sint16 newy = op->y + freearr_y[dir]; 62 sint16 newy = op->y + freearr_y[dir];
69 object *tmp; 63 object *tmp;
70 mapstruct *m; 64 maptile *m;
71 int mflags; 65 int mflags;
72 66
73 if (op == NULL) 67 if (op == NULL)
74 { 68 {
75 LOG (llevError, "Trying to move NULL.\n"); 69 LOG (llevError, "Trying to move NULL.\n");
82 /* If the space the player is trying to is out of the map, 76 /* If the space the player is trying to is out of the map,
83 * bail now - we know it can't work. 77 * bail now - we know it can't work.
84 */ 78 */
85 if (mflags & P_OUT_OF_MAP) 79 if (mflags & P_OUT_OF_MAP)
86 return 0; 80 return 0;
87
88 81
89 /* Is this space blocked? Players with wizpass are immune to 82 /* Is this space blocked? Players with wizpass are immune to
90 * this condition. 83 * this condition.
91 */ 84 */
92 if (blocked_link (op, m, newx, newy) && !QUERY_FLAG (op, FLAG_WIZPASS)) 85 if (blocked_link (op, m, newx, newy) && !QUERY_FLAG (op, FLAG_WIZPASS))
94 87
95 /* 0.94.2 - we need to set the direction for the new animation code. 88 /* 0.94.2 - we need to set the direction for the new animation code.
96 * it uses it to figure out face to use - I can't see it 89 * it uses it to figure out face to use - I can't see it
97 * breaking anything, but it might. 90 * breaking anything, but it might.
98 */ 91 */
99 if (op->more != NULL && !move_ob (op->more, dir, op->more->head)) 92 if (op->more && !move_ob (op->more, dir, op->more->head))
100 return 0; 93 return 0;
101 94
102 op->direction = dir; 95 op->direction = dir;
103 96
104 if (op->will_apply & 4) 97 if (op->will_apply & 4)
105 check_earthwalls (op, m, newx, newy); 98 check_earthwalls (op, m, newx, newy);
99
106 if (op->will_apply & 8) 100 if (op->will_apply & 8)
107 check_doors (op, m, newx, newy); 101 check_doors (op, m, newx, newy);
108 102
109 /* 0.94.1 - I got a stack trace that showed it crash with remove_ob trying 103 /* 0.94.1 - I got a stack trace that showed it crash with remove_ob trying
110 * to remove a removed object, and this function was the culprit. A possible 104 * to remove a removed object, and this function was the culprit. A possible
127 * ok - the caller will deal with actual object removal/insertion 121 * ok - the caller will deal with actual object removal/insertion
128 */ 122 */
129 if (op->head) 123 if (op->head)
130 return 1; 124 return 1;
131 125
132 remove_ob (op); 126 if (m != op->map && op->contr)
127 {
128 if (INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr)))
129 return 0;
130
131 op->remove ();
132
133 if (INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (m), ARG_INT (newx), ARG_INT (newy)))
134 return 0;
135
136 if (INVOKE_MAP (ENTER, m, ARG_PLAYER (op->contr), ARG_INT (newx), ARG_INT (newy)))
137 return 0;
138 }
139 else
140 op->remove ();
133 141
134 /* we already have newx, newy, and m, so lets use them. 142 /* we already have newx, newy, and m, so lets use them.
135 * In addition, this fixes potential crashes, because multipart object was 143 * In addition, this fixes potential crashes, because multipart object was
136 * on edge of map, +=x, +=y doesn't make correct coordinates. 144 * on edge of map, +=x, +=y doesn't make correct coordinates.
137 */ 145 */
175 if (i == -1) 183 if (i == -1)
176 return 0; /* No free spot */ 184 return 0; /* No free spot */
177 185
178 if (op->head != NULL) 186 if (op->head != NULL)
179 op = op->head; 187 op = op->head;
180 remove_ob (op); 188 op->remove ();
181 for (tmp = op; tmp != NULL; tmp = tmp->more) 189 for (tmp = op; tmp != NULL; tmp = tmp->more)
182 tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x), 190 tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x),
183 tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); 191 tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y);
184 192
185 tmp = insert_ob_in_map (op, op->map, originator, 0); 193 tmp = insert_ob_in_map (op, op->map, originator, 0);
205teleport (object *teleporter, uint8 tele_type, object *user) 213teleport (object *teleporter, uint8 tele_type, object *user)
206{ 214{
207 object *altern; 215 object *altern;
208 int i, j, k, nrofalt = 0; 216 int i, j, k, nrofalt = 0;
209 object *other_teleporter, *tmp; 217 object *other_teleporter, *tmp;
210 mapstruct *m; 218 maptile *m;
211 sint16 sx, sy; 219 sint16 sx, sy;
212 220
213 if (user == NULL) 221 if (user == NULL)
214 return 0; 222 return 0;
215 if (user->head != NULL) 223 if (user->head != NULL)
225 if (i == 0 && j == 0) 233 if (i == 0 && j == 0)
226 continue; 234 continue;
227 /* Perhaps this should be extended to support tiled maps */ 235 /* Perhaps this should be extended to support tiled maps */
228 if (OUT_OF_REAL_MAP (teleporter->map, teleporter->x + i, teleporter->y + j)) 236 if (OUT_OF_REAL_MAP (teleporter->map, teleporter->x + i, teleporter->y + j))
229 continue; 237 continue;
230 other_teleporter = get_map_ob (teleporter->map, teleporter->x + i, teleporter->y + j); 238 other_teleporter = GET_MAP_OB (teleporter->map, teleporter->x + i, teleporter->y + j);
231 239
232 while (other_teleporter) 240 while (other_teleporter)
233 { 241 {
234 if (other_teleporter->type == tele_type) 242 if (other_teleporter->type == tele_type)
235 break; 243 break;
278 } 286 }
279 else 287 else
280 return 0; 288 return 0;
281 } 289 }
282 290
283 remove_ob (user); 291 user->remove ();
284 292
285 /* Update location for the object */ 293 /* Update location for the object */
286 for (tmp = user; tmp != NULL; tmp = tmp->more) 294 for (tmp = user; tmp != NULL; tmp = tmp->more)
287 { 295 {
288 tmp->x = other_teleporter->x + freearr_x[k] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x); 296 tmp->x = other_teleporter->x + freearr_x[k] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x);
313 * This is currently only used for the boulder roll code. 321 * This is currently only used for the boulder roll code.
314 * Returns 1 if object does not fit, 0 if it does. 322 * Returns 1 if object does not fit, 0 if it does.
315 */ 323 */
316 324
317int 325int
318try_fit (object *op, mapstruct *m, int x, int y) 326try_fit (object *op, maptile *m, int x, int y)
319{ 327{
320 object *tmp, *more; 328 object *tmp, *more;
321 sint16 tx, ty; 329 sint16 tx, ty;
322 int mflags; 330 int mflags;
323 mapstruct *m2; 331 maptile *m2;
324 332
325 if (op->head) 333 if (op->head)
326 op = op->head; 334 op = op->head;
327 335
328 for (more = op; more; more = more->more) 336 for (more = op; more; more = more->more)
333 mflags = get_map_flags (m, &m2, tx, ty, &tx, &ty); 341 mflags = get_map_flags (m, &m2, tx, ty, &tx, &ty);
334 342
335 if (mflags & P_OUT_OF_MAP) 343 if (mflags & P_OUT_OF_MAP)
336 return 1; 344 return 1;
337 345
338 for (tmp = get_map_ob (m2, tx, ty); tmp; tmp = tmp->above) 346 for (tmp = GET_MAP_OB (m2, tx, ty); tmp; tmp = tmp->above)
339 { 347 {
340 if (tmp->head == op || tmp == op) 348 if (tmp->head == op || tmp == op)
341 continue; 349 continue;
342 350
343 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->type != DOOR)) 351 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->type != DOOR))
361roll_ob (object *op, int dir, object *pusher) 369roll_ob (object *op, int dir, object *pusher)
362{ 370{
363 object *tmp; 371 object *tmp;
364 sint16 x, y; 372 sint16 x, y;
365 int flags; 373 int flags;
366 mapstruct *m; 374 maptile *m;
367 MoveType move_block; 375 MoveType move_block;
368 376
369 if (op->head) 377 if (op->head)
370 op = op->head; 378 op = op->head;
371 379
384 move_block = GET_MAP_MOVE_BLOCK (m, x, y); 392 move_block = GET_MAP_MOVE_BLOCK (m, x, y);
385 393
386 /* If the target space is not blocked, no need to look at the objects on it */ 394 /* If the target space is not blocked, no need to look at the objects on it */
387 if ((op->move_type & move_block) == op->move_type) 395 if ((op->move_type & move_block) == op->move_type)
388 { 396 {
389 for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = tmp->above) 397 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above)
390 { 398 {
391 if (tmp->head == op) 399 if (tmp->head == op)
392 continue; 400 continue;
393 if (OB_MOVE_BLOCK (op, tmp) && !roll_ob (tmp, dir, pusher)) 401 if (OB_MOVE_BLOCK (op, tmp) && !roll_ob (tmp, dir, pusher))
394 return 0; 402 return 0;
395 } 403 }
396 } 404 }
397 if (try_fit (op, m, x, y)) 405 if (try_fit (op, m, x, y))
398 return 0; 406 return 0;
399 407
400 remove_ob (op); 408 op->remove ();
401 for (tmp = op; tmp != NULL; tmp = tmp->more) 409 for (tmp = op; tmp != NULL; tmp = tmp->more)
402 tmp->x += freearr_x[dir], tmp->y += freearr_y[dir]; 410 tmp->x += freearr_x[dir], tmp->y += freearr_y[dir];
403 insert_ob_in_map (op, op->map, pusher, 0); 411 insert_ob_in_map (op, op->map, pusher, 0);
404 return 1; 412 return 1;
405} 413}
411 int str1, str2; 419 int str1, str2;
412 object *owner; 420 object *owner;
413 421
414 if (who->head != NULL) 422 if (who->head != NULL)
415 who = who->head; 423 who = who->head;
416 owner = get_owner (who); 424 owner = who->owner;
417 425
418 /* Wake up sleeping monsters that may be pushed */ 426 /* Wake up sleeping monsters that may be pushed */
419 CLEAR_FLAG (who, FLAG_SLEEP); 427 CLEAR_FLAG (who, FLAG_SLEEP);
420 428
421 /* player change place with his pets or summoned creature */ 429 /* player change place with his pets or summoned creature */
427 && owner == pusher 435 && owner == pusher
428#endif 436#endif
429 ) 437 )
430 { 438 {
431 int temp; 439 int temp;
432 mapstruct *m; 440 maptile *m;
433 441
434 remove_ob (who); 442 who->remove ();
435 remove_ob (pusher); 443 pusher->remove ();
436 temp = pusher->x; 444 temp = pusher->x;
437 pusher->x = who->x; 445 pusher->x = who->x;
438 who->x = temp; 446 who->x = temp;
439 447
440 temp = pusher->y; 448 temp = pusher->y;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines