--- deliantra/server/common/map.C 2006/08/30 08:28:32 1.15 +++ deliantra/server/common/map.C 2006/09/03 00:18:40 1.20 @@ -1,6 +1,6 @@ /* * static char *rcsid_map_c = - * "$Id: map.C,v 1.15 2006/08/30 08:28:32 root Exp $"; + * "$Id: map.C,v 1.20 2006/09/03 00:18:40 root Exp $"; */ /* @@ -175,16 +175,8 @@ */ endbuf = buf + strlen(buf); - for (i = 0; i < NROF_COMPRESS_METHODS; i++) { - if (uncomp[i][0]) - strcpy(endbuf, uncomp[i][0]); - else - *endbuf = '\0'; - if (!stat (buf, &statbuf)) - break; - } - if (i == NROF_COMPRESS_METHODS) - return (-1); + if (stat (buf, &statbuf)) + return -1; if (!S_ISREG (statbuf.st_mode)) return (-1); @@ -492,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 @@ -538,7 +524,7 @@ * 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)"); + LOG(llevDebug,"Discarding object without arch: %s\n", op->name?(const char *)op->name:"(null)"); continue; } @@ -628,12 +614,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; @@ -898,7 +881,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")) { @@ -1235,94 +1218,95 @@ { if (!m->tmpname) m->tmpname = tempnam_local (settings.tmpdir, NULL); + strcpy (filename, m->tmpname); } LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); m->in_memory = MAP_SAVING; - object_freezer fp (filename); + object_freezer freezer; /* legacy */ - fprintf (fp, "arch map\n"); + fprintf (freezer, "arch map\n"); if (m->name) - fprintf (fp, "name %s\n", m->name); + fprintf (freezer, "name %s\n", m->name); if (!flag) - fprintf (fp, "swap_time %d\n", m->swap_time); + fprintf (freezer, "swap_time %d\n", m->swap_time); if (m->reset_timeout) - fprintf (fp, "reset_timeout %d\n", m->reset_timeout); + fprintf (freezer, "reset_timeout %d\n", m->reset_timeout); if (m->fixed_resettime) - fprintf (fp, "fixed_resettime %d\n", m->fixed_resettime); + fprintf (freezer, "fixed_resettime %d\n", m->fixed_resettime); /* we unfortunately have no idea if this is a value the creator set * or a difficulty value we generated when the map was first loaded */ if (m->difficulty) - fprintf (fp, "difficulty %d\n", m->difficulty); + fprintf (freezer, "difficulty %d\n", m->difficulty); if (m->region) - fprintf (fp, "region %s\n", m->region->name); + fprintf (freezer, "region %s\n", m->region->name); if (m->shopitems) { print_shop_string (m, shop); - fprintf (fp, "shopitems %s\n", shop); + fprintf (freezer, "shopitems %s\n", shop); } if (m->shopgreed) - fprintf (fp, "shopgreed %f\n", m->shopgreed); + fprintf (freezer, "shopgreed %f\n", m->shopgreed); #ifndef WIN32 if (m->shopmin) - fprintf (fp, "shopmin %llu\n", m->shopmin); + fprintf (freezer, "shopmin %llu\n", m->shopmin); if (m->shopmax) - fprintf (fp, "shopmax %llu\n", m->shopmax); + fprintf (freezer, "shopmax %llu\n", m->shopmax); #else if (m->shopmin) - fprintf (fp, "shopmin %I64u\n", m->shopmin); + fprintf (freezer, "shopmin %I64u\n", m->shopmin); if (m->shopmax) - fprintf (fp, "shopmax %I64u\n", m->shopmax); + fprintf (freezer, "shopmax %I64u\n", m->shopmax); #endif if (m->shoprace) - fprintf (fp, "shoprace %s\n", m->shoprace); + fprintf (freezer, "shoprace %s\n", m->shoprace); if (m->darkness) - fprintf (fp, "darkness %d\n", m->darkness); + fprintf (freezer, "darkness %d\n", m->darkness); if (m->width) - fprintf (fp, "width %d\n", m->width); + fprintf (freezer, "width %d\n", m->width); if (m->height) - fprintf (fp, "height %d\n", m->height); + fprintf (freezer, "height %d\n", m->height); if (m->enter_x) - fprintf (fp, "enter_x %d\n", m->enter_x); + fprintf (freezer, "enter_x %d\n", m->enter_x); if (m->enter_y) - fprintf (fp, "enter_y %d\n", m->enter_y); + fprintf (freezer, "enter_y %d\n", m->enter_y); if (m->msg) - fprintf (fp, "msg\n%sendmsg\n", m->msg); + fprintf (freezer, "msg\n%sendmsg\n", m->msg); if (m->maplore) - fprintf (fp, "maplore\n%sendmaplore\n", m->maplore); + fprintf (freezer, "maplore\n%sendmaplore\n", m->maplore); if (m->unique) - fprintf (fp, "unique %d\n", m->unique); + fprintf (freezer, "unique %d\n", m->unique); if (m->templatemap) - fprintf (fp, "template %d\n", m->templatemap); + fprintf (freezer, "template %d\n", m->templatemap); if (m->outdoor) - fprintf (fp, "outdoor %d\n", m->outdoor); + fprintf (freezer, "outdoor %d\n", m->outdoor); if (m->temp) - fprintf (fp, "temp %d\n", m->temp); + fprintf (freezer, "temp %d\n", m->temp); if (m->pressure) - fprintf (fp, "pressure %d\n", m->pressure); + fprintf (freezer, "pressure %d\n", m->pressure); if (m->humid) - fprintf (fp, "humid %d\n", m->humid); + fprintf (freezer, "humid %d\n", m->humid); if (m->windspeed) - fprintf (fp, "windspeed %d\n", m->windspeed); + fprintf (freezer, "windspeed %d\n", m->windspeed); if (m->winddir) - fprintf (fp, "winddir %d\n", m->winddir); + fprintf (freezer, "winddir %d\n", m->winddir); if (m->sky) - fprintf (fp, "sky %d\n", m->sky); + fprintf (freezer, "sky %d\n", m->sky); if (m->nosmooth) - fprintf (fp, "nosmooth %d\n", m->nosmooth); + fprintf (freezer, "nosmooth %d\n", m->nosmooth); /* Save any tiling information, except on overlays */ if (flag != 2) for (i = 0; i < 4; i++) if (m->tile_path[i]) - fprintf (fp, "tile_path_%d %s\n", i + 1, m->tile_path[i]); + fprintf (freezer, "tile_path_%d %s\n", i + 1, m->tile_path[i]); - fp.put (m); - fprintf (fp, "end\n"); + freezer.put (m); + fprintf (freezer, "end\n"); /* In the game save unique items in the different file, but * in the editor save them to the normal map file. @@ -1331,20 +1315,24 @@ */ if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap) { - sprintf (buf, "%s.v00", create_items_path (m->path)); - - object_freezer fp2 (buf); + object_freezer unique; if (flag == 2) - save_objects (m, fp, fp2, 2); + save_objects (m, freezer, unique, 2); else - save_objects (m, fp, fp2, 0); + save_objects (m, freezer, unique, 0); + + sprintf (buf, "%s.v00", create_items_path (m->path)); + + unique.save (buf); } else { /* save same file when not playing, like in editor */ - save_objects (m, fp, fp, 0); + save_objects (m, freezer, freezer, 0); } + freezer.save (filename); + return 0; } @@ -1398,18 +1386,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 } /* @@ -1499,7 +1475,7 @@ else last->next = m->next; - free (m); + delete m; }