const char* mapindex_idx2name(unsigned short id, const char *func) { if (id >= MAX_MAPINDEX || !mapindex_exists(id)) { ShowDebug("(%s) mapindex_id2name: Requested name for non-existant map index [%d] in cache.\n", func, id); return indexes[0].name; // dummy empty string so that the callee doesn't crash } return indexes[id].name; }
/// Adds a map to the specified index /// Returns 1 if successful, 0 oherwise int mapindex_addmap(int index, const char* name) { char map_name[MAP_NAME_LENGTH]; if (index == -1){ //autogive index ARR_FIND(1,max_index,index,(indexes[index].name[0] == '\0')); } 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; } mapindex_getmapname(name, map_name); if (map_name[0] == '\0') { ShowError("(mapindex_add) Cannot add maps with no name.\n"); return 0; } if (strlen(map_name) >= MAP_NAME_LENGTH) { ShowError("(mapindex_add) Map name %s is too long. Maps are limited to %d characters.\n", map_name, MAP_NAME_LENGTH); return 0; } if (mapindex_exists(index)) { ShowWarning("(mapindex_add) Overriding index %d: map \"%s\" -> \"%s\"\n", index, indexes[index].name, map_name); strdb_remove(mapindex_db, indexes[index].name); } safestrncpy(indexes[index].name, map_name, MAP_NAME_LENGTH); strdb_iput(mapindex_db, map_name, index); if (max_index <= index) max_index = index+1; return index; }
/// Adds a map to the specified index /// Returns 1 if successful, 0 oherwise int mapindex_addmap (int index, const char *name) { char map_name[MAP_NAME_LENGTH]; if (index == -1) { for (index = 1; index < max_index; index++) { //if (strcmp(indexes[index].name,"#CLEARED#")==0) if (indexes[index].name[0] == '\0') break; } } 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; } mapindex_getmapname (name, map_name); if (map_name[0] == '\0') { ShowError ("(mapindex_add) Cannot add maps with no name.\n"); return 0; } if (strlen (map_name) >= MAP_NAME_LENGTH) { ShowError ("(mapindex_add) Map name %s is too long. Maps are limited to %d characters.\n", map_name, MAP_NAME_LENGTH); return 0; } if (mapindex_exists (index)) ShowWarning ("(mapindex_add) Overriding index %d: map \"%s\" -> \"%s\"\n", index, indexes[index].name, map_name); safestrncpy (indexes[index].name, map_name, MAP_NAME_LENGTH); if (max_index <= index) max_index = index + 1; return index; }