Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

City Production Focus (UI) #6144

Closed
itanasi opened this issue Feb 11, 2022 · 7 comments
Closed

City Production Focus (UI) #6144

itanasi opened this issue Feb 11, 2022 · 7 comments
Labels

Comments

@itanasi
Copy link
Contributor

itanasi commented Feb 11, 2022

Civ 5 (and others in the series) gave the option to focus all production via population and specialists towards one metric. Either maximize Food, Production, Gold, or Science. And obviously revert to Balanced

Would be a nice feature to have.

Could also include UI to handle locking tiles as well (and unlock all tiles), and ideally locking Specialists too.

@xlenstra
Copy link
Collaborator

I think we already have a UI for locking/unlocking tiles, though whether tiles are locked is not actually used anywhere as far as I know. Focusing population to a single stat is also already marked as todo in #4697.

@itanasi
Copy link
Contributor Author

itanasi commented Feb 12, 2022

We have locking and unlocking individual tiles already. But no button to unlock all tiles yet.

@yairm210
Copy link
Owner

The problem isn't the UI, it's that the feature isn't well defined.
What does 'focuses on X' actually mean?
The main problem here is regarding food, I think. You need a minimum amount of food so the city doesn't starve.
A way around this would be to try the naive 'each unit of X is worth 2 instead of 1' in rankStatsValue (that means a new focus:Stat? parameter), and if there's enough food then great
If NOT, then take food-heavy tiles until you have enough to break even, and only then prioritize tiles based on the focused stat

@itanasi
Copy link
Contributor Author

itanasi commented Feb 13, 2022

I haven't found any code about how the Focus works exactly in Civ 5 as basis. I feel like it does the latter. Make sure you don't starve, then max focused stat, then use standard algo for the rest. I should boot it up and fiddle around.

It seems like in Vanilla they had issues where they would starve the city

@xlenstra
Copy link
Collaborator

xlenstra commented Feb 13, 2022

Looking a bit through the source code distributed with the game (G&K version), the relevant function appears to be this:

GetPlotValue()
/// What is the overall value of the current Plot?
int CvCityCitizens::GetPlotValue(CvPlot* pPlot, bool bUseAllowGrowthFlag)
{
	int iValue = 0;

	// Yield Values
	int iFoodYieldValue = (/*12*/ GC.getAI_CITIZEN_VALUE_FOOD() * pPlot->getYield(YIELD_FOOD));
	int iProductionYieldValue = (/*8*/ GC.getAI_CITIZEN_VALUE_PRODUCTION() * pPlot->getYield(YIELD_PRODUCTION));
	int iGoldYieldValue = (/*10*/ GC.getAI_CITIZEN_VALUE_GOLD() * pPlot->getYield(YIELD_GOLD));
	int iScienceYieldValue = (/*6*/ GC.getAI_CITIZEN_VALUE_SCIENCE() * pPlot->getYield(YIELD_SCIENCE));
	int iCultureYieldValue = (/*6*/ GC.getAI_CITIZEN_VALUE_CULTURE() * pPlot->getYield(YIELD_CULTURE));
	int iFaithYieldValue = (/*5*/ GC.getAI_CITIZEN_VALUE_FAITH() * pPlot->getYield(YIELD_FAITH));

	// How much surplus food are we making?
	int iExcessFoodTimes100 = m_pCity->getYieldRateTimes100(YIELD_FOOD) - (m_pCity->foodConsumption() * 100);

	bool bAvoidGrowth = IsAvoidGrowth();

	// City Focus
	CityAIFocusTypes eFocus = GetFocusType();
	if(eFocus == CITY_AI_FOCUS_TYPE_FOOD)
		iFoodYieldValue *= 3;
	else if(eFocus == CITY_AI_FOCUS_TYPE_PRODUCTION)
		iProductionYieldValue *= 3;
	else if(eFocus == CITY_AI_FOCUS_TYPE_GOLD)
		iGoldYieldValue *= 3;
	else if(eFocus == CITY_AI_FOCUS_TYPE_SCIENCE)
		iScienceYieldValue *= 3;
	else if(eFocus == CITY_AI_FOCUS_TYPE_CULTURE)
		iCultureYieldValue *= 3;
	else if(eFocus == CITY_AI_FOCUS_TYPE_GOLD_GROWTH)
	{
		iFoodYieldValue *= 2;
		iGoldYieldValue *= 2;
	}
	else if(eFocus == CITY_AI_FOCUS_TYPE_PROD_GROWTH)
	{
		iFoodYieldValue *= 2;
		iProductionYieldValue *= 2;
	}
	else if(eFocus == CITY_AI_FOCUS_TYPE_FAITH)
	{
		iFaithYieldValue *= 3;
	}

	// Food can be worth less if we don't want to grow
	if(bUseAllowGrowthFlag && iExcessFoodTimes100 >= 0 && bAvoidGrowth)
	{
		// If we at least have enough Food to feed everyone, zero out the value of additional food
		iFoodYieldValue = 0;
	}
	// We want to grow here
	else
	{
		// If we have a non-default and non-food focus, only worry about getting to 0 food
		if(eFocus != NO_CITY_AI_FOCUS_TYPE && eFocus != CITY_AI_FOCUS_TYPE_FOOD && eFocus != CITY_AI_FOCUS_TYPE_PROD_GROWTH && eFocus != CITY_AI_FOCUS_TYPE_GOLD_GROWTH)
		{
			int iFoodT100NeededFor0 = -iExcessFoodTimes100;

			if(iFoodT100NeededFor0 > 0)
			{
				iFoodYieldValue *= 8;
			}
			else
			{
				iFoodYieldValue /= 2;
			}
		}
		// If our surplus is not at least 2, really emphasize food plots
		else if(!bAvoidGrowth)
		{
			int iFoodT100NeededFor2 = 200 - iExcessFoodTimes100;

			if(iFoodT100NeededFor2 > 0)
			{
				iFoodYieldValue *= 8;
			}
			else if (eFocus != CITY_AI_FOCUS_TYPE_FOOD)
			{
				iFoodYieldValue /= 2;
			}
		}
	}

	if((eFocus == NO_CITY_AI_FOCUS_TYPE || eFocus == CITY_AI_FOCUS_TYPE_PROD_GROWTH || eFocus == CITY_AI_FOCUS_TYPE_GOLD_GROWTH) && !bAvoidGrowth && m_pCity->getPopulation() < 5)
	{
		iFoodYieldValue *= 4;
	}

	iValue += iFoodYieldValue;
	iValue += iProductionYieldValue;
	iValue += iGoldYieldValue;
	iValue += iScienceYieldValue;
	iValue += iCultureYieldValue;
	iValue += iFaithYieldValue;

	return iValue;
}

Source: CvGameCoreDLL_Expansion1/CvCityCitizens.cpp::405

Which indeed seems on first glance to do exactly that: get food tiles when we're starving, and otherwise decided based on the focus that is set in the city

@itanasi
Copy link
Contributor Author

itanasi commented Feb 13, 2022

Oooh, had forgotten about the Avoid Growth feature. Add that to the TODO list

@SomeTroglodyte
Copy link
Collaborator

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants