Bazaar developer reference

CvCity::DoNearbyEnemy()

Defined in
CvCity.cpp, line 16433
Class
CvCity
Hook name
CivHooks::CvCity_DoNearbyEnemy

Hooks

static bool BeforeCvCity_DoNearbyEnemy(CvCity* self);static void AfterCvCity_DoNearbyEnemy(CvCity* self);static void ReplaceCvCity_DoNearbyEnemy(void (*original)(CvCity*), CvCity* self);CivRegisterBefore<CivHooks::CvCity_DoNearbyEnemy>(host, &BeforeCvCity_DoNearbyEnemy);CivRegisterAfter<CivHooks::CvCity_DoNearbyEnemy>(host, &AfterCvCity_DoNearbyEnemy);CivRegisterReplace<CivHooks::CvCity_DoNearbyEnemy>(host, &ReplaceCvCity_DoNearbyEnemy);

Code

16433void CvCity::DoNearbyEnemy()16434{16435	AI_PERF_FORMAT("City-AI-perf.csv", ("CvCity::DoNearbyEnemy, Turn %03d, %s, %s", GC.getGame().getElapsedGameTurns(), GetPlayer()->getCivilizationShortDescription(), getName().c_str()) );16436	// Can't actually range strike16437	if(!canRangeStrike())16438		return;1643916440#if defined(MOD_EVENTS_CITY_BOMBARD)16441	int iSearchRange = getBombardRange();16442	16443	if (iSearchRange == 0) return;16444#else16445	int iSearchRange = GC.getCITY_ATTACK_RANGE();16446#endif16447	CvPlot* pBestPlot = NULL;1644816449	bool bFoundEnemy = false;1645016451	for(int iDX = -(iSearchRange); iDX <= iSearchRange && !pBestPlot; iDX++)16452	{16453		for(int iDY = -(iSearchRange); iDY <= iSearchRange && !pBestPlot; iDY++)16454		{16455			CvPlot* pLoopPlot = plotXYWithRangeCheck(getX(), getY(), iDX, iDY, iSearchRange);1645616457			if(pLoopPlot != NULL)16458			{16459				if(pLoopPlot->isVisibleEnemyUnit(getOwner()))16460				{16461					if(canRangeStrikeAt(pLoopPlot->getX(), pLoopPlot->getY()))16462					{16463						bFoundEnemy = true;1646416465						// Notification16466						CvNotifications* pNotifications = GET_PLAYER(getOwner()).GetNotifications();16467						if(pNotifications)16468						{16469							Localization::String strText = Localization::Lookup("TXT_KEY_NOTIFICATION_CITY_CAN_SHOOT");16470							strText << getNameKey();16471							Localization::String strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_CITY_CAN_SHOOT");16472							strSummary << getNameKey();16473							pNotifications->Add(NOTIFICATION_CITY_RANGE_ATTACK, strText.toUTF8(), strSummary.toUTF8(), getX(), getY(), GetID());16474						}1647516476						break;16477					}16478				}16479			}16480		}1648116482		if(bFoundEnemy)16483			break;16484	}16485}

Calls

Called by