Skip to content

Commit f7eec7b

Browse files
authored
Merge pull request #451 from Sharpe49/fix-power-supply-restore
Fixed the wrong states of battery switch, master key and ETS switch after restoring from a save https://bugs.launchpad.net/or/+bug/1940094
2 parents 4d83c00 + 3aac10c commit f7eec7b

File tree

3 files changed

+17
-38
lines changed

3 files changed

+17
-38
lines changed

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ public enum ModeType
3838
// Variables
3939
readonly MSTSWagon Wagon;
4040
protected Timer Timer;
41-
public bool CommandSwitch { get; protected set; } = true;
41+
public bool CommandSwitch { get; protected set; } = false;
4242
public bool CommandButtonOn { get; protected set; } = false;
4343
public bool CommandButtonOff { get; protected set; } = false;
44-
public bool On { get; protected set; } = true;
44+
public bool On { get; protected set; } = false;
4545

4646
public BatterySwitch(MSTSWagon wagon)
4747
{
@@ -91,17 +91,6 @@ public void Copy(BatterySwitch other)
9191

9292
public virtual void Initialize()
9393
{
94-
switch (Mode)
95-
{
96-
case ModeType.Switch:
97-
CommandSwitch = false;
98-
On = false;
99-
break;
100-
101-
case ModeType.PushButtons:
102-
On = false;
103-
break;
104-
}
10594
}
10695

10796
/// <summary>

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public enum ModeType
3535

3636
// Variables
3737
readonly MSTSLocomotive Locomotive;
38-
public bool CommandSwitch { get; protected set; } = true;
39-
public bool On { get; protected set; } = true;
38+
public bool CommandSwitch { get; protected set; } = false;
39+
public bool On { get; protected set; } = false;
4040

4141
public ElectricTrainSupplySwitch(MSTSLocomotive locomotive)
4242
{
@@ -77,18 +77,6 @@ public void Copy(ElectricTrainSupplySwitch other)
7777

7878
public virtual void Initialize()
7979
{
80-
switch (Mode)
81-
{
82-
case ModeType.Unfitted:
83-
CommandSwitch = false;
84-
On = false;
85-
break;
86-
87-
case ModeType.Switch:
88-
CommandSwitch = false;
89-
On = false;
90-
break;
91-
}
9280
}
9381

9482
/// <summary>
@@ -126,6 +114,10 @@ public virtual void Update(float elapsedClockSeconds)
126114
{
127115
switch (Mode)
128116
{
117+
case ModeType.Unfitted:
118+
On = false;
119+
break;
120+
129121
case ModeType.Automatic:
130122
if (On)
131123
{
@@ -150,8 +142,8 @@ public virtual void Update(float elapsedClockSeconds)
150142
{
151143
if (!CommandSwitch || !Locomotive.LocomotivePowerSupply.AuxiliaryPowerSupplyOn)
152144
{
153-
On = false;
154-
Locomotive.SignalEvent(Event.ElectricTrainSupplyOff);
145+
On = false;
146+
Locomotive.SignalEvent(Event.ElectricTrainSupplyOff);
155147
}
156148
}
157149
else

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public enum ModeType
4141
// Variables
4242
readonly MSTSLocomotive Locomotive;
4343
protected Timer Timer;
44-
public bool CommandSwitch { get; protected set; } = true;
45-
public bool On { get; protected set; } = true;
44+
public bool CommandSwitch { get; protected set; } = false;
45+
public bool On { get; protected set; } = false;
4646
public bool OtherCabInUse {
4747
get
4848
{
@@ -105,20 +105,18 @@ public void Copy(MasterKey other)
105105

106106
public virtual void Initialize()
107107
{
108-
if (Mode == ModeType.Manual)
109-
{
110-
CommandSwitch = false;
111-
On = false;
112-
}
113108
}
114109

115110
/// <summary>
116111
/// Initialization when simulation starts with moving train
117112
/// </summary>
118113
public virtual void InitializeMoving()
119114
{
120-
CommandSwitch = true;
121-
On = true;
115+
if (Locomotive.IsLeadLocomotive())
116+
{
117+
CommandSwitch = true;
118+
On = true;
119+
}
122120
}
123121

124122
public virtual void Save(BinaryWriter outf)

0 commit comments

Comments
 (0)