--- deliantra/server/common/object.C 2006/09/14 18:13:01 1.45 +++ deliantra/server/common/object.C 2006/09/27 00:36:08 1.52 @@ -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. @@ -451,7 +450,7 @@ 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); } } @@ -487,6 +486,7 @@ for (op = object::first; op != NULL; op = op->next) if (op->count == i) break; + return op; } @@ -913,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 @@ -949,9 +949,6 @@ void object::unlink () { - //count = 0;//D - if (!prev && !next) return;//D - if (this == object::first) object::first = next; @@ -977,10 +974,10 @@ * The object must have been removed by remove_ob() first for * this function to succeed. * - * If free_inventory is set, free inventory as well. Else drop items in + * If destroy_inventory is set, free inventory as well. Else drop items in * inventory to the ground. */ -void object::free (bool free_inventory) +void object::destroy (bool destroy_inventory) { if (QUERY_FLAG (this, FLAG_FREED)) return; @@ -995,7 +992,7 @@ if (more) { - more->free (free_inventory); + more->destroy (destroy_inventory); more = 0; } @@ -1005,14 +1002,14 @@ * if some form of movement is allowed, let objects * drop on that space. */ - if (free_inventory || !map || map->in_memory != MAP_IN_MEMORY || GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL) + if (destroy_inventory || !map || map->in_memory != MAP_IN_MEMORY || GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL) { object *op = inv; while (op) { object *tmp = op->below; - op->free (free_inventory); + op->destroy (destroy_inventory); op = tmp; } } @@ -1046,6 +1043,9 @@ enemy = 0; attacked_by = 0; + // only relevant for players(?), but make sure of it anyways + contr = 0; + /* Remove object from the active list */ speed = 0; update_ob_speed (this); @@ -1088,9 +1088,8 @@ object *tmp, *last = 0; object *otmp; - tag_t tag; int check_walk_off; - mapstruct *m; + maptile *m; sint16 x, y; @@ -1195,7 +1194,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) @@ -1220,14 +1218,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 */ @@ -1298,7 +1296,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; @@ -1336,7 +1334,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; @@ -1627,7 +1625,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; @@ -1936,25 +1934,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); @@ -2024,7 +2012,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 @@ -2046,7 +2034,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; @@ -2069,7 +2057,7 @@ */ object * -present (unsigned char type, mapstruct *m, int x, int y) +present (unsigned char type, maptile *m, int x, int y) { object * tmp; @@ -2219,7 +2207,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, @@ -2250,14 +2238,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; @@ -2331,7 +2319,7 @@ */ int -find_dir (mapstruct *m, int x, int y, object *exclude) +find_dir (maptile *m, int x, int y, object *exclude) { int i, @@ -2340,7 +2328,7 @@ sint16 nx, ny; object * tmp; - mapstruct * + maptile * mp; MoveType blocked, move_type; @@ -2558,7 +2546,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 @@ -2648,48 +2636,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) { @@ -2720,8 +2688,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) @@ -2739,16 +2706,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; }