// CvUnit.cpp:5133
bool CvUnit::canUpgrade(UnitTypes eUnit, bool bTestVisible) const
{
CvCity* pCity;
if (eUnit == NO_UNIT)
{
return false;
}
if (!canMove())
{
return false;
}
if (GC.getCivilizationInfo(GET_PLAYER(getOwnerINLINE()).getCivilizationType()).getCivilizationUnits(GC.getUnitInfo(eUnit).getUnitClassType()) != eUnit)
{
return false;
}
if (plot()->getTeam() != getTeam())
{
return false;
}
if (!upgradeAvailable(getUnitType(), ((UnitClassTypes)(GC.getUnitInfo(eUnit).getUnitClassType()))))
{
return false;
}
if (!bTestVisible)
{
if (GET_PLAYER(getOwnerINLINE()).getGold() < upgradePrice(eUnit))
{
return false;
}
}
CLLNode<IDInfo>* pUnitNode = plot()->headUnitNode();
while (pUnitNode != NULL)
{
CvUnit* pLoopUnit = ::getUnit(pUnitNode->m_data);
pUnitNode = plot()->nextUnitNode(pUnitNode);
if (pLoopUnit->getTransportUnit() == this)
{
if (GC.getUnitInfo(eUnit).getSpecialCargo() != NO_SPECIALUNIT)
{
if (GC.getUnitInfo(eUnit).getSpecialCargo() != pLoopUnit->getSpecialUnitType())
{
return false;
}
}
if (GC.getUnitInfo(eUnit).getDomainCargo() != NO_DOMAIN)
{
if (GC.getUnitInfo(eUnit).getDomainCargo() != pLoopUnit->getDomainType())
{
return false;
}
}
}
}
if (GC.getUnitInfo(eUnit).getCargoSpace() < getCargo())
{
return false;
}
pCity = GC.getMapINLINE().findCity(getX_INLINE(), getY_INLINE(), NO_PLAYER, getTeam(), true, (getDomainType() == DOMAIN_SEA));
if (pCity != NULL)
{
if (pCity->canTrain(eUnit))
{
return true;
}
}
return false;
}
// CvMap.cpp:664
CvCity* CvMap::findCity(int iX, int iY, PlayerTypes eOwner, TeamTypes eTeam, bool bSameArea, bool bCoastalOnly, TeamTypes eTeamAtWarWith, DirectionTypes eDirection, CvCity* pSkipCity)
{
PROFILE_FUNC();
CvCity* pLoopCity;
CvCity* pBestCity;
int iValue;
int iBestValue;
int iLoop;
int iI;
// XXX look for barbarian cities???
iBestValue = MAX_INT;
pBestCity = NULL;
for (iI = 0; iI < MAX_PLAYERS; iI++)
{
if (GET_PLAYER((PlayerTypes)iI).isAlive())
{
if ((eOwner == NO_PLAYER) || (iI == eOwner))
{
if ((eTeam == NO_TEAM) || (GET_PLAYER((PlayerTypes)iI).getTeam() == eTeam))
{
for (pLoopCity = GET_PLAYER((PlayerTypes)iI).firstCity(&iLoop); pLoopCity != NULL; pLoopCity = GET_PLAYER((PlayerTypes)iI).nextCity(&iLoop))
{
if (!bSameArea || (pLoopCity->area() == plotINLINE(iX, iY)->area()) || (bCoastalOnly && (pLoopCity->waterArea() == plotINLINE(iX, iY)->area())))
{
if (!bCoastalOnly || pLoopCity->isCoastal(GC.getDefineINT("MIN_WATER_SIZE_FOR_OCEAN")))
{
if ((eTeamAtWarWith == NO_TEAM) || atWar(GET_PLAYER((PlayerTypes)iI).getTeam(), eTeamAtWarWith))
{
if ((eDirection == NO_DIRECTION) || (estimateDirection(dxWrap(pLoopCity->getX_INLINE() - iX), dyWrap(pLoopCity->getY_INLINE() - iY)) == eDirection))
{
if ((pSkipCity == NULL) || (pLoopCity != pSkipCity))
{
iValue = plotDistance(iX, iY, pLoopCity->getX_INLINE(), pLoopCity->getY_INLINE());
if (iValue < iBestValue)
{
iBestValue = iValue;
pBestCity = pLoopCity;
}
}
}
}
}
}
}
}
}
}
}
return pBestCity;
}