Bazaar developer reference

MilitaryAIHelpers::IsTestStrategy_EnoughAntiAirUnits(CvPlayer *, int, int)

Defined in
CvMilitaryAI.cpp, line 4872
Hook name
CivHooks::MilitaryAIHelpers_IsTestStrategy_EnoughAntiAirUnits

Hooks

static bool BeforeMilitaryAIHelpers_IsTestStrategy_EnoughAntiAirUnits(CvPlayer* pPlayer, int iNumAA, int iNumMelee, bool& result);static void AfterMilitaryAIHelpers_IsTestStrategy_EnoughAntiAirUnits(CvPlayer* pPlayer, int iNumAA, int iNumMelee, bool& result);static bool ReplaceMilitaryAIHelpers_IsTestStrategy_EnoughAntiAirUnits(bool (*original)(CvPlayer*, int, int), CvPlayer* pPlayer, int iNumAA, int iNumMelee);CivRegisterBefore<CivHooks::MilitaryAIHelpers_IsTestStrategy_EnoughAntiAirUnits>(host, &BeforeMilitaryAIHelpers_IsTestStrategy_EnoughAntiAirUnits);CivRegisterAfter<CivHooks::MilitaryAIHelpers_IsTestStrategy_EnoughAntiAirUnits>(host, &AfterMilitaryAIHelpers_IsTestStrategy_EnoughAntiAirUnits);CivRegisterReplace<CivHooks::MilitaryAIHelpers_IsTestStrategy_EnoughAntiAirUnits>(host, &ReplaceMilitaryAIHelpers_IsTestStrategy_EnoughAntiAirUnits);

Code

4871/// "Enough Anti-Air" Player Strategy: If a player has too many AA units4872bool MilitaryAIHelpers::IsTestStrategy_EnoughAntiAirUnits(CvPlayer* pPlayer, int iNumAA, int iNumMelee)4873{4874	bool bAnyAirforce = false;4875	PlayerTypes eLoopPlayer;4876	for(int iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)4877	{4878		eLoopPlayer = (PlayerTypes) iPlayerLoop;4879		if(eLoopPlayer != pPlayer->GetID() && pPlayer->GetDiplomacyAI()->IsPlayerValid(eLoopPlayer))4880		{4881			if(GET_PLAYER(eLoopPlayer).GetMilitaryAI()->HasAirforce())4882			{4883				bAnyAirforce = true;4884				break;4885			}4886		}4887	}48884889	if(bAnyAirforce)4890	{4891#if defined(MOD_CONFIG_AI_IN_XML)4892		// The original code simplifies to 4*iNumAA > iNumMelee4893		return (GD_INT_GET(AI_CONFIG_MILITARY_MELEE_PER_AA)*iNumAA > iNumMelee);4894#else4895		int iRatio = (iNumAA * 10) / max(1,iNumMelee+iNumAA);4896		return (iRatio > 2);4897#endif4898	}4899	else4900	{4901		return true;4902	}4903}

Calls

Called by