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> |
… | |
… | |
65 | move_ob (object *op, int dir, object *originator) |
59 | move_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 | op->remove (); |
133 | |
127 | |
134 | /* we already have newx, newy, and m, so lets use them. |
128 | /* we already have newx, newy, and m, so lets use them. |
135 | * In addition, this fixes potential crashes, because multipart object was |
129 | * In addition, this fixes potential crashes, because multipart object was |
136 | * on edge of map, +=x, +=y doesn't make correct coordinates. |
130 | * on edge of map, +=x, +=y doesn't make correct coordinates. |
137 | */ |
131 | */ |
… | |
… | |
175 | if (i == -1) |
169 | if (i == -1) |
176 | return 0; /* No free spot */ |
170 | return 0; /* No free spot */ |
177 | |
171 | |
178 | if (op->head != NULL) |
172 | if (op->head != NULL) |
179 | op = op->head; |
173 | op = op->head; |
180 | remove_ob (op); |
174 | op->remove (); |
181 | for (tmp = op; tmp != NULL; tmp = tmp->more) |
175 | for (tmp = op; tmp != NULL; tmp = tmp->more) |
182 | tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x), |
176 | 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); |
177 | tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); |
184 | |
178 | |
185 | tmp = insert_ob_in_map (op, op->map, originator, 0); |
179 | tmp = insert_ob_in_map (op, op->map, originator, 0); |
… | |
… | |
205 | teleport (object *teleporter, uint8 tele_type, object *user) |
199 | teleport (object *teleporter, uint8 tele_type, object *user) |
206 | { |
200 | { |
207 | object *altern; |
201 | object *altern; |
208 | int i, j, k, nrofalt = 0; |
202 | int i, j, k, nrofalt = 0; |
209 | object *other_teleporter, *tmp; |
203 | object *other_teleporter, *tmp; |
210 | mapstruct *m; |
204 | maptile *m; |
211 | sint16 sx, sy; |
205 | sint16 sx, sy; |
212 | |
206 | |
213 | if (user == NULL) |
207 | if (user == NULL) |
214 | return 0; |
208 | return 0; |
215 | if (user->head != NULL) |
209 | if (user->head != NULL) |
… | |
… | |
225 | if (i == 0 && j == 0) |
219 | if (i == 0 && j == 0) |
226 | continue; |
220 | continue; |
227 | /* Perhaps this should be extended to support tiled maps */ |
221 | /* Perhaps this should be extended to support tiled maps */ |
228 | if (OUT_OF_REAL_MAP (teleporter->map, teleporter->x + i, teleporter->y + j)) |
222 | if (OUT_OF_REAL_MAP (teleporter->map, teleporter->x + i, teleporter->y + j)) |
229 | continue; |
223 | continue; |
230 | other_teleporter = get_map_ob (teleporter->map, teleporter->x + i, teleporter->y + j); |
224 | other_teleporter = GET_MAP_OB (teleporter->map, teleporter->x + i, teleporter->y + j); |
231 | |
225 | |
232 | while (other_teleporter) |
226 | while (other_teleporter) |
233 | { |
227 | { |
234 | if (other_teleporter->type == tele_type) |
228 | if (other_teleporter->type == tele_type) |
235 | break; |
229 | break; |
… | |
… | |
278 | } |
272 | } |
279 | else |
273 | else |
280 | return 0; |
274 | return 0; |
281 | } |
275 | } |
282 | |
276 | |
283 | remove_ob (user); |
277 | user->remove (); |
284 | |
278 | |
285 | /* Update location for the object */ |
279 | /* Update location for the object */ |
286 | for (tmp = user; tmp != NULL; tmp = tmp->more) |
280 | for (tmp = user; tmp != NULL; tmp = tmp->more) |
287 | { |
281 | { |
288 | tmp->x = other_teleporter->x + freearr_x[k] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x); |
282 | 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. |
307 | * This is currently only used for the boulder roll code. |
314 | * Returns 1 if object does not fit, 0 if it does. |
308 | * Returns 1 if object does not fit, 0 if it does. |
315 | */ |
309 | */ |
316 | |
310 | |
317 | int |
311 | int |
318 | try_fit (object *op, mapstruct *m, int x, int y) |
312 | try_fit (object *op, maptile *m, int x, int y) |
319 | { |
313 | { |
320 | object *tmp, *more; |
314 | object *tmp, *more; |
321 | sint16 tx, ty; |
315 | sint16 tx, ty; |
322 | int mflags; |
316 | int mflags; |
323 | mapstruct *m2; |
317 | maptile *m2; |
324 | |
318 | |
325 | if (op->head) |
319 | if (op->head) |
326 | op = op->head; |
320 | op = op->head; |
327 | |
321 | |
328 | for (more = op; more; more = more->more) |
322 | for (more = op; more; more = more->more) |
… | |
… | |
333 | mflags = get_map_flags (m, &m2, tx, ty, &tx, &ty); |
327 | mflags = get_map_flags (m, &m2, tx, ty, &tx, &ty); |
334 | |
328 | |
335 | if (mflags & P_OUT_OF_MAP) |
329 | if (mflags & P_OUT_OF_MAP) |
336 | return 1; |
330 | return 1; |
337 | |
331 | |
338 | for (tmp = get_map_ob (m2, tx, ty); tmp; tmp = tmp->above) |
332 | for (tmp = GET_MAP_OB (m2, tx, ty); tmp; tmp = tmp->above) |
339 | { |
333 | { |
340 | if (tmp->head == op || tmp == op) |
334 | if (tmp->head == op || tmp == op) |
341 | continue; |
335 | continue; |
342 | |
336 | |
343 | if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->type != DOOR)) |
337 | if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->type != DOOR)) |
… | |
… | |
361 | roll_ob (object *op, int dir, object *pusher) |
355 | roll_ob (object *op, int dir, object *pusher) |
362 | { |
356 | { |
363 | object *tmp; |
357 | object *tmp; |
364 | sint16 x, y; |
358 | sint16 x, y; |
365 | int flags; |
359 | int flags; |
366 | mapstruct *m; |
360 | maptile *m; |
367 | MoveType move_block; |
361 | MoveType move_block; |
368 | |
362 | |
369 | if (op->head) |
363 | if (op->head) |
370 | op = op->head; |
364 | op = op->head; |
371 | |
365 | |
… | |
… | |
384 | move_block = GET_MAP_MOVE_BLOCK (m, x, y); |
378 | move_block = GET_MAP_MOVE_BLOCK (m, x, y); |
385 | |
379 | |
386 | /* If the target space is not blocked, no need to look at the objects on it */ |
380 | /* 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) |
381 | if ((op->move_type & move_block) == op->move_type) |
388 | { |
382 | { |
389 | for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = tmp->above) |
383 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
390 | { |
384 | { |
391 | if (tmp->head == op) |
385 | if (tmp->head == op) |
392 | continue; |
386 | continue; |
393 | if (OB_MOVE_BLOCK (op, tmp) && !roll_ob (tmp, dir, pusher)) |
387 | if (OB_MOVE_BLOCK (op, tmp) && !roll_ob (tmp, dir, pusher)) |
394 | return 0; |
388 | return 0; |
395 | } |
389 | } |
396 | } |
390 | } |
397 | if (try_fit (op, m, x, y)) |
391 | if (try_fit (op, m, x, y)) |
398 | return 0; |
392 | return 0; |
399 | |
393 | |
400 | remove_ob (op); |
394 | op->remove (); |
401 | for (tmp = op; tmp != NULL; tmp = tmp->more) |
395 | for (tmp = op; tmp != NULL; tmp = tmp->more) |
402 | tmp->x += freearr_x[dir], tmp->y += freearr_y[dir]; |
396 | tmp->x += freearr_x[dir], tmp->y += freearr_y[dir]; |
403 | insert_ob_in_map (op, op->map, pusher, 0); |
397 | insert_ob_in_map (op, op->map, pusher, 0); |
404 | return 1; |
398 | return 1; |
405 | } |
399 | } |
… | |
… | |
411 | int str1, str2; |
405 | int str1, str2; |
412 | object *owner; |
406 | object *owner; |
413 | |
407 | |
414 | if (who->head != NULL) |
408 | if (who->head != NULL) |
415 | who = who->head; |
409 | who = who->head; |
416 | owner = get_owner (who); |
410 | owner = who->owner; |
417 | |
411 | |
418 | /* Wake up sleeping monsters that may be pushed */ |
412 | /* Wake up sleeping monsters that may be pushed */ |
419 | CLEAR_FLAG (who, FLAG_SLEEP); |
413 | CLEAR_FLAG (who, FLAG_SLEEP); |
420 | |
414 | |
421 | /* player change place with his pets or summoned creature */ |
415 | /* player change place with his pets or summoned creature */ |
… | |
… | |
427 | && owner == pusher |
421 | && owner == pusher |
428 | #endif |
422 | #endif |
429 | ) |
423 | ) |
430 | { |
424 | { |
431 | int temp; |
425 | int temp; |
432 | mapstruct *m; |
426 | maptile *m; |
433 | |
427 | |
434 | remove_ob (who); |
428 | who->remove (); |
435 | remove_ob (pusher); |
429 | pusher->remove (); |
436 | temp = pusher->x; |
430 | temp = pusher->x; |
437 | pusher->x = who->x; |
431 | pusher->x = who->x; |
438 | who->x = temp; |
432 | who->x = temp; |
439 | |
433 | |
440 | temp = pusher->y; |
434 | temp = pusher->y; |