Feasibility of limiting # of a certain item in game?
Posted: Tue Nov 12, 2019 11:57 pm
I enthusiastically started constructing a new overhaul mod, that introduces population and 'labor (force)' as something you have to put on a belt and use to craft objects. Yesterday, however, I realized that there is a critical concept to what I want to achieve, that the entire mod hinges on, and if it is fundamentally impossible, then I better quit right now, rather than waste 1000 hours building a large mod:
The challenge I'm faced with is that I need to limit the amount of items (of a certain type/category only) that are currently in the game to a certain (dynamic) variable. The item must be counter regardless of whether it is in an assembler, on a belt, on the ground, in an inventory or in a chest. Is this feasible? Or is it practically impossible?
I've already found a potential way to actuate the 'limiting' when the count of the item is too high. The issue is in actually counting the number of that item(s) present in-game.
The immediate and impractical approach I thought of would be to have a function routinely check every single tile and object in every chunk, counting up on each instance found. This takes several minutes for medium-sized bases, so it's extremely unusable. I'm not well-versed enough in lua (yet) to come up with something better. Is there a better way? Here are the requirements I determined for the counting function:
- has to count number of specified item OR specified group/category of items in-game
- counted items should include those inside chests, belts, buildings, inventory, ground
- function can be costly. Increasing time per tick by ~25% compared to vanilla would still be acceptable
- count only has to be updated at around once per minute, possibly even less
- The specified item(s) will always be created out of an assembler.
- The specified item(s) will only destroyed when put in a chest and manually shot, or when a biter destroys a building containing it.
Is there a way to program a reasonably fast function for this?
Would it be possible for a function to run every time a specified recipe is finished, and count that way?
Cheers!
The challenge I'm faced with is that I need to limit the amount of items (of a certain type/category only) that are currently in the game to a certain (dynamic) variable. The item must be counter regardless of whether it is in an assembler, on a belt, on the ground, in an inventory or in a chest. Is this feasible? Or is it practically impossible?
I've already found a potential way to actuate the 'limiting' when the count of the item is too high. The issue is in actually counting the number of that item(s) present in-game.
The immediate and impractical approach I thought of would be to have a function routinely check every single tile and object in every chunk, counting up on each instance found. This takes several minutes for medium-sized bases, so it's extremely unusable. I'm not well-versed enough in lua (yet) to come up with something better. Is there a better way? Here are the requirements I determined for the counting function:
- has to count number of specified item OR specified group/category of items in-game
- counted items should include those inside chests, belts, buildings, inventory, ground
- function can be costly. Increasing time per tick by ~25% compared to vanilla would still be acceptable
- count only has to be updated at around once per minute, possibly even less
- The specified item(s) will always be created out of an assembler.
- The specified item(s) will only destroyed when put in a chest and manually shot, or when a biter destroys a building containing it.
Is there a way to program a reasonably fast function for this?
Would it be possible for a function to run every time a specified recipe is finished, and count that way?
Cheers!