CvMilitaryAI::GetPowerOfStrongestBuildableUnit(DomainTypes)
- Defined in
- CvMilitaryAI.cpp, line 4106
- Class
- CvMilitaryAI
- Hook name
CivHooks::CvMilitaryAI_GetPowerOfStrongestBuildableUnit
Hooks
static bool BeforeCvMilitaryAI_GetPowerOfStrongestBuildableUnit(CvMilitaryAI* self, DomainTypes eDomain, int& result);static void AfterCvMilitaryAI_GetPowerOfStrongestBuildableUnit(CvMilitaryAI* self, DomainTypes eDomain, int& result);static int ReplaceCvMilitaryAI_GetPowerOfStrongestBuildableUnit(int (*original)(CvMilitaryAI*, DomainTypes), CvMilitaryAI* self, DomainTypes eDomain);CivRegisterBefore<CivHooks::CvMilitaryAI_GetPowerOfStrongestBuildableUnit>(host, &BeforeCvMilitaryAI_GetPowerOfStrongestBuildableUnit);CivRegisterAfter<CivHooks::CvMilitaryAI_GetPowerOfStrongestBuildableUnit>(host, &AfterCvMilitaryAI_GetPowerOfStrongestBuildableUnit);CivRegisterReplace<CivHooks::CvMilitaryAI_GetPowerOfStrongestBuildableUnit>(host, &ReplaceCvMilitaryAI_GetPowerOfStrongestBuildableUnit);
Code
4105/// How strong is the best unit we can train for this domain?4106int CvMilitaryAI::GetPowerOfStrongestBuildableUnit(DomainTypes eDomain)4107{4108 int iRtnValue = 0;4109 for(int iI = 0; iI < GC.getNumUnitInfos(); iI++)4110 {4111 const UnitTypes eUnit = static_cast<UnitTypes>(iI);4112 CvUnitEntry* pkUnitEntry = GC.getUnitInfo(eUnit);4113 if(pkUnitEntry != NULL && pkUnitEntry->GetDomainType() == eDomain)4114 {4115 int iThisPower = pkUnitEntry->GetPower(); // Test the power first, it is much less costly than testing canTrain4116 if(iThisPower > iRtnValue)4117 {4118 if(m_pPlayer->canTrain(eUnit, false /*bContinue*/, false /*bTestVisible*/, true /*bIgnoreCost*/))4119 {4120 iRtnValue = iThisPower;4121 }4122 }4123 }4124 }41254126 return iRtnValue;4127}