CvCity::setAutomatons(int, bool)
- Defined in
- CvCity.cpp, line 7978
- Class
- CvCity
- Hook name
CivHooks::CvCity_setAutomatons
Hooks
static bool BeforeCvCity_setAutomatons(CvCity* self, int iNewValue, bool bReassignPop);static void AfterCvCity_setAutomatons(CvCity* self, int iNewValue, bool bReassignPop);static void ReplaceCvCity_setAutomatons(void (*original)(CvCity*, int, bool), CvCity* self, int iNewValue, bool bReassignPop);CivRegisterBefore<CivHooks::CvCity_setAutomatons>(host, &BeforeCvCity_setAutomatons);CivRegisterAfter<CivHooks::CvCity_setAutomatons>(host, &AfterCvCity_setAutomatons);CivRegisterReplace<CivHooks::CvCity_setAutomatons>(host, &ReplaceCvCity_setAutomatons);
Code
7975// Be very careful with setting bReassignPop to false. This assumes that the caller7976// is manually adjusting the worker assignments *and* handling the setting of7977// the CityCitizens unassigned worker value.7978void CvCity::setAutomatons(int iNewValue, bool bReassignPop /* = true */)7979{7980 VALIDATE_OBJECT7981 int iChange = iNewValue - getAutomatons();79827983 if (iChange != 0) {7984 if (bReassignPop && iChange < 0) {7985 // If we are reducing automatons, remove the workers first7986 for (int iNewPopLoop = -iChange; iNewPopLoop--;) {7987 GetCityCitizens()->DoRemoveWorstCitizen(false, NO_SPECIALIST, iNewValue + getPopulation());7988 }79897990 // Fixup the unassigned workers7991 int iUnassignedWorkers = GetCityCitizens()->GetNumUnassignedCitizens();7992 CvAssert(iUnassignedWorkers >= -iChange);7993 GetCityCitizens()->ChangeNumUnassignedCitizens(std::max(iChange, -iUnassignedWorkers));7994 }79957996 m_iAutomatons = iNewValue;7997 CvAssert(getAutomatons() >= 0);79987999 if (bReassignPop && iChange > 0) {8000 // Give new automatons something to do in the City8001 GetCityCitizens()->ChangeNumUnassignedCitizens(iChange);80028003 // Need to Add Citizens8004 for (int iNewPopLoop = 0; iNewPopLoop < iChange; iNewPopLoop++) {8005 GetCityCitizens()->DoAddBestCitizenFromUnassigned();8006 }8007 }80088009 setLayoutDirty(true);8010 plot()->plotAction(PUF_makeInfoBarDirty);80118012 if((getOwner() == GC.getGame().getActivePlayer()) && isCitySelected())8013 {8014 DLLUI->setDirty(SelectionButtons_DIRTY_BIT, true);8015 DLLUI->setDirty(CityScreen_DIRTY_BIT, true);8016 }80178018 DLLUI->setDirty(CityInfo_DIRTY_BIT, true);8019 }8020}
Calls
- CvCity::getAutomatons() const
- CvCity::GetCityCitizens() const
- CvCity::getOwner() const
- CvCity::getPopulation(bool) const
- CvCity::isCitySelected()
- CvCity::plot() const
- CvCity::setLayoutDirty(bool)
- CvCityCitizens::ChangeNumUnassignedCitizens(int)
- CvCityCitizens::DoAddBestCitizenFromUnassigned()
- CvCityCitizens::DoRemoveWorstCitizen(bool, SpecialistTypes, int)
- CvCityCitizens::GetNumUnassignedCitizens() const
- CvGame::getActivePlayer() const
- CvGlobals::GetEngineUserInterface()
- CvGlobals::getGame()
- CvPlot::plotAction(PlotUnitFunc, int, int, PlayerTypes, TeamTypes)
ICvUserInterface1::setDirty- PUF_makeInfoBarDirty(CvUnit *, int, int)
std::max