--- deliantra/server/common/object.C 2007/03/15 14:23:02 1.136 +++ deliantra/server/common/object.C 2007/04/16 06:23:40 1.137 @@ -456,7 +456,7 @@ static void free_key_values (object *op) { - for (key_value *i = op->key_values; i != 0;) + for (key_value *i = op->key_values; i; ) { key_value *next = i->next; delete i; @@ -467,40 +467,24 @@ op->key_values = 0; } -/* - * 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 -object::copy_to (object *dst) +object & +object::operator =(const object &src) { - bool is_freed = QUERY_FLAG (dst, FLAG_FREED); - bool is_removed = QUERY_FLAG (dst, FLAG_REMOVED); - - *(object_copy *)dst = *this; - - if (is_freed) - SET_FLAG (dst, FLAG_FREED); + bool is_freed = flag [FLAG_FREED]; + bool is_removed = flag [FLAG_REMOVED]; - if (is_removed) - SET_FLAG (dst, FLAG_REMOVED); + *(object_copy *)this = src; - if (speed < 0) - dst->speed_left = speed_left - rndm (); + flag [FLAG_FREED] = is_freed; + flag [FLAG_REMOVED] = is_removed; /* Copy over key_values, if any. */ - if (key_values) + if (src.key_values) { key_value *tail = 0; - key_value *i; + key_values = 0; - dst->key_values = 0; - - for (i = key_values; i; i = i->next) + for (key_value *i = src.key_values; i; i = i->next) { key_value *new_link = new key_value; @@ -509,9 +493,9 @@ new_link->value = i->value; /* Try and be clever here, too. */ - if (!dst->key_values) + if (!key_values) { - dst->key_values = new_link; + key_values = new_link; tail = new_link; } else @@ -521,6 +505,23 @@ } } } +} + +/* + * 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 +object::copy_to (object *dst) +{ + *dst = *this; + + if (speed < 0) + dst->speed_left = speed_left - rndm (); dst->set_speed (dst->speed); }