SHARE
TWEET

simple

a guest Jul 16th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- This code is fucked. Use a 3x2 monitor.
  2. local progVer = "420.69"
  3. local progName = " Ass Eater"
  4. local loopTime = 2 -- Time between program loops, in seconds. Increase this value if program somehow causes a lot of lag. Which should not happen on any computers made this century
  5. local baseControlRodLevel = 1 -- Put this as close to what you guess the optimum control rod level will be for your reactor, plus a little more
  6. local minStoredEnergyPercent = 15 -- Min energy % to store before activating, probably keep it at default (20)
  7. local maxStoredEnergyPercent = 94 -- Max energy % to store before shutdown, probably keep it at default (70)
  8. --Can't for the life of me regulate temperature, may try again later with the following two lines
  9. local minReactorTemp = 20 -- Minimum reactor temperature (^C) to maintain
  10. local maxReactorTemp = 400 -- Maximum reactor temperature (^C) to maintain
  11. local reactorTemp = 380 -- initializing variable
  12. local currentRodLevel = baseControlRodLevel
  13. ----------
  14.  
  15. -- Basic side determination for wrapping
  16. function getDeviceSide(deviceType)
  17.     deviceType = deviceType:lower()
  18.    
  19.     for i, side in pairs(rs.getSides()) do
  20.         if (peripheral.isPresent(side)) then
  21.             if (string.lower(peripheral.getType(side)) == deviceType) then
  22.                 return side;
  23.             end
  24.         end
  25.     end
  26.    
  27.     return nil;
  28. end
  29.  
  30. -- Peripheral wrapping function
  31. function wrapThis(thing, f)
  32.     local wrapped = nil
  33.     while wrapped == nil and f <= 100 do
  34.         wrapped = peripheral.wrap(thing.."_"..f)
  35.         f = f + 1
  36.     end
  37.  
  38.     if wrapped == nil then
  39.         side = getDeviceSide(thing)
  40.         if side ~= nil then
  41.             return peripheral.wrap(side)
  42.         else
  43.             return nil
  44.         end
  45.     else
  46.         return wrapped
  47.     end
  48. end
  49.  
  50.  
  51. print("Initializing program...",1,1);
  52.  
  53. -- Initialize the monitor
  54. -- If it can't find a monitor, just wait 5 seconds then reboot
  55. -- This covers server restarts, and waits for modems to boot up
  56. local monitor = wrapThis("monitor", 0)
  57. if monitor == nil then
  58.     sleep(5)
  59.     finished = true
  60.     os.reboot()
  61. end
  62. local monitorx, monitory = monitor.getSize()
  63. if monitorx ~= 29 or monitory ~= 12 then
  64.     print("Monitor is the wrong size! Needs to be 3x2.")
  65.     sleep(5)
  66.     finished = true
  67.     os.reboot()
  68. end
  69.  
  70. -- Connect to the big reactor peripheral
  71. -- If it can't find a reactor,  wait 5 seconds then reboot
  72. -- This is needed for server restarts when the computer starts up before the modem does
  73. local reactor = wrapThis("BigReactors-Reactor", 0)
  74. if reactor == nil then
  75.     sleep(5)
  76.     finished = true
  77.     os.reboot()
  78. end
  79.  
  80. -- Easyprint, saves program space elsewhere
  81. local function print(str, x, y)
  82.     term.setCursorPos(x, y)
  83.     term.write(str)
  84. end
  85.  
  86. -- Move stuff to monitor
  87. --if  monitor then
  88. --  sleep(1)
  89. --  term.clear()
  90. --  term.setCursorPos(1,1)
  91. --  term.write("Display redirected to Monitor. Type r to reboot, or")
  92. --  term.setCursorPos(1,2)
  93. --  term.write("q to quit and return control to this terminal.")
  94. --  term.redirect(monitor)
  95. --end
  96.  
  97. -- Restore functions to computer terminal
  98. function restoreNativeTerminal()
  99.     repeat
  100.         term.restore()
  101.         local w, h = term.getSize()
  102.     until w == 51 and h == 19
  103. end
  104.  
  105. -- Draw some decorative lines
  106. function drawLines()
  107.     term.setBackgroundColor(colors.black)
  108.     paintutils.drawLine(1, 2, 29, 2, colors.lightBlue)
  109.     paintutils.drawLine(1, 7, 29, 7, colors.lightBlue)
  110.     term.setBackgroundColor(colors.black)
  111. end
  112.  
  113. -- Just to make sure they're relatively high before the control program starts
  114. if  reactor then
  115.     sleep(1)
  116.     reactor.setAllControlRodLevels(baseControlRodLevel)
  117. else
  118.     sleep(5)
  119.     finished = true
  120.     os.reboot()
  121. end
  122.  
  123. -- Draw stuff on the monitor
  124. local function drawInfo()
  125.  
  126.     statusstring = "Reactor status: "
  127.     tempstring = "Temperature: "
  128.     tempstring2 = "deg. C"
  129.     powerstring = "Power Output: "
  130.     powerstring2 = "RF/t"
  131.     rodstring = "Control Rods: "
  132.     rodstring2 = "%"
  133.        
  134.     monitor.setTextColor(colors.green)
  135.     print(progName,5,1)
  136.     monitor.setTextColor(colors.red)
  137.     print("v",19,1)
  138.     monitor.setTextColor(colors.green)
  139.     print(progVer,20,1)
  140.     monitor.setTextColor(colors.white)
  141.        
  142.     print(statusstring,1,3)
  143.     if reactor.getActive() then
  144.         monitor.setTextColor(colors.green)
  145.         print(" online",23,3)
  146.     else
  147.         monitor.setTextColor(colors.red)
  148.         print("offline",23,3)
  149.     end
  150.        
  151.     monitor.setTextColor(colors.white)
  152. --reactortemp = math.floor(reactor.getFuelTemperature())
  153.     print(tempstring,1,4)
  154.     print(reactortemp,16,4)
  155.     print(tempstring2,24,4)
  156.        
  157.     power = math.floor(reactor.getEnergyProducedLastTick())
  158.     print(powerstring,1,5)
  159.     print(power,16,5)
  160.     print(powerstring2,26,5)
  161.  
  162.     rods = reactor.getControlRodLevel(1)
  163.     print(rodstring,1,6)
  164.     print(rods,16,6)
  165.     print(rodstring2,29,6)
  166. end
  167.  
  168. -- Draw stuff on the bottom part of the monitor, power bar etc
  169. function drawBottomPart()
  170.        sleep(5)
  171.        --   reactivity = math.floor(reactor.getFuelReactivity())
  172.        -- paintutils.drawLine(2, 9, 28, 9, colors.gray)
  173.        -- if reactivity > 400 then
  174.          -- paintutils.drawLine(2, 9, math.floor(26*reactivity/500)+1, 9, colors.red)
  175.        -- elseif reactivity > 320 then
  176.        --         paintutils.drawLine(2, 9, math.floor(26*reactivity/500)+1, 9, colors.orange)
  177.        -- elseif reactivity > 240 then
  178.        --         paintutils.drawLine(2, 9, math.floor(26*reactivity/500)+1, 9, colors.yellow)
  179.        -- elseif reactivity > 160 then
  180.        --         paintutils.drawLine(2, 9, math.floor(26*reactivity/500)+1, 9, colors.green)
  181.        -- elseif reactivity > 0 then
  182.        --         paintutils.drawLine(2, 9, math.floor(26*reactivity/500)+1, 9, colors.blue)
  183.        -- end
  184.         term.setBackgroundColor(colors.black)
  185.         print("Fuel Reactivity:",1,8)
  186.        -- print(reactivity,24,8)
  187.         print("%",29,8)
  188.         term.setBackgroundColor(colors.black)
  189.     sleep(5)   
  190.     energystorage = reactor.getEnergyStored()
  191.     storagepercent = math.floor(energystorage/10000000*100)
  192.     paintutils.drawLine(2, 12, 28, 12, colors.gray)
  193.     if storagepercent > 4 then
  194.         paintutils.drawLine(2, 12, math.floor(26*storagepercent/100)+2, 12, colors.yellow)
  195.     elseif storagepercent > 0 then
  196.         paintutils.drawPixel(2,12,colors.yellow)
  197.     end
  198.     term.setBackgroundColor(colors.black)
  199.     print("Internal buffer: ",1,11)
  200.     print(storagepercent,24,11)
  201.     print("%",29,11)
  202.     term.setBackgroundColor(colors.black)
  203. end
  204.  
  205. -- Controls the reactor, keeping it between configured temps and power storage
  206. function control()
  207.     energystorage = reactor.getEnergyStored()
  208. --  reactortemp = math.floor(reactor.getFuelTemperature())
  209.     ediff = (maxStoredEnergyPercent - minStoredEnergyPercent)*100000
  210.     ediffper = ediff / 100
  211.     if energystorage > maxStoredEnergyPercent*100000 then
  212.         reactor.setActive(false)
  213.     reactor.setAllControlRodLevels(reactor.getControlRodLevel(1)+1)
  214.     elseif energystorage < minStoredEnergyPercent*100000 then
  215.         reactor.setActive(true)
  216.         reactor.setAllControlRodLevels(reactor.getControlRodLevel(1)-1)
  217.     elseif energystorage > minStoredEnergyPercent*100000 then
  218.         reactor.setActive(true)
  219.         blarg = energystorage - minStoredEnergyPercent*100000
  220.         blarg2 = math.floor(blarg/(ediffper+1))
  221.         reactor.setAllControlRodLevels(blarg2)
  222.     end
  223. end
  224.  
  225. -- Main program
  226. function main()
  227.     while not finished do
  228.         if reactor.getConnected() then
  229.             drawLines()
  230.             drawInfo()
  231.             drawBottomPart()
  232.             control()
  233.             sleep(loopTime)
  234.         end
  235.     end
  236. end
  237.  
  238. -- Event handler for exiting, editting and debugging
  239. function eventHandler()
  240.     while not finished do
  241.         event, arg1, arg2, arg3 = os.pullEvent()
  242.         if event == "char" and not inManualMode then
  243.             local ch = string.lower(arg1)
  244.             if ch == "q" then
  245.                 finished = true
  246.             elseif ch == "r" then
  247.                 finished = true
  248.                 os.reboot()
  249.             end
  250.         end
  251.     end
  252. end
  253.  
  254. while not finished do
  255.     parallel.waitForAny(eventHandler, main)
  256.     sleep(loopTime)
  257. end
  258.  
  259. -- Returns control to the terminal if the program has an error or whatever
  260. term.clear()
  261. term.setCursorPos(1,1)
  262. restoreNativeTerminal()
  263. term.clear()
  264. term.setCursorPos(1,1)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top