Guest User

(debugging) Branch Mine Program by Trollsama

a guest
Feb 6th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local tunnels = 0               --Number of "Branches" in mine--
  2. local length = 0                --Length of Mineshaft "branches"--
  3. local dropOff = false           --Return to Start Point for Inventory Clearing?--
  4. local placeTorch = false        --Place Torches While Mining?--
  5. local torch = 1                 --Slot Torches are placed in
  6.  
  7. local refuelAt = 5              --default fuel level the turtle will refuel at
  8. local refuelMany = 1            -- how many fuel the turtle will consume while refueling
  9. local emergFuelKeep = 3         -- the number of fuel considered "emergency levels"
  10. local returningToStart = false  --tags the turtle as returning as to bypass checks
  11. local stageCurrent = 0          --current stage of progress
  12. local stage                     -- total stages for mine (1 for the "trunk", and then +1 for every pair of "branches")
  13.  
  14. os.setComputerLabel("ProMine 5000")
  15. --Label change is part of a plan to have the program install into the startup,
  16. --but not bothered to put that in yet due to the size of the program so far,
  17. --and the frustrations I have had while debugging.
  18.  
  19. function header1()      --some simple headers
  20.     term.clear()
  21.     term.setCursorPos(1,1)
  22.     print("Gathering Info 1 - 4")
  23.     term.setCursorPos(25,1)
  24.     print("'Quit' to abort.")
  25. end
  26. function header2()      --some simple headers
  27.     term.clear()
  28.     term.setCursorPos(1,1)
  29.     print("Gathering Info 2 - 4")
  30.     term.setCursorPos(25,1)
  31.     print("'Quit' to abort.")
  32. end
  33. function header3()      --some simple headers
  34.     term.clear()
  35.     term.setCursorPos(1,1)
  36.     print("Gathering Info 3 - 4")
  37.     term.setCursorPos(25,1)
  38.     print("'Quit' to abort.")
  39. end
  40. function header4()      --some simple headers
  41.     term.clear()
  42.     term.setCursorPos(1,1)
  43.     print("Gathering Info 4 - 4")
  44.     term.setCursorPos(25,1)
  45.     print("'Quit' to abort.")
  46. end
  47. function header5()      --some simple headers
  48.     term.clear()
  49.     term.setCursorPos(1,1)
  50.     print("running program")
  51.     term.setCursorPos(25,1)
  52.     print("stage "..stageCurrent.." - "..stage)
  53. end
  54. function quitting()     --the quit program function
  55.         term.setCursorPos(1,5)
  56.         term.clearLine()
  57.         print("Mine Program Aborted... Shutting Down...")
  58.         sleep(2)
  59.         os.shutdown()
  60. end
  61. function openScreen()   --strictly visual, no code relevance.
  62. print("                                       ")
  63. print("  _____           __  __ _             ")
  64. print(" |  __ \\         |  \\/  (_)            ")
  65. print(" | |__) | __ ___ | \\  / |_ _ __   ___  ")
  66. print(" |  ___/ '__/ _ \\| |\\/| | | '_ \\ / _ \\ ")
  67. print(" | |   | | | (_) | |  | | | | | |  __/ ")
  68. print(" |_|   |_|  \\___/|_|  |_|_|_| |_|\\___| ")
  69. print("       _____  ___   ___   ___          ")
  70. print("      | ____|/ _ \\ / _ \\ / _ \\         ")
  71. print("      | |__ | | | | | | | | | |        ")
  72. print("      |___ \\| | | | | | | | | |        ")
  73. print("       ___) | |_| | |_| | |_| |        ")
  74. print("      |____/ \\___/ \\___/ \\___/         ")
  75.  
  76. sleep(2)
  77. for i = 0, 13 do
  78. print("                                       ")
  79. sleep(0.3)
  80. end
  81. end
  82.  
  83.  
  84. local currX = 0     --current X position, in regards to starting point. (forwards/backwards)
  85. local currY = 0     --current Y position, in regards to starting point. (up/down)
  86. local currZ = 0     --current Z position, in regards to starting point. (left/right)
  87. local currO = 0     --current orientation, in regards to starting point. (north-0, east-1, south-2, west-3)
  88.  
  89. --GETTING TUNNEL DISTANCE INFO
  90. --Enters a loop that prevents the stage from
  91. --being skipped without a proper input, then
  92. --stores the data value for later use.
  93.  
  94. openScreen()
  95. repeat          --loop of whole menu section, allows re-entry of data if you are unhappy with the settings
  96. while true do                               --question 1 loop
  97. local num
  98.     header1()
  99.     term.setCursorPos(1,6)
  100.     print("How Long Should I dig The Mineshaft Branches?")
  101.     write("Length: ")
  102.         input = read()                                                                         
  103.         num = tonumber(input)
  104.         if input:lower() == "quit" then     --user quits program
  105.             quitting()
  106.         elseif not num then                 --input was not a number
  107.             term.setCursorPos(1,8)
  108.             term.clearLine()
  109.             print("---------------------------------------")
  110.             print("ERROR: invalid input, not a number.")
  111.             print("---------------------------------------")
  112.             sleep(3)
  113.         elseif num > 200 then               --input was too long
  114.             term.setCursorPos(1,8)
  115.             term.clearLine()
  116.             print("---------------------------------------")
  117.             print("ERROR: too long! Must be 200 or less.")
  118.             print("---------------------------------------")
  119.             sleep(3)
  120.         elseif num < 201 then               --correct input, saves value as "length"
  121.             length = num
  122. break                                       --breaks question 1 loop
  123.         end
  124. end
  125. header1()
  126. term.setCursorPos(1,6)
  127. print("---------------------------------------")
  128. print("Accepted:")
  129. print("tunnels will be "..length.." blocks long.")
  130. print("---------------------------------------")
  131. sleep(2)
  132.  
  133. while true do                               --queestion 2 loop
  134. local num
  135.     header2()
  136.     term.setCursorPos(1,6)
  137.     print("How Many Mineshaft Branches Should I Dig?")
  138.     write("Branches: ")
  139.         input = read()                                                                         
  140.         num = tonumber(input)
  141.         if input:lower() == "quit" then     --user wuits program
  142.             quitting()
  143.         elseif not num then                 --input is not a number
  144.             term.setCursorPos(1,8)
  145.             term.clearLine()
  146.             print("---------------------------------------")
  147.             print("ERROR: invalid input, not a number.")
  148.             print("---------------------------------------")
  149.             sleep(3)
  150.         elseif num <= 20 then               --correct input, value saved as tunnels
  151.             tunnels = num
  152. break
  153.         else                                -- input too long
  154.             term.setCursorPos(1,8)
  155.             term.clearLine()
  156.             print("---------------------------------------")
  157.             print("ERROR: Too Many Tunnels! (20 or less)")
  158.             print("---------------------------------------")
  159.             sleep(2)
  160.         end
  161. end
  162. header2()
  163. term.setCursorPos(1,6)
  164. print("---------------------------------------")
  165. print("Accepted:")
  166. print("I will dig "..tunnels.." mineshafts.")
  167. print("---------------------------------------")
  168. sleep(2)
  169.  
  170. repeat                                      --question 3 loop
  171. loop1 = true
  172.     header3()
  173.     term.setCursorPos(1,6)
  174.         print("Place Torches?")
  175.         write("true/false: ")
  176.         input = read()
  177.                 if input:lower() == "quit" then --user quits program
  178.                 quitting()     
  179.                 elseif input:lower() == "no" or input:lower() == "false" then   --input is false or no, sets placeTorch false and breaks loop
  180.                 placeTorch = false
  181.                 loop1 = false
  182.                 elseif input:lower() == "yes" or input:lower() == "true" then   --input is true or yes, sets placeTorch
  183.                     repeat  --question 3.5 loop
  184.                     local num
  185.                         header3()
  186.                         term.setCursorPos(1,6)
  187.                         print("What slot are the torches in?")
  188.                         write("Slot number: ")
  189.                         input = read()                                                                         
  190.                             num = tonumber(input)
  191.                             if input:lower() == "quit" then     --user quits program
  192.                                 quitting()
  193.                             elseif not num then     --input not number
  194.                                 term.setCursorPos(1,7)
  195.                                 term.clearLine()
  196.                                 print("---------------------------------------")
  197.                                 print("ERROR: Invalid input, not a number!")
  198.                                 print("---------------------------------------")
  199.                                 sleep(3)
  200.                             elseif num >= 1 and num < 16 then   --sets torch slot, torch placement to true and break loop
  201.                                 torch = num
  202.                                 placeTorch = true
  203.                                 loop1 = false
  204.                             elseif num == 16 then   --slot 16 is fuel dedicated, it can not be used
  205.                                 term.setCursorPos(1,7)
  206.                                 term.clearLine()
  207.                                 print("---------------------------------------")
  208.                                 print("ERROR: Slot 16 reserved for fuel!")
  209.                                 print("---------------------------------------")
  210.                                 sleep(3)
  211.                             elseif num > 16 then    --the turtle has no more than 16 slots
  212.                                 term.setCursorPos(1,7)
  213.                                 term.clearLine()
  214.                                 print("---------------------------------------")
  215.                                 print("ERROR: I do not have that many slots!")
  216.                                 print("---------------------------------------")
  217.                                 sleep(3)                               
  218.                             else        --failsafe, don't really need it
  219.                                 term.setCursorPos(1,7)
  220.                                 term.clearLine()
  221.                                 print("---------------------------------------")
  222.                                 print("ERROR: Unknown Input Error!")
  223.                                 print("---------------------------------------")
  224.                                 sleep(3)
  225.                             end
  226.                     until torch < 16 and torch > 0
  227.                 else --input was not valid to the required conditions
  228.                     term.setCursorPos(1,5)
  229.                     term.clearLine()
  230.                     print("---------------------------------------")
  231.                     print("ERROR: Input not recognized... Please enter true, false, yes, no, or quit")
  232.                     print("---------------------------------------")
  233.                     sleep(3)
  234.                 end
  235.  
  236. until loop1 == false
  237. header3()
  238. term.setCursorPos(1,6)
  239. print("---------------------------------------")
  240. print("Accepted:")
  241. print("Lighting mode set to "..tostring(placeTorch))
  242. print("---------------------------------------")
  243. sleep(2)
  244.  
  245. repeat                                      --question loop 4 (does nothing yet)
  246. loop2 = true
  247.     header4()
  248.     term.setCursorPos(1,6)
  249.         print("return Here To Empty My Inventory? (once per branch)")
  250.         write("true/false: ")
  251.             input3 = read()
  252.                 if input3:lower() == "yes" or input3:lower() == "true" then
  253.                     dropOff = true
  254.                     loop2 = false
  255.                 elseif input3:lower() == "false" or input3:lower() == "no" then
  256.                     dropOff = false
  257.                     loop2 = false
  258.                 elseif input3:lower() == "quit" then
  259.                     quitting()
  260.                 else
  261.                     term.setCursorPos(1,5)
  262.                     term.clearLine()
  263.                     print("---------------------------------------")
  264.                     print("ERROR: Input not recognized... Please enter true, false, yes, no or quit")
  265.                     print("---------------------------------------")
  266.                     sleep(3)
  267.                 end
  268. until loop2 == false
  269. header4()
  270. term.setCursorPos(1,6)
  271. print("---------------------------------------")
  272. print("Accepted:")
  273. print("loot drop-off set to "..tostring(dropOff))
  274. print("---------------------------------------")
  275. sleep(2)
  276.  
  277. --[[ once all the information has been gathered, it is listed back to the user
  278. so they can make sure the input was what they wanted. This is the last point
  279. that you are able to quit the program without CTR - T]]
  280.  
  281. term.clear()
  282. term.setCursorPos(1,1)
  283.     print("Confirming Task")
  284.     term.setCursorPos(1,2)
  285.     print("'Quit' to abort.")
  286. term.setCursorPos(1,4)
  287.     print("---------------------------------------")
  288.     print("You would like me to mine:")
  289.     if tunnels == 1 then        --strictly grammar, picks between singular or plural print statements
  290.         print("    "..tunnels.." Branch, that is "..length.." Long")
  291.     else
  292.         print("    "..tunnels.." Branches, each being "..length.." Long")
  293.     end
  294.     print("---------------------------------------")
  295.     print("  Place Torches: "..tostring(placeTorch).."     (slot "..torch..")")
  296.     print("    Return Loot: "..tostring(dropOff))
  297.     print("---------------------------------------")
  298.     print("")
  299.     write("correct?: ")
  300.         input = read()
  301.             if input:lower() == "yes" or input:lower() == "true" then   --starts the program
  302.             term.clear()
  303.             term.setCursorPos(1,10)
  304.                 print("---------------------------------------")
  305.                 print("         Preparing Program...")
  306.                 print("    |                             |")
  307.                 print("---------------------------------------")
  308.                 term.setCursorPos(6,11)
  309.                 for i = 0, 28 do    --strictly visual, loading bar loop.
  310.                     write("#")
  311.                     sleep(.2)
  312.                 end
  313.                 fin = true
  314.                 sleep(1)
  315.             elseif input:lower() == "false" or input:lower() == "no" then   --restarts the questions loop
  316.                 term.setCursorPos(1,10)
  317.                 term.clearLine()
  318.                 print("---------------------------------------")
  319.                 print("           Starting Over...")
  320.                 print("---------------------------------------")
  321.                 sleep(2)
  322.             elseif input:lower() == "quit" then     --user quits the program
  323.                 quitting()
  324.             else        --bad input
  325.                 term.clear()
  326.                 term.setCursorPos(1,1)
  327.                 print("Confirming Task")
  328.                 term.setCursorPos(1,2)
  329.                 print("'Quit' to abort.")
  330.                 term.setCursorPos(1,8)
  331.                 print("---------------------------------------")
  332.                 print("ERROR: Input not recognized... Please enter true, false, yes, no or quit")
  333.                 print("---------------------------------------")
  334.                 sleep(2)
  335.             end
  336. until fin == true
  337.  
  338.  
  339. function ensureSpace()          --checks to make sure there is an empty slot at all times
  340.   if (returningToStart == false) then
  341.         if (turtle.getItemCount(15) > 0) then
  342.           lootRun(true)
  343.         end
  344.   end
  345. end
  346. function ensureFuel()           --checks the fuel levels, and acts accordingly
  347.     local fuelLevel = turtle.getFuelLevel()
  348.     if (fuelLevel ~= "unlimited") then
  349.         if (fuelLevel < refuelAt) then
  350.           turtle.select(16)
  351.             local fuelItems = turtle.getItemCount(16)
  352.             if (fuelItems == 0) then
  353.                 header5()
  354.                 print("Completely out of fuel!")
  355.             elseif (fuelItems == 1) then
  356.                 header5()
  357.                 print("Out of Fuel!")
  358.                
  359.             elseif (fuelItems <= (emergFuelKeep + 1)) then
  360.                 header5()
  361.                 print("Consuming emergency fuel supply. "..(fuelItems - 2).." emergency fuel items remain")
  362.                 turtle.refuel(1)
  363.             else
  364.                 if (fuelItems - (emergFuelKeep + 1) < refuelMany) then
  365.                   turtle.refuel(fuelItems - (emergFuelKeep + 1))
  366.                 else
  367.                   turtle.refuel(refuelMany)
  368.                 end
  369.             end
  370.         end
  371.     end
  372. end  
  373. function emptyInventory()       --invintory emptying script
  374.     local slotLoop = 1
  375.     while (slotLoop < 16) do
  376.         turtle.select(slotLoop)
  377.         if slotLoop == torch then
  378.         sleep(0)
  379.         elseif slotLoop ~= torch then
  380.             turtle.drop()
  381.         end
  382.     slotLoop = slotLoop + 1
  383.     end
  384.   turtle.select(1)
  385. end
  386. function lootRun()              --returning to dump loot, and getting back to position script
  387. returningToStart = true
  388. local savedX = currX
  389. local savedY = currY
  390. local savedZ = currZ
  391. local savedO = currO
  392. while cuurX ~= 0 and currY ~= 0 and currZ ~= 0 do
  393. if currZ ~= 0 then
  394.     faceTrunk()
  395.     repeat
  396.         forward()
  397.     until currZ == 0
  398. end
  399. if currY == 1 then
  400.     down()
  401. elseif currY == 0 then
  402. end
  403. faceHome()
  404. repeat
  405.     forward()
  406. until currX == 0
  407. emptyInventory()
  408. Uturn()
  409. returningToStart = false
  410. repeat
  411.     forward()
  412. until currX == savedX
  413. repeat
  414.     up()
  415. until currY == savedY
  416. repeat
  417.     left()
  418. until  currO == savedO
  419. repeat
  420.     forward()
  421. until currZ == savedZ
  422. end
  423. end
  424.  
  425.  
  426. function left()                 --left turn, with location tracking and wait to move code
  427.     if currO >= 1 and currO < 4 then
  428.         turtle.turnLeft()
  429.         currO = currO - 1
  430.     elseif currO == 0 then
  431.         turtle.turnLeft()
  432.         currO = 3
  433.     else
  434.         navError()
  435.     end
  436. end
  437. function right()                --right turn, with location tracking and wait to move code
  438.     if currO >= 0 and currO < 3 then
  439.         turtle.turnRight()
  440.         currO = currO + 1
  441.     elseif currO == 3 then
  442.         turtle.turnRight()
  443.         currO = 0
  444.     else
  445.         navError()
  446.     end
  447. end
  448. function up()                   --up, with location tracking and wait to move code
  449. while not turtle.up(true) do
  450. sleep(1)
  451. end
  452.     --turtle.up()
  453.     currY = currY + 1
  454.  
  455. end
  456. function down()                 --down, with location tracking and wait to move code
  457. while not turtle.down(true) do
  458. sleep(1)
  459. end
  460.     --turtle.down()
  461.     currY = currY - 1
  462. end
  463. function forward()              --forward, , with location tracking and wait to move code
  464. while not turtle.forward(true) do
  465. sleep(1)
  466. end
  467.     if currO == 0 then
  468.         currX = currX + 1
  469.         --turtle.forward()
  470.     elseif currO == 1 then
  471.         currZ = currZ + 1
  472.         --turtle.forward()
  473.     elseif currO == 2 then
  474.         currX = currX - 1
  475.         --turtle.forward()
  476.     elseif currO == 3 then
  477.         currZ = currZ - 1
  478.         --turtle.forward()
  479.     else
  480.         navError() 
  481.     end
  482. end
  483. function back()                 --back, with location tracking and wait to move code
  484. while not turtle.back(true) do
  485. sleep(1)
  486. end
  487.     if currO == 0 then
  488.         currX = currX - 1
  489.         --turtle.back()
  490.     elseif currO == 1 then
  491.         currZ = currZ - 1
  492.         --turtle.back()
  493.     elseif currO == 2 then
  494.         currX = currX + 1
  495.         --turtle.back()
  496.     elseif currO == 3 then
  497.         currZ = currZ + 1
  498.         --turtle.back()
  499.     else
  500.         navError() 
  501.     end
  502. end
  503. function Uturn()                --turns the turtle to face the oppisite direction
  504. right()
  505. right()
  506. end
  507. function navError()             --error tossed if somthing goes wrong with the navagation scripts
  508.     term.clear()
  509.     term.setCursorPos(1,1)
  510.     print("ERROR: Turtle Locational Awareness System Falure!")
  511.     print(":currO: Exceeded opperational paramiters.")
  512.     print("Expected 0-4, Recieved "..currO)
  513.     print("")
  514.     print("Task Que Cleared,Program Aborted!")
  515.     sleep(10)
  516.     os.pullEvent("terminate")
  517. end
  518. function faceTrunk()            --face the main shaft, regardless of current orentation or location
  519.     if currO == 0 then
  520.         if currZ > 0 then
  521.             right()
  522.         elseif currZ < 0 then
  523.             left()     
  524.         end
  525.     elseif currO == 1 then
  526.         if currZ > 0 then
  527.             Uturn()        
  528.         end
  529.        
  530.     elseif currO == 2 then
  531.         if currZ > 0 then
  532.             left()
  533.         elseif currZ < 0 then
  534.             right()
  535.         end
  536.        
  537.     elseif currO == 3 then
  538.         if currZ < 0 then
  539.             Uturn()
  540.         end
  541.     else
  542.         navError() 
  543.     end
  544. end
  545. function faceHome()             --face the starting point, regardless of current orentation or location
  546.     if currO == 0 then
  547.         Uturn()    
  548.     elseif currO == 1 then
  549.         right()    
  550.     elseif currO == 2 then
  551.            
  552.     elseif currO == 3 then
  553.      left()
  554.     else
  555.         navError() 
  556.     end
  557. end
  558.    
  559. --ACTUAL MINING PROGRAM
  560. --this is what does the tunneling itself.
  561. local waiting = false           --prevents the turtle from being stuck in a loop when moving back to place torches
  562. function mineTrunk()            --the code that calculates and mines the main trunk
  563. trunk = tunnels * 4
  564. header5()
  565. term.setCursorPos(1,3)
  566.     print("Digging Primary Shaft...")
  567. while trunk > 0 do      --loop that keeps the turtle going until the proper length branch has been made.
  568.     ensureFuel()
  569.     turtle.dig()
  570.     sleep(0.5)
  571.     turtle.detect()
  572.     if turtle.detect(true) then     --anti-gravel measures.
  573.         while turtle.detect(true) do
  574.             turtle.dig()
  575.             sleep(0.5)
  576.             turtle.detect()
  577.         end
  578.     end
  579.     ensureSpace()
  580.     forward()
  581.     turtle.digUp()
  582.     sleep(0.5)
  583.     turtle.detectUp()
  584.     if turtle.detectUp(true) then   --anti-gravel measures.
  585.         while turtle.detectUp(true) do
  586.             turtle.digUp()
  587.             sleep(0.5)
  588.             turtle.detectUp()
  589.         end
  590.     end
  591.     ensureSpace()
  592.     left()
  593.     turtle.dig()
  594.     sleep(0.5)
  595.     turtle.detect()
  596.     if turtle.detect(true) then     --anti-gravel measures.
  597.         while turtle.detect(true) do
  598.             turtle.dig()
  599.             sleep(0.5)
  600.             turtle.detect()
  601.         end
  602.     end
  603.     ensureSpace()
  604.     up()
  605.     turtle.dig()
  606.     sleep(0.5)
  607.     turtle.detect()
  608.     if turtle.detect(true) then     --anti-gravel measures.
  609.         while turtle.detect(true) do
  610.             turtle.dig()
  611.             sleep(0.5)
  612.             turtle.detect()
  613.         end
  614.     end
  615.     ensureSpace()
  616.     turtle.digUp()
  617.     sleep(0.5)
  618.     turtle.detectUp()
  619.     if turtle.detectUp(true) then   --anti-gravel measures.
  620.         while turtle.detectUp(true) do
  621.             turtle.digUp()
  622.             sleep(0.5)
  623.             turtle.detectUp()
  624.         end
  625.     end
  626.     ensureSpace()
  627.     waiting = false
  628.     if currX % 6 == 0 and placeTorch and not waiting then --torch placement check and script
  629.         right()
  630.         back()
  631.         turtle.select(torch)
  632.         turtle.placeUp()
  633.         turtle.select(1)
  634.         waiting = true
  635.         forward()
  636.         left()
  637.     end    
  638.     Uturn()
  639.     turtle.dig()
  640.     sleep(0.5)
  641.     turtle.detect()
  642.     if turtle.detect(true) then     --anti-gravel measures.
  643.         while turtle.detect(true) do
  644.             turtle.dig()
  645.             sleep(0.5)
  646.             turtle.detect()
  647.         end
  648.     end
  649.     ensureSpace()
  650.     down()
  651.     turtle.dig()
  652.     sleep(0.5)
  653.     turtle.detect()
  654.     if turtle.detect(true) then --anti-gravel measures. (This should be and will be a function later)
  655.         while turtle.detect(true) do
  656.             turtle.dig()
  657.             sleep(0.5)
  658.             turtle.detect()
  659.         end
  660.     end
  661.     ensureSpace()
  662.     left() 
  663.     trunk = trunk -1
  664. end
  665. end
  666. function mineShaft()            --the code that mines the branches, and relocates for the next pass
  667.     header5()
  668.     term.setCursorPos(1,3)
  669.     print("Digging Mineshaft...")
  670.     repeat                      --the loop that keeps the turtle going until it reaches the appropriate distance
  671.         ensureFuel()
  672.         waiting = false
  673.         turtle.dig()
  674.         sleep(0.5)
  675.         turtle.detect()
  676.         if turtle.detect(true) then     --anti-gravel measures.
  677.             while turtle.detect(true) do
  678.                 turtle.dig()
  679.                 sleep(0.5)
  680.                 turtle.detect()
  681.             end
  682.         end
  683.         ensureSpace()
  684.         forward()
  685.         turtle.digUp()
  686.         ensureSpace()
  687.         if currZ % 8 == 0 and placeTorch and not waiting then   --torch placement test
  688.             back()
  689.             turtle.select(torch)
  690.             turtle.placeUp()
  691.             turtle.select(1)
  692.             waiting = true
  693.             forward()
  694.         end
  695.     until length < currZ or currZ < 0 and length * -1 > currZ
  696. end
  697. tunnels = tunnels + 1           --attempt to fix an issue with the turtles branch counts being short by 1
  698. stageCurrent =  1               --current stage
  699. stage = tunnels + 1             --total stages calculation
  700. mineTrunk()
  701. stageCurrent = stageCurrent + 1
  702. header5()
  703. left()
  704.  
  705. --this is the core loop itself, this is what calls all the functions at the right time to build the mine as a whole
  706. repeat                     
  707. mineShaft()
  708. faceTrunk()
  709.     repeat          --loop to get the turtle back to the "branch"
  710.         forward()
  711.     until currZ == 0   
  712. mineShaft()
  713. faceTrunk()
  714.     stageCurrent = stageCurrent + 1
  715.     header5()
  716.     repeat          --loop to get the turtle back to the "branch"
  717.         forward()
  718.     until currZ == 0   
  719.     left()
  720.     if currX > 3 then   --failsafe to make sure the turtle doesn't backtrack past its starting position.
  721.         for i = 0, 3 do --positioning for the next 2 branches.
  722.             forward()
  723.         end
  724.         right()
  725.     else
  726.     stageCurrent = stage
  727.     end
  728. until stageCurrent == tunnels
  729. faceHome()
  730.     term.clear()
  731.     term.setCursorPos(1,1)
  732.     print("Running program")
  733.     term.setCursorPos(25,1)
  734.     print("Done")
  735. if currX > 0 then       --returning the turtle to the start after a successful run of the program
  736. repeat
  737.     forward()
  738. until currX == 0
  739. end
  740. emptyInventory()
  741. Uturn()
  742. print("")
  743. print("---------------------------------------")
  744. print("          Task Completed")
  745. print("---------------------------------------")
Advertisement
Add Comment
Please, Sign In to add comment