Skip to content

Commit

Permalink
add not_corrupt() function in saved_game class
Browse files Browse the repository at this point in the history
and add comments about other functions.
  • Loading branch information
gfgtdf committed Jun 15, 2014
1 parent ac9628e commit 7e3b5c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/saved_game.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
9 changes: 8 additions & 1 deletion src/saved_game.hpp
Expand Up @@ -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_; }
Expand All @@ -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.
Expand Down

0 comments on commit 7e3b5c1

Please sign in to comment.