From 7e3b5c199aebe9618b2578ea7ca46033700baaba Mon Sep 17 00:00:00 2001 From: gfgtdf Date: Fri, 13 Jun 2014 16:32:00 +0200 Subject: [PATCH] add not_corrupt() function in saved_game class and add comments about other functions. --- src/saved_game.cpp | 17 +++++++++++++++++ src/saved_game.hpp | 9 ++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/saved_game.cpp b/src/saved_game.cpp index 1137993b9786..0e418fd26a2f 100644 --- a/src/saved_game.cpp +++ b/src/saved_game.cpp @@ -167,6 +167,7 @@ void saved_game::write_starting_pos(config_writer& out) const } void saved_game::write_carryover(config_writer& out) const { + assert(not_corrupt()); if(!this->carryover_sides.empty()) { out.write_child("carryover_sides", carryover_sides); @@ -342,3 +343,19 @@ std::string saved_game::get_scenario_id() return carryover_sides_start["next_scenario"]; } } + + +bool saved_game::not_corrupt() const +{ + if(carryover_sides.empty() && carryover_sides_start.empty()) + { + //this case is dangerous but currently not impossible. + WRN_NG << "savefile contains neigher [carryover_sides] not [carryover_sides_start]" << std::endl; + } + // A Scenario can never contain both of them + // normal saves have [carryover_sides] start-of-scenario saved have [carryover_sides_start] + // the function expand_carryover transforms a start of scenario save to a normal save + // the function convert_to_start_save converts a normal save form teh end of the scenaio + // to a start-of-scenario save for a next level + return carryover_sides.empty() || carryover_sides_start.empty(); +} diff --git a/src/saved_game.hpp b/src/saved_game.hpp index 4dfea9ace590..43a522510346 100644 --- a/src/saved_game.hpp +++ b/src/saved_game.hpp @@ -30,6 +30,7 @@ class saved_game void write_carryover(config_writer& out) const; void write_starting_pos(config_writer& out) const; config to_config(); + ///Removes everything except [carryover_sides_start] void remove_old_scenario(); game_classification& classification() { return classification_; } const game_classification& classification() const { return classification_; } @@ -51,13 +52,19 @@ class saved_game { return starting_pos_type_ == STARTINGPOS_SNAPSHOT; } + /// converts a normal savegame form the end of a scenaio to a start-of-scenario savefiel for teh next scenaio, + /// The saved_game must contain a [snapshot] made during the linger mode of the last scenaio. void convert_to_start_save(); + /// retruns from the config from which the replay will be started. Usualy this is [replay_start] but it can also be a [scenario] if no replay_start is present const config& get_replay_starting_pos(); - + /// returns the id of teh curently played scenaio or the id of the next scenaio if this is a between-scenaios-save (also called start-of-scenario) save. std::string get_scenario_id(); + /// retruns from the config from which teh game will be started. [scenario] or [snapshot] in the file config& get_starting_pos(); config& replay_start() { return replay_start_; } const config& replay_start() const { return replay_start_; } + + bool not_corrupt() const; /** * If the game is saved mid-level, we have a series of replay steps * to take the game up to the position it was saved at.