Open tdauth opened 1 year ago
The callback trigger and function should exist only once in a list. Not per requirement and not per recipe. Also add callbacks for crafting items: function TriggerRegisterItemCraftEvent takes trigger whichTrigger returns nothing
The callback triggers for conditions can be used to allow certain recipes for certain units only. They should return a count. If the count is negative than the UI won't even be shown. Add a constants like:
constant integer ITEM_CRAFT_CHECK_RESULT_HIDE = -1 constant integer ITEM_CRAFT_CHECK_RESULT_NOT_AVAILABLE = 0
Maybe add an optional feature to store item types per inventory in a hashtable with a count which makes the checks much faster:
hashtable itemCraftInventoryHashTable = InitHashTable()
function GetItemCraftInventoryCharges takes integer itemTypeId returns integer ... endfunction
The hashtable is always updated on picking up and dropping items.
It would save one inner loop per requirement and the complexity is only O(n*m): We have a loop via all recipes and an inner loop via all requirements.
The hashtable caching would only work if an item is never removed with RemoveItem etc.
Allow combining multiple inventories:
function CombineItemCrafters takes unit crafter1, unit crafter2 returns group
function GetItemCrafters takes unit crafter returns group
function SplitItemCrafters takes unit crafter1, unit crafter2 returns group
function SplitItemCrafters takes unit crafter returns integer
This will allow using more than 6 different items to craft something really special.
Allow specifying where the crafted item is put:
function SetRecipeTarget takes integer recipe, integer target returns nothing
constant integer RECIPE_TARGET_SELF = 0
constant integer RECIPE_TARGET_BUYING_UNIT = 1
constant integer RECIPE_TARGET_BUYING_GROUND = 2
Allow an option for recipes if UI is shown even for recipe not possible. Hiding it would help to have more free slots:
function SetRecipeHideUIOnMissingRequirement takes integer recipe, boolean hide returns nothing
Use structs for the Stashes and not too many hash table keys:
This system here seems to be interesting: https://www.hiveworkshop.com/threads/recipe-system.326370/ It is very minimalistic and easy to use. It does not store the resulting itemTypeId for the crafted item, only the components.