Bazaar developer reference

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

Defined in
CvUnit.cpp, line 13518
Class
CvUnit
Hook name
CivHooks::CvUnit_GetInterceptorCount

Hooks

static bool BeforeCvUnit_GetInterceptorCount(const CvUnit* self, const CvPlot& interceptPlot, CvUnit* pkDefender, bool bLandInterceptorsOnly, bool bVisibleInterceptorsOnly, int& result);static void AfterCvUnit_GetInterceptorCount(const CvUnit* self, const CvPlot& interceptPlot, CvUnit* pkDefender, bool bLandInterceptorsOnly, bool bVisibleInterceptorsOnly, int& result);static int ReplaceCvUnit_GetInterceptorCount(int (*original)(const CvUnit*, const CvPlot&, CvUnit*, bool, bool), const CvUnit* self, const CvPlot& interceptPlot, CvUnit* pkDefender, bool bLandInterceptorsOnly, bool bVisibleInterceptorsOnly);CivRegisterBefore<CivHooks::CvUnit_GetInterceptorCount>(host, &BeforeCvUnit_GetInterceptorCount);CivRegisterAfter<CivHooks::CvUnit_GetInterceptorCount>(host, &AfterCvUnit_GetInterceptorCount);CivRegisterReplace<CivHooks::CvUnit_GetInterceptorCount>(host, &ReplaceCvUnit_GetInterceptorCount);

Code

13518int CvUnit::GetInterceptorCount(const CvPlot& interceptPlot, CvUnit* pkDefender /* = NULL */, bool bLandInterceptorsOnly /*false*/, bool bVisibleInterceptorsOnly /*false*/) const13519{13520	VALIDATE_OBJECT13521	13522	CvUnit* pLoopUnit;13523	int iReturnValue;13524	int iLoop;13525	int iI;1352613527	iReturnValue = 0;1352813529	// Loop through all players' Units (that we're at war with) to see if they can intercept13530	for(iI = 0; iI < MAX_PLAYERS; iI++)13531	{13532		CvPlayerAI& kLoopPlayer = GET_PLAYER((PlayerTypes)iI);13533		if(kLoopPlayer.isAlive())13534		{13535			TeamTypes eLoopTeam = kLoopPlayer.getTeam();13536			if(isEnemy(eLoopTeam) && !isInvisible(eLoopTeam, false, false))13537			{13538				for(pLoopUnit = kLoopPlayer.firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = kLoopPlayer.nextUnit(&iLoop))13539				{13540					// Must be able to intercept13541					if(pLoopUnit != pkDefender && !pLoopUnit->isDelayedDeath() && pLoopUnit->canAirDefend() && !pLoopUnit->isInCombat())13542					{13543						// Must not have already intercepted this turn13544						if(!pLoopUnit->isOutOfInterceptions())13545						{13546							// Must either be a non-air Unit, or an air Unit that hasn't moved this turn13547							if((pLoopUnit->getDomainType() != DOMAIN_AIR) || !(pLoopUnit->hasMoved()))13548							{13549								// Must either be a non-air Unit or an air Unit on intercept13550								if((pLoopUnit->getDomainType() != DOMAIN_AIR) || (pLoopUnit->GetActivityType() == ACTIVITY_INTERCEPT))13551								{13552									// Check input booleans13553									if (!bLandInterceptorsOnly || pLoopUnit->getDomainType() == DOMAIN_LAND)13554									{13555										if (!bVisibleInterceptorsOnly || pLoopUnit->plot()->isVisible(getTeam()))13556										{13557											// Test range13558											if(plotDistance(pLoopUnit->getX(), pLoopUnit->getY(), interceptPlot.getX(), interceptPlot.getY()) <= pLoopUnit->getUnitInfo().GetAirInterceptRange())13559											{13560												if (pLoopUnit->currInterceptionProbability() > 0)13561												{13562													iReturnValue++;13563												}13564											}13565										}13566									}13567								}13568							}13569						}13570					}13571				}13572			}13573		}13574	}1357513576	return iReturnValue;13577}

Calls

Called by