… | |
… | |
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 | // hack to ensure that freed objects still have a valid map |
|
|
810 | { |
|
|
811 | static maptile *freed_map; // freed objects are moved here to avoid crashes |
|
|
812 | |
|
|
813 | if (!freed_map) |
|
|
814 | { |
|
|
815 | freed_map = new maptile; |
|
|
816 | |
|
|
817 | freed_map->name = "/internal/freed_objects_map"; |
|
|
818 | freed_map->width = 3; |
|
|
819 | freed_map->height = 3; |
|
|
820 | |
|
|
821 | freed_map->allocate (); |
|
|
822 | } |
|
|
823 | |
|
|
824 | map = freed_map; |
|
|
825 | x = 1; |
|
|
826 | y = 1; |
|
|
827 | } |
|
|
828 | |
|
|
829 | more = 0; |
|
|
830 | head = 0; |
|
|
831 | inv = 0; |
|
|
832 | |
|
|
833 | // clear those pointers that likely might have circular references to us |
|
|
834 | owner = 0; |
|
|
835 | enemy = 0; |
|
|
836 | attacked_by = 0; |
|
|
837 | |
|
|
838 | // only relevant for players(?), but make sure of it anyways |
|
|
839 | contr = 0; |
|
|
840 | |
|
|
841 | /* Remove object from the active list */ |
|
|
842 | set_speed (0); |
|
|
843 | |
|
|
844 | unlink (); |
|
|
845 | } |
|
|
846 | |
|
|
847 | /* |
783 | /* |
848 | * 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. |
849 | * object.c ? |
785 | * object.c ? |
850 | */ |
786 | */ |
851 | void |
787 | void |
852 | object::destroy_inv (bool drop_to_ground) |
788 | object::destroy_inv (bool drop_to_ground) |
853 | { |
789 | { |
854 | if (!inv) |
|
|
855 | return; |
|
|
856 | |
|
|
857 | /* Only if the space blocks everything do we not process - |
790 | /* Only if the space blocks everything do we not process - |
858 | * if some form of movement is allowed, let objects |
791 | * if some form of movement is allowed, let objects |
859 | * drop on that space. |
792 | * drop on that space. |
860 | */ |
793 | */ |
861 | 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) |
862 | { |
795 | { |
863 | while (inv) |
796 | while (inv) |
864 | { |
|
|
865 | inv->destroy_inv (drop_to_ground); |
|
|
866 | inv->destroy (); |
797 | inv->destroy (); |
867 | } |
|
|
868 | } |
798 | } |
869 | else |
799 | else |
870 | { /* Put objects in inventory onto this space */ |
800 | { /* Put objects in inventory onto this space */ |
871 | while (inv) |
801 | while (inv) |
872 | { |
802 | { |
… | |
… | |
887 | } |
817 | } |
888 | } |
818 | } |
889 | } |
819 | } |
890 | } |
820 | } |
891 | |
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 | attachable::do_destroy (); |
|
|
833 | |
|
|
834 | if (flag [FLAG_IS_LINKED]) |
|
|
835 | remove_button_link (this); |
|
|
836 | |
|
|
837 | if (flag [FLAG_FRIENDLY]) |
|
|
838 | remove_friendly_object (this); |
|
|
839 | |
|
|
840 | if (!flag [FLAG_REMOVED]) |
|
|
841 | remove (); |
|
|
842 | |
|
|
843 | if (flag [FLAG_FREED]) |
|
|
844 | return; |
|
|
845 | |
|
|
846 | flag [FLAG_FREED] = 1; |
|
|
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 | |
892 | void |
889 | void |
893 | object::destroy (bool destroy_inventory) |
890 | object::destroy (bool destroy_inventory) |
894 | { |
891 | { |
895 | if (destroyed ()) |
892 | if (destroyed ()) |
896 | return; |
893 | return; |
897 | |
894 | |
898 | if (more) |
|
|
899 | { |
|
|
900 | //TODO: non-head objects must not have inventory |
|
|
901 | more->destroy (destroy_inventory); |
|
|
902 | more = 0; |
|
|
903 | } |
|
|
904 | |
|
|
905 | if (destroy_inventory) |
895 | if (destroy_inventory) |
906 | destroy_inv (true); |
896 | destroy_inv (false); |
907 | |
897 | |
908 | attachable::destroy (); |
898 | attachable::destroy (); |
909 | } |
899 | } |
910 | |
900 | |
911 | /* |
901 | /* |