Bazaar developer reference

CvCity::DoUpdateFeatureSurrounded()

Defined in
CvCity.cpp, line 3132
Class
CvCity
Hook name
CivHooks::CvCity_DoUpdateFeatureSurrounded

Hooks

static bool BeforeCvCity_DoUpdateFeatureSurrounded(CvCity* self);static void AfterCvCity_DoUpdateFeatureSurrounded(CvCity* self);static void ReplaceCvCity_DoUpdateFeatureSurrounded(void (*original)(CvCity*), CvCity* self);CivRegisterBefore<CivHooks::CvCity_DoUpdateFeatureSurrounded>(host, &BeforeCvCity_DoUpdateFeatureSurrounded);CivRegisterAfter<CivHooks::CvCity_DoUpdateFeatureSurrounded>(host, &AfterCvCity_DoUpdateFeatureSurrounded);CivRegisterReplace<CivHooks::CvCity_DoUpdateFeatureSurrounded>(host, &ReplaceCvCity_DoUpdateFeatureSurrounded);

Code

3131// Are there a lot of clearable features around this city?3132void CvCity::DoUpdateFeatureSurrounded()3133{3134	AI_PERF_FORMAT("City-AI-perf.csv", ("CvCity::DoUpdateFeatureSurrounded, Turn %03d, %s, %s", GC.getGame().getElapsedGameTurns(), GetPlayer()->getCivilizationShortDescription(), getName().c_str()) );3135	int iTotalPlots = 0;3136	int iFeaturedPlots = 0;31373138	// Look two tiles around this city in every direction to see if at least half the plots are covered in a removable feature3139	const int iRange = 2;31403141	for(int iDX = -iRange; iDX <= iRange; iDX++)3142	{3143		for(int iDY = -iRange; iDY <= iRange; iDY++)3144		{3145			CvPlot* pLoopPlot = plotXYWithRangeCheck(getX(), getY(), iDX, iDY, iRange);31463147			// Increase total plot count3148			iTotalPlots++;31493150			if(pLoopPlot == NULL)3151				continue;31523153			if(pLoopPlot->getFeatureType() == NO_FEATURE)3154				continue;31553156			// Must be able to remove this thing?3157			if(!GC.getFeatureInfo(pLoopPlot->getFeatureType())->IsClearable())3158				continue;31593160			iFeaturedPlots++;3161		}3162	}31633164	bool bFeatureSurrounded = false;31653166	// At least half have coverage?3167	if(iFeaturedPlots >= iTotalPlots / 2)3168		bFeatureSurrounded = true;31693170	SetFeatureSurrounded(bFeatureSurrounded);3171}

Calls

Called by