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.110 by root, Sun Jan 7 23:12:03 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 refcnt_inc ();
687 next = object::first; 683 objects.insert (this);
688
689 if (object::first)
690 object::first->prev = this;
691
692 object::first = this;
693} 684}
694 685
695void object::unlink () 686void object::unlink ()
696{ 687{
697 if (this == object::first) 688 objects.erase (this);
698 object::first = next; 689 refcnt_dec ();
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} 690}
713 691
714void 692void
715object::activate () 693object::activate ()
716{ 694{
717 /* If already on active list, don't do anything */ 695 /* If already on active list, don't do anything */
718 if (active ()) 696 if (active)
719 return; 697 return;
720 698
721 if (has_active_speed ()) 699 if (has_active_speed ())
722 { 700 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} 701}
733 702
734void 703void
735object::activate_recursive () 704object::activate_recursive ()
736{ 705{
750 */ 719 */
751void 720void
752object::deactivate () 721object::deactivate ()
753{ 722{
754 /* If not on the active list, nothing needs to be done */ 723 /* If not on the active list, nothing needs to be done */
755 if (!active ()) 724 if (!active)
756 return; 725 return;
757 726
758 if (active_prev == 0) 727 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} 728}
774 729
775void 730void
776object::deactivate_recursive () 731object::deactivate_recursive ()
777{ 732{
829 784
830 if (op->flag [FLAG_STARTEQUIP] 785 if (op->flag [FLAG_STARTEQUIP]
831 || op->flag [FLAG_NO_DROP] 786 || op->flag [FLAG_NO_DROP]
832 || op->type == RUNE 787 || op->type == RUNE
833 || op->type == TRAP 788 || op->type == TRAP
834 || op->flag [FLAG_IS_A_TEMPLATE]) 789 || op->flag [FLAG_IS_A_TEMPLATE]
790 || op->flag [FLAG_DESTROY_ON_DEATH])
835 op->destroy (); 791 op->destroy ();
836 else 792 else
837 map->insert (op, x, y); 793 map->insert (op, x, y);
838 } 794 }
839 } 795 }
901 857
902 // clear those pointers that likely might have circular references to us 858 // clear those pointers that likely might have circular references to us
903 owner = 0; 859 owner = 0;
904 enemy = 0; 860 enemy = 0;
905 attacked_by = 0; 861 attacked_by = 0;
906
907 // only relevant for players(?), but make sure of it anyways
908 contr = 0;
909} 862}
910 863
911void 864void
912object::destroy (bool destroy_inventory) 865object::destroy (bool destroy_inventory)
913{ 866{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines