train_cmd.cpp File Reference

Handling of trains. More...

#include "stdafx.h"
#include "openttd.h"
#include "bridge_map.h"
#include "debug.h"
#include "tile_cmd.h"
#include "landscape.h"
#include "gui.h"
#include "station_map.h"
#include "tunnel_map.h"
#include "articulated_vehicles.h"
#include "command_func.h"
#include "pathfind.h"
#include "npf.h"
#include "station_base.h"
#include "news_func.h"
#include "engine_func.h"
#include "engine_base.h"
#include "company_func.h"
#include "company_base.h"
#include "depot_base.h"
#include "depot_func.h"
#include "waypoint.h"
#include "vehicle_gui.h"
#include "train.h"
#include "bridge.h"
#include "newgrf_callbacks.h"
#include "newgrf_engine.h"
#include "newgrf_sound.h"
#include "newgrf_text.h"
#include "direction_func.h"
#include "yapf/yapf.h"
#include "yapf/follow_track.hpp"
#include "cargotype.h"
#include "group.h"
#include "table/sprites.h"
#include "tunnelbridge_map.h"
#include "strings_func.h"
#include "functions.h"
#include "window_func.h"
#include "date_func.h"
#include "vehicle_func.h"
#include "sound_func.h"
#include "signal_func.h"
#include "variables.h"
#include "autoreplace_gui.h"
#include "gfx_func.h"
#include "settings_type.h"
#include "order_func.h"
#include "newgrf_station.h"
#include "effectvehicle_func.h"
#include "gamelog.h"
#include "network/network.h"
#include "pbs.h"
#include "table/strings.h"
#include "table/train_cmd.h"

Go to the source code of this file.

Data Structures

struct  TrainFindDepotData
struct  TrainTrackFollowerData
 Check for station tiles. More...
class  VehicleOrderSaver
 This class will save the current order of a vehicle and restore it on destruction. More...
struct  RailtypeSlowdownParams
struct  TrainCollideChecker

Defines

#define MKIT(a, b, c, d)   ((a & 0xFF) << 24) | ((b & 0xFF) << 16) | ((c & 0xFF) << 8) | ((d & 0xFF) << 0)

Enumerations

enum  AccelType { AM_ACCEL, AM_BRAKE }

Functions

static Track ChooseTrainTrack (Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool force_res, bool *got_reservation, bool mark_stuck)
static bool TrainCheckIfLineEnds (Vehicle *v)
 Checks for line end.
static void TrainController (Vehicle *v, Vehicle *nomove, bool update_image)
static TileIndex TrainApproachingCrossingTile (const Vehicle *v)
 Determines whether train is approaching a rail-road crossing (thus making it barred).
static void CheckIfTrainNeedsService (Vehicle *v)
static void CheckNextTrainTile (Vehicle *v)
 Check if the train is on the last reserved tile and try to extend the path then.
static DiagDirection TrainExitDir (Direction direction, TrackBits track)
 Determine the side in which the train will leave the tile.
byte FreightWagonMult (CargoID cargo)
 Return the cargo weight multiplier to use for a rail vehicle.
void TrainPowerChanged (Vehicle *v)
 Recalculates the cached total power of a train.
static void TrainCargoChanged (Vehicle *v)
 Recalculates the cached weight of a train and its vehicles.
static void RailVehicleLengthChanged (const Vehicle *u)
 Logs a bug in GRF and shows a warning message if this is for the first time this happened.
void CheckTrainsLengths ()
 Checks if lengths of all rail vehicles are valid.
void TrainConsistChanged (Vehicle *v, bool same_length)
 Recalculates the cached stuff of a train.
static int GetTrainAcceleration (Vehicle *v, bool mode)
 new acceleration
void UpdateTrainAcceleration (Vehicle *v)
static SpriteID GetRailIcon (EngineID engine, bool rear_head, int &y)
void DrawTrainEngine (int x, int y, EngineID engine, SpriteID pal)
static CommandCost CmdBuildRailWagon (EngineID engine, TileIndex tile, uint32 flags)
static void NormalizeTrainVehInDepot (const Vehicle *u)
 Move all free vehicles in the depot to the train.
static CommandCost EstimateTrainCost (EngineID engine, const RailVehicleInfo *rvi)
static void AddRearEngineToMultiheadedTrain (Vehicle *v, Vehicle *u, bool building)
CommandCost CmdBuildRailVehicle (TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 Build a railroad vehicle.
int CheckTrainInDepot (const Vehicle *v, bool needs_to_be_stopped)
int CheckTrainStoppedInDepot (const Vehicle *v)
bool CheckTrainIsInsideDepot (const Vehicle *v)
static Vehicle * UnlinkWagon (Vehicle *v, Vehicle *first)
 Unlink a rail wagon from the consist.
static Vehicle * FindGoodVehiclePos (const Vehicle *src)
static void AddWagonToConsist (Vehicle *v, Vehicle *dest)
static void NormaliseTrainConsist (Vehicle *v)
CommandCost CmdMoveRailVehicle (TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 Move a rail vehicle around inside the depot.
CommandCost CmdSellRailWagon (TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 Sell a (single) train wagon/engine.
static void UpdateVarsAfterSwap (Vehicle *v)
static void SetLastSpeed (Vehicle *v, int spd)
static void MarkTrainAsStuck (Vehicle *v)
 Mark a train as stuck and stop it if it isn't stopped right now.
static void SwapTrainFlags (uint16 *swap_flag1, uint16 *swap_flag2)
static void ReverseTrainSwapVeh (Vehicle *v, int l, int r)
static Vehicle * TrainOnTileEnum (Vehicle *v, void *)
 Check if the vehicle is a train.
static Vehicle * TrainApproachingCrossingEnum (Vehicle *v, void *data)
 Checks if a train is approaching a rail-road crossing.
static bool TrainApproachingCrossing (TileIndex tile)
 Finds a vehicle approaching rail-road crossing.
void UpdateLevelCrossing (TileIndex tile, bool sound)
 Sets correct crossing state.
static void MaybeBarCrossingWithSound (TileIndex tile)
 Bars crossing and plays ding-ding sound if not barred already.
static void AdvanceWagonsBeforeSwap (Vehicle *v)
 Advances wagons for train reversing, needed for variable length wagons.
static void AdvanceWagonsAfterSwap (Vehicle *v)
 Advances wagons for train reversing, needed for variable length wagons.
static void ReverseTrainDirection (Vehicle *v)
CommandCost CmdReverseTrainDirection (TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 Reverse train.
CommandCost CmdForceTrainProceed (TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 Force a train through a red signal.
CommandCost CmdRefitRailVehicle (TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 Refits a train to the specified cargo type.
static bool NtpCallbFindDepot (TileIndex tile, TrainFindDepotData *tfdd, int track, uint length)
static TrainFindDepotData FindClosestTrainDepot (Vehicle *v, int max_distance)
 returns the tile of a depot to goto to.
CommandCost CmdSendTrainToDepot (TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 Send a train to a depot.
void OnTick_Train ()
static void HandleLocomotiveSmokeCloud (const Vehicle *v)
static bool CheckTrainStayInDepot (Vehicle *v)
static void ClearPathReservation (const Vehicle *v, TileIndex tile, Trackdir track_dir)
 Clear the reservation of a tile that was just left by a wagon on track_dir.
void FreeTrainTrackReservation (const Vehicle *v, TileIndex origin, Trackdir orig_td)
 Free the reserved path in front of a vehicle.
static bool NtpCallbFindStation (TileIndex tile, TrainTrackFollowerData *ttfd, Trackdir track, uint length)
static void FillWithStationData (TrainTrackFollowerData *fd, const Vehicle *v)
static Track DoTrainPathfind (Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found, bool do_track_reservation, PBSTileInfo *dest)
 Perform pathfinding for a train.
static PBSTileInfo ExtendTrainReservation (const Vehicle *v, TrackBits *new_tracks, DiagDirection *enterdir)
 Extend a train path as far as possible.
static bool TryReserveSafeTrack (const Vehicle *v, TileIndex tile, Trackdir td, bool override_tailtype)
 Try to reserve any path to a safe tile, ignoring the vehicle's destination.
bool TryPathReserve (Vehicle *v, bool mark_as_stuck, bool first_tile_okay)
 Try to reserve a path to a safe position.
static bool CheckReverseTrain (Vehicle *v)
static int UpdateTrainSpeed (Vehicle *v)
 This function looks at the vehicle and updates it's speed (cur_speed and subspeed) variables.
static void TrainEnterStation (Vehicle *v, StationID station)
static byte AfterSetTrainPos (Vehicle *v, bool new_tile)
static Direction GetNewVehicleDirectionByTile (TileIndex new_tile, TileIndex old_tile)
static int GetDirectionToVehicle (const Vehicle *v, int x, int y)
static bool CheckCompatibleRail (const Vehicle *v, TileIndex tile)
static void AffectSpeedByDirChange (Vehicle *v, Direction new_dir)
 Modify the speed of the vehicle due to a turn.
static void AffectSpeedByZChange (Vehicle *v, byte old_z)
 Modify the speed of the vehicle due to a change in altitude.
static bool TrainMovedChangeSignals (TileIndex tile, DiagDirection dir)
static void SetVehicleCrashed (Vehicle *v)
static uint CountPassengersInTrain (const Vehicle *v)
static Vehicle * FindTrainCollideEnum (Vehicle *v, void *data)
static bool CheckTrainCollision (Vehicle *v)
 Checks whether the specified train has a collision with another vehicle.
static Vehicle * CheckVehicleAtSignal (Vehicle *v, void *data)
static Vehicle * CollectTrackbitsFromCrashedVehiclesEnum (Vehicle *v, void *data)
 Collect trackbits of all crashed train vehicles on a tile.
static void DeleteLastWagon (Vehicle *v)
 Deletes/Clears the last wagon of a crashed train.
static void ChangeTrainDirRandomly (Vehicle *v)
static void HandleCrashedTrain (Vehicle *v)
static void HandleBrokenTrain (Vehicle *v)
static bool TrainApproachingLineEnd (Vehicle *v, bool signal)
 Train is approaching line end, slow down and possibly reverse.
static bool TrainCanLeaveTile (const Vehicle *v)
 Determines whether train would like to leave the tile.
static void TrainLocoHandler (Vehicle *v, bool mode)
void InitializeTrains ()

Variables

static const byte _vehicle_initial_x_fract [4] = {10, 8, 4, 8}
static const byte _vehicle_initial_y_fract [4] = { 8, 4, 8, 10}
static const int8 _vehicle_smoke_pos [8]
static const byte _initial_tile_subcoord [6][4][3]
static const byte _search_directions [6][4]
static const byte _pick_track_table [6] = {1, 3, 2, 2, 0, 0}
static const Direction _new_vehicle_direction_table [11]
static const RailtypeSlowdownParams _railtype_slowdown []
static const uint16 _breakdown_speeds [16]
 Maximum speeds for train that is broken down or approaching line end.


Detailed Description

Handling of trains.

Definition in file train_cmd.cpp.


Function Documentation

static void AdvanceWagonsAfterSwap ( Vehicle *  v  )  [static]

Advances wagons for train reversing, needed for variable length wagons.

This one is called after the train is reversed.

Parameters:
v First vehicle in chain

Definition at line 1816 of file train_cmd.cpp.

References GetRailDepotTrack(), TicksToLeaveDepot(), TRACK_BIT_DEPOT, and TrackToTrackBits().

static void AdvanceWagonsBeforeSwap ( Vehicle *  v  )  [static]

Advances wagons for train reversing, needed for variable length wagons.

This one is called before the train is reversed.

Parameters:
v First vehicle in chain

Definition at line 1788 of file train_cmd.cpp.

static void CheckNextTrainTile ( Vehicle *  v  )  [static]

static bool CheckTrainCollision ( Vehicle *  v  )  [static]

Checks whether the specified train has a collision with another vehicle.

If so, destroys this vehicle, and the other vehicle if its subtype has TS_Front. Reports the incident in a flashy news item, modifies station ratings and plays a sound.

Definition at line 3605 of file train_cmd.cpp.

References AddNewsItem(), FindVehicleOnPos(), FindVehicleOnPosXY(), GetOtherTunnelBridgeEnd(), NS_ACCIDENT_VEHICLE, TRACK_BIT_DEPOT, and TRACK_BIT_WORMHOLE.

void CheckTrainsLengths (  ) 

Checks if lengths of all rail vehicles are valid.

If not, shows an error message.

Definition at line 224 of file train_cmd.cpp.

References _networking, abs(), INVALID_STRING_ID, max(), TicksToLeaveDepot(), and TRACK_BIT_DEPOT.

Referenced by InitializeWindowsAndCaches(), and ReloadNewGRFData().

static void ClearPathReservation ( const Vehicle *  v,
TileIndex  tile,
Trackdir  track_dir 
) [static]

CommandCost CmdBuildRailVehicle ( TileIndex  tile,
uint32  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

static CommandCost CmdBuildRailWagon ( EngineID  engine,
TileIndex  tile,
uint32  flags 
) [static]

CommandCost CmdForceTrainProceed ( TileIndex  tile,
uint32  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Force a train through a red signal.

Parameters:
tile unused
flags type of operation
p1 train to ignore the red signal
p2 unused

Definition at line 2007 of file train_cmd.cpp.

References CMD_ERROR, DC_EXEC, and IsValidVehicleID().

CommandCost CmdMoveRailVehicle ( TileIndex  tile,
uint32  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Move a rail vehicle around inside the depot.

Parameters:
tile unused
flags type of operation Note: DC_AUTOREPLACE is set when autoreplace tries to undo its modifications or moves vehicles to temporary locations inside the depot.
p1 various bitstuffed elements
  • p1 (bit 0 - 15) source vehicle index
  • p1 (bit 16 - 31) what wagon to put the source wagon AFTER, XXX - INVALID_VEHICLE to make a new line
p2 (bit 0) move all vehicles following the source vehicle

Definition at line 1025 of file train_cmd.cpp.

References _settings_game, CALLBACK_FAILED, CBID_TRAIN_ALLOW_WAGON_ATTACH, ClearFreeWagon(), ClearFrontEngine(), CMD_ERROR, CmdMoveRailVehicle(), DC_AUTOREPLACE, DC_EXEC, DEFAULT_GROUP, DeleteVehicleOrders(), DeleteWindowById(), error, GB(), GetEngineGRFID(), GetGRFStringID(), GetLastEnginePart(), GetNextUnit(), GetNextVehicle(), GetVehicleCallbackParent(), HasBit(), HASBITS, InvalidateWindow(), InvalidateWindowClassesData(), InvalidateWindowData(), InvalidateWindowWidget(), IsArticulatedPart(), IsFreeWagon(), IsFrontEngine(), IsRearDualheaded(), IsTrainEngine(), IsValidVehicleID(), VehicleSettings::mammoth_trains, VehicleSettings::max_trains, RemoveVehicleFromGroup(), return_cmd_error, SetFreeWagon(), SetFrontEngine(), SetTrainGroupID(), TrainConsistChanged(), UnlinkWagon(), UpdateTrainGroupID(), and GameSettings::vehicle.

Referenced by CmdMoveRailVehicle().

CommandCost CmdRefitRailVehicle ( TileIndex  tile,
uint32  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Refits a train to the specified cargo type.

Parameters:
tile unused
flags type of operation
p1 vehicle ID of the train to refit param p2 various bitstuffed elements
  • p2 = (bit 0-7) - the new cargo type to refit to
  • p2 = (bit 8-15) - the new cargo subtype to refit to
  • p2 = (bit 16) - refit only this vehicle
Returns:
cost of refit or error

Definition at line 2030 of file train_cmd.cpp.

References CommandCost::AddCost(), CALLBACK_FAILED, CanRefitTo(), CBID_VEHICLE_REFIT_CAPACITY, CBM_VEHICLE_REFIT_CAPACITY, CMD_ERROR, DC_EXEC, GB(), GetRefitCost(), GetVehicleCallback(), HasBit(), InvalidateWindow(), InvalidateWindowClassesData(), IsValidVehicleID(), return_cmd_error, and TrainConsistChanged().

CommandCost CmdReverseTrainDirection ( TileIndex  tile,
uint32  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Reverse train.

Parameters:
tile unused
flags type of operation
p1 train to reverse
p2 if true, reverse a unit in a train (needs to be in a depot)

Definition at line 1957 of file train_cmd.cpp.

References _settings_game, CBM_VEHICLE_ARTIC_ENGINE, CMD_ERROR, DC_EXEC, HasBit(), InvalidateWindow(), IsMultiheaded(), IsValidVehicleID(), VehicleSettings::realistic_acceleration, return_cmd_error, ToggleBit(), and GameSettings::vehicle.

CommandCost CmdSellRailWagon ( TileIndex  tile,
uint32  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Sell a (single) train wagon/engine.

Parameters:
tile unused
flags type of operation
p1 the wagon/engine index
p2 the selling mode
  • p2 = 0: only sell the single dragged wagon/engine (and any belonging rear-engines)
  • p2 = 1: sell the vehicle and all vehicles following it in the chain if the wagon is dragged, don't delete the possibly belonging rear-engine to some front
  • p2 = 2: when selling attached locos, rearrange all vehicles after it to separate lines; all wagons of the same type will go on the same line. Used by the AI currently

Definition at line 1382 of file train_cmd.cpp.

References CommandCost::AddCost(), CMD_ERROR, CMD_MOVE_RAIL_VEHICLE, DC_EXEC, DEFAULT_GROUP, DeleteVehicleOrders(), DeleteWindowById(), DoCommand(), CommandCost::Failed(), GetNextVehicle(), HasBit(), HASBITS, InvalidateWindow(), InvalidateWindowClassesData(), IsArticulatedPart(), IsFrontEngine(), IsMultiheaded(), IsRearDualheaded(), IsTrainEngine(), IsValidVehicleID(), return_cmd_error, SetFrontEngine(), ShowVehicleViewWindow(), TrainConsistChanged(), TS_FRONT, UnlinkWagon(), and UpdateTrainGroupID().

CommandCost CmdSendTrainToDepot ( TileIndex  tile,
uint32  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Send a train to a depot.

Parameters:
tile unused
flags type of operation
p1 train to send to the depot
p2 various bitmasked elements
  • p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
  • p2 bit 8-10 - VLW flag (for mass goto depot)

Definition at line 2234 of file train_cmd.cpp.

References CMD_ERROR, DEPOT_MASS_SEND, DEPOT_SERVICE, IsValidVehicleID(), and SendAllVehiclesToDepot().

static Vehicle* CollectTrackbitsFromCrashedVehiclesEnum ( Vehicle *  v,
void *  data 
) [static]

Collect trackbits of all crashed train vehicles on a tile.

Parameters:
v Vehicle passed from Find/HasVehicleOnPos()
data trackdirbits for the result
Returns:
NULL to iterate over all vehicles on the tile.

Definition at line 3920 of file train_cmd.cpp.

References DiagDirToDiagTrackBits(), GetTunnelBridgeDirection(), and TRACK_BIT_WORMHOLE.

Referenced by DeleteLastWagon().

static void DeleteLastWagon ( Vehicle *  v  )  [static]

Deletes/Clears the last wagon of a crashed train.

It takes the engine of the train, then goes to the last wagon and deletes that. Each call to this function will remove the last wagon of a crashed train. If this wagon was on a crossing, or inside a tunnel/bridge, recalculate the signals as they might need updating

Parameters:
v the Vehicle of which last wagon is to be removed

Definition at line 3943 of file train_cmd.cpp.

References CollectTrackbitsFromCrashedVehiclesEnum(), DiagDirToDiagTrackBits(), FindVehicleOnPos(), GetTunnelBridgeDirection(), HasBit(), HasReservedTracks(), INVALID_DIAGDIR, InvalidateWindow(), IsRailDepotTile(), IsTileType(), MP_TUNNELBRIDGE, SetSignalsOnBothDir(), TRACK_BEGIN, TRACK_BIT_DEPOT, TRACK_BIT_NONE, TRACK_BIT_WORMHOLE, TRACK_END, TRACK_X, TRACK_Y, TrackBitsToTrack(), TrainConsistChanged(), TryReserveRailTrack(), UnreserveRailTrack(), UpdateLevelCrossing(), and UpdateSignalsOnSegment().

static Track DoTrainPathfind ( Vehicle *  v,
TileIndex  tile,
DiagDirection  enterdir,
TrackBits  tracks,
bool *  path_not_found,
bool  do_track_reservation,
PBSTileInfo dest 
) [static]

Perform pathfinding for a train.

Parameters:
v The train
tile The tile the train is about to enter
enterdir Diagonal direction the train is coming from
tracks Usable tracks on the new tile
path_not_found [out] Set to false if the pathfinder couldn't find a way to the destination
do_track_reservation 
dest [out]
Returns:
The best track the train should follow

Definition at line 2618 of file train_cmd.cpp.

References _settings_game, TrainTrackFollowerData::best_bird_dist, TrainTrackFollowerData::best_track, TrainTrackFollowerData::best_track_dist, FindFirstTrack(), FollowTrainReservation(), INVALID_TRACKDIR, IsValidTrackdir(), NewTrainPathfind(), NpfBeginInterval(), NpfEndInterval(), PBSTileInfo::okay, PathfinderSettings::pathfinder_for_trains, GameSettings::pf, PBSTileInfo::tile, TileOffsByDiagDir(), PBSTileInfo::trackdir, TrackdirToTrack(), TRANSPORT_RAIL, VPF_NPF, VPF_NTP, VPF_YAPF, and YapfChooseRailTrack().

static PBSTileInfo ExtendTrainReservation ( const Vehicle *  v,
TrackBits new_tracks,
DiagDirection enterdir 
) [static]

Extend a train path as far as possible.

Stops on encountering a safe tile, another reservation or a track choice.

Returns:
INVALID_TILE indicates that the reservation failed.

Definition at line 2719 of file train_cmd.cpp.

References _settings_game, FindFirstTrackdir(), CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow(), FollowTrainReservation(), PathfinderSettings::forbid_90_deg, HasOnewaySignalBlockingTrackdir(), HasReservedTracks(), IsPlainRailTile(), IsSafeWaitingPosition(), IsTileType(), IsWaitingPositionFree(), KillFirstBit(), CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_err, CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_exitdir, CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_is_station, CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_new_td_bits, CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_new_tile, CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_old_td, CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_old_tile, CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_tiles_skipped, MP_RAILWAY, PathfinderSettings::pathfinder_for_trains, GameSettings::pf, PBSTileInfo::tile, TileOffsByDiagDir(), PBSTileInfo::trackdir, TRACKDIR_BIT_NONE, TrackdirBitsToTrackBits(), TrackdirCrossesTrackdirs(), TrackdirReachesTrackdirs(), TrackdirToTrack(), TryReserveRailTrack(), UnreserveRailTrack(), and VPF_NTP.

static TrainFindDepotData FindClosestTrainDepot ( Vehicle *  v,
int  max_distance 
) [static]

void FreeTrainTrackReservation ( const Vehicle *  v,
TileIndex  origin,
Trackdir  orig_td 
)

byte FreightWagonMult ( CargoID  cargo  ) 

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

Parameters:
cargo Cargo type to get multiplier for
Returns:
Cargo weight multiplier

Definition at line 99 of file train_cmd.cpp.

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

Referenced by TrainCargoChanged().

static void MarkTrainAsStuck ( Vehicle *  v  )  [static]

Mark a train as stuck and stop it if it isn't stopped right now.

Definition at line 1604 of file train_cmd.cpp.

References HasBit(), InvalidateWindowWidget(), and SetBit().

Referenced by TryPathReserve().

static void MaybeBarCrossingWithSound ( TileIndex  tile  )  [inline, static]

Bars crossing and plays ding-ding sound if not barred already.

Parameters:
tile tile with crossing
Precondition:
tile is a rail-road crossing

Definition at line 1773 of file train_cmd.cpp.

References MarkTileDirtyByTile().

Referenced by TrainCheckIfLineEnds().

static void RailVehicleLengthChanged ( const Vehicle *  u  )  [static]

Logs a bug in GRF and shows a warning message if this is for the first time this happened.

Parameters:
u first vehicle of chain

Definition at line 196 of file train_cmd.cpp.

References _networking, GamelogGRFBugReverse(), GBUG_VEH_LENGTH, GRFConfig::grf_bugs, HasBit(), lastof, GRFConfig::name, SetBit(), and SetDParamStr().

Referenced by TrainConsistChanged().

static bool TrainApproachingCrossing ( TileIndex  tile  )  [static]

Finds a vehicle approaching rail-road crossing.

Parameters:
tile tile to test
Returns:
true if a vehicle is approaching the crossing
Precondition:
tile is a rail-road crossing

Definition at line 1729 of file train_cmd.cpp.

References AxisToDiagDir(), HasVehicleOnPos(), ReverseDiagDir(), TileOffsByDiagDir(), and TrainApproachingCrossingEnum().

Referenced by UpdateLevelCrossing().

static Vehicle* TrainApproachingCrossingEnum ( Vehicle *  v,
void *  data 
) [static]

Checks if a train is approaching a rail-road crossing.

Parameters:
v vehicle on tile
data tile with crossing we are testing
Returns:
v if it is approaching a crossing, NULL otherwise

Definition at line