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

Function UpdateTownGrowCounter

src/town_cmd.cpp:3804–3812  ·  view source on GitHub ↗

* Updates town grow counter after growth rate change. * Preserves relative house builting progress whenever it can. * @param t The town to calculate grow counter for * @param prev_growth_rate Town growth rate before it changed (one that was used with grow counter to be updated) */

Source from the content-addressed store, hash-verified

3802 * @param prev_growth_rate Town growth rate before it changed (one that was used with grow counter to be updated)
3803 */
3804static void UpdateTownGrowCounter(Town *t, uint16_t prev_growth_rate)
3805{
3806 if (t->growth_rate == TOWN_GROWTH_RATE_NONE) return;
3807 if (prev_growth_rate == TOWN_GROWTH_RATE_NONE) {
3808 t->grow_counter = std::min<uint16_t>(t->growth_rate, t->grow_counter);
3809 return;
3810 }
3811 t->grow_counter = RoundDivSU((uint32_t)t->grow_counter * (t->growth_rate + 1), prev_growth_rate + 1);
3812}
3813
3814/**
3815 * Calculates amount of active stations in the range of town (HZB_TOWN_EDGE).

Callers 1

UpdateTownGrowthRateFunction · 0.85

Calls 1

RoundDivSUFunction · 0.85

Tested by

no test coverage detected