Reload game config in mp::wait.

The game config is being reloaded to make sure that players have the
same config as host, if possible.

Note that reloading only happens when it is necessary and it would not
happen if host's cache defines matches the player's ones. I.e. regular
MP scenarios won't trigger a config reload.
This commit is contained in:
Andrius Silinskas 2013-09-17 12:54:05 +01:00
parent 359597921f
commit 50460f2596
5 changed files with 42 additions and 2 deletions

View file

@ -30,6 +30,7 @@ mp_game_settings::mp_game_settings() :
mp_scenario(),
mp_scenario_name(),
mp_campaign(),
difficulty_define(),
active_mods(),
side_users(),
num_turns(0),
@ -64,6 +65,7 @@ mp_game_settings::mp_game_settings(const config& cfg) :
mp_scenario(),
mp_scenario_name(),
mp_campaign(),
difficulty_define(),
active_mods(),
side_users(),
num_turns(0),
@ -99,6 +101,7 @@ mp_game_settings::mp_game_settings(const mp_game_settings& settings)
, mp_scenario(settings.mp_scenario)
, mp_scenario_name(settings.mp_scenario_name)
, mp_campaign(settings.mp_campaign)
, difficulty_define(settings.difficulty_define)
, active_mods(settings.active_mods)
, side_users(settings.side_users)
, num_turns(settings.num_turns)
@ -136,6 +139,7 @@ void mp_game_settings::set_from_config(const config& game_cfg)
mp_scenario = cfg["mp_scenario"].str();
mp_scenario_name = cfg["scenario_name"].str();
mp_campaign = cfg["mp_campaign"].str();
difficulty_define = cfg["difficulty_define"].str();
active_mods = utils::split(cfg["active_mods"], ',');
side_users = utils::map_split(cfg["side_users"]);
xp_modifier = cfg["experience_modifier"];
@ -166,6 +170,7 @@ void mp_game_settings::reset()
mp_scenario = "";
mp_scenario_name = "";
mp_campaign = "";
difficulty_define = "";
active_mods.clear();
side_users.clear();
num_turns = 0;
@ -193,6 +198,7 @@ config mp_game_settings::to_config() const
cfg["mp_scenario"] = mp_scenario;
cfg["mp_scenario_name"] = mp_scenario_name;
cfg["mp_campaign"] = mp_campaign;
cfg["difficulty_define"] = difficulty_define;
cfg["active_mods"] = utils::join(active_mods, ",");
cfg["side_users"] = utils::join_map(side_users);
cfg["experience_modifier"] = xp_modifier;

View file

@ -40,6 +40,7 @@ struct mp_game_settings : public savegame::savegame_config
std::string mp_scenario;
std::string mp_scenario_name;
std::string mp_campaign;
std::string difficulty_define;
std::vector<std::string> active_mods;
std::map<std::string, std::string> side_users;

View file

@ -369,6 +369,7 @@ void create_engine::prepare_for_campaign(const std::string& difficulty)
if (difficulty != "") {
state_.classification().difficulty = difficulty;
parameters_.difficulty_define = difficulty;
}
state_.classification().campaign_define =

View file

@ -16,6 +16,7 @@
#include "dialogs.hpp"
#include "gettext.hpp"
#include "game_config_manager.hpp"
#include "game_preferences.hpp"
#include "gui/dialogs/transient_message.hpp"
#include "game_display.hpp"
@ -188,12 +189,21 @@ wait::wait(game_display& disp, const config& cfg, game_state& state,
first_scenario_(first_scenario),
stop_updates_(false)
{
state_ = game_state();
game_menu_.set_numeric_keypress_selection(false);
gamelist_updated();
}
wait::~wait()
{
if (get_result() == QUIT) {
state_ = game_state();
state_.classification().campaign_type = "multiplayer";
resources::config_manager->
load_game_config_for_game(state_.classification());
}
}
void wait::process_event()
{
if (cancel_button_.pressed())
@ -211,6 +221,27 @@ void wait::join_game(bool observe)
return;
}
if (first_scenario_) {
state_ = game_state();
state_.classification().campaign_type = "multiplayer";
const config* campaign = &resources::config_manager->
game_config().find_child("campaign", "id",
level_.child("multiplayer")["mp_campaign"]);
if (*campaign) {
state_.classification().difficulty =
level_.child("multiplayer")["difficulty_define"].str();
state_.classification().campaign_define =
(*campaign)["define"].str();
state_.classification().campaign_xtra_defines =
utils::split((*campaign)["extra_defines"]);
}
// Make sure that we have the same config as host, if possible.
resources::config_manager->
load_game_config_for_game(state_.classification());
}
// Add the map name to the title.
append_to_title(": " + level_["name"].t_str());

View file

@ -28,6 +28,7 @@ class wait : public ui
public:
wait(game_display& disp, const config& cfg, game_state& state, chat& c,
config& gamelist, const bool first_scenario = true);
~wait();
virtual void process_event();
void join_game(bool observe);