@@ -2872,6 +2872,8 @@ public void ComputePosition(Traveller traveler, bool backToFront, float elapsedT
28722872 p . FindCenterLine ( ) ;
28732873 }
28742874 }
2875+
2876+ UpdatePositionFlags ( ) ;
28752877 }
28762878
28772879 #region Traveller-based updates
@@ -3091,6 +3093,38 @@ private void AddVibrations(float factor)
30913093 }
30923094 #endregion
30933095
3096+ void UpdatePositionFlags ( )
3097+ {
3098+ // Position flags can only change when we're moving!
3099+ if ( Train == null || AbsSpeedMpS < 0.01f ) return ;
3100+
3101+ // Calculate the position of the ends of this car relative to the REAR of the train
3102+ var rearOffsetM = Train . PresentPosition [ 1 ] . TCOffset ;
3103+ for ( var i = Train . Cars . IndexOf ( this ) + 1 ; i < Train . Cars . Count ; i ++ )
3104+ rearOffsetM += Train . Cars [ i - 1 ] . CouplerSlackM + Train . Cars [ i - 1 ] . GetCouplerZeroLengthM ( ) + Train . Cars [ i ] . CarLengthM ;
3105+ var frontOffsetM = rearOffsetM + CarLengthM ;
3106+
3107+ // Scan through the track sections forwards from the REAR of the train (`Train.PresentPosition[1]`),
3108+ // stopping as soon as we've passed this car (`checkedM`) or run out of track (`currentPin.Link`)
3109+ var checkedM = 0f ;
3110+ var lastPin = new TrPin { Link = - 1 , Direction = - 1 } ;
3111+ var currentPin = new TrPin { Link = Train . PresentPosition [ 1 ] . TCSectionIndex , Direction = Train . PresentPosition [ 1 ] . TCDirection } ;
3112+ while ( checkedM <= frontOffsetM && currentPin . Link != - 1 )
3113+ {
3114+ var section = Simulator . Signals . TrackCircuitList [ currentPin . Link ] ;
3115+
3116+ // Does this car overlap this track section?
3117+ if ( checkedM <= frontOffsetM && rearOffsetM <= checkedM + section . Length )
3118+ {
3119+ }
3120+ checkedM += section . Length ;
3121+
3122+ var nextPin = section . GetNextActiveLink ( currentPin . Direction , lastPin . Link ) ;
3123+ lastPin = currentPin ;
3124+ currentPin = nextPin ;
3125+ }
3126+ }
3127+
30943128 // TODO These three fields should be in the TrainCarViewer.
30953129 public int TrackSoundType = 0 ;
30963130 public WorldLocation TrackSoundLocation = WorldLocation . None ;
0 commit comments