Advertisement
davedumas0

bigReactorControl.lua

Dec 9th, 2022 (edited)
1,018
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 33.41 KB | Gaming | 0 0
  1. -----local variables------
  2. --------------------------
  3. --======================--
  4. --------------------------
  5. -----local variables------
  6.  
  7.  
  8. local os = require("os")
  9. local computer = require("computer")
  10. local term = require("term")
  11. local filesystem = require("filesystem")
  12. local component = require("component")
  13. local keyboard = require("keyboard")
  14. local event = require("event")
  15. local gpu = component.gpu
  16.  
  17. local event = require("event")
  18.  
  19. local reactor = component.br_reactor
  20.  
  21. local energyStats = reactor.getEnergyStats()
  22. local coolantStatus = reactor.getCoolantFluidStats()
  23.  
  24. -----local variables------
  25. --------------------------
  26. --======================--
  27. --------------------------
  28. -----local variables------
  29.  
  30.  
  31.  
  32.  
  33.  
  34. -------functions----------
  35. --------------------------
  36. --======================--
  37. --------------------------
  38. -------functions----------
  39.  
  40.  
  41. -------UI functions-------
  42. --------------------------
  43. --======================--
  44. --------------------------
  45. -------UI functions-------
  46.  
  47. function resetBgColor ()
  48.   gpu.setBackground(colors_black)
  49. end
  50.  
  51. function resetFgColor ()
  52.   gpu.setForeground(colors_white)
  53. end
  54.  
  55. function resetBgColorANDresetFgColor()
  56.   resetFgColor()
  57.   resetBgColor()
  58. end
  59.  
  60. function setBgColor (color)
  61.   gpu.setBackground(color)
  62. end
  63.  
  64. function setFgColor (color)
  65.   gpu.setForeground(color)
  66. end
  67.  
  68. function renderLine(posX, posY, sizeX, sizeY)
  69.   gpu.fill(posX, posY, sizeX, sizeY, " ")
  70. end
  71.  
  72.  
  73. function setCursorPos (posX, posY)
  74.   term.setCursor(posX, posY)
  75. end
  76.  
  77. function renderText(text)
  78.   term.write(text)
  79. end
  80.  
  81. function drawLine(posX, posY, length, highth, line_color)
  82.   local tX, tY = term.getCursor()
  83.   setBgColor (line_color)
  84.   renderLine(posX, posY, length, highth)
  85.   resetBgColor ()
  86.   setCursorPos (tX, tY)
  87. end
  88.  
  89. function drawText(posX, posY, text, textColor, BgColor)
  90.   local tX, tY = term.getCursor()
  91. setCursorPos(posX, posY)
  92. setFgColor(textColor)
  93. setBgColor(BgColor)
  94. renderText(tostring(text))
  95.   setCursorPos (tX, tY)
  96. end
  97.  
  98. function draw_ProgressBar(orientation, posX, posY, sizeX, sizeY,  maxVAlue, value, bgColor, barColor, showValue)
  99.   if orientation == 1 then
  100.    
  101.   local a =  sizeX*(value / maxVAlue)
  102.   local aa = value.."/"..maxVAlue
  103.   local aaa = string.len(aa)
  104.     if showValue == true then
  105.       setBgColor(bgColor)
  106.        renderLine(posX,  posY,  sizeX,  sizeY)
  107.       setBgColor(barColor)
  108.        renderLine(posX,  posY,  math.floor(a),  sizeY)
  109.       setCursorPos( posX+(sizeX/2)-aaa/2,  posY+sizeY+1)
  110.       setBgColor(reactorPowerInfoPanelBgColor)
  111.       setFgColor(colors_lime)
  112.        renderText( aa)
  113.     else
  114.       setBgColor(bgColor)
  115.       renderLine(posX,  posY,  sizeX,  sizeY)
  116.      setBgColor(barColor)
  117.       renderLine(posX,  posY,  math.floor(a),  sizeY)
  118.     end  
  119.   else
  120.     local a =  sizeY*(value / maxVAlue)
  121.     local aa = value.."/"..maxVAlue
  122.     local aaa = string.len(aa)
  123.     if showValue == true then  
  124.       setBgColor(bgColor)
  125.        renderLine(posX,  posY,  sizeX,  sizeY)
  126.       setBgColor(barColor)
  127.        renderLine(posX,  posY+sizeY-math.floor(a), sizeX, math.floor(a))
  128.       setCursorPos( posX+(sizeX/2)-aaa/2,  posY+sizeY+1)
  129.       setBgColor(reactorPowerInfoPanelBgColor)
  130.       setFgColor(colors_lime)
  131.        renderText( aa)
  132.     else
  133.       setBgColor(bgColor)
  134.       renderLine(posX,  posY,  sizeX,  sizeY)
  135.       setBgColor(barColor)
  136.       renderLine(posX,  posY+sizeY-math.floor(a), sizeX, math.floor(a))
  137.     end
  138.   end
  139. end
  140.  
  141.  
  142. function draw_controlRod(posX, posY, rodValue, bGColor)
  143.   local rodCasingX = posX+1
  144.   local rodCasingY = posY+24/2+1
  145.   local fuelColor = colors_yellow
  146.   local rodColor = colors_cyan
  147.   local rodCasingColor = colors_silver
  148.   local displayValue = rodValue / 10
  149.   if rodValue < 10 then
  150.     setBgColor(bGColor)
  151.     renderLine(rodCasingX+2,  posY-10,  1,  10)
  152.     setBgColor(rodCasingColor)
  153.     renderLine(rodCasingX+1,  posY+1,  3,  10)
  154.     setBgColor(fuelColor)
  155.     renderLine(rodCasingX+2,  posY+1,  1,  10)
  156.     setBgColor(rodColor)
  157.     renderLine(rodCasingX+2,  posY-11,  1,  10)
  158.   else
  159.     setBgColor(bGColor)
  160.     renderLine(rodCasingX+2,  posY-10,  1,  10)
  161.     setBgColor(rodCasingColor)
  162.     renderLine(rodCasingX+1,  posY+1,  3,  10)
  163.     setBgColor(fuelColor)
  164.     renderLine(rodCasingX+2,  posY+1,  1,  10)
  165.     setBgColor(rodColor)
  166.     renderLine(rodCasingX+2,  posY-9+(displayValue),  1,  10)
  167.   end
  168. end
  169.  
  170.  
  171.  
  172.  
  173. function draw_ReactorPanel()
  174.  setBgColor(reactorPanelColor)
  175. renderLine(reactorPanelPosX, reactorPanelPosY,  19,  12)
  176.  
  177. draw_controlRod(reactorPanelPosX, reactorPanelPosY, 0, colors_black)
  178. setCursorPos( reactorPanelPosX+3,  reactorPanelPosY+12)
  179. setBgColor(colors_black)
  180. setFgColor(reactorPowerInfoPanelBgColor)
  181. renderText("1")
  182. draw_controlRod(reactorPanelPosX+4, reactorPanelPosY, 0, colors_black)
  183. setCursorPos( reactorPanelPosX+7,  reactorPanelPosY+12)
  184. setBgColor(colors_black)
  185. setFgColor(reactorPowerInfoPanelBgColor)
  186. renderText("2")
  187.  
  188. draw_controlRod(reactorPanelPosX+8, reactorPanelPosY, 0, colors_black)
  189. setCursorPos( reactorPanelPosX+11,  reactorPanelPosY+12)
  190. setBgColor(colors_black)
  191. setFgColor(reactorPowerInfoPanelBgColor)
  192. renderText("3")
  193. draw_controlRod(reactorPanelPosX+12, reactorPanelPosY, 0, colors_black)
  194. setCursorPos( reactorPanelPosX+15,  reactorPanelPosY+12)
  195. setBgColor(colors_black)
  196. setFgColor(reactorPowerInfoPanelBgColor)
  197. renderText("4")
  198.  drawButtons(table_RactorPanelButtons)
  199. end
  200.  
  201.  
  202. function newButton(label, posX, posY, labelColor, buttonColor, showLabel, sizeOveride, sizeX, sizeY, func, funcDATA, buttonTable)
  203.   button = {}
  204.   button.label = label
  205.   button.posX = posX
  206.   button.posY = posY
  207.   button.labelColor = labelColor
  208.   button.buttonColor = buttonColor
  209.   button.showLabel = showLabel
  210.   button.sizeOveride = sizeOveride
  211.   button.sizeX = sizeX
  212.   button.sizeY = sizeY
  213.   button.func = func
  214.   button.funcDATA = funcDATA
  215. table.insert(buttonTable, button)
  216. end
  217.  
  218. function drawButtons(buttonTable)
  219.  
  220.   for i = 1, #buttonTable do
  221.     if buttonTable[i].sizeOveride then
  222.       drawLine(buttonTable[i].posX, buttonTable[i].posY, buttonTable[i].sizeX, buttonTable[i].sizeY, buttonTable[i].buttonColor)
  223.        if buttonTable[i].showLabel then
  224.          
  225.          drawText(buttonTable[i].posX +buttonTable[i].sizeX/2-string.len(buttonTable[i].label)/2, buttonTable[i].posY+ buttonTable[i].sizeY/2, buttonTable[i].label, buttonTable[i].labelColor, buttonTable[i].buttonColor)      
  226.        end
  227.      else
  228.       drawLine(buttonTable[i].posX, buttonTable[i].posY, string.len(buttonTable[i].label)+2, 3, buttonTable[i].buttonColor)
  229.        if buttonTable[i].showLabel then
  230.          drawText(buttonTable[i].posX+1, buttonTable[i].posY+1, buttonTable[i].label, buttonTable[i].labelColor, buttonTable[i].buttonColor)
  231.        else
  232.         drawLine(buttonTable[i].posX, buttonTable[i].posY, string.len(buttonTable[i].label)+2, 3, buttonTable[i].buttonColor)
  233.        end
  234.     end
  235.   end
  236.  
  237. end
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245. function draw_reactorFuelInfoPanel ()
  246.   setBgColor(reactorPowerInfoPanelBgColor)
  247.   renderLine( reactorFuelInfoPanelPosX,  reactorFuelInfoPanelPosY,  reactorFuelInfoPanelSizeX,  reactorFuelInfoPanelSizeY)
  248.    setBgColor(colors_gray)
  249.    renderLine( reactorFuelInfoPanelPosX+16,  reactorFuelInfoPanelPosY+2,  30,  3)
  250.    setFgColor(colors_black)
  251.    setCursorPos(reactorFuelInfoPanelPosX+19,  reactorFuelInfoPanelPosY+3)
  252.    renderText("max fuel ")
  253.    setCursorPos(reactorFuelInfoPanelPosX+19+string.len("max fuel       ")+1,  reactorFuelInfoPanelPosY+3)
  254.    renderText(fuelMax)
  255.    setBgColor(colors_yellow)
  256.    renderLine( reactorFuelInfoPanelPosX+16,  reactorFuelInfoPanelPosY+6,  30,  3)
  257.    setFgColor(colors_black)
  258.    setCursorPos(reactorFuelInfoPanelPosX+19,  reactorFuelInfoPanelPosY+7)
  259.    renderText("current fuel ")
  260.    setCursorPos(reactorFuelInfoPanelPosX+19+string.len("current fuel   ")+1,  reactorFuelInfoPanelPosY+7)
  261.    renderText(fuelAmount)
  262.    setBgColor(colors_cyan)
  263.    renderLine( reactorFuelInfoPanelPosX+16,  reactorFuelInfoPanelPosY+10,  30,  3)
  264.    setFgColor(colors_black)
  265.    setCursorPos(reactorFuelInfoPanelPosX+19,  reactorFuelInfoPanelPosY+11)
  266.    renderText("current waste ")
  267.    setCursorPos(reactorFuelInfoPanelPosX+19+string.len("current waste  ")+1,  reactorFuelInfoPanelPosY+11)
  268.    renderText(wasteAmount)
  269.   draw_FuelBar()
  270. end
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282. function draw_MainPanel()
  283.   setBgColor(mainPanelPrimaryColor)
  284.   renderLine(mainPanelPosX,  mainPanelPosY,  mainPanelSizeX,  mainPanelSizeY)
  285.     setBgColor(mainPanelSecondaryColor)
  286.   renderLine( mainPanelPosX+1,  mainPanelPosY+1,  mainPanelSizeX-2,  1)
  287.   renderLine( mainPanelPosX+(mainPanelSizeX-3),  mainPanelPosY+2,  2,  1)
  288.  
  289.   renderLine( mainPanelPosX+1,  mainPanelPosY+mainPanelSizeY-2,  mainPanelSizeX-2,  1)
  290.   renderLine( mainPanelPosX+1,  mainPanelPosY+mainPanelSizeY-3,  2,  1)
  291. end
  292.  
  293. -------UI functions-------
  294. --------------------------
  295. --======================--
  296. --------------------------
  297. -------UI functions-------
  298.  
  299.  
  300. -----global variables-----
  301. --------------------------
  302. --======================--
  303. --------------------------
  304. -----global variables-----
  305.  
  306.  
  307. ---------colors-----------
  308. --------------------------
  309. --======================--
  310. --------------------------
  311. ---------colors-----------
  312.  
  313.  
  314. colors_white = 0xffffff
  315. colors_orange = 0xff6600
  316. colors_magenta = 0xff00ff
  317. colors_lightblue = 0x0099ff
  318. colors_yellow = 0xffff00
  319. colors_lime = 0x00ff00
  320. colors_pink = 0xff3399
  321. colors_gray = 0x737373
  322. colors_lightgray = 0xa5a5a5
  323. colors_silver = 0xc0c0c0
  324. colors_cyan = 0x169c9d
  325. colors_purple = 0x8932b7
  326. colors_blue = 0x3c44a9
  327. colors_brown = 0x825432
  328. colors_green = 0x5d7c15
  329. colors_red = 0xb02e26
  330. colors_lightred = 0xffcccb
  331. colors_black = 0x000000
  332.  
  333.  
  334.  
  335. ---------colors-----------
  336. --------------------------
  337. --======================--
  338. --------------------------
  339. ---------colors-----------
  340.  
  341.  
  342. function init_reactorVariables()
  343.   reactorVariable = {}
  344.   reactorVariable.energyStats = {}
  345.    reactorVariable.energyStats.temp = reactor.getEnergyStats()
  346.      
  347.   reactorVariable.energyStats.energyProduced = reactorVariable.energyStats.temp.energyProducedLastTick
  348.    reactorVariable.energyStats.energyStored = reactorVariable.energyStats.temp.energyStored
  349.     reactorVariable.energyStats.energyCapacity = reactorVariable.energyStats.temp.energyCapacity
  350.   reactorVariable.controlRodStats = {}
  351.    reactorVariable.controlRodStats.numberOfControlRods = reactor.getNumberOfControlRods()
  352.     reactorVariable.controlRodStats.controlRodLevels = {}
  353.      for i = 0 , reactorVariable.controlRodStats.numberOfControlRods-1 do
  354.        temp1 = reactor.getControlRodLevel(i)
  355.        table.insert(reactorVariable.controlRodStats.controlRodLevels, temp1)      
  356.      end
  357.   reactorVariable.fuelStats = {}
  358.   reactorVariable.fuelStats.temp = reactor.getFuelStats()
  359.  
  360.    reactorVariable.fuelStats.fuelTemp = reactorVariable.fuelStats.temp.fuelTemperature
  361.     reactorVariable.fuelStats.maxFuel = reactorVariable.fuelStats.temp.fuelCapacity
  362.      reactorVariable.fuelStats.fuelReactivity = reactorVariable.fuelStats.temp.fuelReactivity
  363.       reactorVariable.fuelStats.wasteAmount = reactorVariable.fuelStats.temp.wasteAmount
  364.       reactorVariable.fuelStats.fuelAmount = reactorVariable.fuelStats.temp.fuelAmount
  365.   reactorVariable.temperatures = {}
  366.    reactorVariable.temperatures.casingTemp = reactor.getCasingTemperature()
  367. end
  368.  
  369.  
  370. function init_ReactorPanel()
  371.   reactorPanelPosX = 10
  372.   reactorPanelPosY = 30
  373.   reactorPanelSizeX = 22
  374.   reactorPanelSizeY = 23
  375.   reactorPanelColor = colors_gray
  376.   table_RactorPanelButtons = {}
  377.   newButton("1",  reactorPanelPosX+3,  reactorPanelPosY+13,  colors_black,  reactorPowerInfoPanelBgColor,  false,  true,  1,  1,  testingFunction,  "funcDATA",  table_RactorPanelButtons)
  378.   newButton("2",  reactorPanelPosX+7,  reactorPanelPosY+13,  colors_black,  reactorPowerInfoPanelBgColor,  false,  true,  1,  1,  testingFunction,  "funcDATA",  table_RactorPanelButtons)
  379.   newButton("3",  reactorPanelPosX+11,  reactorPanelPosY+13,  colors_black,  reactorPowerInfoPanelBgColor,  false,  true,  1,  1,  testingFunction,  "funcDATA",  table_RactorPanelButtons)
  380.   newButton("4",  reactorPanelPosX+15,  reactorPanelPosY+13,  colors_black,  reactorPowerInfoPanelBgColor,  false,  true,  1,  1,  testingFunction,  "funcDATA",  table_RactorPanelButtons)
  381.  
  382. end
  383.  
  384.  
  385.  
  386. ---------energy-----------
  387. --------------------------
  388. --======================--
  389. --------------------------
  390. ---------energy-----------
  391.  
  392. function init_reactorPowerInfoPanel()
  393.   onThresh = 0.75
  394.   offThresh = 0.95
  395.  reactorPowerInfoPanelPosX = 15
  396.  reactorPowerInfoPanelPosY = 8
  397.  reactorPowerInfoPanelSizeX = 125
  398.  reactorPowerInfoPanelSizeY = 8
  399.  
  400.  reactorPowerInfoPanelPosX2 = 66
  401.  reactorPowerInfoPanelPosY2 = 16
  402.  reactorPowerInfoPanelSizeX2 = 23
  403.  reactorPowerInfoPanelSizeY2 = 6
  404.  
  405.  manualControl = false
  406.  
  407.  reactorPowerInfoPanelBgColor = colors_blue
  408.  simpleAutoAdjButtons = {}
  409.  overrideButtons = {}
  410.  
  411.   newButton("<",  reactorPowerInfoPanelPosX2+2,  reactorPowerInfoPanelPosY2+2,  colors_black,  colors_lime,  true,  true,  3,  1,  subtractFromOnThresh,  _,  simpleAutoAdjButtons)
  412.   newButton(">",  reactorPowerInfoPanelPosX2+18,  reactorPowerInfoPanelPosY2+2,  colors_black,  colors_lime,  true,  true,  3,  1,  addToOnThresh,  _,  simpleAutoAdjButtons)
  413.   newButton("<",  reactorPowerInfoPanelPosX2+2,  reactorPowerInfoPanelPosY2+4,  colors_black,  colors_red,  true,  true,  3,  1, subtractFromOffThresh,  _,  simpleAutoAdjButtons)
  414.   newButton(">",  reactorPowerInfoPanelPosX2+18,  reactorPowerInfoPanelPosY2+4,  colors_black,  colors_red,  true,  true,  3,  1,  addToOffThresh,  _,  simpleAutoAdjButtons)
  415.   newButton("manual override",  reactorPowerInfoPanelPosX2+1,  reactorPowerInfoPanelPosY2+19,  colors_black,  colors_gray,  true,  true,  21,  3,  manualControlToggle,  "funcDATA",  overrideButtons)
  416. end
  417.  
  418. function draw_reactorPowerInfoPanel()
  419.   local energyStored = reactorVariable.energyStats.energyStored
  420.   local maxEnergy = reactorVariable.energyStats.energyCapacity
  421.   local a = "current power / max power"
  422.   setBgColor(reactorPowerInfoPanelBgColor)
  423.   renderLine( reactorPowerInfoPanelPosX,  reactorPowerInfoPanelPosY,  reactorPowerInfoPanelSizeX,  reactorPowerInfoPanelSizeY)
  424.   renderLine( reactorPowerInfoPanelPosX2,  reactorPowerInfoPanelPosY2,  reactorPowerInfoPanelSizeX2,  reactorPowerInfoPanelSizeY2)
  425.  
  426.  
  427.  
  428.   setBgColor(colors_black)
  429.   renderLine( reactorPowerInfoPanelPosX2,  reactorPowerInfoPanelPosY2+18,  23,  8)
  430.   setBgColor(colors_silver)
  431.   renderLine( reactorPowerInfoPanelPosX2,  reactorPowerInfoPanelPosY2+18,  23,  5)
  432.  
  433.   setBgColor(reactorFuelInfoPanelBgColor)
  434.   setFgColor(colors_lime)
  435.   setCursorPos(reactorPowerInfoPanelPosX+(reactorPowerInfoPanelSizeX/2)-(string.len(a)/2),  reactorPowerInfoPanelPosY+1)
  436.   renderText(a)
  437.   draw_ProgressBar(1, reactorPowerInfoPanelPosX+2,  reactorPowerInfoPanelPosY+2,  reactorPowerInfoPanelSizeX-4,  reactorPowerInfoPanelSizeY-4,  maxEnergy,  energyStored, colors_lightred, colors_green, true)
  438.  
  439.   setBgColor(colors_lime)
  440.   renderLine(reactorPowerInfoPanelPosX2+5,  reactorPowerInfoPanelPosY2+2,  13,  1)
  441.   setCursorPos(reactorPowerInfoPanelPosX2+10,  reactorPowerInfoPanelPosY2+2)
  442.   setBgColor(colors_black)
  443.   renderText(tostring(onThresh*100).."%")
  444.  
  445.   setBgColor(colors_red)
  446.   renderLine(reactorPowerInfoPanelPosX2+5,  reactorPowerInfoPanelPosY2+4,  13,  1)
  447.   setCursorPos(reactorPowerInfoPanelPosX2+10,  reactorPowerInfoPanelPosY2+4)
  448.   setBgColor(colors_black)
  449.   renderText(tostring(offThresh*100).."%")
  450.   drawButtons(simpleAutoAdjButtons)
  451.   drawButtons(overrideButtons)
  452. end
  453.  
  454. function upDateReactorPowerInfoPanel()
  455.   reactorVariable.energyStats.temp = reactor.getEnergyStats()  
  456.    reactorVariable.energyStats.energyProduced = reactorVariable.energyStats.temp.energyProducedLastTick
  457.     reactorVariable.energyStats.energyStored = reactorVariable.energyStats.temp.energyStored
  458.      reactorVariable.energyStats.energyCapacity = reactorVariable.energyStats.temp.energyCapacity
  459.      maxEnergy = reactorVariable.energyStats.energyCapacity
  460.      energyStored = reactorVariable.energyStats.energyStored
  461.  
  462.      setBgColor(colors_lime)
  463.      renderLine(reactorPowerInfoPanelPosX2+5,  reactorPowerInfoPanelPosY2+2,  13,  1)
  464.      setCursorPos(reactorPowerInfoPanelPosX2+10,  reactorPowerInfoPanelPosY2+2)
  465.      setBgColor(colors_lime)
  466.      renderText(tostring(onThresh*100).."%")
  467.  
  468.      setBgColor(colors_red)
  469.      renderLine(reactorPowerInfoPanelPosX2+5,  reactorPowerInfoPanelPosY2+4,  13,  1)
  470.      setCursorPos(reactorPowerInfoPanelPosX2+10,  reactorPowerInfoPanelPosY2+4)
  471.      setBgColor(colors_red)
  472.      renderText(tostring(offThresh*100).."%")
  473.      draw_ProgressBar(1, reactorPowerInfoPanelPosX+2,  reactorPowerInfoPanelPosY+2,  reactorPowerInfoPanelSizeX-4,  reactorPowerInfoPanelSizeY-4,  maxEnergy,  energyStored, colors_lightred, colors_green, true)
  474. end
  475.  
  476. ---------energy-----------
  477. --------------------------
  478. --======================--
  479. --------------------------
  480. ---------energy-----------
  481.  
  482.  
  483.  
  484. -----------fuel-----------
  485. --------------------------
  486. --======================--
  487. --------------------------
  488. -----------fuel-----------
  489.  
  490. function init_fuelBar()
  491.   fuelBarPosX = reactorFuelInfoPanelPosX+4
  492.   fuelBarPosY = reactorFuelInfoPanelPosY+2
  493.   fuelBarSizeX = 7
  494.   fuelBarSizeY = reactorFuelInfoPanelSizeY - 5
  495.  
  496.   reactorVariable.fuelStats.temp = reactor.getFuelStats()
  497.  
  498.    reactorVariable.fuelStats.fuelTemp = reactorVariable.fuelStats.temp.fuelTemperature
  499.     reactorVariable.fuelStats.maxFuel = reactorVariable.fuelStats.temp.fuelCapacity
  500.      reactorVariable.fuelStats.fuelReactivity = reactorVariable.fuelStats.temp.fuelReactivity
  501.   fuelMax = reactorVariable.fuelStats.maxFuel
  502.   fuelAmount = reactorVariable.fuelStats.fuelAmount
  503.   wasteAmount = reactorVariable.fuelStats.wasteAmount
  504. end
  505.  
  506. function init_reactorFuelInfoPanel()
  507.   reactorFuelInfoPanelPosX = 15
  508.   reactorFuelInfoPanelPosY = 17
  509.   reactorFuelInfoPanelSizeX = 50
  510.   reactorFuelInfoPanelSizeY = 25
  511.   reactorFuelInfoPanelBgColor = colors_blue
  512.   ejectWasteButton = {}
  513.   newButton("ejectWaste",  reactorFuelInfoPanelPosX+15,  reactorFuelInfoPanelPosY+16,  colors_black,  colors_gray,  true,  false,  8,  3,  ejectWaste,  _,  ejectWasteButton)
  514.   init_fuelBar()
  515. end
  516.  
  517. function draw_FuelBar()
  518.   local a =  fuelBarSizeY*(fuelAmount / fuelMax)
  519.   local aa = fuelBarSizeY*(wasteAmount / fuelMax)
  520.   setBgColor(colors_gray)
  521.   renderLine(fuelBarPosX, fuelBarPosY+1, fuelBarSizeX, fuelBarSizeY-1)
  522.   setBgColor(colors_yellow)
  523.   renderLine(fuelBarPosX, fuelBarPosY+fuelBarSizeY-math.floor(a), fuelBarSizeX, math.floor(a))
  524.   setBgColor(colors_cyan)
  525.   renderLine(fuelBarPosX, fuelBarPosY+fuelBarSizeY-math.floor(aa), fuelBarSizeX, math.floor(aa))
  526.   setCursorPos(fuelBarPosX, fuelBarPosY+fuelBarSizeY)
  527.   drawButtons(ejectWasteButton)
  528. end
  529.  
  530. function updateFuelInfo()
  531.  
  532.   reactorVariable.fuelStats.temp = reactor.getFuelStats()
  533.    reactorVariable.fuelStats.fuelTemp = reactorVariable.fuelStats.temp.fuelTemperature
  534.     reactorVariable.fuelStats.maxFuel = reactorVariable.fuelStats.temp.fuelCapacity
  535.      reactorVariable.fuelStats.fuelReactivity = reactorVariable.fuelStats.temp.fuelReactivity
  536.   fuelMax = reactorVariable.fuelStats.maxFuel
  537.   fuelAmount = reactorVariable.fuelStats.fuelAmount
  538.   wasteAmount = reactorVariable.fuelStats.wasteAmount
  539.   local a =  fuelBarSizeY*(fuelAmount / fuelMax)
  540.   local aa = fuelBarSizeY*(wasteAmount / fuelMax)
  541.  
  542.   setBgColor(colors_gray)
  543.   renderLine(fuelBarPosX, fuelBarPosY+1, fuelBarSizeX, fuelBarSizeY-1)
  544.   setBgColor(colors_yellow)
  545.   renderLine(fuelBarPosX, fuelBarPosY+fuelBarSizeY-math.floor(a)-math.floor(aa), fuelBarSizeX, math.floor(a))
  546.   setBgColor(colors_cyan)
  547.   renderLine(fuelBarPosX, fuelBarPosY+fuelBarSizeY-math.floor(aa), fuelBarSizeX, math.floor(aa))
  548.   setCursorPos(fuelBarPosX, fuelBarPosY+fuelBarSizeY)
  549.  
  550.  
  551.   setBgColor(colors_gray)
  552.   setFgColor(colors_black)
  553.  
  554.   setCursorPos(reactorFuelInfoPanelPosX+19+string.len("max fuel       ")+1,  reactorFuelInfoPanelPosY+3)
  555.   renderText(fuelMax)
  556.  
  557.   setBgColor(colors_cyan)
  558.   setFgColor(colors_black)
  559.  
  560.   renderLine( reactorFuelInfoPanelPosX+19+string.len("current waste  ")+1,  reactorFuelInfoPanelPosY+11,  11,  1)
  561.   setCursorPos(reactorFuelInfoPanelPosX+19+string.len("current waste  ")+1,  reactorFuelInfoPanelPosY+11)
  562.   renderText(wasteAmount)
  563.  
  564.   setBgColor(colors_yellow)
  565.   setFgColor(colors_black)
  566.   renderLine( reactorFuelInfoPanelPosX+19+string.len("current fuel   ")+1,  reactorFuelInfoPanelPosY+7,  11,  1)
  567.   setCursorPos(reactorFuelInfoPanelPosX+19+string.len("current fuel   ")+1,  reactorFuelInfoPanelPosY+7)
  568.   renderText(fuelAmount)
  569.  
  570. end
  571.  
  572. -----------fuel-----------
  573. --------------------------
  574. --======================--
  575. --------------------------
  576. -----------fuel-----------
  577.  
  578.  
  579. ---------output-----------
  580. --------------------------
  581. --======================--
  582. --------------------------
  583. ---------output-----------
  584.  
  585. function init_reactorOutputPanel ()
  586.   reactorOutputPanelPosX = reactorPowerInfoPanelPosX2
  587.   reactorOutputPanelPosY = reactorPowerInfoPanelPosY2+7
  588.   reactorOutputPanelSizeX = 23
  589.   reactorOutputPanelSizeY = 6
  590.  
  591.   reactorEnergyOutput = reactorVariable.energyStats.energyProduced
  592.   fuelReactivity = reactorVariable.fuelStats.fuelReactivity
  593.  
  594. end
  595.  
  596.  
  597. function draw_reactorOutputPanel()
  598.  
  599.  
  600.  setBgColor(colors_lime)
  601.  renderLine( reactorOutputPanelPosX,  reactorOutputPanelPosY,  reactorOutputPanelSizeX,  4)
  602.  setCursorPos( reactorOutputPanelPosX+reactorOutputPanelSizeX/2-string.len("fuel reactivity")/2,  reactorOutputPanelPosY+1)
  603.  setFgColor(colors_black)
  604.  renderText("fuel reactivity")
  605.  
  606.  
  607.  renderLine( reactorOutputPanelPosX,  reactorOutputPanelPosY+2,  reactorOutputPanelSizeX,  1)
  608.  setCursorPos(reactorOutputPanelPosX+reactorOutputPanelSizeX/2-string.len(tostring(math.floor(fuelReactivity)))/2,  reactorOutputPanelPosY+2)
  609.  renderText(math.floor(fuelReactivity))
  610.  
  611.  setBgColor(colors_orange)
  612.  renderLine( reactorOutputPanelPosX,  reactorOutputPanelPosY+5,  reactorOutputPanelSizeX,  5)
  613.  setCursorPos(reactorOutputPanelPosX+reactorOutputPanelSizeX/2-string.len("energy outut")/2,  reactorOutputPanelPosY+6)
  614.  renderText("energy outut")
  615.  
  616.  
  617.  setCursorPos(reactorOutputPanelPosX+reactorOutputPanelSizeX/2-string.len(math.floor(reactorEnergyOutput))/2,  reactorOutputPanelPosY+7)
  618.  renderText(math.floor(reactorEnergyOutput))
  619.  setCursorPos(reactorOutputPanelPosX+reactorOutputPanelSizeX/2-string.len("RF per TICK")/2,  reactorOutputPanelPosY+8)
  620.  renderText("RF per TICK")
  621. end
  622.  
  623. function upDate_reeactorOutPutPanel()
  624.  
  625.     reactorEnergyOutput = reactorVariable.energyStats.energyProduced
  626.  
  627.  
  628.     fuelReactivity = reactorVariable.fuelStats.fuelReactivity
  629.  
  630.   setBgColor(colors_lime)
  631.   renderLine( reactorOutputPanelPosX,  reactorOutputPanelPosY+5,  reactorOutputPanelSizeX,  5)
  632.   renderLine( reactorOutputPanelPosX,  reactorOutputPanelPosY+2,  reactorOutputPanelSizeX,  1)
  633.   setCursorPos(reactorOutputPanelPosX+reactorOutputPanelSizeX/2-string.len(tostring(math.floor(fuelReactivity)).." %")/2,  reactorOutputPanelPosY+2)
  634.   renderText(math.floor(fuelReactivity).." %")
  635.  
  636.  
  637.    if isReactorActive() then
  638.   setBgColor(colors_orange)
  639.   renderLine( reactorOutputPanelPosX,  reactorOutputPanelPosY+5,  reactorOutputPanelSizeX,  5)
  640.   setCursorPos(reactorOutputPanelPosX+reactorOutputPanelSizeX/2-string.len("energy outut")/2,  reactorOutputPanelPosY+6)
  641.   renderText("energy outut")
  642.  
  643.   renderLine( reactorOutputPanelPosX,  reactorOutputPanelPosY+7,  reactorOutputPanelSizeX,  1)
  644.   setCursorPos(reactorOutputPanelPosX+reactorOutputPanelSizeX/2-string.len(math.floor(reactorEnergyOutput))/2,  reactorOutputPanelPosY+7)
  645.   renderText(math.floor(reactorEnergyOutput))
  646.   setCursorPos(reactorOutputPanelPosX+reactorOutputPanelSizeX/2-string.len("RF per TICK")/2,  reactorOutputPanelPosY+8)
  647.   renderText("RF per TICK")
  648.    else
  649.   setBgColor(colors_gray)
  650.   renderLine( reactorOutputPanelPosX,  reactorOutputPanelPosY+5,  reactorOutputPanelSizeX,  5)
  651.   renderLine( reactorOutputPanelPosX,  reactorOutputPanelPosY+7,  reactorOutputPanelSizeX,  1)
  652.   setCursorPos(reactorOutputPanelPosX+reactorOutputPanelSizeX/2-string.len("energy outut")/2,  reactorOutputPanelPosY+6)
  653.   renderText("energy outut")
  654.   setCursorPos(reactorOutputPanelPosX+reactorOutputPanelSizeX/2-string.len(math.floor(reactorEnergyOutput))/2,  reactorOutputPanelPosY+7)
  655.   renderText(math.floor(reactorEnergyOutput))
  656.   setCursorPos(reactorOutputPanelPosX+reactorOutputPanelSizeX/2-string.len("RF per TICK")/2,  reactorOutputPanelPosY+8)
  657.   renderText("RF per TICK")
  658.    end
  659. end
  660.  
  661. ---------output-----------
  662. --------------------------
  663. --======================--
  664. --------------------------
  665. ---------output-----------
  666.  
  667. -----------temp-----------
  668. --------------------------
  669. --======================--
  670. --------------------------
  671. -----------temp-----------
  672.  
  673.  
  674. function init_reactorTempPanel()
  675.   reactorTempPanelPosX = 90
  676.   reactorTempPanelPosY = 17
  677.   reactorTempPanelSizeX = 50
  678.   reactorTempPanelSizeY = 25
  679.   reactorTempPanelBgColor = colors_blue
  680. end
  681.  
  682. function draw_reactorTempPanel()
  683.   fuelTemp = reactorVariable.fuelStats.fuelTemp
  684.   caseTemp = reactorVariable.temperatures.casingTemp
  685.   sVar1 = math.floor(fuelTemp).."  C"
  686.   sVar2 = math.floor(caseTemp).."  C"
  687.  setBgColor(reactorTempPanelBgColor)
  688.  renderLine(reactorTempPanelPosX,  reactorTempPanelPosY,  reactorTempPanelSizeX,  reactorTempPanelSizeY)
  689.  setCursorPos( reactorTempPanelPosX+10,  reactorTempPanelPosY)
  690.  renderText("CORE")
  691.  setCursorPos( reactorTempPanelPosX+10,  reactorTempPanelPosY+1)
  692.  renderText("TEMP")
  693.  setCursorPos( reactorTempPanelPosX+4+8-(string.len(sVar1)/2),  reactorTempPanelPosY+reactorTempPanelSizeY-2)
  694.  renderText(sVar1)
  695.  setCursorPos( reactorTempPanelPosX+4+16+17,  reactorTempPanelPosY)
  696.  renderText("CASING")
  697.  setCursorPos( reactorTempPanelPosX+4+16+18,  reactorTempPanelPosY+1)
  698.  renderText("TEMP")
  699.  setCursorPos( reactorTempPanelPosX+16+17+8-(string.len(sVar2)/2),  reactorTempPanelPosY+reactorTempPanelSizeY-2)
  700.  renderText(sVar2)
  701.  draw_ProgressBar(2,  reactorTempPanelPosX+4,  reactorTempPanelPosY+2,  16,  reactorTempPanelSizeY-4,  2000,  math.floor(fuelTemp),  colors_gray,  colors_green, false)
  702.  
  703.  draw_ProgressBar(2,  reactorTempPanelPosX+4+16+12,  reactorTempPanelPosY+2,  16,  reactorTempPanelSizeY-4,  2000,  math.floor(caseTemp),  colors_gray,  colors_green, false)
  704.  
  705. end
  706.  
  707. function upDateReactorTempPanel()
  708.   fuelTemp = reactorVariable.fuelStats.fuelTemp
  709.   caseTemp = reactorVariable.temperatures.casingTemp
  710.   sVar1 = math.floor(fuelTemp).."  C"
  711.   sVar2 = math.floor(caseTemp).."  C"
  712.    
  713.   setBgColor(reactorPowerInfoPanelBgColor)
  714.   setFgColor(colors_black)
  715.  
  716.   renderLine( reactorTempPanelPosX,  reactorTempPanelPosY+reactorTempPanelSizeY-2,  reactorTempPanelSizeX,  1)
  717.  
  718.    setCursorPos( reactorTempPanelPosX+16+17+8-(string.len(sVar2)/2),  reactorTempPanelPosY+reactorTempPanelSizeY-2)
  719.    renderText(sVar2)
  720.  
  721.   setBgColor(reactorPowerInfoPanelBgColor)
  722.   setFgColor(colors_black)
  723.    setCursorPos( reactorTempPanelPosX+4+8-(string.len(sVar1)/2),  reactorTempPanelPosY+reactorTempPanelSizeY-2)
  724.    renderText(sVar1)
  725.   if math.floor(fuelTemp) >1000 then
  726.     draw_ProgressBar(2,  reactorTempPanelPosX+4,  reactorTempPanelPosY+2,  16,  reactorTempPanelSizeY-4,  2000,  math.floor(fuelTemp),  colors_gray,  colors_orange, false)
  727.   else
  728.     draw_ProgressBar(2,  reactorTempPanelPosX+4,  reactorTempPanelPosY+2,  16,  reactorTempPanelSizeY-4,  2000,  math.floor(fuelTemp),  colors_gray,  colors_green, false)
  729.   end
  730.    draw_ProgressBar(2,  reactorTempPanelPosX+4+16+12,  reactorTempPanelPosY+2,  16,  reactorTempPanelSizeY-4,  2000,  math.floor(caseTemp),  colors_gray,  colors_green, false)
  731.  
  732. end
  733.  
  734. -----------temp-----------
  735. --------------------------
  736. --======================--
  737. --------------------------
  738. -----------temp-----------
  739.  
  740.  
  741. function init_mainPanel()
  742.    resolutionX, resolutionY = gpu.getResolution()
  743.   mainPanelPosX = 2
  744.   mainPanelPosY = 2
  745.   mainPanelSizeX = resolutionX-2
  746.   mainPanelSizeY = resolutionY-2
  747.   mainPanelPrimaryColor = colors_black
  748.   mainPanelSecondaryColor = colors_orange
  749.   mainPanelButtons = {}
  750.  
  751. end
  752.  
  753.  
  754.  
  755.  
  756.  
  757.  
  758.  
  759.  
  760.  
  761. -----global variables-----
  762. --------------------------
  763. --======================--
  764. --------------------------
  765. -----global variables-----
  766.  
  767.  
  768.  
  769.  
  770.  
  771. ---processing functions---
  772. --------------------------
  773. --======================--
  774. --------------------------
  775. ---processing functions---
  776.  
  777. function addToOnThresh()
  778.  
  779.   if onThresh < 1 and onThresh < offThresh-0.05 then
  780.     onThresh = onThresh+0.05
  781.   end
  782. end
  783.  
  784. function subtractFromOnThresh()
  785.   if onThresh > 0.06 then
  786.    onThresh = onThresh-0.05
  787.   end
  788. end
  789.  
  790. function addToOffThresh()
  791.   if offThresh < 1 then
  792.    offThresh = offThresh+0.05
  793.   end
  794. end
  795.  
  796. function subtractFromOffThresh()
  797.   if offThresh > 0.06 and offThresh > onThresh+0.05 then
  798.    offThresh = offThresh-0.05
  799.   end
  800. end
  801.  
  802. function simpleAutoReactorContol()
  803.   if not manualControl then
  804.    if reactorVariable.energyStats.energyStored < reactorVariable.energyStats.energyCapacity * onThresh then
  805.     activateReactor ()
  806.    elseif reactorVariable.energyStats.energyStored > reactorVariable.energyStats.energyCapacity * offThresh then
  807.     deactivateReactor ()
  808.    end
  809.   end
  810. end
  811.  
  812.  
  813. function testingFunction(text)
  814.  
  815. end
  816.  
  817. function activateReactor ()
  818.   reactor.setActive(true)
  819.   if manualControl then
  820.   overrideButtons = {}
  821.   newButton("auto control",  reactorPowerInfoPanelPosX2+1,  reactorPowerInfoPanelPosY2+19,  colors_black,  colors_gray,  true,  true,  21,  3,  manualControlToggle,  "funcDATA",  overrideButtons)
  822.   newButton("deactivate reactor",  reactorPowerInfoPanelPosX2+1,  reactorPowerInfoPanelPosY2+23,  colors_black,  colors_gray,  true,  true,  21,  3,  deactivateReactor,  "funcDATA",  overrideButtons)
  823.   drawButtons(overrideButtons)
  824.   end
  825. end
  826.  
  827. function isReactorActive()
  828.   t = reactor.getActive()
  829.   return t
  830. end
  831.  
  832.  
  833. function deactivateReactor ()
  834.   reactor.setActive(false)
  835.   if manualControl then
  836.   overrideButtons = {}
  837.   newButton("auto control",  reactorPowerInfoPanelPosX2+1,  reactorPowerInfoPanelPosY2+19,  colors_black,  colors_gray,  true,  true,  21,  3,  manualControlToggle,  "funcDATA",  overrideButtons)
  838.   newButton("activate reactor",  reactorPowerInfoPanelPosX2+1,  reactorPowerInfoPanelPosY2+23,  colors_black,  colors_gray,  true,  true,  21,  3,  deactivateReactor,  "funcDATA",  overrideButtons)
  839.   drawButtons(overrideButtons)
  840.   end
  841. end
  842.  
  843. function ejectWaste()
  844.  reactor.doEjectWaste()
  845. end
  846.  
  847. function manualControlToggle()
  848.  
  849.  manualControl = not manualControl
  850.   if manualControl then
  851.     setBgColor(colors_black)
  852.     renderLine( reactorPowerInfoPanelPosX2,  reactorPowerInfoPanelPosY2+18,  23,  8)
  853.     setBgColor(colors_silver)
  854.     renderLine( reactorPowerInfoPanelPosX2,  reactorPowerInfoPanelPosY2+18,  23,  8)
  855.     overrideButtons = {}
  856.     newButton("auto control",  reactorPowerInfoPanelPosX2+1,  reactorPowerInfoPanelPosY2+19,  colors_black,  colors_gray,  true,  true,  21,  3,  manualControlToggle,  "funcDATA",  overrideButtons)
  857.     newButton("activate reactor",  reactorPowerInfoPanelPosX2+1,  reactorPowerInfoPanelPosY2+23,  colors_black,  colors_gray,  true,  true,  21,  3,  activateReactor,  "funcDATA",  overrideButtons)
  858.   else
  859.     setBgColor(colors_black)
  860.     renderLine( reactorPowerInfoPanelPosX2,  reactorPowerInfoPanelPosY2+23,  23,  3)
  861.     setBgColor(colors_silver)
  862.     renderLine( reactorPowerInfoPanelPosX2,  reactorPowerInfoPanelPosY2+18,  23,  5)
  863.     overrideButtons = {}
  864.     newButton("manual override",  reactorPowerInfoPanelPosX2+1,  reactorPowerInfoPanelPosY2+19,  colors_black,  colors_gray,  true,  true,  21,  3,  manualControlToggle,  "funcDATA",  overrideButtons)
  865.    
  866.   end
  867.   drawButtons(overrideButtons)
  868. end
  869.  
  870. function listenForEvent()
  871.   local eventName, address, posX, posY, temp5, user = event.pull(0.2)
  872.      if eventName == "touch" then
  873.       loopThruButtons(mainPanelButtons, posX, posY)
  874.       loopThruButtons(simpleAutoAdjButtons, posX, posY)
  875.       loopThruButtons(overrideButtons, posX, posY)
  876.       loopThruButtons(ejectWasteButton, posX, posY)
  877.      end
  878. end
  879.  
  880. function removeAllButtons(buttonTable)
  881.   buttonTable = {}
  882. end
  883.  
  884. function loopThruButtons(butonTable, posX, posY)
  885.     t = false
  886.   for i = 1, #butonTable do
  887.     local buttonX = (posX >= butonTable[i].posX and posX < butonTable[i].posX + butonTable[i].sizeX)  
  888.     local buttonY = (posY >= butonTable[i].posY and posY < butonTable[i].posY + butonTable[i].sizeY)  
  889.     local buttonX_02 = (posX >= butonTable[i].posX and posX < butonTable[i].posX + string.len(butonTable[i].label))
  890.     local buttonY_02 = (posY >= butonTable[i].posY and posY < butonTable[i].posY + 3)
  891.     if butonTable[i].sizeOveride then
  892.       if buttonX and buttonY and t == false then  
  893.         butonTable[i].func(butonTable[i].funcDATA)
  894.         t = true
  895.       end
  896.     elseif not butonTable[i].sizeOveride and buttonX_02 and buttonY_02 and t == false then
  897.       butonTable[i].func(butonTable[i].funcDATA)
  898.       t = true
  899.     end
  900.   end
  901. end
  902.  
  903. ---processing functions---
  904. --------------------------
  905. --======================--
  906. --------------------------
  907. ---processing functions---
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920. term.clear()
  921.  
  922. init_reactorVariables()
  923. init_ReactorPanel()
  924. init_mainPanel()
  925.  
  926. init_reactorPowerInfoPanel()
  927.  
  928.  
  929.  
  930. init_reactorFuelInfoPanel()
  931. init_reactorTempPanel()
  932.  
  933. init_reactorOutputPanel ()
  934.  
  935.  
  936.  
  937. draw_MainPanel()
  938.  
  939. draw_reactorPowerInfoPanel()
  940.  
  941. draw_reactorFuelInfoPanel ()
  942.  
  943. draw_reactorTempPanel()
  944. --draw_FuelBar()
  945. --draw_ReactorPanel()
  946.  
  947. draw_reactorOutputPanel()
  948.  
  949.  
  950.  
  951. while true do
  952.   init_reactorVariables()
  953.   upDateReactorPowerInfoPanel()
  954.   updateFuelInfo()
  955.   upDateReactorTempPanel()
  956.   listenForEvent()
  957.   simpleAutoReactorContol()
  958.   upDate_reeactorOutPutPanel()
  959.  
  960.  
  961. end
  962.  
  963.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement