Compare commits
4 commits
9a8f81e428
...
af05e2dd21
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af05e2dd21 | ||
|
|
6ced67f883 | ||
|
|
56c511324e | ||
|
|
ef808abb94 |
1 changed files with 17 additions and 33 deletions
50
mine.lua
50
mine.lua
|
|
@ -6,9 +6,13 @@ local FUEL_RESERVE = 800
|
||||||
local FUEL_REFUEL_UNIT = 8 -- how many items to refuel with at a time
|
local FUEL_REFUEL_UNIT = 8 -- how many items to refuel with at a time
|
||||||
local FULL_CHECK_SLOT = 14 -- slot to check for "fullness"
|
local FULL_CHECK_SLOT = 14 -- slot to check for "fullness"
|
||||||
|
|
||||||
|
|
||||||
|
-- what size is good for a medium-size piece
|
||||||
|
local MED_DIM = 11
|
||||||
|
|
||||||
-- what size of a dimension is considered big enough to split into medium-size
|
-- what size of a dimension is considered big enough to split into medium-size
|
||||||
-- pieces
|
-- pieces
|
||||||
local BIG_DIM = 7
|
local BIG_DIM = MED_DIM * 3
|
||||||
|
|
||||||
local V_ZERO = vector.new(0, 0, 0)
|
local V_ZERO = vector.new(0, 0, 0)
|
||||||
local UNIT_X = vector.new(1, 0, 0)
|
local UNIT_X = vector.new(1, 0, 0)
|
||||||
|
|
@ -32,7 +36,6 @@ end
|
||||||
local bmetatable, new_block
|
local bmetatable, new_block
|
||||||
-- what is this? a type that holds a starting position and a dimention as
|
-- what is this? a type that holds a starting position and a dimention as
|
||||||
-- two vectors
|
-- two vectors
|
||||||
-- TODO learn about metatables
|
|
||||||
local Block = {
|
local Block = {
|
||||||
-- orient our corner and offset to a vector
|
-- orient our corner and offset to a vector
|
||||||
orient = function (self, pos)
|
orient = function (self, pos)
|
||||||
|
|
@ -60,7 +63,6 @@ local Block = {
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
take = function (self, amt, dir)
|
take = function (self, amt, dir)
|
||||||
-- TODO
|
|
||||||
if dir ~= "x" and dir ~= "y" and dir ~= "z" then return nil end
|
if dir ~= "x" and dir ~= "y" and dir ~= "z" then return nil end
|
||||||
|
|
||||||
local block_offset = -1
|
local block_offset = -1
|
||||||
|
|
@ -212,8 +214,6 @@ function dropOffItems (starting_point, go_back)
|
||||||
print("Time to drop off what I got")
|
print("Time to drop off what I got")
|
||||||
-- Turn off mining
|
-- Turn off mining
|
||||||
mode.mine = { forward = true }
|
mode.mine = { forward = true }
|
||||||
-- Note current position (assuming facing FORWARD)
|
|
||||||
local pos_state = getCurrentPos()
|
|
||||||
-- Return to origin, facing BACK
|
-- Return to origin, facing BACK
|
||||||
moveAbs(starting_point)
|
moveAbs(starting_point)
|
||||||
moveAbs(V_ZERO)
|
moveAbs(V_ZERO)
|
||||||
|
|
@ -224,10 +224,9 @@ function dropOffItems (starting_point, go_back)
|
||||||
turtle.drop()
|
turtle.drop()
|
||||||
end
|
end
|
||||||
turtle.select(1)
|
turtle.select(1)
|
||||||
-- Return to current position, facing forward
|
-- Return to the mining zone, facing forward
|
||||||
if go_back then
|
if go_back then
|
||||||
moveAbs(starting_point)
|
moveAbs(starting_point)
|
||||||
moveAbs(pos_state)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -282,33 +281,19 @@ function canMine (block)
|
||||||
end
|
end
|
||||||
|
|
||||||
function splitHorizontal (block)
|
function splitHorizontal (block)
|
||||||
-- TODO make this less naive?
|
local take_amt = 1
|
||||||
-- Future work: potentially split a large block into smaller blocks
|
|
||||||
-- based on currentPos (think splitting down the middle instead of
|
|
||||||
-- splitting off of one end)
|
|
||||||
local differentSigns = function (a, b)
|
|
||||||
return math.abs(a + b) < math.abs(a) + math.abs(b)
|
|
||||||
end
|
|
||||||
local bigBlock = function (block)
|
local bigBlock = function (block)
|
||||||
return (block.v2.x >= BIG_DIM) and (block.v2.z >= BIG_DIM)
|
return (block.v2.x >= BIG_DIM) or (block.v2.z >= BIG_DIM)
|
||||||
end
|
end
|
||||||
local inMiddleOfBlock = function (block)
|
if bigBlock(block) then
|
||||||
local middle_of_x = differentSigns(block.v1.x, block.v2.x)
|
take_amt = MED_DIM
|
||||||
local middle_of_z = differentSigns(block.v1.z, block.v2.z)
|
|
||||||
return middle_of_x or middle_of_z
|
|
||||||
end
|
|
||||||
local inMiddleOfBigBlock = function (block)
|
|
||||||
return bigBlock(block) and inMiddleOfBlock(block)
|
|
||||||
end
|
|
||||||
if inMiddleOfBigBlock(block) then
|
|
||||||
-- TODO split the big block at where the turtle is near
|
|
||||||
end
|
end
|
||||||
-- decide whether to take a slice off of the x or z direction
|
-- decide whether to take a slice off of the x or z direction
|
||||||
-- (criteria: take the dimension that is not too big)
|
-- (criteria: bite a piece off the bigger dimension)
|
||||||
if math.abs(block.v2.z) < BIG_DIM then
|
if math.abs(block.v2.z) >= math.abs(block.v2.x) then
|
||||||
return block:take(1, "z")
|
return block:take(take_amt, "z")
|
||||||
else
|
else
|
||||||
return block:take(1, "x")
|
return block:take(take_amt, "x")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -324,17 +309,16 @@ function split (block)
|
||||||
end
|
end
|
||||||
|
|
||||||
function process (stack, starting_point)
|
function process (stack, starting_point)
|
||||||
-- fuel and go to starting point
|
|
||||||
refuelUntil(FUEL_RESERVE)
|
refuelUntil(FUEL_RESERVE)
|
||||||
mode.mine = { forward = true }
|
mode.mine = { forward = true }
|
||||||
if #stack == 0 then return nil end
|
if #stack == 0 then return nil end
|
||||||
|
checkAndDropOff(starting_point)
|
||||||
local working = table.remove(stack):orient(getCurrentPos())
|
local working = table.remove(stack):orient(getCurrentPos())
|
||||||
print("Working:", working:tostring())
|
print("Working:", working:tostring())
|
||||||
if canMine(working) then
|
if canMine(working) then
|
||||||
checkAndDropOff(starting_point)
|
|
||||||
mine(working)
|
mine(working)
|
||||||
else
|
else
|
||||||
local new, remainder = split(working, mode.v)
|
local new, remainder = split(working)
|
||||||
table.insert(stack, remainder)
|
table.insert(stack, remainder)
|
||||||
table.insert(stack, new)
|
table.insert(stack, new)
|
||||||
end
|
end
|
||||||
|
|
@ -349,7 +333,7 @@ function run (v1, v2)
|
||||||
|
|
||||||
process({ block }, starting_point)
|
process({ block }, starting_point)
|
||||||
-- return to base
|
-- return to base
|
||||||
dropOffItems(starting_point)
|
dropOffItems(starting_point, false)
|
||||||
turnToFace(FORWARD)
|
turnToFace(FORWARD)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue