Bazaar developer reference

CvUnit::GetNumEnemyUnitsAdjacent(const CvUnit *) const

Defined in
CvUnit.cpp, line 14790
Class
CvUnit
Hook name
CivHooks::CvUnit_GetNumEnemyUnitsAdjacent

Hooks

static bool BeforeCvUnit_GetNumEnemyUnitsAdjacent(const CvUnit* self, const CvUnit* pUnitToExclude, int& result);static void AfterCvUnit_GetNumEnemyUnitsAdjacent(const CvUnit* self, const CvUnit* pUnitToExclude, int& result);static int ReplaceCvUnit_GetNumEnemyUnitsAdjacent(int (*original)(const CvUnit*, const CvUnit*), const CvUnit* self, const CvUnit* pUnitToExclude);CivRegisterBefore<CivHooks::CvUnit_GetNumEnemyUnitsAdjacent>(host, &BeforeCvUnit_GetNumEnemyUnitsAdjacent);CivRegisterAfter<CivHooks::CvUnit_GetNumEnemyUnitsAdjacent>(host, &AfterCvUnit_GetNumEnemyUnitsAdjacent);CivRegisterReplace<CivHooks::CvUnit_GetNumEnemyUnitsAdjacent>(host, &ReplaceCvUnit_GetNumEnemyUnitsAdjacent);

Code

14789/// How many enemy Units are adjacent to this guy?14790int CvUnit::GetNumEnemyUnitsAdjacent(const CvUnit* pUnitToExclude) const14791{14792	int iNumEnemiesAdjacent = 0;1479314794	TeamTypes eMyTeam = getTeam();1479514796	CvPlot* pLoopPlot;14797	IDInfo* pUnitNode;1479814799	CvUnit* pLoopUnit;14800	TeamTypes eTheirTeam;1480114802	for(int iI = 0; iI < NUM_DIRECTION_TYPES; iI++)14803	{14804		pLoopPlot = plotDirection(getX(), getY(), ((DirectionTypes)iI));1480514806		if(pLoopPlot != NULL)14807		{14808			pUnitNode = pLoopPlot->headUnitNode();1480914810			// Loop through all units on this plot14811			while(pUnitNode != NULL)14812			{14813				pLoopUnit = ::getUnit(*pUnitNode);14814				pUnitNode = pLoopPlot->nextUnitNode(pUnitNode);1481514816				// No NULL, and no unit we want to exclude14817				if(pLoopUnit && pLoopUnit != pUnitToExclude)14818				{14819					// Must be a combat Unit14820					if(pLoopUnit->IsCombatUnit() && !pLoopUnit->isEmbarked())14821					{14822						eTheirTeam = pLoopUnit->getTeam();1482314824						// This team which this unit belongs to must be at war with us14825						if(GET_TEAM(eTheirTeam).isAtWar(eMyTeam))14826						{14827							// Must be same domain14828							if (pLoopUnit->getDomainType() == getDomainType())14829							{14830								iNumEnemiesAdjacent++;14831							}14832#if defined(MOD_BUGFIX_HOVERING_PATHFINDER)14833							else if (getDomainType() == DOMAIN_SEA && pLoopUnit->IsHoveringUnit()) {14834							14835								// Need to count adjacent hovering units as enemies regardless14836								iNumEnemiesAdjacent++;14837							}14838#endif14839						}14840					}14841				}14842			}14843		}14844	}1484514846	return iNumEnemiesAdjacent;14847}

Calls

Called by