More bugfixes for compacting-storage.lua
This commit is contained in:
parent
ca8d0fea41
commit
892db3d65f
1 changed files with 10 additions and 11 deletions
|
|
@ -10,6 +10,7 @@ local INVENTORY = "left"
|
||||||
local SLEEP_TIME = 30
|
local SLEEP_TIME = 30
|
||||||
local AMOUNT_USED = 63 -- the amount of item used per request
|
local AMOUNT_USED = 63 -- the amount of item used per request
|
||||||
local AMOUNT_RETURNED = 7 -- the amount of item returned per request
|
local AMOUNT_RETURNED = 7 -- the amount of item returned per request
|
||||||
|
local REDUCTION_FACTOR = 0.5 -- when draining, what percent to do at a time
|
||||||
local ITEM_TYPES = { "iron", "copper", "zinc", "gold", "electrum" }
|
local ITEM_TYPES = { "iron", "copper", "zinc", "gold", "electrum" }
|
||||||
local PRIORITY = { "ingot", "block", "nugget" }
|
local PRIORITY = { "ingot", "block", "nugget" }
|
||||||
|
|
||||||
|
|
@ -113,7 +114,7 @@ function should_drain (type, counts)
|
||||||
for _, form in ipairs(PRIORITY) do
|
for _, form in ipairs(PRIORITY) do
|
||||||
local diff = counts[form] - limits[type][form][2]
|
local diff = counts[form] - limits[type][form][2]
|
||||||
if diff > 0 then
|
if diff > 0 then
|
||||||
return form, diff
|
return form, diff * REDUCTION_FACTOR
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -151,20 +152,18 @@ end
|
||||||
|
|
||||||
function decide_action (type, counts)
|
function decide_action (type, counts)
|
||||||
-- using the levels of each form of the item, decide what to do
|
-- using the levels of each form of the item, decide what to do
|
||||||
for _, form in ipairs(PRIORITY) do
|
|
||||||
local drain_form, drain_amt = should_drain(type, counts)
|
local drain_form, drain_amt = should_drain(type, counts)
|
||||||
local fill_dest, fill_src, fill_amt = should_fill(type, counts)
|
local fill_dest, fill_src, fill_amt = should_fill(type, counts)
|
||||||
if drain_form ~= nil then
|
if drain_form ~= nil then
|
||||||
drain(type, form, drain_amt)
|
drain(type, form, drain_amt)
|
||||||
elseif fill_dest ~= nil then
|
elseif fill_dest ~= nil and fill_src ~= nil then
|
||||||
fill(type, fill_src, fill_dest, fill_amt)
|
fill(type, fill_src, fill_dest, fill_amt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
function print_counts (items)
|
function print_counts (items)
|
||||||
for type, counts in pairs(items) do
|
for type, counts in pairs(items) do
|
||||||
for form, count in ipairs(counts) do
|
for form, count in pairs(counts) do
|
||||||
print(("%s %s: %d"):format(type, form, count))
|
print(("%s %s: %d"):format(type, form, count))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -173,7 +172,7 @@ end
|
||||||
while true do
|
while true do
|
||||||
-- 1. Sum items in inventory and organize by item type
|
-- 1. Sum items in inventory and organize by item type
|
||||||
local items = sum_items(peripheral.wrap(INVENTORY))
|
local items = sum_items(peripheral.wrap(INVENTORY))
|
||||||
print_counts(items)
|
-- print_counts(items)
|
||||||
|
|
||||||
-- 2. take one action for each item type per cycle
|
-- 2. take one action for each item type per cycle
|
||||||
for item_type, counts in pairs(items) do
|
for item_type, counts in pairs(items) do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue