Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- установщик схемы в реактор IC2(1.12.2) by serafim
- -- pastebin.com/LYDve4ai update 17.05.21
- -- https://i.imgur.com/GxOR7xv.gif
- local circuits = {
- [360] = {
- 5,6,4,5,6,4,5,6,4,
- 6,1,6,6,1,6,6,1,6,
- 4,6,5,4,6,5,4,6,5,
- 5,6,4,5,6,4,5,6,4,
- 6,1,6,6,1,6,6,1,6,
- 4,6,5,4,6,5,4,6,5
- },
- [420] = {
- 1,4,6,3,6,6,4,6,5,
- 5,4,6,6,4,6,6,1,6,
- 5,6,1,6,6,1,6,6,4,
- 4,6,6,4,6,6,4,6,5,
- 6,1,6,6,1,6,6,1,6,
- 5,6,4,5,6,4,5,6,4
- },
- [1056] = {
- 2,7,7,4,4,7,7,2,5,
- 7,3,3,7,7,3,3,7,5,
- 4,7,7,4,4,7,7,4,5,
- 4,7,7,4,4,7,7,4,5,
- 7,3,3,7,7,3,3,7,5,
- 2,7,7,4,4,7,7,2,5
- },
- [1308] = {
- 7,3,7,4,7,4,7,3,7,
- 4,7,2,7,4,7,2,7,4,
- 7,4,7,4,7,4,7,4,7,
- 3,7,4,7,2,7,4,7,3,
- 7,2,7,4,7,4,7,2,7,
- 4,7,3,7,4,7,3,7,4
- }
- }
- local components = {
- [1] = "ic2:quad_uranium_fuel_rod",
- [2] = "ic2:quad_mox_fuel_rod",
- [3] = "ic2:component_heat_exchanger",
- [4] = "ic2:component_heat_vent",
- [5] = "ic2:plating",
- [6] = "ic2:overclocked_heat_vent",
- [7] = "ic2:advanced_heat_vent"
- }
- local translate = {
- [1] = "счетверённый стержень (УРАН)",
- [2] = "счетверённый стержень (MOX)",
- [3] = "компонентный теплообменник",
- [4] = "компонентный теплоотвод",
- [5] = "реакторная обшивка",
- [6] = "разогнанный теплоотвод",
- [7] = "улучшенный теплоотвод"
- }
- local com = require('component')
- local computer = require("computer")
- local event = require("event")
- local gpu = com.gpu
- local w,h = gpu.getViewport()
- if not com.isAvailable("robot") then
- print("только роботы могут использовать эту программу")
- os.exit()
- end
- local r = require("robot")
- local invsize = r.inventorySize()
- if not com.isAvailable("inventory_controller") then
- print("нет контроллера инвентаря")
- os.exit()
- end
- local i_c = com.inventory_controller
- os.execute("cls")
- local a,set = {...}
- local atr = tonumber(a[1])
- if atr and circuits[atr] then
- set = atr
- else
- gpu.set(1,1,"выберите схему :")
- local x = 18
- for i, d in pairs(circuits) do
- gpu.set(x,1,tostring(i))
- x = x + string.len(i) + 2
- end
- print()
- set = tonumber(io.read())
- if not circuits[set] then
- print("схема не найдена")
- os.exit()
- end
- end
- gpu.fill(1,1,w,2," ")
- gpu.set(1,1,"выбрана схема : "..set.." eu/t")
- local circuit = {}
- for i, d in pairs(circuits) do
- if set == i then
- for a, b in ipairs(d) do
- table.insert(circuit, b)
- end
- break
- end
- end
- gpu.set(1,5,"необходимые компоненты")
- gpu.set(1,6,string.rep("─",50))
- gpu.set(30,5,"всего")
- local function status(msg)
- gpu.fill(1,3,w,1," ")
- gpu.set(1,3,msg)
- end
- local drop = 0
- local scaninv = {}
- local function scan()
- for slot = 1, invsize do
- if r.count(slot) == 0 then
- r.select(slot)
- i_c.equip()
- break
- end
- end
- status("сканирую инвентарь робота")
- scaninv = {}
- for inv = 1, invsize do
- if r.count(inv) > 0 then
- local item = i_c.getStackInInternalSlot(inv)
- for key, val in ipairs(components) do
- if item.name == components[key] then
- table.insert(scaninv,{inv,val})
- break
- end
- end
- end
- end
- local count,y = 0,6
- for key, val in ipairs(components) do
- count = 0
- for ind, dat in ipairs(circuit) do
- if key == dat then
- count = count + 1
- end
- end
- if count > 0 then
- y = y + 1
- gpu.set(1,y,translate[key])
- gpu.set(32,y,tostring(count))
- count = 0
- for ind, dat in ipairs(circuit) do
- if ind >= drop + 1 and key == dat then
- count = count + 1
- end
- end
- for slot, d in ipairs(scaninv) do
- if scaninv[slot][2] == val then
- count = count - r.count(scaninv[slot][1])
- end
- end
- if count > 0 then
- gpu.set(40,5,"не хватает")
- gpu.set(40,y,tostring(count).." ")
- else
- gpu.set(40,5,"хватает ")
- gpu.set(40,y," ")
- end
- end
- end
- end
- local time_start = computer.uptime()
- scan()
- for ind, d in ipairs(circuit) do
- status("выставляю схему в реакторе")
- while ind ~= drop do
- for slot, val in ipairs(scaninv) do
- if scaninv[slot][2] == components[d] then
- if r.count(scaninv[slot][1]) > 0 then
- r.select(scaninv[slot][1])
- r.drop(1)
- drop = drop + 1
- if r.count(scaninv[slot][1]) == 0 then
- table.remove(scaninv,slot)
- end
- end
- break
- end
- end
- if ind ~= drop then
- status("требуется - "..translate[d])
- while true do
- local e = {event.pull()}
- if e[1] == "inventory_changed" and r.count(e[2]) > 0 then
- status("ожидаю компоненты")
- os.sleep(5)
- scan()
- break
- elseif e[1] == "key_down" and e[4] == 29 or e[4] == 157 then
- os.execute("cls")
- os.exit()
- end
- end
- end
- end
- end
- os.execute("cls")
- print("готово "..os.date("%M:%S",computer.uptime()-time_start))
- for i = 1, invsize do
- if r.count(i) == 0 then
- for j = invsize, 1, -1 do
- if r.count(j) > 0 then
- if j < i then
- break
- end
- r.select(j)
- r.transferTo(i)
- break
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement