--- deliantra/server/common/object.C 2008/04/23 07:13:23 1.217 +++ deliantra/server/common/object.C 2008/04/30 08:29:31 1.223 @@ -336,7 +336,7 @@ object * object::visible_to () const { - if (!flag [FLAG_REMOVED]) + if (client_visible () && !flag [FLAG_REMOVED]) { // see if we are in a container of sorts if (env) @@ -360,7 +360,8 @@ // maybe there is a player standing on the same mapspace // this will catch the case where "this" is a player if (object *pl = ms ().player ()) - return pl; + if (!pl->container || this == pl->container) + return pl; } } @@ -747,14 +748,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. @@ -762,12 +763,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) { @@ -966,6 +961,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 () { @@ -985,27 +995,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) { @@ -1028,6 +1020,13 @@ if (destroyed ()) return; + if (!is_head () && !head->destroyed ()) + { + LOG (llevError | logBacktrace, "tried to destroy the tail of an object"); + head->destroy (destroy_inventory); + return; + } + destroy_inv (!destroy_inventory); if (is_head ()) @@ -1057,9 +1056,6 @@ INVOKE_OBJECT (REMOVE, this); - if (object *pl = visible_to ()) - esrv_del_item (pl->contr, count); - flag [FLAG_REMOVED] = true; if (more) @@ -1071,6 +1067,11 @@ */ if (env) { + flag [FLAG_REMOVED] = false; // hack around the issue of visible_to checking flag_removed + if (object *pl = visible_to ()) + esrv_del_item (pl->contr, count); + flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed + adjust_weight (env, -total_weight ()); *(above ? &above->below : &env->inv) = below; @@ -1098,20 +1099,30 @@ } else if (map) { - if (type == PLAYER) + map->dirty = true; + mapspace &ms = this->ms (); + + if (object *pl = ms.player ()) { - // leaving a spot always closes any open container on the ground - if (container && !container->env) - // this causes spurious floorbox updates, but it ensures - // that the CLOSE event is being sent. - close_container (); + if (type == PLAYER) // this == pl(!) + { + // leaving a spot always closes any open container on the ground + if (container && !container->env) + // this causes spurious floorbox updates, but it ensures + // that the CLOSE event is being sent. + close_container (); - --map->players; - map->touch (); - } + --map->players; + map->touch (); + } + else if (pl->container == this) + { + // removing a container should close it + close_container (); + } - map->dirty = true; - mapspace &ms = this->ms (); + esrv_del_item (pl->contr, count); + } /* link the object above us */ if (above) @@ -1151,7 +1162,8 @@ */ pl->close_container (); - esrv_del_item (pl, count); + //TODO: the floorbox prev/next might need updating + esrv_del_item (pl->contr, count); } for (tmp = ms.bot; tmp; tmp = tmp->above) @@ -1287,8 +1299,6 @@ { assert (!op->flag [FLAG_FREED]); - object *top, *floor = NULL; - op->remove (); /* Ideally, the caller figures this out. However, it complicates a lot @@ -1316,6 +1326,9 @@ for (object *tmp = ms.bot; tmp; tmp = tmp->above) if (object::can_merge (op, tmp)) { + // TODO: we atcually want to update tmp, not op, + // but some caller surely breaks when we return tmp + // from here :/ op->nrof += tmp->nrof; tmp->destroy (1); } @@ -1347,6 +1360,8 @@ } else { + object *top, *floor = NULL; + top = ms.bot; /* If there are other objects, then */ @@ -1455,6 +1470,7 @@ op->map->dirty = true; if (object *pl = ms.player ()) + //TODO: the floorbox prev/next might need updating esrv_send_item (pl, op); /* If this object glows, it may affect lighting conditions that are @@ -2606,7 +2622,9 @@ if (container == new_container) return; - if (object *old_container = container) + object *old_container = container; + + if (old_container) { if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) return; @@ -2618,10 +2636,15 @@ closer->destroy (); #endif + // make sure the container is available + esrv_send_item (this, old_container); + old_container->flag [FLAG_APPLIED] = false; container = 0; + // client needs item update to make it work, client bug requires this to be separate esrv_update_item (UPD_FLAGS, this, old_container); + new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); play_sound (sound_find ("chest_close")); } @@ -2644,13 +2667,19 @@ new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); + // make sure the container is available, client bug requires this to be separate + esrv_send_item (this, new_container); + new_container->flag [FLAG_APPLIED] = true; container = new_container; + // client needs flag change esrv_update_item (UPD_FLAGS, this, new_container); esrv_send_inventory (this, new_container); play_sound (sound_find ("chest_open")); } +// else if (!old_container->env && contr && contr->ns) +// contr->ns->floorbox_reset (); } object *