/
MSTSWagon.cs
4432 lines (3903 loc) · 220 KB
/
MSTSWagon.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/>.
/*
* TrainCarSimulator
*
* TrainCarViewer
*
* Every TrainCar generates a FrictionForce.
*
* The viewer is a separate class object since there could be multiple
* viewers potentially on different devices for a single car.
*
*/
//#define ALLOW_ORTS_SPECIFIC_ENG_PARAMETERS
//#define DEBUG_AUXTENDER
// Debug for Friction Force
//#define DEBUG_FRICTION
// Debug for Freight Animation Variable Mass
//#define DEBUG_VARIABLE_MASS
using Microsoft.Xna.Framework;
using Orts.Formats.Msts;
using Orts.Parsers.Msts;
using Orts.Simulation.RollingStocks.SubSystems;
using Orts.Simulation.RollingStocks.SubSystems.Brakes.MSTS;
using Orts.Simulation.RollingStocks.SubSystems.Controllers;
using Orts.Simulation.RollingStocks.SubSystems.PowerSupplies;
using ORTS.Common;
using ORTS.Scripting.Api;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Event = Orts.Common.Event;
namespace Orts.Simulation.RollingStocks
{
///////////////////////////////////////////////////
/// SIMULATION BEHAVIOUR
///////////////////////////////////////////////////
/// <summary>
/// Represents the physical motion and behaviour of the car.
/// </summary>
public class MSTSWagon : TrainCar
{
public Pantographs Pantographs;
public ScriptedPassengerCarPowerSupply PassengerCarPowerSupply => PowerSupply as ScriptedPassengerCarPowerSupply;
public Doors Doors;
public Door RightDoor => Doors.RightDoor;
public Door LeftDoor => Doors.LeftDoor;
public bool MirrorOpen;
public bool UnloadingPartsOpen;
public bool WaitForAnimationReady; // delay counter to start loading/unliading is on;
public bool IsRollerBearing = false; // Has roller bearings
public bool IsLowTorqueRollerBearing = false; // Has low torque roller bearings
public bool IsFrictionBearing = false; //Has oil based friction (or solid bearings)
public bool IsGreaseFrictionBearing = false; // Has grease based friction (or solid bearings)
public bool IsStandStill = true; // Used for MSTS type friction
public bool IsDavisFriction = true; // Default to new Davis type friction
public bool IsBelowMergeSpeed = true; // set indicator for low speed operation as per given speed
public bool GenericItem1;
public bool GenericItem2;
Interpolator BrakeShoeFrictionFactor; // Factor of friction for wagon brake shoes
const float WaterLBpUKG = 10.0f; // lbs of water in 1 gal (uk)
float TempMassDiffRatio;
// simulation parameters
public float Variable1; // used to convey status to soundsource
public float Variable2;
public float Variable3;
// wag file data
public string MainShapeFileName;
public string FreightShapeFileName;
public float FreightAnimMaxLevelM;
public float FreightAnimMinLevelM;
public float FreightAnimFlag = 1; // if absent or >= 0 causes the freightanim to drop in tenders
public string Cab3DShapeFileName; // 3DCab view shape file name
public string InteriorShapeFileName; // passenger view shape file name
public string MainSoundFileName;
public string InteriorSoundFileName;
public string Cab3DSoundFileName;
public float ExternalSoundPassThruPercent = -1;
public float WheelRadiusM = Me.FromIn(18.0f); // Provide some defaults in case it's missing from the wag - Wagon wheels could vary in size from approx 10" to 25".
protected float StaticFrictionFactorN; // factor to multiply friction by to determine static or starting friction - will vary depending upon whether roller or friction bearing
float FrictionLowSpeedN; // Davis low speed value 0 - 5 mph
float FrictionBelowMergeSpeedN; // Davis low speed value for defined speed
public float Friction0N; // static friction
protected float Friction5N; // Friction at 5mph
public float StandstillFrictionN;
public float MergeSpeedFrictionN;
public float MergeSpeedMpS = MpS.FromMpH(5f);
public float DavisAN; // davis equation constant
public float DavisBNSpM; // davis equation constant for speed
public float DavisCNSSpMM; // davis equation constant for speed squared
public float DavisDragConstant; // Drag coefficient for wagon
public float WagonFrontalAreaM2; // Frontal area of wagon
public float TrailLocoResistanceFactor; // Factor to reduce base and wind resistance if locomotive is not leading - based upon original Davis drag coefficients
bool TenderWeightInitialize = true;
float TenderWagonMaxCoalMassKG;
float TenderWagonMaxWaterMassKG;
// Wind Impacts
float WagonDirectionDeg;
float WagonResultantWindComponentDeg;
float WagonWindResultantSpeedMpS;
protected float FrictionC1; // MSTS Friction parameters
protected float FrictionE1; // MSTS Friction parameters
protected float FrictionV2; // MSTS Friction parameters
protected float FrictionC2; // MSTS Friction parameters
protected float FrictionE2; // MSTS Friction parameters
//protected float FrictionSpeedMpS; // Train current speed value for friction calculations ; this value is never used outside of this class, and FrictionSpeedMpS is always = AbsSpeedMpS
public List<MSTSCoupling> Couplers = new List<MSTSCoupling>();
public float Adhesion1 = .27f; // 1st MSTS adhesion value
public float Adhesion2 = .49f; // 2nd MSTS adhesion value
public float Adhesion3 = 2; // 3rd MSTS adhesion value
public float Curtius_KnifflerA = 7.5f; //Curtius-Kniffler constants A
public float Curtius_KnifflerB = 44.0f; // (adhesion coeficient) umax = --------------------- + C
public float Curtius_KnifflerC = 0.161f; // speedMpS * 3.6 + B
public float AdhesionK = 0.7f; //slip characteristics slope
public float AxleInertiaKgm2; //axle inertia
public float AdhesionDriveWheelRadiusM;
public float WheelSpeedMpS;
public float WheelSpeedSlipMpS; // speed of wheel if locomotive is slipping
public float SlipWarningThresholdPercent = 70;
public MSTSNotchController WeightLoadController; // Used to control freight loading in freight cars
public float AbsWheelSpeedMpS; // Math.Abs(WheelSpeedMpS) is used frequently in the subclasses, maybe it's more efficient to compute it once
// Colours for smoke and steam effects
public Color ExhaustTransientColor = Color.Black;
public Color ExhaustDecelColor = Color.WhiteSmoke;
public Color ExhaustSteadyColor = Color.Gray;
// Wagon steam leaks
public float HeatingHoseParticleDurationS;
public float HeatingHoseSteamVelocityMpS;
public float HeatingHoseSteamVolumeM3pS;
// Wagon heating compartment steamtrap leaks
public float HeatingCompartmentSteamTrapParticleDurationS;
public float HeatingCompartmentSteamTrapVelocityMpS;
public float HeatingCompartmentSteamTrapVolumeM3pS;
// Wagon heating steamtrap leaks
public float HeatingMainPipeSteamTrapDurationS;
public float HeatingMainPipeSteamTrapVelocityMpS;
public float HeatingMainPipeSteamTrapVolumeM3pS;
// Steam Brake leaks
public float SteamBrakeLeaksDurationS;
public float SteamBrakeLeaksVelocityMpS;
public float SteamBrakeLeaksVolumeM3pS;
// Water Scoop Spray
public float WaterScoopParticleDurationS;
public float WaterScoopWaterVelocityMpS;
public float WaterScoopWaterVolumeM3pS;
// Tender Water overflow
public float TenderWaterOverflowParticleDurationS;
public float TenderWaterOverflowVelocityMpS;
public float TenderWaterOverflowVolumeM3pS;
// Wagon Power Generator
public float WagonGeneratorDurationS = 1.5f;
public float WagonGeneratorVolumeM3pS = 2.0f;
public Color WagonGeneratorSteadyColor = Color.Gray;
// Heating Steam Boiler
public float HeatingSteamBoilerDurationS;
public float HeatingSteamBoilerVolumeM3pS;
public Color HeatingSteamBoilerSteadyColor = Color.LightSlateGray;
public bool HeatingBoilerSet = false;
// Wagon Smoke
public float WagonSmokeVolumeM3pS;
float InitialWagonSmokeVolumeM3pS = 3.0f;
public float WagonSmokeDurationS;
float InitialWagonSmokeDurationS = 1.0f;
public float WagonSmokeVelocityMpS = 15.0f;
public Color WagonSmokeSteadyColor = Color.Gray;
float TrueCouplerCount = 0;
int CouplerCountLocation;
// Bearing Hot Box Smoke
public float BearingHotBoxSmokeVolumeM3pS;
public float BearingHotBoxSmokeDurationS;
public float BearingHotBoxSmokeVelocityMpS = 15.0f;
public Color BearingHotBoxSmokeSteadyColor = Color.Gray;
/// <summary>
/// True if vehicle is equipped with an additional emergency brake reservoir
/// </summary>
public bool EmergencyReservoirPresent;
public enum BrakeValveType
{
None,
TripleValve, // Plain triple valve
Distributor, // Triple valve with graduated release
DistributingValve, // Triple valve + driver brake valve control. Only for locomotives
}
/// <summary>
/// Type of brake valve in the car
/// </summary>
public BrakeValveType BrakeValve;
/// <summary>
/// True if equipped with handbrake. (Not common for older steam locomotives.)
/// </summary>
public bool HandBrakePresent;
/// <summary>
/// Number of available retainer positions. (Used on freight cars, mostly.) Might be 0, 3 or 4.
/// </summary>
public int RetainerPositions;
/// <summary>
/// Indicates whether a brake is present or not when Manual Braking is selected.
/// </summary>
public bool ManualBrakePresent;
/// <summary>
/// Indicates whether a non auto (straight) brake is present or not when braking is selected.
/// </summary>
public bool NonAutoBrakePresent;
/// <summary>
/// Indicates whether an auxiliary reservoir is present on the wagon or not.
/// </summary>
public bool AuxiliaryReservoirPresent;
/// <summary>
/// Active locomotive for a control trailer
/// </summary>
public MSTSLocomotive ControlActiveLocomotive { get; private set; }
/// <summary>
/// Attached steam locomotive in case this wagon is a tender
/// </summary>
public MSTSSteamLocomotive TendersSteamLocomotive { get; private set; }
/// <summary>
/// Attached steam locomotive in case this wagon is an auxiliary tender
/// </summary>
public MSTSSteamLocomotive AuxTendersSteamLocomotive { get; private set; }
/// <summary>
/// Steam locomotive has a tender coupled to it
/// </summary>
public MSTSSteamLocomotive SteamLocomotiveTender { get; private set; }
/// <summary>
/// Steam locomotive identifier (pass parameters from MSTSSteamLocomotive to MSTSWagon)
/// </summary>
public MSTSSteamLocomotive SteamLocomotiveIdentification { get; private set; }
/// <summary>
/// Diesel locomotive identifier (pass parameters from MSTSDieselLocomotive to MSTSWagon)
/// </summary>
public MSTSDieselLocomotive DieselLocomotiveIdentification { get; private set; }
public Dictionary<string, List<ParticleEmitterData>> EffectData = new Dictionary<string, List<ParticleEmitterData>>();
protected void ParseEffects(string lowercasetoken, STFReader stf)
{
stf.MustMatch("(");
string s;
while ((s = stf.ReadItem()) != ")")
{
var data = new ParticleEmitterData(stf);
if (!EffectData.ContainsKey(s))
EffectData.Add(s, new List<ParticleEmitterData>());
EffectData[s].Add(data);
}
}
public List<IntakePoint> IntakePointList = new List<IntakePoint>();
/// <summary>
/// Supply types for freight wagons and locos
/// </summary>
public enum PickupType
{
None = 0,
FreightGrain = 1,
FreightCoal = 2,
FreightGravel = 3,
FreightSand = 4,
FuelWater = 5,
FuelCoal = 6,
FuelDiesel = 7,
FuelWood = 8, // Think this is new to OR and not recognised by MSTS
FuelSand = 9, // New to OR
FreightGeneral = 10, // New to OR
FreightLivestock = 11, // New to OR
FreightFuel = 12, // New to OR
FreightMilk = 13, // New to OR
SpecialMail = 14, // New to OR
Container = 15 // New to OR
}
public class RefillProcess
{
public static bool OkToRefill { get; set; }
public static int ActivePickupObjectUID { get; set; }
public static bool Unload { get; set; }
}
public MSTSBrakeSystem MSTSBrakeSystem
{
get { return (MSTSBrakeSystem)base.BrakeSystem; }
set { base.BrakeSystem = value; } // value needs to be set to allow trailing cars to have same brake system as locomotive when in simple brake mode
}
public MSTSWagon(Simulator simulator, string wagFilePath)
: base(simulator, wagFilePath)
{
Pantographs = new Pantographs(this);
Doors = new Doors(this);
}
public void Load()
{
if (CarManager.LoadedCars.ContainsKey(WagFilePath))
{
Copy(CarManager.LoadedCars[WagFilePath]);
}
else
{
LoadFromWagFile(WagFilePath);
CarManager.LoadedCars.Add(WagFilePath, this);
}
GetMeasurementUnits();
}
// Values for adjusting wagon physics due to load changes
float LoadEmptyMassKg;
float LoadEmptyORTSDavis_A;
float LoadEmptyORTSDavis_B;
float LoadEmptyORTSDavis_C;
float LoadEmptyWagonFrontalAreaM2;
float LoadEmptyDavisDragConstant;
float LoadEmptyMaxBrakeForceN;
float LoadEmptyMaxHandbrakeForceN;
float LoadEmptyCentreOfGravityM_Y;
float LoadFullMassKg;
float LoadFullORTSDavis_A;
float LoadFullORTSDavis_B;
float LoadFullORTSDavis_C;
float LoadFullWagonFrontalAreaM2;
float LoadFullDavisDragConstant;
float LoadFullMaxBrakeForceN;
float LoadFullMaxHandbrakeForceN;
float LoadFullCentreOfGravityM_Y;
/// <summary>
/// This initializer is called when we haven't loaded this type of car before
/// and must read it new from the wag file.
/// </summary>
public virtual void LoadFromWagFile(string wagFilePath)
{
string dir = Path.GetDirectoryName(wagFilePath);
string file = Path.GetFileName(wagFilePath);
string orFile = dir + @"\openrails\" + file;
if (File.Exists(orFile))
wagFilePath = orFile;
using (STFReader stf = new STFReader(wagFilePath, true))
{
while (!stf.Eof)
{
stf.ReadItem();
Parse(stf.Tree.ToLower(), stf);
}
}
var wagonFolderSlash = Path.GetDirectoryName(WagFilePath) + @"\";
if (MainShapeFileName != null && !File.Exists(wagonFolderSlash + MainShapeFileName))
{
Trace.TraceWarning("{0} references non-existent shape {1}", WagFilePath, wagonFolderSlash + MainShapeFileName);
MainShapeFileName = string.Empty;
}
if (FreightShapeFileName != null && !File.Exists(wagonFolderSlash + FreightShapeFileName))
{
Trace.TraceWarning("{0} references non-existent shape {1}", WagFilePath, wagonFolderSlash + FreightShapeFileName);
FreightShapeFileName = null;
}
if (InteriorShapeFileName != null && !File.Exists(wagonFolderSlash + InteriorShapeFileName))
{
Trace.TraceWarning("{0} references non-existent shape {1}", WagFilePath, wagonFolderSlash + InteriorShapeFileName);
InteriorShapeFileName = null;
}
if (FrontCoupler.Closed.ShapeFileName != null && !File.Exists(wagonFolderSlash + FrontCoupler.Closed.ShapeFileName))
{
Trace.TraceWarning("{0} references non-existent shape {1}", WagFilePath, wagonFolderSlash + FrontCoupler.Closed.ShapeFileName);
FrontCoupler.Closed.ShapeFileName = null;
}
if (RearCoupler.Closed.ShapeFileName != null && !File.Exists(wagonFolderSlash + RearCoupler.Closed.ShapeFileName))
{
Trace.TraceWarning("{0} references non-existent shape {1}", WagFilePath, wagonFolderSlash + RearCoupler.Closed.ShapeFileName);
RearCoupler.Closed.ShapeFileName = null;
}
if (FrontAirHose.Connected.ShapeFileName != null && !File.Exists(wagonFolderSlash + FrontAirHose.Connected.ShapeFileName))
{
Trace.TraceWarning("{0} references non-existent shape {1}", WagFilePath, wagonFolderSlash + FrontAirHose.Connected.ShapeFileName);
FrontAirHose.Connected.ShapeFileName = null;
}
if (RearAirHose.Connected.ShapeFileName != null && !File.Exists(wagonFolderSlash + RearAirHose.Connected.ShapeFileName))
{
Trace.TraceWarning("{0} references non-existent shape {1}", WagFilePath, wagonFolderSlash + RearAirHose.Connected.ShapeFileName);
RearAirHose.Connected.ShapeFileName = null;
}
// If trailing loco resistance constant has not been defined in WAG/ENG file then assign default value based upon orig Davis values
if (TrailLocoResistanceFactor == 0)
{
if (WagonType == WagonTypes.Engine)
{
TrailLocoResistanceFactor = 0.2083f; // engine drag value
}
else if (WagonType == WagonTypes.Tender)
{
TrailLocoResistanceFactor = 1.0f; // assume that tenders have been set with a value of 0.0005 as per freight wagons
}
else //Standard default if not declared anywhere else
{
TrailLocoResistanceFactor = 1.0f;
}
}
// Initialise car body lengths. Assume overhang is 2.0m each end, and bogie centres are the car length minus this value
if (CarCouplerFaceLengthM == 0)
{
CarCouplerFaceLengthM = CarLengthM;
}
if (CarBodyLengthM == 0)
{
CarBodyLengthM = CarCouplerFaceLengthM - 0.8f;
}
if (CarBogieCentreLengthM == 0)
{
CarBogieCentreLengthM = (CarCouplerFaceLengthM - 4.3f);
}
if (CarAirHoseLengthM == 0)
{
CarAirHoseLengthM = Me.FromIn(26.25f); // 26.25 inches
}
var couplerlength = ((CarCouplerFaceLengthM - CarBodyLengthM) / 2) + 0.1f; // coupler length at rest, allow 0.1m also for slack
if (CarAirHoseHorizontalLengthM == 0)
{
CarAirHoseHorizontalLengthM = 0.3862f; // 15.2 inches
}
// Disable derailment coefficent on "dummy" cars. NB: Ideally this should never be used as "dummy" cars interfer with the overall train physics.
if (MSTSWagonNumWheels == 0 && InitWagonNumAxles == 0 )
{
DerailmentCoefficientEnabled = false;
}
// Ensure Drive Axles is set to a default if no OR value added to WAG file
if (InitWagonNumAxles == 0 && WagonType != WagonTypes.Engine)
{
if (MSTSWagonNumWheels != 0 && MSTSWagonNumWheels < 6)
{
WagonNumAxles = (int) MSTSWagonNumWheels;
}
else
{
WagonNumAxles = 4; // Set 4 axles as default
}
if (Simulator.Settings.VerboseConfigurationMessages)
{
Trace.TraceInformation("Number of Wagon Axles set to default value of {0}", WagonNumAxles);
}
}
else
{
WagonNumAxles = InitWagonNumAxles;
}
// Should always be at least one bogie on rolling stock. If is zero then NaN error occurs.
if (WagonNumBogies == 0)
{
WagonNumBogies = 1;
}
// Set wheel flange parameters to default values.
if (MaximumWheelFlangeAngleRad == 0)
{
MaximumWheelFlangeAngleRad = 1.22173f; // Default = 70 deg - Pre 1990 AAR 1:20 wheel
}
if (WheelFlangeLengthM == 0)
{
WheelFlangeLengthM = 0.0254f; // Height = 1.00in - Pre 1990 AAR 1:20 wheel
}
// Initialise steam heat parameters
if (TrainHeatBoilerWaterUsageGalukpH == null) // If no table entered in WAG file, then use the default table
{
TrainHeatBoilerWaterUsageGalukpH = SteamHeatBoilerWaterUsageGalukpH();
}
if (TrainHeatBoilerFuelUsageGalukpH == null) // If no table entered in WAG file, then use the default table
{
TrainHeatBoilerFuelUsageGalukpH = SteamHeatBoilerFuelUsageGalukpH();
}
MaximumSteamHeatingBoilerSteamUsageRateLbpS = TrainHeatBoilerWaterUsageGalukpH.MaxX(); // Find maximum steam capacity of the generator based upon the information in the water usage table
CurrentSteamHeatBoilerFuelCapacityL = MaximiumSteamHeatBoilerFuelTankCapacityL;
if (MaximumSteamHeatBoilerWaterTankCapacityL != 0)
{
CurrentCarSteamHeatBoilerWaterCapacityL = MaximumSteamHeatBoilerWaterTankCapacityL;
}
else
{
CurrentCarSteamHeatBoilerWaterCapacityL = L.FromGUK(800.0f);
}
// If Drag constant not defined in WAG/ENG file then assign default value based upon orig Davis values
if (DavisDragConstant == 0)
{
if (WagonType == WagonTypes.Engine)
{
DavisDragConstant = 0.0024f;
}
else if (WagonType == WagonTypes.Freight)
{
DavisDragConstant = 0.0005f;
}
else if (WagonType == WagonTypes.Passenger)
{
DavisDragConstant = 0.00034f;
}
else if (WagonType == WagonTypes.Tender)
{
DavisDragConstant = 0.0005f;
}
else //Standard default if not declared anywhere else
{
DavisDragConstant = 0.0005f;
}
}
// If wagon frontal area not user defined, assign a default value based upon the wagon dimensions
if (WagonFrontalAreaM2 == 0)
{
WagonFrontalAreaM2 = CarWidthM * CarHeightM;
}
// Initialise key wagon parameters
MassKG = InitialMassKG;
MaxHandbrakeForceN = InitialMaxHandbrakeForceN;
if (MaxBrakeShoeForceN != 0)
{
MaxBrakeForceN = MaxBrakeShoeForceN;
}
else
{
MaxBrakeForceN = InitialMaxBrakeForceN;
}
CentreOfGravityM = InitialCentreOfGravityM;
if (FreightAnimations != null)
{
foreach (var ortsFreightAnim in FreightAnimations.Animations)
{
if (ortsFreightAnim.ShapeFileName != null && !File.Exists(wagonFolderSlash + ortsFreightAnim.ShapeFileName))
{
Trace.TraceWarning("ORTS FreightAnim in trainset {0} references non-existent shape {1}", WagFilePath, wagonFolderSlash + ortsFreightAnim.ShapeFileName);
ortsFreightAnim.ShapeFileName = null;
}
}
// Read freight animation values from animation INCLUDE files
// Read (initialise) "common" (empty values first).
// Test each value to make sure that it has been defined in the WAG file, if not default to Root WAG file value
if (FreightAnimations.WagonEmptyWeight > 0)
{
LoadEmptyMassKg = FreightAnimations.WagonEmptyWeight;
}
else
{
LoadEmptyMassKg = MassKG;
}
if (FreightAnimations.EmptyORTSDavis_A > 0)
{
LoadEmptyORTSDavis_A = FreightAnimations.EmptyORTSDavis_A;
}
else
{
LoadEmptyORTSDavis_A = DavisAN;
}
if (FreightAnimations.EmptyORTSDavis_B > 0)
{
LoadEmptyORTSDavis_B = FreightAnimations.EmptyORTSDavis_B;
}
else
{
LoadEmptyORTSDavis_B = DavisBNSpM;
}
if (FreightAnimations.EmptyORTSDavis_C > 0)
{
LoadEmptyORTSDavis_C = FreightAnimations.EmptyORTSDavis_C;
}
else
{
LoadEmptyORTSDavis_C = DavisCNSSpMM;
}
if (FreightAnimations.EmptyORTSDavisDragConstant > 0)
{
LoadEmptyDavisDragConstant = FreightAnimations.EmptyORTSDavisDragConstant;
}
else
{
LoadEmptyDavisDragConstant = DavisDragConstant;
}
if (FreightAnimations.EmptyORTSWagonFrontalAreaM2 > 0)
{
LoadEmptyWagonFrontalAreaM2 = FreightAnimations.EmptyORTSWagonFrontalAreaM2;
}
else
{
LoadEmptyWagonFrontalAreaM2 = WagonFrontalAreaM2;
}
if (FreightAnimations.EmptyMaxBrakeForceN > 0)
{
LoadEmptyMaxBrakeForceN = FreightAnimations.EmptyMaxBrakeForceN;
}
else
{
LoadEmptyMaxBrakeForceN = MaxBrakeForceN;
}
if (FreightAnimations.EmptyMaxHandbrakeForceN > 0)
{
LoadEmptyMaxHandbrakeForceN = FreightAnimations.EmptyMaxHandbrakeForceN;
}
else
{
LoadEmptyMaxHandbrakeForceN = MaxHandbrakeForceN;
}
if (FreightAnimations.EmptyCentreOfGravityM_Y > 0)
{
LoadEmptyCentreOfGravityM_Y = FreightAnimations.EmptyCentreOfGravityM_Y;
}
else
{
LoadEmptyCentreOfGravityM_Y = CentreOfGravityM.Y;
}
// Read (initialise) Static load ones if a static load
// Test each value to make sure that it has been defined in the WAG file, if not default to Root WAG file value
if (FreightAnimations.FullPhysicsStaticOne != null)
{
if (FreightAnimations.FullPhysicsStaticOne.FullStaticORTSDavis_A > 0)
{
LoadFullORTSDavis_A = FreightAnimations.FullPhysicsStaticOne.FullStaticORTSDavis_A;
}
else
{
LoadFullORTSDavis_A = DavisAN;
}
if (FreightAnimations.FullPhysicsStaticOne.FullStaticORTSDavis_B > 0)
{
LoadFullORTSDavis_B = FreightAnimations.FullPhysicsStaticOne.FullStaticORTSDavis_B;
}
else
{
LoadFullORTSDavis_B = DavisBNSpM;
}
if (FreightAnimations.FullPhysicsStaticOne.FullStaticORTSDavis_C > 0)
{
LoadFullORTSDavis_C = FreightAnimations.FullPhysicsStaticOne.FullStaticORTSDavis_C;
}
else
{
LoadFullORTSDavis_C = DavisCNSSpMM;
}
if (FreightAnimations.FullPhysicsStaticOne.FullStaticORTSDavisDragConstant > 0)
{
LoadFullDavisDragConstant = FreightAnimations.FullPhysicsStaticOne.FullStaticORTSDavisDragConstant;
}
else
{
LoadFullDavisDragConstant = DavisDragConstant;
}
if (FreightAnimations.FullPhysicsStaticOne.FullStaticORTSWagonFrontalAreaM2 > 0)
{
LoadFullWagonFrontalAreaM2 = FreightAnimations.FullPhysicsStaticOne.FullStaticORTSWagonFrontalAreaM2;
}
else
{
LoadFullWagonFrontalAreaM2 = WagonFrontalAreaM2;
}
if (FreightAnimations.FullPhysicsStaticOne.FullStaticMaxBrakeForceN > 0)
{
LoadFullMaxBrakeForceN = FreightAnimations.FullPhysicsStaticOne.FullStaticMaxBrakeForceN;
}
else
{
LoadFullMaxBrakeForceN = MaxBrakeForceN;
}
if (FreightAnimations.FullPhysicsStaticOne.FullStaticMaxHandbrakeForceN > 0)
{
LoadFullMaxHandbrakeForceN = FreightAnimations.FullPhysicsStaticOne.FullStaticMaxHandbrakeForceN;
}
else
{
LoadFullMaxHandbrakeForceN = MaxHandbrakeForceN;
}
if (FreightAnimations.FullPhysicsStaticOne.FullStaticCentreOfGravityM_Y > 0)
{
LoadFullCentreOfGravityM_Y = FreightAnimations.FullPhysicsStaticOne.FullStaticCentreOfGravityM_Y;
}
else
{
LoadFullCentreOfGravityM_Y = CentreOfGravityM.Y;
}
}
// Read (initialise) Continuous load ones if a continuous load
// Test each value to make sure that it has been defined in the WAG file, if not default to Root WAG file value
if (FreightAnimations.FullPhysicsContinuousOne != null)
{
if (FreightAnimations.FullPhysicsContinuousOne.FreightWeightWhenFull > 0)
{
LoadFullMassKg = FreightAnimations.WagonEmptyWeight + FreightAnimations.FullPhysicsContinuousOne.FreightWeightWhenFull;
}
else
{
LoadFullMassKg = MassKG;
}
if (FreightAnimations.FullPhysicsContinuousOne.FullORTSDavis_A > 0)
{
LoadFullORTSDavis_A = FreightAnimations.FullPhysicsContinuousOne.FullORTSDavis_A;
}
else
{
LoadFullORTSDavis_A = DavisAN;
}
if (FreightAnimations.FullPhysicsContinuousOne.FullORTSDavis_B > 0)
{
LoadFullORTSDavis_B = FreightAnimations.FullPhysicsContinuousOne.FullORTSDavis_B;
}
else
{
LoadFullORTSDavis_B = DavisBNSpM;
}
if (FreightAnimations.FullPhysicsContinuousOne.FullORTSDavis_C > 0)
{
LoadFullORTSDavis_C = FreightAnimations.FullPhysicsContinuousOne.FullORTSDavis_C;
}
else
{
LoadFullORTSDavis_C = DavisCNSSpMM;
}
if (FreightAnimations.FullPhysicsContinuousOne.FullORTSDavisDragConstant > 0)
{
LoadFullDavisDragConstant = FreightAnimations.FullPhysicsContinuousOne.FullORTSDavisDragConstant;
}
else
{
LoadFullDavisDragConstant = DavisDragConstant;
}
if (FreightAnimations.FullPhysicsContinuousOne.FullORTSWagonFrontalAreaM2 > 0)
{
LoadFullWagonFrontalAreaM2 = FreightAnimations.FullPhysicsContinuousOne.FullORTSWagonFrontalAreaM2;
}
else
{
LoadFullWagonFrontalAreaM2 = WagonFrontalAreaM2;
}
if (FreightAnimations.FullPhysicsContinuousOne.FullMaxBrakeForceN > 0)
{
LoadFullMaxBrakeForceN = FreightAnimations.FullPhysicsContinuousOne.FullMaxBrakeForceN;
}
else
{
LoadFullMaxBrakeForceN = MaxBrakeForceN;
}
if (FreightAnimations.FullPhysicsContinuousOne.FullMaxHandbrakeForceN > 0)
{
LoadFullMaxHandbrakeForceN = FreightAnimations.FullPhysicsContinuousOne.FullMaxHandbrakeForceN;
}
else
{
LoadFullMaxHandbrakeForceN = MaxHandbrakeForceN;
}
if (FreightAnimations.FullPhysicsContinuousOne.FullCentreOfGravityM_Y > 0)
{
LoadFullCentreOfGravityM_Y = FreightAnimations.FullPhysicsContinuousOne.FullCentreOfGravityM_Y;
}
else
{
LoadFullCentreOfGravityM_Y = CentreOfGravityM.Y;
}
}
if (!FreightAnimations.MSTSFreightAnimEnabled) FreightShapeFileName = null;
if (FreightAnimations.WagonEmptyWeight != -1)
{
// Computes mass when it carries containers
float totalContainerMassKG = 0;
if (FreightAnimations.Animations != null)
{
foreach (var anim in FreightAnimations.Animations)
if (anim is FreightAnimationDiscrete discreteAnim && discreteAnim.Container != null)
{
totalContainerMassKG += discreteAnim.Container.MassKG;
}
}
CalculateTotalMass(totalContainerMassKG);
if (FreightAnimations.StaticFreightAnimationsPresent) // If it is static freight animation, set wagon physics to full wagon value
{
// Update brake parameters
MaxBrakeForceN = LoadFullMaxBrakeForceN;
MaxHandbrakeForceN = LoadFullMaxHandbrakeForceN;
// Update friction related parameters
DavisAN = LoadFullORTSDavis_A;
DavisBNSpM = LoadFullORTSDavis_B;
DavisCNSSpMM = LoadFullORTSDavis_C;
DavisDragConstant = LoadFullDavisDragConstant;
WagonFrontalAreaM2 = LoadFullWagonFrontalAreaM2;
// Update CoG related parameters
CentreOfGravityM.Y = LoadFullCentreOfGravityM_Y;
}
}
if (FreightAnimations.LoadedOne != null) // If it is a Continuouos freight animation, set freight wagon parameters to FullatStart
{
WeightLoadController.CurrentValue = FreightAnimations.LoadedOne.LoadPerCent / 100;
// Update wagon parameters sensitive to wagon mass change
// Calculate the difference ratio, ie how full the wagon is. This value allows the relevant value to be scaled from the empty mass to the full mass of the wagon
TempMassDiffRatio = WeightLoadController.CurrentValue;
// Update brake parameters
MaxBrakeForceN = ((LoadFullMaxBrakeForceN - LoadEmptyMaxBrakeForceN) * TempMassDiffRatio) + LoadEmptyMaxBrakeForceN;
MaxHandbrakeForceN = ((LoadFullMaxHandbrakeForceN - LoadEmptyMaxHandbrakeForceN) * TempMassDiffRatio) + LoadEmptyMaxHandbrakeForceN;
// Update friction related parameters
DavisAN = ((LoadFullORTSDavis_A - LoadEmptyORTSDavis_A) * TempMassDiffRatio) + LoadEmptyORTSDavis_A;
DavisBNSpM = ((LoadFullORTSDavis_B - LoadEmptyORTSDavis_B) * TempMassDiffRatio) + LoadEmptyORTSDavis_B;
DavisCNSSpMM = ((LoadFullORTSDavis_C - LoadEmptyORTSDavis_C) * TempMassDiffRatio) + LoadEmptyORTSDavis_C;
if (LoadEmptyDavisDragConstant > LoadFullDavisDragConstant ) // Due to wind turbulence empty drag might be higher then loaded drag, and therefore both scenarios need to be covered.
{
DavisDragConstant = LoadEmptyDavisDragConstant - ((LoadEmptyDavisDragConstant - LoadFullDavisDragConstant) * TempMassDiffRatio);
}
else
{
DavisDragConstant = ((LoadFullDavisDragConstant - LoadEmptyDavisDragConstant) * TempMassDiffRatio) + LoadEmptyDavisDragConstant;
}
WagonFrontalAreaM2 = ((LoadFullWagonFrontalAreaM2 - LoadEmptyWagonFrontalAreaM2) * TempMassDiffRatio) + LoadEmptyWagonFrontalAreaM2;
// Update CoG related parameters
CentreOfGravityM.Y = ((LoadFullCentreOfGravityM_Y - LoadEmptyCentreOfGravityM_Y) * TempMassDiffRatio) + LoadEmptyCentreOfGravityM_Y;
}
else // If Freight animation is Continuous and freight is not loaded then set initial values to the empty wagon values
{
if (FreightAnimations.ContinuousFreightAnimationsPresent)
{
// If it is an empty continuous freight animation, set wagon physics to empty wagon value
// Update brake physics
MaxBrakeForceN = LoadEmptyMaxBrakeForceN;
MaxHandbrakeForceN = LoadEmptyMaxHandbrakeForceN;
// Update friction related parameters
DavisAN = LoadEmptyORTSDavis_A;
DavisBNSpM = LoadEmptyORTSDavis_B;
DavisCNSSpMM = LoadEmptyORTSDavis_C;
// Update CoG related parameters
CentreOfGravityM.Y = LoadEmptyCentreOfGravityM_Y;
}
}
#if DEBUG_VARIABLE_MASS
Trace.TraceInformation(" =============================== Variable Load Initialisation (MSTSWagon.cs) ===============================");
Trace.TraceInformation("CarID {0}", CarID);
Trace.TraceInformation("Initial Values = Brake {0} Handbrake {1} CoGY {2} Mass {3}", InitialMaxBrakeForceN, InitialMaxHandbrakeForceN, InitialCentreOfGravityM.Y, InitialMassKG);
Trace.TraceInformation("Empty Values = Brake {0} Handbrake {1} DavisA {2} DavisB {3} DavisC {4} CoGY {5}", LoadEmptyMaxBrakeForceN, LoadEmptyMaxHandbrakeForceN, LoadEmptyORTSDavis_A, LoadEmptyORTSDavis_B, LoadEmptyORTSDavis_C, LoadEmptyCentreOfGravityM_Y);
Trace.TraceInformation("Full Values = Brake {0} Handbrake {1} DavisA {2} DavisB {3} DavisC {4} CoGY {5}", LoadFullMaxBrakeForceN, LoadFullMaxHandbrakeForceN, LoadFullORTSDavis_A, LoadFullORTSDavis_B, LoadFullORTSDavis_C, LoadFullCentreOfGravityM_Y);
#endif
}
// Determine whether or not to use the Davis friction model. Must come after freight animations are initialized.
IsDavisFriction = DavisAN != 0 && DavisBNSpM != 0 && DavisCNSSpMM != 0;
if (BrakeSystem == null)
BrakeSystem = MSTSBrakeSystem.Create(CarBrakeSystemType, this);
}
// Compute total mass of wagon including freight animations and variable loads like containers
public void CalculateTotalMass(float totalContainerMassKG)
{
MassKG = FreightAnimations.WagonEmptyWeight + FreightAnimations.FreightWeight + FreightAnimations.StaticFreightWeight + totalContainerMassKG;
}
public void GetMeasurementUnits()
{
IsMetric = Simulator.Settings.Units == "Metric" || (Simulator.Settings.Units == "Automatic" && System.Globalization.RegionInfo.CurrentRegion.IsMetric) ||
(Simulator.Settings.Units == "Route" && Simulator.TRK.Tr_RouteFile.MilepostUnitsMetric);
IsUK = Simulator.Settings.Units == "UK";
}
public override void Initialize()
{
Pantographs.Initialize();
Doors.Initialize();
PassengerCarPowerSupply?.Initialize();
base.Initialize();
if (UnbalancedSuperElevationM == 0 || UnbalancedSuperElevationM > 0.5) // If UnbalancedSuperElevationM > 18", or equal to zero, then set a default value
{
switch (WagonType)
{
case WagonTypes.Freight:
UnbalancedSuperElevationM = Me.FromIn(3.0f); // Unbalanced superelevation has a maximum default value of 3"
break;