Hooks
static bool BeforeMilitaryAIHelpers_NumberOfFillableSlots(CvPlayer* pPlayer, MultiunitFormationTypes formation, bool bRequiresNavalMoves, int* piNumberSlotsRequired, int* piNumberLandReservesUsed, int& result);static void AfterMilitaryAIHelpers_NumberOfFillableSlots(CvPlayer* pPlayer, MultiunitFormationTypes formation, bool bRequiresNavalMoves, int* piNumberSlotsRequired, int* piNumberLandReservesUsed, int& result);static int ReplaceMilitaryAIHelpers_NumberOfFillableSlots(int (*original)(CvPlayer*, MultiunitFormationTypes, bool, int*, int*), CvPlayer* pPlayer, MultiunitFormationTypes formation, bool bRequiresNavalMoves, int* piNumberSlotsRequired, int* piNumberLandReservesUsed);CivRegisterBefore<CivHooks::MilitaryAIHelpers_NumberOfFillableSlots>(host, &BeforeMilitaryAIHelpers_NumberOfFillableSlots);CivRegisterAfter<CivHooks::MilitaryAIHelpers_NumberOfFillableSlots>(host, &AfterMilitaryAIHelpers_NumberOfFillableSlots);CivRegisterReplace<CivHooks::MilitaryAIHelpers_NumberOfFillableSlots>(host, &ReplaceMilitaryAIHelpers_NumberOfFillableSlots);
Code
5072/// How many slots in this army can we fill right now with available units?5073int MilitaryAIHelpers::NumberOfFillableSlots(CvPlayer* pPlayer, MultiunitFormationTypes formation, bool bRequiresNavalMoves, int* piNumberSlotsRequired, int* piNumberLandReservesUsed)5074{5075 CvUnit* pLoopUnit;5076 int iLoop;5077 FStaticVector< CvFormationSlotEntry, 10, false, c_eCiv5GameplayDLL > slotsToFill;5078 FStaticVector< CvFormationSlotEntry, 10, false, c_eCiv5GameplayDLL >::iterator it;5079 int iWillBeFilled = 0;5080 int iLandReservesUsed = 0;50815082 CvMultiUnitFormationInfo* thisFormation = GC.getMultiUnitFormationInfo(formation);5083 for(int iThisSlotIndex = 0; iThisSlotIndex < thisFormation->getNumFormationSlotEntries(); iThisSlotIndex++)5084 {5085 const CvFormationSlotEntry& thisSlotEntry = thisFormation->getFormationSlotEntry(iThisSlotIndex);5086 slotsToFill.push_back(thisSlotEntry);5087 }50885089 bool bMustBeDeepWaterNaval = GET_TEAM(pPlayer->getTeam()).canEmbarkAllWaterPassage() && thisFormation->IsRequiresNavalUnitConsistency();50905091 for(pLoopUnit = pPlayer->firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = pPlayer->nextUnit(&iLoop))5092 {5093 // Don't count scouts5094 if(pLoopUnit->AI_getUnitAIType() != UNITAI_EXPLORE && pLoopUnit->AI_getUnitAIType() != UNITAI_EXPLORE_SEA)5095 {5096 // Don't count units that are damaged too heavily5097 if(pLoopUnit->GetCurrHitPoints() >= pLoopUnit->GetMaxHitPoints() * GC.getAI_OPERATIONAL_PERCENT_HEALTH_FOR_OPERATION() / 100)5098 {5099 if(pLoopUnit->getArmyID() == FFreeList::INVALID_INDEX && pLoopUnit->canRecruitFromTacticalAI())5100 {5101 if(pLoopUnit->GetDeployFromOperationTurn() + GC.getAI_TACTICAL_MAP_TEMP_ZONE_TURNS() < GC.getGame().getGameTurn())5102 {5103 if(!bRequiresNavalMoves || pLoopUnit->getDomainType() == DOMAIN_SEA || pLoopUnit->CanEverEmbark())5104 {5105 if (!bMustBeDeepWaterNaval || pLoopUnit->getDomainType() != DOMAIN_SEA || !pLoopUnit->isTerrainImpassable(TERRAIN_OCEAN))5106 {5107 for(it = slotsToFill.begin(); it != slotsToFill.end(); it++)5108 {5109 CvFormationSlotEntry slotEntry = *it;5110 CvUnitEntry& kUnitInfo = pLoopUnit->getUnitInfo();5111 if(kUnitInfo.GetUnitAIType((UnitAITypes)slotEntry.m_primaryUnitType) ||5112 kUnitInfo.GetUnitAIType((UnitAITypes)slotEntry.m_secondaryUnitType))5113 {5114 slotsToFill.erase(it);5115 iWillBeFilled++;51165117 if(pLoopUnit->getDomainType() == DOMAIN_LAND)5118 {5119 iLandReservesUsed++;5120 }5121 break;5122 }5123 }5124 }5125 }5126 }5127 }5128 }5129 }5130 }51315132 // Now go back through remaining slots and see how many were required, we'll need that many more units5133 if(piNumberSlotsRequired != NULL)5134 {5135 (*piNumberSlotsRequired) = iWillBeFilled;5136 for(int iThisSlotIndex = 0; iThisSlotIndex < (int)slotsToFill.size(); iThisSlotIndex++)5137 {5138 if(slotsToFill[iThisSlotIndex].m_requiredSlot)5139 {5140 (*piNumberSlotsRequired)++;5141 }5142 }5143 }51445145 if(piNumberLandReservesUsed != NULL)5146 {5147 *piNumberLandReservesUsed = iLandReservesUsed;5148 }5149 return iWillBeFilled;5150}