feat: track item usage better
This commit is contained in:
parent
528d5f7f80
commit
04f6d66e56
1 changed files with 11 additions and 4 deletions
|
|
@ -251,11 +251,19 @@ function getNumCraftable (ingredients, current_stock)
|
|||
return result
|
||||
end
|
||||
|
||||
function craftRecipe (ticker, recipe, count)
|
||||
if count == nil then count = 1 end
|
||||
function adjustStock (current_stock, recipe, count)
|
||||
for _, ingredient in ipairs(recipe.ingredients) do
|
||||
item, i_count = ingredient[1], ingredient[2]
|
||||
current_stock[item] = current_stock[item] - (i_count * count)
|
||||
end
|
||||
end
|
||||
|
||||
function craftRecipe (ticker, recipe, current_stock)
|
||||
local count = getNumCraftable(recipe.ingredients, current_stock)
|
||||
if recipe.limit ~= nil then
|
||||
count = math.min(count, recipe.limit)
|
||||
end
|
||||
adjustStock(current_stock, recipe, count)
|
||||
local createRequest
|
||||
createRequest = function (recipe, i)
|
||||
if i == nil then i = 1 end
|
||||
|
|
@ -297,8 +305,7 @@ function run (ticker, export_storage, current_modes)
|
|||
if mode[1] == "recipe" then
|
||||
-- make as many recipes as you can with current stock
|
||||
local recipe = RECIPES[item]
|
||||
local count = getNumCraftable(recipe.ingredients, stock_amounts)
|
||||
craftRecipe(ticker, recipe, count)
|
||||
craftRecipe(ticker, recipe, stock_amounts)
|
||||
elseif mode[1] == "export" then
|
||||
local export_amt = export_amounts[item]
|
||||
if export_amt == nil then export_amt = 0 end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue