Bazaar developer reference

CvCity::GetUnitForOperation()

Defined in
CvCity.cpp, line 17000
Class
CvCity
Hook name
CivHooks::CvCity_GetUnitForOperation

Hooks

static bool BeforeCvCity_GetUnitForOperation(CvCity* self, UnitTypes& result);static void AfterCvCity_GetUnitForOperation(CvCity* self, UnitTypes& result);static UnitTypes ReplaceCvCity_GetUnitForOperation(UnitTypes (*original)(CvCity*), CvCity* self);CivRegisterBefore<CivHooks::CvCity_GetUnitForOperation>(host, &BeforeCvCity_GetUnitForOperation);CivRegisterAfter<CivHooks::CvCity_GetUnitForOperation>(host, &AfterCvCity_GetUnitForOperation);CivRegisterReplace<CivHooks::CvCity_GetUnitForOperation>(host, &ReplaceCvCity_GetUnitForOperation);

Code

16999/// Which unit would we build if we are building one for an operation?17000UnitTypes CvCity::GetUnitForOperation()17001{17002	VALIDATE_OBJECT17003	UnitTypes eBestUnit;17004	UnitAITypes eUnitAI;1700517006	CvPlayerAI& kPlayer = GET_PLAYER(getOwner());1700717008	OperationSlot thisOperationSlot = kPlayer.PeekAtNextUnitToBuildForOperationSlot(getArea());1700917010	if(thisOperationSlot.IsValid())17011	{17012		CvArmyAI* pThisArmy = kPlayer.getArmyAI(thisOperationSlot.m_iArmyID);1701317014		if(pThisArmy)17015		{17016			// figure out the primary and secondary unit type to potentially build17017			int iFormationIndex = pThisArmy->GetFormationIndex();17018			CvMultiUnitFormationInfo* thisFormation = GC.getMultiUnitFormationInfo(iFormationIndex);17019			if(thisFormation)17020			{17021				const CvFormationSlotEntry& slotEntry = thisFormation->getFormationSlotEntry(thisOperationSlot.m_iSlotID);1702217023				eUnitAI = (UnitAITypes)slotEntry.m_primaryUnitType;17024				eBestUnit = m_pCityStrategyAI->GetUnitProductionAI()->RecommendUnit(eUnitAI);17025				if(eBestUnit == NO_UNIT)17026				{17027					eUnitAI = (UnitAITypes)slotEntry.m_secondaryUnitType;17028					eBestUnit = m_pCityStrategyAI->GetUnitProductionAI()->RecommendUnit(eUnitAI);17029				}1703017031				if(eBestUnit != NO_UNIT)17032				{17033					return eBestUnit;17034				}17035			}17036		}17037	}17038	return NO_UNIT;17039}

Calls

Called by