--- deliantra/server/common/map.C 2006/08/31 06:23:19 1.17 +++ deliantra/server/common/map.C 2006/09/04 16:46:32 1.24 @@ -1,6 +1,6 @@ /* * static char *rcsid_map_c = - * "$Id: map.C,v 1.17 2006/08/31 06:23:19 root Exp $"; + * "$Id: map.C,v 1.24 2006/09/04 16:46:32 root Exp $"; */ /* @@ -484,14 +484,8 @@ op->head = tmp; op->map = m; last->more = op; - if (tmp->name != op->name) { - if (op->name) free_string(op->name); - op->name = add_string(tmp->name); - } - if (tmp->title != op->title) { - if (op->title) free_string(op->title); - op->title = add_string(tmp->title); - } + op->name = tmp->name; + op->title = tmp->title; /* we could link all the parts onto tmp, and then just * call insert_ob_in_map once, but the effect is the same, * as insert_ob_in_map will call itself with each part, and @@ -502,79 +496,89 @@ } /* for objects on this space */ } - - /* * Loads (ands parses) the objects into a given map from the specified * file pointer. * mapflags is the same as we get with load_original_map */ +void +load_objects (mapstruct *m, object_thawer &fp, int mapflags) +{ + int i, j; + int unique; + object *op, *prev = NULL, *last_more = NULL, *otmp; -void load_objects (mapstruct *m, object_thawer &fp, int mapflags) { - int i,j,bufstate=LO_NEWFILE; - int unique; - object *op, *prev=NULL,*last_more=NULL, *otmp; - - op=get_object(); - op->map = m; /* To handle buttons correctly */ - - while((i = load_object (fp, op, bufstate, mapflags))) { - /* Since the loading of the map header does not load an object - * anymore, we need to pass LO_NEWFILE for the first object loaded, - * and then switch to LO_REPEAT for faster loading. - */ - bufstate = LO_REPEAT; + op = get_object (); + op->map = m; /* To handle buttons correctly */ - /* if the archetype for the object is null, means that we - * got an invalid object. Don't do anything with it - the game - * or editor will not be able to do anything with it either. - */ - if (op->arch==NULL) { - LOG(llevDebug,"Discarding object without arch: %s\n", op->name?op->name:"(null)"); - continue; + while ((i = load_object (fp, op, mapflags))) + { + /* if the archetype for the object is null, means that we + * got an invalid object. Don't do anything with it - the game + * or editor will not be able to do anything with it either. + */ + if (op->arch == NULL) + { + LOG (llevDebug, "Discarding object without arch: %s\n", + op->name ? (const char *) op->name : "(null)"); + continue; } - switch(i) { + switch (i) + { case LL_NORMAL: /* if we are loading an overlay, put the floors on the bottom */ - if ((QUERY_FLAG(op, FLAG_IS_FLOOR) || - QUERY_FLAG(op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) - insert_ob_in_map(op,m,op,INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); + if ((QUERY_FLAG (op, FLAG_IS_FLOOR) || + QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) + insert_ob_in_map (op, m, op, + INS_NO_MERGE | INS_NO_WALK_ON | + INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); else - insert_ob_in_map(op,m,op,INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); + insert_ob_in_map (op, m, op, + INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | + INS_MAP_LOAD); if (op->inv) - sum_weight(op); + sum_weight (op); - prev=op,last_more=op; + prev = op, last_more = op; break; case LL_MORE: - insert_ob_in_map(op,m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); - op->head=prev,last_more->more=op,last_more=op; + insert_ob_in_map (op, m, op, + INS_NO_MERGE | INS_NO_WALK_ON | + INS_ABOVE_FLOOR_ONLY); + op->head = prev, last_more->more = op, last_more = op; break; } - if (mapflags & MAP_STYLE) { - remove_from_active_list(op); - } - op=get_object(); - op->map = m; + + if (mapflags & MAP_STYLE) + remove_from_active_list (op); + + op = get_object (); + op->map = m; } - for (i=0;iwidth;i++){ - for (j=0;jheight;j++){ - unique =0; - /* check for unique items, or unique squares */ - for (otmp = get_map_ob(m, i, j); otmp; otmp = otmp->above) { - if (QUERY_FLAG(otmp, FLAG_UNIQUE) || QUERY_FLAG(otmp, FLAG_OBJ_SAVE_ON_OVL)) - unique = 1; - if (!(mapflags & (MAP_OVERLAY|MAP_PLAYER_UNIQUE) || unique)) - SET_FLAG(otmp, FLAG_OBJ_ORIGINAL); + + for (i = 0; i < m->width; i++) + { + for (j = 0; j < m->height; j++) + { + unique = 0; + /* check for unique items, or unique squares */ + for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above) + { + if (QUERY_FLAG (otmp, FLAG_UNIQUE) + || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL)) + unique = 1; + if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) + SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); } } } - free_object(op); - link_multipart_objects(m); + + free_object (op); + link_multipart_objects (m); } /* This saves all the objects on the map in a non destructive fashion. @@ -620,12 +624,9 @@ */ mapstruct *get_linked_map(void) { - mapstruct *map=(mapstruct *) calloc(1,sizeof(mapstruct)); + mapstruct *map = new mapstruct; mapstruct *mp; - if(map==NULL) - fatal(OUT_OF_MEMORY); - for(mp=first_map;mp!=NULL&&mp->next!=NULL;mp=mp->next); if(mp==NULL) first_map=map; @@ -817,12 +818,12 @@ } } } + if (!end) { LOG(llevError, "Error loading map header - did not find a newline - perhaps file is truncated? Buf=%s\n", buf); return 1; } - /* key is the field name, value is what it should be set * to. We've already done the work to null terminate key, @@ -890,7 +891,7 @@ else if (!strcmp(key,"oid")) { fp.get (m, atoi(value)); } else if (!strcmp(key, "attach")) { - m->attach = add_string (value); + m->attach = value; } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) { m->enter_x = atoi(value); } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) { @@ -1012,7 +1013,6 @@ mapstruct *m; char pathname[MAX_BUF]; - LOG(llevDebug, "load_original_map: %s (%x)\n", filename,flags); if (flags & MAP_PLAYER_UNIQUE) strcpy(pathname, filename); else if (flags & MAP_OVERLAY) @@ -1020,6 +1020,8 @@ else strcpy(pathname, create_pathname(filename)); + LOG(llevDebug, "load_original_map(%x): %s (%s)\n", flags, filename, pathname); + object_thawer thawer (pathname); if (!thawer) @@ -1181,7 +1183,6 @@ m->in_memory=MAP_LOADING; if (m->tmpname == NULL) /* if we have loaded unique items from */ delete_unique_items(m); /* original map before, don't duplicate them */ - load_object(thawer, NULL, LO_NOREAD,0); load_objects (m, thawer, 0); m->in_memory=MAP_IN_MEMORY; @@ -1395,18 +1396,6 @@ free_object(op); } } -#ifdef MANY_CORES - /* I see periodic cores on metalforge where a map has been swapped out, but apparantly - * an item on that map was not saved - look for that condition and die as appropriate - - * this leaves more of the map data intact for better debugging. - */ - for (op=objects; op!=NULL; op=op->next) { - if (!QUERY_FLAG(op, FLAG_REMOVED) && op->map == m) { - LOG(llevDebug,"free_all_objects: object %s still on map after it should have been freed\n", op->name); - abort(); - } - } -#endif } /* @@ -1496,7 +1485,7 @@ else last->next = m->next; - free (m); + delete m; } @@ -1549,15 +1538,20 @@ else LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name)); + //0.427459955215454 /var/crossfire/players/Saladon/_scorn_apartment_apartments + //0.414906024932861 + //0.427063941955566 + eval_pv ("$x = Event::time", 1);//D if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE)))) return (NULL); + eval_pv ("warn \"LOAD \", Event::time - $x", 1);//D fix_auto_apply(m); /* Chests which open as default */ /* If a player unique map, no extra unique object file to load. * if from the editor, likewise. */ - if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE))) + if (!(flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE))) load_unique_objects(m); if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) {