replays return lvl result, treat OOS as game error in noninteractive

This commit is contained in:
Chris Beck 2014-05-13 18:57:30 -04:00
parent 9db311a441
commit 65250df255
4 changed files with 42 additions and 13 deletions

View file

@ -498,11 +498,11 @@ int game_controller::unit_test()
try {
//LEVEL_RESULT res = play_game(disp(), state_, resources::config_manager->game_config(), IO_NONE, false,false,false,true);
::play_replay(disp(), state_, resources::config_manager->game_config(), video_, true);
/*if (!(res == VICTORY || res == NONE)) {
LEVEL_RESULT res = ::play_replay(disp(), state_, resources::config_manager->game_config(), video_, true);
if (!(res == VICTORY || res == NONE)) {
std::cerr << "Observed failure on replay" << std::endl;
return 4;
}*/
}
/*::play_replay(disp(),state_,resources::config_manager->game_config(),
video_);*/
clear_loaded_game();

View file

@ -206,7 +206,7 @@ static void generate_map(config const*& scenario)
scenario = &new_scenario;
}
void play_replay(display& disp, game_state& gamestate, const config& game_config,
LEVEL_RESULT play_replay(display& disp, game_state& gamestate, const config& game_config,
CVideo& video, bool is_unit_test)
{
std::string type = gamestate.classification().campaign_type;
@ -236,21 +236,44 @@ void play_replay(display& disp, game_state& gamestate, const config& game_config
//if (gamestate.abbrev.empty())
// gamestate.abbrev = (*scenario)["abbrev"];
play_replay_level(game_config, &starting_pos, video, gamestate, is_unit_test);
LEVEL_RESULT res = play_replay_level(game_config, &starting_pos, video, gamestate, is_unit_test);
gamestate.snapshot = config();
recorder.clear();
gamestate.replay_data.clear();
return res;
} catch(game::load_game_failed& e) {
gui2::show_error_message(disp.video(), _("The game could not be loaded: ") + e.message);
if (is_unit_test) {
std::cerr << std::string(_("The game could not be loaded: ")) + " (game::load_game_failed) " + e.message << std::endl;
return DEFEAT;
} else {
gui2::show_error_message(disp.video(), _("The game could not be loaded: ") + e.message);
}
} catch(game::game_error& e) {
gui2::show_error_message(disp.video(), _("Error while playing the game: ") + e.message);
if (is_unit_test) {
std::cerr << std::string(_("Error while playing the game: ")) + " (game::game_error) " + e.message << std::endl;
return DEFEAT;
} else {
gui2::show_error_message(disp.video(), std::string(_("Error while playing the game: ")) + e.message);
}
} catch(incorrect_map_format_error& e) {
gui2::show_error_message(disp.video(), std::string(_("The game map could not be loaded: ")) + e.message);
if (is_unit_test) {
std::cerr << std::string(_("The game map could not be loaded: ")) + " (incorrect_map_format_error) " + e.message << std::endl;
return DEFEAT;
} else {
gui2::show_error_message(disp.video(), std::string(_("The game map could not be loaded: ")) + e.message);
}
} catch(twml_exception& e) {
e.show(disp);
if (is_unit_test) {
std::cerr << std::string("WML Exception: ") + e.user_message << std::endl;
std::cerr << std::string("Dev Message: ") + e.dev_message << std::endl;
return DEFEAT;
} else {
e.show(disp);
}
}
return NONE;
}
static LEVEL_RESULT playsingle_scenario(const config& game_config,

View file

@ -39,7 +39,7 @@ LEVEL_RESULT play_game(game_display& disp, game_state& state,
bool blindfold_replay = false,
bool is_unit_test = false);
void play_replay(display& disp, game_state& state,
LEVEL_RESULT play_replay(display& disp, game_state& state,
const config& game_config, CVideo& video,
bool is_unit_test = false);

View file

@ -357,14 +357,20 @@ void replay_controller::replay_next_side(){
void replay_controller::process_oos(const std::string& msg) const
{
if (game_config::ignore_replay_errors) return;
if (game_config::ignore_replay_errors) {
return;
}
std::stringstream message;
message << _("The replay is corrupt/out of sync. It might not make much sense to continue. Do you want to save the game?");
message << "\n\n" << _("Error details:") << "\n\n" << msg;
savegame::oos_savegame save(to_config());
save.save_game_interactive(resources::screen->video(), message.str(), gui::YES_NO); // can throw end_level_exception
if (non_interactive()) {
throw game::game_error(message.str()); //throw end_level_exception(DEFEAT);
} else {
savegame::oos_savegame save(to_config());
save.save_game_interactive(resources::screen->video(), message.str(), gui::YES_NO); // can throw end_level_exception
}
}
void replay_controller::replay_show_everything(){