DakinUA

Reactor control

Jul 29th, 2021 (edited)
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.51 KB | None | 0 0
  1. -- Низ-0, верх-1, сзади-2, перед-3, право-4, лево-5.
  2. local side = 0
  3. -- Номер слота, в котором лежит стержень, если все схемы разные-ставьте 0 (не работает)
  4. local slot = 22
  5. -- Автозамена стержней(на будущее)
  6. --local autoChange = 0
  7.  
  8.  
  9. -- Обьявление библиотек
  10. local version = "0.4"
  11. local os = require("os")
  12. local component = require("component")
  13. local sides = require("sides")
  14. local math = require("math")
  15. local term = require("term")
  16. local event = require("event")
  17.  
  18. -- Обьявление компонентов
  19. local gpu = component.gpu
  20. -- Раcкомментировать для использования очков AR (не работает)
  21. --local glasses = component.glasses
  22.  
  23. -- Массив данных с адрессами реакторов и инвентарей реакторов
  24. -- statistic - адресс реактора, inventory - адресс контроллера инвентаря
  25.  
  26. local reactor = {  
  27.   r1 = {  
  28.     statistic = "e7e5119c-f89c-413a-8860-3c857426c303",  
  29.     inventory = "f6d4f92c-4bea-4500-8105-3243cb4e9ddd"  
  30.   },
  31.   r2 = {  
  32.     statistic = "c6b55c97-677e-4e2e-8671-d0ea9456402f",  
  33.     inventory = "2b94b239-11de-40b1-936f-10b491ac8a23"  
  34.   },
  35.   r3 = {  
  36.     statistic = "5e1cf1d3-d01c-4ef9-bbe4-9d62a3df6d72",  
  37.     inventory = "a445b4ff-dd8f-4e4d-bccd-bfe48b232b39"
  38.   },
  39.   r4 = {  
  40.     statistic = "e9d92feb-8f29-47a5-a61a-3a047befcb05",  
  41.     inventory = "a6019959-3d34-4f12-a76c-5b4ace0098d8"  
  42.   },
  43.   r5 = {  
  44.     statistic = "66418556-5823-4ca4-842d-05870f651e26",  
  45.     inventory = "096f0a3e-9acd-466c-a39a-3aed3b58ce06"  
  46.   },
  47.   reactor6 = {  
  48.     statistic = "13879e6c-5e64-4c7a-8893-c2043647b153",  
  49.     inventory = "5f82f103-d01c-45c2-b6d5-b1fbc155a465"  
  50.   },
  51.   reactor7 = {  
  52.     statistic = "9903629d-ff29-4b7a-bb11-8a20506b3a71",  
  53.     inventory = "f68cf793-4c54-4fe0-9076-3bb411cb56e7"  
  54.   },
  55.   reactor8 = {  
  56.     statistic = "2b6663c4-6e28-4888-bc8b-690512553c86",  
  57.     inventory = "d38b17d0-515c-4b34-a3dd-4216d3ec938f"  
  58.   }
  59. };
  60.  
  61. local clearCords = {
  62.     r1 = {2, 4, 15, 9},
  63.     r2 = {18, 4, 15, 9},  
  64.     r3 = {34, 4, 15, 9},
  65.     r4 = {50, 4, 15, 9},
  66.     r5 = {66, 4, 14, 9},
  67.     r6 = {2, 16, 15, 9},
  68.     r7 = {18, 16, 15, 9},
  69.     r8 = {34, 16, 15, 9},
  70.     r9 = {50, 16, 15, 9},
  71.     r10 = {66, 16, 14, 9}
  72. };
  73.  
  74. --Координаты надписей
  75.  
  76. local coords = {
  77.     r1 = {
  78.         coordsA = {3, 5},
  79.         coordsV = {4, 6},
  80.         coordsO = {4, 8},
  81.         coordsT = {5, 9}
  82.     };
  83.     --2 = {
  84.     --    coordsA =
  85.     --    coordsV =
  86.     --    coordsO =
  87.     --};
  88. };
  89.  
  90. --Вспомогательная часть
  91.  
  92. local statusReactor = {r1=0, r2=0, r3=0, r4=0, r5=0, r6=0, r7=0, r8=0, r9=0, r10=0};
  93.  
  94.  
  95.  
  96. --Выставление разрешения экрана
  97. gpu.setResolution(80, 25)
  98. --Цвет экрана
  99. gpu.setBackground(0X0000FF)
  100. --Очистка экрана
  101. term.clear()
  102.  
  103. --Нанесение разметки на экране
  104. gpu.set(1, 1, "╔═══════════════╤═══════════════╤═══════════════╤═══════════════╤══════════════╗")
  105. gpu.set(1, 25,"╚═══════════════╧═══════════════╧═══════════════╧═══════════════╧══════════════╝")
  106.  
  107. for i = 2, 24 do
  108.     gpu.set(1, i, "║")
  109.     gpu.set(80, i, "║")
  110.    
  111.     gpu.set(17, i, "│")
  112.     gpu.set(33, i, "│")
  113.     gpu.set(49, i, "│")
  114.     gpu.set(65, i, "│")
  115. end
  116.  
  117. gpu.set(1, 13,"╟───────────────┼───────────────┼───────────────┼───────────────┼──────────────╢")
  118.  
  119. gpu.set(5, 3, "Реактор 1")
  120. gpu.set(21, 3, "Реактор 2")
  121. gpu.set(37, 3, "Реактор 3")
  122. gpu.set(53, 3, "Реактор 4")
  123. gpu.set(69, 3, "Реактор 5")
  124. gpu.set(5, 15, "Реактор 6")
  125. gpu.set(21, 15, "Реактор 7")
  126. gpu.set(37, 15, "Реактор 8")
  127. gpu.set(53, 15, "Реактор 9")
  128. gpu.set(68, 15, "Реактор 10")
  129.  
  130. --Функция, возвращает на место времени
  131. local function getTime(numberReactor, side, slot)
  132.     infoRod = component.proxy(reactor.numberReactor.inventory).getStackInSlot(side,slot)
  133.     if not infoRod then
  134.         return "Слот пустой"
  135.     elseif infoRod.name == "ic2:nuclear" then
  136.         return "Пора менять стержни"
  137.     elseif infoRod.name == "ic2:mox_fuel_rod" or infoRod.name =="ic2:dual_mox_fuel_rod"or infoRod.name =="ic2:quad_mox_fuel_rod" then
  138.         local rodAllSec = infoRod.maxDamage-infoRod.damage
  139.         local rodHour = tostring(math.floor(rodAllSec/3600))
  140.         local rodMin = tostring(math.floor((rodAllSec-rodHour*3600)/60))
  141.         local rodSec = tostring(math.floor(rodAllSec-(rodHour*3600+rodMin*60)))
  142.         return rodHour..":"..rodMin..":"..rodSec
  143.     else
  144.         return "Не правильно выбран слот"
  145.    end
  146. end
  147.  
  148. local function changeStatusReactor(numberReactor, side, slot)
  149.     if statusReactor.numberReactor == 0 then
  150.              
  151.         gpu.fill(clearCords.numberReactor[1], clearCords.numberReactor[2], clearCords.numberReactor[3], clearCords.numberReactor[4], " ") --поменять значения
  152.        
  153.         gpu.set(coords.numberReactor.coordsA, "Активирован")
  154.         gpu.set(coords.numberReactor.coordsV, "Выход:")
  155.         gpu.set(coords.numberReactor.coordsO, "Осталось:")
  156.        
  157.         statusReactor[numberReactor] = 1
  158.        
  159.     elseif statusReactor[numberReactor] == 1 then
  160.            
  161.         gpu.fill(coords.numberReactor.coordsT[1], coords.numberReactor.coordsT[2], 1, 7, " ")
  162.         gpu.set(coords.numberReactor.coordsT[1], coords.numberReactor.coordsT[2], getTime(numberReactor, side, slot))    
  163.            
  164.     elseif statusReactor[numberReactor] == 2 then
  165.         gpu.fill(clearCords.numberReactor[1], clearCords.numberReactor[2], clearCords.numberReactor[3], clearCords.numberReactor[4], " ")
  166.         gpu.set(coordsV, "Выключен")
  167.     end
  168. end
  169.  
  170. while true do
  171.     if component.proxy(reactor.r1.statistic).producesEnergy() == true then
  172.         changeStatusReactor("r1", side, slot)
  173.     else
  174.         print("нет energy")
  175.    end    
  176. end  
  177.  
Add Comment
Please, Sign In to add comment