Page 1 of 1

[MOD 0.17] Multiple Unit Train Control

Posted: Sun Mar 17, 2019 5:33 pm
by robot256
Type: Mod
Name: Multiple Unit Train Control
Description: Lets locomotives provide backwards force in automatic if they are in a bidirectional pair.
License: MIT
Source: GitHub
Download: mods.factorio.com
Version: 0.1.4
Release: 2019-03-27
Tested-With-Factorio-Version: 0.17.17
Category: Helper, Train
Tags: Train

Have you ever wished that all your locomotives would provide acceleration when running automatically, not just the ones facing forwards? You're not alone! With the power of Multiple Unit Train Control (MU Control) technology, a coupled pair of locomotives (an MU consist) can drive in either direction using the power of both!

Summary
Simply take two locomotives of the same type and couple them together facing opposite directions. Now you have an MU consist of two locomotives that can drive in either direction with the force of two locomotives. It will also consume fuel at the rate of two locomotives. Research Wireless MU Control and you can put wagons in between the two locomotives and still get the power boost.

This mod is meant to be an alternative to Noxy's Multidirectional Trains. I created it specifically to work with the Automatic Coupling System mod, because constantly uncoupling, reversing, and recoupling the trains interferes with the train alignment required to do realistic yard switching. MU Control only modifies the train when the locomotives are first linked, so it doesn't change anything while coupling and uncoupling wagons automatically.

Details
Under the hood, MU Control detects when a train is created with opposite-facing locomotives of the same type, and silently replaces them with a different entity, the "MU version", that have twice as much power as before. As long as those two locomotives do not separate, MU Control never changes the train again. If an MU locomotive is found to be without its twin, MU Control will immediately replace it with the normal version.

Since the game still thinks only one locomotive is driving, but with twice the power, the front locomotive will use twice as much fuel and the back won't use any. MU Control automatically balances fuel between them periodically, so the single-direction range of the two together is the same as if they were both facing forward. You can set the frequency of balancing or disable it in the mod settings. If you let it drain to empty, it won't balance the last unit of fuel.

Four modes can be selected in the mod settings:
  • Basic mode: Locomotives that are adjacent or separated by other locomotives can form MU consists. Examples: <L-L>, <L-<L-L>-L>
  • Advanced (Wireless) mode: Locomotives can form MU consists anywhere in the train. Examples: <L-W-W-W-W-L>, <L-<L-W-W-L>-W-W-L>
  • Tech Unlock mode: MU upgrades remain disabled until you complete research MU Control technology. Unlock Wireless mode with a second research technology. Note: After researching a new level, you must manually trigger an MU Control update on each existing train by coupling and uncoupling a wagon. This is to prevent instant upgrades from destroying trains if they are currently moving over a junction.
  • Disabled mode: Reverts all MU locomotives to normal. Note: Mod defaults to Disabled so that you have time to stop all your trains before enabling it.
Features
  • Upgrading and downgrading locomotives preserves color, name, health, fuel inventory, equipment grid, burner heat, and train schedule.
  • Detects when the player uncouples locomotives of an MU consist.
  • Mining, blueprinting, or pressing 'Q' over an MU version will produce its standard version.
  • Mod setting to configure frequency for fuel balancing.
  • Currently supports: Vanilla, Train & Fuel Overhaul, Angle's Petrochem Train, Angel's Smelting Train
Planned Features Known Issues
  • When installing, enabling, or disabling the mod on an existing map, trains that are moving across an intersection during the upgrade may be disconnected, damaged or destroyed in the process.
  • The MU version of each locomotive type is not craftable and should never end up in your inventory, but sometimes it does. It will revert as soon as you place it on a track.
  • When a locomotive is replaced, the train is changed to manual mode. Since you cannot automatically couple two locomotives without them running into each other, creation of an MU consist is expected to be a manual process, but after upgrading a save file you will have to set trains back to automatic.
  • Train kill statistics may not be preserved when upgrading/downgrading locomotives.
  • Mode is currently a runtime setting, so MU Control technologies will be available to research even if you have set MU Control to ignore them.
  • The MU version has a separate item-type circuit signal, which I assume will be faithfully utilized by LTN stops when outputting train rolling stock descriptions. Not a bug, but don't click the wrong one by accident on your crafting machine inserter.
  • When placing *fueled* locomotives via blueprint, fuel item requests will be cancelled when the locomotives are upgraded.
Credits:
Noxy - Multidirectional Trains, which gave me the idea and some examples of train manipulation.
Optera - Train & Fuel Overhaul, which taught me how to make altered entities, and for releasing their copyPrototype library function to public domain.
Train30 - Created the icon graphics for MU Control technologies.
kryshnar - Provided French locale.

Re: [MOD 0.17] Multiple Unit Train Control

Posted: Sun Mar 17, 2019 8:18 pm
by Optera
Good idea for realism.
To get top speed in bidirectional trains though you'd need to have MUs in front and back. Otherwise the wagons higher wind resistance will limit speed and acceleration.

Edit: Seems like you can overcome drag with sheer power.
Train Overhaul locomotives make little difference between pulling and pushing. Nuclear locomotives are even 1m ahead when pushing wagons. :lol:

Re: [MOD 0.17] Multiple Unit Train Control

Posted: Sun Mar 17, 2019 8:41 pm
by robot256
Yup, Radio Controlled MUs is the next feature to add, and I know how to do it now. Wasn't sure if I could do it when I started the project 4 days ago. 8-)

Re: [MOD 0.17] Multiple Unit Train Control

Posted: Mon Mar 18, 2019 3:56 pm
by robot256
Nuclear locomotives are even 1m ahead when pushing wagons. :lol:
Sounds like I need to stick an express loco on the front of my nuclear long-haul trains to act as a wind breaker!

Re: [MOD 0.17] Multiple Unit Train Control

Posted: Sat Mar 23, 2019 3:03 pm
by robot256
I made a rail yard as a stress test for Automatic Coupling System and Multiple Unit Train Control!

https://youtu.be/BIac31j_snU

Re: [MOD 0.17] Multiple Unit Train Control

Posted: Mon Jan 01, 2024 4:01 am
by Degraine
I finally (finally) got all the issues sorted out for adding support for my mod to MUTC. I've uploaded an updated version of my mod to fix some problems, and here's the patches for your side of things.

In generate_all_mu.lua:
Replace

Code: Select all

-- Add Degraine's Electric Locomotive to blacklist if present
if mods["ElectricTrains"] then
  mu_blacklist["electric-locomotive"] = true
end
with

Code: Select all

-- Add dummy fuel item for Degraine's Electric Locomotive if present
if mods["ElectricTrains"] then
  local dummy_fuel = flib.copy_prototype(data.raw["item"]["deg-electric-locomotive-fuel-dummy"],"deg-electric-locomotive-fuel-dummy-mu")
  dummy_fuel.fuel_value = multiply_energy_value(dummy_fuel.fuel_value, 2)
  data:extend{dummy_fuel}
end
And in control.lua, inside the CallRemoteInterface() function, add

Code: Select all

  -- Register MU version of Degraine's Electric Locomotive
  if remote.interfaces["electrictrains"] then
    remote.call("electrictrains", "register", "deg-electric-locomotive-mu", "deg-electric-locomotive-fuel-dummy-mu")
  end
And that should take care of everything. If I need to do balance changes it should adjust the fuel value without any further input on your side.