当前位置: 首页>>代码示例>>C++>>正文


C++ saved_game::set_defaults方法代码示例

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


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

示例1: 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


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