# town.h File Reference

`#include "oldpool.h"`
`#include "core/random_func.hpp"`
`#include "cargo_type.h"`
`#include "tile_type.h"`
`#include "date_type.h"`
`#include "town_type.h"`
`#include "player_type.h"`
`#include "newgrf_string_type.h"`

Go to the source code of this file.

## Data Structures

struct | BuildingCounts
struct | Town
struct | HouseSpec

## Defines

#define | FOR_ALL_TOWNS_FROM(t, start) for (t = GetTown(start); t != NULL; t = (t->index + 1U < GetTownPoolSize()) ? GetTown(t->index + 1U) : NULL) if (t->IsValid())
#define | FOR_ALL_TOWNS(t) FOR_ALL_TOWNS_FROM(t, 0)

## Enumerations

enum | { HOUSE_NO_CLASS = 0, NEW_HOUSE_OFFSET = 110, HOUSE_MAX = 512, INVALID_TOWN = 0xFFFF, INVALID_HOUSE_ID = 0xFFFF, HOUSE_CLASS_MAX = HOUSE_MAX - NEW_HOUSE_OFFSET + 1 }

enum

BuildingFlags {
TILE_NO_FLAG = 0, TILE_SIZE_1x1 = 1U << 0, TILE_NOT_SLOPED = 1U << 1, TILE_SIZE_2x1 = 1U << 2,
TILE_SIZE_1x2 = 1U << 3, TILE_SIZE_2x2 = 1U << 4, BUILDING_IS_ANIMATED = 1U << 5, BUILDING_IS_CHURCH = 1U << 6,
BUILDING_IS_STADIUM = 1U << 7, BUILDING_HAS_1_TILE = TILE_SIZE_1x1 | TILE_SIZE_2x1 | TILE_SIZE_1x2 | TILE_SIZE_2x2, BUILDING_2_TILES_X = TILE_SIZE_2x1 | TILE_SIZE_2x2, BUILDING_2_TILES_Y = TILE_SIZE_1x2 | TILE_SIZE_2x2,
BUILDING_HAS_4_TILES = TILE_SIZE_2x2
}

enum | HouseZonesBits { HZB_TOWN_EDGE = 0, HZB_TOWN_OUTSKIRT, HZB_TOWN_OUTER_SUBURB, HZB_TOWN_INNER_SUBURB, HZB_TOWN_CENTRE }
enum | HouseZones { HZ_NOZNS = 0x0000, HZ_ZON1 = 1U << HZB_TOWN_EDGE, HZ_ZON2 = 1U << HZB_TOWN_OUTSKIRT, HZ_ZON3 = 1U << HZB_TOWN_OUTER_SUBURB, HZ_ZON4 = 1U << HZB_TOWN_INNER_SUBURB, HZ_ZON5 = 1U << HZB_TOWN_CENTRE, HZ_ZONALL = 0x001F, HZ_SUBARTC_ABOVE = 0x0800, HZ_TEMP = 0x1000, HZ_SUBARTC_BELOW = 0x2000, HZ_SUBTROPIC = 0x4000, HZ_TOYLND = 0x8000 }
enum | HouseExtraFlags { NO_EXTRA_FLAG = 0, BUILDING_IS_HISTORICAL = 1U << 0, BUILDING_IS_PROTECTED = 1U << 1, SYNCHRONISED_CALLBACK_1B = 1U << 2, CALLBACK_1A_RANDOM_BITS = 1U << 3 }
enum | { ROAD_REMOVE = 0, UNMOVEABLE_REMOVE = 1, TUNNELBRIDGE_REMOVE = 1, INDUSTRY_REMOVE = 2 }
enum | { TOWN_IS_FUNDED = 0, TOWN_HAS_CHURCH = 1, TOWN_HAS_STADIUM = 2 }
| This enum is used in conjonction with town->flags12. More...

## Functions

uint32 | GetWorldPopulation ()
| Determines the world population Basically, count population of all towns, one by one.
void | UpdateTownVirtCoord (Town *t)
| Resize the sign(label) of the town after changes in population (creation or growth or else).
void | UpdateAllTownVirtCoords ()
| Update the virtual coords needed to draw the town sign for all towns.
void | InitializeTown ()
void | ShowTownViewWindow (TownID town)
void | ExpandTown (Town *t)
| Called from GUI.
Town * | CreateRandomTown (uint attempts, TownSizeMode mode, uint size)
bool | CheckforTownRating (uint32 flags, Town *t, byte type)
static HouseSpec * | GetHouseSpecs (HouseID house_id)
static bool | IsValidTownID (TownID index)
| Check if a TownID is valid.
static TownID | GetMaxTownIndex ()
static uint | GetNumTowns ()
static Town * | GetRandomTown ()
| Return a random valid town.
Town * | CalcClosestTownFromTile (TileIndex tile, uint threshold)
uint | OriginalTileRandomiser (uint x, uint y)
void | ResetHouses ()
void | ClearTownHouse (Town *t, TileIndex tile)
void | AfterLoadTown ()
void | UpdateTownMaxPass (Town *t)
void | UpdateTownRadius (Town *t)
bool | CheckIfAuthorityAllows (TileIndex tile)
Town * | ClosestTownFromTile (TileIndex tile, uint threshold)
void | ChangeTownRating (Town *t, int add, int max)
HouseZonesBits | GetTownRadiusGroup (const Town *t, TileIndex tile)
| Returns the bit corresponding to the town zone of the specified tile.
void | SetTownRatingTestMode (bool mode)

## Variables

HouseSpec | _house_specs [HOUSE_MAX]
static const byte | TOWN_GROWTH_FREQUENCY = 70
| This is the number of ticks between towns being processed for building new houses or roads.
static const byte | TOWN_HOUSE_COMPLETED = 3
| Simple value that indicates the house has reached the final stage of construction.
bool | _town_sort_dirty
byte | _town_sort_order
const Town ** | _town_sort
Town * | _cleared_town
int | _cleared_town_rating

## Detailed Description

Definition in file town.h.

## Enumeration Type Documentation

anonymous enum

This enum is used in conjonction with town->flags12.

IT simply states what bit is used for. It is pretty unrealistic (IMHO) to only have one church/stadium per town, NO MATTER the population of it. And there are 5 more bits available on flags12...

Enumerator:

  TOWN_IS_FUNDED | Town has received some funds for.
  TOWN_HAS_CHURCH | There can be only one church by town.
  TOWN_HAS_STADIUM | There can be only one stadium by town.

Definition at line 242 of file town.h.

enum HouseExtraFlags

Enumerator:

  BUILDING_IS_HISTORICAL | this house will only appear during town generation in random games, thus the historical
  BUILDING_IS_PROTECTED | towns and AI will not remove this house, while human players will be able tp
  SYNCHRONISED_CALLBACK_1B | synchronized callback 1B will be performed, on multi tile houses
  CALLBACK_1A_RANDOM_BITS | callback 1A needs random bits

Definition at line 72 of file town.h.

enum HouseZones

Enumerator:

  HZ_NOZNS | Bit Value Meaning. 0 This is just to get rid of zeros, meaning none
  HZ_ZON1 | 0..4 1,2,4,8,10 which town zones the building can be built in, Zone1 been the further suburb
  HZ_ZON5 | center of town
  HZ_ZONALL | 1F This is just to englobe all above types at once
  HZ_SUBARTC_ABOVE | 11 800 can appear in sub-arctic climate above the snow line
  HZ_TEMP | 12 1000 can appear in temperate climate
  HZ_SUBARTC_BELOW | 13 2000 can appear in sub-arctic climate below the snow line
  HZ_SUBTROPIC | 14 4000 can appear in subtropical climate
  HZ_TOYLND | 15 8000 can appear in toyland climate

Definition at line 55 of file town.h.

## Function Documentation

HouseZonesBits GetTownRadiusGroup | ( | const Town * | t,
|  | TileIndex | tile |
| ) |  |  |

Returns the bit corresponding to the town zone of the specified tile.

Parameters:

  | t | Town on which radius is to be found
  | tile | TileIndex where radius needs to be found

Returns:
  the bit position of the given zone, as defined in HouseZones

Definition at line 1591 of file town_cmd.cpp.

References DistanceSquare().

Referenced by BuildTownHouse(), HouseGetVariable(), and IndustryGetVariable().

uint32 GetWorldPopulation | ( |  | ) |

Determines the world population Basically, count population of all towns, one by one.

Returns:
  uint32 the calculated population of the world

Definition at line 349 of file town_cmd.cpp.

static bool IsValidTownID | ( | TownID | index | ) | `[inline, static]`

Check if a TownID is valid.

Parameters:

  | index | to inquiry in the pool of town

Returns:
  true if it exists

Definition at line 261 of file town.h.

Referenced by CmdBuildRoad(), CmdDoTownAction(), CmdRenameTown(), and GetRandomTown().

void UpdateAllTownVirtCoords | ( |  | ) |

Update the virtual coords needed to draw the town sign for all towns.

Definition at line 322 of file town_cmd.cpp.

References UpdateTownVirtCoord().

Referenced by InitializeWindowsAndCaches().

void UpdateTownVirtCoord | ( | Town * | t | ) |

Resize the sign(label) of the town after changes in population (creation or growth or else).

Parameters:

  | t | Town to update

Definition at line 308 of file town_cmd.cpp.

References MarkTownSignDirty(), TILE_SIZE, TileX(), and TileY().

Referenced by ChangePopulation(), CmdRenameTown(), DoCreateTown(), and UpdateAllTownVirtCoords().

## Variable Documentation

const byte TOWN_GROWTH_FREQUENCY = 70`[static]`

This is the number of ticks between towns being processed for building new houses or roads.

This value originally came from the size of the town array in TTD.

Definition at line 230 of file town.h.

const byte TOWN_HOUSE_COMPLETED = 3`[static]`

Simple value that indicates the house has reached the final stage of construction.

Definition at line 234 of file town.h.

Referenced by BuildTownHouse(), GetHouseBuildingStage(), IncHouseConstructionTick(), and MakeHouseTile().