@@ -296,6 +296,7 @@ public TimetablePool(BinaryReader inf, Simulator simulatorref)
296296 PoolDetails newPool = new PoolDetails ( ) ;
297297 newPool . StoragePath = new Train . TCSubpathRoute ( inf ) ;
298298 newPool . StoragePathTraveller = new Traveller ( simulatorref . TSectionDat , simulatorref . TDB . TrackDB . TrackNodes , inf ) ;
299+ newPool . StoragePathReverseTraveller = new Traveller ( simulatorref . TSectionDat , simulatorref . TDB . TrackDB . TrackNodes , inf ) ;
299300 newPool . StorageName = inf . ReadString ( ) ;
300301
301302 newPool . AccessPaths = new List < Train . TCSubpathRoute > ( ) ;
@@ -362,6 +363,7 @@ virtual public void Save(BinaryWriter outf)
362363 {
363364 thisStorage . StoragePath . Save ( outf ) ;
364365 thisStorage . StoragePathTraveller . Save ( outf ) ;
366+ thisStorage . StoragePathReverseTraveller . Save ( outf ) ;
365367 outf . Write ( thisStorage . StorageName ) ;
366368
367369 outf . Write ( thisStorage . AccessPaths . Count ) ;
@@ -525,10 +527,16 @@ public PoolDetails ExtractStorage(TimetableReader fileContents, Simulator simula
525527 {
526528 Train . TCRoutePath fullRoute = new Train . TCRoutePath ( newPath , - 2 , 1 , simulatorref . Signals , - 1 , simulatorref . Settings ) ;
527529
530+ // front traveller
528531 newPool . StoragePath = new Train . TCSubpathRoute ( fullRoute . TCRouteSubpaths [ 0 ] ) ;
529532 newPool . StoragePathTraveller = new Traveller ( simulatorref . TSectionDat , simulatorref . TDB . TrackDB . TrackNodes , newPath ) ;
530- Traveller dummy = new Traveller ( newPool . StoragePathTraveller ) ;
531- dummy . Move ( simulatorref . Signals . TrackCircuitList [ newPool . StoragePath [ 0 ] . TCSectionIndex ] . Length - newPool . StoragePathTraveller . TrackNodeOffset - 1.0f ) ;
533+
534+ // rear traveller (for moving tables)
535+ AIPathNode lastNode = newPath . Nodes . Last ( ) ;
536+ Traveller . TravellerDirection newDirection = newPool . StoragePathTraveller . Direction == Traveller . TravellerDirection . Forward ? Traveller . TravellerDirection . Backward : Traveller . TravellerDirection . Forward ;
537+ newPool . StoragePathReverseTraveller = new Traveller ( simulatorref . TSectionDat , simulatorref . TDB . TrackDB . TrackNodes ,
538+ lastNode . Location . TileX , lastNode . Location . TileZ , lastNode . Location . Location . X , lastNode . Location . Location . Z , newDirection ) ;
539+
532540 newPool . StorageName = String . Copy ( storagePathName ) ;
533541
534542 // if last element is end of track, remove it from path
@@ -1166,17 +1174,39 @@ public float CalculateStorageLength(PoolDetails reqStorage, TTTrain train)
11661174 float remLength = 0 ;
11671175
11681176 // same direction : use rear of train position
1169- if ( occSectionDirection == storageSectionDirection )
1177+ // for turntable pools, path is defined in opposite direction
1178+
1179+ if ( GetType ( ) == typeof ( TimetableTurntablePool ) )
11701180 {
1171- occSectionIndex = train . PresentPosition [ 1 ] . TCSectionIndex ;
1172- TrackCircuitSection occSection = train . signalRef . TrackCircuitList [ occSectionIndex ] ;
1173- remLength = occSection . Length - train . PresentPosition [ 1 ] . TCOffset ;
1181+ // use rear of train position
1182+ if ( occSectionDirection == storageSectionDirection )
1183+ {
1184+ occSectionIndex = train . PresentPosition [ 1 ] . TCSectionIndex ;
1185+ TrackCircuitSection occSection = train . signalRef . TrackCircuitList [ occSectionIndex ] ;
1186+ remLength = train . PresentPosition [ 1 ] . TCOffset ;
1187+ }
1188+ else
1189+ // use front of train position
1190+ {
1191+ TrackCircuitSection occSection = train . signalRef . TrackCircuitList [ occSectionIndex ] ;
1192+ remLength = occSection . Length - train . PresentPosition [ 0 ] . TCOffset ;
1193+ }
11741194 }
11751195 else
1176- // opposite direction : use front of train position
11771196 {
1178- TrackCircuitSection occSection = train . signalRef . TrackCircuitList [ occSectionIndex ] ;
1179- remLength = train . PresentPosition [ 0 ] . TCOffset ;
1197+ // use rear of train position
1198+ if ( occSectionDirection == storageSectionDirection )
1199+ {
1200+ occSectionIndex = train . PresentPosition [ 1 ] . TCSectionIndex ;
1201+ TrackCircuitSection occSection = train . signalRef . TrackCircuitList [ occSectionIndex ] ;
1202+ remLength = occSection . Length - train . PresentPosition [ 1 ] . TCOffset ;
1203+ }
1204+ else
1205+ // use front of train position
1206+ {
1207+ TrackCircuitSection occSection = train . signalRef . TrackCircuitList [ occSectionIndex ] ;
1208+ remLength = train . PresentPosition [ 0 ] . TCOffset ;
1209+ }
11801210 }
11811211
11821212 for ( int iSection = reqStorage . StoragePath . Count - 1 ; iSection >= 0 && reqStorage . StoragePath [ iSection ] . TCSectionIndex != occSectionIndex ; iSection -- )
0 commit comments