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.15 by pippijn, Mon Jan 15 21:06:20 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines