Let item-request-proxy target specific inventory/grid

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
ickputzdirwech
Filter Inserter
Filter Inserter
Posts: 768
Joined: Sun May 07, 2017 10:16 am
Contact:

Let item-request-proxy target specific inventory/grid

Post by ickputzdirwech »

Problem
A cargo wagon with an equipment grid and an item-request-proxy that requests some equipment. The equipment is inserted into the cargo inventory and not the grid.

Workaround
I register the item-request-proxy for on_entity_destroyed and move the equipment into the grid as soon as the item-request-proxy is fulfilled.

Proposed solution
A way to tell an item-request-proxy to target or at least prioritise a specific inventory/grid.
Mods: Shortcuts for 1.1, ick's Sea Block, ick's vanilla tweaks
Tools: Atom language pack
Text quickly seems cold and unfriendly. Be careful how you write and interpret what others have written.
- A reminder for me and all who read what I write

curiosity
Filter Inserter
Filter Inserter
Posts: 315
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: Let item-request-proxy target specific inventory/grid

Post by curiosity »

This requires vehicle equipment grid to be blueprinted alongside the vehicle. Else you would be throwing a knapsack problem at the devs.

User avatar
ickputzdirwech
Filter Inserter
Filter Inserter
Posts: 768
Joined: Sun May 07, 2017 10:16 am
Contact:

Re: Let item-request-proxy target specific inventory/grid

Post by ickputzdirwech »

curiosity wrote:
Sat May 15, 2021 4:17 pm
This requires vehicle equipment grid to be blueprinted alongside the vehicle.
Mmh, can you explain to me why that would be necessary :?:
Mods: Shortcuts for 1.1, ick's Sea Block, ick's vanilla tweaks
Tools: Atom language pack
Text quickly seems cold and unfriendly. Be careful how you write and interpret what others have written.
- A reminder for me and all who read what I write

curiosity
Filter Inserter
Filter Inserter
Posts: 315
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: Let item-request-proxy target specific inventory/grid

Post by curiosity »

ickputzdirwech wrote:
Sat May 15, 2021 4:28 pm
Mmh, can you explain to me why that would be necessary :?:
See the second sentence.

User avatar
ickputzdirwech
Filter Inserter
Filter Inserter
Posts: 768
Joined: Sun May 07, 2017 10:16 am
Contact:

Re: Let item-request-proxy target specific inventory/grid

Post by ickputzdirwech »

Sorry I just don’t get it. I create an item-request-proxy by script and tell it which entity it should target. Additionally I would like to be able to specify which inventory of that entity the item-request-proxy should target. What does that have to do with blueprinting equipment grids?
Mods: Shortcuts for 1.1, ick's Sea Block, ick's vanilla tweaks
Tools: Atom language pack
Text quickly seems cold and unfriendly. Be careful how you write and interpret what others have written.
- A reminder for me and all who read what I write

curiosity
Filter Inserter
Filter Inserter
Posts: 315
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: Let item-request-proxy target specific inventory/grid

Post by curiosity »

Equipment grids have layout. To put something in you need to determine where to put it. A knapsack problem (in this case, more precisely, a packing problem) is a problem, in which you are given items with some metric (in this case their dimensions in the grid) and "value". You are required to maximize the total value, in this case all items fitting into the grid. Which itself poses a problem of which item to pick if there are for some reason more items than the grid can contain. This class of problems is very hard and time-consuming to solve, and in most cases not fit for real-time computation (e.g. in a game).
Last edited by curiosity on Mon May 17, 2021 10:09 pm, edited 1 time in total.

User avatar
ickputzdirwech
Filter Inserter
Filter Inserter
Posts: 768
Joined: Sun May 07, 2017 10:16 am
Contact:

Re: Let item-request-proxy target specific inventory/grid

Post by ickputzdirwech »

Ok I now understand what you mean. But that's a different issue. I'll explain why:

See the behaviour of a locomotive with a grid. Requested equipment gets inserted directly into the grid since it has no other place to go. True, right now requests for equipment might fail, because previous ones didn't get inserted into the grid in the optimal way. This is the problem you are fearing: it already exists.

For the cargo wagon on the other hand it's not even possible to tell the robots to insert the equipment into the grid, since they will always try and insert it into the cargo inventory first. So even if the devs would fix the "knapsack problem" the issue I am having would still exist. Therefore it's a different problem (but I wouldn't mind blueprintable grids of course).
Mods: Shortcuts for 1.1, ick's Sea Block, ick's vanilla tweaks
Tools: Atom language pack
Text quickly seems cold and unfriendly. Be careful how you write and interpret what others have written.
- A reminder for me and all who read what I write

azaghal
Burner Inserter
Burner Inserter
Posts: 18
Joined: Sat Jun 27, 2020 11:13 am
Contact:

Re: Let item-request-proxy target specific inventory/grid

Post by azaghal »

As it turns out, I have faced a similar issue while, ironically, working on a mod that makes it possible to blueprint (export/import) equipment grid layout/configuration for vehicles.

One thing I ended-up doing was having one item request proxy per equipment item (count=1) in order to try to improve chances of getting all the equipment installed in hopes of having at least one slot available at a time to insert new equipment (and basically moving it into correct position when possible).

As discovered by the OP, I was able to crate item request proxies to deliver the equipment, and faced three possible scenarios:
  1. Equipment would get inserted into inventory (cars etc).
  2. Equipment would get inserted directly into grid, like in case of locomotive.
  3. Equipment would not get inserted at all, and "returned to sender", like in case of artillery wagon. I think what happens here is that construction bots will try to insert the equipment into the ammo slot/inventory, which fails.
The way I'm solving these three (to get the equipment into correct spot) is:
  • Use on_entity_destroyed with some metadata as part of delivery registration process, and have the handler function move the equipment from any entity-attached inventory into the equipment grid. In all honesty, this was probably the cleanest part of implementation.
  • Store initial equipment grid configuration (after excess equipment has been removed), and then in conjunction with on_entity_destroyed and metadata figure out if the equipment matching the destroyed item request proxy might be out of place in the grid (so I can attempt to move it around). Here the code can get a bit ugly.
  • No solution/workaround for this one, unfortunately.
So, in this particular case I would say that it would still be beneficial to specify where the equipment should be inserted - be it specific inventory or equipment grid. As for solving the "knapsack problem", I would dare say that in my particular scenario it would be even fine if I could simply specify during delivery the position where I want to insert the equipment - and I am fine if the item bounces back, at the end of the day it would be up to me to ensure there is sufficient space for it.

And it would be nice to specify either the position within inventory or within the equipment grid in some manner (I wouldn't even mind having to convert the 2D position in grid into a linear "slot-like" index).

At this point I am also starting to consider whether I could somehow have the equipment delivered to a "chest" that would somehow follow the target entity around - though that could prove somewhat more unfriendly/buggy.

P.S.
Excess equipment is removed mostly by dropping it to the ground.

P.S.S.
Ideally, it would be nice to be able to blueprint all vehicles from the get-go using vanilla game - for example I've already implemented a mod for blueprinting inventory filters (mainly meant for cars/tanks/spidertrons). But I wouldn't mind having a mod for it if I had all the API's needed to avoid hacky solutions.

Post Reply

Return to “Modding interface requests”