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)
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);
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;