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.108 by root, Sun Jan 7 02:39:13 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 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
413object * 410object *
414find_object_name (const char *str) 411find_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
681void object::link () 678void 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
695void object::unlink () 685void 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
708bool
709object::active () const
710{
711 return active_next || active_prev || this == active_objects;
712} 688}
713 689
714void 690void
715object::activate () 691object::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
734void 701void
735object::activate_recursive () 702object::activate_recursive ()
736{ 703{
750 */ 717 */
751void 718void
752object::deactivate () 719object::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
775void 728void
776object::deactivate_recursive () 729object::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
911void 861void
912object::destroy (bool destroy_inventory) 862object::destroy (bool destroy_inventory)
913{ 863{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines