/
MSTSDieselLocomotive.cs
1462 lines (1262 loc) · 74.2 KB
/
MSTSDieselLocomotive.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
// COPYRIGHT 2009, 2010, 2011, 2012, 2013 by the Open Rails project.
//
// This file is part of Open Rails.
//
// Open Rails is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Open Rails is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
/* DIESEL LOCOMOTIVE CLASSES
*
* The Locomotive is represented by two classes:
* MSTSDieselLocomotiveSimulator - defines the behaviour, ie physics, motion, power generated etc
* MSTSDieselLocomotiveViewer - defines the appearance in a 3D viewer. The viewer doesn't
* get attached to the car until it comes into viewing range.
*
* Both these classes derive from corresponding classes for a basic locomotive
* LocomotiveSimulator - provides for movement, basic controls etc
* LocomotiveViewer - provides basic animation for running gear, wipers, etc
*
*/
//#define ALLOW_ORTS_SPECIFIC_ENG_PARAMETERS
using Microsoft.Xna.Framework;
using Orts.Formats.Msts;
using Orts.Parsers.Msts;
using Orts.Simulation.Physics;
using Orts.Simulation.RollingStocks.SubSystems.Controllers;
using Orts.Simulation.RollingStocks.SubSystems.PowerSupplies;
using Orts.Simulation.RollingStocks.SubSystems.PowerTransmissions;
using ORTS.Common;
using System.Diagnostics;
using System;
using System.IO;
using System.Text;
using Event = Orts.Common.Event;
using ORTS.Scripting.Api;
using System.Linq;
using Orts.Simulation.RollingStocks.SubSystems.Brakes;
namespace Orts.Simulation.RollingStocks
{
///////////////////////////////////////////////////
/// SIMULATION BEHAVIOUR
///////////////////////////////////////////////////
/// <summary>
/// Adds physics and control for a diesel locomotive
/// </summary>
public class MSTSDieselLocomotive : MSTSLocomotive
{
public ScriptedDieselPowerSupply DieselPowerSupply => PowerSupply as ScriptedDieselPowerSupply;
public float IdleRPM;
public float MaxRPM;
public float GovernorRPM;
public float MaxRPMChangeRate;
public float PercentChangePerSec = .2f;
public float InitialExhaust;
public float InitialMagnitude;
public float MaxExhaust = 2.8f;
public float MaxMagnitude = 1.5f;
public float EngineRPMderivation;
float EngineRPMold;
float EngineRPMRatio; // used to compute Variable1 and Variable2
public float MaximumDieselEnginePowerW;
public MSTSNotchController FuelController = new MSTSNotchController(0, 1, 0.0025f);
public float MaxDieselLevelL = 5000.0f;
public float DieselLevelL
{
get { return FuelController.CurrentValue * MaxDieselLevelL; }
set { FuelController.CurrentValue = value / MaxDieselLevelL; }
}
public float DieselUsedPerHourAtMaxPowerL = 1.0f;
public float DieselUsedPerHourAtIdleL = 1.0f;
public float DieselFlowLps;
public float DieselWeightKgpL = 0.8508f; //per liter
float InitialMassKg = 100000.0f;
public float LocomotiveMaxRailOutputPowerW;
public int currentGearIndexRestore = -1;
public int currentnextGearRestore = -1;
public bool gearSaved;
public int dieselEngineRestoreState;
public float EngineRPM;
public SmoothedData ExhaustParticles = new SmoothedData(1);
public SmoothedData ExhaustMagnitude = new SmoothedData(1);
public SmoothedData ExhaustColorR = new SmoothedData(1);
public SmoothedData ExhaustColorG = new SmoothedData(1);
public SmoothedData ExhaustColorB = new SmoothedData(1);
public float DieselOilPressurePSI = 0f;
public float DieselMinOilPressurePSI;
public float DieselMaxOilPressurePSI;
public float DieselTemperatureDeg = 40f;
public float DieselMaxTemperatureDeg;
public DieselEngine.Cooling DieselEngineCooling = DieselEngine.Cooling.Proportional;
public enum DieselTransmissionTypes
{
Legacy,
Electric,
Hydraulic,
Mechanic,
Hydromechanic,
}
public DieselTransmissionTypes DieselTransmissionType;
float CalculatedMaxContinuousForceN;
// diesel performance reporting
public float DieselPerformanceTimeS = 0.0f; // Records the time since starting movement
public DieselEngines DieselEngines;
/// <summary>
/// Used to accumulate a quantity that is not lost because of lack of precision when added to the Fuel level
/// </summary>
float partialFuelConsumption = 0;
private const float GearBoxControllerBoost = 1; // Slow boost to enable easy single gear up/down commands
public MSTSDieselLocomotive(Simulator simulator, string wagFile)
: base(simulator, wagFile)
{
DieselEngines = new DieselEngines(this);
PowerSupply = new ScriptedDieselPowerSupply(this);
RefillImmediately();
}
/// <summary>
/// Parse the wag file parameters required for the simulator and viewer classes
/// </summary>
public override void Parse(string lowercasetoken, STFReader stf)
{
switch (lowercasetoken)
{
case "engine(ortspowerondelay":
case "engine(ortsauxpowerondelay":
case "engine(ortspowersupply":
case "engine(ortstractioncutoffrelay":
case "engine(ortstractioncutoffrelayclosingdelay":
case "engine(ortsbattery(mode":
case "engine(ortsbattery(delay":
case "engine(ortsbattery(defaulton":
case "engine(ortsmasterkey(mode":
case "engine(ortsmasterkey(delayoff":
case "engine(ortsmasterkey(headlightcontrol":
case "engine(ortselectrictrainsupply(mode":
case "engine(ortselectrictrainsupply(dieselengineminrpm":
LocomotivePowerSupply.Parse(lowercasetoken, stf);
break;
case "engine(dieselengineidlerpm": IdleRPM = stf.ReadFloatBlock(STFReader.UNITS.None, null); break;
case "engine(dieselenginemaxrpm": MaxRPM = stf.ReadFloatBlock(STFReader.UNITS.None, null); break;
case "engine(ortsdieselenginegovernorrpm": GovernorRPM = stf.ReadFloatBlock(STFReader.UNITS.None, 0); break;
case "engine(dieselenginemaxrpmchangerate": MaxRPMChangeRate = stf.ReadFloatBlock(STFReader.UNITS.None, null); break;
case "engine(ortsdieselenginemaxpower": MaximumDieselEnginePowerW = stf.ReadFloatBlock(STFReader.UNITS.Power, null); break;
case "engine(effects(dieselspecialeffects": ParseEffects(lowercasetoken, stf); break;
case "engine(dieselsmokeeffectinitialsmokerate": InitialExhaust = stf.ReadFloatBlock(STFReader.UNITS.None, null); break;
case "engine(dieselsmokeeffectinitialmagnitude": InitialMagnitude = stf.ReadFloatBlock(STFReader.UNITS.None, null); break;
case "engine(dieselsmokeeffectmaxsmokerate": MaxExhaust = stf.ReadFloatBlock(STFReader.UNITS.None, null); break;
case "engine(dieselsmokeeffectmaxmagnitude": MaxMagnitude = stf.ReadFloatBlock(STFReader.UNITS.None, null); break;
case "engine(ortsdieseltransmissiontype":
stf.MustMatch("(");
var transmissionType = stf.ReadString();
try
{
DieselTransmissionType = (DieselTransmissionTypes)Enum.Parse(typeof(DieselTransmissionTypes), transmissionType.First().ToString().ToUpper() + transmissionType.Substring(1));
}
catch
{
STFException.TraceWarning(stf, "Skipped unknown diesel transmission type " + transmissionType);
}
break;
case "engine(ortsdieselengines":
case "engine(gearboxnumberofgears":
case "engine(ortsreversegearboxindication":
case "engine(gearboxdirectdrivegear":
case "engine(ortsmainclutchtype":
case "engine(ortsgearboxtype":
case "engine(gearboxoperation":
case "engine(gearboxenginebraking":
case "engine(gearboxmaxspeedforgears":
case "engine(gearboxmaxtractiveforceforgears":
case "engine(ortsgearboxtractiveforceatspeed":
case "engine(gearboxoverspeedpercentageforfailure":
case "engine(gearboxbackloadforce":
case "engine(gearboxcoastingforce":
case "engine(gearboxupgearproportion":
case "engine(gearboxdowngearproportion":
case "engine(ortsgearboxfreewheel":
DieselEngines.Parse(lowercasetoken, stf);
break;
case "engine(maxdiesellevel": MaxDieselLevelL = stf.ReadFloatBlock(STFReader.UNITS.Volume, null); break;
case "engine(dieselusedperhouratmaxpower": DieselUsedPerHourAtMaxPowerL = stf.ReadFloatBlock(STFReader.UNITS.Volume, null); break;
case "engine(dieselusedperhouratidle": DieselUsedPerHourAtIdleL = stf.ReadFloatBlock(STFReader.UNITS.Volume, null); break;
case "engine(maxoilpressure": DieselMaxOilPressurePSI = stf.ReadFloatBlock(STFReader.UNITS.PressureDefaultPSI, 120f); break;
case "engine(ortsminoilpressure": DieselMinOilPressurePSI = stf.ReadFloatBlock(STFReader.UNITS.PressureDefaultPSI, 40f); break;
case "engine(maxtemperature": DieselMaxTemperatureDeg = stf.ReadFloatBlock(STFReader.UNITS.Temperature, 0); break;
case "engine(ortsdieselcooling": DieselEngineCooling = (DieselEngine.Cooling)stf.ReadInt((int)DieselEngine.Cooling.Proportional); break;
default:
base.Parse(lowercasetoken, stf); break;
}
if (IdleRPM != 0 && MaxRPM != 0 && MaxRPMChangeRate != 0)
{
PercentChangePerSec = MaxRPMChangeRate / (MaxRPM - IdleRPM);
EngineRPM = IdleRPM;
}
}
public override void LoadFromWagFile(string wagFilePath)
{
base.LoadFromWagFile(wagFilePath);
if (Simulator.Settings.VerboseConfigurationMessages) // Display locomotivve name for verbose error messaging
{
Trace.TraceInformation("\n\n ================================================= {0} =================================================", LocomotiveName);
}
NormalizeParams();
// Check to see if Speed of Max Tractive Force has been set - use ORTS value as first priority, if not use MSTS, last resort use an arbitary value.
if (SpeedOfMaxContinuousForceMpS == 0)
{
if (MSTSSpeedOfMaxContinuousForceMpS != 0)
{
SpeedOfMaxContinuousForceMpS = MSTSSpeedOfMaxContinuousForceMpS; // Use MSTS value if present
if (Simulator.Settings.VerboseConfigurationMessages)
Trace.TraceInformation("Speed Of Max Continuous Force: set to default value {0}", FormatStrings.FormatSpeedDisplay(SpeedOfMaxContinuousForceMpS, IsMetric));
}
else if (MaxPowerW != 0 && MaxContinuousForceN != 0)
{
SpeedOfMaxContinuousForceMpS = MaxPowerW / MaxContinuousForceN;
if (Simulator.Settings.VerboseConfigurationMessages)
Trace.TraceInformation("Speed Of Max Continuous Force: set to 'calculated' value {0}", FormatStrings.FormatSpeedDisplay(SpeedOfMaxContinuousForceMpS, IsMetric));
}
else
{
SpeedOfMaxContinuousForceMpS = 10.0f; // If not defined then set at an "arbitary" value of 22mph
if (Simulator.Settings.VerboseConfigurationMessages)
Trace.TraceInformation("Speed Of Max Continuous Force: set to 'arbitary' value {0}", FormatStrings.FormatSpeedDisplay(SpeedOfMaxContinuousForceMpS, IsMetric));
}
}
// Create a diesel engine block if none exits, typically for a MSTS or BASIC configuration
if (DieselEngines.Count == 0)
{
DieselEngines.Add(new DieselEngine(this));
DieselEngines[0].InitFromMSTS();
DieselEngines[0].Initialize();
}
// Check initialization of power values for diesel engines
for (int i = 0; i < DieselEngines.Count; i++)
{
DieselEngines[i].InitDieselRailPowers(this);
}
InitialMassKg = MassKG;
// If traction force curves not set (BASIC configuration) then check that power values are set, otherwise locomotive will not move.
if (TractiveForceCurves == null && LocomotiveMaxRailOutputPowerW == 0)
{
if (MaxPowerW != 0)
{
LocomotiveMaxRailOutputPowerW = MaxPowerW; // Set to default power value
if (Simulator.Settings.VerboseConfigurationMessages)
{
Trace.TraceInformation("MaxRailOutputPower (BASIC Config): set to default value = {0}", FormatStrings.FormatPower(LocomotiveMaxRailOutputPowerW, IsMetric, false, false));
}
}
else
{
LocomotiveMaxRailOutputPowerW = 2500000.0f; // If no default value then set to arbitary value
if (Simulator.Settings.VerboseConfigurationMessages)
{
Trace.TraceInformation("MaxRailOutputPower (BASIC Config): set at arbitary value = {0}", FormatStrings.FormatPower(LocomotiveMaxRailOutputPowerW, IsMetric, false, false));
}
}
if (MaximumDieselEnginePowerW == 0)
{
MaximumDieselEnginePowerW = LocomotiveMaxRailOutputPowerW; // If no value set in ENG file, then set the Prime Mover power to same as RailOutputPower (typically the MaxPower value)
if (Simulator.Settings.VerboseConfigurationMessages)
Trace.TraceInformation("Maximum Diesel Engine Prime Mover Power set the same as MaxRailOutputPower {0} value", FormatStrings.FormatPower(MaximumDieselEnginePowerW, IsMetric, false, false));
}
}
// Check that maximum force value has been set
if (MaxForceN == 0)
{
if (TractiveForceCurves == null) // Basic configuration - ie no force and Power tables, etc
{
float StartingSpeedMpS = 0.1f; // Assumed starting speed for diesel - can't be zero otherwise error will occurr
MaxForceN = LocomotiveMaxRailOutputPowerW / StartingSpeedMpS;
if (Simulator.Settings.VerboseConfigurationMessages)
Trace.TraceInformation("Maximum Force set to {0} value, calculated from Rail Power Value.", FormatStrings.FormatForce(MaxForceN, IsMetric));
}
else
{
float ThrottleSetting = 1.0f; // Must be at full throttle for these calculations
float StartingSpeedMpS = 0.1f; // Assumed starting speed for diesel - can't be zero otherwise error will occurr
float MaxForceN = TractiveForceCurves.Get(ThrottleSetting, StartingSpeedMpS);
if (Simulator.Settings.VerboseConfigurationMessages)
Trace.TraceInformation("Maximum Force set to {0} value, calcuated from Tractive Force Tables", FormatStrings.FormatForce(MaxForceN, IsMetric));
}
}
// Check force assumptions set for diesel
if (Simulator.Settings.VerboseConfigurationMessages)
{
CalculatedMaxContinuousForceN = 0;
float ThrottleSetting = 1.0f; // Must be at full throttle for these calculations
if (TractiveForceCurves == null) // Basic configuration - ie no force and Power tables, etc
{
CalculatedMaxContinuousForceN = ThrottleSetting * LocomotiveMaxRailOutputPowerW / SpeedOfMaxContinuousForceMpS;
Trace.TraceInformation("Diesel Force Settings (BASIC Config): Max Starting Force {0}, Calculated Max Continuous Force {1} @ speed of {2}", FormatStrings.FormatForce(MaxForceN, IsMetric), FormatStrings.FormatForce(CalculatedMaxContinuousForceN, IsMetric), FormatStrings.FormatSpeedDisplay(SpeedOfMaxContinuousForceMpS, IsMetric));
Trace.TraceInformation("Diesel Power Settings (BASIC Config): Prime Mover {0}, Max Rail Output Power {1}", FormatStrings.FormatPower(MaximumDieselEnginePowerW, IsMetric, false, false), FormatStrings.FormatPower(LocomotiveMaxRailOutputPowerW, IsMetric, false, false));
if (MaxForceN < MaxContinuousForceN)
{
Trace.TraceInformation("!!!! Warning: Starting Tractive force {0} is less then Calculated Continuous force {1}, please check !!!!", FormatStrings.FormatForce(MaxForceN, IsMetric), FormatStrings.FormatForce(CalculatedMaxContinuousForceN, IsMetric), FormatStrings.FormatSpeedDisplay(SpeedOfMaxContinuousForceMpS, IsMetric));
}
}
else // Advanced configuration -
{
float StartingSpeedMpS = 0.1f; // Assumed starting speed for diesel - can't be zero otherwise error will occurr
float StartingForceN = TractiveForceCurves.Get(ThrottleSetting, StartingSpeedMpS);
CalculatedMaxContinuousForceN = TractiveForceCurves.Get(ThrottleSetting, SpeedOfMaxContinuousForceMpS);
Trace.TraceInformation("Diesel Force Settings (ADVANCED Config): Max Starting Force {0}, Calculated Max Continuous Force {1}, @ speed of {2}", FormatStrings.FormatForce(StartingForceN, IsMetric), FormatStrings.FormatForce(CalculatedMaxContinuousForceN, IsMetric), FormatStrings.FormatSpeedDisplay(SpeedOfMaxContinuousForceMpS, IsMetric));
Trace.TraceInformation("Diesel Power Settings (ADVANCED Config): Prime Mover {0}, Max Rail Output Power {1} @ {2} rpm", FormatStrings.FormatPower(DieselEngines.MaxPowerW, IsMetric, false, false), FormatStrings.FormatPower(DieselEngines.MaximumRailOutputPowerW, IsMetric, false, false), MaxRPM);
if (StartingForceN < MaxContinuousForceN)
{
Trace.TraceInformation("!!!! Warning: Calculated Starting Tractive force {0} is less then Calculated Continuous force {1}, please check !!!!", FormatStrings.FormatForce(StartingForceN, IsMetric), FormatStrings.FormatForce(CalculatedMaxContinuousForceN, IsMetric), FormatStrings.FormatSpeedDisplay(SpeedOfMaxContinuousForceMpS, IsMetric));
}
}
// Check that MaxPower value is realistic - Calculate power - metric - P = F x V
float CalculatedContinuousPowerW = MaxContinuousForceN * SpeedOfMaxContinuousForceMpS;
if (MaxPowerW < CalculatedContinuousPowerW)
{
Trace.TraceInformation("!!!! Warning: MaxPower {0} is less then continuous force calculated power {1} @ speed of {2}, please check !!!!", FormatStrings.FormatPower(MaxPowerW, IsMetric, false, false), FormatStrings.FormatPower(CalculatedContinuousPowerW, IsMetric, false, false), FormatStrings.FormatSpeedDisplay(SpeedOfMaxContinuousForceMpS, IsMetric));
}
if (!DieselEngines.HasGearBox)
{
// Check Adhesion values
var calculatedmaximumpowerw = CalculatedMaxContinuousForceN * SpeedOfMaxContinuousForceMpS;
var maxforcekN = MaxForceN / 1000.0f;
var designadhesionzerospeed = maxforcekN / (Kg.ToTonne(DrvWheelWeightKg) * 10);
var calculatedmaxcontinuousforcekN = CalculatedMaxContinuousForceN / 1000.0f;
var designadhesionmaxcontspeed = calculatedmaxcontinuousforcekN / (Kg.ToTonne(DrvWheelWeightKg) * 10);
var zerospeed = 0;
var configuredadhesionzerospeed = (Curtius_KnifflerA / (zerospeed + Curtius_KnifflerB) + Curtius_KnifflerC);
var configuredadhesionmaxcontinuousspeed = (Curtius_KnifflerA / (SpeedOfMaxContinuousForceMpS + Curtius_KnifflerB) + Curtius_KnifflerC);
var dropoffspeed = calculatedmaximumpowerw / (MaxForceN);
var configuredadhesiondropoffspeed = (Curtius_KnifflerA / (dropoffspeed + Curtius_KnifflerB) + Curtius_KnifflerC);
Trace.TraceInformation("Slip control system: {0}, Traction motor type: {1}", SlipControlSystem.ToString(), TractionMotorType.ToString()); // Slip control
Trace.TraceInformation("Apparent (Design) Adhesion: Zero - {0:N2} @ {1}, Max Continuous Speed - {2:N2} @ {3}, Drive Wheel Weight - {4}", designadhesionzerospeed, FormatStrings.FormatSpeedDisplay(zerospeed, IsMetric), designadhesionmaxcontspeed, FormatStrings.FormatSpeedDisplay(SpeedOfMaxContinuousForceMpS, IsMetric), FormatStrings.FormatMass(DrvWheelWeightKg, IsMetric));
Trace.TraceInformation("OR Calculated Adhesion Setting: Zero Speed - {0:N2} @ {1}, Dropoff Speed - {2:N2} @ {3}, Max Continuous Speed - {4:N2} @ {5}", configuredadhesionzerospeed, FormatStrings.FormatSpeedDisplay(zerospeed, IsMetric), configuredadhesiondropoffspeed, FormatStrings.FormatSpeedDisplay(dropoffspeed, IsMetric), configuredadhesionmaxcontinuousspeed, FormatStrings.FormatSpeedDisplay(SpeedOfMaxContinuousForceMpS, IsMetric));
}
Trace.TraceInformation("===================================================================================================================\n\n");
}
}
/// <summary>
/// This initializer is called when we are making a new copy of a locomotive already
/// loaded in memory. We use this one to speed up loading by eliminating the
/// need to parse the wag file multiple times.
/// NOTE: you must initialize all the same variables as you parsed above
/// </summary>
public override void Copy(MSTSWagon copy)
{
base.Copy(copy); // each derived level initializes its own variables
MSTSDieselLocomotive locoCopy = (MSTSDieselLocomotive)copy;
EngineRPM = locoCopy.EngineRPM;
IdleRPM = locoCopy.IdleRPM;
MaxRPM = locoCopy.MaxRPM;
GovernorRPM = locoCopy.GovernorRPM;
MaxRPMChangeRate = locoCopy.MaxRPMChangeRate;
MaximumDieselEnginePowerW = locoCopy.MaximumDieselEnginePowerW;
PercentChangePerSec = locoCopy.PercentChangePerSec;
LocomotiveMaxRailOutputPowerW = locoCopy.LocomotiveMaxRailOutputPowerW;
DieselTransmissionType = locoCopy.DieselTransmissionType;
EngineRPMderivation = locoCopy.EngineRPMderivation;
EngineRPMold = locoCopy.EngineRPMold;
MaxDieselLevelL = locoCopy.MaxDieselLevelL;
DieselUsedPerHourAtMaxPowerL = locoCopy.DieselUsedPerHourAtMaxPowerL;
DieselUsedPerHourAtIdleL = locoCopy.DieselUsedPerHourAtIdleL;
DieselFlowLps = 0.0f;
InitialMassKg = MassKG;
if (this.CarID.StartsWith("0"))
DieselLevelL = locoCopy.DieselLevelL;
else
DieselLevelL = locoCopy.MaxDieselLevelL;
if (locoCopy.GearBoxController != null)
GearBoxController = new MSTSNotchController(locoCopy.GearBoxController);
DieselEngines.Copy(locoCopy.DieselEngines);
}
public override void Initialize()
{
DieselEngines.Initialize();
if (DieselEngines[0].GearBox != null)
{
GearBoxController = new MSTSNotchController(DieselEngines[0].GearBox.NumOfGears + 1);
}
base.Initialize();
// Initialise water level in steam heat boiler
if (CurrentLocomotiveSteamHeatBoilerWaterCapacityL == 0 && IsSteamHeatFitted)
{
if (MaximumSteamHeatBoilerWaterTankCapacityL != 0)
{
CurrentLocomotiveSteamHeatBoilerWaterCapacityL = MaximumSteamHeatBoilerWaterTankCapacityL;
}
else
{
CurrentLocomotiveSteamHeatBoilerWaterCapacityL = L.FromGUK(800.0f);
}
}
// TO BE LOOKED AT - fix restoration process for gearbox and gear controller
// It appears that the gearbox is initialised in two different places to cater for Basic and Advanced ENG file configurations(?).
// Hence the restore values recovered in gearbox class are being overwritten , and resume was not working correctly
// Hence restore gear position values are read as part of the diesel and restored at this point.
if (gearSaved)
{
DieselEngines[0].GearBox.nextGearIndex = currentnextGearRestore;
DieselEngines[0].GearBox.currentGearIndex = currentGearIndexRestore;
GearBoxController.SetValue((float)DieselEngines[0].GearBox.currentGearIndex);
}
if (Simulator.Settings.VerboseConfigurationMessages)
{
if (DieselEngines.HasGearBox)
{
Trace.TraceInformation("==================================================== {0} has Gearbox =========================================================", LocomotiveName);
Trace.TraceInformation("Gearbox Type: {0}, Transmission Type: {1}, Number of Gears: {2}, Idle RpM: {3}, Max RpM: {4}, Gov RpM: {5}, GearBoxType: {6}, ClutchType: {7}, FreeWheel: {8}", DieselEngines[0].GearBox.GearBoxOperation, DieselTransmissionType, DieselEngines[0].GearBox.NumOfGears, DieselEngines[0].IdleRPM, DieselEngines[0].MaxRPM, DieselEngines[0].GovernorRPM, DieselEngines[0].GearBox.GearBoxType, DieselEngines[0].GearBox.ClutchType, DieselEngines[0].GearBox.GearBoxFreeWheelFitted);
Trace.TraceInformation("Gear\t Ratio\t Max Speed\t Max TE\t Chg Up RpM\t Chg Dwn RpM\t Coast Force\t Back Force\t");
for (int i = 0; i < DieselEngines[0].GearBox.NumOfGears; i++)
{
Trace.TraceInformation("\t{0}\t\t\t {1:N2}\t\t{2:N2}\t\t{3:N2}\t\t\t{4}\t\t\t\t{5:N0}\t\t\t\t\t{6}\t\t\t{7}", i + 1, DieselEngines[0].GearBox.Gears[i].Ratio, FormatStrings.FormatSpeedDisplay(DieselEngines[0].GearBox.Gears[i].MaxSpeedMpS, IsMetric), FormatStrings.FormatForce(DieselEngines[0].GearBox.Gears[i].MaxTractiveForceN, IsMetric), DieselEngines[0].GearBox.Gears[i].ChangeUpSpeedRpM, DieselEngines[0].GearBox.Gears[i].ChangeDownSpeedRpM, FormatStrings.FormatForce(DieselEngines[0].GearBox.Gears[i].CoastingForceN, IsMetric), FormatStrings.FormatForce(DieselEngines[0].GearBox.Gears[i].BackLoadForceN, IsMetric));
}
var calculatedmaxcontinuousforcekN = DieselEngines[0].GearBox.Gears[0].MaxTractiveForceN / 1000.0f;
var designadhesionmaxcontspeed = calculatedmaxcontinuousforcekN / (Kg.ToTonne(DrvWheelWeightKg) * 10);
Trace.TraceInformation("Apparent (Design) Adhesion for Gear 1: {0:N2} @ {1}, Drive Wheel Weight - {2}", designadhesionmaxcontspeed, FormatStrings.FormatSpeedDisplay(DieselEngines[0].GearBox.Gears[0].MaxSpeedMpS, IsMetric), FormatStrings.FormatMass(DrvWheelWeightKg, IsMetric));
Trace.TraceInformation("===================================================================================================================\n\n");
}
}
}
/// <summary>
/// We are saving the game. Save anything that we'll need to restore the
/// status later.
/// </summary>
public override void Save(BinaryWriter outf)
{
// for example
// outf.Write(Pan);
base.Save(outf);
outf.Write(DieselLevelL);
outf.Write(CurrentLocomotiveSteamHeatBoilerWaterCapacityL);
DieselEngines.Save(outf);
ControllerFactory.Save(GearBoxController, outf);
}
/// <summary>
/// We are restoring a saved game. The TrainCar class has already
/// been initialized. Restore the game state.
/// </summary>
public override void Restore(BinaryReader inf)
{
base.Restore(inf);
DieselLevelL = inf.ReadSingle();
CurrentLocomotiveSteamHeatBoilerWaterCapacityL = inf.ReadSingle();
DieselEngines.Restore(inf);
ControllerFactory.Restore(GearBoxController, inf);
}
//================================================================================================//
/// <summary>
/// Set starting conditions when initial speed > 0
///
public override void InitializeMoving()
{
base.InitializeMoving();
WheelSpeedMpS = SpeedMpS;
DynamicBrakePercent = -1;
DieselEngines.InitializeMoving();
if (DieselEngines[0].GearBox != null && GearBoxController != null)
{
if (IsLeadLocomotive())
{
Train.MUGearboxGearIndex = DieselEngines[0].GearBox.CurrentGearIndex + 1;
Train.AITrainGearboxGearIndex = DieselEngines[0].GearBox.CurrentGearIndex + 1;
}
GearBoxController.CurrentNotch = Train.MUGearboxGearIndex;
GearboxGearIndex = DieselEngines[0].GearBox.CurrentGearIndex + 1;
GearBoxController.SetValue((float)GearBoxController.CurrentNotch);
}
ThrottleController.SetValue(Train.MUThrottlePercent / 100);
}
/// <summary>
/// This function updates periodically the states and physical variables of the locomotive's subsystems.
/// </summary>
public override void Update(float elapsedClockSeconds)
{
DieselEngines.Update(elapsedClockSeconds);
ExhaustParticles.Update(elapsedClockSeconds, DieselEngines[0].ExhaustParticles);
ExhaustMagnitude.Update(elapsedClockSeconds, DieselEngines[0].ExhaustMagnitude);
ExhaustColorR.Update(elapsedClockSeconds, DieselEngines[0].ExhaustColor.R);
ExhaustColorG.Update(elapsedClockSeconds, DieselEngines[0].ExhaustColor.G);
ExhaustColorB.Update(elapsedClockSeconds, DieselEngines[0].ExhaustColor.B);
base.Update(elapsedClockSeconds);
// The following is not in the UpdateControllers function due to the fact that fuel level has to be calculated after the motive force calculation.
FuelController.Update(elapsedClockSeconds);
if (FuelController.UpdateValue > 0.0)
Simulator.Confirmer.UpdateWithPerCent(CabControl.DieselFuel, CabSetting.Increase, FuelController.CurrentValue * 100);
// Update water controller for steam boiler heating tank
if (this.IsLeadLocomotive() && IsSteamHeatFitted)
{
WaterController.Update(elapsedClockSeconds);
if (WaterController.UpdateValue > 0.0)
Simulator.Confirmer.UpdateWithPerCent(CabControl.SteamHeatBoilerWater, CabSetting.Increase, WaterController.CurrentValue * 100);
}
}
/// <summary>
/// This function updates periodically the states and physical variables of the locomotive's controllers.
/// </summary>
protected override void UpdateControllers(float elapsedClockSeconds)
{
base.UpdateControllers(elapsedClockSeconds);
//Currently the ThrottlePercent is global to the entire train
//So only the lead locomotive updates it, the others only updates the controller (actually useless)
if (this.IsLeadLocomotive() || (RemoteControlGroup == -1))
{
if (GearBoxController != null)
{
GearboxGearIndex = (int)GearBoxController.UpdateAndSetBoost(elapsedClockSeconds, GearBoxControllerBoost);
}
}
else
{
if (GearBoxController != null)
{
GearBoxController.UpdateAndSetBoost(elapsedClockSeconds, GearBoxControllerBoost);
}
}
}
/// <summary>
/// This function updates periodically the locomotive's motive force.
/// </summary>
protected override void UpdateTractiveForce(float elapsedClockSeconds, float t, float AbsSpeedMpS, float AbsWheelSpeedMpS)
{
// This section calculates the motive force of the locomotive as follows:
// Basic configuration (no TF table) - uses P = F /speed relationship - requires power and force parameters to be set in the ENG file.
// Advanced configuration (TF table) - use a user defined tractive force table
// With Simple adhesion apart from correction for rail adhesion, there is no further variation to the motive force.
// With Advanced adhesion the raw motive force is fed into the advanced (axle) adhesion model, and is corrected for wheel slip and rail adhesion
// TO be Checked how main power supply conditions apply to geared locomotives - Note for geared locomotives it is possible to get some tractive force due to the drag of a stalled engine, if in gear, and clutch engaged
if ((LocomotivePowerSupply.MainPowerSupplyOn || DieselEngines.HasGearBox) && Direction != Direction.N)
{
// Appartent throttle setting is a reverse lookup of the throttletab vs rpm, hence motive force increase will be related to increase in rpm. The minimum of the two values
// is checked to enable fast reduction in tractive force when decreasing the throttle. Typically it will take longer for the prime mover to decrease rpm then drop motive force.
float LocomotiveApparentThrottleSetting = 0;
if (IsPlayerTrain)
{
LocomotiveApparentThrottleSetting = Math.Min(t, DieselEngines.ApparentThrottleSetting / 100.0f);
}
else // For AI trains, just use the throttle setting
{
LocomotiveApparentThrottleSetting = t;
}
LocomotiveApparentThrottleSetting = MathHelper.Clamp(LocomotiveApparentThrottleSetting, 0.0f, 1.0f); // Clamp decay within bounds
// If there is more then one diesel engine, and one or more engines is stopped, then the Fraction Power will give a fraction less then 1 depending upon power definitions of engines.
float DieselEngineFractionPower = 1.0f;
if (DieselEngines.Count > 1)
{
DieselEngineFractionPower = DieselEngines.RunningPowerFraction;
}
DieselEngineFractionPower = MathHelper.Clamp(DieselEngineFractionPower, 0.0f, 1.0f); // Clamp decay within bounds
// For the advanced adhesion model, a rudimentary form of slip control is incorporated by using the wheel speed to calculate tractive effort.
// As wheel speed is increased tractive effort is decreased. Hence wheel slip is "controlled" to a certain extent.
// This doesn't cover all types of locomotives, for eaxmple if DC traction motors and no slip control, then the tractive effort shouldn't be reduced. This won't eliminate slip, but limits
// its impact. More modern locomotive have a more sophisticated system that eliminates slip in the majority (if not all circumstances).
// Simple adhesion control does not have any slip control feature built into it.
// TODO - a full review of slip/no slip control.
if (TractionMotorType == TractionMotorTypes.AC)
{
AbsTractionSpeedMpS = AbsSpeedMpS;
if (AbsWheelSpeedMpS > 1.1 * MaxSpeedMpS)
{
AverageForceN = TractiveForceN = 0;
return;
}
}
else
{
if (WheelSlip && AdvancedAdhesionModel)
{
AbsTractionSpeedMpS = AbsWheelSpeedMpS;
}
else
{
AbsTractionSpeedMpS = AbsSpeedMpS;
}
}
if (TractiveForceCurves == null)
{
// This sets the maximum force of the locomotive, it will be adjusted down if it exceeds the max power of the locomotive.
float maxForceN = Math.Min(t * MaxForceN * (1 - PowerReduction), AbsTractionSpeedMpS == 0.0f ? (t * MaxForceN * (1 - PowerReduction)) : (t * LocomotiveMaxRailOutputPowerW / AbsTractionSpeedMpS));
// Maximum rail power is reduced by apparent throttle factor and the number of engines running (power ratio)
float maxPowerW = LocomotiveMaxRailOutputPowerW * DieselEngineFractionPower * LocomotiveApparentThrottleSetting;
// If unloading speed is in ENG file, and locomotive speed is greater then unloading speed, and less then max speed, then apply a decay factor to the power/force
if (UnloadingSpeedMpS != 0 && AbsTractionSpeedMpS > UnloadingSpeedMpS && AbsTractionSpeedMpS < MaxSpeedMpS && !WheelSlip)
{
// use straight line curve to decay power to zero by 2 x unloading speed
float unloadingspeeddecay = 1.0f - (1.0f / UnloadingSpeedMpS) * (AbsTractionSpeedMpS - UnloadingSpeedMpS);
unloadingspeeddecay = MathHelper.Clamp(unloadingspeeddecay, 0.0f, 1.0f); // Clamp decay within bounds
maxPowerW *= unloadingspeeddecay;
}
if (DieselEngines.HasGearBox)
{
TractiveForceN = DieselEngines.TractiveForceN;
}
else
{
if (maxForceN * AbsSpeedMpS > maxPowerW)
maxForceN = maxPowerW / AbsTractionSpeedMpS;
TractiveForceN = maxForceN;
// Motive force will be produced until power reaches zero, some locomotives had a overspeed monitor set at the maximum design speed
}
}
else
{
if (DieselEngines.HasGearBox && DieselTransmissionType == MSTSDieselLocomotive.DieselTransmissionTypes.Mechanic)
{
TractiveForceN = DieselEngines.TractiveForceN;
}
else
{
// Tractive force is read from Table using the apparent throttle setting, and then reduced by the number of engines running (power ratio)
TractiveForceN = TractiveForceCurves.Get(LocomotiveApparentThrottleSetting, AbsTractionSpeedMpS) * DieselEngineFractionPower * (1 - PowerReduction);
}
if (TractiveForceN < 0 && !TractiveForceCurves.AcceptsNegativeValues())
TractiveForceN = 0;
}
}
else
{
TractiveForceN = 0f;
}
if (MaxForceN > 0 && MaxContinuousForceN > 0 && PowerReduction < 1)
{
TractiveForceN *= 1 - (MaxForceN - MaxContinuousForceN) / (MaxForceN * MaxContinuousForceN) * AverageForceN * (1 - PowerReduction);
float w = (ContinuousForceTimeFactor - elapsedClockSeconds) / ContinuousForceTimeFactor;
if (w < 0)
w = 0;
AverageForceN = w * AverageForceN + (1 - w) * TractiveForceN;
}
// Calculate fuel consumption will occur unless diesel engine is stopped
DieselFlowLps = DieselEngines.DieselFlowLps;
partialFuelConsumption += DieselEngines.DieselFlowLps * elapsedClockSeconds;
if (partialFuelConsumption >= 0.1)
{
DieselLevelL -= partialFuelConsumption;
partialFuelConsumption = 0;
}
// stall engine if fuel runs out
if (DieselLevelL <= 0.0f)
{
SignalEvent(Event.EnginePowerOff);
DieselEngines.HandleEvent(PowerSupplyEvent.StopEngine);
}
}
/// <summary>
/// This function updates periodically the locomotive's sound variables.
/// </summary>
protected override void UpdateSoundVariables(float elapsedClockSeconds)
{
EngineRPMRatio = (DieselEngines[0].RealRPM - DieselEngines[0].IdleRPM) / (DieselEngines[0].MaxRPM - DieselEngines[0].IdleRPM);
Variable1 = ThrottlePercent / 100.0f;
// else Variable1 = MotiveForceN / MaxForceN; // Gearbased, Variable1 proportional to motive force
// allows for motor volume proportional to effort.
// Refined Variable2 setting to graduate
if (Variable2 != EngineRPMRatio)
{
// We must avoid Variable2 to run outside of [0, 1] range, even temporarily (because of multithreading)
Variable2 = EngineRPMRatio < Variable2 ?
Math.Max(Math.Max(Variable2 - elapsedClockSeconds * PercentChangePerSec, EngineRPMRatio), 0) :
Math.Min(Math.Min(Variable2 + elapsedClockSeconds * PercentChangePerSec, EngineRPMRatio), 1);
}
EngineRPM = Variable2 * (MaxRPM - IdleRPM) + IdleRPM;
if (DynamicBrakePercent > 0)
{
if (MaxDynamicBrakeForceN == 0)
Variable3 = DynamicBrakePercent / 100f;
else
Variable3 = DynamicBrakeForceN / MaxDynamicBrakeForceN;
}
else
Variable3 = 0;
if (elapsedClockSeconds > 0.0f)
{
EngineRPMderivation = (EngineRPM - EngineRPMold) / elapsedClockSeconds;
EngineRPMold = EngineRPM;
}
}
public override void ChangeGearUp()
{
if (DieselEngines[0].GearBox != null)
{
if (DieselEngines[0].GearBox.GearBoxOperation == GearBoxOperation.Semiautomatic)
{
DieselEngines[0].GearBox.AutoGearUp();
GearBoxController.SetValue((float)DieselEngines[0].GearBox.NextGearIndex);
}
else if (DieselEngines[0].GearBox.GearBoxOperation == GearBoxOperation.Manual)
{
DieselEngines[0].GearBox.ManualGearUp = true;
}
}
}
public override void ChangeGearDown()
{
if (DieselEngines[0].GearBox != null)
{
if (DieselEngines[0].GearBox.GearBoxOperation == GearBoxOperation.Semiautomatic)
{
DieselEngines[0].GearBox.AutoGearDown();
GearBoxController.SetValue((float)DieselEngines[0].GearBox.NextGearIndex);
}
else if (DieselEngines[0].GearBox.GearBoxOperation == GearBoxOperation.Manual)
{
DieselEngines[0].GearBox.ManualGearDown = true;
}
}
}
public override float GetDataOf(CabViewControl cvc)
{
float data = 0;
switch (cvc.ControlType.Type)
{
case CABViewControlTypes.GEARS:
if (DieselEngines.HasGearBox)
data = DieselEngines[0].GearBox.GearIndication;
break;
case CABViewControlTypes.FUEL_GAUGE:
if (cvc.Units == CABViewControlUnits.GALLONS)
data = L.ToGUS(DieselLevelL);
else
data = DieselLevelL;
break;
case CABViewControlTypes.ORTS_TRACTION_CUT_OFF_RELAY_DRIVER_CLOSING_ORDER:
data = DieselPowerSupply.TractionCutOffRelay.DriverClosingOrder ? 1 : 0;
break;
case CABViewControlTypes.ORTS_TRACTION_CUT_OFF_RELAY_DRIVER_OPENING_ORDER:
data = DieselPowerSupply.TractionCutOffRelay.DriverOpeningOrder ? 1 : 0;
break;
case CABViewControlTypes.ORTS_TRACTION_CUT_OFF_RELAY_DRIVER_CLOSING_AUTHORIZATION:
data = DieselPowerSupply.TractionCutOffRelay.DriverClosingAuthorization ? 1 : 0;
break;
case CABViewControlTypes.ORTS_TRACTION_CUT_OFF_RELAY_STATE:
switch (DieselPowerSupply.TractionCutOffRelay.State)
{
case TractionCutOffRelayState.Open:
data = 0;
break;
case TractionCutOffRelayState.Closing:
data = 1;
break;
case TractionCutOffRelayState.Closed:
data = 2;
break;
}
break;
case CABViewControlTypes.ORTS_TRACTION_CUT_OFF_RELAY_CLOSED:
switch (DieselPowerSupply.TractionCutOffRelay.State)
{
case TractionCutOffRelayState.Open:
case TractionCutOffRelayState.Closing:
data = 0;
break;
case TractionCutOffRelayState.Closed:
data = 1;
break;
}
break;
case CABViewControlTypes.ORTS_TRACTION_CUT_OFF_RELAY_OPEN:
switch (DieselPowerSupply.TractionCutOffRelay.State)
{
case TractionCutOffRelayState.Open:
case TractionCutOffRelayState.Closing:
data = 1;
break;
case TractionCutOffRelayState.Closed:
data = 0;
break;
}
break;
case CABViewControlTypes.ORTS_TRACTION_CUT_OFF_RELAY_AUTHORIZED:
data = DieselPowerSupply.TractionCutOffRelay.ClosingAuthorization ? 1 : 0;
break;
case CABViewControlTypes.ORTS_TRACTION_CUT_OFF_RELAY_OPEN_AND_AUTHORIZED:
data = (DieselPowerSupply.TractionCutOffRelay.State < TractionCutOffRelayState.Closed && DieselPowerSupply.TractionCutOffRelay.ClosingAuthorization) ? 1 : 0;
break;
default:
data = base.GetDataOf(cvc);
break;
}
return data;
}
public override string GetStatus()
{
var status = new StringBuilder();
status.AppendFormat("{0} = {1}\n", Simulator.Catalog.GetString("Engine"),
Simulator.Catalog.GetParticularString("Engine", GetStringAttribute.GetPrettyName(DieselEngines[0].State)));
if (DieselEngines.HasGearBox)
status.AppendFormat("{0} = {1}\n", Simulator.Catalog.GetString("Gear"),
DieselEngines[0].GearBox.CurrentGearIndex < 0 ? Simulator.Catalog.GetParticularString("Gear", "N") : (DieselEngines[0].GearBox.GearIndication).ToString());
status.AppendLine();
status.AppendFormat("{0} = {1}\n",
Simulator.Catalog.GetString("Battery switch"),
LocomotivePowerSupply.BatterySwitch.On ? Simulator.Catalog.GetString("On") : Simulator.Catalog.GetString("Off"));
status.AppendFormat("{0} = {1}\n",
Simulator.Catalog.GetString("Master key"),
LocomotivePowerSupply.MasterKey.On ? Simulator.Catalog.GetString("On") : Simulator.Catalog.GetString("Off"));
status.AppendFormat("{0} = {1}\n",
Simulator.Catalog.GetString("Traction cut-off relay"),
Simulator.Catalog.GetParticularString("TractionCutOffRelay", GetStringAttribute.GetPrettyName(DieselPowerSupply.TractionCutOffRelay.State)));
status.AppendFormat("{0} = {1}\n",
Simulator.Catalog.GetString("Electric train supply"),
LocomotivePowerSupply.ElectricTrainSupplySwitch.On ? Simulator.Catalog.GetString("On") : Simulator.Catalog.GetString("Off"));
status.AppendLine();
status.AppendFormat("{0} = {1}",
Simulator.Catalog.GetParticularString("PowerSupply", "Power"),
Simulator.Catalog.GetParticularString("PowerSupply", GetStringAttribute.GetPrettyName(LocomotivePowerSupply.MainPowerSupplyState)));
return status.ToString();
}
public override string GetDebugStatus()
{
var status = new StringBuilder(base.GetDebugStatus());
if (DieselEngines.HasGearBox && DieselTransmissionType == DieselTransmissionTypes.Mechanic)
{
status.AppendFormat("\t{0} {1}-{2}", Simulator.Catalog.GetString("Gear"), DieselEngines[0].GearBox.CurrentGearIndex < 0 ? Simulator.Catalog.GetString("N") : (DieselEngines[0].GearBox.GearIndication).ToString(), DieselEngines[0].GearBox.GearBoxType);
}
status.AppendFormat("\t{0} {1}\t\t{2}\n",
Simulator.Catalog.GetString("Fuel"),
FormatStrings.FormatFuelVolume(DieselLevelL, IsMetric, IsUK), DieselEngines.GetStatus());
if (IsSteamHeatFitted && Train.PassengerCarsNumber > 0 && this.IsLeadLocomotive() && Train.CarSteamHeatOn)
{
// Only show steam heating HUD if fitted to locomotive and the train, has passenger cars attached, and is the lead locomotive
// Display Steam Heat info
status.AppendFormat("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}/{7}\t{8}\t{9}\t{10}\t{11}\t{12}\t{13}\t{14}\t{15}\t{16}\t{17}\t{18:N0}\n",
Simulator.Catalog.GetString("StHeat:"),
Simulator.Catalog.GetString("Press"),
FormatStrings.FormatPressure(CurrentSteamHeatPressurePSI, PressureUnit.PSI, MainPressureUnit, true),
Simulator.Catalog.GetString("StTemp"),
FormatStrings.FormatTemperature(C.FromF(SteamHeatPressureToTemperaturePSItoF[CurrentSteamHeatPressurePSI]), IsMetric, false),
Simulator.Catalog.GetString("StUse"),
FormatStrings.FormatMass(pS.TopH(Kg.FromLb(CalculatedCarHeaterSteamUsageLBpS)), IsMetric),
FormatStrings.h,
Simulator.Catalog.GetString("WaterLvl"),
FormatStrings.FormatFuelVolume(CurrentLocomotiveSteamHeatBoilerWaterCapacityL, IsMetric, IsUK),
Simulator.Catalog.GetString("Last:"),
Simulator.Catalog.GetString("Press"),
FormatStrings.FormatPressure(Train.LastCar.CarSteamHeatMainPipeSteamPressurePSI, PressureUnit.PSI, MainPressureUnit, true),
Simulator.Catalog.GetString("Temp"),
FormatStrings.FormatTemperature(Train.LastCar.CarInsideTempC, IsMetric, false),
Simulator.Catalog.GetString("OutTemp"),
FormatStrings.FormatTemperature(CarOutsideTempC, IsMetric, false),
Simulator.Catalog.GetString("NetHt"),
Train.LastCar.CarNetHeatFlowRateW);
}