Add difficulty in game_classification and use it for config loading.
This commit is contained in:
parent
9708f11ca4
commit
3de33c39f5
6 changed files with 20 additions and 14 deletions
|
@ -303,11 +303,10 @@ void game_config_manager::load_game_config_for_editor()
|
|||
}
|
||||
|
||||
void game_config_manager::load_game_config_for_game(
|
||||
const game_classification& classification,
|
||||
const std::string& game_difficulty)
|
||||
const game_classification& classification)
|
||||
{
|
||||
game_config::scoped_preproc_define difficulty(game_difficulty,
|
||||
!game_difficulty.empty());
|
||||
game_config::scoped_preproc_define difficulty(classification.difficulty,
|
||||
!classification.difficulty.empty());
|
||||
game_config::scoped_preproc_define campaign(classification.campaign_define,
|
||||
!classification.campaign_define.empty());
|
||||
game_config::scoped_preproc_define multiplayer("MULTIPLAYER",
|
||||
|
|
|
@ -37,8 +37,7 @@ public:
|
|||
void reload_changed_game_config();
|
||||
|
||||
void load_game_config_for_editor();
|
||||
void load_game_config_for_game(const game_classification& classification,
|
||||
const std::string& game_difficulty = "");
|
||||
void load_game_config_for_game(const game_classification& classification);
|
||||
|
||||
private:
|
||||
game_config_manager(const game_config_manager&);
|
||||
|
|
|
@ -464,8 +464,7 @@ bool game_controller::load_game()
|
|||
|
||||
try {
|
||||
resources::config_manager->
|
||||
load_game_config_for_game(state_.classification(),
|
||||
load.get_difficulty());
|
||||
load_game_config_for_game(state_.classification());
|
||||
} catch(config::error&) {
|
||||
return false;
|
||||
}
|
||||
|
@ -687,6 +686,7 @@ bool game_controller::new_campaign()
|
|||
}
|
||||
|
||||
state_.carryover_sides_start["difficulty"] = difficulties[difficulty];
|
||||
state_.classification().difficulty = difficulties[difficulty];
|
||||
}
|
||||
|
||||
state_.classification().campaign_define = campaign["define"].str();
|
||||
|
@ -953,8 +953,7 @@ void game_controller::launch_game(RELOAD_GAME_DATA reload)
|
|||
if(reload == RELOAD_DATA) {
|
||||
try {
|
||||
resources::config_manager->
|
||||
load_game_config_for_game(state_.classification(),
|
||||
state_.carryover_sides_start["difficulty"]);
|
||||
load_game_config_for_game(state_.classification());
|
||||
} catch(config::error&) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -904,7 +904,8 @@ game_classification::game_classification():
|
|||
completion(),
|
||||
end_credits(true),
|
||||
end_text(),
|
||||
end_text_duration()
|
||||
end_text_duration(),
|
||||
difficulty(DEFAULT_DIFFICULTY)
|
||||
{}
|
||||
|
||||
game_classification::game_classification(const config& cfg):
|
||||
|
@ -921,7 +922,8 @@ game_classification::game_classification(const config& cfg):
|
|||
completion(cfg["completion"]),
|
||||
end_credits(cfg["end_credits"].to_bool(true)),
|
||||
end_text(cfg["end_text"]),
|
||||
end_text_duration(cfg["end_text_duration"])
|
||||
end_text_duration(cfg["end_text_duration"]),
|
||||
difficulty(cfg["difficulty"])
|
||||
{}
|
||||
|
||||
game_classification::game_classification(const game_classification& gc):
|
||||
|
@ -938,7 +940,8 @@ game_classification::game_classification(const game_classification& gc):
|
|||
completion(gc.completion),
|
||||
end_credits(gc.end_credits),
|
||||
end_text(gc.end_text),
|
||||
end_text_duration(gc.end_text_duration)
|
||||
end_text_duration(gc.end_text_duration),
|
||||
difficulty(gc.difficulty)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -959,6 +962,7 @@ config game_classification::to_config() const
|
|||
cfg["end_credits"] = end_credits;
|
||||
cfg["end_text"] = end_text;
|
||||
cfg["end_text_duration"] = str_cast<unsigned int>(end_text_duration);
|
||||
cfg["difficulty"] = difficulty;
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
@ -1239,6 +1243,8 @@ void game_state::write_snapshot(config& cfg, game_display* gui) const
|
|||
cfg["end_text"] = classification_.end_text;
|
||||
cfg["end_text_duration"] = str_cast<unsigned int>(classification_.end_text_duration);
|
||||
|
||||
cfg["difficulty"] = classification_.difficulty;
|
||||
|
||||
if(resources::gamedata != NULL){
|
||||
resources::gamedata->write_snapshot(cfg);
|
||||
}
|
||||
|
|
|
@ -268,7 +268,7 @@ public:
|
|||
bool end_credits; /**< whether to show the standard credits at the end */
|
||||
std::string end_text; /**< end-of-campaign text */
|
||||
unsigned int end_text_duration; /**< for how long the end-of-campaign text is shown */
|
||||
// std::string difficulty; /**< The difficulty level the game is being played on. */
|
||||
std::string difficulty; /**< The difficulty level the game is being played on. */
|
||||
};
|
||||
|
||||
class game_state
|
||||
|
|
|
@ -641,6 +641,9 @@ void loadgame::load_game(
|
|||
gamestate_.classification().campaign_type = load_config_["campaign_type"].str();
|
||||
gamestate_.classification().campaign_xtra_defines = utils::split(load_config_["campaign_extra_defines"]);
|
||||
gamestate_.classification().version = load_config_["version"].str();
|
||||
std::string load_config_difficulty =
|
||||
load_config_.child("carryover_sides_start")["difficulty"];
|
||||
gamestate_.classification().difficulty = load_config_difficulty;
|
||||
|
||||
check_version_compatibility();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue