Bazaar developer reference

CvMilitaryAI::GetNumEnemyAirUnitsInRange(CvPlot *, int, bool, bool) const

Defined in
CvMilitaryAI.cpp, line 3974
Class
CvMilitaryAI
Hook name
CivHooks::CvMilitaryAI_GetNumEnemyAirUnitsInRange

Hooks

static bool BeforeCvMilitaryAI_GetNumEnemyAirUnitsInRange(const CvMilitaryAI* self, CvPlot* pCenterPlot, int iRange, bool bCountFighters, bool bCountBombers, int& result);static void AfterCvMilitaryAI_GetNumEnemyAirUnitsInRange(const CvMilitaryAI* self, CvPlot* pCenterPlot, int iRange, bool bCountFighters, bool bCountBombers, int& result);static int ReplaceCvMilitaryAI_GetNumEnemyAirUnitsInRange(int (*original)(const CvMilitaryAI*, CvPlot*, int, bool, bool), const CvMilitaryAI* self, CvPlot* pCenterPlot, int iRange, bool bCountFighters, bool bCountBombers);CivRegisterBefore<CivHooks::CvMilitaryAI_GetNumEnemyAirUnitsInRange>(host, &BeforeCvMilitaryAI_GetNumEnemyAirUnitsInRange);CivRegisterAfter<CivHooks::CvMilitaryAI_GetNumEnemyAirUnitsInRange>(host, &AfterCvMilitaryAI_GetNumEnemyAirUnitsInRange);CivRegisterReplace<CivHooks::CvMilitaryAI_GetNumEnemyAirUnitsInRange>(host, &ReplaceCvMilitaryAI_GetNumEnemyAirUnitsInRange);

Code

3971/// Assess nearby enemy air assets3972#if defined(MOD_AI_SMART_V3)3973// Add half of unit range to the calculations.3974int CvMilitaryAI::GetNumEnemyAirUnitsInRange(CvPlot* pCenterPlot, int iRange, bool bCountFighters, bool bCountBombers) const3975#else3976int CvMilitaryAI::GetNumEnemyAirUnitsInRange(CvPlot* pCenterPlot, int /*iRange*/, bool bCountFighters, bool bCountBombers) const3977#endif3978{3979	int iRtnValue = 0;39803981	// Loop through all the players3982	for(int iI = 0; iI < MAX_PLAYERS; iI++)3983	{3984		CvPlayer& kPlayer = GET_PLAYER((PlayerTypes)iI);3985		if(kPlayer.isAlive() && kPlayer.GetID() != m_pPlayer->GetID())3986		{3987			if (atWar(kPlayer.getTeam(), m_pPlayer->getTeam()))3988			{3989				// Loop through their units looking for bombers (this will allow us to find bombers on carriers also3990				int iLoopUnit = 0;3991				for(CvUnit* pLoopUnit = kPlayer.firstUnit(&iLoopUnit); pLoopUnit != NULL; pLoopUnit = kPlayer.nextUnit(&iLoopUnit))3992				{3993					if (pLoopUnit->getDomainType() == DOMAIN_AIR)3994					{3995#if defined(MOD_AI_SMART_V3)3996						// Just to keep fighters closer to high range bombers (stealth bombers)3997						int iAcceptableDistance = MOD_AI_SMART_V3 ? min(pLoopUnit->GetRange(), 12) + (iRange / 2) : 10;3998						if ( plotDistance(pCenterPlot->getX(), pCenterPlot->getY(), pLoopUnit->getX(), pLoopUnit->getY()) <= iAcceptableDistance )3999#else4000						if ( plotDistance(pCenterPlot->getX(), pCenterPlot->getY(), pLoopUnit->getX(), pLoopUnit->getY()) <= 10 )4001#endif4002						{4003							// Let's not factor in revealed or visible - As a human I can remember past attacks and intuit whether a bomber could be in range of the city, AIs don't have great intuition...4004							if (pLoopUnit->IsAirSweepCapable() || pLoopUnit->canAirDefend())4005							{4006								if (bCountFighters) iRtnValue++;4007							}4008							else4009							{4010								if (bCountBombers) iRtnValue++;4011							}4012						}4013					}4014				}40154016				// Loop through each of their cities4017				//int iLoop;4018				//CvCity* pLoopCity;4019				//for(pLoopCity = kPlayer.firstCity(&iLoop); pLoopCity != NULL; pLoopCity = kPlayer.nextCity(&iLoop))4020				//{4021				//	CvPlot *pCityPlot = pLoopCity->plot();4022				//	if (pCityPlot->isRevealed(m_pPlayer->getTeam()) && plotDistance(pCenterPlot->getX(), pCenterPlot->getY(), pLoopCity->getX(), pLoopCity->getY()) <= iRange)4023				//	{4024				//		for (int iUnitLoop = 0; iUnitLoop < pCityPlot->getNumUnits(); iUnitLoop++)4025				//		{4026				//			CvUnit *pUnit = pCityPlot->getUnitByIndex(iUnitLoop);4027				//			{4028				//				if (pUnit->getDomainType() == DOMAIN_AIR)4029				//				{4030				//					if (pUnit->IsAirSweepCapable() || pUnit->canAirDefend())4031				//					{4032				//						if (bCountFighters) iRtnValue++;4033				//					}4034				//					else4035				//					{4036				//						if (bCountBombers) iRtnValue++;4037				//					}4038				//				}4039				//			}4040				//		}4041				//	}4042				//}4043			}4044		}4045	}40464047	return iRtnValue;4048}

Calls

Called by