Battery-Electric Train

by catweax

Electric trains, but UPS-friendly. Provides battery-powered locomotives, reusable battery packs and charging facilities. Balanced for vanilla gameplay by default, but trains can be as fast as you want.

Content
5 months ago
1.1 - 2.0
17.2K
Trains

g Battery capacity issue

2 months ago

The root cause of this issue is how the mod computes the capacity of the four tiers of batteries. It's the computation on line 72 of items.lua that evaluates fuel_value.

Right now, it appears to be setting the capacity to 3 times the "vanilla" fuel energy content (e.g. coal being 4 MJ) times the "vanilla" fuel stack size.

So a tier 1 battery has a capacity of 3 * 4MJ * 50 i.e. 600 MJ

The inconsistency happens when you compare tier 3 and tier 4 batteries.

T3 is 3 * 100MJ * 20 =. 6 GJ
T4 is 3 * 1.21GJ * 1 = 3.63 GJ

Net result: for maximum range, use tier 3 batteries.

My suggested fix would be to add a final multiplier factor as a 7th parameter to AddFuel(), pass that parameter to FullFuel(), and then on line 72 multiply the current result by this new multiplier factor to get the final capacity. In my extremely humble opinion, tiers 1, 2 and 3 don't need to change, but tier 4 needs a multiplier of at least 3 (10.89 GJ) if not 4: (14.52 GJ).

Needless to say, this assumes that the desire is to have monotonically increasing capacities as the tier increases. A valid design option is to leave it the way it is, so you would have to decide between tier 3 for long haul trains, and tier 4 for faster short haul routes.

2 months ago

You got me quite confused with that stray point before the 6 GJ, because 3.63 GJ is more than (0).6 GJ.

At any rate, the fuel tiers were implicitly intended to be monotonically increasing because that what you originally got when fueling a locomotive with the four available combustible fuels. I made this mod for Factorio 1.1, so “originally” means 1.1, in which the stack size for rocket fuel was 10, yielding 3 GJ of energy in a fully fueled locomotive. Factorio 2.0 changed the stack size to 20, which produces the inconsistency you mentioned.

The thing is: Don’t you have exactly the same inconsistency when fueling a locomotive with combustible fuel in Factorio 2.0? Filling it with 60 rocket fuel would give you more capacity than fueling it with 3 nuclear fuel, so the trade-off is exactly the same there.

This mod was intended to provide a mostly equivalent replacement for the stock locomotive, which is the reason why the battery pack capacities are calculated based on item stack sizes multiplied by 3: because that’s exactly what can be loaded into a stock locomotive. Therefore, I would argue that the capacity inconsistency you observed means that the mod is exactly working as intended. You can choose between either more range with T3 battery packs, just like when using rocket fuel, or higher acceleration with T4 battery packs, just like when using nuclear fuel.

2 months ago
(updated 2 months ago)

Got it. I've seen in other discussions that this is supposed to work with the absolute bare minimum of changes, thus the reason for the locomotives and batteries being based on the vanilla "burner" locomotive and vanilla fuel sources respectively. So I can accept that this can be closed "working as intended", and indeed that makes for that interesting decision. Do I use T3 batteries for maximum range, or T4 for maximum speed?

Choices like this are very definitely a good part of a well designed game, it's better when there isn't a clear "this is the best choice" solution, so we have to make that decision. 👍

2 months ago
(updated 2 months ago)

I can’t claim that choice as my own, so make sure to direct that praise at the Factorio makers.

I’ll add another entry to this mod’s FAQ page, in case anyone else is wondering about that inconsistency and somehow ends up on the FAQ page.

Also, do you still remember in which other discussions you’ve seen that? I’m curious about other users talking about the mod, as pretty much all the feedback I’m getting here is about bugs and incompatibilities.

2 months ago

It wasn't in another discussion, that's my mistake. I was figuring this out from both looking at the code, as well as the FAQ entry that talks about performance.

New response