1- // COPYRIGHT 2009 - 2022 by the Open Rails project.
1+ // COPYRIGHT 2009 - 2022 by the Open Rails project.
22//
33// This file is part of Open Rails.
44//
@@ -3093,6 +3093,8 @@ private void AddVibrations(float factor)
30933093 }
30943094 #endregion
30953095
3096+ public bool IsOverJunction { get ; private set ; }
3097+
30963098 void UpdatePositionFlags ( )
30973099 {
30983100 // Position flags can only change when we're moving!
@@ -3104,6 +3106,8 @@ void UpdatePositionFlags()
31043106 rearOffsetM += Train . Cars [ i - 1 ] . CouplerSlackM + Train . Cars [ i - 1 ] . GetCouplerZeroLengthM ( ) + Train . Cars [ i ] . CarLengthM ;
31053107 var frontOffsetM = rearOffsetM + CarLengthM ;
31063108
3109+ var isOverJunction = false ;
3110+
31073111 // Scan through the track sections forwards from the REAR of the train (`Train.PresentPosition[1]`),
31083112 // stopping as soon as we've passed this car (`checkedM`) or run out of track (`currentPin.Link`)
31093113 var checkedM = 0f ;
@@ -3116,13 +3120,16 @@ void UpdatePositionFlags()
31163120 // Does this car overlap this track section?
31173121 if ( checkedM <= frontOffsetM && rearOffsetM <= checkedM + section . Length )
31183122 {
3123+ if ( section . CircuitType == TrackCircuitSection . TrackCircuitType . Junction || section . CircuitType == TrackCircuitSection . TrackCircuitType . Crossover ) isOverJunction = true ;
31193124 }
31203125 checkedM += section . Length ;
31213126
31223127 var nextPin = section . GetNextActiveLink ( currentPin . Direction , lastPin . Link ) ;
31233128 lastPin = currentPin ;
31243129 currentPin = nextPin ;
31253130 }
3131+
3132+ IsOverJunction = isOverJunction ;
31263133 }
31273134
31283135 // TODO These three fields should be in the TrainCarViewer.
@@ -3208,58 +3215,6 @@ public bool IsOverTrough()
32083215 return isOverTrough ;
32093216 }
32103217
3211- /// <summary>
3212- /// Checks if traincar is over junction or crossover. Used to check if water scoop breaks
3213- /// </summary>
3214- /// <returns> returns true if car is over junction</returns>
3215-
3216- public bool IsOverJunction ( )
3217- {
3218-
3219- // To Do - This identifies the start of the train, but needs to be further refined to work for each carriage.
3220- var isOverJunction = false ;
3221- // start at front of train
3222- int thisSectionIndex = Train . PresentPosition [ 0 ] . TCSectionIndex ;
3223- float thisSectionOffset = Train . PresentPosition [ 0 ] . TCOffset ;
3224- int thisSectionDirection = Train . PresentPosition [ 0 ] . TCDirection ;
3225-
3226-
3227- float usedCarLength = CarLengthM ;
3228-
3229- if ( Train . PresentPosition [ 0 ] . TCSectionIndex != Train . PresentPosition [ 1 ] . TCSectionIndex )
3230- {
3231- try
3232- {
3233- var copyOccupiedTrack = Train . OccupiedTrack . ToArray ( ) ;
3234- foreach ( var thisSection in copyOccupiedTrack )
3235- {
3236-
3237- // Trace.TraceInformation(" Track Section - Index {0} Ciruit Type {1}", thisSectionIndex, thisSection.CircuitType);
3238-
3239- if ( thisSection . CircuitType == TrackCircuitSection . TrackCircuitType . Junction || thisSection . CircuitType == TrackCircuitSection . TrackCircuitType . Crossover )
3240- {
3241-
3242- // train is on a switch; let's see if car is on a switch too
3243- WorldLocation switchLocation = TileLocation ( Simulator . TDB . TrackDB . TrackNodes [ thisSection . OriginalIndex ] . UiD ) ;
3244- var distanceFromSwitch = WorldLocation . GetDistanceSquared ( WorldPosition . WorldLocation , switchLocation ) ;
3245- if ( distanceFromSwitch < CarLengthM * CarLengthM + Math . Min ( SpeedMpS * 3 , 150 ) )
3246- {
3247- isOverJunction = true ;
3248- return isOverJunction ;
3249- }
3250- }
3251- }
3252- }
3253- catch
3254- {
3255-
3256- }
3257- }
3258-
3259- return isOverJunction ;
3260- }
3261-
3262-
32633218 public static WorldLocation TileLocation ( UiD uid )
32643219 {
32653220 return new WorldLocation ( uid . TileX , uid . TileZ , uid . X , uid . Y , uid . Z ) ;
0 commit comments