# station_cmd.cpp File Reference

Handling of station tiles. More...

`#include "stdafx.h"`
`#include "openttd.h"`
`#include "aircraft.h"`
`#include "bridge_map.h"`
`#include "cmd_helper.h"`
`#include "landscape.h"`
`#include "viewport_func.h"`
`#include "command_func.h"`
`#include "town.h"`
`#include "news_func.h"`
`#include "train.h"`
`#include "roadveh.h"`
`#include "industry_map.h"`
`#include "newgrf_station.h"`
`#include "newgrf_commons.h"`
`#include "yapf/yapf.h"`
`#include "road_internal.h"`
`#include "variables.h"`
`#include "autoslope.h"`
`#include "water.h"`
`#include "station_gui.h"`
`#include "strings_func.h"`
`#include "functions.h"`
`#include "window_func.h"`
`#include "date_func.h"`
`#include "vehicle_func.h"`
`#include "string_func.h"`
`#include "oldpool_func.h"`
`#include "animated_tile_func.h"`
`#include "elrail_func.h"`
`#include "table/strings.h"`
`#include "table/station_land.h"`

Go to the source code of this file.

## Data Structures
struct | StationNameInformation
| Information to handle station action 0 property 24 correctly. More...
## Defines
#define | CHECK_STATIONS_ERR ((Station*)-1)
#define | M(x) ((x) - STR_SV_STNAME)
## Typedefs
typedef bool(* | CMSAMatcher )(TileIndex tile)
| Function to check whether the given tile matches some criterion.
## Enumerations
enum | StationNaming { STATIONNAMING_RAIL = 0, STATIONNAMING_ROAD = 0, STATIONNAMING_AIRPORT, STATIONNAMING_OILRIG, STATIONNAMING_DOCK, STATIONNAMING_BUOY, STATIONNAMING_HELIPORT }
## Functions
bool | IsHangar (TileIndex t)
| Check whether the given tile is a hangar.
RoadStop * | GetRoadStopByTile (TileIndex tile, RoadStopType type)
static uint | GetNumRoadStopsInStation (const Station *st, RoadStopType type)
static Station * | GetStationAround (TileIndex tile, int w, int h, StationID closest_station)
static int | CountMapSquareAround (TileIndex tile, CMSAMatcher cmp)
| Counts the numbers of tiles matching a specific type in the area around.
static bool | CMSAMine (TileIndex tile)
| Check whether the tile is a mine.
static bool | CMSAWater (TileIndex tile)
| Check whether the tile is water.
static bool | CMSATree (TileIndex tile)
| Check whether the tile is a tree.
static bool | CMSAForest (TileIndex tile)
| Check whether the tile is a forest.
static bool | FindNearIndustryName (TileIndex tile, void *user_data)
| Find a station action 0 property 24 station name, or reduce the free_names if needed.
static StringID | GenerateStationName (Station *st, TileIndex tile, int flag)
static Station * | GetClosestDeletedStation (TileIndex tile)
| Find the closest deleted station of the current company.
static void | UpdateStationVirtCoord (Station *st)
| Update the virtual coords needed to draw the station sign.
void | UpdateAllStationVirtCoord ()
| Update the virtual coords needed to draw the station sign for all stations.
static void | UpdateStationVirtCoordDirty (Station *st)
| Update the station virt coords while making the modified parts dirty.
static uint | GetAcceptanceMask (const Station *st)
| Get a mask of the cargo types that the station accepts.
static void | ShowRejectOrAcceptNews (const Station *st, uint num_items, CargoID *cargo, StringID msg)
| Items contains the two cargo names that are to be accepted or rejected.
void | GetProductionAroundTiles (AcceptedCargo produced, TileIndex tile, int w, int h, int rad)
| Get a list of the cargo types being produced around the tile (in a rectangle).
void | GetAcceptanceAroundTiles (AcceptedCargo accepts, TileIndex tile, int w, int h, int rad)
| Get a list of the cargo types that are accepted around the tile.
static void | UpdateStationAcceptance (Station *st, bool show_msg)
| Update the acceptance for a station.
static void | UpdateStationSignCoord (Station *st)
static void | DeleteStationIfEmpty (Station *st)
| This is called right after a station was deleted.
static CommandCost | ClearTile_Station (TileIndex tile, DoCommandFlag flags)
CommandCost | CheckFlatLandBelow (TileIndex tile, uint w, uint h, DoCommandFlag flags, uint invalid_dirs, StationID *station, bool check_clear=true)
| Tries to clear the given area.
static bool | CanExpandRailroadStation (const Station *st, uint *fin, Axis axis)
static byte * | CreateSingle (byte *layout, int n)
static byte * | CreateMulti (byte *layout, int n, byte b)
static void | GetStationLayout (byte *layout, int numtracks, int plat_len, const StationSpec *statspec)
CommandCost | CmdBuildRailroadStation (TileIndex tile_org, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Build railroad station.
static void | MakeRailwayStationAreaSmaller (Station *st)
CommandCost | CmdRemoveFromRailroadStation (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Remove a single tile from a railroad station.
static CommandCost | RemoveRailroadStation (Station *st, TileIndex tile, DoCommandFlag flags)
static RoadStop ** | FindRoadStopSpot (bool truck_station, Station *st)
CommandCost | CmdBuildRoadStop (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Build a bus or truck stop.
static Vehicle * | ClearRoadStopStatusEnum (Vehicle *v, void *)
static CommandCost | RemoveRoadStop (Station *st, DoCommandFlag flags, TileIndex tile)
| Remove a bus station.
CommandCost | CmdRemoveRoadStop (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Remove a bus or truck stop.
static uint | GetMinimalAirportDistanceToTile (const AirportFTAClass *afc, TileIndex town_tile, TileIndex airport_tile)
| Computes the minimal distance from town's xy to any airport's tile.
uint8 | GetAirportNoiseLevelForTown (const AirportFTAClass *afc, TileIndex town_tile, TileIndex tile)
| Get a possible noise reduction factor based on distance from town center.
Town * | AirportGetNearestTown (const AirportFTAClass *afc, TileIndex airport_tile)
| Finds the town nearest to given airport.
void | UpdateAirportsNoise ()
| Recalculate the noise generated by the airports of each town.
CommandCost | CmdBuildAirport (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Place an Airport.
static CommandCost | RemoveAirport (Station *st, DoCommandFlag flags)
CommandCost | CmdBuildBuoy (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Build a buoy.
bool | HasStationInUse (StationID station, CompanyID company)
| Tests whether the company's vehicles have this station in orders When company == INVALID_COMPANY, then check all vehicles.
static CommandCost | RemoveBuoy (Station *st, DoCommandFlag flags)
CommandCost | CmdBuildDock (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Build a dock/haven.
static CommandCost | RemoveDock (Station *st, DoCommandFlag flags)
const DrawTileSprites * | GetStationTileLayout (StationType st, byte gfx)
static void | DrawTile_Station (TileInfo *ti)
void | StationPickerDrawSprite (int x, int y, StationType st, RailType railtype, RoadType roadtype, int image)
static uint | GetSlopeZ_Station (TileIndex tile, uint x, uint y)
static Foundation | GetFoundation_Station (TileIndex tile, Slope tileh)
static void | GetAcceptedCargo_Station (TileIndex tile, AcceptedCargo ac)
static void | GetTileDesc_Station (TileIndex tile, TileDesc *td)
static TrackStatus | GetTileTrackStatus_Station (TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
static void | TileLoop_Station (TileIndex tile)
static void | AnimateTile_Station (TileIndex tile)
static bool | ClickTile_Station (TileIndex tile)
static VehicleEnterTileStatus | VehicleEnter_Station (Vehicle *v, TileIndex tile, int x, int y)
static void | StationHandleBigTick (Station *st)
| This function is called for each station once every 250 ticks.
static void | byte_inc_sat (byte *p)
static void | UpdateStationRating (Station *st)
static void | StationHandleSmallTick (Station *st)
void | OnTick_Station ()
void | StationMonthlyLoop ()
void | ModifyStationRatingAround (TileIndex tile, Owner owner, int amount, uint radius)
static void | UpdateStationWaiting (Station *st, CargoID type, uint amount)
static bool | IsUniqueStationName (const char *name)
CommandCost | CmdRenameStation (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Rename a station.
void | FindStationsAroundTiles (TileIndex tile, int w_prod, int h_prod, StationList *stations)
| Find all (non-buoy) stations around a rectangular producer (industry, house, headquarter, .
uint | MoveGoodsToStation (TileIndex tile, int w, int h, CargoID type, uint amount)
void | BuildOilRig (TileIndex tile)
void | DeleteOilRig (TileIndex tile)
static void | ChangeTileOwner_Station (TileIndex tile, Owner old_owner, Owner new_owner)
static bool | CanRemoveRoadWithStop (TileIndex tile, DoCommandFlag flags)
| Check if a drive-through road stop tile can be cleared.
void | InitializeStations ()
static CommandCost | TerraformTile_Station (TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
## Variables
static const byte | _airport_sections_country []
static const byte | _airport_sections_town []
static const byte | _airport_sections_metropolitan []
static const byte | _airport_sections_international []
static const byte | _airport_sections_intercontinental []
static const byte | _airport_sections_commuter []
static const byte | _airport_sections_heliport []
static const byte | _airport_sections_helidepot []
static const byte | _airport_sections_helistation []
static const byte *const | _airport_sections []
static const TileIndexDiffC | _dock_tileoffs_chkaround []
static const byte | _dock_w_chk [4] = { 2, 1, 2, 1 }
static const byte | _dock_h_chk [4] = { 1, 2, 1, 2 }
const TileTypeProcs | _tile_type_station_procs

## Detailed Description

Handling of station tiles.

Definition in file station_cmd.cpp.

## Typedef Documentation

typedef bool(* CMSAMatcher)(TileIndex tile)

Function to check whether the given tile matches some criterion.

Parameters:

  | tile | the tile to check

Returns:
  true if it matches, false otherwise

Definition at line 111 of file station_cmd.cpp.

## Function Documentation

Town* AirportGetNearestTown | ( | const AirportFTAClass * | afc,
|  | TileIndex | airport_tile |
| ) |  |  |

Finds the town nearest to given airport.

Based on minimal manhattan distance to any airport's tile. If two towns have the same distance, town with lower index is returned.

Parameters:

  | afc | airport's description
  | airport_tile | st->airport_tile

Returns:
  nearest town to airport

Definition at line 1767 of file station_cmd.cpp.

References DistanceManhattan(), GetMinimalAirportDistanceToTile(), AirportFTAClass::size_x, and AirportFTAClass::size_y.

Referenced by CmdBuildAirport(), AIAirport::GetNearestTown(), AIAirport::GetNoiseLevelIncrease(), and UpdateAirportsNoise().

static bool CanRemoveRoadWithStop | ( | TileIndex | tile,
|  | DoCommandFlag | flags |
| ) |  |  | `[static]`

Check if a drive-through road stop tile can be cleared.

Road stops built on town-owned roads check the conditions that would allow clearing of the original road.

Parameters:

  | tile | road stop tile to check
  | flags | command flags

Returns:
  true if the road can be cleared

Definition at line 3144 of file station_cmd.cpp.

References CheckAllowRemoveRoad(), GetAnyRoadBits(), HasBit(), OWNER_TOWN, ROADTYPE_ROAD, and ROADTYPE_TRAM.

CommandCost CheckFlatLandBelow | ( | TileIndex | tile,
|  | uint | w,
|  | uint | h,
|  | DoCommandFlag | flags,
|  | uint | invalid_dirs,
|  | StationID * | station,
|  | bool | check_clear = `true` |
| ) |  |  |

Tries to clear the given area.

Parameters:

  | tile | TileIndex to start check
  | w | width of search area
  | h | height of search area
  | flags | operation to perform
  | invalid_dirs | prohibited directions (set of DiagDirections)
  | station | StationID to be queried and returned if available
  | check_clear | if clearing tile should be performed (in wich case, cost will be added)

Returns:
  the cost in case of success, or an error code if it failed.

Definition at line 666 of file station_cmd.cpp.

References _settings_game, CommandCost::AddCost(), BEGIN_TILE_LOOP, ConstructionSettings::build_on_slopes, CMD_ERROR, CMD_LANDSCAPE_CLEAR, CmdFailed(), GameSettings::construction, DC_AUTO, DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, DoCommand(), END_TILE_LOOP, GetStationIndex(), GetTileSlope(), HasBit(), IsBridgeAbove(), IsSteepSlope(), IsTileType(), MayHaveBridgeAbove(), return_cmd_error, SLOPE_FLAT, SLOPE_NE, SLOPE_NW, SLOPE_SE, SLOPE_SW, and TILE_HEIGHT.

Referenced by CmdBuildAirport(), CmdBuildCompanyHQ(), CmdBuildRailroadStation(), and CmdBuildRoadStop().

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

Place an Airport.

Parameters:

  | tile | tile where airport will be built
  | flags | operation to perform
  | p1 | airport type,

See also:
  airport.h

Parameters:

  | p2 | various bitstuffed elements p2 = (bit 0) - allow airports directly adjacent to other airports. p2 = (bit 16-31) - station ID to join (INVALID_STATION if build new one)

Definition at line 1812 of file station_cmd.cpp.

References _settings_game, CommandCost::AddCost(), Station::AddFacility(), StationSettings::adjacent_stations, Station::airport_flags, Station::airport_tile, Station::airport_type, AirportGetNearestTown(), StationRect::BeforeAddRect(), BEGIN_TILE_LOOP, PoolItem< T, Tid, Tpool >::CanAllocateItem(), CheckFlatLandBelow(), CheckIfAuthorityAllowsNewStation(), CMD_ERROR, CmdFailed(), StationSettings::distant_join_stations, GameSettings::economy, END_TILE_LOOP, Station::facilities, AirportFTAClass::flags, GB(), GetAirportNoiseLevelForTown(), GetClosestDeletedStation(), GetValidAirports(), HasBit(), PoolItem< T, Tid, Tpool >::index, INVALID_TILE, InvalidateWindow(), InvalidateWindowData(), InvalidateWindowWidget(), lengthof, Station::owner, Station::rect, return_cmd_error, SetBit(), Station::sign, AirportFTAClass::size_x, AirportFTAClass::size_y, GameSettings::station, EconomySettings::station_noise_level, StationSettings::station_spread, Station::string_id, SVW_PLANES, Station::town, UpdateAirplanesOnNewStation(), UpdateStationAcceptance(), and UpdateStationVirtCoordDirty().

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

Build a buoy.

Parameters:

  | tile | tile where to place the bouy
  | flags | operation to perform
  | p1 | unused
  | p2 | unused

Definition at line 2025 of file station_cmd.cpp.

References _date, Station::build_date, PoolItem< T, Tid, Tpool >::CanAllocateItem(), Station::dock_tile, Station::facilities, GetTileSlope(), Station::had_vehicle_of_type, PoolItem< T, Tid, Tpool >::index, InvalidateWindowData(), InvalidateWindowWidget(), IsBridgeAbove(), MayHaveBridgeAbove(), Station::owner, OWNER_NONE, return_cmd_error, SetBit(), Station::sign, SLOPE_FLAT, Station::string_id, SVW_SHIPS, Station::town, UpdateStationAcceptance(), and UpdateStationVirtCoordDirty().

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

Build a dock/haven.

Parameters:

  | tile | tile where dock will be built
  | flags | operation to perform
  | p1 | (bit 0) - allow docks directly adjacent to other docks.
  | p2 | bit 16-31: station ID to join (INVALID_STATION if build new one)

Definition at line 2135 of file station_cmd.cpp.

References _settings_game, Station::AddFacility(), StationSettings::adjacent_stations, StationRect::BeforeAddRect(), PoolItem< T, Tid, Tpool >::CanAllocateItem(), CheckIfAuthorityAllowsNewStation(), CMD_ERROR, CMD_LANDSCAPE_CLEAR, CmdFailed(), StationSettings::distant_join_stations, Station::dock_tile, DoCommand(), GB(), GetClosestDeletedStation(), GetInclinedSlopeDirection(), GetTileSlope(), HasBit(), PoolItem< T, Tid, Tpool >::index, INVALID_DIAGDIR, INVALID_TILE, InvalidateWindowData(), InvalidateWindowWidget(), IsBridgeAbove(), IsTileType(), MayHaveBridgeAbove(), MP_WATER, Station::owner, Station::rect, return_cmd_error, ReverseDiagDir(), SetBit(), SLOPE_FLAT, GameSettings::station, Station::string_id, SVW_SHIPS, TileOffsByDiagDir(), ToTileIndexDiff(), Station::town, UpdateStationAcceptance(), and UpdateStationVirtCoordDirty().

CommandCost CmdBuildRailroadStation | ( | TileIndex | tile_org,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

Build railroad station.

Parameters:

  | tile_org | starting position of station dragging/placement
  | flags | operation to perform
  | p1 | various bitstuffed elements p1 = (bit 0- 3) - railtype (p1 & 0xF) p1 = (bit 4) - orientation (Axis) p1 = (bit 8-15) - number of tracks p1 = (bit 16-23) - platform length p1 = (bit 24) - allow stations directly adjacent to other stations.
  | p2 | various bitstuffed elements p2 = (bit 0- 7) - custom station class p2 = (bit 8-15) - custom station id p2 = (bit 16-31) - station ID to join (INVALID_STATION if build new one)

Definition at line 858 of file station_cmd.cpp.

References _settings_game, Station::AddFacility(), AddTrackToSignalBuffer(), StationSettings::adjacent_stations, AllocaM, AllocateSpecToStation(), SmallVector< T, S >::Append(), AXIS_X, AxisToTrack(), StationRect::BeforeAddRect(), Station::cached_anim_triggers, CALLBACK_FAILED, PoolItem< T, Tid, Tpool >::CanAllocateItem(), CBID_STATION_AVAILABILITY, CBID_STATION_TILE_LAYOUT, CBM_STATION_AVAIL, CheckFlatLandBelow(), CheckIfAuthorityAllowsNewStation(), CMD_ERROR, CmdFailed(), DC_EXEC, DeallocateSpecFromStation(), StationSettings::distant_join_stations, FreeTrainTrackReservation(), GB(), GetClosestDeletedStation(), CommandCost::GetCost(), GetCustomStationSpec(), GetNumStationClasses(), GetRailwayStationReservation(), GetTrainForReservation(), GetVehicleTrackdir(), HasBit(), PoolItem< T, Tid, Tpool >::index, INVALID_TILE, InvalidateWindowData(), InvalidateWindowWidget(), IsTileType(), StationSettings::join_stations, SmallVector< T, S >::Length(), Station::MarkTilesDirty(), StationSettings::nonuniform_stations, Station::owner, Station::rect, return_cmd_error, ReverseTrackdir(), SetBit(), SetRailwayStationPlatformReservation(), GameSettings::station, StationSettings::station_spread, Station::string_id, SVW_TRAINS, TileDiffXY(), Station::town, TrackdirToExitdir(), Station::train_tile, Station::trainst_h, Station::trainst_w, TryPathReserve(), UpdateStationAcceptance(), UpdateStationVirtCoordDirty(), ValParamRailtype(), and YapfNotifyTrackLayoutChange().

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

Build a bus or truck stop.

Parameters:

  | tile | tile to build the stop at
  | flags | operation to perform
  | p1 | entrance direction (DiagDirection)
  | p2 | bit 0: 0 for Bus stops, 1 for truck stops bit 1: 0 for normal, 1 for drive-through bit 2..3: the roadtypes bit 5: allow stations directly adjacent to other stations. bit 16..31: station ID to join (INVALID_STATION if build new one)

Definition at line 1355 of file station_cmd.cpp.

References _settings_game, CommandCost::AddCost(), Station::AddFacility(), StationSettings::adjacent_stations, AreValidRoadTypes(), AXIS_X, StationRect::BeforeAddTile(), PoolItem< T, Tid, Tpool >::CanAllocateItem(), CheckFlatLandBelow(), CheckIfAuthorityAllowsNewStation(), CMD_ERROR, CmdFailed(), GameSettings::construction, CountBits(), StationSettings::distant_join_stations, FindRoadStopSpot(), GB(), GetAllRoadBits(), GetClosestDeletedStation(), HasBit(), HasRoadTypesAvail(), PoolItem< T, Tid, Tpool >::index, InvalidateWindowData(), InvalidateWindowWidget(), IsValidAxis(), IsValidDiagDirection(), RoadStop::LIMIT, Station::owner, OWNER_NONE, OWNER_TOWN, Station::rect, return_cmd_error, ConstructionSettings::road_stop_on_competitor_road, ConstructionSettings::road_stop_on_town_road, ROAD_X, ROAD_Y, ROADSTOP_BUS, ROADSTOP_TRUCK, ROADTYPE_ROAD, ROADTYPE_TRAM, ROADTYPES_NONE, SetBit(), Station::sign, GameSettings::station, Station::string_id, SVW_ROADVEHS, Station::town, UpdateStationAcceptance(), and UpdateStationVirtCoordDirty().

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

Remove a single tile from a railroad station.

This allows for custom-built station with holes and weird layouts

Parameters:

  | tile | tile of station piece to remove
  | flags | operation to perform
  | p1 | start_tile
  | p2 | unused

Definition at line 1152 of file station_cmd.cpp.

References _settings_game, AddTrackToSignalBuffer(), StationRect::AfterRemoveTile(), BEGIN_TILE_LOOP, CMD_ERROR, DC_EXEC, DeallocateSpecFromStation(), DeleteStationIfEmpty(), END_TILE_LOOP, Station::facilities, FreeTrainTrackReservation(), GetRailwayStationReservation(), GetTileOwner(), GetTrainForReservation(), GetVehicleTrackdir(), PoolItem< T, Tid, Tpool >::index, INVALID_TILE, InvalidateWindowWidget(), IsTileType(), MapSize(), Station::MarkTilesDirty(), StationSettings::nonuniform_stations, Station::owner, OWNER_WATER, Station::rect, return_cmd_error, ReverseTrackdir(), SetRailwayStationPlatformReservation(), GameSettings::station, SVW_TRAINS, Swap(), TileX(), TileXY(), TileY(), TrackdirToExitdir(), Station::train_tile, TryPathReserve(), UpdateStationVirtCoordDirty(), and YapfNotifyTrackLayoutChange().

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

Remove a bus or truck stop.

Parameters:

  | tile | tile to remove the stop from
  | flags | operation to perform
  | p1 | not used
  | p2 | bit 0: 0 for Bus stops, 1 for truck stops

Definition at line 1581 of file station_cmd.cpp.

References CMD_ERROR, CmdSucceeded(), DIAGDIR_NE, DiagDirToRoadBits(), GB(), GetRoadStopDir(), IsRoadStop(), IsTileType(), RemoveRoadStop(), ROAD_X, ROAD_Y, ROADTYPE_ROAD, and ROADTYPE_TRAM.

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

Rename a station.

Parameters:

  | tile | unused
  | flags | operation to perform
  | p1 | station ID that is to be renamed
  | p2 | unused

Definition at line 2902 of file station_cmd.cpp.

References CMD_ERROR, InvalidateWindowData(), MarkWholeScreenDirty(), MAX_LENGTH_STATION_NAME_BYTES, Station::name, Station::owner, return_cmd_error, StrEmpty(), and UpdateStationVirtCoord().

static bool CMSAForest | ( | TileIndex | tile | ) | `[static]`

Check whether the tile is a forest.

Parameters:

  | tile | the tile to investigate.

Returns:
  true if and only if the tile is a mine

Definition at line 187 of file station_cmd.cpp.

References GetIndustryByTile(), GetIndustrySpec(), INDUSTRYLIFE_ORGANIC, IsTileType(), lengthof, IndustrySpec::life_type, MP_INDUSTRY, Industry::produced_cargo, and Industry::type.

static bool CMSAMine | ( | TileIndex | tile | ) | `[static]`

Check whether the tile is a mine.

Parameters:

  | tile | the tile to investigate.

Returns:
  true if and only if the tile is a mine

Definition at line 140 of file station_cmd.cpp.

References CC_LIQUID, CC_MAIL, CC_PASSENGERS, GetIndustryByTile(), GetIndustrySpec(), INDUSTRYLIFE_EXTRACTIVE, IsTileType(), lengthof, IndustrySpec::life_type, MP_INDUSTRY, Industry::produced_cargo, and Industry::type.

static bool CMSATree | ( | TileIndex | tile | ) | `[static]`

Check whether the tile is a tree.

Parameters:

  | tile | the tile to investigate.

Returns:
  true if and only if the tile is a mine

Definition at line 177 of file station_cmd.cpp.

References IsTileType(), and MP_TREES.

static bool CMSAWater | ( | TileIndex | tile | ) | `[static]`

Check whether the tile is water.

Parameters:

  | tile | the tile to investigate.

Returns:
  true if and only if the tile is a mine

Definition at line 167 of file station_cmd.cpp.

References IsTileType(), IsWater(), and MP_WATER.

static int CountMapSquareAround | ( | TileIndex | tile,
|  | CMSAMatcher | cmp |
| ) |  |  | `[static]`

Counts the numbers of tiles matching a specific type in the area around.

Parameters:

  | tile | the center tile of the 'count area'
  | type | the type of tile searched for
  | industry | when type == MP_INDUSTRY, the type of the industry, in all other cases this parameter is ignored

Returns:
  the result the noumber of matching tiles around

Definition at line 121 of file station_cmd.cpp.

References INVALID_TILE, and TileAddWrap().

static void DeleteStationIfEmpty | ( | Station * | st | ) | `[static]`

This is called right after a station was deleted.

It checks if the whole station is free of substations, and if so, the station will be deleted after a little while.

Parameters:

  | st | Station

Definition at line 644 of file station_cmd.cpp.

References Station::delete_ctr, Station::facilities, InvalidateWindowData(), and Station::owner.

Referenced by CmdRemoveFromRailroadStation(), and RemoveRoadStop().

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

Find a station action 0 property 24 station name, or reduce the free_names if needed.

Parameters:

  | tile | the tile to search
  | user_data | the StationNameInformation to base the search on

Returns:
  true if the tile contains an industry that has not given it's name to one of the other stations in town.

Definition at line 231 of file station_cmd.cpp.

References StationNameInformation::free_names, GetIndustrySpec(), GetIndustryType(), StationNameInformation::indtypes, IsTileType(), M, and MP_INDUSTRY.

static RoadStop** FindRoadStopSpot | ( | bool | truck_station,
|  | Station * | st |
| ) |  |  | `[static]`

Parameters:

  | truck_station | Determines whether a stop is ROADSTOP_BUS or ROADSTOP_TRUCK
  | st | The Station to do the whole procedure for

Returns:
  a pointer to where to link a new RoadStop*

Definition at line 1330 of file station_cmd.cpp.

References Station::bus_stops, RoadStop::next, and Station::truck_stops.

Referenced by CmdBuildRoadStop().

void FindStationsAroundTiles | ( | TileIndex | tile,
|  | int | w_prod,
|  | int | h_prod,
|  | StationList * | stations |
| ) |  |  |

Find all (non-buoy) stations around a rectangular producer (industry, house, headquarter, .

..)

Parameters:

  | tile | North tile of producer
  | w_prod | X extent of producer
  | h_prod | Y extent of producer

Returns:
  : Set of found stations

Definition at line 2937 of file station_cmd.cpp.

References _settings_game, CA_UNMODIFIED, Station::GetCatchmentRadius(), SmallVector< T, S >::Include(), INVALID_TILE, Station::IsBuoy(), IsTileType(), MAX_CATCHMENT, StationSettings::modified_catchment, GameSettings::station, and TileAddWrap().

Referenced by AIIndustry::GetAmountOfStationsAround(), and WhoCanServiceIndustry().

void GetAcceptanceAroundTiles | ( | AcceptedCargo | accepts,
|  | TileIndex | tile,
|  | int | w,
|  | int | h,
|  | int | rad |
| ) |  |  |

Get a list of the cargo types that are accepted around the tile.

Parameters:

  | accepts | Destination array of accepted cargo
  | tile | Center of the search area
  | w | X extent of area
  | h | Y extent of area
  | rad | Search radius in addition to given area

Definition at line 507 of file station_cmd.cpp.

References IsTileType(), lengthof, MapSizeX(), MapSizeY(), max(), min(), TileX(), TileXY(), and TileY().

Referenced by AITileList_IndustryAccepting::AITileList_IndustryAccepting(), DrawStationCoverageAreaText(), AITile::GetCargoAcceptance(), and UpdateStationAcceptance().

static uint GetAcceptanceMask | ( | const Station * | st | ) | `[static]`

Get a mask of the cargo types that the station accepts.

Parameters:

  | st | Station to query

Returns:
  the expected mask

Definition at line 427 of file station_cmd.cpp.

References Station::goods, and HasBit().

Referenced by UpdateStationAcceptance().

uint8 GetAirportNoiseLevelForTown | ( | const AirportFTAClass * | afc,
|  | TileIndex | town_tile,
|  | TileIndex | tile |
| ) |  |  |

Get a possible noise reduction factor based on distance from town center.

The further you get, the less noise you generate. So all those folks at city council can now happily slee... work in their offices

Parameters:

  | afc | AirportFTAClass pointer of the class being proposed
  | town_tile | TileIndex of town's center, the one who will receive the airport's candidature
  | tile | TileIndex of northern tile of an airport (present or to-be-built), NOT the station tile

Returns:
  the noise that will be generated, according to distance

Definition at line 1737 of file station_cmd.cpp.

References _settings_game, GameSettings::difficulty, GetMinimalAirportDistanceToTile(), AirportFTAClass::noise_level, and DifficultySettings::town_council_tolerance.

Referenced by CmdBuildAirport(), AIAirport::GetNoiseLevelIncrease(), and UpdateAirportsNoise().

static Station* GetClosestDeletedStation | ( | TileIndex | tile | ) | `[static]`

Find the closest deleted station of the current company.

Parameters:

  | tile | the tile to search from.

Returns:
  the closest station or NULL if too far.

Definition at line 363 of file station_cmd.cpp.

References DistanceManhattan(), Station::facilities, Station::owner, and Station::xy.

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

static uint GetMinimalAirportDistanceToTile | ( | const AirportFTAClass * | afc,
|  | TileIndex | town_tile,
|  | TileIndex | airport_tile |
| ) |  |  | `[static]`

Computes the minimal distance from town's xy to any airport's tile.

Parameters:

  | afc | airport's description
  | town_tile | town's tile (t->xy)
  | airport_tile | st->airport_tile

Returns:
  minimal manhattan distance from town_tile to any airport's tile

Definition at line 1709 of file station_cmd.cpp.

References AirportFTAClass::size_x, AirportFTAClass::size_y, TileX(), and TileY().

Referenced by AirportGetNearestTown(), and GetAirportNoiseLevelForTown().

void GetProductionAroundTiles | ( | AcceptedCargo | produced,
|  | TileIndex | tile,
|  | int | w,
|  | int | h,
|  | int | rad |
| ) |  |  |

Get a list of the cargo types being produced around the tile (in a rectangle).

Parameters:

  | produced | Destination array of produced cargo
  | tile | Northtile of area
  | w | X extent of the area
  | h | Y extent of the area
  | rad | Search radius in addition to the given area

Definition at line 458 of file station_cmd.cpp.

References _tile_type_procs, TileTypeProcs::get_produced_cargo_proc, GetTileType(), IsTileType(), lengthof, MapSizeX(), MapSizeY(), max(), min(), TileX(), TileXY(), and TileY().

Referenced by AITileList_IndustryProducing::AITileList_IndustryProducing(), DrawStationCoverageAreaText(), and AITile::GetCargoProduction().

bool HasStationInUse | ( | StationID | station,
|  | CompanyID | company |
| ) |  |  |

Tests whether the company's vehicles have this station in orders When company == INVALID_COMPANY, then check all vehicles.

Parameters:

  | station | station ID
  | company | company ID, INVALID_COMPANY to disable the check

Definition at line 2071 of file station_cmd.cpp.

References INVALID_COMPANY.

Referenced by CompanyStationsWindow::BuildStationsList().

bool IsHangar | ( | TileIndex | t | ) |

Check whether the given tile is a hangar.

Parameters:

  | t | the tile to of whether it is a hangar.

Precondition:
  IsTileType(t, MP_STATION)

Returns:
  true if and only if the tile is a hangar.

Definition at line 48 of file station_cmd.cpp.

References Station::Airport(), AirportFTAClass::airport_depots, Station::airport_tile, IsTileType(), MP_STATION, AirportFTAClass::nof_depots, and ToTileIndexDiff().

Referenced by AIOrder::GetOrderDestination(), GetOrderTypeByTile(), and AIAirport::IsHangarTile().

static CommandCost RemoveRoadStop | ( | Station * | st,
|  | DoCommandFlag | flags,
|  | TileIndex | tile |
| ) |  |  | `[static]`

Remove a bus station.

Parameters:

  | st | Station to remove
  | flags | operation to perform
  | tile | TileIndex been queried

Returns:
  cost or failure of operation

Definition at line 1508 of file station_cmd.cpp.

References StationRect::AfterRemoveTile(), Station::bus_stops, CMD_ERROR, DC_BANKRUPT, DeleteStationIfEmpty(), Station::facilities, FindVehicleOnPos(), PoolItem< T, Tid, Tpool >::index, InvalidateWindowWidget(), IsTruckStop(), RoadStop::next, Station::owner, OWNER_WATER, Station::rect, ROADSTOP_BUS, ROADSTOP_TRUCK, SVW_ROADVEHS, Station::truck_stops, and UpdateStationVirtCoordDirty().

Referenced by CmdRemoveRoadStop().

static void ShowRejectOrAcceptNews | ( | const Station * | st,
|  | uint | num_items,
|  | CargoID * | cargo,
|  | StringID | msg |
| ) |  |  | `[static]`

Items contains the two cargo names that are to be accepted or rejected.

msg is the string id of the message to display.

Definition at line 440 of file station_cmd.cpp.

References AddNewsItem(), PoolItem< T, Tid, Tpool >::index, NS_ACCEPTANCE, and Station::xy.

Referenced by UpdateStationAcceptance().

static void StationHandleBigTick | ( | Station * | st | ) | `[static]`

This function is called for each station once every 250 ticks.

Not all stations will get the tick at the same time.

Parameters:

  | st | the station receiving the tick.

Definition at line 2697 of file station_cmd.cpp.

References Station::delete_ctr, Station::facilities, and UpdateStationAcceptance().

void UpdateAllStationVirtCoord | ( |  | ) |

Update the virtual coords needed to draw the station sign for all stations.

Definition at line 399 of file station_cmd.cpp.

References UpdateStationVirtCoord().

Referenced by CmdRenameTown(), and InitializeWindowsAndCaches().

static void UpdateStationAcceptance | ( | Station * | st,
|  | bool | show_msg |
| ) |  |  | `[static]`

Update the acceptance for a station.

Parameters:

  | st | Station to update
  | show_msg | controls whether to display a message that acceptance was changed.

Definition at line 545 of file station_cmd.cpp.

References Rect::bottom, CC_PASSENGERS, Station::facilities, GetAcceptanceAroundTiles(), GetAcceptanceMask(), Station::GetCatchmentRadius(), Station::goods, HasBit(), PoolItem< T, Tid, Tpool >::index, InvalidateWindowWidget(), Station::IsBuoy(), StationRect::IsEmpty(), Rect::left, lengthof, min(), Station::owner, Station::rect, Rect::right, SB(), ShowRejectOrAcceptNews(), SVW_ACCEPTLIST, TileXY(), and Rect::top.

Referenced by CmdBuildAirport(), CmdBuildBuoy(), CmdBuildDock(), CmdBuildRailroadStation(), CmdBuildRoadStop(), and StationHandleBigTick().

static void UpdateStationVirtCoord | ( | Station * | st | ) | `[static]`

Update the virtual coords needed to draw the station sign.

Parameters:

  | st | Station to update for.

Definition at line 386 of file station_cmd.cpp.

References Station::airport_type, Station::facilities, PoolItem< T, Tid, Tpool >::index, Station::sign, TILE_SIZE, TileX(), TileY(), Point::x, Station::xy, and Point::y.

Referenced by CmdRenameStation(), UpdateAllStationVirtCoord(), and UpdateStationVirtCoordDirty().

## Variable Documentation

const byte* const _airport_sections[]`[static]`

Initial value:

     {
      _airport_sections_country,
      _airport_sections_town,
      _airport_sections_heliport,
      _airport_sections_metropolitan,
      _airport_sections_international,
      _airport_sections_commuter,
      _airport_sections_helidepot,
      _airport_sections_intercontinental,
      _airport_sections_helistation
    }

Definition at line 1690 of file station_cmd.cpp.

const byte _airport_sections_commuter[]`[static]`

Initial value:

     {
      85, 30, 115, 115, 32,
      87, 8,    8,   8, 10,
      87, 11,  11,  11, 10,
      26, 23,  23,  23, 26
    }

Definition at line 1666 of file station_cmd.cpp.

const byte _airport_sections_country[]`[static]`

Initial value:

     {
      54, 53, 52, 65,
      58, 57, 56, 55,
      64, 63, 63, 62
    }

Definition at line 1612 of file station_cmd.cpp.

const byte _airport_sections_helidepot[]`[static]`

Initial value:

     {
      124, 32,
      122, 123
    }

Definition at line 1679 of file station_cmd.cpp.

const byte _airport_sections_heliport[]`[static]`

Initial value:

     {
      66,
    }

Definition at line 1674 of file station_cmd.cpp.

const byte _airport_sections_helistation[]`[static]`

Initial value:

     {
       32, 134, 159, 158,
      161, 142, 142, 157
    }

Definition at line 1685 of file station_cmd.cpp.

const byte _airport_sections_intercontinental[]`[static]`

Initial value:

     {
      102, 120,  89,  89,  89,  89,  89,  89, 118,
      120,  23,  23,  23,  23,  23,  23, 119, 117,
       87,  54,  87,   8,   8,   8,   8,  51, 117,
       87, 162,  87,  85, 116, 116,   8,   9,  10,
       87,   8,   8,  11,  31,  11,   8, 160,  32,
       32, 160,   8,  11,  27,  11,   8,   8,  10,
       87,   8,   8,  11,  30,  11,   8,   8,  10,
       87, 142,   8,  11,  29,  11,  10, 163,  10,
       87, 164,  87,   8,   8,   8,  10,  37, 117,
       87, 120,  89,  89,  89,  89,  89,  89, 119,
      121,  23,  23,  23,  23,  23,  23, 119,  37
    }

Definition at line 1650 of file station_cmd.cpp.

const byte _airport_sections_international[]`[static]`

Initial value:

     {
      88, 89, 89, 89, 89, 89,  88,
      51,  8,  8,  8,  8,  8,  32,
      30,  8, 11, 27, 11,  8,  10,
      32,  8, 11, 27, 11,  8, 114,
      87,  8, 11, 85, 11,  8, 114,
      87,  8,  8,  8,  8,  8,  90,
      26, 23, 23, 23, 23, 23,  26
    }

Definition at line 1639 of file station_cmd.cpp.

const byte _airport_sections_metropolitan[]`[static]`

Initial value:

     {
       31,  9, 33,  9,  9, 32,
       27, 36, 29, 34,  8, 10,
       30, 11, 35, 13, 20, 21,
      102,  8,  8,  8,  8, 28,
       83, 84, 84, 84, 84, 83,
       26, 23, 23, 23, 23, 26
    }

Definition at line 1629 of file station_cmd.cpp.

const byte _airport_sections_town[]`[static]`

Initial value:

     {
      31,  9, 33,  9,  9, 32,
      27, 36, 29, 34,  8, 10,
      30, 11, 35, 13, 20, 21,
      51, 12, 14, 17, 19, 28,
      38, 13, 15, 16, 18, 39,
      26, 22, 23, 24, 25, 26
    }

Definition at line 1619 of file station_cmd.cpp.

const TileIndexDiffC _dock_tileoffs_chkaround[]`[static]`

Initial value:

     {
      {-1,  0},
      { 0,  0},
      { 0,  0},
      { 0, -1}
    }

Definition at line 2120 of file station_cmd.cpp.

const TileTypeProcs _tile_type_station_procs

Initial value:

     {
      DrawTile_Station,
      GetSlopeZ_Station,
      ClearTile_Station,
      GetAcceptedCargo_Station,
      GetTileDesc_Station,
      GetTileTrackStatus_Station,
      ClickTile_Station,
      AnimateTile_Station,
      TileLoop_Station,
      ChangeTileOwner_Station,
      NULL,
      VehicleEnter_Station,
      GetFoundation_Station,
      TerraformTile_Station,
    }