if (forsight >= list.Count) SearchTrainInfo(forsight, type); // <CSComment> Doesn't : list.Count - 1 lead to wrong returns if forsight > 0? </CSComment> return list[forsight < list.Count ? forsight : list.Count - 1];
The SearchTrainInfo() function extends the list to the requested "forsight". That last line is just a protection, if a too big "forsight" number was asked for, it still returns some value. I didn't want to give back a null value, since the script writer is not expected to always do null-checks on interface functions, it would be a valid expectation from him, that these functions always return something. You may be right, that it was not the best choice to just repeat the last signal (most probably a STOP) to any bigger numbers, there could have been a dummy signal object defined with aspect none, speed limit float.max, etc., and return that one. Yes, this might be a valid change.
In my code I am about to change the TrainInfo object to something like
Train.TrainInfo TrainInfo { get { if (!TrainInfoUpdatedFlag) _trainInfo = Locomotive.Train.GetTrainInfo(); TrainInfoUpdatedFlag = true; return _trainInfo; } } Train.TrainInfo _trainInfo = new Train.TrainInfo(); bool TrainInfoUpdatedFlag;
where the TrainInfoUpdatedFlag = false can be set in the ClearParams() function, so this way the TrainInfo is updated only once per Update() call, but for sure gets updated at the first use.
I am also about to add the collecting of the generic signals and the trailing switches to the TrainInfo. If we want long-term maintainability, or make our successor developers to understand what we've done, that is the correct solution I think. It also makes the code more clear, since the current functions are mainly just copies from the TrainInfo with slightly modified functionality. (Anyway, they are well coded functions, imho.) TrainInfo is there mainly for feeding the MSTS-style track monitor, and e.g. the ETCS track monitor is just a more advanced track monitor. So these additions naturally belong there. In long term the OR track monitor probably should also be updated to have the missing functions that other TCS system track monitors have.