Bazaar developer reference

CvUnit::GetBestInterceptor(const CvPlot &, CvUnit *, bool, bool) const

Defined in
CvUnit.cpp, line 13451
Class
CvUnit
Hook name
CivHooks::CvUnit_GetBestInterceptor

Hooks

static bool BeforeCvUnit_GetBestInterceptor(const CvUnit* self, const CvPlot& interceptPlot, CvUnit* pkDefender, bool bLandInterceptorsOnly, bool bVisibleInterceptorsOnly, CvUnit*& result);static void AfterCvUnit_GetBestInterceptor(const CvUnit* self, const CvPlot& interceptPlot, CvUnit* pkDefender, bool bLandInterceptorsOnly, bool bVisibleInterceptorsOnly, CvUnit*& result);static CvUnit* ReplaceCvUnit_GetBestInterceptor(CvUnit* (*original)(const CvUnit*, const CvPlot&, CvUnit*, bool, bool), const CvUnit* self, const CvPlot& interceptPlot, CvUnit* pkDefender, bool bLandInterceptorsOnly, bool bVisibleInterceptorsOnly);CivRegisterBefore<CivHooks::CvUnit_GetBestInterceptor>(host, &BeforeCvUnit_GetBestInterceptor);CivRegisterAfter<CivHooks::CvUnit_GetBestInterceptor>(host, &AfterCvUnit_GetBestInterceptor);CivRegisterReplace<CivHooks::CvUnit_GetBestInterceptor>(host, &ReplaceCvUnit_GetBestInterceptor);

Code

13451CvUnit* CvUnit::GetBestInterceptor(const CvPlot& interceptPlot, CvUnit* pkDefender /* = NULL */, bool bLandInterceptorsOnly /*false*/, bool bVisibleInterceptorsOnly /*false*/) const13452{13453	VALIDATE_OBJECT13454		CvUnit* pLoopUnit;13455	CvUnit* pBestUnit;13456	int iValue;13457	int iBestValue;13458	int iLoop;13459	int iI;1346013461	iBestValue = 0;13462	pBestUnit = NULL;1346313464	// Loop through all players' Units (that we're at war with) to see if they can intercept13465	for(iI = 0; iI < MAX_PLAYERS; iI++)13466	{13467		CvPlayerAI& kLoopPlayer = GET_PLAYER((PlayerTypes)iI);13468		if(kLoopPlayer.isAlive())13469		{13470			TeamTypes eLoopTeam = kLoopPlayer.getTeam();13471			if(isEnemy(eLoopTeam) && !isInvisible(eLoopTeam, false, false))13472			{13473				for(pLoopUnit = kLoopPlayer.firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = kLoopPlayer.nextUnit(&iLoop))13474				{13475					// Must be able to intercept13476					if(pLoopUnit != pkDefender && !pLoopUnit->isDelayedDeath() && pLoopUnit->canAirDefend() && !pLoopUnit->isInCombat())13477					{13478						// Must not have already intercepted this turn13479						if(!pLoopUnit->isOutOfInterceptions())13480						{13481							// Must either be a non-air Unit, or an air Unit that hasn't moved this turn13482							if((pLoopUnit->getDomainType() != DOMAIN_AIR) || !(pLoopUnit->hasMoved()))13483							{13484								// Must either be a non-air Unit or an air Unit on intercept13485								if((pLoopUnit->getDomainType() != DOMAIN_AIR) || (pLoopUnit->GetActivityType() == ACTIVITY_INTERCEPT))13486								{13487									// Check input booleans13488									if (!bLandInterceptorsOnly || pLoopUnit->getDomainType() == DOMAIN_LAND)13489									{13490										if (!bVisibleInterceptorsOnly || pLoopUnit->plot()->isVisible(getTeam()))13491										{13492											// Test range13493											if(plotDistance(pLoopUnit->getX(), pLoopUnit->getY(), interceptPlot.getX(), interceptPlot.getY()) <= pLoopUnit->getUnitInfo().GetAirInterceptRange())13494											{13495												iValue = pLoopUnit->currInterceptionProbability();1349613497												if(iValue > iBestValue)13498												{13499													iBestValue = iValue;13500													pBestUnit = pLoopUnit;13501												}13502											}13503										}13504									}13505								}13506							}13507						}13508					}13509				}13510			}13511		}13512	}1351313514	return pBestUnit;13515}

Calls

Called by