Skip to content

Commit 3d5d238

Browse files
committed
Correct issues with gear controls not being passed to other locomotives
1 parent f143fcc commit 3d5d238

File tree

2 files changed

+43
-35
lines changed

2 files changed

+43
-35
lines changed

Source/Orts.Simulation/Simulation/RollingStocks/MSTSControlTrailerCar.cs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -185,47 +185,50 @@ public override void Update(float elapsedClockSeconds)
185185
WheelSpeedMpS = SpeedMpS; // Set wheel speed for control car, required to make wheels go around.
186186

187187

188-
if (ControllerNumberOfGears > 0 && IsLeadLocomotive())
188+
if (ControllerNumberOfGears > 0 && IsLeadLocomotive() && GearBoxController != null)
189189
{
190-
// pass gearbox command key to other locomotives in train, don't treat the player locomotive in this fashion.
190+
// Pass gearbox command key to other locomotives in train, don't treat the player locomotive in this fashion.
191+
// This assumes that Contol cars have been "matched" with motor cars. Also return values will be on thebasis of the last motor car in the train.
192+
191193
foreach (TrainCar car in Train.Cars)
192194
{
193-
194-
195195
var locog = car as MSTSDieselLocomotive;
196196

197-
if (locog != null && car != this && !locog.IsLeadLocomotive() && GearBoxController != null)
197+
if (locog != null && car != this && !locog.IsLeadLocomotive() && (ControlGearDown || ControlGearUp))
198198
{
199199

200200
if (ControlGearUp)
201201
{
202-
202+
203203
locog.GearBoxController.CurrentNotch = GearBoxController.CurrentNotch;
204204
locog.GearBoxController.SetValue((float)locog.GearBoxController.CurrentNotch);
205205

206-
locog.ChangeGearUp();
207-
208-
ControlGearUp = false;
206+
locog.ChangeGearUp();
209207
}
210208

211-
212209
if (ControlGearDown)
213210
{
214211

215212
locog.GearBoxController.CurrentNotch = GearBoxController.CurrentNotch;
216213
locog.GearBoxController.SetValue((float)locog.GearBoxController.CurrentNotch);
217214

218-
locog.ChangeGearDown();
219-
220-
ControlGearDown = false;
215+
locog.ChangeGearDown();
221216
}
217+
}
222218

223-
// Read values for the HuD
219+
// Read values for the HuD, will be based upon the last motorcar
220+
if (locog != null)
221+
{
224222
ControlGearIndex = locog.DieselEngines[0].GearBox.CurrentGearIndex;
225223
ControlGearIndication = locog.DieselEngines[0].GearBox.GearIndication;
226224
}
227-
228225
}
226+
227+
228+
// Rest gear flags once all the cars have been processed
229+
ControlGearUp = false;
230+
ControlGearDown = false;
231+
229232
}
230233

231234
}

Source/Orts.Simulation/Simulation/RollingStocks/MSTSLocomotive.cs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,42 +1828,47 @@ public override void Update(float elapsedClockSeconds)
18281828
var gearloco = this as MSTSDieselLocomotive;
18291829

18301830
// Pass Gearbox commands
1831+
1832+
1833+
1834+
18311835
// Note - at the moment there is only one GearBox Controller created, but a gearbox for each diesel engine is created.
18321836
// 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 && IsLeadLocomotive())
1837+
if (gearloco != null && gearloco.DieselTransmissionType == MSTSDieselLocomotive.DieselTransmissionTypes.Mechanic && GearBoxController.CurrentNotch != previousChangedGearBoxNotch)
18341838
{
1835-
// pass gearbox command key to other gearboxes in the same locomotive, only do the current locomotive
1839+
// pass gearbox command key to other gearboxes in the same locomotive, only do the current locomotive
18361840

1837-
if (gearloco == this)
1841+
int ii = 0;
1842+
foreach (var eng in gearloco.DieselEngines.DEList)
18381843
{
1839-
1840-
int ii = 0;
1841-
foreach (var eng in gearloco.DieselEngines.DEList)
1844+
// don't change the first engine as this is the reference for all the others
1845+
if (ii != 0)
18421846
{
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;
1847+
gearloco.DieselEngines[ii].GearBox.currentGearIndex = gearloco.DieselEngines[0].GearBox.CurrentGearIndex;
18501848
}
1849+
1850+
ii = ii + 1;
18511851
}
18521852

1853-
// pass gearbox command key to other locomotives in train, don't treat the player locomotive in this fashion.
1853+
}
1854+
1855+
// The lead locomotive passes gearbox commands position to other locomotives in train, don't treat the player locomotive in this fashion.
1856+
1857+
if (gearloco != null && gearloco.DieselTransmissionType == MSTSDieselLocomotive.DieselTransmissionTypes.Mechanic && GearBoxController.CurrentNotch != previousChangedGearBoxNotch && IsLeadLocomotive())
1858+
{
1859+
18541860
foreach (TrainCar car in Train.Cars)
18551861
{
1856-
var dieselloco = this as MSTSDieselLocomotive;
18571862
var locog = car as MSTSDieselLocomotive;
18581863

1859-
if (locog != null && dieselloco != null && car != this && !locog.IsLeadLocomotive())
1864+
if (locog != null && gearloco != null && car != this && !locog.IsLeadLocomotive())
18601865
{
18611866

1862-
locog.DieselEngines[0].GearBox.currentGearIndex = dieselloco.DieselEngines[0].GearBox.CurrentGearIndex;
1867+
locog.DieselEngines[0].GearBox.currentGearIndex = gearloco.DieselEngines[0].GearBox.CurrentGearIndex;
18631868

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);
1869+
locog.GearBoxController.CurrentNotch = gearloco.DieselEngines[0].GearBox.CurrentGearIndex + 1;
1870+
locog.GearboxGearIndex = gearloco.DieselEngines[0].GearBox.CurrentGearIndex + 1;
1871+
locog.GearBoxController.SetValue((float)gearloco.GearBoxController.CurrentNotch);
18671872

18681873
locog.Simulator.Confirmer.ConfirmWithPerCent(CabControl.GearBox, CabSetting.Increase, locog.GearBoxController.CurrentNotch);
18691874
locog.AlerterReset(TCSEvent.GearBoxChanged);

0 commit comments

Comments
 (0)