Advertisement
loepie

Untitled

Feb 8th, 2014
59
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 201402082142
  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.     modem.transmit(400, 1, "Big Reactor Manager initializing")
  25. end
  26.  
  27. function configvars()
  28.     pullInfo()
  29.     rods = 99
  30.     target = 5000000 -- adjustable between 0 and 10 million depending how much you want on hand
  31.     full = 10000000 -- full buffer size
  32. end
  33.  
  34. function pullInfo()-- pulling the latest from the reactor
  35.     ReactorTemp = reactor.getTemperature()
  36.     ReactorES = reactor.getEnergyStored()
  37.     ReactorLT = reactor.getEnergyProducedLastTick()
  38.     ReactorCRL = reactor.getControlRodLevel()
  39. end
  40.  
  41. function sendmodeminfo()
  42.     modem.transmit(401, 1, ReactorTemp)
  43.     modem.transmit(402, 1, ReactorES)
  44.     modem.transmit(403, 1, ReactorLT)
  45.     modem.transmit(404, 1, ReactorCRL)
  46. end
  47.  
  48. function displayStats() -- display stats to the monitor in 2 columns
  49. --wrap monitor and pull sizing
  50.     monitor.clear()
  51.     monitor.setCursorPos(1, 1)
  52.     monitor.write("Temp")
  53.     monitor.setCursorPos(width / 2, 1)
  54.     monitor.write("Buffer")
  55.     monitor.setCursorPos(1, 2)
  56.     monitor.write(ReactorTemp)
  57.     monitor.write(" Celcius ")
  58.     monitor.setCursorPos(width / 2, 2)
  59.     monitor.write(math.floor(((ReactorES/full) * 100) + 0.5))
  60.     monitor.write(" %")
  61.     monitor.setCursorPos(1, 4)
  62.     monitor.write("Energy Last Tick: ")
  63.     monitor.setCursorPos(1, 5)
  64.     monitor.write(math.floor(ReactorLT+ 0.5))
  65.     monitor.write("RF/t")
  66.     monitor.setCursorPos(1, 7)
  67.     monitor.write("Rod Insertion")
  68.     monitor.setCursorPos(1, 8)
  69.     monitor.write(rods)
  70.     monitor.write(" %")
  71. end
  72.  
  73. function decrods()
  74.     rods=rods-1
  75.     if (rods < 0) then
  76.         rods=0
  77.         end
  78.     reactor.setAllControlRodLevels(rods)
  79. end
  80.  
  81. function incrods()
  82.     rods=rods+1
  83.     if (rods > 100) then
  84.         rods=100
  85.         end
  86.     reactor.setAllControlRodLevels(rods)
  87. end
  88.  
  89. function rodManagement()
  90. --if we're losing energy and below half or empty... pull rods out by 1%
  91.     if (reactor.getEnergyStored() < energy) and (energy < target) then
  92.         decrods()
  93.         end
  94. -- if energy is increasing and storage is over half  insert rods by 1%
  95.     if (reactor.getEnergyStored() > energy) and (energy > target) then
  96.         incrods()
  97.         end
  98.     if (reactor.getEnergyStored() == 0) then
  99.         decrods()
  100.         end
  101. end
  102.  
  103. function main()
  104.     while (true) do
  105.         pullInfo()
  106.         sendmodeminfo()
  107.         sleep(1)
  108.         displayStats()
  109.         rodManagement()
  110.         sleep(1)
  111.     end
  112. end
  113.  
  114. wrapreactor()
  115. wrapmonitor()
  116. wrapmodem()
  117. configvars()
  118. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement