Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local term = require("term")
- local component = require("component")
- local computer = require("computer")
- local math = require("math")
- local event = require("event")
- local string = require("string")
- local unicode = require("unicode")
- local os = require("os")
- local fs = require('filesystem')
- local gpu = component.gpu
- gpu.setResolution(100,50)
- br = component.getPrimary("br_reactor")
- local boucle2 = 0
- local a = 80
- local b = 1
- local lvl
- local val = 0
- local rod = 1
- local rodmax = br.getNumberOfControlRods()
- local maxcon = rodmax*100
- local termset = 0
- local stco=false
- local kp=1
- local ki=0.1
- local int=0
- local function claim(x,a,b)
- if x<a then
- return a
- end
- if x>b then
- return b
- end
- return x
- end
- local function rodcon(num,rod)
- local x= (num-num%100)/100
- local y=num%100
- if rod<x then
- return 100
- elseif rod>x then
- return 0
- elseif rod==x then
- return y
- end
- end
- local function rodcontrol()
- local err = termset-br.getCasingTemperature()
- local pid_p = err*kp
- local pid_i = int*ki
- local pid = claim((pid_p+pid_i),0,maxcon)
- int=claim((int+err),0,maxcon/ki)
- pid=math.floor(pid)
- pid= ( (pid - 0) / (maxcon - 0) ) * (0 - maxcon) + maxcon
- for i=1,maxcon,1 do
- br.setControlRodLevel(i,rodcon(pid,i))
- end
- gpu.set(22,6, string.format("%10d", pid))
- gpu.set(22,11,string.format("%10d",int))
- end
- local function setColor(bg,fg)
- gpu.setBackground(bg)
- gpu.setForeground(fg)
- end
- local function loadbar(x,y,width,cur,text,bg,fg)
- local raw = " " .. text ..string.rep(" ", width - unicode.len(text) - 2) .. " "
- local oldbg = gpu.setBackground(bg)
- local oldfg = gpu.setForeground(fg)
- gpu.set(x,y,unicode.sub(raw,1,cur))
- gpu.setBackground(oldbg)
- gpu.setForeground(oldfg)
- gpu.set(x+cur,y,unicode.sub(raw,cur+1,width))
- end
- local function hexa(dec)
- local B,K,OUT,I,D = 16,"0123456789ABCDEF","",0
- if dec <= 0 then
- OUT = "00"
- elseif dec > 0 and dec < 16 then
- D = dec + 1
- OUT = "0"..string.sub(K,D,D)
- elseif dec > 16 and dec < 256 then
- V1 = math.modf(dec/B)+1
- V2 = dec-V1*16
- OUT = string.sub(K,V1,V1)..string.sub(K,V2,V2)
- elseif dec >= 255 then
- OUT = "FF"
- end
- return OUT
- end
- local function round(num, dec)
- local mult = 10 ^ (dec or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- local function bargraph(x,y,length,am,cap,na,col,colpol)
- local amount = am
- local capacity = cap
- local pct = amount / capacity
- local cur = math.floor(pct * length)
- local color = col
- local color2 = colpol
- local name = na
- local textfrac = string.format("%s / %s", amount, capacity)
- local textpct = string.format("%.02f%%", pct*100)
- local text = textfrac .. string.rep(" ", length - string.len(textfrac) - string.len(textpct) - 6) .. " " .. textpct .. " "
- local text1 = " Уровень заполнения : ("..name..")"
- loadbar(x,y,length,cur,text1,color,color2)
- loadbar(x,y+1,length,cur,text,color,color2)
- end
- function drawbars()
- amFuel = br.getFuelAmount()
- capFuel = br.getFuelAmountMax()
- naFuel = "ТОПЛИВО - Yellorium"
- colFuel = 0xFFFF00
- colpolFuel = 0x0000FF
- bargraph(2,22,98,amFuel,capFuel,naFuel,colFuel,colpolFuel)
- amWaste = br.getWasteAmount()
- capWaste = 64000
- naWaste = "ОТХОДЫ - Cyanite"
- colWaste = 0x00FFFF
- colpolWaste = 0xFF00FF
- bargraph(2,25,98,amWaste,capWaste,naWaste,colWaste,colpolWaste)
- amSteam = br.getHotFluidAmount()
- capSteam = br.getHotFluidAmountMax()
- naSteam = "ПАР"
- colSteam = 0x8F8F8F
- colpolSteam = 0xFFFF00
- bargraph(2,28,98,amSteam,capSteam,naSteam,colSteam,colpolSteam)
- amWater = br.getCoolantAmount()
- capWater = br.getCoolantAmountMax()
- naWater = "ВОДА"
- colWater = 0x71b6cb
- colpolWater = 0x0000FF
- bargraph(2,31,98,amWater,capWater,naWater,colWater,colpolWater)
- consot = br.getFuelConsumedLastTick()
- consos = consot * 20
- consoh = consos * 3.6
- consoj = consoh * 24
- 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")
- Tcore = br.getCasingTemperature()
- Tfuel = br.getFuelTemperature()
- Reactivity = br.getFuelReactivity()
- Prod = br.getHotFluidProducedLastTick()
- gpu.set(35,38,string.format("% 4.2f",Tcore))
- gpu.set(35,40,string.format("% 4.2f",Tfuel))
- gpu.set(35,42,string.format("% 4.2f",Reactivity))
- gpu.set(35,44,string.format("% 4.2f",Prod))
- if stco then
- rodcontrol()
- end
- end
- local function waste()
- local waste = br.getWasteAmount()
- if waste > 48000 then
- br.doEjectWaste()
- end
- end
- local function marche(x,y)
- gpu.set(x,y," ")
- gpu.set(x,y+1," ВКЛЮЧИТЬ ")
- gpu.set(x,y+2," ")
- end
- local function arret(x,y)
- gpu.set(x,y," ")
- gpu.set(x,y+1," ВЫКЛЮЧИТЬ ")
- gpu.set(x,y+2," ")
- end
- local function start()
- local ON = br.getActive()
- if ON == true then
- setColor(0x00FF00,0x0)
- marche(60,11)
- setColor(0x0,0xFF0000)
- arret(60,15)
- setColor(0x0,0xFFFFFF)
- elseif ON == false then
- setColor(0x0,0x00FF00)
- marche(60,11)
- setColor(0xFF0000,0xFFFFFF)
- arret(60,15)
- setColor(0x0,0xFFFFFF)
- end
- end
- local function scon()
- if stco == true then
- setColor(0x00FF00,0x0)
- marche(5,46)
- setColor(0x0,0xFF0000)
- arret(27,46)
- setColor(0x0,0xFFFFFF)
- elseif stco == false then
- setColor(0x0,0x00FF00)
- marche(5,46)
- setColor(0xFF0000,0xFFFFFF)
- arret(27,46)
- setColor(0x0,0xFFFFFF)
- end
- end
- term.clear()
- gpu.set(1,1,"╔══════════════════════════════════════════════════════════════════════════════════════════════════╗")
- gpu.set(1,2,"║ ║")
- gpu.set(1,3,"║ ███████████████████████████████████████████████ ███████████████████ ║")
- gpu.set(1,4,"║ ██ установка температуры ██ █ Ручной контроль █ ║")
- gpu.set(1,5,"║ ██ ██ █ всех █ ║")
- gpu.set(1,6,"║ ██ ██ █ стержней █ ║")
- gpu.set(1,7,"║ ██ +100 -100 ██ █ █ ║")
- gpu.set(1,8,"║ ██ +10 -10 ██ ███████████████████ ║")
- gpu.set(1,9,"║ ██ +1 -1 ██ ║")
- gpu.set(1,10,"║ ██ ██ ║")
- gpu.set(1,11,"║ ██ ██ █████████████ ║")
- gpu.set(1,12,"║ ██ ██ █ВКЛЮЧИТЬ ██ ║")
- gpu.set(1,13,"║ ██ ██ █████████████ ║")
- gpu.set(1,14,"║ ██ ██ ║")
- gpu.set(1,15,"║ ██ ██ █████████████ ║")
- gpu.set(1,16,"║ ██ ██ █ВЫКЛЮЧИТЬ ██ ║")
- gpu.set(1,17,"║ ███████████████████████████████████████████████ █████████████ ║")
- gpu.set(1,18,"║ ║")
- gpu.set(1,19,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
- gpu.set(1,20,"║ ║")
- gpu.set(1,21,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
- gpu.set(1,22,"║ ║")
- gpu.set(1,23,"║ ║")
- gpu.set(1,24,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
- gpu.set(1,25,"║ ║")
- gpu.set(1,26,"║ ║")
- gpu.set(1,27,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
- gpu.set(1,28,"║ ║")
- gpu.set(1,29,"║ ║")
- gpu.set(1,30,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
- gpu.set(1,31,"║ ║")
- gpu.set(1,32,"║ ║")
- gpu.set(1,33,"╠════════════════════════════════════════════════╦═════════════════════════════════════════════════╣")
- gpu.set(1,34,"║ РАСХОД ТОПЛИВА ║ MiliBukket/second => mb/s Bukket/Hour => b/h ║")
- gpu.set(1,35,"║ ║ MiliBukket/tick => mb/t Bukket/Day => b/d ║")
- gpu.set(1,36,"╠════════════════════════════════════════════════╩══════════════════════╦══════════════════════════╣")
- gpu.set(1,37,"║ ║ ║")
- gpu.set(1,38,"║ ТЕМПЕРАТУРА РЕАКТОРА : °C ║ ║")
- gpu.set(1,39,"║ ║ ██████████████████ ║")
- gpu.set(1,40,"║ ТЕМПЕРАТУРА ТОПЛИВА : °C ║ ██ ИЗВЛЕЧЬ ██ ║")
- gpu.set(1,41,"║ ║ ██ CYANITE ██ ║")
- gpu.set(1,42,"║ РАДИОАКТИВНОСТЬ ТОПЛИВА : % ║ ██████████████████ ║")
- gpu.set(1,43,"║ ║ ║")
- gpu.set(1,44,"║ ПЕРЕРАБОТКА ПАРА : mb/t ║ ██████████████████ ║")
- gpu.set(1,45,"╠═══════════════════════════════════════════════════════════════════════╣ ██ ИЗВЛЕЧЬ ██ ║")
- gpu.set(1,46,"║ █████████████ █████████████ АВТО ТКМПЕРАТУРА ║ ██ YELLORIUM ██ ║")
- gpu.set(1,47,"║ █ВКЛЮЧИТЬ ██ █ВЫКЛЮЧИТЬ ██ ║ ██████████████████ ║")
- gpu.set(1,48,"║ █████████████ █████████████ ║ ║")
- gpu.set(1,49,"║ ║ ║")
- gpu.set(1,50,"╚═══════════════════════════════════════════════════════════════════════╩══════════════════════════╝")
- start()
- scon()
- local function onTouch(event,adress,x,y,clic,pseudo)
- local tclic
- if clic == 0 then
- tclic = "НАЖИТО ЛКМ"
- elseif clic == 1 then
- tclic = "НАЖИТО ПКМ"
- else
- tclic = "НАЖИТО НЕИЗВЕСТНО"
- end
- gpu.set(6,20," "..tclic.." . ИГРОКОМ: "..pseudo.." ( X : "..string.format("% 3s",x).." Y: "..string.format("% 3s",y)..")")
- if x==1 and y==1 then
- computer.pushSignal("quit")
- term.setCursor(1,1)
- return false
- elseif x > 77 and x < 96 and y > 38 and y < 43 then
- br.doEjectWaste()
- elseif x > 77 and x < 96 and y > 43 and y < 48 then
- br.doEjectFuel()
- elseif x > 58 and x < 73 and y > 10 and y < 14 then
- br.setActive(true)
- start()
- elseif x >= 5 and x <= 17 and y >= 46 and y <= 48 then
- stco=true
- scon()
- elseif x >= 27 and x <= 39 and y >= 46 and y <= 48 then
- stco=false
- scon()
- elseif x >= 58 and x <= 73 and y >= 14 and y <= 18 then
- br.setActive(false)
- start()
- gpu.set(22,5, string.format("%10d", termset))
- elseif x >= 9 and x <= 13 and y == 9 then
- if termset >= 2999 then
- termset = 3000
- else
- termset = termset + 1
- end
- gpu.set(22,5, string.format("%10d", termset))
- elseif x >= 9 and x <= 13 and y == 8 then
- if termset >= 2990 then
- termset = 3000
- else
- termset = termset + 10
- end
- gpu.set(22,5, string.format("%10d", termset))
- elseif x >=9 and x <= 13 and y == 7 then
- if termset >= 2900 then
- termset = 3000
- else
- termset = termset + 100
- end
- gpu.set(22,5, string.format("%10d", termset))
- elseif x >= 38 and x <= 43 and y == 9 then
- if termset <= 1 then
- termset = 0
- else
- termset = termset - 1
- end
- gpu.set(22,5, string.format("%10d", termset))
- elseif x >= 38 and x <= 43 and y == 8 then
- if termset <= 10 then
- termset = 0
- else
- termset = termset - 10
- end
- gpu.set(22,5, string.format("%10d", termset))
- elseif x >= 38 and x <= 43 and y == 7 then
- if termset <= 100 then
- termset = 0
- else
- termset = termset - 100
- end
- gpu.set(22,5, string.format("%10d", termset))
- end
- end
- local function onTimer(_,timer)
- waste()
- drawbars()
- return true
- end
- event.listen("touch",onTouch)
- local timer = event.timer(0,onTimer,math.huge)
- event.pull("quit")
- event.cancel(timer)
- event.ignore("touch",onTouch)
- component.gpu.setResolution(160,50)
- term.clear()
Add Comment
Please, Sign In to add comment