--- deliantra/server/common/object.C 2006/12/12 20:53:02 1.63 +++ deliantra/server/common/object.C 2006/12/12 21:39:56 1.64 @@ -528,49 +528,44 @@ casting_time = -1; } -void object::clone (object *destination) -{ - *(object_copy *)destination = *this; - *(object_pod *)destination = *this; - - if (self || cb) - INVOKE_OBJECT (CLONE, this, ARG_OBJECT (destination)); -} - /* - * copy object first frees everything allocated by the second object, - * and then copies the contends of the first object into the second + * copy_to first frees everything allocated by the dst object, + * and then copies the contents of itself into the second * object, allocating what needs to be allocated. Basically, any * data that is malloc'd needs to be re-malloc/copied. Otherwise, * if the first object is freed, the pointers in the new object * will point at garbage. */ void -copy_object (object *op2, object *op) +object::copy_to (object *dst) { - bool is_freed = QUERY_FLAG (op, FLAG_FREED); - bool is_removed = QUERY_FLAG (op, FLAG_REMOVED); + bool is_freed = QUERY_FLAG (dst, FLAG_FREED); + bool is_removed = QUERY_FLAG (dst, FLAG_REMOVED); + + *(object_copy *)dst = *this; + *(object_pod *)dst = *this; - op2->clone (op); + if (self || cb) + INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst)); if (is_freed) - SET_FLAG (op, FLAG_FREED); + SET_FLAG (dst, FLAG_FREED); if (is_removed) - SET_FLAG (op, FLAG_REMOVED); + SET_FLAG (dst, FLAG_REMOVED); - if (op2->speed < 0) - op->speed_left = op2->speed_left - RANDOM () % 200 / 100.0; + if (speed < 0) + dst->speed_left = speed_left - RANDOM () % 200 / 100.0; /* Copy over key_values, if any. */ - if (op2->key_values) + if (key_values) { key_value *tail = 0; key_value *i; - op->key_values = 0; + dst->key_values = 0; - for (i = op2->key_values; i; i = i->next) + for (i = key_values; i; i = i->next) { key_value *new_link = new key_value; @@ -579,9 +574,9 @@ new_link->value = i->value; /* Try and be clever here, too. */ - if (!op->key_values) + if (!dst->key_values) { - op->key_values = new_link; + dst->key_values = new_link; tail = new_link; } else @@ -592,7 +587,7 @@ } } - update_ob_speed (op); + update_ob_speed (dst); } /* @@ -950,7 +945,7 @@ if (QUERY_FLAG (op, FLAG_STARTEQUIP) || QUERY_FLAG (op, FLAG_NO_DROP) || op->type == RUNE || op->type == TRAP || QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) - op->destroy (0); + op->destroy (); else { op->x = x; @@ -1205,8 +1200,7 @@ /* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/ op->weight = 0; /* Don't want any adjustements now */ - op->remove (); - op->destroy (0); + op->destroy (); return top; } } @@ -1346,8 +1340,7 @@ if (CAN_MERGE (op, tmp)) { op->nrof += tmp->nrof; - tmp->remove (); - tmp->destroy (0); + tmp->destroy (); } CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ @@ -1543,13 +1536,8 @@ /* first search for itself and remove any old instances */ for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) - { - if (!strcmp (tmp->arch->name, arch_string)) /* same archetype */ - { - tmp->remove (); - tmp->destroy (0); - } - } + if (!strcmp (tmp->arch->name, arch_string)) /* same archetype */ + tmp->destroy (); tmp1 = arch_to_object (archetype::find (arch_string)); @@ -1569,10 +1557,8 @@ object * get_split_ob (object *orig_ob, uint32 nr) { - object * - newob; - int - is_removed = (QUERY_FLAG (orig_ob, FLAG_REMOVED) != 0); + object *newob; + int is_removed = (QUERY_FLAG (orig_ob, FLAG_REMOVED) != 0); if (orig_ob->nrof < nr) { @@ -1692,7 +1678,7 @@ return op; else { - op->destroy (0); + op->destroy (); return NULL; } } @@ -2534,8 +2520,8 @@ prev = 0; for (part = src; part; part = part->more) { - tmp = get_object (); - copy_object (part, tmp); + tmp = object::create (); + part->copy_to (tmp); tmp->x -= src->x; tmp->y -= src->y; @@ -2589,7 +2575,7 @@ fprintf (tempfile, obstr); fclose (tempfile); - op = get_object (); + op = object::create (); object_thawer thawer (filename);