DEPSTRCZ

uni2.lua

Sep 30th, 2022
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.10 KB | None | 0 0
  1. local term = require("term")
  2. local component = require("component")
  3. local computer = require("computer")
  4. local math = require("math")
  5. local event = require("event")
  6. local string = require("string")
  7. local unicode = require("unicode")
  8. local os = require("os")
  9. local fs = require('filesystem')
  10.  
  11. local gpu = component.gpu
  12. gpu.setResolution(100,50)
  13. br = component.getPrimary("br_reactor")
  14.  
  15. local boucle2 = 0
  16. local a = 80
  17. local b = 1
  18. local lvl
  19. local val = 0
  20. local rod = 1
  21. local nbrrod = br.getNumberOfControlRods()
  22.  
  23. local function setColor(bg,fg)
  24. gpu.setBackground(bg)
  25. gpu.setForeground(fg)
  26. end
  27.  
  28. local function loadbar(x,y,width,cur,text,bg,fg)
  29. local raw = " " .. text ..string.rep(" ", width - unicode.len(text) - 2) .. " "
  30. local oldbg = gpu.setBackground(bg)
  31. local oldfg = gpu.setForeground(fg)
  32. gpu.set(x,y,unicode.sub(raw,1,cur))
  33. gpu.setBackground(oldbg)
  34. gpu.setForeground(oldfg)
  35. gpu.set(x+cur,y,unicode.sub(raw,cur+1,width))
  36. end
  37.  
  38. local function hexa(dec)
  39. local B,K,OUT,I,D = 16,"0123456789ABCDEF","",0
  40. if dec <= 0 then
  41. OUT = "00"
  42. elseif dec > 0 and dec < 16 then
  43. D = dec + 1
  44. OUT = "0"..string.sub(K,D,D)
  45. elseif dec > 16 and dec < 256 then
  46. V1 = math.modf(dec/B)+1
  47. V2 = dec-V1*16
  48. OUT = string.sub(K,V1,V1)..string.sub(K,V2,V2)
  49. elseif dec >= 255 then
  50. OUT = "FF"
  51. end
  52. return OUT
  53. end
  54.  
  55. local function round(num, dec)
  56. local mult = 10 ^ (dec or 0)
  57. return math.floor(num * mult + 0.5) / mult
  58. end
  59.  
  60. local function affrod(x,y,l)
  61. local rodv = rod + l -1
  62. if rodv < 0 or rodv > nbrrod -1then
  63. gpu.set(x,y," ")
  64. else
  65. local lvl = br.getControlRodLevel(rodv)
  66. gpu.set(x,y,"JÁDRO:"..string.format("% 2s",rodv + 1).." / HLOUBKA : "..string.format("% 3s",lvl).."%")
  67. end
  68. end
  69.  
  70. local function control(x,y)
  71. local lvl = br.getControlRodLevel(rod-1)
  72. local rouge = math.floor((100-lvl)*255/50)
  73. local vert = math.floor(lvl*255/50)
  74. local color = hexa(rouge)..hexa(vert).."00"
  75. local color2 = tonumber(string.format("%6s",color),16)
  76. setColor(color2,0x0000FF)
  77. gpu.set(22,48,string.format("% 3s",rod))
  78. setColor(0x0, 0xFFFFFF)
  79. affrod(x,y-6,-3)
  80. affrod(x,y-4,-2)
  81. affrod(x,y-2,-1)
  82. setColor(0x00FF00,0x0000FF)
  83. affrod(x,y,0)
  84. setColor(0x000000,0xFFFFFF)
  85. affrod(x,y+2,1)
  86. affrod(x,y+4,2)
  87. affrod(x,y+6,3)
  88. end
  89.  
  90. local function manualrod(x,y,rod)
  91. local lvl
  92. gpu.set(a,b,"╦═══════════════════╗")
  93. gpu.set(a,b+1,"║ Hloubka tyčí ║")
  94. gpu.set(a,b+2,"╠═══════════════════╣")
  95. gpu.set(a,b+3,"║ ČÍSLO ║")
  96. gpu.set(a,b+4,"║ ║")
  97. gpu.set(a,b+5,"║ █-10█ █+10█ ║")
  98. gpu.set(a,b+6,"║ ║")
  99. gpu.set(a,b+7,"║ █-1 █ █+1 █ ║")
  100. gpu.set(a,b+8,"║ ║")
  101. gpu.set(a,b+9,"║ ██████ ███████ ║")
  102. gpu.set(a,b+10,"║ ZRUŠIT PŘIJMOUT ║")
  103. gpu.set(a,b+11,"║ ██████ ███████ ║")
  104. gpu.set(a,b+12,"╚═══════════════════╣")
  105. lvl = br.getControlRodLevel(rod-1)
  106. gpu.set(a+12,b+3,string.format("% 3s",lvl))
  107. gpu.set(a+8,b+3,string.format("% 2s",rod))
  108. boucle2 = 1
  109. end
  110.  
  111. local function manualallrod()
  112. gpu.set(a,b,"╦═══════════════════╗")
  113. gpu.set(a,b+1,"║ HLOUBKA TYČE ║")
  114. gpu.set(a,b+2,"╠═══════════════════╣")
  115. gpu.set(a,b+3,"║VŠECHNY TYČE █100█ ║")
  116. gpu.set(a,b+4,"║ ║")
  117. gpu.set(a,b+5,"║ █-10█ █+10█ ║")
  118. gpu.set(a,b+6,"║ ║")
  119. gpu.set(a,b+7,"║ █-1 █ █+1 █ ║")
  120. gpu.set(a,b+8,"║ ║")
  121. gpu.set(a,b+9,"║ ██████ ███████ ║")
  122. gpu.set(a,b+10,"║ ZRUŠIT PŘIJMOUT ║")
  123. gpu.set(a,b+11,"║ ██████ ███████ ║")
  124. gpu.set(a,b+12,"╚═══════════════════╣")
  125. gpu.set(a+12,b+3,string.format("% 3s",val))
  126. boucle2 = 2
  127. end
  128.  
  129. local function manualoff()
  130. boucle2 = 0
  131. gpu.set(a,b,"════════════════════╗")
  132. gpu.set(a,b+1," ║")
  133. gpu.set(a,b+2," ║")
  134. gpu.set(a,b+3," ║")
  135. gpu.set(a,b+4," ║")
  136. gpu.set(a,b+5," ║")
  137. gpu.set(a,b+6," ║")
  138. gpu.set(a,b+7," ║")
  139. gpu.set(a,b+8," ║")
  140. gpu.set(a,b+9," ║")
  141. gpu.set(a,b+10," ║")
  142. gpu.set(a,b+11," ║")
  143. gpu.set(a,b+12," ║")
  144. end
  145.  
  146. local function bargraph(x,y,length,am,cap,na,col,colpol)
  147. local amount = am
  148. local capacity = cap
  149. local pct = amount / capacity
  150. local cur = math.floor(pct * length)
  151. local color = col
  152. local color2 = colpol
  153. local name = na
  154. local textfrac = string.format("%s / %s", amount, capacity)
  155. local textpct = string.format("%.02f%%", pct*100)
  156. local text = textfrac .. string.rep(" ", length - string.len(textfrac) - string.len(textpct) - 6) .. " " .. textpct .. " "
  157. local text1 = " Úroveň naplnění : ("..name..")"
  158. loadbar(x,y,length,cur,text1,color,color2)
  159. loadbar(x,y+1,length,cur,text,color,color2)
  160. end
  161.  
  162. function drawbars()
  163. amFuel = br.getFuelAmount()
  164. capFuel = br.getFuelAmountMax()
  165. naFuel = "Palivo - Yellorium"
  166. colFuel = 0xFFFF00
  167. colpolFuel = 0x0000FF
  168. bargraph(2,22,98,amFuel,capFuel,naFuel,colFuel,colpolFuel)
  169. amWaste = br.getWasteAmount()
  170. capWaste = 64000
  171. naWaste = "Odpad - Cyanite"
  172. colWaste = 0x00FFFF
  173. colpolWaste = 0xFF00FF
  174. bargraph(2,25,98,amWaste,capWaste,naWaste,colWaste,colpolWaste)
  175. amSteam = br.getHotFluidAmount()
  176. capSteam = br.getHotFluidAmountMax()
  177. naSteam = "Páry"
  178. colSteam = 0x8F8F8F
  179. colpolSteam = 0xFFFF00
  180. bargraph(2,28,98,amSteam,capSteam,naSteam,colSteam,colpolSteam)
  181. amWater = br.getCoolantAmount()
  182. capWater = br.getCoolantAmountMax()
  183. naWater = "Voda"
  184. colWater = 0x71b6cb
  185. colpolWater = 0x0000FF
  186. bargraph(2,31,98,amWater,capWater,naWater,colWater,colpolWater)
  187. consot = br.getFuelConsumedLastTick()
  188. consos = consot * 20
  189. consoh = consos * 3.6
  190. consoj = consoh * 24
  191. gpu.set(2,35,string.format("% 1.03f",consot).."mb/t =>"..string.format("% 1.02f",consos).."mb/s =>"..string.format("% 3.02f",consoh).."b/h =>"..string.format("% 5.02f",consoj).."b/d")
  192. Tcore = br.getCasingTemperature()
  193. Tfuel = br.getFuelTemperature()
  194. Reactivity = br.getFuelReactivity()
  195. Prod = br.getHotFluidProducedLastTick()
  196. gpu.set(35,38,string.format("% 4.2f",Tcore))
  197. gpu.set(35,40,string.format("% 4.2f",Tfuel))
  198. gpu.set(35,42,string.format("% 4.2f",Reactivity))
  199. gpu.set(35,44,string.format("% 4.2f",Prod))
  200. end
  201.  
  202. local function waste()
  203. local waste = br.getWasteAmount()
  204. if waste > 48000 then
  205. br.doEjectWaste()
  206. end
  207. end
  208.  
  209. local function marche(x,y)
  210. gpu.set(x,y," ")
  211. gpu.set(x,y+1," ZAPNOUT ")
  212. gpu.set(x,y+2," ")
  213. end
  214.  
  215. local function arret(x,y)
  216. gpu.set(x,y," ")
  217. gpu.set(x,y+1," VYPNOUT ")
  218. gpu.set(x,y+2," ")
  219. end
  220.  
  221. local function start()
  222. local ON = br.getActive()
  223. if ON == true then
  224. setColor(0x00FF00,0x0)
  225. marche(60,11)
  226. setColor(0x0,0xFF0000)
  227. arret(60,15)
  228. setColor(0x0,0xFFFFFF)
  229. elseif ON == false then
  230. setColor(0x0,0x00FF00)
  231. marche(60,11)
  232. setColor(0xFF0000,0xFFFFFF)
  233. arret(60,15)
  234. setColor(0x0,0xFFFFFF)
  235. end
  236. end
  237.  
  238. function allrods(val)
  239. for i=0, nbrrod-1 do
  240. level = br.getControlRodLevel(i)
  241. newlevel = val + level
  242. if newlevel > 100 then
  243. newlevel = 100
  244. elseif newlevel < 0 then
  245. newlevel = 0
  246. else
  247. newlevel = level + val
  248. end
  249. br.setControlRodLevel(i,newlevel)
  250. end
  251. end
  252.  
  253. term.clear()
  254. gpu.set(1,1,"╔══════════════════════════════════════════════════════════════════════════════════════════════════╗")
  255. gpu.set(1,2,"║ ║")
  256. gpu.set(1,3,"║ ███████████████████████████████████████████████ ████████████ ║")
  257. gpu.set(1,4,"║ ██ ██ █ Ovládání █ ║")
  258. gpu.set(1,5,"║ ██ ██ █ všech █ ║")
  259. gpu.set(1,6,"║ ██ ██ █ tyčí █ ║")
  260. gpu.set(1,7,"║ ██ ██ ████████████ ║")
  261. gpu.set(1,8,"║ ██ ██ ║")
  262. gpu.set(1,9,"║ ██ ██ ║")
  263. gpu.set(1,10,"║ ██ ██ ║")
  264. gpu.set(1,11,"║ ██ ██ █████████ ║")
  265. gpu.set(1,12,"║ ██ ██ █ZAPNOUT█ ║")
  266. gpu.set(1,13,"║ ██ ██ █████████ ║")
  267. gpu.set(1,14,"║ ██ ██ ║")
  268. gpu.set(1,15,"║ ██ ██ █████████████ ║")
  269. gpu.set(1,16,"║ ██ ██ █VYPNOUT █ ║")
  270. gpu.set(1,17,"║ ███████████████████████████████████████████████ █████████████ ║")
  271. gpu.set(1,18,"║ ║")
  272. gpu.set(1,19,"║ ║")
  273. gpu.set(1,20,"║ ║")
  274. gpu.set(1,21,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
  275. gpu.set(1,22,"║ ║")
  276. gpu.set(1,23,"║ ║")
  277. gpu.set(1,24,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
  278. gpu.set(1,25,"║ ║")
  279. gpu.set(1,26,"║ ║")
  280. gpu.set(1,27,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
  281. gpu.set(1,28,"║ ║")
  282. gpu.set(1,29,"║ ║")
  283. gpu.set(1,30,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
  284. gpu.set(1,31,"║ ║")
  285. gpu.set(1,32,"║ ║")
  286. gpu.set(1,33,"╠════════════════════════════════════════════════╦═════════════════════════════════════════════════╣")
  287. gpu.set(1,34,"║ SPOTŘEBA PALIVA ║ MiliBukket/second => mb/s Bukket/Hour => b/h ║")
  288. gpu.set(1,35,"║ ║ MiliBukket/tick => mb/t Bukket/Day => b/d ║")
  289. gpu.set(1,36,"╠════════════════════════════════════════════════╩══════════════════════╦══════════════════════════╣")
  290. gpu.set(1,37,"║ ║ Manulní vypouštění ║")
  291. gpu.set(1,38,"║ TEPLOTA REAKTORU : °C ║ ║")
  292. gpu.set(1,39,"║ ║ ║")
  293. gpu.set(1,40,"║ TEPLOTA PALIVA : °C ║ ██████████████████ ║")
  294. gpu.set(1,41,"║ ║ ██ CYANITE ██ ║")
  295. gpu.set(1,42,"║ RADIOAKTIVITA PALIVA : % ║ ██████████████████ ║")
  296. gpu.set(1,43,"║ ║ ║")
  297. gpu.set(1,44,"║ RECYKLACE PÁRY : mb/t ║ ██████████████████ ║")
  298. gpu.set(1,45,"╠═══════════════════════════════════════════════════════════════════════╣ ██ VÝPIS ██ ║")
  299. gpu.set(1,46,"║ Manuální výběr tyče ║ ██ YELLORIUM ██ ║")
  300. gpu.set(1,47,"║ ██████████████ ║ ██████████████████ ║")
  301. gpu.set(1,48,"║ █ -10 █ █ -1 █ rod █ +1 █ █ +10 █ ██ Potvrdit ██ ║ ║")
  302. gpu.set(1,49,"║ ██████████████ ║ ║")
  303. gpu.set(1,50,"╚═══════════════════════════════════════════════════════════════════════╩══════════════════════════╝")
  304.  
  305. start()
  306.  
  307. local function onTouch(event,adress,x,y,clic,pseudo)
  308. local tclic
  309. if clic == 0 then
  310. tclic = "НАЖИТО ЛКМ"
  311. elseif clic == 1 then
  312. tclic = "НАЖИТО ПКМ"
  313. else
  314. tclic = "НАЖИТО НЕИЗВЕСТНО"
  315. end
  316.  
  317. if x==1 and y==1 then
  318. computer.pushSignal("quit")
  319. term.setCursor(1,1)
  320. return false
  321.  
  322. elseif boucle2 == 0 then
  323. if x > 48 and x < 67 and y > 46 and y < 50 then
  324. manualrod(x,y,rod)
  325. lvl = br.getControlRodLevel(rod-1)
  326. elseif x > 58 and x < 78 and y > 2 and y < 9 then
  327. manualallrod()
  328. elseif x > 77 and x < 96 and y > 38 and y < 43 then
  329. br.doEjectWaste()
  330. elseif x > 77 and x < 96 and y > 43 and y < 48 then
  331. br.doEjectFuel()
  332. elseif x > 4 and x < 12 and y == 48 then
  333. if rod < 9 then
  334. rod = 0
  335. else
  336. rod = rod - 10
  337. end
  338. elseif x > 13 and x < 20 and y == 48 then
  339. if rod < 1 then
  340. rod = 0
  341. else
  342. rod = rod - 1
  343. end
  344. elseif x > 27 and x < 34 and y == 48 then
  345. if rod > nbrrod - 1 then
  346. rod = nbrrod
  347. else
  348. rod = rod + 1
  349. end
  350. elseif x > 35 and x < 42 and y == 48 then
  351. if rod > nbrrod - 10 then
  352. rod = nbrrod
  353. else
  354. rod = rod + 10
  355. end
  356.  
  357. elseif x > 58 and x < 73 and y > 10 and y < 14 then
  358. br.setActive(true)
  359. start()
  360. elseif x > 58 and x < 73 and y > 14 and y < 18 then
  361. br.setActive(false)
  362. start()
  363. end
  364.  
  365. elseif boucle2 == 1 then
  366. if x > a+5 and x < a+18 and y > b+4 and y < b+8 then
  367. if x > a+11 and x < a+14 and y == b+5 then
  368. if lvl < 91 then
  369. lvl = lvl + 10
  370. else
  371. lvl = 100
  372. end
  373. elseif x > a+14 and x < a+18 and y == b+7 then
  374. if lvl < 100 then
  375. lvl = lvl + 1
  376. else
  377. lvl = 100
  378. end
  379. elseif x > a+5 and x < a+9 and y == b+5 then
  380. if lvl > 10 then
  381. lvl = lvl - 10
  382. else
  383. lvl = 0
  384. end
  385. elseif x > a+5 and x < a+9 and y == b+7 then
  386. if lvl > 1 then
  387. lvl = lvl - 1
  388. else
  389. lvl = 0
  390. end
  391. end
  392. gpu.set(a+14,b+3,string.format("%3s",lvl))
  393. elseif x > a+3 and x < a+11 and y > b+8 and y < b+12 then
  394. manualoff()
  395. elseif x > a+11 and x < a+19 and y > b+8 and y < b+12 then
  396. br.setControlRodLevel(rod-1,lvl)
  397. manualoff()
  398. end
  399. elseif boucle2 == 2 then
  400. if x > a+5 and x < a+17 and y > b+4 and y < b+8 then
  401. if x > a+13 and x < a+18 and y == b+5 then
  402. if val < 91 then
  403. val = val + 10
  404. else
  405. val = 100
  406. end
  407. elseif x > a+13 and x < a+18 and y == b+7 then
  408. if val < 100 then
  409. val = val + 1
  410. else
  411. val = 100
  412. end
  413. elseif x > a+5 and x < a+9 and y == b+5 then
  414. if val > -91 then
  415. val = val - 10
  416. else
  417. val = -100
  418. end
  419. elseif x > a+5 and x < a+9 and y == b+7 then
  420. if val > -100 then
  421. val = val - 1
  422. else
  423. val = -100
  424. end
  425. end
  426. gpu.set(a+14,b+3,string.format("%3s",val))
  427. elseif x > a+3 and x < a+11 and y > b+8 and y < b+12 then
  428. manualoff()
  429. val = 0
  430. elseif x > a+11 and x < a+19 and y > b+8 and y < b+12 then
  431. allrods(val)
  432. manualoff()
  433. val = 0
  434. end
  435. end
  436. end
  437.  
  438. local function onTimer(_,timer)
  439. waste()
  440. control(8,10)
  441. drawbars()
  442. return true
  443. end
  444.  
  445. event.listen("touch",onTouch)
  446. local timer = event.timer(0,onTimer,math.huge)
  447. event.pull("quit")
  448. event.cancel(timer)
  449. event.ignore("touch",onTouch)
  450. component.gpu.setResolution(160,50)
  451. term.clear()
Advertisement
Add Comment
Please, Sign In to add comment