milo crafting updates

This commit is contained in:
kepler155c@gmail.com
2019-06-27 16:29:37 -04:00
parent bbd36ec96a
commit 03643bcd34
6 changed files with 81 additions and 27 deletions

View File

@@ -219,8 +219,8 @@ local function turtleCraft(recipe, storage, request, count)
request.statusCode = Craft.STATUS_ERROR
else
request.crafted = request.crafted + count * recipe.count
request.status = 'crafted'
request.statusCode = Craft.STATUS_SUCCESS
--request.status = 'crafted'
--request.statusCode = Craft.STATUS_SUCCESS
end
else
_G._syslog('just failed')
@@ -319,6 +319,7 @@ function Craft.craftRecipeInternal(recipe, count, storage, origItem, path)
repeat
local craftedIngredient
local abort
for key,icount in pairs(Craft.sumIngredients(recipe)) do
local itemCount = Craft.getItemCount(origItem.ingredients, key)
@@ -330,24 +331,27 @@ function Craft.craftRecipeInternal(recipe, count, storage, origItem, path)
if itemCount < need then
local irecipe = findValidRecipe(key, path)
if not irecipe then
return 0
end
local iqty = need - itemCount
local p = Util.shallowCopy(path)
p[irecipe.result] = true
local crafted = Craft.craftRecipeInternal(irecipe, iqty, storage, origItem, p)
if not origItem.forceCrafting and crafted < iqty then
return 0
end
if origItem.forceCrafting and crafted < iqty then
canCraft = math.min(canCraft, math.floor((itemCount + crafted) / icount))
end
if crafted > 0 then
craftedIngredient = true
abort = true
else
local iqty = need - itemCount
local p = Util.shallowCopy(path)
p[irecipe.result] = true
local crafted = Craft.craftRecipeInternal(irecipe, iqty, storage, origItem, p)
if not origItem.forceCrafting and crafted < iqty then
abort = true
end
if origItem.forceCrafting and crafted < iqty then
canCraft = math.min(canCraft, math.floor((itemCount + crafted) / icount))
end
if crafted > 0 then
craftedIngredient = true
end
end
end
end
if abort then
return 0
end
until not craftedIngredient
local crafted = 0
@@ -476,7 +480,43 @@ function Craft.getResourceList4(inRecipe, items, count)
end
-- given a certain quantity, return how many of those can be crafted
function Craft.getCraftableAmount(inRecipe, limit, items)
function Craft.getCraftableAmount(inRecipe, inCount, items, missing)
local function sumItems(recipe, summedItems, count, path)
local canCraft = 0
for _ = 1, count do
for _,entry in pairs(recipe.ingredients) do
local item = convert(entry)
local summedItem = summedItems[item.key] or Craft.getItemCount(items, item.key)
local irecipe = findValidRecipe(item.key, path)
if irecipe and summedItem <= 0 then
local p = Util.shallowCopy(path)
p[irecipe.result] = true
summedItem = summedItem + sumItems(irecipe, summedItems, item.count, p)
end
if summedItem <= 0 then
if missing and not irecipe then
missing.name = item.key
end
return canCraft
end
if not recipe.craftingTools or not recipe.craftingTools[item.key] then
summedItems[item.key] = summedItem - item.count
end
end
canCraft = canCraft + recipe.count
end
return canCraft
end
local path = { [ inRecipe.result ] = true }
return sumItems(inRecipe, { }, math.ceil(inCount / inRecipe.count), path)
end
-- doesnt work :( solar panel 3 fails (qty 2)
function Craft.getCraftableAmountXXX(inRecipe, limit, items)
local allIngredients = { }
local function sumItems(recipe, count, path)
@@ -485,7 +525,6 @@ function Craft.getCraftableAmount(inRecipe, limit, items)
for _ = 1, count do
for iKey, iCount in pairs(Craft.sumIngredients(recipe)) do
local quantity = allIngredients[iKey] or Craft.getItemCount(items, iKey)
if quantity < iCount then
local irecipe = findValidRecipe(iKey, path)
if irecipe then

View File

@@ -71,8 +71,6 @@ function Milo:setState(key, value)
end
function Milo:resetCraftingStatus()
self.context.storage.activity = { }
for _,key in pairs(Util.keys(self.context.craftingQueue)) do
local item = self.context.craftingQueue[key]
if item.crafted >= item.requested or item.aborted then

View File

@@ -15,13 +15,17 @@ function craftTask:craft(recipe, item)
return
end
-- TODO: refactor into craft.lua
Craft.processPending(item, context.storage)
-- create a mini-list of items that are required for this recipe
item.ingredients = Craft.getResourceList(
recipe, Milo:listItems(), item.requested - item.crafted, item.pending)
for k,v in pairs(item.ingredients) do
if item.pending[k] then
v.status = 'processing'
v.statusCode = Craft.STATUS_INFO
end
end
for k, v in pairs(item.ingredients) do
v.crafted = v.used
v.count = v.used
@@ -39,6 +43,12 @@ function craftTask:craft(recipe, item)
end
function craftTask:cycle()
for _,item in pairs(context.craftingQueue) do
Craft.processPending(item, context.storage)
end
context.storage.activity = { }
for _,key in pairs(Util.keys(context.craftingQueue)) do
local item = context.craftingQueue[key]
if item.requested - item.crafted > 0 then

View File

@@ -156,8 +156,12 @@ local function createPage(node)
end
if row.requested then
row.remaining = math.max(0, row.requested - row.crafted)
--_syslog('%d %d %d %d', row.remaining, row.requested, row.total, row.crafted)
row.status = (row.status or '') ..
string.format(' %d of %d', row.crafted + row.total, row.total + row.requested)
else
row.displayName = ' ' .. row.displayName
row.status = (row.status or '') .. string.format(' %d of %d', row.count, row.total)
end
--row.progress = string.format('%d/%d', row.crafted, row.count)
return row

View File

@@ -91,14 +91,16 @@ local function createPage(node)
value = 'Storage Status',
},
onlineText = UI.Text {
x = 18, ex = -2, y = 2,
x = 18, y = 2,
width = 8,
},
tpsLabel = UI.Text {
x = 2, y = 3,
value = 'Tasks/sec',
},
tpsText = UI.Text {
x = 18, ex = -2, y = 3,
x = 18, y = 3,
width = 8,
},
tasksLabel = UI.Text {
x = -18, y = 3,
@@ -188,6 +190,7 @@ local function createPage(node)
local stateTab = page.tabs[4]
local activityTab = page.tabs[5]
local taskTab = page.tabs[6]
_G._p2 = overviewTab
local function getStorageStats()
local stats = { }