-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTrain.cs
3096 lines (2960 loc) · 111 KB
/
Train.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Text;
using OpenBveApi.Runtime;
using Plugin.AI;
namespace Plugin {
/// <summary>Represents a train that is simulated by this plugin.</summary>
internal class Train {
// --- classes and enumerations ---
/// <summary>Represents handles that can only be read from.</summary>
internal class ReadOnlyHandles {
// --- members ---
/// <summary>The reverser position.</summary>
private int MyReverser;
/// <summary>The power notch.</summary>
private int MyPowerNotch;
/// <summary>The brake notch.</summary>
private int MyBrakeNotch;
/// <summary>Whether the const speed system is enabled.</summary>
private bool MyConstSpeed;
// --- properties ---
/// <summary>Gets or sets the reverser position.</summary>
internal int Reverser {
get {
return this.MyReverser;
}
}
/// <summary>Gets or sets the power notch.</summary>
internal int PowerNotch {
get {
return this.MyPowerNotch;
}
}
/// <summary>Gets or sets the brake notch.</summary>
internal int BrakeNotch {
get {
return this.MyBrakeNotch;
}
}
/// <summary>Gets or sets whether the const speed system is enabled.</summary>
internal bool ConstSpeed {
get {
return this.MyConstSpeed;
}
}
// --- constructors ---
/// <summary>Creates a new instance of this class.</summary>
/// <param name="handles">The handles</param>
internal ReadOnlyHandles(Handles handles) {
this.MyReverser = handles.Reverser;
this.MyPowerNotch = handles.PowerNotch;
this.MyBrakeNotch = handles.BrakeNotch;
this.MyConstSpeed = handles.ConstSpeed;
}
}
// --- plugin ---
/// <summary>Whether the plugin is currently initializing. This happens in-between Initialize and Elapse calls, for example when jumping to a station from the menu.</summary>
internal bool PluginInitializing;
// --- train ---
/// <summary>The train specifications.</summary>
internal VehicleSpecs Specs;
/// <summary>The current state of the train.</summary>
internal VehicleState State;
/// <summary>The driver handles at the last Elapse call.</summary>
internal ReadOnlyHandles Handles;
internal KeyConfiguration CurrentKeyConfiguration = new KeyConfiguration(false);
/// <summary>The current state of the doors.</summary>
internal DoorStates Doors;
/// <summary>Stores whether any safety systems have been tripped.</summary>
internal bool overspeedtripped;
internal bool drastate;
//internal bool deadmanstripped;
/// <summary>Stores whether the startup self-test has been performed.</summary>
internal static bool selftest = false;
/// <summary>Stores whether the master switch is on (Affects in-cab lights etc)</summary>
internal bool MasterSwitch = false;
/// <summary>Stores whether we can fuel the train.</summary>
internal bool canfuel;
// --- acceleration ---
/// <summary>The speed.</summary>
internal int CurrentSpeed;
/// <summary>The current location of the train.</summary>
internal double TrainLocation;
internal double PreviousLocation;
/// <summary>The next signal</summary>
internal SignalData NextSignal;
/// <summary>The in-game time of day, in seconds.</summary>
internal static double SecondsSinceMidnight;
/// <summary>The current value of the accelerometer.</summary>
internal double Acceleration;
/// <summary>The speed of the train at the beginning of the accelerometer timer.</summary>
private double AccelerometerSpeed;
/// <summary>The time elapsed since the last reset of the accelerometer timer.</summary>
private double AccelerometerTimer;
/// <summary>The maximum value for the accelerometer timer.</summary>
private const double AccelerometerMaximumTimer = 0.25;
// --- panel and sound ---
/// <summary>The panel variables.</summary>
internal int[] Panel;
/// <summary>Whether illumination in the panel is enabled.</summary>
internal bool PanelIllumination;
/// <summary>Remembers which of the virtual keys are currently pressed down.</summary>
private readonly bool[] KeysPressed;
// --- devices ---
/// <summary>Traction Manager- Manages brake and power applications</summary>
internal TractionManager TractionManager;
/// <summary>Steam Traction or Null Reference if not installed</summary>
internal steam SteamEngine;
/// <summary>Electric Traction or Null Reference if not installed</summary>
internal Electric ElectricEngine;
/// <summary>Diesel Traction or Null Reference if not installed</summary>
internal Diesel DieselEngine;
/// <summary>Vigilance Devices or Null Reference if not installed</summary>
/// Overspeed, deadman's handle & DRA
internal Vigilance Vigilance;
/// <summary>AWS System</summary>
internal AWS AWS;
/// <summary>TPWS System</summary>
internal TPWS TPWS;
/// <summary>SCMT System</summary>
internal SCMT SCMT;
/// <summary>SCMT Traction Modelling System</summary>
internal SCMT_Traction SCMT_Traction;
/// <summary>CAWS System</summary>
internal CAWS CAWS;
/// <summary>PZB System</summary>
internal PZB PZB;
/// <summary>Startup Self-Test Manager</summary>
internal StartupSelfTestManager StartupSelfTestManager;
/// <summary>Windscreen & Wipers</summary>
internal Windscreen Windscreen;
/// <summary>Advanced animation handlers</summary>
internal Animations Animations;
/// <summary>The AI Driver</summary>
internal AI.AI_Driver Driver;
internal DebugLogger DebugLogger;
/*
* DEVICES ADDED FROM ODAKYUFANATS
*
*/
/// <summary>The AI component that calls out signal aspects and speed restrictions.</summary>
internal Calling Calling;
// --- devices ---
/// <summary>The ATS-Sx device, or a null reference if not installed.</summary>
internal AtsSx AtsSx;
/// <summary>The ATS-Ps device, or a null reference if not installed.</summary>
internal AtsPs AtsPs;
/// <summary>The ATS-P device, or a null reference if not installed.</summary>
internal AtsP AtsP;
/// <summary>The ATC device, or a null reference if not installed.</summary>
internal Atc Atc;
/// <summary>The EB device, or a null reference if not installed.</summary>
internal Eb Eb;
/// <summary>The TASC device, or a null reference if not installed.</summary>
internal Tasc Tasc;
/// <summary>The ATO device, or a null reference if not installed.</summary>
internal Ato Ato;
/// <summary>The F92 device, or a null reference if not installed.</summary>
internal F92 F92;
#if !DebugNBS
//internal LEDLights LedLights;
#endif
internal WesternDiesel WesternDiesel;
/// <summary>A list of all the devices installed on this train</summary>
internal Device[] Devices;
// --- constructors ---
/// <summary>Creates a new train without any devices installed.</summary>
/// <param name="panel">The array of panel variables.</param>
internal Train(int[] panel) {
this.PluginInitializing = false;
this.Specs = new VehicleSpecs(0, BrakeTypes.ElectromagneticStraightAirBrake, 0, false, 0);
this.State = new VehicleState(0.0, new Speed(0.0), 0.0, 0.0, 0.0, 0.0, 0.0);
this.Handles = new ReadOnlyHandles(new Handles(0, 0, 0, false));
this.Doors = DoorStates.None;
this.Panel = panel;
this.KeysPressed = new bool[Enum.GetNames(typeof(VirtualKeys)).Length]; // to allow building against newer OpenBVEAPI versions with longer VirtualKey lengths
}
internal void LoadAWSTPWS()
{
if (this.AWS != null)
{
return;
}
//This function loads AWS and TPWS into memory
this.TPWS = new TPWS(this);
this.AWS = new AWS(this);
this.StartupSelfTestManager = new StartupSelfTestManager(this);
}
// --- functions ---
/// <summary>Sets up the devices from the specified configuration file.</summary>
/// <param name="lines">A string array containing the lines read from the configuration file.</param>
internal void LoadConfigurationFile(string[] lines) {
//Initialise all safety devices first
//Set Enabled state if they are installed
//Only initialise traction types if required
this.TractionManager = new TractionManager(this);
//this.Calling = new Calling(this, playSound);
this.Driver = new AI_Driver(this);
this.DebugLogger = new DebugLogger();
this.SCMT = new SCMT(this);
this.SCMT_Traction = new SCMT_Traction(this);
this.Windscreen = new Windscreen(this);
this.Animations = new Animations(this);
string section = string.Empty;
foreach (string line in lines)
{
//First, check to see if we're running in debug mode
//This needs to be done first, followed by a reparse of the configuration file
//to actually load traction types etc.
if (line.Length != 0 && line[0] == '[' & line[line.Length - 1] == ']')
{
section = line.Substring(1, line.Length - 2).ToLowerInvariant();
if (section == "debug")
{
DebugLogger.DebugDate = DateTime.Now.ToString("dd-MM-yyyy");
DebugLogger.DebugLogEnabled = true;
string version = Assembly.GetEntryAssembly().GetName().Version.ToString();
DebugLogger.LogMessage("BVEC_ATS " + version + " loaded");
}
if (section == "legacykeyassignments")
{
DebugLogger.LogMessage("Using legacy upgraded key assignments");
CurrentKeyConfiguration = new KeyConfiguration(true);
}
}
}
foreach (string t in lines)
{
string line = t;
int semicolon = line.IndexOf(';');
if (semicolon >= 0) {
line = line.Substring(0, semicolon).Trim();
} else {
line = line.Trim();
}
if (line.Length != 0) {
if (line[0] == '[' & line[line.Length - 1] == ']') {
section = line.Substring(1, line.Length - 2).ToLowerInvariant();
switch (section) {
case "steam":
this.SteamEngine = new steam(this);
DebugLogger.LogMessage("Steam traction enabled");
break;
case "diesel":
this.DieselEngine = new Diesel(this);
DebugLogger.LogMessage("Diesel traction enabled");
break;
case "electric":
this.ElectricEngine = new Electric(this);
DebugLogger.LogMessage("Electric traction enabled");
break;
case "vigilance":
this.Vigilance = new Vigilance(this);
DebugLogger.LogMessage("Vigilance system(s) enabled");
break;
case "aws":
LoadAWSTPWS();
this.AWS.Enabled = true;
DebugLogger.LogMessage("AWS enabled");
break;
case "tpws":
LoadAWSTPWS();
this.TPWS.Enabled = true;
DebugLogger.LogMessage("TPWS enabled");
break;
case "scmt":
this.SCMT.Enabled = true;
this.SCMT_Traction.Enabled = true;
DebugLogger.LogMessage("SCMT enabled");
break;
case "caws":
this.CAWS = new CAWS(this);
this.CAWS.Enabled = true;
DebugLogger.LogMessage("CAWS enabled");
break;
case "pzb":
this.PZB = new PZB(this);
this.PZB.Enabled = true;
DebugLogger.LogMessage("PZB enabled");
break;
case "animations":
case "debug":
case "interlocks":
case "keyassignments":
case "legacykeyassignments":
case "settings":
//These don't necessarily need their own parser settings
break;
#if !DebugNBS
//case "ledlights":
//this.LedLights = new LEDLights(this);
//break;
#endif
case "windscreen":
this.Windscreen.Enabled = true;
DebugLogger.LogMessage("Windscreen enabled");
break;
case "ats-sx":
this.AtsSx = new AtsSx(this);
break;
case "ats-ps":
this.AtsPs = new AtsPs(this);
break;
case "ats-p":
this.AtsP = new AtsP(this);
break;
case "atc":
this.Atc = new Atc(this);
break;
case "eb":
this.Eb = new Eb(this);
break;
case "tasc":
this.Tasc = new Tasc(this);
break;
case "ato":
this.Ato = new Ato(this);
break;
case "westerndiesel":
this.WesternDiesel = new WesternDiesel(this);
break;
default:
throw new InvalidDataException("The section " + section + " is not supported.");
}
} else {
int equals = line.IndexOf('=');
if (@equals >= 0) {
string key = line.Substring(0, @equals).Trim().ToLowerInvariant();
string value = line.Substring(@equals + 1).Trim();
string[] splitValue = value.Split(',');
switch (section) {
case "steam":
switch (key) {
case "automatic":
InternalFunctions.ParseBool(value, ref TractionManager.AutomaticAdvancedFunctions, key);
break;
case "heatingpart":
InternalFunctions.ValidateSetting(value, ref SteamEngine.heatingpart, key);
break;
case "heatingrate":
this.SteamEngine.heatingrate = value;
break;
case "overheatwarn":
InternalFunctions.ParseNumber(value, ref SteamEngine.overheatwarn, key);
break;
case "overheat":
InternalFunctions.ParseNumber(value, ref SteamEngine.overheat, key);
break;
case "overheatresult":
InternalFunctions.ValidateSetting(value, ref SteamEngine.overheatresult, key);
break;
case "thermometer":
InternalFunctions.ValidateIndex(value, ref SteamEngine.thermometer, key);
break;
case "overheatindicator":
InternalFunctions.ValidateIndex(value, ref SteamEngine.overheatindicator, key);
break;
case "overheatalarm":
InternalFunctions.ValidateIndex(value, ref SteamEngine.OverheatAlarm.LoopSound, key);
break;
case "cutoffmax":
InternalFunctions.ParseNumber(value, ref SteamEngine.cutoffmax, key);
break;
case "cutoffineffective":
InternalFunctions.ParseNumber(value, ref SteamEngine.cutoffineffective, key);
break;
case "cutoffratio":
InternalFunctions.ParseNumber(value, ref SteamEngine.cutoffratio, key);
break;
case "cutoffratiobase":
InternalFunctions.ParseNumber(value, ref SteamEngine.cutoffratiobase, key);
break;
case "cutoffmin":
InternalFunctions.ParseNumber(value, ref SteamEngine.cutoffmin, key);
break;
case "cutoffdeviation":
InternalFunctions.ParseNumber(value, ref SteamEngine.cutoffdeviation, key);
break;
case "cutoffindicator":
InternalFunctions.ValidateIndex(value, ref SteamEngine.cutoffindicator, key);
break;
case "boilermaxpressure":
InternalFunctions.ParseNumber(value, ref SteamEngine.boilermaxpressure, key);
break;
case "boilerminpressure":
InternalFunctions.ParseNumber(value, ref SteamEngine.boilerminpressure, key);
break;
case "boilerstartwaterlevel":
InternalFunctions.ParseNumber(value, ref SteamEngine.boilerstartwaterlevel, key);
break;
case "boilermaxwaterlevel":
InternalFunctions.ParseNumber(value, ref SteamEngine.boilermaxwaterlevel, key);
break;
case "boilerpressureindicator":
InternalFunctions.ValidateIndex(value, ref SteamEngine.boilerpressureindicator, key);
break;
case "boilerwaterlevelindicator":
InternalFunctions.ValidateIndex(value, ref SteamEngine.boilerwaterlevelindicator, key);
break;
case "boilerwatertosteamrate":
InternalFunctions.ParseNumber(value, ref SteamEngine.boilerwatertosteamrate, key);
break;
case "fuelindicator":
InternalFunctions.ValidateIndex(value, ref SteamEngine.fuelindicator, key);
break;
case "fuelstartamount":
InternalFunctions.ParseNumber(value, ref SteamEngine.fuelstartamount, key);
break;
case "fuelcapacity":
InternalFunctions.ParseNumber(value, ref SteamEngine.fuelcapacity, key);
break;
case "fuelfillspeed":
InternalFunctions.ParseNumber(value, ref SteamEngine.fuelfillspeed, key);
break;
case "fuelfillindicator":
InternalFunctions.ValidateIndex(value, ref SteamEngine.fuelfillindicator, key);
break;
case "injectorrate":
case "livesteaminjectorrate":
//By default, OS_ATS uses a single live-steam injector, which shares a common water and steam rate
for (int k = 0; k < splitValue.Length; k++)
{
switch (k)
{
case 0:
InternalFunctions.ParseNumber(splitValue[k], ref SteamEngine.LiveSteamInjector.WaterRate, key);
if (splitValue.Length == 1)
{
InternalFunctions.ParseNumber(splitValue[k], ref SteamEngine.LiveSteamInjector.SteamRate, key);
}
break;
case 1:
InternalFunctions.ParseNumber(splitValue[k], ref SteamEngine.LiveSteamInjector.SteamRate, key);
break;
default:
InternalFunctions.LogError("Unexpected extra paramaters were found in " + key + ". These have been ignored.", 6);
break;
}
}
InternalFunctions.ParseNumber(value, ref SteamEngine.LiveSteamInjector.WaterRate, key);
break;
case "exhauststeaminjectorrate":
for (int k = 0; k < splitValue.Length; k++)
{
switch (k)
{
case 0:
InternalFunctions.ParseNumber(splitValue[k], ref SteamEngine.LiveSteamInjector.WaterRate, key);
break;
case 1:
InternalFunctions.ParseNumber(splitValue[k], ref SteamEngine.LiveSteamInjector.MinimumPowerNotch, key);
break;
default:
InternalFunctions.LogError("Unexpected extra paramaters were found in " + key + ". These have been ignored.", 6);
break;
}
}
break;
case "injectorindicator":
case "livesteaminjectorindicator":
InternalFunctions.ValidateIndex(value, ref SteamEngine.LiveSteamInjector.PanelIndex, key);
break;
case "exhauststeaminjectorindicator":
InternalFunctions.ValidateIndex(value, ref SteamEngine.ExhaustSteamInjector.PanelIndex, key);
break;
case "automaticindicator":
InternalFunctions.ValidateIndex(value, ref SteamEngine.automaticindicator, key);
break;
case "injectorsound":
case "livesteaminjectorsound":
splitValue = value.Split(',');
for (int k = 0; k < splitValue.Length; k++)
{
switch (k)
{
case 0:
InternalFunctions.ValidateIndex(splitValue[k], ref SteamEngine.LiveSteamInjector.LoopSound, key);
break;
case 1:
InternalFunctions.ValidateIndex(splitValue[k], ref SteamEngine.LiveSteamInjector.PlayOnceSound, key);
break;
default:
InternalFunctions.LogError("Unexpected extra paramaters were found in " + key + ". These have been ignored.", 6);
break;
}
}
break;
case "exhauststeaminjectorsound":
splitValue = value.Split(',');
for (int k = 0; k < splitValue.Length; k++)
{
switch (k)
{
case 0:
InternalFunctions.ValidateIndex(splitValue[k], ref SteamEngine.ExhaustSteamInjector.LoopSound, key);
break;
case 1:
InternalFunctions.ValidateIndex(splitValue[k], ref SteamEngine.ExhaustSteamInjector.PlayOnceSound, key);
break;
default:
InternalFunctions.LogError("Unexpected extra paramaters were found in " + key + ". These have been ignored.", 6);
break;
}
}
break;
case "cylindercocksound":
string[] cylindersplit = value.Split(',');
for (int k = 0; k < cylindersplit.Length; k++)
{
if (k == 0)
{
InternalFunctions.ValidateIndex(cylindersplit[0], ref SteamEngine.CylinderCocks.LoopSound, key);
}
else if(k == 1)
{
InternalFunctions.ValidateIndex(cylindersplit[1], ref SteamEngine.CylinderCocks.PlayOnceSound, key);
}
else
{
InternalFunctions.LogError("Unexpected extra paramaters were found in cylindercocksound. These have been ignored.",6);
break;
}
}
break;
case "cylindercocksindicator":
InternalFunctions.ValidateIndex(value, ref SteamEngine.CylinderCocks.PanelIndex, key);
break;
case "blowoffsound":
InternalFunctions.ValidateIndex(value, ref SteamEngine.Blowoff.SoundIndex, key);
break;
case "blowoffindicator":
InternalFunctions.ValidateIndex(value, ref SteamEngine.Blowoff.PanelIndex, key);
break;
case "blowofftime":
InternalFunctions.ParseNumber(value, ref SteamEngine.Blowoff.BlowoffTime, key);
break;
case "klaxonpressureuse":
InternalFunctions.ParseNumber(value, ref SteamEngine.klaxonpressureuse, key);
break;
case "blowers_pressurefactor":
InternalFunctions.ParseNumber(value, ref SteamEngine.Blowers.PressureIncreaseFactor, key);
break;
case "blowers_firefactor":
InternalFunctions.ParseNumber(value, ref SteamEngine.Blowers.PressureIncreaseFactor, key);
break;
case "blowersound":
InternalFunctions.ValidateIndex(value, ref SteamEngine.Blowers.LoopSound, key);
break;
case "blowersindicator":
InternalFunctions.ValidateIndex(value, ref SteamEngine.Blowers.PanelIndex, key);
break;
case "steamheatindicator":
InternalFunctions.ValidateIndex(value, ref SteamEngine.steamheatindicator, key);
break;
case "steamheatpressureuse":
InternalFunctions.ParseNumber(value, ref SteamEngine.steamheatpressureuse, key);
break;
case "boilerblowoffpressure":
InternalFunctions.ParseNumber(value, ref SteamEngine.Blowoff.TriggerPressure, key);
break;
case "regulatorpressureuse":
InternalFunctions.ParseNumber(value, ref SteamEngine.regulatorpressureuse, key);
break;
case "cylindercocks_pressureuse":
string[] cylindercocksplit = value.Split(',');
for (int k = 0; k < cylindercocksplit.Length; k++)
{
if (k == 0)
{
InternalFunctions.ParseNumber(cylindercocksplit[0], ref SteamEngine.cylindercocks_basepressureuse, key);
}
else
{
InternalFunctions.ParseNumber(cylindercocksplit[1], ref SteamEngine.cylindercocks_notchpressureuse, key);
}
}
break;
default:
throw new InvalidDataException("The parameter " + key + " is not supported.");
}
break;
case "electric":
switch (key)
{
case "heatingpart":
InternalFunctions.ValidateSetting(value, ref ElectricEngine.heatingpart, key);
break;
case "heatingrate":
InternalFunctions.ParseStringToIntArray(value, ref ElectricEngine.HeatingRates, "heatingrate");
break;
case "overheatwarn":
InternalFunctions.ParseNumber(value, ref ElectricEngine.overheatwarn, key);
break;
case "overheat":
InternalFunctions.ParseNumber(value, ref ElectricEngine.overheat, key);
break;
case "overheatresult":
InternalFunctions.ValidateSetting(value, ref ElectricEngine.overheatresult, key);
break;
case "thermometer":
InternalFunctions.ValidateIndex(value, ref ElectricEngine.thermometer, key);
break;
case "overheatindicator":
InternalFunctions.ValidateIndex(value, ref ElectricEngine.overheatindicator, key);
break;
case "overheatalarm":
InternalFunctions.ValidateIndex(value, ref ElectricEngine.overheatalarm, key);
break;
case "ammeter":
InternalFunctions.ValidateIndex(value, ref ElectricEngine.Ammeter.PanelIndex, key);
break;
case "ammetervalues":
this.ElectricEngine.Ammeter.Initialize(value);
break;
case "powerpickuppoints":
InternalFunctions.ParseStringToDoubleArray(value, ref ElectricEngine.PickupLocations, "pickuppoints");
break;
case "powergapbehaviour":
int pgb = 0;
InternalFunctions.ValidateSetting(value, ref pgb, key);
if (pgb < 0 || pgb > 3)
{
InternalFunctions.LogError("powergapbehaviour",0);
break;
}
ElectricEngine.PowerGapBehaviour = (PowerGapBehaviour) pgb;
break;
case "powerindicator":
InternalFunctions.ValidateIndex(value, ref ElectricEngine.powerindicator, key);
break;
case "breakersound":
InternalFunctions.ValidateIndex(value, ref ElectricEngine.breakersound, key);
break;
case "breakerindicator":
InternalFunctions.ValidateIndex(value, ref ElectricEngine.breakerindicator, key);
break;
case "pantographindicator_f":
InternalFunctions.ValidateIndex(value, ref ElectricEngine.FrontPantograph.PanelIndex, key);
break;
case "pantographindicator_r":
InternalFunctions.ValidateIndex(value, ref ElectricEngine.RearPantograph.PanelIndex, key);
break;
case "pantographraisedsound":
InternalFunctions.ValidateIndex(value, ref ElectricEngine.FrontPantograph.RaisedSound, key);
InternalFunctions.ValidateIndex(value, ref ElectricEngine.RearPantograph.RaisedSound, key);
break;
case "pantographloweredsound":
InternalFunctions.ValidateIndex(value, ref ElectricEngine.FrontPantograph.LoweredSound, key);
InternalFunctions.ValidateIndex(value, ref ElectricEngine.RearPantograph.LoweredSound, key);
break;
case "pantographalarmsound":
InternalFunctions.ValidateIndex(value, ref ElectricEngine.FrontPantograph.AlarmSound, key);
InternalFunctions.ValidateIndex(value, ref ElectricEngine.RearPantograph.AlarmSound, key);
break;
case "pantographretryinterval":
InternalFunctions.ParseNumber(value, ref ElectricEngine.pantographretryinterval, key);
break;
case "pantographalarmbehaviour":
InternalFunctions.ValidateSetting(value, ref ElectricEngine.pantographalarmbehaviour, key);
break;
case "pantographfitted":
bool b = true;
InternalFunctions.ParseBool(value, ref b, key);
if (!b)
{
CurrentKeyConfiguration.FrontPantograph = null;
CurrentKeyConfiguration.RearPantograph = null;
}
break;
case "powerloopsound":
try
{
string[] powerloopsplit = value.Split(',');
for (int k = 0; k < powerloopsplit.Length; k++)
{
if (k == 0)
{
this.ElectricEngine.powerloopsound = Convert.ToInt32(powerloopsplit[0]);
}
else
{
this.ElectricEngine.powerlooptime = Convert.ToInt32(powerloopsplit[1]);
}
}
}
catch
{
InternalFunctions.LogError("powerloopsound",0);
}
break;
case "breakerloopsound":
try
{
string[] breakerloopsplit = value.Split(',');
for (int k = 0; k < breakerloopsplit.Length; k++)
{
if (k == 0)
{
this.ElectricEngine.breakerloopsound = Convert.ToInt32(breakerloopsplit[0]);
}
else
{
this.ElectricEngine.breakerlooptime = Convert.ToInt32(breakerloopsplit[1]);
}
}
}
catch
{
InternalFunctions.LogError("breakerloopsound",0);
}
break;
case "automaticpantographlowerbehaviour":
int s = -1;
InternalFunctions.ValidateSetting(value, ref s, key);
if (s < 0 || s > 5)
{
InternalFunctions.LogError("AutomaticPantographLowerBehaviour was not within the range of valid values.",6);
break;
}
ElectricEngine.PantographLoweringMode = (Electric.AutomaticPantographLoweringModes)s;
break;
case "automaticpantographlowerspeed":
InternalFunctions.ParseNumber(value, ref ElectricEngine.AutomaticPantographLowerSpeed, key);
break;
default:
throw new InvalidDataException("The parameter " + key + " is not supported.");
}
break;
case "diesel":
switch (key)
{
case "ammeter":
InternalFunctions.ValidateIndex(value, ref DieselEngine.Ammeter.PanelIndex, key);
break;
case "ammetervalues":
this.DieselEngine.Ammeter.Initialize(value);
break;
case "automatic":
InternalFunctions.ParseBool(value, ref TractionManager.AutomaticAdvancedFunctions, key);
break;
case "heatingpart":
InternalFunctions.ValidateSetting(value, ref DieselEngine.heatingpart, key);
break;
case "heatingrate":
this.DieselEngine.heatingrate = value;
break;
case "overheatwarn":
InternalFunctions.ParseNumber(value, ref DieselEngine.overheatwarn, key);
break;
case "overheat":
InternalFunctions.ParseNumber(value, ref DieselEngine.overheat, key);
break;
case "overheatresult":
InternalFunctions.ValidateSetting(value, ref DieselEngine.overheatresult, key);
break;
case "thermometer":
InternalFunctions.ValidateIndex(value, ref DieselEngine.thermometer, key);
break;
case "overheatindicator":
InternalFunctions.ValidateIndex(value, ref DieselEngine.overheatindicator, key);
break;
case "overheatalarm":
InternalFunctions.ValidateIndex(value, ref DieselEngine.overheatalarm, key);
break;
case "fuelstartamount":
InternalFunctions.ParseNumber(value, ref DieselEngine.fuelstartamount, key);
break;
case "fuelindicator":
InternalFunctions.ValidateIndex(value, ref DieselEngine.fuelindicator, key);
break;
case "automaticindicator":
InternalFunctions.ValidateIndex(value, ref DieselEngine.automaticindicator, key);
break;
case "gearratios":
this.DieselEngine.gearratios = value;
break;
case "gearfadeinrange":
this.DieselEngine.gearfadeinrange = value;
break;
case "gearfadeoutrange":
this.DieselEngine.gearfadeoutrange = value;
break;
case "gearindicator":
InternalFunctions.ValidateIndex(value, ref DieselEngine.gearindicator, key);
break;
case "gearchangesound":
InternalFunctions.ValidateIndex(value, ref DieselEngine.GearChangeSound, key);
break;
case "tachometer":
InternalFunctions.ValidateIndex(value, ref DieselEngine.tachometer, key);
break;
case "allowneutralrevs":
InternalFunctions.ValidateSetting(value, ref DieselEngine.allowneutralrevs, key);
break;
case "revsupsound":
InternalFunctions.ValidateIndex(value, ref DieselEngine.revsupsound, key);
break;
case "revsdownsound":
InternalFunctions.ValidateIndex(value, ref DieselEngine.revsdownsound, key);
break;
case "motorsound":
InternalFunctions.ValidateIndex(value, ref DieselEngine.motorsound, key);
break;
case "fuelconsumption":
this.DieselEngine.fuelconsumption = value;
break;
case "fuelcapacity":
InternalFunctions.ParseNumber(value, ref DieselEngine.fuelcapacity, key);
break;
case "fuelfillspeed":
InternalFunctions.ParseNumber(value, ref DieselEngine.fuelfillspeed, key);
break;
case "fuelfillindicator":
InternalFunctions.ValidateIndex(value, ref DieselEngine.fuelfillindicator, key);
break;
case "gearloopsound":
try
{
string[] gearloopsplit = value.Split(',');
for (int k = 0; k < gearloopsplit.Length; k++)
{
if (k == 0)
{
this.DieselEngine.gearloopsound = Convert.ToInt32(gearloopsplit[0]);
}
else
{
this.DieselEngine.gearlooptime = Convert.ToInt32(gearloopsplit[1]);
}
}
}
catch
{
InternalFunctions.LogError("gearloopsound",0);
}
break;
case "reversercontrol":
InternalFunctions.ValidateSetting(value, ref DieselEngine.reversercontrol, key);
break;
default:
throw new InvalidDataException("The parameter " + key + " is not supported.");
}
break;
case "westerndiesel":
switch (key)
{
case "ilcluster1":
InternalFunctions.ValidateIndex(value, ref WesternDiesel.ILCluster1, key);
break;
case "ilcluster2":
InternalFunctions.ValidateIndex(value, ref WesternDiesel.ILCluster2, key);
break;
case "masterkey":
InternalFunctions.ValidateIndex(value, ref WesternDiesel.MasterKeyIndex, key);
break;
case "startdelay":
InternalFunctions.ParseNumber(value, ref WesternDiesel.Engine1Starter.StartDelay, key);
InternalFunctions.ParseNumber(value, ref WesternDiesel.Engine2Starter.StartDelay, key);
break;
case "fireupdelay":
InternalFunctions.ParseNumber(value, ref WesternDiesel.Engine1Starter.FireUpDelay, key);
InternalFunctions.ParseNumber(value, ref WesternDiesel.Engine2Starter.FireUpDelay, key);
break;
case "rundowndelay":
InternalFunctions.ParseNumber(value, ref WesternDiesel.Engine1Starter.RunDownDelay, key);
InternalFunctions.ParseNumber(value, ref WesternDiesel.Engine2Starter.RunDownDelay, key);
break;
case "dsdsound":
InternalFunctions.ValidateIndex(value, ref WesternDiesel.DSDBuzzer, key);
break;
case "neutralselectedsound":
InternalFunctions.ValidateIndex(value, ref WesternDiesel.NeutralSelectedSound, key);
break;
case "engineloopsound":
InternalFunctions.ValidateIndex(value, ref WesternDiesel.EngineLoopSound, key);
break;
case "turborunupsound":
InternalFunctions.ValidateIndex(value, ref WesternDiesel.Turbocharger.TurbochargerRunUpSound, key);
break;
case "turboloopsound":
InternalFunctions.ValidateIndex(value, ref WesternDiesel.Turbocharger.TurbochargerLoopSound, key);
break;
case "turborundownsound":
InternalFunctions.ValidateIndex(value, ref WesternDiesel.Turbocharger.TurbochargerRunDownSound, key);
break;
case "enginefiresound":
InternalFunctions.ValidateIndex(value, ref WesternDiesel.Engine1Starter.EngineFireSound, key);
InternalFunctions.ValidateIndex(value, ref WesternDiesel.Engine2Starter.EngineFireSound, key);
break;
case "enginestallsound":
InternalFunctions.ValidateIndex(value, ref WesternDiesel.Engine1Starter.EngineStallSound, key);
InternalFunctions.ValidateIndex(value, ref WesternDiesel.Engine2Starter.EngineStallSound, key);
break;
case "enginestopsound":
InternalFunctions.ValidateIndex(value, ref WesternDiesel.EngineStopSound, key);
break;
case "starterloopsound":
InternalFunctions.ValidateIndex(value, ref WesternDiesel.Engine1Starter.StarterLoopSound, key);
InternalFunctions.ValidateIndex(value, ref WesternDiesel.Engine2Starter.StarterLoopSound, key);
break;
case "starterrunupsound":
InternalFunctions.ValidateIndex(value, ref WesternDiesel.Engine1Starter.StarterRunUpSound, key);
InternalFunctions.ValidateIndex(value, ref WesternDiesel.Engine2Starter.StarterRunUpSound, key);
break;
case "switchsound":
InternalFunctions.ValidateIndex(value, ref WesternDiesel.SwitchSound, key);
break;
case "masterkeysound":
InternalFunctions.ValidateIndex(value, ref WesternDiesel.MasterKeySound, key);
break;
case "firebellsound":
InternalFunctions.ValidateIndex(value, ref WesternDiesel.FireBellSound, key);
break;
case "firebellindex":
InternalFunctions.ValidateIndex(value, ref WesternDiesel.FireBellIndex, key);
break;
case "voltsgauge":
InternalFunctions.ValidateIndex(value, ref WesternDiesel.BatteryVoltsGauge, key);
break;
case "ampsgauge":
InternalFunctions.ValidateIndex(value, ref WesternDiesel.BatteryChargeGauge, key);