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.14 by root, Wed Dec 13 03:28:42 2006 UTC vs.
Revision 1.21 by root, Sat Dec 30 10:16:10 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;
278 update_object (op, UP_OBJ_FACE); 273 update_object (op, UP_OBJ_FACE);
279 push_button (op); /* Make all other buttons the same */ 274 push_button (op); /* Make all other buttons the same */
280 } 275 }
281} 276}
282 277
283/*
284 * Updates every button on the map (by calling update_button() for them).
285 */
286
287void
288update_buttons (maptile *m)
289{
290 objectlink *ol;
291 oblinkpt *obp;
292
293 for (obp = m->buttons; obp; obp = obp->next)
294 for (ol = obp->link; ol; ol = ol->next)
295 {
296 if (!ol->ob)
297 {
298 LOG (llevError, "Internal error in update_button (%s (%dx%d), connected %ld).\n",
299 ol->ob ? (const char *) ol->ob->name : "null", ol->ob ? ol->ob->x : -1, ol->ob ? ol->ob->y : -1, obp->value);
300 continue;
301 }
302
303 if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL)
304 {
305 update_button (ol->ob);
306 break;
307 }
308 }
309}
310
311void 278void
312use_trigger (object *op) 279use_trigger (object *op)
313{ 280{
314
315 /* Toggle value */ 281 /* Toggle value */
316 op->value = !op->value; 282 op->value = !op->value;
317 push_button (op); 283 push_button (op);
318} 284}
319 285
320/* 286/*
321 * Note: animate_object should be used instead of this, 287 * Note: animate_object should be used instead of this,
322 * but it can't handle animations in the 8 directions 288 * but it can't handle animations in the 8 directions
323 */ 289 */
324
325void 290void
326animate_turning (object *op) /* only one part objects */ 291animate_turning (object *op) /* only one part objects */
327{ 292{
328 if (++op->state >= NUM_ANIMATIONS (op) / 8) 293 if (++op->state >= NUM_ANIMATIONS (op) / 8)
329 op->state = 0; 294 op->state = 0;
354 ARCH_SACRIFICE (altar) == sacrifice->name || 319 ARCH_SACRIFICE (altar) == sacrifice->name ||
355 ARCH_SACRIFICE (altar) == sacrifice->slaying || 320 ARCH_SACRIFICE (altar) == sacrifice->slaying ||
356 (!strcmp (ARCH_SACRIFICE (altar), query_base_name (sacrifice, 0)))) 321 (!strcmp (ARCH_SACRIFICE (altar), query_base_name (sacrifice, 0))))
357 && NROF_SACRIFICE (altar) <= (sacrifice->nrof ? sacrifice->nrof : 1)) 322 && NROF_SACRIFICE (altar) <= (sacrifice->nrof ? sacrifice->nrof : 1))
358 return 1; 323 return 1;
324
359 if (strcmp (ARCH_SACRIFICE (altar), "money") == 0 325 if (strcmp (ARCH_SACRIFICE (altar), "money") == 0
360 && sacrifice->type == MONEY && sacrifice->nrof * sacrifice->value >= NROF_SACRIFICE (altar)) 326 && sacrifice->type == MONEY && sacrifice->nrof * sacrifice->value >= NROF_SACRIFICE (altar))
361 return 1; 327 return 1;
362 } 328 }
329
363 return 0; 330 return 0;
364} 331}
365 332
366/* 333/*
367 * operate_altar checks if sacrifice was accepted and removes sacrificed 334 * operate_altar checks if sacrifice was accepted and removes sacrificed
414{ 381{
415 op->stats.wc = state; 382 op->stats.wc = state;
416 if (state) 383 if (state)
417 { 384 {
418 use_trigger (op); 385 use_trigger (op);
419 if (op->stats.exp > 0) /* check sanity */ 386 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; 387 op->speed_left = -1;
425 } 388 }
426 else 389 else
427 { 390 {
428 use_trigger (op); 391 use_trigger (op);
429 op->speed = 0; 392 op->set_speed (0);
430 update_ob_speed (op);
431 } 393 }
432} 394}
433 395
434 396
435/* 397/*
570 trigger_move (op, 0); 532 trigger_move (op, 0);
571 else 533 else
572 { 534 {
573 op->stats.wc = 0; 535 op->stats.wc = 0;
574 op->value = !op->value; 536 op->value = !op->value;
575 op->speed = 0; 537 op->set_speed (0);
576 update_ob_speed (op);
577 } 538 }
578 } 539 }
579 return 0; 540 return 0;
580 541
581 case TRIGGER: 542 case TRIGGER:
582 if (cause) 543 if (cause)
583 { 544 {
584 if (in_movement) 545 if (in_movement)
585 return 0; 546 return 0;
547
586 push = 1; 548 push = 1;
587 } 549 }
550
588 if (NUM_ANIMATIONS (op) > 1) 551 if (NUM_ANIMATIONS (op) > 1)
589 { 552 {
590 SET_ANIMATION (op, push); 553 SET_ANIMATION (op, push);
591 update_object (op, UP_OBJ_FACE); 554 update_object (op, UP_OBJ_FACE);
592 } 555 }
556
593 trigger_move (op, push); 557 trigger_move (op, push);
594 return 1; 558 return 1;
595 559
596 default: 560 default:
597 LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type); 561 LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type);
608 if (!map) 572 if (!map)
609 { 573 {
610 LOG (llevError, "Tried to add button-link without map.\n"); 574 LOG (llevError, "Tried to add button-link without map.\n");
611 return; 575 return;
612 } 576 }
613 if (!editor) 577
614 button->path_attuned = connected; /* peterm: I need this so I can rebuild 578 button->path_attuned = connected; /* peterm: I need this so I can rebuild
615 a connected map from a template map. */ 579 a connected map from a template map. */
616
617/* LOG(llevDebug,"adding button %s (%d)\n", button->name, connected);*/
618 580
619 SET_FLAG (button, FLAG_IS_LINKED); 581 SET_FLAG (button, FLAG_IS_LINKED);
620 582
621 ol->ob = button; 583 ol->ob = button;
622 584
623 for (obp = map->buttons; obp && obp->value != connected; obp = obp->next); 585 for (obp = map->buttons; obp && obp->value != connected; obp = obp->next)
586 ;
624 587
625 if (obp) 588 if (obp)
626 { 589 {
627 ol->next = obp->link; 590 ol->next = obp->link;
628 obp->link = ol; 591 obp->link = ol;
792 break; 755 break;
793 case 4: /* charm all monsters */ 756 case 4: /* charm all monsters */
794 if (op == source) 757 if (op == source)
795 break; /* only if 'connected' */ 758 break; /* only if 'connected' */
796 759
797 for (tmp2 = get_map_ob (source->map, source->x, source->y); /* finding an owner */ 760 for (tmp2 = GET_MAP_OB (source->map, source->x, source->y); /* finding an owner */
798 tmp2->type != PLAYER; tmp2 = tmp2->above) 761 tmp2->type != PLAYER; tmp2 = tmp2->above)
799 if (tmp2->above == NULL) 762 if (tmp2->above == NULL)
800 break; 763 break;
801 764
802 if (tmp2->type != PLAYER) 765 if (tmp2->type != PLAYER)
803 break; 766 break;
767
804 tmp->set_owner (tmp2); 768 tmp->set_owner (tmp2);
805 SET_FLAG (tmp, FLAG_MONSTER); 769 SET_FLAG (tmp, FLAG_MONSTER);
770
806 tmp->stats.exp = 0; 771 tmp->stats.exp = 0;
807 SET_FLAG (tmp, FLAG_FRIENDLY); 772 SET_FLAG (tmp, FLAG_FRIENDLY);
773
808 add_friendly_object (tmp); 774 add_friendly_object (tmp);
809 tmp->attack_movement = PETMOVE; 775 tmp->attack_movement = PETMOVE;
810 break; 776 break;
811 777
812 default: 778 default:
818 * It will descend through containers to find the object. 784 * It will descend through containers to find the object.
819 * slaying = match object slaying flag 785 * slaying = match object slaying flag
820 * race = match object archetype name flag 786 * race = match object archetype name flag
821 * hp = match object type (excpt type '0'== PLAYER) 787 * hp = match object type (excpt type '0'== PLAYER)
822 */ 788 */
823
824object * 789object *
825check_inv_recursive (object *op, const object *trig) 790check_inv_recursive (object *op, const object *trig)
826{ 791{
827 object *tmp, *ret = NULL; 792 object *tmp, *ret = NULL;
828 793
829 /* First check the object itself. */ 794 /* First check the object itself. */
830 if ((trig->stats.hp && (op->type == trig->stats.hp)) 795 if ((trig->stats.hp && (op->type == trig->stats.hp))
831 || (trig->slaying && (op->slaying == trig->slaying)) || (trig->race && (op->arch->name == trig->race))) 796 || (trig->slaying && (op->slaying == trig->slaying))
797 || (trig->race && (op->arch->name == trig->race)))
832 return op; 798 return op;
833 799
834 for (tmp = op->inv; tmp; tmp = tmp->below) 800 for (tmp = op->inv; tmp; tmp = tmp->below)
835 { 801 {
836 if (tmp->inv) 802 if (tmp->inv)
838 ret = check_inv_recursive (tmp, trig); 804 ret = check_inv_recursive (tmp, trig);
839 if (ret) 805 if (ret)
840 return ret; 806 return ret;
841 } 807 }
842 else if ((trig->stats.hp && (tmp->type == trig->stats.hp)) 808 else if ((trig->stats.hp && (tmp->type == trig->stats.hp))
843 || (trig->slaying && (tmp->slaying == trig->slaying)) || (trig->race && (tmp->arch->name == trig->race))) 809 || (trig->slaying && (tmp->slaying == trig->slaying))
810 || (trig->race && (tmp->arch->name == trig->race)))
844 return tmp; 811 return tmp;
845 } 812 }
846 return NULL; 813 return NULL;
847} 814}
848 815
851 * the square will activate connected items. 818 * the square will activate connected items.
852 * Monsters can't trigger this square (for now) 819 * Monsters can't trigger this square (for now)
853 * Values are: last_sp = 1/0 obj/no obj triggers 820 * Values are: last_sp = 1/0 obj/no obj triggers
854 * last_heal = 1/0 remove/dont remove obj if triggered 821 * last_heal = 1/0 remove/dont remove obj if triggered
855 * -b.t. (thomas@nomad.astro.psu.edu 822 * -b.t. (thomas@nomad.astro.psu.edu
856 */ 823 *
857 824 * Tue Dec 19 15:34:00 CET 2006 elmex: changed the function to ignore op
825 * because the check-inventory semantic essentially only applies when
826 * something is above the inventory checker.
827 * The semantic prior this change was: trigger if something has moved on or off
828 * and has a matching item. Imagine what happens if someone steps on the inventory
829 * checker with a matching item, has it, activates the connection, throws the item
830 * away, and then leaves the inventory checker. That would've caused an always-enabled
831 * state in the inventory checker. This won't happen anymore now.
832 *
833 */
858void 834void
859check_inv (object *op, object *trig) 835check_inv (object *op, object *trig)
860{ 836{
861 object *match; 837 trig->value = 0; // deactivate if none of the following conditions apply
862 838
863 if (op->type != PLAYER) 839 if (object *pl = trig->ms ().player ())
864 return; 840 {
865 match = check_inv_recursive (op, trig); 841 object *match = check_inv_recursive (pl, trig);
866 if (match && trig->last_sp) 842
867 { 843 if (match && trig->last_sp) // match == having
844 {
868 if (trig->last_heal) 845 if (trig->last_heal)
869 decrease_ob (match); 846 decrease_ob (match);
870 use_trigger (trig);
871 }
872 else if (!match && !trig->last_sp)
873 use_trigger (trig);
874}
875 847
848 trig->value = 1;
849 }
850 else if (!match && !trig->last_sp) // match == not having
851 trig->value = 1;
852 }
853
854 push_button (trig);
855}
856

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines