OpenTTD Source: src/town_cmd.cpp File Reference

OpenTTD Source 15.3

Typedefs | Enumerations | Functions | Variables
town_cmd.cpp File Reference

Handling of town tiles. More...

`#include "stdafx.h"`
`#include "misc/history_type.hpp"`
`#include "misc/history_func.hpp"`
`#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 "clear_map.h"`
`#include "tree_map.h"`
`#include "map_func.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.

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

## Enumerations
enum class | TownGrowthResult { Succeed , SearchStopped , Continue }

## Functions
void | RebuildTownKdtree ()
static bool | TestTownOwnsBridge (TileIndex tile, const Town *t)
| Check if a town 'owns' a bridge.
static bool | TryBuildTownHouse (Town *t, TileIndex tile, TownExpandModes modes)
| Tries to build a house at this tile.
static Town * | CreateRandomTown (uint attempts, uint32_t townnameparts, TownSize size, bool city, TownLayout layout)
| Create a random town somewhere in the world.
static void | TownDrawHouseLift (const TileInfo *ti)
static DiagDirection | RandomDiagDir ()
| Return a random direction.
static void | DrawTile_Town (TileInfo *ti)
| Draw a house and its tile.
static int | GetSlopePixelZ_Town (TileIndex tile, uint, uint, bool)
static Foundation | GetFoundation_Town (TileIndex tile, Slope tileh)
| Get the foundation for a house.
static void | AnimateTile_Town (TileIndex tile)
| Animate a tile for a town.
static bool | IsCloseToTown (TileIndex tile, uint dist)
| Determines if a town is close to a tile.
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.
uint32_t | GetWorldPopulation ()
| Get the total population, the sum of all towns in the world.
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.
static void | AdvanceSingleHouseConstruction (TileIndex tile)
| Helper function for house construction stage progression.
static void | AdvanceHouseConstruction (TileIndex tile)
| Increase the construction stage of a house.
static void | TownGenerateCargo (Town *t, CargoType cargo, uint amount, StationFinder &stations, bool affected_by_recession)
| Generate cargo for a house, scaled by the current economy scale.
static void | TownGenerateCargoOriginal (Town *t, TownProductionEffect tpe, uint8_t rate, StationFinder &stations)
| Generate cargo for a house using the original algorithm.
static void | TownGenerateCargoBinomial (Town *t, TownProductionEffect tpe, uint8_t rate, StationFinder &stations)
| Generate cargo for a house using the binomial algorithm.
static void | TileLoop_Town (TileIndex tile)
| Tile callback function.
static CommandCost | ClearTile_Town (TileIndex tile, DoCommandFlags flags)
| Callback function to clear a house tile.
static void | AddProducedCargo_Town (TileIndex tile, CargoArray &produced)
static void | AddAcceptedCargoSetMask (CargoType cargo, uint amount, CargoArray &acceptance, CargoTypes &always_accepted)
| Fill cargo acceptance array and always_accepted mask, if cargo type is valid.
void | AddAcceptedCargoOfHouse (TileIndex tile, HouseID house, const HouseSpec *hs, Town *t, CargoArray &acceptance, CargoTypes &always_accepted)
| Determine accepted cargo for a house.
static void | AddAcceptedCargo_Town (TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted)
CargoArray | GetAcceptedCargoOfHouse (const HouseSpec *hs)
| Get accepted cargo of a house prototype.
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, TownExpandModes modes)
| Grow the town.
static void | TownTickHandler (Town *t)
| Handle the town tick for a single town, by growing the town if desired.
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.
RoadType | GetTownRoadType ()
| Get the road type that towns should build at this current moment.
static TimerGameCalendar::Date | GetTownRoadTypeFirstIntroductionDate ()
| Get the calendar date of the earliest town-buildable road type.
bool | CheckTownRoadTypes ()
| Check if towns are able to build road.
static bool | IsNeighbourRoadTile (TileIndex tile, const DiagDirection dir, uint dist_multi)
| Check for parallel road inside a given distance.
static bool | IsRoadAllowedHere (Town *t, TileIndex tile, DiagDirection dir)
| Check if a Road is allowed on a given tile.
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.
static bool | GrowTownWithExtraHouse (Town *t, TileIndex tile, TownExpandModes modes)
| Grows the town with an extra house.
static bool | GrowTownWithRoad (const Town *t, TileIndex tile, RoadBits rcmd)
| Grows the town with a road piece.
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.
static bool | GrowTownWithBridge (const Town *t, const TileIndex tile, const DiagDirection bridge_dir)
| Grows the town with a bridge.
static bool | GrowTownWithTunnel (const Town *t, const TileIndex tile, const DiagDirection tunnel_dir)
| Grows the town with a tunnel.
static bool | RoadTypesAllowHouseHere (TileIndex t)
| Checks whether at least one surrounding road allows to build a house here.
static bool | TownCanGrowRoad (TileIndex tile)
| Test if town can grow road onto a specific tile.
static bool | TownAllowedToBuildRoads (TownExpandModes modes)
| Check if the town is allowed to build roads.
static TownGrowthResult | GrowTownInTile (TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection target_dir, Town *t1, TownExpandModes modes)
| Grows the given town.
static bool | CanFollowRoad (TileIndex tile, DiagDirection dir, TownExpandModes modes)
| Checks whether a road can be followed or is a dead end, that can not be extended to the next tile.
static bool | GrowTownAtRoad (Town *t, TileIndex tile, TownExpandModes modes)
| Try to grow a town at a given road tile.
static RoadBits | GenRandomRoadBits ()
| Generate a random road block.
void | UpdateTownRadius (Town *t)
| Update the cached town zone radii of a town, based on the number of houses.
void | UpdateTownMaxPass (Town *t)
| Update the maximum amount of monthly passengers and mail for a town, based on its population.
static void | UpdateTownGrowthRate (Town *t)
| Updates town growth rate.
static void | UpdateTownGrowth (Town *t)
| Updates town growth state (whether it is growing or not).
static void | DoCreateTown (Town *t, TileIndex tile, uint32_t townnameparts, TownSize size, bool city, TownLayout layout, bool manual)
| Actually create a town.
static CommandCost | TownCanBePlacedHere (TileIndex tile, bool check_surrounding)
| Check if it's possible to place a town on a given tile.
static bool | IsUniqueTownName (const std::string &name)
| Verifies this custom name is unique.
std::tuple< CommandCost, Money, TownID > | CmdFoundTown (DoCommandFlags flags, TileIndex tile, TownSize size, bool city, TownLayout layout, bool random_location, uint32_t townnameparts, const std::string &text)
| Create a new town.
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.
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.
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.
HouseZones | GetClimateMaskForLandscape ()
| Get the HouseZones climate mask for the current landscape type.
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)
| Generate a number of towns with a given layout.
HouseZone | GetTownRadiusGroup (const Town *t, TileIndex tile)
| Returns the bit corresponding to the town zone of the specified tile.
static void | ClearMakeHouseTile (TileIndex tile, Town *t, uint8_t counter, uint8_t stage, HouseID type, uint8_t random_bits, bool is_protected)
| Clears tile and builds a house or house part.
static void | MakeTownHouse (TileIndex tile, Town *t, uint8_t counter, uint8_t stage, HouseID type, uint8_t random_bits, bool is_protected)
| Write house information into the map.
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.
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.
static bool | CheckFree2x2Area (TileIndex tile, int z, bool noslope)
| Checks if a house of size 2x2 can be built at this tile.
static bool | TownLayoutAllowsHouseHere (Town *t, TileIndex tile, TownExpandModes modes)
| Checks if the current town layout allows building here.
static bool | TownLayoutAllows2x2HouseHere (Town *t, TileIndex tile, TownExpandModes modes)
| Checks if the current town layout allows a 2x2 building here.
static bool | CheckTownBuild2House (TileIndex *tile, Town *t, int maxz, bool noslope, DiagDirection second, TownExpandModes modes)
| Checks if a 1x2 or 2x1 building is allowed here, accounting for road layout and tile heights.
static bool | CheckTownBuild2x2House (TileIndex *tile, Town *t, int maxz, bool noslope, TownExpandModes modes)
| Checks if a 1x2 or 2x1 building is allowed here, accounting for road layout and tile heights.
static void | BuildTownHouse (Town *t, TileIndex tile, const HouseSpec *hs, HouseID house, uint8_t random_bits, bool house_completed, bool is_protected)
| Build a house at this tile.
CommandCost | CmdPlaceHouse (DoCommandFlags flags, TileIndex tile, HouseID house, bool is_protected, bool replace)
| Place an individual house.
static void | DoClearTownHouseHelper (TileIndex tile, Town *t, HouseID house)
| Update data structures when a house is removed.
TileIndexDiff | GetHouseNorthPart (HouseID &house)
| Determines if a given HouseID is part of a multitile house.
void | ClearTownHouse (Town *t, TileIndex tile)
| Clear a town house.
CommandCost | CmdRenameTown (DoCommandFlags flags, TownID town_id, const std::string &text)
| Rename a town (server-only).
const CargoSpec * | FindFirstCargoWithTownAcceptanceEffect (TownAcceptanceEffect effect)
| Determines the first cargo with a certain town effect.
CommandCost | CmdTownCargoGoal (DoCommandFlags flags, TownID town_id, TownAcceptanceEffect tae, uint32_t goal)
| Change the cargo goal of a town.
CommandCost | CmdTownSetText (DoCommandFlags flags, TownID town_id, const EncodedString &text)
| Set a custom text in the Town window.
CommandCost | CmdTownGrowthRate (DoCommandFlags flags, TownID town_id, uint16_t growth_rate)
| Change the growth rate of the town.
CommandCost | CmdTownRating (DoCommandFlags flags, TownID town_id, CompanyID company_id, int16_t rating)
| Change the rating of a company in a town.
CommandCost | CmdExpandTown (DoCommandFlags flags, TownID town_id, uint32_t grow_amount, TownExpandModes modes)
| Expand a town (scenario editor only).
CommandCost | CmdDeleteTown (DoCommandFlags flags, TownID town_id)
| Delete a town (scenario editor or worldgen only).
uint8_t | GetTownActionCost (TownAction action)
| Get cost factors for a TownAction.
static CommandCost | TownActionAdvertiseSmall (Town *t, DoCommandFlags flags)
| Perform the "small advertising campaign" town action.
static CommandCost | TownActionAdvertiseMedium (Town *t, DoCommandFlags flags)
| Perform the "medium advertising campaign" town action.
static CommandCost | TownActionAdvertiseLarge (Town *t, DoCommandFlags flags)
| Perform the "large advertising campaign" town action.
static CommandCost | TownActionRoadRebuild (Town *t, DoCommandFlags flags)
| Perform the "local road reconstruction" town action.
static bool | CheckClearTile (TileIndex tile)
| Check whether the land can be cleared.
static CommandCost | TownActionBuildStatue (Town *t, DoCommandFlags flags)
| Perform a 9x9 tiles circular search from the center of the town in order to find a free tile to place a statue.
static CommandCost | TownActionFundBuildings (Town *t, DoCommandFlags flags)
| Perform the "fund new buildings" town action.
static CommandCost | TownActionBuyRights (Town *t, DoCommandFlags flags)
| Perform the "buy exclusive transport rights" town action.
static CommandCost | TownActionBribe (Town *t, DoCommandFlags flags)
| Perform the "bribe" town action.
TownActions | GetMaskOfTownActions (CompanyID cid, const Town *t)
| Get a list of available town authority actions.
CommandCost | CmdDoTownAction (DoCommandFlags flags, TownID town_id, TownAction action)
| Do a town action.
template<typename Func >
static void | ForAllStationsNearTown (Town *t, Func func)
static void | UpdateTownRating (Town *t)
| Monthly callback to update town and station ratings.
static void | UpdateTownGrowCounter (Town *t, uint16_t prev_growth_rate)
| Updates town grow counter after growth rate change.
static int | CountActiveStations (Town *t)
| Calculates amount of active stations in the range of town (HZB_TOWN_EDGE).
static uint | GetNormalGrowthRate (Town *t)
| Calculates town growth rate in normal conditions (custom growth rate not set).
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 * | CalcClosestTownFromTile (TileIndex tile, uint threshold)
| Return the town closest to the given tile within threshold.
Town * | ClosestTownFromTile (TileIndex tile, uint threshold)
| Return the town closest (in distance or ownership) to a given tile, within a given threshold.
void | SetTownRatingTestMode (bool mode)
| Switch the town rating to test-mode, to allow commands to be tested without affecting current ratings.
static int | GetRating (const Town *t)
| Get the rating of a town for the _current_company.
void | ChangeTownRating (Town *t, int add, int max, DoCommandFlags flags)
| Changes town rating of the current company.
CommandCost | CheckforTownRating (DoCommandFlags flags, Town *t, TownRatingCheckType type)
| Does the town authority allow the (destructive) action of the current company?
template<>
Town::SuppliedHistory | SumHistory (std::span< const Town::SuppliedHistory > history)
static CommandCost | TerraformTile_Town (TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
std::span< const DrawBuildingsTileStruct > | GetTownDrawTileData ()

## Variables
TownPool | _town_pool ("Town")
TownKdtree | _town_kdtree {}
static bool | _generating_town = false
| Set if a town is being generated.
static TownDrawTileProc *const | _town_draw_tile_procs [1]
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 const 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=CompanyID::Invalid();} for(const Company *c :Company::Iterate()) { if(t->unwanted[c->index] > 0) t->unwanted[c->index]--;} UpdateValidHistory(t->valid_history, HISTORY_YEAR, TimerGameEconomy::month);for(auto &s :t->supplied) RotateHistory(s.history, t->valid_history, HISTORY_YEAR, TimerGameEconomy::month);for(auto &received :t->received) received.NewMonth();UpdateTownGrowth(t);UpdateTownRating(t);SetWindowDirty(WC_TOWN_VIEW, t->index);} })
static const IntervalTimer< TimerGameEconomy > | _economy_towns_yearly ({TimerGameEconomy::YEAR, TimerGameEconomy::Priority::TOWN}, [](auto) { for(const auto t :Map::Iterate()) { if(!IsTileType(t, MP_HOUSE)) continue;IncrementHouseAge(t);} })
const TileTypeProcs | _tile_type_town_procs
| Tile callback functions for a town.

## Detailed Description

Handling of town tiles.

Definition in file town_cmd.cpp.

## Typedef Documentation

## ◆ TownActionProc

typedef CommandCost TownActionProc(Town *t, DoCommandFlags flags)

Definition at line 3653 of file town_cmd.cpp.

## ◆ TownDrawTileProc

typedef void TownDrawTileProc(const TileInfo *ti)

Definition at line 245 of file town_cmd.cpp.

## Enumeration Type Documentation

## ◆ TownGrowthResult

enum class TownGrowthResult
| strong

Definition at line 1511 of file town_cmd.cpp.

## Function Documentation

## ◆ AddAcceptedCargo_Town()

static void AddAcceptedCargo_Town | ( | TileIndex | tile,
|  | CargoArray & | acceptance,
|  | CargoTypes & | always_accepted
| ) |  |
| static

Definition at line 847 of file town_cmd.cpp.

## ◆ AddAcceptedCargoOfHouse()

void AddAcceptedCargoOfHouse | ( | TileIndex | tile,
|  | HouseID | house,
|  | const HouseSpec * | hs,
|  | Town * | t,
|  | CargoArray & | acceptance,
|  | CargoTypes & | always_accepted
| ) |  |

Determine accepted cargo for a house.

Parameters

  | tile | Tile of house, or INVALID_TILE if not yet built.
  | house | HouseID of house.
  | hs | HouseSpec of house.
  | t | Town that house belongs to, or nullptr if not yet built.
  [out] | acceptance | CargoArray to be filled with acceptance information.
  [out] | always_accepted | Bitmask of always accepted cargo types

Definition at line 805 of file town_cmd.cpp.

References _settings_game, AcceptCargo, HouseSpec::accepts_cargo, AddAcceptedCargoSetMask(), CALLBACK_FAILED, HouseSpec::callback_mask, HouseSpec::cargo_acceptance, CargoAcceptance, CBID_HOUSE_ACCEPT_CARGO, CBID_HOUSE_CARGO_ACCEPTANCE, GameSettings::game_creation, GB(), GetCargoTranslation(), HouseSpec::grf_prop, GRFFilePropsBase::grffile, HasBit(), INVALID_TILE, GameCreationSettings::landscape, lengthof, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by GetAcceptedCargoOfHouse().

## ◆ AddAcceptedCargoSetMask()

static void AddAcceptedCargoSetMask | ( | CargoType | cargo,
|  | uint | amount,
|  | CargoArray & | acceptance,
|  | CargoTypes & | always_accepted
| ) |  |
| static

Fill cargo acceptance array and always_accepted mask, if cargo type is valid.

Parameters

  | cargo | Cargo type to add.
  | amount | Amount of cargo to add.
  [out] | acceptance | Output array containing amount of cargo accepted.
  [out] | always_accepted | Output mask of accepted cargo types.

Definition at line 789 of file town_cmd.cpp.

References IsValidCargoType(), and SetBit().

Referenced by AddAcceptedCargoOfHouse().

## ◆ AddProducedCargo_Town()

static void AddProducedCargo_Town | ( | TileIndex | tile,
|  | CargoArray & | produced
| ) |  |
| static

Definition at line 751 of file town_cmd.cpp.

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

References AdvanceSingleHouseConstruction(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), HouseSpec::building_flags, HouseSpec::Get(), GetHouseType(), and TileAddXY().

Referenced by TileLoop_Town().

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

References ChangePopulation(), HouseSpec::Get(), GetHouseConstructionTick(), GetHouseType(), IncHouseConstructionTick(), IsHouseCompleted(), IsTileType(), MarkTileDirtyByTile(), MP_HOUSE, and ResetHouseAge().

Referenced by AdvanceHouseConstruction().

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

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

Referenced by CreateRandomTown().

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

References TimerGameTick::counter, DeleteAnimatedTile(), HouseSpec::Get(), GetHouseType(), GetLiftDestination(), GetLiftPosition(), HaltLift(), LiftHasDestination(), MarkTileDirtyByTile(), NEW_HOUSE_OFFSET, RandomRange(), SetLiftDestination(), and SetLiftPosition().

## ◆ BuildTownHouse()

static void BuildTownHouse | ( | Town * | t,
|  | TileIndex | tile,
|  | const HouseSpec * | hs,
|  | HouseID | house,
|  | uint8_t | random_bits,
|  | bool | house_completed,
|  | bool | is_protected
| ) |  |
| static

Build a house at this tile.

Parameters

  t | The town the house will belong to.
  tile | The tile to try building on.
  hs | The HouseSpec of the house.
  house | The HouseID of the house.
  random_bits | The random data to be associated with the house.
  house_completed | Should the house be placed already complete, instead of under construction?
  is_protected | Whether the house is protected from the town upgrading it.

Definition at line 2775 of file town_cmd.cpp.

References _generating_world, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), HouseSpec::building_flags, BuildingIsHistorical, Town::cache, Chance16(), ChangePopulation(), HouseSpec::extra_flags, GB(), MakeTownHouse(), TownCache::num_houses, HouseSpec::population, Random, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TileDiffXY(), TOWN_HOUSE_COMPLETED, UpdateTownGrowthRate(), and UpdateTownRadius().

Referenced by CmdPlaceHouse(), and TryBuildTownHouse().

## ◆ 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().

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

References Auto, GetTileSlope(), IsBridgeAbove(), IsSteepSlope(), NoWater, RoadTypesAllowHouseHere(), and SLOPE_FLAT.

Referenced by CheckBuildHouseSameZ(), and TryBuildTownHouse().

## ◆ CanFollowRoad()

static bool CanFollowRoad | ( | TileIndex | tile,
|  | DiagDirection | dir,
|  | TownExpandModes | modes
| ) |  |
| 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 1751 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.

Referenced by GrowTownAtRoad().

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

References _settings_game, EconomySettings::allow_town_level_crossings, Auto, DiagDirToAxis(), DiagDirToRoadBits(), DRD_NONE, GameSettings::economy, GetBayRoadStopDir(), GetDriveThroughStopAxis(), GetRoadDepotDirection(), GetTownRoadType(), GetTunnelBridgeDirection(), GetTunnelBridgeTransportType(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, IsBayRoadStopTile(), IsDriveThroughStopTile(), IsRoadDepot(), IsTileType(), IsValidTile(), MP_RAILWAY, MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, NoWater, 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 _generating_town, _settings_client, Town::cache, ClientSettings::gui, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, InvalidateWindowData(), TownCache::population, GUISettings::population_in_label, Town::UpdateVirtCoord(), WC_TOWN_DIRECTORY, and WC_TOWN_VIEW.

Referenced by AdvanceSingleHouseConstruction(), BuildTownHouse(), and ClearTownHouse().

## ◆ ChangeTileOwner_Town()

static void ChangeTileOwner_Town | ( | TileIndex | ,
|  | Owner | ,
|  | Owner |
| ) |  |
| static

Definition at line 910 of file town_cmd.cpp.

## ◆ 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().

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

References _current_company, OWNER_NONE, Backup< T >::Restore(), and CommandCost::Succeeded().

Referenced by TownActionBuildStatue().

## ◆ 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().

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

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

Referenced by CheckTownBuild2x2House().

## ◆ 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().

## ◆ CheckTownBuild2House()

static bool CheckTownBuild2House | ( | TileIndex * | tile,
|  | Town * | t,
|  | int | maxz,
|  | bool | noslope,
|  | DiagDirection | second,
|  | TownExpandModes | modes
| ) |  |
| 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 2724 of file town_cmd.cpp.

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

Referenced by TryBuildTownHouse().

## ◆ CheckTownBuild2x2House()

static bool CheckTownBuild2x2House | ( | TileIndex * | tile,
|  | Town * | t,
|  | int | maxz,
|  | bool | noslope,
|  | TownExpandModes | modes
| ) |  |
| 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 2749 of file town_cmd.cpp.

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

Referenced by TryBuildTownHouse().

## ◆ 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().

## ◆ ClearMakeHouseTile()

static void ClearMakeHouseTile | ( | TileIndex | tile,
|  | Town * | t,
|  | uint8_t | counter,
|  | uint8_t | stage,
|  | HouseID | type,
|  | uint8_t | random_bits,
|  | bool | is_protected
| ) |  |
| 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.
  is_protected | Whether the house is protected from the town upgrading it.

Precondition
  The house can be built here.

Definition at line 2541 of file town_cmd.cpp.

References AddAnimatedTile(), Auto, Execute, HouseSpec::Get(), IncreaseBuildingCount(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, MakeHouseTile(), MarkTileDirtyByTile(), NoWater, and CommandCost::Succeeded().

Referenced by MakeTownHouse().

## ◆ ClearTile_Town()

static CommandCost ClearTile_Town | ( | TileIndex | tile,
|  | DoCommandFlags | 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 717 of file town_cmd.cpp.

References _cheats, _current_company, _settings_game, CommandCost::AddCost(), Auto, ChangeTownRating(), ClearTownHouse(), CommandCostWithParam(), GameSettings::difficulty, Execute, EXPENSES_CONSTRUCTION, HouseSpec::Get(), GetHouseType(), HouseSpec::GetRemovalCost(), 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, Town::ratings, HouseSpec::remove_rating_decrease, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), DifficultySettings::town_council_tolerance, and Cheat::value.

## ◆ 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().

## ◆ CmdDeleteTown()

CommandCost CmdDeleteTown | ( | DoCommandFlags | 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 3295 of file town_cmd.cpp.

References _generating_world, Airport, AT_OILRIG, Town::cache, CMD_ERROR, Execute, CommandCost::Failed(), Industry::GetByTile(), Object::GetByTile(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetNumItems(), GetTileType(), GetTownIndex(), HasTownOwnedRoad(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, IsTileType(), Map::Iterate(), SpecializedStation< Waypoint, true >::Iterate(), SpecializedStation< Station, false >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_depot_pool >::Iterate(), TrackedViewportSign::kdtree_valid, MP_HOUSE, MP_INDUSTRY, MP_OBJECT, MP_ROAD, MP_TUNNELBRIDGE, OBJECT_STATUE, Kdtree< T, TxyFunc, CoordT, DistT >::Remove(), TownCache::sign, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TestTownOwnsBridge(), Industry::town, Object::town, and Object::type.

## ◆ CmdDoTownAction()

CommandCost CmdDoTownAction | ( | DoCommandFlags | flags,
|  | TownID | town_id,
|  | TownAction | 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 3728 of file town_cmd.cpp.

References _current_company, CMD_ERROR, Execute, EXPENSES_OTHER, CommandCost::Failed(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetIfValid(), GetMaskOfTownActions(), GetTownActionCost(), SetWindowDirty(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), to_underlying(), and WC_TOWN_AUTHORITY.

## ◆ CmdExpandTown()

CommandCost CmdExpandTown | ( | DoCommandFlags | flags,
|  | TownID | town_id,
|  | uint32_t | grow_amount,
|  | TownExpandModes | modes
| ) |  |

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

References _current_company, Town::cache, CMD_ERROR, Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetIfValid(), GrowTown(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::None(), TownCache::num_houses, OWNER_DEITY, RandomRange(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), UpdateTownMaxPass(), and UpdateTownRadius().

## ◆ CmdFoundTown()

std::tuple< CommandCost, Money, TownID > CmdFoundTown | ( | DoCommandFlags | 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 2197 of file town_cmd.cpp.

References _current_company, _generating_world, _settings_game, AI::BroadcastNewEvent(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::CanAllocateItem(), CMD_ERROR, CreateRandomTown(), DoCreateTown(), GameSettings::economy, Execute, EXPENSES_OTHER, CommandCost::Failed(), EconomySettings::found_town, GameSettings::game_creation, GetAvailableMoneyForCommand(), CommandCost::GetCost(), GetEncodedString(), GetString(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, IndustryOpen, IsUniqueTownName(), lengthof, MAX_LENGTH_TOWN_NAME_CHARS, CommandCost::MultiplyCost(), Town::name, Game::NewEvent(), NUM_TLS, OWNER_DEITY, Backup< T >::Restore(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TF_CUSTOM_LAYOUT, TF_FORBIDDEN, EconomySettings::town_layout, GameCreationSettings::town_name, TownCanBePlacedHere(), TSZ_END, TSZ_LARGE, TSZ_RANDOM, UpdateNearestTownForRoadTiles(), Town::UpdateVirtCoord(), Utf8StringLength(), and VerifyTownName().

## ◆ CmdPlaceHouse()

CommandCost CmdPlaceHouse | ( | DoCommandFlags | flags,
|  | TileIndex | tile,
|  | HouseID | house,
|  | bool | is_protected,
|  | bool | replace
| ) |  |

Place an individual house.

Parameters

  flags | Type of operation.
  tile | Tile on which to place the house.
  HouseID | The HouseID of the house spec.
  is_protected | Whether the house is protected from the town upgrading it.
  replace | Whether to automatically demolish an existing house on this tile, if present.

Returns
  Empty cost or an error.

Definition at line 2947 of file town_cmd.cpp.

References _settings_game, OrthogonalTileArea::Add(), Auto, HouseSpec::building_flags, BuildTownHouse(), ClearTownHouse(), ClosestTownFromTile(), CMD_ERROR, DIAGDIR_SE, DIAGDIR_SW, GameSettings::economy, HouseSpec::enabled, Execute, HouseSpec::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetNumItems(), GetTileMaxZ(), GetTileSlope(), GetTileType(), IsBridgeAbove(), IsSteepSlope(), MP_HOUSE, NoWater, EconomySettings::place_houses, Random, SLOPE_FLAT, HouseSpec::Specs(), CommandCost::Succeeded(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TileAddByDiagDir(), and TileAddXY().

## ◆ CmdRenameTown()

CommandCost CmdRenameTown | ( | DoCommandFlags | 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 3093 of file town_cmd.cpp.

References Town::cached_name, CMD_ERROR, Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetIfValid(), InvalidateWindowData(), IsUniqueTownName(), MAX_LENGTH_TOWN_NAME_CHARS, Town::name, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), UpdateAllStationVirtCoords(), Town::UpdateVirtCoord(), Utf8StringLength(), and WC_TOWN_DIRECTORY.

## ◆ CmdTownCargoGoal()

CommandCost CmdTownCargoGoal | ( | DoCommandFlags | 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 3143 of file town_cmd.cpp.

References _current_company, CMD_ERROR, Execute, FindFirstCargoWithTownAcceptanceEffect(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetIfValid(), Town::goal, InvalidateWindowData(), OWNER_DEITY, TAE_END, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), UpdateTownGrowth(), and WC_TOWN_VIEW.

## ◆ CmdTownGrowthRate()

CommandCost CmdTownGrowthRate | ( | DoCommandFlags | 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 3194 of file town_cmd.cpp.

References _current_company, CMD_ERROR, CustomGrowth, Execute, Town::flags, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetIfValid(), Town::grow_counter, Town::growth_rate, InvalidateWindowData(), OWNER_DEITY, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), UpdateTownGrowth(), and WC_TOWN_VIEW.

## ◆ CmdTownRating()

CommandCost CmdTownRating | ( | DoCommandFlags | 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 3232 of file town_cmd.cpp.

References _current_company, Clamp(), CMD_ERROR, Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetIfValid(), InvalidateWindowData(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), OWNER_DEITY, Town::ratings, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and WC_TOWN_AUTHORITY.

## ◆ CmdTownSetText()

CommandCost CmdTownSetText | ( | DoCommandFlags | flags,
|  | TownID | town_id,
|  | const EncodedString & | 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 3172 of file town_cmd.cpp.

References _current_company, CMD_ERROR, Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetIfValid(), InvalidateWindowData(), OWNER_DEITY, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), 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 3819 of file town_cmd.cpp.

Referenced by GetNormalGrowthRate(), and UpdateTownGrowth().

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

References _current_company, _generating_world, AlignTileToGrid(), Town::cache, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::CanAllocateItem(), DoCreateTown(), Execute, FindNearestGoodCoastalTownSpot(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, INVALID_TILE, IsTileType(), MP_WATER, OWNER_TOWN, TownCache::population, RandomTile, Backup< T >::Restore(), CommandCost::Succeeded(), and TownCanBePlacedHere().

Referenced by CmdFoundTown(), and GenerateTowns().

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

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

Referenced by ClearTownHouse().

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

References _generating_town, _settings_game, Buildings, Town::cache, GameSettings::economy, Town::exclusive_counter, Town::exclusivity, FindFirstCargoWithTownAcceptanceEffect(), Town::flags, Town::fund_buildings_months, GameSettings::game_creation, Town::goal, TownNameParams::grfid, Town::grow_counter, Town::growth_rate, GrowTown(), Town::have_ratings, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, EconomySettings::initial_city_size, InitializeBuildingCounts(), Town::InitializeLayout(), Kdtree< T, TxyFunc, CoordT, DistT >::Insert(), InvalidateWindowData(), GameCreationSettings::landscape, Town::larger_town, TownCache::num_houses, TownCache::population, Random, RATING_INITIAL, Town::ratings, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), Roads, Town::show_zone, Town::statues, TAE_FOOD, TAE_WATER, Town::time_until_rebuild, TOWN_GROWTH_DESERT, Ticks::TOWN_GROWTH_TICKS, TOWN_GROWTH_WINTER, GameCreationSettings::town_name, TSZ_RANDOM, TownNameParams::type, UpdateAirportsNoise(), UpdateTownGrowthRate(), UpdateTownMaxPass(), UpdateTownRadius(), Town::UpdateVirtCoord(), WC_TOWN_DIRECTORY, and Town::xy.

Referenced by CmdFoundTown(), and CreateRandomTown().

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

References _town_draw_tile_data, AddSortableSpriteToDraw(), DrawFoundation(), DrawGroundSprite(), FOUNDATION_LEVELED, HouseSpec::Get(), GetHouseBuildingStage(), GetHouseType(), HouseSpec::grf_prop, IsInvisibilitySet(), IsTransparencySet(), NEW_HOUSE_OFFSET, PalSpriteID::pal, SLOPE_FLAT, PalSpriteID::sprite, TileInfo::tile, TileInfo::tileh, TileHash2Bit(), TO_HOUSES, Coord3D< T >::x, and Coord3D< T >::y.

## ◆ 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().

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

References CommandCost::Failed(), GetClosestWaterDistance(), INVALID_TILE, IsTileAlignedToGrid(), IsTileFlat(), IsTileType(), MP_CLEAR, and TownCanBePlacedHere().

Referenced by CreateRandomTown().

## ◆ ForAllStationsNearTown()

template<typename Func >

static void ForAllStationsNearTown | ( | Town * | t,
|  | Func | func
| ) |  |
| static

Definition at line 3748 of file town_cmd.cpp.

## ◆ 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().

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

References GB(), Random, and ROAD_NW.

Referenced by GrowTown().

## ◆ 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().

## ◆ GetClimateMaskForLandscape()

HouseZones GetClimateMaskForLandscape | ( |  | ) |

Get the HouseZones climate mask for the current landscape type.

Returns
  HouseZones climate mask.

Definition at line 2366 of file town_cmd.cpp.

References _settings_game, ClimateSubarcticAboveSnow, ClimateSubarcticBelowSnow, ClimateSubtropic, ClimateTemperate, ClimateToyland, GameSettings::game_creation, and GameCreationSettings::landscape.

Referenced by FinaliseHouseArray(), IndustryCargoesWindow::HousesCanAccept(), and HousePickerCallbacks::SetClimateMask().

## ◆ 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().

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

References CALLBACK_FAILED, HouseSpec::callback_mask, CBID_HOUSE_DRAW_FOUNDATIONS, ConvertBooleanCallback(), DrawFoundations, FlatteningFoundation(), FOUNDATION_NONE, HouseSpec::Get(), GetHouseType(), HouseSpec::grf_prop, GRFFilePropsBase::grffile, NEW_HOUSE_OFFSET, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

## ◆ 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().

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

References _settings_game, Town::cache, CountActiveStations(), GameSettings::economy, Town::fund_buildings_months, Town::larger_town, TownCache::num_houses, and EconomySettings::town_growth_rate.

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

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

Referenced by ChangeTownRating(), and CheckforTownRating().

## ◆ GetSlopePixelZ_Town()

static int GetSlopePixelZ_Town | ( | TileIndex | tile,
|  | uint | ,
|  | uint | ,
|  | bool |
| ) |  |
| static

Definition at line 305 of file town_cmd.cpp.

## ◆ GetTileDesc_Town()

static void GetTileDesc_Town | ( | TileIndex | tile,
|  | TileDesc & | td
| ) |  |
| static

Definition at line 866 of file town_cmd.cpp.

## ◆ GetTileTrackStatus_Town()

static TrackStatus GetTileTrackStatus_Town | ( | TileIndex | ,
|  | TransportType | ,
|  | uint | ,
|  | DiagDirection |
| ) |  |
| static

Definition at line 904 of file town_cmd.cpp.

## ◆ 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().

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

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

Referenced by CanFollowRoad(), GrowTown(), GrowTownAtRoad(), GrowTownWithBridge(), GrowTownWithTunnel(), IsNeighbourRoadTile(), 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 1154 of file town_cmd.cpp.

References DiagDirToRoadBits(), GetTileSlope(), Town::layout, ReverseDiagDir(), ROAD_ALL, ROAD_NE, ROAD_NONE, ROAD_NW, ROAD_SE, ROAD_SW, ROAD_X, ROAD_Y, SLOPE_E, SLOPE_N, SLOPE_NE, SLOPE_NW, SLOPE_S, SLOPE_SE, SLOPE_STEEP_E, SLOPE_STEEP_N, SLOPE_STEEP_S, SLOPE_STEEP_W, SLOPE_SW, SLOPE_W, TileIndexToTileIndexDiffC(), TL_2X2_GRID, TL_3X3_GRID, TileIndexDiffC::x, Town::xy, and TileIndexDiffC::y.

Referenced by GrowTownInTile().

## ◆ 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().

## ◆ GetTownRoadTypeFirstIntroductionDate()

static TimerGameCalendar::Date GetTownRoadTypeFirstIntroductionDate | ( |  | ) |
| static

Get the calendar date of the earliest town-buildable road type.

Returns
  introduction date of earliest road type, or INT32_MAX if none available.

Definition at line 995 of file town_cmd.cpp.

References RoadTypeInfo::flags, GetMaskForRoadTramType(), GetRoadTypeInfo(), RoadTypeInfo::introduction_date, RTT_ROAD, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and TownBuild.

Referenced by CheckTownRoadTypes().

## ◆ 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().

## ◆ GrowTown()

static bool GrowTown | ( | Town * | t,
|  | TownExpandModes | modes
| ) |  |
| 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 1897 of file town_cmd.cpp.

References _current_company, Auto, DRD_NONE, Execute, GenRandomRoadBits(), GetTownRoadBits(), GetTownRoadType(), GrowTownAtRoad(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, IsTileFlat(), IsTileType(), MP_HOUSE, NoWater, OWNER_TOWN, Backup< T >::Restore(), ROAD_NONE, TileAdd(), ToTileIndexDiff(), TownAllowedToBuildRoads(), and Town::xy.

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

## ◆ GrowTownAtRoad()

static bool GrowTownAtRoad | ( | Town * | t,
|  | TileIndex | tile,
|  | TownExpandModes | modes
| ) |  |
| 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 1793 of file town_cmd.cpp.

References Town::cache, CanFollowRoad(), DIAGDIR_END, DiagDirToRoadBits(), GetTownRoadBits(), GetTunnelBridgeDirection(), GrowTownInTile(), HasTileRoadType(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, IsRoadDepot(), IsRoadOwner(), IsTileType(), IsValidDiagDirection(), Town::layout, MP_ROAD, MP_TUNNELBRIDGE, TownCache::num_houses, OWNER_NONE, OWNER_TOWN, RandomDiagDir(), ReverseDiagDir(), ROAD_NONE, RTT_ROAD, SetRoadOwner(), SetTownIndex(), Map::Size(), TileAddByDiagDir(), TL_2X2_GRID, TL_3X3_GRID, and TL_BETTER_ROADS.

Referenced by GrowTown().

## ◆ GrowTownInTile()

static TownGrowthResult GrowTownInTile | ( | TileIndex * | tile_ptr,
|  | RoadBits | cur_rb,
|  | DiagDirection | target_dir,
|  | Town * | t1,
|  | TownExpandModes | modes
| ) |  |
| 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

Returns
  Result so far.

Definition at line 1535 of file town_cmd.cpp.

References _settings_game, EconomySettings::allow_town_level_crossings, ConstructionSettings::build_on_slopes, Chance16(), ChangeDiagDir(), CleanUpRoadBits(), GameSettings::construction, DIAGDIR_END, DIAGDIRDIFF_90LEFT, DIAGDIRDIFF_90RIGHT, DiagDirToRoadBits(), DIR_E, DIR_N, DIR_S, DIR_W, GameSettings::economy, GetOtherTunnelBridgeEnd(), GetTownRoadGridElement(), GetTunnelBridgeTransportType(), GrowTownWithBridge(), GrowTownWithExtraHouse(), GrowTownWithRoad(), GrowTownWithTunnel(), HasTileWaterGround(), IsRoadAllowedHere(), IsTileType(), IsValidTile(), Town::layout, MP_HOUSE, MP_RAILWAY, MP_TUNNELBRIDGE, RandomDiagDir(), ReverseDiagDir(), ROAD_E, ROAD_N, ROAD_NONE, ROAD_S, ROAD_W, ROAD_X, RoadTypesAllowHouseHere(), Map::Size(), TileAddByDiagDir(), TileAddByDir(), TL_2X2_GRID, TL_3X3_GRID, TL_BETTER_ROADS, TL_ORIGINAL, TownAllowedToBuildRoads(), TownCanGrowRoad(), TRANSPORT_ROAD, and TryBuildTownHouse().

Referenced by GrowTownAtRoad().

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

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

Referenced by GrowTownInTile().

## ◆ GrowTownWithExtraHouse()

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

Grows the town with an extra house.

Check if there are enough neighbour 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 1213 of file town_cmd.cpp.

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

Referenced by GrowTownInTile().

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

References Auto, DRD_NONE, Execute, GetTownRoadType(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, and NoWater.

Referenced by GrowTownInTile().

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

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

Referenced by GrowTownInTile().

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

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

Referenced by TownCanBePlacedHere().

## ◆ IsNeighbourRoadTile()

static bool IsNeighbourRoadTile | ( | 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 1043 of file town_cmd.cpp.

References ChangeDiagDir(), DIAGDIRDIFF_90LEFT, DIAGDIRDIFF_90RIGHT, DiagDirToRoadBits(), GetTownRoadBits(), IsValidTile(), ReverseDiagDir(), TileAdd(), 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 1077 of file town_cmd.cpp.

References _generating_world, _settings_game, Auto, ConstructionSettings::build_on_slopes, Chance16(), CMD_ERROR, ComplementSlope(), GameSettings::construction, DIAGDIR_NW, DIAGDIR_SE, DiagDirToAxis(), DistanceFromEdge(), DRD_NONE, Execute, CommandCost::Failed(), GetBridgeAxis(), GetFoundationSlope(), GetTileSlope(), GetTownRoadBits(), GetTownRoadType(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, IsBridgeAbove(), IsNeighbourRoadTile(), Town::layout, NoWater, ROAD_NONE, ROAD_X, ROAD_Y, SLOPE_ELEVATED, SLOPE_FLAT, SLOPE_NE, SLOPE_NW, and TL_ORIGINAL.

Referenced by GrowTownInTile().

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

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

Referenced by FindNearestGoodCoastalTownSpot().

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

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

Referenced by CmdFoundTown(), and CmdRenameTown().

## ◆ LevelTownLand()

static void LevelTownLand | ( | TileIndex | tile | ) |
| static

Definition at line 1131 of file town_cmd.cpp.

## ◆ MakeTownHouse()

static void MakeTownHouse | ( | TileIndex | tile,
|  | Town * | t,
|  | uint8_t | counter,
|  | uint8_t | stage,
|  | HouseID | type,
|  | uint8_t | random_bits,
|  | bool | is_protected
| ) |  |
| 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.
  is_protected | Whether the house is protected from the town upgrading it.

Precondition
  The house can be built here.

Definition at line 2565 of file town_cmd.cpp.

References BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), HouseSpec::building_flags, ClearMakeHouseTile(), ForAllStationsAroundTiles(), HouseSpec::Get(), Town::stations_near, and TileDiffXY().

Referenced by BuildTownHouse().

## ◆ OnTick_Town()

void OnTick_Town | ( |  | ) |

Iterate through all towns and call their tick handler.

Definition at line 940 of file town_cmd.cpp.

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

## ◆ RandomDiagDir()

static DiagDirection RandomDiagDir | ( |  | ) |
| inlinestatic

Return a random direction.

Returns
  a random direction

Definition at line 255 of file town_cmd.cpp.

References DIAGDIR_END, and RandomRange().

Referenced by GrowTownAtRoad(), and GrowTownInTile().

## ◆ RebuildTownKdtree()

void RebuildTownKdtree | ( |  | ) |

Definition at line 78 of file town_cmd.cpp.

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

References BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), Station::CatchmentCoversTown(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Town::stations_near, and TileDiffXY().

Referenced by ClearTownHouse().

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

References GetRoadTypeInfo(), INVALID_ROADTYPE, IsAnyRoadStopTile(), IsTileType(), IsValidTile(), MP_ROAD, NoHouses, and ToTileIndexDiff().

Referenced by CanBuildHouseHere(), and GrowTownInTile().

## ◆ 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().

## ◆ SumHistory()

template<>

Town::SuppliedHistory SumHistory | ( | std::span< const Town::SuppliedHistory > | history | ) |

Definition at line 4108 of file town_cmd.cpp.

## ◆ TerraformTile_Town()

static CommandCost TerraformTile_Town | ( | TileIndex | tile,
|  | DoCommandFlags | flags,
|  | int | z_new,
|  | Slope | tileh_new
| ) |  |
| static

Definition at line 4154 of file town_cmd.cpp.

## ◆ TerraformTownTile()

static bool TerraformTownTile | ( | TileIndex | tile,
|  | Slope | edges,
|  | bool | dir
| ) |  |
| static

Definition at line 1121 of file town_cmd.cpp.

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

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

Referenced by CmdDeleteTown(), and 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 602 of file town_cmd.cpp.

References _current_company, _settings_game, AddAnimatedTile(), AdvanceHouseConstruction(), EconomySettings::allow_town_roads, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), HouseSpec::building_flags, Buildings, CALLBACK_FAILED, CALLBACK_HOUSEPRODCARGO_END, HouseSpec::callback_mask, CBID_HOUSE_PRODUCE_CARGO, Chance16(), Clamp(), ClearTownHouse(), TimerGameTick::counter, GameSettings::economy, Town::flags, GB(), HouseSpec::Get(), GetCargoTranslation(), GetHouseAge(), GetHouseType(), HouseSpec::grf_prop, GRFFilePropsBase::grffile, IsGrowing, IsHouseCompleted(), IsValidCargoType(), LiftHasDestination(), HouseSpec::mail_generation, HouseSpec::minimum_life, NEW_HOUSE_OFFSET, OWNER_TOWN, HouseSpec::population, ProduceCargo, Random, Backup< T >::Restore(), Roads, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), TCGM_BITCOUNT, TCGM_ORIGINAL, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TileAddXY(), TileIndexToTileIndexDiffC(), Town::time_until_rebuild, EconomySettings::town_cargogen_mode, TownGenerateCargo(), TownGenerateCargoBinomial(), TownGenerateCargoOriginal(), TPE_MAIL, TPE_PASSENGERS, TryBuildTownHouse(), TileIndexDiffC::x, Town::xy, and TileIndexDiffC::y.

## ◆ TownActionAdvertiseLarge()

static CommandCost TownActionAdvertiseLarge | ( | Town * | t,
|  | DoCommandFlags | 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 3440 of file town_cmd.cpp.

References _current_company, Execute, ModifyStationRatingAround(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and Town::xy.

## ◆ TownActionAdvertiseMedium()

static CommandCost TownActionAdvertiseMedium | ( | Town * | t,
|  | DoCommandFlags | 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 3426 of file town_cmd.cpp.

References _current_company, Execute, ModifyStationRatingAround(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and Town::xy.

## ◆ TownActionAdvertiseSmall()

static CommandCost TownActionAdvertiseSmall | ( | Town * | t,
|  | DoCommandFlags | 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 3412 of file town_cmd.cpp.

References _current_company, Execute, ModifyStationRatingAround(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and Town::xy.

## ◆ TownActionBribe()

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

Perform the "bribe" town action.

Parameters

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

Returns
  An empty cost.

Definition at line 3616 of file town_cmd.cpp.

References _current_company, Chance16(), ChangeTownRating(), Town::exclusive_counter, Town::exclusivity, Execute, GetEncodedString(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, IsLocalCompany(), SpecializedStation< Station, false >::Iterate(), Town::ratings, SetWindowDirty(), ShowErrorMessage(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Town::unwanted, WC_TOWN_AUTHORITY, and WL_INFO.

## ◆ TownActionBuildStatue()

static CommandCost TownActionBuildStatue | ( | Town * | t,
|  | DoCommandFlags | 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.

< Best position found so far.

< Number of tiles tried.

Definition at line 3493 of file town_cmd.cpp.

References _current_company, BuildObject(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_object_pool >::CanAllocateItem(), CheckClearTile(), Execute, GetTileSlope(), INVALID_TILE, IsBridgeAbove(), IsSteepSlope(), IsTileType(), MarkTileDirtyByTile(), MP_CLEAR, MP_HOUSE, MP_TREES, OBJECT_STATUE, OWNER_NONE, Backup< T >::Restore(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), Town::statues, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and Town::xy.

## ◆ TownActionBuyRights()

static CommandCost TownActionBuyRights | ( | Town * | t,
|  | DoCommandFlags | 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 3585 of file town_cmd.cpp.

References _current_company, _settings_game, AddNewsItem(), AI::BroadcastNewEvent(), CMD_ERROR, Company, GameSettings::economy, Town::exclusive_counter, EconomySettings::exclusive_rights, Town::exclusivity, Execute, General, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), GetEncodedString(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, ModifyStationRatingAround(), Game::NewEvent(), SetWindowClassesDirty(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TimerGameEconomy::UsingWallclockUnits(), WC_STATION_VIEW, and Town::xy.

## ◆ TownActionFundBuildings()

static CommandCost TownActionFundBuildings | ( | Town * | t,
|  | DoCommandFlags | 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 3552 of file town_cmd.cpp.

References _settings_game, CMD_ERROR, GameSettings::economy, Execute, EconomySettings::fund_buildings, Town::fund_buildings_months, Town::grow_counter, Town::growth_rate, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, SetWindowDirty(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Ticks::TOWN_GROWTH_TICKS, UpdateTownGrowth(), and WC_TOWN_VIEW.

## ◆ TownActionRoadRebuild()

static CommandCost TownActionRoadRebuild | ( | Town * | t,
|  | DoCommandFlags | 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 3454 of file town_cmd.cpp.

References _current_company, _settings_game, AddNewsItem(), AI::BroadcastNewEvent(), CMD_ERROR, GameSettings::economy, Execute, EconomySettings::fund_roads, General, GetEncodedString(), GetString(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Game::NewEvent(), Normal, Town::road_build_months, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and TimerGameEconomy::UsingWallclockUnits().

## ◆ TownAllowedToBuildRoads()

static bool TownAllowedToBuildRoads | ( | TownExpandModes | modes | ) |
| inlinestatic

Check if the town is allowed to build roads.

Returns
  true If the town is allowed to build roads.

Definition at line 1505 of file town_cmd.cpp.

References Roads, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

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

## ◆ TownCanBePlacedHere()

static CommandCost TownCanBePlacedHere | ( | TileIndex | tile,
|  | bool | check_surrounding
| ) |  |
| static

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

Parameters

  tile | The tile to check.
  check_surrounding | Should we ensure surrounding tiles are free too?

Returns
  A zero cost if allowed, otherwise an error.

Definition at line 2119 of file town_cmd.cpp.

References CLEAR_ROUGH, DistanceFromEdge(), EXPENSES_OTHER, GetClearGround(), GetTileMaxZ(), GetTileType(), GetTileZ(), GetTreeGround(), IsCloseToTown(), IsTileFlat(), IsTileType(), MP_CLEAR, MP_TREES, and TREE_GROUND_ROUGH.

Referenced by CmdFoundTown(), CreateRandomTown(), and FindNearestGoodCoastalTownSpot().

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

References RoadTypeInfo::flags, GetRoadTypeInfo(), GetTownRoadType(), IsTileType(), MP_ROAD, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and TownBuild.

Referenced by GrowTownInTile().

## ◆ TownDrawHouseLift()

static void TownDrawHouseLift | ( | const TileInfo * | ti | ) |
| static

Definition at line 240 of file town_cmd.cpp.

## ◆ TownGenerateCargo()

static void TownGenerateCargo | ( | Town * | t,
|  | CargoType | cargo,
|  | 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 533 of file town_cmd.cpp.

References EconomyIsInRecession(), StationFinder::GetStations(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, ScaleByCargoScale(), and Town.

Referenced by TileLoop_Town(), TownGenerateCargoBinomial(), and TownGenerateCargoOriginal().

## ◆ TownGenerateCargoBinomial()

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

Generate cargo for a house using the binomial 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 579 of file town_cmd.cpp.

References CountBits(), Random, CargoSpec::town_production_cargoes, and TownGenerateCargo().

Referenced by TileLoop_Town().

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

References GB(), Random, CargoSpec::town_production_cargoes, and TownGenerateCargo().

Referenced by TileLoop_Town().

## ◆ TownLayoutAllows2x2HouseHere()

static bool TownLayoutAllows2x2HouseHere | ( | Town * | t,
|  | TileIndex | tile,
|  | TownExpandModes | modes
| ) |  |
| 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 2685 of file town_cmd.cpp.

References Buildings, Town::layout, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), 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,
|  | TownExpandModes | modes
| ) |  |
| 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 2652 of file town_cmd.cpp.

References Buildings, Town::layout, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TileIndexToTileIndexDiffC(), TL_2X2_GRID, TL_3X3_GRID, TownAllowedToBuildRoads(), TileIndexDiffC::x, Town::xy, and TileIndexDiffC::y.

Referenced by CheckTownBuild2House(), and TryBuildTownHouse().

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

References _settings_game, EconomySettings::allow_town_roads, Buildings, GameSettings::economy, Town::flags, Town::grow_counter, Town::growth_rate, GrowTown(), IsGrowing, Roads, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and Ticks::TOWN_GROWTH_TICKS.

Referenced by OnTick_Town().

## ◆ TryBuildTownHouse()

static bool TryBuildTownHouse | ( | Town * | t,
|  | TileIndex | tile,
|  | TownExpandModes | modes
| ) |  |
| 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 2814 of file town_cmd.cpp.

References _generating_world, _settings_game, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::All(), AllowConstruction, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), HouseSpec::building_availability, TownCache::building_counts, HouseSpec::building_flags, BuildingIsHistorical, BuildingIsProtected, BuildTownHouse(), Town::cache, CALLBACK_FAILED, HouseSpec::callback_mask, CanBuildHouseHere(), CBID_HOUSE_ALLOW_CONSTRUCTION, CheckTownBuild2House(), CheckTownBuild2x2House(), HouseSpec::class_id, ClimateSubarcticAboveSnow, ClimateSubarcticBelowSnow, ClimateSubtropic, ClimateTemperate, ClimateToyland, Convert8bitBooleanCallback(), DIAGDIR_SE, DIAGDIR_SW, HouseSpec::enabled, HouseSpec::extra_flags, Town::flags, GameSettings::game_creation, HouseSpec::Get(), GetTileMaxZ(), GetTileSlope(), GetTownRadiusGroup(), HouseSpec::grf_prop, GRFFilePropsBase::grffile, HasChurch, HasStadium, HighestSnowLine(), HouseSpec::Index(), GameCreationSettings::landscape, HouseSpec::max_year, SubstituteGRFFileProps::override_id, HouseSpec::probability, Random, RandomRange(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SLOPE_FLAT, HouseSpec::Specs(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TownLayoutAllowsHouseHere(), and TimerGameCalendar::year.

Referenced by GrowTownInTile(), GrowTownWithExtraHouse(), and TileLoop_Town().

## ◆ 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().

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

References Town::grow_counter, Town::growth_rate, RoundDivSU(), and TOWN_GROWTH_RATE_NONE.

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

References _settings_game, Town::cache, Chance16(), CountActiveStations(), CustomGrowth, GameSettings::economy, Town::flags, Town::fund_buildings_months, GetSnowLine(), GetTropicZone(), Town::goal, Town::growth_rate, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, IsGrowing, TownCache::population, Town::received, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SetWindowDirty(), TAE_END, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TileHeight(), TOWN_GROWTH_DESERT, EconomySettings::town_growth_rate, TOWN_GROWTH_RATE_NONE, TOWN_GROWTH_WINTER, TROPICZONE_DESERT, UpdateTownGrowthRate(), WC_TOWN_VIEW, and Town::xy.

Referenced by CmdTownCargoGoal(), CmdTownGrowthRate(), 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 3863 of file town_cmd.cpp.

References CustomGrowth, Town::flags, GetNormalGrowthRate(), Town::growth_rate, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, SetWindowDirty(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), UpdateTownGrowCounter(), and WC_TOWN_VIEW.

Referenced by BuildTownHouse(), DoCreateTown(), and UpdateTownGrowth().

## ◆ 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().

## ◆ UpdateTownRating()

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

Monthly callback to update town and station ratings.

Parameters

  t | The town to update.

Definition at line 3766 of file town_cmd.cpp.

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

## Variable Documentation

## ◆ _generating_town

bool _generating_town = false
| static

Set if a town is being generated.

Definition at line 88 of file town_cmd.cpp.

Referenced by ChangePopulation(), and DoCreateTown().

## ◆ _tile_type_town_procs

const TileTypeProcs _tile_type_town_procs
| extern

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,
nullptr,
}
TileLoop_Town
static void TileLoop_Town(TileIndex tile)
Tile callback function.
Definition town_cmd.cpp:602
ClearTile_Town
static CommandCost ClearTile_Town(TileIndex tile, DoCommandFlags flags)
Callback function to clear a house tile.
Definition town_cmd.cpp:717
GetFoundation_Town
static Foundation GetFoundation_Town(TileIndex tile, Slope tileh)
Get the foundation for a house.
Definition town_cmd.cpp:315
AnimateTile_Town
static void AnimateTile_Town(TileIndex tile)
Animate a tile for a town.
Definition town_cmd.cpp:339
DrawTile_Town
static void DrawTile_Town(TileInfo *ti)
Draw a house and its tile.
Definition town_cmd.cpp:264

Tile callback functions for a town.

Definition at line 55 of file landscape.cpp.

## ◆ _town_action_proc

TownActionProc* const _town_action_proc[]
| static

Initial value:
= {
TownActionAdvertiseSmall,
TownActionAdvertiseMedium,
TownActionAdvertiseLarge,
TownActionRoadRebuild,
TownActionBuildStatue,
TownActionFundBuildings,
TownActionBuyRights,
TownActionBribe
}
TownActionAdvertiseSmall
static CommandCost TownActionAdvertiseSmall(Town *t, DoCommandFlags flags)
Perform the "small advertising campaign" town action.
Definition town_cmd.cpp:3412
TownActionFundBuildings
static CommandCost TownActionFundBuildings(Town *t, DoCommandFlags flags)
Perform the "fund new buildings" town action.
Definition town_cmd.cpp:3552
TownActionBuildStatue
static CommandCost TownActionBuildStatue(Town *t, DoCommandFlags 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:3493
TownActionBribe
static CommandCost TownActionBribe(Town *t, DoCommandFlags flags)
Perform the "bribe" town action.
Definition town_cmd.cpp:3616
TownActionBuyRights
static CommandCost TownActionBuyRights(Town *t, DoCommandFlags flags)
Perform the "buy exclusive transport rights" town action.
Definition town_cmd.cpp:3585
TownActionAdvertiseMedium
static CommandCost TownActionAdvertiseMedium(Town *t, DoCommandFlags flags)
Perform the "medium advertising campaign" town action.
Definition town_cmd.cpp:3426
TownActionRoadRebuild
static CommandCost TownActionRoadRebuild(Town *t, DoCommandFlags flags)
Perform the "local road reconstruction" town action.
Definition town_cmd.cpp:3454
TownActionAdvertiseLarge
static CommandCost TownActionAdvertiseLarge(Town *t, DoCommandFlags flags)
Perform the "large advertising campaign" town action.
Definition town_cmd.cpp:3440

Definition at line 3654 of file town_cmd.cpp.

## ◆ _town_draw_tile_procs

TownDrawTileProc* const _town_draw_tile_procs[1]
| static

Initial value:
= {
TownDrawHouseLift
}

Definition at line 246 of file town_cmd.cpp.

## ◆ _town_kdtree

TownKdtree _town_kdtree {}

Definition at line 76 of file town_cmd.cpp.

## ◆ _town_rating_test

bool _town_rating_test = false
| static

If `true`, town rating is in test-mode.

Definition at line 3994 of file town_cmd.cpp.

Referenced by ChangeTownRating(), GetRating(), and SetTownRatingTestMode().

## ◆ _town_test_ratings

std::map<const Town *, int> _town_test_ratings
| static

Map of towns to modified ratings, while in town rating test-mode.

Definition at line 3995 of file town_cmd.cpp.

Referenced by ChangeTownRating(), GetRating(), and SetTownRatingTestMode().