Bazaar developer reference

CvMilitaryAI::GetUnitForArmy(CvCity *) const

Defined in
CvMilitaryAI.cpp, line 3712
Class
CvMilitaryAI
Hook name
CivHooks::CvMilitaryAI_GetUnitForArmy

Hooks

static bool BeforeCvMilitaryAI_GetUnitForArmy(const CvMilitaryAI* self, CvCity* pCity, UnitTypes& result);static void AfterCvMilitaryAI_GetUnitForArmy(const CvMilitaryAI* self, CvCity* pCity, UnitTypes& result);static UnitTypes ReplaceCvMilitaryAI_GetUnitForArmy(UnitTypes (*original)(const CvMilitaryAI*, CvCity*), const CvMilitaryAI* self, CvCity* pCity);CivRegisterBefore<CivHooks::CvMilitaryAI_GetUnitForArmy>(host, &BeforeCvMilitaryAI_GetUnitForArmy);CivRegisterAfter<CivHooks::CvMilitaryAI_GetUnitForArmy>(host, &AfterCvMilitaryAI_GetUnitForArmy);CivRegisterReplace<CivHooks::CvMilitaryAI_GetUnitForArmy>(host, &ReplaceCvMilitaryAI_GetUnitForArmy);

Code

3711/// Which unit should be built next for our army3712UnitTypes CvMilitaryAI::GetUnitForArmy(CvCity* pCity) const3713{3714	if(m_eArmyTypeBeingBuilt == NO_ARMY_TYPE)3715	{3716		return NO_UNIT;3717	}37183719	// Look for required units first3720	MultiunitFormationTypes eFormation;3721	if(m_eArmyTypeBeingBuilt == ARMY_TYPE_NAVAL_INVASION)3722	{3723		eFormation = MUFORMATION_NAVAL_INVASION;3724	}3725	else3726	{3727		eFormation = (GC.getGame().getHandicapInfo().GetID() > 4 && !(GC.getMap().GetAIMapHint() & 1)) ? MUFORMATION_BIGGER_CITY_ATTACK_FORCE : MUFORMATION_BASIC_CITY_ATTACK_FORCE;3728	}3729	UnitAITypes eUnitAIType = MilitaryAIHelpers::FirstSlotCityCanFill(m_pPlayer, eFormation, (m_eArmyTypeBeingBuilt == ARMY_TYPE_NAVAL_INVASION), pCity->isCoastal(), false /*bSecondaryUnit*/);3730	UnitTypes eType = pCity->GetCityStrategyAI()->GetUnitProductionAI()->RecommendUnit(eUnitAIType);3731	if(eType == NO_UNIT)3732	{3733		eUnitAIType = MilitaryAIHelpers::FirstSlotCityCanFill(m_pPlayer, eFormation, (m_eArmyTypeBeingBuilt == ARMY_TYPE_NAVAL_INVASION), pCity->isCoastal(), true /*bSecondaryUnit*/);3734		eType = pCity->GetCityStrategyAI()->GetUnitProductionAI()->RecommendUnit(eUnitAIType);3735	}3736	return eType;3737}

Calls

Called by