OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
10 #ifndef GROUND_VEHICLE_HPP
11 #define GROUND_VEHICLE_HPP
78 template <
class T, VehicleType Type>
103 for (T *v = T::From(
this); v !=
nullptr; v = v->Next()) {
118 for (
const T *u = T::From(
this); u !=
nullptr; u = u->Next()) {
120 incl += u->gcache.cached_slope_resistance;
122 incl -= u->gcache.cached_slope_resistance;
141 if (T::From(
this)->TileMayHaveSlopedTrack()) {
148 if (middle_z != this->
z_pos) {
201 if (T::From(
this)->HasToUseGetSlopePixelZ()) {
234 int old_z = this->
z_pos;
370 int tempmax = max_speed;
380 this->
cur_speed = spd = std::max(std::min(this->
cur_speed + ((
int)spd >> 8), tempmax), min_speed);
@ GVSF_ENGINE
Engine that can be front engine, but might be placed behind another engine (not used for road vehicle...
uint32 cached_air_drag
Air drag coefficient of the vehicle (valid only for the first engine).
GroundVehicle()
The constructor at SpecializedVehicle must be called.
int GetAcceleration() const
Calculates the acceleration of the vehicle under its current conditions.
@ GVF_SUPPRESS_IMPLICIT_ORDERS
Disable insertion and removal of automatic orders until the vehicle completes the real order.
EngineID first_engine
Cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
void ClearFreeWagon()
Clear a vehicle from being a free wagon.
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
void ClearFrontEngine()
Remove the front engine state.
Tindex index
Index of this pool item.
virtual uint Crash(bool flooded=false)
Crash the (whole) vehicle chain.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
GroundVehicle< T, Type > GroundVehicleBase
Our type.
static const uint TILE_SIZE
Tile size in world coordinates.
uint16 last_speed
The last speed we did display, so we only have to redraw when this changes.
@ AS_ACCEL
We want to go faster, if possible of course.
bool IsRearDualheaded() const
Tell if we are dealing with the rear end of a multiheaded engine.
uint16 cur_speed
current speed
void UpdateZPositionAndInclination()
Updates vehicle's Z position and inclination.
void SetWagon()
Set a vehicle to be a wagon.
void ClearEngine()
Clear engine status.
@ GVF_GOINGDOWN_BIT
Vehicle is currently going downhill. (Cached track information for acceleration)
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, byte widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
uint16 EngineID
Unique identification number of an engine.
static const uint TILE_UNIT_MASK
For masking in/out the inner-tile world coordinate units.
uint16 cached_total_length
Length of the whole vehicle (valid only for the first engine).
static DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
Cached, frequently calculated values.
GroundVehicleFlags
Ground vehicle flags.
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
int64 GetSlopeResistance() const
Calculates the total slope resistance for this vehicle.
void SetMultiheaded()
Set a vehicle as a multiheaded engine.
uint16 cached_axle_resistance
Resistance caused by the axles of the vehicle (valid only for the first engine).
@ GVF_GOINGUP_BIT
Vehicle is currently going uphill. (Cached track information for acceleration)
uint8 cached_veh_length
Length of this vehicle in units of 1/VEHICLE_LENGTH of normal length. It is cached because this can b...
Class defining several overloaded accessors so we don't have to cast vehicle types that often.
@ GVSF_ARTICULATED_PART
Articulated part of an engine.
uint16 cached_max_track_speed
Maximum consist speed (in internal units) limited by track type (valid only for the first engine).
bool IsChainInDepot() const override
Check whether the whole vehicle chain is in the depot.
GroundVehicleCache gcache
Cache of often calculated values.
void SetFrontEngine()
Set front engine state.
uint32 cached_slope_resistance
Resistance caused by weight when this vehicle part is at a slope.
void SetLastSpeed()
Update the GUI variant of the current speed of the vehicle.
uint32 cached_max_te
Maximum tractive effort of consist (valid only for the first engine).
@ GVSF_WAGON
Wagon (not used for road vehicles).
DiagDirection
Enumeration for diagonal directions.
Direction direction
facing
int UpdateInclination(bool new_tile, bool update_delta)
Checks if the vehicle is in a slope and sets the required flags in that case.
@ GVSF_FREE_WAGON
First in a wagon chain (in depot) (not used for road vehicles).
uint32 cached_power
Total power of the consist (valid only for the first engine).
byte subspeed
fractional speed
static uint GetAdvanceSpeed(uint speed)
Determines the effective vehicle movement speed.
void ClearMultiheaded()
Clear multiheaded engine property.
void SetArticulatedPart()
Set a vehicle to be an articulated part.
void SetEngine()
Set engine status.
void PowerChanged()
Recalculates the cached total power of a vehicle.
bool IsEngine() const
Check if a vehicle is an engine (can be first in a consist).
void SetFreeWagon()
Set a vehicle as a free wagon.
Base class for all vehicles that move through ground.
@ GVSF_MULTIHEADED
Engine is multiheaded (not used for road vehicles).
void ClearWagon()
Clear wagon property.
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
@ GVSF_FRONT
Leading engine of a consist.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
byte progress
The percentage (if divided by 256) this vehicle already crossed the tile unit.
void CargoChanged()
Recalculates the cached weight of a vehicle and its parts.
bool IsWagon() const
Check if a vehicle is a wagon.
bool IsFreeWagon() const
Check if the vehicle is a free wagon (got no engine in front of it).
@ AS_BRAKE
We want to stop.
void UpdateZPosition()
Updates vehicle's Z position.
uint Crash(bool flooded) override
Common code executed for crashed ground vehicles.
uint DoUpdateSpeed(uint accel, int min_speed, int max_speed)
Update the speed of the vehicle.
void UpdateViewport(bool force_update, bool update_delta)
Update vehicle sprite- and position caches.
uint32 cached_weight
Total weight of the consist (valid only for the first engine).
AccelStatus
What is the status of our acceleration?
void ClearArticulatedPart()
Clear a vehicle from being an articulated part.
bool IsMultiheaded() const
Check if the vehicle is a multiheaded engine.