Flag to allow rear facing locomotives to power trains

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
Zanthra
Fast Inserter
Fast Inserter
Posts: 206
Joined: Fri Mar 25, 2016 8:18 am
Contact:

Flag to allow rear facing locomotives to power trains

Post by Zanthra »

How difficult would it be to make a flag to allow locomotives to provide power in reverse in automatic mode? Currently having a locomotive on the back facing forwards provides full power, but if the locomotive is facing backwards it provides none and has to be fully pulled around by the front locomotive (interestingly, you can also have the locomotive at the front facing backwards, and the locomotive at the back facing forwards and you end up with a train that will happily drive either direction in automatic, but only the pusher locomotive at the rear is operating). I would like make a mod that would allow the rear locomotive to provide power even if facing the wrong direction. A flag that allows the current reversing power to apply in automatic would be nice, but a separate modifier for automatic mode would be better as then it could apply full power in automatic while still being more controlled when the player is backing trains up.

It would also be nice if there was a property on trains that could be set true to allow a train to attempt to path backwards even if all locomotives are facing one direction so that single locomotive trains could be set to use terminus stations.

In summary (example names):

For prototype type of "locomotive":

reversing_power_modifier_automatic
If greater than 0, the locomotive will provide that percent of power when the train is traveling in the opposite direction to the direction the locomotive is facing while running in automatic mode..

For entity LuaTrain:

path_reverse
If false, and all locomotives on the train are facing the same direction, the train will only attempt to find an automatic path in the direction the locomotives are facing.
If true, and at least one locomotive has reversing_power_modifier_automatic > 0, attempt to find a path backwards as well as forwards to it's destination.
If the train has at least one locomotive facing each direction, then train pathfinding is done both ways as it currently does.
Last edited by Zanthra on Sat Jun 23, 2018 2:17 am, edited 9 times in total.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5200
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Add flag to allow reversing_power_modifier in automatic mode

Post by eradicator »

Hah, you stroke out that part before i could write an answer :P.

Concerning power providing in "reverse" mode...i just looked that up and it looks like in real world applications neither electrical nor mechanical locomotives suffer any significant penalty (except air friction) for going "backwards", so the whole mechanic of backwards-facing locomotives not providing power is an odd game design decision...?

Conclusion: Definetly +1 to allow backwards facing locos to provide power (they already do in manual i think).
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Zanthra
Fast Inserter
Fast Inserter
Posts: 206
Joined: Fri Mar 25, 2016 8:18 am
Contact:

Re: Add flag to allow reversing_power_modifier in automatic mode

Post by Zanthra »

eradicator wrote:Hah, you stroke out that part before i could write an answer :P.

Concerning power providing in "reverse" mode...i just looked that up and it looks like in real world applications neither electrical nor mechanical locomotives suffer any significant penalty (except air friction) for going "backwards", so the whole mechanic of backwards-facing locomotives not providing power is an odd game design decision...?

Conclusion: Definetly +1 to allow backwards facing locos to provide power (they already do in manual i think).
In the entity definition for locomotive there is a property:

Code: Select all

reversing_power_modifier = 0.6,
This affects the ammount of power the locomotive applies in reverse when being operated manually, and when there are no locomotives on that train facing the other direction. If you have 3 locomotives (0.6MW each facing forwards it has 1.8MW of power forward, and 1.08 MW in reverse. If you have the same three with two forward and one reverse, you have only 1.2MW forward, and ony 0.6MW in reverse, but the latter can operate both forward and reverse in automatic mode.

As for why this was designed this way, now that I know trains are fine with the locomotive at the rear, it could cause a lot of problems for train networks if trains that had all locomotives facing one direction could calculate a path to the destination station in reverse. Then when it arrives, the last cargo wagon is where the locomotive should be, with an inserter dutifully loading it full of fuel while the locomotive is stripped bare and the coal is sent to the furnaces as ore; so it might have something to do with avoiding problems related to that.

It could also be an asthetics issue with trains driving in reverse not looking as cool, or if trains with Cargo Wagon, Locomotive, Cargo Wagon becomes a very efficient single locomotive train setup because the stations can work if it comes in forward or reverse, but would look a bit silly.

Or based on the fact that trains are generally not as stable in push configuration than pull (ignoring the fact that forward facing push locomotives work fine in factorio).

Or perhaps they thought there would be balance issues if 1-4-1 trains with terminus stations were as fast as 2-4 trains with roro stations.

Perhaps that was just the way it worked when someone wrote it into the code without much thought beyond getting trains to move around automatically, and it has worked so far.

Perhaps the reasons are long forgotten.

I would like it to be opened up to modders even if there are good reasons not to change it in the base game.

The second part of this request would be an option that can be set per train that if all the locomotives (perhaps just one) on the train are facing one direction, should it attempt to path in reverse to get to it's next stop. If this is left false, then it won't break train networks by entering stations in reverse when it would not now.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5200
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Add flag to allow reversing_power_modifier in automatic mode

Post by eradicator »

Zanthra wrote:Perhaps that was just the way it worked when someone wrote it into the code without much thought beyond getting trains to move around automatically, and it has worked so far.
I think i'll put my bet on this one :).

You're right thought that it would be weird if all trains tried pathing in both directions (though with any signals around they couldn't most of the time). But form a pure power contribution standpoint it'd still be nice if a train with at least one loco in each direction had the same power in both directions. As you also noticed factorio doesn't really care about push/pull which would be the only realistic reason to limit power (due to tensile/compression properties of metal).

As a side node i've actually used CCLLCC two-way trains, though not much. Partially because of the looks and partially because it's not actually that great to have to deliver fuel to the middle and and unload from the ends.

Maybe an even nicer solution would be to have a "dual-headed" flag for modded loco prototypes that "simply" allows that prototype to act as both forward and backward loco at the same time. You'd lose the granularity of specifying how much % backwards power it can supply, but overall the effect would be similar. (Hm. Could this actually be "faked" by usind two modded half length, half weight locos? Inventory/Animation would break i guess. :()
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Zanthra
Fast Inserter
Fast Inserter
Posts: 206
Joined: Fri Mar 25, 2016 8:18 am
Contact:

Re: Flag to allow rear facing locomotives to power trains

Post by Zanthra »

After the last Friday facts, I figured it would be okay to bump this. If this is a won’t implement, no problem, but I think it’s a reasonable addition.

Thanks

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2809
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: Flag to allow rear facing locomotives to power trains

Post by Optera »

Even steam locomotives where capable of running full power in reverse (though they hardly ever did it) if they had something akin to a cars gearbox: https://en.wikipedia.org/wiki/Walschaerts_valve_gear

I don't see how pathfinding in both directions is any hindrance against implementing locomotives running full power both ways.
If players don't want locomotives to change direction they can use signaling to prevent that.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5200
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Flag to allow rear facing locomotives to power trains

Post by eradicator »

Optera wrote:If players don't want locomotives to change direction they can use signaling to prevent that.
I see no particular need to completely remove one-way locos. Just check if there's locos placed in both directions, or add a checkbox to the loco settings. This topic is imho only about power not about layout. Especially because factorio trains don't magically turn around when leaving a station (like in OTTD), so wagon order matters, and an unexpectedly reversed train can poison your whole main bus before you know it.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2809
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: Flag to allow rear facing locomotives to power trains

Post by Optera »

Having to change every existing locomotive to bi-directional one by one on a map with over 300 locomotives would be annoying.
A game setting to enable bi-directional power and pathfinding for all locomotives would be the best solution.

Alternativly if it's only a checkbox per locomotive it should be exposed to the api. A mod switching all locomotives is whipped together instantly.

ukezi
Filter Inserter
Filter Inserter
Posts: 385
Joined: Sat Jul 02, 2016 11:02 pm
Contact:

Re: Flag to allow rear facing locomotives to power trains

Post by ukezi »

I think there shouldn't be any problem. Make it that way you still need a forward facing locomotive, but any reverse facing also contribute power. The way I would program trains, they would be a construct with a mass and forward and backward power, contributed by the locomotives paced ether way. Then you would just have to change that calculation and have the reversing locomotives also consume flue and so on.

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

Re: Flag to allow rear facing locomotives to power trains

Post by bobingabout »

mods can actually specify how much reverse power a locomotive has, and for the base game locomotive, I believe this is 50%. So even if you only account for this one, the rear facing locomotive of a double headed train should contribute 50% power to assist the train.

With my mod, the MK3 locomotive provides 90% power (I think) which means there's no signignificant difference to having a double headded train, or a train with 2 lead locos, but the game itself doesn't utilise the rear facing locomotives.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2809
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: Flag to allow rear facing locomotives to power trains

Post by Optera »

Sadly reversing_power_modifier is only effective in player driven trains and has no effect on automatic trains whatsoever.

orzelek
Smart Inserter
Smart Inserter
Posts: 3853
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Flag to allow rear facing locomotives to power trains

Post by orzelek »

Optera wrote:Sadly reversing_power_modifier is only effective in player driven trains and has no effect on automatic trains whatsoever.
It would be cool if it actually worked in automatic. Then setting it to 1 would make locos a bit more like normal locos which don't care about directionality most of the time.

Zanthra
Fast Inserter
Fast Inserter
Posts: 206
Joined: Fri Mar 25, 2016 8:18 am
Contact:

Re: Flag to allow rear facing locomotives to power trains

Post by Zanthra »

Optera wrote:Sadly reversing_power_modifier is only effective in player driven trains and has no effect on automatic trains whatsoever.
It's only effective in player driven trains that have no locomotives facing the other direction. If you build a train with 5 forward facing locomotives, and drive it backwards, it's does decently well. If you make it 4 forward, and 1 backwards, and try driving it in reverse manually, suddenly the single backwards locomotive has to haul the other 4 around with no help. ;)

I have since posting this started feeling that this thread may be better suited to the balance forums, as it touches on a lot of questions of whether it should be this way or another in the base game, although I would still like to see it available to moders even if nothing is changed in the base game balance.

Aphelius
Burner Inserter
Burner Inserter
Posts: 13
Joined: Mon Apr 23, 2018 7:43 am
Contact:

Re: Flag to allow rear facing locomotives to power trains

Post by Aphelius »

Bumping because the point is still valid.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1088
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Flag to allow rear facing locomotives to power trains

Post by Pi-C »

While it certainly would be nice if it worked in vanilla, there already is a mod for it. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Post Reply

Return to “Modding interface requests”