OpenTTD Source: src/town.h File Reference

OpenTTD Source 15.3

Data Structures | Typedefs | Enumerations | Functions | Variables
town.h File Reference

Base of the town class. More...

`#include "misc/history_type.hpp"`
`#include "viewport_type.h"`
`#include "timer/timer_game_tick.h"`
`#include "town_map.h"`
`#include "subsidy_type.h"`
`#include "newgrf_storage.h"`
`#include "cargotype.h"`

Go to the source code of this file.

## Data Structures
struct | BuildingCounts< T >
struct | TownCache
| Data structure with cached data of towns. More...
struct | Town
| Town data structure. More...
struct | Town::SuppliedHistory
struct | Town::SuppliedCargo

## Typedefs
typedef Pool< Town, TownID, 64 > | TownPool
using | TownFlags = EnumBitSet< TownFlag, uint8_t >
using | TownActions = EnumBitSet< TownAction, uint8_t >

## Enumerations
enum class | TownFlag : uint8_t { IsGrowing = 0 , HasChurch = 1 , HasStadium = 2 , CustomGrowth = 3 }
| Flags controlling various town behaviours. More...
enum | TownCouncilAttitudes { TOWN_COUNCIL_LENIENT = 0 , TOWN_COUNCIL_TOLERANT = 1 , TOWN_COUNCIL_HOSTILE = 2 , TOWN_COUNCIL_PERMISSIVE = 3 }
| Settings for town council attitudes. More...
enum class | TownRatingCheckType : uint8_t { RoadRemove , TunnelBridgeRemove , End }
| Action types that a company must ask permission for to a town authority. More...
enum | TownDirectoryInvalidateWindowData { TDIWD_FORCE_REBUILD , TDIWD_POPULATION_CHANGE , TDIWD_FORCE_RESORT }
| Special values for town list window for the data parameter of InvalidateWindowData. More...
enum class | TownAction : uint8_t { AdvertiseSmall , AdvertiseMedium , AdvertiseLarge , RoadRebuild , BuildStatue , FundBuildings , BuyRights , Bribe , End }
| Town actions of a company. More...

## Functions
uint32_t | GetWorldPopulation ()
| Get the total population, the sum of all towns in the world.
void | UpdateAllTownVirtCoords ()
| Update the virtual coords needed to draw the town sign for all towns.
void | ClearAllTownCachedNames ()
| Clear the cached_name of all towns.
void | ShowTownViewWindow (TownID town)
void | ExpandTown (Town *t)
void | RebuildTownKdtree ()
CommandCost | CheckforTownRating (DoCommandFlags flags, Town *t, TownRatingCheckType type)
| Does the town authority allow the (destructive) action of the current company?
TileIndexDiff | GetHouseNorthPart (HouseID &house)
| Determines if a given HouseID is part of a multitile house.
Town * | CalcClosestTownFromTile (TileIndex tile, uint threshold=UINT_MAX)
| Return the town closest to the given tile within threshold.
void | ResetHouses ()
| DECLARE_INCREMENT_DECREMENT_OPERATORS (TownAction)
void | ClearTownHouse (Town *t, TileIndex tile)
| Clear a town house.
void | UpdateTownMaxPass (Town *t)
| Update the maximum amount of monthly passengers and mail for a town, based on its population.
void | UpdateTownRadius (Town *t)
| Update the cached town zone radii of a town, based on the number of houses.
CommandCost | CheckIfAuthorityAllowsNewStation (TileIndex tile, DoCommandFlags 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)
| Return the town closest (in distance or ownership) to a given tile, within a given threshold.
void | ChangeTownRating (Town *t, int add, int max, DoCommandFlags flags)
| Changes town rating of the current company.
HouseZone | GetTownRadiusGroup (const Town *t, TileIndex tile)
| Returns the bit corresponding to the town zone of the specified tile.
void | SetTownRatingTestMode (bool mode)
| Switch the town rating to test-mode, to allow commands to be tested without affecting current ratings.
TownActions | GetMaskOfTownActions (CompanyID cid, const Town *t)
| Get a list of available town authority actions.
uint | GetDefaultTownsForMapSize ()
| Calculate the number of towns which should be on the map according to the current "town density" newgame setting and the map size.
bool | GenerateTowns (TownLayout layout, std::optional< uint > number=std::nullopt)
| Generate a number of towns with a given layout.
const CargoSpec * | FindFirstCargoWithTownAcceptanceEffect (TownAcceptanceEffect effect)
| Determines the first cargo with a certain town effect.
CargoArray | GetAcceptedCargoOfHouse (const HouseSpec *hs)
| Get accepted cargo of a house prototype.
uint8_t | GetTownActionCost (TownAction action)
| Get cost factors for a TownAction.
template<class T >
void | MakeDefaultName (T *obj)
| Set the default name for a depot/waypoint.
uint16_t | TownTicksToGameTicks (uint16_t ticks)
RoadType | GetTownRoadType ()
| Get the road type that towns should build at this current moment.
bool | CheckTownRoadTypes ()
| Check if towns are able to build road.
std::span< const DrawBuildingsTileStruct > | GetTownDrawTileData ()

## 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 | TOWN_GROWTH_WINTER = 0xFFFFFFFE
| The town only needs this cargo in the winter (any amount)
static const uint | TOWN_GROWTH_DESERT = 0xFFFFFFFF
| The town needs the cargo for growth when on desert (any amount)
static const uint16_t | TOWN_GROWTH_RATE_NONE = 0xFFFF
| Special value for Town::growth_rate to disable town growth.
static const uint16_t | MAX_TOWN_GROWTH_TICKS = 930
| Max amount of original town ticks that still fit into uint16_t, about equal to UINT16_MAX / TOWN_GROWTH_TICKS but slightly less to simplify calculations.
TownPool | _town_pool

## Detailed Description

Base of the town class.

Definition in file town.h.

## Typedef Documentation

## ◆ TownActions

using TownActions = EnumBitSet<TownAction, uint8_t>

Definition at line 258 of file town.h.

## ◆ TownFlags

using TownFlags = EnumBitSet<TownFlag, uint8_t>

Definition at line 48 of file town.h.

## ◆ TownPool

typedef Pool<Town, TownID, 64> TownPool

Definition at line 37 of file town.h.

## Enumeration Type Documentation

## ◆ TownAction

enum class TownAction : uint8_t
| strong

Town actions of a company.

Enumerator
AdvertiseSmall | Small advertising campaign.
AdvertiseMedium | Medium advertising campaign.
AdvertiseLarge | Large advertising campaign.
RoadRebuild | Rebuild the roads.
BuildStatue | Build a statue.
FundBuildings | Fund new buildings.
BuyRights | Buy exclusive transport rights.
Bribe | Try to bribe the council.

Definition at line 247 of file town.h.

## ◆ TownCouncilAttitudes

enum TownCouncilAttitudes

Settings for town council attitudes.

Definition at line 213 of file town.h.

## ◆ TownDirectoryInvalidateWindowData

enum TownDirectoryInvalidateWindowData

Special values for town list window for the data parameter of InvalidateWindowData.

Definition at line 231 of file town.h.

## ◆ TownFlag

enum class TownFlag : uint8_t
| strong

Flags controlling various town behaviours.

Enumerator
IsGrowing | Conditions for town growth are met. Grow according to Town::growth_rate.
HasChurch | There can be only one church by town.
HasStadium | There can be only one stadium by town.
CustomGrowth | Growth rate is controlled by GS.

Definition at line 41 of file town.h.

## ◆ TownRatingCheckType

enum class TownRatingCheckType : uint8_t
| strong

Action types that a company must ask permission for to a town authority.

See also
  CheckforTownRating

Enumerator
RoadRemove | Removal of a road owned by the town.
TunnelBridgeRemove | Removal of a tunnel or bridge owned by the town.

Definition at line 224 of file town.h.

## Function Documentation

## ◆ CalcClosestTownFromTile()

Town * CalcClosestTownFromTile | ( | TileIndex | tile,
|  | uint | threshold
| ) |  |

Return the town closest to the given tile within threshold.

Parameters

  tile | Starting point of the search.
  threshold | Biggest allowed distance to the town.

Returns
  Closest town to tile within threshold, or `nullptr` if there is no such town.

Note
  This function only uses distance, the ClosestTownFromTile function also takes town ownership into account.

Definition at line 3943 of file town_cmd.cpp.

References DistanceManhattan(), Kdtree< T, TxyFunc, CoordT, DistT >::FindNearest(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetNumItems(), TileX(), TileY(), and Town::xy.

Referenced by AfterLoadGame(), AirportGetNearestTown(), BuildObject(), ClosestTownFromTile(), CmdBuildBridge(), CmdBuildRoad(), CmdBuildTunnel(), Town::PostDestructor(), RemoveRoad(), and UpdateNearestTownForRoadTiles().

## ◆ ChangeTownRating()

void ChangeTownRating | ( | Town * | t,
|  | int | add,
|  | int | max,
|  | DoCommandFlags | 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 achievable with this change.
  flags | Command flags, especially DoCommandFlag::NoModifyTownRating is tested

Definition at line 4040 of file town_cmd.cpp.

References _cheats, _current_company, _town_rating_test, _town_test_ratings, GetRating(), Town::have_ratings, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), Cheats::magic_bulldozer, NoModifyTownRating, Town::ratings, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SetWindowDirty(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Cheat::value, and WC_TOWN_AUTHORITY.

Referenced by CheckAllowRemoveRoad(), ClearTile_Town(), CmdBuildBridge(), CmdPlantTree(), DoClearBridge(), DoClearTunnel(), and TownActionBribe().

## ◆ CheckforTownRating()

CommandCost CheckforTownRating | ( | DoCommandFlags | flags,
|  | Town * | t,
|  | TownRatingCheckType | type
| ) |  |

Does the town authority allow the (destructive) action of the current company?

Parameters

  flags | Checking flags of the command.
  t | Town that must allow the company action.
  type | Type of action that is wanted.

Returns
  A succeeded command if the action is allowed, a failed command if it is not allowed.

Definition at line 4077 of file town_cmd.cpp.

References _cheats, _current_company, _settings_game, CommandCostWithParam(), GameSettings::difficulty, GetRating(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), Cheats::magic_bulldozer, NoTestTownRating, RATING_ROAD_NEEDED_HOSTILE, RATING_ROAD_NEEDED_LENIENT, RATING_ROAD_NEEDED_NEUTRAL, RATING_ROAD_NEEDED_PERMISSIVE, RATING_TUNNEL_BRIDGE_NEEDED_HOSTILE, RATING_TUNNEL_BRIDGE_NEEDED_LENIENT, RATING_TUNNEL_BRIDGE_NEEDED_NEUTRAL, RATING_TUNNEL_BRIDGE_NEEDED_PERMISSIVE, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), to_underlying(), DifficultySettings::town_council_tolerance, and Cheat::value.

Referenced by CheckAllowRemoveRoad(), CmdConvertRoad(), DoClearBridge(), and DoClearTunnel().

## ◆ CheckIfAuthorityAllowsNewStation()

CommandCost CheckIfAuthorityAllowsNewStation | ( | TileIndex | tile,
|  | DoCommandFlags | 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. DoCommandFlag::NoTestTownRating is tested.

Returns
  Succeeded or failed command.

Definition at line 3920 of file town_cmd.cpp.

References _current_company, _settings_game, ClosestTownFromTile(), CommandCostWithParam(), GameSettings::difficulty, EconomySettings::dist_local_authority, GameSettings::economy, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), NoTestTownRating, Town::ratings, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and DifficultySettings::town_council_tolerance.

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

## ◆ CheckTownRoadTypes()

bool CheckTownRoadTypes | ( |  | ) |

Check if towns are able to build road.

Returns
  true iff the towns are currently able to build road.

Definition at line 1015 of file town_cmd.cpp.

References TimerGameCalendar::date, GetEncodedString(), GetTownRoadTypeFirstIntroductionDate(), ShowErrorMessage(), and WL_CRITICAL.

Referenced by _GenerateWorld().

## ◆ ClearAllTownCachedNames()

void ClearAllTownCachedNames | ( |  | ) |

Clear the cached_name of all towns.

Definition at line 430 of file town_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::Iterate().

## ◆ ClearTownHouse()

void ClearTownHouse | ( | Town * | t,
|  | TileIndex | tile
| ) |  |

Clear a town house.

Parameters

  t | The town which owns the house.
  tile | The tile to clear.

Definition at line 3050 of file town_cmd.cpp.

References BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), HouseSpec::building_flags, Town::cache, ChangePopulation(), DoClearTownHouseHelper(), Town::flags, HouseSpec::Get(), GetHouseNorthPart(), GetHouseType(), HasChurch, HasStadium, IsHouseCompleted(), IsTileType(), MP_HOUSE, TownCache::num_houses, HouseSpec::population, RemoveNearbyStations(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TileDiffXY(), and UpdateTownRadius().

Referenced by ClearTile_Town(), CmdPlaceHouse(), and TileLoop_Town().

## ◆ ClosestTownFromTile()

Town * ClosestTownFromTile | ( | TileIndex | tile,
|  | uint | threshold
| ) |  |

Return the town closest (in distance or ownership) to a given tile, within a given threshold.

Parameters

  tile | Starting point of the search.
  threshold | Biggest allowed distance to the town.

Returns
  Closest town to tile within threshold, or `nullptr` if there is no such town.

Note
  If you only care about distance, you can use the CalcClosestTownFromTile function.

Definition at line 3961 of file town_cmd.cpp.

References _generating_world, CalcClosestTownFromTile(), DistanceManhattan(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetNumItems(), GetTileType(), GetTownIndex(), HasTownOwnedRoad(), IsRoadDepot(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::IsValidID(), MP_HOUSE, MP_ROAD, and Town::xy.

Referenced by AfterLoadGame(), BuildStationPart(), CheckAllowRemoveRoad(), CheckIfAuthorityAllowsNewStation(), CheckIfCallBackAllowsCreation(), CmdBuildAirport(), CmdBuildBridge(), CmdConvertRoad(), CmdPlaceHouse(), CmdPlantTree(), DisasterTick_Big_Ufo(), DoClearBridge(), DoClearTunnel(), FindTownForIndustry(), CHKPChunkHandler::FixPointers(), GenerateCompanyName(), GetParamsForOwnedBy(), AirportResolverObject::GetTown(), IndustriesResolverObject::GetTown(), ObjectResolverObject::GetTown(), StationResolverObject::GetTown(), AirportTileScopeResolver::GetVariable(), IndustryTileScopeResolver::GetVariable(), ObjectScopeResolver::GetVariable(), RailTypeScopeResolver::GetVariable(), RoadStopScopeResolver::GetVariable(), RoadTypeScopeResolver::GetVariable(), HighlightTownLocalAuthorityTiles(), MakeDefaultName(), LandInfoWindow::OnInit(), and RemoveGenericRoadStop().

## ◆ FindFirstCargoWithTownAcceptanceEffect()

const CargoSpec * FindFirstCargoWithTownAcceptanceEffect | ( | TownAcceptanceEffect | effect | ) |

Determines the first cargo with a certain town effect.

Parameters

  effect | Town effect of interest

Returns
  first active cargo slot with that effect

Definition at line 3127 of file town_cmd.cpp.

References CargoSpec::Iterate().

Referenced by AfterLoadGame(), CmdTownCargoGoal(), DoCreateTown(), and TownViewWindow::DrawWidget().

## ◆ GenerateTowns()

bool GenerateTowns | ( | TownLayout | layout,
|  | std::optional< uint > | number
| ) |  |

Generate a number of towns with a given layout.

This function is used by the Random Towns button in Scenario Editor as well as in world generation.

Parameters

  layout | The road layout to build.
  number | The number of towns to create. std::nullopt means to use the game settings.

Returns
  true if towns have been successfully created.

Definition at line 2448 of file town_cmd.cpp.

References _random, _settings_game, CreateRandomTown(), CUSTOM_TOWN_NUMBER_DIFFICULTY, GameSettings::difficulty, GameSettings::economy, GenerateTownName(), GetDefaultTownsForMapSize(), GetEncodedString(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetNumItems(), GWP_TOWN, IncreaseGeneratingWorldProgress(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::Iterate(), EconomySettings::larger_towns, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::MAX_SIZE, DifficultySettings::number_towns, Random, Map::ScaleByLandProportion(), SetGeneratingWorldProgress(), ShowErrorMessage(), TSZ_RANDOM, and WL_CRITICAL.

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

## ◆ GetAcceptedCargoOfHouse()

CargoArray GetAcceptedCargoOfHouse | ( | const HouseSpec * | hs | ) |

Get accepted cargo of a house prototype.

Parameters

  hs | Spec of the house.

Returns
  CargoArray filled with cargo accepted by the house.

Definition at line 858 of file town_cmd.cpp.

References AddAcceptedCargoOfHouse(), HouseSpec::Index(), and INVALID_TILE.

Referenced by BuildHouseWindow::GetHouseInformation().

## ◆ GetDefaultTownsForMapSize()

uint GetDefaultTownsForMapSize | ( |  | ) |

Calculate the number of towns which should be on the map according to the current "town density" newgame setting and the map size.

If the number of towns is set to "custom", the function will always return that value instead.

Returns
  The number of towns.

Definition at line 2432 of file town_cmd.cpp.

References _settings_game, _settings_newgame, GameCreationSettings::custom_town_number, CUSTOM_TOWN_NUMBER_DIFFICULTY, GameSettings::difficulty, GameSettings::game_creation, DifficultySettings::number_towns, and Map::ScaleBySize().

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

## ◆ GetHouseNorthPart()

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 3025 of file town_cmd.cpp.

References HouseSpec::Get(), and TileDiffXY().

Referenced by ClearTownHouse(), GetDistanceFromNearbyHouse(), RebuildTownCaches(), TriggerHouseAnimation_WatchedCargoAccepted(), and UpdateHousesAndTowns().

## ◆ GetMaskOfTownActions()

TownActions GetMaskOfTownActions | ( | CompanyID | cid,
|  | const Town * | t
| ) |  |

Get a list of available town authority actions.

Parameters

  cid | The company that is querying the town.
  t | The town that is queried.

Returns
  The bitmasked value of enabled actions.

Definition at line 3672 of file town_cmd.cpp.

References _current_company, _settings_game, EconomySettings::bribe, Bribe, BuildStatue, BuyRights, COMPANY_SPECTATOR, GameSettings::economy, Town::exclusive_counter, EconomySettings::exclusive_rights, Town::exclusivity, EconomySettings::fund_buildings, EconomySettings::fund_roads, FundBuildings, GetAvailableMoney(), GetTownActionCost(), Town::ratings, RoadRebuild, Town::statues, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and Town::unwanted.

Referenced by CmdDoTownAction(), and TownAuthorityWindow::OnPaint().

## ◆ GetTownActionCost()

uint8_t GetTownActionCost | ( | TownAction | action | ) |

Get cost factors for a TownAction.

Parameters

  action | TownAction to get cost factor for.

Returns
  Cost factor.

Factor in the cost of each town action.

See also
  TownActions

Definition at line 3391 of file town_cmd.cpp.

References to_underlying().

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

## ◆ GetTownDrawTileData()

std::span< const DrawBuildingsTileStruct > GetTownDrawTileData | ( |  | ) |

Definition at line 4201 of file town_cmd.cpp.

## ◆ GetTownRadiusGroup()

HouseZone 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 2516 of file town_cmd.cpp.

References DistanceSquare(), Town::fund_buildings_months, to_underlying(), and Town::xy.

Referenced by AirportTileScopeResolver::GetVariable(), HouseScopeResolver::GetVariable(), IndustriesScopeResolver::GetVariable(), IndustryTileScopeResolver::GetVariable(), ObjectScopeResolver::GetVariable(), RailTypeScopeResolver::GetVariable(), RoadStopScopeResolver::GetVariable(), RoadTypeScopeResolver::GetVariable(), and TryBuildTownHouse().

## ◆ GetTownRoadType()

RoadType GetTownRoadType | ( |  | ) |

Get the road type that towns should build at this current moment.

They may have built a different type in the past.

Definition at line 965 of file town_cmd.cpp.

References TimerGameCalendar::date, RoadTypeInfo::flags, GetMaskForRoadTramType(), GetRoadTypeInfo(), RoadTypeInfo::introduction_date, IsInsideMM(), TimerGameConst< struct Calendar >::MAX_DATE, RoadTypeInfo::max_speed, ROADTYPE_ROAD, RTT_ROAD, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and TownBuild.

Referenced by CanRoadContinueIntoNextTile(), GrowTown(), GrowTownWithBridge(), GrowTownWithRoad(), GrowTownWithTunnel(), IsRoadAllowedHere(), and TownCanGrowRoad().

## ◆ GetWorldPopulation()

uint32_t GetWorldPopulation | ( |  | ) |

Get the total population, the sum of all towns in the world.

Returns
  The calculated population of the world

Definition at line 457 of file town_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::Iterate().

Referenced by TownDirectoryWindow::GetWidgetString().

## ◆ MakeDefaultName()

template<class T >

void MakeDefaultName | ( | T * | obj | ) |

Set the default name for a depot/waypoint.

Template Parameters

  T | The type/class to make a default name for

Parameters

  obj | The object/instance we want to find the name for

Definition at line 284 of file town.h.

References ClosestTownFromTile(), HasBit(), and SetBit().

Referenced by AfterLoadGame(), CmdBuildBuoy(), CmdBuildRailWaypoint(), CmdBuildRoadDepot(), CmdBuildRoadWaypoint(), CmdBuildShipDepot(), CmdBuildTrainDepot(), and CmdRenameDepot().

## ◆ RebuildTownKdtree()

void RebuildTownKdtree | ( |  | ) |

Definition at line 78 of file town_cmd.cpp.

## ◆ ResetHouses()

void ResetHouses | ( |  | ) |

Definition at line 81 of file newgrf_house.cpp.

## ◆ SetTownRatingTestMode()

void SetTownRatingTestMode | ( | bool | mode | ) |

Switch the town rating to test-mode, to allow commands to be tested without affecting current ratings.

The function is safe to use in nested calls.

Parameters

  mode | Test mode switch (`true` means go to test-mode, `false` means leave test-mode).

Definition at line 4002 of file town_cmd.cpp.

References _town_rating_test, and _town_test_ratings.

Referenced by CommandHelperBase::InternalDoAfter(), CommandHelperBase::InternalDoBefore(), CommandHelperBase::InternalExecutePrepTest(), and CommandHelperBase::InternalExecuteValidateTestAndPrepExec().

## ◆ ShowTownViewWindow()

void ShowTownViewWindow | ( | TownID | town | ) |

Definition at line 680 of file town_gui.cpp.

## ◆ TownTicksToGameTicks()

uint16_t TownTicksToGameTicks | ( | uint16_t | ticks | ) |
| inline

Definition at line 346 of file town.h.

## ◆ UpdateAllTownVirtCoords()

void UpdateAllTownVirtCoords | ( |  | ) |

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

Definition at line 422 of file town_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::Iterate().

Referenced by UpdateAllVirtCoords().

## ◆ UpdateTownMaxPass()

void UpdateTownMaxPass | ( | Town * | t | ) |

Update the maximum amount of monthly passengers and mail for a town, based on its population.

Parameters

  t | The town to update.

Definition at line 2003 of file town_cmd.cpp.

References Town::cache, TownCache::population, ScaleByCargoScale(), CargoSpec::town_production_cargoes, TPE_MAIL, and TPE_PASSENGERS.

Referenced by AfterLoadGame(), CmdExpandTown(), and DoCreateTown().

## ◆ UpdateTownRadius()

void UpdateTownRadius | ( | Town * | t | ) |

Update the cached town zone radii of a town, based on the number of houses.

Parameters

  t | The town to update.

Definition at line 1956 of file town_cmd.cpp.

References Town::cache, TownCache::num_houses, TownCache::squared_town_zone_radius, and to_underlying().

Referenced by BuildTownHouse(), ClearTownHouse(), CmdExpandTown(), DoCreateTown(), and RebuildTownCaches().

## Variable Documentation

## ◆ CUSTOM_TOWN_MAX_NUMBER

const uint CUSTOM_TOWN_MAX_NUMBER = 5000
| static

this is the maximum number of towns a user can specify in customisation

Definition at line 30 of file town.h.

Referenced by GenerateLandscapeWindow::OnQueryTextFinished(), and GenerateLandscapeWindow::UpdateWidgetSize().

## ◆ CUSTOM_TOWN_NUMBER_DIFFICULTY

const uint CUSTOM_TOWN_NUMBER_DIFFICULTY = 4
| static

value for custom town number in difficulty settings

Definition at line 29 of file town.h.

Referenced by GenerateTowns(), GetDefaultTownsForMapSize(), GenerateLandscapeWindow::GetWidgetString(), and GenerateLandscapeWindow::OnDropdownSelect().

## ◆ MAX_TOWN_GROWTH_TICKS

const uint16_t MAX_TOWN_GROWTH_TICKS = 930
| static

Max amount of original town ticks that still fit into uint16_t, about equal to UINT16_MAX / TOWN_GROWTH_TICKS but slightly less to simplify calculations.

Definition at line 35 of file town.h.

## ◆ TOWN_GROWTH_DESERT

const uint TOWN_GROWTH_DESERT = 0xFFFFFFFF
| static

The town needs the cargo for growth when on desert (any amount)

Definition at line 33 of file town.h.

Referenced by AfterLoadGame(), DoCreateTown(), TownViewWindow::DrawWidget(), TownViewWindow::GetDesiredInfoHeight(), and UpdateTownGrowth().

## ◆ TOWN_GROWTH_RATE_NONE

const uint16_t TOWN_GROWTH_RATE_NONE = 0xFFFF
| static

Special value for Town::growth_rate to disable town growth.

Definition at line 34 of file town.h.

Referenced by AfterLoadGame(), UpdateTownGrowCounter(), and UpdateTownGrowth().

## ◆ TOWN_GROWTH_WINTER

const uint TOWN_GROWTH_WINTER = 0xFFFFFFFE
| static

The town only needs this cargo in the winter (any amount)

Definition at line 32 of file town.h.

Referenced by AfterLoadGame(), DoCreateTown(), TownViewWindow::DrawWidget(), TownViewWindow::GetDesiredInfoHeight(), and UpdateTownGrowth().