voxeltycoon / issues

18 stars 4 forks source link

Wrong number for "Required population" in the city demands window #844

Closed xmnovotny closed 2 years ago

xmnovotny commented 3 years ago

Describe the bug In the industrial type city, there is incorect display of required population for increase demands limit.

Steps to reproduce Look to the numbers of industrial city while it grows, especially for larger cities.

Build version 0.86.0.0, 0.86.0.4

Platform Windows

Reproducibility every time

In the code, there is wrong calcuation of required popuation, because it ignores City.ExtraDemand value.

Below is my quick fix using Harmony, which seems to work:

[HarmonyPostfix]
[HarmonyPatch(typeof(CityWindowDemandsTabHeader), "Invalidate")]
private static void CityWindowDemandsTabHeader_Invalidate_pof(CityWindowDemandsTabHeader __instance, City ____city, Text ____nextPopulationText)
{
    if (____city.Type == CityType.Industrial)
    {
        int demandLimit = ____city.DemandLimit;
        int newPopulation = ____city.GetPopulation(demandLimit - ____city.ExtraDemandLimit + 1);
        if (newPopulation <= 0)
        {
            newPopulation = Mathf.Max(newPopulation, ____city.Population);
        }
        if (____city.Status != CityStatus.Megapolis)
        {
            int newStatusPopulation = ____city.GetPopulation(____city.Status + 1);
            if (newStatusPopulation < newPopulation)
            {
                int newPopulation2 = ____city.GetPopulation(demandLimit - ____city.ExtraDemandLimit);
                newPopulation = Mathf.Min(Mathf.Max(newPopulation2, newStatusPopulation));
            }
        }
        ____nextPopulationText.text = StringHelper.Nicify(newPopulation);
    }
}
andrewpey commented 2 years ago

The latest build on the beta branch should include the fix.