Advertisement
WhiteFire_Sondergaar

Make XyTank

May 31st, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.88 KB | None | 0 0
  1. -- Tank Builder
  2. -- Fenthis
  3.  
  4. -- Slot 1 = Frame
  5. -- Slot 2 = Sides
  6.  
  7. args = { ... }
  8. forward = tonumber(args[1])
  9. right = tonumber(args[2])
  10. up = tonumber(args[3])
  11.  
  12. if not (forward and right and up) then
  13.     print("Usage: maketank forward right up")
  14.     print(" Slot 1: Base and Frame")
  15.     print(" Slot 2: Sides and Top")
  16.     print(" The space must be clear, plus, one extra level above the tank.")
  17.     error("Invalid usage.")
  18. end
  19.  
  20. if not (forward > 2 and right > 2 and up > 2) then
  21.     error("Minimum dimensions are 3x3x3.")
  22. end
  23.  
  24. if (forward > 12 and right > 12 and up > 12) then
  25.     error("Maximum dimensions are 12x12x12.")
  26. end
  27.  
  28. glass = ((right-2)*(up-2)*2) + ((forward-2)*(up-2)*2) + ((forward-2) * (right-2))
  29. frame = (up * 4) + ((forward-2) * 4) + ((right-2) * 4) + ((forward-2) * (right-2))
  30.  
  31. print("Required blocks:")
  32. print("Base + Frame (slot 1): " .. frame)
  33. print("Sides + Top (slot 2):  " .. glass)
  34. print("Estimated fuel use:    " .. glass + frame + right + 2)
  35.  
  36. print("")
  37. print("Press Q to quit, or any other key to start.")
  38.  
  39. e, c = os.pullEvent("char")
  40. if c == "Q" or c == "q" then
  41.     return
  42. end
  43.  
  44. if not act then
  45.     os.loadAPI("act")
  46.     if not act then
  47.         print("act api required.")
  48.         exit()
  49.     end
  50. end
  51.  
  52. function do_left_or_right(dir)
  53.     if dir then
  54.         turtle.turnLeft()
  55.     else
  56.         turtle.turnRight()
  57.     end
  58. end
  59.  
  60. function is_odd(n)
  61.     return ((n % 2) == 1)
  62. end
  63.  
  64. function try_n(times)
  65.     for i = 1, times do
  66.         act.try()
  67.     end
  68. end
  69.  
  70. function do_to_or_botton(top)
  71.     turtle.up()
  72.     for r = 1,right do
  73.         for x = 1,forward do
  74.             -- Frame or side
  75.             if (not top) or r == 1 or r == right or
  76.                 x == 1 or x == forward then
  77.                 act.select(1)
  78.             else
  79.                 act.select(2)
  80.             end
  81.             act.placeDown()
  82.             if x ~= forward then
  83.                 act.try()
  84.             end
  85.         end
  86.  
  87.         if r ~= right then
  88.             do_left_or_right(not is_odd(r))
  89.             act.try()
  90.             do_left_or_right(not is_odd(r))
  91.         end
  92.     end
  93.  
  94.     -- Movve to opisit of starting corner
  95.     if not is_odd(right) then
  96.         turtle.turnLeft()
  97.         turtle.turnLeft()
  98.         try_n(forward - 1)
  99.     end
  100.  
  101.     -- Turn around
  102.     turtle.turnLeft()
  103.     turtle.turnLeft()
  104. end
  105.  
  106. function do_wall(length)
  107.     for i = 1, length do
  108.         if i == 1 or i == length then
  109.             act.select(1)
  110.         else
  111.             act.select(2)
  112.         end
  113.  
  114.         act.placeDown()
  115.  
  116.         if i ~= length then
  117.             act.try()
  118.         end
  119.     end
  120.  
  121.     turtle.turnRight()
  122. end
  123.  
  124. function do_walls()
  125.     for level = 1, (up - 2) do
  126.         turtle.up()
  127.         do_wall(forward)
  128.         do_wall(right)
  129.         do_wall(forward)
  130.         do_wall(right)
  131.     end
  132. end
  133.  
  134. do_to_or_botton(false)
  135. do_walls()
  136. do_to_or_botton(true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement