diff --git a/biofuel-manager.lua b/biofuel-manager.lua index 2a899e5..f9ee1d2 100644 --- a/biofuel-manager.lua +++ b/biofuel-manager.lua @@ -110,9 +110,35 @@ local stock = { 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 +end function getOrders () - -- TODO + 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 end function run (ticker)