Skip to content

Commit f59d201

Browse files
authored
Merge pull request #677 from peternewell/diesel-mechanic#4
Correct double heading bug
2 parents cf1e833 + c1c417f commit f59d201

File tree

5 files changed

+175
-37
lines changed

5 files changed

+175
-37
lines changed

Source/Documentation/Manual/physics.rst

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ needs to be set to "Mechanic".
696696

697697
Two ORTS mechanical gearbox configurations can be set up.
698698

699-
These two gearboxes can be selected by the use of the following parameter:
699+
These three gearboxes can be selected by the use of the following parameter:
700700

701701
``ORTSGearBoxType ( A )`` - represents a semi-automatic pre-selector gearbox that gives
702702
a continuous power output that is not interrupted when changing gears.
@@ -706,6 +706,9 @@ although there is a break in tractive effort when changing from one gear to anot
706706
the engine speed is reduced by a shaft brake if needed, so that there is no need for
707707
the driver to adjust the throttle.
708708

709+
``ORTSGearBoxType ( C )`` - represents a semi-automatic pre-selector type gear box where
710+
there is a need for the driver to adjust the throttle before making a gear change.
711+
709712
One of three possible types of main clutch are selectable for each of the above gear box
710713
types, as follows:
711714

@@ -726,14 +729,20 @@ to coast with the engine in gear.
726729

727730
``GearBoxNumberOfGears`` - The number of gears available in the gear box.
728731

729-
Currently only a BASIC model configuration is available (ie no user defined traction curves or
730-
diesel engine curves are supported). OR calculates the tractive force curves for each gear based
732+
Currently a BASIC model configuration is available (ie no user defined traction curves or
733+
diesel engine curves are supported), or an ADVANCED configuration (ie the user defines the diesel engine
734+
parameters including the torque curve. Two diesel engines of the same type can be installed on the same
735+
locomotive or railcar using the advanced diesel engine block. Where two engines are installed it is
736+
assumed they will each drive a separate axle or bogie via a separate, identical gear box. Two or more
737+
locomotives or power cars in the same consist should also now operate correctly.
738+
739+
OR calculates the tractive force curves for each gear based
731740
on the "inbuilt" torque curve of a typical diesel engine.
732741

733742
``GearBoxMaxSpeedForGears`` - sets the maximum speed for each gear, corresponding to maximum engine
734743
rpm and maximum power . As an example, the values for a typical British Railways first generation dmu are:
735744

736-
GearBoxMaxSpeedForGears( 15.3 27 41 65.5 ) The default values are in mph, although other units can be entered.
745+
``GearBoxMaxSpeedForGears( 15.3 27 41 65.5 )`` - The default values are in mph, although other units can be entered.
737746
In the above case the maximum permitted speed of the train is 70 mph; a small amount of ‘overspeed’ being allowed
738747
in top gear. The fourth gear speed of 65.5 mph corresponds to the maximum engine rpm set in the eng file by
739748
``DieselEngineMaxRPM``. The diesel engine may continue to ‘runaway’ above its normal ‘maximum speed’ until it
@@ -746,10 +755,15 @@ ORTSDieselEngineGovenorRpM ( 2000 )
746755

747756
If under any circumstances the engine reaches ``ORTSDieselEngineGovenorRpM`` then the diesel engine will automatically be shut down.
748757

749-
"ORTSGearBoxTractiveForceAtSpeed" - The tractive force available in each gear at the speed indicated in GearBoxMaxSpeedForGears. Units
758+
``ORTSGearBoxTractiveForceAtSpeed`` - The tractive force available in each gear at the speed indicated in GearBoxMaxSpeedForGears. Units
750759
by default are in N, however lbf, N or kN. Published values for tractive effort of geared locomotives and multiple units
751760
are generally those at the maximum speed for each gear.
752761

762+
``ORTSReverseGearboxIndication`` - Some gearboxes have a "reverse" gearing arrangement, ie N-4-3-2-1. This parameter allows the
763+
gear selector to display gears in the correct order for this type of gearbox arrangement. If using this parameter, note in the
764+
above example that ``GearBoxMaxSpeedForGears`` and ``ORTSGearBoxTractiveForceatSpeed`` need to list the gears in the order 4-3-2-1
765+
rather than in ascending order.
766+
753767
Hence a typical gear configuration for a diesel mechanic locomotive might look like the following:
754768

755769
ORTSDieselTransmissionType ( Mechanic )

Source/Orts.Simulation/Simulation/RollingStocks/MSTSDieselLocomotive.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// COPYRIGHT 2009, 2010, 2011, 2012, 2013 by the Open Rails project.
1+
// COPYRIGHT 2009, 2010, 2011, 2012, 2013 by the Open Rails project.
22
//
33
// This file is part of Open Rails.
44
//
@@ -189,6 +189,7 @@ public override void Parse(string lowercasetoken, STFReader stf)
189189
break;
190190
case "engine(ortsdieselengines":
191191
case "engine(gearboxnumberofgears":
192+
case "engine(ortsreversegearboxindication":
192193
case "engine(gearboxdirectdrivegear":
193194
case "engine(ortsmainclutchtype":
194195
case "engine(ortsgearboxtype":
@@ -851,7 +852,7 @@ public override float GetDataOf(CabViewControl cvc)
851852
{
852853
case CABViewControlTypes.GEARS:
853854
if (DieselEngines.HasGearBox)
854-
data = DieselEngines[0].GearBox.CurrentGearIndex + 1;
855+
data = DieselEngines[0].GearBox.GearIndication;
855856
break;
856857

857858
case CABViewControlTypes.FUEL_GAUGE:
@@ -937,7 +938,7 @@ public override string GetStatus()
937938
Simulator.Catalog.GetParticularString("Engine", GetStringAttribute.GetPrettyName(DieselEngines[0].State)));
938939
if (DieselEngines.HasGearBox)
939940
status.AppendFormat("{0} = {1}\n", Simulator.Catalog.GetString("Gear"),
940-
DieselEngines[0].GearBox.CurrentGearIndex < 0 ? Simulator.Catalog.GetParticularString("Gear", "N") : (DieselEngines[0].GearBox.CurrentGearIndex + 1).ToString());
941+
DieselEngines[0].GearBox.CurrentGearIndex < 0 ? Simulator.Catalog.GetParticularString("Gear", "N") : (DieselEngines[0].GearBox.GearIndication).ToString());
941942
status.AppendLine();
942943
status.AppendFormat("{0} = {1}\n",
943944
Simulator.Catalog.GetString("Battery switch"),
@@ -964,7 +965,7 @@ public override string GetDebugStatus()
964965

965966
if (DieselEngines.HasGearBox && DieselTransmissionType == DieselTransmissionTypes.Mechanic)
966967
{
967-
status.AppendFormat("\t{0} {1}-{2}", Simulator.Catalog.GetString("Gear"), DieselEngines[0].GearBox.CurrentGearIndex < 0 ? Simulator.Catalog.GetString("N") : (DieselEngines[0].GearBox.CurrentGearIndex + 1).ToString(), DieselEngines[0].GearBox.GearBoxType);
968+
status.AppendFormat("\t{0} {1}-{2}", Simulator.Catalog.GetString("Gear"), DieselEngines[0].GearBox.CurrentGearIndex < 0 ? Simulator.Catalog.GetString("N") : (DieselEngines[0].GearBox.GearIndication).ToString(), DieselEngines[0].GearBox.GearBoxType);
968969
}
969970
status.AppendFormat("\t{0} {1}\t\t{2}\n",
970971
Simulator.Catalog.GetString("Fuel"),

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

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)