… | |
… | |
37 | |
37 | |
38 | int nrofallocobjects = 0; |
38 | int nrofallocobjects = 0; |
39 | static UUID uuid; |
39 | static UUID uuid; |
40 | const uint64 UUID_SKIP = 1<<19; |
40 | const uint64 UUID_SKIP = 1<<19; |
41 | |
41 | |
42 | object *active_objects; /* List of active objects that need to be processed */ |
42 | objectvec objects; |
|
|
43 | activevec actives; |
43 | |
44 | |
44 | short freearr_x[SIZEOFFREE] = { 0, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, |
45 | short freearr_x[SIZEOFFREE] = { 0, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, |
45 | 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -2, -1 |
46 | 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -2, -1 |
46 | }; |
47 | }; |
47 | short freearr_y[SIZEOFFREE] = { 0, -1, -1, 0, 1, 1, 1, 0, -1, -2, -2, -2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, |
48 | short freearr_y[SIZEOFFREE] = { 0, -1, -1, 0, 1, 1, 1, 0, -1, -2, -2, -2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, |
… | |
… | |
391 | } |
392 | } |
392 | |
393 | |
393 | /* |
394 | /* |
394 | * 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. |
395 | */ |
396 | */ |
396 | |
|
|
397 | object * |
397 | object * |
398 | find_object (tag_t i) |
398 | find_object (tag_t i) |
399 | { |
399 | { |
400 | for (object *op = object::first; op; op = op->next) |
400 | for_all_objects (op) |
401 | if (op->count == i) |
401 | if (op->count == i) |
402 | return op; |
402 | return op; |
403 | |
403 | |
404 | return 0; |
404 | return 0; |
405 | } |
405 | } |
406 | |
406 | |
407 | /* |
407 | /* |
408 | * 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. |
409 | * Used only by the patch command, but not all that useful. |
409 | * Used only by the patch command, but not all that useful. |
410 | * Enables features like "patch <name-of-other-player> food 999" |
410 | * Enables features like "patch <name-of-other-player> food 999" |
411 | */ |
411 | */ |
412 | |
|
|
413 | object * |
412 | object * |
414 | find_object_name (const char *str) |
413 | find_object_name (const char *str) |
415 | { |
414 | { |
416 | shstr_cmp str_ (str); |
415 | shstr_cmp str_ (str); |
417 | object *op; |
416 | object *op; |
418 | |
417 | |
419 | for (op = object::first; op != NULL; op = op->next) |
418 | for_all_objects (op) |
420 | if (op->name == str_) |
419 | if (op->name == str_) |
421 | break; |
420 | break; |
422 | |
421 | |
423 | return op; |
422 | return op; |
424 | } |
423 | } |
… | |
… | |
676 | object::~object () |
675 | object::~object () |
677 | { |
676 | { |
678 | free_key_values (this); |
677 | free_key_values (this); |
679 | } |
678 | } |
680 | |
679 | |
|
|
680 | static int object_count; |
|
|
681 | |
681 | void object::link () |
682 | void object::link () |
682 | { |
683 | { |
683 | count = ++ob_count; |
684 | assert (!index);//D |
684 | uuid = gen_uuid (); |
685 | uuid = gen_uuid (); |
|
|
686 | count = ++object_count; |
685 | |
687 | |
686 | prev = 0; |
688 | refcnt_inc (); |
687 | next = object::first; |
689 | objects.insert (this); |
688 | |
|
|
689 | if (object::first) |
|
|
690 | object::first->prev = this; |
|
|
691 | |
|
|
692 | object::first = this; |
|
|
693 | } |
690 | } |
694 | |
691 | |
695 | void object::unlink () |
692 | void object::unlink () |
696 | { |
693 | { |
697 | if (this == object::first) |
694 | assert (index);//D |
698 | object::first = next; |
695 | objects.erase (this); |
699 | |
696 | refcnt_dec (); |
700 | /* Remove this object from the list of used objects */ |
|
|
701 | if (prev) prev->next = next; |
|
|
702 | if (next) next->prev = prev; |
|
|
703 | |
|
|
704 | prev = 0; |
|
|
705 | next = 0; |
|
|
706 | } |
|
|
707 | |
|
|
708 | bool |
|
|
709 | object::active () const |
|
|
710 | { |
|
|
711 | return active_next || active_prev || this == active_objects; |
|
|
712 | } |
697 | } |
713 | |
698 | |
714 | void |
699 | void |
715 | object::activate () |
700 | object::activate () |
716 | { |
701 | { |
717 | /* If already on active list, don't do anything */ |
702 | /* If already on active list, don't do anything */ |
718 | if (active ()) |
703 | if (active) |
719 | return; |
704 | return; |
720 | |
705 | |
721 | if (has_active_speed ()) |
706 | if (has_active_speed ()) |
722 | { |
707 | actives.insert (this); |
723 | /* process_events() expects us to insert the object at the beginning |
|
|
724 | * of the list. */ |
|
|
725 | active_next = active_objects; |
|
|
726 | |
|
|
727 | if (active_next) |
|
|
728 | active_next->active_prev = this; |
|
|
729 | |
|
|
730 | active_objects = this; |
|
|
731 | } |
|
|
732 | } |
708 | } |
733 | |
709 | |
734 | void |
710 | void |
735 | object::activate_recursive () |
711 | object::activate_recursive () |
736 | { |
712 | { |
… | |
… | |
750 | */ |
726 | */ |
751 | void |
727 | void |
752 | object::deactivate () |
728 | object::deactivate () |
753 | { |
729 | { |
754 | /* If not on the active list, nothing needs to be done */ |
730 | /* If not on the active list, nothing needs to be done */ |
755 | if (!active ()) |
731 | if (!active) |
756 | return; |
732 | return; |
757 | |
733 | |
758 | if (active_prev == 0) |
734 | actives.erase (this); |
759 | { |
|
|
760 | active_objects = active_next; |
|
|
761 | if (active_next) |
|
|
762 | active_next->active_prev = 0; |
|
|
763 | } |
|
|
764 | else |
|
|
765 | { |
|
|
766 | active_prev->active_next = active_next; |
|
|
767 | if (active_next) |
|
|
768 | active_next->active_prev = active_prev; |
|
|
769 | } |
|
|
770 | |
|
|
771 | active_next = 0; |
|
|
772 | active_prev = 0; |
|
|
773 | } |
735 | } |
774 | |
736 | |
775 | void |
737 | void |
776 | object::deactivate_recursive () |
738 | object::deactivate_recursive () |
777 | { |
739 | { |
… | |
… | |
829 | |
791 | |
830 | if (op->flag [FLAG_STARTEQUIP] |
792 | if (op->flag [FLAG_STARTEQUIP] |
831 | || op->flag [FLAG_NO_DROP] |
793 | || op->flag [FLAG_NO_DROP] |
832 | || op->type == RUNE |
794 | || op->type == RUNE |
833 | || op->type == TRAP |
795 | || op->type == TRAP |
834 | || op->flag [FLAG_IS_A_TEMPLATE]) |
796 | || op->flag [FLAG_IS_A_TEMPLATE] |
|
|
797 | || op->flag [FLAG_DESTROY_ON_DEATH]) |
835 | op->destroy (); |
798 | op->destroy (); |
836 | else |
799 | else |
837 | map->insert (op, x, y); |
800 | map->insert (op, x, y); |
838 | } |
801 | } |
839 | } |
802 | } |
… | |
… | |
847 | } |
810 | } |
848 | |
811 | |
849 | void |
812 | void |
850 | object::do_destroy () |
813 | object::do_destroy () |
851 | { |
814 | { |
|
|
815 | attachable::do_destroy (); |
|
|
816 | |
852 | if (flag [FLAG_IS_LINKED]) |
817 | if (flag [FLAG_IS_LINKED]) |
853 | remove_button_link (this); |
818 | remove_button_link (this); |
854 | |
819 | |
855 | if (flag [FLAG_FRIENDLY]) |
820 | if (flag [FLAG_FRIENDLY]) |
856 | remove_friendly_object (this); |
821 | remove_friendly_object (this); |
857 | |
822 | |
858 | if (!flag [FLAG_REMOVED]) |
823 | if (!flag [FLAG_REMOVED]) |
859 | remove (); |
824 | remove (); |
860 | |
825 | |
861 | if (flag [FLAG_FREED]) |
826 | destroy_inv (true); |
862 | return; |
|
|
863 | |
827 | |
864 | set_speed (0); |
828 | deactivate (); |
|
|
829 | unlink (); |
865 | |
830 | |
866 | flag [FLAG_FREED] = 1; |
831 | flag [FLAG_FREED] = 1; |
867 | |
|
|
868 | attachable::do_destroy (); |
|
|
869 | |
|
|
870 | destroy_inv (true); |
|
|
871 | unlink (); |
|
|
872 | |
832 | |
873 | // hack to ensure that freed objects still have a valid map |
833 | // hack to ensure that freed objects still have a valid map |
874 | { |
834 | { |
875 | 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 |
876 | |
836 | |
… | |
… | |
901 | |
861 | |
902 | // clear those pointers that likely might have circular references to us |
862 | // clear those pointers that likely might have circular references to us |
903 | owner = 0; |
863 | owner = 0; |
904 | enemy = 0; |
864 | enemy = 0; |
905 | attacked_by = 0; |
865 | attacked_by = 0; |
906 | |
|
|
907 | // only relevant for players(?), but make sure of it anyways |
|
|
908 | contr = 0; |
|
|
909 | } |
866 | } |
910 | |
867 | |
911 | void |
868 | void |
912 | object::destroy (bool destroy_inventory) |
869 | object::destroy (bool destroy_inventory) |
913 | { |
870 | { |