Bazaar developer reference

EconomicAIHelpers::IsTestStrategy_TradeWithCityState(EconomicAIStrategyTypes, CvPlayer *)

Defined in
CvEconomicAI.cpp, line 3697
Hook name
CivHooks::EconomicAIHelpers_IsTestStrategy_TradeWithCityState

Hooks

static bool BeforeEconomicAIHelpers_IsTestStrategy_TradeWithCityState(EconomicAIStrategyTypes eStrategy, CvPlayer* pPlayer, bool& result);static void AfterEconomicAIHelpers_IsTestStrategy_TradeWithCityState(EconomicAIStrategyTypes eStrategy, CvPlayer* pPlayer, bool& result);static bool ReplaceEconomicAIHelpers_IsTestStrategy_TradeWithCityState(bool (*original)(EconomicAIStrategyTypes, CvPlayer*), EconomicAIStrategyTypes eStrategy, CvPlayer* pPlayer);CivRegisterBefore<CivHooks::EconomicAIHelpers_IsTestStrategy_TradeWithCityState>(host, &BeforeEconomicAIHelpers_IsTestStrategy_TradeWithCityState);CivRegisterAfter<CivHooks::EconomicAIHelpers_IsTestStrategy_TradeWithCityState>(host, &AfterEconomicAIHelpers_IsTestStrategy_TradeWithCityState);CivRegisterReplace<CivHooks::EconomicAIHelpers_IsTestStrategy_TradeWithCityState>(host, &ReplaceEconomicAIHelpers_IsTestStrategy_TradeWithCityState);

Code

3696/// "Trade with City State" Player Strategy: If there is a merchant who isn't in an operation?  If so, find him a city state3697bool EconomicAIHelpers::IsTestStrategy_TradeWithCityState(EconomicAIStrategyTypes eStrategy, CvPlayer* pPlayer)3698{3699	int iUnitLoop;3700	CvUnit* pLoopUnit;3701	int iLooseMerchant = 0;3702	int iStrategyWeight = 0;37033704	// Never run this strategy for a human player3705	if(!pPlayer->isHuman())3706	{3707		// Look at map for loose merchants3708		for(pLoopUnit = pPlayer->firstUnit(&iUnitLoop); pLoopUnit != NULL; pLoopUnit = pPlayer->nextUnit(&iUnitLoop))3709		{3710			if(pLoopUnit != NULL)3711			{3712				if(pLoopUnit->AI_getUnitAIType() == UNITAI_MERCHANT && pLoopUnit->GetGreatPeopleDirective() == GREAT_PEOPLE_DIRECTIVE_USE_POWER)3713				{3714					if(pLoopUnit->getArmyID() == FFreeList::INVALID_INDEX)3715					{3716						iLooseMerchant++;3717					}3718				}3719			}3720		}37213722		CvEconomicAIStrategyXMLEntry* pStrategy = pPlayer->GetEconomicAI()->GetEconomicAIStrategies()->GetEntry(eStrategy);3723		iStrategyWeight = iLooseMerchant * 10;   // Just one merchant will trigger this3724		int iWeightThresholdModifier = GetWeightThresholdModifier(eStrategy, pPlayer);3725		int iWeightThreshold = pStrategy->GetWeightThreshold() + iWeightThresholdModifier;37263727		if(iStrategyWeight >= iWeightThreshold)3728		{3729			// Launch an operation.3730			pPlayer->addAIOperation(AI_OPERATION_MERCHANT_DELEGATION);37313732			// Set this strategy active3733			return true;3734		}3735	}37363737	return false;3738}

Calls

Called by