Skip to content

Commit

Permalink
change saved_game name to saved_game_ in play_controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Jun 24, 2014
1 parent b51d6a1 commit bd9fb69
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 46 deletions.
30 changes: 15 additions & 15 deletions src/play_controller.cpp
Expand Up @@ -117,7 +117,7 @@ play_controller::play_controller(const config& level, saved_game& state_of_game,
gui_(),
statistics_context_(level["name"]),
level_(level),
gamestate_(state_of_game),
saved_game_(state_of_game),
gamedata_(level),
undo_stack_(new actions::undo_list(level.child("undo_stack"))),
whiteboard_manager_(),
Expand Down Expand Up @@ -150,8 +150,8 @@ play_controller::play_controller(const config& level, saved_game& state_of_game,
resources::units = &gameboard_.units_;


resources::classification = &gamestate_.classification();
resources::mp_settings = &gamestate_.mp_settings();
resources::classification = &saved_game_.classification();
resources::mp_settings = &saved_game_.mp_settings();

persist_.start_transaction();
n_unit::id_manager::instance().set_save_id(level_["next_underlying_unit_id"]);
Expand Down Expand Up @@ -226,7 +226,7 @@ void play_controller::init(CVideo& video){
}
}
team_builder_ptr tb_ptr = gamedata_.create_team_builder(side,
save_id, gameboard_.teams_, level_, *gameboard_.map_, gameboard_.units_, gamestate_.replay_start());
save_id, gameboard_.teams_, level_, *gameboard_.map_, gameboard_.units_, saved_game_.replay_start());
++team_num;
gamedata_.build_team_stage_one(tb_ptr);
team_builders.push_back(tb_ptr);
Expand Down Expand Up @@ -264,7 +264,7 @@ void play_controller::init(CVideo& video){
loadscreen::start_stage("build terrain");
gui_.reset(new game_display(gameboard_, video, whiteboard_manager_, tod_manager_, theme_cfg, level_));
if (!gui_->video().faked()) {
if (gamestate_.mp_settings().mp_countdown)
if (saved_game_.mp_settings().mp_countdown)
gui_->get_theme().modify_label("time-icon", _ ("time left for current turn"));
else
gui_->get_theme().modify_label("time-icon", _ ("current local time"));
Expand Down Expand Up @@ -417,7 +417,7 @@ void play_controller::status_table(){
void play_controller::save_game(){
if(save_blocker::try_block()) {
save_blocker::save_unblocker unblocker;
savegame::ingame_savegame save(gamestate_, *gui_, to_config(), preferences::save_compression_format());
savegame::ingame_savegame save(saved_game_, *gui_, to_config(), preferences::save_compression_format());
save.save_game_interactive(gui_->video(), "", gui::OK_CANCEL);
} else {
save_blocker::on_unblock(this,&play_controller::save_game);
Expand All @@ -427,7 +427,7 @@ void play_controller::save_game(){
void play_controller::save_replay(){
if(save_blocker::try_block()) {
save_blocker::save_unblocker unblocker;
savegame::replay_savegame save(gamestate_, preferences::save_compression_format());
savegame::replay_savegame save(saved_game_, preferences::save_compression_format());
save.save_game_interactive(gui_->video(), "", gui::OK_CANCEL);
} else {
save_blocker::on_unblock(this,&play_controller::save_replay);
Expand All @@ -444,7 +444,7 @@ void play_controller::save_map(){
}

void play_controller::load_game(){
savegame::loadgame load(*gui_, game_config_, gamestate_);
savegame::loadgame load(*gui_, game_config_, saved_game_);
load.load_game();
}

Expand Down Expand Up @@ -584,7 +584,7 @@ void play_controller::fire_start(bool execute){
} else {
it_is_a_new_turn_ = false;
}
if( gamestate_.classification().random_mode != "" && (network::nconnections() != 0))
if( saved_game_.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.");
gui_->add_chat_message(
Expand Down Expand Up @@ -785,7 +785,7 @@ config play_controller::to_config() const

gamedata_.write_snapshot(cfg);

cfg.merge_attributes(gamestate_.classification().to_config());
cfg.merge_attributes(saved_game_.classification().to_config());
return cfg;
}

Expand Down Expand Up @@ -1189,15 +1189,15 @@ void play_controller::expand_autosaves(std::vector<std::string>& items)
std::vector<std::string> newitems;
std::vector<std::string> newsaves;
for (unsigned int turn = this->turn(); turn != 0; turn--) {
std::string name = gamestate_.classification().label + "-" + _("Auto-Save") + lexical_cast<std::string>(turn);
std::string name = saved_game_.classification().label + "-" + _("Auto-Save") + lexical_cast<std::string>(turn);
if (savegame::save_game_exists(name, comp_format)) {
newsaves.push_back(
name + compression::format_extension(comp_format));
newitems.push_back(_("Back to Turn ") + lexical_cast<std::string>(turn));
}
}

const std::string& start_name = gamestate_.classification().label;
const std::string& start_name = saved_game_.classification().label;
if(savegame::save_game_exists(start_name, comp_format)) {
newsaves.push_back(
start_name + compression::format_extension(comp_format));
Expand Down Expand Up @@ -1485,7 +1485,7 @@ void play_controller::process_oos(const std::string& msg) const
message << _("The game is out of sync. It might not make much sense to continue. Do you want to save your game?");
message << "\n\n" << _("Error details:") << "\n\n" << msg;

savegame::oos_savegame save(gamestate_, *gui_, to_config());
savegame::oos_savegame save(saved_game_, *gui_, to_config());
save.save_game_interactive(gui_->video(), message.str(), gui::YES_NO); // can throw end_level_exception
}

Expand Down Expand Up @@ -1520,14 +1520,14 @@ void play_controller::toggle_accelerated_speed()

void play_controller::do_autosave()
{
savegame::autosave_savegame save(gamestate_, *gui_, to_config(), preferences::save_compression_format());
savegame::autosave_savegame save(saved_game_, *gui_, to_config(), preferences::save_compression_format());
save.autosave(false, preferences::autosavemax(), preferences::INFINITE_AUTO_SAVES);
}


void play_controller::do_consolesave(const std::string& filename)
{
savegame::ingame_savegame save(gamestate_, *gui_,
savegame::ingame_savegame save(saved_game_, *gui_,
to_config(), preferences::save_compression_format());
save.save_game_automatic(gui_->video(), true, filename);
}
Expand Down
2 changes: 1 addition & 1 deletion src/play_controller.hpp
Expand Up @@ -240,7 +240,7 @@ class play_controller : public controller_base, public events::observer, public
boost::scoped_ptr<game_display> gui_;
const statistics::scenario_context statistics_context_;
const config& level_;
saved_game& gamestate_;
saved_game& saved_game_;
game_data gamedata_;
/// undo_stack_ is never NULL. It is implemented as a pointer so that
/// undo_list can be an incomplete type at this point (which reduces the
Expand Down
18 changes: 9 additions & 9 deletions src/playmp_controller.cpp
Expand Up @@ -224,7 +224,7 @@ possible_end_play_signal playmp_controller::play_human_turn(){
HANDLE_END_PLAY_SIGNAL( play_slice() );
HANDLE_END_PLAY_SIGNAL( check_end_level() );

if (!linger_ && (current_team().countdown_time() > 0) && gamestate_.mp_settings().mp_countdown) {
if (!linger_ && (current_team().countdown_time() > 0) && saved_game_.mp_settings().mp_countdown) {
SDL_Delay(1);
const int ticks = SDL_GetTicks();
int new_time = current_team().countdown_time()-std::max<int>(1,(ticks - cur_ticks));
Expand All @@ -240,8 +240,8 @@ possible_end_play_signal playmp_controller::play_human_turn(){
} else {
// Clock time ended
// If no turn bonus or action bonus -> defeat
const int action_increment = gamestate_.mp_settings().mp_countdown_action_bonus;
if ( (gamestate_.mp_settings().mp_countdown_turn_bonus == 0 )
const int action_increment = saved_game_.mp_settings().mp_countdown_action_bonus;
if ( (saved_game_.mp_settings().mp_countdown_turn_bonus == 0 )
&& (action_increment == 0 || current_team().action_bonus_count() == 0)) {
// Not possible to end level in MP with throw end_level_exception(DEFEAT);
// because remote players only notice network disconnection
Expand Down Expand Up @@ -325,7 +325,7 @@ void playmp_controller::linger()

// this is actually for after linger mode is over -- we don't want to
// stay stuck in linger state when the *next* scenario is over.
set_completion setter(gamestate_,"running");
set_completion setter(saved_game_,"running");
// End all unit moves
gameboard_.set_all_units_user_end_turn();
//current_team().set_countdown_time(0);
Expand Down Expand Up @@ -410,10 +410,10 @@ void playmp_controller::wait_for_upload()
}

void playmp_controller::after_human_turn(){
if ( gamestate_.mp_settings().mp_countdown ){
const int action_increment = gamestate_.mp_settings().mp_countdown_action_bonus;
const int maxtime = gamestate_.mp_settings().mp_countdown_reservoir_time;
int secs = (current_team().countdown_time() / 1000) + gamestate_.mp_settings().mp_countdown_turn_bonus;
if ( saved_game_.mp_settings().mp_countdown ){
const int action_increment = saved_game_.mp_settings().mp_countdown_action_bonus;
const int maxtime = saved_game_.mp_settings().mp_countdown_reservoir_time;
int secs = (current_team().countdown_time() / 1000) + saved_game_.mp_settings().mp_countdown_turn_bonus;
secs += action_increment * current_team().action_bonus_count();
current_team().set_action_bonus_count(0);
secs = (secs > maxtime) ? maxtime : secs;
Expand Down Expand Up @@ -520,7 +520,7 @@ void playmp_controller::process_oos(const std::string& err_msg) const {
temp_buf << " \n";
}

savegame::oos_savegame save(gamestate_, *gui_, to_config());
savegame::oos_savegame save(saved_game_, *gui_, to_config());
save.save_game_interactive(resources::screen->video(), temp_buf.str(), gui::YES_NO);
}

Expand Down
33 changes: 16 additions & 17 deletions src/playsingle_controller.cpp
Expand Up @@ -345,9 +345,8 @@ void playsingle_controller::report_victory(

possible_end_play_signal playsingle_controller::play_scenario_init(end_level_data & /*eld*/, bool & past_prestart) {
// At the beginning of the scenario, save a snapshot as replay_start
if(gamestate_.replay_start().empty())
{
gamestate_.replay_start() = to_config();
if(saved_game_.replay_start().empty()){
saved_game_.replay_start() = to_config();
}
HANDLE_END_PLAY_SIGNAL( fire_preload() );

Expand Down Expand Up @@ -398,8 +397,8 @@ possible_end_play_signal playsingle_controller::play_scenario_main_loop(end_leve
// Initialize countdown clock.
std::vector<team>::const_iterator t;
for(t = gameboard_.teams().begin(); t != gameboard_.teams().end(); ++t) {
if (gamestate_.mp_settings().mp_countdown && !loading_game_ ){
t->set_countdown_time(1000 * gamestate_.mp_settings().mp_countdown_init_time);
if (saved_game_.mp_settings().mp_countdown && !loading_game_ ){
t->set_countdown_time(1000 * saved_game_.mp_settings().mp_countdown_init_time);
}
}

Expand Down Expand Up @@ -500,7 +499,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
if (gameboard_.teams().empty())
{
//store persistent teams
gamestate_.set_snapshot(config());
saved_game_.set_snapshot(config());

return VICTORY; // this is probably only a story scenario, i.e. has its endlevel in the prestart event
}
Expand All @@ -510,15 +509,15 @@ LEVEL_RESULT playsingle_controller::play_scenario(
}
if (end_level_result == DEFEAT || end_level_result == VICTORY)
{
gamestate_.classification().completion = (end_level_result == VICTORY) ? "victory" : "defeat";
saved_game_.classification().completion = (end_level_result == VICTORY) ? "victory" : "defeat";
// If we're a player, and the result is victory/defeat, then send
// a message to notify the server of the reason for the game ending.
if (!obs) {
config cfg;
config& info = cfg.add_child("info");
info["type"] = "termination";
info["condition"] = "game over";
info["result"] = gamestate_.classification().completion;
info["result"] = saved_game_.classification().completion;
network::send_data(cfg, 0);
} else {
gui2::show_transient_message(gui_->video(),_("Game Over"),
Expand All @@ -532,7 +531,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
}
else if (end_level_result == DEFEAT)
{
gamestate_.classification().completion = "defeat";
saved_game_.classification().completion = "defeat";
game_events::fire("defeat");

if (!obs) {
Expand All @@ -548,7 +547,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
}
else if (end_level_result == VICTORY)
{
gamestate_.classification().completion =
saved_game_.classification().completion =
!end_level.transient.linger_mode ? "running" : "victory";
game_events::fire("victory");

Expand All @@ -572,7 +571,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
LOG_NG << "Add units that survived the scenario to the recall list.\n";
gameboard_.all_survivors_to_recall();

gamestate_.remove_snapshot();
saved_game_.remove_snapshot();
if(!is_observer()) {
persist_.end_transaction();
}
Expand All @@ -583,7 +582,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
{
LOG_NG << "resuming from loaded linger state...\n";
//as carryover information is stored in the snapshot, we have to re-store it after loading a linger state
gamestate_.set_snapshot(config());
saved_game_.set_snapshot(config());
if(!is_observer()) {
persist_.end_transaction();
}
Expand All @@ -598,7 +597,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
// Loading a new game is effectively a quit.
//
if ( game::load_game_exception::game != "" ) {
gamestate_ = saved_game();
saved_game_ = saved_game();
}
throw;
} catch(network::error& e) {
Expand All @@ -608,7 +607,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
disconnect = true;
}

savegame::ingame_savegame save(gamestate_, *gui_, to_config(), preferences::save_compression_format());
savegame::ingame_savegame save(saved_game_, *gui_, to_config(), preferences::save_compression_format());
save.save_game_interactive(gui_->video(), _("A network disconnection has occurred, and the game cannot continue. Do you want to save the game?"), gui::YES_NO);
if(disconnect) {
throw network::error();
Expand Down Expand Up @@ -831,7 +830,7 @@ possible_end_play_signal playsingle_controller::before_human_turn()
HANDLE_END_PLAY_SIGNAL( ai::manager::raise_turn_started() ); //This line throws exception from here: https://github.com/wesnoth/wesnoth/blob/ac96a2b91b3276e20b682210617cf87d1e0d366a/src/playsingle_controller.cpp#L954

if(do_autosaves_ && level_result_ == NONE) {
savegame::autosave_savegame save(gamestate_, *gui_, to_config(), preferences::save_compression_format());
savegame::autosave_savegame save(saved_game_, *gui_, to_config(), preferences::save_compression_format());
save.autosave(game_config::disable_autosave, preferences::autosavemax(), preferences::INFINITE_AUTO_SAVES);
}

Expand Down Expand Up @@ -884,7 +883,7 @@ void playsingle_controller::linger()
// this is actually for after linger mode is over -- we don't
// want to stay stuck in linger state when the *next* scenario
// is over.
set_completion setter(gamestate_,"running");
set_completion setter(saved_game_,"running");

// change the end-turn button text to its alternate label
gui_->get_theme().refresh_title2("button-endturn", "title2");
Expand All @@ -907,7 +906,7 @@ void playsingle_controller::linger()
} catch(const game::load_game_exception &) {
// Loading a new game is effectively a quit.
if ( game::load_game_exception::game != "" ) {
gamestate_ = saved_game();
saved_game_ = saved_game();
}
throw;
}
Expand Down
6 changes: 3 additions & 3 deletions src/replay_controller.cpp
Expand Up @@ -110,7 +110,7 @@ replay_controller::replay_controller(const config& level,
saved_game& state_of_game, const int ticks,
const config& game_config, CVideo& video) :
play_controller(level, state_of_game, ticks, game_config, video, false),
gamestate_start_(gamestate_),
saved_game_start_(saved_game_),
gameboard_start_(gameboard_),
tod_manager_start_(level),
current_turn_(1),
Expand Down Expand Up @@ -302,7 +302,7 @@ void replay_controller::reset_replay()
tod_manager_= tod_manager_start_;
recorder.start_replay();
recorder.set_skip(false);
gamestate_ = gamestate_start_;
saved_game_ = saved_game_start_;
gameboard_ = gameboard_start_;
gui_->change_display_context(&gameboard_); //this doesn't change the pointer value, but it triggers the gui to update the internal terrain builder object,
//idk what the consequences of not doing that are, but its probably a good idea to do it, esp. if layout
Expand Down Expand Up @@ -405,7 +405,7 @@ void replay_controller::process_oos(const std::string& msg) const
if (non_interactive()) {
throw game::game_error(message.str()); //throw end_level_exception(DEFEAT);
} else {
savegame::oos_savegame save(gamestate_, *gui_, to_config());
savegame::oos_savegame save(saved_game_, *gui_, to_config());
save.save_game_interactive(resources::screen->video(), message.str(), gui::YES_NO); // can throw end_level_exception
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/replay_controller.hpp
Expand Up @@ -86,7 +86,7 @@ class replay_controller : public play_controller
play_turn_button() && play_side_button();
}

saved_game gamestate_start_;
saved_game saved_game_start_;
game_board gameboard_start_;
tod_manager tod_manager_start_;

Expand Down

0 comments on commit bd9fb69

Please sign in to comment.