Advertisement
footballfan12

[CC] Reactor Glass

Sep 17th, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.83 KB | None | 0 0
  1. debugger = true --TURN DEBUG CONSOLE ON(true)/OFF(false)
  2. refreshrate = 1 --RATE THE VALUES REFRESH (IN SECONDS)
  3. --[[
  4. Code name:
  5.     Reactor Glass
  6.  
  7. Mod requirements:
  8.     Open Peripherals
  9.     Big Reactors
  10.    
  11. Coded by Cameron Lund
  12.     Bukkit: ShadowDisruptor
  13.     BukkitDev: ShadowDisrupter
  14.     Minecraft: footballfan12
  15.     Pastebin: footballfan12
  16.    
  17. License
  18.     Fair-use
  19. --]]
  20.  
  21. --General setup
  22. term.clear()
  23. print("Booting ReactorGlass")
  24. local bridge = peripheral.wrap("top")
  25. bridge.clear()
  26.  
  27. casingTemp = 0
  28. fuelTemp = 0
  29.  
  30. --Function to draw logo
  31. --Please DO NOT take this away! This is my credit for the code.
  32. function drawLogo(x,y)
  33.     reactorsFound = bridge.addText(x,y+20,("starting"),0xe0e0e0)
  34.     reactorsFound.setScale(0.5)
  35.     logo = bridge.addIcon(x,y,0764,16384)
  36.     text1 = bridge.addText(x+17,y+3,"FootCo Tech.",0xe0e0e0)
  37.     text2 = bridge.addText(x+17,y+12,"Simplicity for all",0xe0e0e0)
  38.     text2.setScale(0.5)
  39. end
  40.  
  41. drawLogo(10,10)
  42. reactorsFound.setText("Setting variables")
  43. local bigReactors = {}
  44. local passiveReactors = {}
  45. local activeReactors = {}
  46. local allowedCommanders = {}
  47. local bridges = { }
  48. local messages={}
  49. local textBoxs={}
  50. local white=0xFAFFFF
  51. local black=0xE6F5EB
  52. local yellow=0xFFFFA3
  53. local red=0xFF0000
  54. local hasPassives = false
  55. local hasActives = false
  56. sleep(0.2)
  57. reactorsFound.setText("Compiling functions")
  58.  
  59. --Following functions are used to get data from reactors.
  60. --  Internal energy(Buffer)
  61. function getEnergy()
  62.     local energy = 0
  63.     local maxEnergy = 0
  64.     for i=1,#passiveReactors do
  65.         local tempReactor = peripheral.wrap(passiveReactors[i])  
  66.         energy = energy + tempReactor.getEnergyStored()
  67.         maxEnergy = maxEnergy + 10000000
  68.     end
  69.     local step1 = energy * 100
  70.     local step2 = step1/maxEnergy
  71.     local step3 = math.floor(step2 + 0.5)
  72.     return step3
  73. end
  74.  
  75. --  Internal fuel
  76. function getInternalFuel()
  77.     local fuel = 0
  78.     local maxFuel = 0
  79.     for i=1,#passiveReactors do
  80.         tempReactor = peripheral.wrap(passiveReactors[i])
  81.         fuel = fuel + tempReactor.getFuelAmount()
  82.         maxFuel = maxFuel + tempReactor.getFuelAmountMax()
  83.     end
  84.     local step1 = fuel * 100
  85.     local step2 = step1/maxFuel
  86.     local step3 = math.floor(step2 + 0.5)
  87.     return step3
  88. end
  89.  
  90. --  Fuel temperature active
  91. function getFuelTemperature2()
  92.     local temp = 0
  93.     local maxTemp = 0
  94.     for i=1,#activeReactors do
  95.         tempReactor = peripheral.wrap(activeReactors[i])
  96.         temp = temp + tempReactor.getFuelTemperature()
  97.         maxTemp = maxTemp + 3500
  98.         fuelTemp = temp
  99.     end
  100.     local step1 = temp*100
  101.     local step2 = step1/maxTemp
  102.     local step3 = math.floor(step2 + 0.5)
  103.     return step3
  104. end
  105.  
  106. --  Fuel temperature passive
  107. function getFuelTemperature()
  108.     local temp = 0
  109.     local maxTemp = 0
  110.     for i=1,#passiveReactors do
  111.         tempReactor = peripheral.wrap(passiveReactors[i])
  112.         temp = temp + tempReactor.getFuelTemperature()
  113.         maxTemp = maxTemp + 3500
  114.         fuelTemp = temp
  115.     end
  116.         for i=1,#activeReactors do
  117.         tempReactor = peripheral.wrap(activeReactors[i])
  118.         temp = temp + tempReactor.getFuelTemperature()
  119.         maxTemp = maxTemp + 3500
  120.         maxFuelTemp2 = temp
  121.     end
  122.     local step1 = temp*100
  123.     local step2 = step1/maxTemp
  124.     local step3 = math.floor(step2 + 0.5)
  125.     return step3
  126. end
  127. --  Casing temperature
  128. function getCasingTemperature()
  129.     local temp = 0
  130.     local maxTemp = 0
  131.     for i=1,#passiveReactors do
  132.         tempReactor = peripheral.wrap(passiveReactors[i])
  133.         temp = temp + tempReactor.getCasingTemperature()
  134.         maxTemp = maxTemp + 3500
  135.         casingTemp = temp
  136.     end
  137.     local step1 = temp*100
  138.     local step2 = step1/maxTemp
  139.     local step3 = math.floor(step2 + 0.5)
  140.     return step3
  141. end
  142.  
  143. --  Coolant amount (Internal)
  144. function getCoolantAmount()
  145.     return 50
  146. end
  147.  
  148. --  Hot fluid amount (Internal)
  149. function getHotFluidAmount()
  150.     return 50
  151. end
  152.  
  153. -- 
  154. --Function to post to debugger
  155. function chat(message, color , mes )
  156.     if debugger == true then
  157.     xPos1 = 211
  158.     if mes == true then
  159.         message="<CONSOLE> " ..message
  160.     elseif not mes then
  161.         message="<ERROR> " ..message
  162.     end
  163.     if string.len(message)<70 then
  164.         table.insert(textBoxs, bridge.addText(xPos1, 5, message, color))
  165.         textBoxs[#textBoxs].setScale(.5)
  166.         textBoxs[#textBoxs].setY(7+(#textBoxs*6))
  167.         again=false
  168.     else
  169.         table.insert(textBoxs, bridge.addText( xPos1, 5, string.sub(message, 1, 70), color))
  170.         textBoxs[#textBoxs].setScale(.5)
  171.         textBoxs[#textBoxs].setY(7+(#textBoxs*6))
  172.         again=true
  173.     end
  174.     if #textBoxs>8 then
  175.         for i=1,#textBoxs do
  176.             num=#textBoxs-i+1
  177.             if textBoxs[num-1]~= nil then
  178.                 textBoxs[num].setY(textBoxs[num-1].getY())
  179.             else
  180.                 textBoxs[num].delete()
  181.                 table.remove(textBoxs, num)
  182.             end
  183.         end
  184.     end
  185.     if again then
  186.         newMessage(string.sub(message, 70, string.len(message)), color, true)
  187.     end
  188.     sleep(0.5)
  189.     end
  190. end
  191.  
  192. --Function to check which peripherals are reactors
  193. local function isReactor(input)
  194.     local tempReactor = peripheral.wrap(input)
  195.     local checkReactor = tempReactor.getConnected()
  196.     return checkReactor
  197. end
  198.  
  199. --Function to determine active/passive reactors
  200. local function whatIs(input)
  201.     local reactor = peripheral.wrap(input)
  202.     local whatIsIt = reactor.isActivelyCooled()
  203.     if whatIsIt then
  204.         table.insert(activeReactors, input)
  205.     else
  206.         table.insert(passiveReactors, input)
  207.     end
  208. end
  209.  
  210. --Function to draw passive group
  211. function drawPassive(xPos, yPos)
  212.     passiveSubTitle = bridge.addText(xPos-1,yPos-2,("Passive reactor(s) averages"),0xe0e0e0)
  213.     passiveSubTitle.setScale(0.5)
  214.     text1 = bridge.addText((xPos-1),(yPos+3)," Label",0xe0e0e0)
  215.     text1.setScale(0.5)
  216.     text1_1 = bridge.addText((xPos-1),(yPos+7)," Label",0xe0e0e0)
  217.     text1_1.setScale(0.5)
  218.     outline1 = bridge.addBox((xPos-1),(yPos+11),52,7,0xe0e0e0)
  219.     barGreen1= bridge.addBox((xPos),(yPos+12),0,5,0x4dff4d,0.7)
  220.     barYellow1 = bridge.addBox((xPos+17),(yPos+12),0,5,0xffff4d,0.7)
  221.     barRed1 = bridge.addBox((xPos+33),(yPos+12),0,5,0xff3333,0.7)
  222.     ourBar1 = {barGreen1,barYellow1,barRed1,outline1,text1,text1_1}
  223.  
  224.     text2 = bridge.addText((xPos+54),(yPos+3)," Label",0xe0e0e0)
  225.     text2.setScale(0.5)
  226.     text2_1 = bridge.addText((xPos+54),(yPos+7)," Label",0xe0e0e0)
  227.     text2_1.setScale(0.5)
  228.     outline2 = bridge.addBox((xPos+54),(yPos+11),52,7,0xe0e0e0)
  229.     barGreen2= bridge.addBox((xPos+55),(yPos+12),0,5,0x4dff4d,0.7)
  230.     barYellow2 = bridge.addBox((xPos+71),(yPos+12),0,5,0xffff4d,0.7)
  231.     barRed2 = bridge.addBox((xPos+87),(yPos+12),0,5,0xff3333,0.7)
  232.     ourBar2 = {barGreen2,barYellow2,barRed2,outline2,text2,text2_1}
  233.  
  234.     text3 = bridge.addText((xPos-1),(yPos+19)," Label",0xe0e0e0)
  235.     text3.setScale(0.5)
  236.     text3_1 = bridge.addText((xPos-1),(yPos+23)," Label",0xe0e0e0)
  237.     text3_1.setScale(0.5)
  238.     outline3 = bridge.addBox((xPos-1),(yPos+27),52,7,0xe0e0e0)
  239.     barGreen3= bridge.addBox((xPos),(yPos+28),0,5,0x4dff4d,0.7)
  240.     barYellow3 = bridge.addBox((xPos+17),(yPos+28),0,5,0xffff4d,0.7)
  241.     barRed3 = bridge.addBox((xPos+33),(yPos+28),0,5,0xff3333,0.7)
  242.     ourBar3 = {barGreen3,barYellow3,barRed3,outline3,text3,text3_1}
  243.  
  244.     text4 = bridge.addText((xPos+54),(yPos+19)," Label",0xe0e0e0)
  245.     text4.setScale(0.5)
  246.     text4_1 = bridge.addText((xPos+54),(yPos+23)," Label",0xe0e0e0)
  247.     text4_1.setScale(0.5)
  248.     outline4 = bridge.addBox((xPos+54),(yPos+27),52,7,0xe0e0e0)
  249.     barGreen4= bridge.addBox((xPos+55),(yPos+28),0,5,0x4dff4d,0.7)
  250.     barYellow4 = bridge.addBox((xPos+71),(yPos+28),0,5,0xffff4d,0.7)
  251.     barRed4 = bridge.addBox((xPos+87),(yPos+28),0,5,0xff3333,0.7)
  252.     ourBar4 = {barGreen4,barYellow4,barRed4,outline4,text4,text4_1}
  253.     ourBar4 = {barGreen4,barYellow4,barRed4,outline4,text4,text4_1}
  254.    
  255.     text_rf_tick = bridge.addText((xPos-1),(yPos+32),"KiRF/t: ",0xe0e0e0)
  256.     text_fuel_burnup = bridge.addText((xPos-1),(yPos+36),"Fuel burnup rate:",0xe0e0e0)
  257.     text_rf_tick.setScale(0.5)
  258.     text_fuel_burnup.setScale(0.5)
  259. end
  260.  
  261. --Function to draw active group
  262. function drawActive(xPos, yPos)
  263.     activeSubTitle = bridge.addText(xPos-1,yPos-2,("Active reactor(s) totals"),0xe0e0e0)
  264.     activeSubTitle.setScale(0.5)
  265.     text5 = bridge.addText((xPos-1),(yPos+3)," Label",0xe0e0e0)
  266.     text5.setScale(0.5)
  267.     outline5 = bridge.addBox((xPos-1),(yPos+7),53,7,0xe0e0e0)
  268.     barGreen5= bridge.addBox((xPos),(yPos+8),0,5,0x4dff4d,0.7)
  269.     barYellow5 = bridge.addBox((xPos+17),(yPos+8),0,5,0xffff4d,0.7)
  270.     barRed5 = bridge.addBox((xPos+33),(yPos+8),0,5,0xff3333,0.7)
  271.     ourBar5 = {barGreen1,barYellow1,barRed1,outline1,text1}
  272.  
  273.     text6 = bridge.addText((xPos+54),(yPos+3)," Label",0xe0e0e0)
  274.     text6.setScale(0.5)  
  275.     outline6 = bridge.addBox((xPos+54),(yPos+7),53,7,0xe0e0e0)
  276.     barGreen6= bridge.addBox((xPos+55),(yPos+8),0,5,0x4dff4d,0.7)
  277.     barYellow6 = bridge.addBox((xPos+71),(yPos+8),0,5,0xffff4d,0.7)
  278.     barRed6 = bridge.addBox((xPos+87),(yPos+8),0,5,0xff3333,0.7)
  279.     ourBar6 = {barGreen2,barYellow2,barRed2,outline2,text2}
  280.  
  281.     text7 = bridge.addText((xPos-1),(yPos+17)," Label",0xe0e0e0)
  282.     text7.setScale(0.5)  
  283.     outline7 = bridge.addBox((xPos-1),(yPos+21),53,7,0xe0e0e0)
  284.     barGreen7= bridge.addBox((xPos),(yPos+22),0,5,0x4dff4d,0.7)
  285.     barYellow7 = bridge.addBox((xPos+17),(yPos+22),0,5,0xffff4d,0.7)
  286.     barRed7 = bridge.addBox((xPos+33),(yPos+22),0,5,0xff3333,0.7)
  287.     ourBar7 = {barGreen3,barYellow3,barRed3,outline3,text3}
  288.  
  289.     text8 = bridge.addText((xPos+54),(yPos+17)," Label",0xe0e0e0)
  290.     text8.setScale(0.5)  
  291.     outline8 = bridge.addBox((xPos+54),(yPos+21),53,7,0xe0e0e0)
  292.     barGreen8= bridge.addBox((xPos+55),(yPos+22),0,5,0x4dff4d,0.7)
  293.     barYellow8 = bridge.addBox((xPos+71),(yPos+22),0,5,0xffff4d,0.7)
  294.     barRed8 = bridge.addBox((xPos+87),(yPos+22),0,5,0xff3333,0.7)
  295.     ourBar8 = {barGreen4,barYellow4,barRed4,outline4,text4}
  296. end
  297.  
  298. --Function to update our bars
  299. function updateBar(tableName, number)
  300.     while true do
  301.         if number <= 16 then
  302.             tableName[1].setWidth(number)
  303.             tableName[2].setWidth(0)
  304.             tableName[3].setWidth(0)
  305.             break
  306.         elseif ((number >= 17) and (number <= 32)) then
  307.             tableName[2].setWidth(number-16)
  308.             tableName[1].setWidth(16)
  309.             tableName[3].setWidth(0)
  310.             break
  311.         elseif ((number >= 33) and (number <= 50)) then
  312.             tableName[3].setWidth(number-32)
  313.             tableName[1].setWidth(16)
  314.             tableName[2].setWidth(16)
  315.             break
  316.         end
  317.     end
  318. end
  319.  
  320. --Function to update bar labels
  321. function updateLabel(labelName , labelText, suffix, number)
  322.     labelName[5].setText(labelText..": ")
  323.     local message = math.floor(number)..suffix
  324.     labelName[6].setText(message)
  325. end  
  326.  
  327. --END OF FUNCTIONS
  328. reactorsFound.setText("Managing peripherals..")
  329. print("Looking for peripherals...")
  330. foundPeripherals = peripheral.getNames()
  331.  if not (#foundPeripherals == 0) then
  332.     chat(#foundPeripherals.." peripherals found!",yellow,true)
  333.     chat("Checking if any peripherals are reactors...",yellow,true)
  334.     for i=1,#foundPeripherals do
  335.         local ok, err = pcall(isReactor, foundPeripherals[i])
  336.         if ok then
  337.             table.insert(bigReactors, foundPeripherals[i])
  338.         else
  339.             chat(foundPeripherals[i].." is not a reactor!",red,false)
  340.         end  
  341.     end
  342.     foundPeripherals = nil
  343.     if #bigReactors > 0 then
  344.         chat("Checking the "..#bigReactors.." big reactors items for passive/active",yellow,true)
  345.         for i=1,#bigReactors do
  346.             local ok, err = pcall(whatIs,bigReactors[i])
  347.         end
  348.         chat("Active reactors found: "..#activeReactors,yellow,true)
  349.         chat("Passive reactors found: "..#passiveReactors,yellow,true)
  350.     else
  351.         reactorsFound.setText("No reactors found!")
  352.         chat("No reactors found!",red,false)
  353.     end
  354. else
  355.     print("No peripherals found!")
  356. end
  357.  
  358. --##############
  359. --#END OF SETUP#
  360. --##############  
  361.    
  362. --Checking what we're working with...
  363. if #passiveReactors > 0 then
  364.     hasPassives = true
  365. end
  366. if #activeReactors > 0 then
  367.     hasActives = true
  368. end
  369.  
  370. --Drawing the GUI accordingly...
  371. if ((hasPassives == true) and (hasActives == true)) then--We have both active and passive
  372.     drawPassive(10,40)
  373.     drawActive(10,80)
  374. elseif ((hasPassives == false) and (hasActives == true)) then--We just have active
  375.     drawActive(10,40)
  376. elseif ((hasPassives == true) and (hasActives == false)) then--We just have passive
  377.     drawPassive(10,40)
  378. else
  379.     chat("Neither actives or passives being found!",red,false)
  380. end
  381. --FIX THIS
  382. reactorsFound.setText("Found reactors: "..#passiveReactors.." passive, "..#activeReactors.." active.")
  383.  
  384. function updateBoard()
  385.     if hasPassives then
  386.         updateBar(ourBar1, (getEnergy()/2))
  387.         updateBar(ourBar2, (getInternalFuel()/2))
  388.         updateBar(ourBar3, (getFuelTemperature()/2))
  389.         updateBar(ourBar4, (getCasingTemperature()/2))
  390.         updateLabel(ourBar1, "Buffer","%",getEnergy())
  391.         updateLabel(ourBar2, "Internal fuel","%",getInternalFuel())
  392.         updateLabel(ourBar3, "Fuel temperature"," C",math.floor(fuelTemp/#passiveReactors))
  393.         updateLabel(ourBar4, "Casing temperature"," C",math.floor(casingTemp/#passiveReactors))
  394.         end
  395.     if hasActives then
  396.         updateBar(ourBar5, (getEnergy()/2))
  397.         updateBar(ourBar6, (getInternalFuel()/2))
  398.         updateBar(ourBar7, (getFuelTemperature()/2))
  399.         updateBar(ourBar8, (getCasingTemperature()/2))
  400.         updateLabel(ourBar5, "Internal fuel","%",getInternalFuel2())
  401.         updateLabel(ourBar6, "Fuel temperature","C",maxFuelTemp2)
  402.         updateLabel(ourBar7, "Fuel temperature"," C",maxFuelTemp)
  403.         updateLabel(ourBar8, "Casing temperature"," C",maxCasingTemp)
  404.     end
  405. end
  406.  
  407. while true do
  408.     updateBoard()
  409.     sleep(refreshrate)
  410. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement