# Town Struct Reference

Inheritance diagram for Town:

## Public Member Functions
| Town (TileIndex tile=INVALID_TILE)
| Creates a new town.
| ~Town ()
| Destroy the town.
void | InitializeLayout (TownLayout layout)
| Assigns town layout.
uint16 | MaxTownNoise () const
| Calculate the max town noise The value is counted using the population divided by the content of the entry in town_noise_population corespondig to the town's tolerance.
void | UpdateVirtCoord ()
| Resize the sign(label) of the town after changes in population (creation or growth or else).
## Static Public Member Functions
static FORCEINLINE Town * | GetByTile (TileIndex tile)
static Town * | GetRandom ()
| Return a random valid town.
static void | PostDestructor (size_t index)
| Invalidating of the "nearest town cache" has to be done after removing item from the pool.
## Data Fields
TileIndex | xy
uint32 | num_houses
uint32 | population
uint32 | townnamegrfid
uint16 | townnametype
uint32 | townnameparts
char * | name
ViewportSign | sign
byte | flags
uint16 | noise_reached
CompanyMask | statues
CompanyMask | have_ratings
uint8 | unwanted [MAX_COMPANIES]
| how many months companies aren't wanted by towns (bribe)
CompanyByte | exclusivity
| which company has exclusivity
uint8 | exclusive_counter
| months till the exclusivity expires
int16 | ratings [MAX_COMPANIES]
uint32 | max_pass
uint32 | max_mail
uint32 | new_max_pass
uint32 | new_max_mail
uint32 | act_pass
uint32 | act_mail
uint32 | new_act_pass
uint32 | new_act_mail
byte | pct_pass_transported
byte | pct_mail_transported
uint16 | act_food
uint16 | act_water
uint16 | new_act_food
uint16 | new_act_water
uint16 | time_until_rebuild
uint16 | grow_counter
int16 | growth_rate
byte | fund_buildings_months
byte | road_build_months
bool | larger_town
TownLayoutByte | layout
| town specific road layout
PartOfSubsidyByte | part_of_subsidy
| NOSAVE: is this town a source/destination of a subsidy?
uint32 | squared_town_zone_radius [HZB_END]
BuildingCounts< uint16 > | building_counts

## Detailed Description

Definition at line 35 of file town.h.

## Member Function Documentation

Town * Town::GetRandom | ( |  | ) | `[static]`

Return a random valid town.

Returns:
  random town, NULL if there are no towns

Definition at line 133 of file town_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_town_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_town_pool >::GetNumItems(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_town_pool >::GetPoolSize(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_town_pool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_town_pool >::IsValidID(), and MAX_UVALUE.

void Town::InitializeLayout | ( | TownLayout | layout | ) |

Assigns town layout.

If Random, generates one based on TileHash.

Definition at line 119 of file town_cmd.cpp.

References NUM_TLS, TileHash(), TileX(), TileY(), and TL_RANDOM.

Referenced by DoCreateTown().

uint16 Town::MaxTownNoise | ( |  | ) | const`[inline]`

Calculate the max town noise The value is counted using the population divided by the content of the entry in town_noise_population corespondig to the town's tolerance.

To this result, we add 3, which is the noise of the lowest airport. So user can at least buld that airport

Returns:
  the maximum noise level the town will tolerate

Definition at line 131 of file town.h.

References _settings_game, GameSettings::difficulty, GameSettings::economy, DifficultySettings::town_council_tolerance, and EconomySettings::town_noise_population.

Referenced by CmdBuildAirport(), TownViewWindow::DrawWidget(), and AITown::GetAllowedNoise().

void Town::PostDestructor | ( | size_t | index | ) | `[static]`

Invalidating of the "nearest town cache" has to be done after removing item from the pool.

Parameters:

  | index | index of deleted item

Reimplemented from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_town_pool >.

Definition at line 110 of file town_cmd.cpp.

References InvalidateWindowData(), and UpdateNearestTownForRoadTiles().

The documentation for this struct was generated from the following files:

- src/town.h
- src/town_cmd.cpp