PlayerTypes CvCity::getLiberationPlayer(bool bConquest) const
{
if (isCapital())
{
return NO_PLAYER;
}
for (int iPlayer = 0; iPlayer < MAX_CIV_PLAYERS; ++iPlayer)
{
CvPlayer& kLoopPlayer = GET_PLAYER((PlayerTypes)iPlayer);
if (kLoopPlayer.isAlive() && kLoopPlayer.getParent() == getOwnerINLINE())
{
CvCity* pLoopCapital = kLoopPlayer.getCapitalCity();
if (NULL != pLoopCapital)
{
if (pLoopCapital->area() == area())
{
return (PlayerTypes)iPlayer;
}
}
}
}
CvPlayer& kOwner = GET_PLAYER(getOwnerINLINE());
if (kOwner.canSplitEmpire() && kOwner.canSplitArea(area()->getID()))
{
PlayerTypes ePlayer = GET_PLAYER(getOwnerINLINE()).getSplitEmpirePlayer(area()->getID());
if (NO_PLAYER != ePlayer)
{
if (GET_PLAYER(ePlayer).isAlive())
{
return ePlayer;
}
}
}
PlayerTypes eBestPlayer = NO_PLAYER;
int iBestValue = 0;
int iTotalCultureTimes100 = countTotalCultureTimes100();
for (int iPlayer = 0; iPlayer < MAX_CIV_PLAYERS; ++iPlayer)
{
CvPlayer& kLoopPlayer = GET_PLAYER((PlayerTypes)iPlayer);
if (kLoopPlayer.isAlive())
{
if (kLoopPlayer.canReceiveTradeCity())
{
CvCity* pCapital = kLoopPlayer.getCapitalCity();
if (NULL != pCapital)
{
int iCapitalDistance = :
lotDistance(getX_INLINE(), getY_INLINE(), pCapital->getX_INLINE(), pCapital->getY_INLINE());
if (area() != pCapital->area())
{
iCapitalDistance *= 2;
}
int iCultureTimes100 = getCultureTimes100((PlayerTypes)iPlayer);
if (bConquest)
{
if (iPlayer == getOriginalOwner())
{
iCultureTimes100 *= 3;
iCultureTimes100 /= 2;
}
}
if (GET_PLAYER((PlayerTypes)iPlayer).getTeam() == getTeam()
|| GET_TEAM(GET_PLAYER((PlayerTypes)iPlayer).getTeam()).isVassal(getTeam())
|| GET_TEAM(getTeam()).isVassal(GET_PLAYER((PlayerTypes)iPlayer).getTeam()))
{
iCultureTimes100 *= 2;
iCultureTimes100 = (iCultureTimes100 + iTotalCultureTimes100) / 2;
}
int iValue = std::max(100, iCultureTimes100) / std::max(1, iCapitalDistance);
if (iValue > iBestValue)
{
iBestValue = iValue;
eBestPlayer = (PlayerTypes)iPlayer;
}
}
}
}
}
if (NO_PLAYER != eBestPlayer)
{
if (getOwnerINLINE() == eBestPlayer)
{
return NO_PLAYER;
}
for (int iPlot = 0; iPlot < NUM_CITY_PLOTS; ++iPlot)
{
CvPlot* pLoopPlot = :
lotCity(getX_INLINE(), getY_INLINE(), iPlot);
if (NULL != pLoopPlot)
{
if (pLoopPlot->isVisibleEnemyUnit(eBestPlayer))
{
return NO_PLAYER;
}
}
}
}
return eBestPlayer;
}