Guest User

startup

a guest
Oct 23rd, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.82 KB | None | 0 0
  1. ----------------- Lejoni Edition ------------------
  2. --- This is a Extreme Reactors control program  ---
  3. --- for Minecraft mod ComputerCraft             ---
  4. ---                                             ---
  5. --- Original by Direwolf20 from:                ---
  6. --- pastebin get R4kXR7RU reactor               ---
  7. --- and it also uses the button API:            ---
  8. --- pastebin get XBbMUYNn button                ---
  9. ---                                             ---
  10. --- Edited by Lejoni to adapt it for use with   ---
  11. --- Draconic Evolution Energy Storage Core.     ---
  12. --- As well as some minor tweaks.               ---
  13. --- Edits are commented in code.                ---
  14. ---------------------------------------------------
  15.  
  16. os.loadAPI("button")
  17. --- Lejoni Edit ---
  18. p = peripheral.find("draconic_rf_storage")
  19. -------------------
  20. m = peripheral.find("monitor")
  21. r = peripheral.find("BigReactors-Reactor")
  22. t = peripheral.find("BigReactors-Turbine")
  23.  
  24. -- Lejonis Edits --
  25. local txtScale = 1
  26. local colum2 = 28
  27. -------------------
  28. local steamReactor = r.isActivelyCooled()
  29. local menuType = "Reactor"
  30.  
  31. local numCapacitors = 1
  32. local turnOnAt = 50
  33. local turnOffAt = 90
  34.  
  35. local energy = 0
  36. local energyStored = 0
  37. local energyMax = 0
  38. local energyStoredPercent = 0
  39. local timerCode
  40. local mode = "Automatic"
  41. local RFProduction = 0
  42. local fuelUse = 0
  43. local coreTemp = 0
  44. local reactorOnline = false
  45. local rodLevel = 0
  46.  
  47. local turbineOnline = false
  48. local turbineRotorSpeed = 0
  49. local turbineRFGen = 0
  50. local turbineFluidRate = 0
  51. local turbineInductor = false
  52.  
  53. local OptFuelRodLevel = 0
  54.  
  55. function autoMenu()
  56.    m.setTextScale(txtScale) --- Lejoni Edit ---
  57.    button.clearTable()
  58.    button.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
  59.    button.setTable("Manual", manualMode, "", 15, 25, 6, 6)
  60.    
  61.    if steamReactor then
  62.       button.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19)
  63.       button.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19)
  64.    end
  65.    button.screen()
  66.    checkMode()
  67.    menuMode()
  68. end
  69.  
  70. function manualMenu()
  71.    m.setTextScale(txtScale) --- Lejoni Edit ---
  72.    button.clearTable()
  73.    button.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
  74.    button.setTable("Manual", manualMode, "", 15, 25, 6, 6)
  75.    button.setTable("Online", online, "", 3, 13, 8, 8)
  76.    button.setTable("Offline", offline, "", 15, 25, 8, 8)
  77.    button.setTable("0", setRods, 0, 11,14, 10, 10)
  78.    button.setTable("10", setRods, 10, 5,8, 12, 12)
  79.    button.setTable("20", setRods, 20, 11,14, 12, 12)
  80.    button.setTable("30", setRods, 30, 17,20, 12, 12)
  81.    button.setTable("40", setRods, 40, 5,8, 14, 14)
  82.    button.setTable("50", setRods, 50, 11,14, 14, 14)
  83.    button.setTable("60", setRods, 60, 17,20, 14, 14)
  84.    button.setTable("70", setRods, 70, 5,8, 16, 16)
  85.    button.setTable("80", setRods, 80, 11,14, 16, 16)
  86.    button.setTable("90", setRods, 90, 17,20, 16, 16)
  87.    button.setTable("+", rodPlus, "", 23, 25, 12, 12)
  88.    button.setTable("-", rodMinus, "", 23, 25, 16, 16)
  89.  
  90.    if steamReactor then
  91.       button.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19)
  92.       button.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19)
  93.      
  94.    end
  95.    button.screen()
  96.    checkMode()
  97.    reactorOnOff()
  98.    menuMode()
  99. end
  100.  
  101. function turbineAutoMenu()
  102.    m.setTextScale(txtScale) --- Lejoni Edit ---
  103.    button.clearTable()
  104.    button.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
  105.    button.setTable("Manual", manualMode, "", 15, 25, 6, 6)
  106.    button.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19)
  107.    button.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19)
  108.    button.screen()
  109.    checkMode()
  110.    menuMode()
  111. end
  112.  
  113. function turbineManualMenu()
  114.    m.setTextScale(txtScale) --- Lejoni Edit ---
  115.    button.clearTable()
  116.    button.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
  117.    button.setTable("Manual", manualMode, "", 15, 25, 6, 6)
  118.    button.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19)
  119.    button.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19)
  120.    button.setTable("Online", setTurbineOnline, "", 3, 13, 8, 8)
  121.    button.setTable("Offline", setTurbineOffline, "", 15, 25, 8, 8)
  122.    button.setTable("Coils On", coilsOn, "", 3, 13, 10, 10)
  123.    button.setTable("Coils Off", coilsOff, "", 15, 25, 10, 10)
  124.    button.screen()
  125.    checkMode()
  126.    turbineOnOff()
  127.    coilsOnOff()
  128.    menuMode()
  129. end
  130.  
  131. function reactorMenu()
  132.    menuType = "Reactor"
  133.    displayScreen()
  134. end
  135.  
  136. function turbineMenu()
  137.    menuType = "Turbine"
  138.    displayScreen()
  139. end
  140.  
  141. function online()
  142.    r.setActive(true)
  143.    --button.flash("Online")
  144. end
  145.  
  146. function offline()
  147.    r.setActive(false)
  148.    --button.flash("Offline")
  149. end
  150.  
  151. function setTurbineOnline()
  152.    t.setActive(true)
  153.    --button.flash("Online")
  154. end
  155.  
  156. function setTurbineOffline()
  157.    t.setActive(false)
  158.    --button.flash("Offline")
  159. end
  160.  
  161. function reactorOnOff()
  162.    button.setButton("Online", r.getActive())
  163.    button.setButton("Offline", not r.getActive())
  164. end
  165.  
  166. function turbineOnOff()
  167.    button.setButton("Online", t.getActive())
  168.    button.setButton("Offline", not t.getActive())
  169. end
  170.  
  171. function coilsOnOff()
  172.    button.setButton("Coils On", t.getInductorEngaged())
  173.    button.setButton("Coils Off", not t.getInductorEngaged())
  174. end
  175.  
  176. function coilsOn()
  177.    t.setInductorEngaged(true)
  178. end
  179.  
  180. function coilsOff()
  181.    t.setInductorEngaged(false)
  182. end
  183.  
  184. function menuMode()
  185.    if steamReactor then
  186.    if menuType == "Reactor" then
  187.      button.setButton("Reactor", true)
  188.      button.setButton("Turbine", false)
  189.    else
  190.      button.setButton("Reactor", false)
  191.      button.setButton("Turbine", true)
  192.    end
  193.    end
  194. end
  195.  
  196. function setRods(setLevel)
  197.    print("Setting Rod Level: "..setLevel)
  198.    button.flash(tostring(setLevel))
  199.    r.setAllControlRodLevels(setLevel)
  200.    fuelRodLevel()
  201. end
  202.  
  203. function rodPlus()
  204.    button.flash("+")
  205.    r.setAllControlRodLevels(rodLevel+1)
  206.    fuelRodLevel()
  207. end
  208.  
  209. function rodMinus()
  210.    button.flash("-")
  211.    r.setAllControlRodLevels(rodLevel-1)
  212.    fuelRodLevel()
  213. end
  214.  
  215. function checkMode()
  216.    button.toggleButton(mode)
  217. end
  218.    
  219. function manualMode()
  220.    mode = "Manual"
  221.    manualMenu()
  222. end
  223.  
  224. function autoMode()
  225.    mode = "Automatic"
  226.    displayScreen()
  227. end
  228.  
  229. function comma_value(amount)
  230.    local formatted = amount
  231.    local swap = false
  232.    if formatted < 0 then
  233.       formatted = formatted*-1
  234.       swap = true
  235.    end
  236.    while true do
  237.       formatted, k = string.gsub(formatted, "^(%d+)(%d%d%d)", '%1,%2')
  238.       if k == 0 then
  239.          break
  240.       end
  241.    end
  242.    if swap then
  243.      formatted = "-"..formatted
  244.    end
  245.    return formatted
  246. end
  247.  
  248. function displayEn()
  249.    m.clear()
  250.    m.setCursorPos(1,1)
  251.    --print("Energy Use: "..energy)
  252.    m.write("Energy Use: ")
  253.    if energy < 0 then
  254.       m.setTextColor(colors.red)
  255.    else
  256.       m.setTextColor(colors.green)
  257.    end
  258.    m.write(comma_value(math.floor(energy)).. "RF/t")
  259.    m.setTextColor(colors.white)
  260.    m.setCursorPos(1,2)
  261.    m.write("Energy Stored: "..energyStoredPercent.."%")
  262.    if menuType == "Reactor" then
  263.       m.setCursorPos(1,3)
  264.       m.write("Reactor is: ")
  265.       if reactorOnline then
  266.        m.setTextColor(colors.green)
  267.        m.write("Online")
  268.       else
  269.        m.setTextColor(colors.red)
  270.        m.write("Offline")
  271.       end
  272.       m.setTextColor(colors.white)
  273.       m.setCursorPos(colum2,1) --- Lejoni Edit ---
  274.       if steamReactor then
  275.          m.write("Steam: ")
  276.          m.setTextColor(colors.green)
  277.          m.write(comma_value(math.floor(RFProduction)).."MB/t")
  278.       else
  279.          m.write("RF Gen: ")
  280.          m.setTextColor(colors.green)
  281.          m.write(comma_value(math.floor(RFProduction)).."RF/t")
  282.       end
  283.       m.setTextColor(colors.white)
  284.       m.setCursorPos(colum2,2) --- Lejoni Edit ---
  285.       m.write("Core Temp: "..math.floor(coreTemp).."c")
  286.       m.setCursorPos(colum2,3) --- Lejoni Edit ---
  287.       m.write("Fuel Use: "..fuelUse.."MB/t")  
  288.   else
  289.       m.setCursorPos(1,3)
  290.       m.write("Turbine is: ")
  291.       if turbineOnline then
  292.        m.setTextColor(colors.green)
  293.        m.write("Online")
  294.       else
  295.        m.setTextColor(colors.red)
  296.        m.write("Offline")
  297.       end
  298.       m.setCursorPos(1,4)
  299.       m.setTextColor(colors.white)
  300.       m.write("Reactor is: ")
  301.       if reactorOnline then
  302.          m.setTextColor(colors.green)
  303.          m.write("Online")
  304.       else
  305.          m.setTextColor(colors.red)
  306.          m.write("Offline")
  307.       end
  308.       m.setTextColor(colors.white)
  309.       m.setCursorPos(colum2,1) --- Lejoni Edit ---
  310.       m.write("RFGen: ")
  311.       m.setTextColor(colors.green)
  312.       m.write(comma_value(math.floor(turbineRFGen)).."RF/t")
  313.       m.setTextColor(colors.white)
  314.       m.setCursorPos(colum2,2) --- Lejoni Edit ---
  315.       m.write("Rotor: "..comma_value(math.floor(turbineRotorSpeed)).." RPM")
  316.       m.setCursorPos(colum2,3) --- Lejoni Edit ---
  317.       m.write("Steam: "..comma_value(turbineFluidRate).."MB/t")  
  318.   end
  319.  
  320. end
  321.  
  322. function checkEn()
  323.    local tempEnergy = 0
  324.    energyStored = p.getEnergyStored()
  325.    energyMax = p.getMaxEnergyStored()
  326.    energyStoredPercent = math.floor((energyStored/energyMax)*100)
  327.    --- Lejoni Edit ---
  328.    if steamReactor then
  329.       RFProduction = t.getEnergyProducedLastTick()
  330.    else
  331.       RFProduction = r.getEnergyProducedLastTick()
  332.    end
  333.    -------------------
  334.    fuelUse = r.getFuelConsumedLastTick()
  335.    fuelUse = math.floor(fuelUse*100)
  336.    fuelUse = fuelUse/100
  337.    coreTemp = r.getFuelTemperature()
  338.    reactorOnline = r.getActive()
  339.    tempEnergy = p.getEnergyStored()
  340.    sleep(0.1)
  341.    --- Lejoni Edit ---
  342.    energy = RFProduction - ((p.getEnergyStored()-tempEnergy)/2)
  343.    -------------------
  344.    energy = energy*numCapacitors
  345.    if steamReactor then
  346.      turbineOnline = t.getActive()
  347.      turbineRotorSpeed = t.getRotorSpeed()
  348.      turbineRFGen = t.getEnergyProducedLastTick()
  349.      turbineFluidRate = t.getFluidFlowRate()
  350.    end
  351. end
  352.  
  353. function fuelRodLevel()
  354.    rodLevel = r.getControlRodLevel(0)
  355.    --print(rodLevel)
  356.    m.setCursorPos(30,5)
  357.    m.write(tostring(rodLevel).."%")
  358.    m.setBackgroundColor(colors.white)
  359.    m.setCursorPos(28,6)
  360.    m.write("       ")
  361.    for i = 1,10 do
  362.       m.setCursorPos(28,i+6)
  363.       m.setBackgroundColor(colors.white)
  364.       m.write(" ")
  365.       m.setBackgroundColor(colors.yellow)
  366.       m.write(" ")
  367.       if rodLevel/10 >= i then
  368.          m.setBackgroundColor(colors.red)
  369.       else
  370.          m.setBackgroundColor(colors.yellow)
  371.       end
  372.       m.write("   ")
  373.       m.setBackgroundColor(colors.yellow)
  374.       m.write(" ")
  375.       m.setBackgroundColor(colors.white)
  376.       m.write(" ")
  377.    end
  378.    m.setCursorPos(28,17)
  379.    m.write("       ")
  380.    m.setBackgroundColor(colors.black)
  381. end
  382.  
  383. function turbineInductorDisplay()
  384.    turbineInductor = t.getInductorEngaged()
  385.    m.setCursorPos(30,5)
  386.    if turbineInductor then
  387.       m.write("On")
  388.    else
  389.       m.write("Off")
  390.    end
  391.    m.setBackgroundColor(colors.gray)
  392.    m.setCursorPos(28,6)
  393.    m.write("       ")
  394.    for i = 1,7 do
  395.       m.setCursorPos(28,i+6)
  396.       m.setBackgroundColor(colors.gray)
  397.       m.write(" ")
  398.       m.setBackgroundColor(colors.lightGray)
  399.       m.write(" ")
  400.       if i % 2 == 0 then
  401.          m.setBackgroundColor(colors.gray)
  402.       end
  403.       m.write(" ")
  404.       m.setBackgroundColor(colors.gray)
  405.       m.write(" ")
  406.       if i % 2 ~= 0 then
  407.          m.setBackgroundColor(colors.lightGray)
  408.       end
  409.       m.write(" ")
  410.       m.setBackgroundColor(colors.lightGray)
  411.       m.write(" ")
  412.       m.setBackgroundColor(colors.gray)
  413.       m.write(" ")
  414.    end
  415.    for i = 8,10 do
  416.    m.setCursorPos(28,i+6)
  417.       m.setBackgroundColor(colors.gray)
  418.       m.write(" ")
  419.       m.setBackgroundColor(colors.lightGray)
  420.       m.write(" ")
  421.       if turbineInductor then
  422.          m.setBackgroundColor(colors.red)
  423.       else
  424.          m.setBackgroundColor(colors.blue)
  425.       end
  426.       m.write(" ")
  427.       m.setBackgroundColor(colors.gray)
  428.       m.write(" ")
  429.       if turbineInductor then
  430.          m.setBackgroundColor(colors.red)
  431.       else
  432.          m.setBackgroundColor(colors.blue)
  433.       end
  434.       m.write(" ")
  435.       m.setBackgroundColor(colors.lightGray)
  436.       m.write(" ")
  437.       m.setBackgroundColor(colors.gray)
  438.       m.write(" ")
  439.    end
  440.    m.setCursorPos(28,17)
  441.    m.write("       ")
  442.    m.setBackgroundColor(colors.black)
  443. end
  444. function getClick()
  445.    local event, side, x, y = os.pullEvent("monitor_touch")
  446.    button.checkxy(x,y)
  447. end
  448.  
  449. function findOptFuelRods()
  450.    m.clear()
  451.    r.setActive(false)
  452.    checkEn()
  453.    displayEn()
  454.    fuelRodLevel()
  455.    while r.getFuelTemperature() > 99 do
  456.       for i= 1,3 do
  457.         checkEn()
  458.         displayEn()
  459.         fuelRodLevel()
  460.         m.setCursorPos(3,6)
  461.         m.write("Finding Optimal Rod Level")
  462.         m.setCursorPos(3,7)
  463.         m.write("Core Temp: "..r.getFuelTemperature())
  464.         m.setCursorPos(3,8)
  465.         m.write("Waiting for 99c")
  466.         sleep(1)
  467.       end
  468.    end
  469.    while r.getHotFluidAmount() > 10000 do
  470.      for i = 1,3 do
  471.         checkEn()
  472.         displayEn()
  473.         fuelRodLevel()
  474.         m.setCursorPos(3,6)
  475.         m.write("Finding Optimal Rod Level, please wait....")
  476.         m.setCursorPos(3,7)
  477.         m.write("Fluid Amount: "..comma_value(r.getHotFluidAmount()).."mb")
  478.         m.setCursorPos(3,8)
  479.         m.write("Waiting for 10,000mb")
  480.         sleep(1)
  481.       end
  482.    end
  483.    r.setAllControlRodLevels(99)
  484.    r.setActive(true)
  485.    
  486.    while r.getFuelTemperature() < 100 do
  487.    for i = 1,5 do
  488.      checkEn()
  489.      displayEn()
  490.      fuelRodLevel()
  491.      m.setCursorPos(3,6)
  492.      m.write("Set all rod levels to 99")
  493.      m.setCursorPos(3,7)
  494.      m.write("Waiting 5 seconds...")
  495.      sleep(1)
  496.    end
  497.    end
  498.    for i = 1,5 do
  499.      checkEn()
  500.      displayEn()
  501.      fuelRodLevel()
  502.      m.setCursorPos(3,6)
  503.      m.write("Set all rod levels to 99")
  504.      m.setCursorPos(3,7)
  505.      m.write("Waiting 5 seconds...")
  506.      sleep(1)
  507.    end
  508.    local tempMB = r.getEnergyProducedLastTick()
  509.    print(tempMB.."MB/t of steam")
  510.    local tempRodLevels = math.floor(2000/tempMB)
  511.    print("2000/"..tempMB.." = "..tempRodLevels)
  512.    tempRodLevels = 100-tempRodLevels+5
  513.    print("Adding 5 to Rod Levels: "..math.floor(tempRodLevels))
  514.    r.setAllControlRodLevels(math.floor(tempRodLevels))
  515.    print("Waiting 10 seconds to confirm...")
  516.    for i = 1,10 do
  517.      checkEn()
  518.      displayEn()
  519.      fuelRodLevel()
  520.      m.setCursorPos(3,6)
  521.      m.write("Estimated Level: "..tempRodLevels)
  522.      m.setCursorPos(3,7)
  523.      m.write("Waiting 10 seconds...")
  524.      sleep(1)
  525.    end
  526.    tempMB = r.getEnergyProducedLastTick()
  527.    while tempMB > 2000 do
  528.       tempRodLevels = tempRodLevels+1
  529.       r.setAllControlRodLevels(math.floor(tempRodLevels))
  530.       print("Setting Rod Levels to: "..tempRodLevels)
  531.       for i = 1,5 do
  532.        checkEn()
  533.        displayEn()
  534.        fuelRodLevel()
  535.        m.setCursorPos(3,6)
  536.        m.write("Getting below 2000mb/t")
  537.        m.setCursorPos(3,7)
  538.        m.write("Currently at: "..tempMB)
  539.        sleep(1)
  540.       end
  541.       tempMB = r.getEnergyProducedLastTick()
  542.    end
  543.    while tempMB < 2000 do
  544.       tempRodLevels = tempRodLevels -1
  545.       r.setAllControlRodLevels(math.floor(tempRodLevels))
  546.       print("Setting Rod Levels to: "..tempRodLevels)
  547.       for i = 1,5 do
  548.        checkEn()
  549.        displayEn()
  550.        fuelRodLevel()
  551.        m.setCursorPos(3,6)
  552.        m.write("Getting Above 2000mb/t")
  553.        m.setCursorPos(3,7)
  554.        m.write("Currently at: "..tempMB)
  555.        sleep(1)
  556.       end
  557.       tempMB = r.getEnergyProducedLastTick()
  558.    end
  559.    OptFuelRodLevel = tempRodLevels
  560. end
  561.    
  562.  
  563. function autoReactor()
  564.    if not steamReactor then
  565.       r.setAllControlRodLevels(0)
  566.       if energyStoredPercent < turnOnAt then
  567.        if not reactorOnline then
  568.          online()
  569.        end
  570.       end
  571.       if energyStoredPercent > turnOffAt then
  572.        if reactorOnline then
  573.          offline()
  574.        end
  575.       end
  576.     else
  577.        r.setAllControlRodLevels(OptFuelRodLevel)
  578.        if energyStoredPercent < turnOnAt then
  579.          --online()
  580.              setTurbineOnline()
  581.              coilsOn()
  582.        end
  583.        if energyStoredPercent > turnOffAt then
  584.          --if turbineRotorSpeed > 1800 then
  585.          --   offline()
  586.          --else
  587.             --   online()
  588.          --end
  589.          setTurbineOnline()
  590.          coilsOff()
  591.        end
  592.     if turbineRotorSpeed > 1800 then
  593.        offline()
  594.     else
  595.        online()
  596.     end
  597.     end
  598. end
  599.  
  600. function displayScreen()
  601.  --  repeat
  602.       checkEn()
  603.       displayEn()
  604.       if menuType == "Reactor" then
  605.         fuelRodLevel()
  606.         if mode == "Automatic" then
  607.            autoMenu()
  608.            autoReactor()
  609.         else
  610.            manualMenu()
  611.         end
  612.        
  613.       else
  614.         turbineInductorDisplay()
  615.         if mode == "Automatic" then
  616.            turbineAutoMenu()
  617.            autoReactor()
  618.         else
  619.            turbineManualMenu()
  620.         end
  621.        
  622.       end
  623.      
  624.       timerCode = os.startTimer(1)
  625.       local event, side, x, y
  626.       repeat
  627.         event, side, x, y = os.pullEvent()
  628.         print(event)
  629.         if event == "timer" then
  630.            print(timerCode..":"..side)
  631.            if timerCode ~= side then
  632.               print("Wrong Code")
  633.             else
  634.               print("Right Code")
  635.             end
  636.         end
  637.        until event~= "timer" or timerCode == side
  638.        if event == "monitor_touch" then
  639.             print(x..":"..y)
  640.             button.checkxy(x,y)
  641.         end
  642.  --  until event ~= "timer"
  643. end
  644.  
  645. if steamReactor then
  646.    findOptFuelRods()
  647. end
  648.  
  649. while true do
  650.    displayScreen()
  651. end
Advertisement
Add Comment
Please, Sign In to add comment