12 #ifndef GROUND_VEHICLE_HPP 13 #define GROUND_VEHICLE_HPP 80 template <
class T, VehicleType Type>
94 int GetAcceleration()
const;
95 bool IsChainInDepot()
const;
105 for (T *v = T::From(
this); v != NULL; v = v->Next()) {
120 for (
const T *u = T::From(
this); u != NULL; u = u->Next()) {
122 incl += u->gcache.cached_slope_resistance;
124 incl -= u->gcache.cached_slope_resistance;
139 this->z_pos = GetSlopePixelZ(this->x_pos, this->y_pos);
143 if (T::From(
this)->TileMayHaveSlopedTrack()) {
150 if (middle_z != this->z_pos) {
168 switch (this->direction) {
170 this->z_pos += (this->x_pos & 1);
break;
172 this->z_pos += (this->x_pos & 1) ^ 1;
break;
174 this->z_pos += (this->y_pos & 1);
break;
176 this->z_pos += (this->y_pos & 1) ^ 1;
break;
180 switch (this->direction) {
182 this->z_pos -= (this->x_pos & 1);
break;
184 this->z_pos -= (this->x_pos & 1) ^ 1;
break;
186 this->z_pos -= (this->y_pos & 1);
break;
188 this->z_pos -= (this->y_pos & 1) ^ 1;
break;
203 if (T::From(
this)->HasToUseGetSlopePixelZ()) {
205 this->z_pos = GetSlopePixelZ(this->x_pos, this->y_pos);
211 int8 x_pos = this->x_pos;
212 int8 y_pos = this->y_pos;
225 assert(this->z_pos == GetSlopePixelZ(this->x_pos, this->y_pos));
236 int old_z = this->z_pos;
239 this->UpdateZPositionAndInclination();
241 this->UpdateZPosition();
244 this->UpdateViewport(
true, update_delta);
336 inline bool IsRearDualheaded()
const {
return this->IsMultiheaded() && !this->IsEngine(); }
345 if (this->cur_speed != this->gcache.
last_speed) {
367 uint spd = this->subspeed + accel;
368 this->subspeed = (byte)spd;
372 int tempmax = max_speed;
373 if (this->cur_speed > max_speed) {
374 tempmax =
max(this->cur_speed - (this->cur_speed / 10) - 1, max_speed);
382 this->cur_speed = spd =
max(
min(this->cur_speed + ((
int)spd >> 8), tempmax), min_speed);
384 int scaled_spd = this->GetAdvanceSpeed(spd);
386 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.
DiagDirection
Enumeration for diagonal directions.
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.
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 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.
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.
uint Crash(bool flooded)
Common code executed for crashed ground vehicles.
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.