Skip to content

Commit 8b9100d

Browse files
authored
Merge pull request #446 from Sharpe49/power-supply-fix-copy
Fix for Copy function not being called in ScriptedDieselPowerSupply and ScriptedElectricPowerSupply https://bugs.launchpad.net/or/+bug/1938744
2 parents e0869b2 + da66aa2 commit 8b9100d

File tree

5 files changed

+36
-34
lines changed

5 files changed

+36
-34
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
namespace Orts.Simulation.RollingStocks.SubSystems.PowerSupplies
2424
{
2525

26-
public class ScriptedDieselPowerSupply : ScriptedLocomotivePowerSupply, ISubSystem<ScriptedDieselPowerSupply>
26+
public class ScriptedDieselPowerSupply : ScriptedLocomotivePowerSupply
2727
{
2828
public MSTSDieselLocomotive DieselLocomotive => Locomotive as MSTSDieselLocomotive;
2929
public ScriptedTractionCutOffRelay TractionCutOffRelay { get; protected set; }
@@ -61,10 +61,14 @@ public override void Parse(string lowercasetoken, STFReader stf)
6161
}
6262
}
6363

64-
public void Copy(ScriptedDieselPowerSupply other)
64+
public override void Copy(IPowerSupply other)
6565
{
6666
base.Copy(other);
67-
TractionCutOffRelay.Copy(other.TractionCutOffRelay);
67+
68+
if (other is ScriptedDieselPowerSupply scriptedOther)
69+
{
70+
TractionCutOffRelay.Copy(scriptedOther.TractionCutOffRelay);
71+
}
6872
}
6973

7074
public override void Initialize()

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
namespace Orts.Simulation.RollingStocks.SubSystems.PowerSupplies
2424
{
2525

26-
public class ScriptedDualModePowerSupply : ScriptedLocomotivePowerSupply, ISubSystem<ScriptedDualModePowerSupply>
26+
public class ScriptedDualModePowerSupply : ScriptedLocomotivePowerSupply
2727
{
2828
public MSTSElectricLocomotive DualModeLocomotive => Locomotive as MSTSElectricLocomotive;
2929
public Pantographs Pantographs => Locomotive.Pantographs;
@@ -61,11 +61,15 @@ public override void Parse(string lowercasetoken, STFReader stf)
6161
}
6262
}
6363

64-
public void Copy(ScriptedDualModePowerSupply other)
64+
public override void Copy(IPowerSupply other)
6565
{
66-
base.Copy(other);
67-
CircuitBreaker.Copy(other.CircuitBreaker);
68-
TractionCutOffRelay.Copy(other.TractionCutOffRelay);
66+
base.Copy(other);
67+
68+
if (other is ScriptedDualModePowerSupply scriptedOther)
69+
{
70+
CircuitBreaker.Copy(scriptedOther.CircuitBreaker);
71+
TractionCutOffRelay.Copy(scriptedOther.TractionCutOffRelay);
72+
}
6973
}
7074

7175
public override void Initialize()

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
namespace Orts.Simulation.RollingStocks.SubSystems.PowerSupplies
2525
{
2626

27-
public class ScriptedElectricPowerSupply : ScriptedLocomotivePowerSupply, ISubSystem<ScriptedElectricPowerSupply>
27+
public class ScriptedElectricPowerSupply : ScriptedLocomotivePowerSupply
2828
{
2929
public MSTSElectricLocomotive ElectricLocomotive => Locomotive as MSTSElectricLocomotive;
3030
public Pantographs Pantographs => Locomotive.Pantographs;
@@ -60,10 +60,14 @@ public override void Parse(string lowercasetoken, STFReader stf)
6060
}
6161
}
6262

63-
public void Copy(ScriptedElectricPowerSupply other)
63+
public override void Copy(IPowerSupply other)
6464
{
65-
base.Copy(other);
66-
CircuitBreaker.Copy(other.CircuitBreaker);
65+
base.Copy(other);
66+
67+
if (other is ScriptedElectricPowerSupply scriptedOther)
68+
{
69+
CircuitBreaker.Copy(scriptedOther.CircuitBreaker);
70+
}
6771
}
6872

6973
public override void Initialize()

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
namespace Orts.Simulation.RollingStocks.SubSystems.PowerSupplies
2626
{
2727

28-
public abstract class ScriptedLocomotivePowerSupply : ILocomotivePowerSupply, ISubSystem<ScriptedLocomotivePowerSupply>
28+
public abstract class ScriptedLocomotivePowerSupply : ILocomotivePowerSupply
2929
{
3030
public readonly MSTSLocomotive Locomotive;
3131
protected Simulator Simulator => Locomotive.Simulator;
@@ -125,24 +125,19 @@ public virtual void Parse(string lowercasetoken, STFReader stf)
125125
}
126126
}
127127

128-
public void Copy(IPowerSupply other)
128+
public virtual void Copy(IPowerSupply other)
129129
{
130130
if (other is ScriptedLocomotivePowerSupply scriptedOther)
131131
{
132-
Copy(scriptedOther);
133-
}
134-
}
132+
BatterySwitch.Copy(scriptedOther.BatterySwitch);
133+
MasterKey.Copy(scriptedOther.MasterKey);
134+
ElectricTrainSupplySwitch.Copy(scriptedOther.ElectricTrainSupplySwitch);
135135

136-
public void Copy(ScriptedLocomotivePowerSupply other)
137-
{
138-
BatterySwitch.Copy(other.BatterySwitch);
139-
MasterKey.Copy(other.MasterKey);
140-
ElectricTrainSupplySwitch.Copy(other.ElectricTrainSupplySwitch);
136+
ScriptName = scriptedOther.ScriptName;
141137

142-
ScriptName = other.ScriptName;
143-
144-
PowerOnDelayS = other.PowerOnDelayS;
145-
AuxPowerOnDelayS = other.AuxPowerOnDelayS;
138+
PowerOnDelayS = scriptedOther.PowerOnDelayS;
139+
AuxPowerOnDelayS = scriptedOther.AuxPowerOnDelayS;
140+
}
146141
}
147142

148143
public virtual void Initialize()

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Orts.Simulation.RollingStocks.SubSystems.PowerSupplies
99
/// Basic power supply class for steam locomotives
1010
/// For electrical systems powered by battery
1111
/// </summary>
12-
public class SteamPowerSupply : ILocomotivePowerSupply, ISubSystem<SteamPowerSupply>
12+
public class SteamPowerSupply : ILocomotivePowerSupply
1313
{
1414
public readonly MSTSSteamLocomotive Locomotive;
1515
public PowerSupplyType Type => PowerSupplyType.Steam;
@@ -70,16 +70,11 @@ public void Copy(IPowerSupply other)
7070
{
7171
if (other is SteamPowerSupply steamOther)
7272
{
73-
Copy(steamOther);
73+
BatterySwitch.Copy(steamOther.BatterySwitch);
74+
MasterKey.Copy(steamOther.MasterKey);
7475
}
7576
}
7677

77-
public void Copy(SteamPowerSupply other)
78-
{
79-
BatterySwitch.Copy(other.BatterySwitch);
80-
MasterKey.Copy(other.MasterKey);
81-
}
82-
8378
public void Initialize()
8479
{
8580
BatterySwitch.Initialize();

0 commit comments

Comments
 (0)