コード例 #1
0
ファイル: mp_game_utils.cpp プロジェクト: Martin9295/wesnoth
// To remove radundant informaion in the clientside internal programmflow
// I want to remove these values from mp_settings so i need to readd them here
static void add_multiplayer_classification(config& multiplayer, saved_game& state)
{
	multiplayer["mp_scenario"] = state.get_scenario_id();
	multiplayer["mp_scenario_name"] = state.get_starting_pos()["name"];
	multiplayer["difficulty_define"] = state.classification().difficulty;
	multiplayer["mp_campaign"] = state.classification().campaign;
}
コード例 #2
0
playsingle_controller::playsingle_controller(const config& level,
        saved_game& state_of_game, const int ticks,
        const config& game_config, CVideo& video, bool skip_replay) :
    play_controller(level, state_of_game, ticks, game_config, video, skip_replay),
    cursor_setter(cursor::NORMAL),
    textbox_info_(),
    replay_sender_(recorder),
    network_reader_(),
    turn_data_(replay_sender_, network_reader_),
    end_turn_(false),
    player_type_changed_(false),
    replaying_(false),
    skip_next_turn_(false),
    do_autosaves_(false),
    level_result_(NONE)
{
    // game may need to start in linger mode
    if (state_of_game.classification().completion == "victory" || state_of_game.classification().completion == "defeat")
    {
        LOG_NG << "Setting linger mode.\n";
        browse_ = linger_ = true;
    }

    ai::game_info ai_info;
    ai::manager::set_ai_info(ai_info);
    ai::manager::add_observer(this) ;
}
コード例 #3
0
ファイル: singleplayer.cpp プロジェクト: kencheng/wesnoth
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;
	}
}
コード例 #4
0
ファイル: mp_game_utils.cpp プロジェクト: Martin9295/wesnoth
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;
}
コード例 #5
0
ファイル: singleplayer.cpp プロジェクト: Wedge009/wesnoth
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;
}
コード例 #6
0
ファイル: playcampaign.cpp プロジェクト: m06x/wesnoth
static void show_carryover_message(saved_game& gamestate, playsingle_controller& playcontroller, display& disp, const end_level_data& end_level, const LEVEL_RESULT res){
	bool has_next_scenario = !resources::gamedata->next_scenario().empty() &&
			resources::gamedata->next_scenario() != "null";
	//maybe this can be the case for scenario that only contain a story and end during the prestart event ?
	if(resources::teams->size() < 1){
		return;
	}

	std::ostringstream report;
	std::string title;

	bool obs = playcontroller.is_observer();

	if (obs) {
		title = _("Scenario Report");
	} else if (res == LEVEL_RESULT::VICTORY) {
		title = _("Victory");
		report << "<b>" << _("You have emerged victorious!") << "</b>\n\n";
	} else {
		title = _("Defeat");
		report <<  _("You have been defeated!") << "\n";
	}

	assert(resources::teams);
	//We need to write the carryover amount to the team thats why we need non const
	std::vector<team>& teams = *resources::teams;
	int persistent_teams = 0;
	BOOST_FOREACH(const team &t, teams) {
		if (t.persistent()){
			++persistent_teams;
		}
	}

	if (persistent_teams > 0 && ((has_next_scenario && end_level.proceed_to_next_level)||
			gamestate.classification().campaign_type == game_classification::CAMPAIGN_TYPE::TEST))
	{
		gamemap map = playcontroller.get_map_const();
		tod_manager tod = playcontroller.get_tod_manager_const();
		int turns_left = std::max<int>(0, tod.number_of_turns() - tod.turn());
		BOOST_FOREACH(team &t, teams)
		{
			if (!t.persistent() || t.lost())
			{
				continue;
			}
			int finishing_bonus_per_turn = map.villages().size() * t.village_gold() + t.base_income();
			int finishing_bonus = t.carryover_bonus() ? finishing_bonus_per_turn * turns_left : 0;
			t.set_carryover_gold(div100rounded((t.gold() + finishing_bonus) * t.carryover_percentage()));
			if(!t.is_local_human())
			{
				continue;
			}
			if (persistent_teams > 1) {
				report << "\n<b>" << t.current_player() << "</b>\n";
			}

			playcontroller.report_victory(report, t, finishing_bonus_per_turn, turns_left, finishing_bonus);
		}
	}
コード例 #7
0
ファイル: savegame.cpp プロジェクト: mrwillis21/wesnoth
ingame_savegame::ingame_savegame(saved_game &gamestate,
					game_display& gui, const config& snapshot_cfg, const compression::format compress_saves)
	: savegame(gamestate, compress_saves, _("Save Game")),
	gui_(gui)
{
	gamestate.set_snapshot(snapshot_cfg);
	snapshot().merge_with(snapshot_cfg);
}
コード例 #8
0
ファイル: mp_game_utils.cpp プロジェクト: Zappaman/wesnoth
void level_to_gamestate(const config& level, saved_game& state)
{
	game_classification::CAMPAIGN_TYPE type = state.classification().campaign_type;
	state = saved_game(level);
	state.classification().campaign_type = type;
	// 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.
}
コード例 #9
0
void start_client(const config& game_config,	saved_game& state, const std::string& host)
{
	const config* game_config_ptr = &game_config;

	// This function does not refer to an addon database, it calls filesystem functions.
	// For the sanity of the mp lobby, this list should be fixed for the entire lobby session,
	// even if the user changes the contents of the addon directory in the meantime.
	std::vector<std::string> installed_addons = ::installed_addons();

	DBG_MP << "starting client" << std::endl;

	preferences::admin_authentication_reset r;

	wesnothd_connection_ptr connection;
	config lobby_config;

	gui2::dialogs::loading_screen::display([&]() {
		std::tie(connection, lobby_config) = open_connection(host);
	});

	if(!connection) {
		return;
	}

	mp_workflow_helper_ptr workflow_helper;
	bool re_enter = false;

	do {
		workflow_helper.reset(new mp_workflow_helper(*game_config_ptr, state, connection.get(), nullptr));

		// A return of false means a config reload was requested, so do that and then loop.
		re_enter = !enter_lobby_mode(workflow_helper, installed_addons, lobby_config);

		if(re_enter) {
			game_config_manager* gcm = game_config_manager::get();
			gcm->reload_changed_game_config();
			gcm->load_game_config_for_game(state.classification()); // NOTE: Using reload_changed_game_config only doesn't seem to work here

			game_config_ptr = &gcm->game_config();

			installed_addons = ::installed_addons(); // Refresh the installed add-on list for this session.

			connection->send_data(config("refresh_lobby"));
		}
	} while(re_enter);
}
コード例 #10
0
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;
}
コード例 #11
0
replay_controller::replay_controller(const config& level,
		saved_game& state_of_game, const int ticks,
		const config& game_config, CVideo& video) :
	play_controller(level, state_of_game, ticks, game_config, video, false),
	saved_game_start_(saved_game_),
	gameboard_start_(gamestate_.board_),
	tod_manager_start_(level),
	current_turn_(1),
	is_playing_(false),
	show_everything_(false),
	show_team_(state_of_game.classification().campaign_type == game_classification::MULTIPLAYER ? 0 : 1)
{
	// Our parent class correctly detects that we are loading a game. However,
	// we are not loading mid-game, so from here on, treat this as not loading
	// a game. (Allows turn_1 et al. events to fire at the correct time.)
	loading_game_ = false;

	init();
	reset_replay();
}
コード例 #12
0
LEVEL_RESULT play_replay_level(const config& game_config,
		CVideo& video, saved_game& state_of_game, bool is_unit_test)
{
	const int ticks = SDL_GetTicks();

	DBG_NG << "creating objects... " << (SDL_GetTicks() - ticks) << std::endl;

	boost::scoped_ptr<replay_controller> rc;

	try {
		rc.reset(new replay_controller(state_of_game.get_replay_starting_pos(), state_of_game, ticks, game_config, video));
	} catch (end_level_exception & e){
		return e.result;
	} catch (end_turn_exception &) {
		throw; //this should never happen? It would likely have crashed the program before, so in refactor I won't change but we should fix it later.
	}
	DBG_NG << "created objects... " << (SDL_GetTicks() - rc->get_ticks()) << std::endl;

	const events::command_disabler disable_commands;

	//replay event-loop
	possible_end_play_signal signal = play_replay_level_main_loop(*rc, is_unit_test);

	if (signal) {
		switch( boost::apply_visitor( get_signal_type(), *signal ) ) {
			case END_LEVEL:
				DBG_NG << "play_replay_level: end_level_exception" << std::endl;
				break;
			case END_TURN:
				DBG_NG << "Unchecked end_turn_exception signal propogated to replay controller play_replay_level! Terminating." << std::endl;
				assert(false && "unchecked end turn exception in replay controller");
				throw 42;
		}
	}

	return VICTORY;
}
コード例 #13
0
ファイル: playcampaign.cpp プロジェクト: AlainODea/wesnoth
static void show_carryover_message(saved_game& gamestate, playsingle_controller& playcontroller, display& disp, const end_level_data& end_level, const LEVEL_RESULT res){
	bool has_next_scenario = !resources::gamedata->next_scenario().empty() &&
			resources::gamedata->next_scenario() != "null";
	//maybe this can be the case for scenario that only contain a story and end during the prestart event ?
	if(resources::teams->size() < 1){
		return;
	}

	std::ostringstream report;
	std::string title;

	bool obs = playcontroller.is_observer();

	if (obs) {
		title = _("Scenario Report");
	} else if (res == VICTORY) {
		title = _("Victory");
		report << "<b>" << _("You have emerged victorious!") << "</b>\n\n";
	} else {
		title = _("Defeat");
		report <<  _("You have been defeated!") << "\n";
	}

	std::vector<team> teams = playcontroller.get_teams_const();
	int persistent_teams = 0;
	BOOST_FOREACH(const team &t, teams) {
		if (t.persistent()){
			++persistent_teams;
		}
	}

	if (persistent_teams > 0 && ((has_next_scenario && end_level.proceed_to_next_level)||
			gamestate.classification().campaign_type == game_classification::TEST))
	{
		gamemap map = playcontroller.get_map_const();
		// NOTE: this function uses game_config::village_income/game_config::base_income which is teh same for all teams
		// the function that actualy does the carryover (carryover.cpp) uses team.base_income() / team.village_gold() since 1.13
		// which can be different for every team
		int finishing_bonus_per_turn =
				map.villages().size() * game_config::village_income +
				game_config::base_income;
		tod_manager tod = playcontroller.get_tod_manager_const();
		int turns_left = std::max<int>(0, tod.number_of_turns() - tod.turn());
		int finishing_bonus = (end_level.gold_bonus && turns_left > -1) ?
				finishing_bonus_per_turn * turns_left : 0;


		BOOST_FOREACH(const team &t, teams)
		{
			if (!t.persistent() || t.lost() || !t.is_human())
			{
				continue;
			}
			int carryover_gold = div100rounded((t.gold() + finishing_bonus) * end_level.carryover_percentage);
			
			if (persistent_teams > 1) {
				report << "\n<b>" << t.current_player() << "</b>\n";
			}

			playcontroller.report_victory(report, carryover_gold, t.gold(), finishing_bonus_per_turn, turns_left, finishing_bonus);
		}
	}
コード例 #14
0
ファイル: singleplayer.cpp プロジェクト: kencheng/wesnoth
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;
}
コード例 #15
0
void level_to_gamestate(const config& level, saved_game& state)
{
	game_classification::CAMPAIGN_TYPE type = state.classification().campaign_type;
	state = saved_game(level);
	state.classification().campaign_type = type;
}
コード例 #16
0
ファイル: savegame.cpp プロジェクト: pax2you4now/wesnoth
scenariostart_savegame::scenariostart_savegame(saved_game &gamestate, const compression::format compress_saves)
	: savegame(gamestate, compress_saves)
{
	set_filename(gamestate.classification().label);
}
コード例 #17
0
ファイル: mp_game_utils.cpp プロジェクト: Martin9295/wesnoth
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\">&#8226; " +
			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;
}
コード例 #18
0
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;
}
コード例 #19
0
ファイル: singleplayer.cpp プロジェクト: shikadilord/wesnoth
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;
}
コード例 #20
0
ファイル: play_controller.cpp プロジェクト: doofus-01/wesnoth
play_controller::play_controller(const config& level, saved_game& state_of_game,
                                 const config& game_config, const ter_data_cache& tdata,
                                 CVideo& video, bool skip_replay)
    : controller_base(game_config, video)
    , observer()
    , quit_confirmation()
    , ticks_(SDL_GetTicks())
    , tdata_(tdata)
    , gamestate_()
    , level_()
    , saved_game_(state_of_game)
    , tooltips_manager_()
    , whiteboard_manager_()
    , plugins_context_()
    , labels_manager_()
    , help_manager_(&game_config)
    , mouse_handler_(nullptr, *this)
    , menu_handler_(nullptr, *this, game_config)
    , hotkey_handler_(new hotkey_handler(*this, saved_game_))
    , soundsources_manager_()
    , persist_()
    , gui_()
    , xp_mod_(new unit_experience_accelerator(level["experience_modifier"].to_int(100)))
    , statistics_context_(new statistics::scenario_context(level["name"]))
    , replay_(new replay(state_of_game.get_replay()))
    , skip_replay_(skip_replay)
    , linger_(false)
    , init_side_done_now_(false)
    , victory_when_enemies_defeated_(level["victory_when_enemies_defeated"].to_bool(true))
    , remove_from_carryover_on_defeat_(level["remove_from_carryover_on_defeat"].to_bool(true))
    , victory_music_()
    , defeat_music_()
    , scope_()
    , ignore_replay_errors_(false)
    , player_type_changed_(false)
{
    copy_persistent(level, level_);

    resources::controller = this;
    resources::persist = &persist_;
    resources::recorder = replay_.get();

    resources::classification = &saved_game_.classification();
    resources::mp_settings = &saved_game_.mp_settings();

    persist_.start_transaction();

    // Setup victory and defeat music
    set_victory_music_list(level_["victory_music"]);
    set_defeat_music_list(level_["defeat_music"]);

    game_config::add_color_info(level);
    hotkey::deactivate_all_scopes();
    hotkey::set_scope_active(hotkey::SCOPE_GAME);
    try {
        init(video, level);
    } catch (...) {
        clear_resources();
        throw;
    }
}
コード例 #21
0
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();
	}
}