--- deliantra/server/include/object.h 2006/09/11 12:08:01 1.27 +++ deliantra/server/include/object.h 2006/09/11 20:28:37 1.28 @@ -78,10 +78,9 @@ // these are not being copied ACC_CLASS (object) -struct object_keep +struct object_keep : refcounted { tag_t ACC (RW, count); /* Unique object number for this object */ - sint32 ACC (RW, refcount); /* How many objects points to this object */ /* These variables are not changed by copy_object() */ struct pl *ACC (RW, contr); /* Pointer to the player which control this object */ @@ -109,12 +108,7 @@ // these are being copied struct object_copy : attachable { - /* These get an extra add_refcount(), after having been copied by memcpy(). - * All fields beow this point are automatically copied by memcpy. If - * adding something that needs a refcount updated, make sure you modify - * copy_object to do so. Everything below here also gets cleared - * by clear_object() - */ + refptr ACC (RW, owner); /* Pointer to the object which controls this one */ shstr ACC (RW, name); /* The name of the object, obviously... */ shstr ACC (RW, name_pl); /* The plural name of the object */ shstr ACC (RW, title); /* Of foo, etc */ @@ -180,11 +174,7 @@ /* See the doc/Developers/objects for more info about body locations */ /* Following mostly refers to fields only used for monsters */ - struct object *ACC (RW, owner); /* Pointer to the object which controls this one */ - /* Owner should not be referred to directly - */ - /* get_owner should be used instead. */ - tag_t ACC (RW, ownercount); /* What count the owner had (in case owner */ - /* has been freed) */ + tag_t ACC (RW, ownercount); /* What count the owner had (in case owner has been freed) *///TODO: remove/fix struct object *ACC (RW, enemy); /* Monster/player to follow even if not closest */ struct object *ACC (RW, attacked_by); /* This object start to attack us! only player & monster */ tag_t ACC (RW, attacked_by_count); /* the tag of attacker, so we can be sure */ @@ -235,10 +225,6 @@ key_value *key_values; /* Fields not explictly known by the loader. */ }; -#define get_object() object::create () -#define free_object(op) (op)->free (0) -#define free_object2(op, free_inv) (op)->free (free_inv) - struct object : zero_initialised, object_keep, object_copy, object_pod { static object *create (); @@ -250,6 +236,9 @@ void clear (); void clone (object *destination); + void set_owner (object *owner); + object *get_owner (); + protected: friend struct archetype; @@ -260,6 +249,25 @@ ~object (); }; +#define get_object() object::create () +#define free_object(op) (op)->free (0) +#define free_object2(op, free_inv) (op)->free (free_inv) +#define clear_owner(op) (op)->owner = 0 +#define copy_owner(op,other) (op)->owner = (other)->owner +#define clear_object(op) (op)->clear () + +static inline object * +get_owner (object *op) +{ + return op->get_owner (); +} + +static inline void +set_owner (object *op, object *owner) +{ + op->set_owner (owner); +} + #define CAN_MERGE(op1,op2) ((op1)->value == (op2)->value && (op1)->name == (op2)->name && object::can_merge ((op1), (op2))) typedef struct oblnk