Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("front")
- TurtleState = 1
- while true do
- Renewnum = 0
- Table = {}
- if fs.exists("disk/state") then
- FState = fs.open("disk/state", "r")
- state = tonumber(FState.readLine())
- FState.close()
- if fs.exists("disk/reactor_data") then
- file = fs.open("disk/reactor_data", "r")
- amount = tonumber(file.readLine())
- table.insert(Table, amount)
- if Table[1] ~=0 then
- for i=1,Table[1] do
- local SubTable = {}
- for j=1,5 do
- temp = tonumber(file.readLine())
- table.insert(SubTable, temp)
- end
- table.insert(Table, SubTable)
- end
- end
- file.close()
- Sides = {"right", "back", "left"}
- if fs.exists("disk/turt_answer") then
- TurtAns = fs.open("disk/turt_answer", "r")
- Reacnum = tonumber(TurtAns.readLine())
- if Reacnum>0 then
- for i=1,Reacnum do
- local temp = tonumber(TurtAns.readLine())+1
- Table[temp][1]=tonumber(TurtAns.readLine())
- print(Table[temp][1])
- Table[temp][5]=tonumber(TurtAns.readLine())
- Table[temp][4]=0
- Table[temp][3]=1
- end
- end
- TurtAns.close()
- if Reacnum>0 then
- TurtAns = fs.open("disk/turt_answer", "w")
- TurtAns.writeLine(0)
- TurtAns.close()
- end
- end
- if state == 1 then
- if Table[1]>3 then
- local temp = math.floor(Table[1]/3)
- for i=1,temp do
- for j=1,3 do
- table.insert(Sides[j])
- end
- end
- end
- time = {}
- for i=1,Table[1] do
- table.insert(time, 0)
- reactor = i+1
- if Table[reactor][1] <= (10000*Table[reactor][5]) then
- if Table[reactor][3] == 1 then
- if i <= 3 then
- redstone.setOutput(Sides[i], true)
- else
- rednet.broadcast(i)
- rednet.broadcast(Sides[i])
- rednet.broadcast("true")
- end
- Table[reactor][2]=1
- time[i]= os.clock()
- else
- if i <= 3 then
- redstone.setOutput(Sides[i], false)
- else
- rednet.broadcast(i)
- rednet.broadcast(Sides[i])
- rednet.broadcast("false")
- end
- Table[reactor][2]=0
- end
- else
- if i <= 3 then
- redstone.setOutput(Sides[i], false)
- else
- rednet.broadcast(i)
- rednet.broadcast(Sides[i])
- rednet.broadcast("false")
- end
- Table[reactor][2]=0
- Table[reactor][3]=0
- Table[reactor][4]=1
- end
- end
- sleep(10)
- for i=1,Table[1] do
- reactor = i+1
- if Table[reactor][2] == 1 then
- Table[reactor][1]=math.floor(Table[reactor][1]+os.clock()-time[i] )
- end
- end
- for i=1,Table[1] do
- reactor = i+1
- Renewnum = Renewnum + Table[reactor][4]
- end
- TurtState = fs.open("disk/turt_state", "r")
- TurtleState=tonumber(TurtState.readLine())
- TurtState.close()
- if TurtleState == 0 then
- TurtAsk = fs.open("disk/turt_ask", "w")
- TurtAsk.writeLine(Renewnum)
- if Renewnum>0 then
- for j=1,Table[1] do
- reactor = 1+j
- if Table[reactor][4] == 1 then
- TurtAsk.writeLine(j)
- end
- end
- end
- TurtAsk.close()
- if Renewnum>0 then
- TurtAsk.close()
- TurtState = fs.open("disk/turt_state", "w")
- TurtState.writeLine(1)
- TurtState.close()
- end
- end
- file = fs.open("disk/reactor_data", "w")
- file.writeLine(Table[1])
- for i=1,Table[1] do
- reactor = i+1
- for j=1,5 do
- file.writeLine(Table[reactor][j])
- end
- end
- file.close()
- else
- for i=1,Table[1] do
- if i <= 3 then
- redstone.setOutput(Sides[i], false)
- else
- rednet.broadcast(i)
- rednet.broadcast(Sides[i])
- end
- end
- end
- else
- print("fill table")
- break
- end
- else
- FState = fs.open("disk/state", "w")
- FState.writeLine(1)
- FState.close()
- end
- end
Add Comment
Please, Sign In to add comment