Bazaar developer reference

CvMilitaryAI::GetBestAirSweepTarget(CvUnit *) const

Defined in
CvMilitaryAI.cpp, line 4051
Class
CvMilitaryAI
Hook name
CivHooks::CvMilitaryAI_GetBestAirSweepTarget

Hooks

static bool BeforeCvMilitaryAI_GetBestAirSweepTarget(const CvMilitaryAI* self, CvUnit* pFighter, CvPlot *& result);static void AfterCvMilitaryAI_GetBestAirSweepTarget(const CvMilitaryAI* self, CvUnit* pFighter, CvPlot *& result);static CvPlot * ReplaceCvMilitaryAI_GetBestAirSweepTarget(CvPlot * (*original)(const CvMilitaryAI*, CvUnit*), const CvMilitaryAI* self, CvUnit* pFighter);CivRegisterBefore<CivHooks::CvMilitaryAI_GetBestAirSweepTarget>(host, &BeforeCvMilitaryAI_GetBestAirSweepTarget);CivRegisterAfter<CivHooks::CvMilitaryAI_GetBestAirSweepTarget>(host, &AfterCvMilitaryAI_GetBestAirSweepTarget);CivRegisterReplace<CivHooks::CvMilitaryAI_GetBestAirSweepTarget>(host, &ReplaceCvMilitaryAI_GetBestAirSweepTarget);

Code

4050/// See if this fighter has an air sweep target we like4051CvPlot *CvMilitaryAI::GetBestAirSweepTarget(CvUnit* pFighter) const4052{4053	CvPlot *pBestTarget = NULL;4054	int iBestCount = 0;40554056	// Loop through all the players4057	for(int iI = 0; iI < MAX_PLAYERS; iI++)4058	{4059		CvPlayer& kPlayer = GET_PLAYER((PlayerTypes)iI);4060		if(kPlayer.isAlive() && kPlayer.GetID() != m_pPlayer->GetID())4061		{4062			if (atWar(kPlayer.getTeam(), m_pPlayer->getTeam()))4063			{4064				// Loop through each of their cities4065				int iLoop;4066				CvCity* pLoopCity;4067				for(pLoopCity = kPlayer.firstCity(&iLoop); pLoopCity != NULL; pLoopCity = kPlayer.nextCity(&iLoop))4068				{4069					CvPlot *pCityPlot = pLoopCity->plot();4070					if (pCityPlot->isVisible(m_pPlayer->getTeam()) && plotDistance(pFighter->getX(), pFighter->getY(), pLoopCity->getX(), pLoopCity->getY()) <= pFighter->GetRange())4071					{4072						if (pFighter->canAirSweepAt(pCityPlot->getX(), pCityPlot->getY()))4073						{4074							int iCountFighters = 0;40754076							for (int iUnitLoop = 0; iUnitLoop < pCityPlot->getNumUnits(); iUnitLoop++)4077							{4078								CvUnit *pUnit = pCityPlot->getUnitByIndex(iUnitLoop);4079								{4080									if (pUnit->getDomainType() == DOMAIN_AIR)4081									{4082										if (pUnit->IsAirSweepCapable() || pUnit->canAirDefend())4083										{4084											iCountFighters++;4085										}4086									}4087								}4088							}40894090							if (iCountFighters > iBestCount)4091							{4092								iBestCount = iCountFighters;4093								pBestTarget = pCityPlot;4094							}4095						}4096					}4097				}4098			}4099		}4100	}41014102	return pBestTarget;4103}

Calls

Called by