loepie

BigReactor with wireless (Monitor) 201402221241

Feb 21st, 2014
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.80 KB | None | 0 0
  1. --Loepie78s Big Reactor Manager v0.1 based on :
  2. --FusionNrg's Big Reactor Manager v1.1
  3. --With wireless
  4. --last revised 22-2-2014
  5. -- designed for reactor to rear of computer with at least a 2x3 monitor on the top of the computer
  6. -- if you want to use this script for multiple reactors, make sure you change the
  7. -- function sendmodeminfo for different modem channels
  8. -- version 201402221241
  9.  
  10. function wrapreactor()
  11. --wrap reactor peripheral
  12.     reactor = peripheral.wrap("back")
  13.     reactor.setActive(true)
  14. end
  15.  
  16. function wrapmonitor()
  17. --applicable monitor variables
  18.     monitor = peripheral.wrap("top")
  19.     monitor.clear()
  20.     monitor.write("System Initialized")
  21.     width, height = monitor.getSize()
  22. end
  23.  
  24. function wrapmodem()
  25. --applicable modem variables
  26.     modem = peripheral.wrap("left")
  27. end
  28.  
  29. function configvars()
  30.     rods = 0 --max means no RF being generated
  31.     target = 8000000 -- adjustable between 0 and 10 million depending how much you want on hand
  32.     full = 10000000 -- full buffer size
  33. end
  34.  
  35. function pullInfo()-- pulling the latest from the reactor
  36.     if  reactor.getConnected() then
  37.         if reactor.getActive() then
  38.             ReactorStatus = "Active"
  39.             ReactorTemp = reactor.getTemperature()
  40.             ReactorES = math.floor(((reactor.getEnergyStored()/full) * 100) + 0.5)
  41.             ReactorMath = reactor.getEnergyStored()
  42.             ReactorLT = math.floor(reactor.getEnergyProducedLastTick() + 0.5)
  43.             ReactorCRL = rods
  44.         else
  45.             ReactorStatus = "Offline"
  46.             ReactorTemp = reactor.getTemperature()
  47.             ReactorES = math.floor(((reactor.getEnergyStored()/full) * 100) + 0.5)
  48.             ReactorMath = reactor.getEnergyStored()
  49.             ReactorLT = math.floor(reactor.getEnergyProducedLastTick() + 0.5)
  50.             ReactorCRL = rods
  51.         end
  52.     else
  53.         ReactorStatus = "Build Incomplete"
  54.         ReactorTemp = "NoTemp"
  55.         ReactorES = "NoBuffer"
  56.         ReactorMath = 0
  57.         ReactorLT = "NoLastTick"
  58.         ReactorCRL = "NoRodControl"
  59.     end
  60. end
  61.  
  62. function sendmodeminfo()
  63.     modem.transmit(600, 3, ReactorStatus)
  64.     modem.transmit(601, 3, ReactorTemp)
  65.     modem.transmit(602, 3, ReactorES)
  66.     modem.transmit(603, 3, ReactorLT)
  67.     modem.transmit(604, 3, ReactorCRL)
  68. end
  69.  
  70. function displayStats() -- display stats to the monitor in 2 columns
  71. --wrap monitor and pull sizing
  72.     monitor.clear()
  73.     monitor.setCursorPos(1, 1)
  74.     monitor.write("Temp")
  75.     monitor.setCursorPos(width / 2, 1)
  76.     monitor.write("Buffer")
  77.     monitor.setCursorPos(1, 2)
  78.     monitor.write(ReactorTemp)
  79.     monitor.write(" Celc. ")
  80.     monitor.setCursorPos(width / 2, 2)
  81. --  monitor.write(math.floor(((ReactorES/full) * 100) + 0.5))
  82.     monitor.write(ReactorES)
  83.     monitor.write(" %")
  84.     monitor.setCursorPos(1, 4)
  85.     monitor.write("Energy Last Tick: ")
  86.     monitor.setCursorPos(1, 5)
  87. --  monitor.write(math.floor(ReactorLT+ 0.5))
  88.     monitor.write(ReactorLT)
  89.     monitor.write()
  90.     monitor.write("RF/t")
  91.     monitor.setCursorPos(1, 7)
  92.     monitor.write("Rod Insertion")
  93.     monitor.setCursorPos(1, 8)
  94.     monitor.write(rods)
  95.     monitor.write(" %")
  96. end
  97.  
  98. function decrods()
  99.     rods=rods-1
  100.     if (rods < 0) then
  101.         rods=0
  102.         end
  103.     reactor.setAllControlRodLevels(rods)
  104. end
  105.  
  106. function incrods()
  107.     rods=rods+1
  108.     if (rods > 100) then
  109.         rods=100
  110.         end
  111.     reactor.setAllControlRodLevels(rods)
  112. end
  113.  
  114. function rodManagement()
  115. --if we're losing energy and below half or empty... pull rods out by 1%
  116.     if (reactor.getEnergyStored() < ReactorMath) and (ReactorMath < target) then
  117.         decrods()
  118.         end
  119. -- if energy is increasing and storage is over half  insert rods by 1%
  120.     if (reactor.getEnergyStored() > ReactorMath) and (ReactorMath > target) then
  121.         incrods()
  122.         end
  123.     if (reactor.getEnergyStored() == 0) then
  124.         decrods()
  125.         end
  126. end
  127.  
  128. function main()
  129.     while (true) do
  130.         pullInfo()
  131.         sendmodeminfo()
  132.         sleep(1)
  133.         displayStats()
  134.         rodManagement()
  135.         sleep(1)
  136.     end
  137. end
  138.  
  139. function waitDelay()
  140.   sleep(10)
  141. end
  142.  
  143. waitDelay()
  144. wrapreactor()
  145. wrapmonitor()
  146. configvars()
  147. wrapmodem()
  148. main()
Advertisement
Add Comment
Please, Sign In to add comment