void create_terrain_maps(const config::const_child_itors &cfgs, t_translation::t_list& terrain_list, std::map<t_translation::t_terrain, terrain_type>& letter_to_terrain) { foreach (const config &t, cfgs) { terrain_type terrain(t); DBG_G << "create_terrain_maps: " << terrain.number() << " " << terrain.id() << " " << terrain.name() << " : " << terrain.editor_group() << "\n"; std::pair<std::map<t_translation::t_terrain, 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; WRN_G << "Duplicate terrain code definition found for " << terrain.number() << "\n"; WRN_G << "Trying to add terrain " << terrain.id() << " (" << terrain.name() << ") " << "[" << terrain.editor_group() << "]" << "\n"; WRN_G << "which conflicts with " << curr.id() << " (" << curr.name() << ") " << "[" << curr.editor_group() << "]" << "\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; std::copy(eg1.begin(), eg1.end(), std::inserter(egs, egs.begin())); std::copy(eg2.begin(), eg2.end(), std::inserter(egs, egs.begin())); std::string joined = utils::join(egs); curr.set_editor_group(joined); WRN_G << "Editor groups merged to: " << joined << "\n"; } else { terrain_list.push_back(terrain.number()); } }
void create_terrain_maps(const config::const_child_itors &cfgs, t_translation::t_list& terrain_list, std::map<t_translation::t_terrain, terrain_type>& letter_to_terrain) { BOOST_FOREACH(const config &t, cfgs) { terrain_type terrain(t); DBG_G << "create_terrain_maps: " << terrain.number() << " " << terrain.id() << " " << terrain.name() << " : " << terrain.editor_group() << "\n"; std::pair<std::map<t_translation::t_terrain, 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; BOOST_FOREACH(std::string& t, eg1) clean_merge &= egs.insert(t).second; BOOST_FOREACH(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 { ERR_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"; ERR_G << "Failed to add terrain " << terrain.id() << " (" << terrain.name() << ") " << "[" << terrain.editor_group() << "]" << "\n"; ERR_G << "which conflicts with " << curr.id() << " (" << curr.name() << ") " << "[" << curr.editor_group() << "]" << "\n"; } } else { terrain_list.push_back(terrain.number()); } }