OpenTTD: src/newgrf_station.h File Reference

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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

Header file for NewGRF stations. More...

`#include "newgrf_animation_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 | StationResolverObject
| Station resolver. More...
struct | EnumPropsT< StationClassID >
struct | StationSpec
| Station specification. More...

## Typedefs
typedef SimpleTinyEnumT < StationClassID, byte > | StationClassIDByte
typedef byte * | StationLayout
typedef NewGRFClass < StationSpec, StationClassID, STAT_CLASS_MAX > | StationClass
| Struct containing information relating to station classes.

## Enumerations
enum | StationClassID { STAT_CLASS_BEGIN = 0, STAT_CLASS_DFLT = 0, STAT_CLASS_WAYP, STAT_CLASS_MAX = 256 }
enum | StationSpecFlags { SSF_SEPARATE_GROUND, SSF_DIV_BY_STATION_SIZE, SSF_CB141_RANDOM_BITS, SSF_CUSTOM_FOUNDATIONS, SSF_EXTENDED_FOUNDATIONS }
| Allow incrementing of StationClassID variables. More...
enum | StationRandomTrigger { SRT_NEW_CARGO, SRT_CARGO_TAKEN, SRT_TRAIN_ARRIVES, SRT_TRAIN_DEPARTS, SRT_TRAIN_LOADS, SRT_PATH_RESERVATION }
| Randomisation triggers for stations. More...

## Functions
const StationSpec * | GetStationSpec (TileIndex t)
uint32 | GetPlatformInfo (Axis axis, byte 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 var10=0)
| Resolve sprites for drawing a station tile.
SpriteID | GetCustomStationFoundationRelocation (const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info)
| Resolve the sprites for custom station foundations.
uint16 | GetStationCallback (CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, BaseStation *st, TileIndex tile)
CommandCost | PerformStationTileSlopeCheck (TileIndex north_tile, TileIndex cur_tile, const StationSpec *statspec, Axis axis, byte plat_len, byte numtracks)
| Check the slope of a tile of a new station.
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.
void | AnimateStationTile (TileIndex tile)
void | TriggerStationAnimation (BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type=CT_INVALID)
void | TriggerStationRandomisation (Station *st, TileIndex tile, StationRandomTrigger trigger, CargoID cargo_type=CT_INVALID)
| Trigger station randomisation.
void | StationUpdateCachedTriggers (BaseStation *st)
| Update the cached animation trigger bitmask for a station.

## Detailed Description

Header file for NewGRF stations.

Definition in file newgrf_station.h.

## Typedef Documentation

typedef NewGRFClass<StationSpec, StationClassID, STAT_CLASS_MAX> StationClass

Struct containing information relating to station classes.

Definition at line 165 of 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 72 of file newgrf_station.h.

enum StationRandomTrigger

Randomisation triggers for stations.

Enumerator:

  SRT_NEW_CARGO | Trigger station on new cargo arrival.
  SRT_CARGO_TAKEN | Trigger station when cargo is completely taken.
  SRT_TRAIN_ARRIVES | Trigger platform when train arrives.
  SRT_TRAIN_DEPARTS | Trigger platform when train leaves.
  SRT_TRAIN_LOADS | Trigger platform when train loads/unloads.
  SRT_PATH_RESERVATION | Trigger platform when train reserves path.

Definition at line 93 of file newgrf_station.h.

enum StationSpecFlags

Allow incrementing of StationClassID variables.

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

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

References StationSpec::grf_prop, GRFFilePropsBase< Tcnt >::grffile, StationSpecList::grfid, GRFFilePropsBase< Tcnt >::local_id, StationSpecList::localidx, BaseStation::num_specs, NUM_STATIONSSPECS_PER_STATION, ReallocT(), BaseStation::speclist, and StationUpdateCachedTriggers().

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

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

References BaseStation::cached_anim_triggers, BaseStation::cached_cargo_triggers, free(), GetCustomStationSpecIndex(), StationSpecList::grfid, INVALID_TILE, StationSpecList::localidx, BaseStation::num_specs, ReallocT(), BaseStation::speclist, StationUpdateCachedTriggers(), 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 780 of file newgrf_station.cpp.

References _local_company, CALLBACK_FAILED, StationSpec::callback_mask, CBID_STATION_SPRITE_LAYOUT, CBM_STATION_SPRITE_LAYOUT, DrawRailTileSeqInGUI(), DrawSprite(), RailtypeInfo::fallback_railtype, StationSpec::flags, FOR_EACH_SET_BIT, NewGRFClass< Tspec, Tid, Tmax >::Get(), GetCustomRailSprite(), GetCustomStationRelocation(), NewGRFSpriteLayout::GetLayout(), GetRailTypeInfo(), RailtypeInfo::GetRailtypeSpriteOffset(), DrawTileSprites::ground, GroundSpritePaletteTransform(), HasBit(), INVALID_TILE, NewGRFSpriteLayout::NeedsPreprocessing(), PalSpriteID::pal, NewGRFSpriteLayout::PrepareLayout(), NewGRFSpriteLayout::ProcessRegisters(), StationSpec::renderdata, RTSG_GROUND, DrawTileSprites::seq, SplitGroundSpriteForOverlay(), PalSpriteID::sprite, SPRITE_MODIFIER_CUSTOM_SPRITE, SSF_SEPARATE_GROUND, and StationSpec::tiles.

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

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

References CBID_NO_CALLBACK, GetRegister(), and SpriteGroup::Resolve().

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

Resolve sprites for drawing a station tile.

Parameters

  statspec | Station spec
  st | Station (NULL 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 SSF_SEPARATE_GROUND is set.

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

Definition at line 606 of file newgrf_station.cpp.

References CBID_NO_CALLBACK, and SpriteGroup::Resolve().

Referenced by DrawStationTile().

uint32 GetPlatformInfo | ( | Axis | axis,
|  | byte | 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 107 of file newgrf_station.cpp.

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

Referenced by CmdBuildRailStation().

CommandCost PerformStationTileSlopeCheck | ( | TileIndex | north_tile,
|  | TileIndex | cur_tile,
|  | const StationSpec * | statspec,
|  | Axis | axis,
|  | byte | plat_len,
|  | byte | 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 652 of file newgrf_station.cpp.

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

Referenced by CheckFlatLandRailStation().

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

Update the cached animation trigger bitmask for a station.

Parameters

  st | Station to update.

Definition at line 1047 of file newgrf_station.cpp.

References BaseStation::cached_anim_triggers, BaseStation::cached_cargo_triggers, StationSpec::cargo_triggers, BaseStation::num_specs, BaseStation::speclist, and AnimationInfo::triggers.

Referenced by AllocateSpecToStation(), and DeallocateSpecFromStation().

void TriggerStationRandomisation | ( | Station * | st,
|  | TileIndex | tile,
|  | StationRandomTrigger | trigger,
|  | CargoID | cargo_type
| ) |  |

Trigger station randomisation.

Parameters

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

Definition at line 965 of file newgrf_station.cpp.

References BaseStation::cached_cargo_triggers, GoodsEntry::cargo, StationSpec::cargo_triggers, CBID_RANDOM_TRIGGER, CT_INVALID, SpecializedStation< Station, false >::GetByTile(), GetStationTileRandomBits(), Station::goods, HasBit(), MarkTileDirtyByTile(), NUM_CARGO, BaseStation::random_bits, SpriteGroup::Resolve(), SetBit(), SetStationTileRandomBits(), SRT_CARGO_TAKEN, TILE_AREA_LOOP, Station::TileBelongsToRailStation(), StationCargoList::TotalCount(), and BaseStation::waiting_triggers.

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