OpenTTD Source
20241120-master-g6d3adc6169
|
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... | |
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 : uint8_t { 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 | |
uint8_t | 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... | |
bool | TrainOnCrossing (TileIndex tile) |
Check if a level crossing tile has a train on it. More... | |
void | NormalizeTrainVehInDepot (const Train *u) |
Move all free vehicles in the depot to the train. | |
Base for the train class.
Definition in file train.h.
enum ConsistChangeFlags |
Flags for Train::ConsistChanged.
enum TrainForceProceeding : uint8_t |
enum 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. |
void CheckTrainsLengths | ( | ) |
Checks if lengths of all rail vehicles are valid.
If not, shows an error message.
Definition at line 76 of file train_cmd.cpp.
References _networking, abs(), INVALID_STRING_ID, SpecializedVehicle< T, Type >::Iterate(), SpecializedVehicle< T, Type >::Next(), PM_PAUSED_ERROR, SetDParam(), ShowErrorMessage(), TicksToLeaveDepot(), TRACK_BIT_DEPOT, VS_CRASHED, and WL_CRITICAL.
void FreeTrainTrackReservation | ( | const Train * | v | ) |
Free the reserved path in front of a vehicle.
v | Train owning the reserved path. |
Definition at line 2386 of file train_cmd.cpp.
References GetStationIndex(), Train::GetVehicleTrackdir(), Vehicle::IsFrontEngine(), IsRailStationTile(), IsTileType(), MP_TUNNELBRIDGE, and Vehicle::tile.
Referenced by CmdConvertRail(), Train::Crash(), and FreeTrainReservation().
uint8_t FreightWagonMult | ( | CargoID | cargo | ) |
Return the cargo weight multiplier to use for a rail vehicle.
cargo | Cargo type to get multiplier for |
Definition at line 69 of file train_cmd.cpp.
References _settings_game, VehicleSettings::freight_trains, CargoSpec::Get(), and GameSettings::vehicle.
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).
engine | The engine to get the sprite from. | |
[out] | width | The width of the sprite. |
[out] | height | The height of the sprite. |
[out] | xoffs | Number of pixels to shift the sprite to the right. |
[out] | yoffs | Number of pixels to shift the sprite downwards. |
image_type | Context the sprite is used in. |
Definition at line 581 of file train_cmd.cpp.
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.
station_id | the ID of the station where we're stopping |
tile | the tile where the vehicle currently is |
v | the 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 |
Definition at line 263 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.
bool TrainOnCrossing | ( | TileIndex | tile | ) |
Check if a level crossing tile has a train on it.
tile | tile to test |
Definition at line 1683 of file train_cmd.cpp.
References HasVehicleOnPos(), IsLevelCrossingTile(), and TrainOnTileEnum().
Referenced by CheckLevelCrossing().
bool TryPathReserve | ( | Train * | v, |
bool | mark_as_stuck, | ||
bool | first_tile_okay | ||
) |
Try to reserve a path to a safe position.
v | The vehicle |
mark_as_stuck | Should the train be marked as stuck on a failed reservation? |
first_tile_okay | True if no path should be reserved if the current tile is a safe position. |
Definition at line 2866 of file train_cmd.cpp.
References _settings_client, ClrBit(), DiagdirReachesTrackdirs(), DiagdirReachesTracks(), FollowTrainReservation(), GetRailDepotDirection(), GetTileRailType(), GetTileTrackStatus(), ClientSettings::gui, HasBit(), HasDepotReservation(), HasReservedTracks(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Vehicle::IsFrontEngine(), MarkTileDirtyByTile(), MarkTrainAsStuck(), PBSTileInfo::okay, Rail90DegTurnDisallowed(), SetDepotReservation(), SetWindowWidgetDirty(), GUISettings::show_track_reservation, PBSTileInfo::tile, Vehicle::tile, TileAddByDiagDir(), TRACK_BIT_DEPOT, TrackCrossesTracks(), PBSTileInfo::trackdir, TrackdirBitsToTrackBits(), TrackdirToExitdir(), TrackdirToTrack(), TrackStatusToTrackdirBits(), TRANSPORT_RAIL, VRF_TRAIN_STUCK, WC_VEHICLE_VIEW, and WID_VV_START_STOP.
Referenced by CmdConvertRail(), and RestoreTrainReservation().