Public Member Functions | Data Fields | Protected Member Functions | Friends

# Train Struct Reference

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

`#include <train.h>`

Inheritance diagram for Train:

## 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.
void | MarkDirty ()
| Marks the vehicles to be redrawn and updates cached variables.
void | UpdateDeltaXY (Direction direction)
| Updates the x and y offsets and the size of the sprite used for this vehicle.
ExpensesType | GetExpenseType (bool income) const
| Sets the expense type associated to this vehicle type.
void | PlayLeaveStationSound () const
| Play the sound associated with leaving the station.
bool | IsPrimaryVehicle () const
| Whether this is the primary vehicle in the chain.
SpriteID | GetImage (Direction direction) const
| Gets the sprite to show for the given direction.
int | GetDisplaySpeed () const
| Gets the speed in km-ish/h that can be sent into SetDParam for string processing.
int | GetDisplayMaxSpeed () const
| Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.
Money | GetRunningCost () const
| Gets the running cost of a vehicle.
int | GetDisplayImageWidth (Point *offset=NULL) const
| Get the width of a train vehicle image in the GUI.
bool | IsInDepot () const
| Check whether the vehicle is in the depot.
bool | IsStoppedInDepot () const
| Check whether the vehicle is in the depot *and* stopped.
bool | Tick ()
| Calls the tick handler of the vehicle.
void | OnNewDay ()
| Calls the new day handler of the vehicle.
uint | Crash (bool flooded=false)
| Common code executed for crashed ground vehicles.
Trackdir | GetVehicleTrackdir () const
| Returns the Trackdir on which the vehicle is currently located.
TileIndex | GetOrderStationLocation (StationID station)
| Determine the location for the station where the vehicle goes to next.
bool | FindClosestDepot (TileIndex *location, DestinationID *destination, bool *reverse)
| Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should reverse.
void | ReserveTrackUnderConsist () const
| Tries to reserve track under whole train consist.
int | GetCurveSpeedLimit () const
| Computes train speed limit caused by curves.
void | ConsistChanged (bool same_length)
| Recalculates the cached stuff of a train.
void | RailtypeChanged ()
| Update visual effect, power and acceleration caches.
int | UpdateSpeed ()
| This function looks at the vehicle and updates its speed (cur_speed and subspeed) variables.
void | UpdateAcceleration ()
int | GetCurrentMaxSpeed () const
| Calculates the maximum speed of the vehicle under its current conditions.
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
| Crash animation counter.
uint16 | flags
TrackBitsByte | track
TrainForceProceedingByte | force_proceed
RailTypeByte | railtype
RailTypes | compatible_railtypes
uint16 | signal_speedlimit
| The maximum speed of the last speed-signal passed by the train.
uint16 | wait_counter
| Ticks waiting in front of a signal, ticks being stuck or a counter for forced proceeding through signals.
## Protected Member Functions
FORCEINLINE uint16 | GetBreakdownSpeed () const
| Gets the speed a broken down train (low speed breakdown) is limited to.
FORCEINLINE uint16 | GetPower () const
| Allows to know the power value that this vehicle will use.
FORCEINLINE uint16 | GetPoweredPartPower (const Train *head) const
| Returns a value if this articulated part is powered.
FORCEINLINE uint16 | GetWeight () const
| Allows to know the weight value that this vehicle will use.
FORCEINLINE byte | GetTractiveEffort () const
| Allows to know the tractive effort value that this vehicle will use.
FORCEINLINE byte | GetAirDragArea () const
| Gets the area used for calculating air drag.
FORCEINLINE byte | GetAirDrag () const
| Gets the air drag coefficient of this vehicle.
FORCEINLINE AccelStatus | GetAccelerationStatus () const
| Checks the current acceleration status of this vehicle.
FORCEINLINE uint16 | GetCurrentSpeed () const
| Calculates the current speed of this vehicle.
FORCEINLINE uint32 | GetRollingFriction () const
| Returns the rolling friction coefficient of this vehicle.
FORCEINLINE int | GetAccelerationType () const
| Allows to know the acceleration type of a vehicle.
FORCEINLINE uint32 | GetSlopeSteepness () const
| Returns the slope steepness used by this vehicle.
FORCEINLINE uint16 | GetMaxTrackSpeed () const
| Gets the maximum speed allowed by the track for this vehicle.
FORCEINLINE bool | TileMayHaveSlopedTrack () const
| Checks if the vehicle is at a tile that can be sloped.
## Friends
struct | GroundVehicle< Train, VEH_TRAIN >

## Detailed Description

'Train' is either a loco or a wagon.

Definition at line 84 of file train.h.

## Constructor & Destructor Documentation

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

We want to 'destruct' the right class.

Definition at line 107 of file train.h.

References Vehicle::PreDestructor().

## Member Function Documentation

void Train::ConsistChanged | ( | bool | same_length | ) |

Recalculates the cached stuff of a train.

Should be called each time a vehicle is added to/removed from the chain, and when the game is loaded. Note: this needs to be called too for 'wagon chains' (in the depot, without an engine)

Parameters:

  | same_length | should length of vehicles stay the same?

Definition at line 185 of file train_cmd.cpp.

References _settings_game, TrainCache::cached_max_curve_speed, VehicleCache::cached_max_speed, TrainCache::cached_num_engines, TrainCache::cached_tilt, GroundVehicleCache::cached_total_length, CALLBACK_FAILED, EngineInfo::callback_mask, GroundVehicle< Train, VEH_TRAIN >::CargoChanged(), CBID_VEHICLE_LENGTH, CBM_VEHICLE_LENGTH, Clamp(), ClrBit(), EF_RAIL_TILTS, Vehicle::engine_type, GroundVehicle< Train, VEH_TRAIN >::gcache, SpecializedVehicle< Train, Type >::Get(), GetCurveSpeedLimit(), GetRailTypeInfo(), GetVehicleCallback(), GetVehicleCapacity(), HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::index, INVALID_ENGINE, Vehicle::InvalidateNewGRFCache(), InvalidateWindowData(), GroundVehicle< Train, VEH_TRAIN >::IsFreeWagon(), Vehicle::IsFrontEngine(), GroundVehicle< Train, VEH_TRAIN >::IsMultiheaded(), RailVehicleInfo::max_speed, min(), EngineInfo::misc_flags, RailVehicleInfo::pow_wag_power, RailVehicleInfo::power, RailtypeInfo::powered_railtypes, PROP_TRAIN_SPEED, PROP_TRAIN_USER_DATA, RAILVEH_WAGON, RailVehicleLengthChanged(), SetBit(), SetWindowDirty(), RailVehicleInfo::shorten_factor, RailVehicleInfo::user_def_data, UsesWagonOverride(), Vehicle::vcache, VE_DISABLE_WAGON_POWER, GameSettings::vehicle, VEHICLE_LENGTH, VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL, VRF_NEED_REPAIR, VRF_POWEREDWAGON, and VehicleSettings::wagon_speed_limits.

Referenced by AfterLoadGame(), AfterLoadVehicles(), CheckCaches(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdRefitVehicle(), CmdReverseTrainDirection(), DeleteLastWagon(), Vehicle::HandleBreakdown(), NormaliseTrainHead(), SettingsDisableElrail(), TransferCargo(), and VehicleEnterDepot().

uint Train::Crash | ( | bool | flooded = `false` | ) | `[virtual]`

Common code executed for crashed ground vehicles.

Parameters:

  | flooded | was this vehicle flooded?

Returns:
  number of victims

Reimplemented from GroundVehicle< Train, VEH_TRAIN >.

Definition at line 2937 of file train_cmd.cpp.

References ClearPathReservation(), GroundVehicle< T, Type >::Crash(), crash_anim_pos, Vehicle::fill_percent_te_id, FreeTrainTrackReservation(), GetOtherTunnelBridgeEnd(), GetVehicleTrackdir(), HasBit(), HideFillingPercent(), INVALID_TILE, Vehicle::IsFrontEngine(), IsTileType(), MP_TUNNELBRIDGE, SpecializedVehicle< T, Type >::Next(), SetTunnelBridgeReservation(), Vehicle::tile, TrainApproachingCrossingTile(), UpdateLevelCrossing(), and VRF_TRAIN_STUCK.

Referenced by TrainCrashed().

bool Train::FindClosestDepot | ( | TileIndex * | location,
|  | DestinationID * | destination,
|  | bool * | reverse |
| ) |  |  | `[virtual]`

Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should reverse.

Parameters:

  | location | where do we go to?
  | destination | what hangar do we go to?
  | reverse | should the vehicle be reversed?

Returns:
  true if a depot could be found.

Reimplemented from Vehicle.

Definition at line 2004 of file train_cmd.cpp.

References FindDepotData::best_length, FindClosestTrainDepot(), GetDepotIndex(), FindDepotData::reverse, and FindDepotData::tile.

FORCEINLINE AccelStatus Train::GetAccelerationStatus | ( |  | ) | const`[inline, protected]`

Checks the current acceleration status of this vehicle.

Returns:
  Acceleration status.

Definition at line 273 of file train.h.

References AS_BRAKE, HasBit(), Vehicle::vehstatus, VRF_BREAKDOWN_BRAKING, VRF_TRAIN_STUCK, and VS_STOPPED.

Referenced by UpdateSpeed().

FORCEINLINE int Train::GetAccelerationType | ( |  | ) | const`[inline, protected]`

Allows to know the acceleration type of a vehicle.

Returns:
  Acceleration type of the vehicle.

Definition at line 303 of file train.h.

References RailtypeInfo::acceleration_type, and GetRailTypeInfo().

FORCEINLINE byte Train::GetAirDrag | ( |  | ) | const`[inline, protected]`

Gets the air drag coefficient of this vehicle.

Returns:
  Air drag value from the engine.

Definition at line 264 of file train.h.

References Vehicle::engine_type.

FORCEINLINE byte Train::GetAirDragArea | ( |  | ) | const`[inline, protected]`

Gets the area used for calculating air drag.

Returns:
  Area of the engine in m^2.

Definition at line 254 of file train.h.

References TRACK_BIT_WORMHOLE, Vehicle::vehstatus, and VS_HIDDEN.

FORCEINLINE uint16 Train::GetBreakdownSpeed | ( |  | ) | const`[inline, protected]`

Gets the speed a broken down train (low speed breakdown) is limited to.

Note:
  This value is not cached, because changing cached_max_speed would have unwanted consequences (e.g. in the GUI).

Parameters:

  | v | The front engine of the vehicle.

Returns:
  The speed the train is limited to.

Definition at line 176 of file train.h.

References BREAKDOWN_LOW_SPEED, Vehicle::IsFrontEngine(), and min().

Referenced by GetCurrentMaxSpeed().

int Train::GetCurrentMaxSpeed | ( |  | ) | const

Calculates the maximum speed of the vehicle under its current conditions.

Returns:
  Maximum speed of the vehicle.

Definition at line 435 of file train_cmd.cpp.

References TrainCache::cached_max_curve_speed, GroundVehicleCache::cached_max_track_speed, Vehicle::cur_speed, Vehicle::current_order, GroundVehicle< Train, VEH_TRAIN >::gcache, GetBreakdownSpeed(), GetCurveSpeedLimit(), GetStationIndex(), GetTrainStopLocation(), HasBit(), IsRailStationTile(), max(), min(), Order::ShouldStopAtStation(), Vehicle::tile, TILE_SIZE, TRACK_BIT_DEPOT, and VRF_BREAKDOWN_SPEED.

Referenced by TrainDetailsInfoTab(), and UpdateSpeed().

FORCEINLINE uint16 Train::GetCurrentSpeed | ( |  | ) | const`[inline, protected]`

Calculates the current speed of this vehicle.

Returns:
  Current speed in km/h-ish.

Definition at line 282 of file train.h.

References Vehicle::cur_speed.

Referenced by GetRollingFriction().

int Train::GetCurveSpeedLimit | ( |  | ) | const

Computes train speed limit caused by curves.

Returns:
  imposed speed limit

Definition at line 366 of file train_cmd.cpp.

References _settings_game, TrainCache::cached_tilt, Clamp(), RailtypeInfo::curve_speed, DIRDIFF_45LEFT, DIRDIFF_45RIGHT, DIRDIFF_90LEFT, DIRDIFF_90RIGHT, DIRDIFF_SAME, DirDifference(), SpecializedVehicle< Train, Type >::First(), GetRailTypeInfo(), VehicleSettings::train_acceleration_model, and GameSettings::vehicle.

Referenced by ConsistChanged(), and GetCurrentMaxSpeed().

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 497 of file train_cmd.cpp.

References GroundVehicleCache::cached_veh_length, Vehicle::engine_type, GroundVehicle< Train, VEH_TRAIN >::gcache, SpecializedVehicle< Train, Type >::Get(), Engine::grf_prop, GRFFilePropsBase< Tcnt >::grffile, GRFFile::traininfo_vehicle_pitch, GRFFile::traininfo_vehicle_width, and VEHICLE_LENGTH.

Referenced by DrawTrainDetails(), DrawTrainImage(), GetLengthOfArticulatedVehicle(), GetVehicleWidth(), HighlightDragPosition(), and DepotWindow::OnPaint().

int Train::GetDisplayMaxSpeed | ( |  | ) | const`[inline, virtual]`

Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.

Returns:
  the vehicle's maximum speed

Reimplemented from Vehicle.

Definition at line 118 of file train.h.

References VehicleCache::cached_max_speed, and Vehicle::vcache.

Referenced by CYapfCostRailT< Types >::PfCalcCost().

int Train::GetDisplaySpeed | ( |  | ) | const`[inline, virtual]`

Gets the speed in km-ish/h that can be sent into SetDParam for string processing.

Returns:
  the vehicle's speed

Reimplemented from Vehicle.

Definition at line 117 of file train.h.

References GroundVehicle< Train, VEH_TRAIN >::gcache, and GroundVehicleCache::last_speed.

ExpensesType Train::GetExpenseType | ( | bool | income | ) | const`[inline, virtual]`

Sets the expense type associated to this vehicle type.

Parameters:

  | income | whether this is income or (running) expenses of the vehicle

Reimplemented from Vehicle.

Definition at line 113 of file train.h.

References EXPENSES_TRAIN_INC.

SpriteID Train::GetImage | ( | Direction | direction | ) | const`[virtual]`

Gets the sprite to show for the given direction.

Parameters:

  | direction | the direction the vehicle is facing

Returns:
  the sprite for the given vehicle in the given direction

Reimplemented from Vehicle.

Definition at line 520 of file train_cmd.cpp.

References Vehicle::cargo, Vehicle::cargo_cap, CargoList< Tinst, Tcont >::Count(), Vehicle::engine_type, SpecializedVehicle< Train, Type >::Get(), HasBit(), ReverseDir(), and VRF_REVERSE_DIRECTION.

Referenced by ChangeTrainDirRandomly(), and DrawTrainDetails().

FORCEINLINE uint16 Train::GetMaxTrackSpeed | ( |  | ) | const`[inline, protected]`

Gets the maximum speed allowed by the track for this vehicle.

Returns:
  Maximum speed allowed.

Definition at line 321 of file train.h.

References GetRailType(), GetRailTypeInfo(), RailtypeInfo::max_speed, and Vehicle::tile.

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 148 of file train.h.

References SpecializedVehicle< T, Type >::GetNextVehicle(), SpecializedVehicle< Train, Type >::GetNextVehicle(), and GroundVehicle< T, Type >::IsRearDualheaded().

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

TileIndex Train::GetOrderStationLocation | ( | StationID | station | ) | `[virtual]`

Determine the location for the station where the vehicle goes to next.

Things done for example are allocating slots in a road stop or exact location of the platform is determined for ships.

Parameters:

  | station | the station to make the next location of the vehicle.

Returns:
  the location (tile) to aim for.

Reimplemented from Vehicle.

Definition at line 2769 of file train_cmd.cpp.

References FACIL_TRAIN, BaseStation::facilities, SpecializedVehicle< Train, Type >::Get(), Vehicle::IncrementRealOrderIndex(), Vehicle::last_station_visited, and BaseStation::xy.

FORCEINLINE uint16 Train::GetPower | ( |  | ) | const`[inline, protected]`

Allows to know the power value that this vehicle will use.

Returns:
  Power value from the engine in HP, or zero if the vehicle is not powered.

Definition at line 193 of file train.h.

References Vehicle::engine_type, GetRailType(), HasPowerOnRail(), Vehicle::IsArticulatedPart(), GroundVehicle< Train, VEH_TRAIN >::IsMultiheaded(), PROP_TRAIN_POWER, and Vehicle::tile.

FORCEINLINE uint16 Train::GetPoweredPartPower | ( | const Train * | head | ) | const`[inline, protected]`

Returns a value if this articulated part is powered.

Returns:
  Power value from the articulated part in HP, or zero if it is not powered.

Definition at line 210 of file train.h.

References GroundVehicleCache::first_engine, GroundVehicle< Train, VEH_TRAIN >::gcache, GetRailType(), HasBit(), HasPowerOnRail(), Vehicle::tile, and VRF_POWEREDWAGON.

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 160 of file train.h.

References SpecializedVehicle< T, Type >::GetPrevVehicle(), SpecializedVehicle< Train, Type >::GetPrevVehicle(), and GroundVehicle< T, Type >::IsRearDualheaded().

Referenced by ReplaceChain().

FORCEINLINE uint32 Train::GetRollingFriction | ( |  | ) | const`[inline, protected]`

Returns the rolling friction coefficient of this vehicle.

Returns:
  Rolling friction coefficient in [1e-4].

Definition at line 291 of file train.h.

References GetCurrentSpeed().

Money Train::GetRunningCost | ( |  | ) | const`[virtual]`

Gets the running cost of a vehicle.

Returns:
  the vehicle's running cost

Reimplemented from Vehicle.

Definition at line 4048 of file train_cmd.cpp.

References Vehicle::engine_type, SpecializedVehicle< Train, Type >::Get(), SpecializedVehicle< T, Type >::GetNextVehicle(), GetPrice(), Engine::grf_prop, GRFFilePropsBase< Tcnt >::grffile, GroundVehicle< T, Type >::IsMultiheaded(), PROP_TRAIN_RUNNING_COST_FACTOR, and RailVehicleInfo::running_cost.

Referenced by OnNewDay().

FORCEINLINE uint32 Train::GetSlopeSteepness | ( |  | ) | const`[inline, protected]`

Returns the slope steepness used by this vehicle.

Returns:
  Slope steepness used by the vehicle.

Definition at line 312 of file train.h.

References _settings_game, VehicleSettings::train_slope_steepness, and GameSettings::vehicle.

FORCEINLINE byte Train::GetTractiveEffort | ( |  | ) | const`[inline, protected]`

Allows to know the tractive effort value that this vehicle will use.

Returns:
  Tractive effort value from the engine.

Definition at line 245 of file train.h.

References Vehicle::engine_type, and PROP_TRAIN_TRACTIVE_EFFORT.

Trackdir Train::GetVehicleTrackdir | ( |  | ) | const`[virtual]`

Returns the Trackdir on which the vehicle is currently located.

Works for trains and ships. Currently works only sortof for road vehicles, since they have a fuzzy concept of being "on" a trackdir. Dunno really what it returns for a road vehicle that is halfway a tile, never really understood that part. For road vehicles that are at the beginning or end of the tile, should just return the diagonal trackdir on which they are driving. I _think_. For other vehicles types, or vehicles with no clear trackdir (such as those in depots), returns 0xFF.

Returns:
  the trackdir of the vehicle

Reimplemented from Vehicle.

Definition at line 4177 of file train_cmd.cpp.

References DiagDirToDiagTrackdir(), DirToDiagDir(), FindFirstTrack(), GetRailDepotDirection(), TRACK_BIT_DEPOT, TRACK_BIT_WORMHOLE, TrackDirectionToTrackdir(), Vehicle::vehstatus, and VS_CRASHED.

Referenced by CheckNextTrainTile(), CmdBuildRailStation(), CmdBuildSingleSignal(), Crash(), FollowTrainReservation(), FreeTrainTrackReservation(), NPFTrainCheckReverse(), NPFTrainFindNearestDepot(), RemoveFromRailBaseStation(), YapfTrainCheckReverse(), and YapfTrainFindNearestDepot().

FORCEINLINE uint16 Train::GetWeight | ( |  | ) | const`[inline, protected]`

Allows to know the weight value that this vehicle will use.

Returns:
  Weight value from the engine in tonnes.

Definition at line 224 of file train.h.

References Vehicle::cargo, Vehicle::cargo_type, CargoList< Tinst, Tcont >::Count(), Vehicle::engine_type, GroundVehicleCache::first_engine, FreightWagonMult(), GroundVehicle< Train, VEH_TRAIN >::gcache, SpecializedVehicle< Train, Type >::Get(), HasBit(), Vehicle::IsArticulatedPart(), PROP_TRAIN_WEIGHT, and VRF_POWEREDWAGON.

bool Train::IsInDepot | ( |  | ) | const`[virtual]`

Check whether the vehicle is in the depot.

Returns:
  true if and only if the vehicle is in the depot.

Reimplemented from Vehicle.

Definition at line 809 of file train_cmd.cpp.

References Vehicle::cur_speed, IsRailDepotTile(), SpecializedVehicle< T, Type >::Next(), Vehicle::tile, and TRACK_BIT_DEPOT.

Referenced by CmdForceTrainProceed(), CmdMassStartStopVehicle(), and IsStoppedInDepot().

bool Train::IsStoppedInDepot | ( |  | ) | const`[virtual]`

Check whether the vehicle is in the depot *and* stopped.

Returns:
  true if and only if the vehicle is in the depot and stopped.

Reimplemented from Vehicle.

Definition at line 822 of file train_cmd.cpp.

References Vehicle::IsFrontEngine(), IsInDepot(), Vehicle::vehstatus, and VS_STOPPED.

Referenced by CmdMoveRailVehicle(), and CmdReverseTrainDirection().

void Train::MarkDirty | ( |  | ) | `[virtual]`

Marks the vehicles to be redrawn and updates cached variables.

This method marks the area of the vehicle on the screen as dirty. It can be use to repaint the vehicle.

Reimplemented from Vehicle.

Definition at line 2783 of file train_cmd.cpp.

References GroundVehicle< Train, VEH_TRAIN >::CargoChanged(), SpecializedVehicle< T, Type >::Next(), and SpecializedVehicle< T, Type >::UpdateViewport().

void Train::RailtypeChanged | ( |  | ) |

Update visual effect, power and acceleration caches.

Called when a vehicle in the consist enters a different railtype.

Definition at line 141 of file train_cmd.cpp.

References Vehicle::IsFrontEngine(), and GroundVehicle< Train, VEH_TRAIN >::PowerChanged().

bool Train::Tick | ( |  | ) | `[virtual]`

Calls the tick handler of the vehicle.

Returns:
  is this vehicle still valid?

Reimplemented from Vehicle.

Definition at line 4070 of file train_cmd.cpp.

References crash_anim_pos, Vehicle::cur_speed, Vehicle::current_order_time, GroundVehicle< Train, VEH_TRAIN >::IsFreeWagon(), Vehicle::IsFrontEngine(), Vehicle::running_ticks, Vehicle::tick_counter, Vehicle::vehstatus, VS_CRASHED, and VS_STOPPED.

FORCEINLINE bool Train::TileMayHaveSlopedTrack | ( |  | ) | const`[inline, protected]`

Checks if the vehicle is at a tile that can be sloped.

Returns:
  True if the tile can be sloped.

Definition at line 330 of file train.h.

References TRACK_BIT_X.

void Train::UpdateDeltaXY | ( | Direction | direction | ) | `[virtual]`

Updates the x and y offsets and the size of the sprite used for this vehicle.

Parameters:

  | direction | the direction the vehicle is facing

Reimplemented from Vehicle.

Definition at line 1437 of file train_cmd.cpp.

References GB(), Vehicle::x_extent, Vehicle::x_offs, Vehicle::y_extent, Vehicle::y_offs, and Vehicle::z_extent.

Referenced by ChangeTrainDirRandomly().

int Train::UpdateSpeed | ( |  | ) |

This function looks at the vehicle and updates its speed (cur_speed and subspeed) variables.

Furthermore, it returns the distance that the train can drive this tick. Vehicle::GetAdvanceDistance() determines the distance to drive before moving a step on the map.

Returns:
  distance to drive.

Definition at line 2802 of file train_cmd.cpp.

References _settings_game, Vehicle::acceleration, AS_BRAKE, GroundVehicleCache::cached_max_track_speed, GroundVehicle< Train, VEH_TRAIN >::DoUpdateSpeed(), GroundVehicle< Train, VEH_TRAIN >::gcache, GroundVehicle< Train, VEH_TRAIN >::GetAcceleration(), GetAccelerationStatus(), GetCurrentMaxSpeed(), VehicleSettings::train_acceleration_model, and GameSettings::vehicle.

## Field Documentation

uint16 Train::signal_speedlimit

The maximum speed of the last speed-signal passed by the train.

Definition at line 99 of file train.h.

Referenced by CheckNextTrainTile().

uint16 Train::wait_counter

Ticks waiting in front of a signal, ticks being stuck or a counter for forced proceeding through signals.

Definition at line 102 of file train.h.

Referenced by AfterLoadGame(), MarkTrainAsStuck(), TryPathReserve(), and VehicleEnterDepot().

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

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