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.18 by root, Thu Dec 21 01:33:49 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/*
277 update_object (op, UP_OBJ_FACE); 273 update_object (op, UP_OBJ_FACE);
278 push_button (op); /* Make all other buttons the same */ 274 push_button (op); /* Make all other buttons the same */
279 } 275 }
280} 276}
281 277
282/*
283 * Updates every button on the map (by calling update_button() for them).
284 */
285
286void
287update_buttons (maptile *m)
288{
289 objectlink *ol;
290 oblinkpt *obp;
291
292 for (obp = m->buttons; obp; obp = obp->next)
293 for (ol = obp->link; ol; ol = ol->next)
294 {
295 if (!ol->ob)
296 {
297 LOG (llevError, "Internal error in update_button (%s (%dx%d), connected %ld).\n",
298 ol->ob ? (const char *) ol->ob->name : "null", ol->ob ? ol->ob->x : -1, ol->ob ? ol->ob->y : -1, obp->value);
299 continue;
300 }
301
302 if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL)
303 {
304 update_button (ol->ob);
305 break;
306 }
307 }
308}
309
310void 278void
311use_trigger (object *op) 279use_trigger (object *op)
312{ 280{
313
314 /* Toggle value */ 281 /* Toggle value */
315 op->value = !op->value; 282 op->value = !op->value;
316 push_button (op); 283 push_button (op);
317} 284}
318 285
319/* 286/*
320 * Note: animate_object should be used instead of this, 287 * Note: animate_object should be used instead of this,
321 * but it can't handle animations in the 8 directions 288 * but it can't handle animations in the 8 directions
322 */ 289 */
323
324void 290void
325animate_turning (object *op) /* only one part objects */ 291animate_turning (object *op) /* only one part objects */
326{ 292{
327 if (++op->state >= NUM_ANIMATIONS (op) / 8) 293 if (++op->state >= NUM_ANIMATIONS (op) / 8)
328 op->state = 0; 294 op->state = 0;
415{ 381{
416 op->stats.wc = state; 382 op->stats.wc = state;
417 if (state) 383 if (state)
418 { 384 {
419 use_trigger (op); 385 use_trigger (op);
420 if (op->stats.exp > 0) /* check sanity */ 386 op->set_speed (op->stats.exp > 0 ? 1. / op->stats.exp : 1.);
421 op->speed = 1.0 / op->stats.exp;
422 else
423 op->speed = 1.0;
424 update_ob_speed (op);
425 op->speed_left = -1; 387 op->speed_left = -1;
426 } 388 }
427 else 389 else
428 { 390 {
429 use_trigger (op); 391 use_trigger (op);
430 op->speed = 0; 392 op->set_speed (0);
431 update_ob_speed (op);
432 } 393 }
433} 394}
434 395
435 396
436/* 397/*
571 trigger_move (op, 0); 532 trigger_move (op, 0);
572 else 533 else
573 { 534 {
574 op->stats.wc = 0; 535 op->stats.wc = 0;
575 op->value = !op->value; 536 op->value = !op->value;
576 op->speed = 0; 537 op->set_speed (0);
577 update_ob_speed (op);
578 } 538 }
579 } 539 }
580 return 0; 540 return 0;
581 541
582 case TRIGGER: 542 case TRIGGER:
583 if (cause) 543 if (cause)
584 { 544 {
585 if (in_movement) 545 if (in_movement)
586 return 0; 546 return 0;
547
587 push = 1; 548 push = 1;
588 } 549 }
550
589 if (NUM_ANIMATIONS (op) > 1) 551 if (NUM_ANIMATIONS (op) > 1)
590 { 552 {
591 SET_ANIMATION (op, push); 553 SET_ANIMATION (op, push);
592 update_object (op, UP_OBJ_FACE); 554 update_object (op, UP_OBJ_FACE);
593 } 555 }
556
594 trigger_move (op, push); 557 trigger_move (op, push);
595 return 1; 558 return 1;
596 559
597 default: 560 default:
598 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);
609 if (!map) 572 if (!map)
610 { 573 {
611 LOG (llevError, "Tried to add button-link without map.\n"); 574 LOG (llevError, "Tried to add button-link without map.\n");
612 return; 575 return;
613 } 576 }
614 if (!editor) 577
615 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
616 a connected map from a template map. */ 579 a connected map from a template map. */
617
618/* LOG(llevDebug,"adding button %s (%d)\n", button->name, connected);*/
619 580
620 SET_FLAG (button, FLAG_IS_LINKED); 581 SET_FLAG (button, FLAG_IS_LINKED);
621 582
622 ol->ob = button; 583 ol->ob = button;
623 584
624 for (obp = map->buttons; obp && obp->value != connected; obp = obp->next); 585 for (obp = map->buttons; obp && obp->value != connected; obp = obp->next)
586 ;
625 587
626 if (obp) 588 if (obp)
627 { 589 {
628 ol->next = obp->link; 590 ol->next = obp->link;
629 obp->link = ol; 591 obp->link = ol;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines