本文整理汇总了C++中saved_game::mp_settings方法的典型用法代码示例。如果您正苦于以下问题:C++ saved_game::mp_settings方法的具体用法?C++ saved_game::mp_settings怎么用?C++ saved_game::mp_settings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类saved_game
的用法示例。
在下文中一共展示了saved_game::mp_settings方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: enter_connect_mode
bool enter_connect_mode(game_display& disp, const config& game_config,
saved_game& state, bool local_players_only) {
ng::connect_engine connect_eng(state, true, NULL);
if (state.mp_settings().show_connect) {
mp::ui::result res;
gamelist.clear();
{
mp::connect ui(disp, state.mp_settings().name, game_config, gamechat, gamelist, connect_eng);
mp::run_lobby_loop(disp, ui);
res = ui.get_result();
if (res == mp::ui::PLAY) {
ui.start_game();
}
}
switch (res) {
case mp::ui::PLAY:
return true;
case mp::ui::CREATE:
enter_create_mode(disp, game_config, state, jump_to_campaign_info(false, -1, "", ""), local_players_only);
break;
case mp::ui::QUIT:
default:
return false;
}
return true;
} else {
connect_eng.start_game();
return true;
}
}
示例2: level_to_gamestate
void level_to_gamestate(const config& level, saved_game& state)
{
game_classification::CAMPAIGN_TYPE type = state.classification().campaign_type;
bool show_connect = state.mp_settings().show_connect;
state = saved_game(level);
state.classification().campaign_type = type;
state.mp_settings().show_connect = show_connect;
}
示例3: enter_connect_mode
bool enter_connect_mode(CVideo& /*video*/, const config& /*game_config*/, saved_game& state, bool /*local_players_only*/)
{
ng::connect_engine connect_eng(state, true, nullptr);
// TODO: fix. Dialog starts game regardless of selection
#if 0
if(state.mp_settings().show_connect) {
lobby_info li(game_config, std::vector<std::string>());
gui2::dialogs::mp_staging dlg(connect_eng, li);
dlg.show(video);
if(dlg.get_retval() != gui2::window::OK) {
// TODO: enable the workflow loops from GUI1
//return enter_create_mode(video, game_config, state, jump_to_campaign_info(false, -1, "", ""), local_players_only);
return false;
}
}
#endif
connect_eng.start_game();
return true;
}
示例4: level_to_gamestate
void level_to_gamestate(const config& level, saved_game& state)
{
game_classification::CAMPAIGN_TYPE type = state.classification().campaign_type;
bool show_connect = state.mp_settings().show_connect;
state = saved_game(level);
state.classification().campaign_type = type;
state.mp_settings().show_connect = show_connect;
// Any replay data is only temporary and should be removed from
// the level data in case we want to save the game later.
if (const config& replay_data = level.child("replay"))
{
LOG_NW << "setting replay\n";
recorder = replay(replay_data);
if (!recorder.empty()) {
recorder.set_skip(false);
recorder.set_to_end();
}
}
//save id setting was moved to play_controller.
}
示例5: enter_connect_mode
static bool enter_connect_mode(game_display& disp, const config& game_config,
saved_game& state,
bool local_players_only = false)
{
DBG_MP << "entering connect mode" << std::endl;
mp::ui::result res;
const network::manager net_manager(1,1);
network_game_manager m;
gamelist.clear();
statistics::fresh_stats();
{
mp::connect_engine_ptr connect_engine(new mp::connect_engine(state, local_players_only, true));
mp::connect ui(disp, state.mp_settings().name, game_config, gamechat, gamelist,
*connect_engine);
run_lobby_loop(disp, ui);
res = ui.get_result();
// start_game() updates the parameters to reflect game start,
// so it must be called before get_level()
if (res == mp::ui::PLAY) {
ui.start_game();
}
}
switch (res) {
case mp::ui::PLAY:
play_game(disp, state, game_config, IO_SERVER, false,
!local_players_only);
recorder.clear();
break;
case mp::ui::CREATE:
enter_create_mode(disp, game_config, state, local_players_only);
break;
case mp::ui::QUIT:
default:
network::send_data(config("refresh_lobby"), 0);
return false;
}
return true;
}
示例6: initial_level_config
config initial_level_config(saved_game& state)
{
const mp_game_settings& params = state.mp_settings();
//Also impliers state.expand_scenario()
//We need to call this before expand_mp_events/options oterwise they might be overwritten
state.expand_random_scenario();
state.expand_mp_events();
state.expand_mp_options();
config& scenario = state.get_starting_pos();
if(!state.mp_settings().saved_game)
{
state.set_random_seed();
if (params.random_start_time)
{
if (!tod_manager::is_start_ToD(scenario["random_start_time"]))
{
scenario["random_start_time"] = true;
}
}
else
{
scenario["random_start_time"] = false;
}
scenario["experience_modifier"] = params.xp_modifier;
}
if (scenario["objectives"].empty()) {
scenario["objectives"] = "<big>" + t_string(N_("Victory:"), "wesnoth") +
"</big>\n<span foreground=\"#00ff00\">• " +
t_string(N_("Defeat enemy leader(s)"), "wesnoth") + "</span>";
}
config level = state.to_config();
add_multiplayer_classification(level.child_or_add("multiplayer"), state);
std::string era = params.mp_era;
//[multiplayer] mp_era= should be persistent over saves.
//[era], [modification]s are toplevel tags here, they are not part of the saved_game and only used during mp_connect/mp_wait
// Initialize the list of sides available for the current era.
// We also need this no not get a segfault in mp_connect for ai configuration
const config &era_cfg =
game_config_manager::get()->game_config().find_child("era", "id", era);
if (!era_cfg) {
if (!params.saved_game)
{
utils::string_map i18n_symbols;
i18n_symbols["era"] = era;
throw config::error(vgettext("Cannot find era $era", i18n_symbols));
}
// FIXME: @todo We should tell user about missing era but still load game
WRN_CF << "Missing era in MP load game " << era << std::endl;
//Otherwise we get an error when qwhen we try to add ai algirithms in moultiplayer_connect
level.add_child("era");
}
else
{
/*config& cfg = */level.add_child("era", era_cfg);
const config& custom_side = game_config_manager::get()->
game_config().find_child("multiplayer_side", "id", "Custom");
level.child("era").add_child_at("multiplayer_side", custom_side, 0);
}
// Add modifications, needed for ai aglorithms which are applied in mp_connect
const std::vector<std::string>& mods = params.active_mods;
for (unsigned i = 0; i < mods.size(); i++) {
/*config& cfg = */level.add_child("modification",
game_config_manager::get()->
game_config().find_child("modification", "id", mods[i]));
}
// This will force connecting clients to be using the same version number as us.
level["version"] = game_config::version;
return level;
}
示例7: start_local_game_commandline
void start_local_game_commandline(const config& game_config, saved_game& state, const commandline_options& cmdline_opts)
{
DBG_MP << "starting local MP game from commandline" << std::endl;
// The setup is done equivalently to lobby MP games using as much of existing
// code as possible. This means that some things are set up that are not
// needed in commandline mode, but they are required by the functions called.
preferences::set_message_private(false);
DBG_MP << "entering create mode" << std::endl;
// Set the default parameters
state.clear(); // This creates these parameters with default values defined in mp_game_settings.cpp
mp_game_settings& parameters = state.mp_settings();
// Hardcoded default values
parameters.mp_era = "era_default";
parameters.name = "multiplayer_The_Freelands";
// Default values for which at getter function exists
parameters.num_turns = settings::get_turns("");
parameters.village_gold = settings::get_village_gold("");
parameters.village_support = settings::get_village_support("");
parameters.xp_modifier = settings::get_xp_modifier("");
// Do not use map settings if --ignore-map-settings commandline option is set
if(cmdline_opts.multiplayer_ignore_map_settings) {
DBG_MP << "ignoring map settings" << std::endl;
parameters.use_map_settings = false;
} else {
parameters.use_map_settings = true;
}
// None of the other parameters need to be set, as their creation values above are good enough for CL mode.
// In particular, we do not want to use the preferences values.
state.classification().campaign_type = game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
// [era] define.
if(cmdline_opts.multiplayer_era) {
parameters.mp_era = *cmdline_opts.multiplayer_era;
}
if(const config& cfg_era = game_config.find_child("era", "id", parameters.mp_era)) {
state.classification().era_define = cfg_era["define"].str();
} else {
std::cerr << "Could not find era '" << parameters.mp_era << "'\n";
return;
}
// [multiplayer] define.
if(cmdline_opts.multiplayer_scenario) {
parameters.name = *cmdline_opts.multiplayer_scenario;
}
if(const config& cfg_multiplayer = game_config.find_child("multiplayer", "id", parameters.name)) {
state.classification().scenario_define = cfg_multiplayer["define"].str();
} else {
std::cerr << "Could not find [multiplayer] '" << parameters.name << "'\n";
return;
}
game_config_manager::get()->load_game_config_for_game(state.classification());
state.set_carryover_sides_start(
config {"next_scenario", parameters.name}
);
state.expand_random_scenario();
state.expand_mp_events();
state.expand_mp_options();
// Should number of turns be determined from scenario data?
if(parameters.use_map_settings && state.get_starting_pos()["turns"]) {
DBG_MP << "setting turns from scenario data: " << state.get_starting_pos()["turns"] << std::endl;
parameters.num_turns = state.get_starting_pos()["turns"];
}
DBG_MP << "entering connect mode" << std::endl;
statistics::fresh_stats();
{
ng::connect_engine_ptr connect_engine(new ng::connect_engine(state, true, nullptr));
// Update the parameters to reflect game start conditions
connect_engine->start_game_commandline(cmdline_opts);
}
if(resources::recorder && cmdline_opts.multiplayer_label) {
std::string label = *cmdline_opts.multiplayer_label;
resources::recorder->add_log_data("ai_log","ai_label",label);
}
unsigned int repeat = (cmdline_opts.multiplayer_repeat) ? *cmdline_opts.multiplayer_repeat : 1;
for(unsigned int i = 0; i < repeat; i++){
saved_game state_copy(state);
campaign_controller controller(state_copy, game_config, game_config_manager::get()->terrain_types());
controller.play_game();
}
}
示例8: initial_level_config
config initial_level_config(saved_game& state)
{
const mp_game_settings& params = state.mp_settings();
state.set_defaults();
// Also impliers state.expand_scenario()
// We need to call this before expand_mp_events/options otherwise they might be overwritten.
state.expand_random_scenario();
state.expand_mp_events();
state.expand_mp_options();
if(!state.valid()) {
throw config::error("Failed to load the scenario");
}
config& scenario = state.get_starting_point();
if(state.mp_settings().saved_game == mp_game_settings::SAVED_GAME_MODE::NONE) {
state.set_random_seed();
}
if(scenario["objectives"].empty()) {
// Generic victory objectives.
std::ostringstream ss;
ss << "<big>";
ss << t_string(N_("Victory:"), "wesnoth") << "</big>\n";
ss << "<span color='#00ff00'>" << font::unicode_bullet << " ";
ss << t_string(N_("Defeat enemy leader(s)"), "wesnoth") << "</span>";
scenario["objectives"] = ss.str();
}
config level = state.to_config();
add_multiplayer_classification(level.child_or_add("multiplayer"), state);
// [multiplayer] mp_era= should be persistent over saves.
std::string era = params.mp_era;
/**
* [era] and [modification]s are toplevel tags here.
* They are not part of the saved_game and are only used during mp_staging/mp_join_game.
*
* @todo: see if all the comments ai algorithms are still up-to-date and relevant.
*
* -- vultraz, 2017-11-24
*/
const config& game_config = game_config_manager::get()->game_config();
const config& era_cfg = game_config.find_child("era", "id", era);
if(!era_cfg) {
if(params.saved_game == mp_game_settings::SAVED_GAME_MODE::NONE) {
throw config::error(VGETTEXT("Cannot find era $era", {{"era", era}}));
}
// FIXME: @todo We should tell user about missing era but still load game...
WRN_CF << "Missing era in MP load game " << era << std::endl;
// Otherwise we get an error when when we try to add ai algorithms in mp_staging.
level.add_child("era");
} else {
level.add_child("era", era_cfg);
// Initialize the list of sides available for the current era.
// We also need this so not to get a segfault in mp_staging for ai configuration.
const config& custom_side = game_config.find_child("multiplayer_side", "id", "Custom");
level.child("era").add_child_at("multiplayer_side", custom_side, 0);
}
// Add modifications, needed for ai algorithms which are applied in mp_staging.
const std::vector<std::string>& mods = params.active_mods;
for(unsigned i = 0; i < mods.size(); ++i) {
if(const config& mod_cfg = game_config.find_child("modification", "id", mods[i])) {
level.add_child("modification", mod_cfg);
}
}
// This will force connecting clients to be using the same version number as us.
level["version"] = game_config::wesnoth_version.str();
return level;
}