feat: implements ordering logic
This commit is contained in:
parent
1be1a52a77
commit
4b0451254d
1 changed files with 27 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue