--- deliantra/server/common/object.C 2008/04/21 23:35:24 1.212 +++ deliantra/server/common/object.C 2008/04/22 07:01:46 1.214 @@ -332,6 +332,41 @@ return 1; } +// find player who can see this object +object * +object::visible_to () const +{ + if (!flag [FLAG_REMOVED]) + { + // see if we are in a container of sorts + if (env) + { + // the player inventory itself is always visible + if (env->type == PLAYER) + return env; + + // else a player could have our env open + object *envest = env->outer_env (); + + // the player itself is always on a map, so we will find him here + // even if our inv is in a player. + if (envest->is_on_map ()) + if (object *pl = envest->ms ().player ()) + if (pl->container == env) + return pl; + } + else + { + // 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; + } + } + + return 0; +} + // adjust weight per container type ("of holding") static sint32 weight_adjust (object *op, sint32 weight) @@ -932,19 +967,15 @@ void object::do_destroy () { - if (object *pl = visible_to ()) - esrv_del_item (pl->contr, count); - - attachable::do_destroy (); - if (flag [FLAG_IS_LINKED]) remove_button_link (this); if (flag [FLAG_FRIENDLY]) remove_friendly_object (this); - if (!flag [FLAG_REMOVED]) - remove (); + remove (); + + attachable::do_destroy (); destroy_inv (true); @@ -1022,12 +1053,16 @@ object *tmp, *last = 0; object *otmp; - if (QUERY_FLAG (this, FLAG_REMOVED)) + if (flag [FLAG_REMOVED]) return; - SET_FLAG (this, FLAG_REMOVED); INVOKE_OBJECT (REMOVE, this); + if (object *pl = visible_to ()) + esrv_del_item (pl->contr, count); + + flag [FLAG_REMOVED] = true; + if (more) more->remove (); @@ -1171,20 +1206,20 @@ ; for (; top; top = top->below) - { - if (top == op) - continue; + if (object::can_merge (op, top)) + { + top->nrof += op->nrof; - if (object::can_merge (op, top)) - { - top->nrof += op->nrof; + if (object *pl = top->visible_to ()) + esrv_update_item (UPD_NROF, pl, top); -/* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/ - op->weight = 0; /* Don't want any adjustements now */ - op->destroy (); - return top; - } - } + op->weight = 0; // cancel the addition above + op->carrying = 0; // must be 0 already + + op->destroy (1); + + return top; + } return 0; } @@ -1496,41 +1531,6 @@ return where->map->insert (this, where->x, where->y, originator, flags); } -// find player who can see this object -object * -object::visible_to () const -{ - if (!flag [FLAG_REMOVED]) - { - // see if we are in a container of sorts - if (env) - { - // the player inventory itself is always visible - if (env->type == PLAYER) - return env; - - // else a player could have our env open - object *envest = env->outer_env (); - - // the player itself is always on a map, so we will find him here - // even if our inv is in a player. - if (envest->is_on_map ()) - if (object *pl = envest->ms ().player ()) - if (pl->container == env) - return pl; - } - else - { - // 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; - } - } - - return 0; -} - /* * decrease(object, number) decreases a specified number from * the amount of an object. If the amount reaches 0, the object @@ -1640,6 +1640,10 @@ /* return the original object and remove inserted object (client needs the original object) */ tmp->nrof += op->nrof; + + if (object *pl = tmp->visible_to ()) + esrv_update_item (UPD_NROF, pl, tmp); + adjust_weight (this, op->total_weight ()); op->destroy (1); @@ -1663,6 +1667,9 @@ op->flag [FLAG_REMOVED] = 0; + if (object *pl = op->visible_to ()) + esrv_send_item (pl, op); + adjust_weight (this, op->total_weight ()); inserted: @@ -1670,9 +1677,9 @@ if (op->glow_radius && map && map->darkness) update_all_los (map, x, y); - if (object *otmp = in_player ()) - if (otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) - otmp->update_stats (); + // if this is a player's inventory, update stats + if (type == PLAYER && !flag [FLAG_NO_FIX_PLAYER]) + update_stats (); INVOKE_OBJECT (INSERT, this);