Using LTN Mod source?
Posted: 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."
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.
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.