local function loadSettings()
file = io.open( "settings.txt", "r" )
while true do
line = file:read()
if line == nil then break end
if line == "true" then
shouldOutput = true
else
shouldOutput = false
end
line = file:read()
if line == nil then break end
doWidth = tonumber(line)
line = file:read()
if line == nil then break end
doLenght = tonumber(line)
line = file:read()
if line == nil then break end
sapling = tonumber(line)
line = file:read()
if line == nil then break end
dirt = tonumber(line)
line = file:read()
if line == nil then break end
fuel = tonumber(line)
file:close()
return true
end
file:close()
return false
end
local function createSettings()
term.clear()
term.setCursorPos( 1,1 )
print( "Set the settings." )
write( "Output Redstone on cycle: " )
local str = string.lower( read() )
if str == "1" or str == "yes" or str == "true" then
shouldOutput = true
else
shouldOutput = false
end
write("How many rows?")
doWidth = tonumber(read())
write("How many trees per row? ")
doLenght = tonumber(read())
write("In what slot is your sapling (1-16)?")
sapling = read()
write("In what slot is the dirt (1-16)?")
dirt = read()
term.write("In what slot is the fuel (1-16)?")
fuel = term.read()
file = io.open("settings.txt", "w")
if file == nil then
--error? could be locked
return
end
if shouldOutput then
file:write( "true" )
file:write( "n" )
else
file:write( "false" )
file:write( "n" )
end
file:write( doWidth )
file:write( "n" )
file:write( doLenght )
file:write( "n" )
file:write( sapling )
file:write( "n" )
file:write( dirt )
file:write( "n" )
file:write( fuel )
file:write( "n" )
file:close()
term.clear()
term.setCursorPos( 1,1 )
print( "Ready to start!" )
end
term.clear()
term.setCursorPos( 1,1 )
print( "X90 Tree Farmer Logger program starting..." )
if fs.exists( "settings.txt" ) then
if not loadSettings() then
createSettings()
end
term.clear()
term.setCursorPos( 1,1 )
print( "Ready to cycle" )
else
createSettings()
end
function goForward (times)
for i=1, times do
turtle.forward()
end
end
function xFarmTree ()
goForward(3)
if turtle.detect() then
turtle.dig()
end
turtle.forward()
if turtle.detectUp() then
while turtle.detectUp() do
turtle.digUp()
turtle.up()
end
while not turtle.compareDown(dirt) do
turtle.down()
if(turtle.detectDown() then
turtle.digDown()
end
end
turtle.up()
turtle.place(sapling)
end
end
function newRow (heading)
if heading == 1 then
turtle.turnLeft()
goForward(7)
turtle.turnLeft()
else
turtle.turnRight()
goForward(7)
turtle.turnRight()
end
end
function checkFuel ()
movementLenght = (doLenght*5)*(doWidth*5)
if turtle.getFuelLevel() < movementLenght then
print("Turtle is refueling")
print("New fuel level is: " + turtle.getFuelLevel())
turtle.refuel(fuel)
else
print("Turtle has a sufficient fuel level");
end
function turtleStart ()
checkFuel()
turtle.up()
end
function turtleShutD ()
turtle.down()
end
--Start the farming process
function harvest ()
turtleStart()
heading=1
for i=1, doWidth do
for i=1, doLenght do
xFarmTree()
end
-- end the farming
--Check what way the turtle is going.
if heading/2 == 0 then
heading = 2
else
heading = 1
end
--check end
newRow(heading)
heading = heading+1
end
turtleShutD()
end
while true do
event, p1, p2 = os.pullEvent()
if event == "rednet_message" and p2 == "start" then
print("Computerized harvest starting.")
harvest()
end
if event == "char" and p1 == "r" then
print("Manual harvest starting.")
harvest()
end
end
--Need to test to see if current code is working as expected.
--Need to implement a proper shutdown function, IE. Where the turtle returns to start point.
--Need to optimize code when finished with beta release.
--Need to implement a rednet server option.
--Need to implpement a feature to save the settings.