electric trains

Post your ideas and suggestions how to improve the game.

Moderator: ickputzdirwech

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Car and train is electric

Post by bobingabout »

orzelek wrote:And what about:
4. Vehicle can consume power provided by it's equipment grid?
Okay, that is an option I would like to see as well. unfortunately, due to the way the locomotive uses a burner= tag instead of an energy_source= tag with type="burner", it is unlikely to happen. I'd love to see it myself too though.

It is pretty unfortunately that everything that seems to have a grid (that isn't a player) is also a burner= entity, not energy_source.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
Engimage
Smart Inserter
Smart Inserter
Posts: 1069
Joined: Wed Jun 29, 2016 10:02 am
Contact:

Re: Car and train is electric

Post by Engimage »

Agreed with you Bob here.
Also there is much sense in adding fueled equipment grid generators. The game screams for mid-game generator like portable steam generator (burner) and portable nuclear reactor using nuclear rods.

Regarding other sides you were talking with Rseding about.
Imagine we finally have a vanilla module to connect portable grid to main power grid to charge batteries (only while standing still or idle to prevent overhead).
Then add a grid to a train and add leaving condition "Accumulator charge % >90"
We have a working solution here. And if a train stops in the middle of nowhere just bring a pole to it or just build your rail power line with medium poles to cover it all.

As an additional idea we could finally preserve power charge of modules while preventing them from stacking with other similar modules. Then you can finally safely replace empty battery with another one which is fully charged in your inventory. This can also effect an old issue with bot collection issue where they fully charge if you mine them. Not easy one to be solved but still doable.
User avatar
thereaverofdarkness
Filter Inserter
Filter Inserter
Posts: 558
Joined: Wed Jun 01, 2016 5:07 am
Contact:

Re: Car and train is electric

Post by thereaverofdarkness »

bobingabout wrote:2. Electrified Rail.
[snip]
it would add too much "overhead" (read memory usage) to implement.
I don't follow. The game already iterates through the rail segments (likely using a much more efficient method than checking every piece) to determine pathways that trains can take. The code is already done; the performance impact is already upon us. Why, then, would adding this functionality cause even a detectable dip in performance?
Meddleman
Long Handed Inserter
Long Handed Inserter
Posts: 51
Joined: Mon Jun 26, 2017 7:39 pm
Contact:

Re: Car and train is electric

Post by Meddleman »

thereaverofdarkness wrote:
bobingabout wrote:2. Electrified Rail.
[snip]
it would add too much "overhead" (read memory usage) to implement.
I don't follow. The game already iterates through the rail segments (likely using a much more efficient method than checking every piece) to determine pathways that trains can take. The code is already done; the performance impact is already upon us. Why, then, would adding this functionality cause even a detectable dip in performance?
The performance dip, I assume, would not be because of having rails, but by having a different mix of rails on the same map. Funnily enough this realization comes from having played OpenTTD.
OpenTTD introduced a seperate "Electrified Rails" railtype, which forces electric trains to drive on them. They were backwards compatible with Diesel and Steam locomotives, just not the other way around.
But OTTD is a "simple" game. It doesn't simulate millions of little entities every second. It relies more on math and a bit of pathfinding. Thats why it could afford to do it. Factorio on the other hand, cannot.

Currently, Factorio's smoothness of gameplay is top-priority since even a slight dip stacks negatively against multiplayer. To introduce a new type of rail would mean electric trains having to pathfind and check if the route they take can get them to their destination without running into non-electrified rails.

While I personally would love electrified rails to be a vanilla addition (I could use rails as a power-conduit instead of relying on long distance power poles), it isn't worth affecting every player negatively to placate a few.

And just to render this entire thread a moot point: There's A Mod For That
Some mods actually use vehicle equipment grids (that piggyback off of Bob's Mods), another uses the train burner-slot function much like barrels might, allowing one to insert "consumable" batteries that get used up, and produce a "dead" battery that can be recharged at specially built charging stations. ;)
User avatar
thereaverofdarkness
Filter Inserter
Filter Inserter
Posts: 558
Joined: Wed Jun 01, 2016 5:07 am
Contact:

Re: Car and train is electric

Post by thereaverofdarkness »

Meddleman wrote:The performance dip, I assume, would not be because of having rails, but by having a different mix of rails on the same map. Funnily enough this realization comes from having played OpenTTD.

But OTTD is a "simple" game. It doesn't simulate millions of little entities every second. It relies more on math and a bit of pathfinding. Thats why it could afford to do it. Factorio on the other hand, cannot.
You're not understanding my point. Factorio sets up a large interconnected railway as one "block". It's already regarded by the game as one entity. That entity can transmit signals to trains without negatively impacting performance, because one train signal is a single tiny event. Factorio processes many little things at once, like inserters checking for items on belts. A single inserter checking a belt for items is probably in the ballpark of being as resource intensive as a train checking the track for other trains in the block, because it's essentially the same activity internally. Having the rail block provide power to a train should cost exactly the same computational resources as having a single electric pole provide power to an assembler, which is less computation than providing power to an inserter because the assembler and train don't change their power usage rates nearly as often.

One rail network providing power to one train should cost less in performance than one electric pole providing power to one inserter.

I didn't say it should not cause a significant dip in performance, I said it should not cause a detectable dip in performance. What I mean by this is that if you used a tool to graph all performance changes during the game, you would not be able to find the point where the train changed its power consumption without an external reference.
rldml
Fast Inserter
Fast Inserter
Posts: 181
Joined: Sun Mar 06, 2016 2:38 am
Contact:

Re: Car and train is electric

Post by rldml »

Perhaps i don't get your point either, but i believe you're wrong (Ans also perhaps i am wrong, i don't know).

There are two things you have to check for any instance which need electricity:

* Is there a connection to a electric network?
* Generate the connected electric networks enough energy to provide all electric consumers in his network?

If the game engine denies the second question, it has to calculate a proportion between the generated and provided ressources and (according to the actually known game logic) has to slow down all entities connected the actual energy network in the same proportion.

Back to electric trains: if they move in an electric network that provides enough energy to supply all consumers, i would aggree to you: You only need two additional checks in the source code to make them move (if the rail is an electrical one AND has right now energy?). But when you're generated energy don't suffice, you have much more calculation to do for every train (because they could move in different electric networks).
mrvn
Smart Inserter
Smart Inserter
Posts: 5884
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Car and train is electric

Post by mrvn »

First I would go with making all rails electric from the start. But so far nothing can use that. Then when you research electric trains you get a power interface and electric locomotives. The power interface connects a rail to a power pole. After that all connected rails carry power. And if you have two power interfaces then the rails connect the two and put them in the same electric network.

Results (intendet or othetwise):
1) rails are either in a electric network or not
2) long chains of power poles going to outposts can be replaced by using the rails to conduct power (exists in mods without even the power interface, how do they do that without destroying UPS?)

Now for the electric trains: Each trains is in exactly one electric network. Just like an inserter or assembler. Since rails carry power a train never changes electric networks unless you build or destroy a track (we can live with some slowdowns there). If power runs out inserters and assemblers slow down. Same thing would happen for trains. Should be the same algorithm at the same cost. So having an electric train is like having one extra inserter.

Now for extra features:

1) Break by running the motor as dynamo. A breaking train could feed power back into the electric grid.
2) Acceleration (especially from standstill) takes a lot of power. Power consumption could be increased when trains start to move.
rldml
Fast Inserter
Fast Inserter
Posts: 181
Joined: Sun Mar 06, 2016 2:38 am
Contact:

Re: Car and train is electric

Post by rldml »

mrvn wrote:Now for the electric trains: Each trains is in exactly one electric network.
Yeah, but you could have more than one electric network, more than one train network, it depends only on your way how you realize stuff like this.
Since rails carry power a train never changes electric networks unless you build or destroy a track (we can live with some slowdowns there). If power runs out inserters and assemblers slow down. Same thing would happen for trains. Should be the same algorithm at the same cost. So having an electric train is like having one extra inserter.
It is not exactly the same: differently than inserters, a train have dullness and therefore don't behave exactly like an inserter.

Additionally (if there is enough energy), for an inserter you can simply set a boolean attribute, which you check every tick (extremly fast solution). So there is no need to make the complete calculation. It is only needed, if you add or remove poles, and only for the area the removed or added poles provide. Trains usually change their position continuously, so you have to make the complete calculation every time a locomotive enters a new tile of railroad. We don't even know, if there is such a thing like train network handled in the game, there is no evidence the game handle train networks as unqiue easy-to-check-entities in the game, because it doesn't need this actually.
Now for extra features:

1) Break by running the motor as dynamo. A breaking train could feed power back into the electric grid.
2) Acceleration (especially from standstill) takes a lot of power. Power consumption could be increased when trains start to move.
That's what i meant, but one step further: To make that happen, you have to (re-)calculate every locomotive entity continuously. That is something, that can cost more UPS than a simple inserter. I actually don't know HOW MUCH, but definitely more then a simple entity.

Greetings, Ronny
User avatar
thereaverofdarkness
Filter Inserter
Filter Inserter
Posts: 558
Joined: Wed Jun 01, 2016 5:07 am
Contact:

Re: Car and train is electric

Post by thereaverofdarkness »

rldml wrote:Additionally (if there is enough energy), for an inserter you can simply set a boolean attribute, which you check every tick (extremly fast solution). So there is no need to make the complete calculation. It is only needed, if you add or remove poles, and only for the area the removed or added poles provide. Trains usually change their position continuously, so you have to make the complete calculation every time a locomotive enters a new tile of railroad.
So it's like picking up an inserter and placing it back down repeatedly. It doesn't have to be fully recalculated just from the train moving, because there is pre-stored data from the electric network. It does have to be re-calculated when you change a unit of track, but that also happens when you change an electric pole.

rldml wrote:We don't even know, if there is such a thing like train network handled in the game, there is no evidence the game handle train networks as unqiue easy-to-check-entities in the game, because it doesn't need this actually.
I don't know how the code is handled, but there is pretty good evidence that the train networks are handled as unique easy-to-check entities because:
1.) it says that in-game
2.) the game seems to have no trouble constantly making trains communicate with the track routes
mrvn
Smart Inserter
Smart Inserter
Posts: 5884
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Car and train is electric

Post by mrvn »

rldml wrote:
mrvn wrote:Now for the electric trains: Each trains is in exactly one electric network.
Yeah, but you could have more than one electric network, more than one train network, it depends only on your way how you realize stuff like this.
But that is imaterial. The train, just like an inserter, can have a pointer to the electric network it is in and vice versa. The point I was trying to make was that the train doesn't have to search and update its electric network as it moves about. It's imply something that gets set when you put down the train, change the rails or power poles. Rarely.
rldml wrote:
Since rails carry power a train never changes electric networks unless you build or destroy a track (we can live with some slowdowns there). If power runs out inserters and assemblers slow down. Same thing would happen for trains. Should be the same algorithm at the same cost. So having an electric train is like having one extra inserter.
It is not exactly the same: differently than inserters, a train have dullness and therefore don't behave exactly like an inserter.

Additionally (if there is enough energy), for an inserter you can simply set a boolean attribute, which you check every tick (extremly fast solution). So there is no need to make the complete calculation. It is only needed, if you add or remove poles, and only for the area the removed or added poles provide. Trains usually change their position continuously, so you have to make the complete calculation every time a locomotive enters a new tile of railroad. We don't even know, if there is such a thing like train network handled in the game, there is no evidence the game handle train networks as unqiue easy-to-check-entities in the game, because it doesn't need this actually.
Dullness? As opposed to a knife having sharpness? What has that go to do with anything? Also, my trains look pretty sharp to me. Additionally, power in an inserter isn't a boolean. An inserter has some internal storage and a consumption rate. When there isn't enough power the inserter gets a certain percentage of the power it needs and becomes slower. Same would happen with trains. When they don't get enough power their acceleration would drop. And the trains speed is calculated every tick already anyway.

And here is where you missed my first point. A train, looking at the electricity, does not move at all. It is in exactly one electric network. Each turn the game adds up all the consumers and producers in each electric network and then hands out the available power to all consumers so they all get an equal percentage (except laser turrets come first). So just like for an inserter the game would see that only 75% of power is available so the train only gets 75% of its required power. Then when the train calculates its new speed it factors in having only 75% acceleration.

I also believe there already is something like a train network or its trivial to handle. There are mods that give you electric rails, allowing you to connect 2 power poles through a train track.
rldml wrote:
Now for extra features:

1) Break by running the motor as dynamo. A breaking train could feed power back into the electric grid.
2) Acceleration (especially from standstill) takes a lot of power. Power consumption could be increased when trains start to move.
That's what i meant, but one step further: To make that happen, you have to (re-)calculate every locomotive entity continuously. That is something, that can cost more UPS than a simple inserter. I actually don't know HOW MUCH, but definitely more then a simple entity.

Greetings, Ronny
You already have to compute every locomotive entity every tick. The speed of the locomotive for the next tick depends on the speed this tick, number of locomotives and cars, breaking force, wind resistance, ...Then you have to update the breaking point, reserve, block or free segments and update signals accordingly. That's probably more than a simple inserter does but you already do a lot there every tick. On the other hand the inserter has to check the belt for items to pick up or drop of.
adjl
Inserter
Inserter
Posts: 26
Joined: Mon May 07, 2018 6:42 pm
Contact:

Re: Car and train is electric

Post by adjl »

Would it not be possible to have electric rails act as power poles themselves (probably with no radius and a wire length equivalent to a small pole), thereby consolidating the electrical network into the rail network and avoiding extra calculations that way? Then it'd simply be a matter of drawing X watts whenever each train is moving, or not letting the train move if X watts aren't available for it.
Aeternus
Filter Inserter
Filter Inserter
Posts: 835
Joined: Wed Mar 29, 2017 2:10 am
Contact:

Re: Car and train is electric

Post by Aeternus »

bobingabout wrote: There are 3 possible ways to do electric trains (we didn't talk about cars)
1. Power poles affect trains.
Unlike an entity that only needs to scan for a grid when it it placed, or an electric pole is placed near it, a locomotive constantly moves, so would need to rescan for an electric grid every time it moved, that means every tick it is in motion. I am told this is also not a cheap procedure, it doesn't really effect the game when you manually place entities every now and then, even when building large blueprints you might get a single update take two ticks instead of one, but if you had trains doing it constantly, it would kill UPS.
Bad idea, requires too many extra entities to be placed.
2. Electrified Rail.
Implemented likely with some entity that interfaces to the rails rather than a pole, for reasons similarly mentioned above... it would add too much "overhead" (read memory usage) to implement. we didn't go into too much details, but still, the main reason rail types were removed so that there is only one type of rail that all trains use was done on purpose to remove overhead, and adding more back in for electric rails isn't going to happen.
Could still be done. Rails are unpowered until a "Rail power converter" is built and placed next to a rail. Unpowered rails could run standard trains, powered rails could also run electric trains. One "converter" would handle all connected rail. The check for the train would be a simple boolean that could be added to the rail block.
3. Accumulator trains and charging stations.
The train has an internal battery, perhaps accumulator wagons to make the battery last longer, and a charging station (or just charge at the station). When the train leaves the station it becomes dependant on it's charge, and in theory there will be no way to charge the train if it doesn't make it into a station (I guess you could build a station on the line next to a locomotive and power it to recharge it)
I tried, unsuccessfully, to write a mod for this one. The problem is that the train demands a burner entity, it did not seem to accept being any other type and would crash the game each time I tried to change that. Accumulator based trains could easily recharge at any station - but they might lack range as a result.

There's also
4: Fuelcell production. Use pure electricity (and some water maybe?) to generate Hydrogen Fuell Cells which could then be used as chemical "batteries" in normal burner engines.
But if that'd be so much better or worse then Nuclear Fuel Cells? I doubt it. It'd be mid-game tech at most, unless there's a high-capacity version that'd rival the Nuclear fuel's range.
User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2638
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

Re: Car and train is electric

Post by steinio »

Example for electric car:
https://mods.factorio.com/mod/vwtransporter_A16
-> put fusion generator into vehicle grid

Example for electric trains:
https://mods.factorio.com/mod/Senpais_Trains
-> place an electric transmitter which supply wireless power to trains.
Image

Transport Belt Repair Man

View unread Posts
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Car and train is electric

Post by bobingabout »

Aeternus wrote:
bobingabout wrote: There are 3 possible ways to do electric trains (we didn't talk about cars)
1. Power poles affect trains.
Unlike an entity that only needs to scan for a grid when it it placed, or an electric pole is placed near it, a locomotive constantly moves, so would need to rescan for an electric grid every time it moved, that means every tick it is in motion. I am told this is also not a cheap procedure, it doesn't really effect the game when you manually place entities every now and then, even when building large blueprints you might get a single update take two ticks instead of one, but if you had trains doing it constantly, it would kill UPS.
Bad idea, requires too many extra entities to be placed.
2. Electrified Rail.
Implemented likely with some entity that interfaces to the rails rather than a pole, for reasons similarly mentioned above... it would add too much "overhead" (read memory usage) to implement. we didn't go into too much details, but still, the main reason rail types were removed so that there is only one type of rail that all trains use was done on purpose to remove overhead, and adding more back in for electric rails isn't going to happen.
Could still be done. Rails are unpowered until a "Rail power converter" is built and placed next to a rail. Unpowered rails could run standard trains, powered rails could also run electric trains. One "converter" would handle all connected rail. The check for the train would be a simple boolean that could be added to the rail block.
3. Accumulator trains and charging stations.
The train has an internal battery, perhaps accumulator wagons to make the battery last longer, and a charging station (or just charge at the station). When the train leaves the station it becomes dependant on it's charge, and in theory there will be no way to charge the train if it doesn't make it into a station (I guess you could build a station on the line next to a locomotive and power it to recharge it)
I tried, unsuccessfully, to write a mod for this one. The problem is that the train demands a burner entity, it did not seem to accept being any other type and would crash the game each time I tried to change that. Accumulator based trains could easily recharge at any station - but they might lack range as a result.

There's also
4: Fuelcell production. Use pure electricity (and some water maybe?) to generate Hydrogen Fuell Cells which could then be used as chemical "batteries" in normal burner engines.
But if that'd be so much better or worse then Nuclear Fuel Cells? I doubt it. It'd be mid-game tech at most, unless there's a high-capacity version that'd rival the Nuclear fuel's range.
My post was detailing the results of a conversation with the devs about just why electric trains will never happen, and never be supported via modding.

your option 4 is what I like to call "Battery powered trains", where you basically just use an item with fuel value in the locomotive instead of a combustible. Internally to the game, it's just a same old train, but has a different fuel category, like the nuclear reactor does now.

It didn't really need a dev discussion, because it requires no game code editing to make work. and he'd already stated that they don't plan on adding any new locomotives to the base game.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
User avatar
thereaverofdarkness
Filter Inserter
Filter Inserter
Posts: 558
Joined: Wed Jun 01, 2016 5:07 am
Contact:

Re: Car and train is electric

Post by thereaverofdarkness »

bobingabout wrote:2. Electrified Rail.
it would add too much "overhead" (read memory usage) to implement.
thereaverofdarkness wrote:The game already iterates through the rail segments (likely using a much more efficient method than checking every piece) to determine pathways that trains can take. The code is already done; the performance impact is already upon us. Why, then, would adding this functionality cause even a detectable dip in performance?
mrvn wrote:Each trains is in exactly one electric network. Just like an inserter or assembler. Since rails carry power a train never changes electric networks unless you build or destroy a track (we can live with some slowdowns there). -snip- So having an electric train is like having one extra inserter.
Aeternus wrote:One "converter" would handle all connected rail. The check for the train would be a simple boolean that could be added to the rail block.

bobingabout wrote:My post was detailing the results of a conversation with the devs about just why electric trains will never happen, and never be supported via modding.
Are we missing something here? I honestly don't understand how an electric train would have a significant performance impact if implemented properly.
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Car and train is electric

Post by bobingabout »

I was told that the pollution modifiers per fuel/recipe would never get into the game, because it does things every single tick that is widely used... but it happened anyway.

So I guess if someone (3rd party with source access) did actually do something that worked, and didn't kill UPS, then it could be included in the official release of the game.
It still doesn't change the fact that the devs don't want to include multiple locomotive types in the base game though.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
Aeternus
Filter Inserter
Filter Inserter
Posts: 835
Joined: Wed Mar 29, 2017 2:10 am
Contact:

Re: Car and train is electric

Post by Aeternus »

Then a kludge that allows you to convert pure electricity into a burn(er)-able fuel source seems the only viable option at present. It should not be too difficult to make a mod for that.

Suggested structure: Fuel Cell Charger
Use the accumulator model and animation. It seems fitting enough.
Structure should not support modules and ignore beacons (no infinite power loops with efficiency beacons)
Power consumption: 2MW
Drain: 20KW

Suggested item: Hydrogen Fuel Cell
Fuel value: 100 MJ
Stack size 20 (slightly lower range then Solid Fuel / Rocket Fuel)
Accelleration 180% (Equal to Rocket Fuel)
Top speed 115% (Equal to Rocket Fuel)

Suggested recipy:
No input (or possibly, water as input? Or a depleted fuel cell? Can vehicles support a burner fuel that spawns an item on consumption?)
60 seconds -> Output 1 fuel cell (total power needed to create one: 120MJ, so 20% loss of power)
User avatar
thereaverofdarkness
Filter Inserter
Filter Inserter
Posts: 558
Joined: Wed Jun 01, 2016 5:07 am
Contact:

Re: Car and train is electric

Post by thereaverofdarkness »

^
I was just thinking of that earlier today.
Jap2.0
Smart Inserter
Smart Inserter
Posts: 2379
Joined: Tue Jun 20, 2017 12:02 am
Contact:

Re: Car and train is electric

Post by Jap2.0 »

bobingabout wrote:I was told that the pollution modifiers per fuel/recipe would never get into the game, because it does things every single tick that is widely used... but it happened anyway.

So I guess if someone (3rd party with source access) did actually do something that worked, and didn't kill UPS, then it could be included in the official release of the game.
It still doesn't change the fact that the devs don't want to include multiple locomotive types in the base game though.
Don't you have source access (hint hint)?
There are 10 types of people: those who get this joke and those who don't.
general_d
Burner Inserter
Burner Inserter
Posts: 5
Joined: Thu Apr 24, 2014 7:35 am
Contact:

Electric trains and track

Post by general_d »

As an old ottd player I'd love to see the ability to have a second recipe for trains and track to make them electric. The rails could be connected to the grid and draw power depending on train usage. Mainly because I don't like fuelling trains. Plus it would be cool to see electric trains.
Post Reply

Return to “Ideas and Suggestions”