summaryrefslogtreecommitdiff
path: root/shop2/stock.lua
diff options
context:
space:
mode:
Diffstat (limited to 'shop2/stock.lua')
-rw-r--r--shop2/stock.lua24
1 files changed, 23 insertions, 1 deletions
diff --git a/shop2/stock.lua b/shop2/stock.lua
index ce76bf0..71a6844 100644
--- a/shop2/stock.lua
+++ b/shop2/stock.lua
@@ -27,7 +27,7 @@ local function item_desc_matches(idesc,itemdetail)
return idesc.itname == itemdetail.name
end
-local function stock_amt(stockinfo,idesc)
+local function amt_of(stockinfo,idesc)
local total = 0
for ix,itm in pairs(stockinfo) do
if item_desc_matches(idesc,itm) then
@@ -37,3 +37,25 @@ local function stock_amt(stockinfo,idesc)
return total
end
+local function give(stockinfo,idesc,amt)
+ amt = amt or 1
+ -- assumes that we have at least amt in stock already
+ -- actually no, might as well double check this anyway
+ assert(amt_of(stockinfo,idesc) >= amt)
+ assert(amt>0)
+ -- make sure current turtle inv slot is empty
+ assert(turtle.getItemCount() == 0)
+
+ for slotidx,idtl in pairs(stockinfo) do
+ if item_desc_matches(idesc,idtl) then
+ local a = math.min(amt,idtl.count)
+ chest.pushItems(localname, slotidx, a, 1)
+ turtle.drop(a)
+ amt = amt - a
+ if amt <= 0 then break end
+ end
+ end
+end
+
+
+return {take_stock=take_stock,amt_of=amt_of,give=give}