Advertisement
loepie

ReactorControl IC2

Mar 10th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local rp = "back"                       -- Location Reactor Redstone Port
  2. local rfp = "reactor_fluid_port_9"      -- Location Reactor Fluid Port
  3. local nr = "nuclear_reactor_3"          -- Location Reactor Access Hatch
  4. local IsActive = "PlaceHolder"         
  5. local ml = "right"                      -- Location Modem
  6. local server = "rs3"
  7.  
  8. term.clear()
  9.  
  10. function PreCheckModem()
  11.     print("function PreChecks modem check")
  12.     isOpenRednet = rednet.isOpen(ml)
  13.     if isOpenRednet == true then
  14.         print("function PreChecks Rednet is open")
  15.     elseif isOpenRednet == false then
  16.         rednet.open(ml)
  17.         isOpenRednet = rednet.isOpen(ml)
  18.         if isOpenRednet == true then
  19.             print("function PreChecks Rednet is open")
  20.         else
  21.             error("function PreChecks unable to open Rednet")
  22.         end
  23.     else
  24.         error("function PreChecks unknown error")
  25.     end
  26.     print("function PreChecks modem seems ok")
  27.     rednet.host("rctrl",server)
  28. end
  29.  
  30. function PreCheckPerfs()
  31.     print("Start peripheral checks")
  32.     if not peripheral.isPresent(nr) then
  33.         error("function PreCheckPerfs missing:"..nr)
  34.     elseif not peripheral.isPresent(rfp) then
  35.         error("function PreCheckPerfs missing:"..rfp)
  36.     end
  37.     print("All peripherals present")
  38. end
  39.  
  40. function TurnOn()
  41.   redstone.setOutput(rp, true)
  42. end
  43.  
  44. function TurnOff()
  45.   redstone.setOutput(rp, false)
  46. end
  47.  
  48. function Status()
  49.   IsActive = redstone.getOutput(rp)
  50.   return IsActive
  51. end
  52.  
  53. function WriteStatus()
  54.     if IsActive==false then
  55.         write("Reactor is inactive")
  56.     elseif IsActive==true then
  57.         write("Reactor is active")
  58.     else
  59.         write("Unknown reactor status")
  60.     end  
  61. end
  62.  
  63. function LiquidTanks()
  64.     tank = peripheral.wrap(rfp)
  65.     EmptyCounter = 0
  66.     while true do
  67.         term.clear()
  68.         term.setCursorPos(1,1)
  69.         tankI = tank.getTankInfo()
  70.         if tankI[2] == nil then
  71.             EmptyCounter = EmptyCounter + 1
  72.         else
  73.             EmptyCounter = 0
  74.             if tankI[1]["contents"]["name"] == "ic2coolant" then
  75.                 ic2c = tankI[1]
  76.             elseif tankI[1]["contents"]["name"] == "ic2hotcoolant" then
  77.                 ic2hc = tankI[1]
  78.             else
  79.                 error("Incorrect liquid in "..tankI[1]["contents"]["name"])
  80.             end
  81.             if tankI[2]["contents"]["name"] == "ic2coolant" then
  82.                 ic2c = tankI[2]
  83.             elseif tankI[2]["contents"]["name"] == "ic2hotcoolant" then
  84.                 ic2hc = tankI[2]
  85.             else
  86.                 error("Incorrect liquid in "..tankI[1]["contents"]["name"])
  87.             end
  88.             ic2cValueC = ic2c["contents"]["amount"]
  89.             ic2hcValueC = ic2hc["contents"]["amount"]
  90.             x = ic2cValueC / 10000 * 100
  91.             --print("Coolant for :"..math.floor(x).."% full")
  92.             if x < 50 then
  93.                 print("warning!! Coolant level below :"..math.floor(x).."% full")
  94.             else
  95.                 print("Coolant level is :"..math.floor(x).."% full")
  96.             end
  97.             y = ic2hcValueC / 10000 * 100
  98.             --print("Coolant for :"..math.floor(y).."% full")
  99.             if y > 50 then
  100.                 print("warning!! Hot Coolant level above :"..math.floor(y).."% full")
  101.             else
  102.                 print("Hot Coolant level is :"..math.floor(y).."% full")
  103.             end
  104.             sleep(0.5)
  105.         end
  106.     end
  107. end
  108.  
  109. -- Let's start the program
  110.  
  111. PreCheckModem()
  112. PreCheckPerfs()
  113.  
  114. local ok, err = pcall(LiquidTanks)
  115. if not ok then
  116.     TurnOff()
  117. end
  118.  
  119. while true do
  120.     term.clear()
  121.     write("1=Turnon,2=TurnOff,3=Status,q=Quit,t=tank info")
  122.     local answer = read()
  123. --  return answer
  124.     if answer=="1" then
  125.         TurnOn()
  126.         Status()
  127.         WriteStatus()
  128.     elseif answer=="2" then
  129.         TurnOff()
  130.         Status()
  131.         WriteStatus()
  132.     elseif answer== "3" then
  133.         Status()
  134.     if IsActive==false then
  135.         write("Reactor Inactive")
  136.         elseif IsActive==true then
  137.     write("Reactor active")
  138.     else
  139.         write("unknown status")
  140.     end
  141.     sleep(2)
  142.     elseif answer=="q" then
  143.         break
  144.     elseif answer=="t" then
  145.         LiquidTanks()
  146.         sleep(2)
  147.     else
  148.         print("wrong input")
  149.     end
  150.     answer = nil
  151. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement