Bazaar developer reference

CvPlayer::GetNumUnitsWithUnitAI(UnitAITypes, bool, bool)

Defined in
CvPlayer.cpp, line 4200
Class
CvPlayer
Hook name
CivHooks::CvPlayer_GetNumUnitsWithUnitAI

Hooks

static bool BeforeCvPlayer_GetNumUnitsWithUnitAI(CvPlayer* self, UnitAITypes eUnitAIType, bool bIncludeBeingTrained, bool bIncludeWater, int& result);static void AfterCvPlayer_GetNumUnitsWithUnitAI(CvPlayer* self, UnitAITypes eUnitAIType, bool bIncludeBeingTrained, bool bIncludeWater, int& result);static int ReplaceCvPlayer_GetNumUnitsWithUnitAI(int (*original)(CvPlayer*, UnitAITypes, bool, bool), CvPlayer* self, UnitAITypes eUnitAIType, bool bIncludeBeingTrained, bool bIncludeWater);CivRegisterBefore<CivHooks::CvPlayer_GetNumUnitsWithUnitAI>(host, &BeforeCvPlayer_GetNumUnitsWithUnitAI);CivRegisterAfter<CivHooks::CvPlayer_GetNumUnitsWithUnitAI>(host, &AfterCvPlayer_GetNumUnitsWithUnitAI);CivRegisterReplace<CivHooks::CvPlayer_GetNumUnitsWithUnitAI>(host, &ReplaceCvPlayer_GetNumUnitsWithUnitAI);

Code

4199/// Returns number of Units a player has with a particular UnitAI.  The second argument allows you to check whether or not to include Units currently being trained in Cities.4200int CvPlayer::GetNumUnitsWithUnitAI(UnitAITypes eUnitAIType, bool bIncludeBeingTrained, bool bIncludeWater)4201{4202	int iNumUnits = 0;42034204	CvUnit* pLoopUnit;4205	CvCity* pLoopCity;4206	int iLoop;42074208	// Current Units4209	for(pLoopUnit = firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = nextUnit(&iLoop))4210	{4211		// Don't include Water Units if we don't want them4212		if(pLoopUnit->getDomainType() != DOMAIN_SEA || bIncludeWater)4213		{4214			if(pLoopUnit->AI_getUnitAIType() == eUnitAIType)4215			{4216				iNumUnits++;4217			}4218		}4219	}42204221	// Units being trained now4222	if(bIncludeBeingTrained)4223	{4224		for(pLoopCity = firstCity(&iLoop); pLoopCity != NULL; pLoopCity = nextCity(&iLoop))4225		{4226			if(pLoopCity->isProductionUnit())4227			{4228				CvUnitEntry* pkUnitEntry = GC.getUnitInfo(pLoopCity->getProductionUnit());4229				if(pkUnitEntry)4230				{4231					// Don't include Water Units if we don't want them4232					if(pkUnitEntry->GetDomainType() != DOMAIN_SEA || bIncludeWater)4233					{4234						if(pkUnitEntry->GetDefaultUnitAIType() == eUnitAIType)4235						{4236							iNumUnits++;4237						}4238					}4239				}4240			}4241		}4242	}42434244	return iNumUnits;4245}

Calls

Called by