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 = 5 --change if the reactor is receiving too many changes
- local max_rate = 1000
- local toggle_display = true
- display_name = "monitor_4"
- -- Advanced settings to change
- local control_rods_starting_level = 20 -- percentage start on rods
- ---------------------------------------------------------------------------
- --
- -- End of Settings
- --
- ---------------------------------------------------------------------------
- cycle = 0
- curr_store = 0
- rate = 0
- num_ctrl_rods = 1
- function main()
- -- local variables for energy store
- local prev_store = 0
- local curr_ctrl_rod = 0
- local up = false
- -- If the reactor is not active, start it
- if r.getActive() == false then
- r.setActive(true)
- end
- -- set control rods to default level
- num_ctrl_rods = r.getNumberOfControlRods()
- local i = 0
- for i=0,num_ctrl_rods-1 do
- r.setControlRodLevel(i,control_rods_starting_level)
- end
- while true do -- run indefinitely
- -- 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 threshold and cycles just started
- if cycle < 10 and curr_store > max_energy_store then
- r.setAllControlRodLevels(100)
- end
- -- WORKING AREA
- -- If current store is above the minimum, keep slow and steady progress. not too fast, not to slow
- if curr_store >= min_energy_store then
- if rate > max_rate or curr_store >= max_energy_store then --Too High\Too Fast
- -- when initially going up (up = false), select the same control rod we turned down last step
- 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 -- Too Low
- if rate <= 0 then-- if energy rate is going down, turn it up
- -- when initially going down (up = true), select the same control rod we turned up last step
- 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
- -- /Working Area
- if not r.getActive() then
- cycle = cycle - 1
- end
- display()
- sleep(1)
- cycle = cycle + 1
- end
- end
- function display()
- term.clear()
- term.setCursorPos(1,1)
- if toggle_display then
- mon = peripheral.wrap(display_name)
- mon.clear()
- mon.setCursorPos(1,1)
- mon.setTextColor(colors.lime)
- end
- if r.getActive() then
- print("Reactor Active | Cycle "..cycle)
- if toggle_display then
- mon.write("Redstone Reactor Active")
- end
- else
- print("Reactor InActive | Cycle "..cycle)
- if toggle_display then
- mon.write("Redstone Reactor ")
- mon.setTextColor(colors.red)
- mon.write("InActive")
- mon.setTextColor(colors.lime)
- end
- end
- print("Store: "..curr_store)
- if toggle_display then
- mon.setTextColor(colors.orange)
- mon.setCursorPos(1,3)
- mon.write("Energy Stre: "..math.floor(curr_store).." RF")
- mon.setCursorPos(1,4)
- mon.write("Energy Prod: "..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("Rate (+,-) : "..math.floor(rate).." RF/Sec")
- end
- for j=0,num_ctrl_rods-1,1 do
- disp_curr_temp = r.getFuelTemperature(j)
- disp_curr_ctrl_rod_lvl = r.getControlRodLevel(j)
- write(j.." "..disp_curr_temp.." C "..disp_curr_ctrl_rod_lvl.."%\n")
- if toggle_display then
- mon.setCursorPos(1,8+j)
- mon.setTextColor(colors.lightGray)
- mon.write(math.floor(j).." ")
- mon.setTextColor(colors.red)
- mon.write(math.floor(disp_curr_temp).." C ")
- mon.setTextColor(colors.yellow)
- mon.write(math.floor(disp_curr_ctrl_rod_lvl).."%")
- end
- end
- redstone.setOutput("left",false)
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement