Rseding91 wrote:Mods have no access to train path finding so even if they did know the lengths between stations and the train they can't tell a train to go to a specific one.
Additionally that data is not stored anywhere - it's calculated on the fly as a train tries to path somewhere.
That's exactly what I was thinking about. You think there is no use for such a function, but there is.
Of course the mod would not feed an array of stations with the same name to that function, but instead it would feed an array of stations with different names.
Here is an example:
LTN mod (and other train-control mods) at some point have to decide "Which station should I send this train to?".
So it could call "get_train_path_length(my_train, target_station1)" or "get_train_path_lengths(my_train, {array-of-stations})"
That would be great if first argument could also be a station not just a train.
and that function would return lua-array of station-distance pairs (or just one pair).
If there are several stations with the same name - return nearest or all of them.
As an example: an LTN netrwork have three coal provider-stations producing coal "Alpha-centauro" "Blue Square" and "Murble valley".
And train have to deliver coal to station "Cancer" and "Great Wall". Now train parked at "Depo".
So: we call
get_train_path_lengths(my_train, "Alpha-centauro") -> 1034
get_train_path_lengths(my_train, "Blue Square") -> 200
get_train_path_lengths(my_train, "Murble valley") -> 10743
get_train_path_lengths(my_train, "Cancer") -> 15000
get_train_path_lengths(my_train, "Great Wall") -> 1200
Now we can pick nearest stations to the train
"Blue Square" -> 200
"Great Wall" -> 1200
And form a schedule
"Depo" -> "Blue Square" -> "Great Wall" -> "Depo"
Of course this algorithm will not give the best path every time, but quite often - it will.
This function doesn't has to be (and really shouldn't be) stored anywhere.
This is just the same call you do in C++ when a player selects a name "Depo" and there are 10 "Depos" in the network.
So before the train actually starts to move you likely call some simmilar function to decide "To which one depo will it go to?"
So, please, just expose it with the same signature as it has inside C++.
-----------------
Of course that would be much more perfomance efficient if there would be "get_best_train_path({first-stop-candidates-array, second-stop-candidates-array, third-stop-candidates-array}) returning the path and distances: {{station=entity1,path_length=555},{station=entity2,path_length=333},{station=entity3,path_length=123}} " - but this is much more complicated function and it would need explicit implementation and that's not a simple request...