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
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>
Original file line number Diff line number Diff 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 :
Original file line number Diff line number Diff 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 :
You can’t perform that action at this time.
0 commit comments