# RoadVehicle Struct Reference

Buses, trucks and trams belong to this class. More...

`#include <roadveh.h>`

Inheritance diagram for RoadVehicle:

## Public Member Functions
| RoadVehicle ()
| We don't want GCC to zero our struct! It already is zeroed and has an index!
virtual | ~RoadVehicle ()
| We want to 'destruct' the right class.
const char * | GetTypeString () const
| Get a string 'representation' of the vehicle type.
void | MarkDirty ()
| Marks the vehicles to be redrawn and updates cached variables.
void | UpdateDeltaXY (Direction direction)
| Updates the x and y offsets and the size of the sprite used for this vehicle.
ExpensesType | GetExpenseType (bool income) const
| Sets the expense type associated to this vehicle type.
bool | IsPrimaryVehicle () const
| Whether this is the primary vehicle in the chain.
SpriteID | GetImage (Direction direction) const
| Gets the sprite to show for the given direction.
int | GetDisplaySpeed () const
| Gets the speed in km-ish/h that can be sent into SetDParam for string processing.
int | GetDisplayMaxSpeed () const
| Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.
Money | GetRunningCost () const
| Gets the running cost of a vehicle.
int | GetDisplayImageWidth (Point *offset=NULL) const
| Get the width of a road vehicle image in the GUI.
bool | IsInDepot () const
| Check whether the vehicle is in the depot.
bool | IsStoppedInDepot () const
| Check whether the vehicle is in the depot *and* stopped.
bool | Tick ()
| Calls the tick handler of the vehicle.
void | OnNewDay ()
| Calls the new day handler of the vehicle.
uint | Crash (bool flooded=false)
| Crash the (whole) vehicle chain.
Trackdir | GetVehicleTrackdir () const
| Returns the Trackdir on which the vehicle is currently located.
TileIndex | GetOrderStationLocation (StationID station)
| Determine the location for the station where the vehicle goes to next.
bool | FindClosestDepot (TileIndex *location, DestinationID *destination, bool *reverse)
| Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should reverse.
bool | IsBus () const
| Check whether a roadvehicle is a bus.
FORCEINLINE bool | IsRoadVehFront () const
| Check if vehicle is a front engine.
FORCEINLINE void | SetRoadVehFront ()
| Set front engine state.
FORCEINLINE bool | IsArticulatedPart () const
| Check if vehicl is an articulated part of an engine.
FORCEINLINE void | SetArticulatedPart ()
| Set a vehicle to be an articulated part.
FORCEINLINE bool | HasArticulatedPart () const
| Check if an engine has an articulated part.
## Data Fields
RoadVehicleCache | rcache
| Cache of often used calculated values.
byte | state
byte | frame
uint16 | blocked_ctr
byte | overtaking
byte | overtaking_ctr
uint16 | crashed_ctr
byte | reverse_ctr
RoadType | roadtype
RoadTypes | compatible_roadtypes

## Detailed Description

Buses, trucks and trams belong to this class.

Definition at line 92 of file roadveh.h.

## Constructor & Destructor Documentation

virtual RoadVehicle::~RoadVehicle | ( |  | ) | `[inline, virtual]`

We want to 'destruct' the right class.

Definition at line 108 of file roadveh.h.

References Vehicle::PreDestructor().

## Member Function Documentation

uint RoadVehicle::Crash | ( | bool | flooded = `false` | ) | `[virtual]`

Crash the (whole) vehicle chain.

Parameters:

  | flooded | whether the cause of the crash is flooding or not.

Returns:
  the number of lost souls.

Reimplemented from Vehicle.

Definition at line 529 of file roadveh_cmd.cpp.

References RoadStop::GetByTile(), GetRoadStopType(), IsInsideMM(), IsRoadVehFront(), RoadStop::Leave(), RVSB_IN_DT_ROAD_STOP, state, and Vehicle::tile.

Referenced by DisasterTick_Ufo().

bool RoadVehicle::FindClosestDepot | ( | TileIndex * | location,
|  | DestinationID * | destination,
|  | bool * | reverse |
| ) |  |  | `[virtual]`

Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should reverse.

Parameters:

  | location | where do we go to?
  | destination | what hangar do we go to?
  | reverse | should the vehicle be reversed?

Returns:
  true if a depot could be found.

Reimplemented from Vehicle.

Definition at line 361 of file roadveh_cmd.cpp.

References FindDepotData::best_length, GetDepotIndex(), and FindDepotData::tile.

int RoadVehicle::GetDisplayImageWidth | ( | Point * | offset = `NULL` | ) | const

Get the width of a road vehicle image in the GUI.

Parameters:

  | offset | Additional offset for positioning the sprite; set to NULL if not needed

Returns:
  Width in pixels

Definition at line 103 of file roadveh_cmd.cpp.

References RoadVehicleCache::cached_veh_length, and rcache.

Referenced by DrawRoadVehImage().

int RoadVehicle::GetDisplayMaxSpeed | ( |  | ) | const`[inline, virtual]`

Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.

Returns:
  the vehicle's maximum speed

Reimplemented from Vehicle.

Definition at line 117 of file roadveh.h.

References Vehicle::max_speed.

int RoadVehicle::GetDisplaySpeed | ( |  | ) | const`[inline, virtual]`

Gets the speed in km-ish/h that can be sent into SetDParam for string processing.

Returns:
  the vehicle's speed

Reimplemented from Vehicle.

Definition at line 116 of file roadveh.h.

References Vehicle::cur_speed.

ExpensesType RoadVehicle::GetExpenseType | ( | bool | income | ) | const`[inline, virtual]`

Sets the expense type associated to this vehicle type.

Parameters:

  | income | whether this is income or (running) expenses of the vehicle

Reimplemented from Vehicle.

Definition at line 113 of file roadveh.h.

References EXPENSES_ROADVEH_INC, and EXPENSES_ROADVEH_RUN.

SpriteID RoadVehicle::GetImage | ( | Direction | direction | ) | const`[virtual]`

Gets the sprite to show for the given direction.

Parameters:

  | direction | the direction the vehicle is facing

Returns:
  the sprite for the given vehicle in the given direction

Reimplemented from Vehicle.

Definition at line 129 of file roadveh_cmd.cpp.

References Vehicle::cargo, Vehicle::cargo_cap, CargoList< Tinst >::Count(), and SpecializedVehicle< RoadVehicle, VEH_ROAD >::Get().

Referenced by DrawRoadVehImage().

TileIndex RoadVehicle::GetOrderStationLocation | ( | StationID | station | ) | `[virtual]`

Determine the location for the station where the vehicle goes to next.

Things done for example are allocating slots in a road stop or exact location of the platform is determined for ships.

Parameters:

  | station | the station to make the next location of the vehicle.

Returns:
  the location (tile) to aim for.

Reimplemented from Vehicle.

Definition at line 613 of file roadveh_cmd.cpp.

References CanVehicleUseStation(), SpecializedVehicle< RoadVehicle, VEH_ROAD >::Get(), Vehicle::IncrementOrderIndex(), and BaseStation::xy.

Referenced by RemoveRoadStop().

Money RoadVehicle::GetRunningCost | ( |  | ) | const`[virtual]`

Gets the running cost of a vehicle.

Returns:
  the vehicle's running cost

Reimplemented from Vehicle.

Definition at line 1597 of file roadveh_cmd.cpp.

References SpecializedVehicle< RoadVehicle, VEH_ROAD >::Get(), GetPrice(), and PROP_ROADVEH_RUNNING_COST_FACTOR.

Referenced by OnNewDay().

const char* RoadVehicle::GetTypeString | ( |  | ) | const`[inline, virtual]`

Get a string 'representation' of the vehicle type.

Returns:
  the string representation.

Reimplemented from Vehicle.

Definition at line 110 of file roadveh.h.

Trackdir RoadVehicle::GetVehicleTrackdir | ( |  | ) | const`[virtual]`

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.

Returns:
  the trackdir of the vehicle

Reimplemented from Vehicle.

Definition at line 1687 of file roadveh_cmd.cpp.

References DiagDirToDiagTrackdir(), DirToDiagDir(), GetRoadStopDir(), INVALID_TRACKDIR, IsInDepot(), IsReversingRoadTrackdir(), IsStandardRoadStopTile(), RVSB_TRACKDIR_MASK, state, and Vehicle::vehstatus.

Referenced by NPFRoadVehicleFindNearestDepot(), CYapfFollowRoadT< Types >::SetOriginFromVehiclePos(), and YapfRoadVehicleFindNearestDepot().

FORCEINLINE bool RoadVehicle::HasArticulatedPart | ( |  | ) | const`[inline]`

Check if an engine has an articulated part.

Returns:
  True if the engine has an articulated part.

Definition at line 157 of file roadveh.h.

References IsArticulatedPart(), and SpecializedVehicle< RoadVehicle, VEH_ROAD >::Next().

Referenced by CheckConsistencyOfArticulatedVehicle(), CmdCloneVehicle(), DrawRoadVehDetails(), RoadStop::Enter(), IsArticulatedVehicleCarryingDifferentCargos(), and RoadFindPathToDest().

FORCEINLINE bool RoadVehicle::IsArticulatedPart | ( |  | ) | const`[inline]`

Check if vehicl is an articulated part of an engine.

Returns:
  Returns true if vehicle is an articulated part

Definition at line 146 of file roadveh.h.

References Vehicle::subtype.

Referenced by HasArticulatedPart().

bool RoadVehicle::IsBus | ( |  | ) | const

Check whether a roadvehicle is a bus.

Returns:
  true if bus

Definition at line 92 of file roadveh_cmd.cpp.

References Vehicle::cargo_type, CC_PASSENGERS, IsCargoInClass(), and IsRoadVehFront().

Referenced by CmdCloneOrder(), NetworkPopulateCompanyStats(), and RoadFindPathToDest().

bool RoadVehicle::IsInDepot | ( |  | ) | const`[inline, virtual]`

Check whether the vehicle is in the depot.

Returns:
  true if and only if the vehicle is in the depot.

Reimplemented from Vehicle.

Definition at line 120 of file roadveh.h.

References RVSB_IN_DEPOT, and state.

Referenced by CmdTurnRoadVeh(), and GetVehicleTrackdir().

FORCEINLINE bool RoadVehicle::IsRoadVehFront | ( |  | ) | const`[inline]`

Check if vehicle is a front engine.

Returns:
  Returns true if vehicle is a front engine

Definition at line 135 of file roadveh.h.

References Vehicle::subtype.

Referenced by AfterLoadVehicles(), Crash(), DisasterTick_Ufo(), IsBus(), Vehicle::IsEngineCountable(), IsPrimaryVehicle(), IsStoppedInDepot(), OnNewDay(), and Tick().

bool RoadVehicle::IsStoppedInDepot | ( |  | ) | const`[virtual]`

Check whether the vehicle is in the depot *and* stopped.

Returns:
  true if and only if the vehicle is in the depot and stopped.

Reimplemented from Vehicle.

Definition at line 308 of file roadveh_cmd.cpp.

References IsRoadVehFront(), SpecializedVehicle< T, Type >::Next(), RVSB_IN_DEPOT, state, Vehicle::tile, and Vehicle::vehstatus.

Referenced by CmdRefitRoadVeh(), and CmdSellRoadVeh().

void RoadVehicle::MarkDirty | ( |  | ) | `[virtual]`

Marks the vehicles to be redrawn and updates cached variables.

This method marks the area of the vehicle on the screen as dirty. It can be use to repaint the vehicle.

Reimplemented from Vehicle.

Definition at line 429 of file roadveh_cmd.cpp.

References SpecializedVehicle< T, Type >::Next(), and Vehicle::UpdateViewport().

bool RoadVehicle::Tick | ( |  | ) | `[virtual]`

Calls the tick handler of the vehicle.

Returns:
  is this vehicle still valid?

Reimplemented from Vehicle.

Definition at line 1608 of file roadveh_cmd.cpp.

References IsRoadVehFront(), Vehicle::running_ticks, and Vehicle::vehstatus.

void RoadVehicle::UpdateDeltaXY | ( | Direction | direction | ) | `[virtual]`

Updates the x and y offsets and the size of the sprite used for this vehicle.

Parameters:

  | direction | the direction the vehicle is facing

Reimplemented from Vehicle.

Definition at line 436 of file roadveh_cmd.cpp.

References GB().

## Field Documentation

byte RoadVehicle::state

See also:
  RoadVehicleStates

Definition at line 94 of file roadveh.h.

Referenced by CmdBuildRoadVeh(), CmdTurnRoadVeh(), Crash(), RoadStop::Enter(), FindVehiclesInRoadStop(), GetVehicleTrackdir(), IsInDepot(), IsStoppedInDepot(), RoadStop::Leave(), and Vehicle::PreDestructor().

The documentation for this struct was generated from the following files:

- src/roadveh.h
- src/roadveh_cmd.cpp