--- deliantra/server/common/object.C 2006/12/13 00:42:03 1.65 +++ deliantra/server/common/object.C 2006/12/20 09:14:21 1.74 @@ -32,6 +32,8 @@ #include #include +#include + int nrofallocobjects = 0; static UUID uuid; const uint64 UUID_SKIP = 1<<19; @@ -185,21 +187,23 @@ * replaces - this is mostly for clarity - a decent compiler should hopefully * reduce this to the same efficiency. * - * Check nrof variable *before* calling CAN_MERGE() + * Check nrof variable *before* calling can_merge() * * Improvements made with merge: Better checking on potion, and also * check weight */ -bool object::can_merge (object *ob1, object *ob2) +bool object::can_merge_slow (object *ob1, object *ob2) { /* A couple quicksanity checks */ - if ((ob1 == ob2) || (ob1->type != ob2->type)) - return 0; - - if (ob1->speed != ob2->speed) + if (ob1 == ob2 + || ob1->type != ob2->type + || ob1->speed != ob2->speed + || ob1->value != ob2->value + || ob1->name != ob2->name) return 0; + //TODO: this ain't working well, use nicer and correct overflow check /* Do not merge objects if nrof would overflow. We use 1UL<<31 since that * value could not be stored in a sint32 (which unfortunately sometimes is * used to store nrof). @@ -219,37 +223,31 @@ if (QUERY_FLAG (ob2, FLAG_IDENTIFIED)) SET_FLAG (ob2, FLAG_BEEN_APPLIED); - - /* the 0x400000 on flags2 is FLAG_INV_LOCK. I don't think something - * being locked in inventory should prevent merging. - * 0x4 in flags3 is CLIENT_SENT - */ - if ((ob1->arch != ob2->arch) || - (ob1->flags[0] != ob2->flags[0]) || - (ob1->flags[1] != ob2->flags[1]) || - ((ob1->flags[2] & ~0x400000) != (ob2->flags[2] & ~0x400000)) || - ((ob1->flags[3] & ~0x4) != (ob2->flags[3] & ~0x4)) || - (ob1->name != ob2->name) || - (ob1->title != ob2->title) || - (ob1->msg != ob2->msg) || - (ob1->weight != ob2->weight) || - (memcmp (&ob1->resist, &ob2->resist, sizeof (ob1->resist)) != 0) || - (memcmp (&ob1->stats, &ob2->stats, sizeof (ob1->stats)) != 0) || - (ob1->attacktype != ob2->attacktype) || - (ob1->magic != ob2->magic) || - (ob1->slaying != ob2->slaying) || - (ob1->skill != ob2->skill) || - (ob1->value != ob2->value) || - (ob1->animation_id != ob2->animation_id) || - (ob1->client_type != ob2->client_type) || - (ob1->materialname != ob2->materialname) || - (ob1->lore != ob2->lore) || - (ob1->subtype != ob2->subtype) || - (ob1->move_type != ob2->move_type) || - (ob1->move_block != ob2->move_block) || - (ob1->move_allow != ob2->move_allow) || - (ob1->move_on != ob2->move_on) || - (ob1->move_off != ob2->move_off) || (ob1->move_slow != ob2->move_slow) || (ob1->move_slow_penalty != ob2->move_slow_penalty)) + if ((ob1->flags ^ ob2->flags).reset (FLAG_INV_LOCKED).reset (FLAG_CLIENT_SENT).any () + || ob1->arch != ob2->arch + || ob1->name != ob2->name + || ob1->title != ob2->title + || ob1->msg != ob2->msg + || ob1->weight != ob2->weight + || memcmp (&ob1->resist, &ob2->resist, sizeof (ob1->resist)) + || memcmp (&ob1->stats , &ob2->stats , sizeof (ob1->stats) ) + || ob1->attacktype != ob2->attacktype + || ob1->magic != ob2->magic + || ob1->slaying != ob2->slaying + || ob1->skill != ob2->skill + || ob1->value != ob2->value + || ob1->animation_id != ob2->animation_id + || ob1->client_type != ob2->client_type + || ob1->materialname != ob2->materialname + || ob1->lore != ob2->lore + || ob1->subtype != ob2->subtype + || ob1->move_type != ob2->move_type + || ob1->move_block != ob2->move_block + || ob1->move_allow != ob2->move_allow + || ob1->move_on != ob2->move_on + || ob1->move_off != ob2->move_off + || ob1->move_slow != ob2->move_slow + || ob1->move_slow_penalty != ob2->move_slow_penalty) return 0; /* This is really a spellbook check - really, we should @@ -262,7 +260,7 @@ return 0; /* Now check to see if the two inventory objects could merge */ - if (!CAN_MERGE (ob1->inv, ob2->inv)) + if (!object::can_merge (ob1->inv, ob2->inv)) return 0; /* inventory ok - still need to check rest of this object to see @@ -356,21 +354,6 @@ } /* - * Eneq(@csd.uu.se): Since we can have items buried in a character we need - * a better check. We basically keeping traversing up until we can't - * or find a player. - */ - -object * -is_player_inv (object *op) -{ - for (; op != NULL && op->type != PLAYER; op = op->env) - if (op->env == op) - op->env = NULL; - return op; -} - -/* * Used by: Crossedit: dump. Server DM commands: dumpbelow, dump. * Some error messages. * The result of the dump is stored in the static global errmsg array. @@ -1059,7 +1042,7 @@ * made to players inventory. If set, avoiding the call * to save cpu time. */ - if ((otmp = is_player_inv (env)) != NULL && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) + if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) fix_player (otmp); if (above != NULL) @@ -1140,7 +1123,7 @@ tmp->container = 0; } - tmp->contr->socket.update_look = 1; + tmp->contr->socket->floorbox_update (); } /* See if player moving off should effect something */ @@ -1202,7 +1185,8 @@ { if (top == op) continue; - if (CAN_MERGE (op, top)) + + if (object::can_merge (op, top)) { top->nrof += op->nrof; @@ -1345,7 +1329,7 @@ */ if (op->nrof && !(flag & INS_NO_MERGE)) for (tmp = GET_MAP_OB (op->map, x, y); tmp != NULL; tmp = tmp->above) - if (CAN_MERGE (op, tmp)) + if (object::can_merge (op, tmp)) { op->nrof += tmp->nrof; tmp->destroy (); @@ -1486,7 +1470,7 @@ if (!(flag & INS_MAP_LOAD)) for (tmp = floor ? floor : GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) if (tmp->type == PLAYER) - tmp->contr->socket.update_look = 1; + tmp->contr->socket->floorbox_update (); /* If this object glows, it may affect lighting conditions that are * visible to others on this map. But update_all_los is really @@ -1504,7 +1488,7 @@ update_object (op, UP_OBJ_INSERT); /* Don't know if moving this to the end will break anything. However, - * we want to have update_look set above before calling this. + * we want to have floorbox_update called before calling this. * * check_move_on() must be after this because code called from * check_move_on() depends on correct map flags (so functions like @@ -1617,12 +1601,12 @@ if (QUERY_FLAG (op, FLAG_REMOVED)) op->nrof -= i; - else if (op->env != NULL) + else if (op->env) { /* is this object in the players inventory, or sub container * therein? */ - tmp = is_player_inv (op->env); + tmp = op->in_player (); /* nope. Is this a container the player has opened? * If so, set tmp to that player. * IMO, searching through all the players will mostly @@ -1633,11 +1617,10 @@ { for (pl = first_player; pl; pl = pl->next) if (pl->ob->container == op->env) - break; - if (pl) - tmp = pl->ob; - else - tmp = NULL; + { + tmp = pl->ob; + break; + } } if (i < op->nrof) @@ -1645,18 +1628,14 @@ sub_weight (op->env, op->weight * i); op->nrof -= i; if (tmp) - { - esrv_send_item (tmp, op); - } + esrv_send_item (tmp, op); } else { op->remove (); op->nrof = 0; if (tmp) - { - esrv_del_item (tmp->contr, op->count); - } + esrv_del_item (tmp->contr, op->count); } } else @@ -1672,7 +1651,7 @@ } /* Since we just removed op, op->above is null */ - for (tmp = above; tmp != NULL; tmp = tmp->above) + for (tmp = above; tmp; tmp = tmp->above) if (tmp->type == PLAYER) { if (op->nrof) @@ -1687,7 +1666,7 @@ else { op->destroy (); - return NULL; + return 0; } } @@ -1757,7 +1736,7 @@ if (op->nrof) { for (tmp = inv; tmp != NULL; tmp = tmp->below) - if (CAN_MERGE (tmp, op)) + if (object::can_merge (tmp, op)) { /* return the original object and remove inserted object (client needs the original object) */ @@ -1785,15 +1764,15 @@ else add_weight (this, (op->weight + op->carrying)); - otmp = is_player_inv (this); + otmp = this->in_player (); if (otmp && otmp->contr) if (!QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) fix_player (otmp); - op->map = NULL; + op->map = 0; op->env = this; - op->above = NULL; - op->below = NULL; + op->above = 0; + op->below = 0; op->x = 0, op->y = 0; /* reset the light list and los of the players on the map */ @@ -2140,11 +2119,13 @@ * to only the spaces immediately surrounding the target area, and * won't look 2 spaces south of the target space. */ - else if ((flag & AB_NO_PASS) && maxfree[i] < stop) + else if ((flag & P_NO_PASS) && maxfree[i] < stop) stop = maxfree[i]; } + if (!index) return -1; + return altern[RANDOM () % index]; }