Bazaar developer reference

CvCitySpecializationAI::FindBestSites()

Defined in
CvCitySpecializationAI.cpp, line 1159
Class
CvCitySpecializationAI
Hook name
CivHooks::CvCitySpecializationAI_FindBestSites

Hooks

static bool BeforeCvCitySpecializationAI_FindBestSites(CvCitySpecializationAI* self);static void AfterCvCitySpecializationAI_FindBestSites(CvCitySpecializationAI* self);static void ReplaceCvCitySpecializationAI_FindBestSites(void (*original)(CvCitySpecializationAI*), CvCitySpecializationAI* self);CivRegisterBefore<CivHooks::CvCitySpecializationAI_FindBestSites>(host, &BeforeCvCitySpecializationAI_FindBestSites);CivRegisterAfter<CivHooks::CvCitySpecializationAI_FindBestSites>(host, &AfterCvCitySpecializationAI_FindBestSites);CivRegisterReplace<CivHooks::CvCitySpecializationAI_FindBestSites>(host, &ReplaceCvCitySpecializationAI_FindBestSites);

Code

1158/// Find the best nearby city site for all yield types1159void CvCitySpecializationAI::FindBestSites()1160{1161	CvPlot* pPlot;1162	int iPlotValue;1163	int iPlotLoop;1164	CvCity* pNearestCity;11651166	// Clear output1167	for(int iI = 0; iI <= YIELD_SCIENCE; iI++)1168	{1169		m_iBestValue[iI] = 0;1170	}11711172	// Found value drops off based on distance, so safe to only look halfway out1173	int iEvalDistance = GC.getSETTLER_EVALUATION_DISTANCE() / 2;11741175	CvSiteEvaluatorForSettler* pSiteEval = GC.getGame().GetSettlerSiteEvaluator();1176	for(iPlotLoop = 0; iPlotLoop < GC.getMap().numPlots(); iPlotLoop++)1177	{1178		pPlot = GC.getMap().plotByIndexUnchecked(iPlotLoop);11791180		if(pSiteEval->CanFound(pPlot, m_pPlayer, true))1181		{1182			// Check if within range of any of our cities1183			pNearestCity = GC.getMap().findCity(pPlot->getX(), pPlot->getY(), m_pPlayer->GetID(), NO_TEAM, true /* bSameArea */);1184			if(pNearestCity != NULL)1185			{1186				if(plotDistance(pPlot->getX(), pPlot->getY(), pNearestCity->getX(), pNearestCity->getY()) <= iEvalDistance)1187				{1188					for(int iI = 0; iI <= YIELD_SCIENCE; iI++)1189					{1190						if(iI != YIELD_SCIENCE)1191						{1192							iPlotValue = PlotValueForSpecificYield(pPlot, (YieldTypes)iI);1193						}1194						else1195						{1196							iPlotValue = PlotValueForScience(pPlot);1197						}11981199						if(iPlotValue > m_iBestValue[iI])1200						{1201							m_iBestValue[iI] = iPlotValue;1202						}1203					}1204				}1205			}1206		}1207	}12081209	LogBestSites();12101211	return;1212}

Calls

Called by