Advertisement
Te-ki

CCBRClient

Feb 13th, 2016
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.63 KB | None | 0 0
  1. --ComputerCraft BigReactors Client by Teki 0.1
  2. local debugTerm = term.current()
  3. local oldTerm = term.current()
  4. local elapsed = os.clock() -- Debug
  5.  
  6. local function Debug(str)
  7.     debugTerm.write(str)
  8.     local X,Y = debugTerm.getCursorPos()
  9.     local sX,sY = debugTerm.getSize()
  10.     if X < sX then
  11.         debugTerm.setCursorPos(1, Y+1)
  12.     else
  13.         debugTerm.scroll(1)
  14.     end
  15. end
  16.  
  17. function drawBar(startX, endX, posY, colorFull, colorEmpty, maxSize, currentSize, label)
  18.     -- label = label .. " " .. currentSize .. "/" .. maxSize
  19.     -- label = label .. " " .. currentSize .. "/" .. maxSize
  20.     while ((endX - startX+1) - #label)/2 >= 1 do
  21.         label = " " .. label .. " "
  22.     end
  23.     length = (endX - startX + 1)*(currentSize/maxSize)
  24.     for i=startX, endX do
  25.         monitor.setCursorPos(i, posY)
  26.         if i-startX+1 <= length then
  27.             monitor.setBackgroundColor(colorFull)
  28.             monitor.setTextColor(colorEmpty)
  29.         else
  30.             monitor.setBackgroundColor(colorEmpty)
  31.             monitor.setTextColor(colorFull)
  32.         end
  33.         if #label < i-startX+1 then
  34.             monitor.write(" ")
  35.         else
  36.             monitor.write(label:sub(i-startX+1, i))
  37.         end
  38.     end
  39.    
  40.     monitor.setBackgroundColour(colors.gray)
  41.     monitor.setTextColor(colors.white)
  42. end
  43.  
  44. local eventType = "mouse_click"
  45. if peripheral.find("monitor") == nil then
  46.     monitor = term.current()
  47. else
  48.     monitor = peripheral.find("monitor")
  49.     monitor.setTextScale(1)
  50.     local sizeX,sizeY = monitor.getSize()
  51.     if sizeX < 20 or sizeY < 18 then
  52.         monitor.setTextScale(0.5)
  53.     end
  54.    
  55.     eventType = "monitor_touch"
  56. end
  57.  
  58. local sizeX,sizeY = monitor.getSize()
  59.  
  60. if peripheral.find("modem") == nil then
  61.     return 0
  62. else
  63.     local side
  64.     local sides = peripheral.getNames()
  65.     for i=1, #sides do
  66.         if peripheral.getType(sides[i]) == "modem" then
  67.             side = sides[i]
  68.         end
  69.     end
  70.     rednet.open(side)
  71.     -- sleep(0)
  72. end
  73.  
  74. -- Reactor data
  75. local getActive = "ACTIVE"
  76. local isActivelyCooled = false
  77. local getHotFluidAmount = 0
  78. local getHotFluidAmountMax = 0
  79. local getEnergyProducedLastTick = 0
  80. local getEnergyStored = 0
  81. local getEnergyCapacity = 0
  82. local getFuelAmount = 0
  83. local getFuelAmountMax = 0
  84. local getFuelConsumedLastTick = 0
  85. local getFuelTemperature = 0
  86. local getFuelReactivity = 0
  87. local getWasteAmount = 0
  88. local getCasingTemperature = 0
  89. local getNumberOfControlRods = 0
  90. local rodsLevels = {0,0,0,0,0,0}
  91. local rodsNames = {"","","","","",""}
  92.  
  93. local fuelEnergyRatio = 0
  94.  
  95. -- Turbine data
  96. local getActiveT = true
  97. local getEnergyStoredT = 0
  98. local getEnergyCapacityT = 0
  99. local getRotorSpeedT = 0
  100. local getInputAmountT = 0
  101. local getInputTypeT = ""
  102. local getOutputAmountT = 0
  103. local getOutputTypeT = ""
  104. local getFluidAmountMaxT = 0
  105. local getFluidFlowRateT = 0
  106. local getFluidFlowRateMaxT = 0
  107. local getFluidFlowRateMaxMaxT = 0
  108. local getEnergyProducedLastTickT = 0
  109. local getBladeEfficiencyT = 0
  110. local getRotorMassT = 0
  111. local getInductorEngagedT = true
  112.  
  113. local eventFired = false
  114. local id, msg = nil
  115. local name = 0
  116. local autoStart = true
  117. local masterTab = 0
  118. local tab = 0
  119.  
  120. local mult = 0
  121.  
  122. local reactorID = nil
  123. local turbineID = nil
  124.  
  125. -- Find Reactor
  126. rednet.broadcast("getConnected", "CCBRClient")
  127. reactorID, msg = rednet.receive("CCBRServeur", 1)
  128. -- Find Turbine
  129. rednet.broadcast("getConnected", "CCBTClient")
  130. turbineID, msg = rednet.receive("CCBTServeur", 1)
  131.  
  132. if turbineID ~= nil then
  133.     masterTab = 1
  134. end
  135.  
  136. local function roundTo(num, n)
  137.   mult = 10^(n or 0)
  138.   return math.floor(num * mult + 0.5) / mult
  139. end
  140.  
  141. function catchDataR()
  142.     -- Querry All ?
  143.     rednet.send(reactorID, "getAll", "CCBRClient")
  144.     id, msg = rednet.receive("CCBRServeur", 1)
  145.     if msg ~= false and msg ~= true and msg ~= nil then
  146.     --[[
  147.         -- Is Active ?
  148.         getActive = msg[2]
  149.         -- is AutoStart enabled ?
  150.         autoStart = msg[22]
  151.         -- Actively Cooled ?
  152.         isActivelyCooled = msg[18]
  153.         -- Hot Fluid Amount ?
  154.         getHotFluidAmount = msg[21]
  155.         -- Hot Fluid Amount Max?
  156.         getHotFluidAmountMax = msg[15]
  157.         -- Energy Production ?
  158.         getEnergyProducedLastTick = roundTo(msg[11], 2)
  159.         -- Energy Stored ?
  160.         getEnergyStored = msg[4]
  161.         -- Energy Capacity ?
  162.         getEnergyCapacity = msg[5]
  163.         -- Fuel Stored ?
  164.         getFuelAmount = msg[8]
  165.         getFuelAmountMax = msg[10]
  166.         -- Fuel Usage ?
  167.         -- getFuelConsumedLastTick = roundTo((msg[16]*72), 2)
  168.         getFuelConsumedLastTick = msg[17]
  169.         -- Fuel Temperature ?
  170.         getFuelTemperature = roundTo(msg[6], 2)
  171.         -- Fuel Reactivity ?
  172.         getFuelReactivity = roundTo(msg[16], 2)
  173.         -- Waste ?
  174.         getWasteAmount = msg[9]
  175.         -- Casing Temperature ?
  176.         getCasingTemperature = roundTo(msg[7], 2)
  177.         -- How Many rods ?
  178.         getNumberOfControlRods = msg[3]
  179.        
  180.         -- rods array
  181.         for i = 0,getNumberOfControlRods-1 do
  182.             -- Get rod level
  183.             -- sleep(0)
  184.             -- rednet.send(reactorID, "getControlRodLevel " .. i, "CCBRClient")
  185.             -- id, msg = rednet.receive("CCBRServeur", 10)
  186.             -- if msg ~= nil then
  187.                 -- rodsLevels[i] = msg
  188.                 rodsLevels[i] = msg[23+i]
  189.             -- end
  190.            
  191.             -- Get rod Name
  192.             -- sleep(0)
  193.             -- rednet.send(reactorID, "getControlRodName " .. i, "CCBRClient")
  194.             -- id, msg = rednet.receive("CCBRServeur", 10)
  195.             -- if msg ~= nil then
  196.                 -- rodsNames[i] = msg
  197.                 rodsNames[i] = msg[23+getNumberOfControlRods+i]
  198.             -- end
  199.         end
  200.     ]]--
  201.         -- Is Active ?
  202.         getActive = msg.getActive
  203.         -- is AutoStart enabled ?
  204.         autoStart = msg.autoStart
  205.         -- Actively Cooled ?
  206.         isActivelyCooled = msg.isActivelyCooled
  207.         -- Hot Fluid Amount ?
  208.         getHotFluidAmount = msg.getHotFluidAmount
  209.         -- Hot Fluid Amount Max?
  210.         getHotFluidAmountMax = msg.getHotFluidAmountMax
  211.         -- Energy Production ?
  212.         getEnergyProducedLastTick = roundTo(msg.getEnergyProducedLastTick, 2)
  213.         -- Energy Stored ?
  214.         getEnergyStored = msg.getEnergyStored
  215.         -- Energy Capacity ?
  216.         getEnergyCapacity = msg.getEnergyCapacity
  217.         -- Fuel Stored ?
  218.         getFuelAmount = msg.getFuelAmount
  219.         getFuelAmountMax = msg.getFuelAmountMax
  220.         -- Fuel Usage ?
  221.         -- getFuelConsumedLastTick = roundTo((msg[16]*72), 2)
  222.         getFuelConsumedLastTick = msg.getFuelConsumedLastTick
  223.         -- Fuel Temperature ?
  224.         getFuelTemperature = roundTo(msg.getFuelTemperature, 2)
  225.         -- Fuel Reactivity ?
  226.         getFuelReactivity = roundTo(msg.getFuelReactivity, 2)
  227.         -- Waste ?
  228.         getWasteAmount = msg.getWasteAmount
  229.         -- Casing Temperature ?
  230.         getCasingTemperature = roundTo(msg.getCasingTemperature, 2)
  231.         -- How Many rods ?
  232.         getNumberOfControlRods = msg.getNumberOfControlRods
  233.        
  234.         -- rods array
  235.         for i = 0,getNumberOfControlRods-1 do
  236.                 rodsLevels[i] = msg[i]
  237.                 rodsNames[i] = msg[getNumberOfControlRods + i]
  238.         end
  239.        
  240.         fuelEnergyRatio = 0
  241.         if getFuelConsumedLastTick > 0 then
  242.             fuelEnergyRatio = getEnergyProducedLastTick/getFuelConsumedLastTick
  243.         end
  244.     end
  245. end
  246.  
  247. function drawDataR()
  248.     -- MONITORING SCREEN
  249.     monitor.clear()
  250.     monitor.setCursorPos(1,1)
  251.    
  252.     if getActive == true then
  253.         paintutils.drawBox(1, 1, sizeX, sizeY, colors.green)
  254.     else
  255.         paintutils.drawBox(1, 1, sizeX, sizeY, colors.orange)
  256.     end
  257.     monitor.setBackgroundColour(colors.gray)
  258.    
  259.     monitor.setCursorPos(3,3)
  260.     monitor.write("STATUS : ")
  261.     if getActive == true then
  262.         monitor.setTextColor(colors.green)
  263.         monitor.write("ACTIVE")
  264.     else
  265.         monitor.setTextColor(colors.orange)
  266.         monitor.write("NOT ACTIVE")
  267.     end
  268.    
  269.     monitor.setTextColor(colors.white)
  270.     monitor.setCursorPos(3,5)
  271.     if isActivelyCooled then
  272.         monitor.write("Steam Rate: " .. getEnergyProducedLastTick .. " mB/t")
  273.         monitor.setCursorPos(3,6)
  274.         monitor.write("Steam Tank: " .. getHotFluidAmount .. "/" .. getHotFluidAmountMax .." mB")
  275.         drawBar(3, sizeX-2, 7, colors.green, colors.red, getHotFluidAmountMax, getHotFluidAmount, roundTo(getHotFluidAmountMax/getHotFluidAmount*100) .. "%")
  276.     else
  277.         monitor.write("Energy Rate : " .. getEnergyProducedLastTick .. " RF/t")
  278.         monitor.setCursorPos(3,6)
  279.         monitor.write("RF Stored : " .. getEnergyStored .. " RF")
  280.         if getEnergyCapacity ~= nil then
  281.             drawBar(3, sizeX-2, 7, colors.green, colors.red, getEnergyCapacity, getEnergyStored, roundTo(100/(getEnergyCapacity/getEnergyStored), 3) .. "%")
  282.         end
  283.     end
  284.     monitor.setCursorPos(3,8)
  285.     monitor.write("Fuel : " .. getFuelAmount .. "/" .. getFuelAmountMax .. " mB")
  286.     monitor.setCursorPos(3,9)
  287.     monitor.write("Waste : " .. getWasteAmount .. " mB")
  288.     monitor.setCursorPos(3,11)
  289.     monitor.write("Fuel Usage : " .. roundTo(getFuelConsumedLastTick, 4) .. " mB/t")
  290.     monitor.setCursorPos(3,12)
  291.     monitor.write("Fuel Temp : " .. getFuelTemperature .. " C")
  292.     monitor.setCursorPos(3,13)
  293.     monitor.write("Fuel Reactivity : " .. getFuelReactivity .. " %")
  294.     monitor.setCursorPos(3,14)
  295.     monitor.write("RF/mB : " .. roundTo(fuelEnergyRatio, 2) .. " RF/mB")
  296.     monitor.setCursorPos(3,15)
  297.     monitor.write("Casing Temp : " .. getCasingTemperature .. " C")
  298. end
  299.  
  300. function drawMenuR()
  301.     -- COMMANDS SCREEN
  302.     monitor.clear()
  303.     monitor.setCursorPos(1,1)
  304.    
  305.     if getActive == true then
  306.         paintutils.drawBox(1, 1, sizeX, sizeY, colors.green)
  307.     else
  308.         paintutils.drawBox(1, 1, sizeX, sizeY, colors.orange)
  309.     end
  310.     monitor.setBackgroundColour(colors.gray)
  311.    
  312.     monitor.setCursorPos(3,3)
  313.     if getActive == true then
  314.         monitor.setTextColor(colors.red)
  315.         monitor.write("DEACTIVATE")
  316.     else
  317.         monitor.setTextColor(colors.green)
  318.         monitor.write("ACTIVATE")
  319.     end
  320.    
  321.     monitor.setCursorPos(21,3)
  322.     if autoStart then
  323.         monitor.setTextColor(colors.green)
  324.         monitor.write("  AUTO")
  325.     else
  326.         monitor.setTextColor(colors.red)
  327.         monitor.write("MANUAL")
  328.     end
  329.    
  330.     monitor.setTextColor(colors.white)
  331.    
  332.     for i = 0,getNumberOfControlRods-1 do
  333.         monitor.setCursorPos(3,5+i)
  334.         monitor.write("Rod" .. i .. " : " .. rodsLevels[i] .. " %")
  335.         monitor.setCursorPos(17,5+i)
  336.         monitor.write("<< <  > >>")
  337.     end
  338.    
  339.     monitor.setCursorPos(3,5+getNumberOfControlRods)
  340.     monitor.write("ALL" .. "  : " .. rodsLevels[0] .. " %")
  341.     monitor.setCursorPos(17,5+getNumberOfControlRods)
  342.     monitor.write("<< <  > >>")
  343. end
  344.  
  345. function catchDataT()
  346.     -- Querry All ?
  347.     sleep(0)
  348.     rednet.send(turbineID, "getAll", "CCBTClient")
  349.     id, msg = rednet.receive("CCBTServeur", 1)
  350.     if msg ~= false and msg ~= true and msg ~= nil then
  351.         -- Is Active ?
  352.         -- getActiveT = msg[2]
  353.         -- getEnergyStoredT = roundTo(msg[3], 0)
  354.         -- getRotorSpeedT = roundTo(msg[4], 2)
  355.         -- getInputAmountT = msg[5]
  356.         -- getInputTypeT = msg[6]
  357.         -- getOutputAmountT = msg[7]
  358.         -- getOutputTypeT = msg[8]
  359.         -- getFluidAmountMaxT = msg[9]
  360.         -- getFluidFlowRateT = roundTo(msg[10], 2)
  361.         -- getFluidFlowRateMaxT = roundTo(msg[11], 0)
  362.         -- getFluidFlowRateMaxMaxT = roundTo(msg[12], 0)
  363.         -- getEnergyProducedLastTickT = roundTo(msg[13], 2)
  364.         -- getBladeEfficiencyT = msg[15]
  365.         -- getRotorMassT = msg[16]
  366.         -- getInductorEngagedT = msg[17]
  367.         -- autoStart = msg[20]
  368.         getActiveT = msg.getActive
  369.         getEnergyStoredT = roundTo(msg.getEnergyStored, 0)
  370.         getEnergyCapacityT = roundTo(msg.getEnergyCapacity, 0)
  371.         getRotorSpeedT = roundTo(msg.getRotorSpeed, 2)
  372.         getInputAmountT = msg.getInputAmount
  373.         getInputTypeT = msg.getInputType
  374.         getOutputAmountT = msg.getOutputAmount
  375.         getOutputTypeT = msg.getOutputType
  376.         getFluidAmountMaxT = msg.getFluidAmountMax
  377.         getFluidFlowRateT = roundTo(msg.getFluidFlowRate, 2)
  378.         getFluidFlowRateMaxT = roundTo(msg.getFluidFlowRateMax, 0)
  379.         getFluidFlowRateMaxMaxT = roundTo(msg.getFluidFlowRateMaxMax, 0)
  380.         getEnergyProducedLastTickT = roundTo(msg.getEnergyProducedLastTick, 2)
  381.         getBladeEfficiencyT = msg.getBladeEfficiency
  382.         getRotorMassT = msg.getRotorMass
  383.         getInductorEngagedT = msg.getInductorEngaged
  384.         autoStart = msg.autoStart
  385.     end
  386. end
  387.  
  388. function drawDataT()
  389.     -- MONITORING SCREEN
  390.     monitor.clear()
  391.     monitor.setCursorPos(1,1)
  392.    
  393.     if getActiveT == true then
  394.         paintutils.drawBox(1, 1, sizeX, sizeY, colors.green)
  395.     else
  396.         paintutils.drawBox(1, 1, sizeX, sizeY, colors.orange)
  397.     end
  398.     monitor.setBackgroundColour(colors.gray)
  399.    
  400.     monitor.setCursorPos(3,3)
  401.     monitor.write("STATUS : ")
  402.     if getActiveT == true then
  403.         monitor.setTextColor(colors.green)
  404.         monitor.write("ACTIVE")
  405.     else
  406.         monitor.setTextColor(colors.orange)
  407.         monitor.write("NOT ACTIVE")
  408.     end
  409.    
  410.     monitor.setTextColor(colors.white)
  411.     monitor.setCursorPos(3,4)
  412.     monitor.write("COILS : ")
  413.     if getInductorEngagedT == true then
  414.         monitor.setTextColor(colors.green)
  415.         monitor.write("Engaged")
  416.     else
  417.         monitor.setTextColor(colors.orange)
  418.         monitor.write("Disengaged")
  419.     end
  420.    
  421.     monitor.setTextColor(colors.white)
  422.    
  423.     monitor.setCursorPos(3,6)
  424.     monitor.write("RF rate : " .. getEnergyProducedLastTickT .. " RF/t")
  425.     monitor.setCursorPos(3,7)
  426.     monitor.write("RF stored : " .. getEnergyStoredT .. " RF")
  427.     drawBar(3, sizeX-2, 8, colors.green, colors.red, getEnergyCapacityT, getEnergyStoredT, roundTo(100/(getEnergyCapacityT/getEnergyStoredT), 3) .. "%")
  428.    
  429.     monitor.setCursorPos(3,9)
  430.     monitor.write("Rotor speed : " .. getRotorSpeedT .. " RPM")
  431.     monitor.setCursorPos(3,10)
  432.     monitor.write("Blade efficiency : " .. getBladeEfficiencyT .. " %")
  433.    
  434.     monitor.setCursorPos(3,12)
  435.     monitor.write("Input amount : " .. getInputAmountT .. " mB")
  436.     monitor.setCursorPos(3,13)
  437.     monitor.write("Output amount : " .. getOutputAmountT .. " mB")
  438. end
  439.  
  440. function drawMenuT()
  441.     -- COMMANDS SCREEN
  442.     monitor.clear()
  443.     monitor.setCursorPos(1,1)
  444.    
  445.     if getActiveT == true then
  446.         paintutils.drawBox(1, 1, sizeX, sizeY, colors.green)
  447.     else
  448.         paintutils.drawBox(1, 1, sizeX, sizeY, colors.orange)
  449.     end
  450.     monitor.setBackgroundColour(colors.gray)
  451.    
  452.     monitor.setCursorPos(3,3)
  453.     if getActiveT == true then
  454.         monitor.setTextColor(colors.red)
  455.         monitor.write("DEACTIVATE")
  456.     else
  457.         monitor.setTextColor(colors.green)
  458.         monitor.write("ACTIVATE")
  459.     end
  460.    
  461.     monitor.setCursorPos(3,4)
  462.     if getInductorEngagedT == true then
  463.         monitor.setTextColor(colors.red)
  464.         monitor.write("DISENGAGE COILS")
  465.     else
  466.         monitor.setTextColor(colors.green)
  467.         monitor.write("ENGAGE COILS")
  468.     end
  469.    
  470.     monitor.setCursorPos(21,3)
  471.     if autoStart then
  472.         monitor.setTextColor(colors.green)
  473.         monitor.write("  AUTO")
  474.     else
  475.         monitor.setTextColor(colors.red)
  476.         monitor.write("MANUAL")
  477.     end
  478.    
  479.     monitor.setTextColor(colors.white)
  480.    
  481.         monitor.setCursorPos(3,6)
  482.         monitor.write("Flow rate : ")
  483.         monitor.setCursorPos(15,6)
  484.         monitor.write(tonumber(getFluidFlowRateMaxT) .. " mb/T")
  485.         monitor.setCursorPos(6,7)
  486.         monitor.write("<<< << <  > >> >>>")
  487. end
  488.  
  489. function drawTabs()
  490.     if masterTab == 0 then
  491.         monitor.setCursorPos(3, sizeY-1)
  492.         monitor.write("Reactor")
  493.     elseif masterTab == 1 then
  494.         monitor.setCursorPos(3, sizeY-1)
  495.         monitor.write("Turbine")
  496.     end
  497.     if tab == 0 then
  498.         monitor.setBackgroundColour(colors.lightGray)
  499.     else
  500.         monitor.setBackgroundColour(colors.gray)
  501.     end
  502.     monitor.setCursorPos(sizeX-14, sizeY-1)
  503.     monitor.write("Info")
  504.     if tab == 1 then
  505.         monitor.setBackgroundColour(colors.lightGray)
  506.     else
  507.         monitor.setBackgroundColour(colors.gray)
  508.     end
  509.     monitor.setCursorPos(sizeX-9, sizeY-1)
  510.     monitor.write("Controls")
  511.    
  512.     monitor.setBackgroundColour(colors.gray)
  513. end
  514.  
  515. function catchEvents()
  516.    
  517.     -- EVENTS
  518.     local event, side, xPos, yPos = os.pullEvent(eventType)
  519.    
  520.     -- eventFired = true
  521.     -- while eventFired do
  522.         -- sleep(0)
  523.     -- end
  524.    
  525.     if turbineID ~= nil and (xPos >= 3 and xPos <= 9 and yPos == sizeY-1) then
  526.         if masterTab == 0 then
  527.             masterTab = 1
  528.         else
  529.             masterTab = 0
  530.         end
  531.     elseif (xPos >= sizeX-14 and xPos <= sizeX-10 and yPos == sizeY-1) then
  532.         tab = 0
  533.     elseif (xPos >= sizeX-9 and xPos <= sizeX-2 and yPos == sizeY-1) then
  534.         tab = 1
  535.     elseif tab == 1 and masterTab == 0 then
  536.         if (xPos >= 3 and xPos <= 11) and (yPos == 3) then
  537.             if getActive == true then
  538.                 sleep(0)
  539.                 rednet.send(reactorID,"setActive false", "CCBRClient")
  540.             else
  541.                 sleep(0)
  542.                 rednet.send(reactorID,"setActive true", "CCBRClient")
  543.             end
  544.         elseif (xPos >= 21 and xPos <= 27) and (yPos == 3) then
  545.             if autoStart == true then
  546.                 sleep(0)
  547.                 rednet.send(reactorID,"setAutoStart false", "CCBRClient")
  548.             else
  549.                 sleep(0)
  550.                 rednet.send(reactorID,"setAutoStart true", "CCBRClient")
  551.             end
  552.         else
  553.             local touched = false
  554.             local touchedId = 0
  555.             local touchedAction = 0
  556.            
  557.             for i=0,getNumberOfControlRods do
  558.                 name = i
  559.                 if i == getNumberOfControlRods then
  560.                     name = "ALL"
  561.                 end
  562.                 if (xPos >= 16 and xPos <= 18 and yPos == 5+i) then
  563.                     touched = true
  564.                     touchedId = i
  565.                     touchedAction = -10
  566.                 elseif (xPos >= 19 and xPos <= 21 and yPos == 5+i) then
  567.                     touched = true
  568.                     touchedId = i
  569.                     touchedAction = -1
  570.                 elseif (xPos >= 22 and xPos <= 24 and yPos == 5+i) then
  571.                     touched = true
  572.                     touchedId = i
  573.                     touchedAction = 1
  574.                 elseif (xPos >= 25 and xPos <= 27 and yPos == 5+i) then
  575.                     touched = true
  576.                     touchedId = i
  577.                     touchedAction = 10
  578.                 end
  579.             end
  580.        
  581.             if (touched) then
  582.                 if (touchedId == getNumberOfControlRods) then
  583.                     sleep(0)
  584.                     rednet.send(reactorID,"setAllControlRodLevels " .. rodsLevels[0] + touchedAction, "CCBRClient")
  585.                 else
  586.                     sleep(0)
  587.                     rednet.send(reactorID,"setControlRodLevel " .. touchedId .. " " .. rodsLevels[touchedId] + touchedAction, "CCBRClient")
  588.                 end
  589.             end
  590.         end
  591.     elseif tab == 1 and masterTab == 1 then
  592.         if (xPos >= 3 and xPos <= 11) and (yPos == 3) then
  593.             if getActiveT == true then
  594.                 sleep(0)
  595.                 rednet.send(turbineID,"setActive false", "CCBTClient")
  596.             else
  597.                 sleep(0)
  598.                 rednet.send(turbineID,"setActive true", "CCBTClient")
  599.             end
  600.         elseif (xPos >= 3 and xPos <= 15) and (yPos == 4) then
  601.             if getInductorEngagedT == true then
  602.                 sleep(0)
  603.                 rednet.send(turbineID,"setInductorEngaged false", "CCBTClient")
  604.             else
  605.                 sleep(0)
  606.                 rednet.send(turbineID,"setInductorEngaged true", "CCBTClient")
  607.             end
  608.         elseif (xPos >= 21 and xPos <= 27) and (yPos == 3) then
  609.             if autoStart == true then
  610.                 sleep(0)
  611.                 rednet.send(turbineID,"setAutoStart false", "CCBTClient")
  612.             else
  613.                 sleep(0)
  614.                 rednet.send(turbineID,"setAutoStart true", "CCBTClient")
  615.             end
  616.         else
  617.             local touched = false
  618.             local touchedAction = 0
  619.             if (xPos >= 6 and xPos <= 8 and yPos == 7) then
  620.                 touched = true
  621.                 touchedAction = -100
  622.             elseif (xPos >= 10 and xPos <= 11 and yPos == 7) then
  623.                 touched = true
  624.                 touchedAction = -10
  625.             elseif (xPos >= 13 and xPos <= 13 and yPos == 7) then
  626.                 touched = true
  627.                 touchedAction = -1
  628.             elseif (xPos >= 16 and xPos <= 16 and yPos == 7) then
  629.                 touched = true
  630.                 touchedAction = 1
  631.             elseif (xPos >= 18 and xPos <= 19 and yPos == 7) then
  632.                 touched = true
  633.                 touchedAction = 10
  634.             elseif (xPos >= 21 and xPos <= 23 and yPos == 7) then
  635.                 touched = true
  636.                 touchedAction = 100
  637.             end
  638.             if (touched) then
  639.                 sleep(0)
  640.                 rednet.send(turbineID,"setFluidFlowRateMax " .. getFluidFlowRateMaxT + touchedAction, "CCBTClient")
  641.             end
  642.         end
  643.     end
  644.     eventFired = true
  645. end
  646.  
  647. function drawAll()
  648.     while not eventFired do
  649.         term.redirect(monitor)
  650.         if masterTab == 0 then
  651.             -- catchDataR()
  652.             if tab == 0 then
  653.                 drawDataR()
  654.             elseif tab == 1 then
  655.                 drawMenuR()
  656.             end
  657.         elseif masterTab == 1 then
  658.             -- catchDataT()
  659.             if tab == 0 then
  660.                 drawDataT()
  661.             elseif tab == 1 then
  662.                 drawMenuT()
  663.             end
  664.         end
  665.         drawTabs()
  666.         term.redirect(oldTerm)
  667.         -- Debug
  668.             -- monitor.setBackgroundColor(colors.white)
  669.             -- monitor.setTextColor(colors.black)
  670.             local elapsedTime = "" .. roundTo((os.clock()- elapsed)/0.05, 1)
  671.             monitor.setCursorPos(sizeX-#elapsedTime, 2)
  672.             monitor.write(elapsedTime)
  673.             elapsed = os.clock()
  674.         -- while (os.clock()- elapsed)/0.05 < 1.05 do
  675.         while os.clock()- elapsed <= 0.051 do
  676.             sleep(0)
  677.         end
  678.         -- End Debug
  679.         -- sleep(0)
  680.         -- sleep(0.1)
  681.     end
  682.     -- eventFired = false
  683. end
  684.  
  685. function updateLoop()
  686.     while not eventFired do
  687.         if masterTab == 0 then
  688.             catchDataR()
  689.         elseif masterTab == 1 then
  690.             catchDataT()
  691.         end
  692.         sleep(0)
  693.     end
  694.     -- eventFired = false
  695. end
  696.  
  697. while true do
  698.     -- parallel.waitForAny(function() parallel.waitForAll(catchEvents, drawAll) end, function() sleep(5) end)
  699.     -- parallel.waitForAll(catchEvents, drawAll)
  700.     parallel.waitForAll(updateLoop, function() parallel.waitForAll(catchEvents, drawAll) end)
  701.     eventFired = false
  702.     -- sleep(0)
  703. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement