@@ -3094,6 +3094,7 @@ private void AddVibrations(float factor)
3094
3094
#endregion
3095
3095
3096
3096
public bool IsOverJunction { get ; private set ; }
3097
+ public bool IsOverTrough { get ; private set ; }
3097
3098
3098
3099
void UpdatePositionFlags ( )
3099
3100
{
@@ -3107,6 +3108,7 @@ void UpdatePositionFlags()
3107
3108
var frontOffsetM = rearOffsetM + CarLengthM ;
3108
3109
3109
3110
var isOverJunction = false ;
3111
+ var isOverTrough = false ;
3110
3112
3111
3113
// Scan through the track sections forwards from the REAR of the train (`Train.PresentPosition[1]`),
3112
3114
// stopping as soon as we've passed this car (`checkedM`) or run out of track (`currentPin.Link`)
@@ -3121,6 +3123,14 @@ void UpdatePositionFlags()
3121
3123
if ( checkedM <= frontOffsetM && rearOffsetM <= checkedM + section . Length )
3122
3124
{
3123
3125
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
+ }
3124
3134
}
3125
3135
checkedM += section . Length ;
3126
3136
@@ -3130,91 +3140,14 @@ void UpdatePositionFlags()
3130
3140
}
3131
3141
3132
3142
IsOverJunction = isOverJunction ;
3143
+ IsOverTrough = isOverTrough ;
3133
3144
}
3134
3145
3135
3146
// TODO These three fields should be in the TrainCarViewer.
3136
3147
public int TrackSoundType = 0 ;
3137
3148
public WorldLocation TrackSoundLocation = WorldLocation . None ;
3138
3149
public float TrackSoundDistSquared = 0 ;
3139
3150
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
-
3218
3151
public static WorldLocation TileLocation ( UiD uid )
3219
3152
{
3220
3153
return new WorldLocation ( uid . TileX , uid . TileZ , uid . X , uid . Y , uid . Z ) ;
0 commit comments