Bazaar developer reference

CvCity::CanBuyPlot(int, int, bool)

Defined in
CvCity.cpp, line 11903
Class
CvCity
Hook name
CivHooks::CvCity_CanBuyPlot
Lua events
GameEvents.CityCanBuyPlot

Hooks

static bool BeforeCvCity_CanBuyPlot(CvCity* self, int iPlotX, int iPlotY, bool bIgnoreCost, bool& result);static void AfterCvCity_CanBuyPlot(CvCity* self, int iPlotX, int iPlotY, bool bIgnoreCost, bool& result);static bool ReplaceCvCity_CanBuyPlot(bool (*original)(CvCity*, int, int, bool), CvCity* self, int iPlotX, int iPlotY, bool bIgnoreCost);CivRegisterBefore<CivHooks::CvCity_CanBuyPlot>(host, &BeforeCvCity_CanBuyPlot);CivRegisterAfter<CivHooks::CvCity_CanBuyPlot>(host, &AfterCvCity_CanBuyPlot);CivRegisterReplace<CivHooks::CvCity_CanBuyPlot>(host, &ReplaceCvCity_CanBuyPlot);

Code

11902/// Can a specific plot be bought for the city11903bool CvCity::CanBuyPlot(int iPlotX, int iPlotY, bool bIgnoreCost)11904{11905	VALIDATE_OBJECT11906	CvPlot* pTargetPlot = NULL;1190711908	if(GC.getBUY_PLOTS_DISABLED())11909	{11910		return false;11911	}1191211913	pTargetPlot = GC.getMap().plot(iPlotX, iPlotY);1191411915	if(!pTargetPlot)11916	{11917		// no plot to buy11918		return false;11919	}1192011921	// if this plot belongs to someone, bail!11922	if(pTargetPlot->getOwner() != NO_PLAYER)11923	{11924		return false;11925	}1192611927	// Must be adjacent to a plot owned by this city11928	CvPlot* pAdjacentPlot;11929	bool bFoundAdjacent = false;11930	for(int iI = 0; iI < NUM_DIRECTION_TYPES; iI++)11931	{11932		pAdjacentPlot = plotDirection(pTargetPlot->getX(), pTargetPlot->getY(), ((DirectionTypes)iI));1193311934		if(pAdjacentPlot != NULL)11935		{11936			if(pAdjacentPlot->getOwner() == getOwner())11937			{11938				if(pAdjacentPlot->GetCityPurchaseID() == GetID())11939				{11940					bFoundAdjacent = true;11941					break;11942				}11943			}11944		}11945	}1194611947	if(!bFoundAdjacent)11948		return false;1194911950	// Max range of 311951#if defined(MOD_GLOBAL_CITY_WORKING)11952	const int iMaxRange = getBuyPlotDistance();11953#else11954	const int iMaxRange = /*3*/ GC.getMAXIMUM_BUY_PLOT_DISTANCE();11955#endif11956	if(plotDistance(iPlotX, iPlotY, getX(), getY()) > iMaxRange)11957		return false;1195811959	// check money11960	if(!bIgnoreCost)11961	{11962		if(GET_PLAYER(getOwner()).GetTreasury()->GetGold() < GetBuyPlotCost(pTargetPlot->getX(), pTargetPlot->getY()))11963		{11964			return false;11965		}11966	}1196711968	ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();11969	if(pkScriptSystem)11970	{11971		CvLuaArgsHandle args;11972		args->Push(getOwner());11973		args->Push(GetID());11974		args->Push(iPlotX);11975		args->Push(iPlotY);1197611977		// Attempt to execute the game events.11978		// Will return false if there are no registered listeners.11979		bool bResult = false;11980		if(LuaSupport::CallTestAll(pkScriptSystem, "CityCanBuyPlot", args.get(), bResult))11981		{11982			// Check the result.11983			if(bResult == false)11984			{11985				return false;11986			}11987		}11988	}1198911990	return true;11991}

Calls

Called by