… | |
… | |
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 |
|
|
795 | || !map |
|
|
796 | || map->in_memory != MAP_IN_MEMORY |
|
|
797 | || map->at (x, y).move_block == MOVE_ALL) |
862 | { |
798 | { |
863 | while (inv) |
799 | while (inv) |
864 | { |
800 | { |
865 | inv->destroy_inv (drop_to_ground); |
801 | inv->destroy_inv (drop_to_ground); |
866 | inv->destroy (); |
802 | inv->destroy (); |
… | |
… | |
887 | } |
823 | } |
888 | } |
824 | } |
889 | } |
825 | } |
890 | } |
826 | } |
891 | |
827 | |
|
|
828 | object *object::create () |
|
|
829 | { |
|
|
830 | object *op = new object; |
|
|
831 | op->link (); |
|
|
832 | return op; |
|
|
833 | } |
|
|
834 | |
|
|
835 | void |
|
|
836 | object::do_destroy () |
|
|
837 | { |
|
|
838 | if (flag [FLAG_IS_LINKED]) |
|
|
839 | remove_button_link (this); |
|
|
840 | |
|
|
841 | if (flag [FLAG_FRIENDLY]) |
|
|
842 | remove_friendly_object (this); |
|
|
843 | |
|
|
844 | if (!flag [FLAG_REMOVED]) |
|
|
845 | remove (); |
|
|
846 | |
|
|
847 | if (flag [FLAG_FREED]) |
|
|
848 | return; |
|
|
849 | |
|
|
850 | set_speed (0); |
|
|
851 | |
|
|
852 | flag [FLAG_FREED] = 1; |
|
|
853 | |
|
|
854 | attachable::do_destroy (); |
|
|
855 | |
|
|
856 | destroy_inv (true); |
|
|
857 | unlink (); |
|
|
858 | |
|
|
859 | // hack to ensure that freed objects still have a valid map |
|
|
860 | { |
|
|
861 | static maptile *freed_map; // freed objects are moved here to avoid crashes |
|
|
862 | |
|
|
863 | if (!freed_map) |
|
|
864 | { |
|
|
865 | freed_map = new maptile; |
|
|
866 | |
|
|
867 | freed_map->name = "/internal/freed_objects_map"; |
|
|
868 | freed_map->width = 3; |
|
|
869 | freed_map->height = 3; |
|
|
870 | |
|
|
871 | freed_map->allocate (); |
|
|
872 | } |
|
|
873 | |
|
|
874 | map = freed_map; |
|
|
875 | x = 1; |
|
|
876 | y = 1; |
|
|
877 | } |
|
|
878 | |
|
|
879 | head = 0; |
|
|
880 | |
|
|
881 | if (more) |
|
|
882 | { |
|
|
883 | more->destroy (); |
|
|
884 | more = 0; |
|
|
885 | } |
|
|
886 | |
|
|
887 | // clear those pointers that likely might have circular references to us |
|
|
888 | owner = 0; |
|
|
889 | enemy = 0; |
|
|
890 | attacked_by = 0; |
|
|
891 | |
|
|
892 | // only relevant for players(?), but make sure of it anyways |
|
|
893 | contr = 0; |
|
|
894 | } |
|
|
895 | |
892 | void |
896 | void |
893 | object::destroy (bool destroy_inventory) |
897 | object::destroy (bool destroy_inventory) |
894 | { |
898 | { |
895 | if (destroyed ()) |
899 | if (destroyed ()) |
896 | return; |
900 | return; |
897 | |
901 | |
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) |
902 | if (destroy_inventory) |
906 | destroy_inv (true); |
903 | destroy_inv (false); |
907 | |
904 | |
908 | attachable::destroy (); |
905 | attachable::destroy (); |
909 | } |
906 | } |
910 | |
907 | |
911 | /* |
908 | /* |
… | |
… | |
1024 | if (map->in_memory == MAP_SAVING) |
1021 | if (map->in_memory == MAP_SAVING) |
1025 | return; |
1022 | return; |
1026 | |
1023 | |
1027 | int check_walk_off = !flag [FLAG_NO_APPLY]; |
1024 | int check_walk_off = !flag [FLAG_NO_APPLY]; |
1028 | |
1025 | |
1029 | for (tmp = GET_MAP_OB (map, x, y); tmp; tmp = tmp->above) |
1026 | for (tmp = map->at (x, y).bot; tmp; tmp = tmp->above) |
1030 | { |
1027 | { |
1031 | /* No point updating the players look faces if he is the object |
1028 | /* No point updating the players look faces if he is the object |
1032 | * being removed. |
1029 | * being removed. |
1033 | */ |
1030 | */ |
1034 | |
1031 | |