[MOD 0.15] SmartTrains 2.0.5

Topics and discussion about specific mods
Post Reply
The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by The Lone Wolfling »

Thanks! I think I get the idea now.

And yes, I would consider that in the category of "useful bugs". (In other words, it's probably unintended behavior, but it's useful unintended behavior.)

Also: I don't suppose you could add a feature to read / set filters? It'd be handy to be able to set the filters to trains set to a line automatically. (Also: I wish there was a quick way to say "set the entire wagon to only hold <X>")

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by Choumiko »

The Lone Wolfling wrote:Thanks! I think I get the idea now.

And yes, I would consider that in the category of "useful bugs". (In other words, it's probably unintended behavior, but it's useful unintended behavior.)
Yeah, let's say it's working as intended :lol: I can't remember what i wanted when i added that in.
The Lone Wolfling wrote:Also: I don't suppose you could add a feature to read / set filters? It'd be handy to be able to set the filters to trains set to a line automatically. (Also: I wish there was a quick way to say "set the entire wagon to only hold <X>")
Sounds reasonable, i'll add it to my ever growing todo list, might be a while

The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by The Lone Wolfling »

After fiddling around with SmartTrains for a while, I have come to the conclusion that it does something different than what I'm looking for. I'm looking for something that'll give trains logistic-bot like behavior, and this doesn't. You can make it simulate certain aspects, but only in a very "square peg in round hole" sort of way.

What I'd like to do is to treat trains as though they were logistic robots - so you mark stations as though they were part of a logistic network (i.e. "keep 100 of <x> in stock", or "this station provides <y>" or "please take all <x> away from this station") and have everything "just work". Some specifics:
  • Partial requests should be distributed semi-evenly. So if I have 3 stations requesting copper plates, I shouldn't end up with 1 getting all loads of copper plates and the others getting nothing. This is one of the big frustrations I'm having with this mod - you can't really do this.
  • I should be able to designate stations as idle stations, where trains will go if there's nothing for them to do.
  • It should set filter slots (so, for instance, if I have a station that produces both lead plates and sulfuric acid barrels, and something requests lead plates, it won't grab sulfuric acid unless there's somewhere it should go to too).
  • Trains should pick up either a whole load or whatever is in the station, whichever is less.
  • Trains should fill up on fuel semi-intelligently. (So if they are heading past an empty fuel station and they aren't full, stop and refuel)
  • Trains should not go to idle stations unless there is nothing for them to do and they are full on fuel.
  • Ideally, trains should be smart enough to move to the next station if they are blocking enough trains.
  • Ideally, trains should be smart enough to not all try to go to the same station at once unless it's really necessary.
  • It should coalesce requests. So for instance, if there's something that requests sulfuric acid on the way, it should pick up both and deliver both.
I am aware that this requires solving the TSP in general. But an approximation should work. Even just "find the nearest (as in fastest to get to) station that can fulfill a request and head there, load up, and head to the station that least recently requested that item (and that doesn't have a train on the way)" should work reasonably well.

So, with that in mind: is what I'm trying to do outside of the design goals of this mod? Or is it a limitation of the current state of the mod? Because currently this isn't really feasible.

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by Choumiko »

The Lone Wolfling wrote:So, with that in mind: is what I'm trying to do outside of the design goals of this mod? Or is it a limitation of the current state of the mod? Because currently this isn't really feasible.
Completely outside of the goals, sorry (because that's a pretty list with interesting ideas).
A lot of your ideas would require calculating/having access to the actual layout of your rail network (travel distances between stations) and/or manipulating train pathfinding (probably by constantly renaming train stations). API access isn't possible, that would leave calculating, which is probably beyond my abilities (at least in a way that doesn't lag your game to death ;) )

Manipulating path finding has the issue that a train completely stops when recalculating it's path. I don't know how it behaves when multiple train stations get renamed in the same tick, my guess is that the effects would not be good, e.g. trains stopping every time a station get's renamed to recalculate and other things.

The one thing SmartTrains sort of does from your list is
  • Trains should fill up on fuel semi-intelligently. (So if they are heading past an empty fuel station and they aren't full, stop and refuel)
They don't refuel when going past a station, but add a refueling station to the end of their schedule when they are under a certain fuelvalue. So if you set up your schedules in a way that the refueling station is near the last station in your schedule (and in the way to the first station) it's nearly the same. I have refueling stations at the exit of my base trainyard(s), one for each main branch.

You can do some pretty/fun stuff when using train lines and combinators together:
Smart Oil
The above uses smart trainstops with the Goto station # signal value to make trains skip stations when they are full and/or leave a station when the tanks are near empty/not filling up quick enough. E.g. a train at Oil 7 arrives directly after another one leaves so the tanks are only filled by 100 oil, once they are < 10 it immediately goes to Oil 4 (where the train before it never went because it got filled at Oil 7), where it get's filled to the max. Once it detects that it's full it skips all other stations and goes directly to unloading. In my case that saves me from having to setup trains for different stations/schedules as well as quite some travel time (~ 3minutes from Oil 7 to Oil 6 wiht 0 second stops at each station between).
One could do something similar for ore trains or even a supply train that only goes to stations when they are signaling that they need to be resupplied.

The better one is with combinators the more SmartTrains could do, though i doubt that any of your ideas would be doable. Partial requests/evenly distributing could be possible in the form of "if item at station < Y then unload X items, go to the next station, if empty or train cargo < Z go to loading station else go to the next station.

The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by The Lone Wolfling »

Limited mod APIs strike again. (I really wish that games would either have a mod API that allowed full access to the game engine (KSP, for instance, at least after the file restrictions were removed), or left it entirely to unofficial versions that did (DF). But this Frankenstein "sure we have a mod API! What? You want to do that? Wait somewhere between a week to never..." is really rather frustrating, to the point where I've thought of starting a DFHack-like project for Factorio (Or rather, just a plugin/hack that allowed memory peek / poke from Lua, from which you can build everything else).) It's the difference between handing someone a bunch of lego blocks and handing someone a bunch of lego blocks half of which are glued together in the way they were "obviously supposed to be used". (And what many people forget is that it's not just that the current API doesn't have the tools, it's that it kills fast turnaround for development. In Minecraft, if I want to try something random and off-the-wall I can hack it together quickly, see if it makes some vague sort of sense, and if it does I can come back later and tidy things up. In Factorio... Not so much. Step one is tidy it up to the point where it can go into a request (at which point it's entirely likely that it'll be shot down as "why on Earth would you do that off-the-wall thing"), step two is wait a week to infinity.)

But I digress. It's too bad to hear that SmartTrains doesn't do what I want, and even more to hear that it essentially cannot be done currently. Consider me enlightened as to the state of mod development for Factorio.

Back on topic:

Two things that would make my life substantially easier (that *are* probably possible), are a) a signal that signals when a train is stopped at it (or a track segment that signals when there is a train on it, either works), and b) a way to distinguish between items in different cars in the train. (So, for instance, distinguishing between "this train has crude oil in the second car" versus "this train has crude oil in the first car")

MrDrummer
Fast Inserter
Fast Inserter
Posts: 131
Joined: Sat Nov 22, 2014 2:51 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by MrDrummer »

Man, when I first installed this mod, I didn't know how to use combinators. Now after watching a few tutorials, and seeing that save has sure helped me understand!

Could you add screenshots to show how to do some basic set-ups? Or perhaps a guide to go along side that save so you can describe what each element does (for those who do not understand how the combinators are used)

Things like checking for the trains/cargo wagons being -1, I still do not have a clue what those change to when items are detected?

Also, in the config for the trains, it would 1. be great to split it up a bit better and 2. explain that the signal is not if the path is directly clear, but instead the circuit signal (perhaps an information window)

The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by The Lone Wolfling »

Doing things with combinators inefficiently is easy (relatively speaking). Doing it efficiently? Not so easy. There are oddities like red + green wire implicitly adding inputs (which in certain cases allows a single combinator to work with 4 distinct inputs).

I've been thinking of building a superoptimizer for combinators. Very simple, "just" generate all possible combinations of combinators (with restrictions relaxing as more are tried, in a semi-diagonal manner) and feed inputs to them, weeding out those that don't work. Keep track of what input set killed a certain network, and try inputs most-killed-by-input first, then, depending on the input size, either sequentially through all remaining or randomly a bunch of times then output for a human to check and either validate or provide a counterexample. (Or potentially even to feed to a SAT solver.)

But I need to play around with combinators a bit more first. It'd be a shame to code something only to find that I coded the combinators wrong.

Also: it'd be handy to be able to specify what circuit value a stop in a train line reacts to. So I could have multiple train lines running through a single stop controlled independently as to where to go.

The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: [MOD 0.12.2+] SmartTrains 0.3.68

Post by The Lone Wolfling »

I'm playing linear Factorio, with just enough height to have a proper train loop, but no more. As such, I have 1 train loop that all my trains run on, with parallel tracks for stations. As such, I need to keep the main loop as uncongested as possible. This poses problems when I have multiple trains that stop at a station. "Ideally" (that is, within the constraints of mods in Factorio currently), I would like to have the following happen for (most) stops:
  • If the current train is full / empty (depending on the station and train line), send it to stop 1 in its line.
  • If the current train cannot fill / empty any more (ditto), or if there is a train waiting to come into the station, send it to its next stop.
I have something that mainly works for this. It's a little clunky, but boo hoo. However, there are two particular problems.
  • In order to detect that there is a train waiting for the station, the only way I've come up with is to have a pre-station placed just before the station that all trains go to before heading to the station proper, but this requires all trains to stop and doubles the length of the station required.
  • There's no way that I know of to differentiate between trains on different lines (well, that's practical at least. Technically I could have every train hold a different unique item or something I suppose). It'd be wonderful if you could specify what signal a particular line responds to, as opposed to just the entire station.

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [MOD 0.12.11] SmartTrains 0.3.69

Post by Choumiko »

SmartTrains 0.3.69
  • updated for Factorio 0.12.11
  • added interface for de-/activating SmartTrains without removing it
To de-/activate use

Code: Select all

/c remote.call("st", "deactivate")
/c remote.call("st", "activate")
This way you don't loose your trainlines/settings from SmartTrains. Mainly done so that i can more easily see the performance difference, but should also allow you to disable it in case off errors/bugs until they are fixed.
The Lone Wolfling wrote:
  • If the current train cannot fill / empty any more (ditto), or if there is a train waiting to come into the station, send it to its next stop.
How would you decide whether a train can not fill/empty anymore? The "Depart" function of SmartTrains sends the train to the next station if it cargo hasn't changed for a certain amount of time. Is that what you mean? Right now this only works on a per line basis (i'm already planning on making it an option for each station individually).
The Lone Wolfling wrote:
  • In order to detect that there is a train waiting for the station, the only way I've come up with is to have a pre-station placed just before the station that all trains go to before heading to the station proper, but this requires all trains to stop and doubles the length of the station required.
  • There's no way that I know of to differentiate between trains on different lines (well, that's practical at least. Technically I could have every train hold a different unique item or something I suppose). It'd be wonderful if you could specify what signal a particular line responds to, as opposed to just the entire station.
How about a signal that can be hooked up to the circuit network outputting it's state? depending on where you place it, the state would/could have different meanings, if you place a bunch of them it would even tell you how many trains are waiting.
Seems like another special signal would be needed that outputs the linenumber of the train at the station.

With these signals you could do the "Go to station 1 (or station Y) when full/empty or x trains waiting" depending on the line the train is on.
Detecting if a train is full for single item cargo can be done already, for mixed cargo with possibly filtered slots yet another signal would be needed.
It certainly sounds interesting.

The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: [MOD 0.12.11] SmartTrains 0.3.69

Post by The Lone Wolfling »

Choumiko wrote: How about a signal that can be hooked up to the circuit network outputting it's state? depending on where you place it, the state would/could have different meanings, if you place a bunch of them it would even tell you how many trains are waiting.
That would be wonderful.
Choumiko wrote: Seems like another special signal would be needed that outputs the linenumber of the train at the station.
I would prefer another solution. That method has race conditions based on how quickly the circuit reading the line # updates compared to the ones updating which station to go to. It can be worked around, but is very clunky and adds even more combinators as opposed to the "line A reads item X, line B reads item Y" solution.

It also has other problems even beyond that (e.g. if you add / delete / modify another line you may have to update every single station with one of these signals, unless I'm mistaken as to what you mean by line number. Ditto, if you have multiple lines that want the same next station you'll still need an additional combinator for every line.)

Let me put it this way: it would technically work, but in practice it'd be so clunky that I doubt I'd ever use it.
Choumiko wrote: Detecting if a train is full for single item cargo can be done already, for mixed cargo with possibly filtered slots yet another signal would be needed.
It certainly sounds interesting.
You can already do this, although it's clunky.. Take advantage of combinators not updating instantly - if you hook up your station to a passthrough combinator reading X and also directly to a comparator combinator set to output when the delayed signal is greater than the non-delayed X one, it'll pulse every time items of type X are removed from the train. (Swap the comparator and you'll get it pulsing every time items are added to the train instead). Connect that to a monostable, and you've got your signal. For multiple items, you either set it to any, or make one pulsar for each item type and feed them all to the monostable.

The problem with the current "go when full / empty" option is that it doesn't interact well with choosing what station to go to next (there's no good way I know of to get it to go to a different station when empty using said option. Or rather, I have been unable to come up with one that doesn't have a race condition)

(By the way: I don't suppose it's possible to detect when there have been changes to the schedule of a train on a line and pop up something asking if you want to update the line? I forget to delete / recreate the line annoyingly often, and as such end up with my changes silently discarded.)

waduk
Filter Inserter
Filter Inserter
Posts: 372
Joined: Tue Feb 10, 2015 5:44 pm
Contact:

Re: [MOD 0.12.11] SmartTrains 0.3.69

Post by waduk »

Simple request, if it not too much trouble.
Can you make the train lines arrange in natural order.
Example, at current version "Station 10" is placed in between "Station 1" and "Station 2".


PS: What i mean by current version is ST 0.3.68 (i can't use 0.3.69 yet, too may broken mod that haven't been updated)

Boogieman14
Filter Inserter
Filter Inserter
Posts: 770
Joined: Sun Sep 07, 2014 12:59 pm
Contact:

Re: [MOD 0.12.11] SmartTrains 0.3.69

Post by Boogieman14 »

Using ST 0.3.69 on Factorio 0.12.12, opening the ST-Settings menu returns an error message:
Image
I don't have OCD, I have CDO. It's the same, but with the letters in the correct order.

User avatar
Darkestnoir
Inserter
Inserter
Posts: 29
Joined: Sun Nov 23, 2014 8:57 pm
Contact:

Re: [MOD 0.12.11] SmartTrains 0.3.69

Post by Darkestnoir »

Boogieman14 wrote:Using ST 0.3.69 on Factorio 0.12.12, opening the ST-Settings menu returns an error message:
Image
Same here.

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [MOD 0.12.11] SmartTrains 0.3.7

Post by Choumiko »

SmartTrains 0.3.7
  • updated for Factorio 0.12.12
  • alphanumeric sorting for trainlines
Looks like i forgot to make a release :roll:
waduk wrote:(i can't use 0.3.69 yet, too may broken mod that haven't been updated)
You can edit it in by hand if you want it for 0.12.10:
control.lua line ~959 change the function to

Code: Select all

function sortByName(a,b)
  local function padnum(d) return ("%012d"):format(d) end
  --table.sort(o, function(a,b)
    return tostring(a):gsub("%d+",padnum):lower() < tostring(b):gsub("%d+",padnum):lower()
  --return a < b
end
(don't ask me what it does, seems to work :D )
in gui.lua change line 297 to

Code: Select all

 for i, l in pairsByKeys(global.trainLines, sortByName) do

User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12888
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: [MOD 0.12.12] SmartTrains 0.3.7

Post by ssilk »

Move to Helper Mods now? :) :) 8-)
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [MOD 0.12.12] SmartTrains 0.3.7

Post by Choumiko »

ssilk wrote:Move to Helper Mods now? :) :) 8-)
Not yet, got few changes to be made/pushed first. And WIP feels like home for SmartTrains :D

jhyatt
Burner Inserter
Burner Inserter
Posts: 19
Joined: Thu Oct 09, 2014 8:06 pm
Contact:

Re: [MOD 0.12.12] SmartTrains 0.3.7

Post by jhyatt »

Does anybody else have issues with smart trains not saving which trains are on which lines when leaving the game and coming back?

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [MOD 0.12.12] SmartTrains 0.3.7

Post by Choumiko »

Works fine for me (0.12.16 and SmartTrains 0.3.7), did you save the game in 0.12.13 or 0.12.14? This could have messed up something.

jhyatt
Burner Inserter
Burner Inserter
Posts: 19
Joined: Thu Oct 09, 2014 8:06 pm
Contact:

Re: [MOD 0.12.12] SmartTrains 0.3.7

Post by jhyatt »

i was running 12.13 updated to 12.16 had to disable all mods due to possible corruption once updated, but i launched Vanilla 12.16 and saved, then re-enabled mods and launched so far everything looks good.

MainTango
Long Handed Inserter
Long Handed Inserter
Posts: 55
Joined: Tue Oct 27, 2015 12:22 am
Contact:

Re: [MOD 0.12.12] SmartTrains 0.3.7

Post by MainTango »

I'm having trouble with the 'Go to station #' feature in the line rules menu.

My scenario is as follows:

I have two oil outposts and a train with rail tankers on stand-by in my main base. Whenever the tanks at one of the outposts fill up beyond a certain threshold, the train goes to that particular outpost to get the oil.

I have the schedule and the rules set up like this:
screenshot
However, when I press 'save' in the rules window and then open it again, the entries in the 'Go to station #' text fields are gone. And the train does indeed act as if there is no entry there. So, after loading the oil at Oil Field NW, it goes to Oil Field South instead of back to the HQ.

Is there a way I can make this work other than altering the schedule or setting up signals with a value of 1 at the outpost train stations?

And another thing. Whenever I try to edit a line, I usually end up redoing it because after I make changes to the schedule and press 'Read from UI' and then 'Save as line', it won't update the line with the new schedule. Instead, I have to either retype the name of the line into the 'save as' field or delete the line and redo it.

On a final note, let me tell you how awesome your mod is. Along with the Fat Controller, it really completes the train experience in Factorio. That functionality should become part of the vanilla game asap. I know, they've put it on the road map.

I'm playing on v0.12.12 with the following mods:
modlist

Post Reply

Return to “Mods”