@@ -3094,6 +3094,7 @@ private void AddVibrations(float factor)
30943094 #endregion
30953095
30963096 public bool IsOverJunction { get ; private set ; }
3097+ public bool IsOverTrough { get ; private set ; }
30973098
30983099 void UpdatePositionFlags ( )
30993100 {
@@ -3107,6 +3108,7 @@ void UpdatePositionFlags()
31073108 var frontOffsetM = rearOffsetM + CarLengthM ;
31083109
31093110 var isOverJunction = false ;
3111+ var isOverTrough = false ;
31103112
31113113 // Scan through the track sections forwards from the REAR of the train (`Train.PresentPosition[1]`),
31123114 // stopping as soon as we've passed this car (`checkedM`) or run out of track (`currentPin.Link`)
@@ -3121,6 +3123,14 @@ void UpdatePositionFlags()
31213123 if ( checkedM <= frontOffsetM && rearOffsetM <= checkedM + section . Length )
31223124 {
31233125 if ( section . CircuitType == TrackCircuitSection . TrackCircuitType . Junction || section . CircuitType == TrackCircuitSection . TrackCircuitType . Crossover ) isOverJunction = true ;
3126+ if ( section . TroughInfo != null )
3127+ {
3128+ foreach ( var troughs in section . TroughInfo )
3129+ {
3130+ var trough = troughs [ currentPin . Direction ] ;
3131+ if ( checkedM + trough . TroughStart <= frontOffsetM && rearOffsetM <= checkedM + trough . TroughEnd ) isOverTrough = true ;
3132+ }
3133+ }
31243134 }
31253135 checkedM += section . Length ;
31263136
@@ -3130,91 +3140,14 @@ void UpdatePositionFlags()
31303140 }
31313141
31323142 IsOverJunction = isOverJunction ;
3143+ IsOverTrough = isOverTrough ;
31333144 }
31343145
31353146 // TODO These three fields should be in the TrainCarViewer.
31363147 public int TrackSoundType = 0 ;
31373148 public WorldLocation TrackSoundLocation = WorldLocation . None ;
31383149 public float TrackSoundDistSquared = 0 ;
31393150
3140-
3141- /// <summary>
3142- /// Checks if traincar is over trough. Used to check if refill possible
3143- /// </summary>
3144- /// <returns> returns true if car is over trough</returns>
3145-
3146- public bool IsOverTrough ( )
3147- {
3148- var isOverTrough = false ;
3149- // start at front of train
3150- int thisSectionIndex = Train . PresentPosition [ 0 ] . TCSectionIndex ;
3151- if ( thisSectionIndex < 0 ) return isOverTrough ;
3152- float thisSectionOffset = Train . PresentPosition [ 0 ] . TCOffset ;
3153- int thisSectionDirection = Train . PresentPosition [ 0 ] . TCDirection ;
3154-
3155-
3156- float usedCarLength = CarLengthM ;
3157- float processedCarLength = 0 ;
3158- bool validSections = true ;
3159-
3160- while ( validSections )
3161- {
3162- TrackCircuitSection thisSection = Train . signalRef . TrackCircuitList [ thisSectionIndex ] ;
3163- isOverTrough = false ;
3164-
3165- // car spans sections
3166- if ( ( CarLengthM - processedCarLength ) > thisSectionOffset )
3167- {
3168- usedCarLength = thisSectionOffset - processedCarLength ;
3169- }
3170-
3171- // section has troughs
3172- if ( thisSection . TroughInfo != null )
3173- {
3174- foreach ( TrackCircuitSection . troughInfoData [ ] thisTrough in thisSection . TroughInfo )
3175- {
3176- float troughStartOffset = thisTrough [ thisSectionDirection ] . TroughStart ;
3177- float troughEndOffset = thisTrough [ thisSectionDirection ] . TroughEnd ;
3178-
3179- if ( troughStartOffset > 0 && troughStartOffset > thisSectionOffset ) // start of trough is in section beyond present position - cannot be over this trough nor any following
3180- {
3181- return isOverTrough ;
3182- }
3183-
3184- if ( troughEndOffset > 0 && troughEndOffset < ( thisSectionOffset - usedCarLength ) ) // beyond end of trough, test next
3185- {
3186- continue ;
3187- }
3188-
3189- if ( troughStartOffset <= 0 || troughStartOffset < ( thisSectionOffset - usedCarLength ) ) // start of trough is behind
3190- {
3191- isOverTrough = true ;
3192- return isOverTrough ;
3193- }
3194- }
3195- }
3196- // tested this section, any need to go beyond?
3197-
3198- processedCarLength += usedCarLength ;
3199- {
3200- // go back one section
3201- int thisSectionRouteIndex = Train . ValidRoute [ 0 ] . GetRouteIndexBackward ( thisSectionIndex , Train . PresentPosition [ 0 ] . RouteListIndex ) ;
3202- if ( thisSectionRouteIndex >= 0 )
3203- {
3204- thisSectionIndex = thisSectionRouteIndex ;
3205- thisSection = Train . signalRef . TrackCircuitList [ thisSectionIndex ] ;
3206- thisSectionOffset = thisSection . Length ; // always at end of next section
3207- thisSectionDirection = Train . ValidRoute [ 0 ] [ thisSectionRouteIndex ] . Direction ;
3208- }
3209- else // ran out of train
3210- {
3211- validSections = false ;
3212- }
3213- }
3214- }
3215- return isOverTrough ;
3216- }
3217-
32183151 public static WorldLocation TileLocation ( UiD uid )
32193152 {
32203153 return new WorldLocation ( uid . TileX , uid . TileZ , uid . X , uid . Y , uid . Z ) ;
0 commit comments