@@ -503,7 +503,7 @@ public void Initialize()
503503
504504 if ( SpeedDeltaFunctionMode == SpeedDeltaMode . Sqrt ) StartReducingSpeedDeltaDownwards /= 3 ;
505505
506- if ( StartInAutoMode ) SpeedRegMode = SpeedRegulatorMode . Auto ;
506+ if ( StartInAutoMode ) SpeedRegMode = SpeedRegulatorMode . Auto ;
507507
508508 if ( UseThrottleAsForceSelector )
509509 {
@@ -761,7 +761,7 @@ public void Update(float elapsedClockSeconds)
761761 }
762762 else
763763 {
764- CCThrottleOrDynBrakePercent = 0 ;
764+ CCThrottleOrDynBrakePercent = 0 ;
765765 TrainBrakePercent = 0 ;
766766 ThrottlePID . Active = false ;
767767 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 }
@@ -1052,15 +1052,15 @@ public void SpeedRegulatorMaxForceChangeByMouse(float value)
10521052 var oldValue = controller . IntermediateValue ;
10531053 var change = controller . SetValue ( value ) ;
10541054 if ( change != 0 )
1055- {
1056- Locomotive . SignalEvent ( Common . Event . CruiseControlMaxForce ) ;
1057- }
1055+ {
1056+ Locomotive . SignalEvent ( Common . Event . CruiseControlMaxForce ) ;
1057+ }
10581058 if ( oldValue != controller . IntermediateValue )
10591059 Simulator . Confirmer . UpdateWithPerCent (
10601060 CabControl . MaxAcceleration ,
10611061 oldValue < controller . IntermediateValue ? CabSetting . Increase : CabSetting . Decrease ,
10621062 controller . CurrentValue * 100 ) ;
1063- }
1063+ }
10641064 public void SpeedRegulatorSelectedSpeedStartIncrease ( )
10651065 {
10661066 var mpc = Locomotive . MultiPositionControllers . Where ( x =>
@@ -1079,9 +1079,9 @@ public void SpeedRegulatorSelectedSpeedStartIncrease()
10791079 return ;
10801080 }
10811081 if ( SpeedSelectorController . CurrentValue == 0 )
1082- {
1083- Locomotive . SignalEvent ( Common . Event . LeverFromZero ) ;
1084- }
1082+ {
1083+ Locomotive . SignalEvent ( Common . Event . LeverFromZero ) ;
1084+ }
10851085 if ( UseThrottleAsSpeedSelector || HasProportionalSpeedSelector || ( UseThrottleAsForceSelector && mpc == null ) )
10861086 SpeedSelectorController . StartIncrease ( ) ;
10871087 else
@@ -1261,30 +1261,30 @@ public void UpdateRequiredForce(float elapsedClockSeconds, bool tractionAllowed)
12611261 // da/dv = -srsd / 2 / sqrt((vset-v) * srsd) which diverges when v = vset
12621262 if ( SpeedDeltaFunctionMode == SpeedDeltaMode . Sqrt )
12631263 demandedAccelerationMpSS = ( float ) - Math . Sqrt ( - demandedAccelerationMpSS ) ;
1264- }
1264+ }
12651265 else if ( deltaSpeedMpS > SpeedDeltaToStartAcceleratingMpS || ( deltaSpeedMpS > SpeedDeltaToStopAcceleratingMpS && prevDemandedAccelerationMpSS > 0 ) )
12661266 {
12671267 demandedAccelerationMpSS = ( deltaSpeedMpS - SpeedDeltaAcceleratingOffsetMpS ) * StartReducingSpeedDelta ;
12681268 if ( SpeedDeltaFunctionMode == SpeedDeltaMode . Sqrt )
12691269 demandedAccelerationMpSS = ( float ) Math . Sqrt ( demandedAccelerationMpSS ) ;
1270- }
1270+ }
12711271 prevDemandedAccelerationMpSS = demandedAccelerationMpSS ;
12721272 if ( ASCAccelerationMpSS > 0 )
12731273 demandedAccelerationMpSS = MathHelper . Clamp ( demandedAccelerationMpSS + ASCAccelerationMpSS , - MaxDecelerationMpSS , MaxAccelerationMpSS + ASCAccelerationMpSS ) ;
1274- else
1274+ else
12751275 demandedAccelerationMpSS = MathHelper . Clamp ( demandedAccelerationMpSS + ASCAccelerationMpSS , - MaxDecelerationMpSS + ASCAccelerationMpSS , MaxAccelerationMpSS ) ;
12761276
12771277 float totalTractionN = 0 ;
12781278 float totalDynamicBrakeN = 0 ;
12791279 float totalTrainBrakeN = 0 ;
12801280 float totalMassKg = 0 ;
12811281 foreach ( var car in Locomotive . Train . Cars )
1282- {
1282+ {
12831283 if ( car is MSTSLocomotive locomotive )
1284- {
1284+ {
12851285 totalTractionN += locomotive . GetAvailableTractionForceN ( 1 ) ;
12861286 totalDynamicBrakeN += locomotive . GetAvailableDynamicBrakeForceN ( 1 ) ;
1287- }
1287+ }
12881288 totalTrainBrakeN += car . FrictionBrakeBlendingMaxForceN ; // TODO: consider changes with speed
12891289 totalMassKg += car . MassKG ;
12901290 }
@@ -1293,16 +1293,16 @@ public void UpdateRequiredForce(float elapsedClockSeconds, bool tractionAllowed)
12931293 MaxTrainBrakeDecelerationMpSS = totalTrainBrakeN / totalMassKg ;
12941294 float maxThrottleAccelerationMpSS = MaxThrottleAccelerationMpSS ;
12951295 if ( maxThrottleAccelerationMpSS < 0.01f )
1296- {
1296+ {
12971297 float coeff = Math . Max ( MpS . FromMpS ( AbsWheelSpeedMpS , ! SpeedIsMph ) / 100 * 1.2f , 1 ) ;
12981298 maxThrottleAccelerationMpSS = 1.5f / coeff ;
1299- }
1299+ }
13001300 float maxDynamicBrakeDecelerationMpSS = MaxDynamicBrakeDecelerationMpSS ;
13011301 if ( maxDynamicBrakeDecelerationMpSS < 0.01f )
13021302 {
13031303 float coeff = Math . Max ( MpS . FromMpS ( AbsWheelSpeedMpS , ! SpeedIsMph ) / 100 * 1.2f , 1 ) ;
13041304 maxDynamicBrakeDecelerationMpSS = 1.5f / coeff ;
1305- }
1305+ }
13061306 float maxTrainBrakeDecelerationMpSS = MaxTrainBrakeDecelerationMpSS ;
13071307 if ( MaxTrainBrakeDecelerationMpSS < 0.01f )
13081308 {
@@ -1317,36 +1317,36 @@ public void UpdateRequiredForce(float elapsedClockSeconds, bool tractionAllowed)
13171317 {
13181318 float a = AccelerationTable [ SelectedMaxAccelerationStep - 1 ] ;
13191319 if ( a > 0 && a < targetThrottleAccelerationMpSS ) targetThrottleAccelerationMpSS = a ;
1320- }
1320+ }
13211321 float maxThrottlePercent = 0 ;
13221322 if ( tractionAllowed && Locomotive . TrainControlSystem . TractionAuthorization && DynamicBrakePID . Percent <= 0 && TrainBrakePID . Percent <= 0 && ( demandedAccelerationMpSS > 0 || ThrottlePID . Percent > 0 ) )
1323- {
1323+ {
13241324 // Max throttle percent is determined by the force selector
13251325 maxThrottlePercent = SelectedMaxAccelerationStep > 0 && ForceStepsThrottleTable . Count >= SelectedMaxAccelerationStep && ! SpeedRegulatorMaxForcePercentUnits ? ForceStepsThrottleTable [ SelectedMaxAccelerationStep - 1 ] : SelectedMaxAccelerationPercent ;
1326- if ( MaxPowerThreshold > 0 )
1327- {
1326+ if ( MaxPowerThreshold > 0 )
1327+ {
13281328 // Linearly increase max throttle percent until max force is available when speed reaches MaxPowerThreshold
1329- float currentSpeed = MpS . FromMpS ( AbsWheelSpeedMpS , ! SpeedIsMph ) ;
1329+ float currentSpeed = MpS . FromMpS ( AbsWheelSpeedMpS , ! SpeedIsMph ) ;
13301330 float overridePercent = ( 100 * currentSpeed ) / MaxPowerThreshold ;
13311331 maxThrottlePercent = Math . Max ( Math . Min ( overridePercent , 100 ) , maxThrottlePercent ) ;
1332- }
1332+ }
13331333 if ( reducingForce ) maxThrottlePercent = Math . Min ( maxThrottlePercent , PowerReductionValue ) ;
13341334 }
13351335 ThrottlePID . Update ( elapsedClockSeconds , targetThrottleAccelerationMpSS , RelativeAccelerationMpSS , 0 , maxThrottlePercent ) ;
13361336
13371337 float minDynamicBrakePercent = 0 ;
13381338 float maxDynamicBrakePercent = 0 ;
13391339 if ( Locomotive . DynamicBrakeAvailable && UseDynBrake && ThrottlePID . Percent <= 0 && ( demandedAccelerationMpSS < 0 || DynamicBrakePID . Percent > 0 ) )
1340- {
1340+ {
13411341 // If train brake is active, we force dynamic brakes to stay active to give preference to brake release
13421342 minDynamicBrakePercent = CCIsUsingTrainBrake ? MinDynamicBrakePercentWhileUsingTrainBrake : 0 ;
13431343 maxDynamicBrakePercent = DynamicBrakeIsSelectedForceDependant ? SelectedMaxAccelerationPercent : 100 ;
1344- }
1344+ }
13451345 DynamicBrakePID . Update ( elapsedClockSeconds , - demandedAccelerationMpSS , AbsWheelSpeedMpS > 0 ? - RelativeAccelerationMpSS : - demandedAccelerationMpSS , minDynamicBrakePercent , maxDynamicBrakePercent ) ;
13461346 float target = ThrottlePID . Percent - DynamicBrakePID . Percent ;
1347- if ( target > CCThrottleOrDynBrakePercent )
1347+ if ( target > CCThrottleOrDynBrakePercent )
13481348 IncreaseForce ( ref CCThrottleOrDynBrakePercent , elapsedClockSeconds , target ) ;
1349- else if ( target < CCThrottleOrDynBrakePercent )
1349+ else if ( target < CCThrottleOrDynBrakePercent )
13501350 DecreaseForce ( ref CCThrottleOrDynBrakePercent , elapsedClockSeconds , target ) ;
13511351 UpdateTrainBrakePercent ( elapsedClockSeconds , demandedAccelerationMpSS ) ;
13521352 }
0 commit comments