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.60 by root, Mon Oct 26 03:43:22 2009 UTC vs.
Revision 1.74 by root, Sat Nov 17 23:39:59 2018 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 9 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 10 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 17 * GNU General Public License for more details.
17 * 18 *
18 * You should have received a copy of the Affero GNU General Public License 19 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see 20 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 21 * <http://www.gnu.org/licenses/>.
21 * 22 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 23 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 24 */
24 25
25#include <global.h> 26#include <global.h>
26 27
52 * is getting moved out of memory, the status of buttons and levers 53 * is getting moved out of memory, the status of buttons and levers
53 * probably isn't important - it will get sorted out when the map is 54 * probably isn't important - it will get sorted out when the map is
54 * re-loaded. As such, just exit this function if that is the case. 55 * re-loaded. As such, just exit this function if that is the case.
55 */ 56 */
56 57
57 if (QUERY_FLAG (ol->ob, FLAG_FREED)) 58 if (ol->ob->flag [FLAG_FREED])
58 return; 59 return;
59 60
60 object *tmp = ol->ob; 61 object *tmp = ol->ob;
61 62
62 /* if the criteria isn't appropriate, don't do anything */ 63 /* if the criteria isn't appropriate, don't do anything */
63 if (state && !QUERY_FLAG (tmp, FLAG_ACTIVATE_ON_PUSH)) 64 if (state && !tmp->flag [FLAG_ACTIVATE_ON_PUSH])
64 continue; 65 continue;
65 66
66 if (!state && !QUERY_FLAG (tmp, FLAG_ACTIVATE_ON_RELEASE)) 67 if (!state && !tmp->flag [FLAG_ACTIVATE_ON_RELEASE])
67 continue; 68 continue;
68 69
69 switch (tmp->type) 70 switch (tmp->type)
70 { 71 {
71 case GATE: 72 case GATE:
137 } 138 }
138 break; 139 break;
139 140
140 case DIRECTOR: 141 case DIRECTOR:
141 case FIREWALL: 142 case FIREWALL:
142 if (!QUERY_FLAG (tmp, FLAG_ANIMATE) && tmp->type == FIREWALL) 143 if (!tmp->flag [FLAG_ANIMATE] && tmp->type == FIREWALL)
143 move_firewall (tmp); 144 move_firewall (tmp);
144 else 145 else
145 { 146 {
146 tmp->stats.sp = absdir (tmp->stats.sp + tmp->stats.maxsp); /* next direction */ 147 tmp->stats.sp = absdir (tmp->stats.sp + tmp->stats.maxsp); /* next direction */
147 animate_turning (tmp); 148 animate_turning (tmp);
236 237
237 object *tmp = ol->ob; 238 object *tmp = ol->ob;
238 239
239 if (tmp->type == BUTTON) 240 if (tmp->type == BUTTON)
240 { 241 {
241 sint32 total = 0; 242 weight_t total = 0;
242 243
243 for (object *ab = tmp->above; ab; ab = ab->above) 244 for (object *ab = tmp->above; ab; ab = ab->above)
244 /* Basically, if the move_type matches that on what the 245 /* Basically, if the move_type matches that on what the
245 * button wants, we count it. The second check is so that 246 * button wants, we count it. The second check is so that
246 * objects who don't move (swords, etc) will count. Note that 247 * objects who don't move (swords, etc) will count. Note that
346 * 347 *
347 * 0.93.4: Linked objects (ie, objects that are connected) can not be 348 * 0.93.4: Linked objects (ie, objects that are connected) can not be
348 * sacrificed. This fixes a bug of trying to put multiple altars/related 349 * sacrificed. This fixes a bug of trying to put multiple altars/related
349 * objects on the same space that take the same sacrifice. 350 * objects on the same space that take the same sacrifice.
350 */ 351 */
351
352int 352int
353check_altar_sacrifice (object *altar, object *sacrifice, object *originator) 353check_altar_sacrifice (object *altar, object *sacrifice, object *originator)
354{ 354{
355 if (sacrifice->flag [FLAG_UNPAID]) 355 if (sacrifice->flag [FLAG_UNPAID]
356 || sacrifice->flag [FLAG_IS_LINKED]
357 || sacrifice->is_player ())
356 return 0; 358 return 0;
357 359
358 if (is_match_expr (ARCH_SACRIFICE (altar))) 360 if (is_match_expr (ARCH_SACRIFICE (altar)))
359 return match (ARCH_SACRIFICE (altar), altar, originator); 361 return match (ARCH_SACRIFICE (altar), sacrifice, altar, originator);
360 362
361 if (!QUERY_FLAG (sacrifice, FLAG_ALIVE) 363 if (!sacrifice->flag [FLAG_ALIVE])
362 && !QUERY_FLAG (sacrifice, FLAG_IS_LINKED)
363 && sacrifice->type != PLAYER)
364 { 364 {
365 if (ARCH_SACRIFICE (altar) == shstr_money 365 if (ARCH_SACRIFICE (altar) == shstr_money
366 && sacrifice->type == MONEY 366 && sacrifice->type == MONEY
367 && sacrifice->nrof * sacrifice->value >= NROF_SACRIFICE (altar)) 367 && sacrifice->nrof * sacrifice->value >= NROF_SACRIFICE (altar))
368 return 1; 368 return 1;
424 new_info_map (NDI_BLACK, altar->map, altar->msg); 424 new_info_map (NDI_BLACK, altar->map, altar->msg);
425 425
426 return 1; 426 return 1;
427} 427}
428 428
429void 429static void
430trigger_move (object *op, int state, object *originator) /* 1 down and 0 up */ 430trigger_move (object *op, int state, object *originator) /* 1 down and 0 up */
431{ 431{
432 op->stats.wc = state; 432 op->stats.wc = state;
433 433
434 if (state) 434 if (state)
460int 460int
461check_trigger (object *op, object *cause, object *originator) 461check_trigger (object *op, object *cause, object *originator)
462{ 462{
463 object *tmp; 463 object *tmp;
464 int push = 0, tot = 0; 464 int push = 0, tot = 0;
465 int in_movement = op->stats.wc || op->speed; 465 int in_movement = op->stats.wc || op->has_active_speed ();
466 466
467 switch (op->type) 467 switch (op->type)
468 { 468 {
469 case TRIGGER_BUTTON: 469 case TRIGGER_BUTTON:
470 if (op->weight > 0) 470 if (op->weight > 0)
562 op->last_sp = -op->last_sp; 562 op->last_sp = -op->last_sp;
563 } 563 }
564 else 564 else
565 { 565 {
566 /* for trigger altar with last_sp, the ON/OFF 566 /* for trigger altar with last_sp, the ON/OFF
567 * status (-> +/- value) is "simulated": 567 * status (-> +/- value) is "simulated":
568 */ 568 */
569 op->value = !op->value; 569 op->value = !op->value;
570 trigger_move (op, 1, cause); 570 trigger_move (op, 1, cause);
571 op->last_sp = -op->last_sp; 571 op->last_sp = -op->last_sp;
572 op->value = !op->value; 572 op->value = !op->value;
586 } 586 }
587 587
588 /* If trigger_altar has "last_sp > 0" set on the map, 588 /* If trigger_altar has "last_sp > 0" set on the map,
589 * it will push the connected value only once per sacrifice. 589 * it will push the connected value only once per sacrifice.
590 * Otherwise (default), the connected value will be 590 * Otherwise (default), the connected value will be
591 * pushed twice: First by sacrifice, second by reset! -AV 591 * pushed twice: First by sacrifice, second by reset! -AV
592 */ 592 */
593 if (!op->last_sp) 593 if (!op->last_sp)
594 trigger_move (op, 0, cause); 594 trigger_move (op, 0, cause);
595 else 595 else
596 { 596 {
739 return obp; 739 return obp;
740 740
741 return 0; 741 return 0;
742} 742}
743 743
744/* This routine makes monsters who are 744/* This routine makes monsters who are
745 * standing on the 'mood floor' change their 745 * standing on the 'mood floor' change their
746 * disposition if it is different. 746 * disposition if it is different.
747 * If floor is to be triggered must have 747 * If floor is to be triggered must have
748 * a speed of zero (default is 1 for all 748 * a speed of zero (default is 1 for all
749 * but the charm floor type). 749 * but the charm floor type).
750 * by b.t. thomas@nomad.astro.psu.edu 750 * by b.t. thomas@nomad.astro.psu.edu
751 */ 751 */
761 return; 761 return;
762 762
763 object *tmp; 763 object *tmp;
764 764
765 for (tmp = ms.top; tmp; tmp = tmp->below) 765 for (tmp = ms.top; tmp; tmp = tmp->below)
766 if (QUERY_FLAG (tmp, FLAG_MONSTER)) 766 if (tmp->flag [FLAG_MONSTER])
767 break; 767 break;
768 768
769 /* doesn't effect players, and if there is a player on this space, won't also 769 /* doesn't effect players, and if there is a player on this space, won't also
770 * be a monster here. 770 * be a monster here.
771 */ 771 */
774 return; 774 return;
775 775
776 switch (op->last_sp) 776 switch (op->last_sp)
777 { 777 {
778 case 0: /* furious--make all monsters mad */ 778 case 0: /* furious--make all monsters mad */
779 if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) 779 if (tmp->flag [FLAG_UNAGGRESSIVE])
780 CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE); 780 tmp->clr_flag (FLAG_UNAGGRESSIVE);
781 781
782 if (QUERY_FLAG (tmp, FLAG_FRIENDLY)) 782 if (tmp->flag [FLAG_FRIENDLY])
783 { 783 {
784 tmp->attack_movement = 0; 784 tmp->attack_movement = 0;
785 /* lots of checks here, but want to make sure we don't 785 /* lots of checks here, but want to make sure we don't
786 * dereference a null value 786 * dereference a null value
787 */ 787 */
796 remove_friendly_object (tmp); 796 remove_friendly_object (tmp);
797 } 797 }
798 break; 798 break;
799 799
800 case 1: /* angry -- get neutral monsters mad */ 800 case 1: /* angry -- get neutral monsters mad */
801 if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (tmp, FLAG_FRIENDLY)) 801 if (tmp->flag [FLAG_UNAGGRESSIVE] && !tmp->flag [FLAG_FRIENDLY])
802 CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE); 802 tmp->clr_flag (FLAG_UNAGGRESSIVE);
803 break; 803 break;
804 804
805 case 2: /* calm -- pacify unfriendly monsters */ 805 case 2: /* calm -- pacify unfriendly monsters */
806 SET_FLAG (tmp, FLAG_UNAGGRESSIVE); 806 tmp->set_flag (FLAG_UNAGGRESSIVE);
807 break; 807 break;
808 808
809 case 3: /* make all monsters fall asleep */ 809 case 3: /* make all monsters fall asleep */
810 SET_FLAG (tmp, FLAG_SLEEP); 810 tmp->set_flag (FLAG_SLEEP);
811 break; 811 break;
812 812
813 case 4: /* charm all monsters */ 813 case 4: /* charm all monsters */
814 if (op == source) 814 if (op == source)
815 break; /* only if 'connected' */ 815 break; /* only if 'connected' */
816 816
817 if (object *pl = source->ms ().player ()) 817 if (object *pl = source->ms ().player ())
818 { 818 {
819 tmp->set_owner (pl); 819 tmp->set_owner (pl);
820 SET_FLAG (tmp, FLAG_MONSTER); 820 tmp->set_flag (FLAG_MONSTER);
821 821
822 tmp->stats.exp = 0; 822 tmp->stats.exp = 0;
823 823
824 add_friendly_object (tmp); 824 add_friendly_object (tmp);
825 tmp->attack_movement = PETMOVE; 825 tmp->attack_movement = PETMOVE;
826 } 826 }
827 break; 827 break;
828 828
829 case 6: // kill monsters 829 case 6: // kill monsters
830 if (!QUERY_FLAG (tmp, FLAG_FRIENDLY)) 830 if (!tmp->flag [FLAG_FRIENDLY])
831 break; 831 break;
832 832
833 // FALL THROUGH 833 // FALL THROUGH
834 case 5: // kill all alives 834 case 5: // kill all alives
835 if (!tmp->flag [FLAG_PRECIOUS]) 835 if (!tmp->flag [FLAG_PRECIOUS])
875 return tmp; 875 return tmp;
876 } 876 }
877 return NULL; 877 return NULL;
878} 878}
879 879
880/* check_inv(), a function to search the inventory, 880/* check_inv(), a function to search the inventory,
881 * of a player and then based on a set of conditions, 881 * of a player and then based on a set of conditions,
882 * the square will activate connected items. 882 * the square will activate connected items.
883 * Monsters can't trigger this square (for now) 883 * Monsters can't trigger this square (for now)
884 * Values are: last_sp = 1/0 obj/no obj triggers 884 * Values are: last_sp = 1/0 obj/no obj triggers
885 * last_heal = 1/0 remove/dont remove obj if triggered 885 * last_heal = 1/0 remove/dont remove obj if triggered
886 * -b.t. (thomas@nomad.astro.psu.edu 886 * -b.t. (thomas@nomad.astro.psu.edu
887 * 887 *
888 * Tue Dec 19 15:34:00 CET 2006 elmex: changed the function to ignore op 888 * Tue Dec 19 15:34:00 CET 2006 elmex: changed the function to ignore op
889 * because the check-inventory semantic essentially only applies when 889 * because the check-inventory semantic essentially only applies when
890 * something is above the inventory checker. 890 * something is above the inventory checker.
891 * The semantic prior this change was: trigger if something has moved on or off 891 * The semantic prior this change was: trigger if something has moved on or off
894 * away, and then leaves the inventory checker. That would've caused an always-enabled 894 * away, and then leaves the inventory checker. That would've caused an always-enabled
895 * state in the inventory checker. This won't happen anymore now. 895 * state in the inventory checker. This won't happen anymore now.
896 * 896 *
897 * Wed Jan 10 11:34:26 CET 2007 elmex: fixed this function, we now check 897 * Wed Jan 10 11:34:26 CET 2007 elmex: fixed this function, we now check
898 * whether op is on this mapspace or not, because the value (1|0) depends 898 * whether op is on this mapspace or not, because the value (1|0) depends
899 * on this information. also make sure to only push_button if op has 899 * on this information. also make sure to only push_button if op has
900 * a matching item (because when we do a push_button with value=0 timed gates 900 * a matching item (because when we do a push_button with value=0 timed gates
901 * will still open)! (i hope i got the semantics right this time) 901 * will still open)! (i hope i got the semantics right this time)
902 * 902 *
903 */ 903 */
904void 904void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines