Advertisement
loepie

Untitled

Feb 8th, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Loepie78s Big Reactor Manager v0.1 based on :
  2. --FusionNrg's Big Reactor Manager v1.1
  3. --With wireless
  4. --last revised 2-6-2014
  5. -- designed for reactor to rear of computer with at least a 2x3 monitor on the top of the computer
  6. -- version 201402090006
  7.  
  8. function wrapreactor()
  9. --wrap reactor peripheral
  10.     reactor = peripheral.wrap("back")
  11.     reactor.setActive(true)
  12. end
  13.  
  14. function wrapmonitor()
  15. --applicable monitor variables
  16.     monitor = peripheral.wrap("top")
  17.     monitor.write("System Initialized")
  18.     width, height = monitor.getSize()
  19. end
  20.  
  21. function wrapmodem()
  22. --applicable modem variables
  23.     modem = peripheral.wrap("left")
  24. end
  25.  
  26. function configvars()
  27.     pullInfo()
  28.     rods = 99 --max means no RF being generated
  29.     target = 5000000 -- adjustable between 0 and 10 million depending how much you want on hand
  30.     full = 10000000 -- full buffer size
  31. end
  32.  
  33. function pullInfo()-- pulling the latest from the reactor
  34.     ReactorTemp = reactor.getTemperature()
  35.     ReactorES = reactor.getEnergyStored()
  36.     ReactorLT = reactor.getEnergyProducedLastTick()
  37.     -- ReactorCRL = reactor.getControlRodLevel()
  38.     ReactorCRL = rods
  39. end
  40.  
  41. function sendmodeminfo()
  42.     modem.transmit(400, 1, reactor.getActive())
  43.     modem.transmit(401, 1, ReactorTemp)
  44.     modem.transmit(402, 1, ReactorES)
  45.     modem.transmit(403, 1, ReactorLT)
  46.     modem.transmit(404, 1, ReactorCRL)
  47. end
  48.  
  49. function displayStats() -- display stats to the monitor in 2 columns
  50. --wrap monitor and pull sizing
  51.     monitor.clear()
  52.     monitor.setCursorPos(1, 1)
  53.     monitor.write("Temp")
  54.     monitor.setCursorPos(width / 2, 1)
  55.     monitor.write("Buffer")
  56.     monitor.setCursorPos(1, 2)
  57.     monitor.write(ReactorTemp)
  58.     monitor.write(" Celc. ")
  59.     monitor.setCursorPos(width / 2, 2)
  60.     monitor.write(math.floor(((ReactorES/full) * 100) + 0.5))
  61.     monitor.write(" %")
  62.     monitor.setCursorPos(1, 4)
  63.     monitor.write("Energy Last Tick: ")
  64.     monitor.setCursorPos(1, 5)
  65.     monitor.write(math.floor(ReactorLT+ 0.5))
  66.     monitor.write("RF/t")
  67.     monitor.setCursorPos(1, 7)
  68.     monitor.write("Rod Insertion")
  69.     monitor.setCursorPos(1, 8)
  70.     monitor.write(rods)
  71.     monitor.write(" %")
  72. end
  73.  
  74. function decrods()
  75.     rods=rods-1
  76.     if (rods < 0) then
  77.         rods=0
  78.         end
  79.     reactor.setAllControlRodLevels(rods)
  80. end
  81.  
  82. function incrods()
  83.     rods=rods+1
  84.     if (rods > 100) then
  85.         rods=100
  86.         end
  87.     reactor.setAllControlRodLevels(rods)
  88. end
  89.  
  90. function rodManagement()
  91. --if we're losing energy and below half or empty... pull rods out by 1%
  92.     if (reactor.getEnergyStored() < ReactorES) and (ReactorES < target) then
  93.         decrods()
  94.         end
  95. -- if energy is increasing and storage is over half  insert rods by 1%
  96.     if (reactor.getEnergyStored() > ReactorES) and (ReactorES > target) then
  97.         incrods()
  98.         end
  99.     if (reactor.getEnergyStored() == 0) then
  100.         decrods()
  101.         end
  102. end
  103.  
  104. function main()
  105.     while (true) do
  106.         pullInfo()
  107.         sendmodeminfo()
  108.         sleep(1)
  109.         displayStats()
  110.         rodManagement()
  111.         sleep(1)
  112.     end
  113. end
  114.  
  115. wrapreactor()
  116. wrapmonitor()
  117. configvars()
  118. wrapmodem()
  119. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement