MilitaryAIHelpers::IsTestStrategy_NeedAirCarriers(CvPlayer *)
- Defined in
- CvMilitaryAI.cpp, line 4940
- Hook name
CivHooks::MilitaryAIHelpers_IsTestStrategy_NeedAirCarriers
Hooks
static bool BeforeMilitaryAIHelpers_IsTestStrategy_NeedAirCarriers(CvPlayer* pPlayer, bool& result);static void AfterMilitaryAIHelpers_IsTestStrategy_NeedAirCarriers(CvPlayer* pPlayer, bool& result);static bool ReplaceMilitaryAIHelpers_IsTestStrategy_NeedAirCarriers(bool (*original)(CvPlayer*), CvPlayer* pPlayer);CivRegisterBefore<CivHooks::MilitaryAIHelpers_IsTestStrategy_NeedAirCarriers>(host, &BeforeMilitaryAIHelpers_IsTestStrategy_NeedAirCarriers);CivRegisterAfter<CivHooks::MilitaryAIHelpers_IsTestStrategy_NeedAirCarriers>(host, &AfterMilitaryAIHelpers_IsTestStrategy_NeedAirCarriers);CivRegisterReplace<CivHooks::MilitaryAIHelpers_IsTestStrategy_NeedAirCarriers>(host, &ReplaceMilitaryAIHelpers_IsTestStrategy_NeedAirCarriers);
Code
4939/// "Need Air Carrier" Player Strategy: If a player needs some aircraft carriers4940bool MilitaryAIHelpers::IsTestStrategy_NeedAirCarriers(CvPlayer* pPlayer)4941{4942 int iNumLoadableAirUnits = 0;4943 int iNumTotalCargoSpace = 0;4944#if defined(MOD_AI_SMART_V3)4945 int iNumCargoUnits = 0;4946 int iNumNavalUnits = 0;4947#endif4948 CvUnit* pLoopUnit;4949 int iLoop;4950 SpecialUnitTypes eSpecialUnitPlane = (SpecialUnitTypes) GC.getInfoTypeForString("SPECIALUNIT_FIGHTER");4951 for(pLoopUnit = pPlayer->firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = pPlayer->nextUnit(&iLoop))4952 {4953 // Don't count civilians or exploration units4954 if(pLoopUnit->AI_getUnitAIType() != UNITAI_EXPLORE && pLoopUnit->AI_getUnitAIType() != UNITAI_EXPLORE_SEA)4955 {4956#if defined(MOD_AI_SMART_V3)4957 if(pLoopUnit->getDomainType() == DOMAIN_SEA)4958 {4959 iNumNavalUnits++;4960 }4961#endif4962 if(pLoopUnit->cargoSpace() > 0)4963 {4964 if(pLoopUnit->specialCargo() != NO_SPECIALUNIT)4965 {4966 if(pLoopUnit->specialCargo() != eSpecialUnitPlane)4967 {4968 continue;4969 }4970 }49714972 if (pLoopUnit->domainCargo() != NO_DOMAIN)4973 {4974 if (pLoopUnit->domainCargo() != DOMAIN_AIR)4975 {4976 continue;4977 }4978 }4979#if defined(MOD_AI_SMART_V3)4980 iNumCargoUnits++;4981#endif4982 iNumTotalCargoSpace += pLoopUnit->cargoSpace();4983 }4984 else if (pLoopUnit->getSpecialUnitType() == eSpecialUnitPlane)4985 {4986 iNumLoadableAirUnits += 1;4987 }4988 }4989 }49904991#if defined(MOD_CONFIG_AI_IN_XML)4992 // Why would we ever want to load EVERY plane onto a carrier?4993 int iFactor = GC.getAI_CONFIG_MILITARY_AIRCRAFT_PER_CARRIER_SPACE();4994 if (iNumLoadableAirUnits > iFactor*iNumTotalCargoSpace)4995#else4996#if defined(MOD_AI_SMART_V3)4997 if ((iNumLoadableAirUnits > iNumTotalCargoSpace) && (!MOD_AI_SMART_V3 || ((iNumNavalUnits / 4) >= iNumCargoUnits)))4998#else4999 if (iNumLoadableAirUnits > iNumTotalCargoSpace)5000#endif5001#endif5002 {5003 return true;5004 }5005 else5006 {5007 return false;5008 }5009}
Calls
- CvGlobals::getAI_CONFIG_MILITARY_AIRCRAFT_PER_CARRIER_SPACE()
- CvGlobals::getInfoTypeForString(const char *, bool) const
- CvPlayer::firstUnit(int *, bool)
- CvPlayer::nextUnit(int *, bool)
- CvUnit::AI_getUnitAIType() const
- CvUnit::cargoSpace() const
- CvUnit::domainCargo() const
- CvUnit::getDomainType() const
- CvUnit::getSpecialUnitType() const
- CvUnit::specialCargo() const