Bazaar developer reference

CvCity::BuyPlot(int, int)

Defined in
CvCity.cpp, line 12416
Class
CvCity
Hook name
CivHooks::CvCity_BuyPlot
Lua events
GameEvents.CityBoughtPlot

Hooks

static bool BeforeCvCity_BuyPlot(CvCity* self, int iPlotX, int iPlotY);static void AfterCvCity_BuyPlot(CvCity* self, int iPlotX, int iPlotY);static void ReplaceCvCity_BuyPlot(void (*original)(CvCity*, int, int), CvCity* self, int iPlotX, int iPlotY);CivRegisterBefore<CivHooks::CvCity_BuyPlot>(host, &BeforeCvCity_BuyPlot);CivRegisterAfter<CivHooks::CvCity_BuyPlot>(host, &AfterCvCity_BuyPlot);CivRegisterReplace<CivHooks::CvCity_BuyPlot>(host, &ReplaceCvCity_BuyPlot);

Code

12415/// Buy the plot and set it's owner to us (executed by the network code)12416void CvCity::BuyPlot(int iPlotX, int iPlotY)12417{12418	VALIDATE_OBJECT12419	CvPlot* pPlot = GC.getMap().plot(iPlotX, iPlotY);12420	if(!pPlot)12421	{12422		return;12423	}1242412425	int iCost = GetBuyPlotCost(iPlotX, iPlotY);12426	CvPlayer& thisPlayer = GET_PLAYER(getOwner());12427	thisPlayer.GetTreasury()->LogExpenditure("", iCost, 1);12428	thisPlayer.GetTreasury()->ChangeGold(-iCost);12429#if defined(MOD_UI_CITY_EXPANSION)12430	bool bWithGold = true;12431	if (MOD_UI_CITY_EXPANSION && GET_PLAYER(getOwner()).isHuman()) {12432		// If we have a culture surplus, we got a discount on the tile, so remove the surplus12433		int iOverflow = GetJONSCultureStored() - GetJONSCultureThreshold();12434		if (iOverflow >= 0) {12435			SetJONSCultureStored(iOverflow);12436			ChangeJONSCultureLevel(1);12437			bWithGold = false;12438		}12439	}12440#endif1244112442#if defined(MOD_UI_CITY_EXPANSION)12443	if (iCost > 0) {12444		// Only do this if we actually paid for the plot (as opposed to getting it for free via city growth)12445#endif12446		thisPlayer.ChangeNumPlotsBought(1);1244712448		// See if there's anyone else nearby that could get upset by this action12449		CvCity* pNearbyCity;12450#if defined(MOD_GLOBAL_CITY_WORKING)12451		for(int iI = 0; iI < GetNumWorkablePlots(); iI++)12452#else12453		for(int iI = 0; iI < NUM_CITY_PLOTS; iI++)12454#endif12455		{12456			pPlot = plotCity(iPlotX, iPlotY, iI);1245712458			if(pPlot != NULL)12459			{12460				pNearbyCity = pPlot->getPlotCity();1246112462				if(pNearbyCity)12463				{12464					if(pNearbyCity->getOwner() != getOwner())12465					{12466						pNearbyCity->AI_ChangeNumPlotsAcquiredByOtherPlayer(getOwner(), 1);12467					}12468				}12469			}12470		}12471#if defined(MOD_UI_CITY_EXPANSION)12472	}12473#endif1247412475	if(GC.getLogging() && GC.getAILogging())12476	{12477		CvPlayerAI& kOwner = GET_PLAYER(getOwner());12478		CvString playerName;12479		FILogFile* pLog;12480		CvString strBaseString;12481		CvString strOutBuf;12482		playerName = kOwner.getCivilizationShortDescription();12483		pLog = LOGFILEMGR.GetLog(kOwner.GetCitySpecializationAI()->GetLogFileName(playerName), FILogFile::kDontTimeStamp);12484		strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns());12485		strBaseString += playerName + ", ";12486		strOutBuf.Format("%s, City Plot Purchased, X: %d, Y: %d", getName().GetCString(), iPlotX, iPlotY);12487		strBaseString += strOutBuf;12488		pLog->Msg(strBaseString);12489	}12490	DoAcquirePlot(iPlotX, iPlotY);12491		12492#if defined(MOD_EVENTS_CITY)12493	if (MOD_EVENTS_CITY) {12494#if defined(MOD_UI_CITY_EXPANSION)12495		GAMEEVENTINVOKE_HOOK(GAMEEVENT_CityBoughtPlot, getOwner(), GetID(), iPlotX, iPlotY, bWithGold, !bWithGold);12496#else12497		GAMEEVENTINVOKE_HOOK(GAMEEVENT_CityBoughtPlot, getOwner(), GetID(), iPlotX, iPlotY, true, false);12498#endif12499	} else {12500#endif12501	ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();12502	if (pkScriptSystem) 12503	{12504		CvLuaArgsHandle args;12505		args->Push(getOwner());12506		args->Push(GetID());12507#if defined(MOD_BUGFIX_MINOR)12508		args->Push(iPlotX);12509		args->Push(iPlotY);12510#else12511		args->Push(plot()->getX());12512		args->Push(plot()->getY());12513#endif12514		args->Push(true); // bGold12515		args->Push(false); // bFaith/bCulture1251612517		bool bResult;12518		LuaSupport::CallHook(pkScriptSystem, "CityBoughtPlot", args.get(), bResult);12519	}12520#if defined(MOD_EVENTS_CITY)12521	}12522#endif1252312524#if !defined(NO_ACHIEVEMENTS)12525	//Achievement test for purchasing 1000 tiles12526	if(thisPlayer.isHuman() && !GC.getGame().isGameMultiPlayer())12527	{12528		gDLL->IncrementSteamStatAndUnlock(ESTEAMSTAT_TILESPURCHASED, 1000, ACHIEVEMENT_PURCHASE_1000TILES);12529	}12530#endif12531}

Calls

Called by