# town_cmd.cpp File Reference

Handling of town tiles. More...

`#include "stdafx.h"`
`#include "road_internal.h"`
`#include "road_cmd.h"`
`#include "landscape.h"`
`#include "viewport_func.h"`
`#include "command_func.h"`
`#include "industry.h"`
`#include "station_base.h"`
`#include "company_base.h"`
`#include "news_func.h"`
`#include "gui.h"`
`#include "unmovable_map.h"`
`#include "variables.h"`
`#include "genworld.h"`
`#include "newgrf.h"`
`#include "newgrf_house.h"`
`#include "newgrf_commons.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 "functions.h"`
`#include "animated_tile_func.h"`
`#include "date_func.h"`
`#include "subsidy_func.h"`
`#include "core/smallmap_type.hpp"`
`#include "core/pool_func.hpp"`
`#include "town.h"`
`#include "townname_func.h"`
`#include "townname_type.h"`
`#include "core/random_func.hpp"`
`#include "table/strings.h"`
`#include "table/town_land.h"`

Go to the source code of this file.

## Data Structures
struct | SpotData
| Used as the user_data for FindFurthestFromWater. More...
## Typedefs
typedef void | TownDrawTileProc (const TileInfo *ti)
typedef void | TownActionProc (Town *t)
## Enumerations
enum | TownGrowthResult { GROWTH_SUCCEED = -1, GROWTH_SEARCH_STOPPED = 0 }
## Functions
static bool | BuildTownHouse (Town *t, TileIndex tile)
| Tries to build a house at this tile.
static Town * | CreateRandomTown (uint attempts, uint32 townnameparts, TownSize size, bool city, TownLayout layout)
static void | TownDrawHouseLift (const TileInfo *ti)
static DiagDirection | RandomDiagDir ()
| Return a random direction.
static void | DrawTile_Town (TileInfo *ti)
| House Tile drawing handler.
static uint | GetSlopeZ_Town (TileIndex tile, uint x, uint y)
static Foundation | GetFoundation_Town (TileIndex tile, Slope tileh)
| Tile callback routine.
static void | AnimateTile_Town (TileIndex tile)
| Animate a tile for a town Only certain houses can be animated The newhouses animation superseeds regular ones.
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.
static void | ChangePopulation (Town *t, int mod)
| Change the towns population.
uint32 | GetWorldPopulation ()
| Determines the world population Basically, count population of all towns, one by one.
static void | MakeSingleHouseBigger (TileIndex tile)
| Helper function for house completion stages progression.
static void | MakeTownHouseBigger (TileIndex tile)
| Make the house advance in its construction stages until completion.
static void | TileLoop_Town (TileIndex tile)
| Tile callback function.
static CommandCost | ClearTile_Town (TileIndex tile, DoCommandFlag flags)
static void | AddProducedCargo_Town (TileIndex tile, CargoArray &produced)
static void | AddAcceptedCargoSetMask (CargoID cargo, uint amount, CargoArray &acceptance, uint32 *always_accepted)
static void | AddAcceptedCargo_Town (TileIndex tile, CargoArray &acceptance, uint32 *always_accepted)
static void | GetTileDesc_Town (TileIndex tile, TileDesc *td)
static TrackStatus | GetTileTrackStatus_Town (TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
static void | ChangeTileOwner_Town (TileIndex tile, Owner old_owner, Owner new_owner)
static bool | GrowTown (Town *t)
| Grow the town.
static void | TownTickHandler (Town *t)
void | OnTick_Town ()
static RoadBits | GetTownRoadBits (TileIndex tile)
| Return the RoadBits of a tile.
static bool | IsNeighborRoadTile (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, int edges, int 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)
| 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 | GrowTownWithBridge (const Town *t, const TileIndex tile, const DiagDirection bridge_dir)
| Grows the town with a bridge.
static void | GrowTownInTile (TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection target_dir, Town *t1)
| Grows the given town.
static int | GrowTownAtRoad (Town *t, TileIndex tile)
| Returns "growth" if a house was built, or no if the build failed.
static RoadBits | GenRandomRoadBits ()
| Generate a random road block.
void | UpdateTownRadius (Town *t)
void | UpdateTownMaxPass (Town *t)
static void | DoCreateTown (Town *t, TileIndex tile, uint32 townnameparts, TownSize size, bool city, TownLayout layout, bool manual)
| Does the actual town creation.
static CommandCost | TownCanBePlacedHere (TileIndex tile)
| Checks if it's possible to place a town at given tile.
static bool | IsUniqueTownName (const char *name)
| Verifies this custom name is unique.
CommandCost | CmdFoundTown (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *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 bool | FindFurthestFromWater (TileIndex tile, void *user_data)
| CircularTileSearch callback; finds the tile furthest from any water.
static bool | FindNearestEmptyLand (TileIndex tile, void *user_data)
| CircularTileSearch callback; finds the nearest land tile.
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.
bool | GenerateTowns (TownLayout layout)
| This function will generate a certain amount of towns, with a certain layout It can be called from the scenario editor (i.e.
HouseZonesBits | 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, byte counter, byte stage, HouseID type, byte random_bits)
| Clears tile and builds a house or house part.
static void | MakeTownHouse (TileIndex t, Town *town, byte counter, byte stage, HouseID type, byte random_bits)
| Write house information into the map.
static bool | CanBuildHouseHere (TileIndex tile, TownID town, bool noslope)
| Checks if a house can be built here.
static bool | CheckBuildHouseSameZ (TileIndex tile, TownID town, uint z, bool noslope)
| Checks if a house can be built at this tile, must have the same max z as parameter.
static bool | CheckFree2x2Area (TileIndex tile, TownID town, uint z, bool noslope)
| Checks if a house of size 2x2 can be built at this tile.
static bool | TownLayoutAllowsHouseHere (Town *t, TileIndex tile)
| Checks if current town layout allows building here.
static bool | TownLayoutAllows2x2HouseHere (Town *t, TileIndex tile)
| Checks if current town layout allows 2x2 building here.
static bool | CheckTownBuild2House (TileIndex *tile, Town *t, uint maxz, bool noslope, DiagDirection second)
| Checks if 1x2 or 2x1 building is allowed here, also takes into account current town layout Also, tests both building positions that occupy this tile.
static bool | CheckTownBuild2x2House (TileIndex *tile, Town *t, uint maxz, bool noslope)
| Checks if 2x2 building is allowed here, also takes into account current town layout Also, tests all four building positions that occupy this tile.
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)
CommandCost | CmdRenameTown (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Rename a town (server-only).
void | ExpandTown (Town *t)
| Called from GUI.
static void | TownActionAdvertiseSmall (Town *t)
static void | TownActionAdvertiseMedium (Town *t)
static void | TownActionAdvertiseLarge (Town *t)
static void | TownActionRoadRebuild (Town *t)
static bool | DoBuildStatueOfCompany (TileIndex tile, TownID town_id)
static bool | SearchTileForStatue (TileIndex tile, void *user_data)
| Search callback function for TownActionBuildStatue.
static void | TownActionBuildStatue (Town *t)
| Perform a 9x9 tiles circular search from the center of the town in order to find a free tile to place a statue.
static void | TownActionFundBuildings (Town *t)
static void | TownActionBuyRights (Town *t)
static void | TownActionBribe (Town *t)
uint | GetMaskOfTownActions (int *nump, CompanyID cid, const Town *t)
| Get a list of available actions to do at a town.
CommandCost | CmdDoTownAction (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Do a town action.
static void | UpdateTownGrowRate (Town *t)
static void | UpdateTownAmounts (Town *t)
static void | UpdateTownUnwanted (Town *t)
bool | CheckIfAuthorityAllowsNewStation (TileIndex tile, DoCommandFlag flags)
| Checks whether the local authority allows construction of a new station (rail, road, airport, dock) on the given tile.
Town * | CalcClosestTownFromTile (TileIndex tile, uint threshold)
Town * | ClosestTownFromTile (TileIndex tile, uint threshold)
void | SetTownRatingTestMode (bool mode)
static int | GetRating (const Town *t)
void | ChangeTownRating (Town *t, int add, int max, DoCommandFlag flags)
| Changes town rating of the current company.
bool | CheckforTownRating (DoCommandFlag flags, Town *t, TownRatingCheckType type)
void | TownsMonthlyLoop ()
void | TownsYearlyLoop ()
void | InitializeTowns ()
static CommandCost | TerraformTile_Town (TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
void | ResetHouses ()
## Variables
static Town * | _cleared_town
static int | _cleared_town_rating
TownID | _new_town_id
TownPool | _town_pool ("Town")
static int | _grow_town_result
static TownDrawTileProc *const | _town_draw_tile_procs [1]
static const byte | _num_initial_towns [4] = {5, 11, 23, 46}
const byte | _town_action_costs [TACT_COUNT]
| Factor in the cost of each town action.
static TownActionProc *const | _town_action_proc []
static bool | _town_rating_test = false
static SmallMap< const Town *, int, 4 > | _town_test_ratings
const TileTypeProcs | _tile_type_town_procs
| Tile callback functions for a town.
HouseSpec | _house_specs [HOUSE_MAX]

## Detailed Description

Handling of town tiles.

Definition in file town_cmd.cpp.

## Function Documentation

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 | which town layout algo is in effect

Returns:
  the adjusted tile

Definition at line 1622 of file town_cmd.cpp.

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

static void AnimateTile_Town | ( | TileIndex | tile | ) | `[static]`

Animate a tile for a town Only certain houses can be animated The newhouses animation superseeds regular ones.

Parameters:

  | tile | TileIndex of the house to animate

Definition at line 275 of file town_cmd.cpp.

References DeleteAnimatedTile(), GetHouseType(), GetLiftDestination(), GetLiftPosition(), HaltLift(), LiftHasDestination(), MarkTileDirtyByTile(), SetLiftDestination(), and SetLiftPosition().

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

Tries to build a house at this tile.

Parameters:

  | t | town the house will belong to
  | tile | where the house will be built

Returns:
  false iff no house can be built at this tile

Definition at line 2061 of file town_cmd.cpp.

References _cur_year, _settings_game, HouseSpec::building_availability, HouseSpec::building_flags, BUILDING_IS_HISTORICAL, CALLBACK_FAILED, HouseSpec::callback_mask, CanBuildHouseHere(), CBID_HOUSE_ALLOW_CONSTRUCTION, CBM_HOUSE_ALLOW_CONSTRUCTION, Chance16(), ChangePopulation(), CheckTownBuild2House(), CheckTownBuild2x2House(), HouseSpec::class_id, DIAGDIR_SE, DIAGDIR_SW, HouseSpec::enabled, HouseSpec::extra_flags, GameSettings::game_creation, GB(), GetTileMaxZ(), GetTileSlope(), GetTownRadiusGroup(), GRFLoadedFeatures::has_newhouses, HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, GameCreationSettings::landscape, MakeTownHouse(), HouseSpec::max_year, HouseSpec::override, HouseSpec::population, HouseSpec::probability, SetBit(), SLOPE_FLAT, GameCreationSettings::snow_line, TOWN_HAS_CHURCH, TOWN_HAS_STADIUM, TOWN_HOUSE_COMPLETED, and TownLayoutAllowsHouseHere().

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

static bool CanBuildHouseHere | ( | TileIndex | tile,
|  | TownID | town,
|  | bool | noslope |
| ) |  |  | `[inline, static]`

Checks if a house can be built here.

Important is slope, bridge above and ability to clear the land.

Parameters:

  | tile | tile to check
  | town | town that is checking
  | noslope | are slopes (foundations) allowed?

Returns:
  true iff house can be built here

Definition at line 1879 of file town_cmd.cpp.

References CMD_LANDSCAPE_CLEAR, DC_NO_WATER, DoCommand(), GetTileSlope(), GetTownIndex(), IsBridgeAbove(), IsSteepSlope(), IsTileType(), MayHaveBridgeAbove(), MP_HOUSE, SLOPE_FLAT, and CommandCost::Succeeded().

Referenced by BuildTownHouse(), and CheckBuildHouseSameZ().

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

Change the towns population.

Parameters:

  | t | Town which polulation has changed
  | mod | polulation change (can be positive or negative)

Definition at line 366 of file town_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, InvalidateWindowData(), SetWindowDirty(), and Town::UpdateVirtCoord().

Referenced by BuildTownHouse(), and MakeSingleHouseBigger().

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

Changes town rating of the current company.

Parameters:

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

Definition at line 2769 of file town_cmd.cpp.

References DC_NO_MODIFY_TOWN_RATING, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), Cheats::magic_bulldozer, SetBit(), SetWindowDirty(), and Cheat::value.

Referenced by CheckAllowRemoveRoad(), and CmdPlantTree().

static bool CheckBuildHouseSameZ | ( | TileIndex | tile,
|  | TownID | town,
|  | uint | z,
|  | bool | noslope |
| ) |  |  | `[inline, static]`

Checks if a house can be built at this tile, must have the same max z as parameter.

Parameters:

  | tile | tile to check
  | town | town that is checking
  | z | max z of this tile so more parts of a house are at the same height (with foundation)
  | noslope | are slopes (foundations) allowed?

Returns:
  true iff house can be built here

See also:
  CanBuildHouseHere()

Definition at line 1905 of file town_cmd.cpp.

References CanBuildHouseHere(), and GetTileMaxZ().

Referenced by CheckFree2x2Area(), and CheckTownBuild2House().

static bool CheckFree2x2Area | ( | TileIndex | tile,
|  | TownID | town,
|  | uint | z,
|  | bool | noslope |
| ) |  |  | `[static]`

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

Parameters:

  | tile | tile, N corner
  | town | town that is checking
  | z | maximum tile z so all tile have the same max z
  | noslope | are slopes (foundations) allowed?

Returns:
  true iff house can be built

See also:
  CheckBuildHouseSameZ()

Definition at line 1925 of file town_cmd.cpp.

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

Referenced by CheckTownBuild2x2House().

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

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

Parameters:

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

Definition at line 2666 of file town_cmd.cpp.

References _settings_game, DC_NO_TEST_TOWN_RATING, EconomySettings::dist_local_authority, GameSettings::economy, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), and SetDParam().

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

static bool CheckTownBuild2House | ( | TileIndex * | tile,
|  | Town * | t,
|  | uint | maxz,
|  | bool | noslope,
|  | DiagDirection | second |
| ) |  |  | `[static]`

Checks if 1x2 or 2x1 building is allowed here, also takes into account current town layout Also, tests both building positions that occupy this tile.

Parameters:

  | tile | tile where the building should be built
  | t | town
  | maxz | all tiles should have the same height
  | noslope | are slopes forbidden?
  | second | diagdir from first tile to second tile

Definition at line 2013 of file town_cmd.cpp.

References CheckBuildHouseSameZ(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, ReverseDiagDir(), TileOffsByDiagDir(), and TownLayoutAllowsHouseHere().

Referenced by BuildTownHouse().

static bool CheckTownBuild2x2House | ( | TileIndex * | tile,
|  | Town * | t,
|  | uint | maxz,
|  | bool | noslope |
| ) |  |  | `[static]`

Checks if 2x2 building is allowed here, also takes into account current town layout Also, tests all four building positions that occupy this tile.

Parameters:

  | tile | tile where the building should be built
  | t | town
  | maxz | all tiles should have the same height
  | noslope | are slopes forbidden?

Definition at line 2038 of file town_cmd.cpp.

References CheckFree2x2Area(), DIAGDIR_END, DIAGDIR_SE, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, ReverseDiagDir(), TileOffsByDiagDir(), and TownLayoutAllows2x2HouseHere().

Referenced by BuildTownHouse().

static void ClearMakeHouseTile | ( | TileIndex | tile,
|  | Town * | t,
|  | byte | counter,
|  | byte | stage,
|  | HouseID | type,
|  | byte | random_bits |
| ) |  |  | `[inline, static]`

Clears tile and builds a house or house part.

Parameters:

  | tile | tile index
  | t | The town to clear the house for
  | counter | of construction step
  | stage | of construction (used for drawing)
  | type | of house. Index into house specs array
  | random_bits | required for newgrf houses

Precondition:
  house can be built here

Definition at line 1836 of file town_cmd.cpp.

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

Referenced by MakeTownHouse().

CommandCost CmdDoTownAction | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

Do a town action.

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

Parameters:

  | tile | unused
  | flags | type of operation
  | p1 | town to do the action at
  | p2 | action to perform,

See also:
  _town_action_proc for the list of available actions

Parameters:

  | text | unused

Returns:
  the cost of this operation or an error

Definition at line 2538 of file town_cmd.cpp.

References CMD_ERROR, DC_EXEC, EXPENSES_OTHER, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_town_pool >::GetIfValid(), GetMaskOfTownActions(), HasBit(), lengthof, and SetWindowDirty().

CommandCost CmdFoundTown | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

Create a new town.

Parameters:

  | tile | coordinates where town is built
  | flags | type of operation
  | p1 | 0..1 size of the town (

See also:
  TownSize) 2 true iff it should be a city 3..5 town road layout (
  TownLayout) 6 use random location (randomize `tile` )

Parameters:

  | p2 | town name parts
  | text | unused

Returns:
  the cost of this operation or an error

Definition at line 1519 of file town_cmd.cpp.

References _settings_game, AddNewsItem(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_town_pool >::CanAllocateItem(), CMD_ERROR, DC_EXEC, DoCreateTown(), GameSettings::economy, EXPENSES_OTHER, CommandCost::Failed(), EconomySettings::found_town, GameSettings::game_creation, GB(), GetAvailableMoneyForCommand(), CommandCost::GetCost(), HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, IsUniqueTownName(), lastof, lengthof, MAX_LENGTH_COMPANY_NAME_BYTES, MAX_LENGTH_TOWN_NAME_BYTES, CommandCost::MultiplyCost(), NR_NONE, NR_TILE, NS_INDUSTRY_OPEN, return_cmd_error, SetDParam(), SetDParamStr(), StrEmpty(), TF_CUSTOM_LAYOUT, TF_FORBIDDEN, TL_RANDOM, EconomySettings::town_layout, GameCreationSettings::town_name, TownCanBePlacedHere(), TS_LARGE, TS_RANDOM, UpdateNearestTownForRoadTiles(), Town::UpdateVirtCoord(), and VerifyTownName().

CommandCost CmdRenameTown | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

Rename a town (server-only).

Parameters:

  | tile | unused
  | flags | type of operation
  | p1 | town ID to rename
  | p2 | unused
  | 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 2282 of file town_cmd.cpp.

References CMD_ERROR, DC_EXEC, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_town_pool >::GetIfValid(), InvalidateWindowData(), IsUniqueTownName(), MAX_LENGTH_TOWN_NAME_BYTES, return_cmd_error, StrEmpty(), UpdateAllStationVirtCoords(), and Town::UpdateVirtCoord().

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

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

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

Does the actual town creation.

Parameters:

  | t | The town
  | tile | Where to put it
  | townnameparts | The town name
  | size | Parameter for size determination
  | city | whether to build a city or town
  | layout | the (road) layout of the town
  | manual | was the town placed manually?

Definition at line 1394 of file town_cmd.cpp.

References _settings_game, GameSettings::economy, Town::exclusive_counter, Town::exclusivity, GameSettings::game_creation, GrowTown(), EconomySettings::initial_city_size, Town::InitializeLayout(), INVALID_COMPANY, InvalidateWindowData(), MAX_COMPANIES, RATING_INITIAL, GameCreationSettings::town_name, TS_RANDOM, UpdateAirportsNoise(), and Town::UpdateVirtCoord().

Referenced by CmdFoundTown().

static void DrawTile_Town | ( | TileInfo * | ti | ) | `[static]`

House Tile drawing handler.

Part of the tile loop process

Parameters:

  | ti | TileInfo of the tile to draw

Definition at line 196 of file town_cmd.cpp.

References _town_draw_tile_data, AddSortableSpriteToDraw(), DrawFoundation(), DrawGroundSprite(), FOUNDATION_LEVELED, GetHouseBuildingStage(), GetHouseType(), IsInvisibilitySet(), IsTransparencySet(), PalSpriteID::pal, SLOPE_FLAT, PalSpriteID::sprite, HouseSpec::substitute_id, TileInfo::tile, TileInfo::tileh, TileHash2Bit(), TO_HOUSES, TileInfo::x, TileInfo::y, and TileInfo::z.

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

CircularTileSearch callback; finds the tile furthest from any water.

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

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

Parameters:

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

Returns:
  always false

Definition at line 1674 of file town_cmd.cpp.

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

Referenced by FindNearestGoodCoastalTownSpot().

static bool FindNearestEmptyLand | ( | TileIndex | tile,
|  | void * | user_data |
| ) |  |  | `[static]`

CircularTileSearch callback; finds the nearest land tile.

Parameters:

  | tile | Start looking from this tile
  | user_data | not used

Definition at line 1696 of file town_cmd.cpp.

References IsTileType(), and MP_CLEAR.

Referenced by 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 retards 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 1713 of file town_cmd.cpp.

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

bool GenerateTowns | ( | TownLayout | layout | ) |

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

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

Parameters:

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

Returns:
  true if towns have been successfully created

Definition at line 1767 of file town_cmd.cpp.

References _settings_game, Chance16(), GameCreationSettings::custom_town_number, CUSTOM_TOWN_NUMBER_DIFFICULTY, GameSettings::difficulty, GameSettings::economy, GameSettings::game_creation, GenerateTownName(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_town_pool >::GetNumItems(), GWP_TOWN, IncreaseGeneratingWorldProgress(), EconomySettings::larger_towns, DifficultySettings::number_towns, ScaleByMapSize(), SetGeneratingWorldProgress(), and TS_RANDOM.

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

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

References GB(), and ROAD_NW.

Referenced by GrowTown().

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

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

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

Parameters:

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

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

Definition at line 2221 of file town_cmd.cpp.

References TileDiffXY().

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

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

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

Parameters:

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

Returns:
  bitmasked value of enabled actions

Definition at line 2489 of file town_cmd.cpp.

References _settings_game, EconomySettings::bribe, COMPANY_SPECTATOR, GameSettings::economy, EconomySettings::exclusive_rights, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), HasBit(), lengthof, TACT_BRIBE, TACT_BUILD_STATUE, TACT_BUY_RIGHTS, TACT_NONE, and Town::unwanted.

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

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

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

Parameters:

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

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

Definition at line 1812 of file town_cmd.cpp.

References DistanceSquare().

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

static RoadBits GetTownRoadBits | ( | TileIndex | tile | ) | `[static]`

Return the RoadBits of a tile.

Note:
  There are many other functions doing things like that.
  Needs to be checked for needlessness.

Parameters:

  | tile | The tile we want to analyse

Returns:
  The roadbits of the given tile

Definition at line 720 of file town_cmd.cpp.

References GetAnyRoadBits(), IsStandardRoadStopTile(), ROAD_NONE, and ROADTYPE_ROAD.

Referenced by GrowTown(), GrowTownAtRoad(), GrowTownWithBridge(), IsNeighborRoadTile(), and IsRoadAllowedHere().

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

Generate the RoadBits of a grid tile.

Parameters:

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

Returns:
  the RoadBit of the current tile regarding the selected town layout

Definition at line 848 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, and TileIndexDiffC::y.

Referenced by GrowTownInTile().

uint32 GetWorldPopulation | ( |  | ) |

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

Returns:
  uint32 the calculated population of the world

Definition at line 380 of file town_cmd.cpp.

Referenced by TownDirectoryWindow::SetStringParameters().

static bool GrowTown | ( | Town * | t | ) | `[static]`

Grow the town.

Parameters:

  | t | town to grow

Returns:
  true iff a house was built

Definition at line 1278 of file town_cmd.cpp.

References _settings_game, EconomySettings::allow_town_roads, CMD_BUILD_ROAD, CMD_LANDSCAPE_CLEAR, DC_EXEC, DC_NO_WATER, DoCommand(), GameSettings::economy, endof, GenRandomRoadBits(), GetTileSlope(), GetTownRoadBits(), GrowTownAtRoad(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, IsTileType(), MP_HOUSE, OWNER_TOWN, ROAD_NONE, SLOPE_FLAT, CommandCost::Succeeded(), TILE_ADD, and ToTileIndexDiff().

Referenced by DoCreateTown(), and ExpandTown().

static int GrowTownAtRoad | ( | Town * | t,
|  | TileIndex | tile |
| ) |  |  | `[static]`

Returns "growth" if a house was built, or no if the build failed.

Parameters:

  | t | town to inquiry
  | tile | to inquiry

Returns:
  something other than zero(0)if town expansion was possible

Definition at line 1196 of file town_cmd.cpp.

References DIAGDIR_END, DiagDirToRoadBits(), GetTownRoadBits(), GrowTownInTile(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, IsTileType(), Town::layout, MapSize(), MP_ROAD, OWNER_NONE, OWNER_TOWN, RandomDiagDir(), ReverseDiagDir(), ROAD_NONE, ROADTYPE_ROAD, SetTownIndex(), TileAddByDiagDir(), TL_2X2_GRID, TL_3X3_GRID, and TL_BETTER_ROADS.

Referenced by GrowTown().

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

Grows the given town.

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

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

Parameters:

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

Definition at line 1030 of file town_cmd.cpp.

References _settings_game, EconomySettings::allow_town_roads, ConstructionSettings::build_on_slopes, BuildTownHouse(), Chance16(), ChangeDiagDir(), CleanUpRoadBits(), GameSettings::construction, DIAGDIR_END, DIAGDIRDIFF_90LEFT, DIAGDIRDIFF_90RIGHT, DiagDirToRoadBits(), GameSettings::economy, GetOtherTunnelBridgeEnd(), GetTownRoadGridElement(), GetTunnelBridgeTransportType(), GrowTownWithBridge(), GrowTownWithExtraHouse(), GrowTownWithRoad(), IsRoadAllowedHere(), IsTileType(), IsValidTile(), Town::layout, MapSize(), MP_HOUSE, MP_TUNNELBRIDGE, RandomDiagDir(), ReverseDiagDir(), ROAD_NONE, TileAddByDiagDir(), TL_2X2_GRID, TL_3X3_GRID, TL_BETTER_ROADS, TL_ORIGINAL, and TRANSPORT_ROAD.

Referenced by GrowTownAtRoad().

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

References CMD_BUILD_BRIDGE, DC_EXEC, DIAGDIR_END, DiagDirToRoadBits(), DoCommand(), GetTileSlope(), GetTownRoadBits(), InclinedSlope(), ReverseDiagDir(), ROADTYPES_ROAD, SLOPE_FLAT, TileAddByDiagDir(), TileOffsByDiagDir(), TileX(), TileY(), and TRANSPORT_ROAD.

Referenced by GrowTownInTile().

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

Grows the town with an extra house.

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

Parameters:

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

Returns:
  true if an extra house has been added

Definition at line 907 of file town_cmd.cpp.

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

Referenced by GrowTownInTile().

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 else false

Definition at line 949 of file town_cmd.cpp.

References CMD_BUILD_ROAD, DC_EXEC, DC_NO_WATER, DoCommand(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, and CommandCost::Succeeded().

Referenced by GrowTownInTile().

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 | maximum distance to be accepted

Returns:
  true if the tile correspond to the distance criteria

Definition at line 326 of file town_cmd.cpp.

References DistanceManhattan().

Referenced by TownCanBePlacedHere().

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

Check for parallel road inside a given distance.

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

Parameters:

  | tile | curent tile
  | dir | target direction
  | dist_multi | distance multiplyer

Returns:
  true if there is a parallel road

Definition at line 737 of file town_cmd.cpp.

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

Referenced by 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 else false

Definition at line 771 of file town_cmd.cpp.

References _settings_game, ConstructionSettings::build_on_slopes, Chance16(), CMD_BUILD_ROAD, CMD_ERROR, CMD_LANDSCAPE_CLEAR, CMD_TERRAFORM_LAND, ComplementSlope(), GameSettings::construction, DC_EXEC, DC_NO_WATER, DIAGDIR_NW, DIAGDIR_SE, DistanceFromEdge(), DoCommand(), CommandCost::Failed(), GetFoundationSlope(), GetTileSlope(), GetTownRoadBits(), IsNeighborRoadTile(), Town::layout, ROAD_NONE, ROAD_X, ROAD_Y, SLOPE_ELEVATED, SLOPE_FLAT, SLOPE_NE, SLOPE_NW, and TL_ORIGINAL.

Referenced by GrowTownInTile().

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 | which town layout algo is in effect

Returns:
  true if the tile is in the correct location

Definition at line 1640 of file town_cmd.cpp.

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

Referenced by FindFurthestFromWater().

static bool IsUniqueTownName | ( | const char * | name | ) | `[static]`

Verifies this custom name is unique.

Only custom names are checked.

Parameters:

  | name | name to check

Returns:
  is this name unique?

Definition at line 1496 of file town_cmd.cpp.

Referenced by CmdFoundTown(), and CmdRenameTown().

static void MakeSingleHouseBigger | ( | TileIndex | tile | ) | `[static]`

Helper function for house completion stages progression.

Parameters:

  | tile | TileIndex of the house (or parts of it) to "grow"

Definition at line 393 of file town_cmd.cpp.

References CALLBACK_FAILED, HouseSpec::callback_mask, CBID_HOUSE_CONSTRUCTION_STATE_CHANGE, CBM_HOUSE_CONSTRUCTION_STATE_CHANGE, ChangePopulation(), GetHouseConstructionTick(), GetHouseType(), HouseSpec::grffile, HasBit(), IncHouseConstructionTick(), IsHouseCompleted(), IsTileType(), LiftHasDestination(), MarkTileDirtyByTile(), MP_HOUSE, HouseSpec::population, and ResetHouseAge().

Referenced by MakeTownHouseBigger().

static void MakeTownHouse | ( | TileIndex | t,
|  | Town * | town,
|  | byte | counter,
|  | byte | stage,
|  | HouseID | type,
|  | byte | random_bits |
| ) |  |  | `[static]`

Write house information into the map.

For houses > 1 tile, all tiles are marked.

Parameters:

  | t | tile index
  | town | The town related to this house
  | counter | of construction step
  | stage | of construction (used for drawing)
  | type | of house. Index into house specs array
  | random_bits | required for newgrf houses

Precondition:
  house can be built here

Definition at line 1860 of file town_cmd.cpp.

References HouseSpec::building_flags, ClearMakeHouseTile(), and TileDiffXY().

Referenced by BuildTownHouse().

static void MakeTownHouseBigger | ( | TileIndex | tile | ) | `[static]`

Make the house advance in its construction stages until completion.

Parameters:

  | tile | TileIndex of house

Definition at line 424 of file town_cmd.cpp.

References HouseSpec::building_flags, GetHouseType(), MakeSingleHouseBigger(), and TILE_ADDXY.

Referenced by TileLoop_Town().

static DiagDirection RandomDiagDir | ( |  | ) | `[inline, static]`

Return a random direction.

Returns:
  a random direction

Definition at line 186 of file town_cmd.cpp.

Referenced by GrowTownAtRoad(), and GrowTownInTile().

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

Search callback function for TownActionBuildStatue.

Parameters:

  | tile | on which to perform the search
  | user_data | The town_id for which we want a statue

Returns:
  the result of the test

Definition at line 2399 of file town_cmd.cpp.

Referenced by TownActionBuildStatue().

static void TileLoop_Town | ( | TileIndex | tile | ) | `[static]`

Tile callback function.

Periodic tic handler for houses and town

Parameters:

  | tile | been asked to do its stuff

Definition at line 439 of file town_cmd.cpp.

References AddAnimatedTile(), HouseSpec::building_flags, BuildTownHouse(), CALLBACK_FAILED, CALLBACK_HOUSEPRODCARGO_END, HouseSpec::callback_mask, CBID_HOUSE_PRODUCE_CARGO, CBM_HOUSE_PRODUCE_CARGO, Chance16(), CT_INVALID, Economy::fluct, GB(), CargoSpec::Get(), GetHouseAge(), GetHouseType(), StationFinder::GetStations(), HouseSpec::grffile, HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, IsHouseCompleted(), LiftHasDestination(), HouseSpec::mail_generation, MakeTownHouseBigger(), HouseSpec::minimum_life, OWNER_NONE, OWNER_TOWN, HouseSpec::population, ST_TOWN, TE_MAIL, TE_PASSENGERS, and TOWN_IS_FUNDED.

static void TownActionBuildStatue | ( | Town * | t | ) | `[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

Definition at line 2410 of file town_cmd.cpp.

References CircularTileSearch(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, SearchTileForStatue(), and SetBit().

static CommandCost TownCanBePlacedHere | ( | TileIndex | tile | ) | `[static]`

Checks if it's possible to place a town at given tile.

Parameters:

  | tile | tile to check

Returns:
  error value or zero cost

Definition at line 1471 of file town_cmd.cpp.

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

Referenced by CmdFoundTown().

static bool TownLayoutAllows2x2HouseHere | ( | Town * | t,
|  | TileIndex | tile |
| ) |  |  | `[inline, static]`

Checks if current town layout allows 2x2 building here.

Parameters:

  | t | town
  | tile | tile to check

Returns:
  true iff town layout allows 2x2 building here

Note:
  see layouts

Definition at line 1977 of file town_cmd.cpp.

References _settings_game, EconomySettings::allow_town_roads, GameSettings::economy, Town::layout, MapSize(), TileX(), TileY(), TL_2X2_GRID, and TL_3X3_GRID.

Referenced by CheckTownBuild2x2House().

static bool TownLayoutAllowsHouseHere | ( | Town * | t,
|  | TileIndex | tile |
| ) |  |  | `[inline, static]`

Checks if current town layout allows building here.

Parameters:

  | t | town
  | tile | tile to check

Returns:
  true iff town layout allows building here

Note:
  see layouts

Definition at line 1946 of file town_cmd.cpp.

References _settings_game, EconomySettings::allow_town_roads, GameSettings::economy, Town::layout, TileIndexToTileIndexDiffC(), TL_2X2_GRID, TL_3X3_GRID, TileIndexDiffC::x, and TileIndexDiffC::y.

Referenced by BuildTownHouse(), and CheckTownBuild2House().

void UpdateAllTownVirtCoords | ( |  | ) |

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

Definition at line 352 of file town_cmd.cpp.

References Town::UpdateVirtCoord().

Referenced by UpdateAllVirtCoords().

static void UpdateTownGrowRate | ( | Town * | t | ) | `[static]`

Towns are processed every TOWN_GROWTH_FREQUENCY ticks, and this is the number of times towns are processed before a new building is built.

Definition at line 2555 of file town_cmd.cpp.

References _settings_game, Chance16(), Clamp(), ClrBit(), DistanceSquare(), GameSettings::economy, GameSettings::game_creation, GetSnowLine(), GetTropicZone(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), GameCreationSettings::landscape, max(), MAX_COMPANIES, min(), BaseStation::owner, RATING_GROWTH_MAXIMUM, RATING_GROWTH_UP_STEP, RATING_STATION_DOWN_STEP, RATING_STATION_UP_STEP, SetBit(), SetWindowDirty(), TilePixelHeight(), EconomySettings::town_growth_rate, TOWN_IS_FUNDED, TROPICZONE_DESERT, and BaseStation::xy.

## Variable Documentation

const TileTypeProcs _tile_type_town_procs

Initial value:

     {
      DrawTile_Town,
      GetSlopeZ_Town,
      ClearTile_Town,
      AddAcceptedCargo_Town,
      GetTileDesc_Town,
      GetTileTrackStatus_Town,
      NULL,
      AnimateTile_Town,
      TileLoop_Town,
      ChangeTileOwner_Town,
      AddProducedCargo_Town,
      NULL,
      GetFoundation_Town,
      TerraformTile_Town,
    }

Tile callback functions for a town.

const byte _town_action_costs[TACT_COUNT]

Initial value:

     {
      2, 4, 9, 35, 48, 53, 117, 175
    }

Factor in the cost of each town action.

See also:
  TownActions

Definition at line 2333 of file town_cmd.cpp.

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

TownActionProc* const _town_action_proc[]`[static]`

Initial value:

     {
      TownActionAdvertiseSmall,
      TownActionAdvertiseMedium,
      TownActionAdvertiseLarge,
      TownActionRoadRebuild,
      TownActionBuildStatue,
      TownActionFundBuildings,
      TownActionBuyRights,
      TownActionBribe
    }

Definition at line 2472 of file town_cmd.cpp.

TownDrawTileProc* const _town_draw_tile_procs[1]`[static]`

Initial value:

     {
      TownDrawHouseLift
    }

Definition at line 177 of file town_cmd.cpp.