Mxx123456

Untitled

Feb 27th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rednet.open("front")
  2. TurtleState = 1
  3. while true do
  4.   Renewnum = 0
  5.   Table = {}
  6.   if fs.exists("disk/state") then
  7.     FState = fs.open("disk/state", "r")
  8.     state = tonumber(FState.readLine())
  9.     FState.close()
  10.     if fs.exists("disk/reactor_data") then
  11.       file = fs.open("disk/reactor_data", "r")
  12.       amount = tonumber(file.readLine())
  13.       table.insert(Table, amount)
  14.       if Table[1] ~=0 then
  15.         for i=1,Table[1] do
  16.           local SubTable = {}
  17.           for j=1,5 do
  18.             temp = tonumber(file.readLine())
  19.             table.insert(SubTable, temp)
  20.           end
  21.           table.insert(Table, SubTable)
  22.         end
  23.       end
  24.       file.close()
  25.       Sides = {"right", "back", "left"}
  26.       if fs.exists("disk/turt_answer") then
  27.         TurtAns = fs.open("disk/turt_answer", "r")
  28.         Reacnum = tonumber(TurtAns.readLine())
  29.         if Reacnum>0 then
  30.           for i=1,Reacnum do
  31.             local temp = tonumber(TurtAns.readLine())+1
  32.             Table[temp][1]=tonumber(TurtAns.readLine())
  33.             print(Table[temp][1])
  34.             Table[temp][5]=tonumber(TurtAns.readLine())
  35.             Table[temp][4]=0
  36.             Table[temp][3]=1
  37.           end
  38.         end
  39.         TurtAns.close()
  40.         if Reacnum>0 then
  41.           TurtAns = fs.open("disk/turt_answer", "w")
  42.           TurtAns.writeLine(0)
  43.           TurtAns.close()
  44.         end
  45.       end
  46.       if state == 1 then
  47.         if Table[1]>3 then
  48.           local temp = math.floor(Table[1]/3)
  49.           for i=1,temp do
  50.             for j=1,3 do
  51.               table.insert(Sides[j])
  52.             end
  53.           end
  54.         end
  55.         time = {}
  56.         for i=1,Table[1] do
  57.           table.insert(time, 0)
  58.           reactor = i+1
  59.           if Table[reactor][1] <= (10000*Table[reactor][5]) then
  60.             if Table[reactor][3] == 1 then
  61.               if i <= 3 then
  62.                 redstone.setOutput(Sides[i], true)
  63.               else
  64.                 rednet.broadcast(i)
  65.                 rednet.broadcast(Sides[i])
  66.                 rednet.broadcast("true")
  67.               end
  68.               Table[reactor][2]=1
  69.               time[i]= os.clock()
  70.             else
  71.               if i <= 3 then
  72.                 redstone.setOutput(Sides[i], false)
  73.               else
  74.                 rednet.broadcast(i)
  75.                 rednet.broadcast(Sides[i])
  76.                 rednet.broadcast("false")
  77.               end
  78.               Table[reactor][2]=0
  79.             end
  80.           else
  81.             if i <= 3 then
  82.               redstone.setOutput(Sides[i], false)
  83.             else
  84.               rednet.broadcast(i)
  85.               rednet.broadcast(Sides[i])
  86.               rednet.broadcast("false")
  87.             end
  88.             Table[reactor][2]=0
  89.             Table[reactor][3]=0
  90.             Table[reactor][4]=1
  91.           end
  92.         end
  93.         sleep(10)
  94.         for i=1,Table[1] do
  95.           reactor = i+1
  96.           if Table[reactor][2] == 1 then
  97.             Table[reactor][1]=math.floor(Table[reactor][1]+os.clock()-time[i] )
  98.           end
  99.         end
  100.         for i=1,Table[1] do
  101.           reactor = i+1
  102.           Renewnum = Renewnum + Table[reactor][4]
  103.         end
  104.         TurtState = fs.open("disk/turt_state", "r")
  105.         TurtleState=tonumber(TurtState.readLine())
  106.         TurtState.close()
  107.         if TurtleState == 0 then
  108.           TurtAsk = fs.open("disk/turt_ask", "w")
  109.           TurtAsk.writeLine(Renewnum)
  110.           if Renewnum>0 then
  111.             for j=1,Table[1] do
  112.               reactor = 1+j
  113.               if Table[reactor][4] == 1 then
  114.                 TurtAsk.writeLine(j)
  115.               end
  116.             end
  117.           end
  118.           TurtAsk.close()
  119.           if Renewnum>0 then
  120.             TurtAsk.close()
  121.             TurtState = fs.open("disk/turt_state", "w")
  122.             TurtState.writeLine(1)
  123.             TurtState.close()
  124.           end
  125.         end
  126.         file = fs.open("disk/reactor_data", "w")
  127.         file.writeLine(Table[1])
  128.         for i=1,Table[1] do
  129.           reactor = i+1
  130.           for j=1,5 do
  131.             file.writeLine(Table[reactor][j])
  132.           end
  133.         end
  134.         file.close()
  135.       else
  136.         for i=1,Table[1] do
  137.           if i <= 3 then
  138.             redstone.setOutput(Sides[i], false)
  139.           else
  140.             rednet.broadcast(i)
  141.             rednet.broadcast(Sides[i])
  142.           end
  143.         end
  144.       end
  145.     else
  146.       print("fill table")
  147.       break
  148.     end
  149.   else
  150.     FState = fs.open("disk/state", "w")
  151.     FState.writeLine(1)
  152.     FState.close()
  153.   end
  154. end
Add Comment
Please, Sign In to add comment