Bazaar developer reference

CvCity::CanBuyAnyPlot()

Defined in
CvCity.cpp, line 11996
Class
CvCity
Hook name
CivHooks::CvCity_CanBuyAnyPlot
Lua events
GameEvents.CityCanBuyAnyPlot

Hooks

static bool BeforeCvCity_CanBuyAnyPlot(CvCity* self, bool& result);static void AfterCvCity_CanBuyAnyPlot(CvCity* self, bool& result);static bool ReplaceCvCity_CanBuyAnyPlot(bool (*original)(CvCity*), CvCity* self);CivRegisterBefore<CivHooks::CvCity_CanBuyAnyPlot>(host, &BeforeCvCity_CanBuyAnyPlot);CivRegisterAfter<CivHooks::CvCity_CanBuyAnyPlot>(host, &AfterCvCity_CanBuyAnyPlot);CivRegisterReplace<CivHooks::CvCity_CanBuyAnyPlot>(host, &ReplaceCvCity_CanBuyAnyPlot);

Code

11995/// Can this city buy a plot, any plot?11996bool CvCity::CanBuyAnyPlot(void)11997{11998	VALIDATE_OBJECT11999	CvPlot* pLoopPlot = NULL;12000	CvPlot* pThisPlot = plot();12001#if defined(MOD_GLOBAL_CITY_WORKING)12002	const int iMaxRange = getBuyPlotDistance();12003#else12004	const int iMaxRange = GC.getMAXIMUM_BUY_PLOT_DISTANCE();12005#endif12006	CvMap& thisMap = GC.getMap();1200712008	ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();12009	if(pkScriptSystem)12010	{12011		CvLuaArgsHandle args;12012		args->Push(getOwner());12013		args->Push(GetID());1201412015		// Attempt to execute the game events.12016		// Will return false if there are no registered listeners.12017		bool bResult = false;12018		if(LuaSupport::CallTestAll(pkScriptSystem, "CityCanBuyAnyPlot", args.get(), bResult))12019		{12020			// Check the result.12021			if(bResult == false)12022			{12023				return false;12024			}12025		}12026	}1202712028	for(int iDX = -iMaxRange; iDX <= iMaxRange; iDX++)12029	{12030		for(int iDY = -iMaxRange; iDY <= iMaxRange; iDY++)12031		{12032			pLoopPlot = plotXYWithRangeCheck(getX(), getY(), iDX, iDY, iMaxRange);12033			if(pLoopPlot != NULL)12034			{12035				if(pLoopPlot->getOwner() != NO_PLAYER)12036				{12037					continue;12038				}1203912040				// we can use the faster, but slightly inaccurate pathfinder here - after all we just need the existence of a path12041				int iInfluenceCost = thisMap.calculateInfluenceDistance(pThisPlot, pLoopPlot, iMaxRange, false);1204212043				if(iInfluenceCost > 0)12044				{12045					return true;12046				}12047			}12048		}12049	}1205012051	return false;12052}

Calls

Called by