… | |
… | |
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 | return ((unsigned int)i) < objects.size () |
401 | if (op->count == i) |
401 | ? objects [i] |
402 | return op; |
402 | : 0; |
403 | |
|
|
404 | return 0; |
|
|
405 | } |
403 | } |
406 | |
404 | |
407 | /* |
405 | /* |
408 | * Returns the first object which has a name equal to the argument. |
406 | * Returns the first object which has a name equal to the argument. |
409 | * Used only by the patch command, but not all that useful. |
407 | * Used only by the patch command, but not all that useful. |
410 | * Enables features like "patch <name-of-other-player> food 999" |
408 | * Enables features like "patch <name-of-other-player> food 999" |
411 | */ |
409 | */ |
412 | |
|
|
413 | object * |
410 | object * |
414 | find_object_name (const char *str) |
411 | find_object_name (const char *str) |
415 | { |
412 | { |
416 | shstr_cmp str_ (str); |
413 | shstr_cmp str_ (str); |
417 | object *op; |
414 | object *op; |
418 | |
415 | |
419 | for (op = object::first; op != NULL; op = op->next) |
416 | for_all_objects (op) |
420 | if (op->name == str_) |
417 | if (op->name == str_) |
421 | break; |
418 | break; |
422 | |
419 | |
423 | return op; |
420 | return op; |
424 | } |
421 | } |
… | |
… | |
678 | free_key_values (this); |
675 | free_key_values (this); |
679 | } |
676 | } |
680 | |
677 | |
681 | void object::link () |
678 | void object::link () |
682 | { |
679 | { |
683 | count = ++ob_count; |
|
|
684 | uuid = gen_uuid (); |
680 | uuid = gen_uuid (); |
685 | |
681 | |
686 | prev = 0; |
682 | objects.insert (this); |
687 | next = object::first; |
|
|
688 | |
|
|
689 | if (object::first) |
|
|
690 | object::first->prev = this; |
|
|
691 | |
|
|
692 | object::first = this; |
|
|
693 | } |
683 | } |
694 | |
684 | |
695 | void object::unlink () |
685 | void object::unlink () |
696 | { |
686 | { |
697 | if (this == object::first) |
687 | objects.erase (this); |
698 | object::first = next; |
|
|
699 | |
|
|
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 | } |
688 | } |
713 | |
689 | |
714 | void |
690 | void |
715 | object::activate () |
691 | object::activate () |
716 | { |
692 | { |
717 | /* If already on active list, don't do anything */ |
693 | /* If already on active list, don't do anything */ |
718 | if (active ()) |
694 | if (active) |
719 | return; |
695 | return; |
720 | |
696 | |
721 | if (has_active_speed ()) |
697 | if (has_active_speed ()) |
722 | { |
698 | 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 | } |
699 | } |
733 | |
700 | |
734 | void |
701 | void |
735 | object::activate_recursive () |
702 | object::activate_recursive () |
736 | { |
703 | { |
… | |
… | |
750 | */ |
717 | */ |
751 | void |
718 | void |
752 | object::deactivate () |
719 | object::deactivate () |
753 | { |
720 | { |
754 | /* If not on the active list, nothing needs to be done */ |
721 | /* If not on the active list, nothing needs to be done */ |
755 | if (!active ()) |
722 | if (!active) |
756 | return; |
723 | return; |
757 | |
724 | |
758 | if (active_prev == 0) |
725 | 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 | } |
726 | } |
774 | |
727 | |
775 | void |
728 | void |
776 | object::deactivate_recursive () |
729 | object::deactivate_recursive () |
777 | { |
730 | { |
… | |
… | |
901 | |
854 | |
902 | // clear those pointers that likely might have circular references to us |
855 | // clear those pointers that likely might have circular references to us |
903 | owner = 0; |
856 | owner = 0; |
904 | enemy = 0; |
857 | enemy = 0; |
905 | attacked_by = 0; |
858 | attacked_by = 0; |
906 | |
|
|
907 | // only relevant for players(?), but make sure of it anyways |
|
|
908 | contr = 0; |
|
|
909 | } |
859 | } |
910 | |
860 | |
911 | void |
861 | void |
912 | object::destroy (bool destroy_inventory) |
862 | object::destroy (bool destroy_inventory) |
913 | { |
863 | { |