From: Holger Schemel Date: Tue, 24 Jan 2017 07:38:34 +0000 (+0100) Subject: added initializing level data from level template if no level file exists X-Git-Tag: 4.0.0.2~27 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=fce2b199f289e67a471d3bfe0bafe9decee86420;p=rocksndiamonds.git added initializing level data from level template if no level file exists --- diff --git a/src/files.c b/src/files.c index b5f5fc7c..0a170578 100644 --- a/src/files.c +++ b/src/files.c @@ -1765,14 +1765,19 @@ static void setLevelInfoToDefaults_Elements(struct LevelInfo *level) } static void setLevelInfoToDefaults(struct LevelInfo *level, - boolean level_info_only) + boolean level_info_only, + boolean reset_file_status) { setLevelInfoToDefaults_Level(level); if (!level_info_only) setLevelInfoToDefaults_Elements(level); - level->no_valid_file = FALSE; + if (reset_file_status) + { + level->no_valid_file = FALSE; + level->no_level_file = FALSE; + } level->changed = FALSE; } @@ -1861,7 +1866,6 @@ static void ActivateLevelTemplate() static char *getLevelFilenameFromBasename(char *basename) { - /* 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); @@ -3182,11 +3186,23 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level, if (!(file = openFile(filename, MODE_READ))) { level->no_valid_file = TRUE; + level->no_level_file = TRUE; - if (!level_info_only) - Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); + if (level_info_only) + return; - return; + Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); + + /* if level file not found, try to initialize level data from template */ + filename = getGlobalLevelTemplateFilename(); + + if (!(file = openFile(filename, MODE_READ))) + return; + + /* default: for empty levels, use level template for custom elements */ + level->use_custom_template = TRUE; + + level->no_valid_file = FALSE; } getFileChunkBE(file, chunk_name, NULL); @@ -5876,7 +5892,7 @@ static void LoadLevelFromFileInfo(struct LevelInfo *level, boolean level_info_only) { /* always start with reliable default values */ - setLevelInfoToDefaults(level, level_info_only); + setLevelInfoToDefaults(level, level_info_only, TRUE); switch (level_file_info->type) { @@ -5909,11 +5925,7 @@ static void LoadLevelFromFileInfo(struct LevelInfo *level, /* if level file is invalid, restore level structure to default values */ if (level->no_valid_file) - { - setLevelInfoToDefaults(level, level_info_only); - - level->no_valid_file = TRUE; /* but keep "no valid file" flag */ - } + setLevelInfoToDefaults(level, level_info_only, FALSE); if (level->game_engine_type == GAME_ENGINE_TYPE_UNKNOWN) level->game_engine_type = GAME_ENGINE_TYPE_RND; @@ -7181,7 +7193,7 @@ boolean SaveLevelChecked(int nr) void DumpLevel(struct LevelInfo *level) { - if (level->no_valid_file) + if (level->no_level_file || level->no_valid_file) { Error(ERR_WARN, "cannot dump -- no valid level file found"); @@ -10062,7 +10074,7 @@ void ConvertLevels() Print("Level %03d: ", level_nr); LoadLevel(level_nr); - if (level.no_valid_file) + if (level.no_level_file || level.no_valid_file) { Print("(no level)\n"); continue; diff --git a/src/main.h b/src/main.h index 0ee11074..12c911b3 100644 --- a/src/main.h +++ b/src/main.h @@ -2596,6 +2596,7 @@ struct LevelInfo boolean use_custom_template; /* use custom properties from template file */ boolean no_valid_file; /* set when level file missing or invalid */ + boolean no_level_file; /* set when falling back to level template */ boolean changed; /* set when level was changed in the editor */ diff --git a/src/screens.c b/src/screens.c index e7f5c051..b2c61ea9 100644 --- a/src/screens.c +++ b/src/screens.c @@ -4142,13 +4142,13 @@ void DrawChooseLevelNr() ti->node_top = &level_number; ti->sort_priority = 10000 + value; - ti->color = (level.no_valid_file ? FC_BLUE : + ti->color = (level.no_level_file ? FC_BLUE : LevelStats_getSolved(i) ? FC_GREEN : LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED); sprintf(identifier, "%d", value); sprintf(name, "%03d: %s", value, - (level.no_valid_file ? "(no file)" : level.name)); + (level.no_level_file ? "(no file)" : level.name)); setString(&ti->identifier, identifier); setString(&ti->name, name); diff --git a/src/tape.c b/src/tape.c index e97dc086..8c1e059b 100644 --- a/src/tape.c +++ b/src/tape.c @@ -1112,7 +1112,7 @@ void AutoPlayTape() Print("Level %03d: ", level_nr); LoadLevel(level_nr); - if (level.no_valid_file) + if (level.no_level_file || level.no_valid_file) { Print("(no level)\n"); continue;