int iYieldValue = 0;
CvWeightedVector<int, SAFE_ESTIMATE_NUM_BUILDINGS, true> validResources;
//notes:
//- economic value is in gold, so use a rough conversion factor for the others
//- for food and gold only surplus is interesting, rest is converted to other yields already
//- ignore trade, as the city might the change owner
iYieldValue += (getYieldRateTimes100(YIELD_FOOD, true) - foodConsumption() * 100) * 3;
iYieldValue += getYieldRateTimes100(YIELD_PRODUCTION, true) * 4;
iYieldValue += getYieldRateTimes100(YIELD_SCIENCE, true) * 3;
iYieldValue += (getYieldRateTimes100(YIELD_GOLD, true) - GetCityBuildings()->GetTotalBaseBuildingMaintenance() * 100) * 1;
iYieldValue += getJONSCulturePerTurn() * 3;
iYieldValue += GetFaithPerTurn() * 3;
#if defined(MOD_API_UNIFIED_YIELDS_TOURISM)
iYieldValue += getYieldRateTimes100(YIELD_TOURISM, true) * 3;
#endif
#if defined(MOD_API_UNIFIED_YIELDS_GOLDEN_AGE)
iYieldValue += getYieldRateTimes100(YIELD_GOLDEN_AGE_POINTS, true) * 3;
#endif
//divide by avg conversion factor
iYieldValue /= 3;
//now check access to resources
//todo: call CvDealAI::GetResourceValue() for each resource
int iWonders = getNumWorldWonders() * 50;
iYieldValue += iWonders;
for (int iI = 0; iI < GetNumWorkablePlots(); iI++)
{
CvPlot* pLoopPlot = GetCityCitizens()->GetCityPlotFromIndex(iI);
//for plots owned by this city
if (NULL != pLoopPlot && GetID() == pLoopPlot->GetCityPurchaseID())
{
//todo: add something for currently unworked plots (future potential)
ResourceTypes eResource = pLoopPlot->getResourceType(getTeam());
if (eResource == NO_RESOURCE)
continue;
const CvResourceInfo* pkResourceInfo = GC.getResourceInfo(eResource);
if (!pkResourceInfo)
continue;
if (GC.getGame().GetGameLeagues()->IsLuxuryHappinessBanned(getOwner(), eResource))
continue;
int iResourceQuantity = pLoopPlot->getNumResource();
validResources.push_back(eResource, iResourceQuantity);
} //owned plots
} //all plots
for (int iPlayerLoop = 0; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++)
{
PlayerTypes ePossibleOwner = (PlayerTypes)iPlayerLoop;
m_aiEconomicValue.setAt(iPlayerLoop, 0); //everybody gets a new value
if (ePossibleOwner != NO_PLAYER && GET_PLAYER(ePossibleOwner).isAlive())
{
int iResourceValue = 0;
if (validResources.size() > 0)
{
for (int iResourceLoop = 0; iResourceLoop < validResources.size(); iResourceLoop++)
{
//todo: add something for currently unworked plots (future potential)
ResourceTypes eResource = (ResourceTypes)validResources.GetElement(iResourceLoop);
if (eResource == NO_RESOURCE)
continue;
if (GET_TEAM(GET_PLAYER(ePossibleOwner).getTeam()).IsResourceObsolete(eResource))
continue;
const CvResourceInfo* pkResourceInfo = GC.getResourceInfo(eResource);
if (!pkResourceInfo)
continue;
int iResourceQuantity = validResources.GetWeight(iResourceLoop);
if (iResourceQuantity > 0)
{
ResourceUsageTypes eUsage = pkResourceInfo->getResourceUsage();
if (eUsage == RESOURCEUSAGE_LUXURY)
{
int iValue = 200;
// If the new owner doesn't have it or the old owner would lose it completely, it's worth more
if ((GET_PLAYER(ePossibleOwner).getNumResourceAvailable(eResource) == 0) || (GET_PLAYER(getOwner()).getNumResourceAvailable(eResource) == iResourceQuantity))
iValue = 600;
int iHappinessFromResource = pkResourceInfo->getHappiness();
iResourceValue += iResourceQuantity * iHappinessFromResource * iValue;
}
else if (eUsage == RESOURCEUSAGE_STRATEGIC)
{
int iValue = 400;
// If the new owner doesn't have it or the old owner would lose it completely, it's worth more
if ((GET_PLAYER(ePossibleOwner).getNumResourceAvailable(eResource) == 0) || (GET_PLAYER(getOwner()).getNumResourceAvailable(eResource) == iResourceQuantity))
iValue = 800;
iResourceValue += iResourceQuantity * iValue;
}
}
}
}
m_aiEconomicValue.setAt(ePossibleOwner, iYieldValue + iResourceValue);
}
}
}