Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local computer = require('computer')
- local term = require('term')
- local fs = require('filesystem')
- local component = require('component')
- local rs = component.redstone
- local modem = component.modem
- local event = require('event')
- local serialize = require("serialization").serialize
- local floor = math.floor
- local transposer
- term.clear()
- RCL = {} -- reactor sheme list
- RCL[1] = "lol"-- path to reactor kit
- local RodList = {}
- RodList['IC2:reactorUraniumSimple'] = 1
- RodList['IC2:reactorUraniumDual'] = 3
- RodList['IC2:reactorUraniumQuad'] = 5
- RodList['IC2:reactorMOXSimple'] = 2
- RodList['IC2:reactorMOXDual'] = 4
- RodList['IC2:reactorMOXQuad'] = 6
- local RodList1 = {}
- RodList1[1] = 'IC2:reactorUraniumSimple'
- RodList1[3] = 'IC2:reactorUraniumDual'
- RodList1[5] = 'IC2:reactorUraniumQuad'
- RodList1[2] = 'IC2:reactorMOXSimple'
- RodList1[4] = 'IC2:reactorMOXDual'
- RodList1[6] = 'IC2:reactorMOXQuad'
- local function copy(tbl)
- local result = {}
- for k, v in pairs(tbl) do
- result[k] = v
- end
- return result
- end
- local function sort(tbl)
- for i = 1, #tbl do
- for j = i + 1, #tbl do
- if floor(tbl[i] / 10) > floor(tbl[j]) then
- tbl[i], tbl[j] = tbl[j], tbl[i]
- end
- end
- end
- end
- ---[[
- modem.open(8)
- local friend
- local fs = io.open("friendAdres", "r")
- if not fs then
- local SECRET_KEY_OUTPUT= "lkwejbhvlkwejbkjwerbfjwhvbjkehfvbejbwejb"
- print("нажмите enter, когда включите робота")
- io.read()
- modem.broadcast(8, SECRET_KEY_OUTPUT)
- local SECRET_KEY_INPUT = "wqerfwevwegwergverbertgbvertesger"
- while true do
- local _, _, sender, _, _, message = event.pull("modem_message")
- if message == SECRET_KEY_INPUT then
- friend = sender
- break
- end
- end
- fs = io.open("friendAdres", "w")
- fs:write(friend)
- fs:close()
- else
- friend = fs:read()
- fs:close()
- term.clear()
- end
- --]]
- print("какую компоновку вы хотите запустить")
- for i = 1, #RCL do
- print(i, ": ", RCL[i])
- end
- local nameKit = io.read() + 0
- term.clear()
- local reactorKit
- local fs = io.open(RCL[nameKit], "r")
- if fs then
- reactorKit = require("serialization").unserialize(fs:read())
- fs:close()
- else
- reactorKit = {
- x = {},
- z = {},
- y = {},
- b = {},
- numR = {},
- numChest = {},
- sideChest = {},
- sideT = {},
- sideR = {},
- adrT = {}, -- adres of transposer
- adrR = {},
- reactor = {},
- perepheryLoc = {x, z, y, b, y1},
- sbor = {x, z, y}
- }
- term.clear()
- adresRed = {}
- --scaning
- print("координаты переферии (x, z, y, b, y1)")
- io.write("x = "); reactorKit.perepheryLoc.x = io.read() + 0
- io.write("z = "); reactorKit.perepheryLoc.z = io.read() + 0
- io.write("y = "); reactorKit.perepheryLoc.y = io.read() + 0
- io.write("b = "); reactorKit.perepheryLoc.b = io.read() + 0
- io.write("y1 = "); reactorKit.perepheryLoc.y1 = io.read() + 0 -- z1 высота, на которой нет помех для передвижения робота
- term.clear()
- print("координаты места сбора (x, z, y)")
- io.write("x = "); reactorKit.sbor.x = io.read() + 0
- io.write("z = "); reactorKit.sbor.z = io.read() + 0
- io.write("y = "); reactorKit.sbor.y = io.read() + 0
- term.clear()
- io.write("Количество сундуков: ") local chestNumber = io.read() + 0
- term.clear()
- for i = 1, chestNumber do
- print("координаты точки примыкания к сундуку ", i)
- io.write("x = "); reactorKit.x[i] = io.read() + 0
- io.write("z = "); reactorKit.z[i] = io.read() + 0
- io.write("y = "); reactorKit.y[i] = io.read() + 0
- io.write("b = "); reactorKit.b[i] = io.read() + 0
- term.clear()
- end
- local i, iR, i1 , a
- local react
- for adres, name in component.list() do
- if (name == "transposer") then
- --reactorKit.nT = reactorKit.nT + 1
- print(adres)
- i = io.read() + 0
- reactorKit.adrT[i] = adres
- io.write("сторона к сундуку у транспозера: ") local n = io.read() + 0
- reactorKit.sideChest[i] = n
- io.write("номер сундука к транспозеру ", i, ": ")
- reactorKit.numChest[i] = io.read() + 0
- io.write("число реакторов у транспозера: ") n = io.read() + 0
- i1 = i * 10
- for j = 1, n do
- --react = reactorKit.reactor[i1 + j]
- io.write("(транспозер)сторона к реактору ", j, ": "); local p = io.read() + 0
- reactorKit.sideT[i1 + j] = p
- io.write("номер редстоун блока: ")
- reactorKit.numR[i1 + j] = io.read() + 0
- io.write("(редстоун)сторона к реактору (или к проводу) ", j, ": ")
- reactorKit.sideR[i1 + j] = io.read() + 0
- react = {}
- local name
- for k = 1, component.invoke(reactorKit.adrT[i], "getInventorySize", p) do
- a = component.invoke(reactorKit.adrT[i], "getStackInSlot", p, k)
- if a and RodList[a.name] then
- if (react[RodList[a.name]] == nil) then
- react[RodList[a.name]] = {}
- end
- react[RodList[a.name]].name = RodList[a.name]
- react[RodList[a.name]][#react[RodList[a.name]] + 1] = k
- end
- end
- --уплотнение
- for k = 1, #RodList1 do
- if (react[k]) then
- if (#react + 1 ~= k) then
- react[#react + 1] = react[k]
- react[k] = nil
- end
- end
- end
- -- запись в основную талицу
- for k = 1, #react do
- reactorKit.reactor[(i1 + j) * 10 + k] = react[k]
- end
- react = nil
- end
- elseif (name == "redstone") then
- --
- adresRed[#adresRed + 1] = adres
- end
- term.clear()
- end
- for j = 1, #adresRed do
- print("укажите номер этого редстоун блока:")
- print(adresRed[j])
- i = io.read() + 0
- reactorKit.adrR[i] = adresRed[j]
- end
- -- сохранение в файл
- fs = io.open(RCL[nameKit], "w")
- fs:write(serialize(reactorKit))
- fs:close()
- end
- react = nil
- fs = io.open("robot", "r")
- if not fs then
- local rob = {
- x = reactorKit.x,
- z = reactorKit.z,
- y = reactorKit.y,
- b = reactorKit.b,
- numChest = reactorKit.numChest,
- fuelRodName = {},
- fuelRodNum = {},
- perephery = reactorKit.perepheryLoc,
- sbor = reactorKit.sbor
- }
- for i,_ in pairs(reactorKit.reactor) do
- rob.fuelRodName[i] = reactorKit.reactor[i].name
- rob.fuelRodNum[i] = #reactorKit.reactor[i]
- end
- fs = io.open("robot", "w")
- fs:write(serialize(rob))
- fs:close()
- else
- rob = require("serialization").unserialize(fs:read())
- fs:close()
- end
- os.sleep(5)
- --отправка данных роботу
- modem.send(friend, 8, serialize(rob))
- --удаление ненужных данных
- rob = nil
- for i,side in pairs(reactorKit.sideR) do
- component.invoke(reactorKit.adrR[reactorKit.numR[i]], "setOutput", side, 100)
- end
- local iter, sideChes, packet, All, Checking, sender, inChest, react, past_packet, reactIter, robotReady
- robotReady = true
- packet = {}
- Checking = {}
- All = false
- past_packet = 1
- while true do
- while true do
- if not robotReady then
- local _, _, sender, _, _, _= event.pull(10, "modem_message")
- if sender == friend then
- os.sleep(1)
- modem.send(friend, 8, "true")
- robotReady = true
- for _,i in pairs(past_packet) do
- Checking[i] = nil
- end
- break
- end
- else
- if packet[1] then
- sort(packet)
- modem.send(friend, 8, serialize(packet))
- past_packet = copy(packet)
- packet = {}
- robotReady = false
- for _,i in ipairs(packet) do
- iter = 1
- while reactorKit.reactor[i*10 + iter] do
- for numSlot,slot in pairs(reactorKit.reactor[i*10 + iter]) do
- if numSlot ~= 'name' then
- transposer.transferItem(reactorKit.sideT[i], reactorKit.sideChest[(i - i%10) / 10], 1, slot)
- end
- end
- iter = iter + 1
- end
- end
- end
- end
- All = false
- --scaning
- if not All then
- All = true
- for i = 10, #reactorKit.adrT * 10, 10 do
- transposer = component.proxy(reactorKit.adrT[i / 10])
- i = i + 1
- while reactorKit.sideT[i] do
- if not Checking[i] and transposer.getStackInSlot(reactorKit.sideT[i], reactorKit.reactor[i * 10 + 1][1]).name ~= RodList1[reactorKit.reactor[i * 10 + 1].name] then
- component.invoke(reactorKit.adrR[reactorKit.numR[i]], "setOutput", reactorKit.sideR[i], 0)
- packet[#packet + 1] = i
- Checking[i] = true
- elseif All then
- All = false
- end
- i = i + 1
- end
- end
- else
- os.sleep(10)
- end
- for _,h in ipairs(packet) do
- print(h, ": ", h)
- end
- io.read()
- term.clear()
- end
- for _,i in pairs(past_packet) do
- iter = 1
- sideChest = reactorKit.sideChest[(i - i%10) / 10]
- while reactorKit.reactor[i*10 + iter] do
- react = reactorKit.reactor[i*10 + iter]
- transposer = component.proxy(reactorKit.adrT[(i - i%10) / 10])
- for slot = 1, transposer.getInventorySize(sideChest) do
- inChest = transposer.getStackInSlot(sideChest, slot)
- if inChest and inChest.name == RodList1[react.name] then
- for numSlot,j in pairs(react) do
- if numSlot ~= "name" then
- transposer.transferItem(sideChest, reactorKit.sideT[i],1,slot, j)
- end
- end
- end
- end
- iter = iter + 1
- end
- component.invoke(reactorKit.adrR[reactorKit.numR[i]], "setOutput", reactorKit.sideR[i], 15)
- end
- past_packet = 1 -- своеобразное удаление прошлого пакета, т.к. он не нужен
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement