OpenTTD Source  1.11.0-beta2
town_cmd.cpp File Reference
#include "stdafx.h"
#include "road.h"
#include "road_internal.h"
#include "road_cmd.h"
#include "landscape.h"
#include "viewport_func.h"
#include "viewport_kdtree.h"
#include "cmd_helper.h"
#include "command_func.h"
#include "industry.h"
#include "station_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 "date_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 "table/strings.h"
#include "table/town_land.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

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

Typedefs

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

Enumerations

enum  TownGrowthResult { GROWTH_SUCCEED = -1, GROWTH_SEARCH_STOPPED = 0 }
 

Functions

void RebuildTownKdtree ()
 
static bool TestTownOwnsBridge (TileIndex tile, const Town *t)
 Check if a town 'owns' a bridge. More...
 
static bool BuildTownHouse (Town *t, TileIndex tile)
 Tries to build a house at this tile. More...
 
static TownCreateRandomTown (uint attempts, uint32 townnameparts, TownSize size, bool city, TownLayout layout)
 
static void TownDrawHouseLift (const TileInfo *ti)
 
static DiagDirection RandomDiagDir ()
 Return a random direction. More...
 
static void DrawTile_Town (TileInfo *ti)
 House Tile drawing handler. More...
 
static int GetSlopePixelZ_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 supersedes regular ones. More...
 
static bool IsCloseToTown (TileIndex tile, uint dist)
 Determines if a town is close to a tile. More...
 
void UpdateAllTownVirtCoords ()
 Update the virtual coords needed to draw the town sign for all towns.
 
void ClearAllTownCachedNames ()
 
static void ChangePopulation (Town *t, int mod)
 Change the towns population. More...
 
uint32 GetWorldPopulation ()
 Determines the world population Basically, count population of all towns, one by one. More...
 
static void RemoveNearbyStations (Town *t, TileIndex tile, BuildingFlags flags)
 Remove stations from nearby station list if a town is no longer in the catchment area of each. More...
 
static void MakeSingleHouseBigger (TileIndex tile)
 Helper function for house completion stages progression. More...
 
static void MakeTownHouseBigger (TileIndex tile)
 Make the house advance in its construction stages until completion. More...
 
static void TileLoop_Town (TileIndex tile)
 Tile callback function. More...
 
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, CargoTypes *always_accepted)
 
static void AddAcceptedCargo_Town (TileIndex tile, CargoArray &acceptance, CargoTypes *always_accepted)
 
static void GetTileDesc_Town (TileIndex tile, TileDesc *td)
 
static TrackStatus GetTileTrackStatus_Town (TileIndex 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. More...
 
static void TownTickHandler (Town *t)
 
void OnTick_Town ()
 
static RoadBits GetTownRoadBits (TileIndex tile)
 Return the RoadBits of a tile. More...
 
RoadType GetTownRoadType (const Town *t)
 
static bool IsNeighborRoadTile (TileIndex tile, const DiagDirection dir, uint dist_multi)
 Check for parallel road inside a given distance. More...
 
static bool IsRoadAllowedHere (Town *t, TileIndex tile, DiagDirection dir)
 Check if a Road is allowed on a given tile. More...
 
static bool TerraformTownTile (TileIndex tile, 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. More...
 
static bool GrowTownWithExtraHouse (Town *t, TileIndex tile)
 Grows the town with an extra house. More...
 
static bool GrowTownWithRoad (const Town *t, TileIndex tile, RoadBits rcmd)
 Grows the town with a road piece. More...
 
static bool CanRoadContinueIntoNextTile (const Town *t, const TileIndex tile, const DiagDirection road_dir)
 Checks if a town road can be continued into the next tile. More...
 
static bool GrowTownWithBridge (const Town *t, const TileIndex tile, const DiagDirection bridge_dir)
 Grows the town with a bridge. More...
 
static bool GrowTownWithTunnel (const Town *t, const TileIndex tile, const DiagDirection tunnel_dir)
 Grows the town with a tunnel. More...
 
static bool RoadTypesAllowHouseHere (TileIndex t)
 Checks whether at least one surrounding roads allows to build a house here. More...
 
static void GrowTownInTile (TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection target_dir, Town *t1)
 Grows the given town. More...
 
static bool CanFollowRoad (TileIndex tile, DiagDirection dir)
 Checks whether a road can be followed or is a dead end, that can not be extended to the next tile. More...
 
static bool GrowTownAtRoad (Town *t, TileIndex tile)
 Returns "growth" if a house was built, or no if the build failed. More...
 
static RoadBits GenRandomRoadBits ()
 Generate a random road block. More...
 
void UpdateTownRadius (Town *t)
 
void UpdateTownMaxPass (Town *t)
 
static void UpdateTownGrowthRate (Town *t)
 Updates town growth rate. More...
 
static void UpdateTownGrowth (Town *t)
 Updates town growth state (whether it is growing or not). More...
 
static void DoCreateTown (Town *t, TileIndex tile, uint32 townnameparts, TownSize size, bool city, TownLayout layout, bool manual)
 Does the actual town creation. More...
 
static CommandCost TownCanBePlacedHere (TileIndex tile)
 Checks if it's possible to place a town at given tile. More...
 
static bool IsUniqueTownName (const char *name)
 Verifies this custom name is unique. More...
 
CommandCost CmdFoundTown (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Create a new town. More...
 
static TileIndex AlignTileToGrid (TileIndex tile, TownLayout layout)
 Towns must all be placed on the same grid or when they eventually interpenetrate their road networks will not mesh nicely; this function adjusts a tile so that it aligns properly. More...
 
static bool IsTileAlignedToGrid (TileIndex tile, TownLayout layout)
 Towns must all be placed on the same grid or when they eventually interpenetrate their road networks will not mesh nicely; this function tells you if a tile is properly aligned. More...
 
static bool FindFurthestFromWater (TileIndex tile, void *user_data)
 CircularTileSearch callback; finds the tile furthest from any water. More...
 
static bool FindNearestEmptyLand (TileIndex tile, void *user_data)
 CircularTileSearch callback; finds the nearest land tile. More...
 
static TileIndex FindNearestGoodCoastalTownSpot (TileIndex tile, TownLayout layout)
 Given a spot on the map (presumed to be a water tile), find a good coastal spot to build a city. More...
 
bool GenerateTowns (TownLayout layout)
 This function will generate a certain amount of towns, with a certain layout It can be called from the scenario editor (i.e. More...
 
HouseZonesBits GetTownRadiusGroup (const Town *t, TileIndex tile)
 Returns the bit corresponding to the town zone of the specified tile. More...
 
static void ClearMakeHouseTile (TileIndex tile, Town *t, byte counter, byte stage, HouseID type, byte random_bits)
 Clears tile and builds a house or house part. More...
 
static void MakeTownHouse (TileIndex t, Town *town, byte counter, byte stage, HouseID type, byte random_bits)
 Write house information into the map. More...
 
static bool CanBuildHouseHere (TileIndex tile, bool noslope)
 Checks if a house can be built here. More...
 
static bool CheckBuildHouseSameZ (TileIndex tile, int z, bool noslope)
 Checks if a house can be built at this tile, must have the same max z as parameter. More...
 
static bool CheckFree2x2Area (TileIndex tile, int z, bool noslope)
 Checks if a house of size 2x2 can be built at this tile. More...
 
static bool TownLayoutAllowsHouseHere (Town *t, TileIndex tile)
 Checks if current town layout allows building here. More...
 
static bool TownLayoutAllows2x2HouseHere (Town *t, TileIndex tile)
 Checks if current town layout allows 2x2 building here. More...
 
static bool CheckTownBuild2House (TileIndex *tile, Town *t, int 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. More...
 
static bool CheckTownBuild2x2House (TileIndex *tile, Town *t, int 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. More...
 
static void DoClearTownHouseHelper (TileIndex tile, Town *t, HouseID house)
 Update data structures when a house is removed. More...
 
TileIndexDiff GetHouseNorthPart (HouseID &house)
 Determines if a given HouseID is part of a multitile house. More...
 
void ClearTownHouse (Town *t, TileIndex tile)
 
CommandCost CmdRenameTown (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Rename a town (server-only). More...
 
const CargoSpecFindFirstCargoWithTownEffect (TownEffect effect)
 Determines the first cargo with a certain town effect. More...
 
CommandCost CmdTownCargoGoal (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Change the cargo goal of a town. More...
 
CommandCost CmdTownSetText (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Set a custom text in the Town window. More...
 
CommandCost CmdTownGrowthRate (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Change the growth rate of the town. More...
 
CommandCost CmdTownRating (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Change the rating of a company in a town. More...
 
CommandCost CmdExpandTown (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Expand a town (scenario editor only). More...
 
CommandCost CmdDeleteTown (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Delete a town (scenario editor or worldgen only). More...
 
static CommandCost TownActionAdvertiseSmall (Town *t, DoCommandFlag flags)
 
static CommandCost TownActionAdvertiseMedium (Town *t, DoCommandFlag flags)
 
static CommandCost TownActionAdvertiseLarge (Town *t, DoCommandFlag flags)
 
static CommandCost TownActionRoadRebuild (Town *t, DoCommandFlag flags)
 
static bool TryClearTile (TileIndex tile)
 Check whether the land can be cleared. More...
 
static bool SearchTileForStatue (TileIndex tile, void *user_data)
 Search callback function for TownActionBuildStatue. More...
 
static CommandCost TownActionBuildStatue (Town *t, DoCommandFlag flags)
 Perform a 9x9 tiles circular search from the center of the town in order to find a free tile to place a statue. More...
 
static CommandCost TownActionFundBuildings (Town *t, DoCommandFlag flags)
 
static CommandCost TownActionBuyRights (Town *t, DoCommandFlag flags)
 
static CommandCost TownActionBribe (Town *t, DoCommandFlag flags)
 
uint GetMaskOfTownActions (int *nump, CompanyID cid, const Town *t)
 Get a list of available actions to do at a town. More...
 
CommandCost CmdDoTownAction (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Do a town action. More...
 
template<typename Func >
static void ForAllStationsNearTown (Town *t, Func func)
 
static void UpdateTownRating (Town *t)
 
static void UpdateTownGrowCounter (Town *t, uint16 prev_growth_rate)
 Updates town grow counter after growth rate change. More...
 
static int CountActiveStations (Town *t)
 Calculates amount of active stations in the range of town (HZB_TOWN_EDGE). More...
 
static uint GetNormalGrowthRate (Town *t)
 Calculates town growth rate in normal conditions (custom growth rate not set). More...
 
static void UpdateTownAmounts (Town *t)
 
static void UpdateTownUnwanted (Town *t)
 
CommandCost CheckIfAuthorityAllowsNewStation (TileIndex tile, DoCommandFlag flags)
 Checks whether the local authority allows construction of a new station (rail, road, airport, dock) on the given tile. More...
 
TownCalcClosestTownFromTile (TileIndex tile, uint threshold)
 Return the town closest to the given tile within threshold. More...
 
TownClosestTownFromTile (TileIndex tile, uint threshold)
 Return the town closest (in distance or ownership) to a given tile, within a given threshold. More...
 
void SetTownRatingTestMode (bool mode)
 Switch the town rating to test-mode, to allow commands to be tested without affecting current ratings. More...
 
static int GetRating (const Town *t)
 Get the rating of a town for the _current_company. More...
 
void ChangeTownRating (Town *t, int add, int max, DoCommandFlag flags)
 Changes town rating of the current company. More...
 
CommandCost CheckforTownRating (DoCommandFlag flags, Town *t, TownRatingCheckType type)
 Does the town authority allow the (destructive) action of the current company? More...
 
void TownsMonthlyLoop ()
 
void TownsYearlyLoop ()
 
static CommandCost TerraformTile_Town (TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
 
void ResetHouses ()
 

Variables

TownID _new_town_id
 
TownPool _town_pool ("Town")
 
TownKdtree _town_kdtree & Kdtree_TownXYFunc
 
static int _grow_town_result
 
static TownDrawTileProc *const _town_draw_tile_procs [1]
 
static const byte _num_initial_towns [4] = {5, 11, 23, 46}
 
const byte _town_action_costs [TACT_COUNT]
 Factor in the cost of each town action. More...
 
static TownActionProc *const _town_action_proc []
 
static bool _town_rating_test = false
 If true, town rating is in test-mode.
 
static SmallMap< const Town *, int > _town_test_ratings
 Map of towns to modified ratings, while in town rating test-mode.
 
const TileTypeProcs _tile_type_town_procs
 Tile callback functions for a town. More...
 
HouseSpec _house_specs [NUM_HOUSES]
 

Detailed Description

Handling of town tiles.

Definition in file town_cmd.cpp.

Function Documentation

◆ 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
tilethe tile to start at
layoutwhich town layout algo is in effect
Returns
the adjusted tile

Definition at line 2043 of file town_cmd.cpp.

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

◆ AnimateTile_Town()

static void AnimateTile_Town ( TileIndex  tile)
static

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

Parameters
tileTileIndex of the house to animate

Definition at line 331 of file town_cmd.cpp.

References GetHouseType(), and NEW_HOUSE_OFFSET.

◆ BuildTownHouse()

static bool BuildTownHouse ( Town t,
TileIndex  tile 
)
static

Tries to build a house at this tile.

Parameters
ttown the house will belong to
tilewhere the house will be built
Returns
false iff no house can be built at this tile

Definition at line 2507 of file town_cmd.cpp.

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

Referenced by GrowTownWithExtraHouse().

◆ CalcClosestTownFromTile()

Town* CalcClosestTownFromTile ( TileIndex  tile,
uint  threshold 
)

Return the town closest to the given tile within threshold.

Parameters
tileStarting point of the search.
thresholdBiggest 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 3577 of file town_cmd.cpp.

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

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

◆ CanBuildHouseHere()

static bool CanBuildHouseHere ( TileIndex  tile,
bool  noslope 
)
inlinestatic

Checks if a house can be built here.

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

Parameters
tiletile to check
noslopeare slopes (foundations) allowed?
Returns
true iff house can be built here

Definition at line 2326 of file town_cmd.cpp.

References CMD_LANDSCAPE_CLEAR, DC_AUTO, DC_NO_WATER, DoCommand(), GetTileSlope(), IsBridgeAbove(), IsSteepSlope(), RoadTypesAllowHouseHere(), SLOPE_FLAT, and CommandCost::Succeeded().

Referenced by BuildTownHouse(), and CheckBuildHouseSameZ().

◆ CanFollowRoad()

static bool CanFollowRoad ( TileIndex  tile,
DiagDirection  dir 
)
static

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

This only checks trivial but often cases.

Parameters
tileStart tile for road.
dirDirection for road to follow or build.
Returns
true If road is or can be connected in the specified direction.

Definition at line 1550 of file town_cmd.cpp.

References _generating_world, _settings_game, EconomySettings::allow_town_roads, DiagDirToRoadBits(), GameSettings::economy, GetTileType(), GetTownRoadBits(), GetTunnelBridgeTransportType(), HasTileWaterGround(), IsDriveThroughStopTile(), IsValidTile(), MP_HOUSE, MP_INDUSTRY, MP_OBJECT, MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, ReverseDiagDir(), ROAD_NONE, TileOffsByDiagDir(), and TRANSPORT_ROAD.

◆ CanRoadContinueIntoNextTile()

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

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

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

Parameters
tThe current town
tileThe tile where the road would be built
road_dirThe direction of the road
Returns
true if the road can be continued, else false

Definition at line 1120 of file town_cmd.cpp.

References DiagDirToRoadBits(), ReverseDiagDir(), and TileOffsByDiagDir().

Referenced by GrowTownWithBridge(), and GrowTownWithTunnel().

◆ ChangePopulation()

static void ChangePopulation ( Town t,
int  mod 
)
static

◆ ChangeTownRating()

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

Changes town rating of the current company.

Parameters
tTown to affect
addValue to add
maxMinimum (add < 0) resp. maximum (add > 0) rating that should be achievable with this change.
flagsCommand flags, especially DC_NO_MODIFY_TOWN_RATING is tested

Definition at line 3674 of file town_cmd.cpp.

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

◆ CheckBuildHouseSameZ()

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

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

Parameters
tiletile to check
zmax z of this tile so more parts of a house are at the same height (with foundation)
noslopeare slopes (foundations) allowed?
Returns
true iff house can be built here
See also
CanBuildHouseHere()

Definition at line 2351 of file town_cmd.cpp.

References CanBuildHouseHere(), and GetTileMaxZ().

Referenced by CheckFree2x2Area(), and CheckTownBuild2House().

◆ CheckforTownRating()

◆ 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
tiletile, N corner
zmaximum tile z so all tile have the same max z
noslopeare slopes (foundations) allowed?
Returns
true iff house can be built
See also
CheckBuildHouseSameZ()

Definition at line 2370 of file town_cmd.cpp.

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

Referenced by CheckTownBuild2x2House().

◆ CheckIfAuthorityAllowsNewStation()

CommandCost CheckIfAuthorityAllowsNewStation ( TileIndex  tile,
DoCommandFlag  flags 
)

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

Parameters
tileThe tile where the station shall be constructed.
flagsCommand flags. DC_NO_TEST_TOWN_RATING is tested.
Returns
Succeeded or failed command.

Definition at line 3556 of file town_cmd.cpp.

References _current_company, _settings_game, ClosestTownFromTile(), DC_NO_TEST_TOWN_RATING, EconomySettings::dist_local_authority, GameSettings::economy, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), and Town::ratings.

Referenced by CmdBuildRailStation().

◆ CheckTownBuild2House()

static bool CheckTownBuild2House ( TileIndex tile,
Town t,
int  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
tiletile where the building should be built
ttown
maxzall tiles should have the same height
noslopeare slopes forbidden?
seconddiagdir from first tile to second tile

Definition at line 2459 of file town_cmd.cpp.

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

◆ CheckTownBuild2x2House()

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

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

Parameters
tiletile where the building should be built
ttown
maxzall tiles should have the same height
noslopeare slopes forbidden?

Definition at line 2484 of file town_cmd.cpp.

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

◆ ClearMakeHouseTile()

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

Clears tile and builds a house or house part.

Parameters
tiletile index
tThe town to clear the house for
counterof construction step
stageof construction (used for drawing)
typeof house. Index into house specs array
random_bitsrequired for newgrf houses
Precondition
house can be built here

Definition at line 2277 of file town_cmd.cpp.

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

Referenced by MakeTownHouse().

◆ ClosestTownFromTile()

Town* ClosestTownFromTile ( TileIndex  tile,
uint  threshold 
)

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

Parameters
tileStarting point of the search.
thresholdBiggest 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 3595 of file town_cmd.cpp.

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

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

◆ CmdDeleteTown()

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

Delete a town (scenario editor or worldgen only).

Parameters
tileUnused.
flagsType of operation.
p1Town ID to delete.
p2Unused.
textUnused.
Returns
Empty cost or an error.

Definition at line 2963 of file town_cmd.cpp.

◆ CmdDoTownAction()

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
tileunused
flagstype of operation
p1town to do the action at
p2action to perform,
See also
_town_action_proc for the list of available actions
Parameters
textunused
Returns
the cost of this operation or an error

Definition at line 3352 of file town_cmd.cpp.

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

◆ CmdExpandTown()

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

Expand a town (scenario editor only).

Parameters
tileUnused.
flagsType of operation.
p1Town ID to expand.
p2Amount to grow, or 0 to grow a random size up to the current amount of houses.
textUnused.
Returns
Empty cost or an error.

Definition at line 2923 of file town_cmd.cpp.

◆ CmdFoundTown()

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

Create a new town.

Parameters
tilecoordinates where town is built
flagstype of operation
p10..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
p2town name parts
textCustom 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 1929 of file town_cmd.cpp.

References _settings_game, CMD_ERROR, GameSettings::game_creation, HasBit(), NUM_TLS, GameCreationSettings::town_name, and TSZ_END.

◆ CmdRenameTown()

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

Rename a town (server-only).

Parameters
tileunused
flagstype of operation
p1town ID to rename
p2unused
textthe new name or an empty string when resetting to the default
Returns
the cost of this operation or an error

Definition at line 2743 of file town_cmd.cpp.

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

◆ CmdTownCargoGoal()

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

Change the cargo goal of a town.

Parameters
tileUnused.
flagsType of operation.
p1various bitstuffed elements
  • p1 = (bit 0 - 15) - Town ID to cargo game of.
  • p1 = (bit 16 - 23) - TownEffect to change the game of.
p2The new goal value.
textUnused.
Returns
Empty cost or an error.

Definition at line 2797 of file town_cmd.cpp.

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

◆ CmdTownGrowthRate()

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

Change the growth rate of the town.

Parameters
tileUnused.
flagsType of operation.
p1Town ID to cargo game of.
p2Amount of days between growth, or TOWN_GROWTH_RATE_NONE, or 0 to reset custom growth rate.
textUnused.
Returns
Empty cost or an error.

Definition at line 2854 of file town_cmd.cpp.

References _current_company, ClrBit(), CMD_ERROR, DC_EXEC, Town::flags, GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::GetIfValid(), Town::grow_counter, Town::growth_rate, InvalidateWindowData(), OWNER_DEITY, SetBit(), TOWN_CUSTOM_GROWTH, UpdateTownGrowth(), and WC_TOWN_VIEW.

◆ CmdTownRating()

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

Change the rating of a company in a town.

Parameters
tileUnused.
flagsType of operation.
p1Bit 0..15 = Town ID to change, bit 16..23 = Company ID to change.
p2Bit 0..15 = New rating of company (signed int16).
textUnused.
Returns
Empty cost or an error.

Definition at line 2894 of file town_cmd.cpp.

References _current_company, CMD_ERROR, and OWNER_DEITY.

◆ CmdTownSetText()

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

Set a custom text in the Town window.

Parameters
tileUnused.
flagsType of operation.
p1Town ID to change the text of.
p2Unused.
textThe new text (empty to remove the text).
Returns
Empty cost or an error.

Definition at line 2830 of file town_cmd.cpp.

References _current_company, CMD_ERROR, DC_EXEC, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::GetIfValid(), InvalidateWindowData(), OWNER_DEITY, StrEmpty(), 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
tThe town to calculate stations for
Returns
Amount of active stations

Definition at line 3439 of file town_cmd.cpp.

Referenced by GetNormalGrowthRate().

◆ DoClearTownHouseHelper()

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

Update data structures when a house is removed.

Parameters
tileTile of the house
tTown owning the house
houseHouse type

Definition at line 2661 of file town_cmd.cpp.

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

◆ DoCreateTown()

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

Does the actual town creation.

Parameters
tThe town
tileWhere to put it
townnamepartsThe town name
sizeParameter for size determination
citywhether to build a city or town
layoutthe (road) layout of the town
manualwas the town placed manually?

Definition at line 1807 of file town_cmd.cpp.

References Town::cache, TownCache::num_houses, Town::time_until_rebuild, and Town::xy.

◆ DrawTile_Town()

static void DrawTile_Town ( TileInfo ti)
static

House Tile drawing handler.

Part of the tile loop process

Parameters
tiTileInfo of the tile to draw

Definition at line 252 of file town_cmd.cpp.

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

◆ FindFirstCargoWithTownEffect()

const CargoSpec* FindFirstCargoWithTownEffect ( TownEffect  effect)

Determines the first cargo with a certain town effect.

Parameters
effectTown effect of interest
Returns
first active cargo slot with that effect

Definition at line 2777 of file town_cmd.cpp.

Referenced by CmdTownCargoGoal().

◆ FindFurthestFromWater()

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

CircularTileSearch callback; finds the tile furthest from any water.

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

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

Parameters
tileStart looking from this tile
user_dataStorage area for data that must last across calls; must be a pointer to struct SpotData
Returns
always false

Definition at line 2095 of file town_cmd.cpp.

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

Referenced by FindNearestGoodCoastalTownSpot().

◆ FindNearestEmptyLand()

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

CircularTileSearch callback; finds the nearest land tile.

Parameters
tileStart looking from this tile
user_datanot used

Definition at line 2117 of file town_cmd.cpp.

References IsTileType(), and MP_CLEAR.

Referenced by FindNearestGoodCoastalTownSpot().

◆ FindNearestGoodCoastalTownSpot()

static TileIndex FindNearestGoodCoastalTownSpot ( TileIndex  tile,
TownLayout  layout 
)
static

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

We don't want to build too close to the edge if we can help it (since that 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
tileStart looking from this spot.
layoutthe road layout to search for
Returns
tile that was found

Definition at line 2134 of file town_cmd.cpp.

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

◆ GenerateTowns()

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
layoutwhich towns will be set to, when created
Returns
true if towns have been successfully created

Definition at line 2201 of file town_cmd.cpp.

◆ GenRandomRoadBits()

static RoadBits GenRandomRoadBits ( )
static

Generate a random road block.

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

Returns
A RoadBits value with 2 bits set

Definition at line 1674 of file town_cmd.cpp.

◆ 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
houseIs 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 2678 of file town_cmd.cpp.

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

◆ GetMaskOfTownActions()

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

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

Parameters
numpif not nullptr add put the number of available actions in it
cidthe company that is querying the town
tthe town that is queried
Returns
bitmasked value of enabled actions

Definition at line 3299 of file town_cmd.cpp.

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

Referenced by TownAuthorityWindow::OnPaint().

◆ GetNormalGrowthRate()

static uint GetNormalGrowthRate ( Town t)
static

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

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

Parameters
tThe 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 3456 of file town_cmd.cpp.

References _settings_game, CountActiveStations(), GameSettings::economy, Town::fund_buildings_months, Town::larger_town, 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
tTown to get the rating from.
Returns
Rating of the current company in the given town.

Definition at line 3656 of file town_cmd.cpp.

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

Referenced by ChangeTownRating(), and CheckforTownRating().

◆ GetTownRadiusGroup()

HouseZonesBits GetTownRadiusGroup ( const Town t,
TileIndex  tile 
)

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

Parameters
tTown on which town zone is to be found
tileTileIndex where town zone needs to be found
Returns
the bit position of the given zone, as defined in HouseZones

Definition at line 2253 of file town_cmd.cpp.

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

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

◆ GetTownRoadBits()

static RoadBits GetTownRoadBits ( TileIndex  tile)
static

Return the RoadBits of a tile.

Note
There are many other functions doing things like that.
Needs to be checked for needlessness.
Parameters
tileThe tile we want to analyse
Returns
The roadbits of the given tile

Definition at line 840 of file town_cmd.cpp.

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

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

◆ GetTownRoadGridElement()

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

Generate the RoadBits of a grid tile.

Parameters
tcurrent town
tiletile in reference to the town
dirThe direction to which we are growing ATM
Returns
the RoadBit of the current tile regarding the selected town layout

Definition at line 1000 of file town_cmd.cpp.

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

◆ GetWorldPopulation()

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

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

Referenced by TownDirectoryWindow::SetStringParameters().

◆ GrowTown()

static bool GrowTown ( Town t)
static

Grow the town.

Parameters
ttown to grow
Returns
true iff something (house, road, bridge, ...) was built

Definition at line 1688 of file town_cmd.cpp.

References _current_company, and OWNER_TOWN.

◆ GrowTownAtRoad()

static bool GrowTownAtRoad ( Town t,
TileIndex  tile 
)
static

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

Parameters
ttown to inquiry
tileto inquiry
Returns
true if town expansion was possible

Definition at line 1592 of file town_cmd.cpp.

References DIAGDIR_END, Town::layout, MapSize(), and TL_BETTER_ROADS.

◆ GrowTownInTile()

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

Grows the given town.

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

  • Generate a random tile and check if there is a road allowed
  • TL_ORIGINAL
  • TL_BETTER_ROADS
  • Check if the town geometry allows a road and which one
  • TL_2X2_GRID
  • TL_3X3_GRID
  • Forbid roads, only build houses
Parameters
tile_ptrThe current tile
cur_rbThe current tiles RoadBits
target_dirThe target road dir
t1The current town

Definition at line 1346 of file town_cmd.cpp.

References MapSize(), and ROAD_NONE.

◆ 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
tThe current town
tileThe current tile
bridge_dirThe valid direction in which to grow a bridge
Returns
true if a bridge has been build else false

Definition at line 1164 of file town_cmd.cpp.

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

◆ GrowTownWithExtraHouse()

static bool GrowTownWithExtraHouse ( Town t,
TileIndex  tile 
)
static

Grows the town with an extra house.

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

Parameters
tThe current town
tileThe target tile for the extra house
Returns
true if an extra house has been added

Definition at line 1059 of file town_cmd.cpp.

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

◆ GrowTownWithRoad()

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

Grows the town with a road piece.

Parameters
tThe current town
tileThe current tile
rcmdThe RoadBits we want to build on the tile
Returns
true if the RoadBits have been added else false

Definition at line 1101 of file town_cmd.cpp.

◆ 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
tThe current town
tileThe current tile
tunnel_dirThe valid direction in which to grow a tunnel
Returns
true if a tunnel has been built, else false

Definition at line 1239 of file town_cmd.cpp.

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

◆ IsCloseToTown()

static bool IsCloseToTown ( TileIndex  tile,
uint  dist 
)
static

Determines if a town is close to a tile.

Parameters
tileTileIndex of the tile to query
distmaximum distance to be accepted
Returns
true if the tile correspond to the distance criteria

Definition at line 382 of file town_cmd.cpp.

Referenced by TownCanBePlacedHere().

◆ IsNeighborRoadTile()

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

Check for parallel road inside a given distance.

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

Parameters
tilecurrent tile
dirtarget direction
dist_multidistance multiplayer
Returns
true if there is a parallel road

Definition at line 888 of file town_cmd.cpp.

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

◆ IsRoadAllowedHere()

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

Check if a Road is allowed on a given tile.

Parameters
tThe current town
tileThe target tile
dirThe direction in which we want to extend the town
Returns
true if it is allowed else false

Definition at line 922 of file town_cmd.cpp.

References DiagDirToAxis(), DistanceFromEdge(), GetBridgeAxis(), GetTownRoadBits(), IsBridgeAbove(), and ROAD_NONE.

◆ 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
tilethe tile to start at
layoutwhich town layout algo is in effect
Returns
true if the tile is in the correct location

Definition at line 2061 of file town_cmd.cpp.

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

Referenced by FindFurthestFromWater().

◆ IsUniqueTownName()

static bool IsUniqueTownName ( const char *  name)
static

Verifies this custom name is unique.

Only custom names are checked.

Parameters
namename to check
Returns
is this name unique?

Definition at line 1908 of file town_cmd.cpp.

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

Referenced by CmdRenameTown().

◆ MakeSingleHouseBigger()

static void MakeSingleHouseBigger ( TileIndex  tile)
static

Helper function for house completion stages progression.

Parameters
tileTileIndex of the house (or parts of it) to "grow"

Definition at line 480 of file town_cmd.cpp.

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

◆ MakeTownHouse()

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
ttile index
townThe town related to this house
counterof construction step
stageof construction (used for drawing)
typeof house. Index into house specs array
random_bitsrequired for newgrf houses
Precondition
house can be built here

Definition at line 2301 of file town_cmd.cpp.

References HouseSpec::building_flags, and ClearMakeHouseTile().

◆ MakeTownHouseBigger()

static void MakeTownHouseBigger ( TileIndex  tile)
static

Make the house advance in its construction stages until completion.

Parameters
tileTileIndex of house

Definition at line 503 of file town_cmd.cpp.

References HouseSpec::building_flags, and GetHouseType().

◆ RandomDiagDir()

static DiagDirection RandomDiagDir ( )
inlinestatic

Return a random direction.

Returns
a random direction

Definition at line 242 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
tTown to work on
tileLocation of house area (north part)
flagsBuildingFlags containing the size of house area

Definition at line 458 of file town_cmd.cpp.

References Town::stations_near.

◆ RoadTypesAllowHouseHere()

static bool RoadTypesAllowHouseHere ( TileIndex  t)
inlinestatic

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

Parameters
tthe tile where the house will be built
Returns
true if at least one surrounding roadtype allows building houses here

Definition at line 1305 of file town_cmd.cpp.

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

Referenced by CanBuildHouseHere().

◆ SearchTileForStatue()

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

Search callback function for TownActionBuildStatue.

Parameters
tileTile on which to perform the search.
user_dataReference to the statue search data.
Returns
Result of the test.

Definition at line 3131 of file town_cmd.cpp.

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

Referenced by TownActionBuildStatue().

◆ SetTownRatingTestMode()

void SetTownRatingTestMode ( bool  mode)

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

The function is safe to use in nested calls.

Parameters
modeTest mode switch (true means go to test-mode, false means leave test-mode).

Definition at line 3636 of file town_cmd.cpp.

References _town_rating_test, and _town_test_ratings.

◆ TestTownOwnsBridge()

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

Check if a town 'owns' a bridge.

Bridges to 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
tileBridge tile to test
tTown we are interested in
Returns
true if town 'owns' a bridge.

Definition at line 85 of file town_cmd.cpp.

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

Referenced by Town::~Town().

◆ TileLoop_Town()

static void TileLoop_Town ( TileIndex  tile)
static

Tile callback function.

Periodic tic handler for houses and town

Parameters
tilebeen asked to do its stuff

Definition at line 518 of file town_cmd.cpp.

References GetHouseType(), and NEW_HOUSE_OFFSET.

◆ TownActionBuildStatue()

static CommandCost TownActionBuildStatue ( Town t,
DoCommandFlag  flags 
)
static

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

Parameters
ttown to search in
flagsUsed to check if the statue must be built or not.
Returns
Empty cost or an error.

Definition at line 3174 of file town_cmd.cpp.

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

◆ TownCanBePlacedHere()

static CommandCost TownCanBePlacedHere ( TileIndex  tile)
static

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

Parameters
tiletile to check
Returns
error value or zero cost

Definition at line 1883 of file town_cmd.cpp.

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

◆ TownLayoutAllows2x2HouseHere()

static bool TownLayoutAllows2x2HouseHere ( Town t,
TileIndex  tile 
)
inlinestatic

Checks if current town layout allows 2x2 building here.

Parameters
ttown
tiletile to check
Returns
true iff town layout allows 2x2 building here
Note
see layouts

Definition at line 2422 of file town_cmd.cpp.

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

Referenced by CheckTownBuild2x2House().

◆ TownLayoutAllowsHouseHere()

static bool TownLayoutAllowsHouseHere ( Town t,
TileIndex  tile 
)
inlinestatic

Checks if current town layout allows building here.

Parameters
ttown
tiletile to check
Returns
true iff town layout allows building here
Note
see layouts

Definition at line 2391 of file town_cmd.cpp.

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

Referenced by BuildTownHouse(), and CheckTownBuild2House().

◆ TryClearTile()

static bool TryClearTile ( TileIndex  tile)
static

Check whether the land can be cleared.

Parameters
tileTile to check.
Returns
The tile can be cleared.

Definition at line 3109 of file town_cmd.cpp.

References _current_company, and OWNER_NONE.

Referenced by SearchTileForStatue().

◆ UpdateTownGrowCounter()

static void UpdateTownGrowCounter ( Town t,
uint16  prev_growth_rate 
)
static

Updates town grow counter after growth rate change.

Preserves relative house builting progress whenever it can.

Parameters
tThe town to calculate grow counter for
prev_growth_rateTown growth rate before it changed (one that was used with grow counter to be updated)

Definition at line 3424 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

◆ UpdateTownGrowthRate()

static void UpdateTownGrowthRate ( Town t)
static

Variable Documentation

◆ _tile_type_town_procs

const TileTypeProcs _tile_type_town_procs
Initial value:
= {
GetSlopePixelZ_Town,
ClearTile_Town,
AddAcceptedCargo_Town,
GetTileDesc_Town,
GetTileTrackStatus_Town,
nullptr,
ChangeTileOwner_Town,
AddProducedCargo_Town,
nullptr,
TerraformTile_Town,
}

Tile callback functions for a town.

Definition at line 46 of file landscape.cpp.

◆ _town_action_costs

const byte _town_action_costs[TACT_COUNT]
Initial value:
= {
2, 4, 9, 35, 48, 53, 117, 175
}

Factor in the cost of each town action.

See also
TownActions

Definition at line 3053 of file town_cmd.cpp.

◆ _town_action_proc

TownActionProc* const _town_action_proc[]
static
Initial value:
= {
TownActionAdvertiseSmall,
TownActionAdvertiseMedium,
TownActionAdvertiseLarge,
TownActionRoadRebuild,
TownActionFundBuildings,
TownActionBuyRights,
TownActionBribe
}

Definition at line 3281 of file town_cmd.cpp.

◆ _town_draw_tile_procs

TownDrawTileProc* const _town_draw_tile_procs[1]
static
Initial value:
= {
TownDrawHouseLift
}

Definition at line 233 of file town_cmd.cpp.

TileLoop_Town
static void TileLoop_Town(TileIndex tile)
Tile callback function.
Definition: town_cmd.cpp:518
TownActionBuildStatue
static CommandCost TownActionBuildStatue(Town *t, DoCommandFlag flags)
Perform a 9x9 tiles circular search from the center of the town in order to find a free tile to place...
Definition: town_cmd.cpp:3174
GetFoundation_Town
static Foundation GetFoundation_Town(TileIndex tile, Slope tileh)
Tile callback routine.
Definition: town_cmd.cpp:307
AnimateTile_Town
static void AnimateTile_Town(TileIndex tile)
Animate a tile for a town Only certain houses can be animated The newhouses animation supersedes regu...
Definition: town_cmd.cpp:331
DrawTile_Town
static void DrawTile_Town(TileInfo *ti)
House Tile drawing handler.
Definition: town_cmd.cpp:252