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.10 by root, Thu Sep 14 22:33:58 2006 UTC vs.
Revision 1.18 by root, Thu Dec 21 01:33:49 2006 UTC

39{ 39{
40 object *tmp = 0; 40 object *tmp = 0;
41 41
42 for (; ol; ol = ol->next) 42 for (; ol; ol = ol->next)
43 { 43 {
44 if (!ol->ob || ol->ob->count != ol->id) 44 if (!ol->ob)
45 { 45 {
46 LOG (llevError, "Internal error in activate_connection_link (%ld).\n", ol->id); 46 LOG (llevError, "Internal error in activate_connection_link.\n");
47 continue; 47 continue;
48 } 48 }
49
49 /* a button link object can become freed when the map is saving. As 50 /* a button link object can become freed when the map is saving. As
50 * a map is saved, objects are removed and freed, and if an object is 51 * a map is saved, objects are removed and freed, and if an object is
51 * on top of a button, this function is eventually called. If a map 52 * on top of a button, this function is eventually called. If a map
52 * is getting moved out of memory, the status of buttons and levers 53 * is getting moved out of memory, the status of buttons and levers
53 * probably isn't important - it will get sorted out when the map is 54 * probably isn't important - it will get sorted out when the map is
187 * the connection was 'state' or 'released'. So that you can activate objects 188 * the connection was 'state' or 'released'. So that you can activate objects
188 * who have FLAG_ACTIVATE_ON_PUSH/RELEASE set properly. 189 * who have FLAG_ACTIVATE_ON_PUSH/RELEASE set properly.
189 * 190 *
190 */ 191 */
191void 192void
192activate_connection (mapstruct *map, long connection, bool state) 193activate_connection (maptile *map, long connection, bool state)
193{ 194{
194 if (INVOKE_MAP (TRIGGER, map, ARG_INT64 (connection), ARG_INT (state))) 195 if (INVOKE_MAP (TRIGGER, map, ARG_INT64 (connection), ARG_INT (state)))
195 return; 196 return;
196 197
197 oblinkpt *obp = get_connection_links (map, connection); 198 oblinkpt *obp = get_connection_links (map, connection);
204 * Updates everything connected with the button op. 205 * Updates everything connected with the button op.
205 * After changing the state of a button, this function must be called 206 * After changing the state of a button, this function must be called
206 * to make sure that all gates and other buttons connected to the 207 * to make sure that all gates and other buttons connected to the
207 * button reacts to the (eventual) change of state. 208 * button reacts to the (eventual) change of state.
208 */ 209 */
209
210void 210void
211update_button (object *op) 211update_button (object *op)
212{ 212{
213 object *ab, *tmp, *head; 213 object *ab, *tmp, *head;
214 int tot, any_down = 0, old_value = op->value; 214 int tot, any_down = 0, old_value = op->value;
218 obp = get_button_links (op); 218 obp = get_button_links (op);
219 /* LOG(llevDebug, "update_button: %s (%d)\n", op->name, op->count); */ 219 /* LOG(llevDebug, "update_button: %s (%d)\n", op->name, op->count); */
220 if (obp) 220 if (obp)
221 for (ol = obp->link; ol; ol = ol->next) 221 for (ol = obp->link; ol; ol = ol->next)
222 { 222 {
223 if (!ol->ob || ol->ob->count != ol->id) 223 if (!ol->ob)
224 { 224 {
225 LOG (llevDebug, "Internal error in update_button (%s).\n", &op->name); 225 LOG (llevDebug, "Internal error in update_button (%s).\n", &op->name);
226 continue; 226 continue;
227 } 227 }
228
228 tmp = ol->ob; 229 tmp = ol->ob;
229 if (tmp->type == BUTTON) 230 if (tmp->type == BUTTON)
230 { 231 {
231 for (ab = tmp->above, tot = 0; ab != NULL; ab = ab->above) 232 for (ab = tmp->above, tot = 0; ab != NULL; ab = ab->above)
232 /* Bug? The pedestal code below looks for the head of 233 /* Bug? The pedestal code below looks for the head of
281/* 282/*
282 * Updates every button on the map (by calling update_button() for them). 283 * Updates every button on the map (by calling update_button() for them).
283 */ 284 */
284 285
285void 286void
286update_buttons (mapstruct *m) 287update_buttons (maptile *m)
287{ 288{
288 objectlink *ol; 289 objectlink *ol;
289 oblinkpt *obp; 290 oblinkpt *obp;
290 291
291 for (obp = m->buttons; obp; obp = obp->next) 292 for (obp = m->buttons; obp; obp = obp->next)
292 for (ol = obp->link; ol; ol = ol->next) 293 for (ol = obp->link; ol; ol = ol->next)
293 { 294 {
294 if (!ol->ob || ol->ob->count != ol->id) 295 if (!ol->ob)
295 { 296 {
296 LOG (llevError, "Internal error in update_button (%s (%dx%d):%d, connected %ld).\n", 297 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, ol->id, obp->value); 298 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 continue;
299 } 300 }
301
300 if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL) 302 if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL)
301 { 303 {
302 update_button (ol->ob); 304 update_button (ol->ob);
303 break; 305 break;
304 } 306 }
351 ARCH_SACRIFICE (altar) == sacrifice->name || 353 ARCH_SACRIFICE (altar) == sacrifice->name ||
352 ARCH_SACRIFICE (altar) == sacrifice->slaying || 354 ARCH_SACRIFICE (altar) == sacrifice->slaying ||
353 (!strcmp (ARCH_SACRIFICE (altar), query_base_name (sacrifice, 0)))) 355 (!strcmp (ARCH_SACRIFICE (altar), query_base_name (sacrifice, 0))))
354 && NROF_SACRIFICE (altar) <= (sacrifice->nrof ? sacrifice->nrof : 1)) 356 && NROF_SACRIFICE (altar) <= (sacrifice->nrof ? sacrifice->nrof : 1))
355 return 1; 357 return 1;
358
356 if (strcmp (ARCH_SACRIFICE (altar), "money") == 0 359 if (strcmp (ARCH_SACRIFICE (altar), "money") == 0
357 && sacrifice->type == MONEY && sacrifice->nrof * sacrifice->value >= NROF_SACRIFICE (altar)) 360 && sacrifice->type == MONEY && sacrifice->nrof * sacrifice->value >= NROF_SACRIFICE (altar))
358 return 1; 361 return 1;
359 } 362 }
363
360 return 0; 364 return 0;
361} 365}
362 366
363/* 367/*
364 * operate_altar checks if sacrifice was accepted and removes sacrificed 368 * operate_altar checks if sacrifice was accepted and removes sacrificed
595 return 0; 599 return 0;
596 } 600 }
597} 601}
598 602
599void 603void
600add_button_link (object *button, mapstruct *map, int connected) 604add_button_link (object *button, maptile *map, int connected)
601{ 605{
602 oblinkpt *obp; 606 oblinkpt *obp;
603 objectlink *ol = get_objectlink (); 607 objectlink *ol = get_objectlink ();
604 608
605 if (!map) 609 if (!map)
614/* LOG(llevDebug,"adding button %s (%d)\n", button->name, connected);*/ 618/* LOG(llevDebug,"adding button %s (%d)\n", button->name, connected);*/
615 619
616 SET_FLAG (button, FLAG_IS_LINKED); 620 SET_FLAG (button, FLAG_IS_LINKED);
617 621
618 ol->ob = button; 622 ol->ob = button;
619 ol->id = button->count;
620 623
621 for (obp = map->buttons; obp && obp->value != connected; obp = obp->next); 624 for (obp = map->buttons; obp && obp->value != connected; obp = obp->next);
622 625
623 if (obp) 626 if (obp)
624 { 627 {
650 if (op->map == NULL) 653 if (op->map == NULL)
651 { 654 {
652 LOG (llevError, "remove_button_link() in object without map.\n"); 655 LOG (llevError, "remove_button_link() in object without map.\n");
653 return; 656 return;
654 } 657 }
658
655 if (!QUERY_FLAG (op, FLAG_IS_LINKED)) 659 if (!QUERY_FLAG (op, FLAG_IS_LINKED))
656 { 660 {
657 LOG (llevError, "remove_button_linked() in unlinked object.\n"); 661 LOG (llevError, "remove_button_linked() in unlinked object.\n");
658 return; 662 return;
659 } 663 }
664
660 for (obp = op->map->buttons; obp; obp = obp->next) 665 for (obp = op->map->buttons; obp; obp = obp->next)
661 for (olp = &obp->link; (ol = *olp); olp = &ol->next) 666 for (olp = &obp->link; (ol = *olp); olp = &ol->next)
662 if (ol->ob == op) 667 if (ol->ob == op)
663 { 668 {
664 669
665/* LOG(llevDebug, "Removed link %d in button %s and map %s.\n", 670/* LOG(llevDebug, "Removed link %d in button %s and map %s.\n",
666 obp->value, op->name, op->map->path); 671 obp->value, op->name, op->map->path);
667*/ 672*/
668 *olp = ol->next; 673 *olp = ol->next;
669 free (ol); 674 delete ol;
670 return; 675 return;
671 } 676 }
677
672 LOG (llevError, "remove_button_linked(): couldn't find object.\n"); 678 LOG (llevError, "remove_button_linked(): couldn't find object.\n");
673 CLEAR_FLAG (op, FLAG_IS_LINKED); 679 CLEAR_FLAG (op, FLAG_IS_LINKED);
674} 680}
675 681
676/* 682/*
677 * Gets the objectlink for this connection from the map. 683 * Gets the objectlink for this connection from the map.
678 */ 684 */
679oblinkpt * 685oblinkpt *
680get_connection_links (mapstruct *map, long connection) 686get_connection_links (maptile *map, long connection)
681{ 687{
682 for (oblinkpt * obp = map->buttons; obp; obp = obp->next) 688 for (oblinkpt * obp = map->buttons; obp; obp = obp->next)
683 if (obp->value == connection) 689 if (obp->value == connection)
684 return obp; 690 return obp;
691
685 return 0; 692 return 0;
686} 693}
687 694
688/* 695/*
689 * Return the first objectlink in the objects linked to this one 696 * Return the first objectlink in the objects linked to this one
695 oblinkpt *obp; 702 oblinkpt *obp;
696 objectlink *ol; 703 objectlink *ol;
697 704
698 if (!button->map) 705 if (!button->map)
699 return NULL; 706 return NULL;
707
700 for (obp = button->map->buttons; obp; obp = obp->next) 708 for (obp = button->map->buttons; obp; obp = obp->next)
701 for (ol = obp->link; ol; ol = ol->next) 709 for (ol = obp->link; ol; ol = ol->next)
702 if (ol->ob == button && ol->id == button->count) 710 if (ol->ob == button)
703 return obp; 711 return obp;
712
704 return NULL; 713 return NULL;
705} 714}
706 715
707/* 716/*
708 * Made as a separate function to increase efficiency 717 * Made as a separate function to increase efficiency
716 725
717 if (!button->map) 726 if (!button->map)
718 return 0; 727 return 0;
719 for (obp = button->map->buttons; obp; obp = obp->next) 728 for (obp = button->map->buttons; obp; obp = obp->next)
720 for (ol = obp->link; ol; ol = ol->next) 729 for (ol = obp->link; ol; ol = ol->next)
721 if (ol->ob == button && ol->id == button->count) 730 if (ol->ob == button)
722 return obp->value; 731 return obp->value;
723 return 0; 732 return 0;
724} 733}
725 734
726/* This routine makes monsters who are 735/* This routine makes monsters who are
763 tmp->attack_movement = 0; 772 tmp->attack_movement = 0;
764 /* lots of checks here, but want to make sure we don't 773 /* lots of checks here, but want to make sure we don't
765 * dereference a null value 774 * dereference a null value
766 */ 775 */
767 if (tmp->type == GOLEM && tmp->owner && tmp->owner->type == PLAYER && tmp->owner->contr->ranges[range_golem] == tmp) 776 if (tmp->type == GOLEM && tmp->owner && tmp->owner->type == PLAYER && tmp->owner->contr->ranges[range_golem] == tmp)
768 {
769 tmp->owner->contr->ranges[range_golem] = NULL; 777 tmp->owner->contr->ranges[range_golem] = 0;
770 tmp->owner->contr->golem_count = 0; 778
771 }
772 tmp->owner = 0; 779 tmp->owner = 0;
773 } 780 }
774 break; 781 break;
775 case 1: /* angry -- get neutral monsters mad */ 782 case 1: /* angry -- get neutral monsters mad */
776 if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (tmp, FLAG_FRIENDLY)) 783 if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (tmp, FLAG_FRIENDLY))
786 break; 793 break;
787 case 4: /* charm all monsters */ 794 case 4: /* charm all monsters */
788 if (op == source) 795 if (op == source)
789 break; /* only if 'connected' */ 796 break; /* only if 'connected' */
790 797
791 for (tmp2 = get_map_ob (source->map, source->x, source->y); /* finding an owner */ 798 for (tmp2 = GET_MAP_OB (source->map, source->x, source->y); /* finding an owner */
792 tmp2->type != PLAYER; tmp2 = tmp2->above) 799 tmp2->type != PLAYER; tmp2 = tmp2->above)
793 if (tmp2->above == NULL) 800 if (tmp2->above == NULL)
794 break; 801 break;
795 802
796 if (tmp2->type != PLAYER) 803 if (tmp2->type != PLAYER)
797 break; 804 break;
805
798 set_owner (tmp, tmp2); 806 tmp->set_owner (tmp2);
799 SET_FLAG (tmp, FLAG_MONSTER); 807 SET_FLAG (tmp, FLAG_MONSTER);
808
800 tmp->stats.exp = 0; 809 tmp->stats.exp = 0;
801 SET_FLAG (tmp, FLAG_FRIENDLY); 810 SET_FLAG (tmp, FLAG_FRIENDLY);
811
802 add_friendly_object (tmp); 812 add_friendly_object (tmp);
803 tmp->attack_movement = PETMOVE; 813 tmp->attack_movement = PETMOVE;
804 break; 814 break;
805 815
806 default: 816 default:
812 * It will descend through containers to find the object. 822 * It will descend through containers to find the object.
813 * slaying = match object slaying flag 823 * slaying = match object slaying flag
814 * race = match object archetype name flag 824 * race = match object archetype name flag
815 * hp = match object type (excpt type '0'== PLAYER) 825 * hp = match object type (excpt type '0'== PLAYER)
816 */ 826 */
817
818object * 827object *
819check_inv_recursive (object *op, const object *trig) 828check_inv_recursive (object *op, const object *trig)
820{ 829{
821 object *tmp, *ret = NULL; 830 object *tmp, *ret = NULL;
822 831
823 /* First check the object itself. */ 832 /* First check the object itself. */
824 if ((trig->stats.hp && (op->type == trig->stats.hp)) 833 if ((trig->stats.hp && (op->type == trig->stats.hp))
825 || (trig->slaying && (op->slaying == trig->slaying)) || (trig->race && (op->arch->name == trig->race))) 834 || (trig->slaying && (op->slaying == trig->slaying))
835 || (trig->race && (op->arch->name == trig->race)))
826 return op; 836 return op;
827 837
828 for (tmp = op->inv; tmp; tmp = tmp->below) 838 for (tmp = op->inv; tmp; tmp = tmp->below)
829 { 839 {
830 if (tmp->inv) 840 if (tmp->inv)
832 ret = check_inv_recursive (tmp, trig); 842 ret = check_inv_recursive (tmp, trig);
833 if (ret) 843 if (ret)
834 return ret; 844 return ret;
835 } 845 }
836 else if ((trig->stats.hp && (tmp->type == trig->stats.hp)) 846 else if ((trig->stats.hp && (tmp->type == trig->stats.hp))
837 || (trig->slaying && (tmp->slaying == trig->slaying)) || (trig->race && (tmp->arch->name == trig->race))) 847 || (trig->slaying && (tmp->slaying == trig->slaying))
848 || (trig->race && (tmp->arch->name == trig->race)))
838 return tmp; 849 return tmp;
839 } 850 }
840 return NULL; 851 return NULL;
841} 852}
842 853
845 * the square will activate connected items. 856 * the square will activate connected items.
846 * Monsters can't trigger this square (for now) 857 * Monsters can't trigger this square (for now)
847 * Values are: last_sp = 1/0 obj/no obj triggers 858 * Values are: last_sp = 1/0 obj/no obj triggers
848 * last_heal = 1/0 remove/dont remove obj if triggered 859 * last_heal = 1/0 remove/dont remove obj if triggered
849 * -b.t. (thomas@nomad.astro.psu.edu 860 * -b.t. (thomas@nomad.astro.psu.edu
850 */ 861 *
851 862 * Tue Dec 19 15:34:00 CET 2006 elmex: changed the function to ignore op
863 * because the check-inventory semantic essentially only applies when
864 * something is above the inventory checker.
865 * The semantic prior this change was: trigger if something has moved on or off
866 * and has a matching item. Imagine what happens if someone steps on the inventory
867 * checker with a matching item, has it, activates the connection, throws the item
868 * away, and then leaves the inventory checker. That would've caused an always-enabled
869 * state in the inventory checker. This won't happen anymore now.
870 *
871 */
852void 872void
853check_inv (object *op, object *trig) 873check_inv (object *op, object *trig)
854{ 874{
855 object *match; 875 trig->value = 0; // deactivate if none of the following conditions apply
856 876
857 if (op->type != PLAYER) 877 if (object *pl = trig->ms ().player ())
858 return; 878 {
859 match = check_inv_recursive (op, trig); 879 object *match = check_inv_recursive (pl, trig);
860 if (match && trig->last_sp)
861 {
862 if (trig->last_heal)
863 decrease_ob (match);
864 use_trigger (trig);
865 }
866 else if (!match && !trig->last_sp)
867 use_trigger (trig);
868}
869 880
870 881 if (match && trig->last_sp) // match == having
871/* This does a minimal check of the button link consistency for object
872 * map. All it really does it much sure the object id link that is set
873 * matches what the object has.
874 */
875void
876verify_button_links (const mapstruct *map)
877{
878 oblinkpt *obp;
879 objectlink *ol;
880
881 if (!map)
882 return;
883
884 for (obp = map->buttons; obp; obp = obp->next)
885 {
886 for (ol = obp->link; ol; ol = ol->next)
887 { 882 {
888 if (ol->id != ol->ob->count) 883 if (trig->last_heal)
889 LOG (llevError, "verify_button_links: object %s on list is corrupt (%d!=%d)\n", &ol->ob->name, ol->id, ol->ob->count); 884 decrease_ob (match);
885
886 trig->value = 1;
890 } 887 }
888 else if (!match && !trig->last_sp) // match == not having
889 trig->value = 1;
891 } 890 }
891
892 push_button (trig);
892} 893}
894

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines