OpenTTD Source 20250312-master-gcdcc6b491d
Station Struct Referencefinal

Station data structure. More...

#include <station_base.h>

Inheritance diagram for Station:
SpecializedStation< Station, false > BaseStation Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_station_pool >

Public Member Functions

RoadStopGetPrimaryRoadStop (RoadStopType type) const
 
RoadStopGetPrimaryRoadStop (const struct RoadVehicle *v) const
 
 Station (TileIndex tile=INVALID_TILE)
 
 ~Station ()
 Clean up a station by clearing vehicle orders, invalidating windows and removing link stats.
 
void AddFacility (StationFacility new_facility_bit, TileIndex facil_xy)
 Called when new facility is built on the station.
 
void MarkTilesDirty (bool cargo_change) const
 Marks the tiles of the station as dirty.
 
void UpdateVirtCoord () override
 Update the virtual coords needed to draw the station sign.
 
void MoveSign (TileIndex new_xy) override
 Move the station main coordinate somewhere else.
 
void AfterStationTileSetChange (bool adding, StationType type)
 After adding/removing tiles to station, update some station-related stuff.
 
uint GetPlatformLength (TileIndex tile, DiagDirection dir) const override
 Determines the REMAINING length of a platform, starting at (and including) the given tile.
 
uint GetPlatformLength (TileIndex tile) const override
 Obtain the length of a platform.
 
void RecomputeCatchment (bool no_clear_nearby_lists=false)
 Recompute tiles covered in our catchment area.
 
uint GetCatchmentRadius () const
 Determines the catchment radius of the station.
 
Rect GetCatchmentRect () const
 Determines catchment rectangle of this station.
 
bool CatchmentCoversTown (TownID t) const
 Test if the given town ID is covered by our catchment area.
 
void AddIndustryToDeliver (Industry *ind, TileIndex tile)
 Add nearby industry to station's industries_near list if it accepts cargo.
 
void RemoveIndustryToDeliver (Industry *ind)
 Remove nearby industry from station's industries_near list.
 
void RemoveFromAllNearbyLists ()
 Remove this station from the nearby stations lists of nearby towns and industries.
 
bool TileIsInCatchment (TileIndex tile) const
 
bool TileBelongsToRailStation (TileIndex tile) const override
 Check whether a specific tile belongs to this station.
 
bool TileBelongsToRoadStop (TileIndex tile) const
 
bool TileBelongsToAirport (TileIndex tile) const
 
uint32_t GetNewGRFVariable (const ResolverObject &object, uint8_t variable, uint8_t parameter, bool &available) const override
 
void GetTileArea (TileArea *ta, StationType type) const override
 Get the tile area for a given station type.
 
- Public Member Functions inherited from SpecializedStation< Station, false >
 SpecializedStation (TileIndex tile)
 Set station type correctly.
 
- Public Member Functions inherited from BaseStation
 BaseStation (TileIndex tile)
 Initialize the base station.
 
virtual uint32_t GetNewGRFVariable (const struct ResolverObject &object, uint8_t variable, uint8_t parameter, bool &available) const =0
 Helper function to get a NewGRF variable that isn't implemented by the base class.
 
const std::string & GetCachedName () const
 
bool IsInUse () const
 Check whether the base station currently is in use; in use means that it is not scheduled for deletion and that it still has some facilities left.
 
uint8_t GetRoadStopRandomBits (TileIndex tile) const
 
uint8_t GetRoadStopAnimationFrame (TileIndex tile) const
 
void SetRoadStopRandomBits (TileIndex tile, uint8_t random_bits)
 
bool SetRoadStopAnimationFrame (TileIndex tile, uint8_t frame)
 
void RemoveRoadStopTileData (TileIndex tile)
 
- Public Member Functions inherited from Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_station_pool >
void * operator new (size_t size)
 Allocates space for new Titem.
 
void * operator new (size_t size, Tindex index)
 Allocates space for new Titem with given index.
 
void * operator new (size_t, void *ptr)
 Allocates space for new Titem at given memory address.
 
void operator delete (void *p, size_t size)
 Marks Titem as free.
 

Static Public Member Functions

static void RecomputeCatchmentForAll ()
 Recomputes catchment of all stations.
 
- Static Public Member Functions inherited from SpecializedStation< Station, false >
static bool IsExpected (const BaseStation *st)
 Helper for checking whether the given station is of this type.
 
static bool IsValidID (auto index)
 Tests whether given index is a valid index for station of this type.
 
static StationGet (auto index)
 Gets station with given index.
 
static StationGetIfValid (auto index)
 Returns station if the index is a valid index for this station type.
 
static StationGetByTile (TileIndex tile)
 Get the station belonging to a specific tile.
 
static StationFrom (BaseStation *st)
 Converts a BaseStation to SpecializedStation with type checking.
 
static const StationFrom (const BaseStation *st)
 Converts a const BaseStation to const SpecializedStation with type checking.
 
static Pool::IterateWrapper< StationIterate (size_t from=0)
 Returns an iterable ensemble of all valid stations of type T.
 
- Static Public Member Functions inherited from BaseStation
static BaseStationGetByTile (TileIndex tile)
 Get the base station belonging to a specific tile.
 
static void PostDestructor (size_t index)
 Invalidating of the JoinStation window has to be done after removing item from the pool.
 
- Static Public Member Functions inherited from Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_station_pool >
static bool CanAllocateItem (size_t n=1)
 Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
 
static bool CleaningPool ()
 Returns current state of pool cleaning - yes or no.
 
static bool IsValidID (auto index)
 Tests whether given index can be used to get valid (non-nullptr) Titem.
 
static Titem * Get (auto index)
 Returns Titem with given index.
 
static Titem * GetIfValid (auto index)
 Returns Titem with given index.
 
static size_t GetPoolSize ()
 Returns first unused index.
 
static size_t GetNumItems ()
 Returns number of valid items in the pool.
 
static void PostDestructor (size_t index)
 Dummy function called after destructor of each member.
 
static Pool::IterateWrapper< Titem > Iterate (size_t from=0)
 Returns an iterable ensemble of all valid Titem.
 

Data Fields

RoadStopbus_stops = nullptr
 All the road stops.
 
TileArea bus_station {}
 Tile area the bus 'station' part covers.
 
RoadStoptruck_stops = nullptr
 All the truck stops.
 
TileArea truck_station {}
 Tile area the truck 'station' part covers.
 
Airport airport {}
 Tile area the airport covers.
 
TileArea ship_station {}
 Tile area the ship 'station' part covers.
 
TileArea docking_station {}
 Tile area the docking tiles cover.
 
IndustryType indtype = IT_INVALID
 Industry type to get the name from.
 
BitmapTileArea catchment_tiles {}
 NOSAVE: Set of individual tiles covered by catchment area.
 
StationHadVehicleOfType had_vehicle_of_type {}
 
uint8_t time_since_load = 0
 
uint8_t time_since_unload = 0
 
uint8_t last_vehicle_type = 0
 
std::list< Vehicle * > loading_vehicles {}
 
std::array< GoodsEntry, NUM_CARGOgoods
 Goods at this station.
 
CargoTypes always_accepted {}
 Bitmask of always accepted cargo types (by houses, HQs, industry tiles when industry doesn't accept cargo)
 
IndustryList industries_near {}
 Cached list of industries near the station that can accept cargo,.
 
Industryindustry = nullptr
 NOSAVE: Associated industry for neutral stations. (Rebuilt on load from Industry->st)
 
- Data Fields inherited from BaseStation
TileIndex xy = INVALID_TILE
 Base tile of the station.
 
TrackedViewportSign sign {}
 NOSAVE: Dimensions of sign.
 
uint8_t delete_ctr = 0
 Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is deleted.
 
std::string name {}
 Custom name.
 
StringID string_id = INVALID_STRING_ID
 Default name (town area) of station.
 
std::string cached_name
 NOSAVE: Cache of the resolved name of the station, if not using a custom name.
 
Towntown = nullptr
 The town this station is associated with.
 
Owner owner = INVALID_OWNER
 The owner of this station.
 
StationFacilities facilities {}
 The facilities that this station has.
 
std::vector< SpecMapping< StationSpec > > speclist {}
 List of rail station specs of this station.
 
std::vector< SpecMapping< RoadStopSpec > > roadstop_speclist {}
 List of road stop specs of this station.
 
TimerGameCalendar::Date build_date {}
 Date of construction.
 
uint16_t random_bits = 0
 Random bits assigned to this station.
 
uint8_t waiting_triggers = 0
 Waiting triggers (NewGRF) for this station.
 
uint8_t cached_anim_triggers = 0
 NOSAVE: Combined animation trigger bitmask, used to determine if trigger processing should happen.
 
uint8_t cached_roadstop_anim_triggers = 0
 NOSAVE: Combined animation trigger bitmask for road stops, used to determine if trigger processing should happen.
 
CargoTypes cached_cargo_triggers {}
 NOSAVE: Combined cargo trigger bitmask.
 
CargoTypes cached_roadstop_cargo_triggers {}
 NOSAVE: Combined cargo trigger bitmask for road stops.
 
TileArea train_station {INVALID_TILE, 0, 0}
 Tile area the train 'station' part covers.
 
StationRect rect {}
 NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
 
std::vector< RoadStopTileDatacustom_roadstop_tile_data {}
 List of custom road stop tile data.
 
- Data Fields inherited from Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_station_pool >
Tindex index
 Index of this pool item.
 

Additional Inherited Members

- Public Types inherited from Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_station_pool >
typedef struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > Pool
 Type of the pool this item is going to be part of.
 
- Static Public Attributes inherited from SpecializedStation< Station, false >
static constexpr StationFacilities EXPECTED_FACIL
 Specialized type.
 

Detailed Description

Station data structure.

Definition at line 496 of file station_base.h.

Constructor & Destructor Documentation

◆ Station()

Station::Station ( TileIndex  tile = INVALID_TILE)

Definition at line 63 of file station.cpp.

◆ ~Station()

Member Function Documentation

◆ AddFacility()

void Station::AddFacility ( StationFacility  new_facility_bit,
TileIndex  facil_xy 
)

Called when new facility is built on the station.

If it is the first facility it initializes also 'xy' and 'random_bits' members

Definition at line 229 of file station.cpp.

References _current_company, BaseStation::build_date, TimerGameCalendar::date, BaseStation::facilities, MoveSign(), BaseStation::owner, Random, BaseStation::random_bits, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SetWindowClassesDirty(), and WC_VEHICLE_ORDERS.

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

◆ AddIndustryToDeliver()

void Station::AddIndustryToDeliver ( Industry ind,
TileIndex  tile 
)

Add nearby industry to station's industries_near list if it accepts cargo.

For industries that are already on the list update distance if it's closer.

Parameters
indIndustry
tileTile of the industry to measure distance to.

Definition at line 388 of file station.cpp.

References DistanceMax(), industries_near, Industry::IsCargoAccepted(), and BaseStation::xy.

Referenced by RecomputeCatchment().

◆ AfterStationTileSetChange()

void Station::AfterStationTileSetChange ( bool  adding,
StationType  type 
)

◆ CatchmentCoversTown()

bool Station::CatchmentCoversTown ( TownID  t) const

Test if the given town ID is covered by our catchment area.

This is used when removing a house tile to determine if it was the last house tile within our catchment.

Parameters
tTownID to test.
Returns
true if at least one house tile of TownID is covered.

Definition at line 451 of file station.cpp.

References catchment_tiles, GetTownIndex(), INVALID_TILE, IsTileType(), and MP_HOUSE.

Referenced by RemoveNearbyStations().

◆ GetCatchmentRadius()

uint Station::GetCatchmentRadius ( ) const

◆ GetCatchmentRect()

Rect Station::GetCatchmentRect ( ) const

Determines catchment rectangle of this station.

Returns
clamped catchment rectangle

Definition at line 365 of file station.cpp.

References GetCatchmentRadius(), Map::MaxX(), Map::MaxY(), and BaseStation::rect.

Referenced by RecomputeCatchment().

◆ GetNewGRFVariable()

uint32_t Station::GetNewGRFVariable ( const ResolverObject object,
uint8_t  variable,
uint8_t  parameter,
bool &  available 
) const
override

Definition at line 412 of file newgrf_station.cpp.

◆ GetPlatformLength() [1/2]

uint Station::GetPlatformLength ( TileIndex  tile) const
overridevirtual

Obtain the length of a platform.

Precondition
tile must be a rail station tile
Parameters
tileA tile that contains the platform in question
Returns
The length of the platform

Implements BaseStation.

Definition at line 266 of file station.cpp.

References GetRailStationAxis(), IsCompatibleTrainStationTile(), TileBelongsToRailStation(), and TileOffsByAxis().

◆ GetPlatformLength() [2/2]

uint Station::GetPlatformLength ( TileIndex  tile,
DiagDirection  dir 
) const
overridevirtual

Determines the REMAINING length of a platform, starting at (and including) the given tile.

Parameters
tilethe tile from which to start searching. Must be a rail station tile
dirThe direction in which to search.
Returns
The platform length

Implements BaseStation.

Definition at line 288 of file station.cpp.

References DIAGDIR_END, IsCompatibleTrainStationTile(), IsRailStationTile(), and TileOffsByDiagDir().

Referenced by GetTrainStopLocation(), and UpdateLoadUnloadTicks().

◆ GetPrimaryRoadStop()

RoadStop * Station::GetPrimaryRoadStop ( RoadStopType  type) const
inline

Definition at line 498 of file station_base.h.

◆ GetTileArea()

void Station::GetTileArea ( TileArea ta,
StationType  type 
) const
overridevirtual

Get the tile area for a given station type.

Parameters
tatile area to fill.
typethe type of the area

Implements BaseStation.

Definition at line 411 of file station_cmd.cpp.

References airport, bus_station, docking_station, BaseStation::train_station, and truck_station.

◆ MoveSign()

void Station::MoveSign ( TileIndex  new_xy)
overridevirtual

Move the station main coordinate somewhere else.

Parameters
new_xynew tile location of the sign

Reimplemented from BaseStation.

Definition at line 462 of file station_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_station_pool >::index, Kdtree< T, TxyFunc, CoordT, DistT >::Insert(), Kdtree< T, TxyFunc, CoordT, DistT >::Remove(), and BaseStation::xy.

Referenced by AddFacility().

◆ RecomputeCatchment()

◆ RecomputeCatchmentForAll()

void Station::RecomputeCatchmentForAll ( )
static

Recomputes catchment of all stations.

This will additionally recompute nearby stations for all towns and industries.

Definition at line 533 of file station.cpp.

References SpecializedStation< Station, false >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_industry_pool >::Iterate(), and Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::Iterate().

Referenced by AfterLoadGame(), and CheckCaches().

◆ RemoveFromAllNearbyLists()

void Station::RemoveFromAllNearbyLists ( )

◆ RemoveIndustryToDeliver()

void Station::RemoveIndustryToDeliver ( Industry ind)

Remove nearby industry from station's industries_near list.

Parameters
indIndustry

Definition at line 414 of file station.cpp.

References industries_near.

◆ TileBelongsToAirport()

bool Station::TileBelongsToAirport ( TileIndex  tile) const
inline

Definition at line 571 of file station_base.h.

◆ TileBelongsToRailStation()

bool Station::TileBelongsToRailStation ( TileIndex  tile) const
inlineoverridevirtual

Check whether a specific tile belongs to this station.

Parameters
tilethe tile to check
Returns
true if the tile belongs to this station

Implements BaseStation.

Definition at line 561 of file station_base.h.

References GetStationIndex(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_station_pool >::index, and IsRailStationTile().

Referenced by GetPlatformLength(), MarkTilesDirty(), and TriggerStationRandomisation().

◆ TileBelongsToRoadStop()

bool Station::TileBelongsToRoadStop ( TileIndex  tile) const
inline

Definition at line 566 of file station_base.h.

◆ TileIsInCatchment()

bool Station::TileIsInCatchment ( TileIndex  tile) const
inline

Definition at line 556 of file station_base.h.

◆ UpdateVirtCoord()

Field Documentation

◆ airport

◆ always_accepted

CargoTypes Station::always_accepted {}

Bitmask of always accepted cargo types (by houses, HQs, industry tiles when industry doesn't accept cargo)

Definition at line 526 of file station_base.h.

Referenced by DeliverGoods(), and UpdateStationAcceptance().

◆ bus_station

TileArea Station::bus_station {}

Tile area the bus 'station' part covers.

Definition at line 506 of file station_base.h.

Referenced by CmdBuildRoadStop(), GetTileArea(), and RemoveRoadStop().

◆ bus_stops

RoadStop* Station::bus_stops = nullptr

All the road stops.

Definition at line 505 of file station_base.h.

Referenced by AfterLoadGame(), FindRoadStopSpot(), GetCatchmentRadius(), and RemoveRoadStop().

◆ catchment_tiles

BitmapTileArea Station::catchment_tiles {}

NOSAVE: Set of individual tiles covered by catchment area.

Definition at line 516 of file station_base.h.

Referenced by CatchmentCoversTown(), CheckSubsidised(), GetAcceptanceAroundStation(), RecomputeCatchment(), RemoveFromAllNearbyLists(), and TriggerWatchedCargoCallbacks().

◆ docking_station

TileArea Station::docking_station {}

Tile area the docking tiles cover.

Definition at line 512 of file station_base.h.

Referenced by CheckForDockingTile(), GetTileArea(), and RemoveDock().

◆ goods

◆ had_vehicle_of_type

StationHadVehicleOfType Station::had_vehicle_of_type {}

Definition at line 518 of file station_base.h.

◆ indtype

IndustryType Station::indtype = IT_INVALID

Industry type to get the name from.

Definition at line 514 of file station_base.h.

Referenced by GenerateStationName().

◆ industries_near

IndustryList Station::industries_near {}

Cached list of industries near the station that can accept cargo,.

See also
DeliverGoodsToIndustry()

Definition at line 528 of file station_base.h.

Referenced by AddCargoDelivery(), AddIndustryToDeliver(), CheckSubsidised(), DeliverGoodsToIndustry(), PopulateStationsNearby(), RecomputeCatchment(), and RemoveIndustryToDeliver().

◆ industry

Industry* Station::industry = nullptr

NOSAVE: Associated industry for neutral stations. (Rebuilt on load from Industry->st)

Definition at line 529 of file station_base.h.

Referenced by ForAllStationsAroundTiles(), and RecomputeCatchment().

◆ last_vehicle_type

uint8_t Station::last_vehicle_type = 0

Definition at line 523 of file station_base.h.

◆ loading_vehicles

std::list<Vehicle *> Station::loading_vehicles {}

Definition at line 524 of file station_base.h.

◆ ship_station

TileArea Station::ship_station {}

Tile area the ship 'station' part covers.

Definition at line 511 of file station_base.h.

Referenced by CmdBuildDock(), GetCatchmentRadius(), ProcessOrders(), and RemoveDock().

◆ time_since_load

uint8_t Station::time_since_load = 0

Definition at line 520 of file station_base.h.

◆ time_since_unload

uint8_t Station::time_since_unload = 0

Definition at line 521 of file station_base.h.

◆ truck_station

TileArea Station::truck_station {}

Tile area the truck 'station' part covers.

Definition at line 508 of file station_base.h.

Referenced by CmdBuildRoadStop(), GetTileArea(), and RemoveRoadStop().

◆ truck_stops

RoadStop* Station::truck_stops = nullptr

All the truck stops.

Definition at line 507 of file station_base.h.

Referenced by AfterLoadGame(), FindRoadStopSpot(), GetCatchmentRadius(), and RemoveRoadStop().


The documentation for this struct was generated from the following files: