… | |
… | |
395 | * Returns the object which has the count-variable equal to the argument. |
395 | * Returns the object which has the count-variable equal to the argument. |
396 | */ |
396 | */ |
397 | object * |
397 | object * |
398 | find_object (tag_t i) |
398 | find_object (tag_t i) |
399 | { |
399 | { |
400 | return ((unsigned int)i) < objects.size () |
400 | for_all_objects (op) |
401 | ? objects [i] |
401 | if (op->count == i) |
402 | : 0; |
402 | return op; |
|
|
403 | |
|
|
404 | return 0; |
403 | } |
405 | } |
404 | |
406 | |
405 | /* |
407 | /* |
406 | * Returns the first object which has a name equal to the argument. |
408 | * Returns the first object which has a name equal to the argument. |
407 | * Used only by the patch command, but not all that useful. |
409 | * Used only by the patch command, but not all that useful. |
… | |
… | |
673 | object::~object () |
675 | object::~object () |
674 | { |
676 | { |
675 | free_key_values (this); |
677 | free_key_values (this); |
676 | } |
678 | } |
677 | |
679 | |
|
|
680 | static int object_count; |
|
|
681 | |
678 | void object::link () |
682 | void object::link () |
679 | { |
683 | { |
|
|
684 | assert (!index);//D |
680 | uuid = gen_uuid (); |
685 | uuid = gen_uuid (); |
|
|
686 | count = ++object_count; |
681 | |
687 | |
|
|
688 | refcnt_inc (); |
682 | objects.insert (this); |
689 | objects.insert (this); |
683 | } |
690 | } |
684 | |
691 | |
685 | void object::unlink () |
692 | void object::unlink () |
686 | { |
693 | { |
|
|
694 | assert (index);//D |
687 | objects.erase (this); |
695 | objects.erase (this); |
|
|
696 | refcnt_dec (); |
688 | } |
697 | } |
689 | |
698 | |
690 | void |
699 | void |
691 | object::activate () |
700 | object::activate () |
692 | { |
701 | { |
… | |
… | |
782 | |
791 | |
783 | if (op->flag [FLAG_STARTEQUIP] |
792 | if (op->flag [FLAG_STARTEQUIP] |
784 | || op->flag [FLAG_NO_DROP] |
793 | || op->flag [FLAG_NO_DROP] |
785 | || op->type == RUNE |
794 | || op->type == RUNE |
786 | || op->type == TRAP |
795 | || op->type == TRAP |
787 | || op->flag [FLAG_IS_A_TEMPLATE]) |
796 | || op->flag [FLAG_IS_A_TEMPLATE] |
|
|
797 | || op->flag [FLAG_DESTROY_ON_DEATH]) |
788 | op->destroy (); |
798 | op->destroy (); |
789 | else |
799 | else |
790 | map->insert (op, x, y); |
800 | map->insert (op, x, y); |
791 | } |
801 | } |
792 | } |
802 | } |
… | |
… | |
800 | } |
810 | } |
801 | |
811 | |
802 | void |
812 | void |
803 | object::do_destroy () |
813 | object::do_destroy () |
804 | { |
814 | { |
|
|
815 | attachable::do_destroy (); |
|
|
816 | |
805 | if (flag [FLAG_IS_LINKED]) |
817 | if (flag [FLAG_IS_LINKED]) |
806 | remove_button_link (this); |
818 | remove_button_link (this); |
807 | |
819 | |
808 | if (flag [FLAG_FRIENDLY]) |
820 | if (flag [FLAG_FRIENDLY]) |
809 | remove_friendly_object (this); |
821 | remove_friendly_object (this); |
810 | |
822 | |
811 | if (!flag [FLAG_REMOVED]) |
823 | if (!flag [FLAG_REMOVED]) |
812 | remove (); |
824 | remove (); |
813 | |
825 | |
814 | if (flag [FLAG_FREED]) |
826 | destroy_inv (true); |
815 | return; |
|
|
816 | |
827 | |
817 | set_speed (0); |
828 | deactivate (); |
|
|
829 | unlink (); |
818 | |
830 | |
819 | flag [FLAG_FREED] = 1; |
831 | flag [FLAG_FREED] = 1; |
820 | |
|
|
821 | attachable::do_destroy (); |
|
|
822 | |
|
|
823 | destroy_inv (true); |
|
|
824 | unlink (); |
|
|
825 | |
832 | |
826 | // hack to ensure that freed objects still have a valid map |
833 | // hack to ensure that freed objects still have a valid map |
827 | { |
834 | { |
828 | static maptile *freed_map; // freed objects are moved here to avoid crashes |
835 | static maptile *freed_map; // freed objects are moved here to avoid crashes |
829 | |
836 | |