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"); manager::read_save_file(filename_, load_config_, &error_log); copy_era(load_config_); gamestate_ = game_state(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 != "multiplayer") { gui2::show_message(gui_.video(), "", _("This is not a multiplayer save")); throw load_game_cancelled_exception(); } check_version_compatibility(); }
bool loadgame::load_multiplayer_game() { show_dialog(false, false); if (filename_.empty()) return false; 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_.set_data(load_config_); } if(!error_log.empty()) { gui2::show_error_message(gui_.video(), _("The file you have tried to load is corrupt: '") + error_log); return false; } if(gamestate_.classification().campaign_type != game_classification::CAMPAIGN_TYPE::MULTIPLAYER) { gui2::show_transient_error_message(gui_.video(), _("This is not a multiplayer save.")); return false; } return check_version_compatibility(); }
int QuestProperties::l_quest(lua_State* l) { // Retrieve the quest properties from the table parameter. luaL_checktype(l, 1, LUA_TTABLE); const std::string& solarus_required_version = LuaTools::opt_string_field(l, 1, "solarus_version", ""); check_version_compatibility(solarus_required_version); const std::string& quest_write_dir = LuaTools::opt_string_field(l, 1, "write_dir", ""); const std::string& title_bar = LuaTools::opt_string_field(l, 1, "title_bar", ""); const std::string& normal_quest_size_string = LuaTools::opt_string_field(l, 1, "normal_quest_size", "320x240"); const std::string& min_quest_size_string = LuaTools::opt_string_field(l, 1, "min_quest_size", normal_quest_size_string); const std::string& max_quest_size_string = LuaTools::opt_string_field(l, 1, "max_quest_size", normal_quest_size_string); FileTools::set_quest_write_dir(quest_write_dir); if (!title_bar.empty()) { Video::set_window_title(title_bar); } Rectangle normal_quest_size, min_quest_size, max_quest_size; bool success = Video::parse_size(normal_quest_size_string, normal_quest_size); if (!success) { LuaTools::arg_error(l, 1, std::string( "Bad field 'normal_quest_size' (not a valid size string: '") + normal_quest_size_string + "')"); } success = Video::parse_size(min_quest_size_string, min_quest_size); if (!success) { LuaTools::arg_error(l, 1, std::string( "Bad field 'min_quest_size' (not a valid size string: '") + min_quest_size_string + "')"); } success = Video::parse_size(max_quest_size_string, max_quest_size); if (!success) { LuaTools::arg_error(l, 1, std::string( "Bad field 'max_quest_size' (not a valid size string: '") + max_quest_size_string + "')"); } if (normal_quest_size.get_width() < min_quest_size.get_width() || normal_quest_size.get_height() < min_quest_size.get_height() || normal_quest_size.get_width() > max_quest_size.get_width() || normal_quest_size.get_height() > max_quest_size.get_height()) { LuaTools::arg_error(l, 1, "Invalid range of quest sizes"); } Video::set_quest_size_range( normal_quest_size, min_quest_size, max_quest_size); return 0; }
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::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(); }
/** * \brief Reads the quest properties file quest.dat and applies its settings. */ void MainLoop::load_quest_properties() { // Read the quest properties file. const std::string file_name("quest.dat"); lua_State* l = luaL_newstate(); const std::string& buffer = QuestFiles::data_file_read(file_name); int load_result = luaL_loadbuffer(l, buffer.data(), buffer.size(), file_name.c_str()); if (load_result != 0) { // Syntax error in quest.dat. // Loading quest.dat failed. // There may be a syntax error, or this is a quest for Solarus 0.9. // There was no version number at that time. if (std::string(buffer).find("[info]")) { // Quest format of Solarus 0.9. Debug::die(std::string("This quest is made for Solarus 0.9 but you are running Solarus ") + SOLARUS_VERSION); } else { Debug::die(std::string("Failed to load quest.dat: ") + lua_tostring(l, -1)); } } QuestProperties properties; properties.import_from_lua(l); lua_close(l); check_version_compatibility(properties.get_solarus_version()); QuestFiles::set_quest_write_dir(properties.get_quest_write_dir()); if (!properties.get_title_bar().empty()) { Video::set_window_title(properties.get_title_bar()); } Video::set_quest_size_range( properties.get_normal_quest_size(), properties.get_min_quest_size(), properties.get_max_quest_size() ); }
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(); }
/** * @brief Reads the quest properties data file quest.lua and applies * these properties to the quest. */ void QuestProperties::load() { // Read the quest properties file. const std::string& file_name = "quest.dat"; lua_State* l = luaL_newstate(); size_t size; char* buffer; FileTools::data_file_open_buffer(file_name, &buffer, &size); luaL_loadbuffer(l, buffer, size, file_name.c_str()); FileTools::data_file_close_buffer(buffer); lua_register(l, "quest", l_quest); if (lua_pcall(l, 0, 0, 0) != 0) { Debug::die(StringConcat() << "Error: failed to load quest.dat: " << lua_tostring(l, -1)); lua_pop(l, 1); } check_version_compatibility(solarus_required_version); lua_close(l); }
/** * \brief Reads the quest properties file quest.dat and applies its settings. */ void MainLoop::load_quest_properties() { const QuestProperties& properties = CurrentQuest::get_properties(); check_version_compatibility(properties.get_solarus_version()); const std::string& title = properties.get_title(); const std::string& quest_version = properties.get_quest_version(); if (!title.empty()) { std::string window_title = title; if (!quest_version.empty()) { window_title += " " + quest_version; } window_title += std::string(" - Solarus ") + SOLARUS_VERSION; Video::set_window_title(window_title); } Video::set_quest_size_range( properties.get_normal_quest_size(), properties.get_min_quest_size(), properties.get_max_quest_size() ); }