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


C++ game_state::set_variables方法代码示例

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


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

示例1: play_replay

void play_replay(display& disp, game_state& gamestate, const config& game_config, 
	hero_map& heros, hero_map& heros_start, card_map& cards, CVideo& video)
{
	std::string type = gamestate.classification().campaign_type;
	if(type.empty())
		type = "scenario";

	// 'starting_pos' will contain the position we start the game from.
	config starting_pos;

	if (gamestate.starting_pos.empty()){
		// Backwards compatibility code for 1.2 and 1.2.1
		const config &scenario = game_config.find_child(type,"id",gamestate.classification().scenario);
		assert(scenario);
		gamestate.starting_pos = scenario;
	}
	starting_pos = gamestate.starting_pos;

	//for replays, use the variables specified in starting_pos
	if (const config &vars = starting_pos.child("variables")) {
		gamestate.set_variables(vars);
	}

	try {
		// Preserve old label eg. replay
		if (gamestate.classification().label.empty())
			gamestate.classification().label = starting_pos["name"].str();
		//if (gamestate.abbrev.empty())
		//	gamestate.abbrev = (*scenario)["abbrev"];

		play_replay_level(game_config, &starting_pos, video, gamestate, heros, heros_start, cards);

		gamestate.snapshot = config();
		recorder.clear();
		gamestate.replay_data.clear();
		gamestate.start_scenario_ss.str("");
		// gamestate.start_hero_ss.str("");
		gamestate.clear_start_hero_data();

	} catch(game::load_game_failed& e) {
		gui2::show_error_message(disp.video(), _("The game could not be loaded: ") + e.message);
	} catch(game::game_error& e) {
		gui2::show_error_message(disp.video(), _("Error while playing the game: ") + e.message);
	} catch(incorrect_map_format_error& e) {
		gui2::show_error_message(disp.video(), std::string(_("The game map could not be loaded: ")) + e.message);
	} catch(twml_exception& e) {
		e.show(disp);
	}
}
开发者ID:coolsee,项目名称:War-Of-Kingdom,代码行数:49,代码来源:playcampaign.cpp

示例2: play_game

LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_config, hero_map& heros, hero_map& heros_start,
		card_map& cards,
		io_type_t io_type, bool skip_replay)
{
	tent::io_type = io_type;
	std::string type = gamestate.classification().campaign_type;
	if (type.empty()) {
		type = "scenario";
	}

	config const* scenario = NULL;

	// 'starting_pos' will contain the position we start the game from.
	config starting_pos;

	// Do we have any snapshot data?
	// yes => this must be a savegame
	// no  => we are starting a fresh scenario
	if (!gamestate.snapshot["runtime"].to_bool() || !recorder.at_end()) {
		gamestate.classification().completion = "running";
		// Campaign or Multiplayer?
		// If the gamestate already contains a starting_pos,
		// then we are starting a fresh multiplayer game.
		// Otherwise this is the start of a campaign scenario.
		if (gamestate.starting_pos["id"].empty() == false) {
			starting_pos = gamestate.starting_pos;
			scenario = &starting_pos;
		} else {
			// reload of the scenario, as starting_pos contains carryover information only
			scenario = &load_campagin_scenario(gamestate.classification().campaign, gamestate.classification().scenario, type);
			VALIDATE(!scenario->empty(), std::string("play_game, cannot load scenario id = ") + gamestate.classification().scenario + " in game_config!");
			gamestate.starting_pos = *scenario;
			starting_pos = gamestate.starting_pos;
			scenario = &starting_pos;
		}
	} else {
		// This game was started from a savegame
		starting_pos = gamestate.starting_pos;
		scenario = &gamestate.snapshot;
		// When starting wesnoth --multiplayer there might be
		// no variables which leads to a segfault
		if (const config &vars = gamestate.snapshot.child("variables")) {
			gamestate.set_variables(vars);
		}
		gamestate.set_menu_items(gamestate.snapshot.child_range("menu_item"));
		// Replace game label with that from snapshot
		if (!gamestate.snapshot["label"].empty()){
			gamestate.classification().label = gamestate.snapshot["label"].str();
		}
	}

	bool fog = scenario->get("fog")->to_bool();
	bool shroud = scenario->get("shroud")->to_bool();

	while (scenario != NULL) {
		// If we are a multiplayer client, tweak the controllers
		if (io_type == IO_CLIENT) {
			if (scenario != &starting_pos) {
				starting_pos = *scenario;
				scenario = &starting_pos;
			}
		}

		config::const_child_itors story = scenario->child_range("story");
		gamestate.classification().next_scenario = (*scenario)["next_scenario"].str();

		bool save_game_after_scenario = true;

		LEVEL_RESULT res = VICTORY;
		end_level_data end_level;

		try {
			// Preserve old label eg. replay
			if (gamestate.classification().label.empty()) {
				t_string tstr = (*scenario)["name"];
				if (gamestate.classification().abbrev.empty()) {
					gamestate.classification().label = tstr;
					gamestate.classification().original_label = tstr.base_str();
				} else {
					gamestate.classification().label = std::string(gamestate.classification().abbrev);
					gamestate.classification().label.append("-");
					gamestate.classification().original_label = gamestate.classification().label;
					gamestate.classification().label.append(tstr);
					gamestate.classification().original_label.append(tstr.base_str());
				}
			}

			// If the entire scenario should be randomly generated
			if ((*scenario)["scenario_generation"] != "") {
				const cursor::setter cursor_setter(cursor::WAIT);

				static config scenario2;
				scenario2 = random_generate_scenario((*scenario)["scenario_generation"], scenario->child("generator"));
				//level_ = scenario;
				//merge carryover information into the newly generated scenario
				config temp(scenario2);
				gamestate.starting_pos = temp;
				scenario = &scenario2;
			}
			std::string map_data = (*scenario)["map_data"];
//.........这里部分代码省略.........
开发者ID:coolsee,项目名称:War-Of-Kingdom,代码行数:101,代码来源:playcampaign.cpp


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