OpenTTD Source: src/town_cmd.cpp File Reference

OpenTTD Source 14.0-RC3

Data Structures | Typedefs | Enumerations | Functions | Variables
town_cmd.cpp File Reference
`#include "stdafx.h"`
`#include "road.h"`
`#include "road_internal.h"`
`#include "road_cmd.h"`
`#include "landscape.h"`
`#include "viewport_func.h"`
`#include "viewport_kdtree.h"`
`#include "command_func.h"`
`#include "company_func.h"`
`#include "industry.h"`
`#include "station_base.h"`
`#include "waypoint_base.h"`
`#include "station_kdtree.h"`
`#include "company_base.h"`
`#include "news_func.h"`
`#include "error.h"`
`#include "object.h"`
`#include "genworld.h"`
`#include "newgrf_debug.h"`
`#include "newgrf_house.h"`
`#include "newgrf_text.h"`
`#include "autoslope.h"`
`#include "tunnelbridge_map.h"`
`#include "strings_func.h"`
`#include "window_func.h"`
`#include "string_func.h"`
`#include "newgrf_cargo.h"`
`#include "cheat_type.h"`
`#include "animated_tile_func.h"`
`#include "subsidy_func.h"`
`#include "core/pool_func.hpp"`
`#include "town.h"`
`#include "town_kdtree.h"`
`#include "townname_func.h"`
`#include "core/random_func.hpp"`
`#include "core/backup_type.hpp"`
`#include "depot_base.h"`
`#include "object_map.h"`
`#include "object_base.h"`
`#include "ai/ai.hpp"`
`#include "game/game.hpp"`
`#include "town_cmd.h"`
`#include "landscape_cmd.h"`
`#include "terraform_cmd.h"`
`#include "tunnelbridge_cmd.h"`
`#include "timer/timer.h"`
`#include "timer/timer_game_calendar.h"`
`#include "timer/timer_game_economy.h"`
`#include "timer/timer_game_tick.h"`
`#include "table/strings.h"`
`#include "table/town_land.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Data Structures
struct | SpotData
| Used as the user_data for FindFurthestFromWater. More...
struct | StatueBuildSearchData
| Structure for storing data while searching the best place to build a statue. More...

## Typedefs
typedef void | TownDrawTileProc(const TileInfo *ti)
typedef CommandCost | TownActionProc(Town *t, DoCommandFlag flags)

## Enumerations
enum | TownGrowthResult { GROWTH_SUCCEED = -1, GROWTH_SEARCH_STOPPED = 0 }

## Functions
void | RebuildTownKdtree ()
static bool | TestTownOwnsBridge (TileIndex tile, const Town *t)
| Check if a town 'owns' a bridge. More...
static bool | BuildTownHouse (Town *t, TileIndex tile)
| Tries to build a house at this tile. More...
static Town * | CreateRandomTown (uint attempts, uint32_t townnameparts, TownSize size, bool city, TownLayout layout)
| Create a random town somewhere in the world. More...
static void | TownDrawHouseLift (const TileInfo *ti)
static DiagDirection | RandomDiagDir ()
| Return a random direction. More...
static void | DrawTile_Town (TileInfo *ti)
| Draw a house and its tile. More...
static int | GetSlopePixelZ_Town (TileIndex tile, uint, uint, bool)
static Foundation | GetFoundation_Town (TileIndex tile, Slope tileh)
| Get the foundation for a house. More...
static void | AnimateTile_Town (TileIndex tile)
| Animate a tile for a town. More...
static bool | IsCloseToTown (TileIndex tile, uint dist)
| Determines if a town is close to a tile. More...
void | UpdateAllTownVirtCoords ()
| Update the virtual coords needed to draw the town sign for all towns.
void | ClearAllTownCachedNames ()
| Clear the cached_name of all towns.
static void | ChangePopulation (Town *t, int mod)
| Change the town's population as recorded in the town cache, town label, and town directory. More...
uint32_t | GetWorldPopulation ()
| Get the total population, the sum of all towns in the world. More...
static void | RemoveNearbyStations (Town *t, TileIndex tile, BuildingFlags flags)
| Remove stations from nearby station list if a town is no longer in the catchment area of each. More...
static void | AdvanceSingleHouseConstruction (TileIndex tile)
| Helper function for house construction stage progression. More...
static void | AdvanceHouseConstruction (TileIndex tile)
| Increase the construction stage of a house. More...
static void | TownGenerateCargo (Town *t, CargoID ct, uint amount, StationFinder &stations, bool affected_by_recession)
| Generate cargo for a house, scaled by the current economy scale. More...
static void | TownGenerateCargoOriginal (Town *t, TownProductionEffect tpe, uint8_t rate, StationFinder &stations)
| Generate cargo for a house using the original algorithm. More...
static void | TownGenerateCargoBinominal (Town *t, TownProductionEffect tpe, uint8_t rate, StationFinder &stations)
| Generate cargo for a house using the binominal algorithm. More...
static void | TileLoop_Town (TileIndex tile)
| Tile callback function. More...
static CommandCost | ClearTile_Town (TileIndex tile, DoCommandFlag flags)
| Callback function to clear a house tile. More...
static void | AddProducedCargo_Town (TileIndex tile, CargoArray &produced)
static void | AddAcceptedCargoSetMask (CargoID cargo, uint amount, CargoArray &acceptance, CargoTypes *always_accepted)
static void | AddAcceptedCargo_Town (TileIndex tile, CargoArray &acceptance, CargoTypes *always_accepted)
static void | GetTileDesc_Town (TileIndex tile, TileDesc *td)
static TrackStatus | GetTileTrackStatus_Town (TileIndex, TransportType, uint, DiagDirection)
static void | ChangeTileOwner_Town (TileIndex, Owner, Owner)
static bool | GrowTown (Town *t)
| Grow the town. More...
static void | TownTickHandler (Town *t)
| Handle the town tick for a single town, by growing the town if desired. More...
void | OnTick_Town ()
| Iterate through all towns and call their tick handler.
static RoadBits | GetTownRoadBits (TileIndex tile)
| Return the RoadBits of a tile, ignoring depot and bay road stops. More...
RoadType | GetTownRoadType ()
| Get the road type that towns should build at this current moment. More...
static bool | IsNeighborRoadTile (TileIndex tile, const DiagDirection dir, uint dist_multi)
| Check for parallel road inside a given distance. More...
static bool | IsRoadAllowedHere (Town *t, TileIndex tile, DiagDirection dir)
| Check if a Road is allowed on a given tile. More...
static bool | TerraformTownTile (TileIndex tile, Slope edges, bool dir)
static void | LevelTownLand (TileIndex tile)
static RoadBits | GetTownRoadGridElement (Town *t, TileIndex tile, DiagDirection dir)
| Generate the RoadBits of a grid tile. More...
static bool | GrowTownWithExtraHouse (Town *t, TileIndex tile)
| Grows the town with an extra house. More...
static bool | GrowTownWithRoad (const Town *t, TileIndex tile, RoadBits rcmd)
| Grows the town with a road piece. More...
static bool | CanRoadContinueIntoNextTile (const Town *t, const TileIndex tile, const DiagDirection road_dir)
| Checks if a town road can be continued into the next tile. More...
static bool | RedundantBridgeExistsNearby (TileIndex tile, void *user_data)
| CircularTileSearch proc which checks for a nearby parallel bridge to avoid building redundant bridges. More...
static bool | GrowTownWithBridge (const Town *t, const TileIndex tile, const DiagDirection bridge_dir)
| Grows the town with a bridge. More...
static bool | GrowTownWithTunnel (const Town *t, const TileIndex tile, const DiagDirection tunnel_dir)
| Grows the town with a tunnel. More...
static bool | RoadTypesAllowHouseHere (TileIndex t)
| Checks whether at least one surrounding road allows to build a house here. More...
static bool | TownCanGrowRoad (TileIndex tile)
| Test if town can grow road onto a specific tile. More...
static bool | TownAllowedToBuildRoads ()
| Check if the town is allowed to build roads. More...
static void | GrowTownInTile (TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection target_dir, Town *t1)
| Grows the given town. More...
static bool | CanFollowRoad (TileIndex tile, DiagDirection dir)
| Checks whether a road can be followed or is a dead end, that can not be extended to the next tile. More...
static bool | GrowTownAtRoad (Town *t, TileIndex tile)
| Try to grow a town at a given road tile. More...
static RoadBits | GenRandomRoadBits ()
| Generate a random road block. More...
void | UpdateTownRadius (Town *t)
| Update the cached town zone radii of a town, based on the number of houses. More...
void | UpdateTownMaxPass (Town *t)
| Update the maximum amount of montly passengers and mail for a town, based on its population. More...
static void | UpdateTownGrowthRate (Town *t)
| Updates town growth rate. More...
static void | UpdateTownGrowth (Town *t)
| Updates town growth state (whether it is growing or not). More...
static void | DoCreateTown (Town *t, TileIndex tile, uint32_t townnameparts, TownSize size, bool city, TownLayout layout, bool manual)
| Actually create a town. More...
static CommandCost | TownCanBePlacedHere (TileIndex tile)
| Check if it's possible to place a town on a given tile. More...
static bool | IsUniqueTownName (const std::string &name)
| Verifies this custom name is unique. More...
std::tuple< CommandCost, Money, TownID > | CmdFoundTown (DoCommandFlag flags, TileIndex tile, TownSize size, bool city, TownLayout layout, bool random_location, uint32_t townnameparts, const std::string &text)
| Create a new town. More...
static TileIndex | AlignTileToGrid (TileIndex tile, TownLayout layout)
| Towns must all be placed on the same grid or when they eventually interpenetrate their road networks will not mesh nicely; this function adjusts a tile so that it aligns properly. More...
static bool | IsTileAlignedToGrid (TileIndex tile, TownLayout layout)
| Towns must all be placed on the same grid or when they eventually interpenetrate their road networks will not mesh nicely; this function tells you if a tile is properly aligned. More...
static bool | FindFurthestFromWater (TileIndex tile, void *user_data)
| CircularTileSearch callback; finds the tile furthest from any water. More...
static bool | FindNearestEmptyLand (TileIndex tile, void *)
| CircularTileSearch callback to find the nearest land tile. More...
static TileIndex | FindNearestGoodCoastalTownSpot (TileIndex tile, TownLayout layout)
| Given a spot on the map (presumed to be a water tile), find a good coastal spot to build a city. More...
bool | GenerateTowns (TownLayout layout)
| Generate a number of towns with a given layout. More...
HouseZonesBits | GetTownRadiusGroup (const Town *t, TileIndex tile)
| Returns the bit corresponding to the town zone of the specified tile. More...
static void | ClearMakeHouseTile (TileIndex tile, Town *t, byte counter, byte stage, HouseID type, byte random_bits)
| Clears tile and builds a house or house part. More...
static void | MakeTownHouse (TileIndex tile, Town *t, byte counter, byte stage, HouseID type, byte random_bits)
| Write house information into the map. More...
static bool | CanBuildHouseHere (TileIndex tile, bool noslope)
| Check if a house can be built here, based on slope, whether there's a bridge above, and if we can clear the land. More...
static bool | CheckBuildHouseSameZ (TileIndex tile, int z, bool noslope)
| Check if a tile where we want to build a multi-tile house has an appropriate max Z. More...
static bool | CheckFree2x2Area (TileIndex tile, int z, bool noslope)
| Checks if a house of size 2x2 can be built at this tile. More...
static bool | TownLayoutAllowsHouseHere (Town *t, TileIndex tile)
| Checks if the current town layout allows building here. More...
static bool | TownLayoutAllows2x2HouseHere (Town *t, TileIndex tile)
| Checks if the current town layout allows a 2x2 building here. More...
static bool | CheckTownBuild2House (TileIndex *tile, Town *t, int maxz, bool noslope, DiagDirection second)
| Checks if a 1x2 or 2x1 building is allowed here, accounting for road layout and tile heights. More...
static bool | CheckTownBuild2x2House (TileIndex *tile, Town *t, int maxz, bool noslope)
| Checks if a 1x2 or 2x1 building is allowed here, accounting for road layout and tile heights. More...
static void | DoClearTownHouseHelper (TileIndex tile, Town *t, HouseID house)
| Update data structures when a house is removed. More...
TileIndexDiff | GetHouseNorthPart (HouseID &house)
| Determines if a given HouseID is part of a multitile house. More...
void | ClearTownHouse (Town *t, TileIndex tile)
| Clear a town house. More...
CommandCost | CmdRenameTown (DoCommandFlag flags, TownID town_id, const std::string &text)
| Rename a town (server-only). More...
const CargoSpec * | FindFirstCargoWithTownAcceptanceEffect (TownAcceptanceEffect effect)
| Determines the first cargo with a certain town effect. More...
CommandCost | CmdTownCargoGoal (DoCommandFlag flags, TownID town_id, TownAcceptanceEffect tae, uint32_t goal)
| Change the cargo goal of a town. More...
CommandCost | CmdTownSetText (DoCommandFlag flags, TownID town_id, const std::string &text)
| Set a custom text in the Town window. More...
CommandCost | CmdTownGrowthRate (DoCommandFlag flags, TownID town_id, uint16_t growth_rate)
| Change the growth rate of the town. More...
CommandCost | CmdTownRating (DoCommandFlag flags, TownID town_id, CompanyID company_id, int16_t rating)
| Change the rating of a company in a town. More...
CommandCost | CmdExpandTown (DoCommandFlag flags, TownID town_id, uint32_t grow_amount)
| Expand a town (scenario editor only). More...
CommandCost | CmdDeleteTown (DoCommandFlag flags, TownID town_id)
| Delete a town (scenario editor or worldgen only). More...
static CommandCost | TownActionAdvertiseSmall (Town *t, DoCommandFlag flags)
| Perform the "small advertising campaign" town action. More...
static CommandCost | TownActionAdvertiseMedium (Town *t, DoCommandFlag flags)
| Perform the "medium advertising campaign" town action. More...
static CommandCost | TownActionAdvertiseLarge (Town *t, DoCommandFlag flags)
| Perform the "large advertising campaign" town action. More...
static CommandCost | TownActionRoadRebuild (Town *t, DoCommandFlag flags)
| Perform the "local road reconstruction" town action. More...
static bool | CheckClearTile (TileIndex tile)
| Check whether the land can be cleared. More...
static bool | SearchTileForStatue (TileIndex tile, void *user_data)
| Search callback function for TownActionBuildStatue. More...
static CommandCost | TownActionBuildStatue (Town *t, DoCommandFlag flags)
| Perform a 9x9 tiles circular search from the center of the town in order to find a free tile to place a statue. More...
static CommandCost | TownActionFundBuildings (Town *t, DoCommandFlag flags)
| Perform the "fund new buildings" town action. More...
static CommandCost | TownActionBuyRights (Town *t, DoCommandFlag flags)
| Perform the "buy exclusive transport rights" town action. More...
static CommandCost | TownActionBribe (Town *t, DoCommandFlag flags)
| Perform the "bribe" town action. More...
TownActions | GetMaskOfTownActions (CompanyID cid, const Town *t)
| Get a list of available town authority actions. More...
CommandCost | CmdDoTownAction (DoCommandFlag flags, TownID town_id, uint8_t action)
| Do a town action. More...
template<typename Func >
static void | ForAllStationsNearTown (Town *t, Func func)
static void | UpdateTownRating (Town *t)
| Monthly callback to update town and station ratings. More...
static void | UpdateTownGrowCounter (Town *t, uint16_t prev_growth_rate)
| Updates town grow counter after growth rate change. More...
static int | CountActiveStations (Town *t)
| Calculates amount of active stations in the range of town (HZB_TOWN_EDGE). More...
static uint | GetNormalGrowthRate (Town *t)
| Calculates town growth rate in normal conditions (custom growth rate not set). More...
CommandCost | CheckIfAuthorityAllowsNewStation (TileIndex tile, DoCommandFlag flags)
| Checks whether the local authority allows construction of a new station (rail, road, airport, dock) on the given tile. More...
Town * | CalcClosestTownFromTile (TileIndex tile, uint threshold)
| Return the town closest to the given tile within threshold. More...
Town * | ClosestTownFromTile (TileIndex tile, uint threshold)
| Return the town closest (in distance or ownership) to a given tile, within a given threshold. More...
void | SetTownRatingTestMode (bool mode)
| Switch the town rating to test-mode, to allow commands to be tested without affecting current ratings. More...
static int | GetRating (const Town *t)
| Get the rating of a town for the _current_company. More...
void | ChangeTownRating (Town *t, int add, int max, DoCommandFlag flags)
| Changes town rating of the current company. More...
CommandCost | CheckforTownRating (DoCommandFlag flags, Town *t, TownRatingCheckType type)
| Does the town authority allow the (destructive) action of the current company? More...
static CommandCost | TerraformTile_Town (TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
void | ResetHouses ()

## Variables
TownPool | _town_pool ("Town")
TownKdtree _town_kdtree & | Kdtree_TownXYFunc
static int | _grow_town_result
static TownDrawTileProc *const | _town_draw_tile_procs [1]
static const byte | _num_initial_towns [4] = {5, 11, 23, 46}
const byte | _town_action_costs [TACT_COUNT]
| Factor in the cost of each town action. More...
static TownActionProc *const | _town_action_proc []
static bool | _town_rating_test = false
| If `true`, town rating is in test-mode.
static std::map< const Town *, int > | _town_test_ratings
| Map of towns to modified ratings, while in town rating test-mode.
static IntervalTimer< TimerGameEconomy > | _economy_towns_monthly ({TimerGameEconomy::MONTH, TimerGameEconomy::Priority::TOWN}, [](auto) { for(Town *t :Town::Iterate()) { if(t->road_build_months !=0) t->road_build_months--;if(t->fund_buildings_months !=0) t->fund_buildings_months--;if(t->exclusive_counter !=0) { if(--t->exclusive_counter==0) t->exclusivity=INVALID_COMPANY;} for(const Company *c :Company::Iterate()) { if(t->unwanted[c->index] > 0) t->unwanted[c->index]--;} for(auto &supplied :t->supplied) supplied.NewMonth();for(auto &received :t->received) received.NewMonth();UpdateTownGrowth(t);UpdateTownRating(t);SetWindowDirty(WC_TOWN_VIEW, t->index);} })
static IntervalTimer< TimerGameEconomy > | _economy_towns_yearly ({TimerGameEconomy::YEAR, TimerGameEconomy::Priority::TOWN}, [](auto) { for(TileIndex t=0;t< Map::Size();t++) { if(!IsTileType(t, MP_HOUSE)) continue;IncrementHouseAge(t);} })
const TileTypeProcs | _tile_type_town_procs
| Tile callback functions for a town. More...
HouseSpec | _house_specs [NUM_HOUSES]

## Detailed Description

Handling of town tiles.

Definition in file town_cmd.cpp.

## Function Documentation

## ◆ AdvanceHouseConstruction()

static void AdvanceHouseConstruction | ( | TileIndex | tile | ) |
| static

Increase the construction stage of a house.

Parameters

  tile | The tile of the house under construction.

Definition at line 514 of file town_cmd.cpp.

References HouseSpec::building_flags, and GetHouseType().

## ◆ AdvanceSingleHouseConstruction()

static void AdvanceSingleHouseConstruction | ( | TileIndex | tile | ) |
| static

Helper function for house construction stage progression.

Parameters

  tile | TileIndex of the house (or parts of it) to construct.

Definition at line 491 of file town_cmd.cpp.

References GetHouseConstructionTick(), IncHouseConstructionTick(), IsTileType(), and MP_HOUSE.

## ◆ AlignTileToGrid()

static TileIndex AlignTileToGrid | ( | TileIndex | tile,
|  | TownLayout | layout
| ) |  |
| static

Towns must all be placed on the same grid or when they eventually interpenetrate their road networks will not mesh nicely; this function adjusts a tile so that it aligns properly.

Parameters

  tile | The tile to start at.
  layout | The town layout in effect.

Returns
  The adjusted tile.

Definition at line 2165 of file town_cmd.cpp.

References TileX(), TileXY(), TileY(), TL_2X2_GRID, and TL_3X3_GRID.

## ◆ AnimateTile_Town()

static void AnimateTile_Town | ( | TileIndex | tile | ) |
| static

Animate a tile for a town.

Only certain houses can be animated. The newhouses animation supersedes regular ones.

Parameters

  tile | TileIndex of the house to animate.

Definition at line 345 of file town_cmd.cpp.

References GetHouseType(), and NEW_HOUSE_OFFSET.

## ◆ BuildTownHouse()

static bool BuildTownHouse | ( | Town * | t,
|  | TileIndex | tile
| ) |  |
| static

Tries to build a house at this tile.

Parameters

  t | The town the house will belong to.
  tile | The tile to try building on.

Returns
  false iff no house can be built on this tile.

Definition at line 2636 of file town_cmd.cpp.

References _settings_game, CanBuildHouseHere(), GameSettings::game_creation, GetTileMaxZ(), GetTileSlope(), GetTownRadiusGroup(), GameCreationSettings::landscape, and TownLayoutAllowsHouseHere().

Referenced by GrowTownWithExtraHouse().

## ◆ 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 3726 of file town_cmd.cpp.

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

Referenced by AirportGetNearestTown(), BuildObject(), ClosestTownFromTile(), CmdBuildBridge(), CmdBuildRoad(), and CmdBuildTunnel().

## ◆ CanBuildHouseHere()

static bool CanBuildHouseHere | ( | TileIndex | tile,
|  | bool | noslope
| ) |  |
| inlinestatic

Check if a house can be built here, based on slope, whether there's a bridge above, and if we can clear the land.

Parameters

  tile | The tile to check.
  noslope | Are foundations prohibited for this house?

Returns
  true iff house can be built here.

Definition at line 2455 of file town_cmd.cpp.

References DC_AUTO, DC_NO_WATER, GetTileSlope(), IsBridgeAbove(), IsSteepSlope(), RoadTypesAllowHouseHere(), and SLOPE_FLAT.

Referenced by BuildTownHouse(), and CheckBuildHouseSameZ().

## ◆ CanFollowRoad()

static bool CanFollowRoad | ( | TileIndex | tile,
|  | DiagDirection | dir
| ) |  |
| static

Checks whether a road can be followed or is a dead end, that can not be extended to the next tile.

This only checks trivial but often cases.

Parameters

  tile | Start tile for road.
  dir | Direction for road to follow or build.

Returns
  true If road is or can be connected in the specified direction.

Definition at line 1667 of file town_cmd.cpp.

References DiagDirToRoadBits(), GetTileType(), GetTownRoadBits(), GetTunnelBridgeTransportType(), HasTileWaterGround(), IsDriveThroughStopTile(), IsValidTile(), MP_HOUSE, MP_INDUSTRY, MP_OBJECT, MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, ReverseDiagDir(), ROAD_NONE, TileOffsByDiagDir(), TownAllowedToBuildRoads(), and TRANSPORT_ROAD.

## ◆ CanRoadContinueIntoNextTile()

static bool CanRoadContinueIntoNextTile | ( | const Town * | t,
|  | const TileIndex | tile,
|  | const DiagDirection | road_dir
| ) |  |
| static

Checks if a town road can be continued into the next tile.

Road vehicle stations, bridges, and tunnels are fine, as long as they are facing the right direction.

Parameters

  t | The current town
  tile | The tile where the road would be built
  road_dir | The direction of the road

Returns
  true if the road can be continued, else false

Definition at line 1184 of file town_cmd.cpp.

References _settings_game, EconomySettings::allow_town_level_crossings, DC_AUTO, DC_NO_WATER, DiagDirToRoadBits(), DRD_NONE, GameSettings::economy, GetRoadDepotDirection(), GetRoadStopDir(), GetTownRoadType(), GetTunnelBridgeDirection(), GetTunnelBridgeTransportType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, IsDriveThroughStopTile(), IsRoadDepot(), IsRoadStop(), IsTileType(), IsValidTile(), MP_RAILWAY, MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, ReverseDiagDir(), TileOffsByDiagDir(), and TRANSPORT_ROAD.

Referenced by GrowTownWithBridge(), and GrowTownWithTunnel().

## ◆ ChangePopulation()

static void ChangePopulation | ( | Town * | t,
|  | int | mod
| ) |  |
| static

Change the town's population as recorded in the town cache, town label, and town directory.

Parameters

  t | The town which has changed.
  mod | The population change (can be positive or negative).

Definition at line 442 of file town_cmd.cpp.

References _settings_client, Town::cache, ClientSettings::gui, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, InvalidateWindowData(), TownCache::population, GUISettings::population_in_label, Town::UpdateVirtCoord(), WC_TOWN_DIRECTORY, and WC_TOWN_VIEW.

Referenced by ClearTownHouse().

## ◆ ChangeTownRating()

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 achievable with this change.
  flags | Command flags, especially DC_NO_MODIFY_TOWN_RATING is tested

Definition at line 3823 of file town_cmd.cpp.

References _cheats, _current_company, _town_rating_test, _town_test_ratings, DC_NO_MODIFY_TOWN_RATING, GetRating(), Town::have_ratings, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), Cheats::magic_bulldozer, Town::ratings, SetBit(), SetWindowDirty(), Cheat::value, and WC_TOWN_AUTHORITY.

## ◆ CheckBuildHouseSameZ()

static bool CheckBuildHouseSameZ | ( | TileIndex | tile,
|  | int | z,
|  | bool | noslope
| ) |  |
| inlinestatic

Check if a tile where we want to build a multi-tile house has an appropriate max Z.

Parameters

  tile | The tile to check.
  z | The max Z level to allow.
  noslope | Are foundations disallowed for this house?

Returns
  true iff house can be built here.

See also
  CanBuildHouseHere()

Definition at line 2480 of file town_cmd.cpp.

References CanBuildHouseHere(), and GetTileMaxZ().

Referenced by CheckFree2x2Area(), and CheckTownBuild2House().

## ◆ CheckClearTile()

static bool CheckClearTile | ( | TileIndex | tile | ) |
| static

Check whether the land can be cleared.

Parameters

  tile | Tile to check.

Returns
  true if the tile can be cleared.

Definition at line 3251 of file town_cmd.cpp.

References _current_company, and OWNER_NONE.

Referenced by SearchTileForStatue().

## ◆ CheckforTownRating()

CommandCost CheckforTownRating | ( | DoCommandFlag | 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 3860 of file town_cmd.cpp.

References _cheats, _current_company, _settings_game, DC_NO_TEST_TOWN_RATING, GameSettings::difficulty, GetRating(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), Cheats::magic_bulldozer, 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, return_cmd_error, SetDParam(), DifficultySettings::town_council_tolerance, TOWN_RATING_CHECK_TYPE_COUNT, and Cheat::value.

## ◆ CheckFree2x2Area()

static bool CheckFree2x2Area | ( | TileIndex | tile,
|  | int | z,
|  | bool | noslope
| ) |  |
| static

Checks if a house of size 2x2 can be built at this tile.

Parameters

  tile | The tile of the house's northernmost tile.
  z | The maximum tile z, so all tiles are the same height.
  noslope | Are foundations disallowed for this house?

Returns
  true iff house can be built here.

See also
  CheckBuildHouseSameZ()

Definition at line 2499 of file town_cmd.cpp.

References CheckBuildHouseSameZ(), DIAGDIR_END, DIAGDIR_SE, and TileOffsByDiagDir().

Referenced by CheckTownBuild2x2House().

## ◆ CheckIfAuthorityAllowsNewStation()

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

Returns
  Succeeded or failed command.

Definition at line 3702 of file town_cmd.cpp.

References _settings_game, GameSettings::difficulty, and DifficultySettings::town_council_tolerance.

## ◆ CheckTownBuild2House()

static bool CheckTownBuild2House | ( | TileIndex * | tile,
|  | Town * | t,
|  | int | maxz,
|  | bool | noslope,
|  | DiagDirection | second
| ) |  |
| static

Checks if a 1x2 or 2x1 building is allowed here, accounting for road layout and tile heights.

Also, tests both building positions that occupy this tile.

Parameters

  tile | The tile where the building should be built.
  t | The town.
  maxz | The maximum Z level, since all tiles must have the same height.
  noslope | Are foundations disallowed for this house?
  second | The diagdir from the first tile to the second tile.

Definition at line 2588 of file town_cmd.cpp.

References CheckBuildHouseSameZ(), ReverseDiagDir(), TileOffsByDiagDir(), and TownLayoutAllowsHouseHere().

## ◆ CheckTownBuild2x2House()

static bool CheckTownBuild2x2House | ( | TileIndex * | tile,
|  | Town * | t,
|  | int | maxz,
|  | bool | noslope
| ) |  |
| static

Checks if a 1x2 or 2x1 building is allowed here, accounting for road layout and tile heights.

Also, tests all four building positions that occupy this tile.

Parameters

  tile | The tile where the building should be built.
  t | The town.
  maxz | The maximum Z level, since all tiles must have the same height.
  noslope | Are foundations disallowed for this house?

Definition at line 2613 of file town_cmd.cpp.

References CheckFree2x2Area(), DIAGDIR_END, DIAGDIR_SE, ReverseDiagDir(), TileOffsByDiagDir(), and TownLayoutAllows2x2HouseHere().

## ◆ ClearMakeHouseTile()

static void ClearMakeHouseTile | ( | TileIndex | tile,
|  | Town * | t,
|  | byte | counter,
|  | byte | stage,
|  | HouseID | type,
|  | byte | random_bits
| ) |  |
| inlinestatic

Clears tile and builds a house or house part.

Parameters

  tile | The tile to build upon.
  t | The town which will own the house.
  counter | The construction stage counter for the house.
  stage | The current construction stage of the house.
  type | The type of house.
  random_bits | Random bits for newgrf houses to use.

Precondition
  The house can be built here.

Definition at line 2410 of file town_cmd.cpp.

References DC_AUTO, DC_EXEC, DC_NO_WATER, IncreaseBuildingCount(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, MakeHouseTile(), and CommandCost::Succeeded().

Referenced by MakeTownHouse().

## ◆ ClearTile_Town()

static CommandCost ClearTile_Town | ( | TileIndex | tile,
|  | DoCommandFlag | flags
| ) |  |
| static

Callback function to clear a house tile.

Parameters

  tile | The tile to clear.
  flags | Type of operation.

Returns
  The cost of this operation or an error.

Definition at line 710 of file town_cmd.cpp.

References DC_AUTO, and return_cmd_error.

## ◆ 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 2832 of file town_cmd.cpp.

References HouseSpec::building_flags, Town::cache, ChangePopulation(), GetHouseNorthPart(), GetHouseType(), IsHouseCompleted(), IsTileType(), MP_HOUSE, TownCache::num_houses, and HouseSpec::population.

## ◆ 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 3744 of file town_cmd.cpp.

References CalcClosestTownFromTile(), GetTileType(), GetTownIndex(), HasTownOwnedRoad(), IsRoadDepot(), and MP_ROAD.

Referenced by FindTownForIndustry(), GenerateCompanyName(), StationResolverObject::GetTown(), ObjectResolverObject::GetTown(), AirportResolverObject::GetTown(), IndustryTileScopeResolver::GetVariable(), AirportTileScopeResolver::GetVariable(), ObjectScopeResolver::GetVariable(), LandInfoWindow::OnInit(), and SetDParamsForOwnedBy().

## ◆ CmdDeleteTown()

CommandCost CmdDeleteTown | ( | DoCommandFlag | flags,
|  | TownID | town_id
| ) |  |

Delete a town (scenario editor or worldgen only).

Parameters

  flags | Type of operation.
  town_id | Town ID to delete.

Returns
  Empty cost or an error.

Definition at line 3076 of file town_cmd.cpp.

## ◆ CmdDoTownAction()

CommandCost CmdDoTownAction | ( | DoCommandFlag | flags,
|  | TownID | town_id,
|  | uint8_t | action
| ) |  |

Do a town action.

This performs an action such as advertising, building a statue, funding buildings, but also bribing the town-council

Parameters

  flags | type of operation
  town_id | town to do the action at
  action | action to perform,

See also
  _town_action_proc for the list of available actions

Returns
  the cost of this operation or an error

Definition at line 3510 of file town_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::GetIfValid(), and lengthof.

## ◆ CmdExpandTown()

CommandCost CmdExpandTown | ( | DoCommandFlag | flags,
|  | TownID | town_id,
|  | uint32_t | grow_amount
| ) |  |

Expand a town (scenario editor only).

Parameters

  flags | Type of operation.
  TownID | Town ID to expand.
  grow_amount | Amount to grow, or 0 to grow a random size up to the current amount of houses.

Returns
  Empty cost or an error.

Definition at line 3039 of file town_cmd.cpp.

## ◆ CmdFoundTown()

std::tuple<CommandCost, Money, TownID> CmdFoundTown | ( | DoCommandFlag | flags,
|  | TileIndex | tile,
|  | TownSize | size,
|  | bool | city,
|  | TownLayout | layout,
|  | bool | random_location,
|  | uint32_t | townnameparts,
|  | const std::string & | text
| ) |  |

Create a new town.

Parameters

  flags | The type of operation.
  tile | The coordinates where town is built.
  size | The size of the town (

See also
  TownSize).

Parameters

  city | Should we build a city?
  layout | The town road layout (

See also
  TownLayout).

Parameters

  random_location | Should we use a random location? (randomize `tile` )
  townnameparts | Town name parts.
  text | Custom name for the town. If empty, the town name parts will be used.

Returns
  The cost of this operation or an error.

Definition at line 2058 of file town_cmd.cpp.

References _settings_game, CMD_ERROR, GameSettings::game_creation, GameCreationSettings::town_name, and TSZ_END.

## ◆ CmdRenameTown()

CommandCost CmdRenameTown | ( | DoCommandFlag | flags,
|  | TownID | town_id,
|  | const std::string & | text
| ) |  |

Rename a town (server-only).

Parameters

  flags | type of operation
  town_id | town ID to rename
  text | the new name or an empty string when resetting to the default

Returns
  the cost of this operation or an error

Definition at line 2875 of file town_cmd.cpp.

References Town::cached_name, CMD_ERROR, DC_EXEC, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::GetIfValid(), InvalidateWindowData(), IsUniqueTownName(), MAX_LENGTH_TOWN_NAME_CHARS, Town::name, return_cmd_error, Town::UpdateVirtCoord(), Utf8StringLength(), and WC_TOWN_DIRECTORY.

## ◆ CmdTownCargoGoal()

CommandCost CmdTownCargoGoal | ( | DoCommandFlag | flags,
|  | TownID | town_id,
|  | TownAcceptanceEffect | tae,
|  | uint32_t | goal
| ) |  |

Change the cargo goal of a town.

Parameters

  flags | Type of operation.
  town_id | Town ID to cargo game of.
  tae | TownEffect to change the game of.
  goal | The new goal value.

Returns
  Empty cost or an error.

Definition at line 2925 of file town_cmd.cpp.

References _current_company, CMD_ERROR, DC_EXEC, FindFirstCargoWithTownAcceptanceEffect(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::GetIfValid(), Town::goal, InvalidateWindowData(), OWNER_DEITY, TAE_END, UpdateTownGrowth(), and WC_TOWN_VIEW.

## ◆ CmdTownGrowthRate()

CommandCost CmdTownGrowthRate | ( | DoCommandFlag | flags,
|  | TownID | town_id,
|  | uint16_t | growth_rate
| ) |  |

Change the growth rate of the town.

Parameters

  flags | Type of operation.
  town_id | Town ID to cargo game of.
  growth_rate | Amount of days between growth, or TOWN_GROWTH_RATE_NONE, or 0 to reset custom growth rate.

Returns
  Empty cost or an error.

Definition at line 2976 of file town_cmd.cpp.

## ◆ CmdTownRating()

CommandCost CmdTownRating | ( | DoCommandFlag | flags,
|  | TownID | town_id,
|  | CompanyID | company_id,
|  | int16_t | rating
| ) |  |

Change the rating of a company in a town.

Parameters

  flags | Type of operation.
  town_id | Town ID to change, bit 16..23 =
  company_id | Company ID to change.
  rating | New rating of company (signed int16_t).

Returns
  Empty cost or an error.

Definition at line 3014 of file town_cmd.cpp.

References _current_company, Clamp(), CMD_ERROR, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), and OWNER_DEITY.

## ◆ CmdTownSetText()

CommandCost CmdTownSetText | ( | DoCommandFlag | flags,
|  | TownID | town_id,
|  | const std::string & | text
| ) |  |

Set a custom text in the Town window.

Parameters

  flags | Type of operation.
  town_id | Town ID to change the text of.
  text | The new text (empty to remove the text).

Returns
  Empty cost or an error.

Definition at line 2954 of file town_cmd.cpp.

References _current_company, CMD_ERROR, DC_EXEC, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::GetIfValid(), InvalidateWindowData(), OWNER_DEITY, Town::text, and WC_TOWN_VIEW.

## ◆ CountActiveStations()

static int CountActiveStations | ( | Town * | t | ) |
| static

Calculates amount of active stations in the range of town (HZB_TOWN_EDGE).

Parameters

  t | The town to calculate stations for

Returns
  Amount of active stations

Definition at line 3601 of file town_cmd.cpp.

## ◆ CreateRandomTown()

static Town * CreateRandomTown | ( | uint | attempts,
|  | uint32_t | townnameparts,
|  | TownSize | size,
|  | bool | city,
|  | TownLayout | layout
| ) |  |
| static

Create a random town somewhere in the world.

Parameters

  attempts | How many times should we try?
  townnameparts | The name of the town.
  size | The size preset of the town.
  city | Should we build a city?
  layout | The road layout to build.

Returns
  The town object, or nullptr if we failed to create a town anywhere.

Definition at line 2277 of file town_cmd.cpp.

## ◆ DoClearTownHouseHelper()

static void DoClearTownHouseHelper | ( | TileIndex | tile,
|  | Town * | t,
|  | HouseID | house
| ) |  |
| static

Update data structures when a house is removed.

Parameters

  tile | Tile of the house
  t | Town owning the house
  house | House type

Definition at line 2790 of file town_cmd.cpp.

References DecreaseBuildingCount(), IsTileType(), and MP_HOUSE.

## ◆ DoCreateTown()

static void DoCreateTown | ( | Town * | t,
|  | TileIndex | tile,
|  | uint32_t | townnameparts,
|  | TownSize | size,
|  | bool | city,
|  | TownLayout | layout,
|  | bool | manual
| ) |  |
| static

Actually create a town.

Parameters

  t | The town.
  tile | Where to put it.
  townnameparts | The town name.
  size | The preset size of the town.
  city | Should we create a city?
  layout | The road layout of the town.
  manual | Was the town placed manually?

Definition at line 1936 of file town_cmd.cpp.

References Town::cache, Town::flags, Town::grow_counter, Town::growth_rate, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, TownCache::num_houses, TownCache::population, Town::time_until_rebuild, Ticks::TOWN_GROWTH_TICKS, UpdateTownRadius(), and Town::xy.

## ◆ DrawTile_Town()

static void DrawTile_Town | ( | TileInfo * | ti | ) |
| static

Draw a house and its tile.

This is a tile callback routine.

Parameters

  ti | TileInfo of the tile to draw

Definition at line 262 of file town_cmd.cpp.

References GetHouseType(), NEW_HOUSE_OFFSET, and TileInfo::tile.

## ◆ 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 2909 of file town_cmd.cpp.

References CargoSpec::Iterate().

Referenced by CmdTownCargoGoal().

## ◆ FindFurthestFromWater()

static bool FindFurthestFromWater | ( | TileIndex | tile,
|  | void * | user_data
| ) |  |
| static

CircularTileSearch callback; finds the tile furthest from any water.

slightly bit tricky, since it has to do a search of its own in order to find the distance to the water from each square in the radius.

Also, this never returns true, because it needs to take into account all locations being searched before it knows which is the furthest.

Parameters

  tile | Start looking from this tile
  user_data | Storage area for data that must last across calls; must be a pointer to struct SpotData

Returns
  always false

Definition at line 2217 of file town_cmd.cpp.

References GetClosestWaterDistance(), IsTileAlignedToGrid(), IsTileFlat(), IsTileType(), SpotData::layout, SpotData::max_dist, MP_CLEAR, and SpotData::tile.

Referenced by FindNearestGoodCoastalTownSpot().

## ◆ FindNearestEmptyLand()

static bool FindNearestEmptyLand | ( | TileIndex | tile,
|  | void * |
| ) |  |
| static

CircularTileSearch callback to find the nearest land tile.

Parameters

  tile | Start looking from this tile

Definition at line 2237 of file town_cmd.cpp.

References IsTileType(), and MP_CLEAR.

Referenced by FindNearestGoodCoastalTownSpot().

## ◆ FindNearestGoodCoastalTownSpot()

static TileIndex FindNearestGoodCoastalTownSpot | ( | TileIndex | tile,
|  | TownLayout | layout
| ) |  |
| static

Given a spot on the map (presumed to be a water tile), find a good coastal spot to build a city.

We don't want to build too close to the edge if we can help it (since that inhibits city growth) hence the search within a search within a search. O(n*m^2), where n is how far to search for land, and m is how far inland to look for a flat spot.

Parameters

  tile | Start looking from this spot.
  layout | the road layout to search for

Returns
  tile that was found

Definition at line 2254 of file town_cmd.cpp.

References CircularTileSearch(), FindFurthestFromWater(), FindNearestEmptyLand(), INVALID_TILE, and SpotData::tile.

## ◆ GenerateTowns()

bool GenerateTowns | ( | TownLayout | layout | ) |

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.

Returns
  true if towns have been successfully created.

Definition at line 2329 of file town_cmd.cpp.

## ◆ GenRandomRoadBits()

static RoadBits GenRandomRoadBits | ( |  | ) |
| static

Generate a random road block.

The probability of a straight road is somewhat higher than a curved.

Returns
  A RoadBits value with 2 bits set

Definition at line 1791 of file town_cmd.cpp.

## ◆ GetFoundation_Town()

static Foundation GetFoundation_Town | ( | TileIndex | tile,
|  | Slope | tileh
| ) |  |
| static

Get the foundation for a house.

This is a tile callback routine.

Parameters

  tile | The tile to find a foundation for.
  tileh | The slope of the tile.

Definition at line 321 of file town_cmd.cpp.

References HouseSpec::callback_mask, CBM_HOUSE_DRAW_FOUNDATIONS, GetHouseType(), HouseSpec::grf_prop, HasBit(), NEW_HOUSE_OFFSET, and GRFFilePropsBase< Tcnt >::spritegroup.

## ◆ 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 2807 of file town_cmd.cpp.

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

## ◆ 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 3462 of file town_cmd.cpp.

References _settings_game, _town_action_costs, EconomySettings::bribe, COMPANY_SPECTATOR, GameSettings::economy, GetAvailableMoney(), lengthof, Town::ratings, TACT_BRIBE, TACT_NONE, and Town::unwanted.

Referenced by TownAuthorityWindow::OnPaint().

## ◆ GetNormalGrowthRate()

static uint GetNormalGrowthRate | ( | Town * | t | ) |
| static

Calculates town growth rate in normal conditions (custom growth rate not set).

If town growth speed is set to None(0) returns the same rate as if it was Normal(2).

Parameters

  t | The town to calculate growth rate for

Returns
  Calculated growth rate

Note: Unserviced+unfunded towns get an additional malus in UpdateTownGrowth(), so the "320" is actually not better than the "420".

Definition at line 3618 of file town_cmd.cpp.

Referenced by UpdateTownGrowthRate().

## ◆ GetRating()

static int GetRating | ( | const Town * | t | ) |
| static

Get the rating of a town for the _current_company.

Parameters

  t | Town to get the rating from.

Returns
  Rating of the current company in the given town.

Definition at line 3805 of file town_cmd.cpp.

References _current_company, _town_rating_test, _town_test_ratings, and Town::ratings.

Referenced by ChangeTownRating(), and CheckforTownRating().

## ◆ GetTownRadiusGroup()

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

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

Referenced by BuildTownHouse(), IndustryTileScopeResolver::GetVariable(), IndustriesScopeResolver::GetVariable(), AirportTileScopeResolver::GetVariable(), HouseScopeResolver::GetVariable(), and ObjectScopeResolver::GetVariable().

## ◆ GetTownRoadBits()

static RoadBits GetTownRoadBits | ( | TileIndex | tile | ) |
| static

Return the RoadBits of a tile, ignoring depot and bay road stops.

Parameters

  tile | The tile to check.

Returns
  The roadbits of the given tile.

Definition at line 901 of file town_cmd.cpp.

References GetAnyRoadBits(), IsBayRoadStopTile(), IsRoadDepotTile(), and ROAD_NONE.

Referenced by CanFollowRoad(), GrowTownWithBridge(), GrowTownWithTunnel(), IsNeighborRoadTile(), and IsRoadAllowedHere().

## ◆ GetTownRoadGridElement()

static RoadBits GetTownRoadGridElement | ( | Town * | t,
|  | TileIndex | tile,
|  | DiagDirection | dir
| ) |  |
| static

Generate the RoadBits of a grid tile.

Parameters

  t | The current town.
  tile | The tile in reference to the town.
  dir | The direction to which we are growing.

Returns
  The RoadBit of the current tile regarding the selected town layout.

Definition at line 1064 of file town_cmd.cpp.

References Town::layout, ROAD_NONE, TileIndexToTileIndexDiffC(), and Town::xy.

## ◆ 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 912 of file town_cmd.cpp.

References ROADTYPE_ROAD.

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

## ◆ 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 455 of file town_cmd.cpp.

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

## ◆ GrowTown()

static bool GrowTown | ( | Town * | t | ) |
| static

Grow the town.

Parameters

  t | The town to grow

Returns
  true if we successfully grew the town with a road or house.

Definition at line 1805 of file town_cmd.cpp.

References _current_company, and OWNER_TOWN.

Referenced by TownTickHandler().

## ◆ GrowTownAtRoad()

static bool GrowTownAtRoad | ( | Town * | t,
|  | TileIndex | tile
| ) |  |
| static

Try to grow a town at a given road tile.

Parameters

  t | The town to grow.
  tile | The road tile to try growing from.

Returns
  true if we successfully expanded the town.

Definition at line 1709 of file town_cmd.cpp.

References DIAGDIR_END, Town::layout, Map::Size(), and TL_BETTER_ROADS.

## ◆ GrowTownInTile()

static void GrowTownInTile | ( | TileIndex * | tile_ptr,
|  | RoadBits | cur_rb,
|  | DiagDirection | target_dir,
|  | Town * | t1
| ) |  |
| static

Grows the given town.

There are at the moment 3 possible way's for the town expansion:

- Generate a random tile and check if there is a road allowed
- TL_ORIGINAL
- TL_BETTER_ROADS
- Check if the town geometry allows a road and which one
- TL_2X2_GRID
- TL_3X3_GRID
- Forbid roads, only build houses

Parameters

  tile_ptr | The current tile
  cur_rb | The current tiles RoadBits
  target_dir | The target road dir
  t1 | The current town

Definition at line 1459 of file town_cmd.cpp.

References ROAD_NONE, and Map::Size().

## ◆ GrowTownWithBridge()

static bool GrowTownWithBridge | ( | const Town * | t,
|  | const TileIndex | tile,
|  | const DiagDirection | bridge_dir
| ) |  |
| static

Grows the town with a bridge.

At first we check if a bridge is reasonable. If so we check if we are able to build it.

Parameters

  t | The current town
  tile | The current tile
  bridge_dir | The valid direction in which to grow a bridge

Returns
  true if a bridge has been build else false

Definition at line 1249 of file town_cmd.cpp.

References Town::cache, CanRoadContinueIntoNextTile(), CircularTileSearch(), CommandFlagsToDCFlags(), DC_EXEC, DIAGDIR_END, DiagDirToRoadBits(), DRD_NONE, GetDisallowedRoadDirections(), GetTileSlope(), GetTownRoadBits(), GetTownRoadType(), InclinedSlope(), IsNormalRoadTile(), IsPlainRailTile(), IsSea(), IsValidTile(), IsWaterTile(), MAX_BRIDGES, TownCache::population, RandomRange(), RedundantBridgeExistsNearby(), ReverseDiagDir(), SLOPE_FLAT, TileAddByDiagDir(), TileOffsByDiagDir(), and TRANSPORT_ROAD.

## ◆ GrowTownWithExtraHouse()

static bool GrowTownWithExtraHouse | ( | Town * | t,
|  | TileIndex | tile
| ) |  |
| static

Grows the town with an extra house.

Check if there are enough neighbor house tiles next to the current tile. If there are enough add another house.

Parameters

  t | The current town.
  tile | The target tile for the extra house.

Returns
  true if an extra house has been added.

Definition at line 1123 of file town_cmd.cpp.

References BuildTownHouse(), DIAGDIR_BEGIN, DIAGDIR_END, DistanceFromEdge(), GetTileType(), MP_HOUSE, MP_VOID, and TileAddByDiagDir().

## ◆ GrowTownWithRoad()

static bool GrowTownWithRoad | ( | const Town * | t,
|  | TileIndex | tile,
|  | RoadBits | rcmd
| ) |  |
| static

Grows the town with a road piece.

Parameters

  t | The current town.
  tile | The current tile.
  rcmd | The RoadBits we want to build on the tile.

Returns
  true if the RoadBits have been added.

Definition at line 1165 of file town_cmd.cpp.

References DC_AUTO, DC_EXEC, DC_NO_WATER, DRD_NONE, GetTownRoadType(), and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index.

## ◆ GrowTownWithTunnel()

static bool GrowTownWithTunnel | ( | const Town * | t,
|  | const TileIndex | tile,
|  | const DiagDirection | tunnel_dir
| ) |  |
| static

Grows the town with a tunnel.

First we check if a tunnel is reasonable. If so we check if we are able to build it.

Parameters

  t | The current town
  tile | The current tile
  tunnel_dir | The valid direction in which to grow a tunnel

Returns
  true if a tunnel has been built, else false

Definition at line 1330 of file town_cmd.cpp.

References Town::cache, CanRoadContinueIntoNextTile(), CommandFlagsToDCFlags(), DC_EXEC, DIAGDIR_END, DiagDirToRoadBits(), GetTileSlope(), GetTileZ(), GetTownRoadBits(), GetTownRoadType(), InclinedSlope(), IsSlopeWithOneCornerRaised(), IsSteepSlope(), IsValidTile(), TownCache::population, ReverseDiagDir(), TileAddByDiagDir(), TileOffsByDiagDir(), and TRANSPORT_ROAD.

## ◆ IsCloseToTown()

static bool IsCloseToTown | ( | TileIndex | tile,
|  | uint | dist
| ) |  |
| static

Determines if a town is close to a tile.

Parameters

  tile | TileIndex of the tile to query.
  dist | The maximum distance to be accepted.

Returns
  true if the tile is within the specified distance.

Definition at line 396 of file town_cmd.cpp.

Referenced by TownCanBePlacedHere().

## ◆ IsNeighborRoadTile()

static bool IsNeighborRoadTile | ( | TileIndex | tile,
|  | const DiagDirection | dir,
|  | uint | dist_multi
| ) |  |
| static

Check for parallel road inside a given distance.

Assuming a road from (tile - TileOffsByDiagDir(dir)) to tile, is there a parallel road left or right of it within distance dist_multi?

Parameters

  tile | The current tile.
  dir | The target direction.
  dist_multi | The distance multiplier.

Returns
  true if there is a parallel road.

Definition at line 953 of file town_cmd.cpp.

References ChangeDiagDir(), DIAGDIRDIFF_90LEFT, DIAGDIRDIFF_90RIGHT, DiagDirToRoadBits(), GetTownRoadBits(), IsValidTile(), ReverseDiagDir(), TILE_ADD, and TileOffsByDiagDir().

Referenced by IsRoadAllowedHere().

## ◆ IsRoadAllowedHere()

static bool IsRoadAllowedHere | ( | Town * | t,
|  | TileIndex | tile,
|  | DiagDirection | dir
| ) |  |
| static

Check if a Road is allowed on a given tile.

Parameters

  t | The current town.
  tile | The target tile.
  dir | The direction in which we want to extend the town.

Returns
  true if it is allowed.

Definition at line 987 of file town_cmd.cpp.

References _generating_world, _settings_game, ConstructionSettings::build_on_slopes, Chance16(), CMD_ERROR, ComplementSlope(), GameSettings::construction, DC_AUTO, DC_EXEC, DC_NO_WATER, DIAGDIR_NW, DIAGDIR_SE, DiagDirToAxis(), DistanceFromEdge(), DRD_NONE, CommandCost::Failed(), GetBridgeAxis(), GetFoundationSlope(), GetTileSlope(), GetTownRoadBits(), GetTownRoadType(), IsBridgeAbove(), IsNeighborRoadTile(), Town::layout, ROAD_NONE, ROAD_X, ROAD_Y, SLOPE_ELEVATED, SLOPE_FLAT, SLOPE_NE, SLOPE_NW, and TL_ORIGINAL.

## ◆ IsTileAlignedToGrid()

static bool IsTileAlignedToGrid | ( | TileIndex | tile,
|  | TownLayout | layout
| ) |  |
| static

Towns must all be placed on the same grid or when they eventually interpenetrate their road networks will not mesh nicely; this function tells you if a tile is properly aligned.

Parameters

  tile | The tile to start at.
  layout | The town layout in effect.

Returns
  true if the tile is in the correct location.

Definition at line 2183 of file town_cmd.cpp.

References TileX(), TileY(), TL_2X2_GRID, and TL_3X3_GRID.

Referenced by FindFurthestFromWater().

## ◆ IsUniqueTownName()

static bool IsUniqueTownName | ( | const std::string & | name | ) |
| static

Verifies this custom name is unique.

Only custom names are checked.

Parameters

  name | The name to check.

Returns
  true if the name is unique

Definition at line 2037 of file town_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::Iterate(), and Town::name.

Referenced by CmdRenameTown().

## ◆ MakeTownHouse()

static void MakeTownHouse | ( | TileIndex | tile,
|  | Town * | t,
|  | byte | counter,
|  | byte | stage,
|  | HouseID | type,
|  | byte | random_bits
| ) |  |
| static

Write house information into the map.

For multi-tile houses, all tiles are marked.

Parameters

  town | The town related to this house
  t | The tile to build on. If a multi-tile house, this is the northern-most tile.
  counter | The counter of the construction stage.
  stage | The current construction stage.
  The | type of house.
  random_bits | Random bits for newgrf houses to use.

Precondition
  The house can be built here.

Definition at line 2433 of file town_cmd.cpp.

References HouseSpec::building_flags, and ClearMakeHouseTile().

## ◆ RandomDiagDir()

static DiagDirection RandomDiagDir | ( |  | ) |
| inlinestatic

Return a random direction.

Returns
  a random direction

Definition at line 253 of file town_cmd.cpp.

References DIAGDIR_END, and RandomRange().

## ◆ RedundantBridgeExistsNearby()

static bool RedundantBridgeExistsNearby | ( | TileIndex | tile,
|  | void * | user_data
| ) |  |
| static

CircularTileSearch proc which checks for a nearby parallel bridge to avoid building redundant bridges.

Parameters

  tile | The tile to search.
  user_data | Reference to the valid direction of the proposed bridge.

Returns
  true if another bridge exists, else false.

Definition at line 1224 of file town_cmd.cpp.

References GetTileSlope(), GetTunnelBridgeTransportType(), InclinedSlope(), IsBridgeTile(), IsValidTile(), ReverseDiagDir(), and TRANSPORT_ROAD.

Referenced by GrowTownWithBridge().

## ◆ RemoveNearbyStations()

static void RemoveNearbyStations | ( | Town * | t,
|  | TileIndex | tile,
|  | BuildingFlags | flags
| ) |  |
| static

Remove stations from nearby station list if a town is no longer in the catchment area of each.

To improve performance only checks stations that cover the provided house area (doesn't need to contain an actual house).

Parameters

  t | Town to work on.
  tile | Location of house area (north tile).
  flags | BuildingFlags containing the size of house area.

Definition at line 469 of file town_cmd.cpp.

References Town::stations_near.

## ◆ RoadTypesAllowHouseHere()

static bool RoadTypesAllowHouseHere | ( | TileIndex | t | ) |
| inlinestatic

Checks whether at least one surrounding road allows to build a house here.

Parameters

  t | The tile where the house will be built.

Returns
  true if at least one surrounding roadtype allows building houses here.

Definition at line 1396 of file town_cmd.cpp.

References endof, IsRoadStopTile(), IsTileType(), IsValidTile(), MP_ROAD, and ToTileIndexDiff().

Referenced by CanBuildHouseHere().

## ◆ SearchTileForStatue()

static bool SearchTileForStatue | ( | TileIndex | tile,
|  | void * | user_data
| ) |  |
| static

Search callback function for TownActionBuildStatue.

Parameters

  tile | Tile on which to perform the search.
  user_data | Reference to the statue search data.

Returns
  Result of the test.

Definition at line 3273 of file town_cmd.cpp.

References StatueBuildSearchData::best_position, CheckClearTile(), GetTileSlope(), INVALID_TILE, IsBridgeAbove(), IsSteepSlope(), IsTileType(), MP_CLEAR, MP_HOUSE, MP_TREES, and StatueBuildSearchData::tile_count.

Referenced by TownActionBuildStatue().

## ◆ 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 3785 of file town_cmd.cpp.

References _town_rating_test, and _town_test_ratings.

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

## ◆ TestTownOwnsBridge()

static bool TestTownOwnsBridge | ( | TileIndex | tile,
|  | const Town * | t
| ) |  |
| static

Check if a town 'owns' a bridge.

Bridges do not directly have an owner, so we check the tiles adjacent to the bridge ends. If either adjacent tile belongs to the town then it will be assumed that the town built the bridge.

Parameters

  tile | The bridge tile to test
  t | The town we are interested in

Returns
  true If town 'owns' a bridge.

Definition at line 92 of file town_cmd.cpp.

References GetOtherTunnelBridgeEnd(), GetTownIndex(), GetTunnelBridgeDirection(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, IsTileOwner(), IsTileType(), MP_ROAD, OWNER_TOWN, ReverseDiagDir(), and TileOffsByDiagDir().

Referenced by Town::~Town().

## ◆ TileLoop_Town()

static void TileLoop_Town | ( | TileIndex | tile | ) |
| static

Tile callback function.

Tile callback function. Periodic tick handler for the tiles of a town.

Parameters

  tile | been asked to do its stuff

Definition at line 598 of file town_cmd.cpp.

References GetHouseType(), and NEW_HOUSE_OFFSET.

## ◆ TownActionAdvertiseLarge()

static CommandCost TownActionAdvertiseLarge | ( | Town * | t,
|  | DoCommandFlag | flags
| ) |  |
| static

Perform the "large advertising campaign" town action.

Parameters

  t | The town to advertise in.
  flags | Type of operation.

Returns
  An empty cost.

Definition at line 3209 of file town_cmd.cpp.

References DC_EXEC.

## ◆ TownActionAdvertiseMedium()

static CommandCost TownActionAdvertiseMedium | ( | Town * | t,
|  | DoCommandFlag | flags
| ) |  |
| static

Perform the "medium advertising campaign" town action.

Parameters

  t | The town to advertise in.
  flags | Type of operation.

Returns
  An empty cost.

Definition at line 3195 of file town_cmd.cpp.

References DC_EXEC.

## ◆ TownActionAdvertiseSmall()

static CommandCost TownActionAdvertiseSmall | ( | Town * | t,
|  | DoCommandFlag | flags
| ) |  |
| static

Perform the "small advertising campaign" town action.

Parameters

  t | The town to advertise in.
  flags | Type of operation.

Returns
  An empty cost.

Definition at line 3181 of file town_cmd.cpp.

References DC_EXEC.

## ◆ TownActionBribe()

static CommandCost TownActionBribe | ( | Town * | t,
|  | DoCommandFlag | flags
| ) |  |
| static

Perform the "bribe" town action.

Parameters

  t | The town to bribe.
  flags | Type of operation.

Returns
  An empty cost.

Definition at line 3407 of file town_cmd.cpp.

References _current_company, Chance16(), DC_EXEC, INVALID_STRING_ID, IsLocalCompany(), SpecializedStation< Station, false >::Iterate(), GoodsEntry::rating, Town::ratings, ShowErrorMessage(), Town::unwanted, and WL_INFO.

## ◆ TownActionBuildStatue()

static CommandCost TownActionBuildStatue | ( | Town * | t,
|  | DoCommandFlag | flags
| ) |  |
| static

Perform a 9x9 tiles circular search from the center of the town in order to find a free tile to place a statue.

Parameters

  t | town to search in
  flags | Used to check if the statue must be built or not.

Returns
  Empty cost or an error.

Definition at line 3316 of file town_cmd.cpp.

References _current_company, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_object_pool >::CanAllocateItem(), CircularTileSearch(), DC_EXEC, INVALID_TILE, OWNER_NONE, return_cmd_error, SearchTileForStatue(), and Town::xy.

## ◆ TownActionBuyRights()

static CommandCost TownActionBuyRights | ( | Town * | t,
|  | DoCommandFlag | flags
| ) |  |
| static

Perform the "buy exclusive transport rights" town action.

Parameters

  t | The town to buy exclusivity in.
  flags | Type of operation.

Returns
  An empty cost.

Definition at line 3374 of file town_cmd.cpp.

References _current_company, _settings_game, CMD_ERROR, DC_EXEC, GameSettings::economy, Town::exclusive_counter, EconomySettings::exclusive_rights, Town::exclusivity, and INVALID_COMPANY.

## ◆ TownActionFundBuildings()

static CommandCost TownActionFundBuildings | ( | Town * | t,
|  | DoCommandFlag | flags
| ) |  |
| static

Perform the "fund new buildings" town action.

Parameters

  t | The town to fund buildings in.
  flags | Type of operation.

Returns
  An empty cost.

Definition at line 3341 of file town_cmd.cpp.

References _settings_game, CMD_ERROR, DC_EXEC, GameSettings::economy, EconomySettings::fund_buildings, Town::fund_buildings_months, Town::grow_counter, Town::growth_rate, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, SetWindowDirty(), Ticks::TOWN_GROWTH_TICKS, UpdateTownGrowth(), and WC_TOWN_VIEW.

## ◆ TownActionRoadRebuild()

static CommandCost TownActionRoadRebuild | ( | Town * | t,
|  | DoCommandFlag | flags
| ) |  |
| static

Perform the "local road reconstruction" town action.

Parameters

  t | The town to grief in.
  flags | Type of operation.

Returns
  An empty cost.

Definition at line 3223 of file town_cmd.cpp.

References _current_company, _settings_game, AddNewsItem(), AI::BroadcastNewEvent(), CMD_ERROR, DC_EXEC, GameSettings::economy, EconomySettings::fund_roads, GetString(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, NF_NORMAL, NR_NONE, NR_TOWN, NT_GENERAL, Town::road_build_months, SetDParam(), SetDParamStr(), NewsStringData::string, and TimerGameEconomy::UsingWallclockUnits().

## ◆ TownAllowedToBuildRoads()

static bool TownAllowedToBuildRoads | ( |  | ) |
| inlinestatic

Check if the town is allowed to build roads.

Returns
  true If the town is allowed to build roads.

Definition at line 1437 of file town_cmd.cpp.

References _generating_world, _settings_game, EconomySettings::allow_town_roads, and GameSettings::economy.

Referenced by CanFollowRoad(), TownLayoutAllows2x2HouseHere(), and TownLayoutAllowsHouseHere().

## ◆ TownCanBePlacedHere()

static CommandCost TownCanBePlacedHere | ( | TileIndex | tile | ) |
| static

Check if it's possible to place a town on a given tile.

Parameters

  tile | The tile to check.

Returns
  A zero cost if allowed, otherwise an error.

Definition at line 2012 of file town_cmd.cpp.

References DistanceFromEdge(), EXPENSES_OTHER, IsCloseToTown(), IsTileFlat(), IsTileType(), MP_CLEAR, MP_TREES, and return_cmd_error.

## ◆ TownCanGrowRoad()

static bool TownCanGrowRoad | ( | TileIndex | tile | ) |
| static

Test if town can grow road onto a specific tile.

Parameters

  tile | Tile to build upon.

Returns
  true iff the tile's road type don't prevent extending the road.

Definition at line 1424 of file town_cmd.cpp.

References IsTileType(), and MP_ROAD.

## ◆ TownGenerateCargo()

static void TownGenerateCargo | ( | Town * | t,
|  | CargoID | ct,
|  | uint | amount,
|  | StationFinder & | stations,
|  | bool | affected_by_recession
| ) |  |
| static

Generate cargo for a house, scaled by the current economy scale.

Parameters

  t | The current town.
  ct | Type of cargo to generate, usually CT_PASSENGERS or CT_MAIL.
  amount | The number of cargo units.
  stations | Available stations for this house.
  affected_by_recession | Is this cargo halved during recessions?

Definition at line 531 of file town_cmd.cpp.

References EconomyIsInRecession(), TransportedCargoStat< Tstorage >::new_act, TransportedCargoStat< Tstorage >::new_max, ScaleByCargoScale(), and Town::supplied.

## ◆ TownGenerateCargoBinominal()

static void TownGenerateCargoBinominal | ( | Town * | t,
|  | TownProductionEffect | tpe,
|  | uint8_t | rate,
|  | StationFinder & | stations
| ) |  |
| static

Generate cargo for a house using the binominal algorithm.

Parameters

  t | The current town.
  tpe | The town production effect.
  rate | The town's product rate for this production.
  stations | Available stations for this house.

Definition at line 575 of file town_cmd.cpp.

References CargoSpec::town_production_cargoes.

## ◆ TownGenerateCargoOriginal()

static void TownGenerateCargoOriginal | ( | Town * | t,
|  | TownProductionEffect | tpe,
|  | uint8_t | rate,
|  | StationFinder & | stations
| ) |  |
| static

Generate cargo for a house using the original algorithm.

Parameters

  t | The current town.
  tpe | The town production effect.
  rate | The town's product rate for this production.
  stations | Available stations for this house.

Definition at line 555 of file town_cmd.cpp.

References CargoSpec::town_production_cargoes.

## ◆ TownLayoutAllows2x2HouseHere()

static bool TownLayoutAllows2x2HouseHere | ( | Town * | t,
|  | TileIndex | tile
| ) |  |
| inlinestatic

Checks if the current town layout allows a 2x2 building here.

Parameters

  t | The town.
  tile | The tile to check.

Returns
  true iff town layout allows a 2x2 building here.

Note
  see layouts

Definition at line 2551 of file town_cmd.cpp.

References Town::layout, TileIndexToTileIndexDiffC(), TL_2X2_GRID, TL_3X3_GRID, TownAllowedToBuildRoads(), TileIndexDiffC::x, Town::xy, and TileIndexDiffC::y.

Referenced by CheckTownBuild2x2House().

## ◆ TownLayoutAllowsHouseHere()

static bool TownLayoutAllowsHouseHere | ( | Town * | t,
|  | TileIndex | tile
| ) |  |
| inlinestatic

Checks if the current town layout allows building here.

Parameters

  t | The town.
  tile | The tile to check.

Returns
  true iff town layout allows building here.

Note
  see layouts

Definition at line 2520 of file town_cmd.cpp.

References Town::layout, TileIndexToTileIndexDiffC(), TL_2X2_GRID, TL_3X3_GRID, TownAllowedToBuildRoads(), TileIndexDiffC::x, Town::xy, and TileIndexDiffC::y.

Referenced by BuildTownHouse(), and CheckTownBuild2House().

## ◆ TownTickHandler()

static void TownTickHandler | ( | Town * | t | ) |
| static

Handle the town tick for a single town, by growing the town if desired.

Parameters

  t | The town to try growing.

Definition at line 870 of file town_cmd.cpp.

References Town::flags, Town::grow_counter, Town::growth_rate, GrowTown(), HasBit(), Ticks::TOWN_GROWTH_TICKS, and TOWN_IS_GROWING.

## ◆ UpdateTownGrowCounter()

static void UpdateTownGrowCounter | ( | Town * | t,
|  | uint16_t | prev_growth_rate
| ) |  |
| static

Updates town grow counter after growth rate change.

Preserves relative house builting progress whenever it can.

Parameters

  t | The town to calculate grow counter for
  prev_growth_rate | Town growth rate before it changed (one that was used with grow counter to be updated)

Definition at line 3586 of file town_cmd.cpp.

Referenced by UpdateTownGrowthRate().

## ◆ UpdateTownGrowth()

static void UpdateTownGrowth | ( | Town * | t | ) |
| static

Updates town growth state (whether it is growing or not).

Parameters

  t | The town to update growth for

Definition at line 3658 of file town_cmd.cpp.

References _settings_game, ClrBit(), GameSettings::economy, Town::flags, Town::fund_buildings_months, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, SetWindowDirty(), EconomySettings::town_growth_rate, TOWN_IS_GROWING, UpdateTownGrowthRate(), and WC_TOWN_VIEW.

Referenced by CmdTownCargoGoal(), and TownActionFundBuildings().

## ◆ UpdateTownGrowthRate()

static void UpdateTownGrowthRate | ( | Town * | t | ) |
| static

Updates town growth rate.

Parameters

  t | The town to update growth rate for

Definition at line 3645 of file town_cmd.cpp.

References Town::flags, GetNormalGrowthRate(), Town::growth_rate, HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, SetWindowDirty(), TOWN_CUSTOM_GROWTH, UpdateTownGrowCounter(), and WC_TOWN_VIEW.

Referenced by UpdateTownGrowth().

## ◆ UpdateTownMaxPass()

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

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

Parameters

  t | The town to update.

Definition at line 1912 of file town_cmd.cpp.

References Town::cache, TransportedCargoStat< Tstorage >::old_max, TownCache::population, ScaleByCargoScale(), Town::supplied, CargoSpec::town_production_cargoes, TPE_MAIL, and TPE_PASSENGERS.

## ◆ 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 1865 of file town_cmd.cpp.

Referenced by DoCreateTown().

## ◆ UpdateTownRating()

static void UpdateTownRating | ( | Town * | t | ) |
| static

Monthly callback to update town and station ratings.

Parameters

  t | The town to update.

Definition at line 3548 of file town_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Iterate(), RATING_GROWTH_MAXIMUM, RATING_GROWTH_UP_STEP, and Town::ratings.

## Variable Documentation

## ◆ _tile_type_town_procs

const TileTypeProcs _tile_type_town_procs

Initial value:
= {
DrawTile_Town,
GetSlopePixelZ_Town,
ClearTile_Town,
AddAcceptedCargo_Town,
GetTileDesc_Town,
GetTileTrackStatus_Town,
nullptr,
AnimateTile_Town,
TileLoop_Town,
ChangeTileOwner_Town,
AddProducedCargo_Town,
nullptr,
GetFoundation_Town,
TerraformTile_Town,
}

Tile callback functions for a town.

Definition at line 50 of file landscape.cpp.

## ◆ _town_action_costs

const byte _town_action_costs[TACT_COUNT]

Initial value:
= {
2, 4, 9, 35, 48, 53, 117, 175
}

Factor in the cost of each town action.

See also
  TownActions

Definition at line 3171 of file town_cmd.cpp.

Referenced by GetMaskOfTownActions().

## ◆ _town_action_proc

TownActionProc* const _town_action_proc[]
| static

Initial value:
= {
TownActionAdvertiseSmall,
TownActionAdvertiseMedium,
TownActionAdvertiseLarge,
TownActionRoadRebuild,
TownActionBuildStatue,
TownActionFundBuildings,
TownActionBuyRights,
TownActionBribe
}

Definition at line 3445 of file town_cmd.cpp.

## ◆ _town_draw_tile_procs

TownDrawTileProc* const _town_draw_tile_procs[1]
| static

Initial value:
= {
TownDrawHouseLift
}

Definition at line 244 of file town_cmd.cpp.

TileLoop_Town
static void TileLoop_Town(TileIndex tile)
Tile callback function.
Definition: town_cmd.cpp:598
TownActionBuildStatue
static CommandCost TownActionBuildStatue(Town *t, DoCommandFlag flags)
Perform a 9x9 tiles circular search from the center of the town in order to find a free tile to place...
Definition: town_cmd.cpp:3316
TownActionBuyRights
static CommandCost TownActionBuyRights(Town *t, DoCommandFlag flags)
Perform the "buy exclusive transport rights" town action.
Definition: town_cmd.cpp:3374
TownActionAdvertiseSmall
static CommandCost TownActionAdvertiseSmall(Town *t, DoCommandFlag flags)
Perform the "small advertising campaign" town action.
Definition: town_cmd.cpp:3181
TownActionRoadRebuild
static CommandCost TownActionRoadRebuild(Town *t, DoCommandFlag flags)
Perform the "local road reconstruction" town action.
Definition: town_cmd.cpp:3223
GetFoundation_Town
static Foundation GetFoundation_Town(TileIndex tile, Slope tileh)
Get the foundation for a house.
Definition: town_cmd.cpp:321
TownActionFundBuildings
static CommandCost TownActionFundBuildings(Town *t, DoCommandFlag flags)
Perform the "fund new buildings" town action.
Definition: town_cmd.cpp:3341
TownActionAdvertiseLarge
static CommandCost TownActionAdvertiseLarge(Town *t, DoCommandFlag flags)
Perform the "large advertising campaign" town action.
Definition: town_cmd.cpp:3209
ClearTile_Town
static CommandCost ClearTile_Town(TileIndex tile, DoCommandFlag flags)
Callback function to clear a house tile.
Definition: town_cmd.cpp:710
TownActionBribe
static CommandCost TownActionBribe(Town *t, DoCommandFlag flags)
Perform the "bribe" town action.
Definition: town_cmd.cpp:3407
AnimateTile_Town
static void AnimateTile_Town(TileIndex tile)
Animate a tile for a town.
Definition: town_cmd.cpp:345
TownActionAdvertiseMedium
static CommandCost TownActionAdvertiseMedium(Town *t, DoCommandFlag flags)
Perform the "medium advertising campaign" town action.
Definition: town_cmd.cpp:3195
DrawTile_Town
static void DrawTile_Town(TileInfo *ti)
Draw a house and its tile.
Definition: town_cmd.cpp:262