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.16 by elmex, Tue Dec 19 15:30:01 2006 UTC vs.
Revision 1.20 by root, Tue Dec 26 08:54:58 2006 UTC

35 * The source argument can be 0 or the source object for this activation. 35 * The source argument can be 0 or the source object for this activation.
36 */ 36 */
37void 37void
38activate_connection_link (objectlink * ol, bool state, object *source = 0) 38activate_connection_link (objectlink * ol, bool state, object *source = 0)
39{ 39{
40 object *tmp = 0;
41
42 for (; ol; ol = ol->next) 40 for (; ol; ol = ol->next)
43 { 41 {
44 if (!ol->ob) 42 if (!ol->ob)
45 { 43 {
46 LOG (llevError, "Internal error in activate_connection_link.\n"); 44 LOG (llevError, "Internal error in activate_connection_link.\n");
55 * re-loaded. As such, just exit this function if that is the case. 53 * re-loaded. As such, just exit this function if that is the case.
56 */ 54 */
57 55
58 if (QUERY_FLAG (ol->ob, FLAG_FREED)) 56 if (QUERY_FLAG (ol->ob, FLAG_FREED))
59 return; 57 return;
58
60 tmp = ol->ob; 59 object *tmp = ol->ob;
61 60
62 /* if the criteria isn't appropriate, don't do anything */ 61 /* if the criteria isn't appropriate, don't do anything */
63 if (state && !QUERY_FLAG (tmp, FLAG_ACTIVATE_ON_PUSH)) 62 if (state && !QUERY_FLAG (tmp, FLAG_ACTIVATE_ON_PUSH))
64 continue; 63 continue;
65 if (!state && !QUERY_FLAG (tmp, FLAG_ACTIVATE_ON_RELEASE)) 64 if (!state && !QUERY_FLAG (tmp, FLAG_ACTIVATE_ON_RELEASE))
66 continue; 65 continue;
67 66
68 switch (tmp->type) 67 switch (tmp->type)
69 { 68 {
70 case GATE: 69 case GATE:
71 case HOLE: 70 case HOLE:
72 tmp->value = tmp->stats.maxsp ? !state : state; 71 tmp->value = tmp->stats.maxsp ? !state : state;
73 tmp->speed = 0.5; 72 tmp->set_speed (0.5);
74 update_ob_speed (tmp);
75 break; 73 break;
76 74
77 case CF_HANDLE: 75 case CF_HANDLE:
78 SET_ANIMATION (tmp, (tmp->value = tmp->stats.maxsp ? !state : state)); 76 SET_ANIMATION (tmp, (tmp->value = tmp->stats.maxsp ? !state : state));
79 update_object (tmp, UP_OBJ_FACE); 77 update_object (tmp, UP_OBJ_FACE);
80 break; 78 break;
81 79
82 case SIGN: 80 case SIGN:
83 if (!tmp->stats.food || tmp->last_eat < tmp->stats.food) 81 if (!tmp->stats.food || tmp->last_eat < tmp->stats.food)
84 { 82 {
85 new_info_map (NDI_UNIQUE | NDI_NAVY, tmp->map, tmp->msg); 83 new_info_map (NDI_UNIQUE | NDI_NAVY, tmp->map, tmp->msg);
86 if (tmp->stats.food) 84 if (tmp->stats.food)
87 tmp->last_eat++; 85 tmp->last_eat++;
88 } 86 }
89 break; 87 break;
90 88
91 case ALTAR: 89 case ALTAR:
92 tmp->value = 1; 90 tmp->value = 1;
93 SET_ANIMATION (tmp, tmp->value); 91 SET_ANIMATION (tmp, tmp->value);
94 update_object (tmp, UP_OBJ_FACE); 92 update_object (tmp, UP_OBJ_FACE);
95 break; 93 break;
96 94
97 case BUTTON: 95 case BUTTON:
98 case PEDESTAL: 96 case PEDESTAL:
99 tmp->value = state; 97 tmp->value = state;
100 SET_ANIMATION (tmp, tmp->value); 98 SET_ANIMATION (tmp, tmp->value);
101 update_object (tmp, UP_OBJ_FACE); 99 update_object (tmp, UP_OBJ_FACE);
102 break; 100 break;
103 101
104 case MOOD_FLOOR: 102 case MOOD_FLOOR:
105 do_mood_floor (tmp, source); 103 do_mood_floor (tmp, source);
106 break; 104 break;
107 105
108 case TIMED_GATE: 106 case TIMED_GATE:
109 tmp->speed = tmp->arch->clone.speed; 107 tmp->set_speed (tmp->arch->clone.speed);
110 update_ob_speed (tmp); /* original values */
111 tmp->value = tmp->arch->clone.value; 108 tmp->value = tmp->arch->clone.value;
112 tmp->stats.sp = 1; 109 tmp->stats.sp = 1;
113 tmp->stats.hp = tmp->stats.maxhp; 110 tmp->stats.hp = tmp->stats.maxhp;
114 /* Handle multipart gates. We copy the value for the other parts 111 /* Handle multipart gates. We copy the value for the other parts
115 * from the head - this ensures that the data will consistent 112 * from the head - this ensures that the data will consistent
116 */ 113 */
117 for (tmp = tmp->more; tmp != NULL; tmp = tmp->more) 114 for (tmp = tmp->more; tmp; tmp = tmp->more)
118 { 115 {
119 tmp->speed = tmp->head->speed;
120 tmp->value = tmp->head->value; 116 tmp->value = tmp->head->value;
121 tmp->stats.sp = tmp->head->stats.sp; 117 tmp->stats.sp = tmp->head->stats.sp;
122 tmp->stats.hp = tmp->head->stats.hp; 118 tmp->stats.hp = tmp->head->stats.hp;
123 update_ob_speed (tmp); 119 tmp->set_speed (tmp->head->speed);
124 } 120 }
125 break; 121 break;
126 122
127 case DIRECTOR: 123 case DIRECTOR:
128 case FIREWALL: 124 case FIREWALL:
129 if (!QUERY_FLAG (tmp, FLAG_ANIMATE) && tmp->type == FIREWALL) 125 if (!QUERY_FLAG (tmp, FLAG_ANIMATE) && tmp->type == FIREWALL)
130 move_firewall (tmp); 126 move_firewall (tmp);
131 else 127 else
132 { 128 {
133 if ((tmp->stats.sp += tmp->stats.maxsp) > 8) /* next direction */ 129 if ((tmp->stats.sp += tmp->stats.maxsp) > 8) /* next direction */
134 tmp->stats.sp = ((tmp->stats.sp - 1) % 8) + 1; 130 tmp->stats.sp = ((tmp->stats.sp - 1) % 8) + 1;
135 animate_turning (tmp); 131 animate_turning (tmp);
136 } 132 }
137 break; 133 break;
138 134
139 case TELEPORTER: 135 case TELEPORTER:
140 move_teleporter (tmp); 136 move_teleporter (tmp);
141 break; 137 break;
142 138
143 case CREATOR: 139 case CREATOR:
144 move_creator (tmp); 140 move_creator (tmp);
145 break; 141 break;
146 142
147 case TRIGGER_MARKER: 143 case TRIGGER_MARKER:
148 move_marker (tmp); 144 move_marker (tmp);
149 break; 145 break;
150 146
151 case DUPLICATOR: 147 case DUPLICATOR:
152 move_duplicator (tmp); 148 move_duplicator (tmp);
153 break; 149 break;
154 } 150 }
155 } 151 }
156} 152}
157 153
158/* 154/*
205 * Updates everything connected with the button op. 201 * Updates everything connected with the button op.
206 * After changing the state of a button, this function must be called 202 * 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 203 * to make sure that all gates and other buttons connected to the
208 * button reacts to the (eventual) change of state. 204 * button reacts to the (eventual) change of state.
209 */ 205 */
210
211void 206void
212update_button (object *op) 207update_button (object *op)
213{ 208{
214 object *ab, *tmp, *head; 209 object *ab, *tmp, *head;
215 int tot, any_down = 0, old_value = op->value; 210 int tot, any_down = 0, old_value = op->value;
354 ARCH_SACRIFICE (altar) == sacrifice->name || 349 ARCH_SACRIFICE (altar) == sacrifice->name ||
355 ARCH_SACRIFICE (altar) == sacrifice->slaying || 350 ARCH_SACRIFICE (altar) == sacrifice->slaying ||
356 (!strcmp (ARCH_SACRIFICE (altar), query_base_name (sacrifice, 0)))) 351 (!strcmp (ARCH_SACRIFICE (altar), query_base_name (sacrifice, 0))))
357 && NROF_SACRIFICE (altar) <= (sacrifice->nrof ? sacrifice->nrof : 1)) 352 && NROF_SACRIFICE (altar) <= (sacrifice->nrof ? sacrifice->nrof : 1))
358 return 1; 353 return 1;
354
359 if (strcmp (ARCH_SACRIFICE (altar), "money") == 0 355 if (strcmp (ARCH_SACRIFICE (altar), "money") == 0
360 && sacrifice->type == MONEY && sacrifice->nrof * sacrifice->value >= NROF_SACRIFICE (altar)) 356 && sacrifice->type == MONEY && sacrifice->nrof * sacrifice->value >= NROF_SACRIFICE (altar))
361 return 1; 357 return 1;
362 } 358 }
359
363 return 0; 360 return 0;
364} 361}
365 362
366/* 363/*
367 * operate_altar checks if sacrifice was accepted and removes sacrificed 364 * operate_altar checks if sacrifice was accepted and removes sacrificed
414{ 411{
415 op->stats.wc = state; 412 op->stats.wc = state;
416 if (state) 413 if (state)
417 { 414 {
418 use_trigger (op); 415 use_trigger (op);
419 if (op->stats.exp > 0) /* check sanity */ 416 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; 417 op->speed_left = -1;
425 } 418 }
426 else 419 else
427 { 420 {
428 use_trigger (op); 421 use_trigger (op);
429 op->speed = 0; 422 op->set_speed (0);
430 update_ob_speed (op);
431 } 423 }
432} 424}
433 425
434 426
435/* 427/*
570 trigger_move (op, 0); 562 trigger_move (op, 0);
571 else 563 else
572 { 564 {
573 op->stats.wc = 0; 565 op->stats.wc = 0;
574 op->value = !op->value; 566 op->value = !op->value;
575 op->speed = 0; 567 op->set_speed (0);
576 update_ob_speed (op);
577 } 568 }
578 } 569 }
579 return 0; 570 return 0;
580 571
581 case TRIGGER: 572 case TRIGGER:
582 if (cause) 573 if (cause)
583 { 574 {
584 if (in_movement) 575 if (in_movement)
585 return 0; 576 return 0;
577
586 push = 1; 578 push = 1;
587 } 579 }
580
588 if (NUM_ANIMATIONS (op) > 1) 581 if (NUM_ANIMATIONS (op) > 1)
589 { 582 {
590 SET_ANIMATION (op, push); 583 SET_ANIMATION (op, push);
591 update_object (op, UP_OBJ_FACE); 584 update_object (op, UP_OBJ_FACE);
592 } 585 }
586
593 trigger_move (op, push); 587 trigger_move (op, push);
594 return 1; 588 return 1;
595 589
596 default: 590 default:
597 LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type); 591 LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type);
608 if (!map) 602 if (!map)
609 { 603 {
610 LOG (llevError, "Tried to add button-link without map.\n"); 604 LOG (llevError, "Tried to add button-link without map.\n");
611 return; 605 return;
612 } 606 }
613 if (!editor) 607
614 button->path_attuned = connected; /* peterm: I need this so I can rebuild 608 button->path_attuned = connected; /* peterm: I need this so I can rebuild
615 a connected map from a template map. */ 609 a connected map from a template map. */
616
617/* LOG(llevDebug,"adding button %s (%d)\n", button->name, connected);*/
618 610
619 SET_FLAG (button, FLAG_IS_LINKED); 611 SET_FLAG (button, FLAG_IS_LINKED);
620 612
621 ol->ob = button; 613 ol->ob = button;
622 614
623 for (obp = map->buttons; obp && obp->value != connected; obp = obp->next); 615 for (obp = map->buttons; obp && obp->value != connected; obp = obp->next)
616 ;
624 617
625 if (obp) 618 if (obp)
626 { 619 {
627 ol->next = obp->link; 620 ol->next = obp->link;
628 obp->link = ol; 621 obp->link = ol;
792 break; 785 break;
793 case 4: /* charm all monsters */ 786 case 4: /* charm all monsters */
794 if (op == source) 787 if (op == source)
795 break; /* only if 'connected' */ 788 break; /* only if 'connected' */
796 789
797 for (tmp2 = get_map_ob (source->map, source->x, source->y); /* finding an owner */ 790 for (tmp2 = GET_MAP_OB (source->map, source->x, source->y); /* finding an owner */
798 tmp2->type != PLAYER; tmp2 = tmp2->above) 791 tmp2->type != PLAYER; tmp2 = tmp2->above)
799 if (tmp2->above == NULL) 792 if (tmp2->above == NULL)
800 break; 793 break;
801 794
802 if (tmp2->type != PLAYER) 795 if (tmp2->type != PLAYER)
803 break; 796 break;
797
804 tmp->set_owner (tmp2); 798 tmp->set_owner (tmp2);
805 SET_FLAG (tmp, FLAG_MONSTER); 799 SET_FLAG (tmp, FLAG_MONSTER);
800
806 tmp->stats.exp = 0; 801 tmp->stats.exp = 0;
807 SET_FLAG (tmp, FLAG_FRIENDLY); 802 SET_FLAG (tmp, FLAG_FRIENDLY);
803
808 add_friendly_object (tmp); 804 add_friendly_object (tmp);
809 tmp->attack_movement = PETMOVE; 805 tmp->attack_movement = PETMOVE;
810 break; 806 break;
811 807
812 default: 808 default:
818 * It will descend through containers to find the object. 814 * It will descend through containers to find the object.
819 * slaying = match object slaying flag 815 * slaying = match object slaying flag
820 * race = match object archetype name flag 816 * race = match object archetype name flag
821 * hp = match object type (excpt type '0'== PLAYER) 817 * hp = match object type (excpt type '0'== PLAYER)
822 */ 818 */
823
824object * 819object *
825check_inv_recursive (object *op, const object *trig) 820check_inv_recursive (object *op, const object *trig)
826{ 821{
827 object *tmp, *ret = NULL; 822 object *tmp, *ret = NULL;
828 823
864 * checker with a matching item, has it, activates the connection, throws the item 859 * checker with a matching item, has it, activates the connection, throws the item
865 * away, and then leaves the inventory checker. That would've caused an always-enabled 860 * away, and then leaves the inventory checker. That would've caused an always-enabled
866 * state in the inventory checker. This won't happen anymore now. 861 * state in the inventory checker. This won't happen anymore now.
867 * 862 *
868 */ 863 */
869
870void 864void
871check_inv (object *op, object *trig) 865check_inv (object *op, object *trig)
872{ 866{
873 object *match = 0;
874
875 trig->value = 0; // deactivate if none of the following conditions apply 867 trig->value = 0; // deactivate if none of the following conditions apply
876 868
877 for (object *tmp = trig->above; tmp; tmp = tmp->above) 869 if (object *pl = trig->ms ().player ())
878 if (tmp->type == PLAYER)
879 { 870 {
880 object *match = check_inv_recursive (tmp, trig); 871 object *match = check_inv_recursive (pl, trig);
881 872
882 if (match && trig->last_sp) // match == having 873 if (match && trig->last_sp) // match == having
883 { 874 {
884 if (trig->last_heal) 875 if (trig->last_heal)
885 decrease_ob (match); 876 decrease_ob (match);
886 877
887 trig->value = 1;
888 }
889 else if (!match && !trig->last_sp) // match == not having
890 trig->value = 1; 878 trig->value = 1;
891
892 break;
893 } 879 }
880 else if (!match && !trig->last_sp) // match == not having
881 trig->value = 1;
882 }
894 883
895 push_button (trig); 884 push_button (trig);
896} 885}
897 886

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines