OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
10 #ifndef GROUND_VEHICLE_HPP
11 #define GROUND_VEHICLE_HPP
81 template <
class T, VehicleType Type>
106 for (T *v = T::From(
this); v !=
nullptr; v = v->Next()) {
121 for (
const T *u = T::From(
this); u !=
nullptr; u = u->Next()) {
123 incl += u->gcache.cached_slope_resistance;
125 incl -= u->gcache.cached_slope_resistance;
144 if (T::From(
this)->TileMayHaveSlopedTrack()) {
151 if (middle_z != this->
z_pos) {
204 if (T::From(
this)->HasToUseGetSlopePixelZ()) {
236 int old_z = this->
z_pos;
372 int tempmax = max_speed;
382 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...
@ DIAGDIR_NE
Northeast, upper right on your monitor.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
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.
int64_t GetSlopeResistance() const
Calculates the total slope resistance for this vehicle.
uint32_t cached_weight
Total weight of the consist (valid only for the first engine).
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.
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
GroundVehicle< T, Type > GroundVehicleBase
Our type.
static const uint TILE_SIZE
Tile size in world coordinates.
DiagDirection
Enumeration for diagonal directions.
@ 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.
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
void UpdateZPositionAndInclination()
Updates vehicle's Z position and inclination.
void SetWagon()
Set a vehicle to be a wagon.
uint16_t last_speed
The last speed we did display, so we only have to redraw when this changes.
void ClearEngine()
Clear engine status.
uint8_t subspeed
fractional speed
int32_t x_pos
x coordinate.
@ GVF_GOINGDOWN_BIT
Vehicle is currently going downhill. (Cached track information for acceleration)
uint32_t cached_air_drag
Air drag coefficient of the vehicle (valid only for the first engine).
static const uint TILE_UNIT_MASK
For masking in/out the inner-tile world coordinate units.
Cached, frequently calculated values.
GroundVehicleFlags
Ground vehicle flags.
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
void SetMultiheaded()
Set a vehicle as a multiheaded engine.
uint16_t cached_max_track_speed
Maximum consist speed (in internal units) limited by track type (valid only for the first engine).
@ GVF_GOINGUP_BIT
Vehicle is currently going uphill. (Cached track information for acceleration)
Class defining several overloaded accessors so we don't have to cast vehicle types that often.
@ GVSF_ARTICULATED_PART
Articulated part of an 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.
uint16_t cur_speed
current speed
void SetLastSpeed()
Update the GUI variant of the current speed of the vehicle.
uint32_t cached_slope_resistance
Resistance caused by weight when this vehicle part is at a slope.
DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
@ GVSF_WAGON
Wagon (not used for road vehicles).
uint8_t progress
The percentage (if divided by 256) this vehicle already crossed the tile unit.
int32_t z_pos
z coordinate.
Direction direction
facing
uint16_t cached_axle_resistance
Resistance caused by the axles of the vehicle (valid only for the first engine).
uint8_t subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
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).
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.
int32_t y_pos
y coordinate.
uint32_t cached_power
Total power of the consist (valid only for the first engine).
@ GVSF_FRONT
Leading engine of a consist.
void CargoChanged()
Recalculates the cached weight of a vehicle and its parts.
bool IsWagon() const
Check if a vehicle is a wagon.
uint16_t EngineID
Unique identification number of an engine.
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.
uint8_t cached_veh_length
Length of this vehicle in units of 1/VEHICLE_LENGTH of normal length. It is cached because this can b...
uint DoUpdateSpeed(uint accel, int min_speed, int max_speed)
Update the speed of the vehicle.
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, WidgetID widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
uint16_t cached_total_length
Length of the whole vehicle (valid only for the first engine).
void UpdateViewport(bool force_update, bool update_delta)
Update vehicle sprite- and position caches.
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.
uint32_t cached_max_te
Maximum tractive effort of consist (valid only for the first engine).
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.