Advertisement
readix

turbineControllerDistant

Apr 23rd, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.77 KB | None | 0 0
  1. local turbine1 = peripheral.wrap("BigReactors-Turbine_13") -- gauche
  2. local turbine2 = peripheral.wrap("BigReactors-Turbine_14") --droite
  3. local wl = peripheral.wrap("back")
  4. local alarm = true
  5. local reactor1 = peripheral.wrap("BigReactors-Reactor_14")
  6. local reactor2 = peripheral.wrap("BigReactors-Reactor_15")
  7. wl.open(199)
  8. term.clear()
  9. local mon = term
  10.  
  11. function controlleAffiche()
  12.     while true do  
  13.    
  14.         affiche(turbine1,reactor1, "left", "left")
  15.    
  16.         sleep(0.5)
  17.    
  18.         affiche(turbine2,reactor2, "right", "right")
  19.    
  20.         sleep(0.5)
  21.     end
  22. end
  23.  
  24. function affiche(turbine, reactor, tName, rName)
  25.    
  26.  
  27.  
  28.     wl.transmit(199,199,tostring(reactor1.getActive()).." "..tostring(reactor2.getActive()).." "..tostring(turbine1.getActive()).." "..tostring(turbine2.getActive()).." "..tostring(math.floor(turbine1.getEnergyProducedLastTick())).." "..
  29.         tostring(math.floor(turbine2.getEnergyProducedLastTick())).." "..tostring(turbine1.getInductorEngaged()).." "..tostring(turbine2.getInductorEngaged()).." "..tostring(math.floor(turbine1.getRotorSpeed())).." "..tostring(math.floor(turbine2.getRotorSpeed())).." "..tostring(reactor1.getFuelAmount()).." "..tostring(reactor2.getFuelAmount()).." "..tostring(math.floor(turbine1.getEnergyStored())).." "..tostring(math.floor(turbine2.getEnergyStored())))
  30.     mon.clear()
  31.   mon.setCursorPos(1,1)
  32.   mon.setTextColor(colors.white)
  33.   mon.write("Reactor "..rName.." active: ")
  34.   mon.setTextColor(colors.lime)
  35.   mon.write(reactor.getActive())
  36.  
  37.   mon.setCursorPos(1,2)
  38.   mon.setTextColor(colors.white)
  39.   mon.write("Turbine "..tName.." active: ")
  40.   mon.setTextColor(colors.lime)
  41.   mon.write(turbine.getActive())
  42.  
  43.   mon.setCursorPos(1,3)
  44.   mon.setTextColor(colors.white)
  45.   mon.write("Turbine "..tName.." engage: ")
  46.   mon.setTextColor(colors.lime)
  47.   mon.write(turbine.getInductorEngaged())
  48.    
  49.   mon.setCursorPos(1,4)
  50.   mon.setTextColor(colors.white)
  51.   mon.write("RF/T: ")  
  52.   mon.setTextColor(colors.lime)
  53.   mon.write(math.floor(turbine.getEnergyProducedLastTick()))
  54.  
  55.   mon.setCursorPos(1,5)
  56.   mon.setTextColor(colors.white)
  57.   mon.write("RF Stored: ")
  58.   mon.setTextColor(colors.lime)
  59.   mon.write(math.floor(turbine.getEnergyStored()))
  60.  
  61.     --[[mon.setCursorPos(1,6)
  62.     mon.setTextColor(colors.white)
  63.     mon.write("Alarm: ")
  64.     mon.setTextColor(colors.lime)
  65.     mon.write(alarm)]]
  66.    
  67.    
  68.  
  69.  end
  70.  
  71.  function receive()
  72.     while true do
  73.         local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  74.         machine, stat = string.match(message, "(%w*)%s(%a*)")
  75.      if isNil(machine,stat) then
  76.         if string.match(machine, 'reactor?')=="reactor" then   
  77.             if string.match(machine, "%d")=="1" then
  78.                 if string.match(stat, "%a*")=="false" then
  79.                     reactor1.setActive(false)
  80.                 elseif string.match(stat,"%a*")=="true" then
  81.                     reactor1.setActive(true)
  82.                 end
  83.             elseif string.match(machine,"%d")=="2" then
  84.                 if string.match(stat, "%a*")=="false" then
  85.                     reactor2.setActive(false)
  86.                 elseif string.match(stat,"%a*")=="true" then
  87.                     reactor2.setActive(true)
  88.                 end
  89.             end
  90.         elseif string.match(machine, 'turbine?')=="turbine" then
  91.             if string.match(machine,'%d')=="2" then
  92.                 if string.match(stat, "%a*")=="false" then
  93.                     turbine2.setInductorEngaged(false)
  94.                 elseif string.match(stat,"%a*")=="true" then
  95.                     turbine2.setInductorEngaged(true)
  96.                 end
  97.             elseif string.match(machine,'%d')=="1" then
  98.                 if string.match(stat, "%a*")=="false" then
  99.                     turbine1.setInductorEngaged(false)
  100.                 elseif string.match(stat,"%a*")=="true" then
  101.                     turbine1.setInductorEngaged(true)
  102.                 end
  103.             end
  104.         end
  105.     end
  106.     end
  107. end
  108.  
  109. function isNil(machine, stat)
  110.     if machine== nil then
  111.         return false
  112.     end
  113.     if stat == nil then
  114.         return false
  115.     end
  116.     return true
  117. end
  118.  
  119.  
  120.  
  121.  
  122.  parallel.waitForAny(receive, controlleAffiche)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement