Bazaar developer reference

CvCity::CommitToBuildingUnitForOperation()

Defined in
CvCity.cpp, line 16952
Class
CvCity
Hook name
CivHooks::CvCity_CommitToBuildingUnitForOperation

Hooks

static bool BeforeCvCity_CommitToBuildingUnitForOperation(CvCity* self, bool& result);static void AfterCvCity_CommitToBuildingUnitForOperation(CvCity* self, bool& result);static bool ReplaceCvCity_CommitToBuildingUnitForOperation(bool (*original)(CvCity*), CvCity* self);CivRegisterBefore<CivHooks::CvCity_CommitToBuildingUnitForOperation>(host, &BeforeCvCity_CommitToBuildingUnitForOperation);CivRegisterAfter<CivHooks::CvCity_CommitToBuildingUnitForOperation>(host, &AfterCvCity_CommitToBuildingUnitForOperation);CivRegisterReplace<CivHooks::CvCity_CommitToBuildingUnitForOperation>(host, &ReplaceCvCity_CommitToBuildingUnitForOperation);

Code

16951/// Build a unit needed to fill in an army for an operation16952bool CvCity::CommitToBuildingUnitForOperation()16953{16954	VALIDATE_OBJECT16955	UnitTypes eBestUnit;16956	UnitAITypes eUnitAI;1695716958	CvPlayerAI& kPlayer = GET_PLAYER(getOwner());1695916960	OperationSlot thisOperationSlot = kPlayer.PeekAtNextUnitToBuildForOperationSlot(getArea());1696116962	if(thisOperationSlot.IsValid())16963	{1696416965		CvArmyAI* pThisArmy = kPlayer.getArmyAI(thisOperationSlot.m_iArmyID);1696616967		if(pThisArmy)16968		{16969			// figure out the primary and secondary unit type to potentially build16970			int iFormationIndex = pThisArmy->GetFormationIndex();16971			CvMultiUnitFormationInfo* thisFormation = GC.getMultiUnitFormationInfo(iFormationIndex);16972			if(thisFormation)16973			{16974				const CvFormationSlotEntry& slotEntry = thisFormation->getFormationSlotEntry(thisOperationSlot.m_iSlotID);1697516976				eUnitAI = (UnitAITypes)slotEntry.m_primaryUnitType;16977				eBestUnit = m_pCityStrategyAI->GetUnitProductionAI()->RecommendUnit(eUnitAI);16978				if(eBestUnit == NO_UNIT)16979				{16980					eUnitAI = (UnitAITypes)slotEntry.m_secondaryUnitType;16981					eBestUnit = m_pCityStrategyAI->GetUnitProductionAI()->RecommendUnit(eUnitAI);16982				}1698316984				if(eBestUnit != NO_UNIT)16985				{16986					// Always try to rush units for operational AI if possible16987					pushOrder(ORDER_TRAIN, eBestUnit, eUnitAI, false, false, false, true /*bRush*/);16988					OperationSlot thisOperationSlot2 = kPlayer.CityCommitToBuildUnitForOperationSlot(getArea(), getProductionTurnsLeft(), this);16989					m_unitBeingBuiltForOperation = thisOperationSlot2;16990					return true;16991				}16992			}16993		}16994	}16995	return false;16996}

Calls

Called by