OpenTTD Source 20260208-master-g43af8e94d0
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 "road.h"
#include "linkgraph/linkgraph_type.h"
#include "industry_type.h"

Go to the source code of this file.

Functions

void ModifyStationRatingAround (TileIndex tile, Owner owner, int amount, uint radius)
 Forcibly modify station ratings near a given tile.
void ShowStationViewWindow (StationID station)
 Opens StationViewWindow for given station.
void UpdateAllStationVirtCoords ()
 Update the virtual coords needed to draw the station sign for all stations.
void ClearAllStationCachedNames ()
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, CargoTypes *always_accepted=nullptr)
 Get the acceptance of cargoes around the tile in 1/8.
void UpdateStationAcceptance (Station *st, bool show_msg)
 Update the acceptance for a station.
CargoTypes GetAcceptanceMask (const Station *st)
 Get a mask of the cargo types that the station accepts.
CargoTypes GetEmptyMask (const Station *st)
 Get a mask of the cargo types that are empty at the station.
void SetRailStationTileFlags (TileIndex tile, const StationSpec *statspec)
 Set rail station tile flags for the given tile.
const DrawTileSpritesGetStationTileLayout (StationType st, uint8_t gfx)
 Get station tile layout for a station type and its station 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)
void UpdateStationDockingTiles (Station *st)
void RemoveDockingTile (TileIndex t)
void ClearDockingTilesCheckingNeighbours (TileIndex tile)
 Clear docking tile status from tiles around a removed dock, if the tile has no neighbours which would keep it as a docking tile.
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, uint32_t time)
 Increase capacity for all link stats associated with vehicles in the given consist.
void IncreaseStats (Station *st, CargoType cargo, StationID next_station_id, uint capacity, uint usage, uint32_t time, EdgeUpdateModes modes)
 Increase capacity for a link stat given by station cargo and next hop.
void RerouteCargo (Station *st, CargoType cargo, StationID avoid, StationID avoid2)
 Reroute cargo of type c at station st or in any vehicles unloading there.
Money StationMaintenanceCost (uint32_t 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

◆ AirportMaintenanceCost()

Money AirportMaintenanceCost ( Owner owner)

Calculates the maintenance cost of all airports of a company.

Parameters
ownerCompany.
Returns
Total cost.

Definition at line 713 of file station.cpp.

References Airport, BaseStation::facilities, InfrastructureAirport, SpecializedStation< Station, false >::Iterate(), BaseStation::owner, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by CompaniesGenStatistics().

◆ ClearAllStationCachedNames()

void ClearAllStationCachedNames ( )

Definition at line 477 of file station_cmd.cpp.

◆ ClearDockingTilesCheckingNeighbours()

void ClearDockingTilesCheckingNeighbours ( TileIndex tile)

Clear docking tile status from tiles around a removed dock, if the tile has no neighbours which would keep it as a docking tile.

Parameters
tileEx-dock tile to check.

Definition at line 3004 of file station_cmd.cpp.

References CheckForDockingTile(), DIAGDIR_BEGIN, DIAGDIR_END, IsValidTile(), SetDockingTile(), and TileOffsByDiagDir().

Referenced by RemoveDock().

◆ DeleteOilRig()

void DeleteOilRig ( TileIndex t)

Definition at line 4764 of file station_cmd.cpp.

◆ GetAcceptanceAroundTiles()

CargoArray GetAcceptanceAroundTiles ( TileIndex center_tile,
int w,
int h,
int rad,
CargoTypes * always_accepted )

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

Parameters
center_tileCenter of the search area
wX extent of area
hY extent of area
radSearch radius in addition to given area
always_acceptedbitmask of cargo accepted by houses and headquarters; can be nullptr

Definition at line 570 of file station_cmd.cpp.

References _settings_game, OrthogonalTileArea::Expand(), Industry::GetByTile(), Industry, and IsTileType().

Referenced by DrawStationCoverageAreaText().

◆ GetAcceptanceMask()

CargoTypes GetAcceptanceMask ( const Station * st)

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

Parameters
stStation to query
Returns
the expected mask

Definition at line 489 of file station_cmd.cpp.

References GoodsEntry::Acceptance, Station::goods, and SetBit().

Referenced by StationViewWindow::DrawAcceptedCargo(), and UpdateStationAcceptance().

◆ GetEmptyMask()

CargoTypes GetEmptyMask ( const Station * st)

Get a mask of the cargo types that are empty at the station.

Parameters
stStation to query
Returns
the empty mask

Definition at line 504 of file station_cmd.cpp.

References Station::goods, and SetBit().

Referenced by TriggerRoadStopRandomisation(), and TriggerStationRandomisation().

◆ GetProductionAroundTiles()

CargoArray GetProductionAroundTiles ( TileIndex north_tile,
int w,
int h,
int rad )

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

Parameters
north_tileNorthern most tile of area
wX extent of the area
hY extent of the area
radSearch radius in addition to the given area

Definition at line 533 of file station_cmd.cpp.

References _settings_game, OrthogonalTileArea::Expand(), GetIndustryIndex(), Industry, FlatSet< Tkey, Tcompare >::insert(), IsTileType(), IsValidCargoType(), Industry::neutral_station, and Industry::produced.

Referenced by DrawStationCoverageAreaText().

◆ GetStationTileLayout()

const DrawTileSprites * GetStationTileLayout ( StationType st,
uint8_t gfx )

Get station tile layout for a station type and its station gfx.

Parameters
stStation type to draw.
gfxStationGfx of tile to draw.
Returns
Tile layout to draw.

Definition at line 3118 of file station_cmd.cpp.

References to_underlying().

Referenced by DrawStationTile().

◆ HasStationInUse()

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

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

Parameters
stationstation ID
include_companyIf true only check vehicles of company, if false only check vehicles of other companies
companycompany ID

Definition at line 2862 of file station_cmd.cpp.

References Vehicle::owner.

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

◆ IncreaseStats() [1/2]

void IncreaseStats ( Station * st,
CargoType cargo,
StationID next_station_id,
uint capacity,
uint usage,
uint32_t time,
EdgeUpdateModes modes )

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

Parameters
stStation to get the link stats from.
cargoCargo to increase stat for.
next_station_idStation the consist will be travelling to next.
capacityCapacity to add to link stat.
usageUsage to add to link stat.
timeThe travel time for the link.
modesUpdate modes to be applied.

Definition at line 4266 of file station_cmd.cpp.

References LinkGraph::AddNode(), Debug, SpecializedStation< Station, false >::Get(), Station::goods, LinkGraphSchedule::instance, GoodsEntry::link_graph, LinkGraph::Merge(), GoodsEntry::node, and LinkGraph::Size().

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

◆ IncreaseStats() [2/2]

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

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

Parameters
stStation to get the link stats from.
frontFirst vehicle in the consist.
next_station_idStation the consist will be travelling to next.
timeThe travel time for the links.

Definition at line 4319 of file station_cmd.cpp.

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

◆ ModifyStationRatingAround()

void ModifyStationRatingAround ( TileIndex tile,
Owner owner,
int amount,
uint radius )

Forcibly modify station ratings near a given tile.

Used when a crash hurts a company's station ratings nearby, or when local authority actions affect nearby ratings.

Parameters
tileThe center of the ratings change area.
ownerThe station owner whose stations are affected.
amountThe amount to change the rating.
radiusThe radius to search for stations, from the origin tile.

Definition at line 4393 of file station_cmd.cpp.

References BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), ClampTo(), DistanceManhattan(), ForAllStationsRadius(), Station::goods, BaseStation::owner, GoodsEntry::rating, GoodsEntry::status, and BaseStation::xy.

Referenced by CheckTrainCollision(), CrashAirplane(), TownActionAdvertiseLarge(), TownActionAdvertiseMedium(), TownActionAdvertiseSmall(), and TownActionBuyRights().

◆ RemoveDockingTile()

void RemoveDockingTile ( TileIndex t)

Definition at line 2983 of file station_cmd.cpp.

◆ RerouteCargo()

void RerouteCargo ( Station * st,
CargoType cargo,
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
stStation to be rerouted at.
cargoType of cargo.
avoidOriginal next hop of cargo, avoid this.
avoid2Another station to be avoided when rerouting.

Definition at line 4147 of file station_cmd.cpp.

References GoodsEntry::GoodsEntryData::cargo, GoodsEntry::GetData(), Station::goods, GoodsEntry::HasData(), Vehicle::Next(), and StationCargoList::Reroute().

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

◆ SetRailStationTileFlags()

void SetRailStationTileFlags ( TileIndex tile,
const StationSpec * statspec )

Set rail station tile flags for the given tile.

Parameters
tileTile to set flags on.
statspecStatspec of the tile.

Definition at line 1416 of file station_cmd.cpp.

References StationSpec::Blocked, GetStationGfx(), GetStationTileFlags(), StationSpec::NoWires, StationSpec::Pylons, SetStationTileBlocked(), SetStationTileHavePylons(), and SetStationTileHaveWires().

Referenced by CmdBuildRailStation(), and CmdBuildRailWaypoint().

◆ ShowStationViewWindow()

void ShowStationViewWindow ( StationID station)

Opens StationViewWindow for given station.

Parameters
stationstation which window should be opened

Definition at line 2176 of file station_gui.cpp.

References AllocateWindowDescFront().

◆ SplitGroundSpriteForOverlay()

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
tiPositional info for the tile to decide snowyness etc. May be nullptr.
[in,out]groundGroundsprite to draw.
[out]overlay_offsetOverlay to draw.
Returns
true if overlay can be drawn.

Definition at line 3134 of file station_cmd.cpp.

References _settings_game, Arctic, GetSnowLine(), GetTropicZone(), RTO_X, RTO_Y, TileInfo::tile, TILE_HEIGHT, Tropic, TROPICZONE_DESERT, and Coord3D< T >::z.

Referenced by DrawStationTile().

◆ StationMaintenanceCost()

Money StationMaintenanceCost ( uint32_t num)
inline

Calculates the maintenance cost of a number of station tiles.

Parameters
numNumber of station tiles.
Returns
Total cost.

Definition at line 60 of file station_func.h.

References InfrastructureStation, and IntSqrt().

Referenced by CompaniesGenStatistics().

◆ StationPickerDrawSprite()

void StationPickerDrawSprite ( int x,
int y,
StationType st,
RailType railtype,
RoadType roadtype,
int image )

Definition at line 3520 of file station_cmd.cpp.

◆ UpdateAirportsNoise()

void UpdateAirportsNoise ( )

Recalculate the noise generated by the airports of each town.

Definition at line 2607 of file station_cmd.cpp.

References AirportGetNearestTown(), AT_OILRIG, GetAirportNoiseLevelForDistance(), INVALID_TILE, SpecializedStation< Station, false >::Iterate(), and Town::noise_reached.

Referenced by DoCreateTown(), and InitializeWindowsAndCaches().

◆ UpdateAllStationVirtCoords()

void UpdateAllStationVirtCoords ( )

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

Definition at line 464 of file station_cmd.cpp.

Referenced by CmdRenameTown(), and UpdateAllVirtCoords().

◆ UpdateStationAcceptance()

◆ UpdateStationDockingTiles()

void UpdateStationDockingTiles ( Station * st)

Definition at line 4689 of file station_cmd.cpp.