Skip to content

Commit ee55d7a

Browse files
committed
Disable derailment coefficient for "dummy" cars
1 parent b87e473 commit ee55d7a

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

Source/Orts.Simulation/Simulation/RollingStocks/MSTSWagon.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,15 @@ public virtual void LoadFromWagFile(string wagFilePath)
491491
{
492492
CarAirHoseHorizontalLengthM = 0.3862f; // 15.2 inches
493493
}
494-
494+
495+
// Disable derailment coefficent on "dummy" cars. NB: Ideally this should never be used as "dummy" cars interfer with the overall train physics.
496+
if (MSTSWagonNumWheels == 0 && InitWagonNumAxles == 0 )
497+
{
498+
DerailmentCoefficientEnabled = false;
499+
}
500+
495501
// Ensure Drive Axles is set to a default if no OR value added to WAG file
496-
if (WagonNumAxles == 0 && WagonType != WagonTypes.Engine)
502+
if (InitWagonNumAxles == 0 && WagonType != WagonTypes.Engine)
497503
{
498504
if (MSTSWagonNumWheels != 0 && MSTSWagonNumWheels < 6)
499505
{
@@ -509,6 +515,10 @@ public virtual void LoadFromWagFile(string wagFilePath)
509515
Trace.TraceInformation("Number of Wagon Axles set to default value of {0}", WagonNumAxles);
510516
}
511517
}
518+
else
519+
{
520+
WagonNumAxles = InitWagonNumAxles;
521+
}
512522

513523
// Should always be at least one bogie on rolling stock. If is zero then NaN error occurs.
514524
if (WagonNumBogies == 0)
@@ -1369,8 +1379,8 @@ public virtual void Parse(string lowercasetoken, STFReader stf)
13691379
break;
13701380
case "wagon(inside": HasInsideView = true; ParseWagonInside(stf); break;
13711381
case "wagon(orts3dcab": Parse3DCab(stf); break;
1372-
case "wagon(numwheels": MSTSWagonNumWheels= stf.ReadFloatBlock(STFReader.UNITS.None, 4.0f); break;
1373-
case "wagon(ortsnumberaxles": WagonNumAxles = stf.ReadIntBlock(null); break;
1382+
case "wagon(numwheels": MSTSWagonNumWheels= stf.ReadFloatBlock(STFReader.UNITS.None, null); break;
1383+
case "wagon(ortsnumberaxles": InitWagonNumAxles = stf.ReadIntBlock(null); break;
13741384
case "wagon(ortsnumberbogies": WagonNumBogies = stf.ReadIntBlock(null); break;
13751385
case "wagon(ortspantographs":
13761386
Pantographs.Parse(lowercasetoken, stf);
@@ -1455,7 +1465,8 @@ public virtual void Copy(MSTSWagon copy)
14551465
AuxTenderWaterMassKG = copy.AuxTenderWaterMassKG;
14561466
TenderWagonMaxCoalMassKG = copy.TenderWagonMaxCoalMassKG;
14571467
TenderWagonMaxWaterMassKG = copy.TenderWagonMaxWaterMassKG;
1458-
WagonNumAxles = copy.WagonNumAxles;
1468+
InitWagonNumAxles = copy.InitWagonNumAxles;
1469+
DerailmentCoefficientEnabled = copy.DerailmentCoefficientEnabled;
14591470
WagonNumBogies = copy.WagonNumBogies;
14601471
MSTSWagonNumWheels = copy.MSTSWagonNumWheels;
14611472
MassKG = copy.MassKG;

Source/Orts.Simulation/Simulation/RollingStocks/TrainCar.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public static Interpolator SteamHeatBoilerFuelUsageGalukpH()
198198
public float CarCouplerFaceLengthM;
199199
public float DerailmentCoefficient;
200200
public float NadalDerailmentCoefficient;
201+
public bool DerailmentCoefficientEnabled = true;
201202
public float MaximumWheelFlangeAngleRad;
202203
public float WheelFlangeLengthM;
203204
public float AngleOfAttackRad;
@@ -630,6 +631,7 @@ public Direction Direction
630631
protected float RouteSpeedMpS; // Max Route Speed Limit
631632
protected const float GravitationalAccelerationMpS2 = 9.80665f; // Acceleration due to gravity 9.80665 m/s2
632633
protected int WagonNumAxles; // Number of axles on a wagon
634+
protected int InitWagonNumAxles; // Initial read of number of axles on a wagon
633635
protected float MSTSWagonNumWheels; // Number of axles on a wagon - used to read MSTS value as default
634636
protected int LocoNumDrvAxles; // Number of drive axles on locomotive
635637
protected float MSTSLocoNumDrvWheels; // Number of drive axles on locomotive - used to read MSTS value as default
@@ -1484,7 +1486,7 @@ public void UpdateTrainDerailmentRisk(float elapsedClockSeconds)
14841486
// To calculate vertical force on outer wheel = (WagMass / NumWheels) * gravity + WagMass / NumAxles * ( (Speed^2 / CurveRadius) - (gravity * superelevation angle)) * (height * track width)
14851487
// Equation 5
14861488

1487-
if (IsPlayerTrain)
1489+
if (IsPlayerTrain && DerailmentCoefficientEnabled)
14881490
{
14891491
if (CouplerForceU > 0 && CouplerSlackM < 0) // If car coupler is in compression, use the buff angle
14901492
{

0 commit comments

Comments
 (0)