Skip to content

Commit 6d2bf04

Browse files
committed
Use reverse path in TT Pool
1 parent 3ffb9bc commit 6d2bf04

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

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

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// COPYRIGHT 2014 by the Open Rails project.
1+
// COPYRIGHT 2014 by the Open Rails project.
22
//
33
// This file is part of Open Rails.
44
//
@@ -176,6 +176,7 @@ public struct PoolDetails
176176
{
177177
public Train.TCSubpathRoute StoragePath; // path defined as storage location
178178
public Traveller StoragePathTraveller; // traveller used to get path position and direction
179+
public Traveller StoragePathReverseTraveller; // traveller used if path must be reversed
179180
public string StorageName; // storage name
180181
public List<Train.TCSubpathRoute> AccessPaths; // access paths defined for storage location
181182
public float StorageLength; // available length
@@ -295,6 +296,7 @@ public TimetablePool(BinaryReader inf, Simulator simulatorref)
295296
PoolDetails newPool = new PoolDetails();
296297
newPool.StoragePath = new Train.TCSubpathRoute(inf);
297298
newPool.StoragePathTraveller = new Traveller(simulatorref.TSectionDat, simulatorref.TDB.TrackDB.TrackNodes, inf);
299+
newPool.StoragePathReverseTraveller = new Traveller(simulatorref.TSectionDat, simulatorref.TDB.TrackDB.TrackNodes, inf);
298300
newPool.StorageName = inf.ReadString();
299301

300302
newPool.AccessPaths = new List<Train.TCSubpathRoute>();
@@ -361,6 +363,7 @@ virtual public void Save(BinaryWriter outf)
361363
{
362364
thisStorage.StoragePath.Save(outf);
363365
thisStorage.StoragePathTraveller.Save(outf);
366+
thisStorage.StoragePathReverseTraveller.Save(outf);
364367
outf.Write(thisStorage.StorageName);
365368

366369
outf.Write(thisStorage.AccessPaths.Count);
@@ -524,10 +527,16 @@ public PoolDetails ExtractStorage(TimetableReader fileContents, Simulator simula
524527
{
525528
Train.TCRoutePath fullRoute = new Train.TCRoutePath(newPath, -2, 1, simulatorref.Signals, -1, simulatorref.Settings);
526529

530+
// front traveller
527531
newPool.StoragePath = new Train.TCSubpathRoute(fullRoute.TCRouteSubpaths[0]);
528532
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+
531540
newPool.StorageName = String.Copy(storagePathName);
532541

533542
// if last element is end of track, remove it from path
@@ -1087,17 +1096,39 @@ public float CalculateStorageLength(PoolDetails reqStorage, TTTrain train)
10871096
float remLength = 0;
10881097

10891098
// 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))
10911102
{
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+
}
10951116
}
10961117
else
1097-
// opposite direction : use front of train position
10981118
{
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+
}
11011132
}
11021133

11031134
for (int iSection = reqStorage.StoragePath.Count - 1; iSection >= 0 && reqStorage.StoragePath[iSection].TCSectionIndex != occSectionIndex; iSection--)

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ public TimetableTurntablePool(BinaryReader inf, Simulator simulatorref)
435435
PoolDetails newPool = new PoolDetails();
436436
newPool.StoragePath = new Train.TCSubpathRoute(inf);
437437
newPool.StoragePathTraveller = new Traveller(Simulatorref.TSectionDat, Simulatorref.TDB.TrackDB.TrackNodes, inf);
438+
newPool.StoragePathReverseTraveller = new Traveller(Simulatorref.TSectionDat, Simulatorref.TDB.TrackDB.TrackNodes, inf);
438439
newPool.StorageName = inf.ReadString();
439440

440441
newPool.AccessPaths = null;
@@ -524,6 +525,7 @@ override public void Save(BinaryWriter outf)
524525
{
525526
thisStorage.StoragePath.Save(outf);
526527
thisStorage.StoragePathTraveller.Save(outf);
528+
thisStorage.StoragePathReverseTraveller.Save(outf);
527529
outf.Write(thisStorage.StorageName);
528530

529531
outf.Write(thisStorage.StoredUnits.Count);
@@ -724,6 +726,7 @@ private void CalculateStorageOffsets(int ipath, Turntable thisTurntable)
724726
exitSectionLength = CalculateVectorLength(0, lastVectorIndex - 2, lastVectorIndex, trackVectors);
725727
thisPath.StoragePath[0].Direction = 1;
726728
thisPath.StoragePathTraveller.Direction = Traveller.TravellerDirection.Forward;
729+
thisPath.StoragePathReverseTraveller.Direction = Traveller.TravellerDirection.Backward;
727730
}
728731
else
729732
{
@@ -734,6 +737,7 @@ private void CalculateStorageOffsets(int ipath, Turntable thisTurntable)
734737
exitSectionLength = CalculateVectorLength(lastVectorIndex + 2, trackVectors.Length - 1, lastVectorIndex, trackVectors);
735738
thisPath.StoragePath[0].Direction = 0;
736739
thisPath.StoragePathTraveller.Direction = Traveller.TravellerDirection.Backward;
740+
thisPath.StoragePathReverseTraveller.Direction = Traveller.TravellerDirection.Forward;
737741
}
738742

739743
float totalLength = baseLength + entrySectionLength;
@@ -2586,4 +2590,4 @@ public bool TestTrainFormation (TTTrain parentTrain)
25862590
return (reqReverse);
25872591
}
25882592
}
2589-
}
2593+
}

0 commit comments

Comments
 (0)