Advertisement
Guest User

startup

a guest
Sep 21st, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.35 KB | None | 0 0
  1. -- Basic settings to change
  2. r = peripheral.wrap("BigReactors-Reactor_0")
  3. local min_energy_store = 8000000
  4. local max_energy_store = 9000000
  5. local update_rate = 5 --change if the reactor is receiving too many changes
  6. local max_rate = 1000
  7. local toggle_display = true
  8. display_name = "monitor_4"
  9.  
  10. -- Advanced settings to change
  11. local control_rods_starting_level = 20 -- percentage start on rods
  12.  
  13. ---------------------------------------------------------------------------
  14. --
  15. --                      End of Settings
  16. --
  17. ---------------------------------------------------------------------------
  18. cycle = 0
  19. curr_store = 0
  20. rate = 0
  21. num_ctrl_rods = 1
  22. function main()
  23.     -- local variables for energy store
  24.     local prev_store = 0
  25.     local curr_ctrl_rod = 0
  26.     local up = false
  27.    
  28.     -- If the reactor is not active, start it
  29.     if r.getActive() == false then
  30.         r.setActive(true)
  31.     end
  32.        
  33.     -- set control rods to default level
  34.     num_ctrl_rods = r.getNumberOfControlRods()
  35.     local i = 0
  36.     for i=0,num_ctrl_rods-1 do
  37.         r.setControlRodLevel(i,control_rods_starting_level)
  38.     end
  39.  
  40.     while true do -- run indefinitely
  41.        
  42.         -- get current energy store
  43.         curr_store = r.getEnergyStored()
  44.         --compare to previous store and get current rate
  45.         rate = curr_store - prev_store
  46.  
  47.         -- turn everything off if store is above max threshold and cycles just started
  48.         if cycle < 10 and curr_store > max_energy_store then
  49.             r.setAllControlRodLevels(100)
  50.         end
  51.                
  52.         -- WORKING AREA
  53.         -- If current store is above the minimum, keep slow and steady progress. not too fast, not to slow
  54.         if curr_store >= min_energy_store then
  55.             if rate > max_rate or curr_store >= max_energy_store then --Too High\Too Fast
  56.                 -- when initially going up (up = false), select the same control rod we turned down last step
  57.                 if up then
  58.                     curr_ctrl_rod = curr_ctrl_rod + 1
  59.                 end
  60.                 if curr_ctrl_rod >= num_ctrl_rods then
  61.                     curr_ctrl_rod = 0
  62.                 end
  63.                 curr_ctrl_rod_lvl = r.getControlRodLevel(curr_ctrl_rod)
  64.                 if curr_ctrl_rod_lvl <= 90 then
  65.                     r.setControlRodLevel(curr_ctrl_rod, curr_ctrl_rod_lvl + 10)
  66.                 end
  67.                 up = true
  68.             end
  69.         else -- Too Low
  70.             if rate <= 0 then-- if energy rate is going down, turn it up
  71.                 -- when initially going down (up = true), select the same control rod we turned up last step
  72.                 if up == false then
  73.                     curr_ctrl_rod = curr_ctrl_rod - 1
  74.                 end
  75.                 if curr_ctrl_rod == -1 then
  76.                     curr_ctrl_rod = num_ctrl_rods - 1
  77.                 end
  78.                 curr_ctrl_rod_lvl = r.getControlRodLevel(curr_ctrl_rod)
  79.                 if curr_ctrl_rod_lvl >= 10 then
  80.                     r.setControlRodLevel(curr_ctrl_rod, curr_ctrl_rod_lvl - 10)
  81.                 end
  82.                 up = false
  83.             end
  84.         end
  85.         -- /Working Area
  86.   if not r.getActive() then
  87.     cycle = cycle - 1
  88.   end
  89.   display()
  90.   sleep(1)
  91.   cycle = cycle + 1
  92.     end
  93. end
  94.  
  95. function display()
  96.  term.clear()
  97.     term.setCursorPos(1,1)
  98.     if toggle_display then
  99.         mon = peripheral.wrap(display_name)
  100.         mon.clear()
  101.         mon.setCursorPos(1,1)
  102.         mon.setTextColor(colors.lime)
  103.     end
  104.     if r.getActive() then
  105.         print("Reactor Active | Cycle "..cycle)
  106.         if toggle_display then
  107.             mon.write("Redstone Reactor Active")
  108.         end
  109.     else
  110.         print("Reactor InActive | Cycle "..cycle)
  111.         if toggle_display then
  112.             mon.write("Redstone Reactor ")
  113.             mon.setTextColor(colors.red)
  114.             mon.write("InActive")
  115.             mon.setTextColor(colors.lime)
  116.         end
  117.     end
  118.     print("Store: "..curr_store)
  119.     if toggle_display then
  120.         mon.setTextColor(colors.orange)
  121.         mon.setCursorPos(1,3)
  122.         mon.write("Energy Stre: "..math.floor(curr_store).." RF")
  123.         mon.setCursorPos(1,4)
  124.         mon.write("Energy Prod: "..math.floor(r.getEnergyProducedLastTick()).." RF/t")
  125.         mon.setCursorPos(1,5)
  126.         mon.write("             "..math.floor(r.getEnergyProducedLastTick()*20).." RF/Sec")
  127.         mon.setCursorPos(1,6)
  128.         mon.write("Rate (+,-) : "..math.floor(rate).." RF/Sec")
  129.     end
  130.     for j=0,num_ctrl_rods-1,1 do
  131.         disp_curr_temp = r.getFuelTemperature(j)
  132.         disp_curr_ctrl_rod_lvl = r.getControlRodLevel(j)
  133.         write(j.."  "..disp_curr_temp.." C  "..disp_curr_ctrl_rod_lvl.."%\n")
  134.         if toggle_display then
  135.             mon.setCursorPos(1,8+j)
  136.             mon.setTextColor(colors.lightGray)
  137.             mon.write(math.floor(j).."  ")
  138.             mon.setTextColor(colors.red)
  139.             mon.write(math.floor(disp_curr_temp).." C  ")
  140.             mon.setTextColor(colors.yellow)
  141.             mon.write(math.floor(disp_curr_ctrl_rod_lvl).."%")
  142.         end
  143.     end
  144.  redstone.setOutput("left",false)
  145. end
  146.  
  147. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement