Bazaar developer reference

EconomicAIHelpers::IsTestStrategy_CitiesNeedNavalGrowth(EconomicAIStrategyTypes, CvPlayer *)

Defined in
CvEconomicAI.cpp, line 3504
Hook name
CivHooks::EconomicAIHelpers_IsTestStrategy_CitiesNeedNavalGrowth

Hooks

static bool BeforeEconomicAIHelpers_IsTestStrategy_CitiesNeedNavalGrowth(EconomicAIStrategyTypes eStrategy, CvPlayer* pPlayer, bool& result);static void AfterEconomicAIHelpers_IsTestStrategy_CitiesNeedNavalGrowth(EconomicAIStrategyTypes eStrategy, CvPlayer* pPlayer, bool& result);static bool ReplaceEconomicAIHelpers_IsTestStrategy_CitiesNeedNavalGrowth(bool (*original)(EconomicAIStrategyTypes, CvPlayer*), EconomicAIStrategyTypes eStrategy, CvPlayer* pPlayer);CivRegisterBefore<CivHooks::EconomicAIHelpers_IsTestStrategy_CitiesNeedNavalGrowth>(host, &BeforeEconomicAIHelpers_IsTestStrategy_CitiesNeedNavalGrowth);CivRegisterAfter<CivHooks::EconomicAIHelpers_IsTestStrategy_CitiesNeedNavalGrowth>(host, &AfterEconomicAIHelpers_IsTestStrategy_CitiesNeedNavalGrowth);CivRegisterReplace<CivHooks::EconomicAIHelpers_IsTestStrategy_CitiesNeedNavalGrowth>(host, &ReplaceEconomicAIHelpers_IsTestStrategy_CitiesNeedNavalGrowth);

Code

3503/// "Cities Need Naval Growth" Player Strategy: Looks at how many of this player's Cities need NAVAL_GROWTH, and depending on the intrinsic NAVAL_GROWTH Flavor decides whether or not it's worth prioritizing this Flavor on an empire-wide scale3504bool EconomicAIHelpers::IsTestStrategy_CitiesNeedNavalGrowth(EconomicAIStrategyTypes eStrategy, CvPlayer* pPlayer)3505{3506	int iNumCitiesNeedNavalGrowth = 0;35073508	CvCity* pLoopCity;3509	int iLoop;35103511	AICityStrategyTypes eStrategyNeedNavalGrowth = (AICityStrategyTypes) GC.getInfoTypeForString("AICITYSTRATEGY_NEED_NAVAL_GROWTH");35123513	// CityStrategy doesn't exist in XML, so abort3514	if(eStrategyNeedNavalGrowth == NO_AICITYSTRATEGY)3515	{3516		return false;3517	}35183519	for(pLoopCity = pPlayer->firstCity(&iLoop); pLoopCity != NULL; pLoopCity = pPlayer->nextCity(&iLoop))3520	{3521		if(pLoopCity->GetCityStrategyAI()->IsUsingCityStrategy(eStrategyNeedNavalGrowth))3522		{3523			iNumCitiesNeedNavalGrowth++;3524		}3525	}35263527	if(iNumCitiesNeedNavalGrowth > 0)3528	{3529		CvEconomicAIStrategyXMLEntry* pStrategy = pPlayer->GetEconomicAI()->GetEconomicAIStrategies()->GetEntry(eStrategy);3530		int iWeightThresholdModifier = GetWeightThresholdModifier(eStrategy, pPlayer);	// 1 Weight per NAVAL_GROWTH Flavor3531		int iWeightThreshold = pStrategy->GetWeightThreshold() + iWeightThresholdModifier;	// 2535323533		int iCurrentWeight = (pPlayer->getNumCities() - 1) * 10;3534		iCurrentWeight /= iWeightThreshold;35353536		// See CvStrategyAI::IsTestStrategy_CitiesNeedBorders for a couple examples on how the math here works35373538		// Do enough of our Cities want NavalGrowth? [Average is 10/30; range is 10/25 to 10/35]3539//		if (iNumCitiesNeedNavalGrowth > (GetPlayer()->getNumCities() - 1) / GC.getAI_STRATEGY_CITIES_NAVAL_GROWTH_DIVISOR())	// 33540		if(iNumCitiesNeedNavalGrowth > iCurrentWeight)3541		{3542			return true;3543		}3544	}35453546	return false;3547}

Calls

Called by