Bazaar developer reference

CvUnit::SentryAlert(bool) const

Defined in
CvUnit.cpp, line 22476
Class
CvUnit
Hook name
CivHooks::CvUnit_SentryAlert

Hooks

static bool BeforeCvUnit_SentryAlert(const CvUnit* self, bool bSameDomainOrRanged, bool& result);static void AfterCvUnit_SentryAlert(const CvUnit* self, bool bSameDomainOrRanged, bool& result);static bool ReplaceCvUnit_SentryAlert(bool (*original)(const CvUnit*, bool), const CvUnit* self, bool bSameDomainOrRanged);CivRegisterBefore<CivHooks::CvUnit_SentryAlert>(host, &BeforeCvUnit_SentryAlert);CivRegisterAfter<CivHooks::CvUnit_SentryAlert>(host, &AfterCvUnit_SentryAlert);CivRegisterReplace<CivHooks::CvUnit_SentryAlert>(host, &ReplaceCvUnit_SentryAlert);

Code

22475#if defined(MOD_BUGFIX_WORKERS_VISIBLE_DANGER) || defined(MOD_BUGFIX_UNITS_AWAKE_IN_DANGER)22476bool CvUnit::SentryAlert(bool bSameDomainOrRanged) const22477#else22478bool CvUnit::SentryAlert() const22479#endif22480{22481	VALIDATE_OBJECT22482	int iRange = visibilityRange();2248322484	if(iRange > 0)22485	{22486		CvUnit* pEnemyUnit;2248722488		for(int iX = -iRange; iX <= iRange; ++iX)22489		{22490			for(int iY = -iRange; iY <= iRange; ++iY)22491			{22492				CvPlot* pPlot = ::plotXYWithRangeCheck(getX(), getY(), iX, iY, iRange);22493				if(NULL != pPlot)22494				{22495					// because canSeePlot() adds one to the range internally22496#if defined MOD_BUGFIX_NAVAL_TARGETING22497					if (plot()->canSeePlot(pPlot, getTeam(), (iRange - 1), NO_DIRECTION, getDomainType()))22498#else22499					if (plot()->canSeePlot(pPlot, getTeam(), (iRange - 1), NO_DIRECTION))22500#endif22501					{22502						if(pPlot->isVisibleEnemyUnit(this))22503						{22504							// Blocker for enemies not in our domain22505							pEnemyUnit = pPlot->getVisibleEnemyDefender(getOwner());22506							if(pEnemyUnit)22507							{22508#if defined(MOD_BUGFIX_WORKERS_VISIBLE_DANGER) || defined(MOD_BUGFIX_UNITS_AWAKE_IN_DANGER)22509								if (bSameDomainOrRanged)22510								{22511									if (pEnemyUnit->isRanged() || pEnemyUnit->getDomainType() == getDomainType()) {22512										return true;22513									}22514								}22515								else22516#endif22517									return true;22518							}22519						}22520					}22521				}22522			}22523		}22524	}2252522526	return false;22527}

Calls

Called by