diff --git a/biofuel-manager.lua b/biofuel-manager.lua index f9ee1d2..57a6267 100644 --- a/biofuel-manager.lua +++ b/biofuel-manager.lua @@ -1,13 +1,15 @@ -- program to manage a biofuel factory with create and some addons + tweaks --- NOTE: this design does not handle stocking the system +-- NOTE: this design does not handle stocking cinder flour or sugar local STORAGE = "" local OIL_TANK = "" local FUEL_TANK = "" -local FACTORY_ADDRESS = "" +local MAIN_SEED_REQUEST = "minecraft:melon_seeds" +local MAIN_PLANT_REQUEST = "minecraft:bamboo" local SPEEDOMETER = "" +local MAIN_REQUESTER = "" local SUBNET_TICKER = "" local SLEEP_T = 10 @@ -101,63 +103,38 @@ local order = { local stock = { seeds = function (amt, requester) - requester.setRequest({ name = MAIN_SEED_REQUEST, count = amt }) - requester.request() + -- TODO end, plants = function (amt, requester) - requester.setRequest({ name = MAIN_PLANT_REQUEST, count = amt }) - requester.request() + -- TODO end, } -function listItems (storage) - local tally = {} - for _, item in pairs(peripheral.call(storage, "list")) do - if tally[item.name] == nil then tally[item.name] = 0 end - tally[item.name] = tally[item.name] + item.count - end - return tally +function getStockRequirements () + -- TODO end function getOrders () - local orders = {} - -- Oil - local oil_amt = table.remove(peripheral.call(OIL_TANK, "tanks")) - if oil_amt == nil then oil_amt = 0 end - local oil_needed = OIL_SETPOINT - oil_amt - if oil_needed > 0 then orders.oil = oil_needed end - -- Biomass - -- TODO use up excess material - local biomass_amt = listItems(STORAGE)["createaddition:biomass"] - if biomass_amt == nil then biomass_amt = 0 end - local biomass_needed = BIOMASS_SETPOINT - biomass_amt - if biomass_needed > 0 then orders.biomass = biomass_needed end - -- Biofuel - -- TODO use up excess material? - local biofuel_amt = table.remove(peripheral.call(FUEL_TANK, "tanks")) - if biofuel_amt == nil then biofuel_amt = 0 end - local biofuel_needed = BIOFUEL_SETPOINT - biofuel_amt - if biofuel_needed > 0 then orders.biofuel = biofuel_needed end - return orders + -- TODO end -function run (ticker) +function run (requester, ticker) if peripheral.call(SPEEDOMETER, "getSpeed") ~= 0 then + local need_to_stock = getStockRequirements() local need_to_create = getOrders() + for type, amt in pairs(need_to_stock) do + stock[type](amt, requester) + end for type, amt in pairs(need_to_create) do order[type](amt, ticker) end end os.sleep(SLEEP_T) - return run(ticker) + return run(requester, ticker) end if arg ~= nil and arg[1] == "run" then + local requester = peripheral.wrap(MAIN_REQUESTER) local ticker = peripheral.wrap(SUBNET_TICKER) - local ran = false - while not ran do - ran, result = run(ticker) - if not ran then print(result) end - os.sleep(SLEEP_T) - end + run(requester, ticker) end