… | |
… | |
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. |
… | |
… | |
658 | |
660 | |
659 | if (op->more) |
661 | if (op->more) |
660 | update_object (op->more, action); |
662 | update_object (op->more, action); |
661 | } |
663 | } |
662 | |
664 | |
663 | object *object::first; |
|
|
664 | |
|
|
665 | object::object () |
665 | object::object () |
666 | { |
666 | { |
667 | SET_FLAG (this, FLAG_REMOVED); |
667 | SET_FLAG (this, FLAG_REMOVED); |
668 | |
668 | |
669 | expmul = 1.0; |
669 | expmul = 1.0; |
… | |
… | |
673 | object::~object () |
673 | object::~object () |
674 | { |
674 | { |
675 | free_key_values (this); |
675 | free_key_values (this); |
676 | } |
676 | } |
677 | |
677 | |
|
|
678 | static int object_count; |
|
|
679 | |
678 | void object::link () |
680 | void object::link () |
679 | { |
681 | { |
680 | assert (!count);//D |
682 | assert (!index);//D |
681 | uuid = gen_uuid (); |
683 | uuid = gen_uuid (); |
|
|
684 | count = ++object_count; |
682 | |
685 | |
683 | refcnt_inc (); |
686 | refcnt_inc (); |
684 | objects.insert (this); |
687 | objects.insert (this); |
685 | } |
688 | } |
686 | |
689 | |
687 | void object::unlink () |
690 | void object::unlink () |
688 | { |
691 | { |
689 | assert (count);//D |
692 | assert (index);//D |
690 | objects.erase (this); |
693 | objects.erase (this); |
691 | refcnt_dec (); |
694 | refcnt_dec (); |
692 | } |
695 | } |
693 | |
696 | |
694 | void |
697 | void |
… | |
… | |
805 | } |
808 | } |
806 | |
809 | |
807 | void |
810 | void |
808 | object::do_destroy () |
811 | object::do_destroy () |
809 | { |
812 | { |
|
|
813 | attachable::do_destroy (); |
|
|
814 | |
810 | if (flag [FLAG_IS_LINKED]) |
815 | if (flag [FLAG_IS_LINKED]) |
811 | remove_button_link (this); |
816 | remove_button_link (this); |
812 | |
817 | |
813 | if (flag [FLAG_FRIENDLY]) |
818 | if (flag [FLAG_FRIENDLY]) |
814 | remove_friendly_object (this); |
819 | remove_friendly_object (this); |
815 | |
820 | |
816 | if (!flag [FLAG_REMOVED]) |
821 | if (!flag [FLAG_REMOVED]) |
817 | remove (); |
822 | remove (); |
818 | |
823 | |
819 | if (flag [FLAG_FREED]) |
824 | destroy_inv (true); |
820 | return; |
|
|
821 | |
825 | |
822 | set_speed (0); |
826 | deactivate (); |
|
|
827 | unlink (); |
823 | |
828 | |
824 | flag [FLAG_FREED] = 1; |
829 | flag [FLAG_FREED] = 1; |
825 | |
|
|
826 | attachable::do_destroy (); |
|
|
827 | |
|
|
828 | destroy_inv (true); |
|
|
829 | unlink (); |
|
|
830 | |
830 | |
831 | // hack to ensure that freed objects still have a valid map |
831 | // hack to ensure that freed objects still have a valid map |
832 | { |
832 | { |
833 | static maptile *freed_map; // freed objects are moved here to avoid crashes |
833 | static maptile *freed_map; // freed objects are moved here to avoid crashes |
834 | |
834 | |