void game_launcher::play_replay() { assert(!load_data_); try { campaign_controller ccontroller(video(), state_, game_config_manager::get()->game_config(), game_config_manager::get()->terrain_types()); ccontroller.play_replay(); } catch (savegame::load_game_exception &e) { load_data_.reset(new savegame::load_game_metadata(std::move(e.data_))); //this will make it so next time through the title screen loop, this game is loaded } catch(wml_exception& e) { e.show(video()); } }
void game_launcher::play_replay() { try { campaign_controller ccontroller(video(), state_, game_config_manager::get()->game_config(), game_config_manager::get()->terrain_types()); ccontroller.play_replay(); clear_loaded_game(); } catch (game::load_game_exception &) { //this will make it so next time through the title screen loop, this game is loaded } catch(twml_exception& e) { e.show(video()); } }
void game_launcher::launch_game(RELOAD_GAME_DATA reload) { assert(!load_data_); if(play_replay_) { play_replay(); return; } gui2::dialogs::loading_screen::display(video(), [this, reload]() { gui2::dialogs::loading_screen::progress("load data"); if(reload == RELOAD_DATA) { try { game_config_manager::get()-> load_game_config_for_game(state_.classification()); } catch(config::error&) { return; } } }); try { campaign_controller ccontroller(video(), state_, game_config_manager::get()->game_config(), game_config_manager::get()->terrain_types()); LEVEL_RESULT result = ccontroller.play_game(); // don't show The End for multiplayer scenario // change this if MP campaigns are implemented if(result == LEVEL_RESULT::VICTORY && !state_.classification().is_normal_mp_game()) { preferences::add_completed_campaign(state_.classification().campaign, state_.classification().difficulty); the_end(video(), state_.classification().end_text, state_.classification().end_text_duration); if(state_.classification().end_credits) { gui2::dialogs::end_credits::display(video(), state_.classification().campaign); } } } catch (savegame::load_game_exception &e) { load_data_.reset(new savegame::load_game_metadata(std::move(e.data_))); //this will make it so next time through the title screen loop, this game is loaded } catch(wml_exception& e) { e.show(video()); } catch(mapgen_exception& e) { gui2::show_error_message(video(), _("Map generator error: ") + e.message); } }
void game_launcher::launch_game(RELOAD_GAME_DATA reload) { if(play_replay_) { play_replay(); return; } gui2::tloadscreen::display(video(), [this, reload]() { gui2::tloadscreen::progress("load data"); if(reload == RELOAD_DATA) { try { game_config_manager::get()-> load_game_config_for_game(state_.classification()); } catch(config::error&) { return; } } }); try { campaign_controller ccontroller(video(), state_, game_config_manager::get()->game_config(), game_config_manager::get()->terrain_types()); LEVEL_RESULT result = ccontroller.play_game(); // don't show The End for multiplayer scenario // change this if MP campaigns are implemented if(result == LEVEL_RESULT::VICTORY && !state_.classification().is_normal_mp_game()) { preferences::add_completed_campaign(state_.classification().campaign, state_.classification().difficulty); the_end(video(), state_.classification().end_text, state_.classification().end_text_duration); if(state_.classification().end_credits) { about::show_about(video(),state_.classification().campaign); } } clear_loaded_game(); } catch (game::load_game_exception &) { //this will make it so next time through the title screen loop, this game is loaded } catch(twml_exception& e) { e.show(video()); } }
bool game_launcher::play_test() { static bool first_time = true; if(!cmdline_opts_.test) { return true; } if(!first_time) return false; first_time = false; state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::TEST; state_.classification().campaign_define = "TEST"; state_.mp_settings().mp_era = "era_default"; state_.mp_settings().show_connect = false; state_.set_carryover_sides_start( config_of("next_scenario", test_scenario_) ); game_config_manager::get()-> load_game_config_for_game(state_.classification()); try { campaign_controller ccontroller(video(), state_, game_config_manager::get()->game_config(), game_config_manager::get()->terrain_types()); ccontroller.play_game(); } catch (savegame::load_game_exception &e) { load_data_.reset(new savegame::load_game_metadata(std::move(e.data_))); return true; } return false; }
// Same as play_test except that we return the results of play_game. int game_launcher::unit_test() { static bool first_time_unit = true; if(!cmdline_opts_.unit_test) { return 0; } if(!first_time_unit) return 0; first_time_unit = false; state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::TEST; state_.classification().campaign_define = "TEST"; state_.set_carryover_sides_start( config_of("next_scenario", test_scenario_) ); game_config_manager::get()-> load_game_config_for_game(state_.classification()); try { campaign_controller ccontroller(video(), state_, game_config_manager::get()->game_config(), game_config_manager::get()->terrain_types(), true); LEVEL_RESULT res = ccontroller.play_game(); if (!(res == LEVEL_RESULT::VICTORY) || lg::broke_strict()) { return 1; } } catch(wml_exception& e) { std::cerr << "Caught WML Exception:" << e.dev_message << std::endl; return 1; } savegame::clean_saves(state_.classification().label); if (cmdline_opts_.noreplaycheck) return 0; //we passed, huzzah! savegame::replay_savegame save(state_, compression::NONE); save.save_game_automatic(video(), false, "unit_test_replay"); //false means don't check for overwrite load_data_.reset(new savegame::load_game_metadata{ "unit_test_replay" , "", true, true, false }); if (!load_game()) { std::cerr << "Failed to load the replay!" << std::endl; return 3; //failed to load replay } try { campaign_controller ccontroller(video(), state_, game_config_manager::get()->game_config(), game_config_manager::get()->terrain_types(), true); LEVEL_RESULT res = ccontroller.play_replay(); if (!(res == LEVEL_RESULT::VICTORY)) { std::cerr << "Observed failure on replay" << std::endl; return 4; } } catch(wml_exception& e) { std::cerr << "WML Exception while playing replay: " << e.dev_message << std::endl; return 4; //failed with an error during the replay } return 0; //we passed, huzzah! }