1 | |
|
|
2 | /* |
1 | /* |
3 | * static char *rcsid_move_c = |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
4 | * "$Id: move.C,v 1.7 2006/09/10 15:59:57 root Exp $"; |
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
|
|
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
|
|
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
|
|
7 | * |
|
|
8 | * Deliantra 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 3 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, see <http://www.gnu.org/licenses/>. |
|
|
20 | * |
|
|
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
5 | */ |
22 | */ |
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 | |
23 | |
30 | #include <global.h> |
24 | #include <global.h> |
31 | #ifndef __CEXTRACT__ |
25 | #ifndef __CEXTRACT__ |
32 | # include <sproto.h> |
26 | # include <sproto.h> |
33 | #endif |
|
|
34 | |
|
|
35 | #ifdef COZY_SERVER |
|
|
36 | // use a ptotoype |
|
|
37 | extern int same_party (partylist *a, partylist *b); |
|
|
38 | #endif |
27 | #endif |
39 | |
28 | |
40 | /* |
29 | /* |
41 | * move_object() tries to move object op in the direction "dir". |
30 | * move_object() tries to move object op in the direction "dir". |
42 | * If it fails (something blocks the passage), it returns 0, |
31 | * If it fails (something blocks the passage), it returns 0, |
… | |
… | |
48 | int |
37 | int |
49 | move_object (object *op, int dir) |
38 | move_object (object *op, int dir) |
50 | { |
39 | { |
51 | return move_ob (op, dir, op); |
40 | return move_ob (op, dir, op); |
52 | } |
41 | } |
53 | |
|
|
54 | |
42 | |
55 | /* object op is trying to move in direction dir. |
43 | /* object op is trying to move in direction dir. |
56 | * originator is typically the same as op, but |
44 | * originator is typically the same as op, but |
57 | * can be different if originator is causing op to |
45 | * can be different if originator is causing op to |
58 | * move (originator is pushing op) |
46 | * move (originator is pushing op) |
… | |
… | |
65 | move_ob (object *op, int dir, object *originator) |
53 | move_ob (object *op, int dir, object *originator) |
66 | { |
54 | { |
67 | sint16 newx = op->x + freearr_x[dir]; |
55 | sint16 newx = op->x + freearr_x[dir]; |
68 | sint16 newy = op->y + freearr_y[dir]; |
56 | sint16 newy = op->y + freearr_y[dir]; |
69 | object *tmp; |
57 | object *tmp; |
70 | mapstruct *m; |
58 | maptile *m; |
71 | int mflags; |
59 | int mflags; |
72 | |
60 | |
73 | if (op == NULL) |
61 | if (op == NULL) |
74 | { |
62 | { |
75 | LOG (llevError, "Trying to move NULL.\n"); |
63 | LOG (llevError, "Trying to move NULL.\n"); |
… | |
… | |
82 | /* 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, |
83 | * bail now - we know it can't work. |
71 | * bail now - we know it can't work. |
84 | */ |
72 | */ |
85 | if (mflags & P_OUT_OF_MAP) |
73 | if (mflags & P_OUT_OF_MAP) |
86 | return 0; |
74 | return 0; |
87 | |
|
|
88 | |
75 | |
89 | /* Is this space blocked? Players with wizpass are immune to |
76 | /* Is this space blocked? Players with wizpass are immune to |
90 | * this condition. |
77 | * this condition. |
91 | */ |
78 | */ |
92 | if (blocked_link (op, m, newx, newy) && !QUERY_FLAG (op, FLAG_WIZPASS)) |
79 | if (blocked_link (op, m, newx, newy) && !QUERY_FLAG (op, FLAG_WIZPASS)) |
… | |
… | |
94 | |
81 | |
95 | /* 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. |
96 | * 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 |
97 | * breaking anything, but it might. |
84 | * breaking anything, but it might. |
98 | */ |
85 | */ |
99 | if (op->more != NULL && !move_ob (op->more, dir, op->more->head)) |
86 | if (op->more && !move_ob (op->more, dir, op->more->head)) |
100 | return 0; |
87 | return 0; |
101 | |
88 | |
102 | op->direction = dir; |
89 | op->direction = dir; |
103 | |
90 | |
104 | if (op->will_apply & 4) |
91 | if (op->will_apply & 4) |
105 | check_earthwalls (op, m, newx, newy); |
92 | check_earthwalls (op, m, newx, newy); |
|
|
93 | |
106 | if (op->will_apply & 8) |
94 | if (op->will_apply & 8) |
107 | check_doors (op, m, newx, newy); |
95 | check_doors (op, m, newx, newy); |
108 | |
96 | |
109 | /* 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 |
110 | * 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 |
… | |
… | |
127 | * ok - the caller will deal with actual object removal/insertion |
115 | * ok - the caller will deal with actual object removal/insertion |
128 | */ |
116 | */ |
129 | if (op->head) |
117 | if (op->head) |
130 | return 1; |
118 | return 1; |
131 | |
119 | |
132 | remove_ob (op); |
120 | if (m != op->map && op->contr) |
|
|
121 | { |
|
|
122 | if (INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr))) |
|
|
123 | return 0; |
|
|
124 | |
|
|
125 | op->remove (); |
|
|
126 | |
|
|
127 | if (INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (m), ARG_INT (newx), ARG_INT (newy))) |
|
|
128 | return 0; |
|
|
129 | |
|
|
130 | if (INVOKE_MAP (ENTER, m, ARG_PLAYER (op->contr), ARG_INT (newx), ARG_INT (newy))) |
|
|
131 | return 0; |
|
|
132 | } |
|
|
133 | else |
|
|
134 | op->remove (); |
133 | |
135 | |
134 | /* we already have newx, newy, and m, so lets use them. |
136 | /* we already have newx, newy, and m, so lets use them. |
135 | * In addition, this fixes potential crashes, because multipart object was |
137 | * In addition, this fixes potential crashes, because multipart object was |
136 | * on edge of map, +=x, +=y doesn't make correct coordinates. |
138 | * on edge of map, +=x, +=y doesn't make correct coordinates. |
137 | */ |
139 | */ |
… | |
… | |
175 | if (i == -1) |
177 | if (i == -1) |
176 | return 0; /* No free spot */ |
178 | return 0; /* No free spot */ |
177 | |
179 | |
178 | if (op->head != NULL) |
180 | if (op->head != NULL) |
179 | op = op->head; |
181 | op = op->head; |
180 | remove_ob (op); |
182 | op->remove (); |
181 | for (tmp = op; tmp != NULL; tmp = tmp->more) |
183 | for (tmp = op; tmp != NULL; tmp = tmp->more) |
182 | tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x), |
184 | tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->x), |
183 | tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); |
185 | tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->y); |
184 | |
186 | |
185 | tmp = insert_ob_in_map (op, op->map, originator, 0); |
187 | tmp = insert_ob_in_map (op, op->map, originator, 0); |
186 | if (tmp) |
188 | if (tmp) |
187 | return 0; |
189 | return 0; |
188 | else |
190 | else |
… | |
… | |
205 | teleport (object *teleporter, uint8 tele_type, object *user) |
207 | teleport (object *teleporter, uint8 tele_type, object *user) |
206 | { |
208 | { |
207 | object *altern; |
209 | object *altern; |
208 | int i, j, k, nrofalt = 0; |
210 | int i, j, k, nrofalt = 0; |
209 | object *other_teleporter, *tmp; |
211 | object *other_teleporter, *tmp; |
210 | mapstruct *m; |
212 | maptile *m; |
211 | sint16 sx, sy; |
213 | sint16 sx, sy; |
212 | |
214 | |
213 | if (user == NULL) |
215 | if (user == NULL) |
214 | return 0; |
216 | return 0; |
215 | if (user->head != NULL) |
217 | if (user->head != NULL) |
… | |
… | |
225 | if (i == 0 && j == 0) |
227 | if (i == 0 && j == 0) |
226 | continue; |
228 | continue; |
227 | /* Perhaps this should be extended to support tiled maps */ |
229 | /* Perhaps this should be extended to support tiled maps */ |
228 | if (OUT_OF_REAL_MAP (teleporter->map, teleporter->x + i, teleporter->y + j)) |
230 | if (OUT_OF_REAL_MAP (teleporter->map, teleporter->x + i, teleporter->y + j)) |
229 | continue; |
231 | continue; |
230 | other_teleporter = get_map_ob (teleporter->map, teleporter->x + i, teleporter->y + j); |
232 | other_teleporter = GET_MAP_OB (teleporter->map, teleporter->x + i, teleporter->y + j); |
231 | |
233 | |
232 | while (other_teleporter) |
234 | while (other_teleporter) |
233 | { |
235 | { |
234 | if (other_teleporter->type == tele_type) |
236 | if (other_teleporter->type == tele_type) |
235 | break; |
237 | break; |
… | |
… | |
278 | } |
280 | } |
279 | else |
281 | else |
280 | return 0; |
282 | return 0; |
281 | } |
283 | } |
282 | |
284 | |
283 | remove_ob (user); |
285 | user->remove (); |
284 | |
286 | |
285 | /* Update location for the object */ |
287 | /* Update location for the object */ |
286 | for (tmp = user; tmp != NULL; tmp = tmp->more) |
288 | for (tmp = user; tmp != NULL; tmp = tmp->more) |
287 | { |
289 | { |
288 | tmp->x = other_teleporter->x + freearr_x[k] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x); |
290 | tmp->x = other_teleporter->x + freearr_x[k] + (tmp->arch == NULL ? 0 : tmp->arch->x); |
289 | tmp->y = other_teleporter->y + freearr_y[k] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); |
291 | tmp->y = other_teleporter->y + freearr_y[k] + (tmp->arch == NULL ? 0 : tmp->arch->y); |
290 | } |
292 | } |
291 | tmp = insert_ob_in_map (user, other_teleporter->map, NULL, 0); |
293 | tmp = insert_ob_in_map (user, other_teleporter->map, NULL, 0); |
292 | return (tmp == NULL); |
294 | return (tmp == NULL); |
293 | } |
295 | } |
294 | |
296 | |
… | |
… | |
313 | * This is currently only used for the boulder roll code. |
315 | * This is currently only used for the boulder roll code. |
314 | * Returns 1 if object does not fit, 0 if it does. |
316 | * Returns 1 if object does not fit, 0 if it does. |
315 | */ |
317 | */ |
316 | |
318 | |
317 | int |
319 | int |
318 | try_fit (object *op, mapstruct *m, int x, int y) |
320 | try_fit (object *op, maptile *m, int x, int y) |
319 | { |
321 | { |
320 | object *tmp, *more; |
322 | object *tmp, *more; |
321 | sint16 tx, ty; |
323 | sint16 tx, ty; |
322 | int mflags; |
324 | int mflags; |
323 | mapstruct *m2; |
325 | maptile *m2; |
324 | |
326 | |
325 | if (op->head) |
327 | if (op->head) |
326 | op = op->head; |
328 | op = op->head; |
327 | |
329 | |
328 | for (more = op; more; more = more->more) |
330 | for (more = op; more; more = more->more) |
… | |
… | |
333 | mflags = get_map_flags (m, &m2, tx, ty, &tx, &ty); |
335 | mflags = get_map_flags (m, &m2, tx, ty, &tx, &ty); |
334 | |
336 | |
335 | if (mflags & P_OUT_OF_MAP) |
337 | if (mflags & P_OUT_OF_MAP) |
336 | return 1; |
338 | return 1; |
337 | |
339 | |
338 | for (tmp = get_map_ob (m2, tx, ty); tmp; tmp = tmp->above) |
340 | for (tmp = GET_MAP_OB (m2, tx, ty); tmp; tmp = tmp->above) |
339 | { |
341 | { |
340 | if (tmp->head == op || tmp == op) |
342 | if (tmp->head == op || tmp == op) |
341 | continue; |
343 | continue; |
342 | |
344 | |
343 | if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->type != DOOR)) |
345 | if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->type != DOOR)) |
… | |
… | |
361 | roll_ob (object *op, int dir, object *pusher) |
363 | roll_ob (object *op, int dir, object *pusher) |
362 | { |
364 | { |
363 | object *tmp; |
365 | object *tmp; |
364 | sint16 x, y; |
366 | sint16 x, y; |
365 | int flags; |
367 | int flags; |
366 | mapstruct *m; |
368 | maptile *m; |
367 | MoveType move_block; |
369 | MoveType move_block; |
368 | |
370 | |
369 | if (op->head) |
371 | if (op->head) |
370 | op = op->head; |
372 | op = op->head; |
371 | |
373 | |
… | |
… | |
384 | move_block = GET_MAP_MOVE_BLOCK (m, x, y); |
386 | move_block = GET_MAP_MOVE_BLOCK (m, x, y); |
385 | |
387 | |
386 | /* If the target space is not blocked, no need to look at the objects on it */ |
388 | /* 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) |
389 | if ((op->move_type & move_block) == op->move_type) |
388 | { |
390 | { |
389 | for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = tmp->above) |
391 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
390 | { |
392 | { |
391 | if (tmp->head == op) |
393 | if (tmp->head == op) |
392 | continue; |
394 | continue; |
393 | if (OB_MOVE_BLOCK (op, tmp) && !roll_ob (tmp, dir, pusher)) |
395 | if (OB_MOVE_BLOCK (op, tmp) && !roll_ob (tmp, dir, pusher)) |
394 | return 0; |
396 | return 0; |
395 | } |
397 | } |
396 | } |
398 | } |
397 | if (try_fit (op, m, x, y)) |
399 | if (try_fit (op, m, x, y)) |
398 | return 0; |
400 | return 0; |
399 | |
401 | |
400 | remove_ob (op); |
402 | op->remove (); |
401 | for (tmp = op; tmp != NULL; tmp = tmp->more) |
403 | for (tmp = op; tmp != NULL; tmp = tmp->more) |
402 | tmp->x += freearr_x[dir], tmp->y += freearr_y[dir]; |
404 | tmp->x += freearr_x[dir], tmp->y += freearr_y[dir]; |
403 | insert_ob_in_map (op, op->map, pusher, 0); |
405 | insert_ob_in_map (op, op->map, pusher, 0); |
404 | return 1; |
406 | return 1; |
405 | } |
407 | } |
… | |
… | |
411 | int str1, str2; |
413 | int str1, str2; |
412 | object *owner; |
414 | object *owner; |
413 | |
415 | |
414 | if (who->head != NULL) |
416 | if (who->head != NULL) |
415 | who = who->head; |
417 | who = who->head; |
416 | owner = get_owner (who); |
418 | owner = who->owner; |
417 | |
419 | |
418 | /* Wake up sleeping monsters that may be pushed */ |
420 | /* Wake up sleeping monsters that may be pushed */ |
419 | CLEAR_FLAG (who, FLAG_SLEEP); |
421 | CLEAR_FLAG (who, FLAG_SLEEP); |
420 | |
422 | |
421 | /* player change place with his pets or summoned creature */ |
423 | /* player change place with his pets or summoned creature */ |
422 | /* TODO: allow multi arch pushing. Can't be very difficult */ |
424 | /* TODO: allow multi arch pushing. Can't be very difficult */ |
423 | if (who->more == NULL |
425 | if (who->more == NULL |
424 | #ifdef COZY_SERVER |
|
|
425 | && ((owner && owner->contr && pusher->contr && same_party (owner->contr->party, pusher->contr->party)) || owner == pusher) |
426 | && ((owner && owner->contr && pusher->contr && same_party (owner->contr->party, pusher->contr->party)) |
426 | #else |
|
|
427 | && owner == pusher |
427 | || owner == pusher) |
428 | #endif |
|
|
429 | ) |
428 | ) |
430 | { |
429 | { |
431 | int temp; |
430 | int temp; |
432 | mapstruct *m; |
431 | maptile *m; |
433 | |
432 | |
434 | remove_ob (who); |
433 | who->remove (); |
435 | remove_ob (pusher); |
434 | pusher->remove (); |
436 | temp = pusher->x; |
435 | temp = pusher->x; |
437 | pusher->x = who->x; |
436 | pusher->x = who->x; |
438 | who->x = temp; |
437 | who->x = temp; |
439 | |
438 | |
440 | temp = pusher->y; |
439 | temp = pusher->y; |
… | |
… | |
447 | |
446 | |
448 | insert_ob_in_map (who, who->map, pusher, 0); |
447 | insert_ob_in_map (who, who->map, pusher, 0); |
449 | insert_ob_in_map (pusher, pusher->map, pusher, 0); |
448 | insert_ob_in_map (pusher, pusher->map, pusher, 0); |
450 | return 0; |
449 | return 0; |
451 | } |
450 | } |
452 | |
|
|
453 | |
451 | |
454 | /* We want ONLY become enemy of evil, unaggressive monster. We must RUN in them */ |
452 | /* We want ONLY become enemy of evil, unaggressive monster. We must RUN in them */ |
455 | /* In original we have here a unaggressive check only - that was the reason why */ |
453 | /* In original we have here a unaggressive check only - that was the reason why */ |
456 | /* we so often become an enemy of friendly monsters... */ |
454 | /* we so often become an enemy of friendly monsters... */ |
457 | /* funny: was they set to unaggressive 0 (= not so nice) they don't attack */ |
455 | /* funny: was they set to unaggressive 0 (= not so nice) they don't attack */ |
458 | |
|
|
459 | if (owner != pusher && pusher->type == PLAYER && who->type != PLAYER && |
456 | if (owner != pusher && pusher->type == PLAYER && who->type != PLAYER && |
460 | !QUERY_FLAG (who, FLAG_FRIENDLY) && !QUERY_FLAG (who, FLAG_NEUTRAL)) |
457 | !QUERY_FLAG (who, FLAG_FRIENDLY) && !QUERY_FLAG (who, FLAG_NEUTRAL)) |
461 | { |
458 | { |
462 | if (pusher->contr->run_on) /* only when we run */ |
459 | if (pusher->contr->run_on) /* only when we run */ |
463 | { |
460 | { |
464 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You start to attack %s !!", &who->name); |
461 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You start to attack %s!!", &who->name); |
465 | CLEAR_FLAG (who, FLAG_UNAGGRESSIVE); /* the sucker don't like you anymore */ |
462 | CLEAR_FLAG (who, FLAG_UNAGGRESSIVE); /* the sucker don't like you anymore */ |
466 | who->enemy = pusher; |
463 | who->enemy = pusher; |
467 | return 1; |
464 | return 1; |
468 | } |
465 | } |
469 | else |
466 | else |
470 | { |
|
|
471 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You avoid attacking %s.", &who->name); |
467 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You avoid attacking %s.", &who->name); |
472 | } |
|
|
473 | } |
468 | } |
474 | |
469 | |
475 | /* now, lets test stand still. we NEVER can push stand_still monsters. */ |
470 | /* now, lets test stand still. we NEVER can push stand_still monsters. */ |
476 | if (QUERY_FLAG (who, FLAG_STAND_STILL)) |
471 | if (QUERY_FLAG (who, FLAG_STAND_STILL)) |
477 | { |
472 | { |
… | |
… | |
487 | */ |
482 | */ |
488 | |
483 | |
489 | str1 = (who->stats.Str > 0 ? who->stats.Str : who->level); |
484 | str1 = (who->stats.Str > 0 ? who->stats.Str : who->level); |
490 | str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level); |
485 | str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level); |
491 | if (QUERY_FLAG (who, FLAG_WIZ) || |
486 | if (QUERY_FLAG (who, FLAG_WIZ) || |
492 | random_roll (str1, str1 / 2 + str1 * 2, who, PREFER_HIGH) >= |
487 | random_roll (str1, str1 * 5 / 2, who, PREFER_HIGH) >= |
493 | random_roll (str2, str2 / 2 + str2 * 2, pusher, PREFER_HIGH) || !move_object (who, dir)) |
488 | random_roll (str2, str2 * 5 / 2, pusher, PREFER_HIGH) || !move_object (who, dir)) |
494 | { |
489 | { |
495 | if (who->type == PLAYER) |
490 | if (who->type == PLAYER) |
496 | { |
|
|
497 | new_draw_info_format (NDI_UNIQUE, 0, who, "%s tried to push you.", &pusher->name); |
491 | new_draw_info_format (NDI_UNIQUE, 0, who, "%s tried to push you.", &pusher->name); |
498 | } |
492 | |
499 | return 0; |
493 | return 0; |
500 | } |
494 | } |
501 | |
495 | |
502 | /* If we get here, the push succeeded. |
496 | /* If we get here, the push succeeded. |
503 | * Let everyone know the status. |
497 | * Let everyone know the status. |