Advertisement
Guest User

ras

a guest
May 24th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.54 KB | None | 0 0
  1. -- CHANGE THIS BASED ON MONITOR LOCATION
  2. local monitorLoc = "left"
  3.  
  4. -- PASSIVE COOLED REACTOR
  5. -- DETERMINES ACTIVATION AND CUTOFF PERCENT
  6. local activatePercent = 90.00
  7. local cutoffPercent = 99.20
  8.  
  9. -- ACTIVE COOLED REACTOR
  10. -- DETERMINES ACTIVATION AND CUTOFF TEMPERATURE
  11. local cutoffTemp = 6000.00
  12. local activateTemp = 800.00
  13.  
  14. -- REACTOR AND MONITOR VARIABLE
  15. local reactor
  16. local monitor
  17.  
  18. -- Reactor Vars
  19. -- DO NOT MODIFY
  20. local isActiveCooled
  21. local isActive
  22. local controlRods
  23. local energyStored
  24. local percentFull
  25. local fuelTemp
  26. local caseTemp
  27. local fuelAmount
  28. local wasteAmount
  29. local fuelMax
  30. local fuelPercent
  31. local energyProduced
  32. local hotFluidProduced
  33. local hotFluidStored
  34. local coolantStored
  35.  
  36. local compStart = false
  37.  
  38. -- getDevices(device): Get device specified by parameter (reactor, monitor)
  39. function getDevices(device)
  40.   local perList = peripheral.getNames()
  41.  
  42.   device = device:lower()
  43.  
  44.   for perIndex = 1, #perList do
  45.     if (string.lower(peripheral.getType(perList[perIndex])) == device) then
  46.       return peripheral.wrap(perList[perIndex])
  47.     end --if statement
  48.   end --for perIndex = 1
  49. end --getDevices
  50.  
  51. function write(message, clear, line, col, color)
  52.   if (line == nil) and (col == nil) and (color == nil) then
  53.     --clearLine(clear)
  54.     monitor.write(message)
  55.   else if (color == nil) then
  56.     monitor.setCursorPos(col, line)
  57.     clearLine(clear)
  58.     monitor.write(message)
  59.   else
  60.     if (line ~= 0) and (col ~= 0) then
  61.       monitor.setCursorPos(col, line)
  62.       clearLine(clear)
  63.     end
  64.     monitor.setTextColor(color)
  65.     monitor.write(message)
  66.     monitor.setTextColor(colors.white)
  67.   end
  68. end
  69. end
  70.  
  71. function clearLine(clear)
  72.   if clear then
  73.     monitor.clearLine()
  74.   end
  75. end
  76.  
  77. function roundOne(num)
  78.   return math.floor(num * 10) * 0.1
  79. end
  80.  
  81. function roundTwo(num)
  82.   return math.floor(num * 100) * 0.01
  83. end
  84.  
  85. --sleep(5)
  86.  
  87. reactor = getDevices("BigReactors-Reactor")
  88.  
  89. monitor = peripheral.wrap(monitorLoc)
  90. monitor.setTextScale(1)
  91. monitor.clear()
  92. monitor.setCursorPos(1,1)
  93.  
  94. -- Setting text to RED and writing intro
  95. write("Reactor Analisys System", true, 1, 1, colors.red)
  96.  
  97. -- Drawing line across screen
  98. monitor.setCursorPos(1,2)
  99. clearLine(true)
  100. for i = 1, 60 do
  101.   write("-", false, 2, i, colors.blue)
  102. end
  103.  
  104. function queryReactor()
  105.   isActiveCooled = reactor.isActivelyCooled();
  106.   isActive = reactor.getActive()
  107.   controlRods = reactor.getNumberOfControlRods()
  108.   fuelTemp = roundOne(reactor.getFuelTemperature())
  109.   caseTemp = roundOne(reactor.getCasingTemperature())
  110.   fuelAmount = math.floor(reactor.getFuelAmount())
  111.   fuelMax = math.floor(reactor.getFuelAmountMax())
  112.   fuelPercent = roundTwo((fuelAmount / fuelMax) * 100)
  113.   wasteAmount = math.floor(reactor.getWasteAmount())
  114.  
  115.   if isActiveCooled then
  116.     hotFluidStored = reactor.getHotFluidAmount()
  117.     coolantStored = reactor.getCoolantAmount()
  118.     hotFluidProduced = reactor.getHotFluidProducedLastTick()
  119.   else
  120.     energyStored = math.floor(reactor.getEnergyStored())
  121.     percentFull = roundTwo((energyStored / 10000000.0) * 100)
  122.     energyProduced = roundTwo(reactor.getEnergyProducedLastTick())
  123.   end
  124.  
  125.   if isActiveCooled then
  126.     if (isActive == false) and (caseTemp < activateTemp) then
  127.       reactor.setActive(true)
  128.       compStart = true
  129.     end
  130.     if (isActive == true) and (compStart == true) and (caseTemp >= cutoffTemp) then
  131.       reactor.setActive(false)
  132.       compStart = false
  133.     end
  134.   end
  135. end
  136.  
  137. function statusLoop()
  138.   -- Primary loop
  139.   while true do
  140.      queryReactor()
  141.    
  142.     -- Active Status
  143.     write("Reactor Status: ", true, 3, 1)
  144.     if isActive then
  145.       write("ONLINE", false, 0, 0, colors.green)
  146.     else
  147.       write("OFFLINE", false, 0, 0, colors.red)
  148.     end
  149.    
  150.     if isActiveCooled == false then
  151.       -- Current Stored Energy
  152.       write("Current Stored Energy: ", true, 4, 1)
  153.       write(energyStored.." RF", false, 0,0, colors.orange)
  154.    
  155.       -- Percentage full
  156.       write("Energy Buffer Percentage: ", true, 5, 1)
  157.       write(roundTwo(percentFull).."%", false, 0,0, colors.orange)
  158.     else
  159.       -- Current Stored Coolant
  160.       write("Current Stored Coolant: ", true, 4, 1)
  161.       write(coolantStored.." mB", false, 0,0, colors.orange)
  162.      
  163.       -- Current Stored Hot Fluid
  164.       write("Current Stored Hot Fluid: ", true, 5, 1)
  165.       write(hotFluidStored.." mB", false, 0,0, colors.orange)
  166.     end
  167.    
  168.     -- Fuel Temp
  169.     write("Fuel Temperature: ", true, 6, 1)
  170.     write(roundOne(fuelTemp).." C", false, 0,0, colors.purple)
  171.    
  172.     -- Case Temp
  173.     write("Case Temperature: ", true, 7, 1)
  174.     write(roundOne(caseTemp).. " C", false, 0,0, colors.purple)
  175.    
  176.     -- Fuel Remaining
  177.     write("Fuel Amount: ", true, 8, 1)
  178.     write(math.floor(fuelAmount).." mB", false, 0,0, colors.yellow)
  179.    
  180.     -- Fuel Percentage
  181.     write("Percentage Remaining: ", true, 9, 1)
  182.     write(roundTwo(fuelPercent).."%", false, 0,0, colors.yellow)
  183.    
  184.     -- Waste Amount
  185.     write("Waste Amount: ", true, 10, 1)
  186.     write(wasteAmount.." mB", false, 0,0, colors.cyan)
  187.    
  188.     if isActiveCooled then
  189.       -- Steam Produced
  190.       write("Steam Produced: ", true, 11, 1)
  191.       write(hotFluidProduced.." mB/t", false, 0,0, colors.orange)
  192.     else
  193.       -- Energy Produced
  194.       write("Energy Produced: ", true, 11, 1)
  195.       write(roundTwo(energyProduced).." RF/t", false, 0,0, colors.orange)
  196.     end
  197.    
  198.     sleep(1)
  199.   end
  200. end
  201.  
  202. function menuLoop()
  203.   print("Terminal Output")
  204.   event, key = os.pullEvent("key")
  205.   return;
  206. end
  207.  
  208. --parallel.waitForAll(menuLoop(), statusLoop())
  209. statusLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement