Skip to content

Commit dca615c

Browse files
authored
Merge pull request #778 from Roeterdink/CorrectionPlayerOnTurntable
Correction for player locomotive on turntable
2 parents df0f361 + 779a819 commit dca615c

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
@@ -1858,16 +1858,15 @@ public bool UpdateTurntableStatePlayer(float elapsedClockSeconds)
18581858
// check if train position on turntable
18591859
if (!trainOnTable.FrontOnBoard)
18601860
{
1861-
if (WorldLocation.Within(parentTrain.FrontTDBTraveller.WorldLocation, parentTurntable.WorldPosition.WorldLocation, parentTurntable.Length / 2))
1861+
if (parentTurntable.CheckOnSection(parentTrain.FrontTDBTraveller))
18621862
{
18631863
trainOnTable.SetFrontState(true);
18641864
parentTrain.Simulator.Confirmer.Information("Front of train is on table");
1865-
18661865
}
18671866
}
18681867
else if (!trainOnTable.BackOnBoard)
18691868
{
1870-
if (WorldLocation.Within(parentTrain.RearTDBTraveller.WorldLocation, parentTurntable.WorldPosition.WorldLocation, parentTurntable.Length / 2))
1869+
if (parentTurntable.CheckOnSection(parentTrain.RearTDBTraveller))
18711870
{
18721871
trainOnTable.SetBackState(true);
18731872
parentTrain.Simulator.Confirmer.Information("Rear of train is on table");
@@ -1882,12 +1881,12 @@ public bool UpdateTurntableStatePlayer(float elapsedClockSeconds)
18821881
if (loco.ThrottlePercent < 1 && Math.Abs(loco.SpeedMpS) < 0.05 && (loco.Direction == Direction.N || Math.Abs(parentTrain.MUReverserPercent) <= 1))
18831882
{
18841883
// check if train still on turntable
1885-
if (!WorldLocation.Within(parentTrain.FrontTDBTraveller.WorldLocation, parentTurntable.WorldPosition.WorldLocation, parentTurntable.Length / 2))
1884+
if (!parentTurntable.CheckOnSection(parentTrain.FrontTDBTraveller))
18861885
{
18871886
trainOnTable.SetFrontState(false);
18881887
parentTrain.Simulator.Confirmer.Information("Front of train slipped off table");
18891888
}
1890-
if (!WorldLocation.Within(parentTrain.RearTDBTraveller.WorldLocation, parentTurntable.WorldPosition.WorldLocation, parentTurntable.Length / 2))
1889+
if (!parentTurntable.CheckOnSection(parentTrain.RearTDBTraveller))
18911890
{
18921891
trainOnTable.SetBackState(false);
18931892
parentTrain.Simulator.Confirmer.Information("Rear of train slipped off table");
@@ -1915,7 +1914,7 @@ public bool UpdateTurntableStatePlayer(float elapsedClockSeconds)
19151914
// check if train position on turntable
19161915
if (!trainOnTable.FrontOnBoard)
19171916
{
1918-
if (WorldLocation.Within(parentTrain.FrontTDBTraveller.WorldLocation, parentTurntable.WorldPosition.WorldLocation, parentTurntable.Length / 2))
1917+
if (parentTurntable.CheckOnSection(parentTrain.FrontTDBTraveller))
19191918
{
19201919
trainOnTable.SetFrontState(true);
19211920
parentTrain.Simulator.Confirmer.Information("Front of train is on table");
@@ -1924,7 +1923,7 @@ public bool UpdateTurntableStatePlayer(float elapsedClockSeconds)
19241923
}
19251924
else if (!trainOnTable.BackOnBoard)
19261925
{
1927-
if (WorldLocation.Within(parentTrain.RearTDBTraveller.WorldLocation, parentTurntable.WorldPosition.WorldLocation, parentTurntable.Length / 2))
1926+
if (parentTurntable.CheckOnSection(parentTrain.RearTDBTraveller))
19281927
{
19291928
trainOnTable.SetBackState(true);
19301929
parentTrain.Simulator.Confirmer.Information("Rear of train is on table");
@@ -1939,12 +1938,12 @@ public bool UpdateTurntableStatePlayer(float elapsedClockSeconds)
19391938
if (loco.ThrottlePercent < 1 && Math.Abs(loco.SpeedMpS) < 0.05 && (loco.Direction == Direction.N || Math.Abs(parentTrain.MUReverserPercent) <= 1))
19401939
{
19411940
// check if train still on turntable
1942-
if (!WorldLocation.Within(parentTrain.FrontTDBTraveller.WorldLocation, parentTurntable.WorldPosition.WorldLocation, parentTurntable.Length / 2))
1941+
if (!parentTurntable.CheckOnSection(parentTrain.FrontTDBTraveller))
19431942
{
19441943
trainOnTable.SetFrontState(false);
19451944
parentTrain.Simulator.Confirmer.Information("Front of train slipped off table");
19461945
}
1947-
if (!WorldLocation.Within(parentTrain.RearTDBTraveller.WorldLocation, parentTurntable.WorldPosition.WorldLocation, parentTurntable.Length / 2))
1946+
if (!parentTurntable.CheckOnSection(parentTrain.RearTDBTraveller))
19481947
{
19491948
trainOnTable.SetBackState(false);
19501949
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
@@ -868,7 +868,30 @@ public override bool CheckMovingTableAligned(Train train, bool forward)
868868
return false;
869869
}
870870

871-
871+
/// <summary>
872+
/// Check if train position is on turntable track section
873+
/// </summary>
874+
875+
public bool CheckOnSection(Traveller trainPosition)
876+
{
877+
bool onTable = false;
878+
int nodeIndex = -1;
879+
880+
for (int inode = 0; inode < MyTrackNodesIndex.Length && nodeIndex == -1; inode++)
881+
{
882+
if (MyTrackNodesIndex[inode] == trainPosition.TrackNodeIndex)
883+
{
884+
nodeIndex = inode;
885+
}
886+
}
887+
888+
if (nodeIndex >= 0)
889+
{
890+
onTable = (trainPosition.TrackVectorSectionIndex == MyTrVectorSectionsIndex[nodeIndex]);
891+
}
892+
893+
return (onTable);
894+
}
872895

873896
/// <summary>
874897
/// PerformUpdateActions: actions to be performed at every animation step

0 commit comments

Comments
 (0)