CvMilitaryAI::GetNearestCoastalCity(PlayerTypes) const
- Defined in
- CvMilitaryAI.cpp, line 1476
- Class
- CvMilitaryAI
- Hook name
CivHooks::CvMilitaryAI_GetNearestCoastalCity
Hooks
static bool BeforeCvMilitaryAI_GetNearestCoastalCity(const CvMilitaryAI* self, PlayerTypes eEnemy, CvCity*& result);static void AfterCvMilitaryAI_GetNearestCoastalCity(const CvMilitaryAI* self, PlayerTypes eEnemy, CvCity*& result);static CvCity* ReplaceCvMilitaryAI_GetNearestCoastalCity(CvCity* (*original)(const CvMilitaryAI*, PlayerTypes), const CvMilitaryAI* self, PlayerTypes eEnemy);CivRegisterBefore<CivHooks::CvMilitaryAI_GetNearestCoastalCity>(host, &BeforeCvMilitaryAI_GetNearestCoastalCity);CivRegisterAfter<CivHooks::CvMilitaryAI_GetNearestCoastalCity>(host, &AfterCvMilitaryAI_GetNearestCoastalCity);CivRegisterReplace<CivHooks::CvMilitaryAI_GetNearestCoastalCity>(host, &ReplaceCvMilitaryAI_GetNearestCoastalCity);
Code
1475/// Find the port operation operations against this enemy should leave from1476CvCity* CvMilitaryAI::GetNearestCoastalCity(PlayerTypes eEnemy) const1477{1478 CvCity* pBestCoastalCity = NULL;1479 CvCity* pLoopCity, *pEnemyCity;1480 int iLoop, iEnemyLoop;1481 int iBestDistance = MAX_INT;14821483 for(pLoopCity = m_pPlayer->firstCity(&iLoop); pLoopCity != NULL; pLoopCity = m_pPlayer->nextCity(&iLoop))1484 {1485 if(pLoopCity->isCoastal())1486 {1487 for(pEnemyCity = GET_PLAYER(eEnemy).firstCity(&iEnemyLoop); pEnemyCity != NULL; pEnemyCity = GET_PLAYER(eEnemy).nextCity(&iEnemyLoop))1488 {1489 // Check all revealed enemy cities1490 if(pEnemyCity->isCoastal() && pEnemyCity->plot()->isRevealed(m_pPlayer->getTeam()))1491 {1492 // On same body of water?1493 if(OnSameBodyOfWater(pLoopCity, pEnemyCity))1494 {1495 int iDistance = plotDistance(pLoopCity->getX(), pLoopCity->getY(), pEnemyCity->getX(), pEnemyCity->getY());1496 if(iDistance < iBestDistance)1497 {1498 iBestDistance = iDistance;1499 pBestCoastalCity = pLoopCity;1500 }1501 }1502 }1503 }1504 }1505 }15061507 return pBestCoastalCity;1508}
Calls
- CvCity::getX() const
- CvCity::getY() const
- CvCity::isCoastal(int) const
- CvCity::plot() const
- CvPlayer::firstCity(int *, bool)
- CvPlayer::getTeam() const
- CvPlayer::nextCity(int *, bool)
- CvPlayerAI::getPlayer(PlayerTypes)
- CvPlot::isRevealed(TeamTypes) const
- OnSameBodyOfWater(CvCity *, CvCity *)
- plotDistance(int, int, int, int)