MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetNormalGrowthRate

Function GetNormalGrowthRate

src/town_cmd.cpp:3836–3857  ·  view source on GitHub ↗

* Calculates town growth rate in normal conditions (custom growth rate not set). * If town growth speed is set to None(0) returns the same rate as if it was Normal(2). * @param t The town to calculate growth rate for * @returns Calculated growth rate */

Source from the content-addressed store, hash-verified

3834 * @returns Calculated growth rate
3835 */
3836static uint GetNormalGrowthRate(Town *t)
3837{
3838 /**
3839 * Note:
3840 * Unserviced+unfunded towns get an additional malus in UpdateTownGrowth(),
3841 * so the "320" is actually not better than the "420".
3842 */
3843 static const uint16_t _grow_count_values[2][6] = {
3844 { 120, 120, 120, 100, 80, 60 }, // Fund new buildings has been activated
3845 { 320, 420, 300, 220, 160, 100 } // Normal values
3846 };
3847
3848 int n = CountActiveStations(t);
3849 uint16_t m = _grow_count_values[t->fund_buildings_months != 0 ? 0 : 1][std::min(n, 5)];
3850
3851 uint growth_multiplier = _settings_game.economy.town_growth_rate != 0 ? _settings_game.economy.town_growth_rate - 1 : 1;
3852
3853 m >>= growth_multiplier;
3854 if (t->larger_town) m /= 2;
3855
3856 return TownTicksToGameTicks(m / (t->cache.num_houses / 50 + 1));
3857}
3858
3859/**
3860 * Updates town growth rate.

Callers 1

UpdateTownGrowthRateFunction · 0.85

Calls 2

CountActiveStationsFunction · 0.85
TownTicksToGameTicksFunction · 0.85

Tested by

no test coverage detected