As far as I have seen from my own attempts at making self routing trains, there is one thing that is not exposed by the LUA API that in my opinion is needed for a mod to be capable of directing trains to where the are needed, and four other API interfaces that although they could be "hacked" around, would make the management of the automated scheduling system much more user "friendly". If by Rail signals, you meant just
'Rail signal's and not
'Train stop's then the majority of this post is invalid as I in my opinion
'Train stop's are much more intesting as all
'Rail signal's from my perspective is help prevent crashs while letting more than one train run on a line of track, while
'Train stop's are what the game actually uses in it's path finding. As far as I know from my own poking around at train automation, there is no way to get the state of a
Rail signal and although there is no way to tell how long a train has been at a
Train stop, you can use the existing API to tell if it is at a stop and then if you so desire force it to move on to the next station in it's route.
The biggest show stopper at this point is the fact that at the moment trains schedules use train station custom names, and there is no way to get this information at the moment, shot of placing down a locomotive and adding every stop to it's schedule manually. Once you are able to get a station's custom name even without the other interfaces a mod should in theory be able to fully direct trains, simply set a train's destination in it's schedule, and tell the train to run in automatic mode, when it get's to the destination load or unload it as needed.
If we got access to station custom names then we run into the first cosmetic thing, the fact that there is no pretty way to interact with custom entities. If you have access to custom station names, and you are able to rename them then you should have everything that is needed to be able to recreate the vanilla station GUI plus add in any GUI logic for automatic train routing. Although it is not presently possible to detect when a player tries interact with an entity, one could create a "crowbar", much like the one in the in the one railroad mod for another game that I will not mention, that when you hold the "crowbar" in hand and click on train stop would bring up the custom routing GUI. Although this is not as nice as an api hook that would let us know when a play tries to interact with an entity and then cancel the default GUI and display our own, or the ability to access the entity GUI from LUA it would still work.
We currently don't have a direct way to know if a train can't reach the next destination, although we can hack it by forcing a train to try to head to the next destination on it's schedule and if it does not start moving then we can assume that there is no path. A direct interface in the train schedule recors list that says if the path is valid or such would be useful.
At the moment the way to give a smart "logistics" train stop the ability know if has or needs something would be to give the train stop the ability to watch chests. Although I was initially thinking that it would be best if the stop was able to pull circuit states off the network, in most situations it would be better/faster to link chests to the train stop, most likely using the previously mentioned "crowbar".
Inventory slots on Cargo wagons are able to be set by the player but not read/set via the LUA API, if had the ability to modify these from LUA then we should be able to then pull a train up to a station that had multiple things in stock and only take the things that we needed. Again it is not something that is really needed, but is something that could improve usability.
The TL;DR version:
The current Show stopper:
Add Setter/getter for
Train stop custom names
Code: Select all
trainstop.getcustomname()
trainstop.setcustomname("New name")
API interfaces that would make Automated trains nicer for moders:
Either cancelable entity interaction or the ability to access the entity GUI.
Code: Select all
game.onevent(defines.events.ontick, function(event)
if event.interactedentity.name == "circuit-train-stop" then
-- TODO: Show custom GUI
-- Prevent the default GUI from showing
return false;
end
end);
A way to check if the current path for a train is viable
Enable checking if a circuit state is true on smart inserters.
Code: Select all
smartinserter.getcircuitstate(defines.circuitconnector.red)
Let Cargo Wagon filters be set/read via lua and not just the player.