void loadgame::load_multiplayer_game() { show_dialog(false, false); if (filename_.empty()) throw load_game_cancelled_exception(); std::string error_log; { cursor::setter cur(cursor::WAIT); log_scope("load_game"); read_save_file(filename_, load_config_, &error_log); copy_era(load_config_); gamestate_ = saved_game(load_config_); } if(!error_log.empty()) { gui2::show_error_message(gui_.video(), _("The file you have tried to load is corrupt: '") + error_log); throw load_game_cancelled_exception(); } if(gamestate_.classification().campaign_type != game_classification::MULTIPLAYER) { gui2::show_transient_error_message(gui_.video(), _("This is not a multiplayer save.")); throw load_game_cancelled_exception(); } check_version_compatibility(); }
void loadgame::check_version_compatibility() { if (gamestate_.classification().version == game_config::version) { return; } const version_info save_version = gamestate_.classification().version; const version_info &wesnoth_version = game_config::wesnoth_version; // Even minor version numbers indicate stable releases which are // compatible with each other. if (wesnoth_version.minor_version() % 2 == 0 && wesnoth_version.major_version() == save_version.major_version() && wesnoth_version.minor_version() == save_version.minor_version()) { return; } // Do not load if too old. If either the savegame or the current // game has the version 'test', load. This 'test' version is never // supposed to occur, except when Soliton is testing MP servers. if (save_version < game_config::min_savegame_version && save_version != game_config::test_version && wesnoth_version != game_config::test_version) { gui2::show_message(gui_.video(), "", _("This save is from a version too old to be loaded.")); throw load_game_cancelled_exception(); } const int res = gui2::show_message(gui_.video(), "", _("This save is from a different version of the game. Do you want to try to load it?"), gui2::tmessage::yes_no_buttons); if(res == gui2::twindow::CANCEL) { throw load_game_cancelled_exception(); } }
void loadgame::load_multiplayer_game(hero_map& heros, hero_map& heros_start) { show_dialog(false, false); if (filename_.empty()) throw load_game_cancelled_exception(); std::string error_log; { cursor::setter cur(cursor::WAIT); log_scope("load_game"); manager::read_save_file(filename_, NULL, &load_config_, &heros_start, &replay_data_, &heros, &error_log); copy_era(load_config_); gamestate_ = game_state(load_config_, replay_data_); } if(!error_log.empty()) { gui2::show_error_message(gui_.video(), _("The file you have tried to load is corrupt: '") + error_log); throw load_game_cancelled_exception(); } if(gamestate_.classification().campaign_type != "multiplayer") { gui2::show_message(gui_.video(), "", _("This is not a multiplayer save")); throw load_game_cancelled_exception(); } check_version_compatibility(); }
void loadgame::check_version_compatibility() { if (gamestate_.classification().version == game_config::version) { return; } const version_info save_version = gamestate_.classification().version; const version_info &wesnoth_version = game_config::wesnoth_version; // If the version isn't good, it probably isn't a compatible stable one, // and the following comparisons would throw. if (!save_version.good()) { const std::string message = _("The save has corrupt version information ($version_number|) and cannot be loaded."); utils::string_map symbols; symbols["version_number"] = gamestate_.classification().version; gui2::show_error_message(gui_.video(), utils::interpolate_variables_into_string(message, &symbols)); throw load_game_cancelled_exception(); } // Even minor version numbers indicate stable releases which are // compatible with each other. if (wesnoth_version.minor_version() % 2 == 0 && wesnoth_version.major_version() == save_version.major_version() && wesnoth_version.minor_version() == save_version.minor_version()) { return; } // Do not load if too old. If either the savegame or the current // game has the version 'test', load. This 'test' version is never // supposed to occur, except when Soliton is testing MP servers. if (save_version < game_config::min_savegame_version && save_version != game_config::test_version && wesnoth_version != game_config::test_version) { const std::string message = _("This save is from an old, unsupported version ($version_number|) and cannot be loaded."); utils::string_map symbols; symbols["version_number"] = save_version.str(); gui2::show_error_message(gui_.video(), utils::interpolate_variables_into_string(message, &symbols)); throw load_game_cancelled_exception(); } int res = gui2::twindow::OK; if(preferences::confirm_load_save_from_different_version()) { const std::string message = _("This save is from a different version of the game ($version_number|). Do you wish to try to load it?"); utils::string_map symbols; symbols["version_number"] = save_version.str(); res = gui2::show_message(gui_.video(), _("Load Game"), utils::interpolate_variables_into_string(message, &symbols), gui2::tmessage::yes_no_buttons); } if(res == gui2::twindow::CANCEL) { throw load_game_cancelled_exception(); } }
void loadgame::load_game( const std::string& filename , const bool show_replay , const bool cancel_orders , const bool select_difficulty , const std::string& difficulty) { filename_ = filename; difficulty_ = difficulty; select_difficulty_ = select_difficulty; if (filename_.empty()){ show_dialog(show_replay, cancel_orders); } else{ show_replay_ = show_replay; cancel_orders_ = cancel_orders; } if (filename_.empty()) throw load_game_cancelled_exception(); if (select_difficulty_) show_difficulty_dialog(); std::string error_log; read_save_file(filename_, load_config_, &error_log); convert_old_saves(load_config_); if(!error_log.empty()) { try { gui2::show_error_message(gui_.video(), _("Warning: The file you have tried to load is corrupt. Loading anyway.\n") + error_log); } catch (utf8::invalid_utf8_exception&) { gui2::show_error_message(gui_.video(), _("Warning: The file you have tried to load is corrupt. Loading anyway.\n") + std::string("(UTF-8 ERROR)")); } } if (!difficulty_.empty()){ load_config_["difficulty"] = difficulty_; } #if 0 gamestate_.classification().campaign_define = load_config_["campaign_define"].str(); gamestate_.classification().campaign_type = lexical_cast_default<game_classification::CAMPAIGN_TYPE> (load_config_["campaign_type"].str(), game_classification::SCENARIO); gamestate_.classification().campaign_xtra_defines = utils::split(load_config_["campaign_extra_defines"]); gamestate_.classification().version = load_config_["version"].str(); gamestate_.classification().difficulty = load_config_["difficulty"].str(); #else // read classification to for loading the game_config config object. gamestate_.classification() = game_classification(load_config_); #endif check_version_compatibility(); }
void loadgame::show_difficulty_dialog() { create_save_info creator; save_info info = creator(filename_); const config& cfg_summary = info.summary(); if ( cfg_summary["corrupt"].to_bool() || (cfg_summary["replay"].to_bool() && !cfg_summary["snapshot"].to_bool(true)) || (!cfg_summary["turn"].empty()) ) return; const config::const_child_itors &campaigns = game_config_.child_range("campaign"); std::vector<std::string> difficulty_descriptions; std::vector<std::string> difficulties; BOOST_FOREACH(const config &campaign, campaigns) { if (campaign["id"] == cfg_summary["campaign"]) { difficulty_descriptions = utils::split(campaign["difficulty_descriptions"], ';'); difficulties = utils::split(campaign["difficulties"], ','); break; } } if (difficulty_descriptions.empty()) return; #if 0 int default_difficulty = -1; for (size_t i = 0; i < difficulties.size(); i++) { if (difficulties[i] == cfg_summary["difficulty"]) { default_difficulty = i; break; } } #endif gui2::tcampaign_difficulty difficulty_dlg(difficulty_descriptions); difficulty_dlg.show(gui_.video()); if (difficulty_dlg.get_retval() != gui2::twindow::OK) { throw load_game_cancelled_exception(); } difficulty_ = difficulties[difficulty_dlg.selected_index()]; }
void loadgame::load_game( const std::string& filename , const bool show_replay , const bool cancel_orders) { filename_ = filename; if (filename_.empty()){ show_dialog(show_replay, cancel_orders); } else{ show_replay_ = show_replay; cancel_orders_ = cancel_orders; } if (filename_.empty()) throw load_game_cancelled_exception(); std::string error_log; manager::read_save_file(filename_, load_config_, &error_log); if(!error_log.empty()) { try { gui2::show_error_message(gui_.video(), _("Warning: The file you have tried to load is corrupt. Loading anyway.\n") + error_log); } catch (utils::invalid_utf8_exception&) { gui2::show_error_message(gui_.video(), _("Warning: The file you have tried to load is corrupt. Loading anyway.\n") + std::string("(UTF-8 ERROR)")); } } gamestate_.classification().difficulty = load_config_["difficulty"].str(); gamestate_.classification().campaign_define = load_config_["campaign_define"].str(); gamestate_.classification().campaign_type = load_config_["campaign_type"].str(); gamestate_.classification().campaign_xtra_defines = utils::split(load_config_["campaign_extra_defines"]); gamestate_.classification().version = load_config_["version"].str(); check_version_compatibility(); }
void loadgame::load_game(std::string& filename, bool show_replay, bool allow_network, hero_map& heros, hero_map* heros_start) { filename_ = filename; if (filename_.empty()){ show_dialog(show_replay, allow_network); } else { show_replay_ = show_replay; } if (filename_.empty()) throw load_game_cancelled_exception(); std::string error_log; manager::read_save_file(filename_, NULL, &load_config_, heros_start, &replay_data_, &heros, &error_log); if(!error_log.empty()) { try { gui2::show_error_message(gui_.video(), _("Warning: The file you have tried to load is corrupt. Loading anyway.\n") + error_log); } catch (utils::invalid_utf8_exception&) { gui2::show_error_message(gui_.video(), _("Warning: The file you have tried to load is corrupt. Loading anyway.\n") + std::string("(UTF-8 ERROR)")); } } gamestate_.classification().create = load_config_["create"].to_long(); gamestate_.classification().duration = load_config_["duration"].to_int(); gamestate_.classification().hash = load_config_["hash"].to_int(); gamestate_.classification().campaign_define = load_config_["campaign_define"].str(); gamestate_.classification().campaign = load_config_["campaign"].str(); gamestate_.classification().campaign_type = load_config_["campaign_type"].str(); gamestate_.classification().version = load_config_["version"].str(); check_version_compatibility(); }