Skip to content

Commit 4757b00

Browse files
authored
Merge pull request #792 from Roeterdink/CorrectRequiredActions
Correct required actions
2 parents 902809c + f6c16fb commit 4757b00

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Source/Orts.Simulation/Simulation/AIs/AITrain.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5100,6 +5100,32 @@ public void CreateTrainAction(float presentSpeedMpS, float reqSpeedMpS, float di
51005100
// correct trigger for approach distance but not backward beyond present position
51015101
triggerDistanceM = Math.Max(PresentPosition[0].DistanceTravelledM, triggerDistanceM - (3.0f * signalApproachDistanceM));
51025102

5103+
// for signal stop item : check if action allready in list, if so, remove (can be result of restore action)
5104+
LinkedListNode<DistanceTravelledItem> thisItemLink = requiredActions.First;
5105+
bool itemFound = false;
5106+
5107+
while (thisItemLink != null && !itemFound)
5108+
{
5109+
DistanceTravelledItem thisDTItem = thisItemLink.Value;
5110+
if (thisDTItem is AIActionItem)
5111+
{
5112+
AIActionItem thisActionItem = thisDTItem as AIActionItem;
5113+
if (thisActionItem.ActiveItem != null && thisActionItem.NextAction == thisAction)
5114+
{
5115+
if (thisActionItem.ActiveItem.ObjectDetails.thisRef == thisItem.ObjectDetails.thisRef)
5116+
{
5117+
// equal item, so remove it
5118+
requiredActions.Remove(thisDTItem);
5119+
itemFound = true;
5120+
}
5121+
}
5122+
}
5123+
if (!itemFound)
5124+
{
5125+
thisItemLink = thisItemLink.Next;
5126+
}
5127+
}
5128+
51035129
// create and insert action
51045130

51055131
AIActionItem newAction = new AIActionItem(thisItem, thisAction);

0 commit comments

Comments
 (0)