--- deliantra/server/common/object.C 2008/04/21 21:32:32 1.211 +++ deliantra/server/common/object.C 2008/04/21 23:35:24 1.212 @@ -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,6 +932,9 @@ void object::do_destroy () { + if (object *pl = visible_to ()) + esrv_del_item (pl->contr, count); + attachable::do_destroy (); if (flag [FLAG_IS_LINKED]) @@ -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 = op->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;