Public Member Functions | Data Fields | Protected Member Functions | Friends

# 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.
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, EngineImageType image_type) 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 | Tick ()
| Calls the tick handler of the vehicle.
void | OnNewDay ()
| Calls the new day handler of the vehicle.
uint | Crash (bool flooded=false)
| Common code executed for crashed ground vehicles.
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.
int | GetCurrentMaxSpeed () const
| Calculates the maximum speed of the vehicle under its current conditions.
int | UpdateSpeed ()
| This function looks at the vehicle and updates its speed (cur_speed and subspeed) variables.
## Data Fields
byte | state
byte | frame
uint16 | blocked_ctr
byte | overtaking
| Set to RVSB_DRIVE_SIDE when overtaking, otherwise 0.
byte | overtaking_ctr
| The length of the current overtake attempt.
uint16 | crashed_ctr
| Animation counter when the vehicle has crashed.
byte | reverse_ctr
RoadType | roadtype
RoadTypes | compatible_roadtypes
## Protected Member Functions
uint16 | GetPower () const
| Allows to know the power value that this vehicle will use.
uint16 | GetPoweredPartPower (const RoadVehicle *head) const
| Returns a value if this articulated part is powered.
uint16 | GetWeight () const
| Allows to know the weight value that this vehicle will use.
byte | GetTractiveEffort () const
| Allows to know the tractive effort value that this vehicle will use.
byte | GetAirDragArea () const
| Gets the area used for calculating air drag.
byte | GetAirDrag () const
| Gets the air drag coefficient of this vehicle.
AccelStatus | GetAccelerationStatus () const
| Checks the current acceleration status of this vehicle.
uint16 | GetCurrentSpeed () const
| Calculates the current speed of this vehicle.
uint32 | GetRollingFriction () const
| Returns the rolling friction coefficient of this vehicle.
int | GetAccelerationType () const
| Allows to know the acceleration type of a vehicle.
uint32 | GetSlopeSteepness () const
| Returns the slope steepness used by this vehicle.
uint16 | GetMaxTrackSpeed () const
| Gets the maximum speed allowed by the track for this vehicle.
bool | TileMayHaveSlopedTrack () const
| Checks if the vehicle is at a tile that can be sloped.
bool | HasToUseGetSlopePixelZ ()
| Road vehicles have to use GetSlopePixelZ() to compute their height if they are reversing because in that case, their direction is not parallel with the road.
## Friends
struct | GroundVehicle< RoadVehicle, VEH_ROAD >

## Detailed Description

Buses, trucks and trams belong to this class.

Definition at line 88 of file roadveh.h.

## Constructor & Destructor Documentation

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

We want to 'destruct' the right class.

Definition at line 103 of file roadveh.h.

References Vehicle::PreDestructor().

## Member Function Documentation

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

Common code executed for crashed ground vehicles.

Parameters:

  | flooded | was this vehicle flooded?

Returns:
  number of victims

Reimplemented from GroundVehicle< RoadVehicle, VEH_ROAD >.

Definition at line 524 of file roadveh_cmd.cpp.

References GroundVehicle< T, Type >::Crash(), crashed_ctr, RoadStop::GetByTile(), GetRoadStopType(), Vehicle::IsFrontEngine(), IsInsideMM(), 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 344 of file roadveh_cmd.cpp.

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

AccelStatus RoadVehicle::GetAccelerationStatus | ( |  | ) | const`[inline, protected]`

Checks the current acceleration status of this vehicle.

Returns:
  Acceleration status.

Definition at line 203 of file roadveh.h.

References AS_BRAKE, Vehicle::vehstatus, and VS_STOPPED.

Referenced by UpdateSpeed().

int RoadVehicle::GetAccelerationType | ( |  | ) | const`[inline, protected]`

Allows to know the acceleration type of a vehicle.

Returns:
  Zero, road vehicles always use a normal acceleration method.

Definition at line 235 of file roadveh.h.

byte RoadVehicle::GetAirDrag | ( |  | ) | const`[inline, protected]`

Gets the air drag coefficient of this vehicle.

Returns:
  Air drag value from the engine.

Definition at line 194 of file roadveh.h.

References Vehicle::engine_type.

byte RoadVehicle::GetAirDragArea | ( |  | ) | const`[inline, protected]`

Gets the area used for calculating air drag.

Returns:
  Area of the engine in m^2.

Definition at line 185 of file roadveh.h.

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

Calculates the maximum speed of the vehicle under its current conditions.

Returns:
  Maximum speed of the vehicle.

Reimplemented from Vehicle.

Definition at line 433 of file roadveh_cmd.cpp.

References _settings_game, VehicleCache::cached_max_speed, Vehicle::current_order, GetBridgeSpec(), GetBridgeType(), IsReversingRoadTrackdir(), Order::max_speed, min(), VehicleSettings::roadveh_acceleration_model, RVSB_TRACKDIR_MASK, RVSB_WORMHOLE, BridgeSpec::speed, state, Vehicle::vcache, GameSettings::vehicle, and VS_HIDDEN.

Referenced by UpdateSpeed().

uint16 RoadVehicle::GetCurrentSpeed | ( |  | ) | const`[inline, protected]`

Calculates the current speed of this vehicle.

Returns:
  Current speed in km/h-ish.

Definition at line 212 of file roadveh.h.

References Vehicle::cur_speed.

Referenced by GetRollingFriction().

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 96 of file roadveh_cmd.cpp.

References GroundVehicleCache::cached_veh_length, GroundVehicle< RoadVehicle, VEH_ROAD >::gcache, and VEHICLE_LENGTH.

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 113 of file roadveh.h.

References VehicleCache::cached_max_speed, and Vehicle::vcache.

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 112 of file roadveh.h.

References GroundVehicle< RoadVehicle, VEH_ROAD >::gcache, and GroundVehicleCache::last_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 109 of file roadveh.h.

References EXPENSES_ROADVEH_INC.

SpriteID RoadVehicle::GetImage | ( | Direction | direction,
|  | EngineImageType | image_type |
| ) |  |  | 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 122 of file roadveh_cmd.cpp.

References Vehicle::cargo, Vehicle::cargo_cap, CargoList< Tinst, Tcont >::Count(), Vehicle::GetEngine(), and Engine::original_image_index.

uint16 RoadVehicle::GetMaxTrackSpeed | ( |  | ) | const`[inline, protected]`

Gets the maximum speed allowed by the track for this vehicle.

Returns:
  Since roads don't limit road vehicle speed, it returns always zero.

Definition at line 253 of file roadveh.h.

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 576 of file roadveh_cmd.cpp.

References CanVehicleUseStation(), SpecializedVehicle< RoadVehicle, Type >::Get(), Vehicle::IncrementRealOrderIndex(), Vehicle::last_station_visited, and BaseStation::xy.

Referenced by RemoveRoadStop().

uint16 RoadVehicle::GetPower | ( |  | ) | const`[inline, protected]`

Allows to know the power value that this vehicle will use.

Returns:
  Power value from the engine in HP, or zero if the vehicle is not powered.

Definition at line 135 of file roadveh.h.

References Vehicle::engine_type, Vehicle::IsArticulatedPart(), and PROP_ROADVEH_POWER.

uint16 RoadVehicle::GetPoweredPartPower | ( | const RoadVehicle * | head | ) | const`[inline, protected]`

Returns a value if this articulated part is powered.

Returns:
  Zero, because road vehicles don't have powered parts.

Definition at line 149 of file roadveh.h.

uint32 RoadVehicle::GetRollingFriction | ( |  | ) | const`[inline, protected]`

Returns the rolling friction coefficient of this vehicle.

Returns:
  Rolling friction coefficient in [1e-4].

Definition at line 221 of file roadveh.h.

References GetCurrentSpeed().

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

Gets the running cost of a vehicle.

Returns:
  the vehicle's running cost

Reimplemented from Vehicle.

Definition at line 1569 of file roadveh_cmd.cpp.

References Vehicle::GetEngine(), Engine::GetGRF(), GetPrice(), and PROP_ROADVEH_RUNNING_COST_FACTOR.

Referenced by OnNewDay().

uint32 RoadVehicle::GetSlopeSteepness | ( |  | ) | const`[inline, protected]`

Returns the slope steepness used by this vehicle.

Returns:
  Slope steepness used by the vehicle.

Definition at line 244 of file roadveh.h.

References _settings_game, VehicleSettings::roadveh_slope_steepness, and GameSettings::vehicle.

byte RoadVehicle::GetTractiveEffort | ( |  | ) | const`[inline, protected]`

Allows to know the tractive effort value that this vehicle will use.

Returns:
  Tractive effort value from the engine.

Definition at line 175 of file roadveh.h.

References Vehicle::engine_type, and PROP_ROADVEH_TRACTIVE_EFFORT.

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 1659 of file roadveh_cmd.cpp.

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

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

uint16 RoadVehicle::GetWeight | ( |  | ) | const`[inline, protected]`

Allows to know the weight value that this vehicle will use.

Returns:
  Weight value from the engine in tonnes.

Definition at line 158 of file roadveh.h.

References Vehicle::cargo, Vehicle::cargo_type, CargoList< Tinst, Tcont >::Count(), Vehicle::engine_type, SpecializedVehicle< RoadVehicle, Type >::Get(), Vehicle::IsArticulatedPart(), and PROP_ROADVEH_WEIGHT.

bool RoadVehicle::HasToUseGetSlopePixelZ | ( |  | ) | `[inline, protected]`

Road vehicles have to use GetSlopePixelZ() to compute their height if they are reversing because in that case, their direction is not parallel with the road.

It is safe to return `true` even if it is not reversing.

Returns:
  are we (possibly) reversing?

Definition at line 277 of file roadveh.h.

References Vehicle::direction, SpecializedVehicle< RoadVehicle, Type >::First(), IsReversingRoadTrackdir(), SpecializedVehicle< T, Type >::Next(), RVSB_TRACKDIR_MASK, and state.

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

Check whether a roadvehicle is a bus.

Returns:
  true if bus

Definition at line 85 of file roadveh_cmd.cpp.

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

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

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 116 of file roadveh.h.

References state.

Referenced by CmdTurnRoadVeh(), and GetVehicleTrackdir().

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 394 of file roadveh_cmd.cpp.

References GroundVehicle< RoadVehicle, VEH_ROAD >::CargoChanged(), SpecializedVehicle< T, Type >::Next(), and SpecializedVehicle< T, Type >::UpdateViewport().

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

Calls the tick handler of the vehicle.

Returns:
  is this vehicle still valid?

Reimplemented from Vehicle.

Definition at line 1580 of file roadveh_cmd.cpp.

References Vehicle::IsFrontEngine(), Vehicle::running_ticks, Vehicle::vehstatus, and VS_STOPPED.

bool RoadVehicle::TileMayHaveSlopedTrack | ( |  | ) | const`[inline, protected]`

Checks if the vehicle is at a tile that can be sloped.

Returns:
  True if the tile can be sloped.

Definition at line 262 of file roadveh.h.

References GetTileTrackStatus(), Vehicle::tile, TRACK_BIT_X, TrackStatusToTrackBits(), and TRANSPORT_ROAD.

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 402 of file roadveh_cmd.cpp.

References GroundVehicleCache::cached_veh_length, GroundVehicle< RoadVehicle, VEH_ROAD >::gcache, IsDiagonalDirection(), VEHICLE_LENGTH, Vehicle::x_bb_offs, Vehicle::x_extent, Vehicle::x_offs, Vehicle::y_bb_offs, Vehicle::y_extent, Vehicle::y_offs, and Vehicle::z_extent.

int RoadVehicle::UpdateSpeed | ( |  | ) |

This function looks at the vehicle and updates its speed (cur_speed and subspeed) variables.

Furthermore, it returns the distance that the vehicle can drive this tick. Vehicle::GetAdvanceDistance() determines the distance to drive before moving a step on the map.

Returns:
  distance to drive.

Definition at line 719 of file roadveh_cmd.cpp.

References _settings_game, AS_BRAKE, GroundVehicle< RoadVehicle, VEH_ROAD >::DoUpdateSpeed(), GroundVehicle< RoadVehicle, VEH_ROAD >::GetAcceleration(), GetAccelerationStatus(), GetCurrentMaxSpeed(), overtaking, VehicleSettings::roadveh_acceleration_model, and GameSettings::vehicle.

## Field Documentation

uint16 RoadVehicle::crashed_ctr

Animation counter when the vehicle has crashed.

See also:
  RoadVehIsCrashed

Definition at line 94 of file roadveh.h.

Referenced by Crash(), DisasterTick_Ufo(), and RoadVehIsCrashed().

byte RoadVehicle::state

See also:
  RoadVehicleStates

Definition at line 89 of file roadveh.h.

Referenced by AddArticulatedParts(), AfterLoadGame(), CmdBuildRoadVehicle(), CmdTurnRoadVeh(), Crash(), DeleteLastRoadVeh(), RoadStop::Enter(), FindVehiclesInRoadStop(), FixOldVehicles(), GetCurrentMaxSpeed(), GetVehicleTrackdir(), HasToUseGetSlopePixelZ(), IsInDepot(), RoadStop::Leave(), and Vehicle::PreDestructor().

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

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