Skip to content

Commit 779a819

Browse files
committed
Correction for player locomotive on turntable
1 parent 3ffb9bc commit 779a819

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,16 +1847,15 @@ public bool UpdateTurntableStatePlayer(float elapsedClockSeconds)
18471847
// check if train position on turntable
18481848
if (!trainOnTable.FrontOnBoard)
18491849
{
1850-
if (WorldLocation.Within(parentTrain.FrontTDBTraveller.WorldLocation, parentTurntable.WorldPosition.WorldLocation, parentTurntable.Length / 2))
1850+
if (parentTurntable.CheckOnSection(parentTrain.FrontTDBTraveller))
18511851
{
18521852
trainOnTable.SetFrontState(true);
18531853
parentTrain.Simulator.Confirmer.Information("Front of train is on table");
1854-
18551854
}
18561855
}
18571856
else if (!trainOnTable.BackOnBoard)
18581857
{
1859-
if (WorldLocation.Within(parentTrain.RearTDBTraveller.WorldLocation, parentTurntable.WorldPosition.WorldLocation, parentTurntable.Length / 2))
1858+
if (parentTurntable.CheckOnSection(parentTrain.RearTDBTraveller))
18601859
{
18611860
trainOnTable.SetBackState(true);
18621861
parentTrain.Simulator.Confirmer.Information("Rear of train is on table");
@@ -1871,12 +1870,12 @@ public bool UpdateTurntableStatePlayer(float elapsedClockSeconds)
18711870
if (loco.ThrottlePercent < 1 && Math.Abs(loco.SpeedMpS) < 0.05 && (loco.Direction == Direction.N || Math.Abs(parentTrain.MUReverserPercent) <= 1))
18721871
{
18731872
// check if train still on turntable
1874-
if (!WorldLocation.Within(parentTrain.FrontTDBTraveller.WorldLocation, parentTurntable.WorldPosition.WorldLocation, parentTurntable.Length / 2))
1873+
if (!parentTurntable.CheckOnSection(parentTrain.FrontTDBTraveller))
18751874
{
18761875
trainOnTable.SetFrontState(false);
18771876
parentTrain.Simulator.Confirmer.Information("Front of train slipped off table");
18781877
}
1879-
if (!WorldLocation.Within(parentTrain.RearTDBTraveller.WorldLocation, parentTurntable.WorldPosition.WorldLocation, parentTurntable.Length / 2))
1878+
if (!parentTurntable.CheckOnSection(parentTrain.RearTDBTraveller))
18801879
{
18811880
trainOnTable.SetBackState(false);
18821881
parentTrain.Simulator.Confirmer.Information("Rear of train slipped off table");
@@ -1904,7 +1903,7 @@ public bool UpdateTurntableStatePlayer(float elapsedClockSeconds)
19041903
// check if train position on turntable
19051904
if (!trainOnTable.FrontOnBoard)
19061905
{
1907-
if (WorldLocation.Within(parentTrain.FrontTDBTraveller.WorldLocation, parentTurntable.WorldPosition.WorldLocation, parentTurntable.Length / 2))
1906+
if (parentTurntable.CheckOnSection(parentTrain.FrontTDBTraveller))
19081907
{
19091908
trainOnTable.SetFrontState(true);
19101909
parentTrain.Simulator.Confirmer.Information("Front of train is on table");
@@ -1913,7 +1912,7 @@ public bool UpdateTurntableStatePlayer(float elapsedClockSeconds)
19131912
}
19141913
else if (!trainOnTable.BackOnBoard)
19151914
{
1916-
if (WorldLocation.Within(parentTrain.RearTDBTraveller.WorldLocation, parentTurntable.WorldPosition.WorldLocation, parentTurntable.Length / 2))
1915+
if (parentTurntable.CheckOnSection(parentTrain.RearTDBTraveller))
19171916
{
19181917
trainOnTable.SetBackState(true);
19191918
parentTrain.Simulator.Confirmer.Information("Rear of train is on table");
@@ -1928,12 +1927,12 @@ public bool UpdateTurntableStatePlayer(float elapsedClockSeconds)
19281927
if (loco.ThrottlePercent < 1 && Math.Abs(loco.SpeedMpS) < 0.05 && (loco.Direction == Direction.N || Math.Abs(parentTrain.MUReverserPercent) <= 1))
19291928
{
19301929
// check if train still on turntable
1931-
if (!WorldLocation.Within(parentTrain.FrontTDBTraveller.WorldLocation, parentTurntable.WorldPosition.WorldLocation, parentTurntable.Length / 2))
1930+
if (!parentTurntable.CheckOnSection(parentTrain.FrontTDBTraveller))
19321931
{
19331932
trainOnTable.SetFrontState(false);
19341933
parentTrain.Simulator.Confirmer.Information("Front of train slipped off table");
19351934
}
1936-
if (!WorldLocation.Within(parentTrain.RearTDBTraveller.WorldLocation, parentTurntable.WorldPosition.WorldLocation, parentTurntable.Length / 2))
1935+
if (!parentTurntable.CheckOnSection(parentTrain.RearTDBTraveller))
19371936
{
19381937
trainOnTable.SetBackState(false);
19391938
parentTrain.Simulator.Confirmer.Information("Rear of train slipped off table");

Source/Orts.Simulation/Simulation/Turntables.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,30 @@ public override bool CheckMovingTableAligned(Train train, bool forward)
854854
return false;
855855
}
856856

857-
857+
/// <summary>
858+
/// Check if train position is on turntable track section
859+
/// </summary>
860+
861+
public bool CheckOnSection(Traveller trainPosition)
862+
{
863+
bool onTable = false;
864+
int nodeIndex = -1;
865+
866+
for (int inode = 0; inode < MyTrackNodesIndex.Length && nodeIndex == -1; inode++)
867+
{
868+
if (MyTrackNodesIndex[inode] == trainPosition.TrackNodeIndex)
869+
{
870+
nodeIndex = inode;
871+
}
872+
}
873+
874+
if (nodeIndex >= 0)
875+
{
876+
onTable = (trainPosition.TrackVectorSectionIndex == MyTrVectorSectionsIndex[nodeIndex]);
877+
}
878+
879+
return (onTable);
880+
}
858881

859882
/// <summary>
860883
/// PerformUpdateActions: actions to be performed at every animation step

0 commit comments

Comments
 (0)