Bazaar developer reference

CvCityCitizens::DoAlterWorkingPlot(int)

Defined in
CvCityCitizens.cpp, line 1727
Class
CvCityCitizens
Hook name
CivHooks::CvCityCitizens_DoAlterWorkingPlot

Hooks

static bool BeforeCvCityCitizens_DoAlterWorkingPlot(CvCityCitizens* self, int iIndex);static void AfterCvCityCitizens_DoAlterWorkingPlot(CvCityCitizens* self, int iIndex);static void ReplaceCvCityCitizens_DoAlterWorkingPlot(void (*original)(CvCityCitizens*, int), CvCityCitizens* self, int iIndex);CivRegisterBefore<CivHooks::CvCityCitizens_DoAlterWorkingPlot>(host, &BeforeCvCityCitizens_DoAlterWorkingPlot);CivRegisterAfter<CivHooks::CvCityCitizens_DoAlterWorkingPlot>(host, &AfterCvCityCitizens_DoAlterWorkingPlot);CivRegisterReplace<CivHooks::CvCityCitizens_DoAlterWorkingPlot>(host, &ReplaceCvCityCitizens_DoAlterWorkingPlot);

Code

1726/// Tell City to work a Plot, pulling a Citizen from the worst location we can1727void CvCityCitizens::DoAlterWorkingPlot(int iIndex)1728{1729	CvAssertMsg(iIndex >= 0, "iIndex expected to be >= 0");1730#if defined(MOD_GLOBAL_CITY_WORKING)1731	CvAssertMsg(iIndex < GetCity()->GetNumWorkablePlots(), "iIndex expected to be < NUM_CITY_PLOTS");1732#else1733	CvAssertMsg(iIndex < NUM_CITY_PLOTS, "iIndex expected to be < NUM_CITY_PLOTS");1734#endif17351736	// Clicking ON the city "resets" it to default setup1737	if(iIndex == CITY_HOME_PLOT)1738	{1739		CvPlot* pLoopPlot;17401741		// If we've forced any plots to be worked, reset them to the normal state1742#if defined(MOD_GLOBAL_CITY_WORKING)1743		for(int iPlotLoop = 0; iPlotLoop < GetCity()->GetNumWorkablePlots(); iPlotLoop++)1744#else1745		for(int iPlotLoop = 0; iPlotLoop < NUM_CITY_PLOTS; iPlotLoop++)1746#endif1747		{1748			if(iPlotLoop != CITY_HOME_PLOT)1749			{1750				pLoopPlot = GetCityPlotFromIndex(iPlotLoop);17511752				if(pLoopPlot != NULL)1753				{1754					if(IsForcedWorkingPlot(pLoopPlot))1755					{1756						SetForcedWorkingPlot(pLoopPlot, false);1757					}1758				}1759			}1760		}17611762		// Reset Forced Default Specialists1763		ChangeNumForcedDefaultSpecialists(-GetNumForcedDefaultSpecialists());17641765		DoReallocateCitizens();1766	}1767	else1768	{1769		CvPlot* pPlot = GetCityPlotFromIndex(iIndex);17701771		if(pPlot != NULL)1772		{1773			if(IsCanWork(pPlot))1774			{1775//				GetCity()->setCitizensAutomated(false);17761777				// If we're already working the Plot, then take the guy off and turn him into a Default Specialist1778				if(IsWorkingPlot(pPlot))1779				{1780					SetWorkingPlot(pPlot, false);1781					SetForcedWorkingPlot(pPlot, false);1782					ChangeNumDefaultSpecialists(1);1783					ChangeNumForcedDefaultSpecialists(1);1784				}1785				// Player picked a new Plot to work1786				else1787				{1788					// Pull from the Default Specialist pool, if possible1789					if(GetNumDefaultSpecialists() > 0)1790					{1791						ChangeNumDefaultSpecialists(-1);1792						// Player is forcibly telling city to work a plot, so reduce count of forced default specialists1793						if(GetNumForcedDefaultSpecialists() > 0)1794							ChangeNumForcedDefaultSpecialists(-1);17951796						SetWorkingPlot(pPlot, true);1797						SetForcedWorkingPlot(pPlot, true);1798					}1799					// No Default Specialists, so grab a better allocated guy1800					else1801					{1802						// Working Plot1803						if(DoRemoveWorstCitizen(true))1804						{1805							SetWorkingPlot(pPlot, true);1806							SetForcedWorkingPlot(pPlot, true);1807							//ChangeNumUnassignedCitizens(-1);1808						}1809						// Good Specialist1810						else1811						{1812							CvAssert(false);1813						}1814					}1815					//if ((GetCity()->extraSpecialists() > 0) || GetCity()->AI_removeWorstCitizen())1816					//{1817					//	SetWorkingPlot(pPlot, true);1818					//}1819				}1820			}1821			// JON: Need to update this block to work with new system1822			else if(pPlot->getOwner() == GetOwner())1823			{1824				// Can't take away forced plots from puppet Cities1825				if(pPlot->getWorkingCityOverride() != NULL)1826				{1827					if(pPlot->getWorkingCityOverride()->IsPuppet())1828					{1829						return;1830					}1831				}18321833				pPlot->setWorkingCityOverride(GetCity());1834			}1835		}1836	}1837}

Calls

Called by