Bazaar developer reference

CvCityCitizens::DoTurn()

Defined in
CvCityCitizens.cpp, line 239
Class
CvCityCitizens
Hook name
CivHooks::CvCityCitizens_DoTurn

Hooks

static bool BeforeCvCityCitizens_DoTurn(CvCityCitizens* self);static void AfterCvCityCitizens_DoTurn(CvCityCitizens* self);static void ReplaceCvCityCitizens_DoTurn(void (*original)(CvCityCitizens*), CvCityCitizens* self);CivRegisterBefore<CivHooks::CvCityCitizens_DoTurn>(host, &BeforeCvCityCitizens_DoTurn);CivRegisterAfter<CivHooks::CvCityCitizens_DoTurn>(host, &AfterCvCityCitizens_DoTurn);CivRegisterReplace<CivHooks::CvCityCitizens_DoTurn>(host, &ReplaceCvCityCitizens_DoTurn);

Code

238/// Processed every turn239void CvCityCitizens::DoTurn()240{241	AI_PERF_FORMAT("City-AI-perf.csv", ("CvCityCitizens::DoTurn, Turn %03d, %s, %s", GC.getGame().getElapsedGameTurns(), m_pCity->GetPlayer()->getCivilizationShortDescription(), m_pCity->getName().c_str()) );242	DoVerifyWorkingPlots();243244	CvPlayerAI& thisPlayer = GET_PLAYER(GetOwner());245246#if defined(MOD_AI_SMART_V3)247	bool bWonder = false;248	bool bSettler = false;249	250	if (MOD_AI_SMART_V3)251	{252		const OrderData* pOrderNode = m_pCity->headOrderQueueNode();253		CvUnitEntry* pkUnitInfo = NULL;254		CvBuildingClassInfo* pkBuildingClassInfo = NULL;255	256		if(pOrderNode != NULL && pOrderNode->eOrderType == ORDER_TRAIN)257		{258			pkUnitInfo = GC.getUnitInfo((UnitTypes)pOrderNode->iData1);259			if(pkUnitInfo != NULL && pkUnitInfo->IsFound())260			{261				bSettler = true;262			}263		}264		else if (pOrderNode != NULL && pOrderNode->eOrderType == ORDER_CONSTRUCT)265		{266			CvBuildingEntry* pkOrderBuildingInfo = GC.getBuildingInfo((BuildingTypes)pOrderNode->iData1);267268			if(pkOrderBuildingInfo)269			{270				const BuildingClassTypes eOrderBuildingClass = (BuildingClassTypes)pkOrderBuildingInfo->GetBuildingClassType();271				if(eOrderBuildingClass != NO_BUILDINGCLASS)272				{273					pkBuildingClassInfo = GC.getBuildingClassInfo(eOrderBuildingClass);274					if(pkBuildingClassInfo && pkBuildingClassInfo->getMaxGlobalInstances() == 1)275					{276						bWonder = true;277					}278				}279			}280		}281	}282#endif283284	if(m_pCity->IsPuppet())285	{286#if defined(MOD_UI_CITY_PRODUCTION)287		if(!(MOD_UI_CITY_PRODUCTION && thisPlayer.isHuman()))288		{289#endif290			SetFocusType(CITY_AI_FOCUS_TYPE_GOLD);291			SetNoAutoAssignSpecialists(false);292			SetForcedAvoidGrowth(false);293			int iExcessFoodTimes100 = m_pCity->getYieldRateTimes100(YIELD_FOOD, false) - (m_pCity->foodConsumption() * 100);294			if(iExcessFoodTimes100 < 0)295			{296				SetFocusType(NO_CITY_AI_FOCUS_TYPE);297				//SetNoAutoAssignSpecialists(true);298				SetForcedAvoidGrowth(false);299			}300#if defined(MOD_UI_CITY_PRODUCTION)301		}302#endif303	}304	else if(!thisPlayer.isHuman())305	{306		CitySpecializationTypes eWonderSpecializationType = thisPlayer.GetCitySpecializationAI()->GetWonderSpecialization();307308		if(GC.getGame().getGameTurn() % 8 == 0)309		{310			SetFocusType(CITY_AI_FOCUS_TYPE_GOLD_GROWTH);311			SetNoAutoAssignSpecialists(true);312			SetForcedAvoidGrowth(false);313			int iExcessFoodTimes100 = m_pCity->getYieldRateTimes100(YIELD_FOOD, false) - (m_pCity->foodConsumption() * 100);314			if(iExcessFoodTimes100 < 200)315			{316				SetFocusType(NO_CITY_AI_FOCUS_TYPE);317				//SetNoAutoAssignSpecialists(true);318			}319		}320#if defined(MOD_AI_SMART_V3)321		if(m_pCity->isCapital() && !thisPlayer.isMinorCiv() && (m_pCity->GetCityStrategyAI()->GetSpecialization() != eWonderSpecializationType) && !bWonder && !bSettler)322#else323		if(m_pCity->isCapital() && !thisPlayer.isMinorCiv() && m_pCity->GetCityStrategyAI()->GetSpecialization() != eWonderSpecializationType)324#endif325		{326			SetFocusType(NO_CITY_AI_FOCUS_TYPE);327			SetNoAutoAssignSpecialists(false);328			SetForcedAvoidGrowth(false);329			int iExcessFoodTimes100 = m_pCity->getYieldRateTimes100(YIELD_FOOD, false) - (m_pCity->foodConsumption() * 100);330			if(iExcessFoodTimes100 < 400)331			{332				SetFocusType(CITY_AI_FOCUS_TYPE_FOOD);333				//SetNoAutoAssignSpecialists(true);334			}335		}336#if defined(MOD_AI_SMART_V3)337		else if((m_pCity->GetCityStrategyAI()->GetSpecialization() == eWonderSpecializationType) || bWonder || bSettler)338#else339		else if(m_pCity->GetCityStrategyAI()->GetSpecialization() == eWonderSpecializationType)340#endif341		{342			SetFocusType(CITY_AI_FOCUS_TYPE_PRODUCTION);343			SetNoAutoAssignSpecialists(false);344			//SetForcedAvoidGrowth(true);345			int iExcessFoodTimes100;// = m_pCity->getYieldRateTimes100(YIELD_FOOD) - (m_pCity->foodConsumption() * 100);346			//if (iExcessFoodTimes100 < 200)347			//{348			SetForcedAvoidGrowth(false);349			//}350#if defined(MOD_AI_SMART_V3)351			if (!MOD_AI_SMART_V3 || !bSettler)352			{353#endif354			iExcessFoodTimes100 = m_pCity->getYieldRateTimes100(YIELD_FOOD, false) - (m_pCity->foodConsumption() * 100);355			if(iExcessFoodTimes100 < 200)356			{357				SetFocusType(CITY_AI_FOCUS_TYPE_PROD_GROWTH);358				//SetNoAutoAssignSpecialists(true);359				SetForcedAvoidGrowth(false);360			}361			iExcessFoodTimes100 = m_pCity->getYieldRateTimes100(YIELD_FOOD, false) - (m_pCity->foodConsumption() * 100);362			if(iExcessFoodTimes100 < 200)363			{364				SetFocusType(NO_CITY_AI_FOCUS_TYPE);365				//SetNoAutoAssignSpecialists(true);366				SetForcedAvoidGrowth(false);367			}368#if defined(MOD_AI_SMART_V3)369			}370#endif371		}372		else if(m_pCity->getPopulation() < 5)  // we want a balanced growth373		{374			SetFocusType(NO_CITY_AI_FOCUS_TYPE);375			//SetNoAutoAssignSpecialists(true);376			SetForcedAvoidGrowth(false);377		}378		else379		{380			// Are we running at a deficit?381			EconomicAIStrategyTypes eStrategyLosingMoney = (EconomicAIStrategyTypes) GC.getInfoTypeForString("ECONOMICAISTRATEGY_LOSING_MONEY", true);382			bool bInDeficit = false;383			if (eStrategyLosingMoney != NO_ECONOMICAISTRATEGY)384			{385				bInDeficit = thisPlayer.GetEconomicAI()->IsUsingStrategy(eStrategyLosingMoney);386			}387388			if(bInDeficit)389			{390				SetFocusType(CITY_AI_FOCUS_TYPE_GOLD_GROWTH);391				SetNoAutoAssignSpecialists(false);392				SetForcedAvoidGrowth(false);393				int iExcessFoodTimes100 = m_pCity->getYieldRateTimes100(YIELD_FOOD, false) - (m_pCity->foodConsumption() * 100);394				if(iExcessFoodTimes100 < 200)395				{396					SetFocusType(NO_CITY_AI_FOCUS_TYPE);397					//SetNoAutoAssignSpecialists(true);398				}399			}400			else if(GC.getGame().getGameTurn() % 3 == 0 && thisPlayer.GetGrandStrategyAI()->GetActiveGrandStrategy() == (AIGrandStrategyTypes) GC.getInfoTypeForString("AIGRANDSTRATEGY_CULTURE"))401			{402				SetFocusType(CITY_AI_FOCUS_TYPE_CULTURE);403				SetNoAutoAssignSpecialists(true);404				SetForcedAvoidGrowth(false);405				int iExcessFoodTimes100 = m_pCity->getYieldRateTimes100(YIELD_FOOD, false) - (m_pCity->foodConsumption() * 100);406				if(iExcessFoodTimes100 < 200)407				{408					SetFocusType(NO_CITY_AI_FOCUS_TYPE);409					//SetNoAutoAssignSpecialists(true);410				}411			}412			else // we aren't a small city, building a wonder, or going broke413			{414				SetNoAutoAssignSpecialists(false);415				SetForcedAvoidGrowth(false);416				CitySpecializationTypes eSpecialization = m_pCity->GetCityStrategyAI()->GetSpecialization();417				if(eSpecialization != -1)418				{419					CvCitySpecializationXMLEntry* pCitySpecializationEntry =  GC.getCitySpecializationInfo(eSpecialization);420					if(pCitySpecializationEntry)421					{422						YieldTypes eYield = pCitySpecializationEntry->GetYieldType();423						if(eYield == YIELD_FOOD)424						{425							SetFocusType(CITY_AI_FOCUS_TYPE_FOOD);426						}427						else if(eYield == YIELD_PRODUCTION)428						{429							SetFocusType(CITY_AI_FOCUS_TYPE_PROD_GROWTH);430						}431						else if(eYield == YIELD_GOLD)432						{433							SetFocusType(CITY_AI_FOCUS_TYPE_GOLD);434						}435						else if(eYield == YIELD_SCIENCE)436						{437							SetFocusType(CITY_AI_FOCUS_TYPE_SCIENCE);438						}439						else440						{441							SetFocusType(NO_CITY_AI_FOCUS_TYPE);442						}443					}444					else445					{446						SetFocusType(NO_CITY_AI_FOCUS_TYPE);447					}448				}449				else450				{451					SetFocusType(NO_CITY_AI_FOCUS_TYPE);452				}453			}454		}455	}456457#if defined(MOD_GLOBAL_CITY_AUTOMATON_WORKERS)458	CvAssertMsg((GetNumCitizensWorkingPlots() + GetTotalSpecialistCount() + GetNumUnassignedCitizens()) <= GetCity()->getPopulation(true), "Gameplay: More workers than population in the city.");459#else460	CvAssertMsg((GetNumCitizensWorkingPlots() + GetTotalSpecialistCount() + GetNumUnassignedCitizens()) <= GetCity()->getPopulation(), "Gameplay: More workers than population in the city.");461#endif462	DoReallocateCitizens();463#if defined(MOD_GLOBAL_CITY_AUTOMATON_WORKERS)464	CvAssertMsg((GetNumCitizensWorkingPlots() + GetTotalSpecialistCount() + GetNumUnassignedCitizens()) <= GetCity()->getPopulation(true), "Gameplay: More workers than population in the city.");465#else466	CvAssertMsg((GetNumCitizensWorkingPlots() + GetTotalSpecialistCount() + GetNumUnassignedCitizens()) <= GetCity()->getPopulation(), "Gameplay: More workers than population in the city.");467#endif468	DoSpecialists();469470#if defined(MOD_GLOBAL_CITY_AUTOMATON_WORKERS)471	CvAssertMsg((GetNumCitizensWorkingPlots() + GetTotalSpecialistCount() + GetNumUnassignedCitizens()) <= GetCity()->getPopulation(true), "Gameplay: More workers than population in the city.");472#else473	CvAssertMsg((GetNumCitizensWorkingPlots() + GetTotalSpecialistCount() + GetNumUnassignedCitizens()) <= GetCity()->getPopulation(), "Gameplay: More workers than population in the city.");474#endif475}

Calls

Called by