|
1 |
| -// COPYRIGHT 2014 by the Open Rails project. |
| 1 | +// COPYRIGHT 2014 by the Open Rails project. |
2 | 2 | //
|
3 | 3 | // This file is part of Open Rails.
|
4 | 4 | //
|
@@ -176,6 +176,7 @@ public struct PoolDetails
|
176 | 176 | {
|
177 | 177 | public Train.TCSubpathRoute StoragePath; // path defined as storage location
|
178 | 178 | public Traveller StoragePathTraveller; // traveller used to get path position and direction
|
| 179 | + public Traveller StoragePathReverseTraveller; // traveller used if path must be reversed |
179 | 180 | public string StorageName; // storage name
|
180 | 181 | public List<Train.TCSubpathRoute> AccessPaths; // access paths defined for storage location
|
181 | 182 | public float StorageLength; // available length
|
@@ -295,6 +296,7 @@ public TimetablePool(BinaryReader inf, Simulator simulatorref)
|
295 | 296 | PoolDetails newPool = new PoolDetails();
|
296 | 297 | newPool.StoragePath = new Train.TCSubpathRoute(inf);
|
297 | 298 | newPool.StoragePathTraveller = new Traveller(simulatorref.TSectionDat, simulatorref.TDB.TrackDB.TrackNodes, inf);
|
| 299 | + newPool.StoragePathReverseTraveller = new Traveller(simulatorref.TSectionDat, simulatorref.TDB.TrackDB.TrackNodes, inf); |
298 | 300 | newPool.StorageName = inf.ReadString();
|
299 | 301 |
|
300 | 302 | newPool.AccessPaths = new List<Train.TCSubpathRoute>();
|
@@ -361,6 +363,7 @@ virtual public void Save(BinaryWriter outf)
|
361 | 363 | {
|
362 | 364 | thisStorage.StoragePath.Save(outf);
|
363 | 365 | thisStorage.StoragePathTraveller.Save(outf);
|
| 366 | + thisStorage.StoragePathReverseTraveller.Save(outf); |
364 | 367 | outf.Write(thisStorage.StorageName);
|
365 | 368 |
|
366 | 369 | outf.Write(thisStorage.AccessPaths.Count);
|
@@ -524,10 +527,16 @@ public PoolDetails ExtractStorage(TimetableReader fileContents, Simulator simula
|
524 | 527 | {
|
525 | 528 | Train.TCRoutePath fullRoute = new Train.TCRoutePath(newPath, -2, 1, simulatorref.Signals, -1, simulatorref.Settings);
|
526 | 529 |
|
| 530 | + // front traveller |
527 | 531 | newPool.StoragePath = new Train.TCSubpathRoute(fullRoute.TCRouteSubpaths[0]);
|
528 | 532 | newPool.StoragePathTraveller = new Traveller(simulatorref.TSectionDat, simulatorref.TDB.TrackDB.TrackNodes, newPath);
|
529 |
| - Traveller dummy = new Traveller(newPool.StoragePathTraveller); |
530 |
| - 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 | + |
531 | 540 | newPool.StorageName = String.Copy(storagePathName);
|
532 | 541 |
|
533 | 542 | // if last element is end of track, remove it from path
|
@@ -1087,17 +1096,39 @@ public float CalculateStorageLength(PoolDetails reqStorage, TTTrain train)
|
1087 | 1096 | float remLength = 0;
|
1088 | 1097 |
|
1089 | 1098 | // same direction : use rear of train position
|
1090 |
| - if (occSectionDirection == storageSectionDirection) |
| 1099 | + // for turntable pools, path is defined in opposite direction |
| 1100 | + |
| 1101 | + if (GetType() == typeof(TimetableTurntablePool)) |
1091 | 1102 | {
|
1092 |
| - occSectionIndex = train.PresentPosition[1].TCSectionIndex; |
1093 |
| - TrackCircuitSection occSection = train.signalRef.TrackCircuitList[occSectionIndex]; |
1094 |
| - remLength = occSection.Length - train.PresentPosition[1].TCOffset; |
| 1103 | + // use rear of train position |
| 1104 | + if (occSectionDirection == storageSectionDirection) |
| 1105 | + { |
| 1106 | + occSectionIndex = train.PresentPosition[1].TCSectionIndex; |
| 1107 | + TrackCircuitSection occSection = train.signalRef.TrackCircuitList[occSectionIndex]; |
| 1108 | + remLength = train.PresentPosition[1].TCOffset; |
| 1109 | + } |
| 1110 | + else |
| 1111 | + // use front of train position |
| 1112 | + { |
| 1113 | + TrackCircuitSection occSection = train.signalRef.TrackCircuitList[occSectionIndex]; |
| 1114 | + remLength = occSection.Length - train.PresentPosition[0].TCOffset; |
| 1115 | + } |
1095 | 1116 | }
|
1096 | 1117 | else
|
1097 |
| - // opposite direction : use front of train position |
1098 | 1118 | {
|
1099 |
| - TrackCircuitSection occSection = train.signalRef.TrackCircuitList[occSectionIndex]; |
1100 |
| - remLength = train.PresentPosition[0].TCOffset; |
| 1119 | + // use rear of train position |
| 1120 | + if (occSectionDirection == storageSectionDirection) |
| 1121 | + { |
| 1122 | + occSectionIndex = train.PresentPosition[1].TCSectionIndex; |
| 1123 | + TrackCircuitSection occSection = train.signalRef.TrackCircuitList[occSectionIndex]; |
| 1124 | + remLength = occSection.Length - train.PresentPosition[1].TCOffset; |
| 1125 | + } |
| 1126 | + else |
| 1127 | + // use front of train position |
| 1128 | + { |
| 1129 | + TrackCircuitSection occSection = train.signalRef.TrackCircuitList[occSectionIndex]; |
| 1130 | + remLength = train.PresentPosition[0].TCOffset; |
| 1131 | + } |
1101 | 1132 | }
|
1102 | 1133 |
|
1103 | 1134 | for (int iSection = reqStorage.StoragePath.Count - 1; iSection >= 0 && reqStorage.StoragePath[iSection].TCSectionIndex != occSectionIndex; iSection--)
|
|
0 commit comments