Advertisement
Shuudoushi

test program

Jan 20th, 2015
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.76 KB | None | 0 0
  1. local component = require("component")
  2. local computer = require("computer")
  3. local string = require("string")
  4. local r1 = component.br_reactor
  5. local term = require("term")
  6. local os = require("os")
  7. local event = require("event")
  8. local kb = require("keyboard")
  9. local unicode = require("unicode")
  10. local running = true
  11. local X = r1.getNumberOfControlRods()
  12. local coolantType = r1.getCoolantType()
  13. local hotFluidType = r1.getHotFluidType()
  14. local commandInput = ""
  15.  
  16. local function round(num, idp)
  17.     local mult = 10^(idp or 0)
  18.     return math.floor(num * mult + 0.5) / mult
  19. end
  20.  
  21. local function rodsList()
  22.     for i = 0,X-1 do
  23.         print("Control Rod " .. r1.getControlRodName(i) .. ": " .. r1.getControlRodLevel(i) .. "% Insertion")
  24.     end
  25. end
  26.  
  27. local function theSplit(inputstr, sep)
  28.         if sep == nil then
  29.             sep = "%s"
  30.         end
  31.         local t={} ; i=1
  32.         for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  33.             t[i] = str
  34.             i = i + 1
  35.         end
  36.     return t
  37. end
  38.  
  39. local function activeCool()
  40.     if coolantType == nil then
  41.         local coolantType = "None"
  42.     end
  43.  
  44.     if hotFluidType == nil then
  45.         local hotFluidType = "None"
  46.     end
  47.  
  48.     if r1.isActivelyCooled() == false then
  49.         print("Max Coolant Amount: " .. r1.getCoolantAmountMax())
  50.         print("Current Coolant Amount: " .. round(r1.getCoolantAmount(), 2))
  51.         print("Coolant: " .. coolantType)
  52.         print("Max Hot Fluid: " .. r1.getHotFluidAmountMax())
  53.         print("Current Hot Fluid: " .. round(r1.getHotFluidAmount(), 2))
  54.         print("Hot Fluid Type: " .. hotFluidType)
  55.     end
  56. end
  57.  
  58. local function ui()
  59.     term.clear()
  60.     term.setCursor(1,1)
  61.     term.write("Reactor Status: ")
  62.  
  63.     if r1.getActive("true") then
  64.         component.gpu.setForeground(0x008000)
  65.         status = "Online"
  66.     else
  67.         component.gpu.setForeground(0xFF0000)
  68.         status = "Offline"
  69.     end
  70.  
  71.     term.write(status)
  72.     component.gpu.setForeground(0xFFFFFF)
  73.     term.setCursor(1,2)
  74.     term.write("Core Temp: " .. round(r1.getFuelTemperature(), 2) .. " " .. unicode.char(248) .. "C")
  75.     term.setCursor(1,3)
  76.     term.write("Case Temp: " .. round(r1.getCasingTemperature(), 2) .. " " .. unicode.char(248) .. "C")
  77.     term.setCursor(1,4)
  78.     term.write("Energy Buffer: " .. round(r1.getEnergyStored(), 2) .. " RF")
  79.     term.setCursor(1,5)
  80.     term.write("Energy Output: " .. round(r1.getEnergyProducedLastTick(), 2) .. " RF/t")
  81.     term.setCursor(1,6)
  82.     term.write("Fuel Reactivity: " .. round(r1.getFuelReactivity(), 2) .. "%")
  83.     term.setCursor(1,7)
  84.     term.write("Max Fuel: " .. round(r1.getFuelAmountMax(), 2) .. " mB")
  85.     term.setCursor(1,8)
  86.     term.write("Remaining Fuel: " .. round(r1.getFuelAmount(), 2) .. " mB")
  87.     term.setCursor(1,9)
  88.     term.write("Fuel Consumtion: " .. round(r1.getFuelConsumedLastTick(), 3) .. " mB/t")
  89.     term.setCursor(1,10)
  90.     term.write("Waste: " .. round(r1.getWasteAmount(), 2) .. " mB")
  91.     term.setCursor(1,11)
  92.     term.write("Number of Control Rods: " .. X)
  93.     term.setCursor(1,12)
  94.     activeCool()
  95.     rodsList()
  96. end
  97.  
  98. local function rodControl(rodNum, percent)
  99.     local rodNum = rodNum - 1
  100.  
  101.     if rodNum >= 0 and rodNum <= X then
  102.         r1.setControlRodLevel(rodNum, percent)
  103.     else
  104.         print("Invald rod Number. Rods numbered as 1~" .. X .. ".")
  105.         os.sleep(2.5)
  106.     end
  107. end
  108.  
  109. local function inputKey()
  110.     term.setCursor(1,3)
  111.     term.write("Command Key: ")
  112.     term.setCursor(1,4)
  113.     term.write("back - Returns to the Status screen.")
  114.     term.setCursor(65,4)
  115.     term.write("rod <1~" .. X .. "> <0~100> - Sets rod X to X% insertion.")
  116.     term.setCursor(1,5)
  117.     term.write("exit - Exits the program, but leaves the reactor running.")
  118.     term.setCursor(65,5)
  119.     term.write("stop - Shuts the reator down.")
  120.     term.setCursor(1,6)
  121.     term.write("start - Starts the reactor.")
  122.     term.setCursor(65,6)
  123.     term.write("setAll <0~100> - Sets all control rods to X.")
  124.     term.setCursor(10,1)
  125. end
  126.  
  127. local function userInput()
  128.     _, _, _, c = event.pull(0.5, "key_down")
  129.  
  130.     if c == kb.keys.enter or c == kb.keys.numpadenter then
  131.     term.clear()
  132.     term.setCursor(1,1)
  133.     term.write("Command: ")
  134.     inputKey()
  135.     commandInput = term.read()
  136.     commandInput = string.gsub(commandInput, "\n", "")
  137. end
  138.  
  139.   if commandInput == "stop" then
  140.     r1.setActive(false)
  141.     ui()
  142.   end
  143.  
  144.   if commandInput == "start" then
  145.     r1.setActive(true)
  146.     ui()
  147.   end
  148.  
  149.   if commandInput == "exit" then
  150.     term.clear()
  151.     term.setCursor(1,1)
  152.     running = false
  153.   end
  154.  
  155.   if commandInput == "back" then
  156.     ui()
  157.   end
  158.  
  159.   if string.match(commandInput, "rod") then
  160.     local output = theSplit(commandInput, " ")
  161.     rod = tonumber(output[2])
  162.     percent = tonumber(output[3])
  163.     output = ""
  164.     commandInput = ""
  165.     rodControl(rod, percent)
  166.     ui()
  167.   end
  168.  
  169.   if string.match(commandInput, "setAll") then
  170.     local output = theSplit(commandInput, " ")
  171.     percentAll = tonumber(output[2])
  172.     r1.setAllControlRodLevels(percentAll)
  173.     output = ""
  174.     commandInput = ""
  175.     ui()
  176.   end
  177. end
  178.  
  179. while running do
  180.     ui()
  181.     userInput()
  182. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement