ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/object.C
(Generate patch)

Comparing deliantra/server/common/object.C (file contents):
Revision 1.107 by pippijn, Sat Jan 6 14:42:29 2007 UTC vs.
Revision 1.112 by root, Mon Jan 8 14:11:04 2007 UTC

37 37
38int nrofallocobjects = 0; 38int nrofallocobjects = 0;
39static UUID uuid; 39static UUID uuid;
40const uint64 UUID_SKIP = 1<<19; 40const uint64 UUID_SKIP = 1<<19;
41 41
42object *active_objects; /* List of active objects that need to be processed */ 42objectvec objects;
43activevec actives;
43 44
44short 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, 45short 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};
47short 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, 48short 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
397object * 397object *
398find_object (tag_t i) 398find_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
413object * 412object *
414find_object_name (const char *str) 413find_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}
676object::~object () 675object::~object ()
677{ 676{
678 free_key_values (this); 677 free_key_values (this);
679} 678}
680 679
680static int object_count;
681
681void object::link () 682void 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
695void object::unlink () 692void 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
708bool
709object::active () const
710{
711 return active_next || active_prev || this == active_objects;
712} 697}
713 698
714void 699void
715object::activate () 700object::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
734void 710void
735object::activate_recursive () 711object::activate_recursive ()
736{ 712{
750 */ 726 */
751void 727void
752object::deactivate () 728object::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
775void 737void
776object::deactivate_recursive () 738object::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
849void 812void
850object::do_destroy () 813object::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
911void 868void
912object::destroy (bool destroy_inventory) 869object::destroy (bool destroy_inventory)
913{ 870{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines