--- deliantra/server/common/object.C 2008/04/21 07:01:40 1.210 +++ deliantra/server/common/object.C 2008/04/22 01:18:10 1.213 @@ -26,7 +26,6 @@ #include #include #include -#include #include #include @@ -353,7 +352,14 @@ { weight = weight_adjust (op, weight); + if (!weight) + return; + op->carrying += weight; + + if (object *pl = op->visible_to ()) + esrv_update_item (UPD_WEIGHT, pl, op); + op = op->env; } } @@ -376,7 +382,15 @@ sum += op->total_weight (); } - carrying = weight_adjust (this, sum); + sum = weight_adjust (this, sum); + + if (sum != carrying) + { + carrying = sum; + + if (object *pl = visible_to ()) + esrv_update_item (UPD_WEIGHT, pl, this); + } } /* @@ -918,16 +932,15 @@ void object::do_destroy () { - 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); @@ -1005,12 +1018,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 (); @@ -1480,32 +1497,33 @@ } // find player who can see this object -static object * -visible_to (object *op) +object * +object::visible_to () const { - if (!op->flag [FLAG_REMOVED]) + if (!flag [FLAG_REMOVED]) { // see if we are in a container of sorts - if (object *env = op->env) + if (env) { // the player inventory itself is always visible if (env->type == PLAYER) return env; // else a player could have our env open - env = env->outer_env (); + 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 (env->is_on_map ()) - if (object *pl = env->ms ().player ()) - if (pl->container == op->env) + 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 - if (object *pl = env->ms ().player ()) + // this will catch the case where "this" is a player + if (object *pl = ms ().player ()) return pl; } } @@ -1523,31 +1541,26 @@ bool object::decrease (sint32 nr) { - nr = min (nr, nrof); - if (!nr) - return 1; + return true; - nrof -= nr; + nr = min (nr, nrof); - object *visible = visible_to (this); + nrof -= nr; if (nrof) { adjust_weight (env, -weight * nr); // carrying == 0 - if (visible) - esrv_send_item (visible, this); + if (object *pl = visible_to ()) + esrv_update_item (UPD_NROF, pl, this); - return 1; + return true; } else { - if (visible) - esrv_del_item (visible->contr, count); - - this->destroy (1); - return 0; + destroy (1); + return false; } } @@ -1560,9 +1573,11 @@ object * object::split (sint32 nr) { - if (nrof < nr) + int have = number_of (); + + if (have < nr) return 0; - else if (nrof == nr) + else if (have == nr) { remove (); return this;