Nike622000

IC2 Reactor display

Oct 26th, 2018
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.78 KB | None | 0 0
  1. local bCol = colors.black
  2. local tCol = colors.white
  3.  
  4. local monSide       = "top"
  5. local reactorCoords = {178,35,5563}
  6. local senIC2Side    = "bottom"
  7. local senIC2Coords  = {185,36,5563}
  8. local senInvSide    = "left"
  9. local senInvCoords  = {185,37,5564}
  10. local bunSide       = "back"
  11.  
  12. --text,displayColor,cableColor
  13. local status = {}
  14. status[1] = {         "Reaktor abgeschaltet.",  colors.gray,               0}
  15. status[2] = {    "Keine Stoerungen gefunden.",  colors.blue,    colors.white}
  16. status[3] = {   "Keine Uranzellen vorhanden.",colors.orange,   colors.orange}
  17. status[4] = {"Keine Isotopezellen vorhanden.",colors.orange,  colors.magenta}
  18. status[5] = {  "Kein Lapis Lazuli vorhanden.",colors.orange,colors.lightBlue}
  19. status[6] = {         "Spieler nicht online.",colors.orange,   colors.yellow}
  20. status[7] = {           "Reaktor ueberhitzt.",   colors.red,     colors.lime}
  21.  
  22. os.loadAPI("ocs/apis/sensor")
  23.  
  24. local m = peripheral.wrap(monSide)
  25. m.setTextScale(.5)
  26. local xMax,yMax = m.getSize()
  27.  
  28. local damageVal  = {}
  29. --Uranium Cells
  30. damageVal[1] = {}
  31. damageVal[1][1] = {"Uranium Cell","Dual Uranium Cell","Quad Uranium Cell"}
  32. damageVal[1][2] = {}
  33. --Isotope and Re-Enriched Cells
  34. damageVal[2] = {}
  35. damageVal[2][1] = {"Depleted Isotope Cell","Re-Enriched Uranium Cell"}
  36. damageVal[2][2] = {}
  37. --Reactor Components
  38. damageVal[3] = {}
  39. damageVal[3][1] = {"Heat Vent","Reactor Heat Vent","Overclocked Heat Vent","Advanced Heat Vent","Component Heat Vent","Heat Exchanger","Reactor Heat Exchanger","Component Heat Exchanger","Advanced Heat Exchanger","RSH-Condensator","LZH-Condensator","Neutron Reflector","Thick Neutron Reflector","10k Coolant Cell","30k Coolant Cell","60k Coolant Cell"}
  40. damageVal[3][2] = {}
  41.  
  42. --Status,Output,Heat,MaxHeat,damageVal(array)
  43. local reactorInfo = {}
  44. reactorInfo[5] = {}
  45.  
  46. function JoJa()
  47.     m.setBackgroundColor(colors.gray)
  48.     m.setCursorPos(1,1)
  49.     for xP = 1,xMax do
  50.         m.write(" ")
  51.     end
  52.     m.setCursorPos(1,1)
  53.     m.setTextColor(colors.cyan)
  54.     m.write("Jo")
  55.     m.setTextColor(colors.orange)
  56.     m.write("Ja ")
  57.     m.setTextColor(colors.lightGray)
  58.     m.write("Productions")
  59. end
  60.  
  61. function drawField(xStart,yStart,xEnd,yEnd,col)
  62.     m.setBackgroundColor(col)
  63.     for yP = yStart,yEnd do
  64.         m.setCursorPos(xStart,yP)
  65.         for xP = xStart,xEnd do
  66.             m.write(" ")
  67.         end
  68.     end
  69. end
  70.  
  71. function bg(col)
  72.     drawField(0,0,xMax,yMax,col)
  73. end
  74.  
  75. function drawFrame(xStart,yStart,xEnd,yEnd,col1,col2,txt)
  76.     drawField(xStart,yStart,xEnd,yEnd,col1)
  77.     drawField(xStart+1,yStart+1,xEnd-1,yEnd-1,col2)
  78.     m.setCursorPos(xStart+2,yStart)
  79.     m.write(" "..txt.." ")
  80. end
  81.  
  82. function showStat()
  83.     local i
  84.     for i = 1,#status do
  85.         if colors.test(rs.getBundledInput(bunSide),status[i][3]) then
  86.             txt = status[i][1]
  87.             col = status[i][2]
  88.         end
  89.     end
  90.     drawField(xMax/2+9, 6,xMax-3,10,col)   
  91.     local arr = {}
  92.     i = 1
  93.     local p = string.find(txt," ")
  94.     while p ~= nil do
  95.         arr[i] = string.sub(txt,1,p-1)
  96.         txt = string.sub(txt,p+1)..""
  97.         i = i+1
  98.         p = string.find(txt," ")
  99.     end
  100.     arr[i] = txt
  101.    
  102.     local j = 1
  103.     i = 1
  104.     temp = arr[1]
  105.     while true do
  106.         i = i+1
  107.         if i > #arr then break end
  108.         while #temp+#arr[i] <= (xMax-4)-(xMax/2+10) do
  109.             temp = temp.." "..arr[i]
  110.             i = i+1
  111.             if i >= #arr then break end
  112.         end
  113.         m.setCursorPos(xMax/2+10,6+j)
  114.         m.write(temp)
  115.         j = j+1
  116.         temp = arr[i]
  117.     end
  118.     m.setCursorPos(xMax/2+10,6+j)
  119.     m.write(temp)
  120. end
  121.  
  122. function drawGraph(xStart,yStart,xEnd,yEnd,col1,col2,val)
  123.     local temp = xStart+math.floor((xEnd-xStart)*(val/100)+.5)
  124.     if temp > xEnd then temp = xEnd end
  125.     for yP = yStart,yEnd do
  126.         m.setCursorPos(xStart,yP)
  127.         m.setBackgroundColor(col1)
  128.         for xP = xStart,temp do
  129.             m.write(" ")
  130.         end
  131.         m.setBackgroundColor(col2)
  132.         if temp+1 <= xEnd then
  133.             for xP = xStart+math.floor((xEnd-xStart)*(val/100)+.5)+1,xEnd do
  134.                 m.write(" ")
  135.             end
  136.         end
  137.     end
  138. end
  139.  
  140. function checkIC2Reactor()
  141.     local s = sensor.wrap(senIC2Side)
  142.     for k1,v1 in pairs(s.getTargets()) do
  143.         if v1.Name == "Nuclear Reactor"
  144.         and v1.Position.X == reactorCoords[1]-senIC2Coords[1]
  145.         and v1.Position.Y == reactorCoords[2]-senIC2Coords[2]
  146.         and v1.Position.Z == reactorCoords[3]-senIC2Coords[3] then
  147.             for k2,v2 in pairs(s.getTargetDetails(k1)) do
  148.                 if k2 == "Active" then
  149.                     reactorInfo[1] = v2
  150.                 elseif k2 == "Output" then
  151.                     reactorInfo[2] = v2
  152.                 elseif k2 == "Heat" then
  153.                     reactorInfo[3] = v2
  154.                 elseif k2 == "MaxHeat" then
  155.                     reactorInfo[4] = v2
  156.                 end
  157.             end
  158.         end
  159.     end
  160. end
  161.  
  162. function checkInvReactor()
  163.     for i = 1,#damageVal do
  164.         damageVal[i][2][1] = 0
  165.         damageVal[i][2][2] = 0
  166.     end
  167.     local s = sensor.wrap(senInvSide)
  168.     for k1,v1 in pairs(s.getTargets()) do
  169.         if v1.Name == "Nuclear Reactor"
  170.         and v1.Position.X == reactorCoords[1]-senInvCoords[1]
  171.         and v1.Position.Y == reactorCoords[2]-senInvCoords[2]
  172.         and v1.Position.Z == reactorCoords[3]-senInvCoords[3] then
  173.             for k2,v2 in pairs(s.getTargetDetails(k1)) do
  174.                 if k2 == "Slots" then
  175.                     for i = 1,#v2 do
  176.                         for j1 = 1,#damageVal do
  177.                             for j2 = 1,#damageVal[j1][1] do
  178.                                 if v2[i].Name == damageVal[j1][1][j2] then
  179.                                     damageVal[j1][2][1] = damageVal[j1][2][1]+v2[i].DamageValue
  180.                                     damageVal[j1][2][2] = damageVal[j1][2][2]+v2[i].Size
  181.                                 end
  182.                             end
  183.                         end
  184.                     end
  185.                 end
  186.             end
  187.         end
  188.     end
  189.     for i = 1,#damageVal do
  190.         reactorInfo[5][i] = 100-((damageVal[i][2][1]/damageVal[i][2][2])/99.9)
  191.         if tostring(reactorInfo[5][i]) == "nan" or reactorInfo[5][i] < 0 then
  192.             reactorInfo[5][i] = 0
  193.         end
  194.     end
  195. end
  196.  
  197. bg(bCol)
  198. JoJa()
  199. m.setTextColor(tCol)
  200. drawFrame(3, 4,xMax/2+4,22,colors.gray,bCol,"Info.")
  201. m.setCursorPos(5,6)
  202. m.write("Status:")
  203. m.setCursorPos(5,8)
  204. m.write("Output:")
  205. m.setCursorPos(5,10)
  206. m.write("Uranium")
  207. m.setCursorPos(5,14)
  208. m.write("Komponenten")
  209. m.setCursorPos(5,18)
  210. m.write("Hitze")
  211. drawFrame(xMax/2+7, 4,xMax-1,12,colors.gray,bCol,"Status")
  212. drawFrame(xMax/2+7,14,xMax-1,22,colors.gray,bCol,"Menue")
  213.  
  214. while true do
  215.     local temp
  216.     local time = textutils.formatTime(os.time(), true)
  217.     checkIC2Reactor()
  218.     checkInvReactor()
  219.     m.setBackgroundColor(colors.gray)
  220.     temp = "     "
  221.     for i = 1,2 do
  222.         m.setCursorPos(xMax+1-#temp,1)
  223.         m.write(temp)
  224.         temp = time
  225.     end
  226.     m.setBackgroundColor(bCol)
  227.     m.setCursorPos(xMax/2,6)
  228.     if reactorInfo[1] then
  229.         m.setTextColor(colors.lime)
  230.         m.write(" AN")
  231.     else
  232.         m.setTextColor(colors.red)
  233.         m.write("AUS")
  234.     end
  235.     m.setTextColor(tCol)
  236.     temp = "         "
  237.     for i = 1,2 do
  238.         m.setCursorPos(xMax/2+3-#temp,8)
  239.         m.write(temp)
  240.         temp = tostring(reactorInfo[2]).." eu/t"
  241.     end
  242.     drawGraph(5,11,xMax/2+2,11,  colors.lime,colors.lightGray,reactorInfo[5][1])
  243.     drawGraph(5,12,xMax/2+2,12,colors.yellow,colors.lightGray,reactorInfo[5][2])
  244.     drawGraph(5,15,xMax/2+2,16,  colors.cyan,colors.lightGray,reactorInfo[5][3])
  245.     drawGraph(5,19,xMax/2+2,20,   colors.red,colors.lightGray,(reactorInfo[3]/reactorInfo[4])*100)
  246.     showStat()
  247.     sleep(5)
  248. end
Advertisement
Add Comment
Please, Sign In to add comment