Advertisement
Guest User

reactorControl

a guest
Oct 23rd, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.42 KB | None | 0 0
  1. -- Reactor Control software v0.1
  2.  
  3. local reactor
  4. local turbine
  5. local monitor
  6. local mode
  7. local max=1500
  8. local min=900
  9.  
  10. function initHardware()
  11.   local table=peripheral.getNames()
  12.   for i,p in pairs(table) do
  13.     local type=peripheral.getType(p)
  14.     if type=="BigReactors-Reactor" then
  15.       reactor=peripheral.wrap(p)
  16.     elseif type=="BigReactors-Turbine" then
  17.       turbine=peripheral.wrap(p)
  18.     elseif type=="monitor" then
  19.       monitor=peripheral.wrap(p)
  20.     end
  21.   end
  22.   if reactor==nil then
  23.     print("No reactor found")
  24.     exit()
  25.   elseif turbine==nil then
  26.     mode="Active"
  27.   else
  28.     mode="Passive"
  29.   end
  30.   print(mode.." cooling mode")
  31. end
  32.  
  33. function checkStatus()
  34.   if mode=="Active" then
  35.     if reactor.getActive() and turbine.getInductorEnabled() then
  36.       return "Active"
  37.     elseif reactor.getActive() then
  38.       return "Spooling up turbine"
  39.     elseif turbine.getInductorEnabled() then
  40.       return "Spooling down turbine"
  41.     else
  42.       return "Inactive"
  43.     end
  44.   elseif mode=="Passive" then
  45.     if reactor.getActive() then
  46.       return "Active"
  47.     else
  48.       return "Inactive"
  49.     end
  50.   end
  51. end
  52.  
  53. function start()
  54.   term.clear()
  55.   term.setCursorPos(1,1)
  56.   print("Initializing reactor")
  57.   reactor.setActive(true)
  58.   if not turbine.getActive() then
  59.     turbine.setActive(true)
  60.   end
  61.   print("Spooling up turbine")
  62.   local x,y=term.getCursorPos()
  63.   while turbine.getRotorSpeed()<min do
  64.     term.setCursorPos(x,y)
  65.     term.clearLine()
  66.     print(turbine.getRotorSpeed().."rpm")
  67.     sleep(1)
  68.   end
  69.   term.setCursorPos(x,y)
  70.   term.clearLine()
  71.   print("Engaging inductor")
  72.   turbine.setInductorEngaged(true)
  73.   print("Status: Active")
  74. end
  75.  
  76. function stop()
  77.   term.clear()
  78.   term.setCursorPos(1,1)
  79.   print("Shutting down reactor")
  80.   reactor.setActive(false)
  81.   print("Spooling down turbine")
  82.   local x,y=term.getCursorPos()
  83.   while turbine.getRotorSpeed()>max do
  84.     term.setCursorPos(x,y)
  85.     term.clearLine()
  86.     print(turbine.getRotorSpeed().." rpm")
  87.     sleep(1)
  88.   end
  89.   term.setCursorPos(x,y)
  90.   term.clearLine()
  91.   print("Disengaging turbine")
  92.   turbine.setInductorEngaged(false)
  93.   print("Status: Shutdown")
  94. end
  95.  
  96. term.clear()
  97. term.setCursorPos(1,1)
  98. initHardware()
  99. repeat
  100.   write("Input command: ")
  101.   line=read()
  102.   if line=="start" then
  103.     start()
  104.   elseif line=="stop" then
  105.     stop()
  106.   elseif line~="exit" then
  107.     print("Invalid command")
  108.   end
  109. until line=="exit"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement