Advertisement
Guest User

startup

a guest
Sep 2nd, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.02 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 = 1 --change if the reactor is receiving too many changes
  6. local max_rate = 1000 * update_rate
  7. local toggle_display = true
  8. local display_name = "monitor_2"
  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.  
  19. -- local variables for energy store
  20. local curr_store = 0
  21. local prev_store = 0
  22. local curr_ctrl_rod = 0
  23. local cycle = 0
  24. local up = false
  25.  
  26. if r.getActive() == false then
  27.   r.setActive(true)
  28. end
  29.  
  30. -- settings from the reactor
  31. local num_ctrl_rods = r.getNumberOfControlRods()
  32.  
  33. -- set control rods to default level
  34. local i = 0
  35. while i ~= num_ctrl_rods do
  36.     r.setControlRodLevel(i,control_rods_starting_level)
  37.  i = i + 1
  38. end
  39.  
  40. while true do -- run indefinately
  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 threshhold and cycles just started
  48.  if cycle < 10 and curr_store > max_energy_store then
  49.    r.setAllControlRodLevels(100)
  50.  end
  51.    
  52.     -- if current store is above min, check for rate and max store
  53.     if curr_store >= min_energy_store then
  54.         --if rate is greater then max_rate or has reached max energy store, turn down reactor
  55.         if rate > max_rate or curr_store >= max_energy_store then
  56.    if up then
  57.      curr_ctrl_rod = curr_ctrl_rod + 1
  58.    end
  59.    if curr_ctrl_rod >= num_ctrl_rods then
  60.      curr_ctrl_rod = 0
  61.    end
  62.             curr_ctrl_rod_lvl = r.getControlRodLevel(curr_ctrl_rod)
  63.             if curr_ctrl_rod_lvl <= 90 then
  64.     r.setControlRodLevel(curr_ctrl_rod, curr_ctrl_rod_lvl + 10)
  65.             end
  66.    up = true
  67.         end
  68.     else
  69.     -- else if current store is below min
  70.   if rate <= 0 then-- if energy rate is going down, turn it up
  71.     if up == false then
  72.     curr_ctrl_rod = curr_ctrl_rod - 1
  73.     end
  74.     if curr_ctrl_rod == -1 then
  75.       curr_ctrl_rod = num_ctrl_rods - 1
  76.     end
  77.         curr_ctrl_rod_lvl = r.getControlRodLevel(curr_ctrl_rod)
  78.     if curr_ctrl_rod_lvl >= 10 then
  79.             r.setControlRodLevel(curr_ctrl_rod, curr_ctrl_rod_lvl - 10)
  80.         end
  81.     up = false
  82.   end
  83.     end
  84.  mon = peripheral.wrap(display_name)
  85.  term.clear()
  86.  mon.clear()
  87.  term.setCursorPos(1,1)
  88.  mon.setCursorPos(1,1)
  89.  mon.setTextColor(colors.lime)
  90.  if r.getActive() then
  91.    print("Reactor Active | Cycle "..cycle)
  92.    mon.write("Reactor Active | Cycle "..cycle)
  93.  else
  94.    print("Reactor InActive | Cycle "..cycle)
  95.    mon.write("Reactor ")
  96.    mon.setTextColor(colors.red)
  97.    mon.write("InActive")
  98.    mon.setTextColor(colors.lime)
  99.    cycle = cycle - 1
  100.  end
  101.  print("Store: "..curr_store)
  102.  mon.setTextColor(colors.orange)
  103.  mon.setCursorPos(1,3)
  104.  mon.write("Energy Store: "..math.floor(curr_store))
  105.  mon.setCursorPos(1,4)
  106.  mon.write("Energy Produced: "..math.floor(r.getEnergyProducedLastTick()).." RF/t")
  107.  mon.setCursorPos(1,5)
  108.  mon.write("                 "..math.floor(r.getEnergyProducedLastTick()*20).." RF/Sec")
  109.  mon.setCursorPos(1,6)
  110.  mon.write("Energy Rate: "..math.floor(rate).." RF/Sec")
  111.  for j=0,num_ctrl_rods-1,1 do
  112.    disp_curr_temp = r.getTemperature(j)
  113.    disp_curr_ctrl_rod_lvl = r.getControlRodLevel(j)
  114.    
  115.    write(j)
  116.    mon.setCursorPos(1,8+j)
  117.    mon.setTextColor(colors.lightGray)
  118.    mon.write(math.floor(j))
  119.    write("  ")  
  120.    mon.write("  ")
  121.    write(disp_curr_temp.." C")
  122.    mon.setTextColor(colors.red)
  123.    mon.write(math.floor(disp_curr_temp).." C")
  124.    write("  ")
  125.    mon.write("  ")
  126.    write(disp_curr_ctrl_rod_lvl)
  127.    mon.setTextColor(colors.yellow)
  128.    mon.write(math.floor(disp_curr_ctrl_rod_lvl))
  129.    write("%\n")
  130.    mon.write("%")
  131.    --print(" "..j.." "..disp_curr_temp.." "..disp_curr_ctrl_rod_lvl.."%")
  132.  end
  133.  prev_store = curr_store
  134.  cycle = cycle + 1
  135. sleep(update_rate)
  136. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement