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 ;
1918using System . IO ;
2019using Orts . Parsers . Msts ;
21- using ORTS . Common ;
2220using ORTS . Scripting . Api ;
2321
2422namespace 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