Skip to content

Commit

Permalink
Merge pull request #785 from Roeterdink/IncorrectCalculationTrainAhead
Browse files Browse the repository at this point in the history
Incorrect calculation of distance to train ahead
  • Loading branch information
cjakeman committed Feb 27, 2023
2 parents eb30a97 + fd121be commit 9ebd050
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Source/Orts.Simulation/Simulation/Signalling/Signals.cs
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
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

0 comments on commit 9ebd050

Please sign in to comment.