Advertisement
PaymentOption

BuildingRoutine

Sep 26th, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.29 KB | None | 0 0
  1. nRoomWidth = 5
  2. nRoomLength = 5
  3.  
  4. nRoomHeight = 3
  5.  
  6. -- BASIC MOVEMENT METHODS --
  7. function placeThenMoveLeft()
  8.     turtle.placeDown()
  9.     turtle.turnLeft()
  10.     turtle.forward()
  11.     turtle.turnRight()
  12. end
  13.  
  14. function placeThenMoveRight()
  15.     turtle.placeDow()
  16.     turtle.turnRight()
  17.     turtle.forward()
  18.     turtle.turnLeft()
  19. end
  20.  
  21. function turnAround()
  22.     turtle.turnRight()
  23.     turtle.turnRight()
  24. end
  25. ----------------------------
  26.  
  27. function buildRoof(nWidth, nLength)
  28.     turtle.up()
  29.  
  30.     for nLine=1, nLength do
  31.         for nBlock=1, nWidth-1 do
  32.             placeThenMoveLeft()
  33.         end
  34.         turtle.placeDown()
  35.  
  36.         turtle.forward()
  37.         if nLine ~= nLength then
  38.             turtle.placeDown()
  39.         end
  40.         turtle.turnRight()
  41.         for nPositionInLine=nWidth-1, 1, -1 do
  42.             turtle.forward()
  43.         end
  44.         turtle.turnLeft()
  45.     end
  46.  
  47.     -- Return to the starting position.
  48.     turnAround()
  49.     for nPositionInLength=nLength, 1, -1 do
  50.         turtle.forward()
  51.     end
  52.     turnAround()
  53. end
  54.  
  55. function buildLayer(nWidth, nLength)
  56.     turtle.up() -- Get above the space to build.
  57.     -- Build the solid outer line first.
  58.     -- +-----+
  59.     -- |     |
  60.     -- +-----x <-
  61.     for nBlock=1, nWidth-1 do
  62.         placeThenMoveLeft()
  63.     end
  64.     turtle.placeDown()
  65.     ---------------
  66.     -- +-----+
  67.     -- |     |
  68.     -- xXXXXXX
  69.     --
  70.     -- Get the turtle in position to build the inner layers.
  71.     turtle.forward()
  72.  
  73.     -- Build the inner layers of the room.
  74.     for nLine=1, nLength-2 do
  75.         turtle.placeDown()
  76.         turtle.turnRight()
  77.         for nPositionInLine=1, nWidth-1 do
  78.             turtle.forward()
  79.         end
  80.         turtle.turnLeft()
  81.         turtle.placeDown()
  82.  
  83.         turtle.forward()
  84.         turtle.turnLeft()
  85.         for nPositionInLine=nWidth-1, 1, -1 do
  86.             turtle.forward()
  87.         end
  88.         turtle.turnRight()
  89.     end
  90.     -- x-----+
  91.     -- X     X
  92.     -- XXXXXXX
  93.  
  94.     -- Build the final solid outer line.
  95.     turtle.placeDown()
  96.     turtle.turnRight()
  97.     for nPositionInLine=nWidth-1, 1, -1 do
  98.         turtle.forward()
  99.         turtle.placeDown()
  100.     end
  101.     turtle.turnLeft()
  102.     turtle.placeDown()
  103.     -- XXXXXXx
  104.     -- X     X
  105.     -- XXXXXXX
  106.  
  107.     -- Return to the original position of the turtle.
  108.     turnAround()
  109.     for nPositionInLength=nLength-1, 1, -1 do
  110.         turtle.forward()
  111.     end
  112.     turnAround()
  113. end
  114.  
  115. function buildStructure(nWidth, nLength, nHeight)
  116.     for nCurrentHeight=1, nHeight do
  117.         buildLayer(nWidth, nLength)
  118.     end
  119.     buildRoof(nWidth, nLength)
  120. end
  121.  
  122. buildStructure(nRoomWidth, nRoomLength, nRoomHeight)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement