1
- // COPYRIGHT 2009 - 2022 by the Open Rails project.
1
+ // COPYRIGHT 2009 - 2022 by the Open Rails project.
2
2
//
3
3
// This file is part of Open Rails.
4
4
//
@@ -208,6 +208,7 @@ public static Interpolator SteamHeatBoilerFuelUsageGalukpH()
208
208
public bool DerailPossible = false ;
209
209
public bool DerailExpected = false ;
210
210
public float DerailElapsedTimeS ;
211
+ public bool HasDerailed = false ;
211
212
212
213
public float MaxHandbrakeForceN ;
213
214
public float MaxBrakeForceN = 89e3f ;
@@ -1733,8 +1734,18 @@ public void UpdateTrainDerailmentRisk(float elapsedClockSeconds)
1733
1734
{
1734
1735
DerailExpected = true ;
1735
1736
Simulator . Confirmer . Message ( ConfirmLevel . Warning , Simulator . Catalog . GetStringFmt ( "Car {0} has derailed on the curve." , CarID ) ) ;
1736
- // Trace.TraceInformation("Car Derail - CarID: {0}, Coupler: {1}, CouplerSmoothed {2}, Lateral {3}, Vertical {4}, Angle {5} Nadal {6} Coeff {7}", CarID, CouplerForceU, CouplerForceUSmoothed.SmoothedValue, TotalWagonLateralDerailForceN, TotalWagonVerticalDerailForceN, WagonCouplerAngleDerailRad, NadalDerailmentCoefficient, DerailmentCoefficient);
1737
- // Trace.TraceInformation("Car Ahead Derail - CarID: {0}, Coupler: {1}, CouplerSmoothed {2}, Lateral {3}, Vertical {4}, Angle {5}", CarAhead.CarID, CarAhead.CouplerForceU, CarAhead.CouplerForceUSmoothed.SmoothedValue, CarAhead.TotalWagonLateralDerailForceN, CarAhead.TotalWagonVerticalDerailForceN, CarAhead.WagonCouplerAngleDerailRad);
1737
+ if ( ! HasDerailed )
1738
+ {
1739
+ string derailReason = "defect" ;
1740
+ if ( CouplerForceU > 0 && CouplerSlackM < 0 ) { derailReason = "jackknifed" ; }
1741
+ else if ( CouplerForceU < 0 && CouplerSlackM > 0 ) { derailReason = "stringlined" ; }
1742
+ Trace . TraceInformation ( "Car {0} derailed ({1}), on {2} curve with radius {3}, at speed {4}, after traveling {5}" ,
1743
+ CarID , derailReason , GetCurveDirection ( ) , FormatStrings . FormatDistance ( CurrentCurveRadiusM , IsMetric ) , FormatStrings . FormatSpeed ( AbsSpeedMpS , IsMetric ) , FormatStrings . FormatDistance ( DistanceM , IsMetric ) ) ;
1744
+ // DistanceM is not a good location measure, as it is based on the train. Two railcars derailing at the same location have a different distance.
1745
+ }
1746
+ HasDerailed = true ;
1747
+ // Trace.TraceInformation("Car Derail - CarID: {0}, Coupler: {1}, CouplerSmoothed {2}, Lateral {3}, Vertical {4}, Angle {5} Nadal {6} Coeff {7}", CarID, CouplerForceU, CouplerForceUSmoothed.SmoothedValue, TotalWagonLateralDerailForceN, TotalWagonVerticalDerailForceN, WagonCouplerAngleDerailRad, NadalDerailmentCoefficient, DerailmentCoefficient);
1748
+ // Trace.TraceInformation("Car Ahead Derail - CarID: {0}, Coupler: {1}, CouplerSmoothed {2}, Lateral {3}, Vertical {4}, Angle {5}", CarAhead.CarID, CarAhead.CouplerForceU, CarAhead.CouplerForceUSmoothed.SmoothedValue, CarAhead.TotalWagonLateralDerailForceN, CarAhead.TotalWagonVerticalDerailForceN, CarAhead.WagonCouplerAngleDerailRad);
1738
1749
}
1739
1750
else if ( DerailPossible )
1740
1751
{
@@ -1744,12 +1755,15 @@ public void UpdateTrainDerailmentRisk(float elapsedClockSeconds)
1744
1755
else
1745
1756
{
1746
1757
DerailElapsedTimeS = 0 ; // Reset timer if derail is not possible
1758
+ HasDerailed = false ;
1747
1759
}
1748
1760
1749
1761
if ( AbsSpeedMpS < 0.01 )
1750
1762
{
1751
1763
DerailExpected = false ;
1752
1764
DerailPossible = false ;
1765
+ DerailElapsedTimeS = 0 ;
1766
+ HasDerailed = false ;
1753
1767
}
1754
1768
1755
1769
// if (CarID == "0 - 84" || CarID == "0 - 83" || CarID == "0 - 82" || CarID == "0 - 81" || CarID == "0 - 80" || CarID == "0 - 79")
@@ -1766,6 +1780,7 @@ public void UpdateTrainDerailmentRisk(float elapsedClockSeconds)
1766
1780
DerailExpected = false ;
1767
1781
DerailPossible = false ;
1768
1782
DerailElapsedTimeS = 0 ;
1783
+ HasDerailed = false ;
1769
1784
}
1770
1785
1771
1786
0 commit comments