MilitaryAIHelpers::ComputeRecommendedNavySize(CvPlayer *)
- Defined in
- CvMilitaryAI.cpp, line 5014
- Hook name
CivHooks::MilitaryAIHelpers_ComputeRecommendedNavySize
Hooks
static bool BeforeMilitaryAIHelpers_ComputeRecommendedNavySize(CvPlayer* pPlayer, int& result);static void AfterMilitaryAIHelpers_ComputeRecommendedNavySize(CvPlayer* pPlayer, int& result);static int ReplaceMilitaryAIHelpers_ComputeRecommendedNavySize(int (*original)(CvPlayer*), CvPlayer* pPlayer);CivRegisterBefore<CivHooks::MilitaryAIHelpers_ComputeRecommendedNavySize>(host, &BeforeMilitaryAIHelpers_ComputeRecommendedNavySize);CivRegisterAfter<CivHooks::MilitaryAIHelpers_ComputeRecommendedNavySize>(host, &AfterMilitaryAIHelpers_ComputeRecommendedNavySize);CivRegisterReplace<CivHooks::MilitaryAIHelpers_ComputeRecommendedNavySize>(host, &ReplaceMilitaryAIHelpers_ComputeRecommendedNavySize);
Code
5013/// How many military units should we have given current threats?5014int MilitaryAIHelpers::ComputeRecommendedNavySize(CvPlayer* pPlayer)5015{5016 int iNumUnitsWanted = 0;5017 int iFlavorNaval = pPlayer->GetGrandStrategyAI()->GetPersonalityAndGrandStrategy((FlavorTypes)GC.getInfoTypeForString("FLAVOR_NAVAL"));5018 // cap at 10?50195020 double dMultiplier;50215022 // Start with 15023 iNumUnitsWanted = 1;50245025 int iNumCoastalCities = 0;5026 int iLoop;5027 CvCity* pCity;5028 for(pCity = pPlayer->firstCity(&iLoop); pCity != NULL; pCity = pPlayer->nextCity(&iLoop))5029 {5030 if(pCity->isCoastal(-1))5031 {5032 iNumCoastalCities++;5033 }5034 }50355036 iNumUnitsWanted += iNumCoastalCities;5037 // Scale up or down based on true threat level and a bit by flavors (multiplier should range from about 0.75 to 2.0)5038 dMultiplier = (double)0.75 + ((double)pPlayer->GetMilitaryAI()->GetHighestThreat() / (double)4.0) + ((double)(iFlavorNaval) / (double)40.0);5039 iNumUnitsWanted = (int)((double)iNumUnitsWanted * dMultiplier* /*0.67*/ GC.getAI_STRATEGY_NAVAL_UNITS_PER_CITY());50405041 iNumUnitsWanted = max(1,iNumUnitsWanted);50425043 EconomicAIStrategyTypes eStrategyNavalMap = (EconomicAIStrategyTypes) GC.getInfoTypeForString("ECONOMICAISTRATEGY_NAVAL_MAP");5044 EconomicAIStrategyTypes eExpandOtherContinents = (EconomicAIStrategyTypes) GC.getInfoTypeForString("ECONOMICAISTRATEGY_EXPAND_TO_OTHER_CONTINENTS");5045 if (pPlayer->GetEconomicAI()->IsUsingStrategy(eStrategyNavalMap) || pPlayer->GetEconomicAI()->IsUsingStrategy(eExpandOtherContinents))5046 {5047 iNumUnitsWanted *= 3;5048 iNumUnitsWanted /= 2;5049 }50505051 if (pPlayer->getCivilizationInfo().isCoastalCiv())5052 {5053 iNumUnitsWanted *= 3;5054 iNumUnitsWanted /= 2;5055 }50565057 // if we are going for conquest we want at least one more task force5058 int iGT = GC.getGame().getGameTurn();5059 iGT = min(iGT,200);5060 AIGrandStrategyTypes eConquestGrandStrategy = (AIGrandStrategyTypes) GC.getInfoTypeForString("AIGRANDSTRATEGY_CONQUEST");5061 if(eConquestGrandStrategy != NO_AIGRANDSTRATEGY)5062 {5063 if(pPlayer->GetGrandStrategyAI()->GetActiveGrandStrategy() == eConquestGrandStrategy)5064 {5065 iNumUnitsWanted += (10 * iGT) / 200;5066 }5067 }50685069 return iNumUnitsWanted;5070}
Calls
- CvCity::isCoastal(int) const
- CvCivilizationInfo::isCoastalCiv() const
- CvEconomicAI::IsUsingStrategy(EconomicAIStrategyTypes)
- CvGame::getGameTurn()
- CvGlobals::getAI_STRATEGY_NAVAL_UNITS_PER_CITY()
- CvGlobals::getGame()
- CvGlobals::getInfoTypeForString(const char *, bool) const
- CvGrandStrategyAI::GetActiveGrandStrategy() const
- CvGrandStrategyAI::GetPersonalityAndGrandStrategy(FlavorTypes, bool)
- CvMilitaryAI::GetHighestThreat()
- CvPlayer::firstCity(int *, bool)
- CvPlayer::getCivilizationInfo() const
- CvPlayer::GetEconomicAI() const
- CvPlayer::GetGrandStrategyAI() const
- CvPlayer::GetMilitaryAI() const
- CvPlayer::nextCity(int *, bool)
std::maxstd::min