@@ -433,6 +433,7 @@ public float OdometerM
433433 public MSTSNotchController DPDynamicBrakeController ;
434434
435435 private int PreviousGearBoxNotch ;
436+ private int previousChangedGearBoxNotch ;
436437
437438 public float EngineBrakeIntervention = - 1 ;
438439 public float TrainBrakeIntervention = - 1 ;
@@ -1265,6 +1266,8 @@ public override void Save(BinaryWriter outf)
12651266 outf . Write ( GenericItem2 ) ;
12661267 outf . Write ( RemoteControlGroup ) ;
12671268 outf . Write ( DPUnitID ) ;
1269+ outf . Write ( PreviousGearBoxNotch ) ;
1270+ outf . Write ( previousChangedGearBoxNotch ) ;
12681271
12691272 base . Save ( outf ) ;
12701273
@@ -1318,6 +1321,8 @@ public override void Restore(BinaryReader inf)
13181321 GenericItem2 = inf . ReadBoolean ( ) ;
13191322 RemoteControlGroup = inf . ReadInt32 ( ) ;
13201323 DPUnitID = inf . ReadInt32 ( ) ;
1324+ PreviousGearBoxNotch = inf . ReadInt32 ( ) ;
1325+ previousChangedGearBoxNotch = inf . ReadInt32 ( ) ;
13211326
13221327 base . Restore ( inf ) ;
13231328
@@ -1820,6 +1825,54 @@ public override void Update(float elapsedClockSeconds)
18201825 }
18211826 }
18221827
1828+ var gearloco = this as MSTSDieselLocomotive ;
1829+
1830+ // Pass Gearbox commands
1831+ // Note - at the moment there is only one GearBox Controller created, but a gearbox for each diesel engine is created.
1832+ // This code keeps all gearboxes in the locomotive aligned with the first engine and gearbox.
1833+ if ( gearloco != null && gearloco . DieselTransmissionType == MSTSDieselLocomotive . DieselTransmissionTypes . Mechanic && GearBoxController . CurrentNotch != previousChangedGearBoxNotch )
1834+ {
1835+ // pass gearbox command key to other gearboxes in the same locomotive, only do the current locomotive
1836+
1837+ if ( gearloco == this )
1838+ {
1839+
1840+ int ii = 0 ;
1841+ foreach ( var eng in gearloco . DieselEngines . DEList )
1842+ {
1843+ // don't change the first engine as this is the reference for all the others
1844+ if ( ii != 0 )
1845+ {
1846+ gearloco . DieselEngines [ ii ] . GearBox . currentGearIndex = gearloco . DieselEngines [ 0 ] . GearBox . CurrentGearIndex ;
1847+ }
1848+
1849+ ii = ii + 1 ;
1850+ }
1851+ }
1852+
1853+ // pass gearbox command key to other locomotives in train, don't treat the player locomotive in this fashion.
1854+ foreach ( TrainCar car in Train . Cars )
1855+ {
1856+ var dieselloco = this as MSTSDieselLocomotive ;
1857+ var locog = car as MSTSDieselLocomotive ;
1858+
1859+ if ( locog != null && dieselloco != null && car != this && ! locog . IsLeadLocomotive ( ) )
1860+ {
1861+
1862+ locog . DieselEngines [ 0 ] . GearBox . currentGearIndex = dieselloco . DieselEngines [ 0 ] . GearBox . CurrentGearIndex ;
1863+
1864+ locog . GearBoxController . CurrentNotch = dieselloco . DieselEngines [ 0 ] . GearBox . CurrentGearIndex + 1 ;
1865+ locog . GearboxGearIndex = dieselloco . DieselEngines [ 0 ] . GearBox . CurrentGearIndex + 1 ;
1866+ locog . GearBoxController . SetValue ( ( float ) dieselloco . GearBoxController . CurrentNotch ) ;
1867+
1868+ locog . Simulator . Confirmer . ConfirmWithPerCent ( CabControl . GearBox , CabSetting . Increase , locog . GearBoxController . CurrentNotch ) ;
1869+ locog . AlerterReset ( TCSEvent . GearBoxChanged ) ;
1870+ locog . SignalGearBoxChangeEvents ( ) ;
1871+ }
1872+ }
1873+
1874+ previousChangedGearBoxNotch = GearBoxController . CurrentNotch ; // reset loop until next gear change
1875+ }
18231876
18241877 TrainControlSystem . Update ( elapsedClockSeconds ) ;
18251878
@@ -2007,7 +2060,6 @@ public override void Update(float elapsedClockSeconds)
20072060 UpdateHornAndBell ( elapsedClockSeconds ) ;
20082061
20092062 UpdateSoundVariables ( elapsedClockSeconds ) ;
2010-
20112063 PrevMotiveForceN = MotiveForceN ;
20122064 base . Update ( elapsedClockSeconds ) ;
20132065
@@ -3579,8 +3631,10 @@ public virtual void StartGearBoxIncrease()
35793631 {
35803632 if ( GearBoxController != null )
35813633 {
3634+
35823635 if ( this is MSTSDieselLocomotive )
35833636 {
3637+
35843638 var dieselloco = this as MSTSDieselLocomotive ;
35853639
35863640 if ( dieselloco . DieselTransmissionType == MSTSDieselLocomotive . DieselTransmissionTypes . Mechanic )
@@ -3589,7 +3643,7 @@ public virtual void StartGearBoxIncrease()
35893643 if ( dieselloco . DieselEngines [ 0 ] . GearBox . GearBoxType != TypesGearBox . C )
35903644 {
35913645 GearBoxController . StartIncrease ( ) ;
3592- Simulator . Confirmer . ConfirmWithPerCent ( CabControl . GearBox , CabSetting . Increase , GearBoxController . CurrentNotch ) ;
3646+ Simulator . Confirmer . ConfirmWithPerCent ( CabControl . GearBox , CabSetting . Increase , dieselloco . DieselEngines [ 0 ] . GearBox . GearIndication ) ;
35933647 AlerterReset ( TCSEvent . GearBoxChanged ) ;
35943648 SignalGearBoxChangeEvents ( ) ;
35953649 dieselloco . DieselEngines [ 0 ] . GearBox . clutchOn = false ;
@@ -3602,7 +3656,7 @@ public virtual void StartGearBoxIncrease()
36023656 if ( ThrottlePercent == 0 )
36033657 {
36043658 GearBoxController . StartIncrease ( ) ;
3605- Simulator . Confirmer . ConfirmWithPerCent ( CabControl . GearBox , CabSetting . Increase , GearBoxController . CurrentNotch ) ;
3659+ Simulator . Confirmer . ConfirmWithPerCent ( CabControl . GearBox , CabSetting . Increase , dieselloco . DieselEngines [ 0 ] . GearBox . GearIndication ) ;
36063660 AlerterReset ( TCSEvent . GearBoxChanged ) ;
36073661 SignalGearBoxChangeEvents ( ) ;
36083662 dieselloco . DieselEngines [ 0 ] . GearBox . clutchOn = false ;
@@ -3652,7 +3706,7 @@ public virtual void StartGearBoxDecrease()
36523706 if ( dieselloco . DieselEngines [ 0 ] . GearBox . GearBoxType != TypesGearBox . C )
36533707 {
36543708 GearBoxController . StartDecrease ( ) ;
3655- Simulator . Confirmer . ConfirmWithPerCent ( CabControl . GearBox , CabSetting . Decrease , GearBoxController . CurrentNotch ) ;
3709+ Simulator . Confirmer . ConfirmWithPerCent ( CabControl . GearBox , CabSetting . Decrease , dieselloco . DieselEngines [ 0 ] . GearBox . GearIndication ) ;
36563710 AlerterReset ( TCSEvent . GearBoxChanged ) ;
36573711 SignalGearBoxChangeEvents ( ) ;
36583712 dieselloco . DieselEngines [ 0 ] . GearBox . clutchOn = false ;
@@ -3663,7 +3717,8 @@ public virtual void StartGearBoxDecrease()
36633717 if ( ThrottlePercent == 0 )
36643718 {
36653719 GearBoxController . StartDecrease ( ) ;
3666- Simulator . Confirmer . ConfirmWithPerCent ( CabControl . GearBox , CabSetting . Decrease , GearBoxController . CurrentNotch ) ;
3720+ Trace . TraceInformation ( "Controller Decrease - Current Notch {0} Indication {1} GearIndex {2}" , GearBoxController . CurrentNotch , dieselloco . DieselEngines [ 0 ] . GearBox . GearIndication , dieselloco . DieselEngines [ 0 ] . GearBox . CurrentGearIndex ) ;
3721+ Simulator . Confirmer . ConfirmWithPerCent ( CabControl . GearBox , CabSetting . Decrease , dieselloco . DieselEngines [ 0 ] . GearBox . GearIndication ) ;
36673722 AlerterReset ( TCSEvent . GearBoxChanged ) ;
36683723 SignalGearBoxChangeEvents ( ) ;
36693724 dieselloco . DieselEngines [ 0 ] . GearBox . clutchOn = false ;
@@ -3746,7 +3801,7 @@ private void SignalGearBoxChangeEvents()
37463801 var dieselloco = this as MSTSDieselLocomotive ;
37473802 if ( change != 0 )
37483803 {
3749- //new GarBoxCommand (Simulator.Log, change > 0, controller.CurrentValue, Simulator.ClockTime);
3804+ //new GearBoxCommand (Simulator.Log, change > 0, controller.CurrentValue, Simulator.ClockTime);
37503805 SignalEvent ( change > 0 ? Event . GearUp : Event . GearDown ) ;
37513806 AlerterReset ( TCSEvent . GearBoxChanged ) ;
37523807 }
@@ -5229,7 +5284,7 @@ public virtual float GetDataOf(CabViewControl cvc)
52295284 {
52305285 var dieselLoco = this as MSTSDieselLocomotive ;
52315286 if ( dieselLoco . DieselEngines . HasGearBox )
5232- data = dieselLoco . DieselEngines [ 0 ] . GearBox . CurrentGearIndex + 1 ;
5287+ data = dieselLoco . DieselEngines [ 0 ] . GearBox . GearIndication ;
52335288 }
52345289 break ;
52355290 }
0 commit comments