Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local comp = require("component")
- local side = require("sides")
- local term = require("term")
- local os = require("os")
- local batteria = comp.ntm_energy_storage
- local reattore = comp.rbmk_console
- local red_funz = comp.proxy("e9456b26-31d7-484f-8f07-958b6075c0c7")
- local red_alar = comp.proxy("3d402465-3c61-4050-9abf-9144189821a0")
- -- bat_ora: livello della batteria attuale
- -- bat_max: livello massimo della batteria
- -- bat_old: livello della batteria vecchio
- -- bat_dif: differenza tra i livelli della batteria
- -- bat_vel: velocità media
- -- bat_per: percentuale della batteria
- local bat_ora, bat_max, bat_old, bat_dif, bat_vel, bat_per
- -- rea_cor: livello del refrigerante attuale
- -- rea_cmx: livello del refrigerante massimo
- -- rea_hor: livello del refrigerante caldo attuale
- -- rea_hmx: livello del refrigerante caldo massimo
- -- rea_cop: percentuale di refrigerante (core)
- -- rea_hop: percentuale di refrigerante (hull)
- -- rea_flx: flusso neutronico attuale nel reattore
- -- rea_per: percentuale di combustibile utilizzabile
- -- rea_cap: capacità del reatore (n. elementi combustibile)
- -- rea_con: livello barre di controllo
- -- rea_cal: livello barre di controllo (calcolato)
- -- rea_hec: calore del reattore (core) (°C)
- -- rea_heh: calore del reattore (hull) (°C)
- -- rea_hcx: calore del reattore (core max) (°C)
- -- rea_hhx: calore del reattore (hull max) (°C)
- -- rea_hpc: percentuale di calore (core)
- -- rea_hph: percentuale di colare (hull)
- -- rea_old: valore di combustibile precedente
- -- rea_vel: velocità di consumo del carburante
- -- nuke: tutti i dati grezzi del reattore raccolti in una tavola
- local rea_flx, rea_per, rea_cap, rea_con, rea_cal
- local rea_cor, rea_cmx, rea_hor, rea_hmx, rea_cop, rea_hop, rea_vel
- local rea_hec, rea_heh, rea_hpc, rea_hph, rea_hcx, rea_hhx
- local rea_old
- local nuke = {}
- -- controlla se pulire o meno lo schermo (era utile per i primi debug,
- -- ora è obsoleta, specialmente per gli schermi più piccoli)
- local mezzo = false
- -- purtroppo non si possono estrarre direttamente questi dati per rendere modulare il programma :/ (10-07-2024)
- rea_cmx = 10000
- rea_hmx = 100000
- rea_hhx = 1500.0
- local x, y, w, h
- local bk, bj, rk, rj
- local t_off = 1.0
- local auto = true
- local bc = false
- local t_op = 0.0
- local n = 10
- local v_bt = {}
- local v_rt = {}
- local SB, SR
- SB = 0.0
- -- allocazione degli spazi dei vettori
- for i=1,n,1 do
- v_bt[i] = 0.0
- v_rt[i] = 0.0
- end
- -- crea un divisore
- local function divisore(char)
- local W = term.window.width
- local X, Y = term.getCursor()
- for i=0, W-X, 1 do
- term.write(char)
- end
- print()
- return
- end
- -- prende i dati necessari dal reattore
- local function RBMK(reactor)
- local X = 0
- local Y = 0
- local colonna
- local totale = {}
- -- reset tavola
- totale.hullTemp = 0.0
- totale.coreSkinTemp = 0.0
- totale.coreMaxTemp = 0.0
- totale.enrichment = 0.0
- totale.flux = 0.0
- totale.level = 0.0
- totale.water = 0
- totale.steam = 0
- totale.fuel = 0
- totale.control = 0
- totale.boiler = 0
- totale.total = 0
- -- lettura del reattore
- -- asse Y (0-14)
- while (Y < 15) do
- X = 0
- -- asse X (0-14)
- while (X < 15) do
- colonna = reactor.getColumnData(X, Y)
- -- controlla che non ci siano spazi vuoti
- if (colonna ~= nil) then
- totale.hullTemp = totale.hullTemp + colonna.hullTemp
- -- contatori
- if (colonna.type == "FUEL") then
- -- carburante
- totale.coreSkinTemp = totale.coreSkinTemp + colonna.coreSkinTemp
- totale.coreMaxTemp = totale.coreMaxTemp + colonna.coreMaxTemp
- totale.enrichment = totale.enrichment + colonna.enrichment
- totale.flux = totale.flux + colonna.fluxSlow
- totale.fuel = totale.fuel + 1
- elseif (colonna.type == "CONTROL") then
- -- barre di controllo
- totale.level = totale.level + colonna.level
- totale.control = totale.control + 1
- elseif (colonna.type == "BOILER") then
- -- generatori di vapore (boiler)
- totale.water = totale.water + colonna.water
- totale.steam = totale.steam + colonna.steam
- totale.boiler = totale.boiler + 1
- end
- -- coontatore elementi del reattore
- totale.total = totale.total + 1
- end
- X = X + 1
- end
- Y = Y + 1
- end
- -- colcolo delle medie
- -- tutto
- totale.hullTemp = totale.hullTemp / totale.total
- -- carburante
- totale.coreSkinTemp = totale.coreSkinTemp / totale.fuel
- totale.coreMaxTemp = totale.coreMaxTemp / totale.fuel
- totale.enrichment = totale.enrichment / totale.fuel
- totale.flux = totale.flux / totale.fuel
- -- barre di controllo
- totale.level = totale.level / totale.control
- -- generatori di vapore (boiler)
- totale.water = totale.water / totale.boiler
- totale.steam = totale.steam / totale.boiler
- return totale
- end
- local function SCRAM()
- local t = os.clock()
- divisore("=")
- print("SEQUENZA DI SCRAM INIZIATA")
- reattore.setLevel(0.0)
- reattore.pressAZ5()
- print("SEQUENZA DI SCRAM FINITA")
- print("Tempo impiegato: " .. os.clock()-t)
- os.exit(1)
- end
- w = term.window.width
- h = term.window.height
- x, y = term.getCursor()
- -- se il cursore si trova a metà o più dell'altezza del monitor, lo schermo viene pulito ed il cursore resettato all'inizio
- if (y >= h/2 and mezzo) then
- term.clear()
- term.setCursor(1, 1)
- end
- x, y = term.getCursor() -- prende la posizione del cursore
- print("Statistiche Centrale")
- divisore("=")
- term.setCursor(1, y+3)
- divisore("-")
- print("> Batteria")
- term.setCursor(1, y+8)
- divisore("-")
- print("> Reattore")
- bat_old = 0
- rea_old = 0.0
- -- CICLO PRINCIPALE
- while (true) do
- -- calcoli
- t_op = os.clock() -- inizio calcolo del tempo di calcolo
- -- SETTORE INTERFACCE REDSTONE
- -- SCRAM
- if (red_funz.getInput(side.west) ~= 0) then
- SCRAM()
- end
- -- controllo della modalità auto
- if (red_funz.getInput(side.east) == 0) then
- auto = false
- else
- auto = true
- end
- -- controllo della disattivazione del reattore
- if (red_funz.getInput(side.north) ~= 0) then
- auto = false
- reattore.setLevel(0.0)
- end
- -- FINE SETTORE INTERFACCE REDSTONE
- bat_ora, bat_max = batteria.getEnergyInfo()
- bat_per = bat_ora / bat_max
- bat_dif = bat_ora - bat_old
- nuke = RBMK(reattore)
- rea_cap = nuke.fuel
- rea_per = 1.0 - nuke.enrichment
- rea_con = nuke.level
- rea_flx = nuke.flux
- rea_cor = nuke.water
- rea_hor = nuke.steam
- rea_cop = rea_cor / rea_cmx
- rea_hop = rea_hor / rea_hmx
- rea_hec = nuke.coreSkinTemp
- rea_hcx = nuke.coreMaxTemp
- rea_heh = nuke.hullTemp
- rea_hpc = rea_hec / rea_hcx
- rea_hph = rea_heh / rea_hhx
- -- calcolo velocità media
- bk = 0.0
- bj = 0
- rk = 0.0
- rj = 0
- for i=n,1,-1 do
- v_bt[i] = v_bt[i-1]
- v_rt[i] = v_rt[i-1]
- end
- v_bt[1] = math.abs(bat_old - bat_ora) / t_off
- v_rt[1] = math.abs(rea_old - rea_per) / t_off
- for i=1,n,1 do
- -- batteria
- if (v_bt[i] ~= 0.0) then
- bk = bk + v_bt[i]
- bj = bj + 1
- end
- -- reattore
- if (v_rt[i] ~= 0.0) then
- rk = rk + v_rt[i]
- rj = rj + 1
- end
- end
- if (bj <= 0) then bj = 1 end
- if (rj <= 0) then rj = 1 end
- bat_vel = bk / bj
- rea_vel = rk / rj
- SB = (bat_max - bat_ora) / (math.abs(bat_vel)+1.0)
- SR = rea_per / (math.abs(rea_vel)+1.0)
- -- stima livello delle barre di controllo (in funzione del livello della batteria e temperatura del core)
- rea_cal = 1.0 - (bat_per + ((rea_hpc >= rea_hph) and rea_hpc or rea_hph))^2.0 -- nelle parentesi interne viene scelto uno dei 2 valori, in quanto core e hull possono avere valori non concordanti
- if (auto) then
- reattore.setLevel(rea_cal)
- end
- -- ALLARMI
- -- livello refrigerante basso
- if (rea_cop < 0.2) then
- if (auto) then reattore.setLevel(rea_cal) end
- red_alar.setOutput(side.east, 15)
- elseif (rea_cop > 0.5) then
- red_alar.setOutput(side.east, 0)
- end
- -- temperatura critica
- if (rea_hpc > 0.8 or rea_hph > 0.8) then
- red_alar.setOutput(side.west, 15)
- if (auto) then SCRAM() end -- Disattivazione automatica
- elseif (rea_hpc < 0.5 and rea_hph < 0.5) then
- red_alar.setOutput(side.west, 0)
- end
- -- FINE ALLARMI
- -- stampa
- term.setCursor(w-16, y)
- print(os.date())
- term.setCursor(1, y+2)
- print(("Battito: %1s | TDC: %7.5f s | Auto: %3s | Attività: %3s"):format((bc and "*" or " "), os.clock()-t_op, (auto and "ON" or "OFF"), (rea_con < 100 and "ON" or "OFF")))
- term.setCursor(1, y+5)
- print(("Carica: %6.2f%s "):format(bat_per*100.0, "%"))
- print(("Velocità: %1s%6.2f MHE/s "):format((bat_dif >= 0 and "+" or "-"), math.abs(bat_dif/1000000.0)))
- print(("Tempo di %9s: %2d %2d:%2d:%2d "):format((bat_dif >= 0 and "ricarica" or "discarica"), math.floor(SB/86400), math.floor((SB/3600)%24), math.floor((SB/60)%60), math.floor(SB%60)))
- term.setCursor(1, y+9)
- print(("Combustibile: %3d -> %6.2f%s"):format(rea_cap, (1.0-rea_per)*100.0, "%"))
- print(("Vel. Esaurimento: %6.2f Dur/s | %2d %2d:%2d:%2d "):format(rea_vel, math.floor(SR/86400), math.floor((SR/3600)%24), math.floor((SR/60)%60), math.floor(SR%60)))
- print(("Flusso Neutronico: %.2f "):format(rea_flx))
- print(("Livello Barre di Controllo (Stimato): %7.3f%s"):format((1.0-rea_cal)*100.0, "%"))
- print(("Livello Barre di Controllo (Attuale): %7.3f%s"):format((1.0-rea_con)*100.0, "%"))
- print(("Calore Core: %6.2f%s (%7.2f / %7.2f °C) "):format(rea_hpc*100.0, "%", rea_hec, rea_hcx))
- print(("Calore Hull: %6.2f%s (%7.2f / %7.2f °C) "):format(rea_hph*100.0, "%", rea_heh, rea_hhx))
- print(("Refrigerante Freddo: %6.2f%s (%6.0f / %6.0f mB) "):format(rea_cop*100.0, "%", rea_cor, rea_cmx))
- print(("Refrigerante Caldo: %6.2f%s (%6.0f / %6.0f mB) "):format(rea_hop*100.0, "%", rea_hor, rea_hmx))
- -- calcoli finali
- bat_old = bat_ora
- rea_old = rea_per
- bc = not bc
- os.sleep(t_off-(os.clock()-t_op))
- end
Advertisement
Add Comment
Please, Sign In to add comment