Bazaar developer reference

CvCityCitizens::GetBestCityPlotWithValue(int &, bool, bool)

Defined in
CvCityCitizens.cpp, line 1489
Class
CvCityCitizens
Hook name
CivHooks::CvCityCitizens_GetBestCityPlotWithValue

Hooks

static bool BeforeCvCityCitizens_GetBestCityPlotWithValue(CvCityCitizens* self, int& iValue, bool bWantBest, bool bWantWorked, CvPlot*& result);static void AfterCvCityCitizens_GetBestCityPlotWithValue(CvCityCitizens* self, int& iValue, bool bWantBest, bool bWantWorked, CvPlot*& result);static CvPlot* ReplaceCvCityCitizens_GetBestCityPlotWithValue(CvPlot* (*original)(CvCityCitizens*, int&, bool, bool), CvCityCitizens* self, int& iValue, bool bWantBest, bool bWantWorked);CivRegisterBefore<CivHooks::CvCityCitizens_GetBestCityPlotWithValue>(host, &BeforeCvCityCitizens_GetBestCityPlotWithValue);CivRegisterAfter<CivHooks::CvCityCitizens_GetBestCityPlotWithValue>(host, &AfterCvCityCitizens_GetBestCityPlotWithValue);CivRegisterReplace<CivHooks::CvCityCitizens_GetBestCityPlotWithValue>(host, &ReplaceCvCityCitizens_GetBestCityPlotWithValue);

Code

1488/// Find a Plot the City is either working or not, and the best/worst value for it - this function does "double duty" depending on what the user wants to find1489CvPlot* CvCityCitizens::GetBestCityPlotWithValue(int& iValue, bool bWantBest, bool bWantWorked)1490{1491	bool bPlotForceWorked;14921493	int iBestPlotValue = -1;1494	int iBestPlotID = -1;14951496	CvPlot* pLoopPlot;14971498	// Look at all workable Plots1499#if defined(MOD_GLOBAL_CITY_WORKING)1500	for(int iPlotLoop = 0; iPlotLoop < GetCity()->GetNumWorkablePlots(); iPlotLoop++)1501#else1502	for(int iPlotLoop = 0; iPlotLoop < NUM_CITY_PLOTS; iPlotLoop++)1503#endif1504	{1505		if(iPlotLoop != CITY_HOME_PLOT)1506		{1507			pLoopPlot = GetCityPlotFromIndex(iPlotLoop);15081509			if(pLoopPlot != NULL)1510			{1511				// Is this a Plot this City controls?1512				if(pLoopPlot->getWorkingCity() != NULL && pLoopPlot->getWorkingCity()->GetID() == GetCity()->GetID())1513				{1514					// Working the Plot and wanting to work it, or Not working it and wanting to find one to work?1515					if((IsWorkingPlot(pLoopPlot) && bWantWorked) ||1516					        (!IsWorkingPlot(pLoopPlot) && !bWantWorked))1517					{1518						// Working the Plot or CAN work the Plot?1519						if(bWantWorked || IsCanWork(pLoopPlot))1520						{1521							iValue = GetPlotValue(pLoopPlot, bWantBest);15221523							bPlotForceWorked = IsForcedWorkingPlot(pLoopPlot);15241525							if(bPlotForceWorked)1526							{1527								// Looking for best, unworked Plot: Forced plots are FIRST to be picked1528								if(bWantBest && !bWantWorked)1529								{1530									iValue += 10000;1531								}1532								// Looking for worst, worked Plot: Forced plots are LAST to be picked, so make it's value incredibly high1533								if(!bWantBest && bWantWorked)1534								{1535									iValue += 10000;1536								}1537							}15381539							if(iBestPlotValue == -1 ||							// First Plot?1540							        (bWantBest && iValue > iBestPlotValue) ||		// Best Plot so far?1541							        (!bWantBest && iValue < iBestPlotValue))			// Worst Plot so far?1542							{1543								iBestPlotValue = iValue;1544								iBestPlotID = iPlotLoop;1545							}1546						}1547					}1548				}1549			}1550		}1551	}15521553	// Passed in by reference1554	iValue = iBestPlotValue;15551556	if(iBestPlotID == -1)1557	{1558		return NULL;1559	}15601561	return GetCityPlotFromIndex(iBestPlotID);1562}

Calls

Called by