CivicTypes CvPlayerAI::AI_bestCivic(CivicOptionTypes eCivicOption)
{
CivicTypes eBestCivic;
int iValue;
int iBestValue;
int iI;
iBestValue = MIN_INT;
eBestCivic = NO_CIVIC;
for (iI = 0; iI < GC.getNumCivicInfos(); iI++)
{
if (GC.getCivicInfo((CivicTypes)iI).getCivicOptionType() == eCivicOption)
{
if (canDoCivics((CivicTypes)iI))
{
iValue = AI_civicValue((CivicTypes)iI);
if (isCivic((CivicTypes)iI))
{
iValue *= 6;
iValue /= 5;
}
if (iValue > iBestValue)
{
iBestValue = iValue;
eBestCivic = ((CivicTypes)iI);
}
}
}
}
return eBestCivic;
}
int CvPlayerAI::AI_civicValue(CivicTypes eCivic)
{
PROFILE_FUNC();
bool bWarPlan;
int iConnectedForeignCities;
int iTotalReligonCount;
int iHighestReligionCount;
int iHappiness;
int iValue;
int iTempValue;
int iI, iJ;
FAssertMsg(eCivic < GC.getNumCivicInfos(), "eCivic is expected to be within maximum bounds (invalid Index)");
FAssertMsg(eCivic >= 0, "eCivic is expected to be non-negative (invalid Index)");
bWarPlan = (GET_TEAM(getTeam()).getAnyWarPlanCount(true) > 0);
iConnectedForeignCities = countPotentialForeignTradeCitiesConnected();
iTotalReligonCount = countTotalHasReligion();
iHighestReligionCount = findHighestHasReligionCount();
iValue = (getNumCities() * 6);
iValue += (GC.getCivicInfo(eCivic).getAIWeight() * getNumCities());
iValue += (getCivicPercentAnger(eCivic) / 10);
iValue += -(GC.getCivicInfo(eCivic).getAnarchyLength() * getNumCities());
iValue += -(getSingleCivicUpkeep(eCivic, true));
iValue += ((GC.getCivicInfo(eCivic).getGreatPeopleRateModifier() * getNumCities()) / 10);
iValue += -((GC.getCivicInfo(eCivic).getDistanceMaintenanceModifier() * max(0, (getNumCities() - 3))) / 8);
iValue += -((GC.getCivicInfo(eCivic).getNumCitiesMaintenanceModifier() * max(0, (getNumCities() - 3))) / 8);
iValue += ((GC.getCivicInfo(eCivic).getExtraHealth() * getTotalPopulation()) / 16);
iValue += (GC.getCivicInfo(eCivic).getFreeExperience() * getNumCities() * ((bWarPlan) ? 6 : 2));
iValue += ((GC.getCivicInfo(eCivic).getWorkerSpeedModifier() * AI_getNumAIUnits(UNITAI_WORKER)) / 4);
iValue += ((GC.getCivicInfo(eCivic).getImprovementUpgradeRateModifier() * getNumCities()) / 50);
iValue += ((GC.getCivicInfo(eCivic).getMilitaryProductionModifier() * getNumCities()) / ((bWarPlan) ? 5 : 20));
iValue += (GC.getCivicInfo(eCivic).getBaseFreeUnits() / 2);
iValue += (GC.getCivicInfo(eCivic).getBaseFreeMilitaryUnits() / 3);
iValue += ((GC.getCivicInfo(eCivic).getFreeUnitsPopulationPercent() * getTotalPopulation()) / 200);
iValue += ((GC.getCivicInfo(eCivic).getFreeMilitaryUnitsPopulationPercent() * getTotalPopulation()) / 300);
iValue += -(GC.getCivicInfo(eCivic).getGoldPerUnit() * getNumUnits());
iValue += -(GC.getCivicInfo(eCivic).getGoldPerMilitaryUnit() * getNumMilitaryUnits());
iValue += ((GC.getCivicInfo(eCivic).getHappyPerMilitaryUnit() * getTotalPopulation()) / 5);
//iValue += ((GC.getCivicInfo(eCivic).isMilitaryFoodProduction()) ? 0 : 0);
iValue += (getWorldSizeMaxConscript(eCivic) * ((bWarPlan) ? 8 : 2));
iValue += ((GC.getCivicInfo(eCivic).isNoUnhealthyPopulation()) ? (getTotalPopulation() / 3) : 0);
iValue += ((GC.getCivicInfo(eCivic).isBuildingOnlyHealthy()) ? (getNumCities() * 3) : 0);
iValue += (GC.getCivicInfo(eCivic).getLargestCityHappiness() * min(getNumCities(), GC.getWorldInfo(GC.getMapINLINE().getWorldSize()).getTargetNumCities()) * 6);
iValue += -((GC.getCivicInfo(eCivic).getWarWearinessModifier() * getNumCities()) / ((bWarPlan) ? 20 : 100));
iValue += (GC.getCivicInfo(eCivic).getFreeSpecialist() * getNumCities() * 12);
iValue += (GC.getCivicInfo(eCivic).getTradeRoutes() * max(getNumCities(), iConnectedForeignCities) * 6);
iValue += -((GC.getCivicInfo(eCivic).isNoForeignTrade()) ? (iConnectedForeignCities * 3) : 0);
iValue += ((GC.getCivicInfo(eCivic).getCivicPercentAnger() * (GC.getGameINLINE().getNumCities() - getNumCities())) / 10);
iValue += (GC.getCivicInfo(eCivic).getNonStateReligionHappiness() * (iTotalReligonCount - iHighestReligionCount) * 5);
if (GC.getCivicInfo(eCivic).isStateReligion())
{
if (iHighestReligionCount > 0)
{
iValue += iHighestReligionCount;
iValue += ((GC.getCivicInfo(eCivic).isNoNonStateReligionSpread()) ? ((getNumCities() - iHighestReligionCount) * 2) : 0);
iValue += (GC.getCivicInfo(eCivic).getStateReligionHappiness() * iHighestReligionCount * 4);
iValue += ((GC.getCivicInfo(eCivic).getStateReligionGreatPeopleRateModifier() * iHighestReligionCount) / 8);
iValue += ((GC.getCivicInfo(eCivic).getStateReligionUnitProductionModifier() * iHighestReligionCount) / 4);
iValue += ((GC.getCivicInfo(eCivic).getStateReligionBuildingProductionModifier() * iHighestReligionCount) / 3);
iValue += (GC.getCivicInfo(eCivic).getStateReligionFreeExperience() * iHighestReligionCount * ((bWarPlan) ? 6 : 2));
}
}
for (iI = 0; iI < NUM_YIELD_TYPES; iI++)
{
iTempValue = 0;
iTempValue += ((GC.getCivicInfo(eCivic).getYieldModifier(iI) * getNumCities()) / 2);
iTempValue += ((GC.getCivicInfo(eCivic).getCapitalYieldModifier(iI) * 3) / 4);
iTempValue += ((GC.getCivicInfo(eCivic).getTradeYieldModifier(iI) * getNumCities()) / 6);
for (iJ = 0; iJ < GC.getNumImprovementInfos(); iJ++)
{
iTempValue += (GC.getCivicInfo(eCivic).getImprovementYieldChanges(iJ, iI) * getImprovementCount((ImprovementTypes)iJ) * 3);
}
iTempValue *= AI_yieldWeight((YieldTypes)iI);
iTempValue /= 100;
iValue += iTempValue;
}
for (iI = 0; iI < NUM_COMMERCE_TYPES; iI++)
{
iTempValue = 0;
iTempValue += ((GC.getCivicInfo(eCivic).getCommerceModifier(iI) * getNumCities()) / 3);
iTempValue += (GC.getCivicInfo(eCivic).getCapitalCommerceModifier(iI) / 2);
iTempValue += ((GC.getCivicInfo(eCivic).getSpecialistExtraCommerce(iI) * getTotalPopulation()) / 6);
iTempValue *= AI_commerceWeight((CommerceTypes)iI);
iTempValue /= 100;
iValue += iTempValue;
}
for (iI = 0; iI < GC.getNumBuildingInfos(); iI++)
{
if (GC.getCivicInfo(eCivic).getBuildingHappinessChanges(iI) != 0)
{
iValue += (GC.getCivicInfo(eCivic).getBuildingHappinessChanges(iI) * countNumBuildings((BuildingTypes)iI) * 4);
}
}
for (iI = 0; iI < GC.getNumFeatureInfos(); iI++)
{
iHappiness = GC.getCivicInfo(eCivic).getFeatureHappinessChanges(iI);
if (iHappiness != 0)
{
iValue += (iHappiness * countCityFeatures((FeatureTypes)iI) * 3);
}
}
for (iI = 0; iI < GC.getNumHurryInfos(); iI++)
{
if (GC.getCivicInfo(eCivic).isHurry(iI))
{
iTempValue = 0;
if (GC.getHurryInfo((HurryTypes)iI).getGoldPerProduction() > 0)
{
iTempValue += ((((AI_avoidScience()) ? 50 : 25) * getNumCities()) / GC.getHurryInfo((HurryTypes)iI).getGoldPerProduction());
}
iTempValue += ((GC.getHurryInfo((HurryTypes)iI).getProductionPerPopulation() * getNumCities()) / 5);
iValue += iTempValue;
}
}
for (iI = 0; iI < GC.getNumSpecialBuildingInfos(); iI++)
{
if (GC.getCivicInfo(eCivic).isSpecialBuildingNotRequired(iI))
{
iValue += ((getNumCities() / 2) + 1); // XXX
}
}
for (iI = 0; iI < GC.getNumSpecialistInfos(); iI++)
{
if (GC.getCivicInfo(eCivic).isSpecialistValid(iI))
{
iValue += ((getNumCities() / 3) + 1); // XXX
}
}
if (GC.getLeaderHeadInfo(getPersonalityType()).getFavoriteCivic() == eCivic)
{
iValue += (getNumCities() * 25);
}
return iValue;
}