mirror of https://github.com/OpenTTD/OpenTTD
(svn r18854) -Codechange [FS#3539]: unconflict acceleration type as 'status' and rail property (Terhken)
parent
11e3a00a23
commit
23a8d2239f
12
src/train.h
12
src/train.h
|
@ -93,10 +93,10 @@ struct TrainCache {
|
||||||
EngineID first_engine; ///< cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
|
EngineID first_engine; ///< cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
|
||||||
};
|
};
|
||||||
|
|
||||||
/** What type of acceleration should we do? */
|
/** What is the status of our acceleration? */
|
||||||
enum AccelType {
|
enum AccelStatus {
|
||||||
AM_ACCEL, ///< We want to go faster, if possible ofcourse
|
AS_ACCEL, ///< We want to go faster, if possible ofcourse
|
||||||
AM_BRAKE ///< We want to stop
|
AS_BRAKE ///< We want to stop
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -444,9 +444,9 @@ protected: /* These functions should not be called outside acceleration code. */
|
||||||
* Checks the current acceleration status of this vehicle.
|
* Checks the current acceleration status of this vehicle.
|
||||||
* @return Acceleration status.
|
* @return Acceleration status.
|
||||||
*/
|
*/
|
||||||
FORCEINLINE AccelType GetAccelerationStatus() const
|
FORCEINLINE AccelStatus GetAccelerationStatus() const
|
||||||
{
|
{
|
||||||
return (this->vehstatus & VS_STOPPED) || HasBit(this->flags, VRF_REVERSING) || HasBit(this->flags, VRF_TRAIN_STUCK) ? AM_BRAKE : AM_ACCEL;
|
return (this->vehstatus & VS_STOPPED) || HasBit(this->flags, VRF_REVERSING) || HasBit(this->flags, VRF_TRAIN_STUCK) ? AS_BRAKE : AS_ACCEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -527,7 +527,7 @@ int Train::GetAcceleration() const
|
||||||
resistance *= 4; //[N]
|
resistance *= 4; //[N]
|
||||||
|
|
||||||
/* This value allows to know if the vehicle is accelerating or braking. */
|
/* This value allows to know if the vehicle is accelerating or braking. */
|
||||||
AccelType mode = this->GetAccelerationStatus();
|
AccelStatus mode = this->GetAccelerationStatus();
|
||||||
|
|
||||||
const int max_te = this->tcache.cached_max_te; // [N]
|
const int max_te = this->tcache.cached_max_te; // [N]
|
||||||
int force;
|
int force;
|
||||||
|
@ -536,17 +536,17 @@ int Train::GetAcceleration() const
|
||||||
force = power / speed; //[N]
|
force = power / speed; //[N]
|
||||||
force *= 22;
|
force *= 22;
|
||||||
force /= 10;
|
force /= 10;
|
||||||
if (mode == AM_ACCEL && force > max_te) force = max_te;
|
if (mode == AS_ACCEL && force > max_te) force = max_te;
|
||||||
} else {
|
} else {
|
||||||
force = power / 25;
|
force = power / 25;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* "kickoff" acceleration */
|
/* "kickoff" acceleration */
|
||||||
force = (mode == AM_ACCEL && !maglev) ? min(max_te, power) : power;
|
force = (mode == AS_ACCEL && !maglev) ? min(max_te, power) : power;
|
||||||
force = max(force, (mass * 8) + resistance);
|
force = max(force, (mass * 8) + resistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == AM_ACCEL) {
|
if (mode == AS_ACCEL) {
|
||||||
return (force - resistance) / (mass * 2);
|
return (force - resistance) / (mass * 2);
|
||||||
} else {
|
} else {
|
||||||
return min(-force - resistance, -10000) / mass;
|
return min(-force - resistance, -10000) / mass;
|
||||||
|
@ -2941,7 +2941,7 @@ int Train::UpdateSpeed()
|
||||||
|
|
||||||
switch (_settings_game.vehicle.train_acceleration_model) {
|
switch (_settings_game.vehicle.train_acceleration_model) {
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
case TAM_ORIGINAL: accel = this->acceleration * (this->GetAccelerationStatus() == AM_BRAKE ? -4 : 2); break;
|
case TAM_ORIGINAL: accel = this->acceleration * (this->GetAccelerationStatus() == AS_BRAKE ? -4 : 2); break;
|
||||||
case TAM_REALISTIC:
|
case TAM_REALISTIC:
|
||||||
this->max_speed = this->GetCurrentMaxSpeed();
|
this->max_speed = this->GetCurrentMaxSpeed();
|
||||||
accel = this->GetAcceleration();
|
accel = this->GetAcceleration();
|
||||||
|
|
Loading…
Reference in New Issue