# town.h File Reference

Base of the town class. More...

`#include "core/pool_type.hpp"`
`#include "viewport_type.h"`
`#include "command_type.h"`
`#include "town_map.h"`
`#include "subsidy_type.h"`

Go to the source code of this file.

## Data Structures
struct | BuildingCounts< T >
struct | Town
## Defines
#define | FOR_ALL_TOWNS_FROM(var, start) FOR_ALL_ITEMS_FROM(Town, town_index, var, start)
#define | FOR_ALL_TOWNS(var) FOR_ALL_TOWNS_FROM(var, 0)
## Typedefs
typedef Pool< Town, TownID, 64, 64000 > | TownPool
## Enumerations
enum | TownRatingCheckType { ROAD_REMOVE = 0, TUNNELBRIDGE_REMOVE = 1, TOWN_RATING_CHECK_TYPE_COUNT }
enum | { TOWN_IS_FUNDED = 0, TOWN_HAS_CHURCH = 1, TOWN_HAS_STADIUM = 2 }
| This enum is used in conjonction with town->flags. More...
enum | TownActions { TACT_NONE = 0x00, TACT_ADVERTISE_SMALL = 0x01, TACT_ADVERTISE_MEDIUM = 0x02, TACT_ADVERTISE_LARGE = 0x04, TACT_ROAD_REBUILD = 0x08, TACT_BUILD_STATUE = 0x10, TACT_FOUND_BUILDINGS = 0x20, TACT_BUY_RIGHTS = 0x40, TACT_BRIBE = 0x80, TACT_COUNT = 8, TACT_ADVERTISE = TACT_ADVERTISE_SMALL | TACT_ADVERTISE_MEDIUM | TACT_ADVERTISE_LARGE, TACT_CONSTRUCTION = TACT_ROAD_REBUILD | TACT_BUILD_STATUE | TACT_FOUND_BUILDINGS, TACT_FUNDS = TACT_BUY_RIGHTS | TACT_BRIBE, TACT_ALL = TACT_ADVERTISE | TACT_CONSTRUCTION | TACT_FUNDS }
| Town actions of a company. More...
## Functions
uint32 | GetWorldPopulation ()
| Determines the world population Basically, count population of all towns, one by one.
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.
bool | CheckforTownRating (DoCommandFlag flags, Town *t, TownRatingCheckType type)
TileIndexDiff | GetHouseNorthPart (HouseID &house)
| Determines if a given HouseID is part of a multitile house.
Town * | CalcClosestTownFromTile (TileIndex tile, uint threshold=UINT_MAX)
void | ResetHouses ()
void | ClearTownHouse (Town *t, TileIndex tile)
void | UpdateTownMaxPass (Town *t)
void | UpdateTownRadius (Town *t)
bool | CheckIfAuthorityAllowsNewStation (TileIndex tile, DoCommandFlag flags)
| Checks whether the local authority allows construction of a new station (rail, road, airport, dock) on the given tile.
Town * | ClosestTownFromTile (TileIndex tile, uint threshold)
void | ChangeTownRating (Town *t, int add, int max, DoCommandFlag flags)
| Changes town rating of the current company.
HouseZonesBits | GetTownRadiusGroup (const Town *t, TileIndex tile)
| Returns the bit corresponding to the town zone of the specified tile.
void | SetTownRatingTestMode (bool mode)
uint | GetMaskOfTownActions (int *nump, CompanyID cid, const Town *t)
| Get a list of available actions to do at a town.
bool | GenerateTowns (TownLayout layout)
| This function will generate a certain amount of towns, with a certain layout It can be called from the scenario editor (i.e.
| DECLARE_ENUM_AS_BIT_SET (TownActions)
static uint | TileHash (uint x, uint y)
| Calculate a hash value from a tile position.
static uint | TileHash2Bit (uint x, uint y)
| Get the last two bits of the TileHash from a tile position.
## Variables
static const uint | CUSTOM_TOWN_NUMBER_DIFFICULTY = 4
| value for custom town number in difficulty settings
static const uint | CUSTOM_TOWN_MAX_NUMBER = 5000
| this is the maximum number of towns a user can specify in customisation
static const uint | INVALID_TOWN = 0xFFFF
TownPool | _town_pool
static const byte | TOWN_GROWTH_FREQUENCY = 70
| This is the number of ticks between towns being processed for building new houses or roads.
const byte | _town_action_costs [TACT_COUNT]
| Factor in the cost of each town action.
TownID | _new_town_id

## Detailed Description

Base of the town class.

Definition in file town.h.

## Enumeration Type Documentation

anonymous enum

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

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 flags...

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 173 of file town.h.

enum TownActions

Town actions of a company.

Enumerator:

  TACT_NONE | Empty action set.
  TACT_ADVERTISE_SMALL | Small advertising campaign.
  TACT_ADVERTISE_MEDIUM | Medium advertising campaign.
  TACT_ADVERTISE_LARGE | Large advertising campaign.
  TACT_ROAD_REBUILD | Rebuild the roads.
  TACT_BUILD_STATUE | Build a statue.
  TACT_FOUND_BUILDINGS | Found new buildings.
  TACT_BUY_RIGHTS | Buy exclusive transport rights.
  TACT_BRIBE | Try to bribe the counsil.
  TACT_COUNT | Number of available town actions.
  TACT_ADVERTISE | All possible advertising actions.
  TACT_CONSTRUCTION | All possible construction actions.
  TACT_FUNDS | All possible funding actions.
  TACT_ALL | All possible actions.

Definition at line 204 of file town.h.

## Function Documentation

void ChangeTownRating | ( | Town * | t,
|  | int | add,
|  | int | max,
|  | DoCommandFlag | flags |
| ) |  |  |

Changes town rating of the current company.

Parameters:

  | t | Town to affect
  | add | Value to add
  | max | Minimum (add < 0) resp. maximum (add > 0) rating that should be archievable with this change
  | flags | Command flags, especially DC_NO_MODIFY_TOWN_RATING is tested

Definition at line 2769 of file town_cmd.cpp.

References DC_NO_MODIFY_TOWN_RATING, Cheats::magic_bulldozer, SetBit(), SetWindowDirty(), and Cheat::value.

Referenced by CheckAllowRemoveRoad(), and CmdPlantTree().

bool CheckIfAuthorityAllowsNewStation | ( | TileIndex | tile,
|  | DoCommandFlag | flags |
| ) |  |  |

Checks whether the local authority allows construction of a new station (rail, road, airport, dock) on the given tile.

Parameters:

  | tile | The tile where the station shall be constructed.
  | flags | Command flags. DC_NO_TEST_TOWN_RATING is tested.

Definition at line 2666 of file town_cmd.cpp.

References _settings_game, DC_NO_TEST_TOWN_RATING, EconomySettings::dist_local_authority, GameSettings::economy, and SetDParam().

Referenced by CmdBuildAirport(), CmdBuildDock(), CmdBuildRailStation(), and CmdBuildRoadStop().

bool GenerateTowns | ( | TownLayout | layout | ) |

This function will generate a certain amount of towns, with a certain layout It can be called from the scenario editor (i.e.

: generate Random Towns) as well as from world creation.

Parameters:

  | layout | which towns will be set to, when created

Returns:
  true if towns have been successfully created

Definition at line 1767 of file town_cmd.cpp.

References _settings_game, Chance16(), GameCreationSettings::custom_town_number, CUSTOM_TOWN_NUMBER_DIFFICULTY, GameSettings::difficulty, GameSettings::economy, GameSettings::game_creation, GenerateTownName(), GWP_TOWN, IncreaseGeneratingWorldProgress(), EconomySettings::larger_towns, DifficultySettings::number_towns, ScaleByMapSize(), SetGeneratingWorldProgress(), and TS_RANDOM.

Referenced by _GenerateWorld(), and FoundTownWindow::OnClick().

TileIndexDiff GetHouseNorthPart | ( | HouseID & | house | ) |

Determines if a given HouseID is part of a multitile house.

The given ID is set to the ID of the north tile and the TileDiff to the north tile is returned.

Parameters:

  | house | Is changed to the HouseID of the north tile of the same house

Returns:
  TileDiff from the tile of the given HouseID to the north tile

Definition at line 2221 of file town_cmd.cpp.

References TileDiffXY().

Referenced by GetDistanceFromNearbyHouse(), SearchNearbyHouseClass(), SearchNearbyHouseGRFID(), SearchNearbyHouseID(), and UpdateHousesAndTowns().

uint GetMaskOfTownActions | ( | int * | nump,
|  | CompanyID | cid,
|  | const Town * | t |
| ) |  |  |

Get a list of available actions to do at a town.

Parameters:

  | nump | if not NULL add put the number of available actions in it
  | cid | the company that is querying the town
  | t | the town that is queried

Returns:
  bitmasked value of enabled actions

Definition at line 2489 of file town_cmd.cpp.

References _settings_game, EconomySettings::bribe, COMPANY_SPECTATOR, GameSettings::economy, EconomySettings::exclusive_rights, HasBit(), lengthof, TACT_BRIBE, TACT_BUILD_STATUE, TACT_BUY_RIGHTS, and TACT_NONE.

Referenced by CmdDoTownAction(), TownAuthorityWindow::DrawWidget(), AITown::IsActionAvailable(), TownAuthorityWindow::OnClick(), and TownAuthorityWindow::OnPaint().

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

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

Parameters:

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

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

Definition at line 1812 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 380 of file town_cmd.cpp.

Referenced by TownDirectoryWindow::SetStringParameters().

static uint TileHash | ( | uint | x,
|  | uint | y |
| ) |  |  | `[inline, static]`

Calculate a hash value from a tile position.

Parameters:

  | x | The X coordinate
  | y | The Y coordinate

Returns:
  The hash of the tile

Definition at line 235 of file town.h.

Referenced by TileHash2Bit().

static uint TileHash2Bit | ( | uint | x,
|  | uint | y |
| ) |  |  | `[inline, static]`

Get the last two bits of the TileHash from a tile position.

See also:
  TileHash()

Parameters:

  | x | The X coordinate
  | y | The Y coordinate

Returns:
  The last two bits from hash of the tile

Definition at line 253 of file town.h.

References GB(), and TileHash().

Referenced by DrawTile_Town(), and HouseGetVariable().

void UpdateAllTownVirtCoords | ( |  | ) |

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

Definition at line 352 of file town_cmd.cpp.

Referenced by UpdateAllVirtCoords().

## Variable Documentation

const byte _town_action_costs[TACT_COUNT]

Factor in the cost of each town action.

See also:
  TownActions

Definition at line 2333 of file town_cmd.cpp.

Referenced by TownAuthorityWindow::DrawWidget(), and TownAuthorityWindow::UpdateWidgetSize().

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 165 of file town.h.