Skip to content

Commit 237bf68

Browse files
authored
Merge pull request #794 from Roeterdink/ReversePathTTPool
Use reverse path in TT Pool
2 parents e810f47 + 6d2bf04 commit 237bf68

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

Source/Orts.Simulation/Simulation/Timetables/TTPool.cs

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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--)

Source/Orts.Simulation/Simulation/Timetables/TTTurntable.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ public TimetableTurntablePool(BinaryReader inf, Simulator simulatorref)
441441
PoolDetails newPool = new PoolDetails();
442442
newPool.StoragePath = new Train.TCSubpathRoute(inf);
443443
newPool.StoragePathTraveller = new Traveller(Simulatorref.TSectionDat, Simulatorref.TDB.TrackDB.TrackNodes, inf);
444+
newPool.StoragePathReverseTraveller = new Traveller(Simulatorref.TSectionDat, Simulatorref.TDB.TrackDB.TrackNodes, inf);
444445
newPool.StorageName = inf.ReadString();
445446

446447
newPool.AccessPaths = null;
@@ -530,6 +531,7 @@ override public void Save(BinaryWriter outf)
530531
{
531532
thisStorage.StoragePath.Save(outf);
532533
thisStorage.StoragePathTraveller.Save(outf);
534+
thisStorage.StoragePathReverseTraveller.Save(outf);
533535
outf.Write(thisStorage.StorageName);
534536

535537
outf.Write(thisStorage.StoredUnits.Count);
@@ -720,6 +722,7 @@ private void CalculateStorageOffsets(int ipath, Turntable thisTurntable)
720722
exitSectionLength = CalculateVectorLength(0, lastVectorIndex - 2, lastVectorIndex, trackVectors);
721723
thisPath.StoragePath[0].Direction = 1;
722724
thisPath.StoragePathTraveller.Direction = Traveller.TravellerDirection.Forward;
725+
thisPath.StoragePathReverseTraveller.Direction = Traveller.TravellerDirection.Backward;
723726
}
724727
else
725728
{
@@ -730,6 +733,7 @@ private void CalculateStorageOffsets(int ipath, Turntable thisTurntable)
730733
exitSectionLength = CalculateVectorLength(lastVectorIndex + 2, trackVectors.Length - 1, lastVectorIndex, trackVectors);
731734
thisPath.StoragePath[0].Direction = 0;
732735
thisPath.StoragePathTraveller.Direction = Traveller.TravellerDirection.Backward;
736+
thisPath.StoragePathReverseTraveller.Direction = Traveller.TravellerDirection.Forward;
733737
}
734738

735739
float totalLength = baseLength + entrySectionLength;

0 commit comments

Comments
 (0)