Code
155/// Pick start positions for all civs156void CvStartPositioner::AssignStartingLocations()157{158 CUSTOMLOG("CvStartPositioner::AssignStartingLocations()");159 CvString strString;160 unsigned int iNextRegion = 0;161 int iPlayersPlaced = 0;162 int iMajorCivs = 0;163 for(size_t i = 0; i < m_PlayerOrder.size(); ++i)164 {165 if(!GET_PLAYER((PlayerTypes)m_PlayerOrder[i].m_iPlayerID).isMinorCiv())166 iMajorCivs++;167 }168169 // MAJOR CIVS170 m_iRequiredSeparation = StartingPlotRange();171172 // ***** Debug *****173 if(GC.getMap().getWorldSize() == WORLDSIZE_DEBUG)174 {175 m_iRequiredSeparation = 1;176 }177178 while(iPlayersPlaced < iMajorCivs && iNextRegion < m_StartRegionVector.size())179 {180 if(m_StartRegionVector[iNextRegion].m_bLargeEnoughForMajorCiv)181 {182 strString.Format("Trying to place major civ with full separation of %d", m_iRequiredSeparation);183 LogStartPositionMessage(strString);184 bool success = AddCivToRegion(m_PlayerOrder[iPlayersPlaced].m_iPlayerID, m_StartRegionVector[iNextRegion], false);185 if(success)186 {187 iPlayersPlaced++;188 m_StartRegionVector[iNextRegion].m_iNumCivsPlaced++;189 }190 }191 iNextRegion++;192 }193194 // MAJOR CIVS AGAIN (those that couldn't be placed normal start distance apart)195196 int iHalfMinimumDist = GC.getMIN_CIV_STARTING_DISTANCE() / 2;197 while(iPlayersPlaced < iMajorCivs && m_iRequiredSeparation >= 0)198 {199 // Resort by fertility (based on the fact that some of these regions are filling up)200 std::sort(m_StartRegionVector.begin(), m_StartRegionVector.end());201202 // Reduce start distance by 1 (the previous condition could get stuck)203 m_iRequiredSeparation--;204 iNextRegion = 0;205206 while(iPlayersPlaced < iMajorCivs && iNextRegion < m_StartRegionVector.size())207 {208 if(m_StartRegionVector[iNextRegion].m_bLargeEnoughForMajorCiv)209 {210 strString.Format("Trying to place major civ with reduced separation of %d", m_iRequiredSeparation);211 LogStartPositionMessage(strString);212 bool success = AddCivToRegion(m_PlayerOrder[iPlayersPlaced].m_iPlayerID, m_StartRegionVector[iNextRegion], m_iRequiredSeparation < iHalfMinimumDist);213 if(success)214 {215 iPlayersPlaced++;216 m_StartRegionVector[iNextRegion].m_iNumCivsPlaced++;217 }218 }219 iNextRegion++;220 }221 }222223 CvAssertMsg(iPlayersPlaced == iMajorCivs, "AssignStartingLocations() can't find enough starting locations for major civs");224225 // MINOR CIVS226 m_iRequiredSeparation = StartingPlotRange();227228 // Resort by fertility (based on the fact that some of these regions are filling up)229 std::sort(m_StartRegionVector.begin(), m_StartRegionVector.end());230 while(iPlayersPlaced < (int)m_PlayerOrder.size() && iNextRegion < m_StartRegionVector.size())231 {232 strString.Format("Trying to place minor civ with full separation of %d", m_iRequiredSeparation);233 LogStartPositionMessage(strString);234 bool success = AddCivToRegion(m_PlayerOrder[iPlayersPlaced].m_iPlayerID, m_StartRegionVector[iNextRegion], false);235 if(success)236 {237 iPlayersPlaced++;238 m_StartRegionVector[iNextRegion].m_iNumCivsPlaced++;239240 // Sort again, now that the region in slot 0 has another civ placed there241 std::sort(m_StartRegionVector.begin(), m_StartRegionVector.end());242 iNextRegion = 0;243 }244245 // Failed, proceed through list of regions246 else247 {248 iNextRegion++;249 }250 }251252 // MINOR CIVS AGAIN (those that couldn't be placed normal start distance apart)253 while(iPlayersPlaced < (int)m_PlayerOrder.size() && m_iRequiredSeparation >= 0)254 {255 // Resort by fertility (based on the fact that some of these regions are filling up)256 std::sort(m_StartRegionVector.begin(), m_StartRegionVector.end());257258 // Reduce start distance by 10%259 m_iRequiredSeparation--;260 iNextRegion = 0;261262 while(iPlayersPlaced < (int)m_PlayerOrder.size() && iNextRegion < m_StartRegionVector.size())263 {264 strString.Format("Trying to place minor civ with reduced separation of %d", m_iRequiredSeparation);265 LogStartPositionMessage(strString);266 bool success = AddCivToRegion(m_PlayerOrder[iPlayersPlaced].m_iPlayerID, m_StartRegionVector[iNextRegion], false);267 if(success)268 {269 iPlayersPlaced++;270 m_StartRegionVector[iNextRegion].m_iNumCivsPlaced++;271272 // Sort again, now that the region in slot 0 has another civ placed there273 std::sort(m_StartRegionVector.begin(), m_StartRegionVector.end());274 iNextRegion = 0;275 }276277 // Failed, proceed through list of regions278 else279 {280 iNextRegion++;281 }282 }283 }284}