Friday Facts #395 - Generic interrupts and Train stop priority

Posted by Klonan on 2024-01-26

Hello,
Another trains FFF!


Generic interrupt

We first showcased the new Schedule interrupts in FFF-389. They allow you to control your trains using conditions and target destinations.

We have played with schedule interrupts extensively, and they work very well for controlling larger numbers of trains and train systems. One small problem/annoyance/crime is that you need to add an interrupt for each type of item manually. So if you want the train to handle Iron gear wheel, you need to create a new interrupt specifying "If you have Iron gear wheel, go to Iron gear wheel dropoff".


Lots of interrupts...

It gets a bit boring and tedious adding new interrupts, and in our mind the goal is clear, "If you have Item X, go to X dropoff".

So that is exactly what we did using a new special wildcard signal called 'Any item'.


A 'Generic interrupt' using the any item signal.

When a train is evaluating an interrupt which uses the 'Any item' signal, it will check the interrupt conditions against each item in the cargo, and the first one that passes will be the 'passing item' for the interrupt. The passing item will replace the 'Any item' in the interrupt target name and target wait conditions.

We also have similar signals for 'Any Fluid', 'Any Fuel' and 'Any Signal'. Using these signals, the interrupt is more generalised and hands-off, as long as you ensure you have your train stops named consistently.

But what if I don't have a "Personal Battery equipment MK2 dropoff"?

So one important thing to make this work, is that the game has to be fail-safe for stops that don't exist. In 1.1, if a train stop doesn't exist (or is disabled), the stop is completely skipped/ignored in the schedule. This can create a big problem, a train can just decide to go again to item pickup while already full.

So in 2.0, we have changed it so that trains will 'No path' for stops that don't exist.


A train with a 'Stop that doesn't exist' goes to 'No path' state.

This means the train will never do something unexpected, and it will be the players configuration error causing the train to wait around for better orders.

Does it still skip if I disable a stop with circuit network?

This leads us onto another change in 2.0, disabling stops will no longer cause trains to skip the stations and repath. We have had the skipping behavior in the game for a long time, but effectively using it has always been a bit janky. Since we added trains limits in 1.1, the usage has been very limited, and can cause a lot of problems if you approach the feature naively.

For example, if you disable a stop while a train is en-route, the train may very well be in a position where it can't path anywhere else (e.g. just turning the corner to arrive). This would cause the train to 'no path' while sticking out onto the mainline, causing chaos for the rest of the trains.

So in 2.0, disabled trains stops will act as if they have 'Train limit = 0':

  • If a train is on the way and the stop is disabled, it will continue to the stop regardless.
  • If a train is told to go to a disabled stop, it will enter the 'Destination full' state and wait until it is enabled.

This change will prevent the damage that disabling stops causes, and means you can have a slightly easier time controlling stops with circuit network. For example, with an artillery outpost, just wire up a chest to read how much ammo is left, and only enable the stop if ammo is empty. This way you don't need to include any combinators to translate the lack of ammo into a Train limit.


Alert for 'No path'

More trains means more chance of something unexpected happening. In Space age, where the players' attention is split between multiple planets, is is especially important that the player is made aware of problems in the train system. So it only made sense to add an alert for trains with 'no path'.

With the new 'Generic interrupt', it means if the train picks up an item for which you have no associated train stop, you will be notified about it, and can decide how to solve it.


Easier train dispatching

Another annoyance which becomes more clear with larger train systems, is the pain of creating and dispatching new trains. With the ability to blueprint trains, it is almost painless, but you still need to manually set them to automatic mode.

No Longer! Now when a train blueprint is fully built (importantly, including fuel requests), it will switch to automatic mode.

This is the last piece of the puzzle, and now if you need to add another 5, 10, 20, 50 trains to your network, it is just a matter of stamping down the train blueprint as many times as needed; No further manual intervention necessary.

Additionally, there were quite a few inconsistencies with blueprinting trains, bugs and unexpected behaviors, which made it a little bit unreliable if the schedule in the blueprint would actually 'stick' to the new train, and if all the wagons would connect correctly. So we've fixed all the cases we could find for 2.0.


Train stop priority

Trains generally prefer stations closer to them. With static routes and limits, the system worked okay. When you have individual train routes for each item, they always have some consistent level of service for that item. If you have 10 iron mines and 3 iron trains, then you know you will always have some trains working that route.

However with generic schedules and 'One big bag of trains', it can happen that all the trains are busy moving around advanced products and nothing is there to direct trains to the mining outposts, especially as the mining outposts are normally far away on the periphery of the base.

Another motivation here was the situation of decommissioning old stations. We want the trains already at the stop to "Get out of here", but often times they would just sit and go "Well my destination is full". So another goal was "When I tell a train to go somewhere manually, I want it to have priority".

So we added the feature of Train stop priority:

The way it works, is that the priority of a train stop has two effects:

  1. When searching for a destination, trains will prefer a higher priority train stop.
  2. When trains are trying to leave a stop, trains at stops with higher priority are dispatched first.

Train stops have a default priority of 50, and players can adjust it to any number they want from 0 to 255. The slider in the train stop suggests values from 10 to 90, but you can be more precise with the textfield. We also added the ability to set the priority using the circuit network.

Additionally, there are some special cases where trains are given the absolute max priority of 255:

  • When the player manually tells the train to go somewhere.
  • When a train has 'no path' or 'destination full' in the middle of the tracks (i.e. not waiting at a train stop).


Icons for Train status

Factorio veterans will know well the flying text popup of 'No Path' and 'Destination full'. Valuable information, but it has always felt a bit ugly and distracting (some people also really hated seeing them in screenshots).

So in 2.0, we changed it so that these states are shown to the player with an icon drawn over the locomotive, and we added the train status to the GUI and tooltip.

The 'No path' icon flashes to let you know that something is wrong. Destination full is just a solid icon shown in alt-mode. These should make it easier to tell at a glance what a train is up to, without having to do the mental pause to verify there is no flying text notification coming soon.


As always, dispatch your thoughts to us at the usual places.