• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ saved_game类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中saved_game的典型用法代码示例。如果您正苦于以下问题:C++ saved_game类的具体用法?C++ saved_game怎么用?C++ saved_game使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了saved_game类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: add_multiplayer_classification

// 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;
}
开发者ID:Martin9295,项目名称:wesnoth,代码行数:9,代码来源:mp_game_utils.cpp


示例2:

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) ;
}
开发者ID:Kanac,项目名称:wesnoth,代码行数:27,代码来源:playsingle_controller.cpp


示例3: 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;
	}
}
开发者ID:kencheng,项目名称:wesnoth,代码行数:33,代码来源:singleplayer.cpp


示例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;
}
开发者ID:Martin9295,项目名称:wesnoth,代码行数:8,代码来源:mp_game_utils.cpp


示例5: 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;
}
开发者ID:Wedge009,项目名称:wesnoth,代码行数:25,代码来源:singleplayer.cpp


示例6: show_carryover_message

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);
		}
	}
开发者ID:m06x,项目名称:wesnoth,代码行数:59,代码来源:playcampaign.cpp


示例7: savegame

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);
}
开发者ID:mrwillis21,项目名称:wesnoth,代码行数:8,代码来源:savegame.cpp


示例8: level_to_gamestate

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.
}
开发者ID:Zappaman,项目名称:wesnoth,代码行数:20,代码来源:mp_game_utils.cpp


示例9: start_client

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);
}
开发者ID:fluffbeast,项目名称:wesnoth-old,代码行数:46,代码来源:multiplayer.cpp


示例10: 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;
}
开发者ID:8680-wesnoth,项目名称:wesnoth-fork-old,代码行数:46,代码来源:multiplayer.cpp


示例11: play_controller

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();
}
开发者ID:8680-wesnoth,项目名称:wesnoth-fork-old,代码行数:20,代码来源:replay_controller.cpp


示例12: play_replay_level

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;
}
开发者ID:8680-wesnoth,项目名称:wesnoth-fork-old,代码行数:37,代码来源:replay_controller.cpp


示例13: show_carryover_message

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);
		}
	}
开发者ID:AlainODea,项目名称:wesnoth,代码行数:62,代码来源:playcampaign.cpp


示例14: enter_create_mode

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);
//.........这里部分代码省略.........
开发者ID:kencheng,项目名称:wesnoth,代码行数:101,代码来源:singleplayer.cpp


示例15: level_to_gamestate

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;
}
开发者ID:GregoryLundberg,项目名称:wesnoth,代码行数:6,代码来源:mp_game_utils.cpp


示例16: savegame

scenariostart_savegame::scenariostart_savegame(saved_game &gamestate, const compression::format compress_saves)
	: savegame(gamestate, compress_saves)
{
	set_filename(gamestate.classification().label);
}
开发者ID:pax2you4now,项目名称:wesnoth,代码行数:5,代码来源:savegame.cpp


示例17: 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\">&#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;
}
开发者ID:Martin9295,项目名称:wesnoth,代码行数:80,代码来源:mp_game_utils.cpp


示例18: 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;
}
开发者ID:GregoryLundberg,项目名称:wesnoth,代码行数:81,代码来源:mp_game_utils.cpp


示例19: enter_create_mode

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;
}
开发者ID:shikadilord,项目名称:wesnoth,代码行数:89,代码来源:singleplayer.cpp


示例20: controller_base

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;
    }
}
开发者ID:doofus-01,项目名称:wesnoth,代码行数:61,代码来源:play_controller.cpp



注:本文中的saved_game类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ sc_event类代码示例发布时间:2022-05-31
下一篇:
C++ sapi_module_struct类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap