Bazaar developer reference

CvPlayer::DoUpdateCramped()

Defined in
CvPlayer.cpp, line 18397
Class
CvPlayer
Hook name
CivHooks::CvPlayer_DoUpdateCramped

Hooks

static bool BeforeCvPlayer_DoUpdateCramped(CvPlayer* self);static void AfterCvPlayer_DoUpdateCramped(CvPlayer* self);static void ReplaceCvPlayer_DoUpdateCramped(void (*original)(CvPlayer*), CvPlayer* self);CivRegisterBefore<CivHooks::CvPlayer_DoUpdateCramped>(host, &BeforeCvPlayer_DoUpdateCramped);CivRegisterAfter<CivHooks::CvPlayer_DoUpdateCramped>(host, &AfterCvPlayer_DoUpdateCramped);CivRegisterReplace<CivHooks::CvPlayer_DoUpdateCramped>(host, &ReplaceCvPlayer_DoUpdateCramped);

Code

18396/// Determines if the player is cramped in his current area.  Not a perfect algorithm, as it will double-count Plots shared by different Cities, but it should be good enough18397void CvPlayer::DoUpdateCramped()18398{18399	CvCity* pLoopCity;18400	CvPlot* pPlot;1840118402	int iTotalPlotsNearby = 0;18403	int iUsablePlotsNearby = 0;1840418405	int iRange = GC.getCRAMPED_RANGE_FROM_CITY();1840618407	int iLoop;18408	for(pLoopCity = firstCity(&iLoop); pLoopCity != NULL; pLoopCity = nextCity(&iLoop))18409	{18410		for(int iX = -iRange; iX <= iRange; iX++)18411		{18412			for(int iY = -iRange; iY <= iRange; iY++)18413			{18414				pPlot = plotXYWithRangeCheck(pLoopCity->getX(), pLoopCity->getY(), iX, iY, iRange);1841518416				if(pPlot != NULL)18417				{18418					// Plot not owned by me18419					if(!pPlot->isOwned() || pPlot->getOwner() != GetID())18420					{18421						iTotalPlotsNearby++;1842218423						// A "good" unowned Plot18424						if(!pPlot->isOwned() && !pPlot->isImpassable() && !pPlot->isMountain() && !pPlot->isWater())18425						{18426							iUsablePlotsNearby++;18427						}18428					}18429				}18430			}18431		}18432	}1843318434	if(iTotalPlotsNearby > 0)18435	{18436		if(100 * iUsablePlotsNearby / iTotalPlotsNearby <= GC.getCRAMPED_USABLE_PLOT_PERCENT())	// 2018437		{18438			m_bCramped = true;18439		}18440		else18441		{18442			m_bCramped = false;18443		}18444	}18445}

Calls

Called by