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 |
… | |
… | |
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)) |
87 | return 0; |
87 | return 0; |
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 | |
|
|
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 |
126 | op->remove (); |
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 | */ |
… | |
… | |
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; |
… | |
… | |
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)) |
… | |
… | |
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; |
… | |
… | |
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 */ |
… | |
… | |
442 | insert_ob_in_map (who, who->map, pusher, 0); |
457 | insert_ob_in_map (who, who->map, pusher, 0); |
443 | insert_ob_in_map (pusher, pusher->map, pusher, 0); |
458 | insert_ob_in_map (pusher, pusher->map, pusher, 0); |
444 | return 0; |
459 | return 0; |
445 | } |
460 | } |
446 | |
461 | |
447 | |
|
|
448 | /* We want ONLY become enemy of evil, unaggressive monster. We must RUN in them */ |
462 | /* We want ONLY become enemy of evil, unaggressive monster. We must RUN in them */ |
449 | /* In original we have here a unaggressive check only - that was the reason why */ |
463 | /* In original we have here a unaggressive check only - that was the reason why */ |
450 | /* we so often become an enemy of friendly monsters... */ |
464 | /* we so often become an enemy of friendly monsters... */ |
451 | /* funny: was they set to unaggressive 0 (= not so nice) they don't attack */ |
465 | /* funny: was they set to unaggressive 0 (= not so nice) they don't attack */ |
452 | |
|
|
453 | if (owner != pusher && pusher->type == PLAYER && who->type != PLAYER && |
466 | if (owner != pusher && pusher->type == PLAYER && who->type != PLAYER && |
454 | !QUERY_FLAG (who, FLAG_FRIENDLY) && !QUERY_FLAG (who, FLAG_NEUTRAL)) |
467 | !QUERY_FLAG (who, FLAG_FRIENDLY) && !QUERY_FLAG (who, FLAG_NEUTRAL)) |
455 | { |
468 | { |
456 | if (pusher->contr->run_on) /* only when we run */ |
469 | if (pusher->contr->run_on) /* only when we run */ |
457 | { |
470 | { |
458 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You start to attack %s !!", &who->name); |
471 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You start to attack %s!!", &who->name); |
459 | CLEAR_FLAG (who, FLAG_UNAGGRESSIVE); /* the sucker don't like you anymore */ |
472 | CLEAR_FLAG (who, FLAG_UNAGGRESSIVE); /* the sucker don't like you anymore */ |
460 | who->enemy = pusher; |
473 | who->enemy = pusher; |
461 | return 1; |
474 | return 1; |
462 | } |
475 | } |
463 | else |
476 | else |
464 | { |
|
|
465 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You avoid attacking %s.", &who->name); |
477 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You avoid attacking %s.", &who->name); |
466 | } |
|
|
467 | } |
478 | } |
468 | |
479 | |
469 | /* now, lets test stand still. we NEVER can push stand_still monsters. */ |
480 | /* now, lets test stand still. we NEVER can push stand_still monsters. */ |
470 | if (QUERY_FLAG (who, FLAG_STAND_STILL)) |
481 | if (QUERY_FLAG (who, FLAG_STAND_STILL)) |
471 | { |
482 | { |
… | |
… | |
481 | */ |
492 | */ |
482 | |
493 | |
483 | str1 = (who->stats.Str > 0 ? who->stats.Str : who->level); |
494 | str1 = (who->stats.Str > 0 ? who->stats.Str : who->level); |
484 | str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level); |
495 | str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level); |
485 | if (QUERY_FLAG (who, FLAG_WIZ) || |
496 | if (QUERY_FLAG (who, FLAG_WIZ) || |
486 | random_roll (str1, str1 / 2 + str1 * 2, who, PREFER_HIGH) >= |
497 | random_roll (str1, str1 * 5 / 2, who, PREFER_HIGH) >= |
487 | random_roll (str2, str2 / 2 + str2 * 2, pusher, PREFER_HIGH) || !move_object (who, dir)) |
498 | random_roll (str2, str2 * 5 / 2, pusher, PREFER_HIGH) || !move_object (who, dir)) |
488 | { |
499 | { |
489 | if (who->type == PLAYER) |
500 | if (who->type == PLAYER) |
490 | { |
|
|
491 | new_draw_info_format (NDI_UNIQUE, 0, who, "%s tried to push you.", &pusher->name); |
501 | new_draw_info_format (NDI_UNIQUE, 0, who, "%s tried to push you.", &pusher->name); |
492 | } |
502 | |
493 | return 0; |
503 | return 0; |
494 | } |
504 | } |
495 | |
505 | |
496 | /* If we get here, the push succeeded. |
506 | /* If we get here, the push succeeded. |
497 | * Let everyone know the status. |
507 | * Let everyone know the status. |