… | |
… | |
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 | */ |
191 | void |
192 | void |
192 | activate_connection (mapstruct *map, long connection, bool state) |
193 | activate_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); |
… | |
… | |
218 | obp = get_button_links (op); |
219 | obp = get_button_links (op); |
219 | /* LOG(llevDebug, "update_button: %s (%d)\n", op->name, op->count); */ |
220 | /* LOG(llevDebug, "update_button: %s (%d)\n", op->name, op->count); */ |
220 | if (obp) |
221 | if (obp) |
221 | for (ol = obp->link; ol; ol = ol->next) |
222 | for (ol = obp->link; ol; ol = ol->next) |
222 | { |
223 | { |
223 | if (!ol->ob || ol->ob->count != ol->id) |
224 | if (!ol->ob) |
224 | { |
225 | { |
225 | LOG (llevDebug, "Internal error in update_button (%s).\n", &op->name); |
226 | LOG (llevDebug, "Internal error in update_button (%s).\n", &op->name); |
226 | continue; |
227 | continue; |
227 | } |
228 | } |
|
|
229 | |
228 | tmp = ol->ob; |
230 | tmp = ol->ob; |
229 | if (tmp->type == BUTTON) |
231 | if (tmp->type == BUTTON) |
230 | { |
232 | { |
231 | for (ab = tmp->above, tot = 0; ab != NULL; ab = ab->above) |
233 | for (ab = tmp->above, tot = 0; ab != NULL; ab = ab->above) |
232 | /* Bug? The pedestal code below looks for the head of |
234 | /* Bug? The pedestal code below looks for the head of |
… | |
… | |
281 | /* |
283 | /* |
282 | * Updates every button on the map (by calling update_button() for them). |
284 | * Updates every button on the map (by calling update_button() for them). |
283 | */ |
285 | */ |
284 | |
286 | |
285 | void |
287 | void |
286 | update_buttons (mapstruct *m) |
288 | update_buttons (maptile *m) |
287 | { |
289 | { |
288 | objectlink *ol; |
290 | objectlink *ol; |
289 | oblinkpt *obp; |
291 | oblinkpt *obp; |
290 | |
292 | |
291 | for (obp = m->buttons; obp; obp = obp->next) |
293 | for (obp = m->buttons; obp; obp = obp->next) |
292 | for (ol = obp->link; ol; ol = ol->next) |
294 | for (ol = obp->link; ol; ol = ol->next) |
293 | { |
295 | { |
294 | if (!ol->ob || ol->ob->count != ol->id) |
296 | if (!ol->ob) |
295 | { |
297 | { |
296 | LOG (llevError, "Internal error in update_button (%s (%dx%d):%d, connected %ld).\n", |
298 | 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); |
299 | ol->ob ? (const char *) ol->ob->name : "null", ol->ob ? ol->ob->x : -1, ol->ob ? ol->ob->y : -1, obp->value); |
298 | continue; |
300 | continue; |
299 | } |
301 | } |
|
|
302 | |
300 | if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL) |
303 | if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL) |
301 | { |
304 | { |
302 | update_button (ol->ob); |
305 | update_button (ol->ob); |
303 | break; |
306 | break; |
304 | } |
307 | } |
… | |
… | |
595 | return 0; |
598 | return 0; |
596 | } |
599 | } |
597 | } |
600 | } |
598 | |
601 | |
599 | void |
602 | void |
600 | add_button_link (object *button, mapstruct *map, int connected) |
603 | add_button_link (object *button, maptile *map, int connected) |
601 | { |
604 | { |
602 | oblinkpt *obp; |
605 | oblinkpt *obp; |
603 | objectlink *ol = get_objectlink (); |
606 | objectlink *ol = get_objectlink (); |
604 | |
607 | |
605 | if (!map) |
608 | if (!map) |
… | |
… | |
614 | /* LOG(llevDebug,"adding button %s (%d)\n", button->name, connected);*/ |
617 | /* LOG(llevDebug,"adding button %s (%d)\n", button->name, connected);*/ |
615 | |
618 | |
616 | SET_FLAG (button, FLAG_IS_LINKED); |
619 | SET_FLAG (button, FLAG_IS_LINKED); |
617 | |
620 | |
618 | ol->ob = button; |
621 | ol->ob = button; |
619 | ol->id = button->count; |
|
|
620 | |
622 | |
621 | for (obp = map->buttons; obp && obp->value != connected; obp = obp->next); |
623 | for (obp = map->buttons; obp && obp->value != connected; obp = obp->next); |
622 | |
624 | |
623 | if (obp) |
625 | if (obp) |
624 | { |
626 | { |
… | |
… | |
650 | if (op->map == NULL) |
652 | if (op->map == NULL) |
651 | { |
653 | { |
652 | LOG (llevError, "remove_button_link() in object without map.\n"); |
654 | LOG (llevError, "remove_button_link() in object without map.\n"); |
653 | return; |
655 | return; |
654 | } |
656 | } |
|
|
657 | |
655 | if (!QUERY_FLAG (op, FLAG_IS_LINKED)) |
658 | if (!QUERY_FLAG (op, FLAG_IS_LINKED)) |
656 | { |
659 | { |
657 | LOG (llevError, "remove_button_linked() in unlinked object.\n"); |
660 | LOG (llevError, "remove_button_linked() in unlinked object.\n"); |
658 | return; |
661 | return; |
659 | } |
662 | } |
|
|
663 | |
660 | for (obp = op->map->buttons; obp; obp = obp->next) |
664 | for (obp = op->map->buttons; obp; obp = obp->next) |
661 | for (olp = &obp->link; (ol = *olp); olp = &ol->next) |
665 | for (olp = &obp->link; (ol = *olp); olp = &ol->next) |
662 | if (ol->ob == op) |
666 | if (ol->ob == op) |
663 | { |
667 | { |
664 | |
668 | |
665 | /* LOG(llevDebug, "Removed link %d in button %s and map %s.\n", |
669 | /* LOG(llevDebug, "Removed link %d in button %s and map %s.\n", |
666 | obp->value, op->name, op->map->path); |
670 | obp->value, op->name, op->map->path); |
667 | */ |
671 | */ |
668 | *olp = ol->next; |
672 | *olp = ol->next; |
669 | free (ol); |
673 | delete ol; |
670 | return; |
674 | return; |
671 | } |
675 | } |
|
|
676 | |
672 | LOG (llevError, "remove_button_linked(): couldn't find object.\n"); |
677 | LOG (llevError, "remove_button_linked(): couldn't find object.\n"); |
673 | CLEAR_FLAG (op, FLAG_IS_LINKED); |
678 | CLEAR_FLAG (op, FLAG_IS_LINKED); |
674 | } |
679 | } |
675 | |
680 | |
676 | /* |
681 | /* |
677 | * Gets the objectlink for this connection from the map. |
682 | * Gets the objectlink for this connection from the map. |
678 | */ |
683 | */ |
679 | oblinkpt * |
684 | oblinkpt * |
680 | get_connection_links (mapstruct *map, long connection) |
685 | get_connection_links (maptile *map, long connection) |
681 | { |
686 | { |
682 | for (oblinkpt * obp = map->buttons; obp; obp = obp->next) |
687 | for (oblinkpt * obp = map->buttons; obp; obp = obp->next) |
683 | if (obp->value == connection) |
688 | if (obp->value == connection) |
684 | return obp; |
689 | return obp; |
|
|
690 | |
685 | return 0; |
691 | return 0; |
686 | } |
692 | } |
687 | |
693 | |
688 | /* |
694 | /* |
689 | * Return the first objectlink in the objects linked to this one |
695 | * Return the first objectlink in the objects linked to this one |
… | |
… | |
695 | oblinkpt *obp; |
701 | oblinkpt *obp; |
696 | objectlink *ol; |
702 | objectlink *ol; |
697 | |
703 | |
698 | if (!button->map) |
704 | if (!button->map) |
699 | return NULL; |
705 | return NULL; |
|
|
706 | |
700 | for (obp = button->map->buttons; obp; obp = obp->next) |
707 | for (obp = button->map->buttons; obp; obp = obp->next) |
701 | for (ol = obp->link; ol; ol = ol->next) |
708 | for (ol = obp->link; ol; ol = ol->next) |
702 | if (ol->ob == button && ol->id == button->count) |
709 | if (ol->ob == button) |
703 | return obp; |
710 | return obp; |
|
|
711 | |
704 | return NULL; |
712 | return NULL; |
705 | } |
713 | } |
706 | |
714 | |
707 | /* |
715 | /* |
708 | * Made as a separate function to increase efficiency |
716 | * Made as a separate function to increase efficiency |
… | |
… | |
716 | |
724 | |
717 | if (!button->map) |
725 | if (!button->map) |
718 | return 0; |
726 | return 0; |
719 | for (obp = button->map->buttons; obp; obp = obp->next) |
727 | for (obp = button->map->buttons; obp; obp = obp->next) |
720 | for (ol = obp->link; ol; ol = ol->next) |
728 | for (ol = obp->link; ol; ol = ol->next) |
721 | if (ol->ob == button && ol->id == button->count) |
729 | if (ol->ob == button) |
722 | return obp->value; |
730 | return obp->value; |
723 | return 0; |
731 | return 0; |
724 | } |
732 | } |
725 | |
733 | |
726 | /* This routine makes monsters who are |
734 | /* This routine makes monsters who are |
… | |
… | |
763 | tmp->attack_movement = 0; |
771 | tmp->attack_movement = 0; |
764 | /* lots of checks here, but want to make sure we don't |
772 | /* lots of checks here, but want to make sure we don't |
765 | * dereference a null value |
773 | * dereference a null value |
766 | */ |
774 | */ |
767 | if (tmp->type == GOLEM && tmp->owner && tmp->owner->type == PLAYER && tmp->owner->contr->ranges[range_golem] == tmp) |
775 | 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; |
776 | tmp->owner->contr->ranges[range_golem] = 0; |
770 | tmp->owner->contr->golem_count = 0; |
777 | |
771 | } |
|
|
772 | tmp->owner = 0; |
778 | tmp->owner = 0; |
773 | } |
779 | } |
774 | break; |
780 | break; |
775 | case 1: /* angry -- get neutral monsters mad */ |
781 | case 1: /* angry -- get neutral monsters mad */ |
776 | if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (tmp, FLAG_FRIENDLY)) |
782 | if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (tmp, FLAG_FRIENDLY)) |
… | |
… | |
865 | } |
871 | } |
866 | else if (!match && !trig->last_sp) |
872 | else if (!match && !trig->last_sp) |
867 | use_trigger (trig); |
873 | use_trigger (trig); |
868 | } |
874 | } |
869 | |
875 | |
870 | |
|
|
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 | */ |
|
|
875 | void |
|
|
876 | verify_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 | { |
|
|
888 | if (ol->id != ol->ob->count) |
|
|
889 | LOG (llevError, "verify_button_links: object %s on list is corrupt (%d!=%d)\n", &ol->ob->name, ol->id, ol->ob->count); |
|
|
890 | } |
|
|
891 | } |
|
|
892 | } |
|
|