Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect calculation of distance to train ahead #785

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/Orts.Simulation/Simulation/Signalling/Signals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3894,7 +3894,7 @@ public void BreakDownRouteList(Train.TCSubpathRoute reqRoute, int firstRouteInde
if (considerSpeedReset)
{
var speed_infoR = thisSpeedpost.this_sig_speed(SignalFunction.SPEED);
speed_info.speed_reset = speed_infoR.speed_reset;
if (speed_infoR != null) speed_info.speed_reset = speed_infoR.speed_reset;
}
if ((isFreight && speed_info.speed_freight > 0) || (!isFreight && speed_info.speed_pass > 0) || speed_info.speed_reset == 1)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1795,8 +1795,35 @@ public bool CheckReserved(Train.TrainRouted thisTrain)
}
else
{
distanceTrainAheadM = offset; // train is off its route - assume full section occupied, offset is deducted later //
trainFound = nextTrain.Train;
distanceTrainAheadM = offset; // train is off its route - check if track occupied by train is ahead or behind us //

if (thisTrain != null)
{
int presentFront = thisTrain.PresentPosition[0].RouteListIndex;

foreach (TrackCircuitSection occSection in nextTrain.Train.OccupiedTrack)
{
int otherSectionIndex = thisTrain.TCRoute.TCRouteSubpaths[thisTrain.TCRoute.activeSubpath].GetRouteIndex(occSection.Index, 0);

// other index is lower - train is behind us
if (otherSectionIndex >= 0 && otherSectionIndex < presentFront)
{
trainFound = null;
continue;
}
// other index is higher - train is in front of us
else if (otherSectionIndex >= 0 && otherSectionIndex > presentFront)
{
trainFound = nextTrain.Train;
continue;
}
}
}
else
{
// else assume ahead of us - assume full section occupied, offset is deducted later //
trainFound = nextTrain.Train;
}
}
}

Expand Down