Some bugfixes to compacting-storage.lua.
This commit is contained in:
parent
eeb2891e9c
commit
26016b36d9
1 changed files with 15 additions and 10 deletions
|
|
@ -7,7 +7,8 @@
|
||||||
-- constants
|
-- constants
|
||||||
|
|
||||||
local INVENTORY = ""
|
local INVENTORY = ""
|
||||||
local SLEEP_TIME = 5
|
local SLEEP_TIME = 30
|
||||||
|
local AMOUNT_PER = 63 -- the amount of item change per request
|
||||||
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" }
|
||||||
|
|
||||||
|
|
@ -17,8 +18,16 @@ end
|
||||||
|
|
||||||
-- TODO map targets to specific relays
|
-- TODO map targets to specific relays
|
||||||
local target = {}
|
local target = {}
|
||||||
|
target.iron = peripheral.wrap""
|
||||||
|
target.copper = peripheral.wrap""
|
||||||
|
target.zinc = peripheral.wrap""
|
||||||
|
target.gold = peripheral.wrap""
|
||||||
|
target.electrum = peripheral.wrap""
|
||||||
|
|
||||||
|
-- Levels
|
||||||
|
local limits = {}
|
||||||
for _, type in ipairs(ITEM_TYPES) do
|
for _, type in ipairs(ITEM_TYPES) do
|
||||||
target[type] = {
|
limits[type] = {
|
||||||
"nugget" = { stacks(4), stacks(8) },
|
"nugget" = { stacks(4), stacks(8) },
|
||||||
"ingot" = { stacks(4), stacks(8) },
|
"ingot" = { stacks(4), stacks(8) },
|
||||||
"block" = { stacks(4), stacks(1000) }
|
"block" = { stacks(4), stacks(1000) }
|
||||||
|
|
@ -51,9 +60,9 @@ end
|
||||||
|
|
||||||
-- basic actions
|
-- basic actions
|
||||||
function request (item_type, conversion_type)
|
function request (item_type, conversion_type)
|
||||||
target[item_type].setOutput(convert.conversion_type, true)
|
target[item_type].setOutput(convert[conversion_type], true)
|
||||||
os.sleep(0.05)
|
os.sleep(0.05)
|
||||||
target[item_type].setOutput(convert.conversion_type, false)
|
target[item_type].setOutput(convert[conversion_type], false)
|
||||||
end
|
end
|
||||||
|
|
||||||
function request_multiple (item_type, conversion_type, count)
|
function request_multiple (item_type, conversion_type, count)
|
||||||
|
|
@ -68,8 +77,6 @@ function request_multiple (item_type, conversion_type, count)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- fundamental actions
|
-- fundamental actions
|
||||||
-- assumptions: a drain or fill of 1 will increase or decrease the amount of
|
|
||||||
-- that item by 63
|
|
||||||
function drain (type, form, amount)
|
function drain (type, form, amount)
|
||||||
local conversion = nil
|
local conversion = nil
|
||||||
if form == "nugget" then
|
if form == "nugget" then
|
||||||
|
|
@ -95,14 +102,12 @@ function fill (type, form, amount)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- making the decision what to do
|
-- making the decision what to do
|
||||||
-- assumptions: a drain or fill of 1 will increase or decrease the amount of
|
|
||||||
-- that item by 63
|
|
||||||
function should_drain (type, counts)
|
function should_drain (type, counts)
|
||||||
local drain_form, amount = nil, 0
|
local drain_form, amount = nil, 0
|
||||||
for _, form in ipairs(PRIORITY) do
|
for _, form in ipairs(PRIORITY) do
|
||||||
local diff = counts[form] - target[type][form][2]
|
local diff = counts[form] - target[type][form][2]
|
||||||
if diff > 0 then
|
if diff > 0 then
|
||||||
amount = math.ceil(diff / 63)
|
amount = math.ceil(diff / AMOUNT_PER)
|
||||||
drain_form = form
|
drain_form = form
|
||||||
return drain_form, amount
|
return drain_form, amount
|
||||||
end
|
end
|
||||||
|
|
@ -115,7 +120,7 @@ function should_fill (type, counts)
|
||||||
local diff = target[type][form][1] - counts[form]
|
local diff = target[type][form][1] - counts[form]
|
||||||
if diff > 0 then
|
if diff > 0 then
|
||||||
if fill_dest == nil then
|
if fill_dest == nil then
|
||||||
amount = math.ceil(diff / 63)
|
amount = math.ceil(diff / AMOUNT_PER)
|
||||||
fill_dest = form
|
fill_dest = form
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue