Public Types | Public Member Functions | Data Fields | Protected Member Functions

GroundVehicle< T, Type > Struct Template Reference

Base class for all vehicles that move through ground. More...

#include <ground_vehicle.hpp>

Inheritance diagram for GroundVehicle< T, Type >:
SpecializedVehicle< T, Type > Vehicle Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool > BaseVehicle BaseConsist

Public Types

typedef GroundVehicle< T, Type > GroundVehicleBase
 Our type.

Public Member Functions

 GroundVehicle ()
 The constructor at SpecializedVehicle must be called.
void PowerChanged ()
 Recalculates the cached total power of a vehicle.
void CargoChanged ()
 Recalculates the cached weight of a vehicle and its parts.
int GetAcceleration () const
 Calculates the acceleration of the vehicle under its current conditions.
bool IsChainInDepot () const
 Check whether the whole vehicle chain is in the depot.
uint Crash (bool flooded)
 Common code executed for crashed ground vehicles.
int32 GetSlopeResistance () const
 Calculates the total slope resistance for this vehicle.
void UpdateZPositionAndInclination ()
 Updates vehicle's Z position and inclination.
void UpdateZPosition ()
 Updates vehicle's Z position.
byte UpdateInclination (bool new_tile, bool update_delta)
 Checks if the vehicle is in a slope and sets the required flags in that case.
void SetFrontEngine ()
 Set front engine state.
void ClearFrontEngine ()
 Remove the front engine state.
void SetArticulatedPart ()
 Set a vehicle to be an articulated part.
void ClearArticulatedPart ()
 Clear a vehicle from being an articulated part.
void SetWagon ()
 Set a vehicle to be a wagon.
void ClearWagon ()
 Clear wagon property.
void SetEngine ()
 Set engine status.
void ClearEngine ()
 Clear engine status.
void SetFreeWagon ()
 Set a vehicle as a free wagon.
void ClearFreeWagon ()
 Clear a vehicle from being a free wagon.
void SetMultiheaded ()
 Set a vehicle as a multiheaded engine.
void ClearMultiheaded ()
 Clear multiheaded engine property.
bool IsFreeWagon () const
 Check if the vehicle is a free wagon (got no engine in front of it).
bool IsEngine () const
 Check if a vehicle is an engine (can be first in a consist).
bool IsWagon () const
 Check if a vehicle is a wagon.
bool IsMultiheaded () const
 Check if the vehicle is a multiheaded engine.
bool IsRearDualheaded () const
 Tell if we are dealing with the rear end of a multiheaded engine.
void SetLastSpeed ()
 Update the GUI variant of the current speed of the vehicle.

Data Fields

GroundVehicleCache gcache
 Cache of often calculated values.
uint16 gv_flags

Protected Member Functions

uint DoUpdateSpeed (uint accel, int min_speed, int max_speed)
 Update the speed of the vehicle.

Detailed Description

template<class T, VehicleType Type>
struct GroundVehicle< T, Type >

Base class for all vehicles that move through ground.

Child classes must define all of the following functions. These functions are not defined as pure virtual functions at this class to improve performance.

virtual uint16 GetPower() const = 0; virtual uint16 GetPoweredPartPower(const T *head) const = 0; virtual uint16 GetWeight() const = 0; virtual byte GetTractiveEffort() const = 0; virtual byte GetAirDrag() const = 0; virtual byte GetAirDragArea() const = 0; virtual AccelStatus GetAccelerationStatus() const = 0; virtual uint16 GetCurrentSpeed() const = 0; virtual uint32 GetRollingFriction() const = 0; virtual int GetAccelerationType() const = 0; virtual int32 GetSlopeSteepness() const = 0; virtual int GetDisplayMaxSpeed() const = 0; virtual uint16 GetMaxTrackSpeed() const = 0; virtual bool TileMayHaveSlopedTrack() const = 0;

Definition at line 81 of file ground_vehicle.hpp.


Member Function Documentation

template<class T , VehicleType Type>
void GroundVehicle< T, Type >::CargoChanged (  ) 
template<class T, VehicleType Type>
uint GroundVehicle< T, Type >::Crash ( bool  flooded  )  [inline, virtual]

Common code executed for crashed ground vehicles.

Parameters:
flooded was this vehicle flooded?
Returns:
number of victims

Reimplemented from Vehicle.

Reimplemented in RoadVehicle, and Train.

Definition at line 102 of file ground_vehicle.hpp.

Referenced by Train::Crash(), RoadVehicle::Crash(), and GroundVehicle< RoadVehicle, VEH_ROAD >::Crash().

template<class T, VehicleType Type>
uint GroundVehicle< T, Type >::DoUpdateSpeed ( uint  accel,
int  min_speed,
int  max_speed 
) [inline, protected]

Update the speed of the vehicle.

It updates the cur_speed and subspeed variables depending on the state of the vehicle; in this case the current acceleration, minimum and maximum speeds of the vehicle. It returns the distance that that the vehicle can drive this tick. Vehicle::GetAdvanceDistance() determines the distance to drive before moving a step on the map.

Parameters:
accel The acceleration we would like to give this vehicle.
min_speed The minimum speed here, in vehicle specific units.
max_speed The maximum speed here, in vehicle specific units.
Returns:
Distance to drive.

Definition at line 365 of file ground_vehicle.hpp.

template<class T , VehicleType Type>
int GroundVehicle< T, Type >::GetAcceleration (  )  const
template<class T, VehicleType Type>
int32 GroundVehicle< T, Type >::GetSlopeResistance (  )  const [inline]

Calculates the total slope resistance for this vehicle.

Returns:
Slope resistance.

Definition at line 116 of file ground_vehicle.hpp.

Referenced by GroundVehicle< T, Type >::GetAcceleration().

template<class T , VehicleType Type>
bool GroundVehicle< T, Type >::IsChainInDepot (  )  const [virtual]

Check whether the whole vehicle chain is in the depot.

Returns:
true if and only if the whole chain is in the depot.

Reimplemented from Vehicle.

Definition at line 173 of file ground_vehicle.cpp.

References SpecializedVehicle< T, Type >::First(), IsDepotTypeTile(), Vehicle::tile, TRANSPORT_RAIL, TRANSPORT_ROAD, VEH_ROAD, and VEH_TRAIN.

Referenced by CheckIfTrainNeedsService(), and CmdForceTrainProceed().

template<class T, VehicleType Type>
bool GroundVehicle< T, Type >::IsEngine (  )  const [inline]

Check if a vehicle is an engine (can be first in a consist).

Returns:
Returns true if vehicle is an engine.

Definition at line 318 of file ground_vehicle.hpp.

Referenced by AfterLoadVehicles(), AgeVehicle(), CheckNewTrain(), CheckTrainAttachment(), CmdMoveRailVehicle(), CmdSellRailWagon(), ConnectMultiheadedTrains(), GroundVehicle< RoadVehicle, VEH_ROAD >::IsRearDualheaded(), NormaliseDualHeads(), and NormaliseSubtypes().

template<class T, VehicleType Type>
bool GroundVehicle< T, Type >::IsFreeWagon (  )  const [inline]

Check if the vehicle is a free wagon (got no engine in front of it).

Returns:
Returns true if the vehicle is a free wagon.

Definition at line 312 of file ground_vehicle.hpp.

Referenced by AfterLoadGame(), AfterLoadVehicles(), BuildDepotVehicleList(), CmdBuildRailWagon(), ConnectMultiheadedTrains(), DepotWindow::DrawVehicleInDepot(), NormalizeTrainVehInDepot(), and UpdateTrainGroupID().

template<class T, VehicleType Type>
bool GroundVehicle< T, Type >::IsMultiheaded (  )  const [inline]

Check if the vehicle is a multiheaded engine.

Returns:
Returns true if the vehicle is a multiheaded engine.

Definition at line 330 of file ground_vehicle.hpp.

Referenced by ArrangeTrains(), CmdReverseTrainDirection(), ConnectMultiheadedTrains(), Train::GetRunningCost(), GetVehicleSet(), GroundVehicle< RoadVehicle, VEH_ROAD >::IsRearDualheaded(), and NormaliseDualHeads().

template<class T, VehicleType Type>
bool GroundVehicle< T, Type >::IsRearDualheaded (  )  const [inline]

Tell if we are dealing with the rear end of a multiheaded engine.

Returns:
True if the engine is the rear part of a dualheaded engine.

Definition at line 336 of file ground_vehicle.hpp.

Referenced by BuildDepotVehicleList(), CheckTrainAttachment(), CmdAutoreplaceVehicle(), CmdCloneVehicle(), CmdMoveRailVehicle(), CmdSellRailWagon(), GetNewEngineType(), Train::GetNextUnit(), Train::GetPrevUnit(), Vehicle::IsEngineCountable(), and ReplaceFreeUnit().

template<class T, VehicleType Type>
bool GroundVehicle< T, Type >::IsWagon (  )  const [inline]

Check if a vehicle is a wagon.

Returns:
Returns true if vehicle is a wagon.

Definition at line 324 of file ground_vehicle.hpp.

Referenced by NormaliseSubtypes().

template<class T, VehicleType Type>
void GroundVehicle< T, Type >::SetLastSpeed (  )  [inline]

Update the GUI variant of the current speed of the vehicle.

Also mark the widget dirty when that is needed, i.e. when the speed of this vehicle has changed.

Definition at line 343 of file ground_vehicle.hpp.

Referenced by CmdReverseTrainDirection(), and MarkTrainAsStuck().

template<class T, VehicleType Type>
byte GroundVehicle< T, Type >::UpdateInclination ( bool  new_tile,
bool  update_delta 
) [inline]

Checks if the vehicle is in a slope and sets the required flags in that case.

Parameters:
new_tile True if the vehicle reached a new tile.
update_delta Indicates to also update the delta.
Returns:
Old height of the vehicle.

Definition at line 234 of file ground_vehicle.hpp.

Referenced by ChangeTrainDirRandomly(), and UpdateStatusAfterSwap().

template<class T, VehicleType Type>
void GroundVehicle< T, Type >::UpdateZPosition (  )  [inline]

Updates vehicle's Z position.

Inclination can't change in the middle of a tile. The faster code is used for trains and road vehicles unless they are reversing on a sloped tile.

Definition at line 162 of file ground_vehicle.hpp.

Referenced by GroundVehicle< RoadVehicle, VEH_ROAD >::UpdateInclination().

template<class T, VehicleType Type>
void GroundVehicle< T, Type >::UpdateZPositionAndInclination (  )  [inline]

Updates vehicle's Z position and inclination.

Used when the vehicle entered given tile.

Precondition:
The vehicle has to be at (or near to) a border of the tile, directed towards tile centre

Definition at line 137 of file ground_vehicle.hpp.

Referenced by GroundVehicle< RoadVehicle, VEH_ROAD >::UpdateInclination().


Field Documentation


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