Example #1
0
void game_state::init(const config& level, play_controller & pc)
{
	events_manager_->read_scenario(level);
	gui2::tloadscreen::progress("init teams");
	if (level["modify_placing"].to_bool()) {
		LOG_NG << "modifying placing..." << std::endl;
		place_sides_in_preferred_locations(level);
	}

	LOG_NG << "initialized time of day regions... "    << (SDL_GetTicks() - pc.ticks()) << std::endl;
	for (const config &t : level.child_range("time_area")) {
		tod_manager_.add_time_area(board_.map(),t);
	}

	LOG_NG << "initialized teams... "    << (SDL_GetTicks() - pc.ticks()) << std::endl;

	board_.teams_.resize(level.child_count("side"));

	std::vector<team_builder_ptr> team_builders;

	int team_num = 0;
	for (const config &side : level.child_range("side"))
	{
		if (first_human_team_ == -1) {
			const std::string &controller = side["controller"];
			if (controller == "human") {
				first_human_team_ = team_num;
			}
		}
		team_builder_ptr tb_ptr = create_team_builder(side,
			board_.teams_, level, board_);
		++team_num;
		build_team_stage_one(tb_ptr);
		team_builders.push_back(tb_ptr);
	}
	{
		//sync traits of start units and the random start time.
		random_new::set_random_determinstic deterministic(gamedata_.rng());

		tod_manager_.resolve_random(*random_new::generator);

		for(team_builder_ptr tb_ptr : team_builders)
		{
			build_team_stage_two(tb_ptr);
		}
		for(size_t i = 0; i < board_.teams_.size(); i++) {
			// Labels from players in your ignore list default to hidden
			if(preferences::is_ignored(board_.teams_[i].current_player())) {
				std::string label_cat = "side:" + std::to_string(i + 1);
				board_.hidden_label_categories_ref().push_back(label_cat);
			}
		}
	}

	pathfind_manager_.reset(new pathfind::manager(level));

	lua_kernel_.reset(new game_lua_kernel(nullptr, *this, pc, *reports_));
}
Example #2
0
void game_state::init(const int ticks, play_controller & pc, const config& level)
{
	int ticks1 = SDL_GetTicks();
	if (level["modify_placing"].to_bool()) {
		LOG_NG << "modifying placing..." << std::endl;
		place_sides_in_preferred_locations(level);
	}

	LOG_NG << "initialized time of day regions... "    << (SDL_GetTicks() - ticks) << std::endl;
	BOOST_FOREACH(const config &t, level.child_range("time_area")) {
		tod_manager_.add_time_area(board_.map(),t);
	}

	LOG_NG << "initialized teams... "    << (SDL_GetTicks() - ticks) << std::endl;
	//loadscreen::start_stage("init teams");

	board_.teams_.resize(level.child_count("side"));

	std::vector<team_builder_ptr> team_builders;

	int team_num = 0;
	BOOST_FOREACH(const config &side, level.child_range("side"))
	{
		if (first_human_team_ == -1) {
			const std::string &controller = side["controller"];
			if (controller == "human") {
				first_human_team_ = team_num;
			}
		}
		team_builder_ptr tb_ptr = create_team_builder(side,
			board_.teams_, level, board_);
		++team_num;
		build_team_stage_one(tb_ptr);
		team_builders.push_back(tb_ptr);
	}
	{
		//sync traits of start units and the random start time.
		random_new::set_random_determinstic deterministic(gamedata_.rng());

		tod_manager_.resolve_random(*random_new::generator);

		BOOST_FOREACH(team_builder_ptr tb_ptr, team_builders)
		{
			build_team_stage_two(tb_ptr);
		}
		for(size_t i = 0; i < board_.teams_.size(); i++) {
			// Labels from players in your ignore list default to hidden
			if(preferences::is_ignored(board_.teams_[i].current_player())) {
				std::string label_cat = "side:" + str_cast(i + 1);
				board_.hidden_label_categories_ref().push_back(label_cat);
			}
		}
	}
Example #3
0
void game_state::init(const int ticks)
{
	if (level_["modify_placing"].to_bool()) {
		LOG_NG << "modifying placing..." << std::endl;
		place_sides_in_preferred_locations();
	}

	LOG_NG << "initialized time of day regions... "    << (SDL_GetTicks() - ticks) << std::endl;
	BOOST_FOREACH(const config &t, level_.child_range("time_area")) {
		tod_manager_.add_time_area(board_.map(),t);
	}

	LOG_NG << "initialized teams... "    << (SDL_GetTicks() - ticks) << std::endl;
	loadscreen::start_stage("init teams");

	board_.teams_.resize(level_.child_count("side"));

	std::vector<team_builder_ptr> team_builders;

	int team_num = 0;
	BOOST_FOREACH(const config &side, level_.child_range("side"))
	{
		if (first_human_team_ == -1) {
			const std::string &controller = side["controller"];
			if (controller == "human" &&
			    side["id"] == preferences::login()) {
				first_human_team_ = team_num;
			} else if (controller == "human") {
				first_human_team_ = team_num;
			}
		}
		team_builder_ptr tb_ptr = gamedata_.create_team_builder(side,
			board_.teams_, level_, *board_.map_);
		++team_num;
		gamedata_.build_team_stage_one(tb_ptr);
		team_builders.push_back(tb_ptr);
	}
	{
		//sync traits of start units and the random start time.
		random_new::set_random_determinstic deterministic(gamedata_.rng());

		tod_manager_.resolve_random(*random_new::generator);

		BOOST_FOREACH(team_builder_ptr tb_ptr, team_builders)
		{
			gamedata_.build_team_stage_two(tb_ptr);
		}
	}
Example #4
0
void play_controller::init(CVideo& video){
	util::scoped_resource<loadscreen::global_loadscreen_manager*, util::delete_item> scoped_loadscreen_manager;
	loadscreen::global_loadscreen_manager* loadscreen_manager = loadscreen::global_loadscreen_manager::get();
	if (!loadscreen_manager)
	{
		scoped_loadscreen_manager.assign(new loadscreen::global_loadscreen_manager(video));
		loadscreen_manager = scoped_loadscreen_manager.get();
	}

	loadscreen::start_stage("load level");
	// i currently assume that no random calls take place before the "prestart" event
	// If i am wrong, use random_new_deterministic
	recorder.set_skip(false);

	bool snapshot = level_["snapshot"].to_bool();

	if (level_["modify_placing"].to_bool()) {
		LOG_NG << "modifying placing..." << std::endl;
		place_sides_in_preferred_locations();
	}

	BOOST_FOREACH(const config &t, level_.child_range("time_area")) {
		tod_manager_.add_time_area(t);
	}

	LOG_NG << "initialized teams... "    << (SDL_GetTicks() - ticks_) << std::endl;
	loadscreen::start_stage("init teams");

	resources::teams->resize(level_.child_count("side"));

	// This *needs* to be created before the show_intro and show_map_scene
	// as that functions use the manager state_of_game
	// Has to be done before registering any events!
	events_manager_.reset(new game_events::manager(level_));

	std::set<std::string> seen_save_ids;

	std::vector<team_builder_ptr> team_builders;

	int team_num = 0;
	BOOST_FOREACH(const config &side, level_.child_range("side"))
	{
		std::string save_id = get_unique_saveid(side, seen_save_ids);
		seen_save_ids.insert(save_id);
		if (first_human_team_ == -1) {
			const std::string &controller = side["controller"];
			if (controller == "human" &&
			    side["id"] == preferences::login()) {
				first_human_team_ = team_num;
			} else if (controller == "human") {
				first_human_team_ = team_num;
			}
		}
		team_builder_ptr tb_ptr = gamedata_.create_team_builder(side,
			save_id, teams_, level_, map_, units_, snapshot, gamestate_.replay_start());
		++team_num;
		gamedata_.build_team_stage_one(tb_ptr);
		team_builders.push_back(tb_ptr);
	}
	{
		//sync traits of start units
		random_new::set_random_determinstic deterministic(gamedata_.rng());
		BOOST_FOREACH(team_builder_ptr tb_ptr, team_builders)
		{
			gamedata_.build_team_stage_two(tb_ptr);
		}
	}