OpenTTD
Functions | Variables
vehicle_sl.cpp File Reference

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

#include "../stdafx.h"
#include "../vehicle_func.h"
#include "../train.h"
#include "../roadveh.h"
#include "../ship.h"
#include "../aircraft.h"
#include "../station_base.h"
#include "../effectvehicle_base.h"
#include "../company_base.h"
#include "../company_func.h"
#include "../disaster_vehicle.h"
#include "saveload.h"
#include <map>
#include "../safeguards.h"

Go to the source code of this file.

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. More...
 
const SaveLoadGetVehicleDescription (VehicleType vt)
 Make it possible to make the saveload tables "friends" of other classes. More...
 
static void Save_VEHS ()
 Will be called when the vehicles need to be saved. More...
 
void Load_VEHS ()
 Will be called when vehicles need to be loaded. More...
 
static void Ptrs_VEHS ()
 

Variables

byte _age_cargo_skip_counter
 Skip aging of cargo? Used before savegame version 162.
 
static uint8 _cargo_days
 
static uint16 _cargo_source
 
static uint32 _cargo_source_xy
 
static uint16 _cargo_count
 
static uint16 _cargo_paid_for
 
static Money _cargo_feeder_share
 
static uint32 _cargo_loaded_at_xy
 
const ChunkHandler _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 249 of file vehicle_sl.cpp.

References Vehicle::fill_percent_te_id, FOR_ALL_VEHICLES, Vehicle::Next(), Vehicle::NextShared(), Vehicle::previous, and Vehicle::previous_shared.

◆ 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 216 of file vehicle_sl.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::GetPoolSize(), and INVALID_ENGINE.

◆ FixupTrainLengths()

void FixupTrainLengths ( )

◆ GetVehicleDescription()

const SaveLoad* GetVehicleDescription ( VehicleType  vt)

Make it possible to make the saveload tables "friends" of other classes.

So we can use private/protected variables in the saveload code.

Saving and loading the current order of vehicles.

The vehicles have a cargo list (and we want that saved).

Parameters
vtthe vehicle type. Can be VEH_END for the common vehicle description data
Returns
the saveload description

Save and load of vehicles

Definition at line 574 of file vehicle_sl.cpp.

References SLE_VAR.

◆ Load_VEHS()

void Load_VEHS ( )

Will be called when vehicles need to be loaded.

Loading of ancient vehicles.

Definition at line 883 of file vehicle_sl.cpp.

◆ ReverseTrainDirection()

void ReverseTrainDirection ( Train v)

Turn a train around.

Parameters
vTrain to turn around.

Definition at line 1821 of file train_cmd.cpp.

References FreeTrainTrackReservation(), HasBit(), InvalidateWindowData(), IsRailDepotTile(), Vehicle::tile, TrainApproachingCrossingTile(), VRF_TRAIN_STUCK, and WC_VEHICLE_DEPOT.

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

References Vehicle::direction, GroundVehicle< T, Type >::gv_flags, SpecializedVehicle< T, Type >::Next(), Swap(), SwapTrainFlags(), Vehicle::tile, UpdateStatusAfterSwap(), Vehicle::vehstatus, VS_HIDDEN, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.

◆ Save_VEHS()

static void Save_VEHS ( )
static

Will be called when the vehicles need to be saved.

Definition at line 872 of file vehicle_sl.cpp.

References FOR_ALL_VEHICLES.

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

References DIAGDIR_BEGIN, DiagdirBetweenTiles(), Vehicle::first, SpecializedVehicle< T, Type >::First(), GetNewVehiclePos(), HasBit(), GetNewVehiclePosResult::new_tile, SpecializedVehicle< T, Type >::Next(), GetNewVehiclePosResult::old_tile, SpecializedVehicle< T, Type >::Previous(), TRACK_BIT_DEPOT, TRACK_BIT_WORMHOLE, TrainCheckIfLineEnds(), TrainEnterStation(), VehicleEnterTile(), VETS_CANNOT_ENTER, VETS_ENTERED_STATION, VETS_STATION_ID_OFFSET, and GetNewVehiclePosResult::y.

Referenced by AdvanceWagonsAfterSwap(), and FixupTrainLengths().

Variable Documentation

◆ _veh_chunk_handlers

const ChunkHandler _veh_chunk_handlers[]
Initial value:
= {
{ 'VEHS', Save_VEHS, Load_VEHS, Ptrs_VEHS, NULL, CH_SPARSE_ARRAY | CH_LAST},
}
static void Save_VEHS()
Will be called when the vehicles need to be saved.
Definition: vehicle_sl.cpp:872
void Load_VEHS()
Will be called when vehicles need to be loaded.
Definition: vehicle_sl.cpp:883
Last chunk in this array.
Definition: saveload.h:104