Skip to content

Commit 01c0838

Browse files
committed
Do not activate ETS switch if no suitable cars are attached
1 parent acd7144 commit 01c0838

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

Source/Orts.Simulation/Common/Scripting/PowerSupply/LocomotivePowerSupply.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,25 @@ protected float ThrottleReductionPercent
207207
/// </summary>
208208
protected float ElectricTrainSupplyPowerW => LpsHost.ElectricTrainSupplyPowerW;
209209

210+
/// <summary>
211+
/// Number of cars that require energy from the electric train supply
212+
/// </summary>
213+
protected int NumberOfElectricTrainSupplyConnectedCars
214+
{
215+
get
216+
{
217+
int count = 0;
218+
foreach (var car in Train.Cars)
219+
{
220+
if (car == null) continue;
221+
if (!(car is MSTSWagon wagon)) continue;
222+
if (!(wagon.PassengerCarPowerSupply?.ElectricTrainSupplyConnectedLocomotives.Contains(Locomotive) ?? false)) continue;
223+
count++;
224+
}
225+
return count;
226+
}
227+
}
228+
210229
/// <summary>
211230
/// Returns the index of the current locomotive in the train (taking into account only locomotives)
212231
/// </summary>

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ public override void Update(float elapsedClockSeconds)
201201
{
202202
QuickPowerOn = false;
203203
SignalEventToTractionCutOffRelay(PowerSupplyEvent.CloseTractionCutOffRelay);
204+
if (NumberOfElectricTrainSupplyConnectedCars > 0) SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.SwitchOnElectricTrainSupply);
204205
}
205206

206207
if (PowerOnTimer.Started)
@@ -215,7 +216,11 @@ public override void Update(float elapsedClockSeconds)
215216

216217
case TractionCutOffRelayState.Closed:
217218
// If traction cut-off relay is closed, quick power-on sequence has finished
218-
QuickPowerOn = false;
219+
if (QuickPowerOn)
220+
{
221+
QuickPowerOn = false;
222+
if (NumberOfElectricTrainSupplyConnectedCars > 0) SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.SwitchOnElectricTrainSupply);
223+
}
219224

220225
if (!PowerOnTimer.Started)
221226
PowerOnTimer.Start();
@@ -311,7 +316,6 @@ public override void HandleEvent(PowerSupplyEvent evt)
311316
SignalEventToBatterySwitch(PowerSupplyEvent.QuickPowerOn);
312317
SignalEventToMasterKey(PowerSupplyEvent.TurnOnMasterKey);
313318
SignalEventToDieselEngines(PowerSupplyEvent.StartEngine);
314-
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.SwitchOnElectricTrainSupply);
315319
break;
316320

317321
case PowerSupplyEvent.QuickPowerOff:

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ public override void Update(float elapsedClockSeconds)
230230
if (QuickPowerOn)
231231
{
232232
QuickPowerOn = false;
233+
if (NumberOfElectricTrainSupplyConnectedCars > 0) SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.SwitchOnElectricTrainSupply);
233234
SignalEventToCircuitBreaker(PowerSupplyEvent.QuickPowerOn);
234235
}
235236

@@ -253,7 +254,11 @@ public override void Update(float elapsedClockSeconds)
253254

254255
case CircuitBreakerState.Closed:
255256
// If circuit breaker is closed, quick power-on sequence has finished
256-
QuickPowerOn = false;
257+
if (QuickPowerOn)
258+
{
259+
QuickPowerOn = false;
260+
if (NumberOfElectricTrainSupplyConnectedCars > 0) SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.SwitchOnElectricTrainSupply);
261+
}
257262

258263
if (!PowerOnTimer.Started)
259264
PowerOnTimer.Start();
@@ -309,7 +314,6 @@ public override void HandleEvent(PowerSupplyEvent evt)
309314
SignalEventToMasterKey(PowerSupplyEvent.TurnOnMasterKey);
310315
SignalEventToPantograph(PowerSupplyEvent.RaisePantograph, 1);
311316
SignalEventToOtherTrainVehiclesWithId(PowerSupplyEvent.RaisePantograph, 1);
312-
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.SwitchOnElectricTrainSupply);
313317
break;
314318

315319
case PowerSupplyEvent.QuickPowerOff:

0 commit comments

Comments
 (0)