Base for the train class. More...
#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... | |
Defines | |
#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, VRF_BREAKDOWN_BRAKING = 10, VRF_BREAKDOWN_POWER = 11, VRF_BREAKDOWN_SPEED = 12, VRF_BREAKDOWN_STOPPED = 13, VRF_IS_BROKEN = (1 << VRF_BREAKDOWN_POWER) | (1 << VRF_BREAKDOWN_SPEED) | (1 << VRF_BREAKDOWN_STOPPED), VRF_NEED_REPAIR = 14, VRF_TO_HEAVY = 15 } |
Rail vehicle flags. More... | |
enum | TrainForceProceeding { TFP_NONE = 0, TFP_STUCK = 1, TFP_SIGNAL = 2 } |
Modes for ignoring signals. More... | |
Functions | |
byte | FreightWagonMult (CargoID cargo) |
Return the cargo weight multiplier to use for a rail vehicle. | |
void | CheckTrainsLengths () |
Checks if lengths of all rail vehicles are valid. | |
void | FreeTrainTrackReservation (const Train *v, TileIndex origin=INVALID_TILE, Trackdir orig_td=INVALID_TRACKDIR) |
Free the reserved path in front of a vehicle. | |
bool | TryPathReserve (Train *v, bool mark_as_stuck=false, bool first_tile_okay=false) |
Try to reserve a path to a safe position. | |
void | DeleteVisibleTrain (Train *v) |
Delete a train while it is visible. | |
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. | |
void | CheckBreakdownFlags (Train *v) |
Checks the breakdown flags (VehicleRailFlags 9-12) and sets the correct value in the first vehicle of the consist. |
Base for the train class.
Definition in file train.h.
enum TrainForceProceeding |
enum VehicleRailFlags |
Rail vehicle flags.
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. |
VRF_BREAKDOWN_BRAKING |
Used to mark a train that is braking because it is broken down. |
VRF_BREAKDOWN_POWER |
Used to mark a train in which the power of one (or more) of the engines is reduced because of a breakdown. |
VRF_BREAKDOWN_SPEED |
Used to mark a train that has a reduced maximum speed because of a breakdown. |
VRF_BREAKDOWN_STOPPED |
Used to mark a train that is stopped because of a breakdown. |
VRF_NEED_REPAIR |
Used to mark a train that has a reduced maximum speed because of a critical breakdown. |
void CheckBreakdownFlags | ( | Train * | v | ) |
Checks the breakdown flags (VehicleRailFlags 9-12) and sets the correct value in the first vehicle of the consist.
This function is generally only called to check if a flag may be cleared.
v | Front engine. | |
flags | Bitmask of the flags to check. |
Definition at line 157 of file train_cmd.cpp.
References BREAKDOWN_CRITICAL, BREAKDOWN_EM_STOP, BREAKDOWN_LOW_POWER, BREAKDOWN_LOW_SPEED, CLRBITS, GroundVehicle< T, Type >::IsEngine(), Vehicle::IsFrontEngine(), SpecializedVehicle< T, Type >::Next(), SetBit(), VRF_BREAKDOWN_BRAKING, VRF_BREAKDOWN_POWER, VRF_BREAKDOWN_SPEED, and VRF_BREAKDOWN_STOPPED.
Referenced by Vehicle::HandleBreakdown().
void CheckTrainsLengths | ( | ) |
Checks if lengths of all rail vehicles are valid.
If not, shows an error message.
Definition at line 108 of file train_cmd.cpp.
References _networking, abs(), CMD_PAUSE, DoCommandP(), SpecializedVehicle< T, Type >::First(), Vehicle::first, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_STRING_ID, max(), SpecializedVehicle< T, Type >::Next(), Vehicle::owner, PM_PAUSED_ERROR, SetDParam(), ShowErrorMessage(), TicksToLeaveDepot(), TRACK_BIT_DEPOT, Vehicle::vehstatus, and WL_CRITICAL.
Referenced by InitializeWindowsAndCaches(), and ReloadNewGRFData().
void DeleteVisibleTrain | ( | Train * | v | ) |
Delete a train while it is visible.
This happens when a company bankrupts when infrastructure sharing is enabled.
v | The train to delete. |
Definition at line 4199 of file train_cmd.cpp.
References AddSideToSignalBuffer(), AddTrackToSignalBuffer(), DiagDirToDiagTrackBits(), FreeTrainTrackReservation(), GetTileOwner(), GetTunnelBridgeDirection(), HasReservedTracks(), INVALID_DIAGDIR, INVALID_TILE, IsLevelCrossingTile(), IsRailDepotTile(), IsTileType(), SpecializedVehicle< T, Type >::Last(), MP_TUNNELBRIDGE, SpecializedVehicle< T, Type >::Previous(), Vehicle::SetNext(), Vehicle::tile, TRACK_BIT_WORMHOLE, TrackBitsToTrack(), TrainApproachingCrossingTile(), UnreserveRailTrack(), UpdateLevelCrossing(), and UpdateSignalsInBuffer().
Referenced by RemoveAndSellVehicle().
Free the reserved path in front of a vehicle.
Definition at line 2258 of file train_cmd.cpp.
References ClearPathReservation(), RailtypeInfo::compatible_railtypes, CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow(), GetRailTypeInfo(), GetReservedTrackbits(), GetSignalStateByTrackdir(), GetStationIndex(), Train::GetVehicleTrackdir(), HasPbsSignalOnTrackdir(), HasSignalOnTrackdir(), INVALID_TILE, INVALID_TRACKDIR, Vehicle::IsFrontEngine(), IsOnewaySignal(), IsPbsSignal(), IsRailStationTile(), IsSpeedSignal(), IsTileType(), IsValidTrackdir(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_is_bridge, CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_is_station, CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_is_tunnel, CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_new_td_bits, CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_new_tile, MarkTileDirtyByTile(), MP_RAILWAY, MP_TUNNELBRIDGE, RemoveFirstTrackdir(), ReverseTrackdir(), SetSignalStateByTrackdir(), SIGNAL_STATE_RED, Vehicle::tile, TrackBitsToTrackdirBits(), TRACKDIR_BIT_NONE, TrackdirToTrack(), TracksOverlap(), TrackToTrackBits(), and UnreserveRailTrack().
Referenced by CmdBuildRailStation(), CmdBuildSingleSignal(), CmdConvertRail(), CmdRemoveSingleRail(), Train::Crash(), DeleteVisibleTrain(), DoClearBridge(), DoClearTunnel(), FixAllReservations(), RemoveFromRailBaseStation(), and RemoveRailStation().
byte FreightWagonMult | ( | CargoID | cargo | ) |
Return the cargo weight multiplier to use for a rail vehicle.
cargo | Cargo type to get multiplier for |
Definition at line 85 of file train_cmd.cpp.
References _settings_game, VehicleSettings::freight_trains, CargoSpec::Get(), and GameSettings::vehicle.
Referenced by DrawTrainDetails(), Train::GetWeight(), TrainDetailsCapacityTab(), and TrainDetailsCargoTab().
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 319 of file train_cmd.cpp.
References GroundVehicleCache::cached_total_length, Vehicle::current_order, Vehicle::direction, DirToDiagDir(), GroundVehicle< T, Type >::gcache, SpecializedStation< Station, false >::Get(), Order::GetDestination(), Station::GetPlatformLength(), Order::GetStopLocation(), Order::IsType(), OSL_PLATFORM_FAR_END, OSL_PLATFORM_MIDDLE, OSL_PLATFORM_NEAR_END, TILE_SIZE, and VEHICLE_LENGTH.
Referenced by Train::GetCurrentMaxSpeed().
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 2684 of file train_cmd.cpp.
References _settings_client, _settings_game, ClrBit(), DiagdirReachesTrackdirs(), DiagdirReachesTracks(), FollowTrainReservation(), PathfinderSettings::forbid_90_deg, GetRailDepotDirection(), 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, GameSettings::pf, 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, and Train::wait_counter.
Referenced by CheckTrainStayInWormHole(), CmdBuildRailStation(), CmdBuildSingleSignal(), CmdConvertRail(), CmdRemoveSingleRail(), CmdRemoveSingleSignal(), DoClearBridge(), DoClearTunnel(), FixAllReservations(), RemoveFromRailBaseStation(), and RemoveRailStation().