print("Forester 0[paste][/paste]2")sleep(5)rednet[paste][/paste]open("right")-- топливо сзади, продукция слева, поле деятельности - спереди-справаlocal tArgs = { [paste][/paste][paste][/paste][paste][/paste] }local moveFw = 0local moveUp = 0local moveDw = 0local moveR = 0local x = 0local y = 0local z = 0local NFuel=100 --требуемое топливо для цикла, предварительное значение[paste][/paste]local Lmove=0 --величина перемещения в заданном направлении[paste][/paste]function compare() turtle[paste][/paste]select(1) if turtle[paste][/paste]getItemCount(1)<40 then for i=1, 16 do if turtle[paste][/paste]compareTo(i) then turtle[paste][/paste]select(i) q=turtle[paste][/paste]getItemCount(i) turtle[paste][/paste]transferTo(1, q) turtle[paste][/paste]select(1) end end endendlocal function plant() if turtle[paste][/paste]getItemCount(1)>20 and turtle[paste][/paste]detectDown()==false then turtle[paste][/paste]select(1) turtle[paste][/paste]placeDown() endendlocal function coordinate()x, y, z = gps[paste][/paste]locate(10)endlocal function compas() print("Compas activated") coordinate() xOld = x yOld = y zOld = z if turtle[paste][/paste]detect() then turtle[paste][/paste]dig() turtle[paste][/paste]forward() else turtle[paste][/paste]attack() sleep(0[paste][/paste]5) turtle[paste][/paste]attack() turtle[paste][/paste]forward() end coordinate() if x ~= xOld then if x > xOld then vect = 1 else vect = 3 end end if z ~= zOld then if z > zOld then vect = 2 else vect = 4 end end turtle[paste][/paste]back()end-- Функция считывания стартовой точки[paste][/paste]local function loadStartPos() print("Loading StartPos[paste][/paste][paste][/paste][paste][/paste]") file = io[paste][/paste]open("forester[paste][/paste]cfg", "a") file:close() file = io[paste][/paste]open("forester[paste][/paste]cfg", "r") test = file:read() if test ~= nil then xsp = tonumber(test) ysp = tonumber(file:read()) zsp = tonumber(file:read()) vectsp = tonumber(file:read()) t = tonumber(file:read()) l = tonumber(file:read()) k = tonumber(file:read()) leav = tonumber(file:read()) CoalF = tonumber(file:read()) NFuel=l*k*4 else print("No StartPos saved, run with arg 1") return end file:close() print("StartPos was loaded[paste][/paste]") compas()endfunction move() if turtle[paste][/paste]forward() == true then Lmove=Lmove+1 Vdir=vectsp+2 if Vdir>4 then Vdir=Vdir-4 end if vect==vectsp or vect==Vdir then moveFw = moveFw + 1 else moveR = moveR + 1 end endendlocal function goUp()if turtle[paste][/paste]up() == true thenmoveUp = moveUp + 1endendlocal function goDown()if turtle[paste][/paste]down() == true thenmoveDw = moveDw + 1endendlocal function vectR()turtle[paste][/paste]turnRight()vect = vect + 1if vect > 4 then vect = 1end-- print("vectr="[paste][/paste][paste][/paste]vect)endlocal function vectL()turtle[paste][/paste]turnLeft()vect = vect - 1if vect < 1 then vect = 4end-- print("vectl="[paste][/paste][paste][/paste]vect)endlocal function refueling() local fuel=turtle[paste][/paste]getFuelLevel() print("Current fuel=", fuel) if NFuel>fuel then if CoalF==1 then print("Fuel neded: "[paste][/paste][paste][/paste]NFuel) sleep(0[paste][/paste]1) print("Current fuel level: "[paste][/paste][paste][/paste]fuel) sleep(0[paste][/paste]1) print("Refueling[paste][/paste][paste][/paste][paste][/paste]") turtle[paste][/paste]select(2) vectR() vectR() turtle[paste][/paste]suck() turtle[paste][/paste]refuel() fuel=turtle[paste][/paste]getFuelLevel() vectR() vectR() print("Fuel neded: "[paste][/paste][paste][/paste]NFuel) sleep(0[paste][/paste]1) print("Current fuel level: "[paste][/paste][paste][/paste]fuel) if NFuel>fuel then while NFuel>fuel do print("not enough fuel place fuel in slot 2") turtle[paste][/paste]select(2) turtle[paste][/paste]refuel() fuel=turtle[paste][/paste]getFuelLevel() sleep(5) end end else print("charging[paste][/paste][paste][/paste][paste][/paste]") while NFuel>fuel do sleep(5) fuel=turtle[paste][/paste]getFuelLevel() print("Fuel neded: "[paste][/paste][paste][/paste]NFuel) sleep(0[paste][/paste]1) print("Current fuel level: "[paste][/paste][paste][/paste]fuel) end end endendlocal function reSupply() while rs[paste][/paste]getInput("left")==true do local fuel=turtle[paste][/paste]getFuelLevel() print("Storage is full[paste][/paste] Refueling[paste][/paste][paste][/paste][paste][/paste]", fuel) sleep(20) end compare() for i=2,16 do turtle[paste][/paste]select(i) turtle[paste][/paste]dropDown() end refueling() end-- Функция сохранения начальной точки[paste][/paste]local function saveStartPos() coordinate() print("Saving StartPos[paste][/paste][paste][/paste][paste][/paste]") xsp = x ysp = y zsp = z vectsp = vect file = io[paste][/paste]open("forester[paste][/paste]cfg", "w") file:write(xsp[paste][/paste][paste][/paste]"\n") file:write(ysp[paste][/paste][paste][/paste]"\n") file:write(zsp[paste][/paste][paste][/paste]"\n") file:write(vectsp[paste][/paste][paste][/paste]"\n") file:write(t[paste][/paste][paste][/paste]"\n") file:write(l[paste][/paste][paste][/paste]"\n") file:write(k[paste][/paste][paste][/paste]"\n") file:write(leav[paste][/paste][paste][/paste]"\n") file:write(CoalF[paste][/paste][paste][/paste]"\n") file:close() print("StartPos was saved[paste][/paste]")end-- Функция задания начальной позиции при аргументе 1if #tArgs == 1 then compas() print("Sleep time, t: ") t=tonumber(read()) print("Length, l: ") l=tonumber(read()) print("Width, k: ") k=tonumber(read()) print("Enable Leaves cutting, 1/0: ") leav=tonumber(read()) print("Enable Coal fuel, 1/0: ") CoalF=tonumber(read()) saveStartPos() NFuel=l*k*4 else loadStartPos()endlocal function leaves()if leav == 1 then if turtle[paste][/paste]detect() then turtle[paste][/paste]dig() vectL() if turtle[paste][/paste]detect() then turtle[paste][/paste]dig() end vectL() if turtle[paste][/paste]detect() then turtle[paste][/paste]dig() end vectL() if turtle[paste][/paste]detect() then turtle[paste][/paste]dig() end vectL() endendendlocal function modul()coordinate()xL = ((x - xsp)^2)^0[paste][/paste]5yL = ((y - ysp)^2)^0[paste][/paste]5zL = ((z - zsp)^2)^0[paste][/paste]5 if vectsp == 1 or vectsp == 3 then lt = xL kt = zL else lt = zL kt = xL endendlocal function woodcut() print("Woodcut initialized[paste][/paste]") moveUp = 0 turtle[paste][/paste]dig() move() turtle[paste][/paste]digDown() turtle[paste][/paste]select(1) amSup=turtle[paste][/paste]getItemCount(1) if amSup>1 then turtle[paste][/paste]placeDown() end while turtle[paste][/paste]detectUp() do turtle[paste][/paste]digUp() goUp() leaves() end moveDw = 0 while moveUp > moveDw do if turtle[paste][/paste]detectDown() then turtle[paste][/paste]digDown() else goDown() end endendlocal function goHome() Lmove = 0 moveUp = 0 moveDw = 0 modul() print("Go Home initialized") if y > ysp + 5 then while moveDw < yL - 5 do if turtle[paste][/paste]detectDown() then turtle[paste][/paste]digDown() else goDown() end end end if y < ysp + 5 then while moveUp < 5 - yL do if turtle[paste][/paste]detectUp() then turtle[paste][/paste]digUp() else goUp() end end end if x > xsp then while vect ~= 3 do vectR() end while xL > Lmove do if turtle[paste][/paste]detect() then turtle[paste][/paste]dig() else move() end end end if x < xsp then while vect ~= 1 do vectR() end Lmove = 0 while xL > Lmove do if turtle[paste][/paste]detect() then turtle[paste][/paste]dig() else move() end end end if z > zsp then while vect ~= 4 do vectR() end Lmove = 0 while zL > Lmove do if turtle[paste][/paste]detect() then turtle[paste][/paste]dig() else move() end end end Lmove = 0 if z < zsp then while vect ~= 2 do vectR() end while zL > Lmove do if turtle[paste][/paste]detect() then turtle[paste][/paste]dig() else move() end end end moveDw = 0 while moveDw < 5 do if turtle[paste][/paste]detectDown() then turtle[paste][/paste]digDown() else goDown() end end while vect ~= vectsp do vectR() endendfunction checkFuel() fuel=turtle[paste][/paste]getFuelLevel() Hfuel=l+k+30 if Hfuel>fuel then goHome() reSupply() endendlocal function patrolling() moveUp = 0 moveFw = 0 moveDw = 0 moveR = 0 turtle[paste][/paste]select(1) move() while moveR < k do while moveFw < l do if turtle[paste][/paste]detect() then woodcut() else turtle[paste][/paste]suckDown() checkFuel() move() plant() end end vectR() if turtle[paste][/paste]detect() then woodcut() else turtle[paste][/paste]suckDown() checkFuel() move() plant() end vectR() moveFw = 0 while moveFw < l do if turtle[paste][/paste]detect() then woodcut() else turtle[paste][/paste]suckDown() checkFuel() move() plant() end end vectL() if turtle[paste][/paste]detect() then woodcut() else turtle[paste][/paste]suckDown() checkFuel() move() plant() end vectL() moveFw = 0 endendwhile true do reSupply() coordinate() if xsp ~= x or ysp ~= y or zsp ~= z or vect ~= vectsp then goHome() reSupply() end patrolling() goHome() reSupply() print("Sleeping "[paste][/paste][paste][/paste]t[paste][/paste][paste][/paste]"sec") sleep(t)end