Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.79 KB | None | 0 0
  1. local offReac = 9850
  2. local perDamage = 77
  3. local perDamageS = 1000
  4.  
  5. local computer = require("computer")
  6. local com = require("component")
  7. local event = require("event")
  8. local gpu = com.gpu
  9. local slotReac = {}
  10. local slotSter = {}
  11. local per,pers,noFuel,toChest,toReac = 0,0,1,1
  12. local vr,data1,sideReac,sideInv,sideRed,sideinterface
  13. local w,h = gpu.getResolution()
  14.  
  15. if not com.isAvailable("reactor_chamber") then
  16. print("для работы нужен адаптер")
  17. os.exit()
  18. end
  19. local reactor = com.reactor_chamber
  20.  
  21. if not com.isAvailable("transposer") then
  22. print("для работы нужен транспозер")
  23. os.exit()
  24. end
  25. local tr = com.transposer
  26.  
  27. if not com.isAvailable("redstone") then
  28. print("для работы нужен контроллер красного камня")
  29. os.exit()
  30. end
  31. local red = com.redstone
  32.  
  33. if reactor.producesEnergy() then
  34. print("\n".."остановите реактор !")
  35. for i=0,5 do
  36. if red.getOutput(i) > 0 then
  37. red.setOutput(i, 0)
  38. end
  39. end
  40. os.exit()
  41. end
  42.  
  43. if reactor.getHeat() > offReac then
  44. print("\n".."перегрев реактора !")
  45. os.exit()
  46. end
  47.  
  48. print("поиск реактора и сундука")
  49. for i=0,5 do
  50. vr = tr.getInventoryName(i)
  51. if vr then
  52. if vr == "ic2:te" then
  53. print("реактор в стороне: "..i)
  54. sideReac = i
  55. end
  56. local chest = string.find(vr,"hest")
  57. if chest then
  58. print("сундук в стороне: "..i)
  59. sideInv = i
  60. end
  61. local interface = string.find(vr,"interface")
  62. if interface then
  63. print("interface в стороне: "..i)
  64. sideinterface = i
  65. end
  66. end
  67. end
  68. if not sideReac then
  69. print("\n".."камера реактора не найдена")
  70. os.exit()
  71. end
  72. if not sideInv then
  73. print("\n".."сундук не найден")
  74. os.exit()
  75. end
  76. if not sideinterface then
  77. print("\n".."interface не найден")
  78. os.exit()
  79. end
  80. local slotsReac = tr.getInventorySize(sideReac)
  81. local slotsInv = tr.getInventorySize(sideInv)
  82. local slotsinterface = tr.getInventorySize(sideinterface)
  83.  
  84. print("сохранение расположения стержней")
  85. local data = tr.getAllStacks(sideReac).getAll()
  86. for i=0, slotsReac+1 do
  87. if data[i] and (data[i].name == 'ic2:quad_uranium_fuel_rod' or data[i].name == "ic2:quad_mox_fuel_rod") then
  88. pers = math.ceil(100*data[i].damage/10000)
  89. print("слот: "..(i).." износ: "..pers.." %")
  90. if pers >= perDamageS then
  91. print("\n".."замените стержень в слоте: "..(i))
  92. os.exit()
  93. end
  94. slotSter[#slotSter+1] = i
  95. end
  96. end
  97.  
  98. print("сохранение расположения конденсаторов")
  99. local data = tr.getAllStacks(sideReac).getAll()
  100. for i=0, slotsReac+1 do
  101. if data[i] and (data[i].name == 'ic2:lzh_condensator' or data[i].name == "ic2:lzh_condensator") then
  102. per = math.ceil(100*data[i].damage/100000)
  103. print("слот: "..(i).." износ: "..per.." %")
  104. if per >= perDamage then
  105. print("\n".."замените конденсатор в слоте: "..(i))
  106. os.exit()
  107. end
  108. slotReac[#slotReac+1] = i
  109. end
  110. end
  111.  
  112. print("пробный запуск")
  113. for i=0,5 do
  114. red.setOutput(i, 15)
  115. if reactor.producesEnergy() then
  116. sideRed = i
  117. red.setOutput(sideRed, 0)
  118. print("редстоун в стороне: "..sideRed)
  119. break
  120. else
  121. red.setOutput(i, 0)
  122. end
  123. if i == 5 then
  124. print("\n".."реактор не запускается")
  125. os.exit()
  126. end
  127. end
  128.  
  129. print("настройка завершена".."\n".."старт...")
  130. os.sleep(2)
  131.  
  132. local function gui()
  133. gpu.setResolution(28,15)
  134. gpu.setBackground(0x000000)
  135. gpu.fill(1,1,28,15," ")
  136. gpu.setForeground(0x669999)
  137. gpu.set(1,1,"┌──────────────────────────┐")
  138. gpu.set(1,2,"│ │ │ │ │ │ │ │ │ │")
  139. gpu.set(1,3,"│──────────────────────────│")
  140. gpu.set(1,4,"│ │ │ │ │ │ │ │ │ │")
  141. gpu.set(1,5,"│──────────────────────────│")
  142. gpu.set(1,6,"│ │ │ │ │ │ │ │ │ │")
  143. gpu.set(1,7,"│──────────────────────────│")
  144. gpu.set(1,8,"│ │ │ │ │ │ │ │ │ │")
  145. gpu.set(1,9,"│──────────────────────────│")
  146. gpu.set(1,10,"│ │ │ │ │ │ │ │ │ │")
  147. gpu.set(1,11,"│──────────────────────────│")
  148. gpu.set(1,12,"│ │ │ │ │ │ │ │ │ │")
  149. gpu.set(1,13,"└──────────────────────────┘")
  150. end
  151.  
  152. local xy = {
  153. {"2","2"},{"5","2"},{"8","2"},{"11","2"},{"14","2"},{"17","2"},{"20","2"},{"23","2"},{"26","2"},
  154. {"2","4"},{"5","4"},{"8","4"},{"11","4"},{"14","4"},{"17","4"},{"20","4"},{"23","4"},{"26","4"},
  155. {"2","6"},{"5","6"},{"8","6"},{"11","6"},{"14","6"},{"17","6"},{"20","6"},{"23","6"},{"26","6"},
  156. {"2","8"},{"5","8"},{"8","8"},{"11","8"},{"14","8"},{"17","8"},{"20","8"},{"23","8"},{"26","8"},
  157. {"2","10"},{"5","10"},{"8","10"},{"11","10"},{"14","10"},{"17","10"},{"20","10"},{"23","10"},{"26","10"},
  158. {"2","12"},{"5","12"},{"8","12"},{"11","12"},{"14","12"},{"17","12"},{"20","12"},{"23","12"},{"26","12"},
  159. }
  160.  
  161. local function circuitCheck()
  162. local data = tr.getAllStacks(sideReac).getAll()
  163. local sh = 0
  164. for i=1,#slotReac do
  165. if data[slotReac[i]].damage then
  166. sh = sh + 1
  167. end
  168. end
  169. if sh == #slotReac then
  170. return true
  171. else
  172. return false
  173. end
  174. end
  175.  
  176. local function stop()
  177. red.setOutput(sideRed, 0)
  178. gpu.setResolution(w, h)
  179. gpu.setBackground(0x000000)
  180. gpu.setForeground(0xFFFFFF)
  181. gpu.fill(1, 1, w, h, " ")
  182. print("программа завершена")
  183. os.sleep(1)
  184. if reactor.producesEnergy() then
  185. print("ВНИМАНИЕ реактор по прежнему активен !!!")
  186. else
  187. print("реактор остановлен")
  188. end
  189. os.exit()
  190. end
  191.  
  192. gui()
  193. gpu.setForeground(0xFF9900)
  194. gpu.set(1,14," для завершения нажмите E ")
  195. while true do
  196.  
  197. local data = tr.getAllStacks(sideReac).getAll()
  198. for i=1,#slotReac do
  199. if data[slotReac[i]].damage then
  200. per = math.ceil(100*data[slotReac[i]].damage/100000)
  201. gpu.setForeground(0xFF9900)
  202. gpu.set(tonumber(xy[slotReac[i]][1]),tonumber(xy[slotReac[i]][2]),tostring(per))
  203. else
  204. per = 0
  205. end
  206.  
  207. if per == 100 then
  208. red.setOutput(sideRed, 0)
  209. gpu.setForeground(0xFF0000)
  210. gpu.set(1,14," снизте % замены конденсат. ")
  211. gpu.set(1,15," реактор остановлен ")
  212. event.pull("key_down")
  213. stop()
  214. end
  215. if computer.energy() <=400 then
  216. print("В Системе Кончился Лазурит! Реактор Остановлен")
  217. stop()
  218. end
  219. if per >= perDamage or per == 0 then
  220. red.setOutput(sideRed, 0)
  221. gpu.setForeground(0xFF9900)
  222. gpu.set(1,15," замена конденсаторов ")
  223. os.sleep(0.2)
  224. toChest = tr.transferItem(sideReac, sideInv, 1, slotReac[i])
  225. gpu.setForeground(0xFF0000)
  226. gpu.set(tonumber(xy[slotReac[i]][1]),tonumber(xy[slotReac[i]][2]),"██")
  227. data1 = tr.getAllStacks(sideInv).getAll()
  228. for i1=0,slotsInv do
  229. if data1[i1] and (data1[i1].name == "ic2:lzh_condensator" or data1[i1].name == "ic2:lzh_condensator") and data1[i1].damage < 100 then
  230. toReac = tr.transferItem(sideInv, sideReac, 1, i1, slotReac[i])
  231. gpu.setForeground(0x00FF00)
  232. gpu.set(tonumber(xy[slotReac[i]][1]),tonumber(xy[slotReac[i]][2]),"██")
  233. break
  234. end
  235. end
  236. end
  237. end
  238.  
  239. -- получаем все слоты реактора
  240. local data = tr.getAllStacks(sideReac).getAll()
  241. -- проходим все слоты
  242. for i=1,#slotSter do
  243. -- если в слоте хуйня
  244. if data[slotSter[i]].name == "ic2:nuclear" then
  245. -- убираем в сундук
  246. tr.transferItem(sideReac, sideinterface, 1, slotSter[i])
  247. -- получаем инвентарь интерфейса
  248. data1 = tr.getAllStacks(sideinterface).getAll()
  249. -- проходим все ячейки
  250. for i1=0,slotsinterface do
  251. -- если в ячейке топливо
  252. if data1[i1] and data1[i1].name == "ic2:quad_mox_fuel_rod" then
  253. -- кладем на место старого
  254. tr.transferItem(sideinterface, sideReac, 1, i1, slotSter[i])
  255. break
  256. end
  257. end
  258. end
  259. end
  260.  
  261.  
  262.  
  263. gpu.setForeground(0xFF0000)
  264. if reactor.getHeat() > offReac then
  265. red.setOutput(sideRed, 0)
  266. gpu.set(1,15," перегрев реактора ! ")
  267. elseif not circuitCheck() then
  268. gpu.set(1,15," нет целых конденсаторов ! ")
  269. elseif toChest == 0 and toReac == 0 then
  270. gpu.set(1,15," в сундуке нет места ! ")
  271. elseif noFuel >= 5 then
  272. gpu.set(1,15," нет топлива ! ")
  273. else
  274. red.setOutput(sideRed, 15)
  275. if not reactor.producesEnergy() then
  276. gpu.set(1,15," реактор не запускается ! ")
  277. else
  278. gpu.setForeground(0x00FF00)
  279. gpu.set(1,15," реактор работает ")
  280. end
  281. end
  282. local e = {event.pull(0.7,"key_down")}
  283. if e[4] == 18 or e[4] == 20 then
  284. stop()
  285. end
  286. if reactor.producesEnergy() and reactor.getReactorEUOutput() == 0 then
  287. noFuel = noFuel + 1
  288. else
  289. noFuel = 0
  290. end
  291. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement