# 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 "../engine_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 241 of file vehicle_sl.cpp.

References Vehicle::AddToShared(), AIR_HELICOPTER, CheckSavegameVersion(), CheckSavegameVersionOldStyle(), CheckValidVehicles(), Train::ConsistChanged(), Vehicle::cur_speed, EF_ROAD_TRAM, Vehicle::First(), OrderList::first, Vehicle::first, RoadVehicleCache::first_engine, TrainCache::first_engine, SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), SpecializedVehicle< RoadVehicle, VEH_ROAD >::From(), SpecializedVehicle< Train, VEH_TRAIN >::From(), OrderList::GetFirstSharedVehicle(), Vehicle::GetImage(), HasBit(), OrderList::Initialize(), Train::IsEngine(), Train::IsFreeWagon(), Train::IsFrontEngine(), RoadVehicle::IsRoadVehFront(), Vehicle::list, Vehicle::Next(), Vehicle::next_shared, Vehicle::NextShared(), Vehicle::old, Vehicle::Previous(), Vehicle::previous, Vehicle::previous_shared, Vehicle::PreviousShared(), RoadVehicle::rcache, ROADTYPE_ROAD, ROADTYPE_TRAM, RoadTypeToRoadTypes(), Vehicle::subtype, BaseVehicle::type, UpdateAircraftCache(), Vehicle::UpdateDeltaXY(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, VehicleMove(), and Vehicle::vehstatus.

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

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_engine_pool >::GetPoolSize(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, BaseVehicle::type, 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 402 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 701 of file vehicle_sl.cpp.

References CargoList< Tinst >::Append(), Vehicle::cargo, CheckSavegameVersion(), Vehicle::current_order, DEFAULT_GROUP, Order::flags, GB(), GetVehicleDescription(), Vehicle::group_id, SlIterateArray(), SlObject(), SlReadByte(), Order::type, 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 690 of file vehicle_sl.cpp.

References GetVehicleDescription(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, SlObject(), and BaseVehicle::type.

## Variable Documentation

const ChunkHandler _veh_chunk_handlers[]

Initial value:

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