Advertisement
Fredyman_95

Simple controler for fusion reactor

Apr 16th, 2022
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.49 KB | None | 0 0
  1. local term = require("term")
  2. local computer = require("computer")
  3. local sides = require("sides")
  4. local component = require("component")
  5. local gpu = component.gpu
  6.  
  7. --System requirements check
  8.  
  9. if gpu.maxResolution() < 100 then
  10.     io.stderr:write("Tier 3 GPU and Screen Required")
  11.     computer.beep()
  12.     os.sleep(0.2)
  13.     computer.beep()
  14.     os.exit(1)
  15. end
  16.  
  17. if not component.isAvailable("reactor_logic_adapter") then
  18.     io.stderr:write("No Reactor Connected.")
  19.     computer.beep()
  20.     os.sleep(0.2)
  21.     computer.beep()
  22.     os.sleep(0.2)
  23.     computer.beep()
  24.     os.exit(1)
  25. end
  26.  
  27. if not component.isAvailable("redstone") then
  28.     io.stderr:write("No RedstoneIO Connected.")
  29.     computer.beep()
  30.     os.sleep(0.2)
  31.     computer.beep()
  32.     os.sleep(0.2)
  33.     computer.beep()
  34.     os.sleep(0.2)
  35.     computer.beep()
  36.     os.exit(1)
  37. end
  38.  
  39.  
  40. local reactor = component.reactor_logic_adapter
  41. local screen = component.screen
  42. local rs = component.redstone
  43.  
  44.  
  45. local whiteColor = 0xFFFFFF
  46. local greenColor = 0x00B600
  47. local redColor = 0xFF0000
  48. local yellowColor = 0xFFDB00
  49. local blueColor = 0x006DFF
  50.  
  51. gpu.setResolution(46, 19)
  52.  
  53. -- User settings --
  54.  
  55. local insertLevel = 600       -- set min level for inserting fuel                     // Default: 600
  56. local critLevel = 400         -- below this level computer start beeping              // Default: 400
  57. local rate = 4                -- set to desired value of ignition level               // Default: 4
  58. local RSTri = sides.north     -- rs signal for start prodution (insert) of tritium    // Default: sides.north
  59. local RSDeu = sides.south     -- rs signal for start prodution (insert) of deuterium  // Default: sides.south
  60. local RSAL = sides.top        -- rs signal for external alarm                         // Default: sides.top
  61. local language = "EN"           -- EN = english, DE = Deutsch, CZ = Cesky               // Default: EN    
  62. -- End if User settings --
  63.  
  64.  
  65. --- Language loading --
  66.  
  67. if language == "EN" then
  68.     gasDeu = "Deuterium:"
  69.     gasTri = "Tritium:"
  70.     TempR = "Reactor Temperature:"
  71.     TempP = "Plasma Temperature:"
  72.     cRate = "Current rate:"
  73.     rStatus = "Status"
  74.     iDeu = "Deuterium injection:"
  75.     iTri = "Tritium injection:"
  76.     iY = "True"
  77.     iN = "False"
  78.     bStatus = "Energy buffer:"
  79.     warningTri1 = "    Warning low Tritium, inserting fuel   "
  80.     warningDeu1 = "   Warning low Deuterium, inserting fuel  "
  81.     ok = "             Reactor is Stable            "
  82.     rOFF = "               Reactor is OFF            "
  83.  
  84. elseif language == "DE" then
  85.     gasDeu = "Deuterium:"
  86.     gasTri = "Tritium:"
  87.     TempR = "Reaktortemperatur:"
  88.     TempP = "Plasmatemperatur:"
  89.     cRate = "Derzeitige Rate:"
  90.     rStatus = "Statusbericht"
  91.     iDeu = "Deuteriuminjektion:"
  92.     iTri = "Tritiuminjektion:"
  93.     iY = "An"
  94.     iN = "Aus"
  95.     bStatus = "Energiespeicher:"
  96.     warningTri1 = "     Warnung wenig Tritium - einfüllen"
  97.     warningDeu1 = "   Warnung wenig Deuterium - einfüllen"
  98.     ok = "             Reaktor ist stabil          "
  99.     rOFF = "               Außer Betrieb           "
  100.  
  101. elseif language == "CZ" then
  102.     gasDeu = "Deuterium:"
  103.     gasTri = "Tritium:"
  104.     TempR = "Teploměr - Reaktor:"
  105.     TempP = "Teploměr - Plasma:"
  106.     cRate = "Vstřikování:"
  107.     rStatus = "Status"
  108.     iDeu = "Doplnění - Deuteria:"
  109.     iTri = "Doplnění - Tritia:"
  110.     iY = "Ano"
  111.     iN = "Ne"
  112.     bStatus = "Zásoba energie:"
  113.     warningTri1 = "      Varování málo Tritia, doplňuji   "
  114.     warningDeu1 = "     Varování málo Deuteria, doplňuji  "
  115.     ok = "                 V pořádku            "
  116.     rOFF = "                Mimo provoz            "
  117. else
  118.     io.stderr:write("Wrong name of language packet or your language is not supported!")
  119.     computer.beep()
  120.     computer.beep()
  121.     os.exit(1)
  122. end
  123.  
  124. -- end of Langoage loading
  125.  
  126. -- Functions --
  127.  
  128.  local function colorTextGYR(rule1, rule2, rule3, posX, posY, text)
  129.     if (rule1) then gpu.setForeground(greenColor) elseif(rule2) then gpu.setForeground(yellowColor) elseif (rule3) then gpu.setForeground(redColor) end
  130.           term.setCursor(posX, posY)
  131.           print(text .." ")
  132.           gpu.setForeground(whiteColor)
  133.  end
  134.  
  135.  local function colorTextGR(rule, PosX, PosY, textT, textF)
  136.     if (rule) then
  137.         gpu.setForeground(greenColor)
  138.         textR = textT
  139.      else
  140.         gpu.setForeground(redColor)
  141.         textR = textF
  142.      end
  143.           term.setCursor(PosX, PosY)
  144.           print(textR .." ")
  145.           gpu.setForeground(whiteColor)
  146.  end
  147.  
  148. local function round(num1, numDecimalPlaces)
  149.         if numDecimalPlaces and numDecimalPlaces>0 then
  150.            local mult = 10^numDecimalPlaces
  151.            return math.floor(num1 * mult + 0.5) / mult
  152.         end
  153.          return math.floor(num1 + 0.5)
  154.  end
  155.  
  156. local function convert(source, posX1, posY1, devi, multi, unit)
  157.     var1 = source / devi
  158.         if multi == 0 then multi = 1 end
  159.     var1 = var1 * multi
  160.     term.setCursor(posX1, posY1)
  161.     print(round(var1, 2) ..unit)
  162.  end
  163.  
  164.  local function Status(tx1, ty1, mes0, mes1, mes2, mes3)
  165.     if (reactor.isIgnited() == false) then
  166.         term.setCursor(3, 11)
  167.         print(mes0)
  168.     else
  169.         if(reactor.getDeuterium() > insertLevel and reactor.getTritium() > insertLevel) then
  170.             reactor.setInjectionRate(rate)
  171.             term.setCursor(tx1, ty1)
  172.             gpu.setForeground(greenColor)
  173.             print(mes1)
  174.             gpu.setForeground(whiteColor)
  175.             rs.setOutput(RSAL, 0)
  176.         end    
  177.         if(reactor.getDeuterium() < insertLevel) then
  178.             reactor.setInjectionRate(2)
  179.             rs.setOutput(RSDeu, 15)
  180.             term.setCursor(tx1, ty1)
  181.             gpu.setForeground(yellowColor)
  182.             print(mes2)
  183.             gpu.setForeground(whiteColor)
  184.             rs.setOutput(RSAL, 15)
  185.         end
  186.         if(reactor.getTritium() < insertLevel) then
  187.             reactor.setInjectionRate(2)
  188.             rs.setOutput(RSTri, 15)
  189.             term.setCursor(tx1, ty1)
  190.             gpu.setForeground(yellowColor)
  191.             print(mes3)
  192.             gpu.setForeground(whiteColor)
  193.             rs.setOutput(RSAL, 15)
  194.         end
  195.     end
  196. end
  197.  
  198.  local function RSoff()
  199.     if(reactor.getDeuterium() > 999) then
  200.         rs.setOutput(RSDeu, 0)
  201.     end
  202.     if(reactor.getTritium() > 999) then
  203.         rs.setOutput(RSTri, 0)
  204.     end
  205.  end
  206.  
  207.  
  208.  local function infoScreen()
  209.         term.setCursor(34, 19)
  210.         print("®Fredyman_95")
  211.         gpu.setForeground(whiteColor)
  212.         term.setCursor(2, 2)
  213.         print(gasDeu)
  214.         term.setCursor(2, 3)
  215.         print(gasTri)
  216.         term.setCursor(2,4)
  217.         print(TempR)
  218.         term.setCursor(2,5)
  219.         print(TempP)
  220.         term.setCursor(2,6)
  221.         print(cRate)
  222.         if language == "DE" then term.setCursor(18,9) else
  223.         term.setCursor(21,9) end
  224.         print(rStatus)
  225.         term.setCursor(2,10)
  226.         print("┌──────────────────────────────────────────┐")
  227.         term.setCursor(2, 11)
  228.         print("│")
  229.         term.setCursor(45, 11)
  230.         print("│")
  231.         term.setCursor(2, 12)
  232.         print("└──────────────────────────────────────────┘")
  233.         term.setCursor(2,14)
  234.         print(iDeu)
  235.         term.setCursor(2,15)
  236.         print(iTri)
  237.         term.setCursor(2,17)
  238.         print(bStatus)
  239.     end
  240.  
  241. local function fillInfo()
  242.     colorTextGYR(reactor.getDeuterium() > 800, reactor.getDeuterium() > insertLevel, reactor.getDeuterium() < critLevel, 13, 2, reactor.getDeuterium())
  243.     colorTextGYR(reactor.getTritium() > 800, reactor.getTritium() > insertLevel, reactor.getTritium() < critLevel, 11, 3, reactor.getTritium())
  244.     convert(reactor.getCaseHeat(), 23, 4, 1000000, 1, " °MC        ")
  245.     convert(reactor.getPlasmaHeat(), 22, 5, 1000000, 1, " °MC        ")
  246.     term.setCursor(16,6)
  247.        if language == "DE" then term.setCursor(19,6) end
  248.     print(reactor.getInjectionRate())
  249.     Status(3, 11, rOFF, ok, warningDeu1, warningTri1)
  250.     RSoff()
  251.     colorTextGR(rs.getOutput(RSDeu) == 15, 23, 14, iY, iN)
  252.     colorTextGR(rs.getOutput(RSTri) == 15, 21, 15, iY, iN)
  253.     if language == "DE" then convert(reactor.getEnergy(), 19, 17, 10000000, 4, " / 400 MRF         ") else
  254.     convert(reactor.getEnergy(), 18, 17, 10000000, 4, " / 400 MRF         ")end
  255. end
  256.  
  257. term.clear()
  258. infoScreen()
  259. while true do
  260. fillInfo()
  261. os.sleep()
  262. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement