--- deliantra/server/common/object.C 2006/12/26 08:54:59 1.87 +++ deliantra/server/common/object.C 2006/12/26 09:52:40 1.89 @@ -780,6 +780,45 @@ next = 0; } +/* + * Remove and free all objects in the inventory of the given object. + * object.c ? + */ +void +object::destroy_inv (bool drop_to_ground) +{ + /* Only if the space blocks everything do we not process - + * if some form of movement is allowed, let objects + * drop on that space. + */ + if (!drop_to_ground || !map || map->in_memory != MAP_IN_MEMORY || GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL) + { + while (inv) + inv->destroy (); + } + else + { /* Put objects in inventory onto this space */ + while (inv) + { + object *op = inv; + + if (op->flag [FLAG_STARTEQUIP] + || op->flag [FLAG_NO_DROP] + || op->type == RUNE + || op->type == TRAP + || op->flag [FLAG_IS_A_TEMPLATE]) + op->destroy (); + else + { + op->remove (); + op->x = x; + op->y = y; + insert_ob_in_map (op, map, 0, 0); /* Insert in same map as the envir */ + } + } + } +} + object *object::create () { object *op = new object; @@ -806,6 +845,10 @@ flag [FLAG_FREED] = 1; + destroy_inv (true); + set_speed (0); + unlink (); + // hack to ensure that freed objects still have a valid map { static maptile *freed_map; // freed objects are moved here to avoid crashes @@ -826,9 +869,13 @@ y = 1; } - more = 0; head = 0; - inv = 0; + + if (more) + { + more->destroy (); + more = 0; + } // clear those pointers that likely might have circular references to us owner = 0; @@ -837,56 +884,6 @@ // only relevant for players(?), but make sure of it anyways contr = 0; - - /* Remove object from the active list */ - set_speed (0); - - unlink (); -} - -/* - * Remove and free all objects in the inventory of the given object. - * object.c ? - */ -void -object::destroy_inv (bool drop_to_ground) -{ - if (!inv) - return; - - /* Only if the space blocks everything do we not process - - * if some form of movement is allowed, let objects - * drop on that space. - */ - if (!drop_to_ground || !map || map->in_memory != MAP_IN_MEMORY || GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL) - { - while (inv) - { - inv->destroy_inv (drop_to_ground); - inv->destroy (); - } - } - else - { /* Put objects in inventory onto this space */ - while (inv) - { - object *op = inv; - - if (op->flag [FLAG_STARTEQUIP] - || op->flag [FLAG_NO_DROP] - || op->type == RUNE - || op->type == TRAP - || op->flag [FLAG_IS_A_TEMPLATE]) - op->destroy (); - else - { - op->remove (); - op->x = x; - op->y = y; - insert_ob_in_map (op, map, 0, 0); /* Insert in same map as the envir */ - } - } - } } void @@ -895,15 +892,8 @@ if (destroyed ()) return; - if (more) - { - //TODO: non-head objects must not have inventory - more->destroy (destroy_inventory); - more = 0; - } - if (destroy_inventory) - destroy_inv (true); + destroy_inv (false); attachable::destroy (); }