The code does not alway return the correct milepost. It appears that the list is ordered based on the order that the mileposts appear in the database, not in milepost order.
The list generated has an appropriate subset of the objects, just improperly ordered where list[0].ThisMile is not always the next milepost. This was observed in th NSF Scenic Route, but not the Zig Zag.
The unsorted list returned by the PlayerTrainMilepost with the Track Monitor showing the train within 1782 function was;
Imported from https://bugs.launchpad.net/bugs/1987435
In TrainControlSystem.cs
The code does not alway return the correct milepost. It appears that the list is ordered based on the order that the mileposts appear in the database, not in milepost order.
The list generated has an appropriate subset of the objects, just improperly ordered where list[0].ThisMile is not always the next milepost. This was observed in th NSF Scenic Route, but not the Zig Zag.
The unsorted list returned by the PlayerTrainMilepost with the Track Monitor showing the train within 1782 function was;
list[0].thisMile 1779 list[1].thisMile 1782 list[2].thisMile 1781 list[3].thisMile 1780
Existing code in the file;
Script.NextMilepost = (value) => { var list = Locomotive.Train.PlayerTrainMileposts[Locomotive.Train.MUDirection == Direction.Reverse ? 1 : 0]; if (list == null || value >= list.Count) return new MilepostInfo(float.MaxValue, -1); return new MilepostInfo(list[value].DistanceToTrainM, float.Parse(list[value].ThisMile)); };
Proposed adding an inplace sort to order by distance from train.
Script.NextMilepost = (value) => { var list = Locomotive.Train.PlayerTrainMileposts[Locomotive.Train.MUDirection == Direction.Reverse ? 1 : 0]; if (list == null || value >= list.Count) return new MilepostInfo(float.MaxValue, -1); list.Sort((a, b) => a.DistanceToTrainM.CompareTo(b.DistanceToTrainM)); return new MilepostInfo(list[value].DistanceToTrainM, float.Parse(list[value].ThisMile)); };