Skip to content

Commit

Permalink
don't do auto delete save on defeat in mp campaigns
Browse files Browse the repository at this point in the history
We now use 'end_level.proceed_to_next_level' instead of 'res == VICTORY
|| (game_type == game_classification::MULTIPLAYER && res == DEFEAT'  to
decide whether we do auto save deletion. The intention is to adress 'if
MP campaigns ever work again, we might need to change this test'
as it was commented in the code

We also refactor playsingle/mp_scenario to not do
playcontroller.update_savegame_snapshot(); if res == DEFEAT since it is
not neeeded in this case.
  • Loading branch information
gfgtdf committed Mar 1, 2015
1 parent 8b83504 commit 180acb0
Showing 1 changed file with 47 additions and 52 deletions.
99 changes: 47 additions & 52 deletions src/game_initialization/playcampaign.cpp
Expand Up @@ -190,26 +190,26 @@ static LEVEL_RESULT playsingle_scenario(const config& game_config,

end_level = playcontroller.get_end_level_data_const();

if (res != QUIT)
if (res == QUIT)
{
//if we are loading from linger mode then we already did this.
if(res != SKIP_TO_LINGER)
{
show_carryover_message(state_of_game, playcontroller, disp, end_level, res);
}
if(!disp.video().faked())
{
try {
playcontroller.maybe_linger();
} catch(end_level_exception& e) {
if (e.result == QUIT) {
return QUIT;
}
return QUIT;
}
//if we are loading from linger mode then we already did this.
if(res != SKIP_TO_LINGER)
{
show_carryover_message(state_of_game, playcontroller, disp, end_level, res);
}
if(!disp.video().faked())
{
try {
playcontroller.maybe_linger();
} catch(end_level_exception& e) {
if (e.result == QUIT) {
return QUIT;
}
}
}
state_of_game.set_snapshot(playcontroller.to_config());

return res;
}

Expand All @@ -232,25 +232,25 @@ static LEVEL_RESULT playmp_scenario(const config& game_config,
if (io_type == IO_CLIENT && playcontroller.is_host())
io_type = IO_SERVER;

if (res != QUIT)
if (res == QUIT)
{
if(res != OBSERVER_END && res != SKIP_TO_LINGER)
{
//We need to call this before linger because it prints the defeated/victory message.
//(we want to see that message before entering the linger mode)
show_carryover_message(state_of_game, playcontroller, disp, end_level, res);
}
if(!disp.video().faked())
{
try {
playcontroller.maybe_linger();
} catch(end_level_exception& e) {
if (e.result == QUIT) {
return QUIT;
}
return QUIT;
}
if(res != OBSERVER_END && res != SKIP_TO_LINGER)
{
//We need to call this before linger because it prints the defeated/victory message.
//(we want to see that message before entering the linger mode)
show_carryover_message(state_of_game, playcontroller, disp, end_level, res);
}
if(!disp.video().faked())
{
try {
playcontroller.maybe_linger();
} catch(end_level_exception& e) {
if (e.result == QUIT) {
return QUIT;
}
}

}
playcontroller.update_savegame_snapshot();
return res;
Expand Down Expand Up @@ -317,40 +317,35 @@ LEVEL_RESULT play_game(game_display& disp, saved_game& gamestate,
if (is_unit_test) {
return res;
}
//in this case we might have skipped state.set_snapshot which means we cannot do gamestate.convert_to_start_save();
if(res == QUIT)
{
if(res == QUIT) {
return res;
}

// Save-management options fire on game end.
// This means: (a) we have a victory, or
// (b) we're multiplayer live, in which
// case defeat is also game end. Someday,
// if MP campaigns ever work again, we might
// need to change this test.
if (res == VICTORY || (game_type == game_classification::MULTIPLAYER && res == DEFEAT)) {
if (preferences::delete_saves())
savegame::clean_saves(gamestate.classification().label);

if (preferences::save_replays() && end_level.replay_save) {
savegame::replay_savegame save(gamestate, preferences::save_compression_format());
save.save_game_automatic(disp.video(), true);
}
// proceed_to_next_level <=> 'any human side recieved victory'
// If 'any human side recieved victory' we do the Save-management options
// Otherwise we are done now
if(!end_level.proceed_to_next_level) {
return res;
}

if (preferences::delete_saves()) {
savegame::clean_saves(gamestate.classification().label);
}
if (preferences::save_replays() && end_level.replay_save) {
savegame::replay_savegame save(gamestate, preferences::save_compression_format());
save.save_game_automatic(disp.video(), true);
}

gamestate.convert_to_start_save();
recorder.clear();

// On DEFEAT, QUIT, or OBSERVER_END, we're done now

//If there is no next scenario we're done now.
if(!end_level.proceed_to_next_level || gamestate.get_scenario_id().empty())
if(gamestate.get_scenario_id().empty())
{
return res;
}
else if(res == OBSERVER_END)
{
// TODO: does it make sense to ask this question if we are currently the host?
const int dlg_res = gui2::show_message(disp.video(), _("Game Over"),
_("This scenario has ended. Do you want to continue the campaign?"),
gui2::tmessage::yes_no_buttons);
Expand Down

0 comments on commit 180acb0

Please sign in to comment.