Bazaar developer reference

CvPlot::getNumVisibleEnemyDefenders(const CvUnit *) const

Defined in
CvPlot.cpp, line 4010
Class
CvPlot
Hook name
CivHooks::CvPlot_getNumVisibleEnemyDefenders

Hooks

static bool BeforeCvPlot_getNumVisibleEnemyDefenders(const CvPlot* self, const CvUnit* pUnit, int& result);static void AfterCvPlot_getNumVisibleEnemyDefenders(const CvPlot* self, const CvUnit* pUnit, int& result);static int ReplaceCvPlot_getNumVisibleEnemyDefenders(int (*original)(const CvPlot*, const CvUnit*), const CvPlot* self, const CvUnit* pUnit);CivRegisterBefore<CivHooks::CvPlot_getNumVisibleEnemyDefenders>(host, &BeforeCvPlot_getNumVisibleEnemyDefenders);CivRegisterAfter<CivHooks::CvPlot_getNumVisibleEnemyDefenders>(host, &AfterCvPlot_getNumVisibleEnemyDefenders);CivRegisterReplace<CivHooks::CvPlot_getNumVisibleEnemyDefenders>(host, &ReplaceCvPlot_getNumVisibleEnemyDefenders);

Code

4010int CvPlot::getNumVisibleEnemyDefenders(const CvUnit* pUnit) const4011{4012	CvAssertMsg(pUnit, "Source unit must be valid");4013	const IDInfo* pUnitNode = m_units.head();4014	if(pUnit && pUnitNode)4015	{4016		TeamTypes eTeam = GET_PLAYER(pUnit->getOwner()).getTeam();4017		bool bAlwaysHostile = pUnit->isAlwaysHostile(*this);4018		int iCount = 0;40194020		do4021		{4022			const CvUnit* pLoopUnit = GetPlayerUnit(*pUnitNode);4023			pUnitNode = m_units.next(pUnitNode);40244025			if(pLoopUnit && !pLoopUnit->isInvisible(eTeam, false))4026			{4027				if(pLoopUnit->IsCanDefend() && isEnemy(pLoopUnit, eTeam, bAlwaysHostile))4028				{4029					++iCount;4030				}4031			}4032		}4033		while(pUnitNode != NULL);4034		return iCount;4035	}4036	return 0;4037}

Calls

Called by