--- deliantra/server/common/map.C 2006/08/28 14:05:23 1.10 +++ deliantra/server/common/map.C 2006/08/30 16:30:37 1.16 @@ -1,6 +1,6 @@ /* * static char *rcsid_map_c = - * "$Id: map.C,v 1.10 2006/08/28 14:05:23 root Exp $"; + * "$Id: map.C,v 1.16 2006/08/30 16:30:37 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); @@ -795,7 +787,7 @@ * return 0 on success, 1 on failure. */ -static int load_map_header(FILE *fp, mapstruct *m) +static int load_map_header(object_thawer &fp, mapstruct *m) { char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key=NULL, *value, *end; int msgpos=0; @@ -895,7 +887,11 @@ * for compatibility reasons. The new values (second) are * what really should be used. */ - else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) { + else if (!strcmp(key,"oid")) { + fp.get (m, atoi(value)); + } else if (!strcmp(key, "attach")) { + m->attach = add_string (value); + } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) { m->enter_x = atoi(value); } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) { m->enter_y = atoi(value); @@ -947,8 +943,6 @@ m->sky = atoi(value); } else if (!strcmp(key, "nosmooth")) { m->nosmooth = atoi(value); - } else if (!strcmp(key, "safe_map")) { - m->safe_map = atoi(value); } else if (!strncmp(key,"tile_path_", 10)) { int tile=atoi(key+10); @@ -1015,9 +1009,7 @@ */ mapstruct *load_original_map(const char *filename, int flags) { - FILE *fp; mapstruct *m; - int comp; char pathname[MAX_BUF]; LOG(llevDebug, "load_original_map: %s (%x)\n", filename,flags); @@ -1028,17 +1020,15 @@ else strcpy(pathname, create_pathname(filename)); - if((fp=open_and_uncompress(pathname, 0, &comp))==NULL) { - LOG(llevError, "Can't open %s: %s\n", pathname, strerror_local(errno)); - return (NULL); - } + object_thawer thawer (pathname); - object_thawer thawer (fp, filename); + if (!thawer) + return 0; m = get_linked_map(); strcpy (m->path, filename); - if (load_map_header(fp, m)) { + if (load_map_header(thawer, m)) { LOG(llevError,"Error loading map header for %s, flags=%d\n", filename, flags); delete_map(m); @@ -1049,12 +1039,12 @@ m->in_memory=MAP_LOADING; load_objects (m, thawer, flags & (MAP_BLOCK|MAP_STYLE)); - close_and_delete(fp, comp); + m->in_memory=MAP_IN_MEMORY; if (!MAP_DIFFICULTY(m)) MAP_DIFFICULTY(m)=calculate_difficulty(m); set_map_reset_time(m); - INVOKE_MAP (INSTANTIATE, m); + m->instantiate (); return (m); } @@ -1065,7 +1055,6 @@ */ static mapstruct *load_temporary_map(mapstruct *m) { - FILE *fp; int comp; char buf[MAX_BUF]; @@ -1079,17 +1068,17 @@ return m; } - if((fp=open_and_uncompress(m->tmpname,0, &comp))==NULL) { - LOG(llevError, "Cannot open %s: %s\n",m->tmpname, strerror_local(errno)); - strcpy(buf, m->path); - delete_map(m); - m = load_original_map(buf, 0); - if(m==NULL) return NULL; - fix_auto_apply(m); /* Chests which open as default */ - return m; - } + object_thawer thawer (m->tmpname); - object_thawer thawer (fp, m->tmpname); + if (!thawer) + { + strcpy (buf, m->path); + delete_map (m); + m = load_original_map (buf, 0); + if (!m) return NULL; + fix_auto_apply (m); /* Chests which open as default */ + return m; + } if (load_map_header(thawer, m)) { LOG(llevError,"Error loading map header for %s (%s)\n", @@ -1102,7 +1091,7 @@ m->in_memory=MAP_LOADING; load_objects (m, thawer, 0); - close_and_delete(fp, comp); + m->in_memory=MAP_IN_MEMORY; INVOKE_MAP (SWAPIN, m); return m; @@ -1115,18 +1104,14 @@ */ mapstruct *load_overlay_map(const char *filename, mapstruct *m) { - FILE *fp; - int comp; char pathname[MAX_BUF]; strcpy(pathname, create_overlay_pathname(filename)); - if((fp=open_and_uncompress(pathname, 0, &comp))==NULL) { -/* LOG(llevDebug,"Can't open overlay %s\n", pathname);*/ - return m; - } + object_thawer thawer (pathname); - object_thawer thawer (fp, pathname); + if (!thawer) + return m; if (load_map_header(thawer, m)) { LOG(llevError,"Error loading map header for overlay %s (%s)\n", @@ -1139,7 +1124,7 @@ m->in_memory=MAP_LOADING; load_objects (m, thawer, MAP_OVERLAY); - close_and_delete(fp, comp); + m->in_memory=MAP_IN_MEMORY; return m; } @@ -1178,8 +1163,7 @@ * m is the map to load unique items into. */ static void load_unique_objects(mapstruct *m) { - FILE *fp; - int comp,count; + int count; char firstname[MAX_BUF]; for (count=0; count<10; count++) { @@ -1189,22 +1173,17 @@ /* If we get here, we did not find any map */ if (count==10) return; - if ((fp=open_and_uncompress(firstname, 0, &comp))==NULL) { - /* There is no expectation that every map will have unique items, but this - * is debug output, so leave it in. - */ - LOG(llevDebug, "Can't open unique items file for %s\n", create_items_path(m->path)); - return; - } + object_thawer thawer (firstname); - object_thawer thawer (fp, firstname); + if (!thawer) + return; 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); - close_and_delete(fp, comp); + m->in_memory=MAP_IN_MEMORY; } @@ -1327,8 +1306,6 @@ fprintf (fp, "sky %d\n", m->sky); if (m->nosmooth) fprintf (fp, "nosmooth %d\n", m->nosmooth); - if (m->safe_map) - fprintf (fp, "safe_map %d\n", m->safe_map); /* Save any tiling information, except on overlays */ if (flag != 2) @@ -1336,6 +1313,7 @@ if (m->tile_path[i]) fprintf (fp, "tile_path_%d %s\n", i + 1, m->tile_path[i]); + fp.put (m); fprintf (fp, "end\n"); /* In the game save unique items in the different file, but @@ -1468,6 +1446,9 @@ if (!m) return; + + m->clear (); + if (m->in_memory == MAP_IN_MEMORY) { /* change to MAP_SAVING, even though we are not, * so that remove_ob doesn't do as much work. @@ -1580,6 +1561,9 @@ return NULL; } + if (flags & MAP_PLAYER_UNIQUE) + INVOKE_MAP (SWAPIN, m); + } else { /* If in this loop, we found a temporary map, so load it up. */