15
15
// You should have received a copy of the GNU General Public License
16
16
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
17
17
18
+ using System . Diagnostics ;
18
19
using System . IO ;
19
20
using Orts . Parsers . Msts ;
21
+ using ORTS . Common ;
20
22
using ORTS . Scripting . Api ;
21
23
22
24
namespace Orts . Simulation . RollingStocks . SubSystems . PowerSupplies
@@ -25,226 +27,103 @@ namespace Orts.Simulation.RollingStocks.SubSystems.PowerSupplies
25
27
/// Basic power supply class for steam locomotives
26
28
/// For electrical systems powered by battery
27
29
/// </summary>
28
- public class SteamPowerSupply : ILocomotivePowerSupply
30
+ public class ScriptedSteamPowerSupply : ScriptedLocomotivePowerSupply
29
31
{
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
32
+ public MSTSSteamLocomotive SteamLocomotive => Locomotive as MSTSSteamLocomotive ;
33
+ public override PowerSupplyType Type => PowerSupplyType . Steam ;
34
+ public ScriptedSteamPowerSupply ( MSTSSteamLocomotive locomotive ) : base ( locomotive )
41
35
{
42
- get
43
- {
44
- return PowerSupplyState . PowerOn ;
45
- }
46
- set { }
36
+ ElectricTrainSupplySwitch = new ElectricTrainSupplySwitch ( Locomotive , ElectricTrainSupplySwitch . ModeType . Unfitted ) ;
47
37
}
48
-
49
- public bool MainPowerSupplyOn => true ;
50
- public bool DynamicBrakeAvailable
38
+ public override void Initialize ( )
51
39
{
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 ;
40
+ base . Initialize ( ) ;
62
41
63
- public PowerSupplyState AuxiliaryPowerSupplyState
64
- {
65
- get
42
+ if ( AbstractScript == null )
66
43
{
67
- return PowerSupplyState . PowerOn ;
68
- }
69
- set { }
70
- }
44
+ if ( ScriptName != null && ScriptName != "Default" )
45
+ {
46
+ Trace . TraceWarning ( "Skipped custom power supply script, not available for steam locomotives." ) ;
47
+ }
71
48
72
- public bool AuxiliaryPowerSupplyOn => true ;
49
+ if ( ParametersFileName != null )
50
+ {
51
+ ParametersFileName = Path . Combine ( Path . Combine ( Path . GetDirectoryName ( Locomotive . WagFilePath ) , "Script" ) , ParametersFileName ) ;
52
+ }
73
53
74
- public PowerSupplyState LowVoltagePowerSupplyState
75
- {
76
- get
77
- {
78
- return Battery . State == PowerSupplyState . PowerOn ? PowerSupplyState . PowerOn : PowerSupplyState . PowerOff ;
79
- }
80
- set { }
81
- }
54
+ if ( AbstractScript == null )
55
+ {
56
+ AbstractScript = new DefaultSteamPowerSupply ( ) ;
57
+ }
82
58
83
- public bool LowVoltagePowerSupplyOn => LowVoltagePowerSupplyState == PowerSupplyState . PowerOn ;
59
+ AssignScriptFunctions ( ) ;
84
60
85
- public PowerSupplyState BatteryState
86
- {
87
- get
88
- {
89
- return Battery . State ;
90
- }
91
- set
92
- {
93
- Battery . State = value ;
61
+ AbstractScript . AttachToHost ( this ) ;
62
+ AbstractScript . Initialize ( ) ;
94
63
}
95
64
}
96
65
97
- public bool BatteryOn => BatteryState == PowerSupplyState . PowerOn ;
98
- public float BatteryVoltageV => BatteryOn ? Battery . VoltageV : 0 ;
66
+ public override void Update ( float elapsedClockSeconds )
67
+ {
68
+ base . Update ( elapsedClockSeconds ) ;
99
69
100
- public PowerSupplyState CabPowerSupplyState
70
+ AbstractScript ? . Update ( elapsedClockSeconds ) ;
71
+ }
72
+ }
73
+ public class DefaultSteamPowerSupply : LocomotivePowerSupply
74
+ {
75
+ public override void Initialize ( )
101
76
{
102
- get
103
- {
104
- return MasterKey . On ? PowerSupplyState . PowerOn : PowerSupplyState . PowerOff ;
105
- }
106
- set { }
107
77
}
108
78
109
- public bool CabPowerSupplyOn => CabPowerSupplyState == PowerSupplyState . PowerOn ;
110
-
111
- public PowerSupplyState ElectricTrainSupplyState
79
+ public override void Update ( float elapsedClockSeconds )
112
80
{
113
- get
114
- {
115
- return PowerSupplyState . Unavailable ;
116
- }
117
- set { }
118
- }
81
+ SetCurrentBatteryState ( BatterySwitchOn ( ) ? PowerSupplyState . PowerOn : PowerSupplyState . PowerOff ) ;
82
+ SetCurrentLowVoltagePowerSupplyState ( BatterySwitchOn ( ) ? PowerSupplyState . PowerOn : PowerSupplyState . PowerOff ) ;
83
+ SetCurrentCabPowerSupplyState ( BatterySwitchOn ( ) && MasterKeyOn ( ) ? PowerSupplyState . PowerOn : PowerSupplyState . PowerOff ) ;
119
84
120
- public bool ElectricTrainSupplyOn => false ;
121
- public bool FrontElectricTrainSupplyCableConnected { get => false ; set { } }
122
- public float ElectricTrainSupplyPowerW => 0f ;
85
+ SetCurrentMainPowerSupplyState ( PowerSupplyState . PowerOn ) ;
86
+ SetCurrentAuxiliaryPowerSupplyState ( PowerSupplyState . PowerOn ) ;
123
87
124
- public bool ServiceRetentionButton
125
- {
126
- get
88
+ if ( ElectricTrainSupplyUnfitted ( ) )
127
89
{
128
- return false ;
90
+ SetCurrentElectricTrainSupplyState ( PowerSupplyState . Unavailable ) ;
129
91
}
130
- set { }
131
- }
132
-
133
- public bool ServiceRetentionCancellationButton
134
- {
135
- get
92
+ else if ( CurrentAuxiliaryPowerSupplyState ( ) == PowerSupplyState . PowerOn
93
+ && ElectricTrainSupplySwitchOn ( ) )
136
94
{
137
- return false ;
95
+ SetCurrentElectricTrainSupplyState ( PowerSupplyState . PowerOn ) ;
138
96
}
139
- set { }
140
- }
141
-
142
- public bool ServiceRetentionActive
143
- {
144
- get
97
+ else
145
98
{
146
- return false ;
99
+ SetCurrentElectricTrainSupplyState ( PowerSupplyState . PowerOff ) ;
147
100
}
148
- set { }
149
101
}
150
102
151
- public SteamPowerSupply ( MSTSSteamLocomotive locomotive )
103
+ public override void HandleEvent ( PowerSupplyEvent evt )
152
104
{
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 )
105
+ switch ( evt )
162
106
{
163
- case "engine(ortsbattery" :
164
- Battery . Parse ( lowercasetoken , stf ) ;
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 ) ;
165
113
break ;
166
- case "engine(ortsmasterkey(mode" :
167
- case "engine(ortsmasterkey(delayoff" :
168
- case "engine(ortsmasterkey(headlightcontrol" :
169
- MasterKey . Parse ( lowercasetoken , stf ) ;
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 ) ;
170
121
break ;
171
- }
172
- }
173
122
174
- public void Copy ( IPowerSupply other )
175
- {
176
- if ( other is SteamPowerSupply steamOther )
177
- {
178
- Battery . Copy ( steamOther . Battery ) ;
179
- MasterKey . Copy ( steamOther . MasterKey ) ;
123
+ default :
124
+ base . HandleEvent ( evt ) ;
125
+ break ;
180
126
}
181
127
}
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
- }
249
128
}
250
129
}
0 commit comments