void CvGame::assignStartingPlots()
{
PROFILE_FUNC();
CvPlot* pPlot;
CvPlot* pBestPlot;
bool bValid;
int iValue;
int iBestValue;
int iI, iJ, iK;
std::vector<int> aiShuffledPlayers(MAX_PLAYERS);
getSorenRand().shuffleSequence(aiShuffledPlayers, "Team starting plot");
for (iI = 0; iI < MAX_PLAYERS; iI++)
{
PlayerTypes ePlayer = (PlayerTypes) aiShuffledPlayers[iI];
CvPlayer& kPlayer = GET_PLAYER(ePlayer);
if (kPlayer.isAlive())
{
if (kPlayer.getStartingPlot() == NULL)
{
iBestValue = 0;
pBestPlot = NULL;
for (iJ = 0; iJ < GC.getMapINLINE().numPlotsINLINE(); iJ++)
{
gDLL->callUpdater(); // allow window updates during launch
pPlot = GC.getMapINLINE().plotByIndexINLINE(iJ);
if (pPlot->isStartingPlot())
{
bValid = true;
for (iK = 0; iK < MAX_PLAYERS; iK++)
{
if (GET_PLAYER((PlayerTypes)iK).isAlive())
{
if (GET_PLAYER((PlayerTypes)iK).getStartingPlot() == pPlot)
{
bValid = false;
break;
}
}
}
if (bValid)
{
iValue = (1 + getSorenRandNum(1000, "Starting Plot"));
if (iValue > iBestValue)
{
iBestValue = iValue;
pBestPlot = pPlot;
}
}
}
}
if (pBestPlot != NULL)
{
kPlayer.setStartingPlot(pBestPlot, true);
}
}
}
}
if (gDLL->getPythonIFace()->pythonAssignStartingPlots() && !gDLL->getPythonIFace()->pythonUsingDefaultImpl())
{
return; // Python override
}
bool bDone = false;
for (int iPass = 0; iPass < 2 * MAX_PLAYERS && !bDone; iPass++)
{
std::vector<int> aiShuffledTeams(MAX_TEAMS);
getSorenRand().shuffleSequence(aiShuffledTeams, "Team starting plot");
for (iI = 0; iI < MAX_TEAMS; ++iI)
{
TeamTypes eTeam = (TeamTypes) aiShuffledTeams[iI];
CvTeam& kTeam = GET_TEAM(eTeam);
if (kTeam.isAlive())
{
for (iJ = 0; iJ < MAX_PLAYERS; ++iJ)
{
CvPlayer& kPlayer = GET_PLAYER((PlayerTypes)iJ);
if (kPlayer.isAlive() && kPlayer.getTeam() == eTeam)
{
if (kPlayer.getStartingPlot() == NULL)
{
CvPlot* pStartingPlot = kPlayer.findStartingPlot(false);
if (NULL != pStartingPlot)
{
kPlayer.setStartingPlot(pStartingPlot, true);
}
break;
}
}
}
}
}
//check all players have starting plots
bDone = true;
for (iJ = 0; iJ < MAX_PLAYERS; iJ++)
{
if (GET_PLAYER((PlayerTypes)iJ).isAlive() && GET_PLAYER((PlayerTypes)iJ).getStartingPlot() == NULL)
{
bDone = false;
}
}
}
FAssertMsg(bDone, "Player has no starting plot");
}