--- deliantra/server/common/object.C 2006/09/27 00:36:08 1.52 +++ deliantra/server/common/object.C 2006/12/19 05:12:52 1.70 @@ -32,6 +32,8 @@ #include #include +#include + int nrofallocobjects = 0; static UUID uuid; const uint64 UUID_SKIP = 1<<19; @@ -106,7 +108,7 @@ uuid.seq = uid; write_uuid (); - LOG (llevDebug, "read UID: %lld\n", uid); + LOG (llevDebug, "read UID: %" PRId64 "\n", uid); fclose (fp); } @@ -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 @@ -376,82 +374,15 @@ * The result of the dump is stored in the static global errmsg array. */ -void -dump_object2 (object *op) -{ - errmsg[0] = 0; - return; - //TODO//D#d# -#if 0 - char *cp; - -/* object *tmp;*/ - - if (op->arch != NULL) - { - strcat (errmsg, "arch "); - strcat (errmsg, op->arch->name ? op->arch->name : "(null)"); - strcat (errmsg, "\n"); - if ((cp = get_ob_diff (op, &empty_archetype->clone)) != NULL) - strcat (errmsg, cp); -# if 0 - /* Don't dump player diffs - they are too long, mostly meaningless, and - * will overflow the buffer. - * Changed so that we don't dump inventory either. This may - * also overflow the buffer. - */ - if (op->type != PLAYER && (cp = get_ob_diff (op, &empty_archetype->clone)) != NULL) - strcat (errmsg, cp); - for (tmp = op->inv; tmp; tmp = tmp->below) - dump_object2 (tmp); -# endif - strcat (errmsg, "end\n"); - } - else - { - strcat (errmsg, "Object "); - if (op->name == NULL) - strcat (errmsg, "(null)"); - else - strcat (errmsg, op->name); - strcat (errmsg, "\n"); -# if 0 - if ((cp = get_ob_diff (op, &empty_archetype->clone)) != NULL) - strcat (errmsg, cp); - for (tmp = op->inv; tmp; tmp = tmp->below) - dump_object2 (tmp); -# endif - strcat (errmsg, "end\n"); - } -#endif -} - -/* - * Dumps an object. Returns output in the static global errmsg array. - */ - -void +char * dump_object (object *op) { - if (op == NULL) - { - strcpy (errmsg, "[NULL pointer]"); - return; - } - errmsg[0] = '\0'; - dump_object2 (op); -} - -void -dump_all_objects (void) -{ - object *op; + if (!op) + return strdup ("[NULLOBJ]"); - for (op = object::first; op != NULL; op = op->next) - { - dump_object (op); - fprintf (logfile, "Object %s\n", errmsg); - } + object_freezer freezer; + save_object (freezer, op, 3); + return freezer.as_string (); } /* @@ -481,13 +412,11 @@ object * find_object (tag_t i) { - object *op; - - for (op = object::first; op != NULL; op = op->next) + for (object *op = object::first; op; op = op->next) if (op->count == i) - break; + return op; - return op; + return 0; } /* @@ -597,48 +526,44 @@ casting_time = -1; } -void object::clone (object *destination) -{ - *(object_copy *)destination = *this; - *(object_pod *)destination = *this; - - if (self || cb) - INVOKE_OBJECT (CLONE, this, ARG_OBJECT (destination)); -} - /* - * copy object first frees everything allocated by the second object, - * and then copies the contends of the first object into the second + * copy_to first frees everything allocated by the dst object, + * and then copies the contents of itself into the second * object, allocating what needs to be allocated. Basically, any * data that is malloc'd needs to be re-malloc/copied. Otherwise, * if the first object is freed, the pointers in the new object * will point at garbage. */ void -copy_object (object *op2, object *op) +object::copy_to (object *dst) { - bool is_freed = QUERY_FLAG (op, FLAG_FREED); - bool is_removed = QUERY_FLAG (op, FLAG_REMOVED); + bool is_freed = QUERY_FLAG (dst, FLAG_FREED); + bool is_removed = QUERY_FLAG (dst, FLAG_REMOVED); + + *(object_copy *)dst = *this; + *(object_pod *)dst = *this; - op2->clone (op); + if (self || cb) + INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst)); if (is_freed) - SET_FLAG (op, FLAG_FREED); + SET_FLAG (dst, FLAG_FREED); + if (is_removed) - SET_FLAG (op, FLAG_REMOVED); + SET_FLAG (dst, FLAG_REMOVED); - if (op2->speed < 0) - op->speed_left = op2->speed_left - RANDOM () % 200 / 100.0; + if (speed < 0) + dst->speed_left = speed_left - RANDOM () % 200 / 100.0; /* Copy over key_values, if any. */ - if (op2->key_values) + if (key_values) { key_value *tail = 0; key_value *i; - op->key_values = 0; + dst->key_values = 0; - for (i = op2->key_values; i; i = i->next) + for (i = key_values; i; i = i->next) { key_value *new_link = new key_value; @@ -647,9 +572,9 @@ new_link->value = i->value; /* Try and be clever here, too. */ - if (!op->key_values) + if (!dst->key_values) { - op->key_values = new_link; + dst->key_values = new_link; tail = new_link; } else @@ -660,7 +585,15 @@ } } - update_ob_speed (op); + update_ob_speed (dst); +} + +object * +object::clone () +{ + object *neu = create (); + copy_to (neu); + return neu; } /* @@ -875,6 +808,7 @@ if ((move_slow | op->move_slow) != move_slow) update_now = 1; } + /* if the object is being removed, we can't make intelligent * decisions, because remove_ob can't really pass the object * that is being removed. @@ -910,14 +844,6 @@ delete *i; mortals.erase (i); } - - static int lastmortals = 0;//D - - if (mortals.size() != lastmortals && lastmortals > 100)//D - { - lastmortals = mortals.size ();//D - LOG (llevDebug, "%d objects in mortal queue\n", lastmortals);//D - } } object::object () @@ -986,7 +912,7 @@ remove_friendly_object (this); if (!QUERY_FLAG (this, FLAG_REMOVED)) - remove_ob (this); + remove (); SET_FLAG (this, FLAG_FREED); @@ -1021,11 +947,11 @@ { object *tmp = op->below; - remove_ob (op); + op->remove (); if (QUERY_FLAG (op, FLAG_STARTEQUIP) || QUERY_FLAG (op, FLAG_NO_DROP) || op->type == RUNE || op->type == TRAP || QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) - free_object (op); + op->destroy (); else { op->x = x; @@ -1038,6 +964,26 @@ } } + // hack to ensure that freed objects still have a valid map + { + static maptile *freed_map; // freed objects are moved here to avoid crashes + + if (!freed_map) + { + freed_map = new maptile; + + freed_map->name = "/internal/freed_objects_map"; + freed_map->width = 3; + freed_map->height = 3; + + freed_map->allocate (); + } + + map = freed_map; + x = 1; + y = 1; + } + // clear those pointers that likely might have circular references to us owner = 0; enemy = 0; @@ -1059,7 +1005,6 @@ * sub_weight() recursively (outwards) subtracts a number from the * weight of an object (and what is carried by it's environment(s)). */ - void sub_weight (object *op, signed long weight) { @@ -1073,7 +1018,7 @@ } } -/* remove_ob(op): +/* op->remove (): * This function removes the object op from the linked list of objects * which it is currently tied to. When this function is done, the * object will have no environment. If the object previously had an @@ -1081,177 +1026,156 @@ * the previous environment. * Beware: This function is called from the editor as well! */ - void -remove_ob (object *op) +object::remove () { object *tmp, *last = 0; object *otmp; int check_walk_off; - maptile *m; - sint16 x, y; - - if (QUERY_FLAG (op, FLAG_REMOVED)) + if (QUERY_FLAG (this, FLAG_REMOVED)) return; - SET_FLAG (op, FLAG_REMOVED); + SET_FLAG (this, FLAG_REMOVED); - if (op->more != NULL) - remove_ob (op->more); + if (more) + more->remove (); /* * In this case, the object to be removed is in someones * inventory. */ - if (op->env != NULL) + if (env) { - if (op->nrof) - sub_weight (op->env, op->weight * op->nrof); + if (nrof) + sub_weight (env, weight * nrof); else - sub_weight (op->env, op->weight + op->carrying); + sub_weight (env, weight + carrying); /* 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. */ - if ((otmp = is_player_inv (op->env)) != NULL && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) + if ((otmp = is_player_inv (env)) != NULL && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) fix_player (otmp); - if (op->above != NULL) - op->above->below = op->below; + if (above != NULL) + above->below = below; else - op->env->inv = op->below; + env->inv = below; - if (op->below != NULL) - op->below->above = op->above; + if (below != NULL) + below->above = above; /* 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. */ - op->x = op->env->x, op->y = op->env->y; - op->map = op->env->map; - op->above = NULL, op->below = NULL; - op->env = NULL; + x = env->x, y = env->y; + map = env->map; + above = 0, below = 0; + env = 0; } - else if (op->map) + else if (map) { - x = op->x; - y = op->y; - m = get_map_from_coord (op->map, &x, &y); - - if (!m) - { - LOG (llevError, "remove_ob called when object was on map but appears to not be within valid coordinates? %s (%d,%d)\n", - op->map->path, op->x, op->y); - /* in old days, we used to set x and y to 0 and continue. - * it seems if we get into this case, something is probablye - * screwed up and should be fixed. - */ - abort (); - } - - if (op->map != m) - LOG (llevDebug, "remove_ob: Object not really on map it claimed to be on? %s != %s, %d,%d != %d,%d\n", - op->map->path, m->path, op->x, op->y, x, y); - /* Re did the following section of code - it looks like it had * lots of logic for things we no longer care about */ /* link the object above us */ - if (op->above) - op->above->below = op->below; + if (above) + above->below = below; else - SET_MAP_TOP (m, x, y, op->below); /* we were top, set new top */ + SET_MAP_TOP (map, x, y, below); /* we were top, set new top */ /* Relink the object below us, if there is one */ - if (op->below) - op->below->above = op->above; + if (below) + below->above = above; else { /* Nothing below, which means we need to relink map object for this space * use translated coordinates in case some oddness with map tiling is * evident */ - if (GET_MAP_OB (m, x, y) != op) + if (GET_MAP_OB (map, x, y) != this) { - dump_object (op); + char *dump = dump_object (this); LOG (llevError, - "remove_ob: GET_MAP_OB does not return object to be removed even though it appears to be on the bottom?\n%s\n", errmsg); - dump_object (GET_MAP_OB (m, x, y)); - LOG (llevError, "%s\n", errmsg); + "remove_ob: GET_MAP_OB does not return object to be removed even though it appears to be on the bottom?\n%s\n", dump); + free (dump); + dump = dump_object (GET_MAP_OB (map, x, y)); + LOG (llevError, "%s\n", dump); + free (dump); } - SET_MAP_OB (m, x, y, op->above); /* goes on above it. */ + SET_MAP_OB (map, x, y, above); /* goes on above it. */ } - op->above = 0; - op->below = 0; + above = 0; + below = 0; - if (op->map->in_memory == MAP_SAVING) + if (map->in_memory == MAP_SAVING) return; - check_walk_off = !QUERY_FLAG (op, FLAG_NO_APPLY); + check_walk_off = !QUERY_FLAG (this, FLAG_NO_APPLY); - for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) + for (tmp = GET_MAP_OB (map, x, y); tmp; tmp = tmp->above) { /* No point updating the players look faces if he is the object * being removed. */ - if (tmp->type == PLAYER && tmp != op) + if (tmp->type == PLAYER && tmp != this) { /* If a container that the player is currently using somehow gets * removed (most likely destroyed), update the player view * appropriately. */ - if (tmp->container == op) + if (tmp->container == this) { - CLEAR_FLAG (op, FLAG_APPLIED); - tmp->container = NULL; + CLEAR_FLAG (this, FLAG_APPLIED); + tmp->container = 0; } - tmp->contr->socket.update_look = 1; + tmp->contr->socket->floorbox_update (); } /* See if player moving off should effect something */ if (check_walk_off - && ((op->move_type & tmp->move_off) - && (op->move_type & ~tmp->move_off & ~tmp->move_block) == 0)) + && ((move_type & tmp->move_off) + && (move_type & ~tmp->move_off & ~tmp->move_block) == 0)) { - move_apply (tmp, op, NULL); + move_apply (tmp, this, 0); - if (op->destroyed ()) + if (destroyed ()) LOG (llevError, "BUG: remove_ob(): name %s, destroyed leaving object\n", tmp->debug_desc ()); } /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */ if (tmp->above == tmp) - tmp->above = NULL; + tmp->above = 0; last = tmp; } /* last == NULL of there are no objects on this space */ - if (last == NULL) + if (!last) { /* set P_NEED_UPDATE, otherwise update_position will complain. In theory, * we could preserve the flags (GET_MAP_FLAGS), but update_position figures * those out anyways, and if there are any flags set right now, they won't * be correct anyways. */ - SET_MAP_FLAGS (op->map, op->x, op->y, P_NEED_UPDATE); - update_position (op->map, op->x, op->y); + SET_MAP_FLAGS (map, x, y, P_NEED_UPDATE); + update_position (map, x, y); } else update_object (last, UP_OBJ_REMOVE); - if (QUERY_FLAG (op, FLAG_BLOCKSVIEW) || (op->glow_radius != 0)) - update_all_los (op->map, op->x, op->y); + if (QUERY_FLAG (this, FLAG_BLOCKSVIEW) || glow_radius) + update_all_los (map, x, y); } } @@ -1276,14 +1200,14 @@ { if (top == op) continue; - if (CAN_MERGE (op, top)) + + if (object::can_merge (op, top)) { top->nrof += op->nrof; /* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/ op->weight = 0; /* Don't want any adjustements now */ - remove_ob (op); - free_object (op); + op->destroy (); return top; } } @@ -1347,15 +1271,16 @@ if (m == NULL) { - dump_object (op); - LOG (llevError, "Trying to insert in null-map!\n%s\n", errmsg); + char *dump = dump_object (op); + LOG (llevError, "Trying to insert in null-map!\n%s\n", dump); + free (dump); return op; } if (out_of_map (m, op->x, op->y)) { - dump_object (op); - LOG (llevError, "Trying to insert object outside the map.\n%s\n", errmsg); + char *dump = dump_object (op); + LOG (llevError, "Trying to insert object outside the map.\n%s\n", dump); #ifdef MANY_CORES /* Better to catch this here, as otherwise the next use of this object * is likely to cause a crash. Better to find out where it is getting @@ -1363,13 +1288,15 @@ */ abort (); #endif + free (dump); return op; } if (!QUERY_FLAG (op, FLAG_REMOVED)) { - dump_object (op); - LOG (llevError, "Trying to insert (map) inserted object.\n%s\n", errmsg); + char *dump = dump_object (op); + LOG (llevError, "Trying to insert (map) inserted object.\n%s\n", dump); + free (dump); return op; } @@ -1417,11 +1344,10 @@ */ 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; - remove_ob (tmp); - free_object (tmp); + tmp->destroy (); } CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ @@ -1559,7 +1485,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 @@ -1577,7 +1503,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,13 +1543,8 @@ /* first search for itself and remove any old instances */ for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) - { - if (!strcmp (tmp->arch->name, arch_string)) /* same archetype */ - { - remove_ob (tmp); - free_object (tmp); - } - } + if (!strcmp (tmp->arch->name, arch_string)) /* same archetype */ + tmp->destroy (); tmp1 = arch_to_object (archetype::find (arch_string)); @@ -1643,10 +1564,8 @@ object * get_split_ob (object *orig_ob, uint32 nr) { - object * - newob; - int - is_removed = (QUERY_FLAG (orig_ob, FLAG_REMOVED) != 0); + object *newob; + int is_removed = (QUERY_FLAG (orig_ob, FLAG_REMOVED) != 0); if (orig_ob->nrof < nr) { @@ -1657,11 +1576,7 @@ newob = object_create_clone (orig_ob); if ((orig_ob->nrof -= nr) < 1) - { - if (!is_removed) - remove_ob (orig_ob); - free_object2 (orig_ob, 1); - } + orig_ob->destroy (1); else if (!is_removed) { if (orig_ob->env != NULL) @@ -1735,7 +1650,7 @@ } else { - remove_ob (op); + op->remove (); op->nrof = 0; if (tmp) { @@ -1751,7 +1666,7 @@ op->nrof -= i; else { - remove_ob (op); + op->remove (); op->nrof = 0; } @@ -1770,7 +1685,7 @@ return op; else { - free_object (op); + op->destroy (); return NULL; } } @@ -1793,46 +1708,42 @@ } } +object * +insert_ob_in_ob (object *op, object *where) +{ + if (!where) + { + char *dump = dump_object (op); + LOG (llevError, "Trying to put object in NULL.\n%s\n", dump); + free (dump); + return op; + } + + if (where->head) + { + LOG (llevDebug, "Warning: Tried to insert object into wrong part of multipart object.\n"); + where = where->head; + } + + return where->insert (op); +} + /* - * insert_ob_in_ob(op,environment): + * env->insert (op) * This function inserts the object op in the linked list * inside the object environment. * - * Eneq(@csd.uu.se): Altered insert_ob_in_ob to make things picked up enter - * the inventory at the last position or next to other objects of the same - * type. - * Frank: Now sorted by type, archetype and magic! - * * The function returns now pointer to inserted item, and return value can * be != op, if items are merged. -Tero */ object * -insert_ob_in_ob (object *op, object *where) +object::insert (object *op) { - object * - tmp, * - otmp; + object *tmp, *otmp; if (!QUERY_FLAG (op, FLAG_REMOVED)) - { - dump_object (op); - LOG (llevError, "Trying to insert (ob) inserted object.\n%s\n", errmsg); - return op; - } - - if (where == NULL) - { - dump_object (op); - LOG (llevError, "Trying to put object in NULL.\n%s\n", errmsg); - return op; - } - - if (where->head) - { - LOG (llevDebug, "Warning: Tried to insert object wrong part of multipart object.\n"); - where = where->head; - } + op->remove (); if (op->more) { @@ -1844,8 +1755,8 @@ CLEAR_FLAG (op, FLAG_REMOVED); if (op->nrof) { - for (tmp = where->inv; tmp != NULL; tmp = tmp->below) - if (CAN_MERGE (tmp, op)) + for (tmp = inv; tmp != NULL; tmp = tmp->below) + if (object::can_merge (tmp, op)) { /* return the original object and remove inserted object (client needs the original object) */ @@ -1853,11 +1764,11 @@ /* Weight handling gets pretty funky. Since we are adding to * tmp->nrof, we need to increase the weight. */ - add_weight (where, op->weight * op->nrof); + add_weight (this, op->weight * op->nrof); SET_FLAG (op, FLAG_REMOVED); - free_object (op); /* free the inserted object */ + op->destroy (); /* free the inserted object */ op = tmp; - remove_ob (op); /* and fix old object's links */ + op->remove (); /* and fix old object's links */ CLEAR_FLAG (op, FLAG_REMOVED); break; } @@ -1868,45 +1779,44 @@ * the weight, so we need to add it in again, since we actually do * the linking below */ - add_weight (where, op->weight * op->nrof); + add_weight (this, op->weight * op->nrof); } else - add_weight (where, (op->weight + op->carrying)); + add_weight (this, (op->weight + op->carrying)); - otmp = is_player_inv (where); - if (otmp && otmp->contr != NULL) - { - if (!QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) - fix_player (otmp); - } + otmp = is_player_inv (this); + if (otmp && otmp->contr) + if (!QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) + fix_player (otmp); op->map = NULL; - op->env = where; + op->env = this; op->above = NULL; op->below = NULL; op->x = 0, op->y = 0; /* reset the light list and los of the players on the map */ - if ((op->glow_radius != 0) && where->map) + if ((op->glow_radius != 0) && map) { #ifdef DEBUG_LIGHTS LOG (llevDebug, " insert_ob_in_ob(): got %s to insert in map/op\n", op->name); #endif /* DEBUG_LIGHTS */ - if (MAP_DARKNESS (where->map)) - update_all_los (where->map, where->x, where->y); + if (MAP_DARKNESS (map)) + update_all_los (map, x, y); } /* Client has no idea of ordering so lets not bother ordering it here. * It sure simplifies this function... */ - if (where->inv == NULL) - where->inv = op; + if (!inv) + inv = op; else { - op->below = where->inv; + op->below = inv; op->below->above = op; - where->inv = op; + inv = op; } + return op; } @@ -2605,34 +2515,37 @@ object * object_create_clone (object *asrc) { - object * - dst = NULL, *tmp, *src, *part, *prev, *item; + object *dst = 0, *tmp, *src, *part, *prev, *item; if (!asrc) - return NULL; + return 0; + src = asrc; if (src->head) src = src->head; - prev = NULL; + prev = 0; for (part = src; part; part = part->more) { - tmp = get_object (); - copy_object (part, tmp); + tmp = part->clone (); tmp->x -= src->x; tmp->y -= src->y; + if (!part->head) { dst = tmp; - tmp->head = NULL; + tmp->head = 0; } else { tmp->head = dst; } - tmp->more = NULL; + + tmp->more = 0; + if (prev) prev->more = tmp; + prev = tmp; } @@ -2668,7 +2581,7 @@ fprintf (tempfile, obstr); fclose (tempfile); - op = get_object (); + op = object::create (); object_thawer thawer (filename);