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.12 by root, Sun Oct 15 02:16:34 2006 UTC vs.
Revision 1.17 by root, Wed Dec 20 09:14:21 2006 UTC

205 * Updates everything connected with the button op. 205 * Updates everything connected with the button op.
206 * After changing the state of a button, this function must be called 206 * After changing the state of a button, this function must be called
207 * to make sure that all gates and other buttons connected to the 207 * to make sure that all gates and other buttons connected to the
208 * button reacts to the (eventual) change of state. 208 * button reacts to the (eventual) change of state.
209 */ 209 */
210
211void 210void
212update_button (object *op) 211update_button (object *op)
213{ 212{
214 object *ab, *tmp, *head; 213 object *ab, *tmp, *head;
215 int tot, any_down = 0, old_value = op->value; 214 int tot, any_down = 0, old_value = op->value;
354 ARCH_SACRIFICE (altar) == sacrifice->name || 353 ARCH_SACRIFICE (altar) == sacrifice->name ||
355 ARCH_SACRIFICE (altar) == sacrifice->slaying || 354 ARCH_SACRIFICE (altar) == sacrifice->slaying ||
356 (!strcmp (ARCH_SACRIFICE (altar), query_base_name (sacrifice, 0)))) 355 (!strcmp (ARCH_SACRIFICE (altar), query_base_name (sacrifice, 0))))
357 && NROF_SACRIFICE (altar) <= (sacrifice->nrof ? sacrifice->nrof : 1)) 356 && NROF_SACRIFICE (altar) <= (sacrifice->nrof ? sacrifice->nrof : 1))
358 return 1; 357 return 1;
358
359 if (strcmp (ARCH_SACRIFICE (altar), "money") == 0 359 if (strcmp (ARCH_SACRIFICE (altar), "money") == 0
360 && sacrifice->type == MONEY && sacrifice->nrof * sacrifice->value >= NROF_SACRIFICE (altar)) 360 && sacrifice->type == MONEY && sacrifice->nrof * sacrifice->value >= NROF_SACRIFICE (altar))
361 return 1; 361 return 1;
362 } 362 }
363
363 return 0; 364 return 0;
364} 365}
365 366
366/* 367/*
367 * operate_altar checks if sacrifice was accepted and removes sacrificed 368 * operate_altar checks if sacrifice was accepted and removes sacrificed
771 tmp->attack_movement = 0; 772 tmp->attack_movement = 0;
772 /* lots of checks here, but want to make sure we don't 773 /* lots of checks here, but want to make sure we don't
773 * dereference a null value 774 * dereference a null value
774 */ 775 */
775 if (tmp->type == GOLEM && tmp->owner && tmp->owner->type == PLAYER && tmp->owner->contr->ranges[range_golem] == tmp) 776 if (tmp->type == GOLEM && tmp->owner && tmp->owner->type == PLAYER && tmp->owner->contr->ranges[range_golem] == tmp)
776 {
777 tmp->owner->contr->ranges[range_golem] = NULL; 777 tmp->owner->contr->ranges[range_golem] = 0;
778 tmp->owner->contr->golem_count = 0; 778
779 }
780 tmp->owner = 0; 779 tmp->owner = 0;
781 } 780 }
782 break; 781 break;
783 case 1: /* angry -- get neutral monsters mad */ 782 case 1: /* angry -- get neutral monsters mad */
784 if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (tmp, FLAG_FRIENDLY)) 783 if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (tmp, FLAG_FRIENDLY))
794 break; 793 break;
795 case 4: /* charm all monsters */ 794 case 4: /* charm all monsters */
796 if (op == source) 795 if (op == source)
797 break; /* only if 'connected' */ 796 break; /* only if 'connected' */
798 797
799 for (tmp2 = get_map_ob (source->map, source->x, source->y); /* finding an owner */ 798 for (tmp2 = GET_MAP_OB (source->map, source->x, source->y); /* finding an owner */
800 tmp2->type != PLAYER; tmp2 = tmp2->above) 799 tmp2->type != PLAYER; tmp2 = tmp2->above)
801 if (tmp2->above == NULL) 800 if (tmp2->above == NULL)
802 break; 801 break;
803 802
804 if (tmp2->type != PLAYER) 803 if (tmp2->type != PLAYER)
805 break; 804 break;
805
806 set_owner (tmp, tmp2); 806 tmp->set_owner (tmp2);
807 SET_FLAG (tmp, FLAG_MONSTER); 807 SET_FLAG (tmp, FLAG_MONSTER);
808
808 tmp->stats.exp = 0; 809 tmp->stats.exp = 0;
809 SET_FLAG (tmp, FLAG_FRIENDLY); 810 SET_FLAG (tmp, FLAG_FRIENDLY);
811
810 add_friendly_object (tmp); 812 add_friendly_object (tmp);
811 tmp->attack_movement = PETMOVE; 813 tmp->attack_movement = PETMOVE;
812 break; 814 break;
813 815
814 default: 816 default:
820 * It will descend through containers to find the object. 822 * It will descend through containers to find the object.
821 * slaying = match object slaying flag 823 * slaying = match object slaying flag
822 * race = match object archetype name flag 824 * race = match object archetype name flag
823 * hp = match object type (excpt type '0'== PLAYER) 825 * hp = match object type (excpt type '0'== PLAYER)
824 */ 826 */
825
826object * 827object *
827check_inv_recursive (object *op, const object *trig) 828check_inv_recursive (object *op, const object *trig)
828{ 829{
829 object *tmp, *ret = NULL; 830 object *tmp, *ret = NULL;
830 831
831 /* First check the object itself. */ 832 /* First check the object itself. */
832 if ((trig->stats.hp && (op->type == trig->stats.hp)) 833 if ((trig->stats.hp && (op->type == trig->stats.hp))
833 || (trig->slaying && (op->slaying == trig->slaying)) || (trig->race && (op->arch->name == trig->race))) 834 || (trig->slaying && (op->slaying == trig->slaying))
835 || (trig->race && (op->arch->name == trig->race)))
834 return op; 836 return op;
835 837
836 for (tmp = op->inv; tmp; tmp = tmp->below) 838 for (tmp = op->inv; tmp; tmp = tmp->below)
837 { 839 {
838 if (tmp->inv) 840 if (tmp->inv)
840 ret = check_inv_recursive (tmp, trig); 842 ret = check_inv_recursive (tmp, trig);
841 if (ret) 843 if (ret)
842 return ret; 844 return ret;
843 } 845 }
844 else if ((trig->stats.hp && (tmp->type == trig->stats.hp)) 846 else if ((trig->stats.hp && (tmp->type == trig->stats.hp))
845 || (trig->slaying && (tmp->slaying == trig->slaying)) || (trig->race && (tmp->arch->name == trig->race))) 847 || (trig->slaying && (tmp->slaying == trig->slaying))
848 || (trig->race && (tmp->arch->name == trig->race)))
846 return tmp; 849 return tmp;
847 } 850 }
848 return NULL; 851 return NULL;
849} 852}
850 853
853 * the square will activate connected items. 856 * the square will activate connected items.
854 * Monsters can't trigger this square (for now) 857 * Monsters can't trigger this square (for now)
855 * Values are: last_sp = 1/0 obj/no obj triggers 858 * Values are: last_sp = 1/0 obj/no obj triggers
856 * last_heal = 1/0 remove/dont remove obj if triggered 859 * last_heal = 1/0 remove/dont remove obj if triggered
857 * -b.t. (thomas@nomad.astro.psu.edu 860 * -b.t. (thomas@nomad.astro.psu.edu
861 *
862 * Tue Dec 19 15:34:00 CET 2006 elmex: changed the function to ignore op
863 * because the check-inventory semantic essentially only applies when
864 * something is above the inventory checker.
865 * The semantic prior this change was: trigger if something has moved on or off
866 * and has a matching item. Imagine what happens if someone steps on the inventory
867 * checker with a matching item, has it, activates the connection, throws the item
868 * away, and then leaves the inventory checker. That would've caused an always-enabled
869 * state in the inventory checker. This won't happen anymore now.
870 *
858 */ 871 */
859 872
860void 873void
861check_inv (object *op, object *trig) 874check_inv (object *op, object *trig)
862{ 875{
863 object *match; 876 object *match = 0;
864 877
878 trig->value = 0; // deactivate if none of the following conditions apply
879
880 for (object *tmp = trig->above; tmp; tmp = tmp->above)
865 if (op->type != PLAYER) 881 if (tmp->type == PLAYER)
866 return;
867 match = check_inv_recursive (op, trig);
868 if (match && trig->last_sp)
869 { 882 {
883 object *match = check_inv_recursive (tmp, trig);
884
885 if (match && trig->last_sp) // match == having
886 {
870 if (trig->last_heal) 887 if (trig->last_heal)
871 decrease_ob (match); 888 decrease_ob (match);
872 use_trigger (trig); 889
890 trig->value = 1;
891 }
892 else if (!match && !trig->last_sp) // match == not having
893 trig->value = 1;
894
895 break;
873 } 896 }
874 else if (!match && !trig->last_sp)
875 use_trigger (trig);
876}
877 897
898 push_button (trig);
899}
900

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines