Bazaar developer reference

CvPlot::updateWorkingCity()

Defined in
CvPlot.cpp, line 7652
Class
CvPlot
Hook name
CivHooks::CvPlot_updateWorkingCity

Hooks

static bool BeforeCvPlot_updateWorkingCity(CvPlot* self);static void AfterCvPlot_updateWorkingCity(CvPlot* self);static void ReplaceCvPlot_updateWorkingCity(void (*original)(CvPlot*), CvPlot* self);CivRegisterBefore<CivHooks::CvPlot_updateWorkingCity>(host, &BeforeCvPlot_updateWorkingCity);CivRegisterAfter<CivHooks::CvPlot_updateWorkingCity>(host, &AfterCvPlot_updateWorkingCity);CivRegisterReplace<CivHooks::CvPlot_updateWorkingCity>(host, &ReplaceCvPlot_updateWorkingCity);

Code

7652void CvPlot::updateWorkingCity()7653{7654	CvCity* pOldWorkingCity;7655	CvCity* pLoopCity;7656	CvCity* pBestCity;7657	CvPlot* pLoopPlot;7658	int iBestPlot;7659	int iI;76607661	pBestCity = getPlotCity();76627663	if(pBestCity == NULL)7664	{7665		pBestCity = getWorkingCityOverride();7666		CvAssertMsg((pBestCity == NULL) || (pBestCity->getOwner() == getOwner()), "pBest city is expected to either be NULL or the current plot instance's");7667	}76687669	if((pBestCity == NULL) && isOwned())7670	{7671		iBestPlot = 0;76727673#if defined(MOD_GLOBAL_CITY_WORKING)7674		for(iI = 0; iI < MAX_CITY_PLOTS; ++iI)7675#else7676		for(iI = 0; iI < NUM_CITY_PLOTS; ++iI)7677#endif7678		{7679			pLoopPlot = plotCity(getX(), getY(), iI);76807681			if(pLoopPlot != NULL)7682			{7683				pLoopCity = pLoopPlot->getPlotCity();76847685				if(pLoopCity != NULL)7686				{7687					if(pLoopCity->getOwner() == getOwner())7688					{7689						// XXX use getGameTurnAcquired() instead???7690						if((pBestCity == NULL) ||7691						        (GC.getCityPlotPriority()[iI] < GC.getCityPlotPriority()[iBestPlot]) ||7692						        ((GC.getCityPlotPriority()[iI] == GC.getCityPlotPriority()[iBestPlot]) &&7693						         ((pLoopCity->getGameTurnFounded() < pBestCity->getGameTurnFounded()) ||7694						          ((pLoopCity->getGameTurnFounded() == pBestCity->getGameTurnFounded()) &&7695						           (pLoopCity->GetID() < pBestCity->GetID())))))7696						{7697							iBestPlot = iI;7698							pBestCity = pLoopCity;7699						}7700					}7701				}7702			}7703		}7704	}77057706	pOldWorkingCity = getWorkingCity();77077708	if(pOldWorkingCity != pBestCity)7709	{7710		// Change what City's allowed to work this Plot7711		if(pBestCity != NULL)7712		{7713			// Remove Citizen from this plot if another City's using it7714			if(pOldWorkingCity != NULL)7715			{7716				// Remove citizen7717				pOldWorkingCity->GetCityCitizens()->SetWorkingPlot(this, false);7718			}77197720			CvAssertMsg(isOwned(), "isOwned is expected to be true");7721			CvAssertMsg(!isBeingWorked(), "isBeingWorked did not return false as expected");7722			m_workingCity = pBestCity->GetIDInfo();77237724			// If we told a City to stop working this plot, tell it to do something else instead7725			if(pOldWorkingCity != NULL)7726			{7727				// Re-add citizen somewhere else7728				pOldWorkingCity->GetCityCitizens()->DoAddBestCitizenFromUnassigned();7729			}7730		}7731		else7732		{7733			m_workingCity.reset();7734		}77357736		updateYield();77377738		GC.GetEngineUserInterface()->setDirty(ColoredPlots_DIRTY_BIT, true);7739	}7740}

Calls

Called by