emagiannu

TURTLE BUILDER: CUBE XYLCRAFT TANK

May 25th, 2013
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.33 KB | None | 0 0
  1. -- TURTLE BUILDER: CUBE XYLCRAFT TANK
  2. -- Autore: DjGiannuzz
  3. -- N.B. E' richiesta una Resupply Turtle ed una Resupply Station
  4.  
  5.  
  6. m = peripheral.wrap("right")
  7. local tArgs =  { ... }
  8.  
  9. MAX = tonumber(tArgs[1])
  10.  
  11.  function calcola()
  12.     a=0
  13.     b=0
  14.    
  15.    
  16.     a=((MAX * MAX)*2)+((MAX-2)*4)
  17.     b= (((MAX-2)*(MAX-2))*4)
  18.    
  19.     c= a/64
  20.     d= a%64
  21.    
  22.     e= b/64
  23.     f= b%64
  24.    
  25.     print("Sono richiesti " .. a .. " blocchi di materiale solido e " .. b .. " di vetro.")
  26.     print("Che corrispondono a:")
  27.     print(math.floor(c) .. " stack + " .. d .. " di materiale solido.")
  28.     print(math.floor(e) .. " stack + " .. f .. " di vetro.")
  29.  end
  30.  
  31. function base()
  32.   a= true
  33.         for j=1, MAX do
  34.           for i=1, MAX do
  35.                 turtle.placeDown()
  36.                 if turtle.getItemCount(1) <10 then
  37.                   m.resupply(1)
  38.                 end
  39.                 if i~=MAX then
  40.                   turtle.forward()
  41.                 end
  42.                
  43.           end
  44.           if (a==true) and (j~=MAX)  then
  45.             turtle.turnRight()
  46.                 turtle.forward()
  47.                 turtle.turnRight()
  48.             a=false
  49.           elseif (a==false) and (j~=MAX) then
  50.             turtle.turnLeft()
  51.                 turtle.forward()
  52.                 turtle.turnLeft()
  53.             a=true
  54.          
  55.           end
  56.         end
  57.        
  58. end
  59.  
  60. function MainCol()
  61. turtle.select(1)
  62.   for i=1, MAX-1 do
  63.           turtle.placeDown()
  64.           if turtle.getItemCount(1) <10 then
  65.           m.resupply(1)
  66.           end
  67.           if i~=MAX-1 then
  68.                 turtle.up()
  69.           end
  70.          
  71.   end
  72. end
  73.  
  74. function col()
  75.         turtle.select(1)
  76.         turtle.forward()
  77.         for i=1, MAX-2 do
  78.                 turtle.down()
  79.         end
  80.         turtle.select(2)
  81.         for i=1, MAX-2 do
  82.                 turtle.placeDown()
  83.                 if turtle.getItemCount(2) <10 then
  84.                   m.resupply(2)
  85.                 end            
  86.                 turtle.up()
  87.         end
  88.         turtle.select(1)
  89.         turtle.placeDown()
  90.         if turtle.getItemCount(1) <10 then
  91.                   m.resupply(1)
  92.         end
  93. end
  94.  
  95. function lato()
  96.                
  97.         for i=1, 4 do
  98.                 if (MAX%2)==0 then
  99.                         turtle.turnRight()
  100.                 else
  101.                         turtle.turnLeft()
  102.                 end
  103.                 if i==1 then
  104.                         turtle.up()
  105.                 end
  106.                 MainCol()
  107.                 for i=1, MAX-2 do
  108.                         col()
  109.                 end
  110.                 turtle.select(1)
  111.                 if i~=4 then
  112.                         turtle.forward()
  113.                         for i=1, MAX-2 do
  114.                                 turtle.down()
  115.                         end
  116.                 end
  117.         end
  118. end
  119.  
  120. function tetto()
  121.         if (MAX%2)==0 then
  122.                 turtle.turnRight()
  123.                 a= true
  124.         else
  125.                 turtle.turnLeft()
  126.                 a=false
  127.         end
  128.         turtle.forward()
  129.        
  130.         turtle.select(1)
  131.        
  132.         for j=1, MAX-2 do
  133.           for i=1, MAX-2 do
  134.                 turtle.placeDown()
  135.                 if turtle.getItemCount(1) <10 then
  136.                   m.resupply(1)
  137.                 end
  138.                 if i~=MAX-2 then
  139.                   turtle.forward()
  140.                 end
  141.                
  142.           end
  143.           if (a==true) and (j~=MAX)  then
  144.             turtle.turnRight()
  145.                 turtle.forward()
  146.                 turtle.turnRight()
  147.             a=false
  148.           elseif (a==false) and (j~=MAX) then
  149.             turtle.turnLeft()
  150.                 turtle.forward()
  151.                 turtle.turnLeft()
  152.             a=true
  153.          
  154.           end
  155.         end
  156. end
  157.  
  158.  
  159.  
  160. --MAIN
  161. if (MAX>= 3) and (MAX<=12) then
  162.         while not m.link() do
  163.           sleep(5)
  164.           print(m.getError() .. " riprovo fra 5 secondi")
  165.         end
  166.         shell.run('clear')
  167.         calcola()
  168.         print("Premi X per continuare.")
  169.        
  170.         local event, param1 = os.pullEvent()
  171.         while param1 ~= 45 do
  172.             local event, param1 = os.pullEvent()
  173.         end
  174.        
  175.         m.resupply(1)
  176.         m.resupply(2)
  177.         turtle.up()
  178.         base()
  179.         lato()
  180.         tetto()
  181.        
  182.        
  183. else
  184.         print ("Ampiezza del Tank non valida")
  185.         sleep(5)
  186.         exit()
  187. end
  188. --END MAIN
Advertisement
Add Comment
Please, Sign In to add comment