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);
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
DiagDirection
Enumeration for diagonal directions.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
uint16_t EngineID
Unique identification number of an engine.
AccelStatus
What is the status of our acceleration?
@ AS_BRAKE
We want to stop.
@ AS_ACCEL
We want to go faster, if possible of course.
GroundVehicleFlags
Ground vehicle flags.
@ GVF_SUPPRESS_IMPLICIT_ORDERS
Disable insertion and removal of automatic orders until the vehicle completes the real order.
@ GVF_GOINGDOWN_BIT
Vehicle is currently going downhill. (Cached track information for acceleration)
@ GVF_GOINGUP_BIT
Vehicle is currently going uphill. (Cached track information for acceleration)
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
Functions related to OTTD's landscape.
Cached, frequently calculated values.
uint32_t cached_weight
Total weight of the consist (valid only for the first engine).
uint32_t cached_air_drag
Air drag coefficient of the vehicle (valid only for the first engine).
uint16_t cached_axle_resistance
Resistance caused by the axles of the vehicle (valid only for the first engine).
EngineID first_engine
Cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
uint16_t last_speed
The last speed we did display, so we only have to redraw when this changes.
uint32_t cached_power
Total power of the consist (valid only for the first engine).
uint16_t cached_total_length
Length of the whole vehicle (valid only for the first engine).
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...
uint32_t cached_max_te
Maximum tractive effort of consist (valid only for the first engine).
uint16_t cached_max_track_speed
Maximum consist speed (in internal units) limited by track type (valid only for the first engine).
uint32_t cached_slope_resistance
Resistance caused by weight when this vehicle part is at a slope.
Base class for all vehicles that move through ground.
bool IsChainInDepot() const override
Check whether the whole vehicle chain is in the depot.
void SetFreeWagon()
Set a vehicle as a free wagon.
int UpdateInclination(bool new_tile, bool update_delta)
Checks if the vehicle is in a slope and sets the required flags in that case.
void ClearWagon()
Clear wagon property.
GroundVehicle< T, Type > GroundVehicleBase
Our type.
GroundVehicleCache gcache
Cache of often calculated values.
void CargoChanged()
Recalculates the cached weight of a vehicle and its parts.
void SetMultiheaded()
Set a vehicle as a multiheaded engine.
bool IsEngine() const
Check if a vehicle is an engine (can be first in a consist).
bool IsRearDualheaded() const
Tell if we are dealing with the rear end of a multiheaded engine.
bool IsMultiheaded() const
Check if the vehicle is a multiheaded engine.
void SetEngine()
Set engine status.
void SetWagon()
Set a vehicle to be a wagon.
void UpdateZPositionAndInclination()
Updates vehicle's Z position and inclination.
void SetFrontEngine()
Set front engine state.
void ClearFreeWagon()
Clear a vehicle from being a free wagon.
bool IsWagon() const
Check if a vehicle is a wagon.
int64_t GetSlopeResistance() const
Calculates the total slope resistance for this vehicle.
void PowerChanged()
Recalculates the cached total power of a vehicle.
void ClearArticulatedPart()
Clear a vehicle from being an articulated part.
void SetArticulatedPart()
Set a vehicle to be an articulated part.
uint Crash(bool flooded) override
Common code executed for crashed ground vehicles.
bool IsFreeWagon() const
Check if the vehicle is a free wagon (got no engine in front of it).
void ClearEngine()
Clear engine status.
void ClearMultiheaded()
Clear multiheaded engine property.
uint DoUpdateSpeed(uint accel, int min_speed, int max_speed)
Update the speed of the vehicle.
GroundVehicle()
The constructor at SpecializedVehicle must be called.
int GetAcceleration() const
Calculates the acceleration of the vehicle under its current conditions.
void ClearFrontEngine()
Remove the front engine state.
void UpdateZPosition()
Updates vehicle's Z position.
void SetLastSpeed()
Update the GUI variant of the current speed of the vehicle.
Tindex index
Index of this pool item.
Class defining several overloaded accessors so we don't have to cast vehicle types that often.
void UpdateViewport(bool force_update, bool update_delta)
Update vehicle sprite- and position caches.
static uint GetAdvanceSpeed(uint speed)
Determines the effective vehicle movement speed.
int32_t z_pos
z coordinate.
Direction direction
facing
virtual uint Crash(bool flooded=false)
Crash the (whole) vehicle chain.
uint8_t subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
uint8_t subspeed
fractional speed
int32_t y_pos
y coordinate.
int32_t x_pos
x coordinate.
uint16_t cur_speed
current speed
uint8_t progress
The percentage (if divided by 256) this vehicle already crossed the tile unit.
static const uint TILE_SIZE
Tile size in world coordinates.
static const uint TILE_UNIT_MASK
For masking in/out the inner-tile world coordinate units.
Base class for all vehicles.
@ GVSF_ARTICULATED_PART
Articulated part of an engine.
@ GVSF_FRONT
Leading engine of a consist.
@ GVSF_MULTIHEADED
Engine is multiheaded (not used for road vehicles).
@ GVSF_FREE_WAGON
First in a wagon chain (in depot) (not used for road vehicles).
@ 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 vehicle...
Functions related to the vehicle's GUIs.
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, WidgetID widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
Window functions not directly related to making/drawing windows.
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers: