Bazaar developer reference

MilitaryAIHelpers::FirstSlotCityCanFill(CvPlayer *, MultiunitFormationTypes, bool, bool, bool)

Defined in
CvMilitaryAI.cpp, line 5153
Hook name
CivHooks::MilitaryAIHelpers_FirstSlotCityCanFill

Hooks

static bool BeforeMilitaryAIHelpers_FirstSlotCityCanFill(CvPlayer* pPlayer, MultiunitFormationTypes formation, bool bRequiresNavalMoves, bool bAtCoastalCity, bool bSecondaryUnit, UnitAITypes& result);static void AfterMilitaryAIHelpers_FirstSlotCityCanFill(CvPlayer* pPlayer, MultiunitFormationTypes formation, bool bRequiresNavalMoves, bool bAtCoastalCity, bool bSecondaryUnit, UnitAITypes& result);static UnitAITypes ReplaceMilitaryAIHelpers_FirstSlotCityCanFill(UnitAITypes (*original)(CvPlayer*, MultiunitFormationTypes, bool, bool, bool), CvPlayer* pPlayer, MultiunitFormationTypes formation, bool bRequiresNavalMoves, bool bAtCoastalCity, bool bSecondaryUnit);CivRegisterBefore<CivHooks::MilitaryAIHelpers_FirstSlotCityCanFill>(host, &BeforeMilitaryAIHelpers_FirstSlotCityCanFill);CivRegisterAfter<CivHooks::MilitaryAIHelpers_FirstSlotCityCanFill>(host, &AfterMilitaryAIHelpers_FirstSlotCityCanFill);CivRegisterReplace<CivHooks::MilitaryAIHelpers_FirstSlotCityCanFill>(host, &ReplaceMilitaryAIHelpers_FirstSlotCityCanFill);

Code

5152/// Army needs more units, which should we build next?5153UnitAITypes MilitaryAIHelpers::FirstSlotCityCanFill(CvPlayer* pPlayer, MultiunitFormationTypes formation, bool bRequiresNavalMoves, bool bAtCoastalCity, bool bSecondaryUnit)5154{5155	CvUnit* pLoopUnit;5156	int iLoop;5157	FStaticVector< CvFormationSlotEntry, 10, false, c_eCiv5GameplayDLL > slotsToFill;5158	FStaticVector< CvFormationSlotEntry, 10, false, c_eCiv5GameplayDLL >::iterator it;51595160	CvMultiUnitFormationInfo* thisFormation = GC.getMultiUnitFormationInfo(formation);5161	for(int iThisSlotIndex = 0; iThisSlotIndex < thisFormation->getNumFormationSlotEntries(); iThisSlotIndex++)5162	{5163		const CvFormationSlotEntry& thisSlotEntry = thisFormation->getFormationSlotEntry(iThisSlotIndex);5164		slotsToFill.push_back(thisSlotEntry);5165	}51665167	bool bMustBeDeepWaterNaval = GET_TEAM(pPlayer->getTeam()).canEmbarkAllWaterPassage() && thisFormation->IsRequiresNavalUnitConsistency();51685169	for(pLoopUnit = pPlayer->firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = pPlayer->nextUnit(&iLoop))5170	{5171		// Don't count scouts5172		if(pLoopUnit->AI_getUnitAIType() != UNITAI_EXPLORE && pLoopUnit->AI_getUnitAIType() != UNITAI_EXPLORE_SEA)5173		{5174			// Don't count units that are damaged too heavily5175			if(pLoopUnit->GetCurrHitPoints() >= pLoopUnit->GetMaxHitPoints() * GC.getAI_OPERATIONAL_PERCENT_HEALTH_FOR_OPERATION() / 100)5176			{5177				if(pLoopUnit->getArmyID() == FFreeList::INVALID_INDEX && pLoopUnit->canRecruitFromTacticalAI())5178				{5179					if(pLoopUnit->GetDeployFromOperationTurn() + GC.getAI_TACTICAL_MAP_TEMP_ZONE_TURNS() < GC.getGame().getGameTurn())5180					{5181						if(!bRequiresNavalMoves || pLoopUnit->getDomainType() == DOMAIN_SEA || pLoopUnit->CanEverEmbark())5182						{5183							if (!bMustBeDeepWaterNaval || pLoopUnit->getDomainType() != DOMAIN_SEA || !pLoopUnit->isTerrainImpassable(TERRAIN_OCEAN))5184							{5185								for(it = slotsToFill.begin(); it != slotsToFill.end(); it++)5186								{5187									CvFormationSlotEntry slotEntry = *it;5188									CvUnitEntry& kUnitInfo = pLoopUnit->getUnitInfo();5189									if(kUnitInfo.GetUnitAIType((UnitAITypes)slotEntry.m_primaryUnitType) ||5190										kUnitInfo.GetUnitAIType((UnitAITypes)slotEntry.m_secondaryUnitType))5191									{5192										slotsToFill.erase(it);5193										break;5194									}5195								}5196							}5197						}5198					}5199				}5200			}5201		}5202	}52035204	// If coastal city, try to find the first one that is a naval AI type5205	if(bAtCoastalCity)5206	{5207		for(int iThisSlotIndex = 0; iThisSlotIndex < (int)slotsToFill.size(); iThisSlotIndex++)5208		{5209			if(slotsToFill[iThisSlotIndex].m_requiredSlot)5210			{5211				UnitAITypes eType = (UnitAITypes)slotsToFill[iThisSlotIndex].m_primaryUnitType;5212				if(eType == UNITAI_ASSAULT_SEA || eType == UNITAI_ATTACK_SEA || eType == UNITAI_RESERVE_SEA || eType == UNITAI_ESCORT_SEA)5213				{5214					if(!bSecondaryUnit)5215					{5216						return (UnitAITypes)slotsToFill[iThisSlotIndex].m_primaryUnitType;5217					}5218					else5219					{5220						return (UnitAITypes)slotsToFill[iThisSlotIndex].m_secondaryUnitType;5221					}5222				}5223			}5224		}5225	}52265227	// Now go back through remaining slots and find first required one5228	for(int iThisSlotIndex = 0; iThisSlotIndex < (int)slotsToFill.size(); iThisSlotIndex++)5229	{5230		if(slotsToFill[iThisSlotIndex].m_requiredSlot)5231		{5232			if(!bSecondaryUnit)5233			{5234				return (UnitAITypes)slotsToFill[iThisSlotIndex].m_primaryUnitType;5235			}5236			else5237			{5238				return (UnitAITypes)slotsToFill[iThisSlotIndex].m_secondaryUnitType;5239			}5240		}5241	}52425243	return NO_UNITAI;5244}

Calls

Called by