Base class for all vehicles that move through ground. More...
#include <ground_vehicle.hpp>
Public Types | |
enum | GroundVehicleSubtypeFlags { 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... | |
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. | |
uint | Crash (bool flooded) |
Common code executed for crashed ground vehicles. | |
FORCEINLINE int32 | GetSlopeResistance () const |
Calculates the total slope resistance for this vehicle. | |
FORCEINLINE void | UpdateZPositionAndInclination () |
Updates vehicle's Z position and inclination. | |
FORCEINLINE void | UpdateZPosition () |
Updates vehicle's Z position. | |
FORCEINLINE byte | UpdateInclination (bool new_tile, bool turned) |
Checks if the vehicle is in a slope and sets the required flags in that case. | |
FORCEINLINE void | SetFrontEngine () |
Set front engine state. | |
FORCEINLINE void | ClearFrontEngine () |
Remove the front engine state. | |
FORCEINLINE void | SetArticulatedPart () |
Set a vehicle to be an articulated part. | |
FORCEINLINE void | ClearArticulatedPart () |
Clear a vehicle from being an articulated part. | |
FORCEINLINE void | SetWagon () |
Set a vehicle to be a wagon. | |
FORCEINLINE void | ClearWagon () |
Clear wagon property. | |
FORCEINLINE void | SetEngine () |
Set engine status. | |
FORCEINLINE void | ClearEngine () |
Clear engine status. | |
FORCEINLINE void | SetFreeWagon () |
Set a vehicle as a free wagon. | |
FORCEINLINE void | ClearFreeWagon () |
Clear a vehicle from being a free wagon. | |
FORCEINLINE void | SetMultiheaded () |
Set a vehicle as a multiheaded engine. | |
FORCEINLINE void | ClearMultiheaded () |
Clear multiheaded engine property. | |
FORCEINLINE bool | IsFrontEngine () const |
Check if the vehicle is a front engine. | |
FORCEINLINE bool | IsFreeWagon () const |
Check if the vehicle is a free wagon (got no engine in front of it). | |
FORCEINLINE bool | IsEngine () const |
Check if a vehicle is an engine (can be first in a consist). | |
FORCEINLINE bool | IsWagon () const |
Check if a vehicle is a wagon. | |
FORCEINLINE bool | IsMultiheaded () const |
Check if the vehicle is a multiheaded engine. | |
FORCEINLINE bool | IsRearDualheaded () const |
Tell if we are dealing with the rear end of a multiheaded engine. | |
FORCEINLINE bool | IsArticulatedPart () const |
Check if the vehicle is an articulated part of an engine. | |
FORCEINLINE bool | HasArticulatedPart () const |
Check if an engine has an articulated part. | |
Data Fields | |
GroundVehicleCache | gcache |
Cache of often calculated values. | |
uint16 | gv_flags |
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 74 of file ground_vehicle.hpp.
enum GroundVehicle::GroundVehicleSubtypeFlags |
Enum to handle ground vehicle subtypes.
Do not access it directly unless you have to. Use the subtype access functions.
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 244 of file ground_vehicle.hpp.
void GroundVehicle< T, Type >::CargoChanged | ( | ) | [inline] |
Recalculates the cached weight of a vehicle and its parts.
Should be called each time the cargo on the consist changes.
Definition at line 80 of file ground_vehicle.cpp.
References GroundVehicleCache::cached_axle_resistance, GroundVehicleCache::cached_weight, SpecializedVehicle< T, Type >::First(), GroundVehicle< T, Type >::gcache, and GroundVehicle< T, Type >::PowerChanged().
Referenced by AfterLoadVehicles(), CmdBuildRoadVehicle(), CmdRefitVehicle(), RoadVehAccelerationModelChanged(), RoadVehSlopeSteepnessChanged(), and TrainSlopeSteepnessChanged().
uint GroundVehicle< T, Type >::Crash | ( | bool | flooded | ) | [inline, virtual] |
Common code executed for crashed ground vehicles.
flooded | was this vehicle flooded? |
Reimplemented from Vehicle.
Reimplemented in RoadVehicle, and Train.
Definition at line 94 of file ground_vehicle.hpp.
Referenced by Train::Crash(), RoadVehicle::Crash(), and GroundVehicle< RoadVehicle, VEH_ROAD >::Crash().
int GroundVehicle< T, Type >::GetAcceleration | ( | ) | const [inline] |
Calculates the acceleration of the vehicle under its current conditions.
Definition at line 106 of file ground_vehicle.cpp.
References AS_ACCEL, GroundVehicleCache::cached_air_drag, GroundVehicleCache::cached_axle_resistance, GroundVehicleCache::cached_max_te, GroundVehicleCache::cached_power, GroundVehicleCache::cached_weight, SpecializedVehicle< T, Type >::From(), GroundVehicle< T, Type >::gcache, GroundVehicle< T, Type >::GetSlopeResistance(), max(), and min().
Referenced by RoadVehAccelerate().
FORCEINLINE int32 GroundVehicle< T, Type >::GetSlopeResistance | ( | ) | const [inline] |
Calculates the total slope resistance for this vehicle.
Definition at line 108 of file ground_vehicle.hpp.
Referenced by GroundVehicle< T, Type >::GetAcceleration().
FORCEINLINE bool GroundVehicle< T, Type >::HasArticulatedPart | ( | ) | const [inline] |
Check if an engine has an articulated part.
Definition at line 359 of file ground_vehicle.hpp.
Referenced by CheckConsistencyOfArticulatedVehicle(), CmdCloneVehicle(), DrawRoadVehDetails(), VehicleDetailsWindow::DrawWidget(), RoadStop::Enter(), Train::GetLastEnginePart(), Train::GetNextVehicle(), IsArticulatedVehicleCarryingDifferentCargos(), DepotWindow::OnRightClick(), and RoadFindPathToDest().
FORCEINLINE bool GroundVehicle< T, Type >::IsArticulatedPart | ( | ) | const [inline] |
Check if the vehicle is an articulated part of an engine.
Definition at line 353 of file ground_vehicle.hpp.
Referenced by BuildDepotVehicleList(), CheckTrainAttachment(), CmdAutoreplaceVehicle(), DrawTrainDetails(), GetCargoSummaryOfArticulatedVehicle(), Train::GetFirstEnginePart(), GetLengthOfArticulatedVehicle(), GetNewEngineType(), Train::GetPrevVehicle(), GetVehicleSet(), InsertInConsist(), Vehicle::IsEngineCountable(), ReplaceFreeUnit(), and TransferCargo().
FORCEINLINE bool GroundVehicle< T, Type >::IsEngine | ( | ) | const [inline] |
Check if a vehicle is an engine (can be first in a consist).
Definition at line 329 of file ground_vehicle.hpp.
Referenced by AfterLoadVehicles(), CheckNewTrain(), CheckTrainAttachment(), CmdMoveRailVehicle(), CmdSellRailWagon(), GroundVehicle< RoadVehicle, VEH_ROAD >::IsRearDualheaded(), NormaliseDualHeads(), and NormaliseSubtypes().
FORCEINLINE bool GroundVehicle< T, Type >::IsFreeWagon | ( | ) | const [inline] |
Check if the vehicle is a free wagon (got no engine in front of it).
Definition at line 323 of file ground_vehicle.hpp.
Referenced by AfterLoadVehicles(), BuildDepotVehicleList(), CmdBuildRailWagon(), DepotWindow::DrawVehicleInDepot(), NormalizeTrainVehInDepot(), and UpdateTrainGroupID().
FORCEINLINE bool GroundVehicle< T, Type >::IsFrontEngine | ( | ) | const [inline] |
Check if the vehicle is a front engine.
Definition at line 317 of file ground_vehicle.hpp.
Referenced by AfterLoadVehicles(), CmdAutoreplaceVehicle(), CmdCloneVehicle(), CmdMoveRailVehicle(), CmdSellRailWagon(), DisasterTick_Ufo(), FreeTrainTrackReservation(), Vehicle::IsEngineCountable(), NormaliseTrainHead(), DepotWindow::OnDragDrop(), RoadVehAccelerationModelChanged(), RoadVehSlopeSteepnessChanged(), SettingsDisableElrail(), SetTrainGroupID(), Vehicle::ShowVisualEffect(), TrainApproachingCrossingEnum(), TrainApproachingCrossingTile(), TrainSlopeSteepnessChanged(), TryPathReserve(), UpdateTrainGroupID(), and WhoCanServiceIndustry().
FORCEINLINE bool GroundVehicle< T, Type >::IsMultiheaded | ( | ) | const [inline] |
Check if the vehicle is a multiheaded engine.
Definition at line 341 of file ground_vehicle.hpp.
Referenced by ArrangeTrains(), CmdReverseTrainDirection(), Train::GetRunningCost(), GroundVehicle< RoadVehicle, VEH_ROAD >::IsRearDualheaded(), and NormaliseDualHeads().
FORCEINLINE bool GroundVehicle< T, Type >::IsRearDualheaded | ( | ) | const [inline] |
Tell if we are dealing with the rear end of a multiheaded engine.
Definition at line 347 of file ground_vehicle.hpp.
Referenced by BuildDepotVehicleList(), CheckTrainAttachment(), CmdAutoreplaceVehicle(), CmdCloneVehicle(), CmdMoveRailVehicle(), CmdSellRailWagon(), GetNewEngineType(), Train::GetNextUnit(), Train::GetPrevUnit(), Vehicle::IsEngineCountable(), and ReplaceFreeUnit().
FORCEINLINE bool GroundVehicle< T, Type >::IsWagon | ( | ) | const [inline] |
Check if a vehicle is a wagon.
Definition at line 335 of file ground_vehicle.hpp.
Referenced by NormaliseSubtypes().
void GroundVehicle< T, Type >::PowerChanged | ( | ) | [inline] |
Recalculates the cached total power of a vehicle.
Should be called when the consist is changed.
Definition at line 22 of file ground_vehicle.cpp.
References GroundVehicleCache::cached_air_drag, GroundVehicleCache::cached_max_te, GroundVehicleCache::cached_max_track_speed, GroundVehicleCache::cached_power, SpecializedVehicle< T, Type >::First(), SpecializedVehicle< T, Type >::From(), GroundVehicle< T, Type >::gcache, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::index, max(), min(), SetWindowDirty(), SetWindowWidgetDirty(), Vehicle::vehstatus, and VS_STOPPED.
Referenced by GroundVehicle< T, Type >::CargoChanged().
FORCEINLINE byte GroundVehicle< T, Type >::UpdateInclination | ( | bool | new_tile, | |
bool | turned | |||
) | [inline] |
Checks if the vehicle is in a slope and sets the required flags in that case.
new_tile | True if the vehicle reached a new tile. | |
turned | Indicates if the vehicle has turned. |
Definition at line 226 of file ground_vehicle.hpp.
Referenced by UpdateStatusAfterSwap().
FORCEINLINE 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 154 of file ground_vehicle.hpp.
Referenced by GroundVehicle< RoadVehicle, VEH_ROAD >::UpdateInclination().
FORCEINLINE void GroundVehicle< T, Type >::UpdateZPositionAndInclination | ( | ) | [inline] |
Updates vehicle's Z position and inclination.
Used when the vehicle entered given tile.
Definition at line 129 of file ground_vehicle.hpp.
Referenced by GroundVehicle< RoadVehicle, VEH_ROAD >::UpdateInclination().
uint16 GroundVehicle< T, Type >::gv_flags |
Definition at line 76 of file ground_vehicle.hpp.
Referenced by GroundVehicle< RoadVehicle, VEH_ROAD >::UpdateZPosition(), and GroundVehicle< RoadVehicle, VEH_ROAD >::UpdateZPositionAndInclination().