# 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 "saveload.h"`
`#include <map>`

Go to the source code of this file.

## Functions

void | ConnectMultiheadedTrains ()
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.
void | AfterLoadVehicles (bool part_of_load)
| Called after load to update coordinates.
const SaveLoad * | GetVehicleDescription (VehicleType vt)
| Make it possible to make the saveload tables "friends" of other classes.
static void | Save_VEHS ()
| Will be called when the vehicles need to be saved.
void | Load_VEHS ()
| Will be called when vehicles need to be loaded.
static void | Ptrs_VEHS ()

## Variables

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

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

References AIR_HELICOPTER, CheckSavegameVersion(), CheckSavegameVersionOldStyle(), CheckValidVehicles(), RoadVehicle::compatible_roadtypes, EF_ROAD_TRAM, RoadVehicleCache::first_engine, TrainCache::first_engine, SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), SpecializedVehicle< RoadVehicle, VEH_ROAD >::From(), SpecializedVehicle< Train, VEH_TRAIN >::From(), HasBit(), Train::IsEngine(), Train::IsFreeWagon(), Train::IsFrontEngine(), RoadVehicle::IsRoadVehFront(), TrainCache::last_speed, RoadVehicle::rcache, RoadVehicle::roadtype, ROADTYPE_ROAD, ROADTYPE_TRAM, RoadTypeToRoadTypes(), Train::tcache, TrainConsistChanged(), UpdateAircraftCache(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, and VehicleMove().

Referenced by ReloadNewGRFData().

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

References VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

Referenced by AfterLoadVehicles().

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:

  | vt | the vehicle type. Can be VEH_END for the common vehicle description data

Returns:
  the saveload description

Save and load of vehicles

Definition at line 401 of file vehicle_sl.cpp.

References VEH_AIRCRAFT, VEH_DISASTER, VEH_EFFECT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

Referenced by Load_VEHS(), and Save_VEHS().

void Load_VEHS | ( |  | ) |

Will be called when vehicles need to be loaded.

Loading of ancient vehicles.

Definition at line 696 of file vehicle_sl.cpp.

References CheckSavegameVersion(), DEFAULT_GROUP, GB(), GetVehicleDescription(), SlIterateArray(), SlObject(), SlReadByte(), VEH_AIRCRAFT, VEH_DISASTER, VEH_EFFECT, VEH_INVALID, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

static void Save_VEHS | ( |  | ) | `[static]`

Will be called when the vehicles need to be saved.

Definition at line 685 of file vehicle_sl.cpp.

References GetVehicleDescription(), and SlObject().

## Variable Documentation

const ChunkHandler _veh_chunk_handlers[]

Initial value:

     {
      { 'VEHS', Save_VEHS, Load_VEHS, Ptrs_VEHS, CH_SPARSE_ARRAY | CH_LAST},
    }