-
Notifications
You must be signed in to change notification settings - Fork 52
/
CsvRwRouteParser.cs
6524 lines (6484 loc) · 401 KB
/
CsvRwRouteParser.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 OpenBveApi;
using OpenBveApi.Colors;
using OpenBveApi.Math;
namespace OpenBve {
internal partial class CsvRwRouteParser {
/// <summary>An abstract signal - All signals must inherit from this class</summary>
private abstract class SignalData { }
// ---SIGNAL TYPES---
/// <summary>Defines a BVE 4 standard signal:
/// A signal has a face based mesh and glow
/// Textures are then substituted according to the aspect
/// </summary>
private class Bve4SignalData : SignalData {
internal ObjectManager.StaticObject BaseObject;
internal ObjectManager.StaticObject GlowObject;
internal Textures.Texture[] SignalTextures;
internal Textures.Texture[] GlowTextures;
}
/// <summary>Defines a default Japanese signal (See the documentation)</summary>
private class CompatibilitySignalData : SignalData {
internal readonly int[] Numbers;
internal readonly ObjectManager.StaticObject[] Objects;
internal CompatibilitySignalData(int[] Numbers, ObjectManager.StaticObject[] Objects) {
this.Numbers = Numbers;
this.Objects = Objects;
}
}
/// <summary>Defines an animated signal object:
/// The object is provided with the aspect number, and then should deal with the rest
/// </summary>
private class AnimatedObjectSignalData : SignalData {
internal ObjectManager.AnimatedObjectCollection Objects;
}
private struct RouteData {
internal double TrackPosition;
internal double BlockInterval;
/// <summary>OpenBVE runs internally in meters per second
/// This value is used to convert between the speed set by Options.UnitsOfSpeed and m/s
/// </summary>
internal double UnitOfSpeed;
/// <summary>If this bool is set to FALSE, then objects will disappear when the block in which their command is placed is exited via by the camera
/// Certain BVE2/4 era routes used this as an animation trick
/// </summary>
internal bool AccurateObjectDisposal;
internal bool SignedCant;
internal bool FogTransitionMode;
internal StructureData Structure;
internal SignalData[] Signals;
internal CompatibilitySignalData[] CompatibilitySignals;
internal Textures.Texture[] TimetableDaytime;
internal Textures.Texture[] TimetableNighttime;
internal BackgroundManager.BackgroundHandle[] Backgrounds;
internal double[] SignalSpeeds;
internal Block[] Blocks;
internal Marker[] Markers;
internal int FirstUsedBlock;
}
// parse route
internal static void ParseRoute(string FileName, bool IsRW, System.Text.Encoding Encoding, string TrainPath, string ObjectPath, string SoundPath, bool PreviewOnly) {
// initialize data
freeObjCount = 0;
railtypeCount = 0;
Game.UnitOfSpeed = "km/h";
Game.SpeedConversionFactor = 0.0;
Game.RouteInformation.RouteBriefing = null;
// customLoadScreen = false;
string CompatibilityFolder = Program.FileSystem.GetDataFolder("Compatibility");
if (!PreviewOnly)
{
CompatibilityObjects.LoadCompatibilityObjects(OpenBveApi.Path.CombineFile(CompatibilityFolder,"CompatibilityObjects.xml"));
}
RouteData Data = new RouteData
{
BlockInterval = 25.0,
AccurateObjectDisposal = false,
FirstUsedBlock = -1,
Blocks = new Block[1]
};
Data.Blocks[0] = new Block();
Data.Blocks[0].Rail = new Rail[1];
Data.Blocks[0].Rail[0].RailStart = true;
Data.Blocks[0].RailType = new int[] { 0 };
Data.Blocks[0].Limit = new Limit[] { };
Data.Blocks[0].Stop = new Stop[] { };
Data.Blocks[0].Station = -1;
Data.Blocks[0].StationPassAlarm = false;
Data.Blocks[0].Accuracy = 2.0;
Data.Blocks[0].AdhesionMultiplier = 1.0;
Data.Blocks[0].CurrentTrackState = new TrackManager.TrackElement(0.0);
if (!PreviewOnly)
{
Data.Blocks[0].Background = 0;
Data.Blocks[0].Brightness = new Brightness[] {};
Data.Blocks[0].Fog.Start = Game.NoFogStart;
Data.Blocks[0].Fog.End = Game.NoFogEnd;
Data.Blocks[0].Fog.Color = new Color24(128, 128, 128);
Data.Blocks[0].Cycle = new int[] {-1};
Data.Blocks[0].RailCycle = new RailCycle[1];
Data.Blocks[0].RailCycle[0].RailCycleIndex = -1;
Data.Blocks[0].Height = IsRW ? 0.3 : 0.0;
Data.Blocks[0].RailFreeObj = new FreeObj[][] {};
Data.Blocks[0].GroundFreeObj = new FreeObj[] {};
Data.Blocks[0].RailWall = new WallDike[] {};
Data.Blocks[0].RailDike = new WallDike[] {};
Data.Blocks[0].RailPole = new Pole[] {};
Data.Blocks[0].Form = new Form[] {};
Data.Blocks[0].Crack = new Crack[] {};
Data.Blocks[0].Signal = new Signal[] {};
Data.Blocks[0].Section = new Section[] {};
Data.Blocks[0].Sound = new Sound[] {};
Data.Blocks[0].Transponder = new Transponder[] {};
Data.Blocks[0].PointsOfInterest = new PointOfInterest[] {};
Data.Markers = new Marker[] {};
string PoleFolder = OpenBveApi.Path.CombineDirectory(CompatibilityFolder, "Poles");
Data.Structure.Poles = new ObjectManager.UnifiedObject[][]
{
new ObjectManager.UnifiedObject[]
{
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(PoleFolder, "pole_1.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false)
},
new ObjectManager.UnifiedObject[]
{
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(PoleFolder, "pole_2.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false)
},
new ObjectManager.UnifiedObject[]
{
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(PoleFolder, "pole_3.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false)
},
new ObjectManager.UnifiedObject[]
{
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(PoleFolder, "pole_4.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false)
}
};
Data.Structure.Rail = new ObjectManager.UnifiedObject[] {};
Data.Structure.Ground = new ObjectManager.UnifiedObject[] {};
Data.Structure.WallL = new ObjectManager.UnifiedObject[] {};
Data.Structure.WallR = new ObjectManager.UnifiedObject[] {};
Data.Structure.DikeL = new ObjectManager.UnifiedObject[] {};
Data.Structure.DikeR = new ObjectManager.UnifiedObject[] {};
Data.Structure.FormL = new ObjectManager.UnifiedObject[] {};
Data.Structure.FormR = new ObjectManager.UnifiedObject[] {};
Data.Structure.FormCL = new ObjectManager.StaticObject[] {};
Data.Structure.FormCR = new ObjectManager.StaticObject[] {};
Data.Structure.RoofL = new ObjectManager.UnifiedObject[] {};
Data.Structure.RoofR = new ObjectManager.UnifiedObject[] {};
Data.Structure.RoofCL = new ObjectManager.StaticObject[] {};
Data.Structure.RoofCR = new ObjectManager.StaticObject[] {};
Data.Structure.CrackL = new ObjectManager.StaticObject[] {};
Data.Structure.CrackR = new ObjectManager.StaticObject[] {};
Data.Structure.FreeObj = new ObjectManager.UnifiedObject[] {};
Data.Structure.Beacon = new ObjectManager.UnifiedObject[] {};
Data.Structure.Cycle = new int[][] {};
Data.Structure.RailCycle = new int[][] { };
Data.Structure.Run = new int[] {};
Data.Structure.Flange = new int[] {};
Data.Backgrounds = new BackgroundManager.StaticBackground[] {};
Data.TimetableDaytime = new Textures.Texture[] {null, null, null, null};
Data.TimetableNighttime = new Textures.Texture[] {null, null, null, null};
// signals
string SignalFolder = OpenBveApi.Path.CombineDirectory(CompatibilityFolder, "Signals");
Data.Signals = new SignalData[7];
Data.Signals[3] = new CompatibilitySignalData(new int[] {0, 2, 4}, new ObjectManager.StaticObject[]
{
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_3_0.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_3_2.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_3_4.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false)
});
Data.Signals[4] = new CompatibilitySignalData(new int[] {0, 1, 2, 4}, new ObjectManager.StaticObject[]
{
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_4_0.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_4a_1.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_4a_2.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_4a_4.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false)
});
Data.Signals[5] = new CompatibilitySignalData(new int[] {0, 1, 2, 3, 4}, new ObjectManager.StaticObject[]
{
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_5_0.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_5a_1.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_5_2.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_5_3.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_5_4.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false)
});
Data.Signals[6] = new CompatibilitySignalData(new int[] {0, 3, 4}, new ObjectManager.StaticObject[]
{
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "repeatingsignal_0.csv"),
Encoding, ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "repeatingsignal_3.csv"),
Encoding, ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "repeatingsignal_4.csv"),
Encoding, ObjectManager.ObjectLoadMode.Normal, false, false, false)
});
// compatibility signals
Data.CompatibilitySignals = new CompatibilitySignalData[9];
Data.CompatibilitySignals[0] = new CompatibilitySignalData(new int[] {0, 2},
new ObjectManager.StaticObject[]
{
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_2_0.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_2a_2.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false)
});
Data.CompatibilitySignals[1] = new CompatibilitySignalData(new int[] {0, 4},
new ObjectManager.StaticObject[]
{
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_2_0.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_2b_4.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false)
});
Data.CompatibilitySignals[2] = new CompatibilitySignalData(new int[] {0, 2, 4},
new ObjectManager.StaticObject[]
{
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_3_0.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_3_2.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_3_4.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false)
});
Data.CompatibilitySignals[3] = new CompatibilitySignalData(new int[] {0, 1, 2, 4},
new ObjectManager.StaticObject[]
{
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_4_0.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_4a_1.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_4a_2.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_4a_4.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false)
});
Data.CompatibilitySignals[4] = new CompatibilitySignalData(new int[] {0, 2, 3, 4},
new ObjectManager.StaticObject[]
{
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_4_0.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_4b_2.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_4b_3.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_4b_4.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false)
});
Data.CompatibilitySignals[5] = new CompatibilitySignalData(new int[] {0, 1, 2, 3, 4},
new ObjectManager.StaticObject[]
{
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_5_0.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_5a_1.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_5_2.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_5_3.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_5_4.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false)
});
Data.CompatibilitySignals[6] = new CompatibilitySignalData(new int[] {0, 2, 3, 4, 5},
new ObjectManager.StaticObject[]
{
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_5_0.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_5_2.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_5_3.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_5_4.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_5b_5.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false)
});
Data.CompatibilitySignals[7] = new CompatibilitySignalData(new int[] {0, 1, 2, 3, 4, 5},
new ObjectManager.StaticObject[]
{
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_6_0.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_6_1.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_6_2.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_6_3.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_6_4.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "signal_6_5.csv"), System.Text.Encoding.UTF8,
ObjectManager.ObjectLoadMode.Normal, false, false, false)
});
Data.CompatibilitySignals[8] = new CompatibilitySignalData(new int[] {0, 3, 4},
new ObjectManager.StaticObject[]
{
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "repeatingsignal_0.csv"),
Encoding, ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "repeatingsignal_3.csv"),
Encoding, ObjectManager.ObjectLoadMode.Normal, false, false, false),
ObjectManager.LoadStaticObject(OpenBveApi.Path.CombineFile(SignalFolder, "repeatingsignal_4.csv"),
Encoding, ObjectManager.ObjectLoadMode.Normal, false, false, false)
});
// game data
Game.Sections = new Game.Section[1];
Game.Sections[0].Aspects = new Game.SectionAspect[]
{new Game.SectionAspect(0, 0.0), new Game.SectionAspect(4, double.PositiveInfinity)};
Game.Sections[0].CurrentAspect = 0;
Game.Sections[0].NextSection = -1;
Game.Sections[0].PreviousSection = -1;
Game.Sections[0].SignalIndices = new int[] {};
Game.Sections[0].StationIndex = -1;
Game.Sections[0].TrackPosition = 0;
Game.Sections[0].Trains = new TrainManager.Train[] {};
/*
* These are the speed limits for the default Japanese signal aspects, and in most cases will be overwritten
*/
Data.SignalSpeeds = new double[]
{0.0, 6.94444444444444, 15.2777777777778, 20.8333333333333, double.PositiveInfinity, double.PositiveInfinity};
}
ParseRouteForData(FileName, IsRW, Encoding, TrainPath, ObjectPath, SoundPath, ref Data, PreviewOnly);
if (Loading.Cancel) return;
ApplyRouteData(FileName, Encoding, ref Data, PreviewOnly);
// if (PreviewOnly == true && customLoadScreen == false)
// {
// Renderer.TextureLogo = null;
// }
}
// ================================
// parse route for data
private class Expression {
internal string File;
internal string Text;
internal int Line;
internal int Column;
internal double TrackPositionOffset;
}
private static void ParseRouteForData(string FileName, bool IsRW, System.Text.Encoding Encoding, string TrainPath, string ObjectPath, string SoundPath, ref RouteData Data, bool PreviewOnly) {
//Read the entire routefile into memory
string[] Lines = System.IO.File.ReadAllLines(FileName, Encoding);
Expression[] Expressions;
PreprocessSplitIntoExpressions(FileName, IsRW, Lines, out Expressions, true, 0.0);
PreprocessChrRndSub(FileName, IsRW, ref Expressions);
double[] UnitOfLength = new double[] { 1.0 };
//Set units of speed initially to km/h
//This represents 1km/h in m/s
Data.UnitOfSpeed = 0.277777777777778;
PreprocessOptions(IsRW, Expressions, ref Data, ref UnitOfLength);
PreprocessSortByTrackPosition(IsRW, UnitOfLength, ref Expressions);
ParseRouteForData(FileName, IsRW, Encoding, Expressions, TrainPath, ObjectPath, SoundPath, UnitOfLength, ref Data, PreviewOnly);
Game.RouteUnitOfLength = UnitOfLength;
}
// preprocess split into expressions
private static void PreprocessSplitIntoExpressions(string FileName, bool IsRW, string[] Lines, out Expression[] Expressions, bool AllowRwRouteDescription, double trackPositionOffset) {
Expressions = new Expression[4096];
int e = 0;
// full-line rw comments
if (IsRW) {
for (int i = 0; i < Lines.Length; i++) {
int Level = 0;
for (int j = 0; j < Lines[i].Length; j++) {
switch (Lines[i][j]) {
case '(':
Level++;
break;
case ')':
Level--;
break;
case ';':
if (Level == 0) {
Lines[i] = Lines[i].Substring(0, j).TrimEnd();
j = Lines[i].Length;
}
break;
case '=':
if (Level == 0) {
j = Lines[i].Length;
}
break;
}
}
}
}
// parse
for (int i = 0; i < Lines.Length; i++) {
if (IsRW & AllowRwRouteDescription) {
// ignore rw route description
if (
Lines[i].StartsWith("[", StringComparison.Ordinal) & Lines[i].IndexOf("]", StringComparison.Ordinal) > 0 |
Lines[i].StartsWith("$")
) {
AllowRwRouteDescription = false;
Game.RouteComment = Game.RouteComment.Trim();
} else {
if (Game.RouteComment.Length != 0) {
Game.RouteComment += "\n";
}
Game.RouteComment += Lines[i];
continue;
}
}
{
// count expressions
int n = 0; int Level = 0;
for (int j = 0; j < Lines[i].Length; j++) {
switch (Lines[i][j]) {
case '(':
Level++;
break;
case ')':
Level--;
break;
case ',':
if (!IsRW & Level == 0) n++;
break;
case '@':
if (IsRW & Level == 0) n++;
break;
}
}
// create expressions
int m = e + n + 1;
while (m >= Expressions.Length) {
Array.Resize<Expression>(ref Expressions, Expressions.Length << 1);
}
Level = 0;
int a = 0, c = 0;
for (int j = 0; j < Lines[i].Length; j++) {
switch (Lines[i][j]) {
case '(':
Level++;
break;
case ')':
Level--;
break;
case ',':
if (Level == 0 & !IsRW) {
string t = Lines[i].Substring(a, j - a).Trim();
if (t.Length > 0 && !t.StartsWith(";")) {
Expressions[e] = new Expression
{
File = FileName,
Text = t,
Line = i + 1,
Column = c + 1,
TrackPositionOffset = trackPositionOffset
};
e++;
}
a = j + 1;
c++;
}
break;
case '@':
if (Level == 0 & IsRW) {
string t = Lines[i].Substring(a, j - a).Trim();
if (t.Length > 0 && !t.StartsWith(";")) {
Expressions[e] = new Expression
{
File = FileName,
Text = t,
Line = i + 1,
Column = c + 1,
TrackPositionOffset = trackPositionOffset
};
e++;
}
a = j + 1;
c++;
}
break;
}
}
if (Lines[i].Length - a > 0) {
string t = Lines[i].Substring(a).Trim();
if (t.Length > 0 && !t.StartsWith(";")) {
Expressions[e] = new Expression
{
File = FileName,
Text = t,
Line = i + 1,
Column = c + 1,
TrackPositionOffset = trackPositionOffset
};
e++;
}
}
}
}
Array.Resize<Expression>(ref Expressions, e);
}
/// <summary>This function processes the list of expressions for $Char, $Rnd, $If and $Sub directives, and evaluates them into the final expressions dataset</summary>
private static void PreprocessChrRndSub(string FileName, bool IsRW, ref Expression[] Expressions) {
System.Globalization.CultureInfo Culture = System.Globalization.CultureInfo.InvariantCulture;
System.Text.Encoding Encoding = new System.Text.ASCIIEncoding();
string[] Subs = new string[16];
int openIfs = 0;
for (int i = 0; i < Expressions.Length; i++) {
string Epilog = " at line " + Expressions[i].Line.ToString(Culture) + ", column " + Expressions[i].Column.ToString(Culture) + " in file " + Expressions[i].File;
bool continueWithNextExpression = false;
for (int j = Expressions[i].Text.Length - 1; j >= 0; j--) {
if (Expressions[i].Text[j] == '$') {
int k;
for (k = j + 1; k < Expressions[i].Text.Length; k++) {
if (Expressions[i].Text[k] == '(') {
break;
} else if (Expressions[i].Text[k] == '/' | Expressions[i].Text[k] == '\\') {
k = Expressions[i].Text.Length + 1;
break;
}
}
if (k <= Expressions[i].Text.Length) {
string t = Expressions[i].Text.Substring(j, k - j).TrimEnd();
int l = 1, h;
for (h = k + 1; h < Expressions[i].Text.Length; h++) {
switch (Expressions[i].Text[h]) {
case '(':
l++;
break;
case ')':
l--;
if (l < 0) {
continueWithNextExpression = true;
Interface.AddMessage(Interface.MessageType.Error, false, "Invalid parenthesis structure in " + t + Epilog);
}
break;
}
if (l <= 0) {
break;
}
}
if (continueWithNextExpression) {
break;
}
if (l != 0) {
Interface.AddMessage(Interface.MessageType.Error, false, "Invalid parenthesis structure in " + t + Epilog);
continueWithNextExpression = true;
break;
}
string s = Expressions[i].Text.Substring(k + 1, h - k - 1).Trim();
switch (t.ToLowerInvariant()) {
case "$if":
if (j != 0) {
Interface.AddMessage(Interface.MessageType.Error, false, "The $If directive must not appear within another statement" + Epilog);
} else {
double num;
if (double.TryParse(s, System.Globalization.NumberStyles.Float, Culture, out num)) {
openIfs++;
Expressions[i].Text = string.Empty;
if (num == 0.0) {
/*
* Blank every expression until the matching $Else or $EndIf
* */
i++;
int level = 1;
while (i < Expressions.Length) {
if (Expressions[i].Text.StartsWith("$if", StringComparison.OrdinalIgnoreCase)) {
Expressions[i].Text = string.Empty;
level++;
} else if (Expressions[i].Text.StartsWith("$else", StringComparison.OrdinalIgnoreCase)) {
Expressions[i].Text = string.Empty;
if (level == 1) {
level--;
break;
}
} else if (Expressions[i].Text.StartsWith("$endif", StringComparison.OrdinalIgnoreCase)) {
Expressions[i].Text = string.Empty;
level--;
if (level == 0) {
openIfs--;
break;
}
} else {
Expressions[i].Text = string.Empty;
}
i++;
}
if (level != 0) {
Interface.AddMessage(Interface.MessageType.Error, false, "$EndIf missing at the end of the file" + Epilog);
}
}
continueWithNextExpression = true;
break;
} else {
Interface.AddMessage(Interface.MessageType.Error, false, "The $If condition does not evaluate to a number" + Epilog);
}
}
continueWithNextExpression = true;
break;
case "$else":
/*
* Blank every expression until the matching $EndIf
* */
Expressions[i].Text = string.Empty;
if (openIfs != 0) {
i++;
int level = 1;
while (i < Expressions.Length) {
if (Expressions[i].Text.StartsWith("$if", StringComparison.OrdinalIgnoreCase)) {
Expressions[i].Text = string.Empty;
level++;
} else if (Expressions[i].Text.StartsWith("$else", StringComparison.OrdinalIgnoreCase)) {
Expressions[i].Text = string.Empty;
if (level == 1) {
Interface.AddMessage(Interface.MessageType.Error, false, "Duplicate $Else encountered" + Epilog);
}
} else if (Expressions[i].Text.StartsWith("$endif", StringComparison.OrdinalIgnoreCase)) {
Expressions[i].Text = string.Empty;
level--;
if (level == 0) {
openIfs--;
break;
}
} else {
Expressions[i].Text = string.Empty;
}
i++;
}
if (level != 0) {
Interface.AddMessage(Interface.MessageType.Error, false, "$EndIf missing at the end of the file" + Epilog);
}
} else {
Interface.AddMessage(Interface.MessageType.Error, false, "$Else without matching $If encountered" + Epilog);
}
continueWithNextExpression = true;
break;
case "$endif":
Expressions[i].Text = string.Empty;
if (openIfs != 0) {
openIfs--;
} else {
Interface.AddMessage(Interface.MessageType.Error, false, "$EndIf without matching $If encountered" + Epilog);
}
continueWithNextExpression = true;
break;
case "$include":
if (j != 0) {
Interface.AddMessage(Interface.MessageType.Error, false, "The $Include directive must not appear within another statement" + Epilog);
continueWithNextExpression = true;
break;
}
string[] args = s.Split(';');
for (int ia = 0; ia < args.Length; ia++) {
args[ia] = args[ia].Trim();
}
int count = (args.Length + 1) / 2;
string[] files = new string[count];
double[] weights = new double[count];
double[] offsets = new double[count];
double weightsTotal = 0.0;
for (int ia = 0; ia < count; ia++) {
string file;
double offset;
int colon = args[2 * ia].IndexOf(':');
if (colon >= 0) {
file = args[2 * ia].Substring(0, colon).TrimEnd();
string value = args[2 * ia].Substring(colon + 1).TrimStart();
if (!double.TryParse(value, NumberStyles.Float, Culture, out offset)) {
continueWithNextExpression = true;
Interface.AddMessage(Interface.MessageType.Error, false, "The track position offset " + value + " is invalid in " + t + Epilog);
break;
}
} else {
file = args[2 * ia];
offset = 0.0;
}
files[ia] = OpenBveApi.Path.CombineFile(System.IO.Path.GetDirectoryName(FileName), file);
offsets[ia] = offset;
if (!System.IO.File.Exists(files[ia])) {
continueWithNextExpression = true;
Interface.AddMessage(Interface.MessageType.Error, false, "The file " + file + " could not be found in " + t + Epilog);
for (int ta = i; ta < Expressions.Length - 1; ta++)
{
Expressions[ta] = Expressions[ta + 1];
}
Array.Resize<Expression>(ref Expressions, Expressions.Length - 1);
i--;
break;
}
if (2 * ia + 1 < args.Length)
{
if (!NumberFormats.TryParseDoubleVb6(args[2 * ia + 1], out weights[ia])) {
continueWithNextExpression = true;
Interface.AddMessage(Interface.MessageType.Error, false, "A weight is invalid in " + t + Epilog);
break;
}
if (weights[ia] <= 0.0) {
continueWithNextExpression = true;
Interface.AddMessage(Interface.MessageType.Error, false, "A weight is not positive in " + t + Epilog);
break;
}
weightsTotal += weights[ia];
}
else {
weights[ia] = 1.0;
weightsTotal += 1.0;
}
}
if (count == 0) {
continueWithNextExpression = true;
Interface.AddMessage(Interface.MessageType.Error, false, "No file was specified in " + t + Epilog);
break;
}
if (!continueWithNextExpression) {
double number = Program.RandomNumberGenerator.NextDouble() * weightsTotal;
double value = 0.0;
int chosenIndex = 0;
for (int ia = 0; ia < count; ia++) {
value += weights[ia];
if (value > number) {
chosenIndex = ia;
break;
}
}
Expression[] expr;
//Get the text encoding of our $Include file
System.Text.Encoding includeEncoding = TextEncoding.GetSystemEncodingFromFile(files[chosenIndex]);
if (!includeEncoding.Equals(Encoding))
{
//If the encodings do not match, add a warning
//This is not critical, but it's a bad idea to mix and match character encodings within a routefile, as the auto-detection may sometimes be wrong
Interface.AddMessage(Interface.MessageType.Warning, false, "The text encoding of the $Include file " + files[chosenIndex] + " does not match that of the base routefile.");
}
string[] lines = System.IO.File.ReadAllLines(files[chosenIndex], includeEncoding);
PreprocessSplitIntoExpressions(files[chosenIndex], IsRW, lines, out expr, false, offsets[chosenIndex] + Expressions[i].TrackPositionOffset);
int length = Expressions.Length;
if (expr.Length == 0) {
for (int ia = i; ia < Expressions.Length - 1; ia++) {
Expressions[ia] = Expressions[ia + 1];
}
Array.Resize<Expression>(ref Expressions, length - 1);
} else {
Array.Resize<Expression>(ref Expressions, length + expr.Length - 1);
for (int ia = Expressions.Length - 1; ia >= i + expr.Length; ia--) {
Expressions[ia] = Expressions[ia - expr.Length + 1];
}
for (int ia = 0; ia < expr.Length; ia++) {
Expressions[i + ia] = expr[ia];
}
}
i--;
continueWithNextExpression = true;
}
break;
case "$chr":
{
int x;
if (NumberFormats.TryParseIntVb6(s, out x)) {
if (x > 0 & x < 128) {
Expressions[i].Text = Expressions[i].Text.Substring(0, j) + new string(Encoding.GetChars(new byte[] { (byte)x })) + Expressions[i].Text.Substring(h + 1);
} else {
continueWithNextExpression = true;
Interface.AddMessage(Interface.MessageType.Error, false, "Index does not correspond to a valid ASCII character in " + t + Epilog);
}
} else {
continueWithNextExpression = true;
Interface.AddMessage(Interface.MessageType.Error, false, "Index is invalid in " + t + Epilog);
}
} break;
case "$rnd":
{
int m = s.IndexOf(";", StringComparison.Ordinal);
if (m >= 0) {
string s1 = s.Substring(0, m).TrimEnd();
string s2 = s.Substring(m + 1).TrimStart();
int x; if (NumberFormats.TryParseIntVb6(s1, out x)) {
int y; if (NumberFormats.TryParseIntVb6(s2, out y)) {
int z = x + (int)Math.Floor(Program.RandomNumberGenerator.NextDouble() * (double)(y - x + 1));
Expressions[i].Text = Expressions[i].Text.Substring(0, j) + z.ToString(Culture) + Expressions[i].Text.Substring(h + 1);
} else {
continueWithNextExpression = true;
Interface.AddMessage(Interface.MessageType.Error, false, "Index2 is invalid in " + t + Epilog);
}
} else {
continueWithNextExpression = true;
Interface.AddMessage(Interface.MessageType.Error, false, "Index1 is invalid in " + t + Epilog);
}
} else {
continueWithNextExpression = true;
Interface.AddMessage(Interface.MessageType.Error, false, "Two arguments are expected in " + t + Epilog);
}
} break;
case "$sub":
{
l = 0;
bool f = false;
int m;
for (m = h + 1; m < Expressions[i].Text.Length; m++) {
switch (Expressions[i].Text[m]) {
case '(': l++; break;
case ')': l--; break;
case '=': if (l == 0) {
f = true;
}
break;
default:
if (!char.IsWhiteSpace(Expressions[i].Text[m])) l = -1;
break;
}
if (f | l < 0) break;
}
if (f) {
l = 0;
int n;
for (n = m + 1; n < Expressions[i].Text.Length; n++) {
switch (Expressions[i].Text[n]) {
case '(': l++; break;
case ')': l--; break;
}
if (l < 0) break;
}
int x;
if (NumberFormats.TryParseIntVb6(s, out x)) {
if (x >= 0) {
while (x >= Subs.Length) {
Array.Resize<string>(ref Subs, Subs.Length << 1);
}
Subs[x] = Expressions[i].Text.Substring(m + 1, n - m - 1).Trim();
Expressions[i].Text = Expressions[i].Text.Substring(0, j) + Expressions[i].Text.Substring(n);
} else {
continueWithNextExpression = true;
Interface.AddMessage(Interface.MessageType.Error, false, "Index is expected to be non-negative in " + t + Epilog);
}
} else {
continueWithNextExpression = true;
Interface.AddMessage(Interface.MessageType.Error, false, "Index is invalid in " + t + Epilog);
}
} else {
int x;
if (NumberFormats.TryParseIntVb6(s, out x)) {
if (x >= 0 & x < Subs.Length && Subs[x] != null) {
Expressions[i].Text = Expressions[i].Text.Substring(0, j) + Subs[x] + Expressions[i].Text.Substring(h + 1);
} else {
continueWithNextExpression = true;
Interface.AddMessage(Interface.MessageType.Error, false, "Index is out of range in " + t + Epilog);
}
} else {
continueWithNextExpression = true;
Interface.AddMessage(Interface.MessageType.Error, false, "Index is invalid in " + t + Epilog);
}
}
}
break;
}
}
}
if (continueWithNextExpression) {
break;
}
}
}
// handle comments introduced via chr, rnd, sub
{
int length = Expressions.Length;
for (int i = 0; i < length; i++) {
Expressions[i].Text = Expressions[i].Text.Trim();
if (Expressions[i].Text.Length != 0) {
if (Expressions[i].Text[0] == ';') {
for (int j = i; j < length - 1; j++) {
Expressions[j] = Expressions[j + 1];
}
length--;
i--;
}
} else {
for (int j = i; j < length - 1; j++) {
Expressions[j] = Expressions[j + 1];
}
length--;
i--;
}
}
if (length != Expressions.Length) {
Array.Resize<Expression>(ref Expressions, length);
}
}
}
// preprocess options
private static void PreprocessOptions(bool IsRW, Expression[] Expressions, ref RouteData Data, ref double[] UnitOfLength) {
System.Globalization.CultureInfo Culture = System.Globalization.CultureInfo.InvariantCulture;
string Section = "";
bool SectionAlwaysPrefix = false;
// process expressions
for (int j = 0; j < Expressions.Length; j++) {
if (IsRW && Expressions[j].Text.StartsWith("[") && Expressions[j].Text.EndsWith("]")) {
Section = Expressions[j].Text.Substring(1, Expressions[j].Text.Length - 2).Trim();
if (string.Compare(Section, "object", StringComparison.OrdinalIgnoreCase) == 0) {
Section = "Structure";
} else if (string.Compare(Section, "railway", StringComparison.OrdinalIgnoreCase) == 0) {
Section = "Track";
}
SectionAlwaysPrefix = true;
} else {
// find equals
int Equals = Expressions[j].Text.IndexOf('=');
if (Equals >= 0) {
// handle RW cycle syntax
string t = Expressions[j].Text.Substring(0, Equals);
if (Section.ToLowerInvariant() == "cycle" & SectionAlwaysPrefix) {
double b; if (NumberFormats.TryParseDoubleVb6(t, out b)) {
t = ".Ground(" + t + ")";
}
} else if (Section.ToLowerInvariant() == "signal" & SectionAlwaysPrefix) {
double b; if (NumberFormats.TryParseDoubleVb6(t, out b)) {
t = ".Void(" + t + ")";
}
}
// convert RW style into CSV style
Expressions[j].Text = t + " " + Expressions[j].Text.Substring(Equals + 1);
}
// separate command and arguments
string Command, ArgumentSequence;
SeparateCommandsAndArguments(Expressions[j], out Command, out ArgumentSequence, Culture, true);
// process command
double Number;
bool NumberCheck = !IsRW || string.Compare(Section, "track", StringComparison.OrdinalIgnoreCase) == 0;
if (!NumberCheck || !NumberFormats.TryParseDoubleVb6(Command, UnitOfLength, out Number)) {
// split arguments
string[] Arguments;
{
int n = 0;
for (int k = 0; k < ArgumentSequence.Length; k++) {
if (IsRW & ArgumentSequence[k] == ',') {
n++;
} else if (ArgumentSequence[k] == ';') {
n++;
}
}
Arguments = new string[n + 1];
int a = 0, h = 0;
for (int k = 0; k < ArgumentSequence.Length; k++) {
if (IsRW & ArgumentSequence[k] == ',') {
Arguments[h] = ArgumentSequence.Substring(a, k - a).Trim();
a = k + 1; h++;
} else if (ArgumentSequence[k] == ';') {
Arguments[h] = ArgumentSequence.Substring(a, k - a).Trim();
a = k + 1; h++;
}
}
if (ArgumentSequence.Length - a > 0) {
Arguments[h] = ArgumentSequence.Substring(a).Trim();
h++;
}
Array.Resize<string>(ref Arguments, h);
}
// preprocess command
if (Command.ToLowerInvariant() == "with") {
if (Arguments.Length >= 1) {
Section = Arguments[0];
SectionAlwaysPrefix = false;
} else {
Section = "";
SectionAlwaysPrefix = false;
}
Command = null;
} else {
if (Command.StartsWith(".")) {
Command = Section + Command;
} else if (SectionAlwaysPrefix) {
Command = Section + "." + Command;
}
Command = Command.Replace(".Void", "");
}
// handle indices
if (Command != null && Command.EndsWith(")")) {
for (int k = Command.Length - 2; k >= 0; k--) {
if (Command[k] == '(') {
string Indices = Command.Substring(k + 1, Command.Length - k - 2).TrimStart();
Command = Command.Substring(0, k).TrimEnd();
int h = Indices.IndexOf(";", StringComparison.Ordinal);
int CommandIndex1;
if (h >= 0) {