So I've been trying to design a multi-resource train loading/unloading stations for quite some time. After many design iterations, I've realized it's almost but not quite possible in the current game even including any published mods. I've tried to outline below the challenges and possible fixes/changes/enhancements to make such a contraption actually possible. Would love to see what folks think and/or how they've tackled this problem.
Goal: Create a train stop that can load an arbitrary number of different resources onto trains at full speed.
Here's a layout that almost works:
How it works:
- Multiple resources come in on the belt from the upper left, in this example Pipe & plastic bottles (Bob's mods)
- The resources are evenly distributed across 24 crates using belt splitters & the circuit network (for maximum loading speed)
- Combinators control stack filter inserters (or filter inserters) to load appropriate quantities of resources on the train
- The "Smart Trains" mod is used so that the combinators can tell what is already loaded onto the train and the constant combinator in the lower right sets the desired total quantities to be loaded
- The arithmetic combinator in the upper right outputs the contents of all storage chests, so that the upstream production facilities can know when to stop producing (e.g. to load the buffer chests with up to 1k of each resource)
- The buffer chests can become unbalanced due to uneven loading of the train. If the station is only stocked to, e.g., 1k of each resource, it's possible to have all 1k in the chests for car 2 while car 1 is completely devoid of resources and never loads
- Trains with filtered stacks cannot load properly. Suppose a train wants to pick up only pipes, so it's cargo stacks are all filtered to pipe. The circuit network can't know this, and stack filter inserters can only load one resource at a time. The circuit network may set them to plastic bottles and the train never fills
- Inserters can become deadlocked if they pick up a stack but the train fills up before the stack is placed. Bad cases can make it impossible to fill the train
- SmartTrains only exposes total contents of the train, but there's no way to determine which wagon needs which resources. Only one resource can be loaded at a time for the whole train even if all but one car is already full of that resource.
So first I'll assert that I think this is a reasonable problem that should be possible, though difficult, rather than the current situation where it's impossible. Hopefully we can agree on that. Also, I know inserter deadlock has been discussed ad naseum in many contexts, so I'll try not to rehash elements of that discussion and only discuss things I haven't seen before (but there are a few inserter-related things that matter).
- Knowing available space: I think it's necessary to know the available space in a cargo wagon for smart loading, rather than know its contents. This matters particularly for handling filtered stacks. The circuit network must know what can be loaded to properly program the stack filter inserters that load the wagons. It's not a panacea, though, because it's nearly impossible to avoid deadlock on resources with low stack sizes. For example, if there's one open stack, 12 stack inserters of Oil Barrels would more than fill the open slot, so some Stack inserters would become deadlocked. Available space must also be knowable on a per wagon basis rather than a per-train basis to similarly avoid deadlock
- Backing out deadlock: Even knowing available space, it's not possible to avoid deadlock at all times since the train can leave mid-insertion, or inserters can race with each other to fill only a small amount of remaining space.
- Rebalancing Chests: It's possible to have some buffer chests run dry while others are full. It is therefore necessary to have some kind of solution to rebalance the buffer chests until resources are redistributed.
In order to address the three problems above, I think this is the minimum set of game changes necessary to make a smart loading station possible:
- Connect Rails to Circuit Network: Rails should be connectable to the circuit network just like transport belts. They should sense the available space in any wagon stopped above them. They should output available space in filtered stacks, and also a special signal that indicates the number of completely open stacks
- Reversible Inserters: Reversible inserters would make it possible to both rebalance chests AND back out inserter deadlock when it inevitably happens. The suggested behavior is that Filter Inserters & Stack Filter Inserters forward load positive values on the circuit network (existing behavior), and reverse load negative values on the circuit network (new behavior). They'd have a special "Everything" signal that means "forward load (or reverse load)" any resource, e.g., a wildcard load/unload. This would make it possible to break deadlocks on the train-loading Stack Filter Inserters as they could be programmed to reverse load themselves after the train leaves the station. It would also make it possible to rebalance the chests since the filter inserters that pull off the belts can unload excessive quantities of resources back onto the input belts.