1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game |
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 authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
25 | #include <funcpoint.h> |
26 | #include <funcpoint.h> |
26 | |
27 | |
27 | /* |
28 | /* |
… | |
… | |
67 | switch (tmp->type) |
68 | switch (tmp->type) |
68 | { |
69 | { |
69 | case GATE: |
70 | case GATE: |
70 | case HOLE: |
71 | case HOLE: |
71 | tmp->value = tmp->stats.maxsp ? !state : state; |
72 | tmp->value = tmp->stats.maxsp ? !state : state; |
72 | tmp->speed = 0.5; |
73 | tmp->set_speed (0.5); |
73 | update_ob_speed (tmp); |
|
|
74 | break; |
74 | break; |
75 | |
75 | |
76 | case CF_HANDLE: |
76 | case CF_HANDLE: |
77 | SET_ANIMATION (tmp, (tmp->value = tmp->stats.maxsp ? !state : state)); |
77 | SET_ANIMATION (tmp, (tmp->value = tmp->stats.maxsp ? !state : state)); |
78 | update_object (tmp, UP_OBJ_FACE); |
78 | update_object (tmp, UP_OBJ_FACE); |
… | |
… | |
103 | case MOOD_FLOOR: |
103 | case MOOD_FLOOR: |
104 | do_mood_floor (tmp, source); |
104 | do_mood_floor (tmp, source); |
105 | break; |
105 | break; |
106 | |
106 | |
107 | case TIMED_GATE: |
107 | case TIMED_GATE: |
108 | tmp->speed = tmp->arch->clone.speed; |
108 | tmp->set_speed (tmp->arch->clone.speed); |
109 | update_ob_speed (tmp); /* original values */ |
|
|
110 | tmp->value = tmp->arch->clone.value; |
109 | tmp->value = tmp->arch->clone.value; |
111 | tmp->stats.sp = 1; |
110 | tmp->stats.sp = 1; |
112 | tmp->stats.hp = tmp->stats.maxhp; |
111 | tmp->stats.hp = tmp->stats.maxhp; |
113 | /* Handle multipart gates. We copy the value for the other parts |
112 | /* Handle multipart gates. We copy the value for the other parts |
114 | * from the head - this ensures that the data will consistent |
113 | * from the head - this ensures that the data will consistent |
115 | */ |
114 | */ |
116 | for (tmp = tmp->more; tmp != NULL; tmp = tmp->more) |
115 | for (tmp = tmp->more; tmp; tmp = tmp->more) |
117 | { |
116 | { |
118 | tmp->speed = tmp->head->speed; |
|
|
119 | tmp->value = tmp->head->value; |
117 | tmp->value = tmp->head->value; |
120 | tmp->stats.sp = tmp->head->stats.sp; |
118 | tmp->stats.sp = tmp->head->stats.sp; |
121 | tmp->stats.hp = tmp->head->stats.hp; |
119 | tmp->stats.hp = tmp->head->stats.hp; |
122 | update_ob_speed (tmp); |
120 | tmp->set_speed (tmp->head->speed); |
123 | } |
121 | } |
124 | break; |
122 | break; |
125 | |
123 | |
126 | case DIRECTOR: |
124 | case DIRECTOR: |
127 | case FIREWALL: |
125 | case FIREWALL: |
… | |
… | |
276 | update_object (op, UP_OBJ_FACE); |
274 | update_object (op, UP_OBJ_FACE); |
277 | push_button (op); /* Make all other buttons the same */ |
275 | push_button (op); /* Make all other buttons the same */ |
278 | } |
276 | } |
279 | } |
277 | } |
280 | |
278 | |
281 | /* |
|
|
282 | * Updates every button on the map (by calling update_button() for them). |
|
|
283 | */ |
|
|
284 | |
|
|
285 | void |
|
|
286 | update_buttons (maptile *m) |
|
|
287 | { |
|
|
288 | objectlink *ol; |
|
|
289 | oblinkpt *obp; |
|
|
290 | |
|
|
291 | for (obp = m->buttons; obp; obp = obp->next) |
|
|
292 | for (ol = obp->link; ol; ol = ol->next) |
|
|
293 | { |
|
|
294 | if (!ol->ob) |
|
|
295 | { |
|
|
296 | LOG (llevError, "Internal error in update_button (%s (%dx%d), connected %ld).\n", |
|
|
297 | ol->ob ? (const char *) ol->ob->name : "null", ol->ob ? ol->ob->x : -1, ol->ob ? ol->ob->y : -1, obp->value); |
|
|
298 | continue; |
|
|
299 | } |
|
|
300 | |
|
|
301 | if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL) |
|
|
302 | { |
|
|
303 | update_button (ol->ob); |
|
|
304 | break; |
|
|
305 | } |
|
|
306 | } |
|
|
307 | } |
|
|
308 | |
|
|
309 | void |
279 | void |
310 | use_trigger (object *op) |
280 | use_trigger (object *op) |
311 | { |
281 | { |
312 | |
|
|
313 | /* Toggle value */ |
282 | /* Toggle value */ |
314 | op->value = !op->value; |
283 | op->value = !op->value; |
315 | push_button (op); |
284 | push_button (op); |
316 | } |
285 | } |
317 | |
286 | |
318 | /* |
287 | /* |
319 | * Note: animate_object should be used instead of this, |
288 | * Note: animate_object should be used instead of this, |
320 | * but it can't handle animations in the 8 directions |
289 | * but it can't handle animations in the 8 directions |
321 | */ |
290 | */ |
322 | |
|
|
323 | void |
291 | void |
324 | animate_turning (object *op) /* only one part objects */ |
292 | animate_turning (object *op) /* only one part objects */ |
325 | { |
293 | { |
326 | if (++op->state >= NUM_ANIMATIONS (op) / 8) |
294 | if (++op->state >= NUM_ANIMATIONS (op) / 8) |
327 | op->state = 0; |
295 | op->state = 0; |
… | |
… | |
414 | { |
382 | { |
415 | op->stats.wc = state; |
383 | op->stats.wc = state; |
416 | if (state) |
384 | if (state) |
417 | { |
385 | { |
418 | use_trigger (op); |
386 | use_trigger (op); |
419 | if (op->stats.exp > 0) /* check sanity */ |
387 | op->set_speed (op->stats.exp > 0 ? 1. / op->stats.exp : 1.); |
420 | op->speed = 1.0 / op->stats.exp; |
|
|
421 | else |
|
|
422 | op->speed = 1.0; |
|
|
423 | update_ob_speed (op); |
|
|
424 | op->speed_left = -1; |
388 | op->speed_left = -1; |
425 | } |
389 | } |
426 | else |
390 | else |
427 | { |
391 | { |
428 | use_trigger (op); |
392 | use_trigger (op); |
429 | op->speed = 0; |
393 | op->set_speed (0); |
430 | update_ob_speed (op); |
|
|
431 | } |
394 | } |
432 | } |
395 | } |
433 | |
396 | |
434 | |
397 | |
435 | /* |
398 | /* |
… | |
… | |
570 | trigger_move (op, 0); |
533 | trigger_move (op, 0); |
571 | else |
534 | else |
572 | { |
535 | { |
573 | op->stats.wc = 0; |
536 | op->stats.wc = 0; |
574 | op->value = !op->value; |
537 | op->value = !op->value; |
575 | op->speed = 0; |
538 | op->set_speed (0); |
576 | update_ob_speed (op); |
|
|
577 | } |
539 | } |
578 | } |
540 | } |
579 | return 0; |
541 | return 0; |
580 | |
542 | |
581 | case TRIGGER: |
543 | case TRIGGER: |
582 | if (cause) |
544 | if (cause) |
583 | { |
545 | { |
584 | if (in_movement) |
546 | if (in_movement) |
585 | return 0; |
547 | return 0; |
|
|
548 | |
586 | push = 1; |
549 | push = 1; |
587 | } |
550 | } |
|
|
551 | |
588 | if (NUM_ANIMATIONS (op) > 1) |
552 | if (NUM_ANIMATIONS (op) > 1) |
589 | { |
553 | { |
590 | SET_ANIMATION (op, push); |
554 | SET_ANIMATION (op, push); |
591 | update_object (op, UP_OBJ_FACE); |
555 | update_object (op, UP_OBJ_FACE); |
592 | } |
556 | } |
|
|
557 | |
593 | trigger_move (op, push); |
558 | trigger_move (op, push); |
594 | return 1; |
559 | return 1; |
595 | |
560 | |
596 | default: |
561 | default: |
597 | LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type); |
562 | LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type); |
… | |
… | |
740 | */ |
705 | */ |
741 | |
706 | |
742 | void |
707 | void |
743 | do_mood_floor (object *op, object *source) |
708 | do_mood_floor (object *op, object *source) |
744 | { |
709 | { |
745 | object *tmp; |
|
|
746 | object *tmp2; |
|
|
747 | |
|
|
748 | if (!source) |
710 | if (!source) |
749 | source = op; |
711 | source = op; |
750 | |
712 | |
751 | for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = tmp->above) |
713 | mapspace &ms = op->ms (); |
|
|
714 | |
|
|
715 | if (!(ms.flags () & P_IS_ALIVE)) |
|
|
716 | return; |
|
|
717 | |
|
|
718 | object *tmp; |
|
|
719 | |
|
|
720 | for (tmp = ms.top; tmp; tmp = tmp->below) |
752 | if (QUERY_FLAG (tmp, FLAG_MONSTER)) |
721 | if (QUERY_FLAG (tmp, FLAG_MONSTER)) |
753 | break; |
722 | break; |
754 | |
723 | |
755 | /* doesn't effect players, and if there is a player on this space, won't also |
724 | /* doesn't effect players, and if there is a player on this space, won't also |
756 | * be a monster here. |
725 | * be a monster here. |
757 | */ |
726 | */ |
|
|
727 | //TODO: have players really FLAG_MONSTER? kept it for safety |
758 | if (!tmp || tmp->type == PLAYER) |
728 | if (!tmp || tmp->type == PLAYER) |
759 | return; |
729 | return; |
760 | |
730 | |
761 | switch (op->last_sp) |
731 | switch (op->last_sp) |
762 | { |
732 | { |
763 | case 0: /* furious--make all monsters mad */ |
733 | case 0: /* furious--make all monsters mad */ |
764 | if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) |
734 | if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) |
765 | CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE); |
735 | CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE); |
|
|
736 | |
766 | if (QUERY_FLAG (tmp, FLAG_FRIENDLY)) |
737 | if (QUERY_FLAG (tmp, FLAG_FRIENDLY)) |
767 | { |
738 | { |
768 | CLEAR_FLAG (tmp, FLAG_FRIENDLY); |
|
|
769 | remove_friendly_object (tmp); |
|
|
770 | tmp->attack_movement = 0; |
739 | tmp->attack_movement = 0; |
771 | /* lots of checks here, but want to make sure we don't |
740 | /* lots of checks here, but want to make sure we don't |
772 | * dereference a null value |
741 | * dereference a null value |
773 | */ |
742 | */ |
774 | if (tmp->type == GOLEM && tmp->owner && tmp->owner->type == PLAYER && tmp->owner->contr->ranges[range_golem] == tmp) |
743 | if (tmp->type == GOLEM |
|
|
744 | && tmp->owner |
|
|
745 | && tmp->owner->type == PLAYER |
|
|
746 | && tmp->owner->contr->golem == tmp) |
775 | tmp->owner->contr->ranges[range_golem] = 0; |
747 | tmp->owner->contr->golem = 0; |
776 | |
748 | |
777 | tmp->owner = 0; |
749 | tmp->owner = 0; |
|
|
750 | |
|
|
751 | remove_friendly_object (tmp); |
778 | } |
752 | } |
779 | break; |
753 | break; |
|
|
754 | |
780 | case 1: /* angry -- get neutral monsters mad */ |
755 | case 1: /* angry -- get neutral monsters mad */ |
781 | if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (tmp, FLAG_FRIENDLY)) |
756 | if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (tmp, FLAG_FRIENDLY)) |
782 | CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE); |
757 | CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE); |
783 | break; |
758 | break; |
|
|
759 | |
784 | case 2: /* calm -- pacify unfriendly monsters */ |
760 | case 2: /* calm -- pacify unfriendly monsters */ |
785 | if (!QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) |
|
|
786 | SET_FLAG (tmp, FLAG_UNAGGRESSIVE); |
761 | SET_FLAG (tmp, FLAG_UNAGGRESSIVE); |
787 | break; |
762 | break; |
|
|
763 | |
788 | case 3: /* make all monsters fall asleep */ |
764 | case 3: /* make all monsters fall asleep */ |
789 | if (!QUERY_FLAG (tmp, FLAG_SLEEP)) |
|
|
790 | SET_FLAG (tmp, FLAG_SLEEP); |
765 | SET_FLAG (tmp, FLAG_SLEEP); |
791 | break; |
766 | break; |
|
|
767 | |
792 | case 4: /* charm all monsters */ |
768 | case 4: /* charm all monsters */ |
793 | if (op == source) |
769 | if (op == source) |
794 | break; /* only if 'connected' */ |
770 | break; /* only if 'connected' */ |
795 | |
771 | |
796 | for (tmp2 = GET_MAP_OB (source->map, source->x, source->y); /* finding an owner */ |
772 | if (object *pl = source->ms ().player ()) |
797 | tmp2->type != PLAYER; tmp2 = tmp2->above) |
773 | { |
798 | if (tmp2->above == NULL) |
774 | tmp->set_owner (pl); |
|
|
775 | SET_FLAG (tmp, FLAG_MONSTER); |
|
|
776 | |
|
|
777 | tmp->stats.exp = 0; |
|
|
778 | |
|
|
779 | add_friendly_object (tmp); |
|
|
780 | tmp->attack_movement = PETMOVE; |
|
|
781 | } |
799 | break; |
782 | break; |
800 | |
783 | |
801 | if (tmp2->type != PLAYER) |
784 | case 6: // kill monsters |
|
|
785 | if (!QUERY_FLAG (tmp, FLAG_FRIENDLY)) |
802 | break; |
786 | break; |
803 | |
787 | |
804 | tmp->set_owner (tmp2); |
788 | // FALL THROUGH |
805 | SET_FLAG (tmp, FLAG_MONSTER); |
789 | case 5: // kill all alives |
806 | |
790 | if (!tmp->flag [FLAG_PRECIOUS]) |
807 | tmp->stats.exp = 0; |
791 | { |
808 | SET_FLAG (tmp, FLAG_FRIENDLY); |
792 | get_archetype ("burnout")->insert_at (tmp, source); |
809 | |
793 | tmp->destroy (); |
810 | add_friendly_object (tmp); |
794 | } |
811 | tmp->attack_movement = PETMOVE; |
|
|
812 | break; |
795 | break; |
813 | |
796 | |
814 | default: |
797 | default: |
815 | break; |
798 | break; |
816 | } |
799 | } |
… | |
… | |
864 | * and has a matching item. Imagine what happens if someone steps on the inventory |
847 | * and has a matching item. Imagine what happens if someone steps on the inventory |
865 | * checker with a matching item, has it, activates the connection, throws the item |
848 | * checker with a matching item, has it, activates the connection, throws the item |
866 | * away, and then leaves the inventory checker. That would've caused an always-enabled |
849 | * away, and then leaves the inventory checker. That would've caused an always-enabled |
867 | * state in the inventory checker. This won't happen anymore now. |
850 | * state in the inventory checker. This won't happen anymore now. |
868 | * |
851 | * |
|
|
852 | * Wed Jan 10 11:34:26 CET 2007 elmex: fixed this function, we now check |
|
|
853 | * whether op is on this mapspace or not, because the value (1|0) depends |
|
|
854 | * on this information. also make sure to only push_button if op has |
|
|
855 | * a matching item (because when we do a push_button with value=0 timed gates |
|
|
856 | * will still open)! (i hope i got the semantics right this time) |
|
|
857 | * |
869 | */ |
858 | */ |
870 | void |
859 | void |
871 | check_inv (object *op, object *trig) |
860 | check_inv (object *op, object *trig) |
872 | { |
861 | { |
873 | trig->value = 0; // deactivate if none of the following conditions apply |
862 | trig->value = 0; // deactivate if none of the following conditions apply |
874 | |
863 | |
875 | if (object *pl = trig->ms ().player ()) |
864 | object *pl = trig->ms ().player (); |
876 | { |
|
|
877 | object *match = check_inv_recursive (pl, trig); |
865 | object *match = check_inv_recursive (op, trig); |
878 | |
866 | |
|
|
867 | // elmex: a note about (pl == op): |
|
|
868 | // if pl == 0 then the player has left this space |
|
|
869 | // if pl != 0 then a player is on this mapspace, but then |
|
|
870 | // we still have to check whether it's the player that triggered |
|
|
871 | // this inv-checker, because if not, then the op left this inv-checker |
|
|
872 | // and we have to set the value to 0 |
|
|
873 | |
879 | if (match && trig->last_sp) // match == having |
874 | if (match && trig->last_sp) // match == having |
880 | { |
875 | { |
881 | if (trig->last_heal) |
876 | if (trig->last_heal) |
882 | decrease_ob (match); |
877 | decrease_ob (match); |
883 | |
878 | |
884 | trig->value = 1; |
879 | trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left |
885 | } |
880 | push_button (trig); |
|
|
881 | } |
886 | else if (!match && !trig->last_sp) // match == not having |
882 | else if (!match && !trig->last_sp) // match == not having |
887 | trig->value = 1; |
|
|
888 | } |
883 | { |
889 | |
884 | trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left |
890 | push_button (trig); |
885 | push_button (trig); |
|
|
886 | } |
891 | } |
887 | } |
892 | |
888 | |