Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.94 KB | None | 0 0
  1. --[[
  2. Program Name: Comms Quarry(turtle)
  3. Author: Ryder Daniel
  4. Creation Date: 25/12/16
  5. RULES OF THE QUARRY:
  6. 1: The turtle will travel to the location, then always dig west
  7. 2: The turtle always drops the items beneath it, thus prepare a cargo acceptance area accordingly
  8. 3: The cargo dropping area is the home coordinates
  9. ]]--
  10.  
  11. args = {...} --arguments for computer/turtle ID
  12.  
  13. --[[initialising vars for convenience]]--
  14. --[[
  15. Rules:
  16. 1: the initial turtle or the leftmost turtle will be the first one, acting like a clock hand
  17.  
  18. Notes:
  19. I will write the code so it assumes that all the turtles are spaced out evenly according to the spacing
  20. variable and also that they are all facing the same direction by making the defined turtle the leftmost
  21. one. An example of my logic is that if you have a turtle facing south with a spacing of two, the computer
  22. will assume that the next turtle will be two blocks to the east facing the same way. The turtles will
  23. misbehave if you do it any other way because they only know what you let them...
  24. ]]--
  25.  
  26. xCoord =
  27. zCoord =
  28. yCoord =
  29. xTarget = 0
  30. zTarget = 0
  31. yTarget = 0
  32. orientation = 3 --direction facing (1:N 2:E 3:S 4:W)
  33. defaultHomeLook = "south" --default facing direction upon going home
  34. spacing = 2 --spacing of the turtles. the gap in between is equal to the entry - 1
  35. lineLength = 0 --length of the quarry
  36. lines = 0 --width of the quarry
  37. depth = 0 --depth of the quarries
  38.  
  39. --when setting up the turtles, dont forget to set the argument for the first turtle to 0
  40.  
  41. function knowplace()
  42. if orientation == 1 then
  43. xCoord = xCoord + (spacing * tonumber(args[1]))
  44. defaultLook = "east"
  45. elseif orientation == 2 then
  46. zCoord = zCoord + (spacing * tonumber(args[1]))
  47. defaultLook = "south"
  48. elseif orientation == 3 then
  49. xCoord = xCoord - (spacing * tonumber(args[1]))
  50. defaultLook = "west"
  51. elseif orientation == 4 then
  52. zCoord = zCoord - (spacing * tonumber(args[1]))
  53. defaultLook = "north"
  54. end
  55. end
  56.  
  57. --[[vars]]--
  58.  
  59. cruise = 100 -- cruising altitude
  60. xHome, zHome, yHome = 0 -- declaring home coords
  61. xProg, zProg, yProg = 0 -- declaring progress coords
  62. progDir = 0 -- declarinf where the turtle was last looking
  63. progState = "even"
  64. orientations = {"north", "east", "south", "west"}
  65.  
  66.  
  67. --[[quarry vars]]--
  68.  
  69. lineProg, linesDone = 0
  70.  
  71. --[[functions for movement]]--
  72.  
  73. function left()
  74. orientation = orientation - 1
  75. orientation = (orientation - 1) % 4
  76. orientation = orientation + 1
  77. turtle.turnLeft()
  78. end
  79.  
  80. function right()
  81. orientation = orientation - 1
  82. orientation = (orientation + 1) % 4
  83. orientation = orientation + 1
  84. turtle.turnRight()
  85. end
  86.  
  87. function moveUp()
  88. yCoord = yCoord + 1
  89. turtle.up()
  90. end
  91.  
  92. function moveDown()
  93. yCoord = yCoord - 1
  94. turtle.down()
  95. end
  96.  
  97. function forwardX()
  98. xCoord = xCoord + 1
  99. turtle.forward()
  100. end
  101.  
  102. function backX()
  103. xCoord = xCoord - 1
  104. turtle.forward()
  105. end
  106.  
  107. function forwardZ()
  108. zCoord = zCoord + 1
  109. turtle.forward()
  110. end
  111.  
  112. function backZ()
  113. zCoord = zCoord - 1
  114. turtle.forward()
  115. end
  116.  
  117. function look(direction)
  118. while direction ~= orientations[orientation] do
  119. right()
  120. end
  121. end
  122.  
  123. function gotoxzyDir(xTarget, zTarget, yTarget, dir, trav)
  124. if trav == true then
  125. while yCoord < cruise do
  126. moveUp()
  127. end
  128. while yCoord > cruise do
  129. moveDown()
  130. end
  131. end
  132. if xTarget < xCoord then
  133. look("west")
  134. while xTarget < xCoord do
  135. backX()
  136. end
  137. end
  138. if xTarget > xCoord then
  139. look("east")
  140. while xTarget > xCoord do
  141. forwardX()
  142. end
  143. end
  144. if zTarget < zCoord then
  145. look("north")
  146. while zTarget < zCoord do
  147. backZ()
  148. end
  149. end
  150. if zTarget > zCoord then
  151. look("south")
  152. while zTarget > zCoord do
  153. forwardZ()
  154. end
  155. end
  156. while yCoord < yTarget do
  157. moveUp()
  158. end
  159. while yCoord > yTarget do
  160. moveDown()
  161. end
  162. look(dir)
  163. end
  164.  
  165. function gohome()
  166. yProg = yCoord
  167. xProg = xCoord
  168. zProg = zCoord
  169. while yCoord < cruise do
  170. moveUp()
  171. end
  172. while yCoord > cruise do
  173. moveDown()
  174. end
  175. if xHome < xCoord then
  176. look("west")
  177. while xHome < xCoord do
  178. backX()
  179. end
  180. end
  181. if xHome > xCoord then
  182. look("east")
  183. while xHome > xCoord do
  184. forwardX()
  185. end
  186. end
  187. if zHome < zCoord then
  188. look("north")
  189. while zHome < zCoord do
  190. backZ()
  191. end
  192. end
  193. if zHome > zCoord then
  194. look("south")
  195. while zHome > zCoord do
  196. forwardZ()
  197. end
  198. end
  199. while yCoord < yHome do
  200. moveUp()
  201. end
  202. while yCoord > yHome do
  203. moveDown()
  204. end
  205. look(defaultHomeLook)
  206. end
  207.  
  208. --[[functions for the quarry]]--
  209. function updateProg()
  210. xProg = xCoord
  211. zProg = zCoord
  212. yProg = yCoord
  213. progDir = orientation
  214. end
  215.  
  216. function checkInvIsFull()
  217. if turtle.getItemCount(16) == 0 then
  218. return false
  219. end
  220. end
  221.  
  222. function moveForward()
  223. mn = 0
  224. while turtle.detect() do
  225. turtle.dig()
  226. end
  227. moved = false
  228. while not(moved) do
  229. moved = turtle.forward()
  230. mn = mn +1
  231. if mn == 20 and yProg < 7 then
  232. gohome()
  233. getJob()
  234. end
  235. end
  236. if orientation == 1 then
  237. zCoord = zCoord - 1
  238. elseif orientation == 2 then
  239. xCoord = xCoord + 1
  240. elseif orientation == 3 then
  241. zCoord = zCoord + 1
  242. elseif orientation == 4 then
  243. xCoord = xCoord -1
  244. end
  245. updateProg()
  246. if checkInvIsFull() ~= false then
  247. gohome()
  248. emptyItems()
  249. returnAndFinishLayer()
  250. end
  251. end
  252.  
  253. function digLine()
  254. for i =1, lineLength - 1 do
  255. moveForward()
  256. lineProg = lineLength - i
  257. end
  258. end
  259.  
  260. function digLayer(lines)
  261. for i = 1, lines do
  262. digLine()
  263. linesDone = i
  264. if i % 2 == 1 and i < lines then
  265. progState = "even"
  266. left()
  267. moveForward()
  268. left()
  269. elseif i < lines then
  270. progState = "odd"
  271. right()
  272. moveForward()
  273. right()
  274. end
  275.  
  276. end
  277. updateProg()
  278. end
  279.  
  280. function digQuarry()
  281. while yProg > yTarget - depth do
  282. digLayer(lines)
  283. gotoxzyDir(xTarget, zTarget, yCoord, defaultLook, false)
  284. turtle.digDown()
  285. moveDown()
  286. updateProg()
  287. end
  288. gohome()
  289. print("FINISHED Awaiting Job...")
  290. end
  291.  
  292. function returnAndFinishLayer()
  293. gotoxzyDir(xProg, zProg, yProg, progDir, true)
  294. for i=1, lineProg do
  295. moveForward()
  296. end
  297. linesDone = linesDone + 1
  298. if progState == "odd" then
  299. left()
  300. moveForward()
  301. left()
  302. elseif progState == "even" then
  303. right()
  304. moveForward()
  305. right()
  306. end
  307. digLayer(lines - linesDone)
  308. digQuarry()
  309. end
  310.  
  311. function emptyItems()
  312. for i=1,16 do
  313. turtle.select(i)
  314. turtle.dropDown(64)
  315. end
  316. end
  317.  
  318. --[[comms stuff]]--
  319. function main()
  320. term.clear()
  321. center(1,"RYDER'S QUARRY INITIALIZING INTERFACE")
  322. term.setCursorPos(1,3)
  323. print("PLEASE ENTER THE DEPTH OF THE HOLE: ")
  324. depth = read()
  325. print("PLEASE ENTER THE LENGTH: ")
  326. lineLength = read()
  327. print("PLEASE ENTER THE WIDTH: ")
  328. lines = read()
  329. print("PLEASE ENTER THE X COORDINATE FOR THE TOP LEFT OF THE QUARRY: ")
  330. xTarget = read()
  331. print("PLEASE ENTER THE Z COORDINATE FOR THE TOP LEFT OF THE QUARRY: ")
  332. zTarget = read()
  333. print("PLEASE ENTER THE SURFACE LEVEL OF THE QUARRY: ")
  334. yTarget = read()
  335. print("PLEASE ENTER THE DIRECTION OF THE TURTLE:(1:N, 2:E 3:S, 4:W)")
  336. orientation = read()
  337. t = true
  338. while t do
  339. term.clear()
  340. center(1,"RYDER'S QUARRY INITIALIZING INTERFACE", true)
  341. for i = 3, 11 do
  342. term.setCursorPos((w/2 - string.len(arr[i-2]) + 2),i)
  343. print(arr[i-2])
  344. end
  345. term.setCursorPos((w/2)+2,3)
  346. print(diam)
  347. term.setCursorPos((w/2)+2,4)
  348. print(depth)
  349. term.setCursorPos((w/2)+2,5)
  350. print(length)
  351. term.setCursorPos((w/2)+2,6)
  352. print(width)
  353. term.setCursorPos((w/2)+2,7)
  354. print(turts)
  355. term.setCursorPos((w/2)+2,8)
  356. print(xTar)
  357. term.setCursorPos((w/2)+2,9)
  358. print(zTar)
  359. term.setCursorPos((w/2)+2,10)
  360. print(yTar)
  361. term.setCursorPos((w/2)+2,11)
  362. print(dir)
  363. center(13, "IS THIS THE CORRECT INFORMATION? (Y/N)", true)
  364. input = read()
  365. if input == "y" or input == "Y" or input == "YES" or input == "yes" then
  366. t = false
  367. digQuarry()
  368. elseif input == "N" or input == "n" or input == "NO" or input == "no" then
  369. t = false
  370. else
  371. break
  372. end
  373. end
  374. end
  375. end
  376.  
  377. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement