Advertisement
loepie

BigReactor with wireless

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