Esempio n. 1
0
void game_state::write(config& cfg) const
{
	cfg["init_side_done"] = init_side_done_;
	if(gamedata_.phase() == game_data::PLAY) {
		cfg["playing_team"] = player_number_ - 1;
	}
	cfg["server_request_number"] = server_request_number_;
	//Call the lua save_game functions
	lua_kernel_->save_game(cfg);

	//Write the game events.
	events_manager_->write_events(cfg);

	//Write the map, unit_map, and teams info
	board_.write_config(cfg);

	//Write the tod manager, and time areas
	cfg.merge_with(tod_manager_.to_config());

	//write out the current state of the map
	cfg.merge_with(pathfind_manager_->to_config());

	//Write the game data, including wml vars
	gamedata_.write_snapshot(cfg);

	// Preserve the undo stack so that fog/shroud clearing is kept accurate.
	undo_stack_->write(cfg.add_child("undo_stack"));

	if(end_level_data_.get_ptr() != nullptr) {
		end_level_data_->write(cfg.add_child("end_level_data"));
	}
}
Esempio n. 2
0
/**
 * Writes our data to a config, as a child if @a child_name is specified.
 * (No child is created if there is no data.)
 */
void movetype::resistances::write(config & out_cfg, const std::string & child_name) const
{
	if ( cfg_.empty() )
		return;

	if ( child_name.empty() )
		out_cfg.merge_with(cfg_);
	else
		out_cfg.add_child(child_name, cfg_);
}
Esempio n. 3
0
/**
 * If there is data, writes it to a config.
 * @param[out] out_cfg     The config that will receive the data.
 * @param[in]  child_name  If not empty, create and write to a child config with this tag.
 *                         This child will *not* be created if there is no data to write.
 */
void movetype::terrain_info::data::write(
	config & out_cfg, const std::string & child_name) const
{
	if ( cfg_.empty() )
		return;

	if ( child_name.empty() )
		out_cfg.merge_with(cfg_);
	else
		out_cfg.add_child(child_name, cfg_);
}
	void operator()(config& child, const std::string& key, int startindex, int /*endindex*/) const
	{
		// The merge_with function only accepts configs so we convert vector -> config.
		config datatemp;

		// Add empty config to 'shift' the merge to startindex
		for(int index = 0; index < startindex; ++index) {
			datatemp.add_child(key);
		}

		// move datasource_ -> datatemp
		for(std::size_t index = 0; index < datasource_.size(); ++index) {
			datatemp.add_child(key).swap(datasource_[index]);
		}

		child.merge_with(datatemp);
	}