diff options
author | DracoRPG <DracoRPG@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-04-06 17:22:40 +0000 |
---|---|---|
committer | DracoRPG <DracoRPG@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-04-06 17:22:40 +0000 |
commit | ded1f674755335a9cbb5c08e321b4a4c092a0e8d (patch) | |
tree | 4ff5231731935b41f9ef1fdccf9b14ef5b4e85b3 /src/map/map.c | |
parent | 2d75543b172d4cf141278bbd224e2353f19b5c86 (diff) | |
download | hercules-ded1f674755335a9cbb5c08e321b4a4c092a0e8d.tar.gz hercules-ded1f674755335a9cbb5c08e321b4a4c092a0e8d.tar.bz2 hercules-ded1f674755335a9cbb5c08e321b4a4c092a0e8d.tar.xz hercules-ded1f674755335a9cbb5c08e321b4a4c092a0e8d.zip |
I'm still here!
Rewrote fame ranking lists- changed MAP_NAME_LENGTH to 12, now there's MAP_NAME_LENGTH_EXT at 16 for
uses where there is / may be the .gat extension, code adjusted accordingly
- moved map_normalize_name to mapindex_normalize_name so that everything
handling map names uses the same extension-removing function
- greatly enhanced the map cache generator, complete documentation on the
tool and the map cache format can be found in doc/
- the map cache format changed a bit as a consequence, but of course a new
valid one is included (contains latest Nameless Island maps)
- fixed a duplicate entry in map index
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@10167 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/map.c')
-rw-r--r-- | src/map/map.c | 70 |
1 files changed, 30 insertions, 40 deletions
diff --git a/src/map/map.c b/src/map/map.c index f9c60d428..b69bd4367 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -145,6 +145,20 @@ struct charid2nick { int req_id; }; +// This is the main header found at the very beginning of the map cache +struct map_cache_main_header { + unsigned long file_size; + unsigned short map_count; +}; + +// This is the header appended before every compressed map cells info in the map cache +struct map_cache_map_info { + char name[MAP_NAME_LENGTH]; + short xs; + short ys; + long len; +}; + char map_cache_file[256]="db/map_cache.dat"; char db_path[256] = "db"; char motd_txt[256] = "conf/motd.txt"; @@ -2410,61 +2424,34 @@ int map_eraseipport(unsigned short mapindex, uint32 ip, uint16 port) * Map cache reading *===========================================*/ -// This is the header appended before every compressed map cells info -struct map_cache_info { - char name[MAP_NAME_LENGTH]; - unsigned short index; - short xs; - short ys; - long len; -}; - -FILE *map_cache_fp; - -// Removes the extension from a map name -char *map_normalize_name(char *mapname) -{ - char *ptr, *ptr2; - ptr = strchr(mapname, '.'); - if (ptr) { //Check and remove extension. - while (ptr[1] && (ptr2 = strchr(ptr+1, '.'))) - ptr = ptr2; //Skip to the last dot. - if(stricmp(ptr,".gat") == 0 || - stricmp(ptr,".afm") == 0 || - stricmp(ptr,".af2") == 0) - *ptr = '\0'; //Remove extension. - } - return mapname; -} - -int map_readmap(struct map_data *m) +int map_readfromcache(struct map_data *m, FILE *fp) { int i; - unsigned short map_count; - struct map_cache_info info; + struct map_cache_main_header header; + struct map_cache_map_info info; unsigned long size; unsigned char *buf; - if(!map_cache_fp) + if(!fp) return 0; - fseek(map_cache_fp, 0, SEEK_SET); - fread(&map_count, sizeof(map_count), 1, map_cache_fp); + fseek(fp, 0, SEEK_SET); + fread(&header, sizeof(struct map_cache_main_header), 1, fp); - for(i = 0; i < map_count; i++) { - fread(&info, sizeof(info), 1, map_cache_fp); + for(i = 0; i < header.map_count; i++) { + fread(&info, sizeof(struct map_cache_map_info), 1, fp); if(strcmp(m->name, info.name) == 0) { // Map found m->xs = info.xs; m->ys = info.ys; m->gat = (unsigned char *)aMalloc(m->xs*m->ys); // Allocate room for map cells data buf = aMalloc(info.len); // Allocate a temp buffer to read the zipped map - fread(buf, info.len, 1, map_cache_fp); + fread(buf, info.len, 1, fp); size = m->xs*m->ys; decode_zip(m->gat, &size, buf, info.len); // Unzip the map from the buffer aFree(buf); return 1; } else // Map not found, jump to the beginning of the next map info header - fseek(map_cache_fp, info.len, SEEK_CUR); + fseek(fp, info.len, SEEK_CUR); } return 0; @@ -2482,7 +2469,7 @@ int map_addmap(char *mapname) { return 1; } - memcpy(map[map_num].name, map_normalize_name(mapname), MAP_NAME_LENGTH-1); + memcpy(map[map_num].name, mapindex_normalize_name(mapname), MAP_NAME_LENGTH-1); map_num++; return 0; } @@ -2520,8 +2507,9 @@ int map_readallmaps (void) { int i; int maps_removed = 0; + FILE *fp; - if(!(map_cache_fp = fopen(map_cache_file, "rb"))) + if(!(fp = fopen(map_cache_file, "rb"))) { ShowFatalError("Unable to open map cache file "CL_WHITE"%s"CL_RESET"\n", map_cache_file); exit(1); //No use launching server if maps can't be read. @@ -2559,7 +2547,7 @@ int map_readallmaps (void) fflush(stdout); } - if(!map_readmap(&map[i])) { + if(!map_readfromcache(&map[i], fp)) { map_delmapid(i); maps_removed++; i--; @@ -2609,6 +2597,8 @@ int map_readallmaps (void) map[i].block_mob_count = (int*)aCallocA(size, 1); } + fclose(fp); + // finished map loading printf("\r"); ShowInfo("Successfully loaded '"CL_WHITE"%d"CL_RESET"' maps.%30s\n",map_num,""); |