OpenTTD Source 20260208-master-g43af8e94d0
vehicle_sl.cpp File Reference

Code handling saving and loading of vehicles. More...

#include "../stdafx.h"
#include "saveload.h"
#include "compat/vehicle_sl_compat.h"
#include "../debug.h"
#include "../vehicle_func.h"
#include "../train.h"
#include "../roadveh.h"
#include "../ship.h"
#include "../aircraft.h"
#include "../timetable.h"
#include "../station_base.h"
#include "../effectvehicle_base.h"
#include "../company_base.h"
#include "../company_func.h"
#include "../disaster_vehicle.h"
#include "../economy_base.h"
#include "../safeguards.h"

Go to the source code of this file.

Data Structures

class  SlVehicleCommon
class  SlVehicleTrain
class  SlVehicleRoadVehPath
class  SlVehicleRoadVeh
class  SlVehicleShipPath
class  SlVehicleShip
class  SlVehicleAircraft
class  SlVehicleEffect
class  SlVehicleDisaster
struct  VEHSChunkHandler

Functions

void ConnectMultiheadedTrains ()
 Link front and rear multiheaded engines to each other This is done when loading a savegame.
void ConvertOldMultiheadToNew ()
 Converts all trains to the new subtype format introduced in savegame 16.2 It also links multiheaded engines or make them forget they are multiheaded if no suitable partner is found.
void UpdateOldAircraft ()
 need to be called to load aircraft from old version
static void CheckValidVehicles ()
 Check all vehicles to ensure their engine type is valid for the currently loaded NewGRFs (that includes none...) This only makes a difference if NewGRFs are missing, otherwise all vehicles will be valid.
void AfterLoadVehiclesPhase1 (bool part_of_load)
 Called after load for phase 1 of vehicle initialisation.
void AfterLoadVehiclesPhase2 (bool part_of_load)
 Called after load for phase 2 of vehicle initialisation.
bool TrainController (Train *v, Vehicle *nomove, bool reverse=true)
 Move a vehicle chain one movement stop forwards.
void ReverseTrainDirection (Train *v)
 Turn a train around.
void ReverseTrainSwapVeh (Train *v, int l, int r)
 Swap vehicles l and r in consist v, and reverse their direction.
void FixupTrainLengths ()
 Fixup old train spacing.
const ChunkHandlerTable _veh_chunk_handlers (veh_chunk_handlers)

Variables

uint8_t _age_cargo_skip_counter
 Skip aging of cargo? Used before savegame version 162.
static uint8_t _cargo_periods
static StationID _cargo_source
static TileIndex _cargo_source_xy
static uint16_t _cargo_count
static uint16_t _cargo_paid_for
static Money _cargo_feeder_share
static const SaveLoad _vehicle_desc []
static const VEHSChunkHandler VEHS
static const ChunkHandlerRef veh_chunk_handlers []

Detailed Description

Code handling saving and loading of vehicles.

Definition in file vehicle_sl.cpp.

Function Documentation

◆ AfterLoadVehiclesPhase1()

void AfterLoadVehiclesPhase1 ( bool part_of_load)

Called after load for phase 1 of vehicle initialisation.

So we can set the #previous and #first pointers while loading.

For instantiating the shared vehicle chain.

Definition at line 256 of file vehicle_sl.cpp.

Referenced by AfterLoadGame(), and ReloadNewGRFData().

◆ AfterLoadVehiclesPhase2()

◆ CheckValidVehicles()

void CheckValidVehicles ( )
static

Check all vehicles to ensure their engine type is valid for the currently loaded NewGRFs (that includes none...) This only makes a difference if NewGRFs are missing, otherwise all vehicles will be valid.

This does not make such a game playable, it only prevents crash.

Definition at line 225 of file vehicle_sl.cpp.

References Engine::IterateType(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

Referenced by OrderList::AfterLoadVehiclesPhase1.

◆ ConnectMultiheadedTrains()

void ConnectMultiheadedTrains ( )

Link front and rear multiheaded engines to each other This is done when loading a savegame.

Definition at line 35 of file vehicle_sl.cpp.

References GroundVehicle< T, Type >::ClearEngine(), Vehicle::engine_type, SpecializedVehicle< T, Type >::GetNextVehicle(), GroundVehicle< T, Type >::IsEngine(), GroundVehicle< T, Type >::IsMultiheaded(), and Vehicle::spritenum.

Referenced by AfterLoadGame().

◆ ConvertOldMultiheadToNew()

void ConvertOldMultiheadToNew ( )

Converts all trains to the new subtype format introduced in savegame 16.2 It also links multiheaded engines or make them forget they are multiheaded if no suitable partner is found.

Definition at line 113 of file vehicle_sl.cpp.

References ClrBit(), HasBit(), SpecializedVehicle< T, Type >::Next(), RAILVEH_MULTIHEAD, RAILVEH_WAGON, SetBit(), and SlErrorCorrupt().

Referenced by AfterLoadGame().

◆ FixupTrainLengths()

◆ ReverseTrainDirection()

◆ ReverseTrainSwapVeh()

void ReverseTrainSwapVeh ( Train * v,
int l,
int r )

Swap vehicles l and r in consist v, and reverse their direction.

Parameters
vConsist to change.
lVehicle index in the consist of the first vehicle.
rVehicle index in the consist of the second vehicle.

Definition at line 1650 of file train_cmd.cpp.

References Vehicle::direction, GroundVehicle< T, Type >::gv_flags, Hidden, SpecializedVehicle< T, Type >::Next(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SwapTrainFlags(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Vehicle::tile, UpdateStatusAfterSwap(), Vehicle::vehstatus, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.

Referenced by FixupTrainLengths(), and ReverseTrainDirection().

◆ TrainController()

bool TrainController ( Train * v,
Vehicle * nomove,
bool reverse )

Move a vehicle chain one movement stop forwards.

Parameters
vFirst vehicle to move.
nomoveStop moving this and all following vehicles.
reverseSet to false to not execute the vehicle reversing. This does not change any other logic.
Returns
True if the vehicle could be moved forward, false otherwise.

Definition at line 3288 of file train_cmd.cpp.

References _accel_slowdown, _settings_client, _settings_game, AffectSpeedByZChange(), TrainCache::cached_max_curve_speed, CannotEnter, CCF_TRACK, CheckNextTrainTile(), ClearPathReservation(), Train::ConsistChanged(), Crashed, Vehicle::cur_speed, Ticks::DAY_TICKS, DIAGDIR_BEGIN, DIAGDIR_END, DiagdirBetweenTiles(), DiagdirReachesTrackdirs(), DiagDirToDiagTrack(), DIRDIFF_45LEFT, DIRDIFF_45RIGHT, DirDifference(), Vehicle::direction, EnteredStation, EnteredWormhole, FindFirstBit(), FindFirstTrack(), FindFirstTrackdir(), SpecializedVehicle< T, Type >::First(), SpecializedVehicle< Train, Type >::From(), Train::GetAccelerationType(), Train::GetCurveSpeedLimit(), GetNewVehiclePos(), GetOtherTunnelBridgeEnd(), GetReservedTrackbits(), GetStationIndex(), GetTileRailType(), GetTileTrackStatus(), GetTunnelBridgeDirection(), Train::GetVehicleTrackdir(), HasCrossingReservation(), HasOnewaySignalBlockingTrackdir(), HasPbsSignalOnTrackdir(), HasReservedTracks(), HasSignalOnTrackdir(), HasSignals(), HasVehicleOnTile(), Hidden, INVALID_TILE, InvalidateWindowData(), Vehicle::IsFrontEngine(), IsLevelCrossingTile(), IsPlainRailTile(), IsTileType(), IsTunnel(), IsValidDiagDirection(), AccelerationSlowdownParams::large_turn, MarkTileDirtyByTile(), MarkTrainAsStuck(), GetNewVehiclePosResult::new_tile, SpecializedVehicle< T, Type >::Next(), GetNewVehiclePosResult::old_tile, Vehicle::owner, SpecializedVehicle< T, Type >::Previous(), Vehicle::progress, Rail90DegTurnDisallowed(), ReverseDiagDir(), ReverseTrackdir(), ReverseTrainDirection(), SetSignalStateByTrackdir(), SIGNAL_STATE_RED, SIGSEG_PBS, SIGTYPE_PBS, AccelerationSlowdownParams::small_turn, SND_0E_LEVEL_CROSSING, Stuck, Vehicle::subspeed, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TFP_NONE, TFP_SIGNAL, TFP_STUCK, Vehicle::tick_counter, Vehicle::tile, TileAddByDiagDir(), TRACK_BIT_DEPOT, TRACK_BIT_LEFT, TRACK_BIT_LOWER, TRACK_BIT_MASK, TRACK_BIT_NONE, TRACK_BIT_RIGHT, TRACK_BIT_UPPER, TRACK_BIT_WORMHOLE, TRACK_BIT_X, TRACK_BIT_Y, TrackBitsToTrack(), TrackCrossesTracks(), TrackdirBitsToTrackBits(), TrackDirectionToTrackdir(), TrackdirToExitdir(), TrackdirToTrack(), TrackStatusToRedSignals(), TrackStatusToTrackdirBits(), TrackToTrackBits(), TrainApproachingCrossingTile(), TrainCheckIfLineEnds(), TrainEnterStation(), TRANSPORT_RAIL, TryPathReserve(), TryReserveRailTrack(), TunnelBridge, BaseVehicle::type, Train::UpdateDeltaXY(), GroundVehicle< T, Type >::UpdateInclination(), UpdateLevelCrossing(), Vehicle::UpdatePosition(), UpdateSignalsOnSegment(), VEH_TRAIN, VehicleEnterTile(), VehicleExitDir(), Vehicle::vehstatus, Train::wait_counter, WC_VEHICLE_VIEW, Vehicle::x_pos, GetNewVehiclePosResult::y, and Vehicle::y_pos.

Referenced by AdvanceWagonsAfterSwap(), AdvanceWagonsBeforeSwap(), and FixupTrainLengths().

◆ UpdateOldAircraft()

Variable Documentation

◆ _age_cargo_skip_counter

uint8_t _age_cargo_skip_counter
extern

Skip aging of cargo? Used before savegame version 162.

Definition at line 79 of file misc_sl.cpp.

Referenced by OrderList::AfterLoadVehiclesPhase1.

◆ _cargo_count

uint16_t _cargo_count
static

Definition at line 641 of file vehicle_sl.cpp.

◆ _cargo_feeder_share

Money _cargo_feeder_share
static

Definition at line 643 of file vehicle_sl.cpp.

◆ _cargo_paid_for

uint16_t _cargo_paid_for
static

Definition at line 642 of file vehicle_sl.cpp.

◆ _cargo_periods

uint8_t _cargo_periods
static

Definition at line 638 of file vehicle_sl.cpp.

◆ _cargo_source

StationID _cargo_source
static

Definition at line 639 of file vehicle_sl.cpp.

◆ _cargo_source_xy

TileIndex _cargo_source_xy
static

Definition at line 640 of file vehicle_sl.cpp.

◆ _vehicle_desc

const SaveLoad _vehicle_desc[]
static
Initial value:
= {
}
#define SLE_SAVEBYTE(base, variable)
Only write byte during saving; never read it during loading.
Definition saveload.h:1119
#define SLEG_STRUCT(name, handler)
Storage of a structs in every savegame version.
Definition saveload.h:1254
Vehicle data structure.

Definition at line 1095 of file vehicle_sl.cpp.

◆ veh_chunk_handlers

const ChunkHandlerRef veh_chunk_handlers[]
static
Initial value:
= {
VEHS,
}

Definition at line 1178 of file vehicle_sl.cpp.

◆ VEHS

const VEHSChunkHandler VEHS
static

Definition at line 1177 of file vehicle_sl.cpp.