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

Correct required actions #792

Merged
merged 1 commit into from Feb 27, 2023
Merged
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
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