summaryrefslogtreecommitdiff
path: root/src/common/mapindex.c
diff options
context:
space:
mode:
authorDracoRPG <DracoRPG@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-04-06 17:22:40 +0000
committerDracoRPG <DracoRPG@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-04-06 17:22:40 +0000
commitded1f674755335a9cbb5c08e321b4a4c092a0e8d (patch)
tree4ff5231731935b41f9ef1fdccf9b14ef5b4e85b3 /src/common/mapindex.c
parent2d75543b172d4cf141278bbd224e2353f19b5c86 (diff)
downloadhercules-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/mapindex.c')
-rw-r--r--src/common/mapindex.c52
1 files changed, 32 insertions, 20 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.
}