OpenTTD Source  20240919-master-gdf0233f4c2
vehicle_sl.cpp File Reference
#include "../stdafx.h"
#include "saveload.h"
#include "compat/vehicle_sl_compat.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  SlVehicleRoadVeh
 
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. More...
 
void AfterLoadVehicles (bool part_of_load)
 Called after load to update coordinates. More...
 
bool TrainController (Train *v, Vehicle *nomove, bool reverse=true)
 Move a vehicle chain one movement stop forwards. More...
 
void ReverseTrainDirection (Train *v)
 Turn a train around. More...
 
void ReverseTrainSwapVeh (Train *v, int l, int r)
 Swap vehicles l and r in consist v, and reverse their direction. More...
 
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 uint16_t _cargo_source
 
static uint32_t _cargo_source_xy
 
static uint16_t _cargo_count
 
static uint16_t _cargo_paid_for
 
static Money _cargo_feeder_share
 
const static 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

◆ AfterLoadVehicles()

void AfterLoadVehicles ( bool  part_of_load)

Called after load to update coordinates.

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

For instantiating the shared vehicle chain.

Definition at line 255 of file vehicle_sl.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Iterate().

◆ CheckValidVehicles()

static 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 224 of file vehicle_sl.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::GetPoolSize(), INVALID_ENGINE, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Iterate(), Engine::IterateType(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

◆ ReverseTrainDirection()

void ReverseTrainDirection ( Train v)

Turn a train around.

Parameters
vTrain to turn around.

Definition at line 1967 of file train_cmd.cpp.

References IsRailDepotTile(), and Vehicle::tile.

◆ 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 1630 of file train_cmd.cpp.

References SpecializedVehicle< T, Type >::Next().

◆ TrainController()

Variable Documentation

◆ _vehicle_desc

const static SaveLoad _vehicle_desc[]
static
Initial value:

Definition at line 1028 of file vehicle_sl.cpp.

◆ veh_chunk_handlers

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

Definition at line 1111 of file vehicle_sl.cpp.

SlVehicleShip
Definition: vehicle_sl.cpp:856
SlVehicleAircraft
Definition: vehicle_sl.cpp:885
SlVehicleTrain
Definition: vehicle_sl.cpp:785
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:244
SLE_SAVEBYTE
#define SLE_SAVEBYTE(base, variable)
Only write byte during saving; never read it during loading.
Definition: saveload.h:1044
SlVehicleEffect
Definition: vehicle_sl.cpp:925
SlVehicleRoadVeh
Definition: vehicle_sl.cpp:820
SlVehicleDisaster
Definition: vehicle_sl.cpp:970
SLEG_STRUCT
#define SLEG_STRUCT(name, handler)
Storage of a structs in every savegame version.
Definition: saveload.h:1178