CvMilitaryAI::GetMostThreatenedCity(int)
- Defined in
- CvMilitaryAI.cpp, line 1644
- Class
- CvMilitaryAI
- Hook name
CivHooks::CvMilitaryAI_GetMostThreatenedCity
Hooks
static bool BeforeCvMilitaryAI_GetMostThreatenedCity(CvMilitaryAI* self, int iOrder, CvCity*& result);static void AfterCvMilitaryAI_GetMostThreatenedCity(CvMilitaryAI* self, int iOrder, CvCity*& result);static CvCity* ReplaceCvMilitaryAI_GetMostThreatenedCity(CvCity* (*original)(CvMilitaryAI*, int), CvMilitaryAI* self, int iOrder);CivRegisterBefore<CivHooks::CvMilitaryAI_GetMostThreatenedCity>(host, &BeforeCvMilitaryAI_GetMostThreatenedCity);CivRegisterAfter<CivHooks::CvMilitaryAI_GetMostThreatenedCity>(host, &AfterCvMilitaryAI_GetMostThreatenedCity);CivRegisterReplace<CivHooks::CvMilitaryAI_GetMostThreatenedCity>(host, &ReplaceCvMilitaryAI_GetMostThreatenedCity);
Code
1643/// Which city is in the most danger now?1644CvCity* CvMilitaryAI::GetMostThreatenedCity(int iOrder)1645{1646 // slewis - this is slow, but I did it quickly!16471648 FFastVector<CvCity*> m_apCities;1649 m_apCities.push_back_copy(NULL, iOrder + 1);16501651 for(int iCycle = 0; iCycle < iOrder + 1; iCycle++)1652 {1653 CvCity* pCity = NULL;1654 int iHighestThreatValue = 0;16551656 CvCity* pLoopCity;1657 int iLoopCity = 0;1658 for(pLoopCity = m_pPlayer->firstCity(&iLoopCity); pLoopCity != NULL; pLoopCity = m_pPlayer->nextCity(&iLoopCity))1659 {1660 bool bCityAlreadyExamined = false;1661 for(uint ui = 0; ui < m_apCities.size(); ui++)1662 {1663 if(pLoopCity == m_apCities[ui])1664 {1665 bCityAlreadyExamined = true;1666 break;1667 }1668 }1669 if(bCityAlreadyExamined)1670 {1671 continue;1672 }16731674 int iThreatValue = pLoopCity->getThreatValue();1675 iThreatValue = iThreatValue * pLoopCity->getPopulation();16761677 if(pLoopCity->isCapital())1678 {1679 iThreatValue = (iThreatValue * GC.getAI_MILITARY_CITY_THREAT_WEIGHT_CAPITAL()) / 100;1680 }16811682 if(iThreatValue > iHighestThreatValue)1683 {1684 pCity = pLoopCity;1685 iHighestThreatValue = iThreatValue;1686 }1687 }16881689 if(pCity)1690 {1691 m_apCities[iCycle] = pCity;1692 }1693 else1694 {1695 // we didn't find a city, so bail1696 break;1697 }1698 }16991700 return m_apCities[iOrder];1701}
Calls
BaseVector::operator[]BaseVector::size- CvCity::getPopulation(bool) const
- CvCity::getThreatValue()
- CvCity::isCapital() const
- CvGlobals::getAI_MILITARY_CITY_THREAT_WEIGHT_CAPITAL()
- CvPlayer::firstCity(int *, bool)
- CvPlayer::nextCity(int *, bool)
FFastVector::FFastVectorFFastVector::push_back_copy