MuChT007

powerPlantControlRoomWIP

Feb 14th, 2021 (edited)
1,087
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.74 KB | None | 0 0
  1. --Setup
  2. local modem = peripheral.wrap("left")
  3. local mon = peripheral.wrap("bottom")
  4. local txChannel = 1410
  5. local rxChannel = 1400
  6. local room = "storage" --for how in the control room "production" or "storage"
  7.  
  8. --Variables
  9.  
  10. local data={}
  11. modem.open(rxChannel)
  12. mon.setTextScale(0.5)
  13. x, y = mon.getSize()
  14.  
  15. --Functions
  16.  
  17. function showMessage(line, message, sender)
  18.     --mon.setTextScale(0.5)
  19.     if sender == "RedNet" then
  20.         mon.setCursorPos(1,line)
  21.         mon.setTextColor( colors.lime)
  22.         mon.write("RedNet")
  23.         sleep (0.2)
  24.         mon.setCursorPos(1,line)
  25.         mon.clearLine()
  26.         mon.setTextColor( colors.gray )
  27.         mon.write("RedNet")
  28.     end
  29.     mon.setCursorPos(10,line)
  30.     mon.write("                                                                     ")
  31.     mon.setCursorPos(10,line)
  32.     mon.setTextColor( colors.white )
  33.     mon.write("message: "..message)
  34. end
  35.  
  36. --Functions
  37. function drawCentered(line, text)
  38.  mon.setCursorPos((x - string.len(text))/ 2, line)
  39.  mon.write(text)
  40. end
  41.  
  42. function drawAcross(line, char)
  43.     mon.setCursorPos(1, line)
  44.     for i = 1,  x do
  45.         mon.write(char)
  46.     end
  47. end
  48.  
  49. function drawPcBar(line, char, size)
  50.     oldColor = mon.getTextColor()
  51.     mon.setCursorPos(1, line)
  52.     mon.clearLine()
  53.     maxLengt = math.ceil(x * 0.8)
  54.     sizeB = math.ceil(size*maxLengt/100)
  55.     mon.setTextColor( colors.white )
  56.     mon.setCursorPos(1, line)
  57.     mon.write("[")
  58.     mon.setCursorPos(2, line)
  59.     if size < 25 then newColor = colors.red end
  60.     if ((size < 75) and (size > 25)) then newColor = colors.orange end
  61.     if size > 75 then newColor = colors.lime end
  62.     mon.setTextColor( newColor )
  63.     for i = 1,  sizeB do
  64.         mon.write(char)
  65.     end
  66.     mon.setCursorPos((maxLengt+2), line)
  67.     mon.setTextColor( colors.white )
  68.     mon.write("]   "..size.."%")
  69.     mon.setTextColor( oldColor )
  70. end
  71.  
  72. function differential(line, actual, maximum, variation)
  73.     mon.setCursorPos(1, line)
  74.     mon.clearLine()
  75.     mon.write(actual.."RF /"..maximum.."RF")
  76.     oldColor = mon.getTextColor()
  77.     if variation < 0 then newColor = colors.red else newColor = colors.lime end
  78.     mon.setTextColor( newColor )
  79.     mon.setCursorPos(30, line)
  80.     mon.write(variation.."RF")
  81.     mon.setTextColor( oldColor )
  82. end
  83.  
  84. --body
  85.  
  86.     --prepare screen for storage operator
  87.     if room == "storage" then
  88.         mon.clear()
  89.         mon.setTextColor( colors.white )
  90.         mon.setBackgroundColor(colors.gray)
  91.         drawCentered(2, "Power storage monitoring")
  92.         drawAcross(3, "=")
  93.         --Coal part
  94.         drawAcross(6, "-")
  95.         mon.setTextColor(colors.yellow)
  96.         mon.setCursorPos(5,7)
  97.         mon.write("Coal RF storage:")
  98.         --Renewable part
  99.         mon.setTextColor( colors.white )
  100.         drawAcross(11, "-")
  101.         mon.setTextColor(colors.yellow)
  102.         mon.setCursorPos(5,12)
  103.         mon.write("Renewable RF storage:")
  104.         --Nuclear part
  105.         mon.setTextColor( colors.white )
  106.         drawAcross(16, "-")
  107.         mon.setTextColor(colors.yellow)
  108.         mon.setCursorPos(5,17)
  109.         mon.write("Nuclear RF storage:")
  110.        
  111.         --Reserve part 1
  112.         mon.setTextColor( colors.white )
  113.         drawAcross(21, "-")
  114.         mon.setTextColor(colors.yellow)
  115.         mon.setCursorPos(5,22)
  116.         mon.write("Unused RF storage:")
  117.         --Reserve part  2
  118.         mon.setTextColor( colors.white )
  119.         drawAcross(26, "-")
  120.         mon.setTextColor(colors.yellow)
  121.         mon.setCursorPos(5,27)
  122.         mon.write("Unused RF storage:")
  123.     end
  124.  
  125.     --prepare screen for production operator
  126.  
  127.  
  128. --loop
  129. while true do
  130.     event, side, frequency, replyFrequency, message, distance = os.pullEvent("modem_message")
  131.     showMessage(4, message, "RedNet")
  132.     data = textutils.unserialize(message)
  133.     local production = data[1] --Where RF come from
  134.     local typeOf = data[2] --What control room the message is for
  135.    
  136.     --Production control room
  137.     if room == "production" then
  138.     end
  139.     --Storage control room
  140.     if room == "storage" then
  141.         local maxCap = data[3] --Max RF in this storage
  142.         local actCap = data[4] --RF stored in this storage
  143.         local pcCap = (actCap*100)/maxCap --RF stored in %
  144.         pcCap = math.ceil(pcCap)
  145.  
  146.         --Coal
  147.         if production == "coal" then
  148.             drawPcBar(8, "#", pcCap)
  149.             coalActCap = actCap
  150.             if coalOldCap then var = coalActCap - coalOldCap end
  151.             if var then differential(9, actCap, maxCap, var) end
  152.             coalOldCap = coalActCap
  153.         end
  154.        
  155.         --Renewable
  156.         if production == "renewable" then
  157.             drawPcBar(13, "#", pcCap)
  158.             renewableActCap = actCap
  159.             if renewableOldCap then var = renewableActCap - renewableOldCap end
  160.             if var then differential(14, actCap, maxCap, var) end
  161.             renewableOldCap = renewableActCap
  162.         end
  163.        
  164.         --Nuclear
  165.         if production == "nuclear" then
  166.             drawPcBar(18, "#", pcCap)
  167.             NuclearActCap = actCap
  168.             if nuclearOldCap then var = NuclearActCap - nuclearOldCap end
  169.             if var then differential(19, actCap, maxCap, var) end
  170.             nuclearOldCap = NuclearActCap
  171.         end
  172.     end
  173. end
  174.  
  175.  
  176.  
  177.  
  178.  
Add Comment
Please, Sign In to add comment