# Train Struct Reference

'Train' is either a loco or a wagon. More...

`#include <train.h>`

Inheritance diagram for Train:

## Public Types

enum | TrainSubtype { TS_FRONT = 0, TS_ARTICULATED_PART = 1, TS_WAGON = 2, TS_ENGINE = 3, TS_FREE_WAGON = 4, TS_MULTIHEADED = 5 }
| enum to handle train subtypes Do not access it directly unless you have to. More...

## Public Member Functions

| Train ()
| We don't want GCC to zero our struct! It already is zeroed and has an index!
virtual | ~Train ()
| We want to 'destruct' the right class.
const char * | GetTypeString () const
void | MarkDirty ()
void | UpdateDeltaXY (Direction direction)
ExpensesType | GetExpenseType (bool income) const
void | PlayLeaveStationSound () const
bool | IsPrimaryVehicle () const
SpriteID | GetImage (Direction direction) const
int | GetDisplaySpeed () const
int | GetDisplayMaxSpeed () const
Money | GetRunningCost () const
int | GetDisplayImageWidth (Point *offset=NULL) const
| Get the width of a train vehicle image in the GUI.
bool | IsInDepot () const
bool | IsStoppedInDepot () const
bool | Tick ()
void | OnNewDay ()
uint | Crash (bool flooded=false)
Trackdir | GetVehicleTrackdir () const
TileIndex | GetOrderStationLocation (StationID station)
bool | FindClosestDepot (TileIndex *location, DestinationID *destination, bool *reverse)
void | ReserveTrackUnderConsist () const
| Tries to reserve track under whole train consist.
FORCEINLINE void | SetFrontEngine ()
| Set front engine state.
FORCEINLINE void | ClearFrontEngine ()
| Remove the front engine state.
FORCEINLINE void | SetArticulatedPart ()
| Set a vehicle to be an articulated part.
FORCEINLINE void | ClearArticulatedPart ()
| Clear a vehicle from being an articulated part.
FORCEINLINE void | SetWagon ()
| Set a vehicle to be a wagon.
FORCEINLINE void | ClearWagon ()
| Clear wagon property.
FORCEINLINE void | SetEngine ()
| Set engine status.
FORCEINLINE void | ClearEngine ()
| Clear engine status.
FORCEINLINE void | SetFreeWagon ()
| Set if a vehicle is a free wagon.
FORCEINLINE void | ClearFreeWagon ()
| Clear a vehicle from being a free wagon.
FORCEINLINE void | SetMultiheaded ()
| Set if a vehicle is a multiheaded engine.
FORCEINLINE void | ClearMultiheaded ()
| Clear multiheaded engine property.
FORCEINLINE bool | IsFrontEngine () const
| Check if train is a front engine.
FORCEINLINE bool | IsFreeWagon () const
| Check if train is a free wagon (got no engine in front of it).
FORCEINLINE bool | IsEngine () const
| Check if a vehicle is an engine (can be first in a train).
FORCEINLINE bool | IsWagon () const
| Check if a train is a wagon.
FORCEINLINE bool | IsMultiheaded () const
| Check if train is a multiheaded engine.
FORCEINLINE bool | IsRearDualheaded () const
| Tell if we are dealing with the rear end of a multiheaded engine.
FORCEINLINE bool | IsArticulatedPart () const
| Check if train is an articulated part of an engine.
FORCEINLINE bool | HasArticulatedPart () const
| Check if an engine has an articulated part.
FORCEINLINE Train * | GetNextArticPart () const
| Get the next part of a multi-part engine.
FORCEINLINE Train * | GetFirstEnginePart ()
| Get the first part of a multi-part engine.
FORCEINLINE const Train * | GetFirstEnginePart () const
| Get the first part of a multi-part engine.
FORCEINLINE Train * | GetLastEnginePart ()
| Get the last part of a multi-part engine.
FORCEINLINE Train * | GetNextVehicle () const
| Get the next real (non-articulated part) vehicle in the consist.
FORCEINLINE Train * | GetPrevVehicle () const
| Get the previous real (non-articulated part) vehicle in the consist.
FORCEINLINE Train * | GetNextUnit () const
| Get the next real (non-articulated part and non rear part of dualheaded engine) vehicle in the consist.
FORCEINLINE Train * | GetPrevUnit ()
| Get the previous real (non-articulated part and non rear part of dualheaded engine) vehicle in the consist.

## Data Fields

TrainCache | tcache
Train * | other_multiheaded_part
uint16 | crash_anim_pos
uint16 | flags
TrackBitsByte | track
byte | force_proceed
RailTypeByte | railtype
RailTypes | compatible_railtypes

## Detailed Description

'Train' is either a loco or a wagon.

Definition at line 105 of file train.h.

## Member Enumeration Documentation

enum Train::TrainSubtype

enum to handle train subtypes Do not access it directly unless you have to.

Use the access functions below This is an enum to tell what bit to access as it is a bitmask

Enumerator:

  TS_FRONT | Leading engine of a train.
  TS_ARTICULATED_PART | Articulated part of an engine.
  TS_WAGON | Wagon.
  TS_ENGINE | Engine, that can be front engine, but might be placed behind another engine.
  TS_FREE_WAGON | First in a wagon chain (in depot).
  TS_MULTIHEADED | Engine is multiheaded.

Definition at line 151 of file train.h.

## Constructor & Destructor Documentation

virtual Train::~Train | ( |  | ) | `[inline, virtual]`

We want to 'destruct' the right class.

Definition at line 122 of file train.h.

## Member Function Documentation

int Train::GetDisplayImageWidth | ( | Point * | offset = `NULL` | ) | const

Get the width of a train vehicle image in the GUI.

Parameters:

  | offset | Additional offset for positioning the sprite; set to NULL if not needed

Returns:
  Width in pixels

Definition at line 597 of file train_cmd.cpp.

References TrainCache::cached_veh_length, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::Get(), Point::x, and Point::y.

Referenced by DrawTrainDetails(), DrawTrainImage(), and GetLengthOfArticulatedVehicle().

FORCEINLINE bool Train::IsFrontEngine | ( |  | ) | const`[inline]`

Check if train is a front engine.

Returns:
  Returns true if train is a front engine

Definition at line 225 of file train.h.

References HasBit(), and TS_FRONT.

Referenced by AfterLoadVehicles(), CmdAutoreplaceVehicle(), CmdCloneVehicle(), CmdMoveRailVehicle(), CmdSellRailWagon(), FreeTrainTrackReservation(), GetTrainAcceleration(), NormaliseTrainHead(), RemoveAndSellVehicle(), SettingsDisableElrail(), SetTrainGroupID(), TrainApproachingCrossingEnum(), TrainApproachingCrossingTile(), TrainConsistChanged(), TryPathReserve(), UpdateTrainGroupID(), and WhoCanServiceIndustry().

FORCEINLINE bool Train::IsFreeWagon | ( |  | ) | const`[inline]`

Check if train is a free wagon (got no engine in front of it).

Returns:
  Returns true if train is a free wagon

Definition at line 231 of file train.h.

References HasBit(), and TS_FREE_WAGON.

Referenced by AfterLoadVehicles(), BuildDepotVehicleList(), CmdBuildRailWagon(), NormalizeTrainVehInDepot(), TrainConsistChanged(), and UpdateTrainGroupID().

FORCEINLINE bool Train::IsEngine | ( |  | ) | const`[inline]`

Check if a vehicle is an engine (can be first in a train).

Returns:
  Returns true if vehicle is an engine

Definition at line 237 of file train.h.

References HasBit(), and TS_ENGINE.

Referenced by AfterLoadVehicles(), CheckNewTrain(), CheckTrainAttachment(), CmdMoveRailVehicle(), CmdSellRailWagon(), IsRearDualheaded(), NormaliseDualHeads(), and NormaliseSubtypes().

FORCEINLINE bool Train::IsWagon | ( |  | ) | const`[inline]`

Check if a train is a wagon.

Returns:
  Returns true if vehicle is a wagon

Definition at line 243 of file train.h.

References HasBit(), and TS_WAGON.

Referenced by NormaliseSubtypes().

FORCEINLINE bool Train::IsMultiheaded | ( |  | ) | const`[inline]`

Check if train is a multiheaded engine.

Returns:
  Returns true if vehicle is a multiheaded engine

Definition at line 249 of file train.h.

References HasBit(), and TS_MULTIHEADED.

Referenced by ArrangeTrains(), CmdReverseTrainDirection(), IsRearDualheaded(), and NormaliseDualHeads().

FORCEINLINE bool Train::IsRearDualheaded | ( |  | ) | const`[inline]`

Tell if we are dealing with the rear end of a multiheaded engine.

Returns:
  True if the engine is the rear part of a dualheaded engine.

Definition at line 255 of file train.h.

References IsEngine(), and IsMultiheaded().

Referenced by BuildDepotVehicleList(), CheckTrainAttachment(), CmdAutoreplaceVehicle(), CmdCloneVehicle(), CmdMoveRailVehicle(), CmdSellRailWagon(), GetNewEngineType(), GetNextUnit(), GetPrevUnit(), and ReplaceFreeUnit().

FORCEINLINE bool Train::IsArticulatedPart | ( |  | ) | const`[inline]`

Check if train is an articulated part of an engine.

Returns:
  Returns true if train is an articulated part

Definition at line 261 of file train.h.

References HasBit(), and TS_ARTICULATED_PART.

Referenced by BuildDepotVehicleList(), CheckTrainAttachment(), CmdAutoreplaceVehicle(), DrawTrainDetails(), GetCargoSummaryOfArticulatedVehicle(), GetFirstEnginePart(), GetLengthOfArticulatedVehicle(), GetNewEngineType(), GetPrevVehicle(), HasArticulatedPart(), InsertInConsist(), ReplaceFreeUnit(), TransferCargo(), and UpdateTrainPowerProc().

FORCEINLINE bool Train::HasArticulatedPart | ( |  | ) | const`[inline]`

Check if an engine has an articulated part.

Returns:
  True if the engine has an articulated part.

Definition at line 267 of file train.h.

References IsArticulatedPart(), and SpecializedVehicle< Train, VEH_TRAIN >::Next().

Referenced by CheckConsistencyOfArticulatedVehicle(), CmdCloneVehicle(), GetLastEnginePart(), GetNextArticPart(), GetNextVehicle(), and IsArticulatedVehicleCarryingDifferentCargos().

FORCEINLINE Train* Train::GetNextArticPart | ( |  | ) | const`[inline]`

Get the next part of a multi-part engine.

Will only work on a multi-part engine (this->EngineHasArticPart() == true), Result is undefined for normal engine.

Returns:
  next part of articulated engine

Definition at line 276 of file train.h.

References HasArticulatedPart(), and SpecializedVehicle< Train, VEH_TRAIN >::Next().

Referenced by CheckConsistencyOfArticulatedVehicle(), CmdCloneVehicle(), GetLastEnginePart(), GetNextVehicle(), and IsArticulatedVehicleCarryingDifferentCargos().

FORCEINLINE Train* Train::GetFirstEnginePart | ( |  | ) | `[inline]`

Get the first part of a multi-part engine.

Returns:
  First part of the engine.

Definition at line 286 of file train.h.

References IsArticulatedPart(), and SpecializedVehicle< T, Type >::Previous().

Referenced by CmdMoveRailVehicle(), and CmdSellRailWagon().

FORCEINLINE const Train* Train::GetFirstEnginePart | ( |  | ) | const`[inline]`

Get the first part of a multi-part engine.

Returns:
  First part of the engine.

Definition at line 297 of file train.h.

References IsArticulatedPart(), and SpecializedVehicle< T, Type >::Previous().

FORCEINLINE Train* Train::GetLastEnginePart | ( |  | ) | `[inline]`

Get the last part of a multi-part engine.

Returns:
  Last part of the engine.

Definition at line 308 of file train.h.

References GetNextArticPart(), and HasArticulatedPart().

Referenced by CmdMoveRailVehicle(), RemoveFromConsist(), and TransferCargo().

FORCEINLINE Train* Train::GetNextVehicle | ( |  | ) | const`[inline]`

Get the next real (non-articulated part) vehicle in the consist.

Returns:
  Next vehicle in the consist.

Definition at line 319 of file train.h.

References GetNextArticPart(), HasArticulatedPart(), and SpecializedVehicle< T, Type >::Next().

Referenced by ArrangeTrains(), CmdCloneVehicle(), DrawTrainDetails(), GetNextUnit(), GetTrainDetailsWndVScroll(), and NormaliseDualHeads().

FORCEINLINE Train* Train::GetPrevVehicle | ( |  | ) | const`[inline]`

Get the previous real (non-articulated part) vehicle in the consist.

Returns:
  Previous vehicle in the consist.

Definition at line 332 of file train.h.

References IsArticulatedPart(), SpecializedVehicle< T, Type >::Previous(), and SpecializedVehicle< Train, VEH_TRAIN >::Previous().

Referenced by GetPrevUnit().

FORCEINLINE Train* Train::GetNextUnit | ( |  | ) | const`[inline]`

Get the next real (non-articulated part and non rear part of dualheaded engine) vehicle in the consist.

Returns:
  Next vehicle in the consist.

Definition at line 344 of file train.h.

References GetNextVehicle(), and IsRearDualheaded().

Referenced by AIVehicle::_MoveWagonInternal(), AIVehicle::_SellWagonInternal(), ArrangeTrains(), CmdAutoreplaceVehicle(), AIVehicle::GetNumWagons(), and ReplaceChain().

FORCEINLINE Train* Train::GetPrevUnit | ( |  | ) | `[inline]`

Get the previous real (non-articulated part and non rear part of dualheaded engine) vehicle in the consist.

Returns:
  Previous vehicle in the consist.

Definition at line 356 of file train.h.

References GetPrevVehicle(), and IsRearDualheaded().

Referenced by ReplaceChain().

The documentation for this struct was generated from the following files:

- src/train.h
- src/train_cmd.cpp