Skip to content

Commit dcc1764

Browse files
authored
Merge pull request #1115 from cesarBLG/automatic-ets
Do not activate ETS switch if no suitable cars are attached
2 parents fe3b901 + cb97e1d commit dcc1764

File tree

4 files changed

+52
-9
lines changed

4 files changed

+52
-9
lines changed

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/DieselPowerSupply.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,13 @@ public override void HandleEvent(PowerSupplyEvent evt)
311311
SignalEventToBatterySwitch(PowerSupplyEvent.QuickPowerOn);
312312
SignalEventToMasterKey(PowerSupplyEvent.TurnOnMasterKey);
313313
SignalEventToDieselEngines(PowerSupplyEvent.StartEngine);
314-
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.SwitchOnElectricTrainSupply);
314+
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.QuickPowerOn);
315315
break;
316316

317317
case PowerSupplyEvent.QuickPowerOff:
318318
QuickPowerOn = false;
319-
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.SwitchOffElectricTrainSupply);
320-
SignalEventToTractionCutOffRelay(PowerSupplyEvent.OpenTractionCutOffRelay);
319+
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.QuickPowerOff);
320+
SignalEventToTractionCutOffRelay(PowerSupplyEvent.QuickPowerOff);
321321
SignalEventToDieselEngines(PowerSupplyEvent.StopEngine);
322322
SignalEventToMasterKey(PowerSupplyEvent.TurnOffMasterKey);
323323
SignalEventToBatterySwitch(PowerSupplyEvent.QuickPowerOff);

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/ElectricPowerSupply.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,12 @@ public override void HandleEvent(PowerSupplyEvent evt)
309309
SignalEventToMasterKey(PowerSupplyEvent.TurnOnMasterKey);
310310
SignalEventToPantograph(PowerSupplyEvent.RaisePantograph, 1);
311311
SignalEventToOtherTrainVehiclesWithId(PowerSupplyEvent.RaisePantograph, 1);
312-
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.SwitchOnElectricTrainSupply);
312+
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.QuickPowerOn);
313313
break;
314314

315315
case PowerSupplyEvent.QuickPowerOff:
316316
QuickPowerOn = false;
317-
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.SwitchOffElectricTrainSupply);
317+
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.QuickPowerOff);
318318
SignalEventToCircuitBreaker(PowerSupplyEvent.QuickPowerOff);
319319
SignalEventToPantographs(PowerSupplyEvent.LowerPantograph);
320320
SignalEventToOtherTrainVehicles(PowerSupplyEvent.LowerPantograph);

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/ElectricTrainSupplySwitch.cs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,27 @@ public enum ModeType
3737
readonly MSTSLocomotive Locomotive;
3838
public bool CommandSwitch { get; protected set; } = false;
3939
public bool On { get; protected set; } = false;
40+
public bool QuickPowerOn = false;
41+
private bool firstUpdate = true;
42+
43+
/// <summary>
44+
/// Number of cars that require energy from the electric train supply
45+
/// </summary>
46+
protected int NumberOfElectricTrainSupplyConnectedCars
47+
{
48+
get
49+
{
50+
int count = 0;
51+
foreach (var car in Locomotive.Train.Cars)
52+
{
53+
if (car == null) continue;
54+
if (!(car is MSTSWagon wagon)) continue;
55+
if (!(wagon.PassengerCarPowerSupply?.ElectricTrainSupplyConnectedLocomotives.Contains(Locomotive) ?? false)) continue;
56+
count++;
57+
}
58+
return count;
59+
}
60+
}
4061

4162
public ElectricTrainSupplySwitch(MSTSLocomotive locomotive, ModeType defaultMode = ModeType.Automatic)
4263
{
@@ -122,15 +143,15 @@ public virtual void Update(float elapsedClockSeconds)
122143
case ModeType.Automatic:
123144
if (On)
124145
{
125-
if (!Locomotive.LocomotivePowerSupply.AuxiliaryPowerSupplyOn)
146+
if (!Locomotive.LocomotivePowerSupply.AuxiliaryPowerSupplyOn || NumberOfElectricTrainSupplyConnectedCars == 0)
126147
{
127148
On = false;
128149
Locomotive.SignalEvent(Event.ElectricTrainSupplyOff);
129150
}
130151
}
131152
else
132153
{
133-
if (Locomotive.LocomotivePowerSupply.AuxiliaryPowerSupplyOn)
154+
if (Locomotive.LocomotivePowerSupply.AuxiliaryPowerSupplyOn && NumberOfElectricTrainSupplyConnectedCars > 0)
134155
{
135156
On = true;
136157
Locomotive.SignalEvent(Event.ElectricTrainSupplyOn);
@@ -139,6 +160,19 @@ public virtual void Update(float elapsedClockSeconds)
139160
break;
140161

141162
case ModeType.Switch:
163+
if (QuickPowerOn && !firstUpdate)
164+
{
165+
if (NumberOfElectricTrainSupplyConnectedCars == 0 || CommandSwitch)
166+
{
167+
QuickPowerOn = false;
168+
}
169+
else if (Locomotive.LocomotivePowerSupply.AuxiliaryPowerSupplyOn)
170+
{
171+
QuickPowerOn = false;
172+
CommandSwitch = true;
173+
Locomotive.SignalEvent(Event.ElectricTrainSupplyCommandOn);
174+
}
175+
}
142176
if (On)
143177
{
144178
if (!CommandSwitch || !Locomotive.LocomotivePowerSupply.AuxiliaryPowerSupplyOn)
@@ -157,12 +191,19 @@ public virtual void Update(float elapsedClockSeconds)
157191
}
158192
break;
159193
}
194+
firstUpdate = false;
160195
}
161196

162197
public virtual void HandleEvent(PowerSupplyEvent evt)
163198
{
164199
switch (evt)
165200
{
201+
case PowerSupplyEvent.QuickPowerOn:
202+
if (Mode == ModeType.Switch)
203+
{
204+
QuickPowerOn = true;
205+
}
206+
break;
166207
case PowerSupplyEvent.SwitchOnElectricTrainSupply:
167208
if (Mode == ModeType.Switch)
168209
{
@@ -172,6 +213,8 @@ public virtual void HandleEvent(PowerSupplyEvent evt)
172213
break;
173214

174215
case PowerSupplyEvent.SwitchOffElectricTrainSupply:
216+
case PowerSupplyEvent.QuickPowerOff:
217+
QuickPowerOn = false;
175218
if (Mode == ModeType.Switch)
176219
{
177220
CommandSwitch = false;

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/SteamPowerSupply.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ public override void HandleEvent(PowerSupplyEvent evt)
109109
SignalEventToMasterKey(PowerSupplyEvent.TurnOnMasterKey);
110110
SignalEventToPantograph(PowerSupplyEvent.RaisePantograph, 1);
111111
SignalEventToOtherTrainVehiclesWithId(PowerSupplyEvent.RaisePantograph, 1);
112-
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.SwitchOnElectricTrainSupply);
112+
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.QuickPowerOn);
113113
break;
114114

115115
case PowerSupplyEvent.QuickPowerOff:
116-
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.SwitchOffElectricTrainSupply);
116+
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.QuickPowerOff);
117117
SignalEventToPantographs(PowerSupplyEvent.LowerPantograph);
118118
SignalEventToOtherTrainVehicles(PowerSupplyEvent.LowerPantograph);
119119
SignalEventToMasterKey(PowerSupplyEvent.TurnOffMasterKey);

0 commit comments

Comments
 (0)