OpenTTD
Data Structures | Enumerations | Functions | Variables
newgrf_station.cpp File Reference

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

#include "stdafx.h"
#include "debug.h"
#include "station_base.h"
#include "waypoint_base.h"
#include "roadstop_base.h"
#include "newgrf_cargo.h"
#include "newgrf_station.h"
#include "newgrf_spritegroup.h"
#include "newgrf_sound.h"
#include "newgrf_railtype.h"
#include "town.h"
#include "newgrf_town.h"
#include "company_func.h"
#include "tunnelbridge_map.h"
#include "newgrf_animation_base.h"
#include "newgrf_class_func.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  ETileArea
 
struct  StationAnimationBase
 Helper class for animation control. More...
 

Enumerations

enum  TriggerArea { TA_TILE, TA_PLATFORM, TA_WHOLE }
 

Functions

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. More...
 
static TileIndex FindRailStationEnd (TileIndex tile, TileIndexDiff delta, bool check_type, bool check_axis)
 Find the end of a railway station, from the tile, in the direction of delta. More...
 
static uint32 GetPlatformInfoHelper (TileIndex tile, bool check_type, bool check_axis, bool centred)
 
static uint32 GetRailContinuationInfo (TileIndex tile)
 
SpriteID GetCustomStationRelocation (const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32 var10)
 Resolve sprites for drawing a station tile. More...
 
SpriteID GetCustomStationFoundationRelocation (const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info)
 Resolve the sprites for custom station foundations. More...
 
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. More...
 
int AllocateSpecToStation (const StationSpec *statspec, BaseStation *st, bool exec)
 Allocate a StationSpec to a Station. More...
 
void DeallocateSpecFromStation (BaseStation *st, byte specindex)
 Deallocate a StationSpec from a Station. More...
 
bool DrawStationTile (int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
 Draw representation of a station tile for GUI purposes. More...
 
const StationSpecGetStationSpec (TileIndex t)
 
bool IsStationTileBlocked (TileIndex tile)
 Check whether a rail station tile is NOT traversable. More...
 
bool CanStationTileHavePylons (TileIndex tile)
 Check if a rail station tile shall have pylons when electrified. More...
 
bool CanStationTileHaveWires (TileIndex tile)
 Check if a rail station tile shall have wires when electrified. More...
 
uint16 GetAnimStationCallback (CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, BaseStation *st, TileIndex tile, int extra_data)
 Wrapper for animation control, see #GetStationCallback. More...
 
void AnimateStationTile (TileIndex tile)
 
void TriggerStationAnimation (BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type)
 
void TriggerStationRandomisation (Station *st, TileIndex tile, StationRandomTrigger trigger, CargoID cargo_type)
 Trigger station randomisation. More...
 
void StationUpdateCachedTriggers (BaseStation *st)
 Update the cached animation trigger bitmask for a station. More...
 

Variables

static const uint NUM_STATIONSSPECS_PER_STATION = 255
 Maximum number of parts per station.
 
struct {
   uint32   v40
 
   uint32   v41
 
   uint32   v45
 
   uint32   v46
 
   uint32   v47
 
   uint32   v49
 
   uint8   valid
 Bits indicating what variable is valid (for each bit, 0 is invalid, 1 is 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

◆ AllocateSpecToStation()

int AllocateSpecToStation ( const StationSpec statspec,
BaseStation st,
bool  exec 
)

Allocate a StationSpec to a Station.

This is called once per build operation.

Parameters
statspecStationSpec to allocate.
stStation to allocate it to.
execWhether to actually allocate the spec.
Returns
Index within the Station's spec list, or -1 if the allocation failed.

Definition at line 663 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().

◆ CanStationTileHavePylons()

bool CanStationTileHavePylons ( TileIndex  tile)

Check if a rail station tile shall have pylons when electrified.

Parameters
tileTile to test.
Returns
Tile shall have pylons.
Note
This could be cached (during build) in the map array to save on all the dereferencing.

Definition at line 864 of file newgrf_station.cpp.

◆ CanStationTileHaveWires()

bool CanStationTileHaveWires ( TileIndex  tile)

Check if a rail station tile shall have wires when electrified.

Parameters
tileTile to test.
Returns
Tile shall have wires.
Note
This could be cached (during build) in the map array to save on all the dereferencing.

Definition at line 878 of file newgrf_station.cpp.

Referenced by MaskWireBits().

◆ DeallocateSpecFromStation()

void DeallocateSpecFromStation ( BaseStation st,
byte  specindex 
)

Deallocate a StationSpec from a Station.

Called when removing a single station tile.

Parameters
stStation to work with.
specindexIndex of the custom station within the Station's spec list.
Returns
Indicates whether the StationSpec was deallocated.

Definition at line 716 of file newgrf_station.cpp.

References INVALID_TILE.

◆ 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
xPosition x of image.
yPosition y of image.
axisAxis.
railtypeRail type.
sclass,stationType of station.
stationstation ID
Returns
True if the tile was drawn (allows for fallback to default graphic)

Definition at line 763 of file newgrf_station.cpp.

◆ FindRailStationEnd()

static TileIndex FindRailStationEnd ( TileIndex  tile,
TileIndexDiff  delta,
bool  check_type,
bool  check_axis 
)
static

Find the end of a railway station, from the tile, in the direction of delta.

Parameters
tileStart tile.
deltaMovement direction.
check_typeStop when the custom station type changes.
check_axisStop when the station direction changes.
Returns
Found end of the railway station.

Definition at line 145 of file newgrf_station.cpp.

References AXIS_X, GetCustomStationSpecIndex(), GetRailStationAxis(), GetStationIndex(), HasStationRail(), IsTileType(), MP_STATION, OrthogonalTileArea::tile, and TILE_ADD.

◆ GetAnimStationCallback()

uint16 GetAnimStationCallback ( CallbackID  callback,
uint32  param1,
uint32  param2,
const StationSpec statspec,
BaseStation st,
TileIndex  tile,
int  extra_data 
)

Wrapper for animation control, see #GetStationCallback.

Definition at line 885 of file newgrf_station.cpp.

◆ GetCustomStationFoundationRelocation()

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

Resolve the sprites for custom station foundations.

Parameters
statspecStation spec
stStation
tileStation tile being drawn
layoutSpritelayout as returned by previous callback
edge_infoInformation 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 606 of file newgrf_station.cpp.

References CBID_NO_CALLBACK, and SpriteGroup::Resolve().

◆ GetCustomStationRelocation()

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

Resolve sprites for drawing a station tile.

Parameters
statspecStation spec
stStation (NULL in GUI)
tileStation tile being drawn (INVALID_TILE in GUI)
var10Value 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 589 of file newgrf_station.cpp.

References CBID_NO_CALLBACK, and SpriteGroup::Resolve().

◆ GetPlatformInfo()

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.

◆ IsStationTileBlocked()

bool IsStationTileBlocked ( TileIndex  tile)

Check whether a rail station tile is NOT traversable.

Parameters
tileTile to test.
Returns
Station tile is blocked.
Note
This could be cached (during build) in the map array to save on all the dereferencing.

Definition at line 851 of file newgrf_station.cpp.

Referenced by CmdConvertRail().

◆ PerformStationTileSlopeCheck()

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_tileNorther tile of the station rect.
cur_tileTile to check.
statspecStation spec.
axisAxis of the new station.
plat_lenPlatform length.
numtracksNumber of platforms.
Returns
Succeeded or failed command.

Definition at line 635 of file newgrf_station.cpp.

References AXIS_Y, CBID_STATION_LAND_SLOPE_CHECK, GetTileSlope(), and HasBit().

Referenced by CheckFlatLandRailStation().

◆ StationUpdateCachedTriggers()

void StationUpdateCachedTriggers ( BaseStation st)

Update the cached animation trigger bitmask for a station.

Parameters
stStation to update.

Definition at line 1030 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().

◆ TriggerStationRandomisation()

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

Trigger station randomisation.

Parameters
ststation being triggered
tilespecific tile of platform to trigger
triggertrigger type
cargo_typecargo type causing trigger

Definition at line 948 of file newgrf_station.cpp.

Referenced by CYapfReserveTrack< Types >::ReserveRailStationPlatform(), and TrainEnterStation().