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

Function UpdateTownRadius

src/town_cmd.cpp:1956–1997  ·  view source on GitHub ↗

* Update the cached town zone radii of a town, based on the number of houses. * @param t The town to update. */

Source from the content-addressed store, hash-verified

1954 * @param t The town to update.
1955 */
1956void UpdateTownRadius(Town *t)
1957{
1958 static const std::array<std::array<uint32_t, NUM_HOUSE_ZONES>, 23> _town_squared_town_zone_radius_data = {{
1959 { 4, 0, 0, 0, 0}, // 0
1960 { 16, 0, 0, 0, 0},
1961 { 25, 0, 0, 0, 0},
1962 { 36, 0, 0, 0, 0},
1963 { 49, 0, 4, 0, 0},
1964 { 64, 0, 4, 0, 0}, // 20
1965 { 64, 0, 9, 0, 1},
1966 { 64, 0, 9, 0, 4},
1967 { 64, 0, 16, 0, 4},
1968 { 81, 0, 16, 0, 4},
1969 { 81, 0, 16, 0, 4}, // 40
1970 { 81, 0, 25, 0, 9},
1971 { 81, 36, 25, 0, 9},
1972 { 81, 36, 25, 16, 9},
1973 { 81, 49, 0, 25, 9},
1974 { 81, 64, 0, 25, 9}, // 60
1975 { 81, 64, 0, 36, 9},
1976 { 81, 64, 0, 36, 16},
1977 {100, 81, 0, 49, 16},
1978 {100, 81, 0, 49, 25},
1979 {121, 81, 0, 49, 25}, // 80
1980 {121, 81, 0, 49, 25},
1981 {121, 81, 0, 49, 36}, // 88
1982 }};
1983
1984 if (t->cache.num_houses < std::size(_town_squared_town_zone_radius_data) * 4) {
1985 t->cache.squared_town_zone_radius = _town_squared_town_zone_radius_data[t->cache.num_houses / 4];
1986 } else {
1987 int mass = t->cache.num_houses / 8;
1988 /* Actually we are proportional to sqrt() but that's right because we are covering an area.
1989 * The offsets are to make sure the radii do not decrease in size when going from the table
1990 * to the calculated value.*/
1991 t->cache.squared_town_zone_radius[to_underlying(HouseZone::TownEdge)] = mass * 15 - 40;
1992 t->cache.squared_town_zone_radius[to_underlying(HouseZone::TownOutskirt)] = mass * 9 - 15;
1993 t->cache.squared_town_zone_radius[to_underlying(HouseZone::TownOuterSuburb)] = 0;
1994 t->cache.squared_town_zone_radius[to_underlying(HouseZone::TownInnerSuburb)] = mass * 5 - 5;
1995 t->cache.squared_town_zone_radius[to_underlying(HouseZone::TownCentre)] = mass * 3 + 5;
1996 }
1997}
1998
1999/**
2000 * Update the maximum amount of monthly passengers and mail for a town, based on its population.

Callers 5

DoCreateTownFunction · 0.85
BuildTownHouseFunction · 0.85
ClearTownHouseFunction · 0.85
CmdExpandTownFunction · 0.85
RebuildTownCachesFunction · 0.85

Calls 2

to_underlyingFunction · 0.85
sizeFunction · 0.50

Tested by

no test coverage detected