|
@@ -125,25 +125,25 @@ struct Train FINAL : public GroundVehicl
|
|
|
int GetCurrentMaxSpeed() const;
|
|
|
|
|
|
/**
|
|
|
* Get the next real (non-articulated part and non rear part of dualheaded engine) vehicle in the consist.
|
|
|
* @return Next vehicle in the consist.
|
|
|
*/
|
|
|
FORCEINLINE Train *GetNextUnit() const
|
|
|
inline Train *GetNextUnit() const
|
|
|
{
|
|
|
Train *v = this->GetNextVehicle();
|
|
|
if (v != NULL && v->IsRearDualheaded()) v = v->GetNextVehicle();
|
|
|
|
|
|
return v;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Get the previous real (non-articulated part and non rear part of dualheaded engine) vehicle in the consist.
|
|
|
* @return Previous vehicle in the consist.
|
|
|
*/
|
|
|
FORCEINLINE Train *GetPrevUnit()
|
|
|
inline Train *GetPrevUnit()
|
|
|
{
|
|
|
Train *v = this->GetPrevVehicle();
|
|
|
if (v != NULL && v->IsRearDualheaded()) v = v->GetPrevVehicle();
|
|
|
|
|
|
return v;
|
|
|
}
|
|
@@ -164,13 +164,13 @@ struct Train FINAL : public GroundVehicl
|
|
|
protected: // These functions should not be called outside acceleration code.
|
|
|
|
|
|
/**
|
|
|
* Allows to know the power value that this vehicle will use.
|
|
|
* @return Power value from the engine in HP, or zero if the vehicle is not powered.
|
|
|
*/
|
|
|
FORCEINLINE uint16 GetPower() const
|
|
|
inline uint16 GetPower() const
|
|
|
{
|
|
|
/* Power is not added for articulated parts */
|
|
|
if (!this->IsArticulatedPart() && HasPowerOnRail(this->railtype, GetRailType(this->tile))) {
|
|
|
uint16 power = GetVehicleProperty(this, PROP_TRAIN_POWER, RailVehInfo(this->engine_type)->power);
|
|
|
/* Halve power for multiheaded parts */
|
|
|
if (this->IsMultiheaded()) power /= 2;
|
|
@@ -181,13 +181,13 @@ protected: // These functions should not
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Returns a value if this articulated part is powered.
|
|
|
* @return Power value from the articulated part in HP, or zero if it is not powered.
|
|
|
*/
|
|
|
FORCEINLINE uint16 GetPoweredPartPower(const Train *head) const
|
|
|
inline uint16 GetPoweredPartPower(const Train *head) const
|
|
|
{
|
|
|
/* For powered wagons the engine defines the type of engine (i.e. railtype) */
|
|
|
if (HasBit(this->flags, VRF_POWEREDWAGON) && HasPowerOnRail(head->railtype, GetRailType(this->tile))) {
|
|
|
return RailVehInfo(this->gcache.first_engine)->pow_wag_power;
|
|
|
}
|
|
|
|
|
@@ -195,13 +195,13 @@ protected: // These functions should not
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Allows to know the weight value that this vehicle will use.
|
|
|
* @return Weight value from the engine in tonnes.
|
|
|
*/
|
|
|
FORCEINLINE uint16 GetWeight() const
|
|
|
inline uint16 GetWeight() const
|
|
|
{
|
|
|
uint16 weight = (CargoSpec::Get(this->cargo_type)->weight * this->cargo.Count() * FreightWagonMult(this->cargo_type)) / 16;
|
|
|
|
|
|
/* Vehicle weight is not added for articulated parts. */
|
|
|
if (!this->IsArticulatedPart()) {
|
|
|
weight += GetVehicleProperty(this, PROP_TRAIN_WEIGHT, RailVehInfo(this->engine_type)->weight);
|
|
@@ -216,109 +216,109 @@ protected: // These functions should not
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Allows to know the tractive effort value that this vehicle will use.
|
|
|
* @return Tractive effort value from the engine.
|
|
|
*/
|
|
|
FORCEINLINE byte GetTractiveEffort() const
|
|
|
inline byte GetTractiveEffort() const
|
|
|
{
|
|
|
return GetVehicleProperty(this, PROP_TRAIN_TRACTIVE_EFFORT, RailVehInfo(this->engine_type)->tractive_effort);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Gets the area used for calculating air drag.
|
|
|
* @return Area of the engine in m^2.
|
|
|
*/
|
|
|
FORCEINLINE byte GetAirDragArea() const
|
|
|
inline byte GetAirDragArea() const
|
|
|
{
|
|
|
/* Air drag is higher in tunnels due to the limited cross-section. */
|
|
|
return (this->track == TRACK_BIT_WORMHOLE && this->vehstatus & VS_HIDDEN) ? 28 : 14;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Gets the air drag coefficient of this vehicle.
|
|
|
* @return Air drag value from the engine.
|
|
|
*/
|
|
|
FORCEINLINE byte GetAirDrag() const
|
|
|
inline byte GetAirDrag() const
|
|
|
{
|
|
|
return RailVehInfo(this->engine_type)->air_drag;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Checks the current acceleration status of this vehicle.
|
|
|
* @return Acceleration status.
|
|
|
*/
|
|
|
FORCEINLINE AccelStatus GetAccelerationStatus() const
|
|
|
inline AccelStatus GetAccelerationStatus() const
|
|
|
{
|
|
|
return (this->vehstatus & VS_STOPPED) || HasBit(this->flags, VRF_REVERSING) || HasBit(this->flags, VRF_TRAIN_STUCK) ? AS_BRAKE : AS_ACCEL;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Calculates the current speed of this vehicle.
|
|
|
* @return Current speed in km/h-ish.
|
|
|
*/
|
|
|
FORCEINLINE uint16 GetCurrentSpeed() const
|
|
|
inline uint16 GetCurrentSpeed() const
|
|
|
{
|
|
|
return this->cur_speed;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Returns the rolling friction coefficient of this vehicle.
|
|
|
* @return Rolling friction coefficient in [1e-4].
|
|
|
*/
|
|
|
FORCEINLINE uint32 GetRollingFriction() const
|
|
|
inline uint32 GetRollingFriction() const
|
|
|
{
|
|
|
/* Rolling friction for steel on steel is between 0.1% and 0.2%.
|
|
|
* The friction coefficient increases with speed in a way that
|
|
|
* it doubles at 512 km/h, triples at 1024 km/h and so on. */
|
|
|
return 15 * (512 + this->GetCurrentSpeed()) / 512;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Allows to know the acceleration type of a vehicle.
|
|
|
* @return Acceleration type of the vehicle.
|
|
|
*/
|
|
|
FORCEINLINE int GetAccelerationType() const
|
|
|
inline int GetAccelerationType() const
|
|
|
{
|
|
|
return GetRailTypeInfo(this->railtype)->acceleration_type;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Returns the slope steepness used by this vehicle.
|
|
|
* @return Slope steepness used by the vehicle.
|
|
|
*/
|
|
|
FORCEINLINE uint32 GetSlopeSteepness() const
|
|
|
inline uint32 GetSlopeSteepness() const
|
|
|
{
|
|
|
return _settings_game.vehicle.train_slope_steepness;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Gets the maximum speed allowed by the track for this vehicle.
|
|
|
* @return Maximum speed allowed.
|
|
|
*/
|
|
|
FORCEINLINE uint16 GetMaxTrackSpeed() const
|
|
|
inline uint16 GetMaxTrackSpeed() const
|
|
|
{
|
|
|
return GetRailTypeInfo(GetRailType(this->tile))->max_speed;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Checks if the vehicle is at a tile that can be sloped.
|
|
|
* @return True if the tile can be sloped.
|
|
|
*/
|
|
|
FORCEINLINE bool TileMayHaveSlopedTrack() const
|
|
|
inline bool TileMayHaveSlopedTrack() const
|
|
|
{
|
|
|
/* Any track that isn't TRACK_BIT_X or TRACK_BIT_Y cannot be sloped. */
|
|
|
return this->track == TRACK_BIT_X || this->track == TRACK_BIT_Y;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Trains can always use the faster algorithm because they
|
|
|
* have always the same direction as the track under them.
|
|
|
* @return false
|
|
|
*/
|
|
|
FORCEINLINE bool HasToUseGetSlopePixelZ()
|
|
|
inline bool HasToUseGetSlopePixelZ()
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
#define FOR_ALL_TRAINS(var) FOR_ALL_VEHICLES_OF_TYPE(Train, var)
|