Bazaar developer reference

CvCity::GetIndividualPlotScore(const CvPlot *) const

Defined in
CvCity.cpp, line 12595
Class
CvCity
Hook name
CivHooks::CvCity_GetIndividualPlotScore

Hooks

static bool BeforeCvCity_GetIndividualPlotScore(const CvCity* self, const CvPlot* pPlot, int& result);static void AfterCvCity_GetIndividualPlotScore(const CvCity* self, const CvPlot* pPlot, int& result);static int ReplaceCvCity_GetIndividualPlotScore(int (*original)(const CvCity*, const CvPlot*), const CvCity* self, const CvPlot* pPlot);CivRegisterBefore<CivHooks::CvCity_GetIndividualPlotScore>(host, &BeforeCvCity_GetIndividualPlotScore);CivRegisterAfter<CivHooks::CvCity_GetIndividualPlotScore>(host, &AfterCvCity_GetIndividualPlotScore);CivRegisterReplace<CivHooks::CvCity_GetIndividualPlotScore>(host, &ReplaceCvCity_GetIndividualPlotScore);

Code

12594/// Compute value of a plot we might buy12595int CvCity::GetIndividualPlotScore(const CvPlot* pPlot) const12596{12597	VALIDATE_OBJECT12598	int iRtnValue = 0;12599	ResourceTypes eResource;12600	int iYield;12601	int iI;12602	YieldTypes eSpecializationYield = NO_YIELD;12603	CitySpecializationTypes eSpecialization;12604	CvCity* pCity;1260512606	eSpecialization = GetCityStrategyAI()->GetSpecialization();1260712608	if(eSpecialization != NO_CITY_SPECIALIZATION)12609	{12610		eSpecializationYield = GC.getCitySpecializationInfo(eSpecialization)->GetYieldType();12611	}1261212613	// Does it have a resource?12614	eResource = pPlot->getResourceType(getTeam());12615	if(eResource != NO_RESOURCE)12616	{12617		CvResourceInfo *pkResource = GC.getResourceInfo(eResource);12618		if (pkResource)12619		{12620			if(GET_TEAM(getTeam()).GetTeamTechs()->HasTech((TechTypes)pkResource->getTechReveal()))12621			{12622				int iRevealPolicy = pkResource->getPolicyReveal();12623				if (iRevealPolicy == NO_POLICY || GET_PLAYER(getOwner()).GetPlayerPolicies()->HasPolicy((PolicyTypes)iRevealPolicy))12624				{12625					ResourceUsageTypes eResourceUsage = GC.getResourceInfo(eResource)->getResourceUsage();12626					if(eResourceUsage == RESOURCEUSAGE_STRATEGIC)12627					{12628						iRtnValue += /* 50 */ GC.getAI_PLOT_VALUE_STRATEGIC_RESOURCE();12629					}1263012631					// Luxury resource?12632					else if(eResourceUsage == RESOURCEUSAGE_LUXURY)12633					{12634						int iLuxuryValue = /* 40 */ GC.getAI_PLOT_VALUE_LUXURY_RESOURCE();1263512636						// Luxury we don't have yet?12637						if(GET_PLAYER(getOwner()).getNumResourceTotal(eResource) == 0)12638							iLuxuryValue *= 2;1263912640						iRtnValue += iLuxuryValue;12641					}12642				}12643			}12644		}12645	}1264612647	int iYieldValue = 0;12648	int iTempValue;1264912650	YieldTypes eYield;1265112652	CvCityStrategyAI* pCityStrategyAI = GetCityStrategyAI();1265312654	// Valuate the yields from this plot12655	for(iI = 0; iI < NUM_YIELD_TYPES; iI++)12656	{12657		eYield = (YieldTypes) iI;1265812659		iYield = pPlot->calculateNatureYield(eYield, getTeam());12660		iTempValue = 0;1266112662		if(eYield == eSpecializationYield)12663			iTempValue += iYield* /*20*/ GC.getAI_PLOT_VALUE_SPECIALIZATION_MULTIPLIER();1266412665		else12666			iTempValue += iYield* /*10*/ GC.getAI_PLOT_VALUE_YIELD_MULTIPLIER();1266712668		// Deficient? If so, give it a boost12669		if(pCityStrategyAI->IsYieldDeficient(eYield))12670			iTempValue *= /*5*/ GC.getAI_PLOT_VALUE_DEFICIENT_YIELD_MULTIPLIER();1267112672		iYieldValue += iTempValue;12673	}1267412675	iRtnValue += iYieldValue;1267612677	// For each player not on our team, check how close their nearest city is to this plot12678	CvPlayer& owningPlayer = GET_PLAYER(m_eOwner);12679	CvDiplomacyAI* owningPlayerDiploAI = owningPlayer.GetDiplomacyAI();12680	for(iI = 0; iI < MAX_MAJOR_CIVS; iI++)12681	{12682		CvPlayer& loopPlayer = GET_PLAYER((PlayerTypes)iI);12683		if(loopPlayer.isAlive())12684		{12685			if(loopPlayer.getTeam() != getTeam())12686			{12687				DisputeLevelTypes eLandDisputeLevel = owningPlayerDiploAI->GetLandDisputeLevel((PlayerTypes)iI);1268812689				if(eLandDisputeLevel != NO_DISPUTE_LEVEL && eLandDisputeLevel != DISPUTE_LEVEL_NONE)12690				{12691					pCity = GC.getMap().findCity(pPlot->getX(), pPlot->getY(), (PlayerTypes)iI, NO_TEAM, true /*bSameArea */);1269212693					if(pCity)12694					{12695						int iDistance = plotDistance(pPlot->getX(), pPlot->getY(), pCity->getX(), pCity->getY());1269612697						// Only want to account for civs with a city within 10 tiles12698						if(iDistance < 10)12699						{12700							switch(eLandDisputeLevel)12701							{12702							case DISPUTE_LEVEL_FIERCE:12703								iRtnValue += (10 - iDistance) * /* 6 */ GC.getAI_PLOT_VALUE_FIERCE_DISPUTE();12704								break;12705							case DISPUTE_LEVEL_STRONG:12706								iRtnValue += (10 - iDistance) * /* 4 */GC.getAI_PLOT_VALUE_STRONG_DISPUTE();12707								break;12708							case DISPUTE_LEVEL_WEAK:12709								iRtnValue += (10 - iDistance) * /* 2 */ GC.getAI_PLOT_VALUE_WEAK_DISPUTE();12710								break;12711							}12712						}12713					}12714				}12715			}12716		}12717	}1271812719	// Modify value based on cost - the higher it is compared to the "base" cost the less the value12720	int iCost = GetBuyPlotCost(pPlot->getX(), pPlot->getY());12721	iRtnValue *= GET_PLAYER(getOwner()).GetBuyPlotCost();1272212723	// Protect against div by 0.12724	CvAssertMsg(iCost != 0, "Plot cost is 0");12725	if(iCost != 0)12726		iRtnValue /= iCost;12727	else12728		iRtnValue = 0;1272912730	return iRtnValue;12731}

Calls

Called by