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; } }
void start_local_game(const config& game_config, saved_game& state) { DBG_MP << "starting local game" << std::endl; preferences::set_message_private(false); // TODO: should lobby_info take a nullptr in this case, or should we pass the installed_addons data here too? lobby_info li(game_config, {}); mp_workflow_helper_ptr workflow_helper = std::make_shared<mp_workflow_helper>(game_config, state, nullptr, &li); enter_create_mode(workflow_helper); }
static bool enter_connect_mode(game_display& disp, const config& game_config, game_state& state, const mp_game_settings& params, 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(disp, state, params, local_players_only, true)); mp::connect ui(disp, params.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; }
static void enter_connect_mode(game_display& disp, const config& game_config, hero_map& heros, hero_map& heros_start, card_map& cards, config& gamelist, const mp_game_settings& params, const int num_turns, mp::controller default_controller, bool local_players_only = false) { mp::ui::result res; game_state state; const network::manager net_manager(1,1); network_game_manager m; gamelist.clear(); statistics::fresh_stats(); // if (gui2::new_widgets) { gui2::tmp_side_creator dlg(heros, disp, *resources::game_map, game_config, gamelist, params, num_turns, default_controller, local_players_only); dlg.show(disp.video()); switch (dlg.get_legacy_result()) { case gui2::tmp_side_creator::PLAY: res = mp::ui::PLAY; dlg.start_game(); state = dlg.get_state(); // lobby may modify hero's side_feature heros_start = heros; break; case gui2::tmp_side_creator::CREATE: res = mp::ui::CREATE; break; default: res = mp::ui::QUIT; } switch (res) { case mp::ui::PLAY: play_game(disp, state, game_config, heros, heros_start, cards, IO_SERVER); recorder.clear(); break; case mp::ui::CREATE: enter_create_mode(disp, game_config, heros, heros_start, cards, gamelist, default_controller, local_players_only); break; case mp::ui::QUIT: default: network::send_data(config("refresh_lobby"), 0); break; } }
static void enter_connect_mode(game_display& disp, const config& game_config, mp::chat& chat, config& gamelist, const mp_game_settings& params, const int num_turns, mp::controller default_controller, bool local_players_only = false) { mp::ui::result res; game_state state; const network::manager net_manager(1,1); network_game_manager m; upload_log nolog(false); gamelist.clear(); statistics::fresh_stats(); { mp::connect ui(disp, game_config, chat, gamelist, params, num_turns, default_controller, local_players_only); 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(); state = ui.get_state(); } } switch (res) { case mp::ui::PLAY: play_game(disp, state, game_config, nolog, IO_SERVER); recorder.clear(); break; case mp::ui::CREATE: enter_create_mode(disp, game_config, chat, gamelist, default_controller, local_players_only); break; case mp::ui::QUIT: default: network::send_data(config("refresh_lobby"), 0, true); break; } }
static void enter_lobby_mode(game_display& disp, const config& game_config, mp::chat& chat, config& gamelist) { mp::ui::result res; while (true) { const config &cfg = game_config.child("lobby_music"); if (cfg) { foreach (const config &i, cfg.child_range("music")) { sound::play_music_config(i); } sound::commit_music_changes(); } else { sound::empty_playlist(); sound::stop_music(); } lobby_info li(game_config); gui2::tlobby_main dlg(game_config, li, disp); dlg.set_preferences_callback( boost::bind(do_preferences_dialog, boost::ref(disp), boost::ref(game_config))); dlg.show(disp.video()); //ugly kludge for launching other dialogs like the old lobby switch (dlg.get_legacy_result()) { case gui2::tlobby_main::CREATE: res = mp::ui::CREATE; break; case gui2::tlobby_main::JOIN: res = mp::ui::JOIN; break; case gui2::tlobby_main::OBSERVE: res = mp::ui::OBSERVE; break; default: res = mp::ui::QUIT; } switch (res) { case mp::ui::JOIN: try { enter_wait_mode(disp, game_config, chat, gamelist, false); } catch(config::error& error) { if(!error.message.empty()) { gui2::show_error_message(disp.video(), error.message); } //update lobby content network::send_data(config("refresh_lobby"), 0, true); } break; case mp::ui::OBSERVE: try { enter_wait_mode(disp, game_config, chat, gamelist, true); } catch(config::error& error) { if(!error.message.empty()) { gui2::show_error_message(disp.video(), error.message); } } // update lobby content unconditionally because we might have left only after the // game ended in which case we ignored the gamelist and need to request it again network::send_data(config("refresh_lobby"), 0, true); break; case mp::ui::CREATE: try { enter_create_mode(disp, game_config, chat, gamelist, mp::CNTR_NETWORK); } catch(config::error& error) { if (!error.message.empty()) gui2::show_error_message(disp.video(), error.message); //update lobby content network::send_data(config("refresh_lobby"), 0, true); } break; case mp::ui::QUIT: return; case mp::ui::PREFERENCES: { do_preferences_dialog(disp, game_config); //update lobby content network::send_data(config("refresh_lobby"), 0, true); } break; default: return; } }
bool enter_create_mode(game_display& disp, const config& game_config, saved_game& state, jump_to_campaign_info jump_to_campaign, bool local_players_only) { bool configure_canceled = false; do { ng::create_engine create_eng(disp, state); create_eng.set_current_level_type(ng::level::TYPE::SP_CAMPAIGN); std::vector<ng::create_engine::level_ptr> campaigns( create_eng.get_levels_by_type_unfiltered(ng::level::TYPE::SP_CAMPAIGN)); if (campaigns.empty()) { gui2::show_error_message(disp.video(), _("No campaigns are available.\n")); return false; } bool use_deterministic_mode = false; // No campaign selected from command line if (jump_to_campaign.campaign_id_.empty() == true) { gui2::tcampaign_selection dlg(create_eng); try { dlg.show(disp.video()); } catch(twml_exception& e) { e.show(disp); return false; } if(dlg.get_retval() != gui2::twindow::OK) { return false; } use_deterministic_mode = dlg.get_deterministic(); } else { // don't reset the campaign_id_ so we can know // if we should quit the game or return to the main menu // checking for valid campaign name bool not_found = true; for(size_t i = 0; i < campaigns.size(); ++i) { if (campaigns[i]->data()["id"] == jump_to_campaign.campaign_id_) { create_eng.set_current_level(i); not_found = false; break; } } // didn't find any campaign with that id if (not_found) { //TODO: use ERR_NG or similar std::cerr<<"No such campaign id to jump to: ["<<jump_to_campaign.campaign_id_<<"]\n"; return false; } } std::string random_mode = use_deterministic_mode ? "deterministic" : ""; state.classification().random_mode = random_mode; std::string selected_difficulty = create_eng.select_campaign_difficulty(jump_to_campaign.difficulty_); if (selected_difficulty == "FAIL") return false; if (selected_difficulty == "CANCEL") { if (jump_to_campaign.campaign_id_.empty() == false) { jump_to_campaign.campaign_id_ = ""; } // canceled difficulty dialog, relaunch the campaign selection dialog return enter_create_mode(disp, game_config, state, jump_to_campaign, local_players_only); } create_eng.prepare_for_era_and_mods(); create_eng.prepare_for_campaign(selected_difficulty); if(!jump_to_campaign.scenario_id_.empty()) { state.set_carryover_sides_start( config_of("next_scenario", jump_to_campaign.scenario_id_) ); } create_eng.prepare_for_new_level(); create_eng.get_parameters(); if(!state.valid()) { //TODO: use ERR_NG or similar std::cerr << "Cannot load scenario with id=" << state.get_scenario_id() << "\n"; return false; } configure_canceled = !enter_configure_mode(disp, game_config_manager::get()->game_config(), state, local_players_only); } while (configure_canceled); return true; }
static void enter_lobby_mode(game_display& disp, const config& game_config, game_state& state) { DBG_MP << "entering lobby mode" << std::endl; mp::ui::result res; while (true) { const config &cfg = game_config.child("lobby_music"); if (cfg) { BOOST_FOREACH(const config &i, cfg.child_range("music")) { sound::play_music_config(i); } sound::commit_music_changes(); } else { sound::empty_playlist(); sound::stop_music(); } lobby_info li(game_config); // Force a black background const Uint32 color = SDL_MapRGBA(disp.video().getSurface()->format , 0 , 0 , 0 , 255); sdl_fill_rect(disp.video().getSurface(), NULL, color); if(preferences::new_lobby()) { gui2::tlobby_main dlg(game_config, li, disp); dlg.set_preferences_callback( boost::bind(do_preferences_dialog, boost::ref(disp), boost::ref(game_config))); dlg.show(disp.video()); //ugly kludge for launching other dialogs like the old lobby switch (dlg.get_legacy_result()) { case gui2::tlobby_main::CREATE: res = mp::ui::CREATE; break; case gui2::tlobby_main::JOIN: res = mp::ui::JOIN; break; case gui2::tlobby_main::OBSERVE: res = mp::ui::OBSERVE; break; default: res = mp::ui::QUIT; } } else { mp::lobby ui(disp, game_config, gamechat, gamelist); run_lobby_loop(disp, ui); res = ui.get_result(); } switch (res) { case mp::ui::JOIN: try { enter_wait_mode(disp, game_config, state, false); } catch(config::error& error) { if(!error.message.empty()) { gui2::show_error_message(disp.video(), error.message); } //update lobby content network::send_data(config("refresh_lobby"), 0); } break; case mp::ui::OBSERVE: try { enter_wait_mode(disp, game_config, state, true); } catch(config::error& error) { if(!error.message.empty()) { gui2::show_error_message(disp.video(), error.message); } } // update lobby content unconditionally because we might have left only after the // game ended in which case we ignored the gamelist and need to request it again network::send_data(config("refresh_lobby"), 0); break; case mp::ui::CREATE: try { enter_create_mode(disp, game_config, state, false); } catch(config::error& error) { if (!error.message.empty()) gui2::show_error_message(disp.video(), error.message); //update lobby content network::send_data(config("refresh_lobby"), 0); } break; case mp::ui::QUIT: return; case mp::ui::PREFERENCES: { do_preferences_dialog(disp, game_config); //update lobby content network::send_data(config("refresh_lobby"), 0); } break; default: return; } }
bool enter_create_mode(CVideo& video, const config& game_config, saved_game& state, jump_to_campaign_info jump_to_campaign, bool local_players_only) { bool configure_canceled = false; do { ng::create_engine create_eng(video, state); create_eng.set_current_level_type(ng::level::TYPE::SP_CAMPAIGN); const std::vector<ng::create_engine::level_ptr> campaigns = create_eng.get_levels_by_type_unfiltered(ng::level::TYPE::SP_CAMPAIGN); if(campaigns.empty()) { gui2::show_error_message(video, _("No campaigns are available.")); return false; } std::string random_mode = ""; // No campaign selected from command line if(jump_to_campaign.campaign_id_.empty()) { gui2::tcampaign_selection dlg(create_eng); try { dlg.show(video); } catch(twml_exception& e) { e.show(video); return false; } if(dlg.get_retval() != gui2::twindow::OK) { return false; } if(dlg.get_deterministic()) { random_mode = "deterministic"; } } else { // Don't reset the campaign_id_ so we can know // if we should quit the game or return to the main menu // Checking for valid campaign name const auto campaign = std::find_if(campaigns.begin(), campaigns.end(), [&jump_to_campaign](ng::create_engine::level_ptr level) { return level->data()["id"] == jump_to_campaign.campaign_id_; }); // Didn't find a campaign with that id if(campaign == campaigns.end()) { ERR_NG << "No such campaign id to jump to: [" << jump_to_campaign.campaign_id_ << "]" << std::endl; return false; } create_eng.set_current_level(campaign - campaigns.begin()); } state.classification().random_mode = random_mode; const std::string selected_difficulty = create_eng.select_campaign_difficulty(jump_to_campaign.difficulty_); if(selected_difficulty == "FAIL") return false; if(selected_difficulty == "CANCEL") { if(!jump_to_campaign.campaign_id_.empty()) { jump_to_campaign.campaign_id_ = ""; } // Canceled difficulty dialog, relaunch the campaign selection dialog return enter_create_mode(video, game_config, state, jump_to_campaign, local_players_only); } create_eng.prepare_for_era_and_mods(); create_eng.prepare_for_campaign(selected_difficulty); if(!jump_to_campaign.scenario_id_.empty()) { state.set_carryover_sides_start( config_of("next_scenario", jump_to_campaign.scenario_id_) ); } if(!state.valid()) { ERR_NG << "Cannot load scenario with id=" << state.get_scenario_id() << std::endl; return false; } configure_canceled = !enter_configure_mode(video, game_config_manager::get()->game_config(), state, create_eng, local_players_only); } while (configure_canceled); return true; }