Using LTN Mod source?

Adds new train stops forming a highly configurable logistic network.

Moderator: Optera

Post Reply
nljr
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue May 30, 2017 2:32 am
Contact:

Using LTN Mod source?

Post by nljr »

I see the source for LTN is marked "No Modification - Although I can't stop you from looking at my code, you are not allowed to distribute anything altered, or derived from my code without explicit permission first."

So, here's what I would like to try:

First: The LTN Combinator (https://mods.factorio.com/mod/LTN_Combinator_Modernized) is a huge help and I would like to simplify my builds by merging it into the train station. It's an MIT license which allows non-commercial use with modifications. I'd like to slip it right in to replace that green light which is part of the station.

Second: I've had a problem with stations that both request and provide items. If an item being requested ever gets over-filled (whether it's a train that comes in with more than requested or me stuffing the box), the signal going to the station becomes positive. USUALLY, the provide threshold will prevent any trouble.

But when a product is badly over-stocked, it looks *exactly* like providing the resource to LTN. So LTN will send a train to pick up an item which is supposed to be requested, not provided. This train never gets filled and causes endless traffic jams.

The simplest fix is to stop letting stations both provide and request, it's too late in my current run, and also very convenient, so I might not be able to give it up.

I can correct this with combinators, but it's delicate, error prone and complex. I have to deduct the request from the inventory, then filter out positive values. But then any products the station is supplying must be wired separately. Worse, all the other settings like stack thresholds from the LTN combinator are positive. So to avoid suppressing those signals, I can't put the requests directly into the LTN combinator. Guess I could use two, but that's SUPER confusing. One of the big advantages of the LTN combinator is the ability to make requests in stacks.

I think that's the best I can do with the LTN combinator separate from the station.

Merging the LTN combinator into the station would mean the LTN logic directly knows about requests. It could actually detect the difference between a provided resource and a massive over-stock. I would add a signal to ignore the overstock while still providing other products. Someone has probably built a station that can automatically switch between providing and supplying and they'd want to disable the overstock protection.

Those are the main things I want to try, but once I've experimented with the code, I might try a couple more fixes.

First stretch goal:

The remaining content to be loaded can be calculated as LTN Request - Train content. Let's call that "TBL" for "To Be Loaded" This is a common formula people use to control the inserters loading a train. In practice, TBL can be calculated with two combinators that are cookie-cutter and easy to blueprint. Still, it would be cool if that logic were built-in to LTN. Maybe with a flag to turn it on. I wouldn't bother if that was the only thing I was fixing, but its not.

In a high-speed station using 12 stack (bulk) inserters, there can be over 100 items in the hands of the inserters at once PER car. If the product happens to be solid rocket fuel or something else with tiny stack size, that can be 10+ stacks per car. Reserving 10 empty slots seems pretty extreme, so I came up with combinators to reduce the problem. Force stack-size for the inserters to 1, then add 5 if TBL is more than 50 and unblock the stack-size entirely if TBL is more than 100.

This looks like a gas pump which slows down the fuel delivery as it approaches a preset limit. This almost eliminates the need for reserve slots. I think you could eliminate it completely if you switched off most of the inserters for very small TBL, but that causes imbalances in chest inventory. Might be okay if you used warehouses for stations..

That still doesn't actually work with FILTER stack inserters and multiple products. The train comes in with TBL of 1000 coal and 1000 stone. The filter stack inserters choose to load the coal first (or vice versa, doesn't matter). When the coal TBL drops below 100, the combinators still see 1100 total TBL, so the stack size doesn't reduce and the train ends up overfilled with coal and not enough space for stone. The only way I could see to correct this would involve https://mods.factorio.com/mod/UsefulCombinators, but I have doubts about that mod. Even then, it would be a tapestry of combinators that are easy to screw up.

So again, the LTN code that powers the station could do some of the work for the player. Add a checkbox to limit the request to one product at a time and output that TBL, plus calculate and output a recommended stack size limit. (Thresholds and stack sizes could be a global setting.)

Second stretch goal:

I'd love to try adding the feature of extending the mission of a train when it finishes drop-off without returning to a depot. I know that would be a major rewrite, but I'd like to use the existing code as a starting point. This is especially useful when a station is both requesting and providing, because it could just start loading a new product as soon as it finishes unloading.

nljr
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue May 30, 2017 2:32 am
Contact:

Re: Using LTN Mod source?

Post by nljr »

I decided to put together a save in god-mode which demonstrates the problems I described. But I could only demo one.

The first change is just a quality of life issue, not something I can demo.
The over-stock problem is too trivial to even make a good demo. If a requester station is overstocked, LTN thinks it's a provider.
The last change is a cool enhancement, not a problem.

So, my demo is just the step-down solution, with 4 example networks.

In the first version, the inserters have left-over inventory after some loads, but it can be fixed with my gas-pump fix.

Second has my gas-pump fix and won't leave inventory on the inserters.

Third has my gas-pump fix with mixed request stations. The mixed loads sometimes cause inventory to be left on the inserters even with my gas-pump fix. This could be fixed with more combinators since there are just two products with no filter inserters.

Fourth has mixed *chests* with filter inserters. It consistently screws up and I can't fix it.
Attachments
experiment.zip
(2.56 MiB) Downloaded 7 times

User avatar
jodokus31
Smart Inserter
Smart Inserter
Posts: 1604
Joined: Sun Feb 26, 2017 4:13 pm
Contact:

Re: Using LTN Mod source?

Post by jodokus31 »

nljr wrote:
Mon Apr 08, 2024 10:29 pm
I see the source for LTN is marked "No Modification - Although I can't stop you from looking at my code, you are not allowed to distribute anything altered, or derived from my code without explicit permission first."
Be aware, that you are not allowed to distribute any changes to the code. I didn't check, what is in the zip file.

The mod has a remote interface, which you can use to add custom functionality.

nljr
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue May 30, 2017 2:32 am
Contact:

Re: Using LTN Mod source?

Post by nljr »

I am aware, as I quoted in my first comment, that modifications require authorization.

Which is why I was asking. Can I please use the source in a new mod with enhancements?

User avatar
jodokus31
Smart Inserter
Smart Inserter
Posts: 1604
Joined: Sun Feb 26, 2017 4:13 pm
Contact:

Re: Using LTN Mod source?

Post by jodokus31 »

nljr wrote:
Tue Apr 09, 2024 3:47 pm
I am aware, as I quoted in my first comment, that modifications require authorization.

Which is why I was asking. Can I please use the source in a new mod with enhancements?
Just a warning, I would not invest too much time with the code until you get permission.

I would recommend to check, if your ideas can be done via remote interface and/or rather ask the author to provide the needed functionality in the mod or via remote interface.

nljr
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue May 30, 2017 2:32 am
Contact:

Re: Using LTN Mod source?

Post by nljr »

I was hoping the author would see this and give me permission. If not, I can start from the combinator instead. More to learn that way.

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

Re: Using LTN Mod source?

Post by Optera »

nljr wrote:
Wed Apr 10, 2024 2:10 am
I was hoping the author would see this and give me permission. If not, I can start from the combinator instead. More to learn that way.
Firstly, a public forum is the worst channel to ask for permissions.
Secondly, reading through your design proposal I'd still decline.
nljr wrote:
Mon Apr 08, 2024 10:29 pm
But when a product is badly over-stocked, it looks *exactly* like providing the resource to LTN. So LTN will send a train to pick up an item which is supposed to be requested, not provided. This train never gets filled and causes endless traffic jams.

The simplest fix is to stop letting stations both provide and request, it's too late in my current run, and also very convenient, so I might not be able to give it up.
If that's the only problem you attempt to fix, try setting higher default thresholds.
That's practically what the combinator does.

Post Reply

Return to “Logistic Train Network”