File tree Expand file tree Collapse file tree 3 files changed +31
-4
lines changed
Common/Scripting/PowerSupply
Simulation/RollingStocks/SubSystems/PowerSupplies Expand file tree Collapse file tree 3 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -207,6 +207,25 @@ protected float ThrottleReductionPercent
207
207
/// </summary>
208
208
protected float ElectricTrainSupplyPowerW => LpsHost . ElectricTrainSupplyPowerW ;
209
209
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
+
210
229
/// <summary>
211
230
/// Returns the index of the current locomotive in the train (taking into account only locomotives)
212
231
/// </summary>
Original file line number Diff line number Diff line change @@ -201,6 +201,7 @@ public override void Update(float elapsedClockSeconds)
201
201
{
202
202
QuickPowerOn = false ;
203
203
SignalEventToTractionCutOffRelay ( PowerSupplyEvent . CloseTractionCutOffRelay ) ;
204
+ if ( NumberOfElectricTrainSupplyConnectedCars > 0 ) SignalEventToElectricTrainSupplySwitch ( PowerSupplyEvent . SwitchOnElectricTrainSupply ) ;
204
205
}
205
206
206
207
if ( PowerOnTimer . Started )
@@ -215,7 +216,11 @@ public override void Update(float elapsedClockSeconds)
215
216
216
217
case TractionCutOffRelayState . Closed :
217
218
// 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
+ }
219
224
220
225
if ( ! PowerOnTimer . Started )
221
226
PowerOnTimer . Start ( ) ;
@@ -311,7 +316,6 @@ public override void HandleEvent(PowerSupplyEvent evt)
311
316
SignalEventToBatterySwitch ( PowerSupplyEvent . QuickPowerOn ) ;
312
317
SignalEventToMasterKey ( PowerSupplyEvent . TurnOnMasterKey ) ;
313
318
SignalEventToDieselEngines ( PowerSupplyEvent . StartEngine ) ;
314
- SignalEventToElectricTrainSupplySwitch ( PowerSupplyEvent . SwitchOnElectricTrainSupply ) ;
315
319
break ;
316
320
317
321
case PowerSupplyEvent . QuickPowerOff :
Original file line number Diff line number Diff line change @@ -230,6 +230,7 @@ public override void Update(float elapsedClockSeconds)
230
230
if ( QuickPowerOn )
231
231
{
232
232
QuickPowerOn = false ;
233
+ if ( NumberOfElectricTrainSupplyConnectedCars > 0 ) SignalEventToElectricTrainSupplySwitch ( PowerSupplyEvent . SwitchOnElectricTrainSupply ) ;
233
234
SignalEventToCircuitBreaker ( PowerSupplyEvent . QuickPowerOn ) ;
234
235
}
235
236
@@ -253,7 +254,11 @@ public override void Update(float elapsedClockSeconds)
253
254
254
255
case CircuitBreakerState . Closed :
255
256
// 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
+ }
257
262
258
263
if ( ! PowerOnTimer . Started )
259
264
PowerOnTimer . Start ( ) ;
@@ -309,7 +314,6 @@ public override void HandleEvent(PowerSupplyEvent evt)
309
314
SignalEventToMasterKey ( PowerSupplyEvent . TurnOnMasterKey ) ;
310
315
SignalEventToPantograph ( PowerSupplyEvent . RaisePantograph , 1 ) ;
311
316
SignalEventToOtherTrainVehiclesWithId ( PowerSupplyEvent . RaisePantograph , 1 ) ;
312
- SignalEventToElectricTrainSupplySwitch ( PowerSupplyEvent . SwitchOnElectricTrainSupply ) ;
313
317
break ;
314
318
315
319
case PowerSupplyEvent . QuickPowerOff :
You can’t perform that action at this time.
0 commit comments