This commit is contained in:
Kai Vogelgesang 2020-07-08 13:04:31 +02:00
parent fc0b34731f
commit 86fbf428b2

View File

@ -43,6 +43,12 @@ local BACKUP_SAP_SLOT_TARGET_COUNT = 20
-- Should be enough even if every tree is fully grown
local FUEL_LEVEL_TARGET = 1000
local function breakpoint()
write("Enter to step ")
repeat e, d = os.pullEvent() until e == "key" and d == 257
print("(OK)")
end
local function calculate_tree_position(row_index, tree_index)
local x = (row_index - 1) * 5
@ -105,6 +111,10 @@ local state_machine = {
local x, z = calculate_tree_position(T.state.current_row, T.state.current_tree)
local o
if T.state.current_tree > 12 then
breakpoint()
end
if T.state.current_row ~= 1 and T.state.current_tree == 1 then
-- we just turned towards a new row and are approaching in positive x direction
x = x - 1
@ -139,7 +149,6 @@ local state_machine = {
["ASCEND_TREE"] = function()
local success, data = turtle.inspectUp()
print("inspect", success, data)
if not success and T.state.y < TREE_MAX_Y - 1 then
-- probably reset after chopping a block
T.up()
@ -147,15 +156,14 @@ local state_machine = {
while true do
local success, data = turtle.inspectUp()
print("inspect", success, data)
if not success or data.name ~= LOG_NAME then
print("chopped all the wood")
-- chopped all the wood
break
end
turtle.digUp()
if T.state.y == TREE_MAX_Y - 1 then
print("below last log")
breakpoint()
-- we are below the last log, no need to move up
break
end
@ -251,8 +259,4 @@ while true do
print("State: " .. T.state.current_state)
print("Pos: " .. T.state.x .. "," .. T.state.z .. "(" .. T.getOrientation() .. ")")
T.state.current_state = state_machine[T.state.current_state]()
write("Enter to step ")
repeat e, d = os.pullEvent() until e == "key" and d == 257
print("(OK)")
end