Bazaar developer reference

CvEconomicAI::GetBestGreatWorkCity(CvPlot *, GreatWorkType) const

Defined in
CvEconomicAI.cpp, line 887
Class
CvEconomicAI
Hook name
CivHooks::CvEconomicAI_GetBestGreatWorkCity

Hooks

static bool BeforeCvEconomicAI_GetBestGreatWorkCity(const CvEconomicAI* self, CvPlot * pStartPlot, GreatWorkType eGreatWork, CvCity*& result);static void AfterCvEconomicAI_GetBestGreatWorkCity(const CvEconomicAI* self, CvPlot * pStartPlot, GreatWorkType eGreatWork, CvCity*& result);static CvCity* ReplaceCvEconomicAI_GetBestGreatWorkCity(CvCity* (*original)(const CvEconomicAI*, CvPlot *, GreatWorkType), const CvEconomicAI* self, CvPlot * pStartPlot, GreatWorkType eGreatWork);CivRegisterBefore<CivHooks::CvEconomicAI_GetBestGreatWorkCity>(host, &BeforeCvEconomicAI_GetBestGreatWorkCity);CivRegisterAfter<CivHooks::CvEconomicAI_GetBestGreatWorkCity>(host, &AfterCvEconomicAI_GetBestGreatWorkCity);CivRegisterReplace<CivHooks::CvEconomicAI_GetBestGreatWorkCity>(host, &ReplaceCvEconomicAI_GetBestGreatWorkCity);

Code

886/// Find the best city to create a Great Work in887CvCity* CvEconomicAI::GetBestGreatWorkCity(CvPlot *pStartPlot, GreatWorkType eGreatWork) const888{889	CvCity* pBestCity = NULL;890	CvCity* pLoopCity;891	int iLoop;892	int iBestDistance = MAX_INT;893894	// Make sure there is an undamaged city with a Great Work slot895	GreatWorkSlotType eGreatWorkSlot = CultureHelpers::GetGreatWorkSlot(eGreatWork);896	if (m_pPlayer->GetCulture()->HasAvailableGreatWorkSlot(eGreatWorkSlot))897	{898		for(pLoopCity = m_pPlayer->firstCity(&iLoop); pLoopCity != NULL; pLoopCity = m_pPlayer->nextCity(&iLoop))899		{900			if (pLoopCity->getDamage() == 0)901			{902				int iDistance = plotDistance(pStartPlot->getX(), pStartPlot->getY(), pLoopCity->getX(), pLoopCity->getY());903				if(iDistance < iBestDistance)904				{905					iBestDistance = iDistance;906					pBestCity = pLoopCity;907				}908			}909		}910	}911912	return pBestCity;913}

Calls

Called by