LittleBlackA

Reactor API

Oct 10th, 2014
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.76 KB | None | 0 0
  1. -------------------------------
  2. --  Base monitoring Program  --
  3. -------------------------------
  4. -- Designed/Coded By:  audi9 --
  5. -------------------------------
  6. --      Version 0.1          --
  7. -------------------------------
  8. --      Changelog            --
  9. --      ----------           --
  10. --      V0.1: The beginning! --
  11. --     - Started It!         --
  12. --     - BigReactor Support  --
  13. --     - Focusing on mon     --
  14. --       buttons and such.   --
  15. --     - BigReactor controls --
  16. --       itself via an API   --
  17. -------------------------------
  18. --  Email Me for info at:    --
  19. -------------------------------
  20.  
  21. --/* This is reactor API */--
  22.  
  23. -- House Keeping
  24. mon = peripheral.wrap('right')
  25. reactor = peripheral.wrap('BigReactors-Reactor_3')
  26. mon.clear()
  27. xPos, yPos = mon.getSize()
  28. emptyflag=0
  29. offlineflag=0
  30. flashflag=0
  31.  
  32. local oldTime = os.time()
  33. local function sleepCheckin()
  34.     local newTime = os.time()
  35.     if newTime - oldTime >= (0.020 * 1.5) then
  36.             oldTime = newTime
  37.             sleep(10)
  38.     end
  39. end
  40. end
  41.  
  42. function Launch()
  43.     mon.clear()
  44.     while true do  
  45.         mon.setCursorPos(2,1)
  46.             mon.setTextColor(colors.white)
  47.             mon.write("Base Monitoring Program 0.1 (Alpha)")
  48.         mon.setCursorPos(1,2)
  49.             mon.write("--------------------------------------")
  50.         mon.setCursorPos(1,3)
  51.             mon.write("Home")
  52.         mon.setCursorPos(6,3)
  53.             mon.write(" > Power")
  54.         mon.setCursorPos(2,5)
  55.                  mon.write("Fuel Level:")
  56.         mon.setCursorPos(1,6)
  57.             mon.write("----------------")
  58.         mon.setCursorPos(1,7)
  59.             mon.setTextColor(colors.yellow)
  60.                 mon.write(math.floor(((reactor.getFuelAmount()/reactor.getFuelAmountMax())*100)+0.5).."% Fuel")
  61.         mon.setCursorPos(1,8)
  62.             mon.setTextColor(colors.lightBlue)
  63.                 mon.write(math.floor(((reactor.getWasteAmount()/reactor.getFuelAmountMax())*100)+0.5).."% Waste")
  64.                
  65.         mon.setCursorPos(2,10)
  66.             mon.setTextColor(colors.white)
  67.                  mon.write("Control Rod Levels:")
  68.         mon.setCursorPos(1,11)
  69.             mon.write("---------------------")         
  70.         mon.setTextColor(colors.green)
  71.             mon.setCursorPos(1,12)
  72.                 mon.write('Rod 1:  '..(100-(reactor.getControlRodLevel(0)))..'% Depth')            
  73.             mon.setCursorPos(1,13)
  74.                 mon.write('Rod 2:  '..(100-(reactor.getControlRodLevel(1)))..'% Depth')            
  75.             mon.setCursorPos(1,14)
  76.                 mon.write('Rod 3:  '..(100-(reactor.getControlRodLevel(2)))..'% Depth')            
  77.             mon.setCursorPos(1,15)
  78.                 mon.write('Rod 4:  '..(100-(reactor.getControlRodLevel(3)))..'% Depth')            
  79.             mon.setCursorPos(1,16)
  80.                 mon.write('Rod 5:  '..(100-(reactor.getControlRodLevel(4)))..'% Depth')
  81.                
  82.         mon.setCursorPos(2,18)
  83.             mon.setTextColor(colors.white)
  84.                  mon.write("Temperature:")
  85.         mon.setCursorPos(1,19)
  86.             mon.write("----------------")  
  87.         mon.setCursorPos(1,20)
  88.             mon.setTextColor(colors.lightGray)
  89.                 mon.write('Casing: ')
  90.                     if reactor.getCasingTemperature()>=650 then
  91.                         mon.setTextColor(colors.purple)
  92.                             else if reactor.getCasingTemperature()>=950 then
  93.                                 mon.setTextColor(colors.red)
  94.                                 else
  95.                                     mon.setTextColor(colors.green)
  96.                             end
  97.                     end
  98.                    
  99.                     mon.write(reactor.getCasingTemperature()..'C')
  100.                    
  101.         mon.setCursorPos(1,21)
  102.            mon.setTextColor(colors.yellow)
  103.                 mon.write('Fuel: ')
  104.                     if reactor.getFuelTemperature()>=650 then
  105.                         mon.setTextColor(colors.purple)
  106.                             else if reactor.getFuelTemperature()>=950 then
  107.                                 mon.setTextColor(colors.red)
  108.                                 else
  109.                                     mon.setTextColor(colors.green)
  110.                             end
  111.                     end
  112.                    
  113.                     mon.write(reactor.getFuelTemperature()..'C')
  114.                    
  115.         mon.setCursorPos(2,23)
  116.             mon.setTextColor(colors.white)
  117.                  mon.write("Flux:")
  118.         mon.setCursorPos(1,24)
  119.             mon.write("----------------")
  120.                 mon.setTextColor(colors.green)
  121.                     mon.setCursorPos(1,25)
  122.                         mon.write(reactor.getEnergyStored()..' RF Stored      ')
  123.                             if reactor.getEnergyProducedLastTick()>=500 and reactor.getEnergyProducedLastTick()<2000 then
  124.                                 mon.setTextColor(colors.orange)
  125.                             end
  126.                                            
  127.                             if reactor.getEnergyProducedLastTick()>=2000 then
  128.                                 mon.setTextColor(colors.red)
  129.                             end
  130.                            
  131.                             mon.write((math.floor(reactor.getEnergyProducedLastTick()+0.5))..'RF/t')
  132.                     if flashflag==0 then
  133.                         flashflag=1
  134.                             if offlineflag==1 then
  135.                                 mon.setCursorPos(1,27)
  136.                                     mon.setTextColor(colors.lightGray)
  137.                                         mon.write('OFFLINE - Manual Override')
  138.                             end
  139.                            
  140.                             if emptyflag==1 then
  141.                                 mon.setCursorPos(1,27)
  142.                                     mon.setTextColor(colors.pink)
  143.                                         mon.write('OFFLINE - Fuel Exhausted')
  144.                             end
  145.                                                
  146.                             if emptyflag==0 and offlineflag==0 and reactor.getControlRodLevel(0)>75 then
  147.                                 mon.setCursorPos(1,27)
  148.                                     mon.setTextColor(colors.yellow)
  149.                                         mon.write('ONLINE - Low Power Mode')
  150.                             end
  151.                                                
  152.                             if emptyflag==0 and offlineflag==0 and reactor.getControlRodLevel(0)<=75 then
  153.                                 mon.setCursorPos(1,27)
  154.                                     mon.setTextColor(colors.orange)
  155.                                         mon.write('ONLINE - High Power Mode')
  156.                             end
  157.                         else
  158.                             flashflag=0
  159.                                 mon.setCursorPos(1,27)
  160.                                     mon.clearLine()
  161.                         end
  162.  
  163.                         if reactor.getEnergyStored()<=10000000 and reactor.getEnergyStored()>100 then
  164.                             reactor.setAllControlRodLevels(0+(math.floor(reactor.getEnergyStored()/100000)))
  165.                             else
  166.                                 reactor.setAllControlRodLevels(0)
  167.                         end
  168.  
  169.                         if reactor.getFuelAmount()<=100 and offlineflag==0 then
  170.                             reactor.setAllControlRodLevels(100)
  171.                                 reactor.setActive(false)
  172.                                     emptyflag=1
  173.                             else
  174.                                 emptyflag=0
  175.                         end
  176.      
  177.                         if rs.getInput('bottom')==false and emptyflag==0 then
  178.                             reactor.setActive(true)
  179.                                     offlineflag=0
  180.                         end
  181.  
  182.                         if rs.getInput('bottom')==true and emptyflag==0 then
  183.                             reactor.setActive(false)
  184.                                 reactor.setAllControlRodLevels(100)
  185.                                     offlineflag=1
  186.                         end
  187.         end
  188.  
  189.             else
  190.                 sleepCheckin()
  191.     end
  192. end
Advertisement
Add Comment
Please, Sign In to add comment