Skip to content

Commit fbe9f5c

Browse files
committed
Automatic merge of T1.6-104-gfe3b901f2 and 13 pull requests
- Pull request #1156 at f46d5f2: Fix incorrectly disabled options in train operations window - Pull request #1091 at 492795a: Automatic speed control - Pull request #1115 at cb97e1d: Do not activate ETS switch if no suitable cars are attached - Pull request #1120 at ba3c47f: Automatically Calculate Friction Values if Missing - Pull request #1121 at 91d2d26: Manually Override Articulation - Pull request #1124 at e241a0d: Built-in PBL2 brake controller - Pull request #1157 at 39cd994: Dynamic brake authorization by TCS - Pull request #1159 at 48c9a63: Skip OR warnings about TSRE-specific token Ruler - Pull request #1161 at 6cfe4e2: Fix string trim in .ini files - Pull request #1162 at 2516cce: specifies precedence of DDS over ACE - Pull request #1082 at 5845a1a: Allow variable water level in glass gauge - Pull request #1128 at 1d7643d: Particle Emitter Overhaul - Pull request #1160 at c45a926: Route Based TTrack Sounds
15 parents c258b50 + fe3b901 + f46d5f2 + 492795a + cb97e1d + ba3c47f + 91d2d26 + e241a0d + 39cd994 + 48c9a63 + 6cfe4e2 + 2516cce + 5845a1a + 1d7643d + c45a926 commit fbe9f5c

File tree

5 files changed

+64
-50
lines changed

5 files changed

+64
-50
lines changed

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -207,25 +207,6 @@ 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-
229210
/// <summary>
230211
/// Returns the index of the current locomotive in the train (taking into account only locomotives)
231212
/// </summary>

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public class DefaultDieselPowerSupply : DieselPowerSupply
150150
/// </remarks>
151151
private DieselEngineState PreviousSecondEngineState;
152152

153-
private (bool CloseTractionCutOffRelay, bool SwitchOnElectricTrainSupply) QuickPowerOn = (false, false);
153+
private bool QuickPowerOn = false;
154154

155155
public override void Initialize()
156156
{
@@ -197,9 +197,9 @@ public override void Update(float elapsedClockSeconds)
197197
{
198198
case TractionCutOffRelayState.Open:
199199
// If traction cut-off relay is open, then it must be closed to finish the quick power-on sequence
200-
if (QuickPowerOn.CloseTractionCutOffRelay)
200+
if (QuickPowerOn)
201201
{
202-
QuickPowerOn.CloseTractionCutOffRelay = false;
202+
QuickPowerOn = false;
203203
SignalEventToTractionCutOffRelay(PowerSupplyEvent.CloseTractionCutOffRelay);
204204
}
205205

@@ -215,7 +215,7 @@ public override void Update(float elapsedClockSeconds)
215215

216216
case TractionCutOffRelayState.Closed:
217217
// If traction cut-off relay is closed, quick power-on sequence has finished
218-
if (QuickPowerOn.CloseTractionCutOffRelay) QuickPowerOn.CloseTractionCutOffRelay = false;
218+
QuickPowerOn = false;
219219

220220
if (!PowerOnTimer.Started)
221221
PowerOnTimer.Start();
@@ -235,12 +235,6 @@ public override void Update(float elapsedClockSeconds)
235235
{
236236
SignalEvent(Event.PowerConverterOn);
237237
SetCurrentAuxiliaryPowerSupplyState(PowerSupplyState.PowerOn);
238-
239-
if (QuickPowerOn.SwitchOnElectricTrainSupply)
240-
{
241-
QuickPowerOn.SwitchOnElectricTrainSupply = false;
242-
if (NumberOfElectricTrainSupplyConnectedCars > 0) SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.SwitchOnElectricTrainSupply);
243-
}
244238
}
245239
break;
246240
}
@@ -313,16 +307,17 @@ public override void HandleEvent(PowerSupplyEvent evt)
313307
switch (evt)
314308
{
315309
case PowerSupplyEvent.QuickPowerOn:
316-
QuickPowerOn = (true, true);
310+
QuickPowerOn = true;
317311
SignalEventToBatterySwitch(PowerSupplyEvent.QuickPowerOn);
318312
SignalEventToMasterKey(PowerSupplyEvent.TurnOnMasterKey);
319313
SignalEventToDieselEngines(PowerSupplyEvent.StartEngine);
314+
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.QuickPowerOn);
320315
break;
321316

322317
case PowerSupplyEvent.QuickPowerOff:
323-
QuickPowerOn = (false, false);
324-
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.SwitchOffElectricTrainSupply);
325-
SignalEventToTractionCutOffRelay(PowerSupplyEvent.OpenTractionCutOffRelay);
318+
QuickPowerOn = false;
319+
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.QuickPowerOff);
320+
SignalEventToTractionCutOffRelay(PowerSupplyEvent.QuickPowerOff);
326321
SignalEventToDieselEngines(PowerSupplyEvent.StopEngine);
327322
SignalEventToMasterKey(PowerSupplyEvent.TurnOffMasterKey);
328323
SignalEventToBatterySwitch(PowerSupplyEvent.QuickPowerOff);

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public class DefaultElectricPowerSupply : ElectricPowerSupply
176176
private Timer PowerOnTimer;
177177
private Timer AuxPowerOnTimer;
178178

179-
private (bool CloseCircuitBreaker, bool SwitchOnElectricTrainSupply) QuickPowerOn;
179+
private bool QuickPowerOn = false;
180180

181181
public override void Initialize()
182182
{
@@ -227,9 +227,9 @@ public override void Update(float elapsedClockSeconds)
227227
{
228228
case CircuitBreakerState.Open:
229229
// If circuit breaker is open, then it must be closed to finish the quick power-on sequence
230-
if (QuickPowerOn.CloseCircuitBreaker)
230+
if (QuickPowerOn)
231231
{
232-
QuickPowerOn.CloseCircuitBreaker = false;
232+
QuickPowerOn = false;
233233
SignalEventToCircuitBreaker(PowerSupplyEvent.QuickPowerOn);
234234
}
235235

@@ -253,7 +253,7 @@ public override void Update(float elapsedClockSeconds)
253253

254254
case CircuitBreakerState.Closed:
255255
// If circuit breaker is closed, quick power-on sequence has finished
256-
if (QuickPowerOn.CloseCircuitBreaker) QuickPowerOn.CloseCircuitBreaker = false;
256+
QuickPowerOn = false;
257257

258258
if (!PowerOnTimer.Started)
259259
PowerOnTimer.Start();
@@ -269,12 +269,6 @@ public override void Update(float elapsedClockSeconds)
269269
{
270270
SignalEvent(Event.PowerConverterOn);
271271
SetCurrentAuxiliaryPowerSupplyState(PowerSupplyState.PowerOn);
272-
273-
if (QuickPowerOn.SwitchOnElectricTrainSupply)
274-
{
275-
QuickPowerOn.SwitchOnElectricTrainSupply = false;
276-
if (NumberOfElectricTrainSupplyConnectedCars > 0) SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.SwitchOnElectricTrainSupply);
277-
}
278272
}
279273
SetFilterVoltageV(VoltageFilter.Filter(PantographVoltageV(), elapsedClockSeconds));
280274
break;
@@ -310,16 +304,17 @@ public override void HandleEvent(PowerSupplyEvent evt)
310304
switch (evt)
311305
{
312306
case PowerSupplyEvent.QuickPowerOn:
313-
QuickPowerOn = (true, true);
307+
QuickPowerOn = true;
314308
SignalEventToBatterySwitch(PowerSupplyEvent.QuickPowerOn);
315309
SignalEventToMasterKey(PowerSupplyEvent.TurnOnMasterKey);
316310
SignalEventToPantograph(PowerSupplyEvent.RaisePantograph, 1);
317311
SignalEventToOtherTrainVehiclesWithId(PowerSupplyEvent.RaisePantograph, 1);
312+
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.QuickPowerOn);
318313
break;
319314

320315
case PowerSupplyEvent.QuickPowerOff:
321-
QuickPowerOn = (false, false);
322-
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.SwitchOffElectricTrainSupply);
316+
QuickPowerOn = false;
317+
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.QuickPowerOff);
323318
SignalEventToCircuitBreaker(PowerSupplyEvent.QuickPowerOff);
324319
SignalEventToPantographs(PowerSupplyEvent.LowerPantograph);
325320
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)