OpenTTD Source: src/newgrf_station.h File Reference

OpenTTD Source 15.3

Data Structures | Typedefs | Enumerations | Functions | Variables
newgrf_station.h File Reference

Header file for NewGRF stations. More...

`#include "core/enum_type.hpp"`
`#include "bridge_type.h"`
`#include "newgrf_animation_type.h"`
`#include "newgrf_badge_type.h"`
`#include "newgrf_callbacks.h"`
`#include "newgrf_class.h"`
`#include "newgrf_commons.h"`
`#include "cargo_type.h"`
`#include "station_type.h"`
`#include "rail_type.h"`
`#include "newgrf_spritegroup.h"`
`#include "newgrf_town.h"`

Go to the source code of this file.

## Data Structures
struct | StationScopeResolver
| Scope resolver for stations. More...
struct | StationScopeResolver::Cache
| Station variable cache This caches 'expensive' station variable lookups which iterate over several tiles that may be called multiple times per Resolve(). More...
struct | StationResolverObject
| Station resolver. More...
struct | StationSpec
| Station specification. More...

## Typedefs
using | StationSpecFlags = EnumBitSet< StationSpecFlag, uint8_t >
using | StationClass = NewGRFClass< StationSpec, StationClassID, STAT_CLASS_MAX >
| Class containing information relating to station classes.

## Enumerations
enum | StationClassID : uint16_t { STAT_CLASS_BEGIN = 0 , STAT_CLASS_DFLT = 0 , STAT_CLASS_WAYP , STAT_CLASS_MAX = UINT16_MAX }
enum class | StationSpecFlag : uint8_t { SeparateGround = 0 , DivByStationSize = 1 , Cb141RandomBits = 2 , CustomFoundations = 3 , ExtendedFoundations = 4 }
| Allow incrementing of StationClassID variables. More...

## Functions
const StationSpec * | GetStationSpec (TileIndex t)
uint16_t | GetStationLayoutKey (uint8_t platforms, uint8_t length)
| Get the station layout key for a given station layout size.
bool | IsWaypointClass (const StationClass &cls)
| Test if a StationClass is the waypoint class.
uint32_t | GetPlatformInfo (Axis axis, uint8_t tile, int platforms, int length, int x, int y, bool centred)
| Evaluate a tile's position within a station, and return the result in a bit-stuffed format.
SpriteID | GetCustomStationRelocation (const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32_t var10=0)
| Resolve sprites for drawing a station tile.
void | GetCustomStationRelocation (SpriteLayoutProcessor &processor, const StationSpec *statspec, BaseStation *st, TileIndex tile)
SpriteID | GetCustomStationFoundationRelocation (const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info)
| Resolve the sprites for custom station foundations.
uint16_t | GetStationCallback (CallbackID callback, uint32_t param1, uint32_t param2, const StationSpec *statspec, BaseStation *st, TileIndex tile, std::span< int32_t > regs100={})
CommandCost | PerformStationTileSlopeCheck (TileIndex north_tile, TileIndex cur_tile, const StationSpec *statspec, Axis axis, uint8_t plat_len, uint8_t numtracks)
| Check the slope of a tile of a new station.
std::optional< uint8_t > | AllocateSpecToStation (const StationSpec *spec, BaseStation *st)
| Allocate a StationSpec to a Station.
void | AssignSpecToStation (const StationSpec *spec, BaseStation *st, uint8_t specindex)
| Assign a previously allocated StationSpec specindex to a Station.
void | DeallocateSpecFromStation (BaseStation *st, uint8_t specindex)
| Deallocate a StationSpec from a Station.
bool | DrawStationTile (int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
| Draw representation of a station tile for GUI purposes.
void | AnimateStationTile (TileIndex tile)
void | TriggerStationAnimation (BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoType cargo_type=INVALID_CARGO)
void | TriggerStationRandomisation (BaseStation *st, TileIndex tile, StationRandomTrigger trigger, CargoType cargo_type=INVALID_CARGO)
| Trigger station randomisation.
void | StationUpdateCachedTriggers (BaseStation *st)
| Update the cached animation trigger bitmask for a station.

## Variables
static const uint32_t | STATION_CLASS_LABEL_DEFAULT = 'DFLT'
static const uint32_t | STATION_CLASS_LABEL_WAYPOINT = 'WAYP'

## Detailed Description

Header file for NewGRF stations.

Definition in file newgrf_station.h.

## Typedef Documentation

## ◆ StationClass

using StationClass = NewGRFClass<StationSpec, StationClassID, STAT_CLASS_MAX>

Class containing information relating to station classes.

Definition at line 184 of file newgrf_station.h.

## ◆ StationSpecFlags

using StationSpecFlags = EnumBitSet<StationSpecFlag, uint8_t>

Definition at line 120 of file newgrf_station.h.

## Enumeration Type Documentation

## ◆ StationClassID

enum StationClassID : uint16_t

Enumerator
STAT_CLASS_BEGIN | the lowest valid value
STAT_CLASS_DFLT | Default station class.
STAT_CLASS_WAYP | Waypoint class.
STAT_CLASS_MAX | Maximum number of classes.

Definition at line 103 of file newgrf_station.h.

## ◆ StationSpecFlag

enum class StationSpecFlag : uint8_t
| strong

Allow incrementing of StationClassID variables.

Enumerator
SeparateGround | Use different sprite set for ground sprites.
DivByStationSize | Divide cargo amount by station size.
Cb141RandomBits | Callback 141 needs random bits.
CustomFoundations | Draw custom foundations.
ExtendedFoundations | Extended foundation block instead of simple.

Definition at line 113 of file newgrf_station.h.

## Function Documentation

## ◆ AllocateSpecToStation()

std::optional< uint8_t > AllocateSpecToStation | ( | const StationSpec * | spec,
|  | BaseStation * | st
| ) |  |

Allocate a StationSpec to a Station.

This is called once per build operation.

Parameters

  spec | StationSpec to allocate.
  st | Station to allocate it to.

Returns
  Index within the Station's station spec list, or std::nullopt if the allocation failed.

Definition at line 704 of file newgrf_station.cpp.

References NUM_STATIONSSPECS_PER_STATION, and BaseStation::speclist.

Referenced by CmdBuildRailStation(), CmdBuildRailWaypoint(), and MoveWaypointsToBaseStations().

## ◆ AnimateStationTile()

void AnimateStationTile | ( | TileIndex | tile | ) |

Definition at line 895 of file newgrf_station.cpp.

## ◆ AssignSpecToStation()

void AssignSpecToStation | ( | const StationSpec * | spec,
|  | BaseStation * | st,
|  | uint8_t | specindex
| ) |  |

Assign a previously allocated StationSpec specindex to a Station.

Parameters

  spec | StationSpec to assign..
  st | Station to allocate it to.
  specindex | Spec index of allocation.

Definition at line 739 of file newgrf_station.cpp.

References StationSpec::grf_prop, GRFFilePropsBase::grfid, GRFFilePropsBase::local_id, BaseStation::speclist, and StationUpdateCachedTriggers().

Referenced by CmdBuildRailStation(), CmdBuildRailWaypoint(), and MoveWaypointsToBaseStations().

## ◆ DeallocateSpecFromStation()

void DeallocateSpecFromStation | ( | BaseStation * | st,
|  | uint8_t | specindex
| ) |  |

Deallocate a StationSpec from a Station.

Called when removing a single station tile.

Parameters

  st | Station to work with.
  specindex | Index of the custom station within the Station's station spec list.

Definition at line 756 of file newgrf_station.cpp.

References BaseStation::cached_anim_triggers, BaseStation::cached_cargo_triggers, GetCustomStationSpecIndex(), GetRailTileArea(), INVALID_TILE, BaseStation::speclist, StationUpdateCachedTriggers(), and BaseStation::TileBelongsToRailStation().

Referenced by CmdBuildRailStation(), CmdBuildRailWaypoint(), and RemoveFromRailBaseStation().

## ◆ DrawStationTile()

bool DrawStationTile | ( | int | x,
|  | int | y,
|  | RailType | railtype,
|  | Axis | axis,
|  | StationClassID | sclass,
|  | uint | station
| ) |  |

Draw representation of a station tile for GUI purposes.

Parameters

  x | Position x of image.
  y | Position y of image.
  axis | Axis.
  railtype | Rail type.
  sclass,station | Type of station.
  station | station ID

Returns
  True if the tile was drawn (allows for fallback to default graphic)

Definition at line 803 of file newgrf_station.cpp.

References _local_company, CALLBACK_FAILED, StationSpec::callback_mask, CBID_STATION_DRAW_TILE_LAYOUT, DrawRailTileSeqInGUI(), DrawSprite(), DrawTileLayout, RailTypeInfo::fallback_railtype, StationSpec::flags, NewGRFClass< Tspec, Tindex, Tmax >::Get(), GetCompanyPalette(), GetCustomRailSprite(), GetCustomStationRelocation(), SpriteLayoutProcessor::GetLayout(), GetRailTypeInfo(), RailTypeInfo::GetRailtypeSpriteOffset(), NewGRFClass< Tspec, Tindex, Tmax >::GetSpec(), GetStationTileLayout(), DrawTileSprites::ground, GroundSpritePaletteTransform(), HasBit(), INVALID_TILE, NewGRFSpriteLayout::NeedsPreprocessing(), PalSpriteID::pal, StationSpec::renderdata, RTSG_GROUND, SeparateGround, SplitGroundSpriteForOverlay(), PalSpriteID::sprite, SPRITE_MODIFIER_CUSTOM_SPRITE, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by StationPickerCallbacks::DrawType(), DrawWaypointSprite(), and BuildRailStationWindow::DrawWidget().

## ◆ GetCustomStationFoundationRelocation()

SpriteID GetCustomStationFoundationRelocation | ( | const StationSpec * | statspec,
|  | BaseStation * | st,
|  | TileIndex | tile,
|  | uint | layout,
|  | uint | edge_info
| ) |  |

Resolve the sprites for custom station foundations.

Parameters

  statspec | Station spec
  st | Station
  tile | Station tile being drawn
  layout | Spritelayout as returned by previous callback
  edge_info | Information about northern tile edges; whether they need foundations or merge into adjacent tile's foundations.

Returns
  First sprite of a set of foundation sprites for various slopes, or 0 if default foundations shall be drawn.

Definition at line 646 of file newgrf_station.cpp.

References CBID_NO_CALLBACK.

Referenced by DrawCustomStationFoundations().

## ◆ GetCustomStationRelocation() [1/2]

SpriteID GetCustomStationRelocation | ( | const StationSpec * | statspec,
|  | BaseStation * | st,
|  | TileIndex | tile,
|  | uint32_t | var10
| ) |  |

Resolve sprites for drawing a station tile.

Parameters

  statspec | Station spec
  st | Station (nullptr in GUI)
  tile | Station tile being drawn (INVALID_TILE in GUI)
  var10 | Value to put in variable 10; normally 0; 1 when resolving the groundsprite and StationSpecFlag::SeparateGround is set.

Returns
  First sprite of the Action 1 spriteset to use, minus an offset of SPR_RAIL_PLATFORM_Y_FRONT (0x42D) to accommodate for weird NewGRF specs.

Definition at line 612 of file newgrf_station.cpp.

References CBID_NO_CALLBACK.

Referenced by DrawStationTile().

## ◆ GetCustomStationRelocation() [2/2]

void GetCustomStationRelocation | ( | SpriteLayoutProcessor & | processor,
|  | const StationSpec * | statspec,
|  | BaseStation * | st,
|  | TileIndex | tile
| ) |  |

Definition at line 622 of file newgrf_station.cpp.

## ◆ GetPlatformInfo()

uint32_t GetPlatformInfo | ( | Axis | axis,
|  | uint8_t | tile,
|  | int | platforms,
|  | int | length,
|  | int | x,
|  | int | y,
|  | bool | centred
| ) |  |

Evaluate a tile's position within a station, and return the result in a bit-stuffed format.

if not centered: .TNLcCpP, if centered: .TNL..CP

- T = Tile layout number (GetStationGfx)
- N = Number of platforms
- L = Length of platforms
- C = Current platform number from start, c = from end
- P = Position along platform from start, p = from end

if centered, C/P start from the centre and c/p are not available.

Returns
  Platform information in bit-stuffed format.

Definition at line 120 of file newgrf_station.cpp.

References AXIS_X, Clamp(), and SB().

Referenced by CmdBuildRailStation().

## ◆ GetStationCallback()

uint16_t GetStationCallback | ( | CallbackID | callback,
|  | uint32_t | param1,
|  | uint32_t | param2,
|  | const StationSpec * | statspec,
|  | BaseStation * | st,
|  | TileIndex | tile,
|  | std::span< int32_t > | regs100 = `{}`
| ) |  |

Definition at line 660 of file newgrf_station.cpp.

## ◆ GetStationLayoutKey()

uint16_t GetStationLayoutKey | ( | uint8_t | platforms,
|  | uint8_t | length
| ) |  |
| inline

Get the station layout key for a given station layout size.

Parameters

  platforms | Number of platforms.
  length | Length of platforms.

Returns
  Key of station layout.

Definition at line 194 of file newgrf_station.h.

Referenced by StationChangeInfo().

## ◆ GetStationSpec()

const StationSpec * GetStationSpec | ( | TileIndex | t | ) |

Definition at line 871 of file newgrf_station.cpp.

## ◆ IsWaypointClass()

bool IsWaypointClass | ( | const StationClass & | cls | ) |
| inline

Test if a StationClass is the waypoint class.

Parameters

  cls | StationClass to test.

Returns
  true if the class is the waypoint class.

Definition at line 204 of file newgrf_station.h.

References GB(), and NewGRFClass< Tspec, Tindex, Tmax >::global_id.

## ◆ PerformStationTileSlopeCheck()

CommandCost PerformStationTileSlopeCheck | ( | TileIndex | north_tile,
|  | TileIndex | cur_tile,
|  | const StationSpec * | statspec,
|  | Axis | axis,
|  | uint8_t | plat_len,
|  | uint8_t | numtracks
| ) |  |

Check the slope of a tile of a new station.

Parameters

  north_tile | Norther tile of the station rect.
  cur_tile | Tile to check.
  statspec | Station spec.
  axis | Axis of the new station.
  plat_len | Platform length.
  numtracks | Number of platforms.

Returns
  Succeeded or failed command.

Definition at line 676 of file newgrf_station.cpp.

References AXIS_Y, CALLBACK_FAILED, CBID_STATION_LAND_SLOPE_CHECK, GetErrorMessageFromLocationCallbackResult(), GetTileSlope(), StationSpec::grf_prop, GRFFilePropsBase::grffile, HasBit(), SLOPE_EW, TileX(), TileY(), and ToggleBit().

Referenced by CheckFlatLandRailStation().

## ◆ StationUpdateCachedTriggers()

void StationUpdateCachedTriggers | ( | BaseStation * | st | ) |

Update the cached animation trigger bitmask for a station.

Parameters

  st | Station to update.

Definition at line 1025 of file newgrf_station.cpp.

References BaseStation::cached_anim_triggers, BaseStation::cached_cargo_triggers, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set().

Referenced by AssignSpecToStation(), and DeallocateSpecFromStation().

## ◆ TriggerStationAnimation()

void TriggerStationAnimation | ( | BaseStation * | st,
|  | TileIndex | tile,
|  | StationAnimationTrigger | trigger,
|  | CargoType | cargo_type = `INVALID_CARGO`
| ) |  |

Definition at line 903 of file newgrf_station.cpp.

## ◆ TriggerStationRandomisation()

void TriggerStationRandomisation | ( | BaseStation * | st,
|  | TileIndex | trigger_tile,
|  | StationRandomTrigger | trigger,
|  | CargoType | cargo_type
| ) |  |

Trigger station randomisation.

Parameters

  st | station being triggered
  trigger_tile | specific tile of platform to trigger
  trigger | trigger type
  cargo_type | cargo type causing trigger

Definition at line 949 of file newgrf_station.cpp.

References BaseStation::cached_cargo_triggers, StationSpec::cargo_triggers, CargoTaken, CBID_RANDOM_TRIGGER, SpecializedStation< Station, false >::From(), GetEmptyMask(), GetRailTileArea(), GetStationTileRandomBits(), HasBit(), IsValidCargoType(), MarkTileDirtyByTile(), Random, BaseStation::random_bits, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SetStationTileRandomBits(), BaseStation::TileBelongsToRailStation(), and BaseStation::waiting_random_triggers.

Referenced by Vehicle::LeaveStation(), LoadUnloadVehicle(), CYapfReserveTrack< Types >::ReserveRailStationPlatform(), CYapfReserveTrack< Types >::ReserveSingleTrack(), TrainEnterStation(), and TryReserveRailTrack().

## Variable Documentation

## ◆ STATION_CLASS_LABEL_DEFAULT

const uint32_t STATION_CLASS_LABEL_DEFAULT = 'DFLT'
| static

Definition at line 100 of file newgrf_station.h.

## ◆ STATION_CLASS_LABEL_WAYPOINT

const uint32_t STATION_CLASS_LABEL_WAYPOINT = 'WAYP'
| static

Definition at line 101 of file newgrf_station.h.