@@ -594,10 +594,38 @@ public override void Restore(BinaryReader inf)
594
594
595
595
public override void Initialize ( bool handbrakeOn , float maxPressurePSI , float fullServPressurePSI , bool immediateRelease )
596
596
{
597
+ MSTSLocomotive loco = Car as MSTSLocomotive ;
598
+
597
599
BrakeLine1PressurePSI = Car . Train . EqualReservoirPressurePSIorInHg ;
598
600
BrakeLine2PressurePSI = Car . Train . BrakeLine2PressurePSI ;
599
- if ( Car is MSTSLocomotive && Car . Train . LeadLocomotive is MSTSLocomotive lead )
600
- lead . EngineBrakeController ? . UpdateEngineBrakePressure ( ref BrakeLine3PressurePSI , 1000 ) ;
601
+ // Initialize locomotive brakes
602
+ if ( loco != null && Car . Train . LeadLocomotive is MSTSLocomotive lead )
603
+ {
604
+ bool brakeLine3Init = false ;
605
+
606
+ if ( loco == lead ) // Always initialize loco brakes on lead loco
607
+ brakeLine3Init = true ;
608
+ else
609
+ {
610
+ foreach ( List < TrainCar > group in Car . Train . LocoGroups )
611
+ {
612
+ if ( group . Contains ( loco ) )
613
+ {
614
+ if ( group . Contains ( lead ) )
615
+ brakeLine3Init = true ; // Always initialize loco brakes on locos in same group as lead loco
616
+ else if ( loco . DPSyncIndependent && lead . DPSyncIndependent )
617
+ brakeLine3Init = true ; // Otherwise, only initialize loco brakes if synchronized by DP system
618
+
619
+ break ;
620
+ }
621
+ }
622
+ }
623
+
624
+ if ( brakeLine3Init ) // Sync loco brakes with lead brake system
625
+ lead . EngineBrakeController ? . UpdateEngineBrakePressure ( ref BrakeLine3PressurePSI , 1000 ) ;
626
+ else // Release loco brakes
627
+ BrakeLine3PressurePSI = 0.0f ;
628
+ }
601
629
if ( maxPressurePSI > 0 )
602
630
ControlResPressurePSI = maxPressurePSI ;
603
631
@@ -623,7 +651,7 @@ public override void Initialize(bool handbrakeOn, float maxPressurePSI, float fu
623
651
IsolationValve = ValveState . Release ;
624
652
HandbrakePercent = handbrakeOn & HandBrakePresent ? 100 : 0 ;
625
653
SetRetainer ( RetainerSetting . Exhaust ) ;
626
- if ( Car is MSTSLocomotive loco )
654
+ if ( loco != null )
627
655
loco . MainResPressurePSI = loco . MaxMainResPressurePSI ;
628
656
629
657
// Prevent initialization triggering emergency vent valves
0 commit comments