Advertisement
Guest User

startup

a guest
May 28th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.03 KB | None | 0 0
  1. local modem = peripheral.wrap("bottom")
  2. local mon = peripheral.wrap("left")
  3. local cap = peripheral.wrap("right")
  4.  
  5. capNum = 3
  6. --UTILITIES
  7.  
  8. function contact(message)
  9.   modem.transmit(621, 622, message)
  10.   modem.open(622)
  11.   timerID = os.startTimer(.5)
  12.   local event, modemSide, senderChannel, replyChannel, m, senderDistance = os.pullEvent("modem_message")
  13.   if event == "modem_message" then
  14.     os.cancelTimer(timerID)
  15.     modem.close(622)
  16.     return m
  17.   elseif event == "timer" then
  18.     print("A timeout has occured, will skip this request")
  19.   else
  20.     print("An unknown event occured")
  21.     os.cancelTimer(timerID)
  22.   end
  23.   modem.close(622)
  24. end
  25.  
  26. maximumFuel = contact("getFuelAmountMax")
  27.  
  28. function writeLine(x,y,label,content,colorvar,optional)
  29.   mon.setCursorPos(x,y)
  30.   mon.clearLine()
  31.   mon.setTextColor(colors.white)
  32.   mon.write(label..": ")
  33.   mon.setTextColor(colorvar)
  34.   if optional == nil then
  35.     mon.write(tostring(contact(content)))
  36.   else
  37.     mon.write(tostring(optional))
  38.   end
  39. end
  40.  
  41. function percent(part,whole)
  42.   --print("Part: "..tostring(part).." Whole: "..tostring(whole))
  43.   local per = part/whole*100
  44.   local color
  45.   if per < 20 then color = colors.red
  46.   elseif per < 40 then color = colors.orange
  47.   elseif per < 60 then color = colors.yellow
  48.   elseif per < 80 then color = colors.lime
  49.   elseif per < 100 then color = colors.green
  50.   elseif per == 100 then color = colors.cyan
  51.   end
  52.   return color
  53. end
  54.  
  55. --WRITING
  56.  
  57. function active(x,y)
  58.   temp = contact("getActive")
  59.   if temp then colorvar = colors.green
  60.   else colorvar = colors.red
  61.   end
  62.   writeLine(x,y,"Active", _,colorvar, temp)
  63. end
  64.  
  65.  
  66.  
  67. function displayPer(x,y,label,cont,max,append,invert,literal)
  68.   if literal == nil then temp = contact(cont)
  69.   else temp = cont end
  70.   if invert then colorvar = percent(max-temp,max)
  71.   else colorvar = percent(temp, max)
  72.   end
  73.   writeLine(x,y,label, _,colorvar, math.floor(temp))
  74.   mon.setTextColor(colors.cyan)
  75.   mon.write(" "..append.." ("..tostring(math.floor(temp/max*100)).."%)")
  76. end
  77.  
  78. function colorWrite(color, text, x, y)
  79. if x ~= nil then
  80. mon.setCursorPos(x,y)
  81. mon.clearLine()
  82. end
  83. mon.setTextColor(color)
  84. mon.write(text)
  85. end
  86.  
  87. function energyStored(x,y)  
  88.   displayPer(x,y,"RF in Reactor","getEnergyStored",10000000, "RF")
  89. end
  90.  
  91. function fuelTemp(x,y)
  92.   displayPer(x,y,"Fuel Temp", "getFuelTemperature",2000, "C", true)
  93. end
  94.  
  95. function caseTemp(x,y)
  96.   displayPer(x,y,"Casing Temp", "getCasingTemperature",2000,"C", true)  
  97. end
  98.  
  99. function efficiency(x,y)
  100.   proE = contact("getEnergyProducedLastTick")
  101.   cosF = contact("getFuelConsumedLastTick")
  102.   colorWrite(colors.white, "Efficiency: ",x,y)
  103.   colorWrite(colors.cyan, tostring(math.floor(proE/cosF)).." RF/mB")
  104. end
  105.  
  106. function capEnergy(x,y)
  107.   displayPer(x,y,"RF in Capacitor", capNum*cap.getEnergyStored(), capNum*cap.getMaxEnergyStored(), "RF", false, true)
  108. end
  109.  
  110. function fuelWaste(x,y)
  111.   colorWrite(colors.white,"Fuel: ", x, y)
  112.   fuel = contact("getFuelAmount")
  113.   colorWrite(percent(fuel,maximumFuel), tostring(math.floor(fuel)))
  114.   colorWrite(colors.cyan, " mB ")
  115.   colorWrite(colors.white, "Waste: ")
  116.   waste = contact("getWasteAmount")
  117.   colorWrite(percent(maximumFuel-waste,maximumFuel),tostring(waste))
  118.   colorWrite(colors.cyan, " mB ("..tostring(math.floor(fuel/waste*100)).."%)")
  119.   colorWrite(colors.white, "Ratio: ", x,y+1)
  120.   colorWrite(colors.cyan, tostring(fuel/waste))
  121.   colorWrite(colors.white, " to 1")
  122. end
  123.  
  124. --MAIN LOOP
  125. --The monitor is 36 across
  126. while true do
  127.   --mon.clear()
  128.   mon.setTextScale(0.5)
  129.   active(1,1)
  130.   sleep(.1)
  131.   energyStored(1,2)
  132.   sleep(.1)
  133.   capEnergy(1,3)
  134.   sleep(.1)
  135.   fuelTemp(1,4)
  136.   sleep(.1)
  137.   caseTemp(1,5)
  138.   sleep(.1)
  139.   fuelWaste(1,6)
  140.   sleep(.1)
  141.   efficiency(1,8)
  142.   if cap.getEnergyStored()/cap.getMaxEnergyStored() > .9 then contact("setActiveFalse")
  143.   elseif cap.getEnergyStored()/cap.getMaxEnergyStored() <.75 then contact("setActiveTrue")
  144.   end
  145.   if contact("getFuelAmount")<2000 then contact("setActiveFalse"); colorWrite(colors.red, "Warning! Fuel monitor tripped!", 1,9)
  146.   end
  147. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement