Skip to content

Commit

Permalink
Merge pull request #792 from Roeterdink/CorrectRequiredActions
Browse files Browse the repository at this point in the history
Correct required actions
  • Loading branch information
cjakeman committed Feb 27, 2023
2 parents 902809c + f6c16fb commit 4757b00
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Source/Orts.Simulation/Simulation/AIs/AITrain.cs
Expand Up @@ -5100,6 +5100,32 @@ public virtual void SuspendTrain(Train incorporatingTrain)
// correct trigger for approach distance but not backward beyond present position
triggerDistanceM = Math.Max(PresentPosition[0].DistanceTravelledM, triggerDistanceM - (3.0f * signalApproachDistanceM));

// for signal stop item : check if action allready in list, if so, remove (can be result of restore action)
LinkedListNode<DistanceTravelledItem> thisItemLink = requiredActions.First;
bool itemFound = false;

while (thisItemLink != null && !itemFound)
{
DistanceTravelledItem thisDTItem = thisItemLink.Value;
if (thisDTItem is AIActionItem)
{
AIActionItem thisActionItem = thisDTItem as AIActionItem;
if (thisActionItem.ActiveItem != null && thisActionItem.NextAction == thisAction)
{
if (thisActionItem.ActiveItem.ObjectDetails.thisRef == thisItem.ObjectDetails.thisRef)
{
// equal item, so remove it
requiredActions.Remove(thisDTItem);
itemFound = true;
}
}
}
if (!itemFound)
{
thisItemLink = thisItemLink.Next;
}
}

// create and insert action

AIActionItem newAction = new AIActionItem(thisItem, thisAction);
Expand Down

0 comments on commit 4757b00

Please sign in to comment.