… | |
… | |
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 | } |
… | |
… | |
661 | |
660 | |
662 | if (op->more) |
661 | if (op->more) |
663 | update_object (op->more, action); |
662 | update_object (op->more, action); |
664 | } |
663 | } |
665 | |
664 | |
666 | object *object::first; |
|
|
667 | |
|
|
668 | object::object () |
665 | object::object () |
669 | { |
666 | { |
670 | SET_FLAG (this, FLAG_REMOVED); |
667 | SET_FLAG (this, FLAG_REMOVED); |
671 | |
668 | |
672 | expmul = 1.0; |
669 | expmul = 1.0; |
… | |
… | |
676 | object::~object () |
673 | object::~object () |
677 | { |
674 | { |
678 | free_key_values (this); |
675 | free_key_values (this); |
679 | } |
676 | } |
680 | |
677 | |
|
|
678 | static int object_count; |
|
|
679 | |
681 | void object::link () |
680 | void object::link () |
682 | { |
681 | { |
683 | count = ++ob_count; |
682 | assert (!index);//D |
684 | uuid = gen_uuid (); |
683 | uuid = gen_uuid (); |
|
|
684 | count = ++object_count; |
685 | |
685 | |
686 | prev = 0; |
686 | refcnt_inc (); |
687 | next = object::first; |
687 | objects.insert (this); |
688 | |
|
|
689 | if (object::first) |
|
|
690 | object::first->prev = this; |
|
|
691 | |
|
|
692 | object::first = this; |
|
|
693 | } |
688 | } |
694 | |
689 | |
695 | void object::unlink () |
690 | void object::unlink () |
696 | { |
691 | { |
697 | if (this == object::first) |
692 | assert (index);//D |
698 | object::first = next; |
693 | objects.erase (this); |
699 | |
694 | 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 | } |
695 | } |
713 | |
696 | |
714 | void |
697 | void |
715 | object::activate () |
698 | object::activate () |
716 | { |
699 | { |
717 | /* If already on active list, don't do anything */ |
700 | /* If already on active list, don't do anything */ |
718 | if (active ()) |
701 | if (active) |
719 | return; |
702 | return; |
720 | |
703 | |
721 | if (has_active_speed ()) |
704 | if (has_active_speed ()) |
722 | { |
705 | 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 | } |
706 | } |
733 | |
707 | |
734 | void |
708 | void |
735 | object::activate_recursive () |
709 | object::activate_recursive () |
736 | { |
710 | { |
… | |
… | |
750 | */ |
724 | */ |
751 | void |
725 | void |
752 | object::deactivate () |
726 | object::deactivate () |
753 | { |
727 | { |
754 | /* If not on the active list, nothing needs to be done */ |
728 | /* If not on the active list, nothing needs to be done */ |
755 | if (!active ()) |
729 | if (!active) |
756 | return; |
730 | return; |
757 | |
731 | |
758 | if (active_prev == 0) |
732 | 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 | } |
733 | } |
774 | |
734 | |
775 | void |
735 | void |
776 | object::deactivate_recursive () |
736 | object::deactivate_recursive () |
777 | { |
737 | { |
… | |
… | |
829 | |
789 | |
830 | if (op->flag [FLAG_STARTEQUIP] |
790 | if (op->flag [FLAG_STARTEQUIP] |
831 | || op->flag [FLAG_NO_DROP] |
791 | || op->flag [FLAG_NO_DROP] |
832 | || op->type == RUNE |
792 | || op->type == RUNE |
833 | || op->type == TRAP |
793 | || op->type == TRAP |
834 | || op->flag [FLAG_IS_A_TEMPLATE]) |
794 | || op->flag [FLAG_IS_A_TEMPLATE] |
|
|
795 | || op->flag [FLAG_DESTROY_ON_DEATH]) |
835 | op->destroy (); |
796 | op->destroy (); |
836 | else |
797 | else |
837 | map->insert (op, x, y); |
798 | map->insert (op, x, y); |
838 | } |
799 | } |
839 | } |
800 | } |
… | |
… | |
847 | } |
808 | } |
848 | |
809 | |
849 | void |
810 | void |
850 | object::do_destroy () |
811 | object::do_destroy () |
851 | { |
812 | { |
|
|
813 | attachable::do_destroy (); |
|
|
814 | |
852 | if (flag [FLAG_IS_LINKED]) |
815 | if (flag [FLAG_IS_LINKED]) |
853 | remove_button_link (this); |
816 | remove_button_link (this); |
854 | |
817 | |
855 | if (flag [FLAG_FRIENDLY]) |
818 | if (flag [FLAG_FRIENDLY]) |
856 | remove_friendly_object (this); |
819 | remove_friendly_object (this); |
857 | |
820 | |
858 | if (!flag [FLAG_REMOVED]) |
821 | if (!flag [FLAG_REMOVED]) |
859 | remove (); |
822 | remove (); |
860 | |
823 | |
861 | if (flag [FLAG_FREED]) |
824 | destroy_inv (true); |
862 | return; |
|
|
863 | |
825 | |
864 | set_speed (0); |
826 | deactivate (); |
|
|
827 | unlink (); |
865 | |
828 | |
866 | flag [FLAG_FREED] = 1; |
829 | flag [FLAG_FREED] = 1; |
867 | |
|
|
868 | attachable::do_destroy (); |
|
|
869 | |
|
|
870 | destroy_inv (true); |
|
|
871 | unlink (); |
|
|
872 | |
830 | |
873 | // hack to ensure that freed objects still have a valid map |
831 | // hack to ensure that freed objects still have a valid map |
874 | { |
832 | { |
875 | 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 |
876 | |
834 | |
… | |
… | |
901 | |
859 | |
902 | // clear those pointers that likely might have circular references to us |
860 | // clear those pointers that likely might have circular references to us |
903 | owner = 0; |
861 | owner = 0; |
904 | enemy = 0; |
862 | enemy = 0; |
905 | attacked_by = 0; |
863 | attacked_by = 0; |
906 | |
|
|
907 | // only relevant for players(?), but make sure of it anyways |
|
|
908 | contr = 0; |
|
|
909 | } |
864 | } |
910 | |
865 | |
911 | void |
866 | void |
912 | object::destroy (bool destroy_inventory) |
867 | object::destroy (bool destroy_inventory) |
913 | { |
868 | { |