--- deliantra/server/common/object.C 2008/05/17 00:17:02 1.243 +++ deliantra/server/common/object.C 2008/09/29 09:04:50 1.258 @@ -188,16 +188,9 @@ || ob1->name != ob2->name) return 0; - // some objects are unmergable - if (!ob1->nrof || !ob2->nrof) - return 0; - - /* Do not merge objects if nrof would overflow. First part checks - * for unsigned overflow (2c), second part checks whether the result - * would fit into a 32 bit signed int, which is often used to hold - * nrof values. - */ - if (~ob1->nrof < ob2->nrof || ob1->nrof + ob2->nrof > (1UL << 31)) + /* Do not merge objects if nrof would overflow, assume nrof + * is always 0 .. 2**31-1 */ + if (ob1->nrof > 0x7fffffff - ob2->nrof) return 0; /* If the objects have been identified, set the BEEN_APPLIED flag. @@ -241,7 +234,6 @@ if ((ob1->flag ^ ob2->flag) .reset (FLAG_INV_LOCKED) - .reset (FLAG_CLIENT_SENT) .reset (FLAG_REMOVED) .any ()) return 0; @@ -351,7 +343,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 ()) - if (!pl->container || this == pl->container) + if ((!pl->container && pl->contr->ns && !pl->contr->ns->update_look) + || this == pl->container) return pl; } } @@ -645,7 +638,7 @@ if (speed < 0) dst->speed_left -= rndm (); - dst->set_speed (dst->speed); + dst->activate (); } void @@ -775,7 +768,7 @@ || (m.move_off | op->move_off ) != m.move_off || (m.move_slow | op->move_slow) != m.move_slow /* This isn't perfect, but I don't expect a lot of objects to - * to have move_allow right now. + * have move_allow right now. */ || ((m.move_block | op->move_block) & ~op->move_allow) != m.move_block || 1) // the above is not strong enough a test to skip updating. los maybe? TODO (Schmorp) @@ -839,6 +832,9 @@ if (active) return; + if (has_active_speed () && flag [FLAG_FREED]) LOG (llevError | logBacktrace, "BUG: tried to activate freed object %s\n", debug_desc ());//D + if (has_active_speed () && flag [FLAG_DEBUG]) LOG (llevError | logBacktrace, "BUG: tried to activate DEBUG object %s\n", debug_desc ());//D temp + if (has_active_speed ()) actives.insert (this); } @@ -915,10 +911,7 @@ || ms ().move_block == MOVE_ALL) { while (inv) - { - inv->destroy_inv (false); - inv->destroy (); - } + inv->destroy (true); } else { /* Put objects in inventory onto this space */ @@ -992,7 +985,7 @@ if (more) { - more->destroy (); + more->destroy (true); more = 0; } @@ -1123,6 +1116,8 @@ above = 0; below = 0; + ms.flags_ = 0; + if (map->in_memory == MAP_SAVING) return; @@ -1164,13 +1159,6 @@ last = tmp; } - /* last == NULL if there are no objects on this space */ - //TODO: this makes little sense, why only update the topmost object? - if (!last) - map->at (x, y).flags_ = 0; - else - update_object (last, UP_OBJ_REMOVE); - if (flag [FLAG_BLOCKSVIEW] || glow_radius) update_all_los (map, x, y); } @@ -1205,7 +1193,7 @@ op->weight = 0; // cancel the addition above op->carrying = 0; // must be 0 already - op->destroy (1); + op->destroy (true); return top; } @@ -1243,6 +1231,8 @@ object * insert_ob_in_map_at (object *op, maptile *m, object *originator, int flag, int x, int y) { + op->remove (); + for (object *tmp = op->head_ (); tmp; tmp = tmp->more) { tmp->x = x + tmp->arch->x; @@ -1275,7 +1265,22 @@ object * insert_ob_in_map (object *op, maptile *m, object *originator, int flag) { - op->remove (); + if (op->is_on_map ()) + { + LOG (llevError, "insert_ob_in_map called for object already on map"); + abort (); + } + + if (op->env) + { + LOG (llevError, "insert_ob_in_map called for object in an inventory (proceeding)"); + op->remove (); + } + + if (m == &freed_map)//D TODO: remove soon + {//D + LOG (llevError | logBacktrace, "tries to insret object on freed objects map: %s", op->debug_desc ());//D + }//D /* Ideally, the caller figures this out. However, it complicates a lot * of areas of callers (eg, anything that uses find_free_spot would now @@ -1283,7 +1288,7 @@ */ if (!xy_normalise (m, op->x, op->y)) { - op->head_ ()->destroy (1);// remove head_ once all tail object destroyers found + op->head_ ()->destroy (true);// remove head_ once all tail object destroyers found return 0; } @@ -1306,7 +1311,7 @@ // but some caller surely breaks when we return tmp // from here :/ op->nrof += tmp->nrof; - tmp->destroy (1); + tmp->destroy (true); } CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ @@ -1491,7 +1496,7 @@ for (object *tmp = op->ms ().bot; tmp; tmp = tmp->above) if (!strcmp (tmp->arch->archname, arch_string)) /* same archetype */ - tmp->destroy (1); + tmp->destroy (true); object *tmp = arch_to_object (archetype::find (arch_string)); @@ -1525,11 +1530,10 @@ nr = min (nr, nrof); - nrof -= nr; - - if (nrof) + if (nrof > nr) { - adjust_weight (env, -weight * nr); // carrying == 0 + nrof -= nr; + adjust_weight (env, -weight * max (1, nr)); // carrying == 0 if (object *pl = visible_to ()) esrv_update_item (UPD_NROF, pl, this); @@ -1538,7 +1542,7 @@ } else { - destroy (1); + destroy (); return false; } } @@ -1625,7 +1629,7 @@ adjust_weight (this, op->total_weight ()); - op->destroy (1); + op->destroy (true); op = tmp; goto inserted; } @@ -2484,7 +2488,7 @@ // remove the "Close old_container" object. if (object *closer = old_container->inv) if (closer->type == CLOSE_CON) - closer->destroy (); + closer->destroy (true); #endif // make sure the container is available @@ -2550,7 +2554,7 @@ object::force_add (const shstr name, int duration) { if (object *force = force_find (name)) - force->destroy (); + force->destroy (true); object *force = get_archetype (FORCE_NAME);