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.113 by root, Tue Jan 9 21:32:41 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}
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
666object *object::first;
667
668object::object () 665object::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;
676object::~object () 673object::~object ()
677{ 674{
678 free_key_values (this); 675 free_key_values (this);
679} 676}
680 677
678static int object_count;
679
681void object::link () 680void 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
695void object::unlink () 690void 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
708bool
709object::active () const
710{
711 return active_next || active_prev || this == active_objects;
712} 695}
713 696
714void 697void
715object::activate () 698object::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
734void 708void
735object::activate_recursive () 709object::activate_recursive ()
736{ 710{
750 */ 724 */
751void 725void
752object::deactivate () 726object::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
775void 735void
776object::deactivate_recursive () 736object::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
849void 810void
850object::do_destroy () 811object::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
911void 866void
912object::destroy (bool destroy_inventory) 867object::destroy (bool destroy_inventory)
913{ 868{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines