# newgrf_station.h File Reference

Header file for NewGRF stations. More...

`#include "engine_type.h"`
`#include "newgrf_callbacks.h"`
`#include "newgrf_cargo.h"`
`#include "tile_type.h"`
`#include "station_type.h"`
`#include "strings_type.h"`
`#include "sprite.h"`
`#include "direction_type.h"`
`#include "newgrf.h"`

Go to the source code of this file.

## Data Structures
struct | EnumPropsT< StationClassID >
| Define basic enum properties. More...
struct | StationSpec
struct | StationClass
| Struct containing information relating to station classes. More...
## Typedefs
typedef TinyEnumT< StationClassID > | StationClassIDByte
typedef byte * | StationLayout
## Enumerations
enum | StationClassID { STAT_CLASS_BEGIN = 0, STAT_CLASS_DFLT = 0, STAT_CLASS_WAYP, STAT_CLASS_MAX = 32 }
enum | StationSpecFlags { SSF_SEPARATE_GROUND, SSF_DIV_BY_STATION_SIZE, SSF_CB141_RANDOM_BITS, SSF_CUSTOM_FOUNDATIONS, SSF_EXTENDED_FOUNDATIONS }
enum | StatAnimTrigger { STAT_ANIM_BUILT, STAT_ANIM_NEW_CARGO, STAT_ANIM_CARGO_TAKEN, STAT_ANIM_TRAIN_ARRIVES, STAT_ANIM_TRAIN_DEPARTS, STAT_ANIM_TRAIN_LOADS, STAT_ANIM_250_TICKS }
## Functions
| DECLARE_POSTFIX_INCREMENT (StationClassID)
| Allow incrementing of StationClassID variables.
void | ResetStationClasses ()
| Reset station classes to their default state.
StationClassID | AllocateStationClass (uint32 cls)
| Allocate a station class for the given class id.
void | SetStationClassName (StationClassID sclass, StringID name)
| Set the name of a custom station class.
StringID | GetStationClassName (StationClassID sclass)
| Retrieve the name of a custom station class.
const StationSpec * | GetStationSpec (TileIndex t)
uint | GetNumStationClasses ()
| Get the number of station classes in use.
uint | GetNumCustomStations (StationClassID sclass)
| Return the number of stations for the given station class.
void | SetCustomStationSpec (StationSpec *statspec)
| Tie a station spec to its station class.
const StationSpec * | GetCustomStationSpec (StationClassID sclass, uint station)
| Retrieve a station spec from a class.
const StationSpec * | GetCustomStationSpecByGrf (uint32 grfid, byte localidx, int *index)
| Retrieve a station spec by GRF location.
uint32 | GetPlatformInfo (Axis axis, byte tile, int platforms, int length, int x, int y, bool centred)
SpriteID | GetCustomStationRelocation (const StationSpec *statspec, const Station *st, TileIndex tile)
SpriteID | GetCustomStationGroundRelocation (const StationSpec *statspec, const Station *st, TileIndex tile)
uint16 | GetStationCallback (CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, const Station *st, TileIndex tile)
int | AllocateSpecToStation (const StationSpec *statspec, Station *st, bool exec)
| Allocate a StationSpec to a Station.
void | DeallocateSpecFromStation (Station *st, byte 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 | StationAnimationTrigger (const Station *st, TileIndex tile, StatAnimTrigger trigger, CargoID cargo_type=CT_INVALID)
void | StationUpdateAnimTriggers (Station *st)
| Update the cached animation trigger bitmask for a station.

## Detailed Description

Header file for NewGRF stations.

Definition in file newgrf_station.h.

## Enumeration Type Documentation

enum StationClassID

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 18 of file newgrf_station.h.

enum StationSpecFlags

Enumerator:

  SSF_SEPARATE_GROUND | Use different sprite set for ground sprites.
  SSF_DIV_BY_STATION_SIZE | Divide cargo amount by station size.
  SSF_CB141_RANDOM_BITS | Callback 141 needs random bits.
  SSF_CUSTOM_FOUNDATIONS | Draw custom foundations.
  SSF_EXTENDED_FOUNDATIONS | Extended foundation block instead of simple.

Definition at line 32 of file newgrf_station.h.

## Function Documentation

int AllocateSpecToStation | ( | const StationSpec * | statspec,
|  | Station * | st,
|  | bool | exec |
| ) |  |  |

Allocate a StationSpec to a Station.

This is called once per build operation.

Parameters:

  | statspec | StationSpec to allocate.
  | st | Station to allocate it to.
  | exec | Whether to actually allocate the spec.

Returns:
  Index within the Station's spec list, or -1 if the allocation failed.

Definition at line 692 of file newgrf_station.cpp.

References Station::num_specs, ReallocT(), and Station::speclist.

Referenced by CmdBuildRailroadStation().

StationClassID AllocateStationClass | ( | uint32 | cls | ) |

Allocate a station class for the given class id.

Parameters:

  | cls | A 32 bit value identifying the class.

Returns:
  Index into _station_classes of allocated class.

Definition at line 67 of file newgrf_station.cpp.

References grfmsg(), StationClass::id, STAT_CLASS_BEGIN, STAT_CLASS_DFLT, and STAT_CLASS_MAX.

void DeallocateSpecFromStation | ( | Station * | st,
|  | byte | 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 spec list.

Returns:
  Indicates whether the StationSpec was deallocated.

Definition at line 742 of file newgrf_station.cpp.

References BEGIN_TILE_LOOP, Station::cached_anim_triggers, END_TILE_LOOP, GetStationIndex(), PoolItem< T, Tid, Tpool >::index, IsTileType(), MP_STATION, Station::num_specs, ReallocT(), Station::speclist, StationUpdateAnimTriggers(), Station::train_tile, Station::trainst_h, and Station::trainst_w.

Referenced by CmdBuildRailroadStation(), and CmdRemoveFromRailroadStation().

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 786 of file newgrf_station.cpp.

References CALLBACK_FAILED, CBID_STATION_SPRITE_LAYOUT, CBM_STATION_SPRITE_LAYOUT, RailtypeInfo::custom_ground_offset, DrawTileSeqStruct::delta_x, DrawTileSeqStruct::delta_y, DrawTileSeqStruct::delta_z, DrawSprite(), foreach_draw_tile_seq, GetCustomStationSpec(), GetRailTypeInfo(), DrawTileSprites::ground, GroundSpritePaletteTransform(), HasBit(), DrawTileSeqStruct::image, INVALID_TILE, PalSpriteID::pal, DrawTileSprites::seq, PalSpriteID::sprite, SPRITE_MASK, SpriteLayoutPaletteTransform(), ST_NORMAL, RailtypeInfo::total_offset, Point::x, and Point::y.

Referenced by DrawWaypointSprite().

const StationSpec* GetCustomStationSpec | ( | StationClassID | sclass,
|  | uint | station |
| ) |  |  |

Retrieve a station spec from a class.

Parameters:

  | sclass | Index of the station class.
  | station | The station index with the class.

Returns:
  The station spec.

Definition at line 148 of file newgrf_station.cpp.

References StationClass::spec, and STAT_CLASS_MAX.

Referenced by AfterLoadWaypoints(), CmdBuildRailroadStation(), CmdBuildTrainWaypoint(), and DrawStationTile().

const StationSpec* GetCustomStationSpecByGrf | ( | uint32 | grfid,
|  | byte | localidx,
|  | int * | index |
| ) |  |  |

Retrieve a station spec by GRF location.

Parameters:

  | grfid | GRF ID of station spec.
  | localidx | Index within GRF file of station spec.
  | index | Pointer to return the index of the station spec in its station class. If NULL then not used.

Returns:
  The station spec.

Definition at line 166 of file newgrf_station.cpp.

References StationClass::spec, STAT_CLASS_BEGIN, STAT_CLASS_MAX, and StationClass::stations.

Referenced by AIRail::BuildNewGRFRailStation().

uint GetNumCustomStations | ( | StationClassID | sclass | ) |

Return the number of stations for the given station class.

Parameters:

  | sclass | Index of the station class.

Returns:
  Number of stations in the class.

Definition at line 114 of file newgrf_station.cpp.

References STAT_CLASS_MAX, and StationClass::stations.

Referenced by AfterLoadWaypoints(), BuildRailClick_Waypoint(), CmdBuildTrainWaypoint(), and ShowStationBuilder().

uint GetNumStationClasses | ( |  | ) |

Get the number of station classes in use.

Returns:
  Number of station classes.

Definition at line 102 of file newgrf_station.cpp.

References StationClass::id, and STAT_CLASS_MAX.

Referenced by CmdBuildRailroadStation(), and ShowStationBuilder().

void ResetStationClasses | ( |  | ) |

Reset station classes to their default state.

This includes initialising the Default and Waypoint classes with an empty entry, for standard stations and waypoints.

Definition at line 37 of file newgrf_station.cpp.

References StationClass::id, StationClass::name, StationClass::spec, STAT_CLASS_BEGIN, STAT_CLASS_MAX, and StationClass::stations.

Referenced by ResetNewGRFData().

void SetCustomStationSpec | ( | StationSpec * | statspec | ) |

Tie a station spec to its station class.

Parameters:

  | statspec | The station spec.

Definition at line 124 of file newgrf_station.cpp.

References ReallocT(), StationClass::spec, STAT_CLASS_MAX, and StationClass::stations.

void StationUpdateAnimTriggers | ( | Station * | st | ) |

Update the cached animation trigger bitmask for a station.

Parameters:

  | st | Station to update.

Definition at line 1058 of file newgrf_station.cpp.

References Station::cached_anim_triggers, Station::num_specs, and Station::speclist.

Referenced by DeallocateSpecFromStation().