Skip to content

Commit 613b95e

Browse files
committed
Automatic merge of T1.5.1-1732-gfdbea15ea and 15 pull requests
- Pull request #570 at f11a428: glTF 2.0 support with PBR lighting - Pull request #1030 at d3ae4a2: Refactor settings, in prep for settings exporter - Pull request #1052 at 3b5cb90: Content Manager: Add axle count, and lowest derail force - Pull request #1062 at bbc0013: Train Forces popup Window. - Pull request #1064 at cb510d6: Add Train Info tab to Help window (F1) - Pull request #1066 at 62c89c1: Log derailment, using TraceInformation. - Pull request #892 at 1f5ba4c: Signal Function OPP_SIG_ID_TRAINPATH - Pull request #1049 at 6a0c471: Re-organise document storage and access - Pull request #1057 at 254b6d4: Switchable brake system - Pull request #1069 at 3f153f0: Mouse wheel control only with Alt – Followup for #1051 - Pull request #1070 at f818e40: Fix a NullReferenceException in TCS scripts - Pull request #1071 at 722dd3f: Change cover image for v1.6 - Pull request #1074 at e9a66c1: Gradient - commit 2024-16-12 - Pull request #1076 at d1ff8fd: Allow depart early - Pull request #1077 at 7e73abd: Fix SME brakes not working
17 parents af20571 + fdbea15 + f11a428 + d3ae4a2 + 3b5cb90 + bbc0013 + cb510d6 + 62c89c1 + 1f5ba4c + 6a0c471 + 254b6d4 + 3f153f0 + f818e40 + 722dd3f + e9a66c1 + d1ff8fd + 7e73abd commit 613b95e

File tree

2 files changed

+189
-69
lines changed

2 files changed

+189
-69
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// COPYRIGHT 2020 by the Open Rails project.
1+
// COPYRIGHT 2020 by the Open Rails project.
22
//
33
// This file is part of Open Rails.
44
//
@@ -31,17 +31,16 @@ public enum ModeType
3131
Unfitted, // Locomotive without ETS
3232
Switch, // Locomotive with ETS activation via a switch
3333
}
34-
public ModeType Mode { get; protected set; }
34+
public ModeType Mode { get; protected set; } = ModeType.Automatic;
3535

3636
// Variables
3737
readonly MSTSLocomotive Locomotive;
3838
public bool CommandSwitch { get; protected set; } = false;
3939
public bool On { get; protected set; } = false;
4040

41-
public ElectricTrainSupplySwitch(MSTSLocomotive locomotive, ModeType defaultMode = ModeType.Automatic)
41+
public ElectricTrainSupplySwitch(MSTSLocomotive locomotive)
4242
{
4343
Locomotive = locomotive;
44-
Mode = defaultMode;
4544
}
4645

4746
public virtual void Parse(string lowercasetoken, STFReader stf)

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

Lines changed: 186 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
1717

18-
using System.Diagnostics;
1918
using System.IO;
2019
using Orts.Parsers.Msts;
21-
using ORTS.Common;
2220
using ORTS.Scripting.Api;
2321

2422
namespace Orts.Simulation.RollingStocks.SubSystems.PowerSupplies
@@ -27,103 +25,226 @@ namespace Orts.Simulation.RollingStocks.SubSystems.PowerSupplies
2725
/// Basic power supply class for steam locomotives
2826
/// For electrical systems powered by battery
2927
/// </summary>
30-
public class ScriptedSteamPowerSupply : ScriptedLocomotivePowerSupply
28+
public class SteamPowerSupply : ILocomotivePowerSupply
3129
{
32-
public MSTSSteamLocomotive SteamLocomotive => Locomotive as MSTSSteamLocomotive;
33-
public override PowerSupplyType Type => PowerSupplyType.Steam;
34-
public ScriptedSteamPowerSupply(MSTSSteamLocomotive locomotive) : base(locomotive)
30+
public TrainCar Car { get; }
31+
public MSTSSteamLocomotive Locomotive => Car as MSTSSteamLocomotive;
32+
public PowerSupplyType Type => PowerSupplyType.Steam;
33+
34+
public Pantographs Pantographs => Locomotive.Pantographs;
35+
public Battery Battery { get; protected set; }
36+
public BatterySwitch BatterySwitch => Battery.BatterySwitch;
37+
public MasterKey MasterKey { get; protected set; }
38+
public ElectricTrainSupplySwitch ElectricTrainSupplySwitch => null;
39+
40+
public PowerSupplyState MainPowerSupplyState
3541
{
36-
ElectricTrainSupplySwitch = new ElectricTrainSupplySwitch(Locomotive, ElectricTrainSupplySwitch.ModeType.Unfitted);
42+
get
43+
{
44+
return PowerSupplyState.PowerOn;
45+
}
46+
set{}
3747
}
38-
public override void Initialize()
48+
49+
public bool MainPowerSupplyOn => true;
50+
public bool DynamicBrakeAvailable
3951
{
40-
base.Initialize();
52+
get
53+
{
54+
return false;
55+
}
56+
set{}
57+
}
58+
public float PowerSupplyDynamicBrakePercent { get; set; } = -1;
59+
public float MaximumDynamicBrakePowerW { get; set; } = 0;
60+
public float MaxThrottlePercent { get; set; } = 100;
61+
public float ThrottleReductionPercent { get; set; } = 0;
4162

42-
if (AbstractScript == null)
63+
public PowerSupplyState AuxiliaryPowerSupplyState
64+
{
65+
get
4366
{
44-
if (ScriptName != null && ScriptName != "Default")
45-
{
46-
Trace.TraceWarning("Skipped custom power supply script, not available for steam locomotives.");
47-
}
67+
return PowerSupplyState.PowerOn;
68+
}
69+
set{}
70+
}
4871

49-
if (ParametersFileName != null)
50-
{
51-
ParametersFileName = Path.Combine(Path.Combine(Path.GetDirectoryName(Locomotive.WagFilePath), "Script"), ParametersFileName);
52-
}
72+
public bool AuxiliaryPowerSupplyOn => true;
5373

54-
if (AbstractScript == null)
55-
{
56-
AbstractScript = new DefaultSteamPowerSupply();
57-
}
74+
public PowerSupplyState LowVoltagePowerSupplyState
75+
{
76+
get
77+
{
78+
return Battery.State == PowerSupplyState.PowerOn ? PowerSupplyState.PowerOn : PowerSupplyState.PowerOff;
79+
}
80+
set{}
81+
}
5882

59-
AssignScriptFunctions();
83+
public bool LowVoltagePowerSupplyOn => LowVoltagePowerSupplyState == PowerSupplyState.PowerOn;
6084

61-
AbstractScript.AttachToHost(this);
62-
AbstractScript.Initialize();
85+
public PowerSupplyState BatteryState
86+
{
87+
get
88+
{
89+
return Battery.State;
90+
}
91+
set
92+
{
93+
Battery.State = value;
6394
}
6495
}
6596

66-
public override void Update(float elapsedClockSeconds)
67-
{
68-
base.Update(elapsedClockSeconds);
97+
public bool BatteryOn => BatteryState == PowerSupplyState.PowerOn;
98+
public float BatteryVoltageV => BatteryOn ? Battery.VoltageV : 0;
6999

70-
AbstractScript?.Update(elapsedClockSeconds);
71-
}
72-
}
73-
public class DefaultSteamPowerSupply : LocomotivePowerSupply
74-
{
75-
public override void Initialize()
100+
public PowerSupplyState CabPowerSupplyState
76101
{
102+
get
103+
{
104+
return MasterKey.On ? PowerSupplyState.PowerOn : PowerSupplyState.PowerOff;
105+
}
106+
set{}
77107
}
78108

79-
public override void Update(float elapsedClockSeconds)
109+
public bool CabPowerSupplyOn => CabPowerSupplyState == PowerSupplyState.PowerOn;
110+
111+
public PowerSupplyState ElectricTrainSupplyState
80112
{
81-
SetCurrentBatteryState(BatterySwitchOn() ? PowerSupplyState.PowerOn : PowerSupplyState.PowerOff);
82-
SetCurrentLowVoltagePowerSupplyState(BatterySwitchOn() ? PowerSupplyState.PowerOn : PowerSupplyState.PowerOff);
83-
SetCurrentCabPowerSupplyState(BatterySwitchOn() && MasterKeyOn() ? PowerSupplyState.PowerOn : PowerSupplyState.PowerOff);
113+
get
114+
{
115+
return PowerSupplyState.Unavailable;
116+
}
117+
set{}
118+
}
84119

85-
SetCurrentMainPowerSupplyState(PowerSupplyState.PowerOn);
86-
SetCurrentAuxiliaryPowerSupplyState(PowerSupplyState.PowerOn);
120+
public bool ElectricTrainSupplyOn => false;
121+
public bool FrontElectricTrainSupplyCableConnected { get => false; set { } }
122+
public float ElectricTrainSupplyPowerW => 0f;
87123

88-
if (ElectricTrainSupplyUnfitted())
124+
public bool ServiceRetentionButton
125+
{
126+
get
89127
{
90-
SetCurrentElectricTrainSupplyState(PowerSupplyState.Unavailable);
128+
return false;
91129
}
92-
else if (CurrentAuxiliaryPowerSupplyState() == PowerSupplyState.PowerOn
93-
&& ElectricTrainSupplySwitchOn())
130+
set{}
131+
}
132+
133+
public bool ServiceRetentionCancellationButton
134+
{
135+
get
94136
{
95-
SetCurrentElectricTrainSupplyState(PowerSupplyState.PowerOn);
137+
return false;
96138
}
97-
else
139+
set{}
140+
}
141+
142+
public bool ServiceRetentionActive
143+
{
144+
get
98145
{
99-
SetCurrentElectricTrainSupplyState(PowerSupplyState.PowerOff);
146+
return false;
100147
}
148+
set{}
101149
}
102150

103-
public override void HandleEvent(PowerSupplyEvent evt)
151+
public SteamPowerSupply(MSTSSteamLocomotive locomotive)
104152
{
105-
switch (evt)
153+
Car = locomotive;
154+
155+
Battery = new Battery(Locomotive);
156+
MasterKey = new MasterKey(Locomotive);
157+
}
158+
159+
public virtual void Parse(string lowercasetoken, STFReader stf)
160+
{
161+
switch (lowercasetoken)
106162
{
107-
case PowerSupplyEvent.QuickPowerOn:
108-
SignalEventToBatterySwitch(PowerSupplyEvent.QuickPowerOn);
109-
SignalEventToMasterKey(PowerSupplyEvent.TurnOnMasterKey);
110-
SignalEventToPantograph(PowerSupplyEvent.RaisePantograph, 1);
111-
SignalEventToOtherTrainVehiclesWithId(PowerSupplyEvent.RaisePantograph, 1);
112-
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.SwitchOnElectricTrainSupply);
163+
case "engine(ortsbattery":
164+
Battery.Parse(lowercasetoken, stf);
113165
break;
114-
115-
case PowerSupplyEvent.QuickPowerOff:
116-
SignalEventToElectricTrainSupplySwitch(PowerSupplyEvent.SwitchOffElectricTrainSupply);
117-
SignalEventToPantographs(PowerSupplyEvent.LowerPantograph);
118-
SignalEventToOtherTrainVehicles(PowerSupplyEvent.LowerPantograph);
119-
SignalEventToMasterKey(PowerSupplyEvent.TurnOffMasterKey);
120-
SignalEventToBatterySwitch(PowerSupplyEvent.QuickPowerOff);
166+
case "engine(ortsmasterkey(mode":
167+
case "engine(ortsmasterkey(delayoff":
168+
case "engine(ortsmasterkey(headlightcontrol":
169+
MasterKey.Parse(lowercasetoken, stf);
121170
break;
171+
}
172+
}
122173

123-
default:
124-
base.HandleEvent(evt);
125-
break;
174+
public void Copy(IPowerSupply other)
175+
{
176+
if (other is SteamPowerSupply steamOther)
177+
{
178+
Battery.Copy(steamOther.Battery);
179+
MasterKey.Copy(steamOther.MasterKey);
126180
}
127181
}
182+
183+
public void Initialize()
184+
{
185+
Battery.Initialize();
186+
MasterKey.Initialize();
187+
}
188+
189+
public virtual void InitializeMoving()
190+
{
191+
Battery.InitializeMoving();
192+
MasterKey.InitializeMoving();
193+
}
194+
195+
public void Save(BinaryWriter outf)
196+
{
197+
Battery.Save(outf);
198+
MasterKey.Save(outf);
199+
}
200+
201+
public void Restore(BinaryReader inf)
202+
{
203+
Battery.Restore(inf);
204+
MasterKey.Restore(inf);
205+
}
206+
207+
public void Update(float elapsedClockSeconds)
208+
{
209+
Battery.State = BatterySwitch.On ? PowerSupplyState.PowerOn : PowerSupplyState.PowerOff;
210+
}
211+
212+
public void HandleEvent(PowerSupplyEvent evt)
213+
{
214+
BatterySwitch.HandleEvent(evt);
215+
MasterKey.HandleEvent(evt);
216+
}
217+
218+
public void HandleEvent(PowerSupplyEvent evt, int id)
219+
{
220+
}
221+
222+
public void HandleEventFromTcs(PowerSupplyEvent evt)
223+
{
224+
}
225+
226+
public void HandleEventFromTcs(PowerSupplyEvent evt, int id)
227+
{
228+
}
229+
230+
public void HandleEventFromTcs(PowerSupplyEvent evt, string message)
231+
{
232+
}
233+
234+
public void HandleEventFromLeadLocomotive(PowerSupplyEvent evt)
235+
{
236+
}
237+
238+
public void HandleEventFromLeadLocomotive(PowerSupplyEvent evt, int id)
239+
{
240+
}
241+
242+
public void HandleEventFromOtherLocomotive(int locoIndex, PowerSupplyEvent evt)
243+
{
244+
}
245+
246+
public void HandleEventFromOtherLocomotive(int locoIndex, PowerSupplyEvent evt, int id)
247+
{
248+
}
128249
}
129250
}

0 commit comments

Comments
 (0)