@@ -594,10 +594,38 @@ public override void Restore(BinaryReader inf)
594594
595595 public override void Initialize ( bool handbrakeOn , float maxPressurePSI , float fullServPressurePSI , bool immediateRelease )
596596 {
597+ MSTSLocomotive loco = Car as MSTSLocomotive ;
598+
597599 BrakeLine1PressurePSI = Car . Train . EqualReservoirPressurePSIorInHg ;
598600 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+ }
601629 if ( maxPressurePSI > 0 )
602630 ControlResPressurePSI = maxPressurePSI ;
603631
@@ -623,7 +651,7 @@ public override void Initialize(bool handbrakeOn, float maxPressurePSI, float fu
623651 IsolationValve = ValveState . Release ;
624652 HandbrakePercent = handbrakeOn & HandBrakePresent ? 100 : 0 ;
625653 SetRetainer ( RetainerSetting . Exhaust ) ;
626- if ( Car is MSTSLocomotive loco )
654+ if ( loco != null )
627655 loco . MainResPressurePSI = loco . MaxMainResPressurePSI ;
628656
629657 // Prevent initialization triggering emergency vent valves
0 commit comments