Skip to content

Commit 8a6f833

Browse files
SteelFillcesarBLG
authored andcommitted
From the top! Submitting just the updated physics now
1 parent 8e14454 commit 8a6f833

File tree

1 file changed

+20
-100
lines changed

1 file changed

+20
-100
lines changed

Source/Orts.Simulation/Simulation/RollingStocks/MSTSLocomotive.cs

Lines changed: 20 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,6 +2827,7 @@ public void SimpleAdhesion()
28272827

28282828
float max0 = DrvWheelWeightKg * 9.81f * uMax; //Ahesion limit in [N]
28292829
float max1;
2830+
float SandingFrictionFactor = 1;
28302831

28312832
if (Simulator.WeatherType == WeatherType.Rain || Simulator.WeatherType == WeatherType.Snow)
28322833
{
@@ -2845,30 +2846,19 @@ public void SimpleAdhesion()
28452846
//float max1 = (Sander ? .95f : Adhesion2) * max0; //Not used this way
28462847
max1 = MaxForceN;
28472848
//add sander
2848-
if (AbsSpeedMpS < SanderSpeedOfMpS && CurrentTrackSandBoxCapacityM3 > 0.0 && MainResPressurePSI > 80.0)
2849+
if (Sander && AbsSpeedMpS < SanderSpeedOfMpS && CurrentTrackSandBoxCapacityM3 > 0.0 && MainResPressurePSI > 80.0)
28492850
{
2850-
if (SanderSpeedEffectUpToMpS > 0.0f)
2851+
switch (Simulator.WeatherType)
28512852
{
2852-
if ((Sander) && (AbsSpeedMpS < SanderSpeedEffectUpToMpS))
2853-
{
2854-
switch (Simulator.WeatherType)
2855-
{
2856-
case WeatherType.Clear: max0 *= (1.0f - 0.5f / SanderSpeedEffectUpToMpS * AbsSpeedMpS) * 1.2f; break;
2857-
case WeatherType.Rain: max0 *= (1.0f - 0.5f / SanderSpeedEffectUpToMpS * AbsSpeedMpS) * 1.8f; break;
2858-
case WeatherType.Snow: max0 *= (1.0f - 0.5f / SanderSpeedEffectUpToMpS * AbsSpeedMpS) * 2.5f; break;
2859-
}
2860-
}
2853+
case WeatherType.Clear: SandingFrictionFactor = 1.2f; break;
2854+
case WeatherType.Rain: SandingFrictionFactor = 1.8f; break;
2855+
case WeatherType.Snow: SandingFrictionFactor = 2.5f; break;
28612856
}
2862-
else
2863-
if (Sander)
2857+
if (SanderSpeedEffectUpToMpS > 0.0f) // Reduce sander effectiveness if max effective speed is defined
28642858
{
2865-
switch (Simulator.WeatherType)
2866-
{
2867-
case WeatherType.Clear: max0 *= 1.2f; break;
2868-
case WeatherType.Rain: max0 *= 1.8f; break;
2869-
case WeatherType.Snow: max0 *= 2.5f; break;
2870-
}
2859+
SandingFrictionFactor *= (1.0f - 0.5f / SanderSpeedEffectUpToMpS * AbsSpeedMpS);
28712860
}
2861+
max0 *= Math.Max(SandingFrictionFactor, 1.0f); // Prevent sand from harming adhesion above max effective speed
28722862
}
28732863

28742864
max1 = max0;
@@ -3142,92 +3132,22 @@ public virtual void UpdateFrictionCoefficient(float elapsedClockSeconds)
31423132
}
31433133
}
31443134

3145-
BaseFrictionCoefficientFactor = MathHelper.Clamp(BaseFrictionCoefficientFactor, 0.5f, 1.0f);
3135+
BaseFrictionCoefficientFactor = MathHelper.Clamp(BaseFrictionCoefficientFactor, 0.5f, 1.0f);
31463136

3147-
// Snow covered track
3148-
if (Simulator.WeatherType == WeatherType.Snow)
3137+
// Increase friction coefficient when sanding
3138+
if (Sander && AbsSpeedMpS < SanderSpeedOfMpS && CurrentTrackSandBoxCapacityM3 > 0.0 && MainResPressurePSI > 80.0)
31493139
{
3150-
if (AbsSpeedMpS < SanderSpeedOfMpS && CurrentTrackSandBoxCapacityM3 > 0.0 && MainResPressurePSI > 80.0 && (AbsSpeedMpS > 0))
3140+
switch (Simulator.WeatherType)
31513141
{
3152-
if (SanderSpeedEffectUpToMpS > 0.0f)
3153-
{
3154-
if ((Sander) && (AbsSpeedMpS < SanderSpeedEffectUpToMpS))
3155-
{
3156-
SandingFrictionCoefficientFactor = (1.0f - 0.5f / SanderSpeedEffectUpToMpS * AbsSpeedMpS) * 1.50f;
3157-
BaseFrictionCoefficientFactor *= SandingFrictionCoefficientFactor;
3158-
3159-
}
3160-
}
3161-
else
3162-
{
3163-
if (Sander) // If sander is on, and train speed is greater then zero, then put sand on the track
3164-
{
3165-
SandingFrictionCoefficientFactor = 1.50f;
3166-
BaseFrictionCoefficientFactor *= SandingFrictionCoefficientFactor; // Sanding track adds approx 150% adhesion (best case)
3167-
}
3168-
}
3142+
case WeatherType.Clear: SandingFrictionCoefficientFactor = 1.40f; break;
3143+
case WeatherType.Rain: SandingFrictionCoefficientFactor = 1.25f; break;
3144+
case WeatherType.Snow: SandingFrictionCoefficientFactor = 1.50f; break;
31693145
}
3170-
else if (Sander && CurrentTrackSandBoxCapacityM3 > 0.0 && MainResPressurePSI > 80.0)
3146+
if (SanderSpeedEffectUpToMpS > 0.0f) // Reduce sander effectiveness if max effective speed is defined
31713147
{
3172-
SandingFrictionCoefficientFactor = 1.50f;
3173-
BaseFrictionCoefficientFactor *= SandingFrictionCoefficientFactor; // Sanding track adds approx 150% adhesion (best case)
3148+
SandingFrictionCoefficientFactor *= (1.0f - 0.5f / SanderSpeedEffectUpToMpS * AbsSpeedMpS);
31743149
}
3175-
}
3176-
else if (Simulator.WeatherType == WeatherType.Rain)
3177-
{
3178-
if (AbsSpeedMpS < SanderSpeedOfMpS && CurrentTrackSandBoxCapacityM3 > 0.0 && MainResPressurePSI > 80.0 && (AbsSpeedMpS > 0))
3179-
{
3180-
if (SanderSpeedEffectUpToMpS > 0.0f)
3181-
{
3182-
if ((Sander) && (AbsSpeedMpS < SanderSpeedEffectUpToMpS))
3183-
{
3184-
SandingFrictionCoefficientFactor = (1.0f - 0.5f / SanderSpeedEffectUpToMpS * AbsSpeedMpS) * 1.25f;
3185-
BaseFrictionCoefficientFactor *= SandingFrictionCoefficientFactor;
3186-
3187-
}
3188-
}
3189-
else
3190-
{
3191-
if (Sander) // If sander is on, and train speed is greater then zero, then put sand on the track
3192-
{
3193-
SandingFrictionCoefficientFactor = 1.25f;
3194-
BaseFrictionCoefficientFactor *= SandingFrictionCoefficientFactor; // Sanding track adds approx 125% adhesion (best case)
3195-
}
3196-
}
3197-
}
3198-
else if (Sander && CurrentTrackSandBoxCapacityM3 > 0.0 && MainResPressurePSI > 80.0)
3199-
{
3200-
SandingFrictionCoefficientFactor = 1.25f;
3201-
BaseFrictionCoefficientFactor *= SandingFrictionCoefficientFactor; // Sanding track adds approx 125% adhesion (best case)
3202-
}
3203-
}
3204-
else // dry weather
3205-
{
3206-
if (AbsSpeedMpS < SanderSpeedOfMpS && CurrentTrackSandBoxCapacityM3 > 0.0 && MainResPressurePSI > 80.0 && (AbsSpeedMpS > 0))
3207-
{
3208-
if (SanderSpeedEffectUpToMpS > 0.0f)
3209-
{
3210-
if ((Sander) && (AbsSpeedMpS < SanderSpeedEffectUpToMpS))
3211-
{
3212-
SandingFrictionCoefficientFactor = (1.0f - 0.5f / SanderSpeedEffectUpToMpS * AbsSpeedMpS) * 1.40f;
3213-
BaseFrictionCoefficientFactor *= SandingFrictionCoefficientFactor;
3214-
}
3215-
}
3216-
else
3217-
{
3218-
if (Sander) // If sander is on, and train speed is greater then zero, then put sand on the track
3219-
{
3220-
SandingFrictionCoefficientFactor = 1.40f;
3221-
BaseFrictionCoefficientFactor *= SandingFrictionCoefficientFactor; // Sanding track adds approx 140% adhesion (best case)
3222-
}
3223-
}
3224-
}
3225-
else if (Sander && CurrentTrackSandBoxCapacityM3 > 0.0 && MainResPressurePSI > 80.0)
3226-
{
3227-
SandingFrictionCoefficientFactor = 1.40f;
3228-
BaseFrictionCoefficientFactor *= SandingFrictionCoefficientFactor; // Sanding track adds approx 140% adhesion (best case)
3229-
}
3230-
3150+
BaseFrictionCoefficientFactor *= Math.Max(SandingFrictionCoefficientFactor, 1.0f); // Prevent sand from harming adhesion above max effective speed
32313151
}
32323152

32333153
// For wagons use base Curtius-Kniffler adhesion factor - u = 0.33
@@ -3282,7 +3202,7 @@ public void UpdateTrackSander(float elapsedClockSeconds)
32823202
// The following assumptions have been made:
32833203
//
32843204

3285-
if (Sander) // If sander is on adjust parameters
3205+
if (Sander && AbsSpeedMpS < SanderSpeedOfMpS) // If sander switch is on, and not blocked by speed, adjust parameters
32863206
{
32873207
if (CurrentTrackSandBoxCapacityM3 > 0.0) // if sand still in sandbox then sanding is available
32883208
{

0 commit comments

Comments
 (0)