예제 #1
0
void create_terrain_maps(const config::const_child_itors &cfgs,
                         t_translation::ter_list& terrain_list,
                         std::map<t_translation::terrain_code, terrain_type>& letter_to_terrain)
{
	for (const config &terrain_data : cfgs)
	{
		terrain_type terrain(terrain_data);
		DBG_G << "create_terrain_maps: " << terrain.number() << " "
			<< terrain.id() << " " << terrain.name() << " : " << terrain.editor_group() << "\n";

		std::pair<std::map<t_translation::terrain_code, terrain_type>::iterator, bool> res;
		res = letter_to_terrain.insert(std::make_pair(terrain.number(), terrain));
		if (!res.second) {
			terrain_type& curr = res.first->second;
			if(terrain == curr) {
				LOG_G << "Merging terrain " << terrain.number()
					<< ": " << terrain.id() << " (" << terrain.name() << ")\n";
				std::vector<std::string> eg1 = utils::split(curr.editor_group());
				std::vector<std::string> eg2 = utils::split(terrain.editor_group());
				std::set<std::string> egs;
				bool clean_merge = true;
				for (std::string& t : eg1) {
					clean_merge &= egs.insert(t).second;
				}
				for (std::string& t : eg2) {
					clean_merge &= egs.insert(t).second;
				}

				std::string joined = utils::join(egs);
				curr.set_editor_group(joined);
				if(clean_merge) {
					LOG_G << "Editor groups merged to: " << joined << "\n";
				} else {
					LOG_G << "Merged terrain " << terrain.number()
					<< ": " << terrain.id() << " (" << terrain.name() << ") "
					<< "with duplicate editor groups [" << terrain.editor_group() << "] "
					<< "and [" << curr.editor_group() << "]\n";
				}
			} else {
				ERR_G << "Duplicate terrain code definition found for " << terrain.number() << "\n"
					<< "Failed to add terrain " << terrain.id() << " (" << terrain.name() << ") "
					<< "[" << terrain.editor_group() << "]" << "\n"
					<< "which conflicts with  " << curr.id() << " (" << curr.name() << ") "
					<< "[" << curr.editor_group() << "]" << "\n\n";
			}
		} else {
			terrain_list.push_back(terrain.number());
		}
	}
}