Advertisement
RLPGhost

Control Réactor v2

Mar 28th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.61 KB | None | 0 0
  1. local tank = peripheral.wrap("rcirontankvalvetile_0")
  2. local modem = peripheral.wrap("back")
  3. local wifi = peripheral.wrap("top")
  4. local reactor = peripheral.wrap("BigReactors-Reactor_2")
  5. local turbine = peripheral.wrap("BigReactors-Turbine_4")
  6. local turbine2 = peripheral.wrap("BigReactors-Turbine_5")
  7. local capacitor = peripheral.wrap("tile_blockcapacitorbank_name_2")
  8.  
  9. local cap                -- Tank capacity
  10. local amount             -- Amount liquid in tank
  11. local percentfull        -- Percent liquid in tank
  12.  
  13. local rodLevel = 0
  14. local minRodLevel = 55
  15. local maxRodLevel = 65
  16.  
  17. local enderMonitorRedstone = false
  18.  
  19. local rpmTurbine = 0
  20. local minRpmTurbine = 1700
  21. local maxRpmTurbine = 1800
  22.  
  23.  
  24. local nbSlot = 120
  25.  
  26.  
  27. function getTank(tankPeriph)
  28.     local tableInfo = tankPeriph.getTankInfo("unknown") -- Local to the getTank function.
  29.  
  30.     fluidRaw = nil
  31.     fluidName = nil
  32.     fluidAmount = nil
  33.     fluidCapacity = nil
  34.      
  35.     for k,v in pairs(tableInfo) do
  36.       fluidCapacity = v.capacity
  37.  
  38.       if v.contents then
  39.         for i,w in pairs(v.contents) do
  40.           if i == "rawName" then
  41.             fluidRaw = w
  42.           elseif i == "amount" then
  43.             fluidAmount = w
  44.           elseif i == "name" then
  45.             fluidName = w
  46.           end
  47.         end
  48.       end
  49.     end
  50.  
  51.     return fluidRaw, fluidName, fluidAmount, fluidCapacity -- Returning the values of global variables (which are nil).
  52. end
  53.  
  54.  
  55. --// Programme de controle reacteur
  56.  
  57.  
  58. while true do
  59.  
  60. local fluidRaw, fluidName, fluidAmount, fluidCapacity = getTank(tank)
  61.  
  62. if fluidName then
  63.     -- Get values for tank capacity and amount
  64.     fluidName = string.gsub(fluidName, "^%l", string.upper)
  65.     cap = fluidCapacity / 1000
  66.     amount = fluidAmount
  67. end
  68.  
  69. if amount == nil then
  70.       amount = 0
  71.       percentfull = 0
  72.     else
  73.       -- Use math.floor to convert to integers
  74.       amount = math.floor(amount / 1000)
  75.       percentfull = math.floor(100 * amount / cap)
  76. end
  77.  
  78.    
  79. if percentfull < 40 then
  80.     reactor.setActive(true)
  81.     rodLevel = minRodLevel
  82.     reactor.setAllControlRodLevels(rodLevel)
  83.    
  84. end
  85.  
  86. if percentfull > 60 then
  87.     rodLevel = maxRodLevel
  88.     reactor.setAllControlRodLevels(rodLevel)
  89.    
  90. end
  91.  
  92. if percentfull > 75 then
  93.     reactor.setActive(false)
  94. end
  95.  
  96. enderMonitorRedstone = redstone.getInput("right")
  97.  
  98. if enderMonitorRedstone then
  99.     turbine.setInductorEngaged (true)
  100.     turbine2.setInductorEngaged (true)
  101.     else
  102.     turbine.setInductorEngaged (false)
  103.     turbine2.setInductorEngaged (false)
  104. end
  105.  
  106. rpmTurbine = turbine.getRotorSpeed()
  107.  
  108. if rpmTurbine < minRpmTurbine then
  109.     turbine.setActive(true)
  110. end
  111.  
  112. if rpmTurbine > maxRpmTurbine then
  113.     turbine.setActive(false)
  114. end
  115.  
  116. rpmTurbine2 = turbine2.getRotorSpeed()
  117.  
  118. if rpmTurbine2 < minRpmTurbine then
  119.     turbine2.setActive(true)
  120. end
  121.  
  122. if rpmTurbine2 > maxRpmTurbine then
  123.     turbine2.setActive(false)
  124. end
  125.  
  126. capacitorEnergy = capacitor.getEnergyStored("unknown") * nbSlot
  127. capacitorEnergyMax = capacitor.getMaxEnergyStored("unknown") * nbSlot
  128. percentcelule = math.floor(100 * capacitorEnergy / capacitorEnergyMax )
  129.  
  130.  
  131. local tableau = {reacteur = reactor.getActive(), barreLevel = reactor.getControlRodLevel(1),conso = reactor.getFuelConsumedLastTick() ,steam = amount , capacity = cap , percent = percentfull, turbine = turbine.getActive() , rpm = rpmTurbine , electroAimant = turbine.getInductorEngaged() , energy = capacitorEnergy, energyMax = capacitorEnergyMax , celpercent = percentcelule , energyProduct = turbine.getEnergyProducedLastTick()+turbine2.getEnergyProducedLastTick()}
  132. local sendmsg = textutils.serialize(tableau)
  133.  
  134. wifi.transmit(2,0,sendmsg)
  135.  
  136. sleep(2)
  137.  
  138. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement