Bazaar developer reference

CvPlot::setPlotCity(CvCity *)

Defined in
CvPlot.cpp, line 7557
Class
CvPlot
Hook name
CivHooks::CvPlot_setPlotCity
Lua events
GameEvents.TerraformingPlot

Hooks

static bool BeforeCvPlot_setPlotCity(CvPlot* self, CvCity* pNewValue);static void AfterCvPlot_setPlotCity(CvPlot* self, CvCity* pNewValue);static void ReplaceCvPlot_setPlotCity(void (*original)(CvPlot*, CvCity*), CvPlot* self, CvCity* pNewValue);CivRegisterBefore<CivHooks::CvPlot_setPlotCity>(host, &BeforeCvPlot_setPlotCity);CivRegisterAfter<CivHooks::CvPlot_setPlotCity>(host, &AfterCvPlot_setPlotCity);CivRegisterReplace<CivHooks::CvPlot_setPlotCity>(host, &ReplaceCvPlot_setPlotCity);

Code

7557void CvPlot::setPlotCity(CvCity* pNewValue)7558{7559	CvPlot* pLoopPlot;7560	int iI;75617562	if(getPlotCity() != pNewValue)7563	{7564		if(isCity())7565		{7566			// Is a route is here?  If so, we may now need to pay maintenance for it.  Yes, yes, I know, we're removing a city7567			// so most likely the owner will loose the plot shortly, but it is best to keep the costs in sync, else bad things happen7568			// if it doesn't get properly updated (like it has been == negative maintenance costs asserts)7569			if(getRouteType() != NO_ROUTE && getPlotCity()->getOwner() == getOwner())7570			{7571				// Maintenance change!7572				if(MustPayMaintenanceHere(getOwner()))7573				{7574					GET_PLAYER(getOwner()).GetTreasury()->ChangeBaseImprovementGoldMaintenance(GC.getRouteInfo(getRouteType())->GetGoldMaintenance());7575				}7576			}75777578#if defined(MOD_GLOBAL_CITY_WORKING)7579			for(iI = 0; iI < getPlotCity()->GetNumWorkablePlots(); ++iI)7580#else7581			for(iI = 0; iI < NUM_CITY_PLOTS; ++iI)7582#endif7583			{7584				pLoopPlot = plotCity(getX(), getY(), iI);75857586				if(pLoopPlot != NULL)7587				{7588					pLoopPlot->changeCityRadiusCount(-1);7589					pLoopPlot->changePlayerCityRadiusCount(getPlotCity()->getOwner(), -1);7590				}7591			}7592		}75937594#if defined(MOD_EVENTS_TERRAFORMING)7595		if (MOD_EVENTS_TERRAFORMING) {7596			int iNewOwner = (pNewValue != NULL) ? pNewValue->getOwner() : -1;7597			int iNewCity = (pNewValue != NULL) ? pNewValue->GetID() : -1;7598			GAMEEVENTINVOKE_HOOK(GAMEEVENT_TerraformingPlot, TERRAFORMINGEVENT_CITY, m_iX, m_iY, 0, iNewOwner, m_plotCity.eOwner, iNewCity, m_plotCity.iID);7599		}7600#endif76017602		if(pNewValue != NULL)7603		{7604			m_plotCity = pNewValue->GetIDInfo();7605		}7606		else7607		{7608			m_plotCity.reset();7609		}76107611		if(isCity())7612		{7613#if defined(MOD_GLOBAL_CITY_WORKING)7614			for(iI = 0; iI < getPlotCity()->GetNumWorkablePlots(); ++iI)7615#else7616			for(iI = 0; iI < NUM_CITY_PLOTS; ++iI)7617#endif7618			{7619				pLoopPlot = plotCity(getX(), getY(), iI);76207621				if(pLoopPlot != NULL)7622				{7623					pLoopPlot->changeCityRadiusCount(1);7624					pLoopPlot->changePlayerCityRadiusCount(getPlotCity()->getOwner(), 1);7625				}7626			}76277628			// Is a route is here?  If we already owned this plot, then we were paying maintenance, now we don't have to.7629			if(getRouteType() != NO_ROUTE && getPlotCity()->getOwner() == getOwner())7630			{7631				// Maintenance change!7632				if(MustPayMaintenanceHere(getOwner()))7633				{7634					GET_PLAYER(getOwner()).GetTreasury()->ChangeBaseImprovementGoldMaintenance(-GC.getRouteInfo(getRouteType())->GetGoldMaintenance());7635				}7636			}76377638		}76397640		updateYield();7641	}7642}

Calls

Called by