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.8 by root, Thu Sep 14 22:34:04 2006 UTC vs.
Revision 1.15 by pippijn, Mon Jan 15 21:06:20 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
3 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 21 *
21 The author can be reached via e-mail to <crossfire@schmorp.de> 22 * The author can be reached via e-mail to <crossfire@schmorp.de>
22*/ 23 */
23 24
24#include <global.h> 25#include <global.h>
25#ifndef __CEXTRACT__ 26#ifndef __CEXTRACT__
26# include <sproto.h> 27# include <sproto.h>
27#endif 28#endif
59move_ob (object *op, int dir, object *originator) 60move_ob (object *op, int dir, object *originator)
60{ 61{
61 sint16 newx = op->x + freearr_x[dir]; 62 sint16 newx = op->x + freearr_x[dir];
62 sint16 newy = op->y + freearr_y[dir]; 63 sint16 newy = op->y + freearr_y[dir];
63 object *tmp; 64 object *tmp;
64 mapstruct *m; 65 maptile *m;
65 int mflags; 66 int mflags;
66 67
67 if (op == NULL) 68 if (op == NULL)
68 { 69 {
69 LOG (llevError, "Trying to move NULL.\n"); 70 LOG (llevError, "Trying to move NULL.\n");
76 /* 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,
77 * bail now - we know it can't work. 78 * bail now - we know it can't work.
78 */ 79 */
79 if (mflags & P_OUT_OF_MAP) 80 if (mflags & P_OUT_OF_MAP)
80 return 0; 81 return 0;
81
82 82
83 /* Is this space blocked? Players with wizpass are immune to 83 /* Is this space blocked? Players with wizpass are immune to
84 * this condition. 84 * this condition.
85 */ 85 */
86 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))
88 88
89 /* 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.
90 * 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
91 * breaking anything, but it might. 91 * breaking anything, but it might.
92 */ 92 */
93 if (op->more != NULL && !move_ob (op->more, dir, op->more->head)) 93 if (op->more && !move_ob (op->more, dir, op->more->head))
94 return 0; 94 return 0;
95 95
96 op->direction = dir; 96 op->direction = dir;
97 97
98 if (op->will_apply & 4) 98 if (op->will_apply & 4)
99 check_earthwalls (op, m, newx, newy); 99 check_earthwalls (op, m, newx, newy);
100
100 if (op->will_apply & 8) 101 if (op->will_apply & 8)
101 check_doors (op, m, newx, newy); 102 check_doors (op, m, newx, newy);
102 103
103 /* 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
104 * 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
121 * ok - the caller will deal with actual object removal/insertion 122 * ok - the caller will deal with actual object removal/insertion
122 */ 123 */
123 if (op->head) 124 if (op->head)
124 return 1; 125 return 1;
125 126
126 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 ();
127 142
128 /* we already have newx, newy, and m, so lets use them. 143 /* we already have newx, newy, and m, so lets use them.
129 * In addition, this fixes potential crashes, because multipart object was 144 * In addition, this fixes potential crashes, because multipart object was
130 * on edge of map, +=x, +=y doesn't make correct coordinates. 145 * on edge of map, +=x, +=y doesn't make correct coordinates.
131 */ 146 */
169 if (i == -1) 184 if (i == -1)
170 return 0; /* No free spot */ 185 return 0; /* No free spot */
171 186
172 if (op->head != NULL) 187 if (op->head != NULL)
173 op = op->head; 188 op = op->head;
174 remove_ob (op); 189 op->remove ();
175 for (tmp = op; tmp != NULL; tmp = tmp->more) 190 for (tmp = op; tmp != NULL; tmp = tmp->more)
176 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),
177 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);
178 193
179 tmp = insert_ob_in_map (op, op->map, originator, 0); 194 tmp = insert_ob_in_map (op, op->map, originator, 0);
199teleport (object *teleporter, uint8 tele_type, object *user) 214teleport (object *teleporter, uint8 tele_type, object *user)
200{ 215{
201 object *altern; 216 object *altern;
202 int i, j, k, nrofalt = 0; 217 int i, j, k, nrofalt = 0;
203 object *other_teleporter, *tmp; 218 object *other_teleporter, *tmp;
204 mapstruct *m; 219 maptile *m;
205 sint16 sx, sy; 220 sint16 sx, sy;
206 221
207 if (user == NULL) 222 if (user == NULL)
208 return 0; 223 return 0;
209 if (user->head != NULL) 224 if (user->head != NULL)
219 if (i == 0 && j == 0) 234 if (i == 0 && j == 0)
220 continue; 235 continue;
221 /* Perhaps this should be extended to support tiled maps */ 236 /* Perhaps this should be extended to support tiled maps */
222 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))
223 continue; 238 continue;
224 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);
225 240
226 while (other_teleporter) 241 while (other_teleporter)
227 { 242 {
228 if (other_teleporter->type == tele_type) 243 if (other_teleporter->type == tele_type)
229 break; 244 break;
272 } 287 }
273 else 288 else
274 return 0; 289 return 0;
275 } 290 }
276 291
277 remove_ob (user); 292 user->remove ();
278 293
279 /* Update location for the object */ 294 /* Update location for the object */
280 for (tmp = user; tmp != NULL; tmp = tmp->more) 295 for (tmp = user; tmp != NULL; tmp = tmp->more)
281 { 296 {
282 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);
307 * This is currently only used for the boulder roll code. 322 * This is currently only used for the boulder roll code.
308 * Returns 1 if object does not fit, 0 if it does. 323 * Returns 1 if object does not fit, 0 if it does.
309 */ 324 */
310 325
311int 326int
312try_fit (object *op, mapstruct *m, int x, int y) 327try_fit (object *op, maptile *m, int x, int y)
313{ 328{
314 object *tmp, *more; 329 object *tmp, *more;
315 sint16 tx, ty; 330 sint16 tx, ty;
316 int mflags; 331 int mflags;
317 mapstruct *m2; 332 maptile *m2;
318 333
319 if (op->head) 334 if (op->head)
320 op = op->head; 335 op = op->head;
321 336
322 for (more = op; more; more = more->more) 337 for (more = op; more; more = more->more)
327 mflags = get_map_flags (m, &m2, tx, ty, &tx, &ty); 342 mflags = get_map_flags (m, &m2, tx, ty, &tx, &ty);
328 343
329 if (mflags & P_OUT_OF_MAP) 344 if (mflags & P_OUT_OF_MAP)
330 return 1; 345 return 1;
331 346
332 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)
333 { 348 {
334 if (tmp->head == op || tmp == op) 349 if (tmp->head == op || tmp == op)
335 continue; 350 continue;
336 351
337 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->type != DOOR)) 352 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->type != DOOR))
355roll_ob (object *op, int dir, object *pusher) 370roll_ob (object *op, int dir, object *pusher)
356{ 371{
357 object *tmp; 372 object *tmp;
358 sint16 x, y; 373 sint16 x, y;
359 int flags; 374 int flags;
360 mapstruct *m; 375 maptile *m;
361 MoveType move_block; 376 MoveType move_block;
362 377
363 if (op->head) 378 if (op->head)
364 op = op->head; 379 op = op->head;
365 380
378 move_block = GET_MAP_MOVE_BLOCK (m, x, y); 393 move_block = GET_MAP_MOVE_BLOCK (m, x, y);
379 394
380 /* 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 */
381 if ((op->move_type & move_block) == op->move_type) 396 if ((op->move_type & move_block) == op->move_type)
382 { 397 {
383 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)
384 { 399 {
385 if (tmp->head == op) 400 if (tmp->head == op)
386 continue; 401 continue;
387 if (OB_MOVE_BLOCK (op, tmp) && !roll_ob (tmp, dir, pusher)) 402 if (OB_MOVE_BLOCK (op, tmp) && !roll_ob (tmp, dir, pusher))
388 return 0; 403 return 0;
389 } 404 }
390 } 405 }
391 if (try_fit (op, m, x, y)) 406 if (try_fit (op, m, x, y))
392 return 0; 407 return 0;
393 408
394 remove_ob (op); 409 op->remove ();
395 for (tmp = op; tmp != NULL; tmp = tmp->more) 410 for (tmp = op; tmp != NULL; tmp = tmp->more)
396 tmp->x += freearr_x[dir], tmp->y += freearr_y[dir]; 411 tmp->x += freearr_x[dir], tmp->y += freearr_y[dir];
397 insert_ob_in_map (op, op->map, pusher, 0); 412 insert_ob_in_map (op, op->map, pusher, 0);
398 return 1; 413 return 1;
399} 414}
405 int str1, str2; 420 int str1, str2;
406 object *owner; 421 object *owner;
407 422
408 if (who->head != NULL) 423 if (who->head != NULL)
409 who = who->head; 424 who = who->head;
410 owner = get_owner (who); 425 owner = who->owner;
411 426
412 /* Wake up sleeping monsters that may be pushed */ 427 /* Wake up sleeping monsters that may be pushed */
413 CLEAR_FLAG (who, FLAG_SLEEP); 428 CLEAR_FLAG (who, FLAG_SLEEP);
414 429
415 /* player change place with his pets or summoned creature */ 430 /* player change place with his pets or summoned creature */
421 && owner == pusher 436 && owner == pusher
422#endif 437#endif
423 ) 438 )
424 { 439 {
425 int temp; 440 int temp;
426 mapstruct *m; 441 maptile *m;
427 442
428 remove_ob (who); 443 who->remove ();
429 remove_ob (pusher); 444 pusher->remove ();
430 temp = pusher->x; 445 temp = pusher->x;
431 pusher->x = who->x; 446 pusher->x = who->x;
432 who->x = temp; 447 who->x = temp;
433 448
434 temp = pusher->y; 449 temp = pusher->y;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines