--- deliantra/server/common/object.C 2008/05/07 13:38:16 1.239 +++ deliantra/server/common/object.C 2008/08/31 02:01:41 1.255 @@ -188,12 +188,9 @@ || ob1->name != ob2->name) 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. @@ -208,7 +205,7 @@ if (QUERY_FLAG (ob2, FLAG_IDENTIFIED)) SET_FLAG (ob2, FLAG_BEEN_APPLIED); - if (ob1->arch->name != ob2->arch->name + if (ob1->arch->archname != ob2->arch->archname || ob1->name != ob2->name || ob1->title != ob2->title || ob1->msg != ob2->msg @@ -219,6 +216,7 @@ || ob1->skill != ob2->skill || ob1->value != ob2->value || ob1->animation_id != ob2->animation_id + || (ob1->face != ob2->face && !ob1->animation_id) // face and animation are dependent on each other || ob1->client_type != ob2->client_type || ob1->materialname != ob2->materialname || ob1->lore != ob2->lore @@ -236,7 +234,6 @@ if ((ob1->flag ^ ob2->flag) .reset (FLAG_INV_LOCKED) - .reset (FLAG_CLIENT_SENT) .reset (FLAG_REMOVED) .any ()) return 0; @@ -346,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; } } @@ -480,13 +478,13 @@ find_object_name (const char *str) { shstr_cmp str_ (str); - object *op; - for_all_objects (op) - if (op->name == str_) - break; + if (str_) + for_all_objects (op) + if (op->name == str_) + return op; - return op; + return 0; } /* @@ -770,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) @@ -910,10 +908,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 */ @@ -1118,6 +1113,8 @@ above = 0; below = 0; + ms.flags_ = 0; + if (map->in_memory == MAP_SAVING) return; @@ -1159,13 +1156,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); } @@ -1238,6 +1228,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; @@ -1270,7 +1262,23 @@ 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 (op->face && !face_info (op->face))//D TODO: remove soon + {//D + LOG (llevError | logBacktrace, "op->face out of bounds: %s", op->debug_desc ());//D + op->face = 1;//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 @@ -1312,12 +1320,16 @@ if (flag & INS_BELOW_ORIGINATOR) { - if (originator->map != op->map || originator->x != op->x || originator->y != op->y || !originator->is_on_map ()) + if (originator->map != op->map || originator->x != op->x || originator->y != op->y) { LOG (llevError, "insert_ob_in_map called with INS_BELOW_ORIGINATOR when originator not on same space!\n"); abort (); } + if (!originator->is_on_map ()) + LOG (llevDebug | logBacktrace, "insert_ob_in_map(%s) called with INS_BELOW_ORIGINATOR when originator '%s' not on map", + op->debug_desc (), originator->debug_desc ()); + op->above = originator; op->below = originator->below; originator->below = op; @@ -1393,10 +1405,7 @@ if (flag & INS_ABOVE_FLOOR_ONLY) top = floor; - /* Top is the object that our object (op) is going to get inserted above. - */ - - /* no top found, insert at bottom */ + // insert object above top, or bottom-most if top = 0 if (!top) { op->below = 0; @@ -1406,14 +1415,14 @@ *(op->above ? &op->above->below : &ms.top) = op; } else - { /* get inserted into the stack above top */ + { op->above = top->above; top->above = op; op->below = top; *(op->above ? &op->above->below : &ms.top) = op; } - } /* else not INS_BELOW_ORIGINATOR */ + } if (op->type == PLAYER) { @@ -1519,11 +1528,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); @@ -1532,7 +1540,7 @@ } else { - destroy (1); + destroy (); return false; } } @@ -2418,12 +2426,13 @@ char info2[256 * 4]; char *p = info; - p += snprintf (p, 512, "{cnt:%d,uuid:%s,name:\"%s\"%s%s,flags:[%s],type:%d}", + p += snprintf (p, 512, "{cnt:%d,uuid:%s,name:\"%s\"%s%s%s,flags:[%s],type:%d}", count, uuid.c_str (), &name, - title ? "\",title:\"" : "", + title ? ",title:\"" : "", title ? (const char *)title : "", + title ? "\"" : "", flag_desc (flagdesc, 512), type); if (!flag[FLAG_REMOVED] && env)