2020using Orts . Parsers . Msts ;
2121using System . IO ;
2222using ORTS . Common ;
23+ using System . Linq ;
2324
2425namespace Orts . Formats . Msts
2526{
@@ -131,7 +132,14 @@ public Tr_RouteFile(STFReader stf)
131132 if ( Description == null ) throw new STFException ( stf , "Missing Description" ) ;
132133 if ( RouteStart == null ) throw new STFException ( stf , "Missing RouteStart" ) ;
133134 if ( ForestClearDistance == 0 && RemoveForestTreesFromRoads ) Trace . TraceWarning ( "You must define also ORTSUserPreferenceForestClearDistance to avoid trees on roads" ) ;
134- if ( SuperElevation . Count <= 0 ) SuperElevation . Add ( new SuperElevationStandard ( ) ) ;
135+ if ( SuperElevation . Count <= 0 )
136+ {
137+ // No superelevation standard defined, create the default one
138+ if ( SuperElevationHgtpRadiusM != null )
139+ SuperElevation . Add ( new SuperElevationStandard ( SuperElevationHgtpRadiusM , MilepostUnitsMetric ) ) ;
140+ else
141+ SuperElevation . Add ( new SuperElevationStandard ( MilepostUnitsMetric ) ) ;
142+ }
135143 }
136144
137145 public string RouteID ; // ie JAPAN1 - used for TRK file and route folder name
@@ -228,23 +236,57 @@ public string ENVFileName(SeasonType seasonType, WeatherType weatherType)
228236
229237 public class SuperElevationStandard
230238 {
231- public float MaxFreightUnderbalanceM = float . PositiveInfinity ;
232- public float MaxPaxUnderbalanceM = float . PositiveInfinity ;
233- public float MinCantM = 0.0125f ; // Default 1.25 cm ~ 0.5 inches
234- public float MaxCantM = 0.15f ; // Default limit on superelevation is 15 cm ~ 6 inches
235- public float MinSpeedMpS = MpS . FromKpH ( 25.0f ) ; // Default 25 kmh ~ 15 mph
239+ public float MaxFreightUnderbalanceM = float . PositiveInfinity ; // Limit to be set elsewhere
240+ public float MaxPaxUnderbalanceM = float . PositiveInfinity ; // Limit to be set elsewhere
241+ public float MinCantM = 0.010f ; // Default 10 mm ( 0.5 inches on imperial routes)
242+ public float MaxCantM = 0.180f ; // Default limit on superelevation is 180 mm (5 inches on imperial routes)
243+ public float MinSpeedMpS = MpS . FromKpH ( 25.0f ) ; // Default 25 kmh ( 15 mph on imperial routes)
236244 public float MaxSpeedMpS = float . PositiveInfinity ; // Default unlimited
237- public float PrecisionM = 0.005f ; // Default 5 mm ~ 0.2 inches
245+ public float PrecisionM = 0.005f ; // Default 5 mm (0.25 inches on imperial routes)
238246 public float RunoffSlope = 0.003f ; // Maximum rate of change of superelevation per track length, default 0.3%
239- public float RunoffSpeedMpS = 0.04f ; // Maximum rate of change of superelevation per second, default 4 cm / sec ~ 1.5 inches / sec
247+ public float RunoffSpeedMpS = 0.055f ; // Maximum rate of change of superelevation per second, default 55 mm / sec ( 1.5 inches / sec on imperial routes)
240248 public bool UseLegacyCalculation = true ; // Should ORTSTrackSuperElevation be used for superelevation calculations?
241249
242- public SuperElevationStandard ( )
250+ // Initialize new instance with default values (default metric values)
251+ public SuperElevationStandard ( bool metric = true )
243252 {
244- // Initialize new instance with default values
245- MaxFreightUnderbalanceM = 0.05f ; // Default 5 cm ~ 2 inches
246- MaxPaxUnderbalanceM = 0.075f ; // Default 7.5 cm ~ 3 inches
253+ if ( metric )
254+ {
255+ // Set underbalance to millimeter values for metric routes
256+ MaxFreightUnderbalanceM = 0.100f ; // Default 100 mm
257+ MaxPaxUnderbalanceM = 0.150f ; // Default 150 mm
258+ // Other parameters are already metric by default
259+ }
260+ else
261+ {
262+ // Set values in imperial units
263+ MaxFreightUnderbalanceM = Me . FromIn ( 2.0f ) ; // Default 2 inches
264+ MaxPaxUnderbalanceM = Me . FromIn ( 3.0f ) ; // Default 3 inches
265+ MinCantM = Me . FromIn ( 0.5f ) ;
266+ MaxCantM = Me . FromIn ( 6.0f ) ;
267+ MinSpeedMpS = MpS . FromMpH ( 15.0f ) ;
268+ PrecisionM = Me . FromIn ( 0.25f ) ;
269+ RunoffSpeedMpS = MpS . FromMpH ( 0.0852f ) ; // 1.5 inches per second
270+ }
247271 }
272+
273+ // Initialize new instance from superelevation interpolator
274+ // Interpolator X values should be curve radius, Y values amount of superelevation in meters
275+ public SuperElevationStandard ( Interpolator elevTable , bool metric = true )
276+ {
277+ MinCantM = elevTable . Y . Min ( ) ;
278+ MaxCantM = elevTable . Y . Max ( ) ;
279+
280+ if ( ! metric )
281+ {
282+ // Some extra data still required, use imperial units if the route uses it
283+ MinSpeedMpS = MpS . FromMpH ( 15.0f ) ;
284+ PrecisionM = Me . FromIn ( 0.25f ) ;
285+ RunoffSpeedMpS = MpS . FromMpH ( 0.0852f ) ; // 1.5 inches per second
286+ }
287+ }
288+
289+ // Read data for new instance using STF format
248290 public SuperElevationStandard ( STFReader stf )
249291 {
250292 stf . MustMatch ( "(" ) ;
@@ -268,7 +310,7 @@ public SuperElevationStandard(STFReader stf)
268310 {
269311 if ( MaxPaxUnderbalanceM > 10.0f )
270312 {
271- // Neither underbalance has been defined
313+ // Neither underbalance has been defined, assume some defaults
272314 MaxFreightUnderbalanceM = 0.05f ; // Default 5 cm ~ 2 inches
273315 MaxPaxUnderbalanceM = 0.075f ; // Default 7.5 cm ~ 3 inches
274316 }
0 commit comments