Advertisement
kk258966

BR3CC

Aug 21st, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.89 KB | None | 0 0
  1. local reactor
  2. local monitor
  3. local shutoff=50
  4. local sume=0
  5. local sumf=0
  6. local sumt=0
  7. local cyclee=0
  8. local cyclef=0
  9. local cyclet=0
  10. local cooldown=false
  11.  
  12. function findDev (dType)
  13.   local d
  14.   for _,d in pairs(peripheral.getNames()) do
  15.    if (peripheral.getType(d) == dType) then
  16.      return peripheral.wrap(d)
  17.    end
  18.   end
  19.   return nil, dType..": not found"
  20. end
  21. function setupDevs()
  22.   reactor=findDev("BigReactors-Reactor")
  23.   monitor=findDev("monitor")
  24.   monitor.setTextScale(0.5)
  25.   term.redirect(monitor)
  26. end
  27.  
  28. function display()
  29.   term.clear()
  30.   term.setCursorPos(1,1)
  31.   print("---------------------------------------------------------")
  32.   print("Reactor Status          | "..textutils.formatTime(os.time(),true))
  33.   print("---------------------------------------------------------")
  34.   print("Active                  | "..tostring(reactor.getActive()))
  35.   print("EnergyStored (RF)       | "..tostring(reactor.getEnergyStored()).." RF")
  36.   print("FuelTemperature         | "..tostring(math.floor(reactor.getFuelTemperature())).." C")
  37.   print("CasingTemperature       | "..tostring(math.floor(reactor.getCasingTemperature())).." C")
  38.   print("FuelReactivity          | "..tostring(math.floor(reactor.getFuelReactivity())).." %")
  39.   print("EnergyProducedLastTick  | "..tostring(math.floor(reactor.getEnergyProducedLastTick())).." RF/t")
  40.   print("FuelConsumedLastTick    | "..tostring(reactor.getFuelConsumedLastTick()).." mB/t")
  41.   print("---------------------------------------------------------")
  42.   print("TicksLastCycle          | "..tostring(cyclet).." t")
  43.   print("EnergyProducedLastCycle | "..tostring(cyclee).." kRF")
  44.   print("FuelConsumedCycle       | "..tostring(cyclef).." mB")
  45.   print("EfficienyLastCycle      | "..tostring(cyclee/cyclef).." kRF/mB")
  46.   print("EnergyProducedPerTick   | "..tostring(cyclee/cyclet).." kRF/t")
  47.   print("FuelConsumedPerTick     | "..tostring(cyclef/cyclet).." mB/t")
  48.   print("---------------------------------------------------------")
  49. end
  50.  
  51. function workReactor()
  52.   local energy=reactor.getEnergyStored()
  53.   local percent=math.floor(energy/100000)
  54.   local active=percent<shutoff
  55.   if (active and cooldown) then
  56.     -- Turning reactor back on
  57.     -- Perform calculations on last cycle
  58.     cyclee=sume
  59.     cyclef=sumf
  60.     cyclet=sumt
  61.     sume=0
  62.     sumf=0
  63.     sumt=0
  64.     cooldown=false
  65.   end
  66.   if (not active and not cooldown) then
  67.     -- Turning reactor off
  68.     -- Going into cooldown phase
  69.     cooldown=true
  70.   end
  71.   reactor.setAllControlRodLevels(percent)
  72.   reactor.setActive(active)
  73. end
  74.  
  75. function main()
  76.   cooldown = not reactor.getActive()
  77.   local tick=0
  78.   while true do
  79.     sume=sume+reactor.getEnergyProducedLastTick()/1000
  80.     sumf=sumf+reactor.getFuelConsumedLastTick()
  81.     sumt=sumt+1
  82.     tick=tick+1
  83.     if (tick == 20) then
  84.       workReactor()
  85.       display()
  86.       tick=0
  87.     end
  88.     sleep(.05)
  89.   end
  90. end
  91.  
  92. setupDevs()
  93. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement