--- deliantra/server/common/object.C 2008/05/06 20:08:37 1.236 +++ deliantra/server/common/object.C 2008/05/06 21:04:37 1.237 @@ -1059,14 +1059,6 @@ adjust_weight (env, -total_weight ()); - // make sure cmov optimisation is applicable - *(above ? &above->below : &env->inv) = below; - *(below ? &below->above : &above ) = above; // &above is just a dummy - - above = 0; - below = 0; - env = 0; - /* we set up values so that it could be inserted into * the map, but we don't actually do that - it is up * to the caller to decide what we want to do. @@ -1075,6 +1067,14 @@ x = env->x; y = env->y; + // make sure cmov optimisation is applicable + *(above ? &above->below : &env->inv) = below; + *(below ? &below->above : &above ) = above; // &above is just a dummy + + above = 0; + below = 0; + env = 0; + /* NO_FIX_PLAYER is set when a great many changes are being * made to players inventory. If set, avoiding the call * to save cpu time. @@ -1269,8 +1269,6 @@ object * insert_ob_in_map (object *op, maptile *m, object *originator, int flag) { - assert (!op->flag [FLAG_FREED]); - op->remove (); /* Ideally, the caller figures this out. However, it complicates a lot @@ -1298,7 +1296,7 @@ for (object *tmp = ms.bot; tmp; tmp = tmp->above) if (object::can_merge (op, tmp)) { - // TODO: we atcually want to update tmp, not op, + // TODO: we actually want to update tmp, not op, // but some caller surely breaks when we return tmp // from here :/ op->nrof += tmp->nrof; @@ -1313,7 +1311,7 @@ if (flag & INS_BELOW_ORIGINATOR) { - if (originator->map != op->map || originator->x != op->x || originator->y != op->y) + if (originator->map != op->map || originator->x != op->x || originator->y != op->y || !originator->is_on_map ()) { LOG (llevError, "insert_ob_in_map called with INS_BELOW_ORIGINATOR when originator not on same space!\n"); abort (); @@ -1321,26 +1319,18 @@ op->above = originator; op->below = originator->below; - - if (op->below) - op->below->above = op; - else - ms.bot = op; - - /* since *below* originator, no need to update top */ originator->below = op; + + *(op->below ? &op->below->above : &ms.bot) = op; } else { - object *top, *floor = NULL; - - top = ms.bot; + object *floor = 0; + object *top = ms.top; /* If there are other objects, then */ if (top) { - object *last = 0; - /* * If there are multiple objects on this space, we do some trickier handling. * We've already dealt with merging if appropriate. @@ -1353,24 +1343,21 @@ * when lots of spells are cast in one area. Currently, it is presumed * that flying non pickable objects are spell objects. */ - for (top = ms.bot; top; top = top->above) + for (object *tmp = ms.bot; tmp; tmp = tmp->above) { - if (QUERY_FLAG (top, FLAG_IS_FLOOR) || QUERY_FLAG (top, FLAG_OVERLAY_FLOOR)) - floor = top; + if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) || QUERY_FLAG (tmp, FLAG_OVERLAY_FLOOR)) + floor = tmp; - if (QUERY_FLAG (top, FLAG_NO_PICK) && (top->move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) && !QUERY_FLAG (top, FLAG_IS_FLOOR)) + if (QUERY_FLAG (tmp, FLAG_NO_PICK) && (tmp->move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) && !QUERY_FLAG (tmp, FLAG_IS_FLOOR)) { /* We insert above top, so we want this object below this */ - top = top->below; + top = tmp->below; break; } - last = top; + top = tmp; } - /* Don't want top to be NULL, so set it to the last valid object */ - top = last; - /* We let update_position deal with figuring out what the space * looks like instead of lots of conditions here. * makes things faster, and effectively the same result. @@ -1386,6 +1373,8 @@ && ms.flags () & P_BLOCKSVIEW && (op->face && !faces [op->face].visibility)) { + object *last; + for (last = top; last != floor; last = last->below) if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT)) break; @@ -1406,30 +1395,23 @@ /* Top is the object that our object (op) is going to get inserted above. */ - /* First object on this space */ + /* no top found, insert on top */ if (!top) { - op->above = ms.bot; + op->above = 0; + op->below = ms.top; + ms.top = op; - if (op->above) - op->above->below = op; - - op->below = 0; - ms.bot = op; + *(op->below ? &op->below->above : &ms.bot) = op; } else { /* get inserted into the stack above top */ op->above = top->above; - - if (op->above) - op->above->below = op; + top->above = op; op->below = top; - top->above = op; + *(op->above ? &op->above->below : &ms.top) = op; } - - if (!op->above) - ms.top = op; } /* else not INS_BELOW_ORIGINATOR */ if (op->type == PLAYER)