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.50 by root, Thu Jan 1 11:41:17 2009 UTC vs.
Revision 1.51 by root, Thu Jan 8 03:03:23 2009 UTC

32 * This function takes a objectlink list with all the objects are going to be activated. 32 * This function takes a objectlink list with all the objects are going to be activated.
33 * state is a true/false flag that will actiavte objects that have FLAG_ACTIVATE_ON_PUSH/RELEASE set. 33 * state is a true/false flag that will actiavte objects that have FLAG_ACTIVATE_ON_PUSH/RELEASE set.
34 * The source argument can be 0 or the source object for this activation. 34 * The source argument can be 0 or the source object for this activation.
35 */ 35 */
36void 36void
37activate_connection_link (objectlink * ol, bool state, object *source = 0) 37activate_connection_link (objectlink *ol, bool state, object *source = 0)
38{ 38{
39 for (; ol; ol = ol->next) 39 for (; ol; ol = ol->next)
40 { 40 {
41 if (!ol->ob) 41 if (!ol->ob)
42 { 42 {
111 break; 111 break;
112 112
113 case TIMED_GATE: 113 case TIMED_GATE:
114 if (!tmp->active) 114 if (!tmp->active)
115 tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("trigger_gate")); 115 tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("trigger_gate"));
116
116 tmp->set_speed (tmp->arch->speed); 117 tmp->set_speed (tmp->arch->speed);
117 tmp->value = tmp->arch->value; 118 tmp->value = tmp->arch->value;
118 tmp->stats.sp = 1; 119 tmp->stats.sp = 1;
119 tmp->stats.hp = tmp->stats.maxhp; 120 tmp->stats.hp = tmp->stats.maxhp;
120 /* Handle multipart gates. We copy the value for the other parts 121 /* Handle multipart gates. We copy the value for the other parts
156 break; 157 break;
157 158
158 case DUPLICATOR: 159 case DUPLICATOR:
159 move_duplicator (tmp); 160 move_duplicator (tmp);
160 break; 161 break;
162
163 case MAPSCRIPT:
164 cfperl_mapscript_activate (tmp, source, state);
165 break;
161 } 166 }
162 } 167 }
163} 168}
164 169
165/* 170/*
175 * 180 *
176 */ 181 */
177void 182void
178push_button (object *op) 183push_button (object *op)
179{ 184{
180 oblinkpt *obp = get_button_links (op); 185 if (oblinkpt *obp = op->find_link ())
181 186 {
182 if (!obp) 187 if (INVOKE_MAP (TRIGGER, op->map, ARG_STRING (&obp->id), ARG_INT (op->value)))
183 return; 188 return;
184 189
185 if (INVOKE_MAP (TRIGGER, op->map, ARG_INT64 (obp->value), ARG_INT (op->value)))
186 return;
187
188 activate_connection_link (obp->link, op->value, op); 190 activate_connection_link (obp->link, op->value, op);
191 }
189} 192}
190 193
191/* 194/*
192 * elmex: 195 * elmex:
193 * This activates a connection, similar to push_button (object *op) but it takes 196 * This activates a connection, similar to push_button (object *op) but it takes
195 * the connection was 'state' or 'released'. So that you can activate objects 198 * the connection was 'state' or 'released'. So that you can activate objects
196 * who have FLAG_ACTIVATE_ON_PUSH/RELEASE set properly. 199 * who have FLAG_ACTIVATE_ON_PUSH/RELEASE set properly.
197 * 200 *
198 */ 201 */
199void 202void
200activate_connection (maptile *map, long connection, bool state) 203maptile::trigger (shstr_tmp id, bool state, object *originator)
201{ 204{
202 if (INVOKE_MAP (TRIGGER, map, ARG_INT64 (connection), ARG_INT (state))) 205 if (INVOKE_MAP (TRIGGER, this, ARG_STRING (&id), ARG_INT (state), ARG_OBJECT (originator)))
203 return; 206 return;
204 207
205 oblinkpt *obp = get_connection_links (map, connection); 208 if (oblinkpt *obp = find_link (id))
206
207 if (obp)
208 activate_connection_link (obp->link, state); 209 activate_connection_link (obp->link, state, originator);
209} 210}
210 211
211/* 212/*
212 * Updates everything connected with the button op. 213 * Updates everything connected with the button op.
213 * After changing the state of a button, this function must be called 214 * After changing the state of a button, this function must be called
216 */ 217 */
217void 218void
218update_button (object *op) 219update_button (object *op)
219{ 220{
220 int any_down = 0, old_value = op->value; 221 int any_down = 0, old_value = op->value;
221 oblinkpt *obp = 0;
222 objectlink *ol;
223 222
224 obp = get_button_links (op); 223 if (oblinkpt *obp = op->find_link ())
225 if (obp)
226 for (ol = obp->link; ol; ol = ol->next) 224 for (objectlink *ol = obp->link; ol; ol = ol->next)
227 { 225 {
228 if (!ol->ob) 226 if (!ol->ob)
229 { 227 {
230 LOG (llevDebug, "Internal error in update_button (%s).\n", &op->name); 228 LOG (llevDebug, "Internal error in update_button (%s).\n", &op->name);
231 continue; 229 continue;
586 return 0; 584 return 0;
587 } 585 }
588} 586}
589 587
590void 588void
591add_button_link (object *button, maptile *map, int connected) 589object::add_link (maptile *map, shstr_tmp id)
592{ 590{
593 oblinkpt *obp;
594 objectlink *ol = get_objectlink ();
595
596 if (!map) 591 if (!map)
597 { 592 {
598 LOG (llevError, "Tried to add button-link without map.\n"); 593 LOG (llevError, "Tried to add button-link without map.\n");
599 return; 594 return;
600 } 595 }
601 596
602 button->path_attuned = connected; /* peterm: I need this so I can rebuild 597 flag [FLAG_IS_LINKED] = true;
603 a connected map from a template map. */
604 598
605 SET_FLAG (button, FLAG_IS_LINKED); 599 objectlink *ol = get_objectlink ();
606
607 ol->ob = button; 600 ol->ob = this;
608 601
609 for (obp = map->buttons; obp && obp->value != connected; obp = obp->next) 602 for (oblinkpt *obp = map->buttons; obp; obp = obp->next)
610 ; 603 if (obp->id == id)
611
612 if (obp)
613 { 604 {
614 ol->next = obp->link; 605 ol->next = obp->link;
615 obp->link = ol; 606 obp->link = ol;
607 return;
616 } 608 }
617 else 609
618 {
619 obp = get_objectlinkpt (); 610 oblinkpt *obp = get_objectlinkpt ();
620 obp->value = connected; 611 obp->id = id;
621 612
622 obp->next = map->buttons; 613 obp->next = map->buttons;
623 map->buttons = obp; 614 map->buttons = obp;
624 obp->link = ol; 615 obp->link = ol;
625 }
626} 616}
627 617
628/* 618/*
629 * Remove the object from the linked lists of buttons in the map. 619 * Remove the object from the linked lists of buttons in the map.
630 * This is only needed by editors. 620 * This is only needed by editors.
631 */ 621 */
632
633void 622void
634remove_button_link (object *op) 623object::remove_link ()
635{ 624{
636 oblinkpt *obp; 625 if (!map)
637 objectlink **olp, *ol;
638
639 if (op->map == NULL)
640 { 626 {
641 LOG (llevError, "remove_button_link() in object without map.\n"); 627 LOG (llevError, "remove_button_link() in object without map.\n");
642 return; 628 return;
643 } 629 }
644 630
645 if (!QUERY_FLAG (op, FLAG_IS_LINKED)) 631 if (!flag [FLAG_IS_LINKED])
646 { 632 {
647 LOG (llevError, "remove_button_linked() in unlinked object.\n"); 633 LOG (llevError, "remove_button_linked() in unlinked object.\n");
648 return; 634 return;
649 } 635 }
650 636
637 flag [FLAG_IS_LINKED] = false;
638
651 for (obp = op->map->buttons; obp; obp = obp->next) 639 for (oblinkpt *obp = map->buttons; obp; obp = obp->next)
652 for (olp = &obp->link; (ol = *olp); olp = &ol->next) 640 for (objectlink **olp = &obp->link; *olp; olp = &(*olp)->next)
653 if (ol->ob == op) 641 if ((*olp)->ob == this)
654 { 642 {
655 643 objectlink *ol = *olp;
656/* LOG(llevDebug, "Removed link %d in button %s and map %s.\n",
657 obp->value, op->name, op->map->path);
658*/
659 *olp = ol->next; 644 *olp = ol->next;
660 delete ol; 645 delete ol;
661 return; 646 return;
662 } 647 }
663 648
664 LOG (llevError, "remove_button_linked(): couldn't find object.\n"); 649 LOG (llevError, "remove_button_linked(): couldn't find object.\n");
665 CLEAR_FLAG (op, FLAG_IS_LINKED); 650}
651
652/*
653 * Updates every button on the map (by calling update_button() for them).
654 */
655void
656maptile::update_buttons ()
657{
658 for (oblinkpt *obp = buttons; obp; obp = obp->next)
659 for (objectlink *ol = obp->link; ol; ol = ol->next)
660 {
661 if (!ol->ob)
662 {
663 LOG (llevError, "Internal error in update_button (%s (%dx%d), connected %ld).\n",
664 ol->ob ? (const char *) ol->ob->name : "null", ol->ob ? ol->ob->x : -1, ol->ob ? ol->ob->y : -1, &obp->id);
665 continue;
666 }
667
668 if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL)
669 {
670 update_button (ol->ob);
671 break;
672 }
673 }
666} 674}
667 675
668/* 676/*
669 * Gets the objectlink for this connection from the map. 677 * Gets the objectlink for this connection from the map.
670 */ 678 */
671oblinkpt * 679oblinkpt *
672get_connection_links (maptile *map, long connection) 680maptile::find_link (shstr_tmp id)
673{ 681{
674 for (oblinkpt * obp = map->buttons; obp; obp = obp->next) 682 for (oblinkpt *obp = buttons; obp; obp = obp->next)
675 if (obp->value == connection) 683 if (obp->id == id)
676 return obp; 684 return obp;
677 685
678 return 0; 686 return 0;
679} 687}
680 688
681/* 689/*
682 * Return the first objectlink in the objects linked to this one 690 * Return the first objectlink in the objects linked to this one
683 */ 691 */
684
685oblinkpt * 692oblinkpt *
686get_button_links (const object *button) 693object::find_link () const
687{ 694{
688 oblinkpt *obp; 695 if (map)
689 objectlink *ol;
690
691 if (!button->map)
692 return NULL;
693
694 for (obp = button->map->buttons; obp; obp = obp->next) 696 for (oblinkpt *obp = map->buttons; obp; obp = obp->next)
695 for (ol = obp->link; ol; ol = ol->next) 697 for (objectlink *ol = obp->link; ol; ol = ol->next)
696 if (ol->ob == button) 698 if (ol->ob == this)
697 return obp; 699 return obp;
698 700
699 return NULL;
700}
701
702/*
703 * Made as a separate function to increase efficiency
704 */
705
706int
707get_button_value (const object *button)
708{
709 oblinkpt *obp;
710 objectlink *ol;
711
712 if (!button->map)
713 return 0;
714 for (obp = button->map->buttons; obp; obp = obp->next)
715 for (ol = obp->link; ol; ol = ol->next)
716 if (ol->ob == button)
717 return obp->value;
718 return 0; 701 return 0;
719} 702}
720 703
721/* This routine makes monsters who are 704/* This routine makes monsters who are
722 * standing on the 'mood floor' change their 705 * standing on the 'mood floor' change their
724 * If floor is to be triggered must have 707 * If floor is to be triggered must have
725 * a speed of zero (default is 1 for all 708 * a speed of zero (default is 1 for all
726 * but the charm floor type). 709 * but the charm floor type).
727 * by b.t. thomas@nomad.astro.psu.edu 710 * by b.t. thomas@nomad.astro.psu.edu
728 */ 711 */
729
730void 712void
731do_mood_floor (object *op, object *source) 713do_mood_floor (object *op, object *source)
732{ 714{
733 if (!source) 715 if (!source)
734 source = op; 716 source = op;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines