You're describing the system I presented. In detail. It has all the properties you envision. You even did the same priority calculation I do. I literally do the same: an arithmetic combinator with P=50 - C. Everything else is being done by the game engine with all the interrupts I described.waterBear wrote: Thu Sep 25, 2025 2:30 am Yeah, that's the dream. I think you can probably do it with a centralized system, but I am lazy and don't want to build (another) huge combinator brain. Good luck though!
As for the trip planning, I do everything I can to let the game mechanics do that for me. One of my tricks is to attach a single combinator to each stop that basically says "set priority to 50 minus C" where C is the number of trains on the way or at the stop. That automagically prevents the trains from all going to the nearest pickup and ignoring distant providers, for example. It also works for delivery stations. Sometimes you have multiple ore drop offs that all need to be evenly fed, and this trick solves that problem nicely - with one combinator.
It's one of the reasons I don't like a lot of my own solution ideas so far. I want to avoid a system that tells the trains where to go via signal, both because that's going to end up being a mess of combinators and also because then I have to do that work instead of the game engine.
The only thing we differ is "multiple ore drop offs that all need to be evenly fed". The general solution to this is not a circuit but instead overproviding ore. Produce more ore than is being consumed, so full trains will accumulate in the long run, so there will always be a full train available for any drop off station, so they're being filled by a waterfall of trains automatically.
Since your factory will always grow, never shrink, there can never be any "too big" ore supply, since you need to build more ore loading stations anyway.
If you must underprovide, you can use a circuit to disable any unloading station until its buffer chests are below a threshold. Using priority even for unloading stations instead of disabling or just relying on train limits as I do is a neat idea by @Harb42, I guess I will combine this with the buffer chest fill state on my own maps. This will help during initial ramp up. Thanks for that idea!
By calculating this way, you get unavoidable edge cases. It's not possible to reduce the amount of the global demand and react on it the same tick. There is a minimum delay of 1 tick. In the 0th tick a train reserves a station, so its from C=0 to C=1. This means, global demand is lowered by 1, because the train was just dispatched. However, you cannot react in the same tick, because if there is a circuit reacting to the value of C, its reaction is visible only in the next tick, so for one tick there is a wrong value for the global demand. Depending on how important that value is for whatever, this can be a problem. And it will hit in the long run. Not perhaps during development, but later if you run it for days with a larger amount of trains.waterBear wrote: Wed Sep 24, 2025 10:57 pm The basic idea for the most common implementation is this: A requesting stop globally broadcasts a needed number of train loads of an item. Provider stops then come online, and trains go straight to them.
There are lots of "gotchas" with the way trains and interrupts work that make this harder than it sounds in practice. It's do-able if you have one provider station for every item. By playing with the C signal from the stops, you can ensure that global demand gets reduced by 1 for every train on its way to either a provider stop for the item or to the requesting stop.
to help solve this problem, I'll take my work back offline.
This can happen for everything: If you use circuits, there is always a delay between a status change and the reaction to that status change. The delay is absolutely unavoidable, minimum 1 but usually 2 or more depending on intermediate combinators, however some built in game mechanics don't have this delay but react instantly such as reserving a station that just got empty. So some things just cannot be controlled and managed correctly all time with circuits.