CvAIOperation::GetOperationStartCity() const
- Defined in
- CvAIOperation.cpp, line 869
- Class
- CvAIOperation
- Hook name
CivHooks::CvAIOperation_GetOperationStartCity- Overridden by
- CvAINavalEscortedOperation::GetOperationStartCity() const, CvAINavalOperation::GetOperationStartCity() const, CvAIOperationNukeAttack::GetOperationStartCity() const
Hooks
static bool BeforeCvAIOperation_GetOperationStartCity(const CvAIOperation* self, CvCity*& result);static void AfterCvAIOperation_GetOperationStartCity(const CvAIOperation* self, CvCity*& result);static CvCity* ReplaceCvAIOperation_GetOperationStartCity(CvCity* (*original)(const CvAIOperation*), const CvAIOperation* self);CivRegisterBefore<CivHooks::CvAIOperation_GetOperationStartCity>(host, &BeforeCvAIOperation_GetOperationStartCity);CivRegisterAfter<CivHooks::CvAIOperation_GetOperationStartCity>(host, &AfterCvAIOperation_GetOperationStartCity);CivRegisterReplace<CivHooks::CvAIOperation_GetOperationStartCity>(host, &ReplaceCvAIOperation_GetOperationStartCity);
Code
868/// Find the area where our operation is occurring869CvCity* CvAIOperation::GetOperationStartCity() const870{871 if(GetStartCityPlot())872 {873 return GetStartCityPlot()->getPlotCity();874 }875876 CvCity* pCapitalCity;877 CvArea* pLoopArea;878 int iLoop;879 int iMyCities;880 int iEnemyCities;881 int iBestTotal = 0;882 CvArea* pBestArea = NULL;883 CvCity* pBestCity = NULL;884885 CvPlayer& thisPlayer = GET_PLAYER(m_eOwner);886887 // Do we still have a capital?888 pCapitalCity = thisPlayer.getCapitalCity();889890 if(pCapitalCity != NULL)891 {892 return pCapitalCity;893 }894895 // No capital, find the area with the most combined cities between us and our enemy (and need at least 1 from each)896 for(pLoopArea = GC.getMap().firstArea(&iLoop); pLoopArea != NULL; pLoopArea = GC.getMap().nextArea(&iLoop))897 {898 if(pLoopArea->isWater())899 {900 continue;901 }902903 iMyCities = pLoopArea->getCitiesPerPlayer(GetOwner());904 if(iMyCities > 0)905 {906 if(m_eEnemy != NO_PLAYER && m_eEnemy != BARBARIAN_PLAYER)907 {908 iEnemyCities = pLoopArea->getCitiesPerPlayer(m_eEnemy);909 if(iEnemyCities == 0)910 {911 continue;912 }913 }914 else915 {916 iEnemyCities = 0;917 }918919 if((iMyCities + iEnemyCities) > iBestTotal)920 {921 iBestTotal = iMyCities + iEnemyCities;922 pBestArea = pLoopArea;923 }924 }925 }926927 if(pBestArea != NULL)928 {929 // Know which continent to use, now use our largest city there as the start city930 CvCity* pCity;931 iBestTotal = 0;932 for(pCity = thisPlayer.firstCity(&iLoop); pCity != NULL; pCity = thisPlayer.nextCity(&iLoop))933 {934 if(pCity->getArea() == pBestArea->GetID())935 {936 if(pCity->getPopulation() > iBestTotal)937 {938 iBestTotal = pCity->getPopulation();939 pBestCity = pCity;940 }941 }942 }943 return pBestCity;944 }945 else946 {947 return NULL;948 }949}
Calls
- CvAIOperation::GetOwner() const
- CvAIOperation::GetStartCityPlot() const
- CvArea::getCitiesPerPlayer(PlayerTypes) const
- CvArea::GetID() const
- CvArea::isWater() const
- CvCity::getArea() const
- CvCity::getPopulation(bool) const
- CvGlobals::getMap()
- CvMap::firstArea(int *, bool)
- CvMap::nextArea(int *, bool)
- CvPlayer::firstCity(int *, bool)
- CvPlayer::getCapitalCity()
- CvPlayer::nextCity(int *, bool)
- CvPlayerAI::getPlayer(PlayerTypes)
- CvPlot::getPlotCity() const