@@ -502,7 +502,7 @@ public void Initialize()
502502
503503 if ( SpeedDeltaFunctionMode == SpeedDeltaMode . Sqrt ) StartReducingSpeedDeltaDownwards /= 3 ;
504504
505- if ( StartInAutoMode ) SpeedRegMode = SpeedRegulatorMode . Auto ;
505+ if ( StartInAutoMode ) SpeedRegMode = SpeedRegulatorMode . Auto ;
506506
507507 if ( UseThrottleAsForceSelector )
508508 {
@@ -760,7 +760,7 @@ public void Update(float elapsedClockSeconds)
760760 }
761761 else
762762 {
763- CCThrottleOrDynBrakePercent = 0 ;
763+ CCThrottleOrDynBrakePercent = 0 ;
764764 TrainBrakePercent = null ;
765765 ThrottlePID . Active = false ;
766766 DynamicBrakePID . Active = false ;
@@ -778,7 +778,7 @@ public void Update(float elapsedClockSeconds)
778778 EngineBrakePercent = ParkingBrakePercent ;
779779 }
780780 else
781- {
781+ {
782782 EngineBrakePercent = 0 ;
783783 }
784784 }
@@ -1057,15 +1057,15 @@ public void SpeedRegulatorMaxForceChangeByMouse(float value)
10571057 var oldValue = controller . IntermediateValue ;
10581058 var change = controller . SetValue ( value ) ;
10591059 if ( change != 0 )
1060- {
1061- Locomotive . SignalEvent ( Common . Event . CruiseControlMaxForce ) ;
1062- }
1060+ {
1061+ Locomotive . SignalEvent ( Common . Event . CruiseControlMaxForce ) ;
1062+ }
10631063 if ( oldValue != controller . IntermediateValue )
10641064 Simulator . Confirmer . UpdateWithPerCent (
10651065 CabControl . MaxAcceleration ,
10661066 oldValue < controller . IntermediateValue ? CabSetting . Increase : CabSetting . Decrease ,
10671067 controller . CurrentValue * 100 ) ;
1068- }
1068+ }
10691069 public void SpeedRegulatorSelectedSpeedStartIncrease ( )
10701070 {
10711071 var mpc = Locomotive . MultiPositionControllers . Where ( x =>
@@ -1084,9 +1084,9 @@ public void SpeedRegulatorSelectedSpeedStartIncrease()
10841084 return ;
10851085 }
10861086 if ( SpeedSelectorController . CurrentValue == 0 )
1087- {
1088- Locomotive . SignalEvent ( Common . Event . LeverFromZero ) ;
1089- }
1087+ {
1088+ Locomotive . SignalEvent ( Common . Event . LeverFromZero ) ;
1089+ }
10901090 if ( UseThrottleAsSpeedSelector || HasProportionalSpeedSelector || ( UseThrottleAsForceSelector && mpc == null ) )
10911091 SpeedSelectorController . StartIncrease ( ) ;
10921092 else
@@ -1266,30 +1266,30 @@ public void UpdateRequiredForce(float elapsedClockSeconds, bool tractionAllowed)
12661266 // da/dv = -srsd / 2 / sqrt((vset-v) * srsd) which diverges when v = vset
12671267 if ( SpeedDeltaFunctionMode == SpeedDeltaMode . Sqrt )
12681268 demandedAccelerationMpSS = ( float ) - Math . Sqrt ( - demandedAccelerationMpSS ) ;
1269- }
1269+ }
12701270 else if ( deltaSpeedMpS > SpeedDeltaToStartAcceleratingMpS || ( deltaSpeedMpS > SpeedDeltaToStopAcceleratingMpS && prevDemandedAccelerationMpSS > 0 ) )
12711271 {
12721272 demandedAccelerationMpSS = ( deltaSpeedMpS - SpeedDeltaAcceleratingOffsetMpS ) * StartReducingSpeedDelta ;
12731273 if ( SpeedDeltaFunctionMode == SpeedDeltaMode . Sqrt )
12741274 demandedAccelerationMpSS = ( float ) Math . Sqrt ( demandedAccelerationMpSS ) ;
1275- }
1275+ }
12761276 prevDemandedAccelerationMpSS = demandedAccelerationMpSS ;
12771277 if ( ASCAccelerationMpSS > 0 )
12781278 demandedAccelerationMpSS = MathHelper . Clamp ( demandedAccelerationMpSS + ASCAccelerationMpSS , - MaxDecelerationMpSS , MaxAccelerationMpSS + ASCAccelerationMpSS ) ;
1279- else
1279+ else
12801280 demandedAccelerationMpSS = MathHelper . Clamp ( demandedAccelerationMpSS + ASCAccelerationMpSS , - MaxDecelerationMpSS + ASCAccelerationMpSS , MaxAccelerationMpSS ) ;
12811281
12821282 float totalTractionN = 0 ;
12831283 float totalDynamicBrakeN = 0 ;
12841284 float totalTrainBrakeN = 0 ;
12851285 float totalMassKg = 0 ;
12861286 foreach ( var car in Locomotive . Train . Cars )
1287- {
1287+ {
12881288 if ( car is MSTSLocomotive locomotive )
1289- {
1289+ {
12901290 totalTractionN += locomotive . GetAvailableTractionForceN ( 1 ) ;
12911291 totalDynamicBrakeN += locomotive . GetAvailableDynamicBrakeForceN ( 1 ) ;
1292- }
1292+ }
12931293 totalTrainBrakeN += car . FrictionBrakeBlendingMaxForceN ; // TODO: consider changes with speed
12941294 totalMassKg += car . MassKG ;
12951295 }
@@ -1298,16 +1298,16 @@ public void UpdateRequiredForce(float elapsedClockSeconds, bool tractionAllowed)
12981298 MaxTrainBrakeDecelerationMpSS = totalTrainBrakeN / totalMassKg ;
12991299 float maxThrottleAccelerationMpSS = MaxThrottleAccelerationMpSS ;
13001300 if ( maxThrottleAccelerationMpSS < 0.01f )
1301- {
1301+ {
13021302 float coeff = Math . Max ( MpS . FromMpS ( AbsWheelSpeedMpS , ! SpeedIsMph ) / 100 * 1.2f , 1 ) ;
13031303 maxThrottleAccelerationMpSS = 1.5f / coeff ;
1304- }
1304+ }
13051305 float maxDynamicBrakeDecelerationMpSS = MaxDynamicBrakeDecelerationMpSS ;
13061306 if ( maxDynamicBrakeDecelerationMpSS < 0.01f )
13071307 {
13081308 float coeff = Math . Max ( MpS . FromMpS ( AbsWheelSpeedMpS , ! SpeedIsMph ) / 100 * 1.2f , 1 ) ;
13091309 maxDynamicBrakeDecelerationMpSS = 1.5f / coeff ;
1310- }
1310+ }
13111311 float maxTrainBrakeDecelerationMpSS = MaxTrainBrakeDecelerationMpSS ;
13121312 if ( MaxTrainBrakeDecelerationMpSS < 0.01f )
13131313 {
@@ -1322,36 +1322,36 @@ public void UpdateRequiredForce(float elapsedClockSeconds, bool tractionAllowed)
13221322 {
13231323 float a = AccelerationTable [ SelectedMaxAccelerationStep - 1 ] ;
13241324 if ( a > 0 && a < targetThrottleAccelerationMpSS ) targetThrottleAccelerationMpSS = a ;
1325- }
1325+ }
13261326 float maxThrottlePercent = 0 ;
13271327 if ( tractionAllowed && Locomotive . TrainControlSystem . TractionAuthorization && DynamicBrakePID . Percent <= 0 && TrainBrakePID . Percent <= 0 && ( demandedAccelerationMpSS > 0 || ThrottlePID . Percent > 0 ) )
1328- {
1328+ {
13291329 // Max throttle percent is determined by the force selector
13301330 maxThrottlePercent = SelectedMaxAccelerationStep > 0 && ForceStepsThrottleTable . Count >= SelectedMaxAccelerationStep && ! SpeedRegulatorMaxForcePercentUnits ? ForceStepsThrottleTable [ SelectedMaxAccelerationStep - 1 ] : SelectedMaxAccelerationPercent ;
1331- if ( MaxPowerThreshold > 0 )
1332- {
1331+ if ( MaxPowerThreshold > 0 )
1332+ {
13331333 // Linearly increase max throttle percent until max force is available when speed reaches MaxPowerThreshold
1334- float currentSpeed = MpS . FromMpS ( AbsWheelSpeedMpS , ! SpeedIsMph ) ;
1334+ float currentSpeed = MpS . FromMpS ( AbsWheelSpeedMpS , ! SpeedIsMph ) ;
13351335 float overridePercent = ( 100 * currentSpeed ) / MaxPowerThreshold ;
13361336 maxThrottlePercent = Math . Max ( Math . Min ( overridePercent , 100 ) , maxThrottlePercent ) ;
1337- }
1337+ }
13381338 if ( reducingForce ) maxThrottlePercent = Math . Min ( maxThrottlePercent , PowerReductionValue ) ;
13391339 }
13401340 ThrottlePID . Update ( elapsedClockSeconds , targetThrottleAccelerationMpSS , RelativeAccelerationMpSS , 0 , maxThrottlePercent ) ;
13411341
13421342 float minDynamicBrakePercent = 0 ;
13431343 float maxDynamicBrakePercent = 0 ;
13441344 if ( Locomotive . DynamicBrakeAvailable && UseDynBrake && ThrottlePID . Percent <= 0 && ( demandedAccelerationMpSS < 0 || DynamicBrakePID . Percent > 0 ) )
1345- {
1345+ {
13461346 // If train brake is active, we force dynamic brakes to stay active to give preference to brake release
13471347 minDynamicBrakePercent = CCIsUsingTrainBrake ? MinDynamicBrakePercentWhileUsingTrainBrake : 0 ;
13481348 maxDynamicBrakePercent = DynamicBrakeIsSelectedForceDependant ? SelectedMaxAccelerationPercent : 100 ;
1349- }
1349+ }
13501350 DynamicBrakePID . Update ( elapsedClockSeconds , - demandedAccelerationMpSS , AbsWheelSpeedMpS > 0 ? - RelativeAccelerationMpSS : - demandedAccelerationMpSS , minDynamicBrakePercent , maxDynamicBrakePercent ) ;
13511351 float target = ThrottlePID . Percent - DynamicBrakePID . Percent ;
1352- if ( target > CCThrottleOrDynBrakePercent )
1352+ if ( target > CCThrottleOrDynBrakePercent )
13531353 IncreaseForce ( ref CCThrottleOrDynBrakePercent , elapsedClockSeconds , target ) ;
1354- else if ( target < CCThrottleOrDynBrakePercent )
1354+ else if ( target < CCThrottleOrDynBrakePercent )
13551355 DecreaseForce ( ref CCThrottleOrDynBrakePercent , elapsedClockSeconds , target ) ;
13561356 UpdateTrainBrakePercent ( elapsedClockSeconds , demandedAccelerationMpSS ) ;
13571357 }
0 commit comments