Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Basic settings to change
- r = peripheral.wrap("BigReactors-Reactor_0")
- local min_energy_store = 8000000
- local max_energy_store = 9000000
- local update_rate = 1 --change if the reactor is receiving too many changes
- local max_rate = 1000 * update_rate
- local toggle_display = true
- local display_name = "monitor_2"
- -- Advanced settings to change
- local control_rods_starting_level = 20 -- percentage start on rods
- ---------------------------------------------------------------------------
- --
- -- End of Settings
- --
- ---------------------------------------------------------------------------
- -- local variables for energy store
- local curr_store = 0
- local prev_store = 0
- local curr_ctrl_rod = 0
- local cycle = 0
- local up = false
- if r.getActive() == false then
- r.setActive(true)
- end
- -- settings from the reactor
- local num_ctrl_rods = r.getNumberOfControlRods()
- -- set control rods to default level
- local i = 0
- while i ~= num_ctrl_rods do
- r.setControlRodLevel(i,control_rods_starting_level)
- i = i + 1
- end
- while true do -- run indefinately
- -- get current energy store
- curr_store = r.getEnergyStored()
- --compare to previous store and get current rate
- rate = curr_store - prev_store
- -- turn everything off if store is above max threshhold and cycles just started
- if cycle < 10 and curr_store > max_energy_store then
- r.setAllControlRodLevels(100)
- end
- -- if current store is above min, check for rate and max store
- if curr_store >= min_energy_store then
- --if rate is greater then max_rate or has reached max energy store, turn down reactor
- if rate > max_rate or curr_store >= max_energy_store then
- if up then
- curr_ctrl_rod = curr_ctrl_rod + 1
- end
- if curr_ctrl_rod >= num_ctrl_rods then
- curr_ctrl_rod = 0
- end
- curr_ctrl_rod_lvl = r.getControlRodLevel(curr_ctrl_rod)
- if curr_ctrl_rod_lvl <= 90 then
- r.setControlRodLevel(curr_ctrl_rod, curr_ctrl_rod_lvl + 10)
- end
- up = true
- end
- else
- -- else if current store is below min
- if rate <= 0 then-- if energy rate is going down, turn it up
- if up == false then
- curr_ctrl_rod = curr_ctrl_rod - 1
- end
- if curr_ctrl_rod == -1 then
- curr_ctrl_rod = num_ctrl_rods - 1
- end
- curr_ctrl_rod_lvl = r.getControlRodLevel(curr_ctrl_rod)
- if curr_ctrl_rod_lvl >= 10 then
- r.setControlRodLevel(curr_ctrl_rod, curr_ctrl_rod_lvl - 10)
- end
- up = false
- end
- end
- mon = peripheral.wrap(display_name)
- term.clear()
- mon.clear()
- term.setCursorPos(1,1)
- mon.setCursorPos(1,1)
- mon.setTextColor(colors.lime)
- if r.getActive() then
- print("Reactor Active | Cycle "..cycle)
- mon.write("Reactor Active | Cycle "..cycle)
- else
- print("Reactor InActive | Cycle "..cycle)
- mon.write("Reactor ")
- mon.setTextColor(colors.red)
- mon.write("InActive")
- mon.setTextColor(colors.lime)
- cycle = cycle - 1
- end
- print("Store: "..curr_store)
- mon.setTextColor(colors.orange)
- mon.setCursorPos(1,3)
- mon.write("Energy Store: "..math.floor(curr_store))
- mon.setCursorPos(1,4)
- mon.write("Energy Produced: "..math.floor(r.getEnergyProducedLastTick()).." RF/t")
- mon.setCursorPos(1,5)
- mon.write(" "..math.floor(r.getEnergyProducedLastTick()*20).." RF/Sec")
- mon.setCursorPos(1,6)
- mon.write("Energy Rate: "..math.floor(rate).." RF/Sec")
- for j=0,num_ctrl_rods-1,1 do
- disp_curr_temp = r.getTemperature(j)
- disp_curr_ctrl_rod_lvl = r.getControlRodLevel(j)
- write(j)
- mon.setCursorPos(1,8+j)
- mon.setTextColor(colors.lightGray)
- mon.write(math.floor(j))
- write(" ")
- mon.write(" ")
- write(disp_curr_temp.." C")
- mon.setTextColor(colors.red)
- mon.write(math.floor(disp_curr_temp).." C")
- write(" ")
- mon.write(" ")
- write(disp_curr_ctrl_rod_lvl)
- mon.setTextColor(colors.yellow)
- mon.write(math.floor(disp_curr_ctrl_rod_lvl))
- write("%\n")
- mon.write("%")
- --print(" "..j.." "..disp_curr_temp.." "..disp_curr_ctrl_rod_lvl.."%")
- end
- prev_store = curr_store
- cycle = cycle + 1
- sleep(update_rate)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement