ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/button.C
(Generate patch)

Comparing deliantra/server/common/button.C (file contents):
Revision 1.20 by root, Tue Dec 26 08:54:58 2006 UTC vs.
Revision 1.28 by root, Mon Jan 29 15:36:25 2007 UTC

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 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/*
273 update_object (op, UP_OBJ_FACE); 274 update_object (op, UP_OBJ_FACE);
274 push_button (op); /* Make all other buttons the same */ 275 push_button (op); /* Make all other buttons the same */
275 } 276 }
276} 277}
277 278
278/*
279 * Updates every button on the map (by calling update_button() for them).
280 */
281
282void
283update_buttons (maptile *m)
284{
285 objectlink *ol;
286 oblinkpt *obp;
287
288 for (obp = m->buttons; obp; obp = obp->next)
289 for (ol = obp->link; ol; ol = ol->next)
290 {
291 if (!ol->ob)
292 {
293 LOG (llevError, "Internal error in update_button (%s (%dx%d), connected %ld).\n",
294 ol->ob ? (const char *) ol->ob->name : "null", ol->ob ? ol->ob->x : -1, ol->ob ? ol->ob->y : -1, obp->value);
295 continue;
296 }
297
298 if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL)
299 {
300 update_button (ol->ob);
301 break;
302 }
303 }
304}
305
306void 279void
307use_trigger (object *op) 280use_trigger (object *op)
308{ 281{
309
310 /* Toggle value */ 282 /* Toggle value */
311 op->value = !op->value; 283 op->value = !op->value;
312 push_button (op); 284 push_button (op);
313} 285}
314 286
315/* 287/*
316 * Note: animate_object should be used instead of this, 288 * Note: animate_object should be used instead of this,
317 * but it can't handle animations in the 8 directions 289 * but it can't handle animations in the 8 directions
318 */ 290 */
319
320void 291void
321animate_turning (object *op) /* only one part objects */ 292animate_turning (object *op) /* only one part objects */
322{ 293{
323 if (++op->state >= NUM_ANIMATIONS (op) / 8) 294 if (++op->state >= NUM_ANIMATIONS (op) / 8)
324 op->state = 0; 295 op->state = 0;
734 */ 705 */
735 706
736void 707void
737do_mood_floor (object *op, object *source) 708do_mood_floor (object *op, object *source)
738{ 709{
739 object *tmp;
740 object *tmp2;
741
742 if (!source) 710 if (!source)
743 source = op; 711 source = op;
744 712
745 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)
746 if (QUERY_FLAG (tmp, FLAG_MONSTER)) 721 if (QUERY_FLAG (tmp, FLAG_MONSTER))
747 break; 722 break;
748 723
749 /* 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
750 * be a monster here. 725 * be a monster here.
751 */ 726 */
727 //TODO: have players really FLAG_MONSTER? kept it for safety
752 if (!tmp || tmp->type == PLAYER) 728 if (!tmp || tmp->type == PLAYER)
753 return; 729 return;
754 730
755 switch (op->last_sp) 731 switch (op->last_sp)
756 { 732 {
757 case 0: /* furious--make all monsters mad */ 733 case 0: /* furious--make all monsters mad */
758 if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) 734 if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE))
759 CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE); 735 CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE);
736
760 if (QUERY_FLAG (tmp, FLAG_FRIENDLY)) 737 if (QUERY_FLAG (tmp, FLAG_FRIENDLY))
761 { 738 {
762 CLEAR_FLAG (tmp, FLAG_FRIENDLY);
763 remove_friendly_object (tmp); 739 remove_friendly_object (tmp);
740
764 tmp->attack_movement = 0; 741 tmp->attack_movement = 0;
765 /* lots of checks here, but want to make sure we don't 742 /* lots of checks here, but want to make sure we don't
766 * dereference a null value 743 * dereference a null value
767 */ 744 */
768 if (tmp->type == GOLEM && tmp->owner && tmp->owner->type == PLAYER && tmp->owner->contr->ranges[range_golem] == tmp) 745 if (tmp->type == GOLEM && tmp->owner && tmp->owner->type == PLAYER && tmp->owner->contr->ranges[range_golem] == tmp)
769 tmp->owner->contr->ranges[range_golem] = 0; 746 tmp->owner->contr->ranges[range_golem] = 0;
770 747
771 tmp->owner = 0; 748 tmp->owner = 0;
772 } 749 }
773 break; 750 break;
751
774 case 1: /* angry -- get neutral monsters mad */ 752 case 1: /* angry -- get neutral monsters mad */
775 if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (tmp, FLAG_FRIENDLY)) 753 if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (tmp, FLAG_FRIENDLY))
776 CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE); 754 CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE);
777 break; 755 break;
756
778 case 2: /* calm -- pacify unfriendly monsters */ 757 case 2: /* calm -- pacify unfriendly monsters */
779 if (!QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE))
780 SET_FLAG (tmp, FLAG_UNAGGRESSIVE); 758 SET_FLAG (tmp, FLAG_UNAGGRESSIVE);
781 break; 759 break;
760
782 case 3: /* make all monsters fall asleep */ 761 case 3: /* make all monsters fall asleep */
783 if (!QUERY_FLAG (tmp, FLAG_SLEEP))
784 SET_FLAG (tmp, FLAG_SLEEP); 762 SET_FLAG (tmp, FLAG_SLEEP);
785 break; 763 break;
764
786 case 4: /* charm all monsters */ 765 case 4: /* charm all monsters */
787 if (op == source) 766 if (op == source)
788 break; /* only if 'connected' */ 767 break; /* only if 'connected' */
789 768
790 for (tmp2 = GET_MAP_OB (source->map, source->x, source->y); /* finding an owner */ 769 if (object *pl = source->ms ().player ())
791 tmp2->type != PLAYER; tmp2 = tmp2->above) 770 {
792 if (tmp2->above == NULL) 771 tmp->set_owner (pl);
772 SET_FLAG (tmp, FLAG_MONSTER);
773
774 tmp->stats.exp = 0;
775
776 add_friendly_object (tmp);
777 tmp->attack_movement = PETMOVE;
778 }
793 break; 779 break;
794 780
795 if (tmp2->type != PLAYER) 781 case 6:
782 if (!QUERY_FLAG (tmp, FLAG_FRIENDLY))
796 break; 783 break;
797 784
798 tmp->set_owner (tmp2); 785 // FALL THROUGH
799 SET_FLAG (tmp, FLAG_MONSTER); 786 case 5:
800 787 get_archetype ("burnout")->insert_at (tmp, source);
801 tmp->stats.exp = 0; 788 tmp->destroy ();
802 SET_FLAG (tmp, FLAG_FRIENDLY);
803
804 add_friendly_object (tmp);
805 tmp->attack_movement = PETMOVE;
806 break; 789 break;
807 790
808 default: 791 default:
809 break; 792 break;
810 } 793 }
858 * and has a matching item. Imagine what happens if someone steps on the inventory 841 * and has a matching item. Imagine what happens if someone steps on the inventory
859 * checker with a matching item, has it, activates the connection, throws the item 842 * checker with a matching item, has it, activates the connection, throws the item
860 * away, and then leaves the inventory checker. That would've caused an always-enabled 843 * away, and then leaves the inventory checker. That would've caused an always-enabled
861 * state in the inventory checker. This won't happen anymore now. 844 * state in the inventory checker. This won't happen anymore now.
862 * 845 *
846 * Wed Jan 10 11:34:26 CET 2007 elmex: fixed this function, we now check
847 * whether op is on this mapspace or not, because the value (1|0) depends
848 * on this information. also make sure to only push_button if op has
849 * a matching item (because when we do a push_button with value=0 timed gates
850 * will still open)! (i hope i got the semantics right this time)
851 *
863 */ 852 */
864void 853void
865check_inv (object *op, object *trig) 854check_inv (object *op, object *trig)
866{ 855{
867 trig->value = 0; // deactivate if none of the following conditions apply 856 trig->value = 0; // deactivate if none of the following conditions apply
868 857
869 if (object *pl = trig->ms ().player ()) 858 object *pl = trig->ms ().player ();
870 {
871 object *match = check_inv_recursive (pl, trig); 859 object *match = check_inv_recursive (op, trig);
872 860
861 // elmex: a note about (pl == op):
862 // if pl == 0 then the player has left this space
863 // if pl != 0 then a player is on this mapspace, but then
864 // we still have to check whether it's the player that triggered
865 // this inv-checker, because if not, then the op left this inv-checker
866 // and we have to set the value to 0
867
873 if (match && trig->last_sp) // match == having 868 if (match && trig->last_sp) // match == having
874 { 869 {
875 if (trig->last_heal) 870 if (trig->last_heal)
876 decrease_ob (match); 871 decrease_ob (match);
877 872
878 trig->value = 1; 873 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left
879 } 874 push_button (trig);
875 }
880 else if (!match && !trig->last_sp) // match == not having 876 else if (!match && !trig->last_sp) // match == not having
881 trig->value = 1;
882 } 877 {
883 878 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left
884 push_button (trig); 879 push_button (trig);
880 }
885} 881}
886 882

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines