Skip to content

Commit

Permalink
load replay from [scenario] if [replay_start] is not present
Browse files Browse the repository at this point in the history
the intention is to change the serverside generated replays to contain
[scenario] & [carryover_sides_start] & [replay]. [replay_start] would
be wrong because carryover isn't expanded in these servergenerated
saves.

Servergenerated saves from reloaded (non start of scenario) games will
then contain  [replay_start] & [carryover_sides] & [replay]
  • Loading branch information
gfgtdf committed Jun 15, 2014
1 parent a898333 commit 9e40b26
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/playcampaign.cpp
Expand Up @@ -162,7 +162,8 @@ LEVEL_RESULT play_replay(display& disp, saved_game& gamestate, const config& gam
const std::string campaign_type_str = lexical_cast<std::string> (gamestate.classification().campaign_type);

// 'starting_pos' will contain the position we start the game from.
const config& starting_pos = gamestate.replay_start();
// this call also might expand [scenario] in case thatt there is no replay_start
const config& starting_pos = gamestate.get_replay_starting_pos();

try {
// Preserve old label eg. replay
Expand Down
4 changes: 1 addition & 3 deletions src/replay_controller.cpp
Expand Up @@ -50,14 +50,12 @@ LEVEL_RESULT play_replay_level(const config& game_config,
{
const int ticks = SDL_GetTicks();

config init_level = state_of_game.replay_start();

DBG_NG << "creating objects... " << (SDL_GetTicks() - ticks) << std::endl;

boost::scoped_ptr<replay_controller> rc;

try {
rc.reset(new replay_controller(init_level, state_of_game, ticks, game_config, video));
rc.reset(new replay_controller(state_of_game.get_replay_starting_pos(), state_of_game, ticks, game_config, video));
} catch (end_level_exception & e){
return e.result;
} catch (end_turn_exception &) {
Expand Down
3 changes: 2 additions & 1 deletion src/save_index.cpp
Expand Up @@ -397,7 +397,8 @@ save_info create_save_info::operator()(const std::string& filename) const
void extract_summary_from_config(config& cfg_save, config& cfg_summary)
{
const config &cfg_snapshot = cfg_save.child("snapshot");
const config &cfg_replay_start = cfg_save.child("replay_start");
//Servergenerated replays contain [scenario] and no [replay_start]
const config &cfg_replay_start = cfg_save.child("replay_start") ? cfg_save.child("replay_start") : cfg_save.child("scenario") ;

const config &cfg_replay = cfg_save.child("replay");
const bool has_replay = cfg_replay && !cfg_replay.empty();
Expand Down
20 changes: 20 additions & 0 deletions src/saved_game.cpp
Expand Up @@ -247,6 +247,26 @@ config& saved_game::get_starting_pos()
return starting_pos_;
}


const config& saved_game::get_replay_starting_pos()
{
if(!this->replay_start_.empty())
{
return replay_start_;
}
if(!this->carryover_sides_start.empty())
{
//Try to load the scenario form game config or from [scenario] if there is no [replay_start]
expand_scenario();
expand_carryover();
}
if(starting_pos_type_ == STARTINGPOS_SCENARIO)
{
return starting_pos_;
}
return this->replay_start_.child("some_non_existet_invalid");
}

void saved_game::remove_old_scenario()
{
remove_snapshot();
Expand Down
3 changes: 2 additions & 1 deletion src/saved_game.hpp
Expand Up @@ -51,7 +51,8 @@ class saved_game
return starting_pos_type_ == STARTINGPOS_SNAPSHOT;
}
void convert_to_start_save();

const config& get_replay_starting_pos();

config& get_starting_pos();
config& replay_start() { return replay_start_; }
/**
Expand Down

0 comments on commit 9e40b26

Please sign in to comment.