Skip to content

Commit

Permalink
Merge pull request #177 from gfgtdf/remove_diffic
Browse files Browse the repository at this point in the history
remove "difficulty_" and "random_mode_" from game_data and carryover
(we already have them in the classification)
  • Loading branch information
gfgtdf committed Jun 1, 2014
2 parents 1979e5e + c0b8168 commit ebbf813
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/ai/default/ai.cpp
Expand Up @@ -250,7 +250,7 @@ bool ai_default_recruitment_stage::recruit_usage(const std::string& usage)
//FIXME: This message should be suppressed when WML author
//chooses the default recruitment pattern.
const std::string warning = "At difficulty level " +
resources::gamedata->difficulty() + ", trying to recruit a:" +
resources::state_of_game->classification().difficulty + ", trying to recruit a:" +
usage + " but no unit of that type (usage=) is"
" available. Check the recruit and [ai]"
" recruitment_pattern keys for team '" +
Expand Down
2 changes: 1 addition & 1 deletion src/ai/testing/ca.cpp
Expand Up @@ -361,7 +361,7 @@ bool recruitment_phase::recruit_usage(const std::string& usage)
//FIXME: This message should be suppressed when WML author
//chooses the default recruitment pattern.
const std::string warning = "At difficulty level " +
resources::gamedata->difficulty() + ", trying to recruit a:" +
resources::state_of_game->classification().difficulty + ", trying to recruit a:" +
usage + " but no unit of that type (usage=) is"
" available. Check the recruit and [ai]"
" recruitment_pattern keys for team '" +
Expand Down
34 changes: 6 additions & 28 deletions src/gamestatus.cpp
Expand Up @@ -193,8 +193,6 @@ carryover_info::carryover_info(const config& cfg)
, variables_(cfg.child_or_empty("variables"))
, rng_(cfg)
, wml_menu_items_()
, difficulty_(cfg["difficulty"].empty() ? DEFAULT_DIFFICULTY : cfg["difficulty"].str())
, random_mode_(cfg["random_mode"].str())
, next_scenario_(cfg["next_scenario"])
{
end_level_.read(cfg.child_or_empty("end_level_data"));
Expand Down Expand Up @@ -262,8 +260,6 @@ void carryover_info::transfer_from(game_data& gamedata){
variables_ = gamedata.get_variables();
wml_menu_items_ = gamedata.get_wml_menu_items();
rng_ = gamedata.rng();
difficulty_ = gamedata.difficulty();
random_mode_ = gamedata.random_mode();
next_scenario_ = gamedata.next_scenario();
}

Expand All @@ -283,13 +279,6 @@ void carryover_info::transfer_to(config& level){
wml_menu_items_.to_config(level);
}

if(level["difficulty"].empty()){
level["difficulty"] = difficulty_;
}
if(level["random_mode"].empty()){
level["random_mode"] = random_mode_;
}
difficulty_ = "";
next_scenario_ = "";

}
Expand All @@ -298,8 +287,6 @@ const config carryover_info::to_config()
{
config cfg;

cfg["difficulty"] = difficulty_;
cfg["random_mode"] = random_mode_;
cfg["next_scenario"] = next_scenario_;

BOOST_FOREACH(carryover& c, carryover_sides_){
Expand Down Expand Up @@ -624,8 +611,6 @@ game_data::game_data()
, temporaries_()
, phase_(INITIAL)
, can_end_turn_(true)
, difficulty_(DEFAULT_DIFFICULTY)
, random_mode_("")
, scenario_()
, next_scenario_()
{}
Expand All @@ -639,8 +624,6 @@ game_data::game_data(const config& level)
, temporaries_()
, phase_(INITIAL)
, can_end_turn_(level["can_end_turn"].to_bool(true))
, difficulty_(level["difficulty"].empty() ? DEFAULT_DIFFICULTY : level["difficulty"].str())
, random_mode_(level["random_mode"].str())
, scenario_(level["id"])
, next_scenario_(level["next_scenario"])
{
Expand All @@ -657,8 +640,6 @@ game_data::game_data(const game_data& data)
, temporaries_()
, phase_(data.phase_)
, can_end_turn_(data.can_end_turn_)
, difficulty_(data.difficulty_)
, random_mode_(data.random_mode_)
, scenario_(data.scenario_)
, next_scenario_(data.next_scenario_)
{}
Expand Down Expand Up @@ -723,8 +704,6 @@ void game_data::clear_variable(const std::string& varname)
}

void game_data::write_snapshot(config& cfg){
cfg["difficulty"] = difficulty_;
cfg["random_mode"] = random_mode_;
cfg["scenario"] = scenario_;
cfg["next_scenario"] = next_scenario_;

Expand All @@ -739,8 +718,6 @@ void game_data::write_snapshot(config& cfg){
}

void game_data::write_config(config_writer& out){
out.write_key_val("difficulty", difficulty_);
out.write_key_val("random_mode", random_mode_);
out.write_key_val("scenario", scenario_);
out.write_key_val("next_scenario", next_scenario_);

Expand Down Expand Up @@ -823,7 +800,7 @@ game_classification::game_classification(const config& cfg):
end_credits(cfg["end_credits"].to_bool(true)),
end_text(cfg["end_text"]),
end_text_duration(cfg["end_text_duration"]),
difficulty(cfg["difficulty"]),
difficulty(cfg["difficulty"].empty() ? DEFAULT_DIFFICULTY : cfg["difficulty"].str()),
random_mode(cfg["random_mode"])
{}

Expand Down Expand Up @@ -1092,13 +1069,14 @@ void extract_summary_from_config(config& cfg_save, config& cfg_summary)

if(cfg_save.has_child("carryover_sides_start")){
cfg_summary["scenario"] = cfg_save.child("carryover_sides_start")["next_scenario"];
cfg_summary["difficulty"] = cfg_save.child("carryover_sides_start")["difficulty"];
cfg_summary["random_mode"] = cfg_save.child("carryover_sides_start")["random_mode"];
} else {
cfg_summary["scenario"] = cfg_save["scenario"];
cfg_summary["difficulty"] = cfg_save["difficulty"];
cfg_summary["random_mode"] = cfg_save["random_mode"];
}

cfg_summary["difficulty"] = cfg_save["difficulty"];
cfg_summary["random_mode"] = cfg_save["random_mode"];


cfg_summary["campaign"] = cfg_save["campaign"];
cfg_summary["version"] = cfg_save["version"];
cfg_summary["corrupt"] = "";
Expand Down
10 changes: 0 additions & 10 deletions src/gamestatus.hpp
Expand Up @@ -101,8 +101,6 @@ class carryover_info{
, variables_()
, rng_()
, wml_menu_items_()
, difficulty_(DEFAULT_DIFFICULTY)
, random_mode_("")
, next_scenario_()
{}
// Turns config from a loaded savegame into carryover_info
Expand Down Expand Up @@ -131,8 +129,6 @@ class carryover_info{

const end_level_data& get_end_level() const;

const std::string& difficulty() const { return difficulty_; }
const std::string& random_mode() const { return random_mode_; }
const std::string& next_scenario() const { return next_scenario_; }

const config to_config();
Expand All @@ -142,8 +138,6 @@ class carryover_info{
config variables_;
rand_rng::simple_rng rng_;
game_events::wmi_container wml_menu_items_;
std::string difficulty_; /**< The difficulty level the game is being played on. */
std::string random_mode_; /**< whether we generate a new randomseed for each user action. */
std::string next_scenario_; /**< the scenario coming next (for campaigns) */
};

Expand Down Expand Up @@ -203,8 +197,6 @@ class game_data : public variable_set {
void write_snapshot(config& cfg);
void write_config(config_writer& out);

const std::string& difficulty() const { return difficulty_; }
const std::string& random_mode() const { return random_mode_; }
const std::string& next_scenario() const { return next_scenario_; }
void set_next_scenario(const std::string& next_scenario) { next_scenario_ = next_scenario; }

Expand All @@ -219,8 +211,6 @@ class game_data : public variable_set {
friend struct variable_info;
PHASE phase_;
bool can_end_turn_;
std::string difficulty_; /**< The difficulty level the game is being played on. */
std::string random_mode_;
std::string scenario_; /**< the scenario being played */
std::string next_scenario_; /**< the scenario coming next (for campaigns) */
};
Expand Down
2 changes: 1 addition & 1 deletion src/play_controller.cpp
Expand Up @@ -585,7 +585,7 @@ void play_controller::fire_start(bool execute){
} else {
it_is_a_new_turn_ = false;
}
if((gamedata_.random_mode() != "" || gamestate_.classification().random_mode != "") && (network::nconnections() != 0))
if( gamestate_.classification().random_mode != "" && (network::nconnections() != 0))
{
std::string mes = _("MP game uses an alternative random mode, if you don't know what this message means, then most likeley someone is cheating or someone reloaded a corrupt game.");
resources::screen->add_chat_message(
Expand Down
7 changes: 4 additions & 3 deletions src/savegame.cpp
Expand Up @@ -574,21 +574,22 @@ void loadgame::load_game(
}

if (!difficulty_.empty()){
if ( config & carryover = load_config_.child("carryover_sides_start") )
carryover["difficulty"] = difficulty_;
load_config_["difficulty"] = difficulty_;
}

gamestate_.classification().campaign_define = load_config_["campaign_define"].str();
gamestate_.classification().campaign_type = lexical_cast_default<game_classification::CAMPAIGN_TYPE> (load_config_["campaign_type"].str(), game_classification::SCENARIO);
gamestate_.classification().campaign_xtra_defines = utils::split(load_config_["campaign_extra_defines"]);
gamestate_.classification().version = load_config_["version"].str();
gamestate_.classification().difficulty = load_config_["difficulty"].str();
/*
if (config & carryover_sides_start = load_config_.child("carryover_sides_start")) {
std::string load_config_difficulty = carryover_sides_start["difficulty"];
gamestate_.classification().difficulty = load_config_difficulty;
} else {
gamestate_.classification().difficulty = difficulty_;
}

*/
check_version_compatibility();

}
Expand Down
9 changes: 6 additions & 3 deletions src/savegame.hpp
Expand Up @@ -105,11 +105,14 @@ class loadgame
const std::string & filename() const { return filename_; }

std::string get_difficulty() const
{ if ( const config & carryover = load_config_.child("carryover_sides_start") )
{ return load_config_["difficulty"].empty() ? DEFAULT_DIFFICULTY : load_config_["difficulty"].str(); }
/*
{ if ( const config & carryover = load_config_.child("carryover_sides_start") )
return carryover["difficulty"];
else
return DEFAULT_DIFFICULTY; }

return DEFAULT_DIFFICULTY;
}
*/
private:
/** Display the load-game dialog. */
void show_dialog(bool show_replay, bool cancel_orders);
Expand Down
9 changes: 1 addition & 8 deletions src/synced_context.cpp
Expand Up @@ -210,14 +210,7 @@ void synced_context::pull_remote_user_input()

boost::shared_ptr<random_new::rng> synced_context::get_rng_for_action()
{
/*
i copied the code for "deterministic_mode" from the code for "difficulty".
i don't know why we have this information twice, i just did it because we have the information for difficulty twice too.
*/
const std::string& v1 = resources::gamedata->random_mode();
const std::string& v2 = resources::state_of_game->classification().random_mode;
assert(v1==v2);
const std::string& mode= v1; // = resources ... gamestate ... get_random_mode()
const std::string& mode = resources::state_of_game->classification().random_mode;
if(mode == "deterministic")
{
return boost::shared_ptr<random_new::rng>(new random_new::rng_deterministic(resources::gamedata->rng()));
Expand Down

0 comments on commit ebbf813

Please sign in to comment.