+/** + * Calculates town growth rate in normal conditions (custom growth rate not set). + * @param town The town to calculate growth rate for + * @returns Calculated growth rate + */ +static uint GetNormalGrowthRate(Town *t) +{ + /** + * Towns are processed every TOWN_GROWTH_TICKS ticks, and this is the + * number of times towns are processed before a new building is built. + */ + static const uint16 _grow_count_values[2][6] = { + { 120, 120, 120, 100, 80, 60 }, // Fund new buildings has been activated + { 320, 420, 300, 220, 160, 100 } // Normal values + }; + + int n = CountActiveStations(t); + uint16 m = _grow_count_values[t->fund_buildings_months != 0 ? 0 : 1][min(n, 5)]; + + /* Use the normal growth rate values if new buildings have been funded in + * this town and the growth rate is set to none. */ + uint growth_multiplier = _settings_game.economy.town_growth_rate != 0 ? _settings_game.economy.town_growth_rate - 1 : 1; + + m >>= growth_multiplier; + if (t->larger_town) m /= 2; + + return m / (t->cache.num_houses / 50 + 1); +}