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.19 by root, Mon Dec 25 11:25:49 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/*
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
285void
286update_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
309void 279void
310use_trigger (object *op) 280use_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
323void 291void
324animate_turning (object *op) /* only one part objects */ 292animate_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
742void 707void
743do_mood_floor (object *op, object *source) 708do_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); 739 remove_friendly_object (tmp);
740
770 tmp->attack_movement = 0; 741 tmp->attack_movement = 0;
771 /* 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
772 * dereference a null value 743 * dereference a null value
773 */ 744 */
774 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)
775 tmp->owner->contr->ranges[range_golem] = 0; 746 tmp->owner->contr->ranges[range_golem] = 0;
776 747
777 tmp->owner = 0; 748 tmp->owner = 0;
778 } 749 }
779 break; 750 break;
751
780 case 1: /* angry -- get neutral monsters mad */ 752 case 1: /* angry -- get neutral monsters mad */
781 if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (tmp, FLAG_FRIENDLY)) 753 if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (tmp, FLAG_FRIENDLY))
782 CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE); 754 CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE);
783 break; 755 break;
756
784 case 2: /* calm -- pacify unfriendly monsters */ 757 case 2: /* calm -- pacify unfriendly monsters */
785 if (!QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE))
786 SET_FLAG (tmp, FLAG_UNAGGRESSIVE); 758 SET_FLAG (tmp, FLAG_UNAGGRESSIVE);
787 break; 759 break;
760
788 case 3: /* make all monsters fall asleep */ 761 case 3: /* make all monsters fall asleep */
789 if (!QUERY_FLAG (tmp, FLAG_SLEEP))
790 SET_FLAG (tmp, FLAG_SLEEP); 762 SET_FLAG (tmp, FLAG_SLEEP);
791 break; 763 break;
764
792 case 4: /* charm all monsters */ 765 case 4: /* charm all monsters */
793 if (op == source) 766 if (op == source)
794 break; /* only if 'connected' */ 767 break; /* only if 'connected' */
795 768
796 for (tmp2 = GET_MAP_OB (source->map, source->x, source->y); /* finding an owner */ 769 if (object *pl = source->ms ().player ())
797 tmp2->type != PLAYER; tmp2 = tmp2->above) 770 {
798 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 }
799 break; 779 break;
800 780
801 if (tmp2->type != PLAYER) 781 case 6:
782 if (!QUERY_FLAG (tmp, FLAG_FRIENDLY))
802 break; 783 break;
803 784
804 tmp->set_owner (tmp2); 785 // FALL THROUGH
805 SET_FLAG (tmp, FLAG_MONSTER); 786 case 5:
806 787 get_archetype ("burnout")->insert_at (tmp, source);
807 tmp->stats.exp = 0; 788 tmp->destroy ();
808 SET_FLAG (tmp, FLAG_FRIENDLY);
809
810 add_friendly_object (tmp);
811 tmp->attack_movement = PETMOVE;
812 break; 789 break;
813 790
814 default: 791 default:
815 break; 792 break;
816 } 793 }
864 * 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
865 * 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
866 * 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
867 * state in the inventory checker. This won't happen anymore now. 844 * state in the inventory checker. This won't happen anymore now.
868 * 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 *
869 */ 852 */
870void 853void
871check_inv (object *op, object *trig) 854check_inv (object *op, object *trig)
872{ 855{
873 trig->value = 0; // deactivate if none of the following conditions apply 856 trig->value = 0; // deactivate if none of the following conditions apply
874 857
875 if (object *pl = trig->ms ().player ()) 858 object *pl = trig->ms ().player ();
876 {
877 object *match = check_inv_recursive (pl, trig); 859 object *match = check_inv_recursive (op, trig);
878 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
879 if (match && trig->last_sp) // match == having 868 if (match && trig->last_sp) // match == having
880 { 869 {
881 if (trig->last_heal) 870 if (trig->last_heal)
882 decrease_ob (match); 871 decrease_ob (match);
883 872
884 trig->value = 1; 873 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left
885 } 874 push_button (trig);
875 }
886 else if (!match && !trig->last_sp) // match == not having 876 else if (!match && !trig->last_sp) // match == not having
887 trig->value = 1;
888 } 877 {
889 878 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left
890 push_button (trig); 879 push_button (trig);
880 }
891} 881}
892 882

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines