Advertisement
dadragon84

do_wheat

Feb 26th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.88 KB | None | 0 0
  1. -- do_wheat  (part of FarmerTurt)
  2. -----------------------------------------------------------------------
  3. term.clear()
  4. term.setCursorPos(1, 1)
  5. minerID = os.getComputerID()
  6. turtleName = nil
  7. consoleID = 0
  8. version = "1.0"
  9. function getConsoleID()
  10.   local fname = "ConsoleID"
  11.   if fs.exists(fname) then
  12.     file = fs.open(fname, "r")
  13.     consoleID = tonumber(file.readAll())
  14.     file.close()
  15.     print("Monitor Console ID: "..consoleID)
  16.   else
  17.     updateStatus("Waiting for Console ID...",true)
  18.     term.write("Monitor Console ID: ")
  19.     consoleID = io.read()
  20.     file = fs.open(fname, "w")
  21.     file.write(consoleID)
  22.     file.close()
  23.     consoleID = tonumber(consoleID)
  24.   end
  25. end
  26. function updateStatus(msg, silent)
  27.   if not rednet.isOpen("right") then rednet.open("right") end
  28.   if rednet.isOpen("right") then
  29.     if turtleName == nil then return end
  30.     networkmsg = "MM:"..turtleName..": "..msg
  31.     if consoleID == 0 then
  32.       rednet.broadcast(networkmsg)
  33.     else
  34.       rednet.send(consoleID,networkmsg)
  35.     end
  36.   end
  37.   if not silent then print(msg) end
  38. end
  39. function getTurtleName()
  40.   local fname = "TurtleName"
  41.   if fs.exists(fname) then
  42.     file = fs.open(fname, "r")
  43.     turtleName = file.readAll()
  44.     file.close()
  45.   else
  46.     term.write("Turtle Name: ")
  47.     turtleName = io.read()
  48.     file = fs.open(fname, "w")
  49.     file.write(turtleName)
  50.     file.close()
  51.   end
  52. end
  53. -- Main Program
  54. updateStatus("Starting")
  55. term.clear()
  56. term.setCursorPos(1,1)
  57. getTurtleName()
  58. getConsoleID()
  59. function update()
  60. end
  61.  
  62.   function fuelItUp()
  63.   updateStatus("...Working")
  64. --Finds out if the turtle needs to refuel and if it has fuel to run
  65.   needsFuel = turtle.getFuelLevel()
  66.   minimumFuelLevel = 10
  67.   hasFuel = turtle.getItemCount(16)
  68.   useFuel = turtle.refuel()
  69.   if needsFuel == "unlimited" then
  70.    
  71.   else
  72.     if tonumber(needsFuel) < tonumber(minimumFuelLevel) then
  73.       if hasFuel > 0 then
  74.         turtle.select(16)
  75.         turtle.refuel(1)
  76.         turtle.select(1)
  77.       else
  78.         updateStatus("Please insert fuel into slot 16")
  79.         repeat os.sleep(1)
  80.         until tonumber(turtle.getItemCount(16)) > 0
  81.         fuelItUp()
  82.       end
  83.     end
  84.   end
  85. end
  86. function questions()
  87.   print("PREREQUISITES: Fuel in last slot 16, chest in slot 1.")
  88.   print("How many blocks deep?")
  89.   length = io.read()
  90.   print("How many rows wide?")
  91.   rows = io.read()
  92.   declarations()
  93. end
  94.  
  95. function declarations()
  96.   currentPos = 0
  97.   currentRow = 1
  98.   startBlock = 1
  99.   startRow = 1
  100.   totalPlanted = 0
  101.   detDown = turtle.detectDown()
  102.   prime()
  103. end
  104.  
  105. function prime()
  106.   fuelItUp()
  107.   turtle.up()
  108.   turtle.forward()
  109.   currentPos = currentPos + 1
  110.   plantDown()
  111. end
  112.  
  113. function plant()
  114.   if detDown == true then
  115.     turtle.digDown()
  116.     turtle.suckDown()
  117.   end
  118. end
  119.  
  120. function plantDown()
  121.   while tonumber(currentPos) ~= tonumber(length) do
  122.     fuelItUp()
  123.     plant()
  124.     turtle.forward()
  125.     currentPos = currentPos + 1
  126.   end
  127.   if tonumber(currentRow) ~= tonumber(rows) then
  128.     if tonumber(currentRow) % 2 == 0 then
  129.       plant()
  130.       rightTurn()
  131.     else
  132.       plant()
  133.       leftTurn()
  134.     end
  135.   else
  136.     plant()
  137.     ending()
  138.   end
  139. end
  140.  
  141. function leftTurn()
  142.   turtle.turnLeft()
  143.   turtle.forward()
  144.   turtle.forward() -- skip water lane
  145.   turtle.turnLeft()
  146.   currentRow = currentRow + 1
  147.   plantBack()
  148. end
  149.  
  150. function rightTurn()
  151.   turtle.turnRight()
  152.   turtle.forward()
  153.   turtle.forward() -- skip water lane
  154.   turtle.turnRight()
  155.   currentRow = currentRow + 1
  156.   plantDown()
  157. end
  158.  
  159. function plantBack()
  160.   while tonumber(currentPos) ~= tonumber(startBlock) do
  161.     fuelItUp()
  162.     plant()
  163.     turtle.forward()
  164.     currentPos = currentPos - 1
  165.   end
  166.   if tonumber(currentRow) ~= tonumber(rows) then
  167.     if tonumber(currentRow) % 2 == 0 then
  168.       plant()
  169.       rightTurn()
  170.     else
  171.       plant()
  172.       leftTurn()
  173.     end
  174.   else
  175.     plant()
  176.     ending()
  177.   end
  178. end
  179.  
  180. function ending()
  181. updateStatus("Finished")
  182.   if tonumber(currentRow) % 2 == 0 then
  183.     turtle.forward()
  184.     turtle.turnLeft()
  185.     turtle.down()
  186.     turtle.down()
  187.   else
  188.     turtle.turnLeft()
  189.     turtle.turnLeft()
  190.     while tonumber(currentPos) ~= tonumber(startBlock - 1) do
  191.       turtle.forward()
  192.       currentPos = currentPos - 1
  193.     end
  194.     turtle.turnLeft()
  195.     turtle.down()
  196.     turtle.down()
  197.   end
  198.   while tonumber(currentRow) ~= tonumber(startRow) do
  199.     turtle.forward()
  200.     turtle.forward()
  201.     currentRow = currentRow - 1
  202.   end
  203.   dropoff()
  204. end
  205.  
  206. function dropoff()
  207.   s = 1
  208.   total = 0
  209.   while s < 16 do
  210.     items = turtle.getItemCount(s)
  211.     total = items + total
  212.     if items > 0 then
  213.       turtle.select(s)
  214.       turtle.drop()
  215.     end
  216.     s = s + 1
  217.   end
  218.   turtle.turnLeft()
  219.   print("Total Items Deposited:")
  220.   print(total)
  221.   updateStatus("Total Items Deposited  " ..total)
  222.  
  223. end
  224.  
  225. questions()
  226. print("Press Enter to Continue")
  227. io.read()
  228. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement