1
- // COPYRIGHT 2009, 2010, 2011, 2012, 2013 by the Open Rails project.
1
+ // COPYRIGHT 2009 by the Open Rails project.
2
2
//
3
3
// This file is part of Open Rails.
4
4
//
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
- /* DIESEL LOCOMOTIVE CLASSES
19
- *
20
- * The Locomotive is represented by two classes:
21
- * MSTSDieselLocomotiveSimulator - defines the behaviour, ie physics, motion, power generated etc
22
- * MSTSDieselLocomotiveViewer - defines the appearance in a 3D viewer. The viewer doesn't
23
- * get attached to the car until it comes into viewing range.
24
- *
25
- * Both these classes derive from corresponding classes for a basic locomotive
26
- * LocomotiveSimulator - provides for movement, basic controls etc
27
- * LocomotiveViewer - provides basic animation for running gear, wipers, etc
28
- *
29
- */
30
-
31
18
using System . Diagnostics ;
32
19
using System . IO ;
33
20
using System . Text ;
21
+ using Orts . Formats . Msts ;
34
22
using Orts . Parsers . Msts ;
35
23
using Orts . Simulation . Physics ;
36
24
using Orts . Simulation . RollingStocks . SubSystems . Controllers ;
37
25
using Orts . Simulation . RollingStocks . SubSystems . PowerSupplies ;
38
26
using Orts . Simulation . RollingStocks . SubSystems . PowerTransmissions ;
27
+ using ORTS . Common ;
39
28
40
29
namespace Orts . Simulation . RollingStocks
41
30
{
@@ -49,17 +38,14 @@ public class MSTSControlTrailerCar : MSTSLocomotive
49
38
int ControlGearIndication ;
50
39
TypesGearBox ControlGearBoxType ;
51
40
41
+ private bool controlTrailerBrakeSystemSet = false ;
42
+
52
43
public MSTSControlTrailerCar ( Simulator simulator , string wagFile )
53
44
: base ( simulator , wagFile )
54
45
{
55
46
PowerSupply = new ScriptedControlCarPowerSupply ( this ) ;
56
47
}
57
48
58
- public override void LoadFromWagFile ( string wagFilePath )
59
- {
60
- base . LoadFromWagFile ( wagFilePath ) ;
61
- }
62
-
63
49
public override void Initialize ( )
64
50
{
65
51
// Initialise gearbox controller
@@ -83,18 +69,12 @@ public override void Parse(string lowercasetoken, STFReader stf)
83
69
{
84
70
switch ( lowercasetoken )
85
71
{
86
- case "engine(ortspowerondelay" :
87
- case "engine(ortsauxpowerondelay" :
88
72
case "engine(ortspowersupply" :
89
73
case "engine(ortspowersupplyparameters" :
90
- case "engine(ortstractioncutoffrelay" :
91
- case "engine(ortstractioncutoffrelayclosingdelay" :
92
74
case "engine(ortsbattery" :
93
75
case "engine(ortsmasterkey(mode" :
94
76
case "engine(ortsmasterkey(delayoff" :
95
77
case "engine(ortsmasterkey(headlightcontrol" :
96
- case "engine(ortselectrictrainsupply(mode" :
97
- case "engine(ortselectrictrainsupply(dieselengineminrpm" :
98
78
LocomotivePowerSupply . Parse ( lowercasetoken , stf ) ;
99
79
break ;
100
80
@@ -161,6 +141,31 @@ public override void InitializeMoving()
161
141
/// </summary>
162
142
public override void Update ( float elapsedClockSeconds )
163
143
{
144
+ FindControlActiveLocomotive ( ) ;
145
+ // A control car typically doesn't have its own compressor and relies on the attached power car. However OR uses the lead locomotive as the reference car for compressor calculations.
146
+ // Hence whilst users are encouraged to leave these parameters out of the ENG file, they need to be setup for OR to work correctly.
147
+ // Some parameters need to be split across the unpowered and powered car for correct timing and volume calculations.
148
+ // This setup loop is only processed the first time that update is run.
149
+ if ( ! controlTrailerBrakeSystemSet )
150
+ {
151
+ if ( ControlActiveLocomotive != null )
152
+ {
153
+ // Split reservoir volume across the power car and the active locomotive
154
+ MainResVolumeM3 = ControlActiveLocomotive . MainResVolumeM3 / 2 ;
155
+ ControlActiveLocomotive . MainResVolumeM3 = MainResVolumeM3 ;
156
+
157
+ MaxMainResPressurePSI = ControlActiveLocomotive . MaxMainResPressurePSI ;
158
+ MainResPressurePSI = MaxMainResPressurePSI ;
159
+ ControlActiveLocomotive . MainResPressurePSI = MainResPressurePSI ;
160
+ controlTrailerBrakeSystemSet = true ; // Ensure this loop is only processes the first time update routine run
161
+ MaximumMainReservoirPipePressurePSI = ControlActiveLocomotive . MaximumMainReservoirPipePressurePSI ;
162
+ CompressorRestartPressurePSI = ControlActiveLocomotive . CompressorRestartPressurePSI ;
163
+ MainResChargingRatePSIpS = ControlActiveLocomotive . MainResChargingRatePSIpS ;
164
+ BrakePipeChargingRatePSIorInHgpS = ControlActiveLocomotive . BrakePipeChargingRatePSIorInHgpS ;
165
+ TrainBrakePipeLeakPSIorInHgpS = ControlActiveLocomotive . TrainBrakePipeLeakPSIorInHgpS ;
166
+ }
167
+ }
168
+
164
169
base . Update ( elapsedClockSeconds ) ;
165
170
WheelSpeedMpS = SpeedMpS ; // Set wheel speed for control car, required to make wheels go around.
166
171
@@ -213,11 +218,45 @@ public override void Update(float elapsedClockSeconds)
213
218
public override string GetStatus ( )
214
219
{
215
220
var status = new StringBuilder ( ) ;
216
- if ( HasGearController )
217
- status . AppendFormat ( "{0} = {1}\n " , Simulator . Catalog . GetString ( "Gear" ) ,
218
- ControlGearIndex < 0 ? Simulator . Catalog . GetParticularString ( "Gear" , "N" ) : ( ControlGearIndication ) . ToString ( ) ) ;
219
- status . AppendLine ( ) ;
220
-
221
+ status . AppendFormat ( "{0} = {1}\n " ,
222
+ Simulator . Catalog . GetString ( "Battery switch" ) ,
223
+ LocomotivePowerSupply . BatterySwitch . On ? Simulator . Catalog . GetString ( "On" ) : Simulator . Catalog . GetString ( "Off" ) ) ;
224
+ status . AppendFormat ( "{0} = {1}\n " ,
225
+ Simulator . Catalog . GetString ( "Master key" ) ,
226
+ LocomotivePowerSupply . MasterKey . On ? Simulator . Catalog . GetString ( "On" ) : Simulator . Catalog . GetString ( "Off" ) ) ;
227
+ if ( ControlActiveLocomotive != null )
228
+ {
229
+ status . AppendLine ( ) ;
230
+ if ( ControlActiveLocomotive is MSTSElectricLocomotive electric )
231
+ {
232
+ status . AppendFormat ( "{0} = " , Simulator . Catalog . GetString ( "Pantographs" ) ) ;
233
+ foreach ( var pantograph in electric . Pantographs . List )
234
+ status . AppendFormat ( "{0} " , Simulator . Catalog . GetParticularString ( "Pantograph" , GetStringAttribute . GetPrettyName ( pantograph . State ) ) ) ;
235
+ status . AppendLine ( ) ;
236
+ status . AppendFormat ( "{0} = {1}\n " ,
237
+ Simulator . Catalog . GetString ( "Circuit breaker" ) ,
238
+ Simulator . Catalog . GetParticularString ( "CircuitBreaker" , GetStringAttribute . GetPrettyName ( electric . ElectricPowerSupply . CircuitBreaker . State ) ) ) ;
239
+ }
240
+ else if ( ControlActiveLocomotive is MSTSDieselLocomotive diesel )
241
+ {
242
+ status . AppendLine ( ) ;
243
+ status . AppendFormat ( "{0} = {1}\n " , Simulator . Catalog . GetString ( "Engine" ) ,
244
+ Simulator . Catalog . GetParticularString ( "Engine" , GetStringAttribute . GetPrettyName ( diesel . DieselEngines [ 0 ] . State ) ) ) ;
245
+ if ( HasGearController )
246
+ status . AppendFormat ( "{0} = {1}\n " , Simulator . Catalog . GetString ( "Gear" ) ,
247
+ ControlGearIndex < 0 ? Simulator . Catalog . GetParticularString ( "Gear" , "N" ) : ( ControlGearIndication ) . ToString ( ) ) ;
248
+ status . AppendFormat ( "{0} = {1}\n " ,
249
+ Simulator . Catalog . GetString ( "Traction cut-off relay" ) ,
250
+ Simulator . Catalog . GetParticularString ( "TractionCutOffRelay" , GetStringAttribute . GetPrettyName ( diesel . DieselPowerSupply . TractionCutOffRelay . State ) ) ) ;
251
+ }
252
+ status . AppendFormat ( "{0} = {1}\n " ,
253
+ Simulator . Catalog . GetString ( "Electric train supply" ) ,
254
+ ControlActiveLocomotive . LocomotivePowerSupply . ElectricTrainSupplySwitch . On ? Simulator . Catalog . GetString ( "On" ) : Simulator . Catalog . GetString ( "Off" ) ) ;
255
+ status . AppendLine ( ) ;
256
+ status . AppendFormat ( "{0} = {1}" ,
257
+ Simulator . Catalog . GetParticularString ( "PowerSupply" , "Power" ) ,
258
+ Simulator . Catalog . GetParticularString ( "PowerSupply" , GetStringAttribute . GetPrettyName ( ControlActiveLocomotive . LocomotivePowerSupply . MainPowerSupplyState ) ) ) ;
259
+ }
221
260
return status . ToString ( ) ;
222
261
}
223
262
@@ -296,5 +335,69 @@ public override void ChangeGearDown()
296
335
ControlGearUp = false ;
297
336
ControlGearDown = true ;
298
337
}
338
+ public override float GetDataOf ( CabViewControl cvc )
339
+ {
340
+ float data ;
341
+ switch ( cvc . ControlType . Type )
342
+ {
343
+ // Locomotive controls
344
+ case CABViewControlTypes . AMMETER :
345
+ case CABViewControlTypes . AMMETER_ABS :
346
+ case CABViewControlTypes . DYNAMIC_BRAKE_FORCE :
347
+ case CABViewControlTypes . LOAD_METER :
348
+ case CABViewControlTypes . ORTS_SIGNED_TRACTION_BRAKING :
349
+ case CABViewControlTypes . ORTS_SIGNED_TRACTION_TOTAL_BRAKING :
350
+ case CABViewControlTypes . TRACTION_BRAKING :
351
+ case CABViewControlTypes . WHEELSLIP :
352
+ data = ControlActiveLocomotive ? . GetDataOf ( cvc ) ?? 0 ;
353
+ break ;
354
+ // Diesel locomotive controls
355
+ case CABViewControlTypes . FUEL_GAUGE :
356
+ case CABViewControlTypes . ORTS_DIESEL_TEMPERATURE :
357
+ case CABViewControlTypes . ORTS_OIL_PRESSURE :
358
+ case CABViewControlTypes . ORTS_PLAYER_DIESEL_ENGINE :
359
+ case CABViewControlTypes . ORTS_TRACTION_CUT_OFF_RELAY_AUTHORIZED :
360
+ case CABViewControlTypes . ORTS_TRACTION_CUT_OFF_RELAY_CLOSED :
361
+ case CABViewControlTypes . ORTS_TRACTION_CUT_OFF_RELAY_DRIVER_CLOSING_AUTHORIZATION :
362
+ case CABViewControlTypes . ORTS_TRACTION_CUT_OFF_RELAY_DRIVER_CLOSING_ORDER :
363
+ case CABViewControlTypes . ORTS_TRACTION_CUT_OFF_RELAY_DRIVER_OPENING_ORDER :
364
+ case CABViewControlTypes . ORTS_TRACTION_CUT_OFF_RELAY_OPEN :
365
+ case CABViewControlTypes . ORTS_TRACTION_CUT_OFF_RELAY_OPEN_AND_AUTHORIZED :
366
+ case CABViewControlTypes . ORTS_TRACTION_CUT_OFF_RELAY_STATE :
367
+ case CABViewControlTypes . RPM :
368
+ case CABViewControlTypes . RPM_2 :
369
+ data = ( ControlActiveLocomotive as MSTSDieselLocomotive ) ? . GetDataOf ( cvc ) ?? 0 ;
370
+ break ;
371
+ // Electric locomotive controls
372
+ case CABViewControlTypes . LINE_VOLTAGE :
373
+ case CABViewControlTypes . ORTS_PANTOGRAPH_VOLTAGE_AC :
374
+ case CABViewControlTypes . ORTS_PANTOGRAPH_VOLTAGE_DC :
375
+ case CABViewControlTypes . PANTO_DISPLAY :
376
+ case CABViewControlTypes . PANTOGRAPH :
377
+ case CABViewControlTypes . PANTOGRAPH2 :
378
+ case CABViewControlTypes . ORTS_PANTOGRAPH3 :
379
+ case CABViewControlTypes . ORTS_PANTOGRAPH4 :
380
+ case CABViewControlTypes . PANTOGRAPHS_4 :
381
+ case CABViewControlTypes . PANTOGRAPHS_4C :
382
+ case CABViewControlTypes . PANTOGRAPHS_5 :
383
+ case CABViewControlTypes . ORTS_VOLTAGE_SELECTOR :
384
+ case CABViewControlTypes . ORTS_PANTOGRAPH_SELECTOR :
385
+ case CABViewControlTypes . ORTS_POWER_LIMITATION_SELECTOR :
386
+ case CABViewControlTypes . ORTS_CIRCUIT_BREAKER_DRIVER_CLOSING_ORDER :
387
+ case CABViewControlTypes . ORTS_CIRCUIT_BREAKER_DRIVER_OPENING_ORDER :
388
+ case CABViewControlTypes . ORTS_CIRCUIT_BREAKER_DRIVER_CLOSING_AUTHORIZATION :
389
+ case CABViewControlTypes . ORTS_CIRCUIT_BREAKER_STATE :
390
+ case CABViewControlTypes . ORTS_CIRCUIT_BREAKER_CLOSED :
391
+ case CABViewControlTypes . ORTS_CIRCUIT_BREAKER_OPEN :
392
+ case CABViewControlTypes . ORTS_CIRCUIT_BREAKER_AUTHORIZED :
393
+ case CABViewControlTypes . ORTS_CIRCUIT_BREAKER_OPEN_AND_AUTHORIZED :
394
+ data = ( ControlActiveLocomotive as MSTSElectricLocomotive ) ? . GetDataOf ( cvc ) ?? 0 ;
395
+ break ;
396
+ default :
397
+ data = base . GetDataOf ( cvc ) ;
398
+ break ;
399
+ }
400
+ return data ;
401
+ }
299
402
}
300
403
}
0 commit comments