# vehicle_base.h File Reference

Base class for all vehicles. More...

`#include "vehicle_type.h"`
`#include "track_type.h"`
`#include "rail_type.h"`
`#include "road_type.h"`
`#include "cargo_type.h"`
`#include "direction_type.h"`
`#include "gfx_type.h"`
`#include "command_type.h"`
`#include "date_type.h"`
`#include "company_base.h"`
`#include "company_type.h"`
`#include "oldpool.h"`
`#include "order_base.h"`
`#include "cargopacket.h"`
`#include "texteff.hpp"`
`#include "group_type.h"`
`#include "engine_type.h"`
`#include "order_func.h"`
`#include "transport_type.h"`

Go to the source code of this file.

## Data Structures
struct | VehicleRail
struct | VehicleAir
struct | VehicleRoad
struct | VehicleEffect
struct | VehicleDisaster
struct | VehicleShip
struct | Vehicle
struct | DisasterVehicle
| This class 'wraps' Vehicle; you do not actually instantiate this class. More...
struct | InvalidVehicle
| This class 'wraps' Vehicle; you do not actually instantiate this class. More...
struct | FreeUnitIDGenerator
| Generates sequence of free UnitID numbers. More...
## Defines
#define | FOR_ALL_VEHICLES_FROM(v, start) for (v = GetVehicle(start); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) if (v->IsValid())
#define | FOR_ALL_VEHICLES(v) FOR_ALL_VEHICLES_FROM(v, 0)
## Enumerations
enum | RoadVehicleStates { RVSB_IN_DEPOT = 0xFE, RVSB_WORMHOLE = 0xFF, RVS_USING_SECOND_BAY = 1, RVS_IS_STOPPING = 2, RVS_DRIVE_SIDE = 4, RVS_IN_ROAD_STOP = 5, RVS_IN_DT_ROAD_STOP = 6, RVSB_IN_ROAD_STOP = 1 << RVS_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END = RVSB_IN_ROAD_STOP + TRACKDIR_END, RVSB_IN_DT_ROAD_STOP = 1 << RVS_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END = RVSB_IN_DT_ROAD_STOP + TRACKDIR_END, RVSB_TRACKDIR_MASK = 0x0F, RVSB_ROAD_STOP_TRACKDIR_MASK = 0x09 }
| Road vehicle states. More...
enum | VehStatus { VS_HIDDEN = 0x01, VS_STOPPED = 0x02, VS_UNCLICKABLE = 0x04, VS_DEFPAL = 0x08, VS_TRAIN_SLOWING = 0x10, VS_SHADOW = 0x20, VS_AIRCRAFT_BROKEN = 0x40, VS_CRASHED = 0x80 }
enum | VehicleFlags { VF_LOADING_FINISHED, VF_CARGO_UNLOADING, VF_BUILT_AS_PROTOTYPE, VF_TIMETABLE_STARTED, VF_AUTOFILL_TIMETABLE, VF_AUTOFILL_PRES_WAIT_TIME }
enum | VehicleRailFlags { VRF_REVERSING = 0, VRF_GOINGUP = 1, VRF_GOINGDOWN = 2, VRF_POWEREDWAGON = 3, VRF_REVERSE_DIRECTION = 4, VRF_NO_PATH_TO_DESTINATION = 5, VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL = 6, VRF_TOGGLE_REVERSE = 7, VRF_TRAIN_STUCK = 8 }
## Functions
const SaveLoad * | GetVehicleDescription (VehicleType vt)
| Make it possible to make the saveload tables "friends" of other classes.
bool | LoadOldVehicle (LoadgameState *ls, int num)
static VehicleID | GetMaxVehicleIndex ()
static uint | GetNumVehicles ()
static bool | IsValidVehicleID (uint index)
| Check if an index is a vehicle-index (so between 0 and max-vehicles).
static Order * | GetVehicleOrder (const Vehicle *v, int index)
static Order * | GetLastVehicleOrder (const Vehicle *v)
| Returns the last order of a vehicle, or NULL if it doesn't exists.
Trackdir | GetVehicleTrackdir (const Vehicle *v)
| Returns the Trackdir on which the vehicle is currently located.
void | CheckVehicle32Day (Vehicle *v)
## Variables
static const int32 | INVALID_COORD = 0x7fffffff

## Detailed Description

Base class for all vehicles.

Definition in file vehicle_base.h.

## Enumeration Type Documentation

enum RoadVehicleStates

Road vehicle states.

Enumerator:

  RVSB_IN_DEPOT | The vehicle is in a depot.
  RVSB_WORMHOLE | The vehicle is in a tunnel and/or bridge.
  RVS_USING_SECOND_BAY | Only used while in a road stop.
  RVS_IS_STOPPING | Only used for drive-through stops. Vehicle will stop here.
  RVS_DRIVE_SIDE | Only used when retrieving move data.
  RVS_IN_ROAD_STOP | The vehicle is in a road stop.
  RVS_IN_DT_ROAD_STOP | The vehicle is in a drive-through road stop.
  RVSB_IN_ROAD_STOP | The vehicle is in a road stop.
  RVSB_IN_DT_ROAD_STOP | The vehicle is in a drive-through road stop.
  RVSB_TRACKDIR_MASK | The mask used to extract track dirs.
  RVSB_ROAD_STOP_TRACKDIR_MASK | Only bits 0 and 3 are used to encode the trackdir for road stops.

Definition at line 29 of file vehicle_base.h.

enum VehicleFlags

Enumerator:

  VF_TIMETABLE_STARTED | Whether the vehicle has started running on the timetable yet.
  VF_AUTOFILL_TIMETABLE | Whether the vehicle should fill in the timetable automatically.
  VF_AUTOFILL_PRES_WAIT_TIME | Whether non-destructive auto-fill should preserve waiting times.

Definition at line 74 of file vehicle_base.h.

## Function Documentation

static Order* GetLastVehicleOrder | ( | const Vehicle * | v | ) | `[inline, static]`

Returns the last order of a vehicle, or NULL if it doesn't exists.

Parameters:

  | v | Vehicle to query

Returns:
  last order of a vehicle, if available

Definition at line 720 of file vehicle_base.h.

Referenced by CheckOrders().

const SaveLoad* GetVehicleDescription | ( | VehicleType | vt | ) |

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

Parameters:

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

Returns:
  the saveload description

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

Saving and loading the current order of vehicles.

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

Referenced by Load_VEHS(), and Save_VEHS().

Trackdir GetVehicleTrackdir | ( | const Vehicle * | v | ) |

Returns the Trackdir on which the vehicle is currently located.

Works for trains and ships. Currently works only sortof for road vehicles, since they have a fuzzy concept of being "on" a trackdir. Dunno really what it returns for a road vehicle that is halfway a tile, never really understood that part. For road vehicles that are at the beginning or end of the tile, should just return the diagonal trackdir on which they are driving. I _think_. For other vehicles types, or vehicles with no clear trackdir (such as those in depots), returns 0xFF.

Definition at line 1193 of file vehicle.cpp.

References DiagDirToDiagTrackdir(), DirToDiagDir(), FindFirstTrack(), GetRailDepotDirection(), GetRoadStopDir(), INVALID_TRACKDIR, IsReversingRoadTrackdir(), RVSB_TRACKDIR_MASK, TRACK_BIT_DEPOT, TRACK_BIT_WORMHOLE, and TrackDirectionToTrackdir().

Referenced by CheckNextTrainTile(), ChooseShipTrack(), CmdBuildRailroadStation(), CmdRemoveFromRailroadStation(), FindClosestTrainDepot(), FollowTrainReservation(), FreeTrainTrackReservation(), YapfCheckReverseTrain(), YapfFindNearestRailDepotTwoWay(), and YapfFindNearestRoadDepot().

static bool IsValidVehicleID | ( | uint | index | ) | `[inline, static]`

Check if an index is a vehicle-index (so between 0 and max-vehicles).

Parameters:

  | index | of the vehicle to query

Returns:
  Returns true if the vehicle-id is in range

Definition at line 685 of file vehicle_base.h.

Referenced by CmdAddVehicleGroup(), CmdAutofillTimetable(), CmdAutoreplaceVehicle(), CmdChangeServiceInt(), CmdChangeTimetable(), CmdCloneOrder(), CmdCloneVehicle(), CmdDeleteOrder(), CmdForceTrainProceed(), CmdInsertOrder(), CmdModifyOrder(), CmdMoveOrder(), CmdMoveRailVehicle(), CmdOrderRefit(), CmdRefitAircraft(), CmdRefitRailVehicle(), CmdRefitRoadVeh(), CmdRefitShip(), CmdRenameVehicle(), CmdRestoreOrderIndex(), CmdReverseTrainDirection(), CmdSellAircraft(), CmdSellRailWagon(), CmdSellRoadVeh(), CmdSellShip(), CmdSendAircraftToHangar(), CmdSendRoadVehToDepot(), CmdSendShipToDepot(), CmdSendTrainToDepot(), CmdSetVehicleOnTime(), CmdSkipToOrder(), CmdStartStopVehicle(), CmdTurnRoadVeh(), and AIVehicle::IsValidVehicle().