OpenTTD: src/station_func.h File Reference

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

Functions
station_func.h File Reference

Functions related to stations. More...

`#include "sprite.h"`
`#include "rail_type.h"`
`#include "road_type.h"`
`#include "vehicle_type.h"`
`#include "economy_func.h"`
`#include "rail.h"`
`#include "linkgraph/linkgraph_type.h"`

Go to the source code of this file.

## Functions
void | ModifyStationRatingAround (TileIndex tile, Owner owner, int amount, uint radius)
void | FindStationsAroundTiles (const TileArea &location, StationList *stations)
| Find all stations around a rectangular producer (industry, house, headquarter, ...)
void | ShowStationViewWindow (StationID station)
| Opens StationViewWindow for given station.
void | UpdateAllStationVirtCoords ()
| Update the virtual coords needed to draw the station sign for all stations.
CargoArray | GetProductionAroundTiles (TileIndex tile, int w, int h, int rad)
| Get the cargo types being produced around the tile (in a rectangle).
CargoArray | GetAcceptanceAroundTiles (TileIndex tile, int w, int h, int rad, uint32 *always_accepted=NULL)
| Get the acceptance of cargoes around the tile in 1/8.
void | UpdateStationAcceptance (Station *st, bool show_msg)
| Update the acceptance for a station.
const DrawTileSprites * | GetStationTileLayout (StationType st, byte gfx)
void | StationPickerDrawSprite (int x, int y, StationType st, RailType railtype, RoadType roadtype, int image)
bool | HasStationInUse (StationID station, bool include_company, CompanyID company)
| Tests whether the company's vehicles have this station in orders.
void | DeleteOilRig (TileIndex t)
bool | IsStationTileBlocked (TileIndex tile)
| Check whether a rail station tile is NOT traversable.
bool | CanStationTileHavePylons (TileIndex tile)
| Check if a rail station tile shall have pylons when electrified.
bool | CanStationTileHaveWires (TileIndex tile)
| Check if a rail station tile shall have wires when electrified.
void | UpdateAirportsNoise ()
| Recalculate the noise generated by the airports of each town.
bool | SplitGroundSpriteForOverlay (const TileInfo *ti, SpriteID *ground, RailTrackOffset *overlay_offset)
| Check whether a sprite is a track sprite, which can be replaced by a non-track ground sprite and a rail overlay.
void | IncreaseStats (Station *st, const Vehicle *v, StationID next_station_id)
| Increase capacity for all link stats associated with vehicles in the given consist.
void | IncreaseStats (Station *st, CargoID cargo, StationID next_station_id, uint capacity, uint usage, EdgeUpdateMode mode)
| Increase capacity for a link stat given by station cargo and next hop.
void | RerouteCargo (Station *st, CargoID c, StationID avoid, StationID avoid2)
| Reroute cargo of type c at station st or in any vehicles unloading there.
static Money | StationMaintenanceCost (uint32 num)
| Calculates the maintenance cost of a number of station tiles.
Money | AirportMaintenanceCost (Owner owner)
| Calculates the maintenance cost of all airports of a company.

## Detailed Description

Functions related to stations.

Definition in file station_func.h.

## Function Documentation

Money AirportMaintenanceCost | ( | Owner | owner | ) |

Calculates the maintenance cost of all airports of a company.

Parameters

  owner | Company.

Returns
  Total cost.

Definition at line 558 of file station.cpp.

References Station::airport, FACIL_AIRPORT, BaseStation::facilities, Airport::GetSpec(), AirportSpec::maintenance_cost, and BaseStation::owner.

Referenced by CompaniesGenStatistics(), CompanyInfrastructureWindow::DrawWidget(), CompanyInfrastructureWindow::GetTotalMaintenanceCost(), and CompanyInfrastructureWindow::UpdateWidgetSize().

bool CanStationTileHavePylons | ( | TileIndex | tile | ) |

Check if a rail station tile shall have pylons when electrified.

Parameters

  tile | Tile to test.

Returns
  Tile shall have pylons.

Note
  This could be cached (during build) in the map array to save on all the dereferencing.

Definition at line 888 of file newgrf_station.cpp.

References GetStationGfx(), HasBit(), and StationSpec::pylons.

Referenced by DrawCatenaryRailway().

bool CanStationTileHaveWires | ( | TileIndex | tile | ) |

Check if a rail station tile shall have wires when electrified.

Parameters

  tile | Tile to test.

Returns
  Tile shall have wires.

Note
  This could be cached (during build) in the map array to save on all the dereferencing.

Definition at line 902 of file newgrf_station.cpp.

References GetStationGfx(), HasBit(), and StationSpec::wires.

Referenced by DrawCatenaryRailway(), and MaskWireBits().

void FindStationsAroundTiles | ( | const TileArea & | location,
|  | StationList * | stations
| ) |  |

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

Parameters

  location | The location/area of the producer
  stations | The list to store the stations in

Definition at line 3764 of file station_cmd.cpp.

References _settings_game, CA_UNMODIFIED, GameSettings::construction, ConstructionSettings::freeform_edges, SpecializedStation< Station, false >::GetByTile(), Station::GetCatchmentRadius(), OrthogonalTileArea::h, SmallVector< T, S >::Include(), IsTileType(), MapSizeX(), MapSizeY(), MAX_CATCHMENT, StationSettings::modified_catchment, MP_STATION, GameSettings::station, OrthogonalTileArea::tile, TileX(), TileXY(), TileY(), and OrthogonalTileArea::w.

Referenced by StationFinder::GetStations(), and WhoCanServiceIndustry().

CargoArray GetAcceptanceAroundTiles | ( | TileIndex | tile,
|  | int | w,
|  | int | h,
|  | int | rad,
|  | uint32 * | always_accepted
| ) |  |

Get the acceptance of cargoes around the tile in 1/8.

Parameters

  tile | Center of the search area
  w | X extent of area
  h | Y extent of area
  rad | Search radius in addition to given area
  always_accepted | bitmask of cargo accepted by houses and headquarters; can be NULL

Definition at line 520 of file station_cmd.cpp.

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

Referenced by DrawStationCoverageAreaText(), and UpdateStationAcceptance().

CargoArray GetProductionAroundTiles | ( | TileIndex | tile,
|  | int | w,
|  | int | h,
|  | int | rad
| ) |  |

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

Parameters

  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 467 of file station_cmd.cpp.

References CT_INVALID, OrthogonalTileArea::Intersects(), lengthof, Industry::location, MapSizeX(), MapSizeY(), max(), min(), Industry::produced_cargo, TILE_AREA_LOOP, TileX(), TileXY(), and TileY().

Referenced by DrawStationCoverageAreaText().

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

Tests whether the company's vehicles have this station in orders.

Parameters

  station | station ID
  include_company | If true only check vehicles of company, if false only check vehicles of other companies
  company | company ID

Definition at line 2439 of file station_cmd.cpp.

References FOR_ALL_VEHICLES, Order::GetDestination(), Order::IsType(), and Vehicle::owner.

Referenced by CompanyStationsWindow::BuildStationsList(), and RemoveBuoy().

void IncreaseStats | ( | Station * | st,
|  | const Vehicle * | front,
|  | StationID | next_station_id
| ) |  |

Increase capacity for all link stats associated with vehicles in the given consist.

Parameters

  st | Station to get the link stats from.
  front | First vehicle in the consist.
  next_station_id | Station the consist will be travelling to next.

Definition at line 3581 of file station_cmd.cpp.

References Vehicle::cargo, Vehicle::cargo_type, EUM_INCREASE, IncreaseStats(), min(), Vehicle::Next(), Vehicle::refit_cap, and VehicleCargoList::StoredCount().

void IncreaseStats | ( | Station * | st,
|  | CargoID | cargo,
|  | StationID | next_station_id,
|  | uint | capacity,
|  | uint | usage,
|  | EdgeUpdateMode | mode
| ) |  |

Increase capacity for a link stat given by station cargo and next hop.

Parameters

  st | Station to get the link stats from.
  cargo | Cargo to increase stat for.
  next_station_id | Station the consist will be travelling to next.
  capacity | Capacity to add to link stat.
  usage | Usage to add to link stat.
  mode | Update mode to be applied.

Definition at line 3529 of file station_cmd.cpp.

References LinkGraph::AddNode(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_link_graph_pool >::CanAllocateItem(), DEBUG, SpecializedStation< Station, false >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_link_graph_pool >::Get(), Station::goods, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, LinkGraphSchedule::Instance(), GoodsEntry::link_graph, LinkGraph::Merge(), GoodsEntry::node, LinkGraphSchedule::Queue(), LinkGraph::Size(), and LinkGraphSchedule::Unqueue().

Referenced by Vehicle::BeginLoading(), IncreaseStats(), and LinkRefresher::RefreshStats().

bool IsStationTileBlocked | ( | TileIndex | tile | ) |

Check whether a rail station tile is NOT traversable.

Parameters

  tile | Tile to test.

Returns
  Station tile is blocked.

Note
  This could be cached (during build) in the map array to save on all the dereferencing.

Definition at line 875 of file newgrf_station.cpp.

References StationSpec::blocked, GetStationGfx(), and HasBit().

Referenced by AfterLoadCompanyStats(), AfterLoadGame(), CmdBuildRailStation(), CmdConvertRail(), ExploreSegment(), IsCompatibleTrainStationTile(), RemoveFromRailBaseStation(), and RemoveRailStation().

void RerouteCargo | ( | Station * | st,
|  | CargoID | c,
|  | StationID | avoid,
|  | StationID | avoid2
| ) |  |

Reroute cargo of type c at station st or in any vehicles unloading there.

Make sure the cargo's new next hop is neither "avoid" nor "avoid2".

Parameters

  st | Station to be rerouted at.
  c | Type of cargo.
  avoid | Original next hop of cargo, avoid this.
  avoid2 | Another station to be avoided when rerouting.

Definition at line 3430 of file station_cmd.cpp.

References Vehicle::cargo, GoodsEntry::cargo, Vehicle::cargo_type, Station::goods, Vehicle::Next(), VehicleCargoList::Reroute(), and StationCargoList::Reroute().

Referenced by DeleteStaleLinks(), LinkGraphJob::~LinkGraphJob(), and Station::~Station().

void ShowStationViewWindow | ( | StationID | station | ) |

Opens StationViewWindow for given station.

Parameters

  station | station which window should be opened

Definition at line 2110 of file station_gui.cpp.

bool SplitGroundSpriteForOverlay | ( | const TileInfo * | ti,
|  | SpriteID * | ground,
|  | RailTrackOffset * | overlay_offset
| ) |  |

Check whether a sprite is a track sprite, which can be replaced by a non-track ground sprite and a rail overlay.

If the ground sprite is suitable, ground is replaced with the new non-track ground sprite, and overlay_offset is set to the overlay to draw.

Parameters

  | ti | Positional info for the tile to decide snowyness etc. May be NULL.
  [in,out] | ground | Groundsprite to draw.
  [out] | overlay_offset | Overlay to draw.

Returns
  true if overlay can be drawn.

Definition at line 2635 of file station_cmd.cpp.

References _settings_game, GameSettings::game_creation, GetSnowLine(), GetTropicZone(), GameCreationSettings::landscape, RTO_X, RTO_Y, TileInfo::tile, TILE_HEIGHT, TROPICZONE_DESERT, and TileInfo::z.

Referenced by DrawStationTile().

static Money StationMaintenanceCost | ( | uint32 | num | ) |
| inlinestatic

Calculates the maintenance cost of a number of station tiles.

Parameters

  num | Number of station tiles.

Returns
  Total cost.

Definition at line 61 of file station_func.h.

References IntSqrt().

Referenced by CompaniesGenStatistics(), CompanyInfrastructureWindow::DrawWidget(), CompanyInfrastructureWindow::GetTotalMaintenanceCost(), and CompanyInfrastructureWindow::UpdateWidgetSize().

void UpdateAllStationVirtCoords | ( |  | ) |

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

Definition at line 422 of file station_cmd.cpp.

References BaseStation::UpdateVirtCoord().

Referenced by CmdRenameTown(), and UpdateAllVirtCoords().

void UpdateStationAcceptance | ( | Station * | st,
|  | bool | show_msg
| ) |  |

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 555 of file station_cmd.cpp.

References _local_company, Station::always_accepted, CC_PASSENGERS, CT_INVALID, FACIL_BUS_STOP, FACIL_TRUCK_STOP, BaseStation::facilities, GoodsEntry::GES_ACCEPTANCE, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_link_graph_pool >::Get(), GetAcceptanceAroundTiles(), GetAcceptanceMask(), Station::GetCatchmentRadius(), Station::goods, HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, IsCargoInClass(), BaseStation::IsInUse(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_link_graph_pool >::IsValidID(), lengthof, GoodsEntry::link_graph, GoodsEntry::node, NUM_CARGO, BaseStation::owner, BaseStation::rect, SB(), SetWindowWidgetDirty(), ShowRejectOrAcceptNews(), GoodsEntry::status, TileXY(), WC_STATION_VIEW, and WID_SV_ACCEPT_RATING_LIST.

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