Skip to content

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

@xmnovotny

Description

@xmnovotny

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);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions