TKArchie

Mining Turtle

Mar 17th, 2013
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.71 KB | None | 0 0
  1. --[[Copyright PrinceTommen - Script developed for CyanideEpic (twitch.tv/cyanideepic)]]--
  2. --[[You are all allowed to use it as long as you don't pretend it's yours]]--
  3. --[[Have fun !]]--
  4.  
  5. --[[ FTB Players: I recommand you to use a "chunk loader mining turtle"]]--
  6. version = 3.4
  7. --[[
  8. Release Note:
  9. 3.4: Added: Favorite configuration system
  10. Ability to choose the direction of the series of parallel tunnels (right or left)
  11. Support of execution without torches or chests (will not try to place them)
  12. Security that stops the turtle when it runs out of chests or torches (suggested by CyanideEpic)
  13. Chests and torches status updated automatically
  14. Security that requires the user to press enter before the turtle starts (suggested by CyanideEpic)
  15. The turtle now returns to its starting position after it finishes
  16. New rotation function as well a a specific torch placing function
  17. Fixed: The turtle will now properly finish the hub after mining an odd number of tunnels
  18. The torch placement has been modified to avoid conflicts with chests
  19. 3.3: Added: Enderchest Support (suggested by Niseg and Daniteh)
  20. Release note
  21. 3.2: Fixed: Very important chest placing issue (only appeared in 3.1)
  22. 3.1: Added: New mining pattern for more efficiency (suggested by Niseg)
  23. Smarter fuel management: Will now consume the "stored" fuel before refueling
  24. Can now consume any type of fuel supported by turtles (check the wiki)
  25. Fuel type can be changed while the turtle is mining
  26. Optimized the mining of 3 blocks high tunnels
  27. Better interface, instructions remain visible and a line is dedicated to the fuel status (updated automatically)
  28. Option to throw cobblestone automatically (suggested by Niseg)
  29. Fixed: Refueling issue in certain circumstances (reported by CyanideEpic)
  30. ]]--
  31.  
  32.  
  33. local function turn(FacingAngle, Bool_rotation, Rotation_integer)
  34. if Bool_rotation then
  35. for u=1, Rotation_integer do
  36. turtle.turnRight()
  37. end
  38. FacingAngle = FacingAngle + Rotation_integer
  39. else
  40. for u=1, Rotation_integer do
  41. turtle.turnLeft()
  42. end
  43. FacingAngle = FacingAngle - Rotation_integer
  44. end
  45. FacingAngle = math.abs((FacingAngle - 1)%4+1)
  46. return FacingAngle
  47. end
  48.  
  49. local function refuel()
  50. turtle.select(2)
  51. boolRefuel = turtle.refuel(1)
  52. if not(boolRefuel) then
  53. term.setCursorPos(1,11)
  54. write("No fuel -")
  55. while not(turtle.refuel(1)) do
  56. FacingAngle = turn(FacingAngle, true, 4)
  57. end
  58. end
  59. refuel_count = 80 - turtle.getFuelLevel()
  60. term.setCursorPos(1,11)
  61. write("Fuel OK -")
  62. return refuel_count
  63. end
  64.  
  65. local function moveForward(FacingAngle, Boolfb, moving_integer, digUpBool, digDownBool, refuel_count)
  66. local moving_count = 1
  67. for moving_count=1,moving_integer do
  68. if (refuel_count == 80) then
  69. refuel_count = refuel()
  70. end
  71. Bool1 = false
  72. while not(Bool1) do
  73. if (Boolfb) then
  74. turtle.dig()
  75. Bool1 = turtle.forward()
  76. if (digUpBool) then
  77. turtle.digUp()
  78. end
  79. if (digDownBool) then
  80. turtle.digDown()
  81. end
  82. else
  83. Bool1 = turtle.back()
  84. if not(Bool1) then
  85. turn(FacingAngle, true, 2)
  86. turtle.dig()
  87. turn(FacingAngle, false, 2)
  88. end
  89. end
  90. end
  91. moving_count = moving_count + 1
  92. refuel_count = refuel_count + 1
  93. end
  94. return refuel_count
  95. end
  96.  
  97. local function moveUp(Boolud, moving_integer, refuel_count, Bool_DigFront)
  98. local moving_count = 1
  99. for moving_count=1, moving_integer do
  100. if (refuel_count == 80) then
  101. refuel_count = refuel()
  102. end
  103. Bool2 = false
  104. if Bool_DigFront then
  105. turtle.dig()
  106. end
  107. while not(Bool2) do
  108. if (Boolud) then
  109. turtle.digUp()
  110. Bool2 = turtle.up()
  111. else
  112. turtle.digDown()
  113. Bool2 = turtle.down()
  114. end
  115. end
  116. moving_count = moving_count + 1
  117. refuel_count = refuel_count + 1
  118. end
  119. return refuel_count
  120. end
  121.  
  122. local function inventoryManagement(saved_slots,refuel_count,Right_or_Left,throw_cobble)
  123. if Chest_approval then
  124. m = saved_slots + 1
  125. thrown_slots = 0
  126. if (throw_cobble) then
  127. m = m+1
  128. end
  129. n = m
  130. if (turtle.getItemCount(16) ~= 0) then
  131. repeat
  132. item_count = turtle.getItemCount(n)
  133. if (item_count ~= 0) then
  134. boolSlotOccupied = true
  135. n = n + 1
  136. else
  137. boolSlotOccupied = false
  138. end
  139. until (boolSlotOccupied == false) or (n == 17)
  140. if n==17 then
  141. if (throw_cobble) then
  142. for j=1, 12 do
  143. turtle.select(4)
  144. Bool_match_cobble = turtle.compareTo(j+4)
  145. if Bool_match_cobble then
  146. thrown_slots = thrown_slots + 1
  147. turtle.select(j+4)
  148. turtle.drop()
  149. end
  150. end
  151. turtle.select(4)
  152. turtle.drop(turtle.getItemCount(4)-1)
  153. end
  154. if (thrown_slots <= 2) then
  155. if Chest_shortage then
  156. turtle.select(3)
  157. turtle.drop()
  158. term.setCursorPos(24,11)
  159. write("No chests")
  160. repeat
  161. turn(FacingAngle, true, 4)
  162. until (turtle.getItemCount(3) ~= 0)
  163. term.setCursorPos(24,11)
  164. write("Chests OK")
  165. Chest_shortage = false
  166. end
  167. if (Right_or_Left == "left") then
  168. FacingAngle = turn(FacingAngle, true, 1)
  169. else
  170. FacingAngle = turn(FacingAngle, false, 1)
  171. end
  172. refuel_count = moveForward(FacingAngle, true, 1, false, true, refuel_count)
  173. turtle.select(3)
  174. turtle.digDown()
  175. turtle.placeDown()
  176. for u=m,16 do
  177. turtle.select(u)
  178. turtle.dropDown()
  179. end
  180. if enderchest then
  181. turtle.select(3)
  182. turtle.drop()
  183. turtle.digDown()
  184. end
  185. if (turtle.getItemCount(3) == 0) then
  186. Chest_shortage = true
  187. end
  188. refuel_count = moveForward(FacingAngle, false, 1, false, false, refuel_count)
  189. if (Right_or_Left == "left") then
  190. FacingAngle = turn(FacingAngle, false, 1)
  191. else
  192. FacingAngle = turn(FacingAngle, true, 1)
  193. end
  194. end
  195. end
  196. end
  197. end
  198. return refuel_count
  199. end
  200.  
  201.  
  202. local function placeTorch(Position)
  203. if Torch_approval then
  204. if Torch_shortage then
  205. turtle.select(1)
  206. turtle.drop()
  207. term.setCursorPos(11,11)
  208. write("No Torches -")
  209. repeat
  210. turn(FacingAngle, true, 4)
  211. until (turtle.getItemCount(1) ~= 0)
  212. term.setCursorPos(11,11)
  213. write("Torches OK -")
  214. Torch_shortage = false
  215. end
  216. turtle.select(1)
  217. if Position == "front" then
  218. turtle.dig()
  219. turtle.place()
  220. elseif Position == "below" then
  221. turtle.digDown()
  222. turtle.placeDown()
  223. elseif Position == "up" then
  224. turtle.digUp()
  225. turtle.placeUp()
  226. end
  227. if (turtle.getItemCount(1) == 0) then
  228. Torch_shortage = true
  229. end
  230. end
  231. end
  232.  
  233.  
  234. local function digVerticalLayer(refuel_count, FacingAngle, Width, Height, Height_Position, Bool_Torches, Right_or_Left)
  235. if Right_or_Left then
  236. Right_or_Left = "left"
  237. else
  238. Right_or_Left = "right"
  239. end
  240. done_columns = 0
  241. if (Height_Position == "up") then
  242. for columns=1, math.floor(Width/4) do
  243. turtle.digUp()
  244. if (Height > 3) then
  245. refuel_count = moveUp(true, 1, refuel_count, false)
  246. turtle.dig()
  247. refuel_count = moveUp(false, (Height-2), refuel_count, true)
  248. turtle.digDown()
  249. end
  250. refuel_count = moveForward(FacingAngle, true, 2, true, true, refuel_count)
  251. refuel_count = inventoryManagement(3, refuel_count, Right_or_Left, throw_cobble)
  252. if (Height > 3) then
  253. refuel_count = moveUp(false, 1, refuel_count, false)
  254. turtle.dig()
  255. refuel_count = moveUp(true, (Height-2), refuel_count, true)
  256. turtle.digUp()
  257. end
  258. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  259. done_columns = done_columns + 1
  260. if (Width - 4*done_columns ~= 0) then
  261. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  262. end
  263. end
  264. if ((Width - 4*math.floor(Width/4)) == 0) then
  265. Height_Position = "up"
  266. elseif ((Width - 4*math.floor(Width/4)) == 1) then
  267. turtle.digUp()
  268. refuel_count = moveUp(false, (Height-3), refuel_count, false)
  269. turtle.digDown()
  270. refuel_count = inventoryManagement(3, refuel_count, Right_or_Left, throw_cobble)
  271. Height_Position = "down"
  272. elseif ((Width - 4*math.floor(Width/4)) >= 2) then
  273. if (Height > 3) then
  274. refuel_count = moveUp(true, 1, refuel_count, false)
  275. turtle.dig()
  276. refuel_count = moveUp(false, (Height-2), refuel_count, true)
  277. turtle.digDown()
  278. end
  279. turtle.digUp()
  280. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  281. refuel_count = inventoryManagement(3, refuel_count, Right_or_Left, throw_cobble)
  282. Height_Position = "down"
  283. if ((Width - 4*math.floor(Width/4)) == 3) then
  284. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  285. refuel_count = moveUp(true, (Height - 3), refuel_count, false)
  286. turtle.digUp()
  287. Height_Position = "up"
  288. end
  289. end
  290. elseif (Height_Position == "down") then
  291. for columns=1, math.floor(Width/4) do
  292. turtle.digDown()
  293. if (Height > 3) then
  294. refuel_count = moveUp(false, 1, refuel_count, false)
  295. turtle.dig()
  296. refuel_count = moveUp(true, (Height - 2), refuel_count, true)
  297. turtle.digUp()
  298. end
  299. refuel_count = moveForward(FacingAngle, true, 2, true, true, refuel_count)
  300. if (Height > 3) then
  301. refuel_count = moveUp(true, 1, refuel_count, false)
  302. turtle.dig()
  303. refuel_count = moveUp(false, (Height - 2), refuel_count, true)
  304. turtle.digDown()
  305. end
  306. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  307. done_columns = done_columns + 1
  308. if (Width - 4*done_columns ~= 0) then
  309. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  310. end
  311. refuel_count = inventoryManagement(3, refuel_count, Right_or_Left, throw_cobble)
  312. if (done_columns%2 == 0) and Bool_Torches then
  313. FacingAngle = turn(FacingAngle,true , 1)
  314. placeTorch("front")
  315. FacingAngle = turn(FacingAngle, false, 1)
  316. end
  317. end
  318. if ((Width - 4*math.floor(Width/4)) == 0) then
  319. Height_Position = "down"
  320. elseif ((Width - 4*math.floor(Width/4)) == 1) then
  321. turtle.digDown()
  322. refuel_count = moveUp(true, (Height - 3), refuel_count, false)
  323. turtle.digUp()
  324. Height_Position = "up"
  325. elseif ((Width - 4*math.floor(Width/4)) >= 2) then
  326. if (Height > 3) then
  327. refuel_count = moveUp(false, 1, refuel_count, false)
  328. turtle.dig()
  329. refuel_count = moveUp(true, (Height - 2), refuel_count, true)
  330. turtle.digUp()
  331. end
  332. turtle.digDown()
  333. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  334. Height_Position = "up"
  335. if ((Width - 4*math.floor(Width/4)) == 3) then
  336. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  337. refuel_count = moveUp(false, (Height - 3), refuel_count, false)
  338. turtle.digDown()
  339. refuel_count = inventoryManagement(3, refuel_count, Right_or_Left, throw_cobble)
  340. Height_Position = "down"
  341. end
  342. end
  343. end
  344. return refuel_count, Height_Position
  345. end
  346.  
  347. local function resetScreen()
  348. term.clear()
  349. term.setCursorPos(14,1)
  350. write("Mining Turtle")
  351. term.setCursorPos(5,2)
  352. write("For CyanideEpic and his friends")
  353. term.setCursorPos(1,13)
  354. write("By PrinceTommen, version "..version)
  355. end
  356.  
  357. resetScreen()
  358. if (io.open("favorite", "r") ~= nil) then
  359. term.setCursorPos(1,4)
  360. repeat
  361. write("Do you wish to use your favorite configuration ? (Yes/No)")
  362. term.setCursorPos(1,6)
  363. Favorite_approval = read()
  364. until (Favorite_approval == "Yes") or (Favorite_approval == "No")
  365. if (Favorite_approval == "Yes") then
  366. handle = fs.open("favorite", "r")
  367. input = handle.readAll()
  368. handle.close()
  369. favorite = textutils.unserialize(input)
  370. tunnels_integer = favorite.tunnels_integer
  371. Width = favorite.Width
  372. Height = favorite.Height
  373. Length = favorite.Length
  374. tunnels_separation = favorite.tunnels_separation
  375. if favorite.throw_cobble == 1 then
  376. throw_cobble = true
  377. else
  378. throw_cobble = false
  379. end
  380. if favorite.enderchest == 1 then
  381. enderchest = true
  382. else
  383. enderchest = false
  384. end
  385. end
  386. end
  387. if (io.open("favorite", "r") == nil) or ((io.open("favorite", "r") ~= nil) and (Favorite_approval == "No")) then
  388. resetScreen()
  389. term.setCursorPos(1,4)
  390. print("Number of parallel tunnels ? ")
  391. term.setCursorPos(37,4)
  392. tunnels_integer = tonumber(read())
  393. term.setCursorPos(1,5)
  394. print("Width of the tunnels ? ")
  395. term.setCursorPos(37,5)
  396. Width = tonumber(read())
  397. term.setCursorPos(1,6)
  398. print("Height of the tunnels ? ")
  399. term.setCursorPos(37,6)
  400. Height = tonumber(read())
  401. if (Height < 3) then
  402. Height = 3
  403. end
  404. term.setCursorPos(1,7)
  405. print("Length of the tunnels ? ")
  406. term.setCursorPos(37,7)
  407. Length = tonumber(read())
  408. if (tunnels_integer > 1) then
  409. term.setCursorPos(1,8)
  410. print("Separating blocks between tunnels ? ")
  411. term.setCursorPos(37,8)
  412. tunnels_separation = tonumber(read())
  413. end
  414. repeat
  415. resetScreen()
  416. term.setCursorPos(1,4)
  417. print("Are you willing to throw cobblestone away ? (Yes/No)")
  418. term.setCursorPos(1,6)
  419. throw_cobble = read()
  420. until (throw_cobble == "Yes") or (throw_cobble == "No")
  421. repeat
  422. resetScreen()
  423. term.setCursorPos(1,4)
  424. print("Are you willing to use an enderchest ? (Yes/No)")
  425. term.setCursorPos(1,6)
  426. enderchest = read()
  427. until (enderchest == "Yes") or (enderchest == "No")
  428.  
  429. resetScreen()
  430. term.setCursorPos(1,4)
  431. write("Do you want to save this configuration as your favorite ? (Yes/No)")
  432. repeat
  433. term.setCursorPos(1,6)
  434. New_favorite = read()
  435. until (New_favorite == "Yes") or (New_favorite == "No")
  436. if (New_favorite == "Yes") then
  437. favorite = {}
  438. favorite.tunnels_integer = tunnels_integer
  439. favorite.Width = Width
  440. favorite.Height = Height
  441. favorite.Length = Length
  442. favorite.tunnels_separation = tunnels_separation
  443. output = textutils.serialize(favorite)
  444. handle = fs.open("favorite", "w")
  445. handle.write(output)
  446. handle.close()
  447. end
  448. end
  449. if (tunnels_integer > 1) then
  450. repeat
  451. resetScreen()
  452. term.setCursorPos(1,4)
  453. print("The first tunnel will be in front of the turtle. Do you want the tunnels to be dug on the right or on the left of the first tunnel (They will be parallel to the first one) ? (Right/Left)")
  454. term.setCursorPos(1,9)
  455. Bool_direction = read()
  456. until (Bool_direction == "Right") or (Bool_direction == "Left")
  457. end
  458. if (tunnels_integer == 1) and (Width > 1) then
  459. repeat
  460. resetScreen()
  461. term.setCursorPos(1,4)
  462. print("Do you want the current position of the turtle to be the right or the left of the tunnel ? (Right/Left)")
  463. term.setCursorPos(1,9)
  464. Bool_direction = read()
  465. until (Bool_direction == "Right") or (Bool_direction == "Left")
  466. end
  467.  
  468. resetScreen()
  469. term.setCursorPos(1,4)
  470. if (enderchest == "Yes") then
  471. enderchest = true
  472. write("Torches in the first (upper-left) slot. Coal (or anything that can power a turtle) in the second one, one enderchest (only one) in the third one.")
  473. else
  474. enderchest = false
  475. write("Torches in the first (upper-left) slot. Coal (or anything that that can power a turtle) in the second one, chests in the third one.")
  476. end
  477. if (throw_cobble == "Yes") then
  478. throw_cobble = true
  479. term.setCursorPos(1,8)
  480. write("Please make sure there is cobble in the fourth slot.")
  481. else
  482. throw_cobble = false
  483. end
  484. if (Bool_direction == "Right") then
  485. Bool_direction = true
  486. else
  487. Bool_direction = false
  488. end
  489. term.setCursorPos(1,11)
  490. write("Pres enter to start")
  491. while true do
  492. press, key = os.pullEvent()
  493. if press == "key" and key == 28 then
  494. break
  495. end
  496. end
  497. term.setCursorPos(1,11)
  498. write(" ")
  499. if (turtle.getItemCount(1) == 0) then
  500. repeat
  501. resetScreen()
  502. term.setCursorPos(1,4)
  503. print("The torches slot is empty. Are you sure you do not want to use torches ? (Yes/No)")
  504. term.setCursorPos(1,7)
  505. Torch_approval = read()
  506. until (Torch_approval == "Yes") or (Torch_approval == "No")
  507. else
  508. Torch_approval = "No"
  509. end
  510. if (Torch_approval == "Yes") then
  511. Torch_approval = false
  512. elseif (Torch_approval == "No") then
  513. Torch_approval = true
  514. end
  515. if (turtle.getItemCount(3) == 0) then
  516. repeat
  517. resetScreen()
  518. term.setCursorPos(1,4)
  519. print("The chests slot is empty. Are you sure you do not want to use chests ? (Yes/No)")
  520. term.setCursorPos(1,7)
  521. Chest_approval = read()
  522. until (Chest_approval == "Yes") or (Chest_approval == "No")
  523. else
  524. Chest_approval = "No"
  525. end
  526. if (Chest_approval == "Yes") then
  527. Chest_approval = false
  528. elseif (Chest_approval == "No") then
  529. Chest_approval = true
  530. end
  531. if Torch_approval and (turtle.getItemCount(1) == 0) then
  532. Torch_shortage = true
  533. term.setCursorPos(11,11)
  534. write("No Torches -")
  535. elseif Torch_approval and (turtle.getItemCount(1) ~= 0) then
  536. Torch_shortage = false
  537. term.setCursorPos(11,11)
  538. write("Torches OK -")
  539. end
  540. if Chest_approval and (turtle.getItemCount(3) == 0) then
  541. Chest_shortage = true
  542. term.setCursorPos(24,11)
  543. write("No Chests")
  544. elseif Chest_approval and (turtle.getItemCount(3) ~= 0) then
  545. Chest_shotage = false
  546. term.setCursorPos(24,11)
  547. write("Chests OK")
  548. end
  549.  
  550. term.setCursorPos(1,11)
  551. write("Fuel OK -")
  552. refuel_count = 80 - turtle.getFuelLevel()
  553. FacingAngle = 0
  554. tunnel_forth = true
  555.  
  556.  
  557. refuel_count = moveUp(true, 1, refuel_count, false)
  558. if (Width == 1) then
  559. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  560. end
  561. for done_tunnels=1, tunnels_integer do
  562. if (Width >= 2) then
  563. for done_layers=1, math.ceil(Length/2) do
  564. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  565. FacingAngle = turn(FacingAngle, Bool_direction, 1)
  566. refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, Width, Height, "down", false, Bool_direction)
  567. FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  568. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  569. FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  570. refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, Width, Height, Height_Position, false, not(Bool_direction))
  571. FacingAngle = turn(FacingAngle, Bool_direction, 1)
  572. if (done_layers%4 == 0) then
  573. refuel_count = moveUp(false, 1, refuel_count, false)
  574. FacingAngle = turn(FacingAngle, Bool_direction, 1)
  575. placeTorch("front")
  576. FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  577. refuel_count = moveUp(true, 1, refuel_count, false)
  578. end
  579. end
  580. elseif (Width == 1) then
  581. refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, 2*math.ceil(Length/2), Height, "down", true, Bool_direction)
  582. end
  583. if (Height_Position == "up") then
  584. refuel_count = moveUp(false, (Height - 3), refuel_count, false)
  585. Height_Position = "down"
  586. end
  587. if tunnel_forth and (tunnels_integer - done_tunnels >= 1) then
  588. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  589. FacingAngle = turn(FacingAngle, Bool_direction, 1)
  590. refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, ((2*Width)+tunnels_separation), Height, "down", false, not(Bool_direction))
  591. if (Height_Position == "up") then
  592. refuel_count = moveUp(false, (Height - 3), refuel_count, false)
  593. Height_Position = "down"
  594. end
  595. FacingAngle = turn(FacingAngle, Bool_direction, 1)
  596. placeTorch("below")
  597. elseif not(tunnel_forth) then
  598. refuel_count = moveForward(FacingAngle, true, 1, true, false, refuel_count)
  599. FacingAngle = turn(FacingAngle, Bool_direction, 1)
  600. refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, ((2*Width)-1+tunnels_separation), Height, "down", false, Bool_direction)
  601. FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  602. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  603. FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  604. refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, ((2*Width)-1+tunnels_separation), Height, Height_Position, false, not(Bool_direction))
  605. if (Height_Position == "up") then
  606. refuel_count = moveUp(false, (Height - 3), refuel_count, false)
  607. Height_Position = "down"
  608. end
  609. FacingAngle = turn(FacingAngle, Bool_direction, 2)
  610. refuel_count = moveForward(FacingAngle, true, (Width-2), true, true, refuel_count)
  611. placeTorch("front")
  612. FacingAngle = turn(FacingAngle, not(Bool_direction), 2)
  613. refuel_count = moveForward(FacingAngle, true, (Width-2), true, true, refuel_count)
  614. if (tunnels_integer - done_tunnels ~= 0) then
  615. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  616. refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (tunnels_separation+1), Height, Height_Position, false, Bool_direction)
  617. FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  618. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  619. FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  620. refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (tunnels_separation+1), Height, Height_Position, false, not(Bool_direction))
  621. refuel_count = moveForward(FacingAngle, false, tunnels_separation, true, true, refuel_count)
  622. FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  623. placeTorch("front")
  624. FacingAngle = turn(FacingAngle, not(Bool_direction), 2)
  625. end
  626. end
  627. if tunnel_forth and (tunnels_integer - done_tunnels == 0) and (Width > 1) then
  628. refuel_count = moveForward(FacingAngle, false, 2*math.ceil(Length/2), false, false, refuel_count)
  629. FacingAngle = turn(FacingAngle, Bool_direction, 1)
  630. refuel_count = moveForward(FacingAngle, true, 1, false, false, refuel_count)
  631. refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (Width - 1), Height, Height_Position, false, Bool_direction)
  632. FacingAngle = turn(FacingAngle, Bool_direction, 1)
  633. refuel_count = moveForward(FacingAngle, true, 1, false, false, refuel_count)
  634. FacingAngle = turn(FacingAngle, Bool_direction, 1)
  635. refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (Width - 1), Height, Height_Position, false, not(Bool_direction))
  636. if (Height_Position == "up") then
  637. refuel_count = moveUp(false, (Height - 3), refuel_count, false)
  638. Height_Position = "down"
  639. end
  640. refuel_count = moveForward(FacingAngle, false, (Width - 2), false, false, refuel_count)
  641. FacingAngle = turn(FacingAngle, Bool_direction, 2)
  642. end
  643. tunnel_forth = not(tunnel_forth)
  644. if (Width == 1) and (tunnels_integer - done_tunnels ~= 0) then
  645. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  646. elseif (Width == 1) and (tunnels_integer - done_tunnels == 0) then
  647. refuel_count = moveForward(FacingAngle, false, (2*math.ceil(Length/2)), false, false, refuel_count)
  648. end
  649. end
  650. refuel_count = moveUp(false, 1, refuel_count, false)
  651. if (Width == 1) then
  652. refuel_count = moveForward(FacingAngle, false, 1, false, false, refuel_count)
  653. FacingAngle = turn(FacingAngle, Bool_direction, 1)
  654. end
  655. refuel_count = moveForward(FacingAngle, false, ((tunnels_integer*Width) - 1 + (tunnels_separation*(tunnels_integer - 1))), false, false, refuel_count)
  656. FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
Advertisement
Add Comment
Please, Sign In to add comment