--- deliantra/server/common/object.C 2008/04/24 12:06:01 1.221 +++ deliantra/server/common/object.C 2008/05/02 20:28:44 1.225 @@ -608,13 +608,11 @@ object & object::operator =(const object &src) { - bool is_freed = flag [FLAG_FREED]; - bool is_removed = flag [FLAG_REMOVED]; + remove (); *(object_copy *)this = src; - flag [FLAG_FREED] = is_freed; - flag [FLAG_REMOVED] = is_removed; + flag [FLAG_REMOVED] = true; /* Copy over key_values, if any. */ if (src.key_values) @@ -688,6 +686,7 @@ { object *neu = create (); copy_to (neu); + neu->map = map; // not copied by copy_to return neu; } @@ -748,14 +747,14 @@ void update_object (object *op, int action) { - if (op == NULL) + if (!op) { /* this should never happen */ - LOG (llevDebug, "update_object() called for NULL object.\n"); + LOG (llevError | logBacktrace, "update_object() called for NULL object.\n"); return; } - if (op->env) + if (!op->is_on_map ()) { /* Animation is currently handled by client, so nothing * to do in this case. @@ -763,12 +762,6 @@ return; } - /* If the map is saving, don't do anything as everything is - * going to get freed anyways. - */ - if (!op->map || op->map->in_memory == MAP_SAVING) - return; - /* make sure the object is within map boundaries */ if (op->x < 0 || op->x >= op->map->width || op->y < 0 || op->y >= op->map->height) { @@ -967,6 +960,21 @@ return op; } +static struct freed_map : maptile +{ + freed_map () + { + path = ""; + name = "/internal/freed_objects_map"; + width = 3; + height = 3; + nodrop = 1; + + alloc (); + in_memory = MAP_ACTIVE; + } +} freed_map; // freed objects are moved here to avoid crashes + void object::do_destroy () { @@ -986,27 +994,9 @@ flag [FLAG_FREED] = 1; // hack to ensure that freed objects still have a valid map - { - static maptile *freed_map; // freed objects are moved here to avoid crashes - - if (!freed_map) - { - freed_map = new maptile; - - freed_map->path = ""; - freed_map->name = "/internal/freed_objects_map"; - freed_map->width = 3; - freed_map->height = 3; - freed_map->nodrop = 1; - - freed_map->alloc (); - freed_map->in_memory = MAP_ACTIVE; - } - - map = freed_map; - x = 1; - y = 1; - } + map = &freed_map; + x = 1; + y = 1; if (more) { @@ -1033,6 +1023,7 @@ { LOG (llevError | logBacktrace, "tried to destroy the tail of an object"); head->destroy (destroy_inventory); + return; } destroy_inv (!destroy_inventory); @@ -2336,17 +2327,18 @@ object * object_create_clone (object *asrc) { - object *dst = 0, *tmp, *src, *prev, *item; + object *dst = 0; if (!asrc) return 0; - src = asrc->head_ (); + object *src = asrc->head_ (); - prev = 0; + object *prev = 0; for (object *part = src; part; part = part->more) { - tmp = part->clone (); + object *tmp = part->clone (); + tmp->x -= src->x; tmp->y -= src->y; @@ -2366,7 +2358,7 @@ prev = tmp; } - for (item = src->inv; item; item = item->below) + for (object *item = src->inv; item; item = item->below) insert_ob_in_ob (object_create_clone (item), dst); return dst;