Bazaar developer reference

CvUnit::GetNumSpecificEnemyUnitsAdjacent(const CvUnit *, const CvUnit *) const

Defined in
CvUnit.cpp, line 14921
Class
CvUnit
Hook name
CivHooks::CvUnit_GetNumSpecificEnemyUnitsAdjacent

Hooks

static bool BeforeCvUnit_GetNumSpecificEnemyUnitsAdjacent(const CvUnit* self, const CvUnit* pUnitToExclude, const CvUnit* pUnitCompare, int& result);static void AfterCvUnit_GetNumSpecificEnemyUnitsAdjacent(const CvUnit* self, const CvUnit* pUnitToExclude, const CvUnit* pUnitCompare, int& result);static int ReplaceCvUnit_GetNumSpecificEnemyUnitsAdjacent(int (*original)(const CvUnit*, const CvUnit*, const CvUnit*), const CvUnit* self, const CvUnit* pUnitToExclude, const CvUnit* pUnitCompare);CivRegisterBefore<CivHooks::CvUnit_GetNumSpecificEnemyUnitsAdjacent>(host, &BeforeCvUnit_GetNumSpecificEnemyUnitsAdjacent);CivRegisterAfter<CivHooks::CvUnit_GetNumSpecificEnemyUnitsAdjacent>(host, &AfterCvUnit_GetNumSpecificEnemyUnitsAdjacent);CivRegisterReplace<CivHooks::CvUnit_GetNumSpecificEnemyUnitsAdjacent>(host, &ReplaceCvUnit_GetNumSpecificEnemyUnitsAdjacent);

Code

14921int CvUnit::GetNumSpecificEnemyUnitsAdjacent(const CvUnit* pUnitToExclude, const CvUnit* pUnitCompare) const14922{14923	int iNumEnemiesAdjacent = 0;1492414925	TeamTypes eMyTeam = getTeam();1492614927	CvPlot* pLoopPlot;14928	IDInfo* pUnitNode;1492914930	CvUnit* pLoopUnit;14931	TeamTypes eTheirTeam;1493214933	for(int iI = 0; iI < NUM_DIRECTION_TYPES; iI++)14934	{14935		pLoopPlot = plotDirection(getX(), getY(), ((DirectionTypes)iI));1493614937		if(pLoopPlot != NULL)14938		{14939			pUnitNode = pLoopPlot->headUnitNode();1494014941			// Loop through all units on this plot14942			while(pUnitNode != NULL)14943			{14944				pLoopUnit = ::getUnit(*pUnitNode);14945				pUnitNode = pLoopPlot->nextUnitNode(pUnitNode);1494614947				// No NULL, and no unit we want to exclude14948				if(pLoopUnit && pLoopUnit != pUnitToExclude)14949				{14950					// Must be a combat Unit14951					if(pLoopUnit->IsCombatUnit())14952					{14953						eTheirTeam = pLoopUnit->getTeam();1495414955						// This team which this unit belongs to must be at war with us14956						if(GET_TEAM(eTheirTeam).isAtWar(eMyTeam))14957						{1495814959							if(pLoopUnit->getUnitType() == pUnitCompare->getUnitType())14960							{14961								iNumEnemiesAdjacent++;14962							}14963						}14964					}14965				}14966			}14967		}14968	}1496914970	return iNumEnemiesAdjacent;14971}

Calls