Skip to content

Commit 6d52299

Browse files
committed
Add ability to control vacuum brakes and gears to Control Car
1 parent f59d201 commit 6d52299

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@
4242
using System.Text;
4343
using Event = Orts.Common.Event;
4444
using ORTS.Scripting.Api;
45+
using static Orts.Simulation.RollingStocks.MSTSDieselLocomotive;
4546

4647
namespace Orts.Simulation.RollingStocks
4748
{
4849
public class MSTSControlTrailerCar : MSTSLocomotive
4950
{
5051

52+
public int ControlGearBoxNumberOfGears = 1;
53+
54+
5155
public MSTSControlTrailerCar(Simulator simulator, string wagFile)
5256
: base(simulator, wagFile)
5357
{
@@ -96,12 +100,55 @@ public override void Parse(string lowercasetoken, STFReader stf)
96100
LocomotivePowerSupply.Parse(lowercasetoken, stf);
97101
break;
98102

103+
// to setup gearbox controller
104+
case "engine(gearboxnumberofgears": ControlGearBoxNumberOfGears = stf.ReadIntBlock(1); break;
105+
106+
99107
default:
100108
base.Parse(lowercasetoken, stf); break;
101109
}
102110

103111
}
104112

113+
/// <summary>
114+
/// This initializer is called when we are making a new copy of a locomotive already
115+
/// loaded in memory. We use this one to speed up loading by eliminating the
116+
/// need to parse the wag file multiple times.
117+
/// NOTE: you must initialize all the same variables as you parsed above
118+
/// </summary>
119+
public override void Copy(MSTSWagon copy)
120+
{
121+
122+
base.Copy(copy); // each derived level initializes its own variables
123+
124+
MSTSControlTrailerCar locoCopy = (MSTSControlTrailerCar)copy;
125+
126+
ControlGearBoxNumberOfGears = locoCopy.ControlGearBoxNumberOfGears;
127+
128+
129+
}
130+
131+
/// <summary>
132+
/// We are saving the game. Save anything that we'll need to restore the
133+
/// status later.
134+
/// </summary>
135+
public override void Save(BinaryWriter outf)
136+
{
137+
ControllerFactory.Save(GearBoxController, outf);
138+
}
139+
140+
/// <summary>
141+
/// We are restoring a saved game. The TrainCar class has already
142+
/// been initialized. Restore the game state.
143+
/// </summary>
144+
public override void Restore(BinaryReader inf)
145+
{
146+
base.Restore(inf);
147+
ControllerFactory.Restore(GearBoxController, inf);
148+
149+
}
150+
151+
105152
/// <summary>
106153
/// Set starting conditions when initial speed > 0
107154
///
@@ -112,6 +159,14 @@ public override void InitializeMoving()
112159
WheelSpeedMpS = SpeedMpS;
113160

114161
ThrottleController.SetValue(Train.MUThrottlePercent / 100);
162+
163+
// Initialise gearbox controller
164+
if (ControlGearBoxNumberOfGears > 0)
165+
{
166+
GearBoxController = new MSTSNotchController(ControlGearBoxNumberOfGears + 1);
167+
}
168+
169+
115170
}
116171

117172
/// <summary>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,8 +1504,8 @@ public override void Initialize()
15041504
// Initialise Brake Pipe Quick Charging Rate
15051505
if (BrakePipeQuickChargingRatePSIpS == 0) BrakePipeQuickChargingRatePSIpS = BrakePipeChargingRatePSIorInHgpS;
15061506

1507-
// Initialise Exhauster Charging rate in diesel and electric locomotives. The equivalent ejector charging rates are set in the steam locomotive.
1508-
if (this is MSTSDieselLocomotive || this is MSTSElectricLocomotive)
1507+
// Initialise Exhauster Charging rate in diesel, control cars and electric locomotives. The equivalent ejector charging rates are set in the steam locomotive.
1508+
if (this is MSTSDieselLocomotive || this is MSTSElectricLocomotive || this is MSTSControlTrailerCar)
15091509
{
15101510
ExhausterHighSBPChargingRatePSIorInHgpS = BrakePipeChargingRatePSIorInHgpS;
15111511
ExhausterLowSBPChargingRatePSIorInHgpS = BrakePipeChargingRatePSIorInHgpS / 5.0f; // Low speed exhauster setting is 1/5 of high speed

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Brakes/MSTS/VacuumSinglePipe.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,8 +996,9 @@ protected static void PropagateBrakeLinePressures(float elapsedClockSeconds, Tra
996996
// Brake Controller is in Release position - decrease brake pipe value pressure - PSI goes from 14.5 to 4.189 - releasing brakes
997997
else if (lead.TrainBrakeController.TrainBrakeControllerState == ControllerState.Release)
998998
{
999+
9991000
float TrainPipePressureDiffPSI = 0;
1000-
if (lead.EngineType == TrainCar.EngineTypes.Diesel || lead.EngineType == TrainCar.EngineTypes.Electric)
1001+
if (lead.EngineType == TrainCar.EngineTypes.Diesel || lead.EngineType == TrainCar.EngineTypes.Electric || lead.EngineType == TrainCar.EngineTypes.Control)
10011002
{
10021003
// diesel and electric locomotives use vacuum exhauster
10031004
TrainPipePressureDiffPSI = TrainPipeTimeVariationS * EQReleaseNetBPLossGainPSI;

0 commit comments

Comments
 (0)