Advertisement
jamawie

Reactor+Turbine

May 23rd, 2015
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.63 KB | None | 0 0
  1. --Program made by jamawie
  2. -------------------------
  3. reactor     = peripheral.wrap("BigReactors-Reactor_12")
  4. turbine     = peripheral.wrap("BigReactors-Turbine_9")
  5. mon         = peripheral.wrap("back")
  6. speaker     = peripheral.wrap("right")
  7. reactivity  = 10 --standard: 50
  8. speakDelay = 60 -- 1==0.5 Seconds
  9. -------------------------
  10.  
  11. local maxTemp = 2500
  12. local maxEnergy = 1000000
  13. local maxHotFluidReactor = math.floor(reactor.getHotFluidAmountMax()/100)*50
  14. local maxEnergyTurbine = math.floor(maxEnergy/100)*80
  15. local x,y = mon.getSize()
  16. local turbineOn = true
  17. local systemOnlineOffline = "offline"
  18. local reactorOnlineOffline= false
  19. local processEnergy = math.floor(maxEnergy/x-2)
  20. local processFuel = math.floor(reactor.getFuelAmountMax()/x-2)
  21. local delay = 0
  22.  
  23. -------------------------
  24.  
  25. function actualising()
  26.     turbineEnergyStored         = turbine.getEnergyStored()
  27.     turbineRotorSpeed           = turbine.getRotorSpeed()
  28.     turbineFluidFlowRate        = turbine.getFluidFlowRateMaxMax()
  29.     turbinePowerOutput          = turbine.getEnergyProducedLastTick()
  30.     turbinePowerPercent         = math.floor(turbine.getEnergyStored()/maxEnergy)*100
  31.     turbinePowerProcess         = math.floor(turbine.getEnergyStored()/processEnergy)
  32.    
  33.     reactorCasingTemperature    = reactor.getCasingTemperature()
  34.     reactorHotFluid             = reactor.getHotFluidAmount()
  35.     reactorFluidPercent         = math.floor(reactor.getFuelAmount()/reactor.getFuelAmountMax())*100
  36.     reactorFluidProcess         = math.floor(reactor.getFuelAmount()/processFuel)
  37.    
  38.     turbineInductionCoilsOnOff  = turbine.getInductorEngaged()
  39. end
  40.  
  41. function reactorF()
  42.     if not reactor.getActive() then
  43.         reactor.setActive(true)
  44.     end
  45.     if reactorHotFluid<=5000 and reactorCasingTemperature<=400 then
  46.         reactor.setAllControlRodLevels(reactivity)
  47.         reactorOnlineOffline = true
  48.     else
  49.         reactor.setAllControlRodLevels(100)
  50.         reactorOnlineOffline = false
  51.     end
  52. end
  53.  
  54. function turbineF()
  55.     if turbineEnergyStored <=100000 then
  56.         turbineOn=true
  57.     elseif turbineEnergyStored >= maxEnergyTurbine then
  58.         turbineOn=false
  59.     end
  60.    
  61.     if turbineEnergyStored<=maxEnergyTurbine and turbineOn then
  62.         systemOnlineOffline = "online"
  63.         if not turbine.getActive() then
  64.             turbine.setActive(true)
  65.         end
  66.         if turbineRotorSpeed>1810 then
  67.             turbine.setInductorEngaged(true)
  68.             if turbineRotorSpeed<1820 then
  69.             turbine.setFluidFlowRateMax(800)
  70.             end
  71.             if turbineRotorSpeed>1900 then
  72.             turbine.setFluidFlowRateMax(0)
  73.             end
  74.         elseif turbineRotorSpeed<1810 then
  75.             turbine.setFluidFlowRateMax(850)
  76.             if turbineRotorSpeed>1700 then
  77.             turbine.setFluidFlowRateMax(850)
  78.             end
  79.             if turbineRotorSpeed<1700 then
  80.             turbine.setFluidFlowRateMax(turbine.getFluidFlowRateMaxMax())
  81.             turbine.setInductorEngaged(false)
  82.             end
  83.         end
  84.     else
  85.         turbine.setFluidFlowRateMax(0)
  86.         turbine.setInductorEngaged(false)
  87.         systemOnlineOffline = "offline"
  88.     end
  89. end
  90.  
  91. function draw()
  92.     name = "Reactor-/Turbinesteuerung"
  93. -------------------------
  94.     mon.setBackgroundColor(colors.black)
  95.     for i=1,y do
  96.         mon.setCursorPos(1,i)
  97.         for j=1,x do
  98.             mon.write(" ")
  99.         end
  100.     end
  101.     mon.setBackgroundColor(colors.cyan)
  102.     mon.setCursorPos(1,1)
  103.     for i=1,x do
  104.         mon.write(" ")
  105.     end
  106.    
  107.     mon.setTextColor(colors.black)
  108.     mon.setCursorPos(math.floor((x-#name)/2)+1,1)
  109.     mon.write(name)
  110.     mon.setBackgroundColor(colors.black)
  111.     mon.setTextColor(colors.white)
  112.     mon.setCursorPos(1,2)
  113.     mon.write("System Status:")
  114.     mon.setCursorPos(1,4)
  115.     mon.write("Reactor:")
  116.     mon.setCursorPos(1,5)
  117.     mon.write("Induction Coils:")
  118.     mon.setCursorPos(1,6)
  119.     mon.write("Power Output:")
  120.     mon.setCursorPos(1,7)
  121.     mon.write("Speed:")
  122.     mon.setCursorPos(1,9)
  123.     mon.write("Power:")
  124.     mon.setCursorPos(1,11)
  125.     mon.write("Fuel:")
  126.    
  127.     mon.setCursorPos(x-#systemOnlineOffline,2)
  128.     if systemOnlineOffline=="online" then mon.setTextColor(colors.lime) else mon.setTextColor(colors.red) end
  129.     mon.write(systemOnlineOffline)
  130.     if reactorOnlineOffline then mon.setCursorPos(x-2,4); mon.setTextColor(colors.lime); mon.write("on") else mon.setCursorPos(x-3,4); mon.setTextColor(colors.red); mon.write("off") end
  131.     if turbineInductionCoilsOnOff then mon.setCursorPos(x-2,5); mon.setTextColor(colors.lime); mon.write("on") else mon.setCursorPos(x-3,5); mon.setTextColor(colors.red); mon.write("off") end
  132.     mon.setCursorPos(x-3-5,6); mon.setTextColor(colors.white)
  133.     mon.write(turbinePowerOutput)
  134.     mon.setCursorPos(x-3,6)
  135.     mon.write("RF/T ")
  136.     mon.setCursorPos(x-4-4,7)
  137.     mon.write(turbineRotorSpeed)
  138.     mon.setCursorPos(x-4,7)
  139.     mon.write(" RPM  ")
  140.    
  141.     mon.setBackgroundColor(colors.gray)
  142.     for i=10,12,2 do
  143.         mon.setCursorPos(2,i)
  144.         for j=1,x-2 do
  145.             mon.write(" ")
  146.         end
  147.     end
  148.    
  149.     mon.setCursorPos(2,10)
  150.     mon.setBackgroundColor(colors.orange)
  151.     for i=1,turbinePowerProcess do
  152.         mon.write(" ")
  153.     end
  154.     mon.setCursorPos(2,12)
  155.     mon.setBackgroundColor(colors.yellow)
  156.     for i=1,reactorFluidProcess do
  157.         mon.write(" ")
  158.     end
  159.     mon.setBackgroundColor(colors.black)
  160.     mon.setCursorPos(x,12)
  161.     mon.write(" ")
  162. end
  163.  
  164. function start_screen()
  165.  mon.clear()
  166.  x,y = mon.getSize()
  167.  len1 = 24
  168.  midx = math.floor((x-len1)/2)
  169.  midy = math.floor(y/2)
  170.  mon.setCursorPos(midx,midy)
  171.  mon.setTextColor(colors.lightGray)
  172.  mon.write("Reactor-/Turbinesteuerung")
  173.  len1 = 14
  174.  midx = math.floor((x-len1)/2)
  175.  midy = midy+1
  176.  mon.setCursorPos(midx,midy)
  177.  mon.setTextColor(colors.lightGray)
  178.  mon.write("(C) by jamawie")
  179.  len1 = 18
  180.  midx = math.floor((x-len1)/2)
  181.  midy = midy+2
  182.  mon.setCursorPos(midx,midy)
  183.  mon.setTextColor(colors.lightGray)
  184.  mon.write("")
  185.  mon.setCursorPos(2,y)
  186.  mon.setTextColor(colors.red)
  187.  mon.write("Weitergabe nicht gestattet!")
  188.  mon.setTextColor(colors.black)
  189.  
  190.  sleep(10)
  191. end
  192.  
  193. function offlineScreen(offArg)
  194.  mon.clear()
  195.  x,y = mon.getSize()
  196.  len1 = 7
  197.  midx = math.floor((x-len1)/2)
  198.  midy = math.floor(y/2)
  199.  mon.setCursorPos(midx,midy)
  200.  mon.setTextColor(colors.lightGray)
  201.  mon.write("offline")
  202.  
  203.  offStringPlayerOffline     = "Spieler nicht online!"
  204.  offStringNoFuel            = "Kein Fuel vorhanden!"
  205.  len2   = string.len(offStringPlayerOffline)
  206.  midx2  = math.floor((x-len2)/2)
  207.  len3   = string.len(offStringNoFuel)
  208.  midx3  = math.floor((x-len3)/2)
  209.  if offArg=="offline" then
  210.   mon.setCursorPos(midx2,y)
  211.   mon.setTextColor(colors.lightGray)
  212.   mon.write(offStringPlayerOffline)
  213.  elseif offArg=="noFuel" then
  214.   mon.setCursorPos(midx3,y)
  215.   mon.setTextColor(colors.lightGray)
  216.   mon.write(offStringNoFuel)
  217.  end
  218.  mon.setTextColor(colors.black)
  219. end
  220.  
  221. function redIn()
  222.  sides = {"top","bottom","left","right","front","back"}
  223.  for i=1,#sides do
  224.   resault = rs.getInput(sides[i])
  225.   if resault==true then
  226.    return true
  227.   end
  228.  end
  229.  return false
  230. end
  231.  
  232. function eventHandler()
  233.     while true do
  234.         event, arg1, arg2, arg3 = os.pullEvent()
  235.         if event == "char" and not inManualMode then
  236.             local ch = string.lower(arg1)
  237.             if ch == "q" then
  238.             elseif ch == "r" then
  239.                 os.reboot()
  240.             elseif ch == "u" then
  241.                 if fs.exists("update") then
  242.                     shell.run("update")
  243.                 else
  244.                     shell.run("pastebin get VfHgjUsS update")
  245.                     shell.run("update")
  246.                 end
  247.             end
  248.         end
  249.     end
  250. end
  251.  
  252. function speak()
  253.  
  254. end
  255. -----------------------------
  256.  
  257. function main()
  258. term.setCursorPos(1,1)
  259. term.write("Display redirected to Monitor. Type r to reboot, or")
  260. term.setCursorPos(1,2)
  261. term.write("q to quit and return control to this terminal.")
  262. term.setCursorPos(1,3)
  263. term.write("Press u to update!")
  264. start_screen()
  265. while true do
  266.  if redIn() then
  267.     mon.clear()
  268.     actualising()
  269.     draw()
  270.     reactorF()
  271.     turbineF()
  272.     speak()
  273.  else
  274.     offlineScreen("offline")
  275.     reactor.setActive(false)
  276.     turbine.setFluidFlowRateMax(0)
  277.     turbine.setInductorEngaged(false)
  278.     if turbine.getRotorSpeed()<=1 then
  279.         turbine.setActive(false)
  280.     end
  281.     sleep(0.5)
  282.  end
  283. sleep(0.15)
  284. delay=delay+1
  285. end
  286. end
  287.  
  288. parallel.waitForAny(main, eventHandler)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement