diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index de252cdb41..1f0aecd4ab 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -79,6 +79,8 @@ void RebuildTownKdtree() _town_kdtree.Build(townids.begin(), townids.end()); } +/** Set if a town is being generated. */ +static bool _generating_town = false; /** * Check if a town 'owns' a bridge. @@ -442,6 +444,8 @@ void ClearAllTownCachedNames() static void ChangePopulation(Town *t, int mod) { t->cache.population += mod; + if (_generating_town) [[unlikely]] return; + InvalidateWindowData(WC_TOWN_VIEW, t->index); // Cargo requirements may appear/vanish for small populations if (_settings_client.gui.population_in_label) t->UpdateVirtCoord(); @@ -1973,6 +1977,8 @@ static void UpdateTownGrowth(Town *t); */ static void DoCreateTown(Town *t, TileIndex tile, uint32_t townnameparts, TownSize size, bool city, TownLayout layout, bool manual) { + AutoRestoreBackup backup(_generating_town, true); + t->xy = tile; t->cache.num_houses = 0; t->time_until_rebuild = 10; @@ -2016,9 +2022,6 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32_t townnameparts, TownSi } t->townnameparts = townnameparts; - t->UpdateVirtCoord(); - InvalidateWindowData(WC_TOWN_DIRECTORY, 0, TDIWD_FORCE_REBUILD); - t->InitializeLayout(layout); t->larger_town = city; @@ -2036,6 +2039,9 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32_t townnameparts, TownSi GrowTown(t); } while (--i); + t->UpdateVirtCoord(); + InvalidateWindowData(WC_TOWN_DIRECTORY, 0, TDIWD_FORCE_REBUILD); + t->cache.num_houses -= x; UpdateTownRadius(t); UpdateTownGrowthRate(t);