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.19 by root, Mon Dec 25 11:25:49 2006 UTC vs.
Revision 1.24 by elmex, Tue Jan 9 16:38:23 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
3 3
4 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 Copyright (C) 1992 Frank Tore Johansen
6 7
7 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
67 switch (tmp->type) 68 switch (tmp->type)
68 { 69 {
69 case GATE: 70 case GATE:
70 case HOLE: 71 case HOLE:
71 tmp->value = tmp->stats.maxsp ? !state : state; 72 tmp->value = tmp->stats.maxsp ? !state : state;
72 tmp->speed = 0.5; 73 tmp->set_speed (0.5);
73 update_ob_speed (tmp);
74 break; 74 break;
75 75
76 case CF_HANDLE: 76 case CF_HANDLE:
77 SET_ANIMATION (tmp, (tmp->value = tmp->stats.maxsp ? !state : state)); 77 SET_ANIMATION (tmp, (tmp->value = tmp->stats.maxsp ? !state : state));
78 update_object (tmp, UP_OBJ_FACE); 78 update_object (tmp, UP_OBJ_FACE);
103 case MOOD_FLOOR: 103 case MOOD_FLOOR:
104 do_mood_floor (tmp, source); 104 do_mood_floor (tmp, source);
105 break; 105 break;
106 106
107 case TIMED_GATE: 107 case TIMED_GATE:
108 tmp->speed = tmp->arch->clone.speed; 108 tmp->set_speed (tmp->arch->clone.speed);
109 update_ob_speed (tmp); /* original values */
110 tmp->value = tmp->arch->clone.value; 109 tmp->value = tmp->arch->clone.value;
111 tmp->stats.sp = 1; 110 tmp->stats.sp = 1;
112 tmp->stats.hp = tmp->stats.maxhp; 111 tmp->stats.hp = tmp->stats.maxhp;
113 /* Handle multipart gates. We copy the value for the other parts 112 /* Handle multipart gates. We copy the value for the other parts
114 * from the head - this ensures that the data will consistent 113 * from the head - this ensures that the data will consistent
115 */ 114 */
116 for (tmp = tmp->more; tmp != NULL; tmp = tmp->more) 115 for (tmp = tmp->more; tmp; tmp = tmp->more)
117 { 116 {
118 tmp->speed = tmp->head->speed;
119 tmp->value = tmp->head->value; 117 tmp->value = tmp->head->value;
120 tmp->stats.sp = tmp->head->stats.sp; 118 tmp->stats.sp = tmp->head->stats.sp;
121 tmp->stats.hp = tmp->head->stats.hp; 119 tmp->stats.hp = tmp->head->stats.hp;
122 update_ob_speed (tmp); 120 tmp->set_speed (tmp->head->speed);
123 } 121 }
124 break; 122 break;
125 123
126 case DIRECTOR: 124 case DIRECTOR:
127 case FIREWALL: 125 case FIREWALL:
276 update_object (op, UP_OBJ_FACE); 274 update_object (op, UP_OBJ_FACE);
277 push_button (op); /* Make all other buttons the same */ 275 push_button (op); /* Make all other buttons the same */
278 } 276 }
279} 277}
280 278
281/*
282 * Updates every button on the map (by calling update_button() for them).
283 */
284
285void
286update_buttons (maptile *m)
287{
288 objectlink *ol;
289 oblinkpt *obp;
290
291 for (obp = m->buttons; obp; obp = obp->next)
292 for (ol = obp->link; ol; ol = ol->next)
293 {
294 if (!ol->ob)
295 {
296 LOG (llevError, "Internal error in update_button (%s (%dx%d), connected %ld).\n",
297 ol->ob ? (const char *) ol->ob->name : "null", ol->ob ? ol->ob->x : -1, ol->ob ? ol->ob->y : -1, obp->value);
298 continue;
299 }
300
301 if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL)
302 {
303 update_button (ol->ob);
304 break;
305 }
306 }
307}
308
309void 279void
310use_trigger (object *op) 280use_trigger (object *op)
311{ 281{
312
313 /* Toggle value */ 282 /* Toggle value */
314 op->value = !op->value; 283 op->value = !op->value;
315 push_button (op); 284 push_button (op);
316} 285}
317 286
318/* 287/*
319 * Note: animate_object should be used instead of this, 288 * Note: animate_object should be used instead of this,
320 * but it can't handle animations in the 8 directions 289 * but it can't handle animations in the 8 directions
321 */ 290 */
322
323void 291void
324animate_turning (object *op) /* only one part objects */ 292animate_turning (object *op) /* only one part objects */
325{ 293{
326 if (++op->state >= NUM_ANIMATIONS (op) / 8) 294 if (++op->state >= NUM_ANIMATIONS (op) / 8)
327 op->state = 0; 295 op->state = 0;
414{ 382{
415 op->stats.wc = state; 383 op->stats.wc = state;
416 if (state) 384 if (state)
417 { 385 {
418 use_trigger (op); 386 use_trigger (op);
419 if (op->stats.exp > 0) /* check sanity */ 387 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; 388 op->speed_left = -1;
425 } 389 }
426 else 390 else
427 { 391 {
428 use_trigger (op); 392 use_trigger (op);
429 op->speed = 0; 393 op->set_speed (0);
430 update_ob_speed (op);
431 } 394 }
432} 395}
433 396
434 397
435/* 398/*
570 trigger_move (op, 0); 533 trigger_move (op, 0);
571 else 534 else
572 { 535 {
573 op->stats.wc = 0; 536 op->stats.wc = 0;
574 op->value = !op->value; 537 op->value = !op->value;
575 op->speed = 0; 538 op->set_speed (0);
576 update_ob_speed (op);
577 } 539 }
578 } 540 }
579 return 0; 541 return 0;
580 542
581 case TRIGGER: 543 case TRIGGER:
582 if (cause) 544 if (cause)
583 { 545 {
584 if (in_movement) 546 if (in_movement)
585 return 0; 547 return 0;
548
586 push = 1; 549 push = 1;
587 } 550 }
551
588 if (NUM_ANIMATIONS (op) > 1) 552 if (NUM_ANIMATIONS (op) > 1)
589 { 553 {
590 SET_ANIMATION (op, push); 554 SET_ANIMATION (op, push);
591 update_object (op, UP_OBJ_FACE); 555 update_object (op, UP_OBJ_FACE);
592 } 556 }
557
593 trigger_move (op, push); 558 trigger_move (op, push);
594 return 1; 559 return 1;
595 560
596 default: 561 default:
597 LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type); 562 LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type);
803 768
804 tmp->set_owner (tmp2); 769 tmp->set_owner (tmp2);
805 SET_FLAG (tmp, FLAG_MONSTER); 770 SET_FLAG (tmp, FLAG_MONSTER);
806 771
807 tmp->stats.exp = 0; 772 tmp->stats.exp = 0;
808 SET_FLAG (tmp, FLAG_FRIENDLY);
809 773
810 add_friendly_object (tmp); 774 add_friendly_object (tmp);
811 tmp->attack_movement = PETMOVE; 775 tmp->attack_movement = PETMOVE;
812 break; 776 break;
813 777
868 * 832 *
869 */ 833 */
870void 834void
871check_inv (object *op, object *trig) 835check_inv (object *op, object *trig)
872{ 836{
837 sint32 prev_state = trig->value;
873 trig->value = 0; // deactivate if none of the following conditions apply 838 trig->value = 0; // deactivate if none of the following conditions apply
874 839
875 if (object *pl = trig->ms ().player ()) 840 if (object *pl = trig->ms ().player ())
876 { 841 {
877 object *match = check_inv_recursive (pl, trig); 842 object *match = check_inv_recursive (pl, trig);
885 } 850 }
886 else if (!match && !trig->last_sp) // match == not having 851 else if (!match && !trig->last_sp) // match == not having
887 trig->value = 1; 852 trig->value = 1;
888 } 853 }
889 854
855 if (prev_state != trig->value)
890 push_button (trig); 856 push_button (trig);
891} 857}
892 858

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines