From: Holger Schemel Date: Tue, 26 Oct 2004 00:16:37 +0000 (+0200) Subject: rnd-20041026-1-src X-Git-Tag: 3.1.1^2~51 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=77acdb46d729cd3f9893d6a91740cb058923d4cf;p=rocksndiamonds.git rnd-20041026-1-src * added auto-detection for various types of Emerald Mine level files --- diff --git a/ChangeLog b/ChangeLog index 4d93a179..dde58647 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2004-10-26 + * added auto-detection for various types of Emerald Mine level files + 2004-10-17 * fixed bug with scrollbars getting too small when list is very large diff --git a/src/conftime.h b/src/conftime.h index 2fb9d365..3639cfa3 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2004-10-18 00:52]" +#define COMPILE_DATE_STRING "[2004-10-26 02:14]" diff --git a/src/files.c b/src/files.c index 9ff9a52f..f1c17f8e 100644 --- a/src/files.c +++ b/src/files.c @@ -428,36 +428,14 @@ static int getFileTypeFromBasename(char *basename) return LEVEL_FILE_TYPE_UNKNOWN; } -static char *getSingleLevelBasename(int nr, int type) +static char *getSingleLevelBasename(int nr) { static char basename[MAX_FILENAME_LEN]; - char *level_filename = getStringCopy(leveldir_current->level_filename); - if (level_filename == NULL) - level_filename = getStringCat2("%03d.", LEVELFILE_EXTENSION); + if (nr < 0) + sprintf(basename, "template.%s", LEVELFILE_EXTENSION); else - type = LEVEL_FILE_TYPE_UNKNOWN; /* force specified file name/pattern */ - - switch (type) - { - case LEVEL_FILE_TYPE_RND: - if (nr < 0) - sprintf(basename, "template.%s", LEVELFILE_EXTENSION); - else - sprintf(basename, "%03d.%s", nr, LEVELFILE_EXTENSION); - break; - - case LEVEL_FILE_TYPE_EM: - sprintf(basename, "%d", nr); - break; - - case LEVEL_FILE_TYPE_UNKNOWN: - default: - sprintf(basename, level_filename, nr); - break; - } - - free(level_filename); + sprintf(basename, "%03d.%s", nr, LEVELFILE_EXTENSION); return basename; } @@ -500,9 +478,9 @@ static char *getPackedLevelBasename(int type) return basename; } -static char *getSingleLevelFilename(int nr, int type) +static char *getSingleLevelFilename(int nr) { - return getLevelFilenameFromBasename(getSingleLevelBasename(nr, type)); + return getLevelFilenameFromBasename(getSingleLevelBasename(nr)); } #if 0 @@ -514,9 +492,10 @@ static char *getPackedLevelFilename(int type) char *getDefaultLevelFilename(int nr) { - return getSingleLevelFilename(nr, LEVEL_FILE_TYPE_RND); + return getSingleLevelFilename(nr); } +#if 0 static void setLevelFileInfo_SingleLevelFilename(struct LevelFileInfo *lfi, int type) { @@ -525,6 +504,23 @@ static void setLevelFileInfo_SingleLevelFilename(struct LevelFileInfo *lfi, lfi->basename = getSingleLevelBasename(lfi->nr, lfi->type); lfi->filename = getLevelFilenameFromBasename(lfi->basename); } +#endif + +static void setLevelFileInfo_FormatLevelFilename(struct LevelFileInfo *lfi, + int type, char *format, ...) +{ + static char basename[MAX_FILENAME_LEN]; + va_list ap; + + va_start(ap, format); + vsprintf(basename, format, ap); + va_end(ap); + + lfi->type = type; + lfi->packed = FALSE; + lfi->basename = basename; + lfi->filename = getLevelFilenameFromBasename(lfi->basename); +} static void setLevelFileInfo_PackedLevelFilename(struct LevelFileInfo *lfi, int type) @@ -564,7 +560,8 @@ static int getFiletypeFromID(char *filetype_id) return filetype; } -static void determineLevelFileInfo_Filename(struct LevelFileInfo *lfi) +#if 0 +static void OLD_determineLevelFileInfo_Filename(struct LevelFileInfo *lfi) { /* special case: level number is negative => check for level template file */ if (lfi->nr < 0) @@ -603,6 +600,79 @@ static void determineLevelFileInfo_Filename(struct LevelFileInfo *lfi) /* no known level file found -- try to use default values */ setLevelFileInfo_SingleLevelFilename(lfi, LEVEL_FILE_TYPE_UNKNOWN); } +#endif + +static void determineLevelFileInfo_Filename(struct LevelFileInfo *lfi) +{ + int nr = lfi->nr; + + /* special case: level number is negative => check for level template file */ + if (nr < 0) + { + setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_RND, + "template.%s", LEVELFILE_EXTENSION); + + /* no fallback if template file not existing */ + return; + } + + /* special case: check for file name/pattern specified in "levelinfo.conf" */ + if (leveldir_current->level_filename != NULL) + { + int filetype = getFiletypeFromID(leveldir_current->level_filetype); + + setLevelFileInfo_FormatLevelFilename(lfi, filetype, + leveldir_current->level_filename, nr); + if (fileExists(lfi->filename)) + return; + } + + /* check for native Rocks'n'Diamonds level file */ + setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_RND, + "%03d.%s", nr, LEVELFILE_EXTENSION); + if (fileExists(lfi->filename)) + return; + + /* check for Emerald Mine level file (V1) */ + setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_EM, "a%c%c", + 'a' + (nr / 10) % 26, '0' + nr % 10); + if (fileExists(lfi->filename)) + return; + setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_EM, "A%c%c", + 'A' + (nr / 10) % 26, '0' + nr % 10); + if (fileExists(lfi->filename)) + return; + + /* check for Emerald Mine level file (V2 to V5) */ + setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_EM, "%d", nr); + if (fileExists(lfi->filename)) + return; + + /* check for Emerald Mine level file (V6 / single mode) */ + setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_EM, "%02ds", nr); + if (fileExists(lfi->filename)) + return; + setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_EM, "%02dS", nr); + if (fileExists(lfi->filename)) + return; + + /* check for Emerald Mine level file (V6 / teamwork mode) */ + setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_EM, "%02dt", nr); + if (fileExists(lfi->filename)) + return; + setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_EM, "%02dT", nr); + if (fileExists(lfi->filename)) + return; + + /* check for various packed level file formats */ + setLevelFileInfo_PackedLevelFilename(lfi, LEVEL_FILE_TYPE_UNKNOWN); + if (fileExists(lfi->filename)) + return; + + /* no known level file found -- use default values (and fail later) */ + setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_RND, + "%03d.%s", nr, LEVELFILE_EXTENSION); +} static void determineLevelFileInfo_Filetype(struct LevelFileInfo *lfi) { diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 225d385c..aa5cbb1e 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1504,6 +1504,9 @@ void dumpList(ListNode *node_first) boolean fileExists(char *filename) { + if (filename == NULL) + return FALSE; + #if 0 printf("checking file '%s'\n", filename); #endif