From: Holger Schemel Date: Mon, 23 Jan 2017 22:09:41 +0000 (+0100) Subject: added separate functions to determine local and global level template file X-Git-Tag: 4.0.0.2~28 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=04b6a442e77073cbe0c99f3f343a737d471c3312;p=rocksndiamonds.git added separate functions to determine local and global level template file --- diff --git a/src/files.c b/src/files.c index eb33f7dc..b5f5fc7c 100644 --- a/src/files.c +++ b/src/files.c @@ -1861,13 +1861,15 @@ static void ActivateLevelTemplate() static char *getLevelFilenameFromBasename(char *basename) { - static char *filename = NULL; + /* use different slots for level template files and regular level files */ + static char *filename[2] = { NULL, NULL }; + int pos = (strEqual(basename, LEVELTEMPLATE_FILENAME) ? 0 : 1); - checked_free(filename); + checked_free(filename[pos]); - filename = getPath2(getCurrentLevelDir(), basename); + filename[pos] = getPath2(getCurrentLevelDir(), basename); - return filename; + return filename[pos]; } static int getFileTypeFromBasename(char *basename) @@ -1921,7 +1923,7 @@ static char *getSingleLevelBasenameExt(int nr, char *extension) static char basename[MAX_FILENAME_LEN]; if (nr < 0) - sprintf(basename, "template.%s", extension); + sprintf(basename, "%s", LEVELTEMPLATE_FILENAME); else sprintf(basename, "%03d.%s", nr, extension); @@ -2053,31 +2055,47 @@ static int getFiletypeFromID(char *filetype_id) return filetype; } -static void determineLevelFileInfo_Filename(struct LevelFileInfo *lfi) +char *getLocalLevelTemplateFilename() { - int nr = lfi->nr; + return getDefaultLevelFilename(-1); +} - /* special case: level number is negative => check for level template file */ - if (nr < 0) +char *getGlobalLevelTemplateFilename() +{ + /* global variable "leveldir_current" must be modified in the loop below */ + LevelDirTree *leveldir_current_last = leveldir_current; + char *filename = NULL; + + /* check for template level in path from current to topmost tree node */ + + while (leveldir_current != NULL) { - /* global variable "leveldir_current" must be modified in the loop below */ - LevelDirTree *leveldir_current_last = leveldir_current; + filename = getDefaultLevelFilename(-1); - /* check for template level in path from current to topmost tree node */ + if (fileExists(filename)) + break; - while (leveldir_current != NULL) - { - setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_RND, - "template.%s", LEVELFILE_EXTENSION); + leveldir_current = leveldir_current->node_parent; + } - if (fileExists(lfi->filename)) - break; + /* restore global variable "leveldir_current" modified in above loop */ + leveldir_current = leveldir_current_last; - leveldir_current = leveldir_current->node_parent; - } + return filename; +} + +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, + getSingleLevelBasename(-1)); - /* restore global variable "leveldir_current" modified in above loop */ - leveldir_current = leveldir_current_last; + /* replace local level template filename with global template filename */ + lfi->filename = getGlobalLevelTemplateFilename(); /* no fallback if template file not existing */ return; diff --git a/src/files.h b/src/files.h index 1bb53808..46dcae9c 100644 --- a/src/files.h +++ b/src/files.h @@ -30,6 +30,8 @@ void setElementChangeInfoToDefaults(struct ElementChangeInfo *); void copyElementInfo(struct ElementInfo *, struct ElementInfo *); char *getDefaultLevelFilename(int); +char *getLocalLevelTemplateFilename(); +char *getGlobalLevelTemplateFilename(); void LoadLevelFromFilename(struct LevelInfo *, char *); void LoadLevel(int); diff --git a/src/libgame/system.h b/src/libgame/system.h index fb209d30..25be3c85 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -508,6 +508,7 @@ #define SOUNDSINFO_FILENAME "soundsinfo.conf" #define MUSICINFO_FILENAME "musicinfo.conf" #define ARTWORKINFO_CACHE_FILE "artworkinfo.cache" +#define LEVELTEMPLATE_FILENAME "template.level" #define LEVELFILE_EXTENSION "level" #define TAPEFILE_EXTENSION "tape" #define SCOREFILE_EXTENSION "score"