LTN - Logistic Train Network - Manual

Adds new train stops forming a highly configurable logistic network.

Moderator: Optera

User avatar
Smart Inserter
Smart Inserter
Posts: 2074
Joined: Sat Jun 11, 2016 6:41 am

LTN - Logistic Train Network - Manual

Post by Optera » Thu Jul 20, 2017 6:26 am

Type: Mod
Name: Logistic Train Network
Description: Adds new train stops forming a highly configurable logistic network.
License: private use only, no modification, no redistibution, no commercial use
Source: GitHub
Download: Mod Portal
Version: 1.10.11
Release: 2019-05-28
Tested with Factorio Version: 0.16.51 / 0.17.42
Category: (Train)
Tags: logistic, train

Demo Map:
LTN Demo
Demo Map for LTN 1.9.10 - requires no mods other than LTN
(3.23 MiB) Downloaded 757 times
Small map running 5 trains in nearly realistic fashion. Showcasing station designs from simplistic 1 combinator to depots using train compositions and a truly universal provider/requester station.

Designs for stations, depots, control circuits and more can be found in the Design thread.

Video Tutorial:
Thanks to Nilaus for creating this very basic tutorial.

Long Description:
After brooding for weeks over ideas in this thread I sat down and wrote this as proof of concept.
Big thanks to Choumiko. Seeing how certain things work in Smarter Trains and Rail Tanker made writing this mod a whole lot easier.

This mod adds one new train stop "logistic-train-stop" acting as anchor points for building a train powered logistic network.
Stops consist of 3 entities, the stop itself and the automatic placed lamp (input) and yellow constant combinator (output).
Stop Entities
2016-11-20-11-52-03-3807521.jpg (41.26 KiB) Viewed 88144 times
Stop: (behaves like base stop)
  • read from train enable by default
  • send to train enabled by default

Constant Combinator: (signal output)
  • train composition: position of wagons & locomotives in parked train (all stops)
    binary encoded signal of train composition up to 31 carriages with lsb at the train stop. More information about binary encoding here
  • Expected train inventory after un-/loading is complete. (only Requester & Provider)

Lamp: (color coded status)
Values can only be read through green wire.
  • green = 1: normal status
  • blue = n: LTN Controlled Train parked at stop, n = number of trains
  • yellow = n: Stop is part of a scheduled delivery, n = number of trains
  • white = 1: Error - not initialized
  • red = 1: Error - short circuit
  • red = 2: Error - deactivated stop
  • pink = 1: Error - duplicate station name (only Depots may use duplicate name)
Lamp: (signal input)

All Stops:
Image Encoded Network ID - Binary coded signal assigning a stop to specific networks. (defaults to 0xFFFFFFFF = all networks)
Deliveries are only generated when between Depot, Provider, Requester within the same network. Stops can be assigned to multiple networks e.g. 6 assigns a stop to networks 2 and 4.

Depot: (ignores Requester & Provider signals)
Image Stop is Depot - flags this stop as depot (default=0 false)

Requester & Provider:
Image provided items (positive number) and requested items (negative number)
Image minimum train length (optional) - minimum length of locos + wagon allowed in this station (default=0 no limit)
Image maximum train length (optional) - maximum length of locos + wagon allowed in this station (default=0 no limit)
Image limit trains (optional) - number of trains (deliveries) allowed simultaneously at this station (default=0 no limit)

Image Request Threshold (optional) - Missing amount of items/fluids triggering a delivery. (global default=1000)
Image Request Stack Threshold (optional) - Missing amount of item stacks triggering a delivery. Takes priority over Request Threshold.
Image Request Priority (optional) - higher priority will be served first (default=0)
Image Disable Warnings (optional) - Suppresses warnings, like no station supplying x found, for this Requester. (default=0 false)

Image Provide Threshold (optional) - Amount of items/fluids required to act as provider. (global default=1000)
Image Provide Stack Threshold (optional) - Amount of item stacks required to act as provider. Takes priority over Provide Threshold.
Image Provider Priority (optional) - higher priority will be used first (default=0)
Image Locked Slots per Wagon (optional) - number of inventory slots per wagon locked for this provider (default=0 false)

Odhrean made this graph depicting what delivery size is used depending on thresholds and train size in a setup with 1 requester and 1 provider using L-4C trains.
LTN_Request_Provide_Threshold.png (54.34 KiB) Viewed 33404 times
Changelog: ... /changelog

User avatar
Smart Inserter
Smart Inserter
Posts: 2074
Joined: Sat Jun 11, 2016 6:41 am

Additional information

Post by Optera » Fri Jul 21, 2017 5:46 pm

Planned features:
Will potentially be changed/added soon™ in no particular order.
  • merge stops to one logical unit
    Honestly I don't know if I'll ever get to it.
Rejected features:
Reoccurring requests that either can't be implemented or don't align with my vision for LTN.
  • limit trains by composition signal #93
    Can't be done. Composition signal is ambiguous outside a specific stop.
  • Dispatch new order at request station viewtopic.php?f=214&t=51770
    Could be done with annoying limitations and a lot of overhead. Details explained in the topic.
  • Button - Return all Trains to Depot viewtopic.php?f=214&t=53195
    Can't be done safely without API exposure of the pathfinder.
  • Relative Thresholds viewtopic.php?f=214&t=61852
    Certainly nice to have, just not feasible to implement.
Incompatible Mods:
FAQ / Known Issues:
  • Trains not running deliveries
    1. Check provide and request threshold, if none is set global setting is used
    2. Check if train size is plausible between requester and provider
    3. Check if Network ID is plausible between requester, provider and depot
  • Changing train composition makes trains switch to manual mode.
    Workaround for this behavior. After you're done rearranging trains send them back to the depot in automatic mode to register with LTN again.
  • updating mods using mod settings breaks settings. viewtopic.php?f=28&t=45308#p261686
    manually revert settings to default after updating
  • controlling pumps with circuit network for unloading will make them stop early
    Support stop output should round up fluids
    Meanwhile don't use Stop output fluid values to control pumps for unloading. Use Inventory Sensor instead to have fluids always rounded up.
  • trains longer than 31 carriages don't display train composition signals
    Nothing I can do about that, the circuit network is signed int and can only display 31 bits.

User avatar
Smart Inserter
Smart Inserter
Posts: 2074
Joined: Sat Jun 11, 2016 6:41 am

Remote Interface

Post by Optera » Sun Feb 10, 2019 3:46 pm

register to event in on_init and on_load:

Code: Select all

local on_dispatcher_updated_event ="logistic-train-network", "on_dispatcher_updated")
script.on_event(on_dispatcher_updated_event, dispatcher_updated_handler)
consume event handler like base game events:

Code: Select all

local function dispatcher_updated_handler(event)
  -- print all event properties
Interface - Demo code: ... ontrol.lua
Interface - Event data structure 1.10.7:
Raised every UpdateInterval, after delivery generation

event.logistic_train_stops = { [stopID], {
-- stop data

-- control signals

-- parked train data

Raised every UpdateInterval, after delivery generation

event.update_interval = int -- LTN update interval (depends on existing ltn stops and stops per tick setting
event.provided_by_stop = { [stopID], { [item], count } }
event.requests_by_stop = { [stopID], { [item], count } }
event.deliveries = { trainID = {force, train, from, to, networkID, started, shipment = { item = count } } }
event.available_trains = { [trainID ], { capacity, fluid_capacity, force, network_id, train } }

Raised when no train was found to handle a request

Contains: = requester.backer_name
event.to_id = requester.unit_number
(optional) event.item
(optional) event.from
(optional) event.from_id
(optional) event.minTraincars
(optional) event.maxTraincars
(optional) event.shipment = { [item], count }

Raised when a train leaves provider stop

event.trainID = {force, train, from, to, networkID, started, shipment = { [item], count } } -- updated shipment to current train inventory
event.original_shipment = { [item], count } }

Raised when train leaves requester stop

event.trainID = {force, train, from, to, networkID, started, shipment = { [item], count } }

Raised when rolling stock of a train gets removed or the delivery timed out

event.trainID = {force, train, from, to, networkID, started, shipment = { [item], count } }


Return to “Logistic Train Network”

Who is online

Users browsing this forum: No registered users