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/common | |
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/common')
-rw-r--r-- | src/common/mapindex.c | 52 | ||||
-rw-r--r-- | src/common/mapindex.h | 1 | ||||
-rw-r--r-- | src/common/mmo.h | 5 |
3 files changed, 36 insertions, 22 deletions
diff --git a/src/common/mapindex.c b/src/common/mapindex.c index bfd67140a..cc847e538 100644 --- a/src/common/mapindex.c +++ b/src/common/mapindex.c @@ -15,42 +15,53 @@ //Leave an extra char of space to hold the terminator, in case for the strncpy(mapindex_id2name()) calls. struct indexes { char name[MAP_NAME_LENGTH+1]; //Stores map name - int length; //Stores string length WITHOUT the extension for quick lookup. + char exists; //Set to 1 if index exists } indexes[MAX_MAPINDEX]; static unsigned short max_index = 0; -char mapindex_cfgfile[80] = "db/map_list.txt"; +char mapindex_cfgfile[80] = "db/map_index.txt"; + +// Removes the extension from a map name +char *mapindex_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; +} /// Adds a map to the specified index /// Returns 1 if successful, 0 oherwise int mapindex_addmap(int index, const char *name) { char map_name[1024]; - char *ext; - int length; if (index < 0 || index >= MAX_MAPINDEX) { ShowError("(mapindex_add) Map index (%d) for \"%s\" out of range (max is %d)\n", index, name, MAX_MAPINDEX); return 0; } + snprintf(map_name, 1024, "%s", name); - map_name[1023] = 0; - length = strlen(map_name); - if (length > MAP_NAME_LENGTH) { + mapindex_normalize_name(map_name); + + if (strlen(map_name) > MAP_NAME_LENGTH-1) { ShowError("(mapindex_add) Map name %s is too long. Maps are limited to %d characters.\n", map_name, MAP_NAME_LENGTH); return 0; } - if ((ext = strstr(map_name, ".")) != NULL) { // Remove extension - length = ext-map_name; - *ext = '\0'; - } - if (indexes[index].length) + if (indexes[index].exists) ShowWarning("(mapindex_add) Overriding index %d: map \"%s\" -> \"%s\"\n", index, indexes[index].name, map_name); strncpy(indexes[index].name, map_name, MAP_NAME_LENGTH); - indexes[index].length = length; + indexes[index].exists = 1; if (max_index <= index) max_index = index+1; return 1; @@ -59,17 +70,18 @@ int mapindex_addmap(int index, const char *name) unsigned short mapindex_name2id(const char* name) { //TODO: Perhaps use a db to speed this up? [Skotlex] int i; - int length = strlen(name); - char *ext = strstr(name, "."); - if (ext) - length = ext-name; //Base map-name length without the extension. + char map_name[1024]; + + snprintf(map_name, 1024, "%s", name); + mapindex_normalize_name(map_name); + for (i = 1; i < max_index; i++) { - if (strncmp(indexes[i].name,name,length)==0) + if (strcmp(indexes[i].name,map_name)==0) return i; } #ifdef MAPINDEX_AUTOADD - if( mapindex_addmap(i,name) ) + if( mapindex_addmap(i,map_name) ) { ShowDebug("mapindex_name2id: Auto-added map \"%s\" to position %d\n", indexes[i], i); return i; @@ -83,7 +95,7 @@ unsigned short mapindex_name2id(const char* name) { } const char* mapindex_id2name(unsigned short id) { - if (id > MAX_MAPINDEX || !indexes[id].length) { + if (id > MAX_MAPINDEX || !indexes[id].exists) { ShowDebug("mapindex_id2name: Requested name for non-existant map index [%d] in cache.\n", id); return indexes[0].name; //Theorically this should never happen, hence we return this string to prevent null pointer crashes. } diff --git a/src/common/mapindex.h b/src/common/mapindex.h index dfcb150e2..0ec192258 100644 --- a/src/common/mapindex.h +++ b/src/common/mapindex.h @@ -37,6 +37,7 @@ extern char mapindex_cfgfile[80]; #define MAP_VEINS "veins" #define MAP_JAIL "sec_pri" #define MAP_NOVICE "new_zone01" +char *mapindex_normalize_name(char *mapname); int mapindex_addmap(int index, const char *name); unsigned short mapindex_name2id(const char*); const char* mapindex_id2name(unsigned short); diff --git a/src/common/mmo.h b/src/common/mmo.h index f07876115..8d5071cc2 100644 --- a/src/common/mmo.h +++ b/src/common/mmo.h @@ -77,8 +77,9 @@ #define NAME_LENGTH 24 //For item names, which tend to have much longer names. #define ITEM_NAME_LENGTH 50 -//For Map Names, which the client considers to be 16 in length -#define MAP_NAME_LENGTH 16 +//For Map Names, which the client considers to be 16 in length including the .gat extension +#define MAP_NAME_LENGTH 12 +#define MAP_NAME_LENGTH_EXT 16 #define MAX_FRIENDS 40 #define MAX_MEMOPOINTS 10 |