--- deliantra/server/common/object.C 2006/09/14 01:19:47 1.42 +++ deliantra/server/common/object.C 2006/09/17 16:21:53 1.51 @@ -1,4 +1,3 @@ - /* CrossFire, A Multiplayer game for X-windows @@ -19,7 +18,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - The authors can be reached via e-mail at crossfire-devel@real-time.com + The authors can be reached via e-mail at */ /* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects. @@ -37,7 +36,6 @@ static UUID uuid; const uint64 UUID_SKIP = 1<<19; -object *objects; /* Pointer to the list of used objects */ object *active_objects; /* List of active objects that need to be processed */ short freearr_x[SIZEOFFREE] = { 0, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, @@ -449,10 +447,10 @@ { object *op; - for (op = objects; op != NULL; op = op->next) + for (op = object::first; op != NULL; op = op->next) { dump_object (op); - fprintf (logfile, "Object %d\n:%s\n", op->count, errmsg); + fprintf (logfile, "Object %s\n", errmsg); } } @@ -485,9 +483,10 @@ { object *op; - for (op = objects; op != NULL; op = op->next) + for (op = object::first; op != NULL; op = op->next) if (op->count == i) break; + return op; } @@ -503,7 +502,7 @@ shstr_cmp str_ (str); object *op; - for (op = objects; op != NULL; op = op->next) + for (op = object::first; op != NULL; op = op->next) if (op->name == str_) break; @@ -517,27 +516,6 @@ } /* - * Returns the object which this object marks as being the owner. - * A id-scheme is used to avoid pointing to objects which have been - * freed and are now reused. If this is detected, the owner is - * set to NULL, and NULL is returned. - * Changed 2004-02-12 - if the player is setting at the play again - * prompt, he is removed, and we don't want to treat him as an owner of - * anything, so check removed flag. I don't expect that this should break - * anything - once an object is removed, it is basically dead anyways. - */ -object * -object::get_owner () -{ - if (!owner - || QUERY_FLAG (owner, FLAG_FREED) - || QUERY_FLAG (owner, FLAG_REMOVED)) - owner = 0; - - return owner; -} - -/* * Sets the owner and sets the skill and exp pointers to owner's current * skill and experience objects. */ @@ -614,7 +592,6 @@ expmul = 1.0; face = blank_face; - attacked_by_count = -1; if (settings.casting_time) casting_time = -1; @@ -919,11 +896,13 @@ update_object (op->more, action); } -static unordered_vector mortals; +object::vector object::mortals; +object::vector object::objects; // not yet used +object *object::first; void object::free_mortals () { - for (unordered_vector::iterator i = mortals.begin (); i != mortals.end ();) + for (AUTODECL (i, mortals.begin ()); i != mortals.end ();) if ((*i)->refcnt) ++i; // further delay freeing else @@ -934,7 +913,7 @@ static int lastmortals = 0;//D - if (mortals.size() != lastmortals)//D + if (mortals.size() != lastmortals && lastmortals > 100)//D { lastmortals = mortals.size ();//D LOG (llevDebug, "%d objects in mortal queue\n", lastmortals);//D @@ -947,7 +926,6 @@ expmul = 1.0; face = blank_face; - attacked_by_count = -1; } object::~object () @@ -961,21 +939,18 @@ uuid = gen_uuid (); prev = 0; - next = objects; + next = object::first; - if (objects) - objects->prev = this; + if (object::first) + object::first->prev = this; - objects = this; + object::first = this; } void object::unlink () { - //count = 0;//D - if (!prev && !next) return;//D - - if (this == objects) - objects = next; + if (this == object::first) + object::first = next; /* Remove this object from the list of used objects */ if (prev) prev->next = next; @@ -1063,7 +1038,10 @@ } } - owner = 0; + // clear those pointers that likely might have circular references to us + owner = 0; + enemy = 0; + attacked_by = 0; /* Remove object from the active list */ speed = 0; @@ -1085,9 +1063,8 @@ while (op != NULL) { if (op->type == CONTAINER) - { - weight = (signed long) (weight * (100 - op->stats.Str) / 100); - } + weight = (signed long) (weight * (100 - op->stats.Str) / 100); + op->carrying -= weight; op = op->env; } @@ -1105,22 +1082,13 @@ void remove_ob (object *op) { - object * - tmp, * - last = NULL; - object * - otmp; + object *tmp, *last = 0; + object *otmp; - tag_t - tag; - int - check_walk_off; - mapstruct * - m; - - sint16 - x, - y; + int check_walk_off; + maptile *m; + + sint16 x, y; if (QUERY_FLAG (op, FLAG_REMOVED)) return; @@ -1223,7 +1191,6 @@ if (op->map->in_memory == MAP_SAVING) return; - tag = op->count; check_walk_off = !QUERY_FLAG (op, FLAG_NO_APPLY); for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) @@ -1248,14 +1215,14 @@ } /* 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)) + if (check_walk_off + && ((op->move_type & tmp->move_off) + && (op->move_type & ~tmp->move_off & ~tmp->move_block) == 0)) { move_apply (tmp, op, NULL); - if (was_destroyed (op, tag)) - { - LOG (llevError, "BUG: remove_ob(): name %s, archname %s destroyed " "leaving object\n", &tmp->name, &tmp->arch->name); - } + if (op->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 */ @@ -1318,7 +1285,7 @@ } } - return NULL; + return 0; } /* @@ -1326,7 +1293,7 @@ * job preparing multi-part monsters */ object * -insert_ob_in_map_at (object *op, mapstruct *m, object *originator, int flag, int x, int y) +insert_ob_in_map_at (object *op, maptile *m, object *originator, int flag, int x, int y) { object *tmp; @@ -1364,7 +1331,7 @@ */ object * -insert_ob_in_map (object *op, mapstruct *m, object *originator, int flag) +insert_ob_in_map (object *op, maptile *m, object *originator, int flag) { object *tmp, *top, *floor = NULL; sint16 x, y; @@ -1655,7 +1622,7 @@ } } - tmp1 = arch_to_object (find_archetype (arch_string)); + tmp1 = arch_to_object (archetype::find (arch_string)); tmp1->x = op->x; tmp1->y = op->y; @@ -1964,25 +1931,15 @@ int check_move_on (object *op, object *originator) { - object * - tmp; - tag_t - tag; - mapstruct * - m = op->map; - int - x = op->x, y = op->y; + object *tmp; + maptile *m = op->map; + int x = op->x, y = op->y; - MoveType - move_on, - move_slow, - move_block; + MoveType move_on, move_slow, move_block; if (QUERY_FLAG (op, FLAG_NO_APPLY)) return 0; - tag = op->count; - move_on = GET_MAP_MOVE_ON (op->map, op->x, op->y); move_slow = GET_MAP_MOVE_SLOW (op->map, op->x, op->y); move_block = GET_MAP_MOVE_BLOCK (op->map, op->x, op->y); @@ -2052,7 +2009,7 @@ { move_apply (tmp, op, originator); - if (was_destroyed (op, tag)) + if (op->destroyed ()) return 1; /* what the person/creature stepped onto has moved the object @@ -2074,7 +2031,7 @@ */ object * -present_arch (const archetype *at, mapstruct *m, int x, int y) +present_arch (const archetype *at, maptile *m, int x, int y) { object * tmp; @@ -2097,7 +2054,7 @@ */ object * -present (unsigned char type, mapstruct *m, int x, int y) +present (unsigned char type, maptile *m, int x, int y) { object * tmp; @@ -2247,7 +2204,7 @@ */ int -find_free_spot (const object *ob, mapstruct *m, int x, int y, int start, int stop) +find_free_spot (const object *ob, maptile *m, int x, int y, int start, int stop) { int i, @@ -2278,14 +2235,14 @@ } /* - * find_first_free_spot(archetype, mapstruct, x, y) works like + * find_first_free_spot(archetype, maptile, x, y) works like * find_free_spot(), but it will search max number of squares. * But it will return the first available spot, not a random choice. * Changed 0.93.2: Have it return -1 if there is no free spot available. */ int -find_first_free_spot (const object *ob, mapstruct *m, int x, int y) +find_first_free_spot (const object *ob, maptile *m, int x, int y) { int i; @@ -2359,7 +2316,7 @@ */ int -find_dir (mapstruct *m, int x, int y, object *exclude) +find_dir (maptile *m, int x, int y, object *exclude) { int i, @@ -2368,7 +2325,7 @@ sint16 nx, ny; object * tmp; - mapstruct * + maptile * mp; MoveType blocked, move_type; @@ -2586,7 +2543,7 @@ int -can_see_monsterP (mapstruct *m, int x, int y, int dir) +can_see_monsterP (maptile *m, int x, int y, int dir) { sint16 dx, dy; int @@ -2676,48 +2633,28 @@ prev = tmp; } - /*** copy inventory ***/ for (item = src->inv; item; item = item->below) - { - (void) insert_ob_in_ob (object_create_clone (item), dst); - } + insert_ob_in_ob (object_create_clone (item), dst); return dst; } -/* return true if the object was destroyed, 0 otherwise */ -int -was_destroyed (const object *op, tag_t old_tag) -{ - /* checking for FLAG_FREED isn't necessary, but makes this function more - * robust */ - return op->count != old_tag || QUERY_FLAG (op, FLAG_FREED); -} - /* GROS - Creates an object using a string representing its content. */ - /* Basically, we save the content of the string to a temp file, then call */ - /* load_object on it. I admit it is a highly inefficient way to make things, */ - /* but it was simple to make and allows reusing the load_object function. */ - /* Remember not to use load_object_str in a time-critical situation. */ - /* Also remember that multiparts objects are not supported for now. */ object * load_object_str (const char *obstr) { - object * - op; - char - filename[MAX_BUF]; + object *op; + char filename[MAX_BUF]; sprintf (filename, "%s/cfloadobstr2044", settings.tmpdir); - FILE * - tempfile = fopen (filename, "w"); + FILE *tempfile = fopen (filename, "w"); if (tempfile == NULL) { @@ -2748,8 +2685,7 @@ object * find_obj_by_type_subtype (const object *who, int type, int subtype) { - object * - tmp; + object *tmp; for (tmp = who->inv; tmp; tmp = tmp->below) if (tmp->type == type && tmp->subtype == subtype) @@ -2767,16 +2703,11 @@ key_value * get_ob_key_link (const object *ob, const char *key) { - key_value * - link; + key_value *link; for (link = ob->key_values; link != NULL; link = link->next) - { - if (link->key == key) - { - return link; - } - } + if (link->key == key) + return link; return NULL; }