# newgrf_station.cpp File Reference

Functions for dealing with station classes and custom stations. More...

`#include "stdafx.h"`
`#include "variables.h"`
`#include "debug.h"`
`#include "station_base.h"`
`#include "waypoint_base.h"`
`#include "roadstop_base.h"`
`#include "newgrf_cargo.h"`
`#include "newgrf_commons.h"`
`#include "newgrf_station.h"`
`#include "newgrf_spritegroup.h"`
`#include "newgrf_sound.h"`
`#include "town.h"`
`#include "newgrf_town.h"`
`#include "date_func.h"`
`#include "company_func.h"`
`#include "animated_tile_func.h"`
`#include "functions.h"`
`#include "tunnelbridge_map.h"`
`#include "newgrf.h"`
`#include "core/random_func.hpp"`
`#include "table/strings.h"`

Go to the source code of this file.

## Data Structures
struct | ETileArea
## Enumerations
enum | { MAX_SPECLIST = 255 }
enum | TriggerArea { TA_TILE, TA_PLATFORM, TA_WHOLE }
## Functions
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.
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)
static TileIndex | FindRailStationEnd (TileIndex tile, TileIndexDiff delta, bool check_type, bool check_axis)
static uint32 | GetPlatformInfoHelper (TileIndex tile, bool check_type, bool check_axis, bool centred)
static uint32 | GetRailContinuationInfo (TileIndex tile)
static uint32 | StationGetRandomBits (const ResolverObject *object)
static uint32 | StationGetTriggers (const ResolverObject *object)
static void | StationSetTriggers (const ResolverObject *object, int triggers)
static uint32 | StationGetVariable (const ResolverObject *object, byte variable, byte parameter, bool *available)
static const SpriteGroup * | StationResolveReal (const ResolverObject *object, const RealSpriteGroup *group)
static void | NewStationResolver (ResolverObject *res, const StationSpec *statspec, const BaseStation *st, TileIndex tile)
static const SpriteGroup * | ResolveStation (ResolverObject *object)
SpriteID | GetCustomStationRelocation (const StationSpec *statspec, const BaseStation *st, TileIndex tile)
SpriteID | GetCustomStationGroundRelocation (const StationSpec *statspec, const BaseStation *st, TileIndex tile)
SpriteID | GetCustomStationFoundationRelocation (const StationSpec *statspec, const BaseStation *st, TileIndex tile)
uint16 | GetStationCallback (CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, const BaseStation *st, TileIndex tile)
int | AllocateSpecToStation (const StationSpec *statspec, BaseStation *st, bool exec)
| Allocate a StationSpec to a Station.
void | DeallocateSpecFromStation (BaseStation *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.
const StationSpec * | GetStationSpec (TileIndex t)
bool | IsStationTileBlocked (TileIndex tile)
bool | IsStationTileElectrifiable (TileIndex tile)
void | AnimateStationTile (TileIndex tile)
static void | ChangeStationAnimationFrame (const StationSpec *ss, const BaseStation *st, TileIndex tile, uint16 random_bits, StatAnimTrigger trigger, CargoID cargo_type)
void | StationAnimationTrigger (const BaseStation *st, TileIndex tile, StatAnimTrigger trigger, CargoID cargo_type)
void | StationUpdateAnimTriggers (BaseStation *st)
| Update the cached animation trigger bitmask for a station.
## Variables
static StationClass | _station_classes [STAT_CLASS_MAX]
struct {
uint32 v40
uint32 v41
uint32 v45
uint32 v46
uint32 v47
uint32 v49
uint8 valid
} | _svc
| Station variable cache This caches 'expensive' station variable lookups which iterate over several tiles that may be called multiple times per Resolve().

## Detailed Description

Functions for dealing with station classes and custom stations.

Definition in file newgrf_station.cpp.

## Function Documentation

int AllocateSpecToStation | ( | const StationSpec * | statspec,
|  | BaseStation * | 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 782 of file newgrf_station.cpp.

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

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

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

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

void DeallocateSpecFromStation | ( | BaseStation * | 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 832 of file newgrf_station.cpp.

References BaseStation::cached_anim_triggers, GetCustomStationSpecIndex(), INVALID_TILE, BaseStation::num_specs, ReallocT(), BaseStation::speclist, StationUpdateAnimTriggers(), TILE_AREA_LOOP, and BaseStation::TileBelongsToRailStation().

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

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

References CALLBACK_FAILED, CBID_STATION_SPRITE_LAYOUT, CBM_STATION_SPRITE_LAYOUT, RailtypeInfo::custom_ground_offset, DrawRailTileSeqInGUI(), DrawSprite(), GetCustomStationSpec(), GetRailTypeInfo(), DrawTileSprites::ground, GroundSpritePaletteTransform(), HasBit(), INVALID_TILE, PalSpriteID::pal, PalSpriteID::sprite, SPRITE_MODIFIER_CUSTOM_SPRITE, and RailtypeInfo::total_offset.

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

References StationClass::spec, and STAT_CLASS_MAX.

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

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

References STAT_CLASS_MAX, and StationClass::stations.

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

uint GetNumStationClasses | ( |  | ) |

Get the number of station classes in use.

Returns:
  Number of station classes.

Definition at line 151 of file newgrf_station.cpp.

References StationClass::id, and STAT_CLASS_MAX.

Referenced by CmdBuildRailStation(), 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 86 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 173 of file newgrf_station.cpp.

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

void StationUpdateAnimTriggers | ( | BaseStation * | st | ) |

Update the cached animation trigger bitmask for a station.

Parameters:

  | st | Station to update.

Definition at line 1072 of file newgrf_station.cpp.

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

Referenced by DeallocateSpecFromStation().