… | |
… | |
778 | |
778 | |
779 | prev = 0; |
779 | prev = 0; |
780 | next = 0; |
780 | next = 0; |
781 | } |
781 | } |
782 | |
782 | |
783 | object *object::create () |
|
|
784 | { |
|
|
785 | object *op = new object; |
|
|
786 | op->link (); |
|
|
787 | return op; |
|
|
788 | } |
|
|
789 | |
|
|
790 | void |
|
|
791 | object::do_destroy () |
|
|
792 | { |
|
|
793 | attachable::do_destroy (); |
|
|
794 | |
|
|
795 | if (flag [FLAG_IS_LINKED]) |
|
|
796 | remove_button_link (this); |
|
|
797 | |
|
|
798 | if (flag [FLAG_FRIENDLY]) |
|
|
799 | remove_friendly_object (this); |
|
|
800 | |
|
|
801 | if (!flag [FLAG_REMOVED]) |
|
|
802 | remove (); |
|
|
803 | |
|
|
804 | if (flag [FLAG_FREED]) |
|
|
805 | return; |
|
|
806 | |
|
|
807 | flag [FLAG_FREED] = 1; |
|
|
808 | |
|
|
809 | while (inv) |
|
|
810 | inv->destroy (); |
|
|
811 | |
|
|
812 | set_speed (0); |
|
|
813 | unlink (); |
|
|
814 | |
|
|
815 | // hack to ensure that freed objects still have a valid map |
|
|
816 | { |
|
|
817 | static maptile *freed_map; // freed objects are moved here to avoid crashes |
|
|
818 | |
|
|
819 | if (!freed_map) |
|
|
820 | { |
|
|
821 | freed_map = new maptile; |
|
|
822 | |
|
|
823 | freed_map->name = "/internal/freed_objects_map"; |
|
|
824 | freed_map->width = 3; |
|
|
825 | freed_map->height = 3; |
|
|
826 | |
|
|
827 | freed_map->allocate (); |
|
|
828 | } |
|
|
829 | |
|
|
830 | map = freed_map; |
|
|
831 | x = 1; |
|
|
832 | y = 1; |
|
|
833 | } |
|
|
834 | |
|
|
835 | head = 0; |
|
|
836 | |
|
|
837 | if (more) |
|
|
838 | { |
|
|
839 | more->destroy (); |
|
|
840 | more = 0; |
|
|
841 | } |
|
|
842 | |
|
|
843 | // clear those pointers that likely might have circular references to us |
|
|
844 | owner = 0; |
|
|
845 | enemy = 0; |
|
|
846 | attacked_by = 0; |
|
|
847 | |
|
|
848 | // only relevant for players(?), but make sure of it anyways |
|
|
849 | contr = 0; |
|
|
850 | } |
|
|
851 | |
|
|
852 | /* |
783 | /* |
853 | * 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. |
854 | * object.c ? |
785 | * object.c ? |
855 | */ |
786 | */ |
856 | void |
787 | void |
… | |
… | |
886 | } |
817 | } |
887 | } |
818 | } |
888 | } |
819 | } |
889 | } |
820 | } |
890 | |
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 | |
891 | void |
889 | void |
892 | object::destroy (bool destroy_inventory) |
890 | object::destroy (bool destroy_inventory) |
893 | { |
891 | { |
894 | if (destroyed ()) |
892 | if (destroyed ()) |
895 | return; |
893 | return; |
896 | |
894 | |
897 | if (destroy_inventory) |
895 | if (destroy_inventory) |
898 | destroy_inv (true); |
896 | destroy_inv (false); |
899 | |
897 | |
900 | attachable::destroy (); |
898 | attachable::destroy (); |
901 | } |
899 | } |
902 | |
900 | |
903 | /* |
901 | /* |
… | |
… | |
1016 | if (map->in_memory == MAP_SAVING) |
1014 | if (map->in_memory == MAP_SAVING) |
1017 | return; |
1015 | return; |
1018 | |
1016 | |
1019 | int check_walk_off = !flag [FLAG_NO_APPLY]; |
1017 | int check_walk_off = !flag [FLAG_NO_APPLY]; |
1020 | |
1018 | |
1021 | for (tmp = GET_MAP_OB (map, x, y); tmp; tmp = tmp->above) |
1019 | for (tmp = map->at (x, y).bot; tmp; tmp = tmp->above) |
1022 | { |
1020 | { |
1023 | /* 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 |
1024 | * being removed. |
1022 | * being removed. |
1025 | */ |
1023 | */ |
1026 | |
1024 | |
… | |
… | |
1046 | && (move_type & ~tmp->move_off & ~tmp->move_block) == 0)) |
1044 | && (move_type & ~tmp->move_off & ~tmp->move_block) == 0)) |
1047 | { |
1045 | { |
1048 | move_apply (tmp, this, 0); |
1046 | move_apply (tmp, this, 0); |
1049 | |
1047 | |
1050 | if (destroyed ()) |
1048 | if (destroyed ()) |
|
|
1049 | LOG (llevError, "BUG: remove_ob(): name %s, destroyed leaving object\n", tmp->debug_desc ()); |
1051 | 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 ()); |
1052 | } |
1051 | } |
1053 | |
1052 | |
1054 | /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */ |
1053 | /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */ |
1055 | |
1054 | |