@@ -260,26 +260,38 @@ private void CheckEvents(int ElementIndex, int Direction, double OldDelta, doubl
260
260
{
261
261
return ;
262
262
}
263
+
264
+ int Index = TrackIndex ;
263
265
if ( Direction < 0 )
264
266
{
265
- for ( int j = Tracks [ TrackIndex ] . Elements [ ElementIndex ] . Events . Length - 1 ; j >= 0 ; j -- )
267
+ for ( int j = Tracks [ Index ] . Elements [ ElementIndex ] . Events . Length - 1 ; j >= 0 ; j -- )
266
268
{
267
- if ( OldDelta > Tracks [ TrackIndex ] . Elements [ ElementIndex ] . Events [ j ] . TrackPositionDelta & NewDelta <= Tracks [ TrackIndex ] . Elements [ ElementIndex ] . Events [ j ] . TrackPositionDelta )
269
+ if ( Tracks [ Index ] . Elements [ ElementIndex ] . Events . Length == 0 )
270
+ {
271
+ return ;
272
+ }
273
+ if ( OldDelta > Tracks [ Index ] . Elements [ ElementIndex ] . Events [ j ] . TrackPositionDelta & NewDelta <= Tracks [ Index ] . Elements [ ElementIndex ] . Events [ j ] . TrackPositionDelta )
268
274
{
269
- Tracks [ TrackIndex ] . Elements [ ElementIndex ] . Events [ j ] . TryTrigger ( - 1 , this . TriggerType , this . Train , this . CarIndex ) ;
275
+ Tracks [ Index ] . Elements [ ElementIndex ] . Events [ j ] . TryTrigger ( - 1 , this . TriggerType , this . Train , this . CarIndex ) ;
270
276
}
271
277
}
272
278
}
273
279
else if ( Direction > 0 )
274
280
{
275
- for ( int j = 0 ; j < Tracks [ TrackIndex ] . Elements [ ElementIndex ] . Events . Length ; j ++ )
281
+ for ( int j = 0 ; j < Tracks [ Index ] . Elements [ ElementIndex ] . Events . Length ; j ++ )
276
282
{
277
- if ( OldDelta < Tracks [ TrackIndex ] . Elements [ ElementIndex ] . Events [ j ] . TrackPositionDelta & NewDelta >= Tracks [ TrackIndex ] . Elements [ ElementIndex ] . Events [ j ] . TrackPositionDelta )
283
+ if ( OldDelta < Tracks [ Index ] . Elements [ ElementIndex ] . Events [ j ] . TrackPositionDelta & NewDelta >= Tracks [ Index ] . Elements [ ElementIndex ] . Events [ j ] . TrackPositionDelta )
278
284
{
279
- Tracks [ TrackIndex ] . Elements [ ElementIndex ] . Events [ j ] . TryTrigger ( 1 , this . TriggerType , this . Train , this . CarIndex ) ;
285
+ Tracks [ Index ] . Elements [ ElementIndex ] . Events [ j ] . TryTrigger ( 1 , this . TriggerType , this . Train , this . CarIndex ) ;
280
286
}
281
287
}
282
288
}
289
+
290
+ if ( Index != TrackIndex )
291
+ {
292
+ //We have swapped tracks, so need to check the events on the new track also
293
+ CheckEvents ( ElementIndex , Direction , OldDelta , NewDelta ) ;
294
+ }
283
295
}
284
296
}
285
297
}
0 commit comments