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.27 by pippijn, Mon Jan 15 21:06:18 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
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 21 *
21 The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 23 */
23 24
24#include <global.h> 25#include <global.h>
25#include <funcpoint.h> 26#include <funcpoint.h>
26 27
27/* 28/*
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
864 * and has a matching item. Imagine what happens if someone steps on the inventory 828 * and has a matching item. Imagine what happens if someone steps on the inventory
865 * checker with a matching item, has it, activates the connection, throws the item 829 * checker with a matching item, has it, activates the connection, throws the item
866 * away, and then leaves the inventory checker. That would've caused an always-enabled 830 * away, and then leaves the inventory checker. That would've caused an always-enabled
867 * state in the inventory checker. This won't happen anymore now. 831 * state in the inventory checker. This won't happen anymore now.
868 * 832 *
833 * Wed Jan 10 11:34:26 CET 2007 elmex: fixed this function, we now check
834 * whether op is on this mapspace or not, because the value (1|0) depends
835 * on this information. also make sure to only push_button if op has
836 * a matching item (because when we do a push_button with value=0 timed gates
837 * will still open)! (i hope i got the semantics right this time)
838 *
869 */ 839 */
870void 840void
871check_inv (object *op, object *trig) 841check_inv (object *op, object *trig)
872{ 842{
873 trig->value = 0; // deactivate if none of the following conditions apply 843 trig->value = 0; // deactivate if none of the following conditions apply
874 844
875 if (object *pl = trig->ms ().player ()) 845 object *pl = trig->ms ().player ();
876 {
877 object *match = check_inv_recursive (pl, trig); 846 object *match = check_inv_recursive (op, trig);
878 847
848 // elmex: a note about (pl == op):
849 // if pl == 0 then the player has left this space
850 // if pl != 0 then a player is on this mapspace, but then
851 // we still have to check whether it's the player that triggered
852 // this inv-checker, because if not, then the op left this inv-checker
853 // and we have to set the value to 0
854
879 if (match && trig->last_sp) // match == having 855 if (match && trig->last_sp) // match == having
880 { 856 {
881 if (trig->last_heal) 857 if (trig->last_heal)
882 decrease_ob (match); 858 decrease_ob (match);
883 859
884 trig->value = 1; 860 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left
885 } 861 push_button (trig);
862 }
886 else if (!match && !trig->last_sp) // match == not having 863 else if (!match && !trig->last_sp) // match == not having
887 trig->value = 1;
888 } 864 {
889 865 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left
890 push_button (trig); 866 push_button (trig);
867 }
891} 868}
892 869

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines