Force a train to move to the next station (of the same name)

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
TwistedForHire
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sun Dec 08, 2024 9:16 pm
Contact:

Force a train to move to the next station (of the same name)

Post by TwistedForHire »

I have a train circuit around my base. I have a bunch of artillery stops that I want me artillery train to stop at, wait for a bit of the wagons to shoot, then move on to the next station. All the stations have the same name. At each station, I disable the station if train is there. In the train, I have a condition for the train to wait for 2 minutes. However, when the 2 minutes is up, it doesn't move to the next station. If I toggle the train from auto->manual->auto or if I manually click on the station stop/go button, it will move on.

Is there a way to force the train to move on?
eugenekay
Fast Inserter
Fast Inserter
Posts: 113
Joined: Tue May 15, 2018 2:14 am
Contact:

Re: Force a train to move to the next station (of the same name)

Post by eugenekay »

With only one “Train Stop”? I don’t think so, since the Train is already “at” the stop (even if it is Disabled), it meets the Pathing condition so it stays put.

However…. You don’t need to do this with “only one Stop”. At each of your Outpost stations, have two “Train Stop” entities; one for ArtilleryFire, and a second for ArtilleryDone spaced right next to it. Scheduling:
- ArtilleryFire: Wait for 120 seconds
- ArtilleryDone: Wait for 1 second

The train should then Fire for 2 minutes, move forward, then Path to the next ArtilleryFire station in line.

Separately, use an Interrupt to detect when the cargo of Artillery shells runs low, and setup a Temporary stop for ArtilleryReload.

I hope this helps. :-)
TwistedForHire
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sun Dec 08, 2024 9:16 pm
Contact:

Re: Force a train to move to the next station (of the same name)

Post by TwistedForHire »

That is a great idea! Thank you. Yea I have an artillery load interrupt that is working great. I think the two stop will work great!
TwistedForHire
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sun Dec 08, 2024 9:16 pm
Contact:

Re: Force a train to move to the next station (of the same name)

Post by TwistedForHire »

Yup, that works perfectly, thank you very much. I discovered that using the "Inactivity" condition is actually the best. As long as the artillery is shooting, it will sit there any wait. But once it's done for the time set, it will move on. Now I have automated border cleaning. :ugeek:
Kalanndok
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Sat Dec 12, 2015 9:07 am
Contact:

Re: Force a train to move to the next station (of the same name)

Post by Kalanndok »

Do you really need a wait condition on the second stop? Afaik a stop with no wait condition serves as a mandatory waypoint but the train would just run through.

Another thing: You would need to find a way to determine the need for an artillery train so that the train can be actively called to that station. Otherwise you might have the train swapping between two stations without biters and the one with biters in range would never get serviced.
Tertius
Smart Inserter
Smart Inserter
Posts: 1024
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Re: Force a train to move to the next station (of the same name)

Post by Tertius »

A design from the request in the OP:
- We have a bunch of same-named outposts, one artillery loading station and an artillery train.
- we want to visit all outposts with our artillery train, the same station every 5 minutes
- if the artillery train runs empty, it should go to the base and refill. Otherwise it should visit the next outpost

First the outpost. After the artillery train left, we want to wait 5 minutes, then request the train again. Can also be higher, for example 10 minutes, since enemy expansion is not that aggressive that our base will be overrun if we don't immediately shoot a new expansion patrol.
So build a counter with a decider combinator and connect it to the station. Read the train id from the station and use it as counter condition: count if train ID = 0. This means, the counter counts as long as there is no train active at this station. As station activation condition set counter > 18000 (60 ticks * 60 seconds * 5 minutes), so the station will activate if the counter counted beyond 18000, which means it counted 5 minutes.

Next the train. As default schedule, set the loading station. Wait condition "train full".
The outposts are visited via interrupt. As interrupt condition set cargo > 5 artillery shell (we don't want to drive with an almost empty train to a new outpost). As destination set the outpost, as wait condition set inactivity > 30 seconds. Scanning and shooting is activity, so it will leave if all this has finished.

The main schedule entry is simple: station is shell loading station, waiting condition is "cargo full".

And that's it.

First, an empty train goes to the shell loading station and is being loaded. If it's full, the interrupts are checked. Cargo > 5 is true, so the interrupt fires and the outpost is put as destination.
Since we just started, no outpost reached their timeout yet, so no station is active, so the train just stays at the loading station and waits with "destination full".
As soon as the 5 minute timer has elapsed for one outpost, that station gets activated and the train drives there. As soon as it arrives there, it starts scanning+shooting, and at the same time the counter at the station is reset since a train id is read from the station. The station deactivates immediately, but this is not relevant for the current train. It continues shooting and continues to reset the counter.

Eventually the shooting finished and the waiting condition is elapsed. The interrupt is checked again. If the train has <= 5 shells the interrupt doesn't trigger, so the cycle starts at the beginning with going to the loading station. Else, if it has > 5 shells, the interrupt is triggered again and its outpost is added to the schedule.
In this moment, the train releases the station and its counter starts again. It starts on the train trying to leave, not when the train arrived.
If there is no active station yet, the train stays there (showing "destination full"). The station itself is still deactivated, since 5 minutes didn't elapse yet. As soon as some station elapses its own timer, it opens and the train drives there and the cycle starts again with that station.

This scales well. If you need more than one artillery train, add more. If you need more loading stations, add more (all with the same name). You might want a small optimization if you use multiple trains: if you have a non-empty train at an outpost, but no other open outpost, you can use the time to refill the train instead of just waiting with an half empty train. To achieve this, use the "station full" condition in the outpost interrupt. Trigger the outpost interrupt only if cargo > 5 AND outpost is not full OR cargo > 5 AND currently at depot (more on the depot later). This way the train only gets an outpost as destination if there is currently an open outpost. Otherwise nothing triggers and the train returns to the loading station for refill. You might also want to add a depot if you do this, so full trains are able to leave the loading station, so trains from outposts are able to return to the base. The depot gets its own interrupt: go to the depot if currently at loading station AND outpost is full. The depot waiting condition in its schedule entry in the interrupt is just waiting 5 seconds. After the 5 seconds, interrupts are checked and the outpost interrupt will trigger since the train has cargo > 5 shells, so the train will continue to wait with destination full or leave the depot as soon as an outpost opens.
Krasaar
Manual Inserter
Manual Inserter
Posts: 1
Joined: Tue Dec 10, 2024 11:59 am
Contact:

Re: Force a train to move to the next station (of the same name)

Post by Krasaar »

I have been playing around with a similar design and this is what I came up with:
Outpost preview
Outpost preview
12-10-2024, 13-02-23.png (440.25 KiB) Viewed 308 times
How it works:
there is a clock set to 600 sec by default. Each minute it checks if the time is right for an artillery train to show up
Clock explanation
Clock explanation
12-10-2024, 13-06-19.png (989.86 KiB) Viewed 308 times
L is the limit so only one train shows up there.
R stands for running clock
the memory cell above sets the train limit (and enables it too) if the conditions are met and stays like that until a train comes to the station
in which case the id is compared to different than 0 when if true returns R == 1
the second station stays off unless a train shows up to the first station (I had a case where a train would target a takeoff station from another outpost)
Then it's turned off again once a train takes off an outpost.
Here are my blueprints if you want to try them out / improve them

Tertius
Smart Inserter
Smart Inserter
Posts: 1024
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Re: Force a train to move to the next station (of the same name)

Post by Tertius »

This is an implementation of my design from above post. It uses 1 station at the outpost.

One small but important change from the design: Factorio behaves inconsistent if a train station is set inactive in contrast to a train station's train limit is set to 0. In my design I said a train about to leave a station is not considered at the station any more, just its limit reservation stays, but this is wrong. If a train is at a disabled station, it will stay at this station if an interrupt orders it to go to a station with this name. However, if you set train limit=0 instead of disabling the station, the train will leave and go to the next enabled station!

I don't know what is intended behavior (there are several bug reports about this), but as long as the current behavior exists, the implementation I describe will work.

On the left, there are 5 outposts. I simulate artillery shooting by taking off a bunch of shells each visit, so the train will run low on shells eventually. Reloading takes place at the Base station, only when shells < 5.
out.mp4
(6.18 MiB) Downloaded 6 times

The blueprint contains the whole demo setup from the video.



The outpost has 2 combinators. One is a counter that counts as long as there is no train at the station:
Screenshot 2024-12-12 110614.png
Screenshot 2024-12-12 110614.png (76.78 KiB) Viewed 242 times


The other one sets the train limit L to 1 if the counter exceeds 7200 ticks (2 minutes). For a real map, increase this to something like 18000 (5 minutes).
Screenshot 2024-12-12 110759.png
Screenshot 2024-12-12 110759.png (62.73 KiB) Viewed 242 times


Station settings:
Screenshot 2024-12-12 110829.png
Screenshot 2024-12-12 110829.png (40.46 KiB) Viewed 242 times


Train schedule:
Screenshot 2024-12-12 110918.png
Screenshot 2024-12-12 110918.png (78.08 KiB) Viewed 242 times


Train interrupt:
Screenshot 2024-12-12 110933.png
Screenshot 2024-12-12 110933.png (39.47 KiB) Viewed 242 times
Post Reply

Return to “Gameplay Help”