Advertisement
markman4897

quarry

Apr 19th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1. -- quarry - a simple quarry program
  2. -- Version: 1.0.0
  3. -- by @markman4897
  4.  
  5. -- Requires MPR library.
  6.  
  7. -- TODO:
  8. -- - add more ways to understand arguments in
  9. --   quarry function so it recognises
  10. --    . xzy lengths
  11. --    . 2 xz coords and y length
  12. --    . 2 xzy choords
  13. --
  14. -- - add support for arguments to run this
  15. --   program
  16.  
  17.  
  18. -- =========
  19. -- Variables
  20. -- =========
  21.  
  22. -- Load MPR library
  23.  
  24. os.loadAPI("MPR")
  25.  
  26. -- Overwrite starting coords from MPR
  27.  
  28. MPR.set("x",109)
  29. MPR.set("z",1021)
  30. MPR.set("y",93)
  31.  
  32. MPR.set("dir",1)
  33.  
  34. -- Set quarry size
  35. a = 5
  36. b = 1
  37. c = 2
  38.  
  39.  
  40. -- =========
  41. -- Functions
  42. -- =========
  43.  
  44. -- Quarry function
  45.  
  46. function quarry(a,b,c)
  47.     -- understand data
  48.     line = a
  49.     left = b
  50.     depth = c
  51.  
  52.     -- depth loop
  53.     for i=1,depth,1 do
  54.         -- if first time, dont dig one down
  55.         if i~= 1 then
  56.             MPR.mine("down")
  57.         end
  58.  
  59.         -- remember direction for turning
  60.         d = MPR.get("dir")
  61.  
  62.         -- layer loop
  63.         for ii=1,left,1 do
  64.             MPR.mine("forw",a-1)
  65.             if ii ~= left then
  66.                 if MPR.get("dir") == d then
  67.                     MPR.turn("left")
  68.                     MPR.mine("forw")
  69.                     MPR.turn("left")                   
  70.                 else
  71.                     MPR.turn("right")
  72.                     MPR.mine("forw")
  73.                     MPR.turn("right")
  74.                 end
  75.             end
  76.         end
  77.  
  78.         -- turn so walls are on left and back
  79.         if MPR.get("dir") == d then
  80.             MPR.turn("left",2)
  81.         else
  82.             MPR.turn("left")
  83.         end
  84.     end
  85.  
  86.     return true
  87.  
  88. end
  89.  
  90.  
  91. -- ============
  92. -- Main program
  93. -- ============
  94.  
  95. -- Run the program
  96.  
  97. quarry(a,b,c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement