OpenTTD Source 20250428-master-ga5578166bb
vehicle_base.h File Reference

Base class for all vehicles. More...

#include "track_type.h"
#include "command_type.h"
#include "order_base.h"
#include "cargopacket.h"
#include "texteff.hpp"
#include "engine_type.h"
#include "order_func.h"
#include "transport_type.h"
#include "group_type.h"
#include "base_consist.h"
#include "network/network.h"
#include "saveload/saveload.h"
#include "timer/timer_game_calendar.h"

Go to the source code of this file.

Data Structures

struct  NewGRFCache
 Cached often queried (NewGRF) values. More...
 
struct  VehicleCache
 Cached often queried values common to all vehicles. More...
 
struct  VehicleSpriteSeq
 Sprite sequence for a vehicle part. More...
 
struct  MutableSpriteCache
 Cache for vehicle sprites and values relating to whether they should be updated before drawing, or calculating the viewport. More...
 
struct  RefitDesc
 Simulated cargo type and capacity for prediction of future links. More...
 
struct  ClosestDepot
 Structure to return information about the closest depot location, and whether it could be found. More...
 
struct  Vehicle
 Vehicle data structure. More...
 
struct  Vehicle::OrderIterator
 Iterator to iterate orders Supports deletion of current order. More...
 
struct  Vehicle::IterateWrapper
 Iterable ensemble of orders. More...
 
struct  SpecializedVehicle< T, Type >
 Class defining several overloaded accessors so we don't have to cast vehicle types that often. More...
 

Typedefs

using VehStates = EnumBitSet< VehState, uint8_t >
 
typedef Pool< Vehicle, VehicleID, 512 > VehiclePool
 A vehicle pool for a little over 1 million vehicles.
 

Enumerations

enum class  VehState : uint8_t {
  Hidden = 0 , Stopped = 1 , Unclickable = 2 , DefaultPalette = 3 ,
  TrainSlowing = 4 , Shadow = 5 , AircraftBroken = 6 , Crashed = 7
}
 Vehicle state bits in Vehicle::vehstatus. More...
 
enum  NewGRFCacheValidValues : uint8_t {
  NCVV_POSITION_CONSIST_LENGTH = 0 , NCVV_POSITION_SAME_ID_LENGTH = 1 , NCVV_CONSIST_CARGO_INFORMATION = 2 , NCVV_COMPANY_INFORMATION = 3 ,
  NCVV_POSITION_IN_VEHICLE = 4 , NCVV_END
}
 Bit numbers used to indicate which of the NewGRFCache values are valid. More...
 
enum  VisualEffect : uint8_t {
  VE_OFFSET_START = 0 , VE_OFFSET_COUNT = 4 , VE_OFFSET_CENTRE = 8 , VE_TYPE_START = 4 ,
  VE_TYPE_COUNT = 2 , VE_TYPE_DEFAULT = 0 , VE_TYPE_STEAM = 1 , VE_TYPE_DIESEL = 2 ,
  VE_TYPE_ELECTRIC = 3 , VE_DISABLE_EFFECT = 6 , VE_ADVANCED_EFFECT = VE_DISABLE_EFFECT , VE_DISABLE_WAGON_POWER = 7 ,
  VE_DEFAULT = 0xFF
}
 Meaning of the various bits of the visual effect. More...
 
enum  VisualEffectSpawnModel : uint8_t {
  VESM_NONE = 0 , VESM_STEAM , VESM_DIESEL , VESM_ELECTRIC ,
  VESM_END
}
 Models for spawning visual effects. More...
 
enum  GroundVehicleSubtypeFlags : uint8_t {
  GVSF_FRONT = 0 , GVSF_ARTICULATED_PART = 1 , GVSF_WAGON = 2 , GVSF_ENGINE = 3 ,
  GVSF_FREE_WAGON = 4 , GVSF_MULTIHEADED = 5
}
 Enum to handle ground vehicle subtypes. More...
 

Functions

bool LoadOldVehicle (LoadgameState &ls, int num)
 Load the vehicles of an old style savegame.
 
void FixOldVehicles (LoadgameState &ls)
 Convert the old style vehicles into something that resembles the old new style savegames.
 

Variables

const uint TILE_AXIAL_DISTANCE = 192
 
const uint TILE_CORNER_DISTANCE = 128
 
VehiclePool _vehicle_pool
 
static const int32_t INVALID_COORD = 0x7fffffff
 Sentinel for an invalid coordinate.
 

Detailed Description

Base class for all vehicles.

Definition in file vehicle_base.h.

Typedef Documentation

◆ VehiclePool

A vehicle pool for a little over 1 million vehicles.

Definition at line 185 of file vehicle_base.h.

◆ VehStates

using VehStates = EnumBitSet<VehState, uint8_t>

Definition at line 41 of file vehicle_base.h.

Enumeration Type Documentation

◆ GroundVehicleSubtypeFlags

enum GroundVehicleSubtypeFlags : uint8_t

Enum to handle ground vehicle subtypes.

This is defined here instead of at GroundVehicle because some common function require access to these flags. Do not access it directly unless you have to. Use the subtype access functions.

Enumerator
GVSF_FRONT 

Leading engine of a consist.

GVSF_ARTICULATED_PART 

Articulated part of an engine.

GVSF_WAGON 

Wagon (not used for road vehicles).

GVSF_ENGINE 

Engine that can be front engine, but might be placed behind another engine (not used for road vehicles).

GVSF_FREE_WAGON 

First in a wagon chain (in depot) (not used for road vehicles).

GVSF_MULTIHEADED 

Engine is multiheaded (not used for road vehicles).

Definition at line 101 of file vehicle_base.h.

◆ NewGRFCacheValidValues

enum NewGRFCacheValidValues : uint8_t

Bit numbers used to indicate which of the NewGRFCache values are valid.

Enumerator
NCVV_POSITION_CONSIST_LENGTH 

This bit will be set if the NewGRF var 40 currently stored is valid.

NCVV_POSITION_SAME_ID_LENGTH 

This bit will be set if the NewGRF var 41 currently stored is valid.

NCVV_CONSIST_CARGO_INFORMATION 

This bit will be set if the NewGRF var 42 currently stored is valid.

NCVV_COMPANY_INFORMATION 

This bit will be set if the NewGRF var 43 currently stored is valid.

NCVV_POSITION_IN_VEHICLE 

This bit will be set if the NewGRF var 4D currently stored is valid.

NCVV_END 

End of the bits.

Definition at line 44 of file vehicle_base.h.

◆ VehState

enum class VehState : uint8_t
strong

Vehicle state bits in Vehicle::vehstatus.

Enumerator
Hidden 

Vehicle is not visible.

Stopped 

Vehicle is stopped by the player.

Unclickable 

Vehicle is not clickable by the user (shadow vehicles).

DefaultPalette 

Use default vehicle palette.

See also
DoDrawVehicle
TrainSlowing 

Train is slowing down.

Shadow 

Vehicle is a shadow vehicle.

AircraftBroken 

Aircraft is broken down.

Crashed 

Vehicle is crashed.

Definition at line 31 of file vehicle_base.h.

◆ VisualEffect

enum VisualEffect : uint8_t

Meaning of the various bits of the visual effect.

Enumerator
VE_OFFSET_START 

First bit that contains the offset (0 = front, 8 = centre, 15 = rear)

VE_OFFSET_COUNT 

Number of bits used for the offset.

VE_OFFSET_CENTRE 

Value of offset corresponding to a position above the centre of the vehicle.

VE_TYPE_START 

First bit used for the type of effect.

VE_TYPE_COUNT 

Number of bits used for the effect type.

VE_TYPE_DEFAULT 

Use default from engine class.

VE_TYPE_STEAM 

Steam plumes.

VE_TYPE_DIESEL 

Diesel fumes.

VE_TYPE_ELECTRIC 

Electric sparks.

VE_DISABLE_EFFECT 

Flag to disable visual effect.

VE_ADVANCED_EFFECT 

Flag for advanced effects.

VE_DISABLE_WAGON_POWER 

Flag to disable wagon power.

VE_DEFAULT 

Default value to indicate that visual effect should be based on engine class.

Definition at line 67 of file vehicle_base.h.

◆ VisualEffectSpawnModel

enum VisualEffectSpawnModel : uint8_t

Models for spawning visual effects.

Enumerator
VESM_NONE 

No visual effect.

VESM_STEAM 

Steam model.

VESM_DIESEL 

Diesel model.

VESM_ELECTRIC 

Electric model.

Definition at line 87 of file vehicle_base.h.

Function Documentation

◆ FixOldVehicles()

void FixOldVehicles ( LoadgameState ls)
extern

Convert the old style vehicles into something that resembles the old new style savegames.

Then AfterLoadGame can handle the rest of the conversion.

Definition at line 236 of file oldloader_sl.cpp.

◆ LoadOldVehicle()

bool LoadOldVehicle ( LoadgameState ls,
int  num 
)
extern

Load the vehicles of an old style savegame.

Parameters
lsState (buffer) of the currently loaded game.
numThe number of vehicles to load.
Returns
True iff loading went without problems.

So we can set the proper next pointer while loading.

Parameters
lsState (buffer) of the currently loaded game.
numThe number of vehicles to load.
Returns
True iff loading went without problems.

Definition at line 238 of file oldloader_sl.cpp.

Variable Documentation

◆ INVALID_COORD

const int32_t INVALID_COORD = 0x7fffffff
static

◆ TILE_AXIAL_DISTANCE

const uint TILE_AXIAL_DISTANCE = 192

Definition at line 27 of file vehicle_base.h.

◆ TILE_CORNER_DISTANCE

const uint TILE_CORNER_DISTANCE = 128

Definition at line 28 of file vehicle_base.h.