diff --git a/compacting-storage.lua b/compacting-storage.lua index efc63b6..8fdd2dd 100644 --- a/compacting-storage.lua +++ b/compacting-storage.lua @@ -107,7 +107,7 @@ function craft_multiple (requester, item_type, conversion_type, count) end function execute_crafts (requester, item_type, crafts) - local num_crafts = crafts.nuggets + local num_crafts = crafts.nugget if num_crafts > 0 then print(("Crafting %s nuggets"):format(item_type)) craft_multiple(item_type, 4, num_crafts) @@ -115,7 +115,7 @@ function execute_crafts (requester, item_type, crafts) print(("Crafting %s ingots"):format(item_type)) craft_multiple(item_type, 1, -num_crafts) end - num_crafts = crafts.blocks + num_crafts = crafts.block if num_crafts > 0 then print(("Crafting %s blocks"):format(item_type)) craft_multiple(requester, item_type, 2, num_crafts) @@ -141,12 +141,12 @@ function sum_items (inv_f) end function dist_to_num (dist) - return dist.nuggets + dist.ingots * INGOTS + dist.blocks * BLOCKS + return dist.nugget + dist.ingot * INGOTS + dist.block * BLOCKS end function get_dist (item_type, items) -- TODO change plurals to singulars to match mc - local dist = { nuggets = 0, ingots = 0, blocks = 0 } + local dist = { nugget = 0, ingot = 0, block = 0 } for item, count in pairs(items) do local type, form = item:match":(%l-)_(%l*)" form = string.format("%ss", form) @@ -158,42 +158,42 @@ function get_dist (item_type, items) end function decide_dist (num) - local dist = { nuggets = 0, ingots = 0, blocks = 0 } + local dist = { nugget = 0, ingot = 0, block = 0 } if num > MAX_NUM then local excess = num - MAX_NUM - dist.blocks = math.floor(excess / BLOCKS) - num = num - (dist.blocks * BLOCKS) + dist.block = math.floor(excess / BLOCKS) + num = num - (dist.block * BLOCKS) end local balance = math.floor(num / 10) - dist.nuggets, dist.ingots = balance, balance + dist.nugget, dist.ingot = balance, balance num = num - (balance * 10) - dist.nuggets = dist.nuggets + num + dist.nugget = dist.nugget + num return dist end function get_diff (dist1, dist2) return { - nuggets = dist1.nuggets - dist2.nuggets, - ingots = dist1.ingots - dist2.ingots, - blocks = dist1.blocks - dist2.blocks + nugget = dist1.nugget - dist2.nugget, + ingot = dist1.ingot - dist2.ingot, + block = dist1.block - dist2.block } end function filter_clamp (diff, current_dist) -- reduce diff numbers to what can be crafted using current resources - if diff.blocks > 0 then - diff.blocks = math.min( - diff.blocks - (diff.blocks % BLOCK_RATIO), - math.floor(current_dist.ingots / 9) + if diff.block > 0 then + diff.block = math.min( + diff.block - (diff.block % BLOCK_RATIO), + math.floor(current_dist.ingot / 9) ) end - if diff.nuggets > 0 then - diff.nuggets = math.min( - diff.nuggets - (diff.nuggets % NUGGET_RATIO), - current_dist.ingots * 9 + if diff.nugget > 0 then + diff.nugget = math.min( + diff.nugget - (diff.nugget % NUGGET_RATIO), + current_dist.ingot * 9 ) end - diff.ingots = (-diff.nuggets / 9) + (-diff.blocks * 9) + diff.ingot = (-diff.nugget / 9) + (-diff.block * 9) return diff end @@ -201,8 +201,8 @@ function diff_to_crafts (diff) -- go from one end e.g. nuggets to the other e.g. blocks, removing -- from the diff to create crafts until the diff is empty local crafts = {} - crafts.nuggets = math.floor(diff.nuggets / NUGGET_RATIO) - crafts.blocks = math.floor(diff.blocks / BLOCK_RATIO) + crafts.nugget = math.floor(diff.nugget / NUGGET_RATIO) + crafts.block = math.floor(diff.block / BLOCK_RATIO) return crafts end