Skip to content

Commit

Permalink
game_config_manger refactoring
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gfgtdf committed Jun 29, 2020
1 parent 93aa2ca commit b63a3be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
22 changes: 0 additions & 22 deletions src/game_config_manager.cpp
Expand Up @@ -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();
Expand Down
9 changes: 8 additions & 1 deletion src/saved_game.cpp
Expand Up @@ -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<std::string> 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.
Expand Down

0 comments on commit b63a3be

Please sign in to comment.