From b63a3be6785ae0f5a60ee5fafffbbe6b5fe2436b Mon Sep 17 00:00:00 2001 From: gfgtdf Date: Mon, 22 Jun 2020 22:13:47 +0200 Subject: [PATCH] game_config_manger refactoring This commit prepares a patch to disable unused addons during a game. We try to reduce codes that change the game_config config object. In particular this removes a code that changes the order of terrain graphics tag. This could in theory break code that relied on that order but afaik the terrain_graphics tags offers a `precedence` that allows users to specify the order in which terrain graphics are applied. so no additional compatabiltiy code is needed. --- src/game_config_manager.cpp | 22 ---------------------- src/saved_game.cpp | 9 ++++++++- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/src/game_config_manager.cpp b/src/game_config_manager.cpp index 0ffc7f4e335d..53bdd8e7f756 100644 --- a/src/game_config_manager.cpp +++ b/src/game_config_manager.cpp @@ -274,34 +274,12 @@ void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload, main_transaction.lock(); - // Put the gfx rules aside so that we can prepend the add-on - // rules to them. - config core_terrain_rules; - core_terrain_rules.splice_children(game_config_, "terrain_graphics"); - if (!game_config::no_addons && !cmdline_opts_.noaddons) load_addons_cfg(); - // If multiplayer campaign is being loaded, [scenario] tags should - // become [multiplayer] tags and campaign's id should be added to them - // to allow to recognize which scenarios belongs to a loaded campaign. - if (classification != nullptr) { - if (const config& campaign = game_config().find_child("campaign", "id", classification->campaign)) - { - const bool require_campaign = campaign["require_campaign"].to_bool(true); - for (config& scenario : game_config_.child_range("scenario")) - { - scenario["require_scenario"] = require_campaign; - } - } - } // Extract the Lua scripts at toplevel. game_lua_kernel::extract_preload_scripts(game_config()); - game_config_.clear_children("lua"); - - // Put the gfx rules back to game config. - game_config_.splice_children(core_terrain_rules, "terrain_graphics"); set_multiplayer_hashes(); set_unit_data(); diff --git a/src/saved_game.cpp b/src/saved_game.cpp index d24a7de18a84..1a8d09c811d0 100644 --- a/src/saved_game.cpp +++ b/src/saved_game.cpp @@ -217,12 +217,19 @@ void saved_game::set_defaults() { const bool is_loaded_game = this->starting_point_type_ != STARTING_POINT_SCENARIO; const bool is_multiplayer_tag = classification().get_tagname() == "multiplayer"; - + const game_config_view& game_config = game_config_manager::get()->game_config(); static const std::vector team_defaults { "carryover_percentage", "carryover_add", }; + + if (const config& campaign = game_config.find_child("campaign", "id", classification_.campaign)) + { + bool require_campaign = campaign["require_campaign"].to_bool(true); + starting_point_["require_scenario"] = require_campaign; + } + for(config& side : starting_point_.child_range("side")) { // Set save_id default value directly after loading to its default to prevent different default behaviour in // mp_connect code and sp code.