Compare commits
No commits in common. "5acc3ab0f7045767dfb89eec93e9ad0f35fa4785" and "b60bb94e0716b76a111c21ff261218051c381666" have entirely different histories.
5acc3ab0f7
...
b60bb94e07
1 changed files with 27 additions and 131 deletions
|
|
@ -9,157 +9,53 @@ local FLOORS = {
|
||||||
return first_char == "A" or first_char == "W"
|
return first_char == "A" or first_char == "W"
|
||||||
end,
|
end,
|
||||||
detect = function ()
|
detect = function ()
|
||||||
return redstone.getOutput("top")
|
-- TODO
|
||||||
end,
|
end,
|
||||||
call = function ()
|
call = function ()
|
||||||
redstone.setOutput("top", true)
|
-- TODO
|
||||||
os.sleep(0.5)
|
|
||||||
redstone.setOutput("top", false)
|
|
||||||
end
|
end
|
||||||
storage = "create:item_vault_17",
|
storage = "",
|
||||||
elevator_storage = "bottom",
|
elevator_storage = "",
|
||||||
},
|
}
|
||||||
{
|
|
||||||
match = function (input)
|
|
||||||
local first_char = string.sub(input, 1, 1)
|
|
||||||
return first_char == "F"
|
|
||||||
end,
|
|
||||||
detect = function ()
|
|
||||||
local relay = "redstone_relay_21"
|
|
||||||
peripheral.call(relay, "getOutput", "top")
|
|
||||||
end,
|
|
||||||
call = function ()
|
|
||||||
local relay = "redstone_relay_21"
|
|
||||||
peripheral.call(relay, "setOutput", "top", true)
|
|
||||||
os.sleep(0.5)
|
|
||||||
peripheral.call(relay, "setOutput", "top", false)
|
|
||||||
end
|
|
||||||
storage = "create:item_vault_18",
|
|
||||||
elevator_storage = "create:portable_storage_interface_8",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
match = function (input)
|
|
||||||
local first_char = string.sub(input, 1, 1)
|
|
||||||
return first_char == "L"
|
|
||||||
end,
|
|
||||||
detect = function ()
|
|
||||||
local relay = "redstone_relay_22"
|
|
||||||
peripheral.call(relay, "getOutput", "top")
|
|
||||||
end,
|
|
||||||
call = function ()
|
|
||||||
local relay = "redstone_relay_22"
|
|
||||||
peripheral.call(relay, "setOutput", "top", true)
|
|
||||||
os.sleep(0.5)
|
|
||||||
peripheral.call(relay, "setOutput", "top", false)
|
|
||||||
end
|
|
||||||
storage = "create:item_vault_19",
|
|
||||||
elevator_storage = "create:portable_storage_interface_9",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
match = function (input)
|
|
||||||
local first_char = string.sub(input, 1, 1)
|
|
||||||
return first_char == "E"
|
|
||||||
end,
|
|
||||||
detect = function ()
|
|
||||||
local relay = "redstone_relay_23"
|
|
||||||
peripheral.call(relay, "getOutput", "top")
|
|
||||||
end,
|
|
||||||
call = function ()
|
|
||||||
local relay = "redstone_relay_23"
|
|
||||||
peripheral.call(relay, "setOutput", "top", true)
|
|
||||||
os.sleep(0.5)
|
|
||||||
peripheral.call(relay, "setOutput", "top", false)
|
|
||||||
end
|
|
||||||
storage = "create:item_vault_20",
|
|
||||||
elevator_storage = "create:portable_storage_interface_10",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local SLEEP_T = 5
|
local SLEEP_T = 5
|
||||||
|
|
||||||
local PKG_QUEUE = {
|
local PKG_STACK = {
|
||||||
insert = function (self, floor_i)
|
transfer_all = function (self, src, dest)
|
||||||
local is_in = function (item, list)
|
-- TODO
|
||||||
for _, l_item in ipairs(list) do
|
|
||||||
if l_item == item then return true end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
if not is_in(floor_i, self.queue) then
|
|
||||||
table.insert(self.queue, floor_i)
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
check_floors = function (self, floors)
|
|
||||||
for i, floor in pairs(floors) do
|
|
||||||
if #(peripheral.call(floor.storage, "list")) > 0 then
|
|
||||||
self:insert(i)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
check_cargo = function (self, inv, floors)
|
|
||||||
for slot, item in pairs(peripheral.call(inv, "list")) do
|
|
||||||
local item_detail = peripheral.call(src, "getItemDetail", slot)
|
|
||||||
for i, floor in ipairs(floors) do
|
|
||||||
if item_detail.package ~= nil and
|
|
||||||
floor.match(item_detail.package.getAddress()) then
|
|
||||||
self:insert(i)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
transfer_all = function (self, src, dest, floors)
|
|
||||||
-- assumption: this always transfers into the cargo box
|
|
||||||
for slot, item in pairs(peripheral.call(src, "list")) do
|
|
||||||
local item_detail = peripheral.call(src, "getItemDetail", slot)
|
|
||||||
for i, floor in ipairs(floors) do
|
|
||||||
if item_detail.package ~= nil and
|
|
||||||
floor.match(item_detail.package.getAddress()) then
|
|
||||||
self:insert(i)
|
|
||||||
peripheral.call(src, "pushItems", dest, slot)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
transfer_matching = function (self, src, dest, match_f)
|
transfer_matching = function (self, src, dest, match_f)
|
||||||
-- assumption: this always transfers out of the cargo box
|
-- TODO
|
||||||
for slot, item in pairs(peripheral.call(src, "list")) do
|
|
||||||
local item_detail = peripheral.call(src, "getItemDetail", slot)
|
|
||||||
if item_detail.package ~= nil and
|
|
||||||
match_f(item_detail.package.getAddress()) then
|
|
||||||
peripheral.call(src, "pushItems", dest, slot)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
get_next_floor = function (self)
|
get_next_floor = function (self)
|
||||||
return table.remove(self.queue, 1)
|
-- TODO
|
||||||
end
|
end
|
||||||
queue = {},
|
stack = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
function run (floors, queue, first_run)
|
function run (floors, stack)
|
||||||
local next_floor = nil
|
local next_addr = nil
|
||||||
queue:check_floors(floors)
|
for _, floor in pairs(floors) do
|
||||||
for i, floor in pairs(floors) do
|
|
||||||
if floor.detect() then
|
if floor.detect() then
|
||||||
if first_run then
|
stack:transfer_all(floor.storage, floor.elevator_storage)
|
||||||
queue:check_cargo(floor.elevator_storage, floors)
|
stack:transfer_matching(
|
||||||
end
|
|
||||||
queue:transfer_all(floor.storage, floor.elevator_storage, floors)
|
|
||||||
queue:transfer_matching(
|
|
||||||
floor.elevator_storage, floor.storage, floor.match
|
floor.elevator_storage, floor.storage, floor.match
|
||||||
)
|
)
|
||||||
next_floor = queue:get_next_floor()
|
next_addr = stack:get_next_floor()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if next_floor ~= nil then
|
if next_addr ~= nil then
|
||||||
floors[next_floor].call()
|
for _, floor in pairs(floors) do
|
||||||
|
if floor.match(next_addr) then
|
||||||
|
floor.call()
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
os.sleep(SLEEP_T)
|
|
||||||
return run(floors, queue, false)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if arg ~= nil and arg[1] == "run" then
|
while true do
|
||||||
run(FLOORS, queue, true)
|
run(FLOORS)
|
||||||
|
os.sleep(SLEEP_T)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue