10 #ifndef GROUND_VEHICLE_HPP 11 #define GROUND_VEHICLE_HPP 78 template <
class T, VehicleType Type>
92 int GetAcceleration()
const;
93 bool IsChainInDepot()
const override;
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;
137 this->z_pos = GetSlopePixelZ(this->x_pos, this->y_pos);
141 if (T::From(
this)->TileMayHaveSlopedTrack()) {
148 if (middle_z != this->z_pos) {
166 switch (this->direction) {
168 this->z_pos += (this->x_pos & 1);
break;
170 this->z_pos += (this->x_pos & 1) ^ 1;
break;
172 this->z_pos += (this->y_pos & 1);
break;
174 this->z_pos += (this->y_pos & 1) ^ 1;
break;
178 switch (this->direction) {
180 this->z_pos -= (this->x_pos & 1);
break;
182 this->z_pos -= (this->x_pos & 1) ^ 1;
break;
184 this->z_pos -= (this->y_pos & 1);
break;
186 this->z_pos -= (this->y_pos & 1) ^ 1;
break;
201 if (T::From(
this)->HasToUseGetSlopePixelZ()) {
203 this->z_pos = GetSlopePixelZ(this->x_pos, this->y_pos);
209 int8 x_pos = this->x_pos;
210 int8 y_pos = this->y_pos;
223 assert(this->z_pos == GetSlopePixelZ(this->x_pos, this->y_pos));
234 int old_z = this->z_pos;
237 this->UpdateZPositionAndInclination();
239 this->UpdateZPosition();
242 this->UpdateViewport(
true, update_delta);
334 inline bool IsRearDualheaded()
const {
return this->IsMultiheaded() && !this->IsEngine(); }
343 if (this->cur_speed != this->gcache.
last_speed) {
365 uint spd = this->subspeed + accel;
366 this->subspeed = (byte)spd;
370 int tempmax = max_speed;
371 if (this->cur_speed > max_speed) {
372 tempmax =
max(this->cur_speed - (this->cur_speed / 10) - 1, max_speed);
380 this->cur_speed = spd =
max(
min(this->cur_speed + ((
int)spd >> 8), tempmax), min_speed);
382 int scaled_spd = this->GetAdvanceSpeed(spd);
384 scaled_spd += this->progress;
void ClearEngine()
Clear engine status.
AccelStatus
What is the status of our acceleration?
GroundVehicleFlags
Ground vehicle flags.
static DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
void SetFrontEngine()
Set front engine state.
virtual uint Crash(bool flooded=false)
Crash the (whole) vehicle chain.
uint DoUpdateSpeed(uint accel, int min_speed, int max_speed)
Update the speed of the vehicle.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
void ClearArticulatedPart()
Clear a vehicle from being an articulated part.
Leading engine of a consist.
void UpdateZPositionAndInclination()
Updates vehicle's Z position and inclination.
bool IsMultiheaded() const
Check if the vehicle is a multiheaded engine.
Engine that can be front engine, but might be placed behind another engine (not used for road vehicle...
uint32 cached_power
Total power of the consist (valid only for the first engine).
GroundVehicle()
The constructor at SpecializedVehicle must be called.
uint16 cached_axle_resistance
Resistance caused by the axles of the vehicle (valid only for the first engine).
static T max(const T a, const T b)
Returns the maximum of two values.
Wagon (not used for road vehicles).
Cached, frequently calculated values.
Functions related to the vehicle's GUIs.
static const uint TILE_SIZE
Tile size in world coordinates.
EngineID first_engine
Cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
Class defining several overloaded accessors so we don't have to cast vehicle types that often...
uint32 cached_air_drag
Air drag coefficient of the vehicle (valid only for the first engine).
GroundVehicle< T, Type > GroundVehicleBase
Our type.
bool IsWagon() const
Check if a vehicle is a wagon.
void SetEngine()
Set engine status.
int64 GetSlopeResistance() const
Calculates the total slope resistance for this vehicle.
void ClearFrontEngine()
Remove the front engine state.
void ClearFreeWagon()
Clear a vehicle from being a free wagon.
Vehicle view; Window numbers:
uint32 cached_slope_resistance
Resistance caused by weight when this vehicle part is at a slope.
bool IsRearDualheaded() const
Tell if we are dealing with the rear end of a multiheaded engine.
static T min(const T a, const T b)
Returns the minimum of two values.
Vehicle is currently going uphill. (Cached track information for acceleration)
We want to go faster, if possible of course.
Engine is multiheaded (not used for road vehicles).
uint16 last_speed
The last speed we did display, so we only have to redraw when this changes.
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
uint Crash(bool flooded) override
Common code executed for crashed ground vehicles.
Vehicle is currently going downhill. (Cached track information for acceleration)
Articulated part of an engine.
void UpdateZPosition()
Updates vehicle's Z position.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, byte widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
Base class for all vehicles.
uint16 EngineID
Unique identification number of an engine.
uint16 cached_total_length
Length of the whole vehicle (valid only for the first engine).
First in a wagon chain (in depot) (not used for road vehicles).
uint16 cached_max_track_speed
Maximum consist speed (in internal units) limited by track type (valid only for the first engine)...
static const uint TILE_UNIT_MASK
For masking in/out the inner-tile world coordinate units.
Functions related to OTTD's landscape.
void SetLastSpeed()
Update the GUI variant of the current speed of the vehicle.
bool IsFreeWagon() const
Check if the vehicle is a free wagon (got no engine in front of it).
uint8 cached_veh_length
Length of this vehicle in units of 1/VEHICLE_LENGTH of normal length. It is cached because this can b...
void ClearMultiheaded()
Clear multiheaded engine property.
void SetArticulatedPart()
Set a vehicle to be an articulated part.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
DiagDirection
Enumeration for diagonal directions.
void SetFreeWagon()
Set a vehicle as a free wagon.
uint32 cached_max_te
Maximum tractive effort of consist (valid only for the first engine).
Window functions not directly related to making/drawing windows.
int UpdateInclination(bool new_tile, bool update_delta)
Checks if the vehicle is in a slope and sets the required flags in that case.
Base class for all vehicles that move through ground.
void SetMultiheaded()
Set a vehicle as a multiheaded engine.
void SetWagon()
Set a vehicle to be a wagon.
uint32 cached_weight
Total weight of the consist (valid only for the first engine).
Disable insertion and removal of automatic orders until the vehicle completes the real order...
bool IsEngine() const
Check if a vehicle is an engine (can be first in a consist).
GroundVehicleCache gcache
Cache of often calculated values.
void ClearWagon()
Clear wagon property.