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 | /* |
… | |
… | |
704 | */ |
705 | */ |
705 | |
706 | |
706 | void |
707 | void |
707 | do_mood_floor (object *op, object *source) |
708 | do_mood_floor (object *op, object *source) |
708 | { |
709 | { |
709 | object *tmp; |
|
|
710 | object *tmp2; |
|
|
711 | |
|
|
712 | if (!source) |
710 | if (!source) |
713 | source = op; |
711 | source = op; |
714 | |
712 | |
715 | 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) |
716 | if (QUERY_FLAG (tmp, FLAG_MONSTER)) |
721 | if (QUERY_FLAG (tmp, FLAG_MONSTER)) |
717 | break; |
722 | break; |
718 | |
723 | |
719 | /* 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 |
720 | * be a monster here. |
725 | * be a monster here. |
721 | */ |
726 | */ |
|
|
727 | //TODO: have players really FLAG_MONSTER? kept it for safety |
722 | if (!tmp || tmp->type == PLAYER) |
728 | if (!tmp || tmp->type == PLAYER) |
723 | return; |
729 | return; |
724 | |
730 | |
725 | switch (op->last_sp) |
731 | switch (op->last_sp) |
726 | { |
732 | { |
727 | case 0: /* furious--make all monsters mad */ |
733 | case 0: /* furious--make all monsters mad */ |
728 | if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) |
734 | if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) |
729 | CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE); |
735 | CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE); |
|
|
736 | |
730 | if (QUERY_FLAG (tmp, FLAG_FRIENDLY)) |
737 | if (QUERY_FLAG (tmp, FLAG_FRIENDLY)) |
731 | { |
738 | { |
732 | CLEAR_FLAG (tmp, FLAG_FRIENDLY); |
|
|
733 | remove_friendly_object (tmp); |
|
|
734 | tmp->attack_movement = 0; |
739 | tmp->attack_movement = 0; |
735 | /* 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 |
736 | * dereference a null value |
741 | * dereference a null value |
737 | */ |
742 | */ |
738 | 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) |
739 | tmp->owner->contr->ranges[range_golem] = 0; |
747 | tmp->owner->contr->golem = 0; |
740 | |
748 | |
741 | tmp->owner = 0; |
749 | tmp->owner = 0; |
|
|
750 | |
|
|
751 | remove_friendly_object (tmp); |
742 | } |
752 | } |
743 | break; |
753 | break; |
|
|
754 | |
744 | case 1: /* angry -- get neutral monsters mad */ |
755 | case 1: /* angry -- get neutral monsters mad */ |
745 | if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (tmp, FLAG_FRIENDLY)) |
756 | if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (tmp, FLAG_FRIENDLY)) |
746 | CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE); |
757 | CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE); |
747 | break; |
758 | break; |
|
|
759 | |
748 | case 2: /* calm -- pacify unfriendly monsters */ |
760 | case 2: /* calm -- pacify unfriendly monsters */ |
749 | if (!QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) |
|
|
750 | SET_FLAG (tmp, FLAG_UNAGGRESSIVE); |
761 | SET_FLAG (tmp, FLAG_UNAGGRESSIVE); |
751 | break; |
762 | break; |
|
|
763 | |
752 | case 3: /* make all monsters fall asleep */ |
764 | case 3: /* make all monsters fall asleep */ |
753 | if (!QUERY_FLAG (tmp, FLAG_SLEEP)) |
|
|
754 | SET_FLAG (tmp, FLAG_SLEEP); |
765 | SET_FLAG (tmp, FLAG_SLEEP); |
755 | break; |
766 | break; |
|
|
767 | |
756 | case 4: /* charm all monsters */ |
768 | case 4: /* charm all monsters */ |
757 | if (op == source) |
769 | if (op == source) |
758 | break; /* only if 'connected' */ |
770 | break; /* only if 'connected' */ |
759 | |
771 | |
760 | for (tmp2 = GET_MAP_OB (source->map, source->x, source->y); /* finding an owner */ |
772 | if (object *pl = source->ms ().player ()) |
761 | tmp2->type != PLAYER; tmp2 = tmp2->above) |
773 | { |
762 | 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 | } |
763 | break; |
782 | break; |
764 | |
783 | |
765 | if (tmp2->type != PLAYER) |
784 | case 6: // kill monsters |
|
|
785 | if (!QUERY_FLAG (tmp, FLAG_FRIENDLY)) |
766 | break; |
786 | break; |
767 | |
787 | |
768 | tmp->set_owner (tmp2); |
788 | // FALL THROUGH |
769 | SET_FLAG (tmp, FLAG_MONSTER); |
789 | case 5: // kill all alives |
770 | |
790 | if (!tmp->flag [FLAG_PRECIOUS]) |
771 | tmp->stats.exp = 0; |
791 | { |
772 | SET_FLAG (tmp, FLAG_FRIENDLY); |
792 | get_archetype ("burnout")->insert_at (tmp, source); |
773 | |
793 | tmp->destroy (); |
774 | add_friendly_object (tmp); |
794 | } |
775 | tmp->attack_movement = PETMOVE; |
|
|
776 | break; |
795 | break; |
777 | |
796 | |
778 | default: |
797 | default: |
779 | break; |
798 | break; |
780 | } |
799 | } |
… | |
… | |
828 | * 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 |
829 | * 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 |
830 | * 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 |
831 | * state in the inventory checker. This won't happen anymore now. |
850 | * state in the inventory checker. This won't happen anymore now. |
832 | * |
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 | * |
833 | */ |
858 | */ |
834 | void |
859 | void |
835 | check_inv (object *op, object *trig) |
860 | check_inv (object *op, object *trig) |
836 | { |
861 | { |
837 | trig->value = 0; // deactivate if none of the following conditions apply |
862 | trig->value = 0; // deactivate if none of the following conditions apply |
838 | |
863 | |
839 | if (object *pl = trig->ms ().player ()) |
864 | object *pl = trig->ms ().player (); |
840 | { |
|
|
841 | object *match = check_inv_recursive (pl, trig); |
865 | object *match = check_inv_recursive (op, trig); |
842 | |
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 | |
843 | if (match && trig->last_sp) // match == having |
874 | if (match && trig->last_sp) // match == having |
844 | { |
875 | { |
845 | if (trig->last_heal) |
876 | if (trig->last_heal) |
846 | decrease_ob (match); |
877 | decrease_ob (match); |
847 | |
878 | |
848 | trig->value = 1; |
879 | trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left |
849 | } |
880 | push_button (trig); |
|
|
881 | } |
850 | else if (!match && !trig->last_sp) // match == not having |
882 | else if (!match && !trig->last_sp) // match == not having |
851 | trig->value = 1; |
|
|
852 | } |
883 | { |
853 | |
884 | trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left |
854 | push_button (trig); |
885 | push_button (trig); |
|
|
886 | } |
855 | } |
887 | } |
856 | |
888 | |