implement the deterministic mode for sp. part1

I don't really know much about the gamestatus cpp/hpp file, so i just
copied from the difficulty code (to create the random_mode attribute).

I add the deterministic mode to the ui in another commit.
This commit is contained in:
gfgtdf 2014-04-02 21:36:58 +02:00
parent 01f38ca46e
commit 8495ebceae
3 changed files with 39 additions and 6 deletions

View File

@ -194,6 +194,7 @@ carryover_info::carryover_info(const config& cfg)
, 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"));
@ -262,6 +263,7 @@ void carryover_info::transfer_from(game_data& gamedata){
wml_menu_items_ = gamedata.get_wml_menu_items();
rng_ = gamedata.rng();
difficulty_ = gamedata.difficulty();
random_mode_ = gamedata.random_mode();
next_scenario_ = gamedata.next_scenario();
}
@ -284,15 +286,20 @@ void carryover_info::transfer_to(config& level){
if(level["difficulty"].empty()){
level["difficulty"] = difficulty_;
}
if(level["random_mode"].empty()){
level["random_mode"] = random_mode_;
}
difficulty_ = "";
next_scenario_ = "";
}
const config carryover_info::to_config() {
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_){
@ -634,6 +641,7 @@ game_data::game_data()
, phase_(INITIAL)
, can_end_turn_(true)
, difficulty_(DEFAULT_DIFFICULTY)
, random_mode_("")
, scenario_()
, next_scenario_()
{}
@ -648,6 +656,7 @@ game_data::game_data(const config& level)
, 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"])
{
@ -665,6 +674,7 @@ game_data::game_data(const game_data& data)
, 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_)
{}
@ -730,6 +740,7 @@ 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_;
@ -745,6 +756,7 @@ 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_);
@ -810,7 +822,8 @@ game_classification::game_classification():
end_credits(true),
end_text(),
end_text_duration(),
difficulty(DEFAULT_DIFFICULTY)
difficulty(DEFAULT_DIFFICULTY),
random_mode("")
{}
game_classification::game_classification(const config& cfg):
@ -828,7 +841,8 @@ 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"]),
random_mode(cfg["random_mode"])
{}
game_classification::game_classification(const game_classification& gc):
@ -846,7 +860,8 @@ game_classification::game_classification(const game_classification& gc):
end_credits(gc.end_credits),
end_text(gc.end_text),
end_text_duration(gc.end_text_duration),
difficulty(gc.difficulty)
difficulty(gc.difficulty),
random_mode(gc.random_mode)
{
}
@ -868,6 +883,7 @@ config game_classification::to_config() const
cfg["end_text"] = end_text;
cfg["end_text_duration"] = str_cast<unsigned int>(end_text_duration);
cfg["difficulty"] = difficulty;
cfg["random_mode"] = random_mode;
return cfg;
}
@ -959,6 +975,7 @@ void convert_old_saves(config& cfg){
carryover.add_child("menu_item", menu_item);
}
carryover["difficulty"] = cfg["difficulty"];
carryover["random_mode"] = cfg["random_mode"];
//the scenario to be played is always stored as next_scenario in carryover_sides_start
carryover["next_scenario"] = cfg["scenario"];
@ -1067,7 +1084,8 @@ void game_state::write_snapshot(config& cfg, game_display* gui) const
cfg["end_text_duration"] = str_cast<unsigned int>(classification_.end_text_duration);
cfg["difficulty"] = classification_.difficulty;
cfg["random_mode"] = classification_.random_mode;
if(resources::gamedata != NULL){
resources::gamedata->write_snapshot(cfg);
}
@ -1096,9 +1114,11 @@ 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["campaign"] = cfg_save["campaign"];
cfg_summary["version"] = cfg_save["version"];

View File

@ -101,6 +101,7 @@ public:
, rng_()
, wml_menu_items_()
, difficulty_(DEFAULT_DIFFICULTY)
, random_mode_("")
, next_scenario_()
{}
// Turns config from a loaded savegame into carryover_info
@ -130,6 +131,7 @@ public:
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();
@ -140,6 +142,7 @@ private:
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) */
};
@ -200,6 +203,7 @@ public:
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; }
@ -215,6 +219,7 @@ private:
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) */
bool is_determisic_mode_;
@ -247,6 +252,7 @@ public:
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 random_mode;
};
class game_state

View File

@ -150,7 +150,14 @@ void synced_context::pull_remote_user_input()
boost::shared_ptr<random_new::rng> synced_context::get_rng_for(const std::string& commandname)
{
const std::string/*&*/ mode= ""; // = resources ... gamestate ... get_random_mode()
/*
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()
if(mode == "deterministic")
{
return boost::shared_ptr<random_new::rng>(new random_new::rng_deterministic(resources::gamedata->rng()));