… | |
… | |
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 | { |
|
|
682 | assert (!index);//D |
680 | uuid = gen_uuid (); |
683 | uuid = gen_uuid (); |
|
|
684 | count = ++object_count; |
681 | |
685 | |
682 | refcnt_inc (); |
686 | refcnt_inc (); |
683 | objects.insert (this); |
687 | objects.insert (this); |
684 | } |
688 | } |
685 | |
689 | |
686 | void object::unlink () |
690 | void object::unlink () |
687 | { |
691 | { |
|
|
692 | assert (index);//D |
688 | objects.erase (this); |
693 | objects.erase (this); |
689 | refcnt_dec (); |
694 | refcnt_dec (); |
690 | } |
695 | } |
691 | |
696 | |
692 | void |
697 | void |
… | |
… | |
803 | } |
808 | } |
804 | |
809 | |
805 | void |
810 | void |
806 | object::do_destroy () |
811 | object::do_destroy () |
807 | { |
812 | { |
|
|
813 | attachable::do_destroy (); |
|
|
814 | |
808 | if (flag [FLAG_IS_LINKED]) |
815 | if (flag [FLAG_IS_LINKED]) |
809 | remove_button_link (this); |
816 | remove_button_link (this); |
810 | |
817 | |
811 | if (flag [FLAG_FRIENDLY]) |
818 | if (flag [FLAG_FRIENDLY]) |
812 | remove_friendly_object (this); |
819 | remove_friendly_object (this); |
813 | |
820 | |
814 | if (!flag [FLAG_REMOVED]) |
821 | if (!flag [FLAG_REMOVED]) |
815 | remove (); |
822 | remove (); |
816 | |
823 | |
817 | if (flag [FLAG_FREED]) |
824 | destroy_inv (true); |
818 | return; |
|
|
819 | |
825 | |
820 | set_speed (0); |
826 | deactivate (); |
|
|
827 | unlink (); |
821 | |
828 | |
822 | flag [FLAG_FREED] = 1; |
829 | flag [FLAG_FREED] = 1; |
823 | |
|
|
824 | attachable::do_destroy (); |
|
|
825 | |
|
|
826 | destroy_inv (true); |
|
|
827 | unlink (); |
|
|
828 | |
830 | |
829 | // hack to ensure that freed objects still have a valid map |
831 | // hack to ensure that freed objects still have a valid map |
830 | { |
832 | { |
831 | 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 |
832 | |
834 | |
… | |
… | |
2161 | |
2163 | |
2162 | return 3; |
2164 | return 3; |
2163 | } |
2165 | } |
2164 | |
2166 | |
2165 | /* |
2167 | /* |
2166 | * absdir(int): Returns a number between 1 and 8, which represent |
|
|
2167 | * the "absolute" direction of a number (it actually takes care of |
|
|
2168 | * "overflow" in previous calculations of a direction). |
|
|
2169 | */ |
|
|
2170 | |
|
|
2171 | int |
|
|
2172 | absdir (int d) |
|
|
2173 | { |
|
|
2174 | while (d < 1) |
|
|
2175 | d += 8; |
|
|
2176 | |
|
|
2177 | while (d > 8) |
|
|
2178 | d -= 8; |
|
|
2179 | |
|
|
2180 | return d; |
|
|
2181 | } |
|
|
2182 | |
|
|
2183 | /* |
|
|
2184 | * dirdiff(dir1, dir2) returns how many 45-degrees differences there is |
2168 | * dirdiff(dir1, dir2) returns how many 45-degrees differences there is |
2185 | * between two directions (which are expected to be absolute (see absdir()) |
2169 | * between two directions (which are expected to be absolute (see absdir()) |
2186 | */ |
2170 | */ |
2187 | |
|
|
2188 | int |
2171 | int |
2189 | dirdiff (int dir1, int dir2) |
2172 | dirdiff (int dir1, int dir2) |
2190 | { |
2173 | { |
2191 | int d; |
2174 | int d; |
2192 | |
2175 | |
… | |
… | |
2631 | { |
2614 | { |
2632 | static char info[256 * 4]; |
2615 | static char info[256 * 4]; |
2633 | return debug_desc (info); |
2616 | return debug_desc (info); |
2634 | } |
2617 | } |
2635 | |
2618 | |
|
|
2619 | const char * |
|
|
2620 | object::debug_desc2 () const |
|
|
2621 | { |
|
|
2622 | static char info[256 * 4]; |
|
|
2623 | return debug_desc (info); |
|
|
2624 | } |
|
|
2625 | |