OFgRc

Draconic Reactor Monitor 1.0

May 6th, 2021 (edited)
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.27 KB | None | 0 0
  1. --[[
  2. This program is for the Computercraft mod.
  3. It allows you to monitor the performance of the reactor from the Draconic Evolution mod.
  4.  
  5. Instructions:
  6. Put the computer back to the reactor stabilizer,
  7. connect the input and output gates,
  8. connect the 5x4 blocks monitor.
  9.  
  10. click on computer,
  11. write the command : pastebin get F6mkHf8A start_program
  12. And Enter the command: start_program
  13.  
  14. Tutorial: https://youtu.be/SVl8znXLEPo
  15.  
  16. Version 1.0 by OFgRc
  17. ]]
  18. --- load
  19. local mon = peripheral.find("monitor")
  20. term.redirect(mon)
  21. local RA = peripheral.wrap("back")
  22. local RI = RA.getReactorInfo()
  23. local function RI_RE()
  24.   RI = RA.getReactorInfo()
  25. end
  26. local r_s = true
  27. local fl = io.open("on.nfp","w")
  28. fl:write("   111e111\n 11011101110\ne1111e1011e10\n0111001010111\n11e111111001e\ne111011eee111\n1011011111011\n 11e1101e111\n   1110001")
  29. fl:close()
  30. fl = io.open("off.nfp","w")
  31. fl:write("   fffffff\n fffeeefffef\nffffffeefffff\nfffffffffffff\nfefffffffefff\nfffffffffeeff\nffffeefffffff\n fffffffffff\n   fffeeef")
  32. fl:close()
  33. fl = io.open("charge.nfp","w")
  34. fl:write("   bbbbbbb\n bbb3b99bbbb\nbbbbbbbbbbb3b\n3b9bbbbbbbbb9\n9bbb3bbb99bb9\nbbbbbbbbbbbb9\nbb99bbbb33bbb\n bbbb3bbbbbb\n   3bbbbb9")
  35. fl:close()
  36. fl = io.open("warn.nfp","w")
  37. fl:write("   0000100\n 000a0000a0e\n0000000100000\na0100000000a0\n0e01011100000\n101000a000100\n0000000100000\n 00a00000a00\n   0001e00")
  38. fl:close()
  39.  
  40. --vars
  41. local page = 1
  42. local bp = "nill"
  43. local sbp = true
  44. local ProgramVersion = "1.0"
  45. local status = RI["status"]
  46. local img_on = paintutils.loadImage("on.nfp")
  47. local img_charge = paintutils.loadImage("charge.nfp")
  48. local img_off = paintutils.loadImage("off.nfp")
  49. local img_warn = paintutils.loadImage("warn.nfp")
  50. local t_line
  51. local s_line
  52. local e_line
  53. local c_line
  54. local output_gate,input_gate = peripheral.find("flux_gate")
  55. --functions
  56. local function ev(b,st)
  57.   os.startTimer(1)
  58.   local event,button,x,y = os.pullEvent()
  59.   if event == "monitor_touch" then
  60.     if page == 1 then
  61.       if st == "warming_up" or st == "running" then
  62.         if x >= 38 and y >= 18 and x <= 46 and y <= 19 then
  63.           RA.stopReactor()  
  64.         end
  65.       elseif b == "start" then
  66.         if x >= 25 and y >= 18 and x <= 33 and y <= 19 then
  67.           RA.chargeReactor()
  68.         end
  69.       end
  70.       if b == "active" then
  71.         if x >= 25 and y >= 18 and x <= 33 and y <= 19 then
  72.           RA.activateReactor()
  73.         end
  74.      end
  75.     end
  76.   end
  77. end
  78. local function clearAll()
  79.   term.setBackgroundColor(colors.black)
  80.   term.setTextColor(colors.white)
  81.   paintutils.drawPixel(1,1,colors.black)
  82.   term.setCursorPos(1,1)
  83.   term.clear()
  84. end
  85.  
  86. local function default()
  87.   term.setBackgroundColor(colors.black)
  88.   term.setTextColor(colors.white)
  89.   term.setCursorPos(1,1)
  90. end
  91.  
  92. local function gFP()
  93.   return(math.floor((RI["fieldStrength"] / RI["maxFieldStrength"]) * 10000 + 0.5) / 10000)
  94. end
  95. local function gEP()
  96.   return(math.floor((RI["energySaturation"] / RI["maxEnergySaturation"]) * 10000 + 0.5) / 10000)
  97. end
  98. local function gFC()
  99.   return(math.floor((RI["fuelConversion"] / RI["maxFuelConversion"]) * 10000 + 0.5) / 10000)
  100. end
  101.  
  102. local FP = gFP()
  103. local EP = gEP()
  104. local FC = gFC()
  105.  
  106. local function drawAll()
  107.   clearAll()
  108.  
  109.   status = RI["status"]
  110.   paintutils.drawFilledBox(2,2,19,14,colors.gray)
  111.   term.setCursorPos(4,2)
  112.   term.setBackgroundColor(colors.white)
  113.   term.setTextColor(colors.black)
  114.   term.write(" STATUS ")
  115.   term.setTextColor(colors.white)
  116.   paintutils.drawBox(21,2,49,14,colors.gray)
  117.   term.setCursorPos(23,2)
  118.   term.setBackgroundColor(colors.black)
  119.   term.write(" INFO ")
  120.   paintutils.drawBox(2,16,49,25,colors.gray)
  121.   term.setCursorPos(4,16)
  122.   term.setBackgroundColor(colors.black)
  123.   term.write(" CONTROLS ")
  124.  
  125.   paintutils.drawLine(29,4,38,4,colors.gray)
  126.   term.setCursorPos(23,4)
  127.   term.setBackgroundColor(colors.black)
  128.   term.setTextColor(colors.orange)
  129.   term.write("Temp.")
  130.   term.setCursorPos(40,4)
  131.   term.write(RI["temperature"].."C")
  132.   paintutils.drawLine(29,6,38,6,colors.gray)
  133.   term.setCursorPos(23,6)
  134.   term.setBackgroundColor(colors.black)
  135.   term.setTextColor(colors.lightBlue)
  136.   term.write("Field")
  137.   term.setCursorPos(40,6)
  138.   term.write((tostring(FP * 100).."%"))
  139.   paintutils.drawLine(29,8,38,8,colors.gray)
  140.   term.setCursorPos(23,8)
  141.   term.setBackgroundColor(colors.black)
  142.   term.setTextColor(colors.green)
  143.   term.write("Energ.")
  144.   term.setCursorPos(40,8)
  145.   term.write((tostring(EP * 100).."%"))
  146.   paintutils.drawLine(29,10,38,10,colors.gray)
  147.   term.setCursorPos(23,10)
  148.   term.setBackgroundColor(colors.black)
  149.   term.setTextColor(colors.white)
  150.   term.write("Conv.")
  151.   term.setCursorPos(40,10)
  152.   term.write((tostring(FC * 100).."%"))
  153.  
  154.   term.setCursorPos(22,12)
  155.   term.setBackgroundColor(colors.black)
  156.   term.setTextColor(colors.red)
  157.   term.write("Generation Rate:"..RI["generationRate"].."rf/t")
  158.  
  159.   default()
  160.  
  161.   term.setTextColor(colors.gray)
  162.   term.write("status: ".. status)
  163.   term.setCursorPos(30,26)
  164.   term.write("Version "..ProgramVersion.." by OFgRc")
  165.  
  166.   if status == "cold" then
  167.     paintutils.drawImage(img_off,4,4)
  168.   elseif status == "warming_up" or status == "cooling" then
  169.     paintutils.drawImage(img_charge,4,4)
  170.   elseif status == "running" or status == "stopping" then
  171.     paintutils.drawImage(img_on,4,4)
  172.   elseif status == "beyond_hope" then
  173.     paintutils.drawImage(img_warn,4,4)
  174.   end          
  175.  
  176.   local rt = RI["temperature"]
  177.   local n = -1
  178.   if rt > 0 then n = n +1 end
  179.   if rt >= 1111 then n = n +1 end
  180.   if rt >= 2222 then n = n + 1 end
  181.   if rt >= 3333 then n = n + 1 end
  182.   if rt >= 4444 then n = n + 1 end
  183.   if rt >= 5555 then n = n + 1 end
  184.   if rt >= 6666 then n = n + 1 end
  185.   if rt >= 7777 then n = n + 1 end
  186.   if rt >= 8888 then n = n + 1 end
  187.   if rt >= 9999 then n = n + 1 end
  188.   n = 29 + n
  189.   if n > 29 then
  190.     paintutils.drawLine(29,4,n,4,colors.orange) end
  191.   n = -1
  192.   rt = FP * 100
  193.   if rt > 0 then n = n + 1 end
  194.   if rt >= 11 then n = n + 1 end
  195.   if rt >= 22 then n = n + 1 end
  196.   if rt >= 33 then n = n + 1 end
  197.   if rt >= 44 then n = n + 1 end
  198.   if rt >= 55 then n = n + 1 end
  199.   if rt >= 66 then n = n + 1 end
  200.   if rt >= 77 then n = n + 1 end
  201.   if rt >= 88 then n = n + 1 end
  202.   if rt >= 99 then n = n + 1 end
  203.   n = 29 + n
  204.   if n > 29 then
  205.     paintutils.drawLine(29,6,n,6,colors.lightBlue) end
  206.   n = -1
  207.   rt = EP * 100
  208.   if rt > 0 then n = n+1 end
  209.   if rt >= 11 then n = n+1 end
  210.   if rt >= 22 then n = n+1 end
  211.   if rt >= 33 then n = n+1 end
  212.   if rt >= 44 then n = n+1 end
  213.   if rt >= 55 then n = n+1 end
  214.   if rt >= 66 then n = n+1 end
  215.   if rt >= 77 then n = n+1 end
  216.   if rt >= 88 then n = n+1 end
  217.   if rt >= 99 then n = n+1 end
  218.   n = 29 +n
  219.   if n > 29 then
  220.     paintutils.drawLine(29,8,n,8,colors.green) end
  221.   n = -1
  222.   rt = FC * 100
  223.   if rt > 0 then n = n+1 end
  224.   if rt >= 11 then n = n+1 end
  225.   if rt >= 22 then n = n+1 end
  226.   if rt >= 33 then n = n+1 end
  227.   if rt >= 44 then n = n+1 end
  228.   if rt >= 55 then n = n+1 end
  229.   if rt >= 66 then n = n+1 end
  230.   if rt >= 77 then n = n+1 end
  231.   if rt >= 88 then n = n+1 end
  232.   if rt >= 99 then n = n+1 end
  233.   n = 29 + n
  234.   if n > 29 then
  235.     paintutils.drawLine(29,10,n,10,colors.white) end
  236.   term.setBackgroundColor(colors.black)
  237.   term.setTextColor(colors.blue)
  238.   term.setCursorPos(4,18)
  239.   term.write("Shield Flow:")
  240.   term.setCursorPos(4,19)
  241.   term.write(input_gate.getFlow() .. "rf/t")
  242.   term.setTextColor(colors.orange)
  243.   term.setCursorPos(4,21)
  244.   term.write("Geniration Flow:")
  245.   term.setCursorPos(4,22)
  246.   term.write(output_gate.getFlow() .. "rf/t")
  247.   default()
  248.  
  249.   if redstone.getInput("front") == true then
  250.     r_s = false
  251.   end
  252.   default()
  253.   if page == 1 then
  254.     if status == "cold" or status == "cooling" then
  255.       bp = "start"
  256.     elseif RI["temperature"] > 1999 and status == "warming_up" then
  257.       bp = "active"
  258.     elseif status == "stopping" then
  259.       bp = "active"
  260.     else
  261.       bp = "nill"
  262.     end
  263.     if status == "warming_up" or status == "running" then
  264.       paintutils.drawFilledBox(38,18,46,19,colors.red)
  265.       term.setCursorPos(38,18)
  266.       term.write("  Stop")
  267.       term.setCursorPos(38,19)
  268.       term.write(" Reactor")
  269.     end
  270.     if bp == "start" then
  271.       paintutils.drawFilledBox(25,18,33,19,colors.blue)
  272.       term.setCursorPos(25,18)
  273.       term.write("  Start")
  274.       term.setCursorPos(25,19)
  275.       term.write(" Reactor")
  276.     end
  277.     if  bp == "active" then
  278.       paintutils.drawFilledBox(25,18,33,19,colors.lime)
  279.       term.setCursorPos(25,18)
  280.       term.write("   Run")
  281.       term.setCursorPos(25,19)
  282.       term.write(" Reactor")
  283.     end
  284.   end
  285.   ev(bp,status)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
  286. end
  287. --run
  288. clearAll()
  289. while r_s == true do
  290.   RI_RE()
  291.   EP = gEP()
  292.   FP = gFP()
  293.   FC = gFC()
  294.   drawAll()
  295.   sleep(0.1)
  296. end
Add Comment
Please, Sign In to add comment