Electric Locomotives, that do not require any fuel but run on electricity
Overhead lines that are required to distribute the power to the locomotives
Overhead line poles with and without integrated signals
English and German translation
Development status
I retired this project. This mod is trying to do things that are not meant to do with the Factorio API and it is a pain to find workarounds (It also hurts performance). Therefore, I decided to stop working on this project. If you want to take over the project, please message me.
If you are good with Blender (it's not hard to be better than I am) and want to help me out with the 3D Models of the locomotives, you totally can! Either PM me or create a pull request on Github, but please use the exact same camera and animation setting that I used in the sample files.
Notes on what's possible and what's not
As I used signals as the base entity for the poles it is unfortunately not possible to display the wire's reach and have that run-and-place-automatically feature from vanilla poles.
Unfortunately, due to the way I needed to implement the poles, neither the upgrade planner nor the FARL mod are compatible with this mod.
The hard cap to four modules in the modular locomotive will not be removed. It is not arbitrary - see the "internals" section for an explanation.
Issues/Bugs
If you should find any bugs in the mod, please report them over at github or the mod portal. I prefer useful, detailed bug reports, so please read this article first.
Basics
Once you have researched the Electric Trains technology, you can start crafting a bunch of overhead line poles and a few electric locomotives. Then, it's time to power up your first railway. You can use any railway you've already built, normal trains can drive on the powered sections just fine.
Placing a pole is just like placing a rail signal. In fact, there are even poles that have integrated rail signals. However, for the standard poles that don't have a signal, it doesn't actually matter, on which side of the rail they are placed.
Poles can be placed up to 16 tiles apart, but in a curve a pole needs to be at most 3 tiles away from that curve. As it is currently (0.16) not possible to draw the wire whenever it can connect, there is a warning message instead if the poles are too far apart. This can be turned off in the mod settings if you find it too annoying.
When you placed down the poles and they connected successfully, you'll see green particles to inform you that the connection is established and the green rails are now powered. Conversely, if you remove a pole, red particles show you the change to the unpowered state. If you want to see, which rails are powered or unpowered after the fact, you can use the Overhead line debugger. Simply select an area with it, and all rails show their powered state. This can be especially useful when designing intersections.
Speaking of intersections, it can get pretty messy if you install a wire on every path the train can take; on some intersection designs it is even impossible. You can consider to only power a part of the rails though: When a train travels through the intersection, it usually has enough momentum to make it through without stopping. Or, if you want to be on the safe side, just add a locomotive in either direction on either side of the train.
If you want to have signal wires between your poles, you can just install them like you would on normal power poles. The mod also offers an option to automatically install circuit wires between newly placed adjacent poles.
Once you have built a network of powered rails, you can finally add your locomotive. Simply place it on the powered rail and you're done! Of course, only if your power poles are actually connected to your power network: You can easily do this with a vanilla power pole next to it. Now, your locomotive will never need to refuel and can simply drive on and on and on (As long as you don't have a blackout of course). You'll also find that the overhead lines have a power coverage area, just like normal power poles. This allows you to place entities like lamps or inserters next to the rail without needing additional powerpoles.
There are currently three tiers of locomotives with the following characteristics. (Acceleration is compared to a vanilla locomotive running on coal)
Tier 1 (Electric Locomotive): Power usage 600kW, Top Speed 285 km/h, Acceleration 150%
Tier 2 (Advanced Electric Locomotive): Power usage 1.2MW, Top Speed 311km/h, Acceleration 200%
Tier 3 (Modular Locomotive): Power usage 1.8MW, Top Speed 311km/h, Acceleration 250%, upgradeable with modules
The modular locomotive is a special one: It has an equipment grid, which can take specialized modules to improve it's statistics. You can place up to four modules in the locomotive. An info text will pop up once you close the GUI to inform you of the new stats of the locomotive. There are multiple different setups you can try:
Add three speed modules and an efficiency module for trains that need to go long ways and have a long time to reach maximum speed
Add three productivity modules and an efficiency module for trains that need to start and stop often and need high acceleration
Add two efficiency and two battery modules to get a locomotive that can drive a long time without the need to be under a powered rail
Experiment yourself! There will be a setup just right for your needs.
Internals
INTERNALS
Entities
A powerpole consists of multiple entities that work together. First, we have the placer entity. This is the thing that is placed by the item, but is never actually used ingame. It's use is mainly to allow it to be rotated in 8 directions and to get the UI for placing a rail signal (even though a standard pole isn't one). Once the placer is built, it is immediately deleted and replaced by the actual entities.
The first is the base, which is either a constant combinator for the standard pole, or a signal for the signal pole. The purpose of the base is mainly the signal behaviour for the poles that need it. It also doubles as the attachment point for the circuit wires.
The next entity is the power consumer, which is also visible in the power GUI. The entity itself is rendered as the vertical part of the pole.
The wire holder is separated from the pole, as it needs to be on a higher render layer: The holder is quite high, so it always needs to be rendered above trains. The issue is, that the Factorio API doesn't allow modders to freely choose a render layer of every entity, therefore the wire holder is an additional one. It doesn't serve any purpose other than visuals.
The final entity is the attachment point for the copper wire. It is a completely invisible medium power pole that is placed somewhere on the rail. (It actually has a small selection box in order to allow the player to change the wiring if something with the automatic placement goes wrong).
So, overall, a pole consists of a total of four entities.
You might wonder why I didn't just use a normal power pole type and be done with it. The issue with that was, that power poles rotate whenever they want to get the "best" wiring pattern. You cannot at all force them to stay in one direction, what I obviously need for the overhead lines. Therefore, the only power pole I used is completely invisible.
Powering the trains
It would be easy if a train could simply plug in to a power area and just... work. Unfortunately, trains are locked to a burner power source. Therefore, I somehow needed to refill the fuel tank all the time. I decided to do a refill every second to save UPS, but that is configurable too.
I created a dummy fuel item, which has as much energy as a locomotive is supposed to store. This item is set to be the fuel of the locomotive. Note that it isn't actually placed in the inventory, as the electric locomotive doesn't have one, it is just set as the "currently burning item". It is set only if the fuel has run empty, which might happen when the train loses power shortly.
The next step is to find out whether the train is actually below an overhead line. To make things easier, the mod keeps a cache of all rails that are powered (remember the green icon?) and maps them to the closest power consumer in a power pole. The locomotive to update then simply checks what track it is standing on, looks in the map and if it finds a power consumer, it knows it is powered. Then, the burner fuel is topped up from that pole and the next locomotive can be handled.
All of this is unfortunately quite complicated, but it somehow works quite well.
The modular locomotive
This one is even more hacked together than the other locomotives. First, I needed some kind of inventory for the modules. Luckily, you can give locomotives an equipment grid, so I used that. However, the equipment you put in there obviously cannot change the locomotive's base stats as these are defined in a read-only prototype when the game starts.
The only way to change the acceleration and speed of the locomotive is via fuel items. Therefore, I created a bunch of dummy fuel items that are swapped out whenever the module configuration is changed. This is also the reason for the hard cap to four modules: If I allowed more, the amount of dummy items would simply explode.
If you know your math, you can calculate that with four modules picked from five options (no module is also an option of course) without taking the order into account, there are already 70 different dummy fuel items. With only one module more, there would be 126 items needed, with two more even 210! I found it quite unreasonable to create that many (pretty much unused) items, which is why the module count is capped at 4.
Re: [MOD 0.16] Realistic Electric Trains
Posted: Mon Feb 18, 2019 6:32 pm
by Optera
This is by far the closest to a proper electric train I've seen in Factorio so far.
10 ticks for update seems still a bit fast. With the power graph updating at most every 5s you could potentially get away with running every 300th tick.
Even less if you don't care about uneven power graphs.
Re: [MOD 0.16] Realistic Electric Trains
Posted: Mon Feb 18, 2019 6:36 pm
by JAetherwing
Optera wrote: ↑Mon Feb 18, 2019 6:32 pm10 ticks for update seems still a bit fast.
Honestly, I'm still experimenting quite a lot
I might change it to 60 or more ticks as I go.
Re: [MOD 0.16] Realistic Electric Trains
Posted: Mon Feb 18, 2019 7:09 pm
by Optera
A good choice is to let users set the update frequency according to their needs. Since you might also need to adjust the fuel item it would have to be a startup setting though.
Toying around a little with it I noticed some shortcomings:
only signal poles keep circuit wires when blueprinting
fake entities show up in deconstruction planner
locomotive acceleration seems too low, especially compared to the boost rocket fuel and nuclear fuel provide
Re: [MOD 0.16] Realistic Electric Trains
Posted: Mon Feb 18, 2019 7:33 pm
by WraithCadmus
Hmm, maybe hang a research off the higher levels of Braking Force to bump the acceleration?
EDIT: Also Optera knows more about trains that anyone else I know
Re: [MOD 0.16] Realistic Electric Trains
Posted: Mon Feb 18, 2019 9:29 pm
by Optera
WraithCadmus wrote: ↑Mon Feb 18, 2019 7:33 pm
Hmm, maybe hang a research off the higher levels of Braking Force to bump the acceleration?
EDIT: Also Optera knows more about trains that anyone else I know
Sadly you can't add acceleration research.
Only thing you could do is swap the fuel item for one with a higher acceleration and top speed bonus after completing a research. But it wouldn't show the speed bonus in the bonus overview tab only directly on the locomotives.
Factorio has a fuel progression system making it hard to add locomotives with different fuels feel balanced alongside the base locomotive.
For my train overhaul mod I went and also rebalanced all fuel boni so locomotive upgrades had meaning.
No matter how much you know, there's always someone knowing more.
Re: [MOD 0.16] Realistic Electric Trains
Posted: Mon Feb 18, 2019 10:06 pm
by JAetherwing
Optera wrote: ↑Mon Feb 18, 2019 7:09 pm
A good choice is to let users set the update frequency according to their needs. Since you might also need to adjust the fuel item it would have to be a startup setting though.
Toying around a little with it I noticed some shortcomings:
only signal poles keep circuit wires when blueprinting
fake entities show up in deconstruction planner
locomotive acceleration seems too low, especially compared to the boost rocket fuel and nuclear fuel provide
Good idea on the configurable update time, I'll add that to my ToDo list.
For the other points you mentioned, I'm honestly a little bit at a loss... I have actually posted a question about the blueprinted circuit wires in the Mod Help Forum, but didn't get any useful answer yet. The problem is that I use placer entities in order to get the rail signal placement indicators, but this then breaks ghost wire connections.. If you know how to fix that, I'd really appreciate any help
Finally, acceleration will be set a bit higher, but there'll be some higher tier locomotives anyway sooner or later.
Re: [MOD 0.16] Realistic Electric Trains
Posted: Tue Feb 19, 2019 7:45 am
by Optera
Preserving connections from blueprints is not straight forward, as you probably already guessed considering what you did to make the poles look nice.
You have to allow the entity with connectors into blueprints and make it placable (bp mustn't turn red).
In your on_built_entity and on_robot_built_entity handler you then have to find the ghost entity belonging to the created pole and if it exists revive it otherwise create a new one like you currently do.
Caveats:
There's a lot terribly written mods out there messing with blueprints and ghost entities. My advice don't accommodate for their bad writing and have them fix their code. Creative Mode for example has an interface to add ghosts it should never touch into a blacklist.
Re: [MOD 0.16] Realistic Electric Trains
Posted: Tue Feb 19, 2019 2:04 pm
by yukinyaa
hey hey github link is broken
Re: [MOD 0.16] Realistic Electric Trains
Posted: Tue Feb 19, 2019 2:59 pm
by JAetherwing
Uhm... That shouldn't be the case. The link works totally fine for me, even from a different computer. What error do you get?
As I used signals as the base entity for the poles it is unfortunately not possible to display the wire's reach and have that run-and-place-automatically feature from vanilla poles.
This might be a very long fetched idea, but rail signals could be connected with red/green wires. Would it be possible to achieve a visual wire feedback system with 'listening to whenever an electric pole is being placed it is also automatically connected with a custom wire'?. That wire should have a range that can be modified and thus at least should achieve some visual feedback. Not sure how much fiddeling this would be, especially since the poles around the corner have a slightly smaller range...
Just an idea I guess, maybe it would be worth to just wait out 0.17
Re: [MOD 0.16] Realistic Electric Trains
Posted: Tue Feb 19, 2019 10:52 pm
by timer67
Hey, was enjoying this mod in my singleplayer game but it seems to be causing instant desync issues in Multiplayer
Re: [MOD 0.16] Realistic Electric Trains
Posted: Wed Feb 20, 2019 7:16 am
by JAetherwing
I'd appreciate a little bit more information about the problem you face in order to resolve it.
I know it's cliché, but "It works on my machine"
Re: [MOD 0.16] Realistic Electric Trains
Posted: Wed Feb 20, 2019 9:29 am
by Optera
Debugging MP desyncs is a royal pain. Unlike other bugs where we see exactly what line caused it, all information we ever get from desync reports is it happened.
Check if data anywhere in a local table or variable can change during runtime and might be different when players join running games.
Re: [MOD 0.16] Realistic Electric Trains
Posted: Wed Feb 20, 2019 3:23 pm
by timer67
Yeah, there is literally no error.
Just <Player> Desynced.
Same every time on a connection.
Re: [MOD 0.16] Realistic Electric Trains
Posted: Wed Feb 20, 2019 6:46 pm
by eduran
Your on_tick handler looks like a good suspect for the desync issue.
local dummy_fuel
local dummy_fuel_value
local max_transfer = config.loco_max_energy_transfer_val
function on_tick(event)
if event.tick % 10 == 0 then
if not dummy_fuel then
dummy_fuel = game.item_prototypes["ret-dummy-fuel-1"]
dummy_fuel_value = dummy_fuel.fuel_value
end
.......
Player A creates the game, triggers on tick and dummy_fuel is set -> Player B joins on one of the 9/10 ticks without update -> at the end of that tick, dummy_fuel and dummy_fuel_value are different for player A and B -> desync
Re: [MOD 0.16] Realistic Electric Trains
Posted: Wed Feb 20, 2019 6:55 pm
by JAetherwing
I thought so too, but then I apparently was extremely lucky to not get desynced for a few dozen times.
Are local variables included in the crc check though? And if so, where should I cache the prototypes instead? I can't access the game object in the on_load event for instance.
I can (and probably will) move the current assignment out if the if block that checks the tick number though.
Re: [MOD 0.16] Realistic Electric Trains
Posted: Wed Feb 20, 2019 7:06 pm
by Mohit
Hello, your mod is that what i was looking for for longer time here in factorio, but you should try to add soudn to locomotive like is in nuclear locomotives, that real electric train engine. Second thing which would be better is to have possibility to place those electric rail poles in some way like normal electric poles, or similiar way, its hard to know where exactly put that pole
One more thing try add higher tiers of locomotive or something electric trains have better speed usually than diesel engine locomotives and more power.
Re: [MOD 0.16] Realistic Electric Trains
Posted: Wed Feb 20, 2019 7:12 pm
by eduran
You cannot desync in singleplayer, if that is what you tested. And yes, local variables are included.
I would probably store it in global. Moving the assignment directly into on_tick should also do the trick, with the downside of performing a mostly useless check on every tick (which is not a big deal).
Re: [MOD 0.16] Realistic Electric Trains
Posted: Thu Feb 21, 2019 7:17 am
by psihius
You can also use `on_nth_tick` event instead of doing division in the `if` statement every tick