[MOD 0.17 - 0.18] Inventory Sensor

Topics and discussion about specific mods
rasmi
Manual Inserter
Manual Inserter
Posts: 4
Joined: Thu Jul 25, 2019 9:19 am
Contact:

Re: [MOD 0.16 / 0.17] Inventory Sensor 1.7.3

Post by rasmi »

All you need in
All I need is to stop wasting everyone time. Sorry about that. I understood, the feature interfere with your vision and you are not eager to have it. I am fine with that and I respect your judgment.

Again, I'm here not to introduce new design, but to request a feature that is not presented anywhere in the mods. I understand that the range of use case scenarious is very tight and my execution of the feature is may be a very rough. I tried to reduce amount of work required from you when I requested to do something I want. I can keep it for my own private use. No biggie.
See my designs here:
You don't even need inventory sensors. You simply load.
Yes — I know these designs. They are great and I am surely overcomplicating things. In most cases these designs are work like a charm and in most cases LTN trains are driving half-loaded if all tresholds are configured properly. I don't see any problems in my games with LTN. LTN delivery model is good enough.

However there are corner cases in these designs, which are possible to see in a certian conditions. For example when you try to order a full train of barrels (stack size = 10) and plates (stack size = 100). Surely I can fix that by using "locked slot per wagon" feature. But in my vision this is not ideal.

So I want another design, truly universal, without *any* restrictions on input and absolutely robust. I agree, this is a definition of overengineering. But let say this is the way I having fun with the game.

mrvn
Smart Inserter
Smart Inserter
Posts: 3952
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: [MOD 0.16 / 0.17] Inventory Sensor 1.7.3

Post by mrvn »

rasmi wrote:
Fri Jul 26, 2019 8:32 am
All you need in
All I need is to stop wasting everyone time. Sorry about that. I understood, the feature interfere with your vision and you are not eager to have it. I am fine with that and I respect your judgment.

Again, I'm here not to introduce new design, but to request a feature that is not presented anywhere in the mods. I understand that the range of use case scenarious is very tight and my execution of the feature is may be a very rough. I tried to reduce amount of work required from you when I requested to do something I want. I can keep it for my own private use. No biggie.
See my designs here:
You don't even need inventory sensors. You simply load.
Yes — I know these designs. They are great and I am surely overcomplicating things. In most cases these designs are work like a charm and in most cases LTN trains are driving half-loaded if all tresholds are configured properly. I don't see any problems in my games with LTN. LTN delivery model is good enough.

However there are corner cases in these designs, which are possible to see in a certian conditions. For example when you try to order a full train of barrels (stack size = 10) and plates (stack size = 100). Surely I can fix that by using "locked slot per wagon" feature. But in my vision this is not ideal.

So I want another design, truly universal, without *any* restrictions on input and absolutely robust. I agree, this is a definition of overengineering. But let say this is the way I having fun with the game.
For items with different stack sizes you use the stack limit. Set it to 40 for normal cargo wagons, 80 for double sized wagons. If your provider stations also setz a provier limit of the same then LTN will only ever request full trains. An I mean full trains period. No half filled trains ever. Reserved slots also makes no sense for a requester station.

Now if you want a station to provide barrels and plates then you run into problems.

1) The inserters must not end up holding anything in their hand when a train leaves. That means setting the reserved slots. And with barrels a stack inserter can hold a full stack of barrels. So you need to reserve at least one slot per inserter (so up to 12) for excess barrels. That means ~3/4 full trains often.
2) Some station could request a mixture of barrels and plates. So besides excess barrels you can also have excess plates. You don't need another 12 slots for plates because they have a larger stack size. But worst case you have to account for 12 plates and 10 barrels per stack inserter.

So I would say 15 reserved slots to be sure. That's a lot of empty space when the train isn't over filled.

The alternative is to use more circuit logic to make the inserters load count perfect (or at least near to it). That way you can reduce the need for reserved slots.

For example for my factory producing all manners of belts, splitters, inserters, belt boxes and loaders I have one fast filter inserter set to stacksize override=1 and enabled as long as items are missing from the train. Next to that a stack filter inserter set to only load items that lack more than a 12 count and 4 more stack filter inserters set to only load items that lack more than a 60 (iirc) count. When loading the inserters cut of when I near the target count from LTN. At the end only the fast filter inserter loads the items one by one. It loads count perfect. That means I don't have to set any Reserved Slots.

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

Re: [MOD 0.17] Inventory Sensor 1.7.3

Post by Pi-C »

Is it possible to get the number of empty slots in an inventory with this mod?

Use case: I want to determine whether a cargo train still has some slots that can be filled and route it accordingly. For example, it would make sense that a partially filled cargo train goes to a station and picks up more stuff, while it would not make sense for a completely filled train to go to a station and leave again without dropping off or picking up a single item. While it's easy to check whether a train is empty, it's next to impossible right now to check whether it's completely filled (because of, for example, different stack sizes of different items, filtered/limited inventories, or modded wagons with extended/reduced inventory). My cargo trains are meant to carry mixed cargo, so I won't filter their inventories, but being able to see whether there are empty slots would certainly be useful.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Honktown
Filter Inserter
Filter Inserter
Posts: 497
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: [MOD 0.17] Inventory Sensor 1.7.3

Post by Honktown »

Pi-C wrote:
Wed Jan 15, 2020 11:39 am
Is it possible to get the number of empty slots in an inventory with this mod?

Use case: I want to determine whether a cargo train still has some slots that can be filled and route it accordingly. For example, it would make sense that a partially filled cargo train goes to a station and picks up more stuff, while it would not make sense for a completely filled train to go to a station and leave again without dropping off or picking up a single item. While it's easy to check whether a train is empty, it's next to impossible right now to check whether it's completely filled (because of, for example, different stack sizes of different items, filtered/limited inventories, or modded wagons with extended/reduced inventory). My cargo trains are meant to carry mixed cargo, so I won't filter their inventories, but being able to see whether there are empty slots would certainly be useful.
Just passing by. That sounds like a neat idea. Haven't played with combinators yet. Would a special combinator that say, read available space in stacks as output signals, and output maybe E as empty spaces make sense? Couldn't promise performance if you're mega-training (would have to read a stopped train every tick, or at least every n ticks when it's stopped and the combinator is connected). A single constant read when a train stops would be super-performance friendly, but then you'd need more combinators to do a difference and track the filling yourself, etc.

My idea:
0. record when the special combinator is placed, figure out how to detect when it's connected to a station
1. when a train stops (event) check for combinator connected to station (table of stations->combinators, direct connection would probably be easiest)
2. read through inventory, ignore full stacks, record difference from full stacks, add up empty spaces
3. output signal
4. repeat (2) every n ticks
5. when train leaves, stop output on combinator
I have mods! I guess!
Link

mrvn
Smart Inserter
Smart Inserter
Posts: 3952
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: [MOD 0.17] Inventory Sensor 1.7.3

Post by mrvn »

Honktown wrote:
Wed Jan 15, 2020 12:14 pm
Pi-C wrote:
Wed Jan 15, 2020 11:39 am
Is it possible to get the number of empty slots in an inventory with this mod?

Use case: I want to determine whether a cargo train still has some slots that can be filled and route it accordingly. For example, it would make sense that a partially filled cargo train goes to a station and picks up more stuff, while it would not make sense for a completely filled train to go to a station and leave again without dropping off or picking up a single item. While it's easy to check whether a train is empty, it's next to impossible right now to check whether it's completely filled (because of, for example, different stack sizes of different items, filtered/limited inventories, or modded wagons with extended/reduced inventory). My cargo trains are meant to carry mixed cargo, so I won't filter their inventories, but being able to see whether there are empty slots would certainly be useful.
Just passing by. That sounds like a neat idea. Haven't played with combinators yet. Would a special combinator that say, read available space in stacks as output signals, and output maybe E as empty spaces make sense? Couldn't promise performance if you're mega-training (would have to read a stopped train every tick, or at least every n ticks when it's stopped and the combinator is connected). A single constant read when a train stops would be super-performance friendly, but then you'd need more combinators to do a difference and track the filling yourself, etc.

My idea:
0. record when the special combinator is placed, figure out how to detect when it's connected to a station
1. when a train stops (event) check for combinator connected to station (table of stations->combinators, direct connection would probably be easiest)
2. read through inventory, ignore full stacks, record difference from full stacks, add up empty spaces
3. output signal
4. repeat (2) every n ticks
5. when train leaves, stop output on combinator
Maybe replace the TrainStop with one that has the special combinator builtin? That way you don't have to handle detecting it getting connected or disconnected or worrying about having 2 stations connected and such.

Performance wise it might also be useful to do some of it in combinators. For example then the train arrives calculate the free space in LUA and programm some constant combinators with it. Then vanilla combinators read out the actual item count on the train and compare it with the data from the constant combinators to figure out how much was loaded/unloaded and output an updated stack count. All of that combinator mess could be placed hidden automatically when you place the train stop. So the user only sees one output terminal that gives the stack count.

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

Re: [MOD 0.17] Inventory Sensor 1.7.3

Post by Pi-C »

Honktown wrote:
Wed Jan 15, 2020 12:14 pm
Would a special combinator that say, read available space in stacks as output signals, and output maybe E as empty spaces make sense?
While I don't have Inventory Sensors yet, I have a couple of other mods that add new combinators (Remote Switch, the wisp detector from Will-o'-the-Wisps, Ghost Scanner, the radio from Shortwave etc.). Too many different special combinators could complicate the game (need to put up an assembler for each combinator, more items taking up space in the inventory), so adding functions to already existing combinators would be preferable, I guess. Also, it feels natural that IS should be able to read the number of free slots because IS is about inventories already, and empty slots are part of the inventory just the same as filled slots.

Apart from that, I would need to add another combinator anyway (because I don't have IS yet), so in my case it wouldn't make a difference whether I'd add a new mod by you or IS. If you'd want to make a mod for this, I'd certainly use it!
A single constant read when a train stops would be super-performance friendly,
Best thing would be if vanilla train stops would have a signal for open inventory slots. :-D
but then you'd need more combinators to do a difference and track the filling yourself, etc.
I use several combinators at every station already (for guidance -- comparing train type/inventory contents with what is needed by other stations and setting signals accordingly; and for ordering trains), so that's not a problem.
My idea:
0. record when the special combinator is placed, figure out how to detect when it's connected to a station
Would it really be possible to use only one combinator for each train? That certainly would be an advantage! I'd thought of placing an inventory sensor in front of each wagon and use the sum of their signals, but that may be difficult in curves. For detecting the station: If you'd connect the combinator to a station that has "Read stopped train" set, it should receive a "T" signal with the train ID as long as a train in automatic mode stops there.
2. read through inventory, ignore full stacks, record difference from full stacks, add up empty spaces
What do you mean with "record difference from full stacks" -- partial stacks (e.g. 20 iron plates)? Do you mean to resort the inventory (thus reducing, for example, 3 stacks with 20 iron plates + 32 iron plates + 87 iron plates to 2 stacks with 100 iron plates + 39 iron plates)? Unless you really do resort the inventory (not just calculate the possible capacity) that wouldn't help much: There may be trains where all slots are occupied with just half a stack. If such a train loaded with iron plates would be called to a station providing coal on the assumption that half of the slots are still free, it would still go there in vain as you can't put coal onto a stack of iron plates.
5. when train leaves, stop output on combinator
The "T" signal from the station would come in handy again here. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

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

Re: [MOD 0.17] Inventory Sensor 1.7.3

Post by Optera »

That would be a pretty large hit to performance. Instead of entity.get_inventory() it'd have to iterate each slot in the inventory.
With the way IS has to poll every n-th tick to catch manual trains and wagons without locomotives, the performance hit will be too large for me to consider adding this feature.

A custom trainstop like mrvn suggested would sum up slots per train.
If per wagon granularity isn't required it would be much lighter on performance and could hook right into train events.
However it'd be incompatible with any other mods train stops (LTN, Smarter Trains, asf)

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

Re: [MOD 0.17] Inventory Sensor 1.7.3

Post by Pi-C »

Optera wrote:
Wed Jan 15, 2020 3:56 pm
That would be a pretty large hit to performance. Instead of entity.get_inventory() it'd have to iterate each slot in the inventory.
With the way IS has to poll every n-th tick to catch manual trains and wagons without locomotives, the performance hit will be too large for me to consider adding this feature.
Thank you for the explanation, that's indeed a good reason not to implement it!
A custom trainstop like mrvn suggested would sum up slots per train.
If per wagon granularity isn't required it would be much lighter on performance and could hook right into train events.
Per wagon granularity is required only for stations providing different goods, and only if you'd load one kind of cargo into the first wagon, another type in the second etc. These are edge cases, though, generally I just want to know if there is some room left on a train. Oh, and I really like mrvn's idea of using a trainstop instead of a combinator! It's more compact than having to place an extra combinator next to the train stop.
However it'd be incompatible with any other mods train stops (LTN, Smarter Trains, asf)
Would such a thing even be needed with other mods' train stops? I want this feature for routing trains in a network where really every station has the same name and control everything via the circuit network, but as I understand LTN, it does routing internally and users don't have to interfere with it anyway.

By the way, LTN etc. use their own train stops already, or could you use them together with vanilla train stops? Would there be any argument against replacing vanilla train stops with those suggested by mrvn? They would output one more signal (which you could choose to ignore), but having two different kinds of train stops where only one will be used seems unnecessary. Perhaps it could work as a mod option?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Honktown
Filter Inserter
Filter Inserter
Posts: 497
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: [MOD 0.17] Inventory Sensor 1.7.3

Post by Honktown »

mrvn wrote:
Wed Jan 15, 2020 1:44 pm
nd track the filling yourself, etc.
Maybe replace the TrainStop with one that has the special combinator builtin? That way you don't have to handle detecting it getting connected or disconnected or worrying about having 2 stations connected and such.
Hey look at this smart guy. It did come to mind to see if one could make special circuit rails, that read just the wagon on themselves. That would allow individual carriage sensing if possible.
Pi-C wrote:
Wed Jan 15, 2020 2:25 pm
...
For the reading stacks part, the available space for existing stacks could be read and sum up (stack_size - count) for all slots and item types. If a train had all slots half full of iron plates, it can still receive iron plates, which would be the output signal.

Unfortunately wagons are different than the inventory of the whole train, so each wagon would have to be sensed for things to work right (or only one wagon).

Empty spaces would be much easier to track, just do for i=1..last_inventory if slotempty E = E + 1. As for using T as a signal, each combinator would have to be checked if it's getting signal T at any point in time. That could be more performance friendly than checking for stopped train events, hmmm. Depends on ratio of trains stopping to how expensive checking the circuit signal is * n combinators every tick. The latter could be made into a deterministic table.insert() style storage.
I have mods! I guess!
Link

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

Re: [MOD 0.17] Inventory Sensor 1.7.3

Post by Optera »

The debate about possible implementations of reading empty slots in trains no longer belongs in this thread.
Please start a new thread in Modding Discussions for it.

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

Re: [MOD 0.17] Inventory Sensor 1.7.3

Post by Pi-C »

Optera wrote:
Thu Jan 16, 2020 8:05 am
Please start a new thread in Modding Discussions for it.
Sorry for capturing your thread! I've just made a new one here.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

mrvn
Smart Inserter
Smart Inserter
Posts: 3952
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: [MOD 0.17] Inventory Sensor 1.7.3

Post by mrvn »

Pi-C wrote:
Wed Jan 15, 2020 2:25 pm
2. read through inventory, ignore full stacks, record difference from full stacks, add up empty spaces
What do you mean with "record difference from full stacks" -- partial stacks (e.g. 20 iron plates)? Do you mean to resort the inventory (thus reducing, for example, 3 stacks with 20 iron plates + 32 iron plates + 87 iron plates to 2 stacks with 100 iron plates + 39 iron plates)? Unless you really do resort the inventory (not just calculate the possible capacity) that wouldn't help much: There may be trains where all slots are occupied with just half a stack. If such a train loaded with iron plates would be called to a station providing coal on the assumption that half of the slots are still free, it would still go there in vain as you can't put coal onto a stack of iron plates.
I think he means that if you have 3 stacks with 20 iron plates + 32 iron plates + 87 iron plates then the combinator should output that there is still space for 1 stack iron plates even if no fields in the train is empty. The combinator would output (<empty space> + <partial space>) / <stacksize> rounded down.

Post Reply

Return to “Mods”

Who is online

Users browsing this forum: BlueTemplar, dorfl, minxkin