OpenTTD
Data Structures | Macros | Typedefs | Enumerations | Functions
train.h File Reference

Base for the train class. More...

#include "core/enum_type.hpp"
#include "newgrf_engine.h"
#include "cargotype.h"
#include "rail.h"
#include "engine_base.h"
#include "rail_map.h"
#include "ground_vehicle.hpp"

Go to the source code of this file.

Data Structures

struct  TrainCache
 Variables that are cached to improve performance and such. More...
 
struct  Train
 'Train' is either a loco or a wagon. More...
 

Macros

#define FOR_ALL_TRAINS(var)   FOR_ALL_VEHICLES_OF_TYPE(Train, var)
 

Typedefs

typedef SimpleTinyEnumT< TrainForceProceeding, byte > TrainForceProceedingByte
 

Enumerations

enum  VehicleRailFlags {
  VRF_REVERSING = 0, VRF_POWEREDWAGON = 3, VRF_REVERSE_DIRECTION = 4, VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL = 6,
  VRF_TOGGLE_REVERSE = 7, VRF_TRAIN_STUCK = 8, VRF_LEAVING_STATION = 9
}
 Rail vehicle flags. More...
 
enum  TrainForceProceeding { TFP_NONE = 0, TFP_STUCK = 1, TFP_SIGNAL = 2 }
 Modes for ignoring signals. More...
 
enum  ConsistChangeFlags {
  CCF_LENGTH = 0x01, CCF_CAPACITY = 0x02, CCF_TRACK = 0, CCF_LOADUNLOAD = 0,
  CCF_AUTOREFIT = CCF_CAPACITY, CCF_REFIT = CCF_LENGTH | CCF_CAPACITY, CCF_ARRANGE = CCF_LENGTH | CCF_CAPACITY, CCF_SAVELOAD = CCF_LENGTH
}
 Flags for Train::ConsistChanged. More...
 

Functions

byte FreightWagonMult (CargoID cargo)
 Return the cargo weight multiplier to use for a rail vehicle. More...
 
void CheckTrainsLengths ()
 Checks if lengths of all rail vehicles are valid. More...
 
void FreeTrainTrackReservation (const Train *v)
 Free the reserved path in front of a vehicle. More...
 
bool TryPathReserve (Train *v, bool mark_as_stuck=false, bool first_tile_okay=false)
 Try to reserve a path to a safe position. More...
 
int GetTrainStopLocation (StationID station_id, TileIndex tile, const Train *v, int *station_ahead, int *station_length)
 Get the stop location of (the center) of the front vehicle of a train at a platform of a station. More...
 
void GetTrainSpriteSize (EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type)
 Get the size of the sprite of a train sprite heading west, or both heads (used for lists). More...
 

Detailed Description

Base for the train class.

Definition in file train.h.

Enumeration Type Documentation

◆ ConsistChangeFlags

Flags for Train::ConsistChanged.

Enumerator
CCF_LENGTH 

Allow vehicles to change length.

CCF_CAPACITY 

Allow vehicles to change capacity.

CCF_TRACK 

Valid changes while vehicle is driving, and possibly changing tracks.

CCF_LOADUNLOAD 

Valid changes while vehicle is loading/unloading.

CCF_AUTOREFIT 

Valid changes for autorefitting in stations.

CCF_REFIT 

Valid changes for refitting in a depot.

CCF_ARRANGE 

Valid changes for arranging the consist in a depot.

CCF_SAVELOAD 

Valid changes when loading a savegame. (Everything that is not stored in the save.)

Definition at line 47 of file train.h.

◆ TrainForceProceeding

Modes for ignoring signals.

Enumerator
TFP_NONE 

Normal operation.

TFP_STUCK 

Proceed till next signal, but ignore being stuck till then. This includes force leaving depots.

TFP_SIGNAL 

Ignore next signal, after the signal ignore being stuck.

Definition at line 39 of file train.h.

◆ VehicleRailFlags

Rail vehicle flags.

Enumerator
VRF_POWEREDWAGON 

Wagon is powered.

VRF_REVERSE_DIRECTION 

Reverse the visible direction of the vehicle.

VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL 

Electric train engine is allowed to run on normal rail. */.

VRF_TOGGLE_REVERSE 

Used for vehicle var 0xFE bit 8 (toggled each time the train is reversed, accurate for first vehicle only).

VRF_TRAIN_STUCK 

Train can't get a path reservation.

VRF_LEAVING_STATION 

Train is just leaving a station.

Definition at line 27 of file train.h.

Function Documentation

◆ CheckTrainsLengths()

void CheckTrainsLengths ( )

Checks if lengths of all rail vehicles are valid.

If not, shows an error message.

Definition at line 94 of file train_cmd.cpp.

References Vehicle::first.

◆ FreeTrainTrackReservation()

void FreeTrainTrackReservation ( const Train v)

Free the reserved path in front of a vehicle.

Parameters
vTrain owning the reserved path.

Definition at line 2258 of file train_cmd.cpp.

Referenced by CmdConvertRail(), Train::Crash(), FreeTrainReservation(), and ReverseTrainDirection().

◆ FreightWagonMult()

byte FreightWagonMult ( CargoID  cargo)

Return the cargo weight multiplier to use for a rail vehicle.

Parameters
cargoCargo type to get multiplier for
Returns
Cargo weight multiplier

Definition at line 87 of file train_cmd.cpp.

References _settings_game, VehicleSettings::freight_trains, CargoSpec::Get(), and GameSettings::vehicle.

Referenced by Train::GetWeight().

◆ GetTrainSpriteSize()

void GetTrainSpriteSize ( EngineID  engine,
uint &  width,
uint &  height,
int &  xoffs,
int &  yoffs,
EngineImageType  image_type 
)

Get the size of the sprite of a train sprite heading west, or both heads (used for lists).

Parameters
engineThe engine to get the sprite from.
[out]widthThe width of the sprite.
[out]heightThe height of the sprite.
[out]xoffsNumber of pixels to shift the sprite to the right.
[out]yoffsNumber of pixels to shift the sprite downwards.
image_typeContext the sprite is used in.

Definition at line 572 of file train_cmd.cpp.

◆ GetTrainStopLocation()

int GetTrainStopLocation ( StationID  station_id,
TileIndex  tile,
const Train v,
int *  station_ahead,
int *  station_length 
)

Get the stop location of (the center) of the front vehicle of a train at a platform of a station.

Parameters
station_idthe ID of the station where we're stopping
tilethe tile where the vehicle currently is
vthe vehicle to get the stop location of
station_ahead'return' the amount of 1/16th tiles in front of the train
station_length'return' the station length in 1/16th tiles
Returns
the location, calculated from the begin of the station to stop at.

Definition at line 279 of file train_cmd.cpp.

References GroundVehicleCache::cached_total_length, Vehicle::current_order, Vehicle::direction, DirToDiagDir(), GroundVehicle< T, Type >::gcache, SpecializedStation< Station, false >::Get(), Station::GetPlatformLength(), Order::IsType(), OSL_PLATFORM_FAR_END, OSL_PLATFORM_MIDDLE, and TILE_SIZE.

◆ TryPathReserve()

bool TryPathReserve ( Train v,
bool  mark_as_stuck,
bool  first_tile_okay 
)

Try to reserve a path to a safe position.

Parameters
vThe vehicle
mark_as_stuckShould the train be marked as stuck on a failed reservation?
first_tile_okayTrue if no path should be reserved if the current tile is a safe position.
Returns
True if a path could be reserved.

Definition at line 2696 of file train_cmd.cpp.

Referenced by CmdConvertRail(), and RestoreTrainReservation().