… | |
… | |
522 | tail = new_link; |
522 | tail = new_link; |
523 | } |
523 | } |
524 | } |
524 | } |
525 | } |
525 | } |
526 | |
526 | |
527 | update_ob_speed (dst); |
527 | dst->set_speed (dst->speed); |
528 | } |
528 | } |
529 | |
529 | |
530 | object * |
530 | object * |
531 | object::clone () |
531 | object::clone () |
532 | { |
532 | { |
… | |
… | |
554 | * Updates the speed of an object. If the speed changes from 0 to another |
554 | * Updates the speed of an object. If the speed changes from 0 to another |
555 | * value, or vice versa, then add/remove the object from the active list. |
555 | * value, or vice versa, then add/remove the object from the active list. |
556 | * This function needs to be called whenever the speed of an object changes. |
556 | * This function needs to be called whenever the speed of an object changes. |
557 | */ |
557 | */ |
558 | void |
558 | void |
559 | update_ob_speed (object *op) |
559 | object::set_speed (float speed) |
560 | { |
560 | { |
561 | extern int arch_init; |
561 | extern int arch_init; |
562 | |
562 | |
563 | /* No reason putting the archetypes objects on the speed list, |
563 | /* No reason putting the archetypes objects on the speed list, |
564 | * since they never really need to be updated. |
564 | * since they never really need to be updated. |
565 | */ |
565 | */ |
566 | if (QUERY_FLAG (op, FLAG_FREED) && op->speed) |
566 | if (flag [FLAG_FREED] && speed) |
567 | { |
567 | { |
568 | LOG (llevError, "Object %s is freed but has speed.\n", &op->name); |
568 | LOG (llevError, "Object %s is freed but has speed.\n", &name); |
569 | op->speed = 0; |
569 | speed = 0; |
570 | } |
570 | } |
|
|
571 | |
|
|
572 | this->speed = speed; |
571 | |
573 | |
572 | if (arch_init) |
574 | if (arch_init) |
573 | return; |
575 | return; |
574 | |
576 | |
575 | if (FABS (op->speed) > MIN_ACTIVE_SPEED) |
577 | if (FABS (speed) > MIN_ACTIVE_SPEED) |
576 | { |
578 | { |
577 | /* If already on active list, don't do anything */ |
579 | /* If already on active list, don't do anything */ |
578 | if (op->active_next || op->active_prev || op == active_objects) |
580 | if (active_next || active_prev || this == active_objects) |
579 | return; |
581 | return; |
580 | |
582 | |
581 | /* process_events() expects us to insert the object at the beginning |
583 | /* process_events() expects us to insert the object at the beginning |
582 | * of the list. */ |
584 | * of the list. */ |
583 | op->active_next = active_objects; |
585 | active_next = active_objects; |
584 | |
586 | |
585 | if (op->active_next != NULL) |
587 | if (active_next) |
586 | op->active_next->active_prev = op; |
588 | active_next->active_prev = this; |
587 | |
589 | |
588 | active_objects = op; |
590 | active_objects = this; |
589 | } |
591 | } |
590 | else |
592 | else |
591 | { |
593 | { |
592 | /* If not on the active list, nothing needs to be done */ |
594 | /* If not on the active list, nothing needs to be done */ |
593 | if (!op->active_next && !op->active_prev && op != active_objects) |
595 | if (!active_next && !active_prev && this != active_objects) |
594 | return; |
596 | return; |
595 | |
597 | |
596 | if (op->active_prev == NULL) |
598 | if (!active_prev) |
597 | { |
599 | { |
598 | active_objects = op->active_next; |
600 | active_objects = active_next; |
599 | |
601 | |
600 | if (op->active_next != NULL) |
602 | if (active_next) |
601 | op->active_next->active_prev = NULL; |
603 | active_next->active_prev = 0; |
602 | } |
604 | } |
603 | else |
605 | else |
604 | { |
606 | { |
605 | op->active_prev->active_next = op->active_next; |
607 | active_prev->active_next = active_next; |
606 | |
608 | |
607 | if (op->active_next) |
609 | if (active_next) |
608 | op->active_next->active_prev = op->active_prev; |
610 | active_next->active_prev = active_prev; |
609 | } |
611 | } |
610 | |
612 | |
611 | op->active_next = NULL; |
613 | active_next = 0; |
612 | op->active_prev = NULL; |
614 | active_prev = 0; |
613 | } |
615 | } |
614 | } |
616 | } |
615 | |
617 | |
616 | /* This function removes object 'op' from the list of active |
618 | /* This function removes object 'op' from the list of active |
617 | * objects. |
619 | * objects. |
… | |
… | |
776 | |
778 | |
777 | prev = 0; |
779 | prev = 0; |
778 | next = 0; |
780 | next = 0; |
779 | } |
781 | } |
780 | |
782 | |
781 | object *object::create () |
|
|
782 | { |
|
|
783 | object *op = new object; |
|
|
784 | op->link (); |
|
|
785 | return op; |
|
|
786 | } |
|
|
787 | |
|
|
788 | /* |
|
|
789 | * free_object() frees everything allocated by an object, removes |
|
|
790 | * it from the list of used objects, and puts it on the list of |
|
|
791 | * free objects. The IS_FREED() flag is set in the object. |
|
|
792 | * The object must have been removed by remove_ob() first for |
|
|
793 | * this function to succeed. |
|
|
794 | * |
|
|
795 | * If destroy_inventory is set, free inventory as well. Else drop items in |
|
|
796 | * inventory to the ground. |
|
|
797 | */ |
|
|
798 | void |
|
|
799 | object::do_destroy () |
|
|
800 | { |
|
|
801 | attachable::do_destroy (); |
|
|
802 | |
|
|
803 | if (flag [FLAG_IS_LINKED]) |
|
|
804 | remove_button_link (this); |
|
|
805 | |
|
|
806 | if (flag [FLAG_FRIENDLY]) |
|
|
807 | remove_friendly_object (this); |
|
|
808 | |
|
|
809 | if (!flag [FLAG_REMOVED]) |
|
|
810 | remove (); |
|
|
811 | |
|
|
812 | if (flag [FLAG_FREED]) |
|
|
813 | return; |
|
|
814 | |
|
|
815 | flag [FLAG_FREED] = 1; |
|
|
816 | |
|
|
817 | // hack to ensure that freed objects still have a valid map |
|
|
818 | { |
|
|
819 | static maptile *freed_map; // freed objects are moved here to avoid crashes |
|
|
820 | |
|
|
821 | if (!freed_map) |
|
|
822 | { |
|
|
823 | freed_map = new maptile; |
|
|
824 | |
|
|
825 | freed_map->name = "/internal/freed_objects_map"; |
|
|
826 | freed_map->width = 3; |
|
|
827 | freed_map->height = 3; |
|
|
828 | |
|
|
829 | freed_map->allocate (); |
|
|
830 | } |
|
|
831 | |
|
|
832 | map = freed_map; |
|
|
833 | x = 1; |
|
|
834 | y = 1; |
|
|
835 | } |
|
|
836 | |
|
|
837 | more = 0; |
|
|
838 | head = 0; |
|
|
839 | inv = 0; |
|
|
840 | |
|
|
841 | // clear those pointers that likely might have circular references to us |
|
|
842 | owner = 0; |
|
|
843 | enemy = 0; |
|
|
844 | attacked_by = 0; |
|
|
845 | |
|
|
846 | // only relevant for players(?), but make sure of it anyways |
|
|
847 | contr = 0; |
|
|
848 | |
|
|
849 | /* Remove object from the active list */ |
|
|
850 | speed = 0; |
|
|
851 | update_ob_speed (this); |
|
|
852 | |
|
|
853 | unlink (); |
|
|
854 | } |
|
|
855 | |
|
|
856 | /* |
783 | /* |
857 | * Remove and free all objects in the inventory of the given object. |
784 | * Remove and free all objects in the inventory of the given object. |
858 | * object.c ? |
785 | * object.c ? |
859 | */ |
786 | */ |
860 | void |
787 | void |
861 | object::destroy_inv (bool drop_to_ground) |
788 | object::destroy_inv (bool drop_to_ground) |
862 | { |
789 | { |
863 | if (!inv) |
|
|
864 | return; |
|
|
865 | |
|
|
866 | /* Only if the space blocks everything do we not process - |
790 | /* Only if the space blocks everything do we not process - |
867 | * if some form of movement is allowed, let objects |
791 | * if some form of movement is allowed, let objects |
868 | * drop on that space. |
792 | * drop on that space. |
869 | */ |
793 | */ |
870 | if (!drop_to_ground || !map || map->in_memory != MAP_IN_MEMORY || GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL) |
794 | if (!drop_to_ground || !map || map->in_memory != MAP_IN_MEMORY || GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL) |
871 | { |
795 | { |
872 | while (inv) |
796 | while (inv) |
873 | { |
|
|
874 | inv->destroy_inv (drop_to_ground); |
|
|
875 | inv->destroy (); |
797 | inv->destroy (); |
876 | } |
|
|
877 | } |
798 | } |
878 | else |
799 | else |
879 | { /* Put objects in inventory onto this space */ |
800 | { /* Put objects in inventory onto this space */ |
880 | while (inv) |
801 | while (inv) |
881 | { |
802 | { |
… | |
… | |
896 | } |
817 | } |
897 | } |
818 | } |
898 | } |
819 | } |
899 | } |
820 | } |
900 | |
821 | |
|
|
822 | object *object::create () |
|
|
823 | { |
|
|
824 | object *op = new object; |
|
|
825 | op->link (); |
|
|
826 | return op; |
|
|
827 | } |
|
|
828 | |
|
|
829 | void |
|
|
830 | object::do_destroy () |
|
|
831 | { |
|
|
832 | if (flag [FLAG_IS_LINKED]) |
|
|
833 | remove_button_link (this); |
|
|
834 | |
|
|
835 | if (flag [FLAG_FRIENDLY]) |
|
|
836 | remove_friendly_object (this); |
|
|
837 | |
|
|
838 | if (!flag [FLAG_REMOVED]) |
|
|
839 | remove (); |
|
|
840 | |
|
|
841 | if (flag [FLAG_FREED]) |
|
|
842 | return; |
|
|
843 | |
|
|
844 | flag [FLAG_FREED] = 1; |
|
|
845 | |
|
|
846 | attachable::do_destroy (); |
|
|
847 | |
|
|
848 | destroy_inv (true); |
|
|
849 | set_speed (0); |
|
|
850 | unlink (); |
|
|
851 | |
|
|
852 | // hack to ensure that freed objects still have a valid map |
|
|
853 | { |
|
|
854 | static maptile *freed_map; // freed objects are moved here to avoid crashes |
|
|
855 | |
|
|
856 | if (!freed_map) |
|
|
857 | { |
|
|
858 | freed_map = new maptile; |
|
|
859 | |
|
|
860 | freed_map->name = "/internal/freed_objects_map"; |
|
|
861 | freed_map->width = 3; |
|
|
862 | freed_map->height = 3; |
|
|
863 | |
|
|
864 | freed_map->allocate (); |
|
|
865 | } |
|
|
866 | |
|
|
867 | map = freed_map; |
|
|
868 | x = 1; |
|
|
869 | y = 1; |
|
|
870 | } |
|
|
871 | |
|
|
872 | head = 0; |
|
|
873 | |
|
|
874 | if (more) |
|
|
875 | { |
|
|
876 | more->destroy (); |
|
|
877 | more = 0; |
|
|
878 | } |
|
|
879 | |
|
|
880 | // clear those pointers that likely might have circular references to us |
|
|
881 | owner = 0; |
|
|
882 | enemy = 0; |
|
|
883 | attacked_by = 0; |
|
|
884 | |
|
|
885 | // only relevant for players(?), but make sure of it anyways |
|
|
886 | contr = 0; |
|
|
887 | } |
|
|
888 | |
901 | void |
889 | void |
902 | object::destroy (bool destroy_inventory) |
890 | object::destroy (bool destroy_inventory) |
903 | { |
891 | { |
904 | if (destroyed ()) |
892 | if (destroyed ()) |
905 | return; |
893 | return; |
906 | |
894 | |
907 | if (more) |
|
|
908 | { |
|
|
909 | //TODO: non-head objects must not have inventory |
|
|
910 | more->destroy (destroy_inventory); |
|
|
911 | more = 0; |
|
|
912 | } |
|
|
913 | |
|
|
914 | if (destroy_inventory) |
895 | if (destroy_inventory) |
915 | destroy_inv (true); |
896 | destroy_inv (false); |
916 | |
897 | |
917 | attachable::destroy (); |
898 | attachable::destroy (); |
918 | } |
899 | } |
919 | |
900 | |
920 | /* |
901 | /* |
… | |
… | |
1033 | if (map->in_memory == MAP_SAVING) |
1014 | if (map->in_memory == MAP_SAVING) |
1034 | return; |
1015 | return; |
1035 | |
1016 | |
1036 | int check_walk_off = !flag [FLAG_NO_APPLY]; |
1017 | int check_walk_off = !flag [FLAG_NO_APPLY]; |
1037 | |
1018 | |
1038 | for (tmp = GET_MAP_OB (map, x, y); tmp; tmp = tmp->above) |
1019 | for (tmp = map->at (x, y).bot; tmp; tmp = tmp->above) |
1039 | { |
1020 | { |
1040 | /* No point updating the players look faces if he is the object |
1021 | /* No point updating the players look faces if he is the object |
1041 | * being removed. |
1022 | * being removed. |
1042 | */ |
1023 | */ |
1043 | |
1024 | |
… | |
… | |
1063 | && (move_type & ~tmp->move_off & ~tmp->move_block) == 0)) |
1044 | && (move_type & ~tmp->move_off & ~tmp->move_block) == 0)) |
1064 | { |
1045 | { |
1065 | move_apply (tmp, this, 0); |
1046 | move_apply (tmp, this, 0); |
1066 | |
1047 | |
1067 | if (destroyed ()) |
1048 | if (destroyed ()) |
|
|
1049 | LOG (llevError, "BUG: remove_ob(): name %s, destroyed leaving object\n", tmp->debug_desc ()); |
1068 | LOG (llevError, "BUG: remove_ob(): name %s, destroyed leaving object\n", tmp->debug_desc ()); |
1050 | LOG (llevError, "BUG: remove_ob(): name %s, destroyed leaving object\n", tmp->debug_desc ()); |
1069 | } |
1051 | } |
1070 | |
1052 | |
1071 | /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */ |
1053 | /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */ |
1072 | |
1054 | |