Code
62void CvCityManager::OnCityCreated(CvCity* pkAddCity)63{64 // First add it to all the other city lists65 for (CityMap::iterator itr = ms_kCityMap.begin(); itr != ms_kCityMap.end(); ++itr)66 {67 CvCity* pkCity = (*itr).first;68 if ((*itr).first != pkAddCity) // It should not be in there, but check anyhow69 {70 CityList &kCityList = (*itr).second;7172 AddToSortedList(kCityList, pkCity->getX(), pkCity->getY(), pkAddCity);73 }74 }7576 // Then make a list for it77 std::pair<CityMap::iterator, bool> kResult = ms_kCityMap.insert(CityMap::value_type(pkAddCity, ms_kEmptyList));7879 CityList& kCityList = (*kResult.first).second;80 kCityList.reserve(256); // Reserving an arbitrary number of cities. Large games can probably have more than this, but this is a good middle ground.8182 // Instead of adding all the cities, then sorting the list, this will add them to their correctly sorted position one at a time.83 // This might be a tad slower, but city creation is not happening all the time and if we did the sort, the list would have to store the distance84 int iFromX = pkAddCity->getX();85 int iFromY = pkAddCity->getY();86 for (CityMap::iterator itr = ms_kCityMap.begin(); itr != ms_kCityMap.end(); ++itr)87 {88 CvCity* pkCity = (*itr).first;89 if ((*itr).first != pkAddCity)90 {91 AddToSortedList(kCityList, iFromX, iFromY, pkCity);92 }93 }94}