Advertisement
ivan52

TreeFerma(CC)

Feb 14th, 2015
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.39 KB | None | 0 0
  1. loc = {x=0, y=0, z=0, b=0}
  2. a=10
  3. p=0
  4.  
  5. function oblom()
  6.   fx = fs.open('locX','r')
  7.   loc.x = tonumber(fx.readLine())
  8.   fx.close()
  9.   fy = fs.open('locY','r')
  10.   loc.y = tonumber(fy.readLine())
  11.   fy.close()
  12.   fz = fs.open('locZ','r')
  13.   loc.z = tonumber(fz.readLine())
  14.   fz.close()
  15.   fb = fs.open('locB','r')
  16.   loc.b = tonumber(fb.readLine())
  17.   fb.close()
  18.   fp = fs.open('locP','r')
  19.   p = tonumber(fp.readLine())
  20.   fp.close()
  21.   fa = fs.open('pecA','r')
  22.   a = tonumber(fa.readLine())
  23.   fa.close()
  24.   if a>10 then
  25.        while turtle.getFuelLevel()<11000 do
  26.        turtle.select(1)
  27.        if a<11 then
  28.        while loc.b~=1 do
  29.        turnRight()
  30.        end
  31.        turtle.suck(64 - turtle.getItemCount())
  32.        a=11
  33.        fa=fs.open('pecA','w')
  34.        fa.write(a)
  35.        fa.close()
  36.        end
  37.        if a<12 then
  38.        while loc.b ~= 0 do
  39.        turnLeft()
  40.        end
  41.        if loc.z<2 then
  42.        while loc.y < 1 do
  43.        forward()
  44.        end
  45.        while loc.z < 2  do
  46.        up()
  47.        end
  48.        end
  49.        while loc.y>0 do
  50.        back()
  51.        end
  52.        turtle.dropDown()
  53.        a=12
  54.        fa=fs.open('pecA','w')
  55.        fa.write(a)
  56.        fa.close()
  57.        end
  58.        if a<13 then
  59.        if loc.z > 0 then
  60.        while loc.y < 1 do
  61.        forward()
  62.        end
  63.        while loc.z>0  do
  64.        down()
  65.        end
  66.        end
  67.        while loc.y>0 do
  68.        back()
  69.        end
  70.        a=13
  71.        fa=fs.open('pecA','w')
  72.        fa.write(a)
  73.        fa.close()
  74.        end
  75.        if a<14 then
  76.          while turtle.getItemCount()<64 do
  77.            turtle.suckUp()
  78.            sleep(8)
  79.          end
  80.          turtle.dropUp()
  81.          a=14
  82.          fa=fs.open('pecA','w')
  83.          fa.write(a)
  84.          fa.close()
  85.        end
  86.        if a<15 then
  87.          turtle.refuel()
  88.          a=15
  89.          fa=fs.open('pecA','w')
  90.          fa.write(a)
  91.          fa.close()
  92.        end
  93.        a=10
  94.        fa=fs.open('pecA','w')
  95.        fa.write(a)
  96.        fa.close()
  97. end  
  98. end
  99.  
  100.   if (loc.y ~= 4) or (loc.x ~= 0) or (loc.b ~= 2)
  101.   then
  102.      if ((loc.b == 1) or (loc.b == 3)) and (loc.z >= 2)
  103.      then
  104.          if p == 1 then
  105.            forward()
  106.            p=0
  107.            fp=fs.open('locP','w')
  108.            fp.write(p)
  109.            fp.close()
  110.          end
  111.         if (loc.z > 2) or ((loc.x+2)%2 == 1)
  112.         then
  113.         up()
  114.         while turtle.compareUp() == true do
  115.           turtle.digUp()
  116.           up()
  117.         end
  118.         while loc.z>2 do
  119.           turtle.digDown()
  120.           down()
  121.         end
  122.         turtle.digDown()
  123.         turtle.select(16)
  124.         turtle.placeDown()
  125.         turtle.select(1)
  126.         back()
  127.       end
  128.     end
  129.     if a ~= 1 then
  130.     dom(true)
  131.     end
  132.     a=1
  133.     fa=fs.open('pecA','w')
  134.     fa.write(a)
  135.     fa.close()
  136.     while loc.b~=0 do
  137.     turnLeft()
  138.     end
  139.     while loc.y < 1 do
  140.     forward()
  141.     end
  142. while loc.z<2 do
  143.     up()
  144.   end
  145.   while loc.y < 4 do
  146.     forward()
  147.   end  
  148.   a=10
  149.   fa=fs.open('pecA','w')
  150.   fa.write(a)
  151.   fa.close()
  152.    end
  153. end
  154. function forward()
  155.   if turtle.forward() then
  156.     if loc.b == 0 then loc.y = loc.y+1
  157.     elseif loc.b == 1 then loc.x = loc.x+1
  158.     elseif loc.b == 2 then loc.y = loc.y-1
  159.     else loc.x = loc.x-1 end
  160.     fx=fs.open('locX','w')
  161.     fx.write(loc.x)
  162.     fx.close()
  163.     fy=fs.open('locY','w')
  164.     fy.write(loc.y)
  165.     fy.close()
  166.     return true
  167.   else
  168.     return false
  169.   end
  170. end
  171. function back()
  172.   if turtle.back() then
  173.     if loc.b == 0 then loc.y = loc.y-1
  174.     elseif loc.b == 1 then loc.x = loc.x-1
  175.     elseif loc.b == 2 then loc.y = loc.y+1
  176.     else loc.x = loc.x+1 end
  177.     fx=fs.open('locX','w')
  178.     fx.write(loc.x)
  179.     fx.close()
  180.     fy=fs.open('locY','w')
  181.     fy.write(loc.y)
  182.     fy.close()
  183.     return true
  184.   else
  185.     return false
  186.   end
  187. end
  188. function up()
  189.   if turtle.up() then
  190.     loc.z = loc.z+1
  191.     fz=fs.open('locZ','w')
  192.     fz.write(loc.z)
  193.     fz.close()
  194.     return true
  195.   else
  196.     return false
  197.   end
  198. end
  199. function down()
  200.   if turtle.down() then
  201.     loc.z = loc.z-1
  202.     fz=fs.open('locZ','w')
  203.     fz.write(loc.z)
  204.     fz.close()
  205.     return true
  206.   else
  207.     return false
  208.   end
  209. end
  210. function turnRight()
  211.   turtle.turnRight()
  212.   loc.b = (loc.b+1)%4
  213.   fb=fs.open('locB','w')
  214.   fb.write(loc.b)
  215.   fb.close()
  216.  
  217. end
  218. function turnLeft()
  219.   turtle.turnLeft()
  220.   loc.b = (loc.b+3)%4
  221.   fb=fs.open('locB','w')
  222.   fb.write(loc.b)
  223.   fb.close()
  224. end
  225.  
  226.  
  227.  
  228. function dom(noreturn)
  229.   -- двигаемся домой
  230.   local d = loc.b
  231.   local p = loc.x
  232.   local t = loc.y
  233.   if loc.b ~= 2 then
  234.     while loc.b ~= 2 do
  235.       turnRight()
  236.     end
  237.   end
  238.   if loc.x > 0 then
  239.     turnRight()
  240.     if turtle.detect()==true then
  241.       while loc.b ~= 2 do
  242.         turnLeft()
  243.       end
  244.       forward()
  245.       turnRight()
  246.     end
  247.     while loc.x ~= 0 do
  248.       forward()
  249.     end
  250.     turnLeft()
  251.   end
  252.   if loc.x < 0 then
  253.     turnLeft()
  254.     while loc.x ~= 0 do
  255.       forward()
  256.     end
  257.     turnRight()
  258.   end
  259.   while loc.y > 1 do
  260.     forward()
  261.   end
  262.   while loc.z>0 do
  263.     down()
  264.   end
  265.   forward()
  266.  
  267.   -- выгрузка дерева
  268.   if turtle.getItemCount(1)>1 then
  269.   while loc.b ~=1 do
  270.   turnLeft()
  271.   end
  272.   for i=1,15 do
  273.     turtle.select(i)
  274.     if turtle.compareTo(16)==true then
  275.       turtle.dropDown()
  276.     else
  277.       turtle.drop()
  278.     end
  279.   end
  280.   while loc.b ~= 2 do
  281.   turnRight()
  282.   end
  283.   for i=1,15 do
  284.     turtle.select(i)
  285.     if turtle.compareTo(16)==true then
  286.       turtle.dropDown()
  287.     else
  288.       turtle.drop()
  289.     end
  290.   end
  291.   end
  292.   while loc.b ~= 2 do
  293.   turnLeft()
  294.   end
  295.   -- забираем саженцы
  296.   turtle.select(16)
  297.   turtle.suckDown(64-turtle.getItemCount(16))
  298.  
  299.   -- зарядка
  300.   while turtle.getFuelLevel()<11000 do
  301.   turtle.select(1)
  302.   turnRight()
  303.   turtle.suck(64 - turtle.getItemCount())
  304.   a=11
  305.   fa=fs.open('pecA','w')
  306.   fa.write(a)
  307.   fa.close()
  308.   turnLeft()
  309.   forward()
  310.   for i=1,2  do
  311.   up()
  312.   end
  313.   back()
  314.   turtle.dropDown()
  315.   a=12
  316.   fa=fs.open('pecA','w')
  317.   fa.write(a)
  318.   fa.close()
  319.   forward()
  320.   for i=1,2  do
  321.   down()
  322.   end
  323.   back()
  324.   a=13
  325.   fa=fs.open('pecA','w')
  326.   fa.write(a)
  327.   fa.close()
  328.   while turtle.getItemCount()<64 do
  329.   turtle.suckUp()
  330.   sleep(8)
  331.   end
  332.   turtle.dropUp()
  333.   a=14
  334.   fa=fs.open('pecA','w')
  335.   fa.write(a)
  336.   fa.close()
  337.   turtle.refuel()
  338.   a=15
  339.   fa=fs.open('pecA','w')
  340.   fa.write(a)
  341.   fa.close()
  342.   end
  343.   a=10
  344.   fa=fs.open('pecA','w')
  345.   fa.write(a)
  346.   fa.close()
  347.   turtle.select(1)
  348.   -- возвращаемся если нет флага "в один конец"
  349.   if not noreturn then
  350.     forward()
  351.     while loc.z<2 do
  352.       up()
  353.     end
  354.     while loc.y < t do
  355.       forward()
  356.     end
  357.     if loc.x ~= p then
  358.       turnRight()
  359.       while loc.x ~=p do
  360.         forward()
  361.       end
  362.     end
  363.     if loc.b ~= d then
  364.       while loc.b ~= d do
  365.         turnLeft()
  366.       end
  367.     end
  368.   end
  369. end
  370.  
  371. function usl()
  372. if turtle.getItemCount(15)>32
  373. then
  374. dom()
  375. end
  376. if turtle.getItemCount(16)<8
  377. then
  378. dom()
  379. end
  380. if turtle.getFuelLevel()<5000
  381. then
  382. dom()
  383. end
  384. end
  385.  
  386. function axe()
  387. if turtle.detect()==true
  388. then
  389. turtle.dig()
  390. p=1
  391. fp=fs.open('locP','w')
  392. fp.write(p)
  393. fp.close()
  394. forward()
  395. p=0
  396. fp=fs.open('locP','w')
  397. fp.write(p)
  398. fp.close()
  399. turtle.digDown()
  400. while turtle.compareUp() == true do
  401. turtle.digUp()
  402. up()
  403. end
  404. while loc.z>2 do
  405. turtle.digDown()
  406. down()
  407. end
  408. turtle.select(16)
  409. turtle.placeDown()
  410. turtle.select(1)
  411. back()
  412. end
  413. end
  414.  
  415.  
  416.  
  417.  
  418. if fs.exists('locX') == false then
  419.     fx=fs.open('locX','w')
  420.     fx.write(loc.x)
  421.     fx.close()
  422. end
  423. if fs.exists('locY') == false then
  424.     fy=fs.open('locY','w')
  425.     fy.write(loc.y)
  426.     fy.close()
  427. end
  428. if fs.exists('locZ') == false then
  429.     fx=fs.open('locZ','w')
  430.     fx.write(loc.x)
  431.     fx.close()
  432. end
  433. if fs.exists('locB') == false then
  434.     fb=fs.open('locB','w')
  435.     fb.write(loc.b)
  436.     fb.close()
  437. end
  438. if fs.exists('locP') == false then
  439.     fp=fs.open('locP','w')
  440.     fp.write(p)
  441.     fp.close()
  442. end
  443. if fs.exists('pecA') == false then
  444.     fa=fs.open('pecA','w')
  445.     fa.write(a)
  446.     fa.close()
  447. end
  448. oblom()
  449. while true do
  450. for i=1, 8 do
  451.     usl()
  452.     forward()
  453.     turnLeft()
  454.     axe()
  455.     for t=1,2 do
  456.         turnRight()
  457.     end
  458.     axe()
  459.     turnLeft()
  460.     forward()
  461.     if (i == 4) or (i==8) then
  462.       turnRight()
  463.       for c=1, 4 do forward() end
  464.       turnRight()
  465.     end
  466.   end
  467. for i=1,10 do
  468. sleep(72)
  469. print(i*10,' %')
  470. end
  471. term.clear()
  472. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement