Factorio

Factorio

Not enough ratings
Vanilla LTN Using Interrupts
By Stan Da Man
An easy guide on how to make a logistic train network in vanilla using interrupts and minimal circuitry.
2
   
Award
Favorite
Favorited
Unfavorite
Intro
When building train networks, I often spend a lot of time messing with train schedules, and they always end up being the same from play-through to play-through. A single pickup station, a corresponding drop-off station, and a refueling station or more recently, a refueling interrupt, are all it takes to make a fully functional train group. These requirements rarely change for the majority of trains in the average base, but every time I set up trains in a new save I have to do the same boring and basic setup for each train group and every type of item ever transported on the rail network.

When Generic Interrupts were announced in FFF-395, I saw it as a potential solution to the annoyance of manually setting up trains with basically the same schedule each time. There were comments on that post saying that this system could be used to imitate the logistic trains mod, and while I had personally never played with that mod, I wondered if the inclusion of similar capabilities could make setting up a train network interesting again.

But first, what would a train system using interrupts have to do?
Goals
  1. Only 1 group of trains per cargo type (Cargo Wagon/Fluid Wagon)
  2. Trains are universal: Any train can carry any cargo of its type
  3. Minimal use of circuits because I wanted to keep it simple
  4. Fast cargo delivery: The system should not operate significantly less efficiently than a normal train system not using interupts

All of these goals and more are accomplished by this system, given the requirements are met.
Requirements
  1. A large stacker with train stops to serve as the buffer station, preferably at or near the center of your base. Check the end of the guide for size reference.
  2. One (1) constant combinator. This is all the trains need to take requests at the buffer station.
  3. More trains than you think you will need.
The Buffer
The buffer station is where the magic happens, as it is here that the trains receive their instructions. The only thing they need is a wire going from the station they are parked at to the constant combinator. To make it less cluttered, I strung the wire along rows of stations to large power poles that led to the combinator. Only one wire type needs to be attached to the stations, but it should be the same wire connected to each station so that each train can see the contents of all the other trains and the combinator.



The only necessary boxes to check for the circuit connections are Read Train Contents and Send To Train.

The constant combinator only needs to contain a list of everything that you need to ship by rail in your factory, and will be read by the trains using interrupts in order to send them to the correct stations. The trains are smart enough to know when certain stations do not exist, so don't be afraid to set the combinator before you build your stations.



The negative values for some items will be explained in the Optional Things section.
This is not the only station that the trains need of course, however the next ones are even simpler to construct.
Stations
All pickup and drop-off stations use their corresponding item icons in the names so they can be accessed by trains using parameters.



The item icon can be anywhere in the name as long as it is consistent between stations and the same icon as the cargo that the trains are trying to pick up or drop off.



Train limits do not have to be set to 1, but any station with a train limit higher than that should expect that number of trains to arrive. Since trains are universal it is not recommended to leave the stations without limits as this will cause every available train to path to that station at once.

Priority can be changed as usual without messing up the scheduling.

Fluid Stations

Fluid Station are very similar to cargo stations in how they are named. The only difference is that there is no space between the item icon and the word "dropoff" in my example. This is because cargo and fluid trains use the same buffer station and the same circuit network to assign stations, and if the interrupts and station names didn't account for that, cargo trains would go to fluid pickup stations and fluid trains would go to cargo stations.

The Schedule
The all-important schedule is what took the longest of everything on this project and actually caused me significant problems as the biters evolved around me as I sat in my factory messing around with a single train on a circular track. At the end of that day it works very well and I am honestly quite proud of myself as I haven't seen this done as simply by anyone else. Here it is:


You could cut this down to only four interrupts if refueling can be accomplished in another way.



Go to Cargo Pickup sends the train from the buffer station to the desired pickup station after deciding which station that is using the combinator. This is where the wire connecting all of the stations comes in handy; it allows trains running this interrupt to see how much of each resource is already in the buffer and decide its destination accordingly.






Go to Dropoff and Wait for Dropoff make the Trains wait at the buffer until a dropoff station is available.




Buffer While Empty makes the empty trains wait at the buffer stations, checking every 30 seconds for a change in the circuits or an open pickup station so they can leave.




Fluid Trains Schedule

The schedule for fluid trains is nearly identical to the one for cargo trains except for the parameters being about fluids instead of cargo and the lack of a space in the station name.



Optional Things
Some changes can be optionally made to the system to make it more efficient or potentially require fewer total trains.

Increased Buffer Size

In the Buffer section this image shows most items with a value of one, but some with values of far below zero, such as iron ore. For very common and/or high volume materials that you need more of in the buffer, this is a way to change the minimum number of trains carrying that cargo that the buffer station asks for at all times. As seen in the Go to Pickup interrupt, the circuit parameter must be less than or equal to one. When a train carrying that resource is parked at the buffer station, that value will far exceed one and the condition will not pass. The very low negative values can bypass that by making a single train not enough to raise the circuit condition over one. Specifically, a value of -16,000 iron ore will request two additional iron ore trains for a minimum of three in the buffer, and a value of -16,000 iron plates will request one additional iron plates train for a minimum of two in the buffer. This is because a train carrying four wagons of iron ore or similar has 8,000 items, and a train carrying four wagons of iron plates or similar has 16,000 items. This can be adjusted to the stack size of any item or fluid easily by just looking at the locomotive of a train filled with that item or fluid.





Refueling

One of the best ways to refuel trains in Factorio 2.0 is with a refueling interrupt shared by all trains. In this system, the buffer station could also double as a refueling station, but that would have been more trouble than it was worth, so I included basic refueling in the design. The buffer station must be set as a second stop in the interrupt or else the trains will idle at the refueling station, not knowing where to go.





Just In Time

Stations can be set individually to request "just-in-time" pickup or dropoff of materials. This can be accomplished with a single decider combinator per station that sets the train limit to one only upon a condition being met of a certain number of items being present or not present at the station. These circuit conditions do not need to go anywhere other than to the station that they are referencing because the trains mainly decide where to go based on train limits. I never implemented this, but in theory it could cut down on the total number of trains needed as they would not spend so much time waiting at stations for full or empty cargo.



Beautifying the Buffer

I put lamps with colors corresponding to different RGB values next to each station in the buffer stack and matched them. When the setting on trains to match the color of the destination station is turned on, it creates a fun effect where a blue train will pull into a blue station and a blue lamp will turn on. It also makes it easier to tell at a glance what buffer stations are being used.

Blueprint Book
I have made a blueprint book including cargo and fluid trains and stations, as well as the buffer station with a combinator next to it. Remember, the buffer stations must all be connected to each other and a single combinator for the system to work. I recommend making your own tileable buffer station blueprint using the one provided as a template.

https://factoriobin.com/post/8q6h6p
Conclusion
I had a lot of fun with this project and with 2.0 over the course of about 2 weeks and I was pleasantly surprised at how well the system was able to function even in a decent sized rail base. I had 144 cargo trains alone all with the same schedule running the whole thing after all. I was playing on a rail world with water turned way up to cover some of the already scarce resource nodes. The idea was that I would use elevated rails and mainly avoid the biters, but resource scarcity and oil forced me into direct confrontation with large biters before even acquiring blue science. I suppose it may have been my insistence on using trains for nearly all logistics as soon as I had the system working, but I blame my starter iron patch for the low production.

Anyways, for the people who made it this far into the guide, I will leave you this awesome screenshot I took of my Grand Spaghetti Station built on the charred remains of my starter base. See if you can spot the spaceship wreck!

13 Comments
Stan Da Man  [author] Apr 24 @ 2:53pm 
If I understand correctly, the system you are describing is very similar to the "Just in time" section under Optional Things. In theory your version should solve an issue with the unmodified setup where having more than just a few pickup stations such as mines will flood the buffer station with trains carrying that type of resource. If the buffer is requesting a resource, it will send trains to all pickup stations with that resource available. if that number is very high, for example twenty iron ore mines, the buffer station will send out twenty empty trains to those stations, which will then return with twenty loads of iron ore.
T_BENZIN Apr 24 @ 11:25am 
Oh, and there's a flaw at the dropoff station: when condition for amount is met but train is still unloading at the station, then supply network is resieveing -1 demand value from that station. Could be fixed with more logic but I don't see it as a major issue as long as you don't overfill the station's buffer and the train keep waiting to be unloaded.
T_BENZIN Apr 24 @ 11:20am 
Dropoff Station Logic: The logic of the Dropoff Station and the Arithmetic Combinator is the same: you want to send -1 to the radar network with green cable to prevent multiple trains doing the same job. The condition of the decision combinator is different from that of the pickup: you connect the buffer chest to its input with red cable and the radar to the same input with green cable, the condition is: available ammount of station's resources is greater than or equal to treshold (again, 8 000 in my example) read only from red cable, and the same resource signal greater than zero but read only from green cable: that's our radar data for demand, finally the resource signal with value 1 outputs to the train station to activate it if both conditions are met.
If this text is not clear, feel free to add me to your friends list and I'll be happy to demonstrate it on the multiplayer this coming weekend.
T_BENZIN Apr 24 @ 11:19am 
Pickup Station Logic: In the station itself you have to uncheck the "Send to train" box and check "Enable/Disable" and "Read train count", the "Enable/Disable" condition is set to any station's resource signal greater than zero. With red network cable you link every single station's buffer chest with decider combinator's input. There's a single condition in the decider: the resource is less than the desired amount (8,000 for example), if true, it should output a signal with that resource with the specified value of 1. The decider combiner's output is connected to the train station with a red cable, to enable it when there are not enough resources in the chests, and to the radar with a green cable, to send a demand signal to the network. Finally, the station is connected to an arithmetic combiner which multiplies the train count signal by -1 and then sends the station's resource signal to the radar with the green network cable: to prevent multiple trains from supplying the same station
T_BENZIN Apr 24 @ 11:19am 
So I've decided to turn the pickup and dropoff stations on and off under certain conditions. The pickup station is turned on when there is a demand from one or more dropoff stations, and the pickup station's buffer chests have enough resources for a full haul (8,000 in my case). The dropoff station will of course be activated if the buffer chests are below the desired amount of resources (I also set it to 8,000). There is also the potential problem of every pickup station being activated when a single dropoff station signals for a supply, and free trains at depots all rushing to different pickup stations at the same time.
The setup itself is quite simple: each pickup and dropoff station needs a decider combiner, an arithmetic combiner and a radar to share data with other stations (alternatively, you can connect each station with network wires).
T_BENZIN Apr 24 @ 11:19am 
I was thinking more along the lines of dropoff stations requesting resources when they're low, and pickup stations providing resources when there's active demand (and the resources are present at the station).
I tried something, and here's what I came up with. Disclaimer: I recently re-picked up Factorio, and even before that I was nowhere near building megabases: never had the patience, I guess, lol. The solution may be terrible, but I've tested it on my brand new world, with a single iron ore line: so far so good.
Stan Da Man  [author] Apr 24 @ 6:45am 
Not that I have built anything like that lol. If you do that or if you find another solution for even distribution, please let me know with a comment on this guide; I would love to see it!
Stan Da Man  [author] Apr 24 @ 6:45am 
For example if you had ten iron ore dropoff stations in two groups of five: one group close to the buffer station and one group far away, the close group would get all of the iron ore as long as you aren't producing enough for all ten at your mining outposts. If you just set the priorities of the far away group stations higher, you would get the inverse problem where the far away stations would get all of the ore. A solution other than just building more iron outposts would be a circuit network that sets the priorities of the stations, subtracts one from the priority of a station when a train enters it, and occasionally adds one to every stations priority to make sure that they never reach zero and break. The result would be each station gets a single train in order of how far away from the buffer station they are from closest to farthest, and then the cycle resets and the closest station get a train.
Stan Da Man  [author] Apr 24 @ 6:45am 
A train will stay at pickup stations until it is full, at buffer stations until a dropoff station is empty, and at dropoff stations until it is empty. Supply and demand are managed by the buffer station because it always wants at least one train of every type of resource in the buffer. If you are asking if the trains spread resources between dropoff stations evenly or something similar the short answer is that they don't. But it is not impossible. In the Stations section of the guide i said that station priority can be changed like normal with out messing up the trains or system in any way. If you wanted to distribute resources evenly you could make a circuit network that sets the priority lower or higher depending on the amount of time since the last train left, how much material is in the station buffer, or something similar.
T_BENZIN Apr 24 @ 1:12am 
Thanks for the manual! Am I understanding correctly that this setup implies that trains are running between pickup and dropoff constantly, without getting any info on supply/demand of resources on stations?