@@ -163,6 +163,8 @@ public TrainCar LastCar
163163 public bool HuDIsWheelSlip;
164164 public bool IsBrakeSkid;
165165
166+ public bool TrackJointSoundSetUpInitialise = true;
167+
166168 public bool HotBoxSetOnTrain = false;
167169 public int ActivityDurationS
168170 {
@@ -2009,6 +2011,84 @@ public virtual void Update(float elapsedClockSeconds, bool auxiliaryUpdate = tru
20092011 LogTrainSpeed(Simulator.ClockTime);
20102012 }
20112013
2014+ // Initialise track joint trigger points. Sets the trigger point for the track joint reletative to other cars.
2015+ // This is then reset every time a track joint is triggered, and positioned the same distance apart, hence reletative positions are maintained.
2016+ // Only runs once at start up.
2017+ if (TrackJointSoundSetUpInitialise && (float)Simulator.TRK.Tr_RouteFile.DistanceBetweenTrackJointsM > 0 && Simulator.TRK.Tr_RouteFile.TrackSoundDefaultContinuousPlay)
2018+ {
2019+ var trackjointdistanceM = (float)Simulator.TRK.Tr_RouteFile.DistanceBetweenTrackJointsM;
2020+ var trainLengthM = 0.0f;
2021+ var cummulativeTrackJointDistanceM = 0.0f;
2022+ var remainDistanceM = (float)Simulator.TRK.Tr_RouteFile.DistanceBetweenTrackJointsM;
2023+
2024+ foreach (var car in Cars)
2025+ {
2026+ // Initialise from the next track joint
2027+
2028+ // if remain distance has gone negative then car has moved over the next track joint
2029+ if (trackjointdistanceM > car.CarLengthM)
2030+ {
2031+
2032+ car.realTimeTrackJointDistanceM = cummulativeTrackJointDistanceM;
2033+ trainLengthM += car.CarLengthM;
2034+ cummulativeTrackJointDistanceM += car.CarLengthM;
2035+ remainDistanceM -= car.CarLengthM;
2036+
2037+ // Set values for printing values initially applied
2038+ bool concretesleepers = false;
2039+
2040+ if ((float)Simulator.TRK.Tr_RouteFile.ConcreteSleepers == 1)
2041+ {
2042+ concretesleepers = true;
2043+ }
2044+
2045+ if (Simulator.Settings.VerboseConfigurationMessages && Simulator.TRK.Tr_RouteFile.TrackSoundDefaultContinuousPlay)
2046+ {
2047+ Trace.TraceInformation("======================================================================================================================");
2048+ Trace.TraceInformation("TType Track Sounds Initialisation - Concrete Sleepers = {0}, Track Joint Distance = {1} m", concretesleepers, (float)Simulator.TRK.Tr_RouteFile.DistanceBetweenTrackJointsM);
2049+ }
2050+
2051+ // the next track joint has been reached reset all parameters in preparation for the next pass
2052+ if (remainDistanceM < 0.0f)
2053+ {
2054+ cummulativeTrackJointDistanceM = Math.Abs(remainDistanceM);
2055+ remainDistanceM = trackjointdistanceM - cummulativeTrackJointDistanceM;
2056+ }
2057+
2058+ }
2059+ // Trackjoint less then Car length
2060+ else if (trackjointdistanceM < car.CarLengthM)
2061+ {
2062+ car.realTimeTrackJointDistanceM = cummulativeTrackJointDistanceM;
2063+ trainLengthM += car.CarLengthM;
2064+ cummulativeTrackJointDistanceM += trackjointdistanceM;
2065+ remainDistanceM -= car.CarLengthM;
2066+
2067+ if (remainDistanceM < 0.0f)
2068+ {
2069+
2070+ while (Math.Abs(remainDistanceM) > trackjointdistanceM)
2071+ {
2072+ remainDistanceM += trackjointdistanceM;
2073+ }
2074+
2075+ cummulativeTrackJointDistanceM = Math.Abs(remainDistanceM);
2076+ remainDistanceM = trackjointdistanceM - cummulativeTrackJointDistanceM;
2077+ }
2078+ }
2079+
2080+ if (Simulator.Settings.VerboseConfigurationMessages && Simulator.TRK.Tr_RouteFile.TrackSoundDefaultContinuousPlay)
2081+ {
2082+ Trace.TraceInformation("CarID {0}, Dist from Joint = {1} m, Car Length = {2} m, Train Length = {3} m, Axle Count = {4}", car.CarID, car.realTimeTrackJointDistanceM, car.CarLengthM, trainLengthM, car.SoundAxleCount);
2083+ }
2084+
2085+ }
2086+
2087+ Trace.TraceInformation("======================================================================================================================");
2088+
2089+ TrackJointSoundSetUpInitialise = false;
2090+ }
2091+
20122092 } // end Update
20132093
20142094 //================================================================================================//
0 commit comments