Page 1 of 1

[0.13]Deactivating Train Stop via Network

Posted: Thu Jun 30, 2016 5:27 am
by jomama
Summary: I want to be able to switch whether a station can be found by trains based on network condition.

As was touched upon here (viewtopic.php?p=164194#p164194) and a few other places, I thought we were going to be able to turn off a train station using network conditions in 13. Unless I'm missing something, that's not the case, so putting it as a suggestion here. To clarify, unlike the thread linked above, I'm talking about being able to make a station ignored by all trains pathfinding -- not having each train make the decision about whether to skip a stop or not (though that is an interesting suggestion).

What I would like to be able to do is have each of my mines given the same station name but have some level of control over when a train visits the mine, like a circuit condition if the ore in the chests is over 6k. This way I can worry about building new mines and not worry about whether my trains are appropriately visiting my existing mines. When a mine starts to run dry it will automatically be visited less, and when it is empty it will no longer be visited. No more worrying about deconstructing empty mines so my trains don't waste time. No more worrying about trains always visiting the closer mine and ignoring the farther but much richer mine.

It seems like we're so close to being able to do this, but just need to be able to deactivate (or remove, or even rename) the station. Unfortunately, it seems I can only control the signal leading into the station, but that doesn't stop the trains from trying to get there (they just queue up outside the station, waiting for the green light).

If I'm missing something obvious please let me know. I've tried a lot of things but can't find an ideal solution that doesn't require me constantly monitoring my trains and mine levels to switch routes. I think maybe the train switch of the rail logic mod (viewtopic.php?f=93&t=14105) might work, but it seems like vanilla should have a way to do this.

Re: [0.13]Deactivating Station via Network

Posted: Thu Jun 30, 2016 4:51 pm
by siggboy
If you're willing to install a mod (SmartTrains), then there are solutions to this -- albeit slightly more complex than what you have in mind. Check the link in my signature.

Re: [0.13]Deactivating Station via Network

Posted: Fri Jul 01, 2016 4:07 am
by rnorris
I am also interested in a feature that can do this. It would be possible to add a sort of 'requester station' to the rail network using this (analogous to a requester chest in a logistics system).

Re: [0.13]Deactivating Station via Network

Posted: Fri Jul 01, 2016 11:05 am
by ssilk
rnorris wrote:I am also interested in a feature that can do this. It would be possible to add a sort of 'requester station' to the rail network using this (analogous to a requester chest in a logistics system).
Aaah. :) That fetches together with my thoughts to this subject.

I try to put it together as short as possible:

- An "exchange" between two train stops can only occur, if there is a path (forward and return) between the two train stops
- One of that pair needs to request items, the other provides. (it could be also in both directions at once, but that would make things now too complex to discuss them)
- If there are provided items, that are requested a train will get an order (a schedule) to run between the two stations.
---- that means: We have a pool of trains, that have nothing to do. They can be used to connect to the train-network.
- before the train comes it is needed, that we pull the provided items out of usage of the local logistic system around the provider station (a simple solution would be, that there are some special chests, that the logistic bots will deliver then, but simpler solution is to put the item just into waiting-chests at the train stop as usual).
- The items will be loaded into train. Only the requested items for that target should be loaded. Many possibilities to achieve that.
- The train drives to the target station
- The requested items are unloaded. That is also special, we need some kind of inserter-logic for that.
- Now it could happen, that items remain in the wagons. That needs to be cleared first. This means, the train needs to drive in that case to a "storage station" then, to unload the remaining unneeded items.

Now the circle repeats.

That is just the very basic functionality of that and what I like here is, that it mirrors the functionality of the logistic system just in a much bigger area.

There is a lot things, that is needed for that, for example some kind of wireless multiplexer connection to transfer the needed items.

Re: [0.13]Deactivating Station via Network

Posted: Fri Jul 01, 2016 4:38 pm
by jomama
siggboy wrote:If you're willing to install a mod (SmartTrains), then there are solutions to this -- albeit slightly more complex than what you have in mind. Check the link in my signature.
I've looked at that, and it is definitely more complicated than what I was putting together! But I'm fine with having separate trains for my different ores for now. What I'm trying to do seems so simple I thought maybe the devs could squeeze it in to a minor update... especially since I thought this was already in the works for 13 (unless I misread some posts from a log time ago).
rnorris wrote:I am also interested in a feature that can do this. It would be possible to add a sort of 'requester station' to the rail network using this (analogous to a requester chest in a logistics system).
ssilk wrote:Aaah. :) That fetches together with my thoughts to this subject.
So you guys are thinking more along the lines of using a train to bridge logistics networks. Way more complex, but a fun idea. Kind of like what siggboy is trying to do in his combinator magick thread. I've wanted to get a resupply train out to my outposts, but I haven't gotten that far since I spend too much time babysitting my existing rail network (which is what I'm trying to get fixed!). Maybe once I expand far enough away from the starting zone that the mines have enough ores to last longer then I'll have more time to work on other puzzles... or I'll keep expanding my factory to consume raw goods faster and even the bigger mines will go dry faster and I'll be back to full-time managing which mines are visited...

Even just making the logic so that the trains ignore a station that is inaccessible due to a circuit-controlled red signal would do the trick. If I read right, trains already treat a circuit-controlled-red differently from a train-induced-red signal, but to the opposite effect of what I need -- they are more likely to wait for a circuit-red than a train-red. I'm sure there was a reason it was done that way, but it's killin' me.

Re: [0.13]Deactivating Station via Network

Posted: Fri Jul 01, 2016 11:58 pm
by siggboy
jomama wrote:
siggboy wrote:If you're willing to install a mod (SmartTrains), then there are solutions to this -- albeit slightly more complex than what you have in mind. Check the link in my signature.
I've looked at that, and it is definitely more complicated than what I was putting together!
If you use the simple version (does not have real requester stations) then it's not really complicated, and it basically does exactly what you want -- it only sends the trains when the outposts have mined some ore that is ready to pick up. You can also use it to deliver empty oil barrels to the pumping stations (and pick up any filled ones on the way back, of course).

The one major caveat is that you need red wire to be running between all the stations; this is something that is most easily achieved with FARL, but of course it could also be done manually.

The mod itself (SmartTrains) is even very useful without such combinator circuits.
But I'm fine with having separate trains for my different ores for now. What I'm trying to do seems so simple I thought maybe the devs could squeeze it in to a minor update... especially since I thought this was already in the works for 13 (unless I misread some posts from a log time ago).
The biggest of bases have been built based on very simple rail networks; none of these advanced features are truly necessary if you want to run a heavy duty factory. The new train station conditions already eliminate the problem of empty trains driving around (because you can have the trains wait at the outpost until the wagon is filled).
So you guys are thinking more along the lines of using a train to bridge logistics networks. Way more complex, but a fun idea. Kind of like what siggboy is trying to do in his combinator magick thread.
Well, my "combinator magick" is basically a logistic network for trains. I've never thought about that being the "bridge" between actual logistic (robot) networks. The main reason why I've created my setup (and others have done similar things, mind you) is so that I could have ONE single train line, and would not have to assign individual trains connecting certain outposts and unloads. The extension that turned it into a real logistic network, namely requester stations, was only added later.

My current version is powerful enough that you can easily run a completely distributed base, where you not only ship ore to the base, but also ship around any intermediate products any way you like -- and you never have to explicitely assign a train to any station, as they're all assigned to the main line, and that only happens once, when you create a new train.

None of this is actually "needed" to make a record breaking base. But it's a ton of fun, I can say that much.

Re: [0.13]Deactivating Station via Network

Posted: Tue Jul 05, 2016 4:45 am
by NorwegianBlue
+1 !

Re: [0.13]Deactivating Station via Network

Posted: Wed Jul 06, 2016 1:41 pm
by Lucius
Puppet and Ghost Trains

If you REALLY-REALLY want to deactivate a station, you could just put a "puppet train" (locomotive and no carts) at your station which leaves only when certain circuit conditions are met (chests full). Other trains will look for a station with the same name somewhere else until they find a "free" one.
(Now that I think about it, I have no idea whatsoever of what happens if they don't find one, never happened to me so far :o )

Kinda feels like cheating though, since the main purpose of a "smart train" network is to use the least number of locomotives (from my perspective anyway).
I think a really straightforward way to implement "on-off stations" would be to "trick" the software that runs railways.
If it believes there's already a train stopped at that station, no other train will try to go there if other stations with the same name are available.


Railway Signals
But enough of this! On-Off stations are a too convenient solution for a common problem!
I wanted to introduce an alternative to simply shut stations down! :mrgreen:

In a nutshell
Railway Signal+Circuit Network placed at the "entrance railway" of the station!
If Circuit forces Railway Signal to turn Red --> the attached piece of rail CEASES TO EXIST. (at least in the eyes of the software that manages railways routes)

Longer Explanation
FLOWCHART for an empty "Iron Ore Train" leaving an "Iron Unload" station:
Can I get to any "Iron Load" named station without passing through any Railway Signal made Red by a Circuit Network?
NO-->No Path error (Or skip this station, I'll let you figure out which is best)
YES --> Go to the nearest Iron Load station, as you would normally do.
(Optional: the Red signal now turns to Yellow, to prevent more than one train to go to that chosen "Iron Load" station. The piece of rail still doesn't "exist" for ALL the other trains. I believe the functioning is quite similar to the "normal" yellow sign)

If you try to do the same thing with signals now, you'll end up with all the trains patiently waiting at the red signal of the nearest Iron Load station. Throwing Mayhem all over the rest of the railway.

Obvious Objection
This sounds so complicated, why don't we just shut down the station alltogether and get it over with?

I'm not a Factorio Programmer, so it's not really up to me to say what's complicated and what's not, Maybe this is easyer to implement than the stations! I thought it was a thing worth to point out. :roll:
And as said before: Isn't turning off stations just a waaaay too easy solution to this problem? Let us players sweat a little! There's no fun otherwise!
I've been on this "problem" since 0.13 release and it's been fun to find a way to hack the system!
Besides, maybe this "Signals" thing can have other applications, like connect/disconnect two big railway systems and probably more stuff i'd never think of! :D

Re: [0.13]Deactivating Station via Network

Posted: Wed Jul 06, 2016 2:21 pm
by jomama
Lucius wrote: If you REALLY-REALLY want to deactivate a station, you could just put a "puppet train" (locomotive and no carts) at your station which leaves only when certain circuit conditions are met (chests full).
Yeah, I've considered doing this. I haven't because 1) like you said, it's not really efficient and doesn't make the rail network smarter, and 2) I'm not sure if my other trains would still prefer the occupied station in favor of a much further station of the same name (I haven't fully tested the station picking logic with the new wait conditions).
Lucius wrote: If Circuit forces Railway Signal to turn Red --> the attached piece of rail CEASES TO EXIST. (at least in the eyes of the software that manages railways routes)
I think something kind of like this could be done with one of the mods I linked in the first post, but that one actually removes the rail so it's not quite the same. It wouldn't work for a two-way rail, for example, if you wanted to shut down one direction. But I agree that it would be nice if at least the trains would ignore a station that was blocked by a circuit-controlled-red signal, or was in a block/segment marked red by a circuit.

Re: [0.13]Deactivating Station via Network

Posted: Wed Jul 06, 2016 6:26 pm
by Aladrius
+1 for this.


I've started working on a mod to implement something like this. Turning the station 'off' via circuit network and having it behave in the same way as when a station is destroyed/picked up would be a very clean way to add a ton of functionality.

Playing with what's readily available in the API, I put together a mod that changes the station name depending on circuit network input. Main limitation of this approach so far is that in changing a station name, say from 'A' to 'B', any trains with 'A' in their schedules just change their schedule to 'B', unless another station named 'A' still exists. Workaround for this currently is a dummy track with a bunch of stations with the possible name variations already set. This makes the trains sit emitting 'No Route' waiting for a correctly named station they can reach show up. I'd much prefer the station removed behavior, but I'm not proficient enough in modding yet to know how to accomplish this.

Re: [0.13]Deactivating Station via Network

Posted: Fri Jul 08, 2016 2:35 pm
by jomama
Aladrius wrote:I put together a mod that changes the station name depending on circuit network input.
Is your mod available for download? I also started looking at the API to figure out how to add/remove a period or underscore to the end of the name based on circuit condition. I wasn't having much luck finding the right control functions, and then went on vacation and gave up. :(

Re: [0.13]Deactivating Station via Network

Posted: Fri Jul 08, 2016 2:38 pm
by siggboy
This is all crazy. Just use SmartTrains.

Re: [0.13]Deactivating Station via Network

Posted: Fri Jul 08, 2016 3:08 pm
by Nexela
I've started working on a mod to implement something like this. Turning the station 'off' via circuit network and having it behave in the same way as when a station is destroyed/picked up would be a very clean way to add a ton of functionality.
Does Entity.active work on stations? If it does what about making a custom combinator that turns off whatever item it is pointing at. At lease I think something like this is possible.......

Re: [0.13]Deactivating Station via Network

Posted: Sun Jul 10, 2016 2:14 pm
by Aladrius
Nexela wrote: Does Entity.active work on stations? If it does what about making a custom combinator that turns off whatever item it is pointing at. At lease I think something like this is possible.......
That's the first thing I tried. Setting this true or false doesn't appear to have any impact on the rail station.
jomama wrote: Is your mod available for download? I also started looking at the API to figure out how to add/remove a period or underscore to the end of the name based on circuit condition. I wasn't having much luck finding the right control functions, and then went on vacation and gave up.
I'm testing it out today, ironing out a few issues. I'll put it up in the mods in progress forum once I've got them resolved.

Re: [0.13]Deactivating Station via Network

Posted: Mon Jul 11, 2016 1:00 pm
by Aladrius
jomama wrote:
Aladrius wrote:I put together a mod that changes the station name depending on circuit network input.
Is your mod available for download? I also started looking at the API to figure out how to add/remove a period or underscore to the end of the name based on circuit condition. I wasn't having much luck finding the right control functions, and then went on vacation and gave up. :(
Put it up this morning:

https://mods.factorio.com/mods/Aladrius ... train-stop

Re: [0.13]Deactivating Train Stop via Network

Posted: Tue Jul 12, 2016 4:13 pm
by jomama
Awesome! Love it! I did change it for myself though, so that it doesn't require a new entity and works with the normal train station. If they implement equivalent functionality in vanilla, I don't want to have to keep the mod or have to rebuild all my train stations in my saves. Cool that it works with other signal colors too... I'm sure I could use that for other things, like supply requests or something. It's like signalling without having to run wires to my outposts, which I don't want to do because I'm way too lazy.

Looking forward to getting my factory running more automatically :) though probably won't get to until the weekend :(

Re: [0.13]Deactivating Train Stop via Network

Posted: Mon Aug 15, 2016 12:38 am
by tengumai
jomama wrote:Awesome! Love it! I did change it for myself though, so that it doesn't require a new entity and works with the normal train station.
Sounds nice, and exactly what I need. Would you post your version please?

Re: [0.13]Deactivating Station via Network

Posted: Mon Aug 15, 2016 1:36 am
by tengumai
I love this, thank you for authoring it.

MY STORY: My main bus has multiple train stations for receiving iron. (ditto for copper). Each station has the same name.

BEFORE: Trains usually went to station 1 and often queued for delivery. The receive buffer at station 1 was constantly full. Trains often left with a full load. Stations 2-4 were usually empty. My main bus was not getting all the iron it needed.

NOW: When a station's buffer is full, it changes its name, taking itself out of "delivery rotation" until its buffer reduces. Trains go to alternate stations. Bus is satisfied.

I didn't want to rework my entire train system with a massive change like smart trains. This was small, simple, effective. I think that in many ways it exemplifies the pervasive Factorio spirit of choreographing independent actors to achieve system effects.