Advertisement
m1cr0man

Reactor Controller 2.5

Jun 26th, 2012
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.18 KB | None | 0 0
  1. -- Reactor Controller 2.5 by m1cr0man
  2.  
  3. os.loadAPI("/reactor/m1")
  4. local origx, origy = term.getSize()
  5. m1.set(true, origy-10, 2)
  6. local relock, info, m1cr0s, wiring, downtime, eutick, ice, ids, ticktime, version, rats, thermal, user, savecount = nil, {[1] = "pwdchk"}, {}, {}, nil, 250, {}, {[1] = false}, os.startTimer(1), "2.5", {}, {[1] = false, [3] = false}, {menu = 0, input = "", line = origy-7}, 0
  7. local evt, p1, p2;
  8.  
  9. function save(arg)          --To provide a central place for controlling settings file
  10.     if arg == nil then
  11.         m1.tablesave("/reactor/settings", {[1] = wiring, [2] = m1cr0s, [3] = eutick, [4] = downtime, [5] = ice, [6] = ids, [7] = thermal})
  12.     else
  13.         local loaded = m1.tableload("/reactor/settings")
  14.         wiring, m1cr0s, eutick, downtime, ice, ids, thermal = loaded[1], loaded[2], loaded[3], loaded[4], loaded[5], loaded[6], loaded[7]
  15.     end
  16. end
  17.  
  18. function wireschk(wire)     --Handles redstone state checking
  19.     if wiring[1] == true then return(m1.redchk(wiring[wire]))
  20.     else return(m1.redchk(wiring[1], nil, wiring[wire])) end
  21. end
  22.  
  23. function wires(wire, state) --Handles redstone wiring actions
  24.     if wiring[1] == true then
  25.         if wire == "door" and state == nil then
  26.             local currstate = wireschk(wire)
  27.             m1.redinvert(wiring[wire])
  28.             if not currstate then wiring[5] = "Open" else wiring[5] = "Closed" end
  29.         else
  30.             rs.setOutput(wiring[wire], state)
  31.             if wire == "door" and state then wiring[5] = "Open" elseif wire == "door" then wiring[5] = "Closed" end
  32.         end
  33.     else
  34.         local cols = 0
  35.         if wire == "door" and state == nil then
  36.             local currstate = wireschk("door")
  37.         --Sort out reactor colour
  38.             if (wiring[6] == "On" and not wiring[7]) or (wiring[6] == "Off" and wiring[7]) then cols = colors[wiring["reactor"]] end
  39.             if not currstate then cols = cols+colors[wiring["door"]] end
  40.             rs.setBundledOutput(wiring[1], cols)
  41.     --Update Door Status
  42.             if not currstate then wiring[5] = "Open" else wiring[5] = "Closed" end
  43.         else
  44.     --Check if reactor wire should go on or not, same for door wire
  45.             if (wire == "reactor" and ((wiring[7] and state == wiring[7]) or (not wiring[7] and state ~= wiring[7]))) or (wire == "door" and state) then cols = colors[wiring[wire]] end
  46.     --Check for and keep currently active wires on
  47.             if wire == "reactor" and wiring["door"] and wiring[5] == "Open" then cols = cols+colors[wiring["door"]]
  48.             elseif wire == "door" and ((wiring[6] == "On" and not wiring[7]) or (wiring[6] == "Off" and wiring[7])) then cols = cols+colors[wiring["reactor"]] end
  49.             rs.setBundledOutput(wiring[1], cols)
  50.     --Update Door Status
  51.             if wire == "door" and state then wiring[5] = "Open" elseif wire == "door" then wiring[5] = "Closed" end
  52.         end
  53.     end
  54. --Update status of reactor
  55.     if wire == "reactor" and state ~= wiring[7] then wiring[6] = "On" elseif wire == "reactor" then wiring[6] = "Off" end  
  56. end
  57.  
  58. function redraw(hst, reset) --Redraws constant GUI items, also handles variable resetting to default
  59.     m1.printex(1, "-----Reactor Controller "..version.."-----", "center")
  60.     m1.printex(2, "------History------")
  61.     m1.printex(origy-8, "-------------------")
  62. --Add history and/or clear bottom of screen
  63.     if reset then for line = 1,6 do m1.printex(origy-line, " ") end end
  64.     if hst then m1.printex(origy-9, hst, 1, "history") end
  65. --Update Reactor Status at bottom of UI
  66.     local status = "Reactor:"..wiring[6]
  67.     if wiring["door"] then status = status.." - Door:"..wiring[5] end
  68.     if thermal[1] then status = status.." - Heat:"..wiring[8] end
  69.     if downtime then status = status.." - Time:"..tostring(downtime) end
  70.     m1.printex(origy, status, "center")
  71. end
  72.  
  73. function userAction(action) --Handles user actions
  74. --Shutdown
  75.     if action == 1 then
  76.         wires("reactor", wiring[7])
  77.         ice[4], ice[2], downtime, thermal[3] = 0, 0, nil, false
  78.         if thermal[4] ~= 1 then thermal[4] = 0 end
  79.         redraw("INFO: Reactor Shutdown", true)
  80. --Generate X EUs
  81.     elseif action == 2 then
  82.         downtime = math.floor((downtime*1000000)/(eutick*20)) --All The Math
  83.         wires("reactor", not wiring[7])
  84.         redraw("INFO: Reactor shutting down in "..tostring(downtime).." seconds", true)
  85. --Reset Detectors
  86.     elseif action == 3 then
  87.         ice[4], ice[2], downtime, thermal[3] = 0, 0, nil, false
  88.         redraw("INFO: Detectors Reset", true)
  89. --Toggle Door
  90.     elseif action == 4 and wiring["door"] then
  91.         wires("door")
  92.         redraw("INFO: Door "..wiring[5], true)
  93. --Toggle ESU Control
  94.     elseif action == 5 and wiring["esu"] then
  95.         if thermal[4] == 1 then
  96.             thermal[4] = false
  97.             redraw("INFO: ESU control enabled", true)
  98.             return "enabled"
  99.         else
  100.             thermal[4] = 1
  101.             redraw("INFO: ESU control disabled", true)
  102.             return "disabled"
  103.         end
  104. --Start reactor
  105.     elseif action == 6 then
  106.         wires("reactor", not wiring[7])
  107.         ice[4], ice[2], downtime, thermal[3] = 0, 0, nil, false
  108.         if thermal[4] ~= 1 then thermal[4] = false end
  109.         redraw("INFO: Reactor Started", true)
  110.     end
  111. end
  112.  
  113. function pwdchk()           --Checks info table credentials
  114.     if type(m1cr0s[1]) == "number" then
  115.         m1.tablesend(info, m1cr0s[1])
  116.         local id, result = rednet.receive(m1cr0s[1], 1)
  117.         ticktime, ice[4] = os.startTimer(1), os.startTimer(ice[3]/2)
  118.         if result == nil then
  119.             return "No Connection to Server "..tostring(m1cr0s[1])
  120.         elseif m1.deserialize(result) == nil then
  121.             return result
  122.         elseif m1.deserialize(result)[1] ~= "true" then
  123.             return m1.deserialize(result)[1]
  124.         elseif m1.deserialize(result)[1] == "true" and m1.deserialize(result)[2] < m1cr0s[2] then
  125.             return "Access Denied"
  126.         elseif m1.deserialize(result)[1] == "true" and m1.deserialize(result)[2] >= m1cr0s[2] then
  127.             return true
  128.         end
  129.     else
  130.         local count = 0
  131.         for i,data in ipairs(info[3]) do if data == m1cr0s[3][i] then count = count+1 end end
  132.         if count == #m1cr0s[3] then return true else return false end
  133.     end
  134. end
  135.  
  136. function reset()            --Manage cancel/reset of user input
  137.     redraw(nil, true)
  138.     info, user, relock = {[1] = "pwdchk"}, {menu = 0, input = "", line = origy-7}, nil
  139.     m1.printex(user.line, "Enter Username:")
  140. end
  141.  
  142. function checkUser()        --Handles user input and menus
  143.     local function getInput(mode, limit)    --Manage keys pressed
  144.     --Password
  145.         if mode == true then
  146.             if p1 == 14 then table.remove(info[3])
  147.             elseif evt == "key" then table.insert(info[3], p1*(info[2]:len()/2)) end
  148.             local stars = ""
  149.             for i = 1,#info[3] do stars = stars.."*" end
  150.             m1.printex(user.line+1, stars)
  151.     --Other fields
  152.         else
  153.             if p1 == 14 then user.input = user.input:sub(1, user.input:len()-1)
  154.             elseif evt == "char" and (mode ~= "num" or (mode == "num" and (tonumber(p1) or p1 == "."))) and (not limit or user.input:len() <= limit) then user.input = user.input..p1 end
  155.             m1.printex(user.line+1, user.input)
  156.         end
  157.     end
  158.  
  159. --Cancel on press escape or press cancel in menu
  160.     if p1 == 1 or (user.menu == 0.75 and p1 == "9") then reset()
  161. --Menu 0 = Get Username, or move onto password
  162.     elseif user.menu == 0 and p1 == 28 then
  163.         info[2], user.input, user.line, user.menu, info[3] = user.input, "", origy-5, 0.5, {}
  164.         m1.printex(user.line, "Enter Password:")
  165.     elseif user.menu == 0 then getInput()
  166. --Menu 0.5 = Get Password and check credentials
  167.     elseif user.menu == 0.5 and p1 == 28 then
  168.     --Check Password
  169.         local result = pwdchk()
  170.         if result ~= true then
  171.             if result ~= false then redraw(result) else redraw("Incorrect Name/Password") end
  172.             relock = 3
  173.             reset()
  174.         else
  175.     --If password is right
  176.             user.menu, relock, user.line = 0.75, 15, origy-7
  177.             m1.printex(user.line, "Password Correct, Select Action:")
  178.             m1.printex(user.line+1, "[1] Shutdown Reactor")
  179.             m1.printex(user.line+2, "[2] Generate Xm EUs")
  180.             m1.printex(user.line+3, "[3] Reset Detectors")
  181.             if wiring["door"] then m1.printex(nil, "[4] Toggle Door") end
  182.             if wiring["esu"] then m1.printex(nil, "[5] Toggle ESU Control") end
  183.             m1.printex(nil, "[6] Start Reactor Permanently (unless fault)")
  184.             m1.printex(user.line+1, "[7] + Remote Controller", "right", "noclr")
  185.             m1.printex(user.line+2, "[8] - Remote Controller", "right", "noclr")
  186.             m1.printex(user.line+3, "[9] Cancel             ", "right", "noclr")
  187.             info = {[1] = "pwdchk"}
  188.         end
  189.     elseif user.menu == 0.5 then getInput(true)
  190. --Selecting sub menu
  191.     elseif user.menu == 0.75 and evt == "char" and tonumber(p1) and tonumber(p1) > 0 and tonumber(p1) < 10 then
  192.         redraw(nil, true)
  193.         relock, user.menu, user.line = nil, tonumber(p1), origy-7
  194.     --Generate X EUs
  195.         if user.menu == 2 then m1.printex(user.line, "How many EUs? (x1m):")
  196.     --Get PCID for add/remove controller
  197.         elseif user.menu == 7 or user.menu == 8 then m1.printex(user.line, "Enter PCID:")
  198.     --Other actions
  199.         else
  200.             userAction(user.menu)
  201.             reset()
  202.         end
  203. --Generate X EU Stuff
  204.     elseif user.menu == 2 and p1 == 28 then
  205.         downtime = user.input
  206.         userAction(user.menu)
  207.         reset()
  208. --Add/Remove Remote Controller Stuff
  209.     elseif user.menu == 7 and p1 == 28 then
  210.         ids[tonumber(user.input)] = true
  211.         redraw("INFO: PC "..user.input.." Added", true)
  212.         reset()
  213.     elseif user.menu == 8 and p1 == 28 then
  214.         ids[tonumber(user.input)] = false
  215.         redraw("INFO: PC "..user.input.." Removed", true)
  216.         reset()
  217. --Get input for pcid and x eu actions (as a number)
  218.     elseif user.menu == 2 or user.menu == 7 or user.menu == 8 then getInput("num") end
  219. end
  220.  
  221. function checkMsg()         --Handles wifi stuff
  222.     if evt == "rednet_message" and p2:find("r3act0r1d") then
  223.         redraw("INFO: Sent PCID to "..tostring(p1))
  224.         if ids[p1] then rednet.send(p1, tostring(m1cr0s[1])) else rednet.send(p1, "Unauthorised") end
  225.     --Verify message to stop crashes
  226.     elseif evt == "rednet_message" and ids[p1] and type(m1.deserialize(p2)) == "table" then
  227.         if m1.deserialize(p2)[1] == "pwdchk" then
  228.     --Check Password if computer is authorised
  229.             if not ids[p1] then
  230.                 rednet.send(p1, "Unauthorised")
  231.                 redraw("INFO: PC "..tostring(p1).." attempted unauthorised access")
  232.                 return true
  233.             end
  234.             info = m1.deserialize(p2)
  235.             for i, data in pairs(info[3]) do info[3][i] = data*(info[2]:len()/2) end
  236.             local result = pwdchk()
  237.         --If its wrong
  238.             if result ~= true then
  239.                 if result ~= false then redraw("INFO: Error @ PC "..":"..tostring(p1)..result) else redraw("INFO: Error @ PC "..tostring(p1)..":".."Incorrect Name/Password") end
  240.                 rednet.send(p1, tostring(result))
  241.                 return true
  242.             end
  243.         --If its right
  244.             rednet.send(p1, tostring(result))
  245.             redraw("INFO: "..info[2].." logged in from PC "..tostring(p1))
  246.             rats[p1], info = os.clock(), {[1] = "pwdchk"}
  247.     --Check actions from remote controller
  248.         elseif m1.deserialize(p2)[1] == "r3act0rctr1r" then
  249.             local tbl = m1.deserialize(p2)
  250.     --Mange Actual commands
  251.             if not rats[p1] then
  252.                 rednet.send(p1, "Unauthorised")
  253.                 redraw("INFO: PC "..tostring(p1).." attempted unauthorised access")
  254.     --Send history
  255.             elseif tbl[2] == 7 then
  256.                 m1.tablesend(m1.gethistory(), p1)
  257.                 redraw("INFO: PC "..tostring(p1).." requested history")
  258.     --Shutdown, Reset Detector, Start Reactor
  259.             elseif tbl[2] == 1 or tbl[2] == 3 or tbl[2] == 6 then
  260.                 userAction(tbl[2])
  261.                 rednet.send(p1, "true")
  262.     --Timed generator
  263.             elseif type(tbl[2]) == "string" and tbl[2]:find("eu") then
  264.                 downtime = tonumber(tbl[2]:sub(3, tbl[2]:len()))
  265.                 userAction(2)
  266.                 rednet.send(p1, tostring(downtime))
  267.     --Door Toggle
  268.             elseif tbl[2] == 4 and wiring["door"] then
  269.                 userAction(3)
  270.                 rednet.send(p1, wiring[5])
  271.     --Send wires status
  272.             elseif tbl[2] == 9 then
  273.                 local msg = {[1] = wiring[5], [2] = wiring[6], [3] = wiring[8], [4] = downtime}
  274.                 if not wiring["door"] then msg[1] = false end
  275.                 if not thermal[1] then msg[3] = false end
  276.                 if wiring["esu"] then msg[5] = true end
  277.                 m1.tablesend(msg, p1)
  278.     --Toggle ESU Control
  279.             elseif tbl[2] == 5 then
  280.                 rednet.send(p1, userAction(5))
  281.     --Deauthorisation of the RAT after exiting
  282.             elseif tbl[2] == 8 then
  283.                 rats[p1] = false
  284.                 redraw("INFO: Lease for controller "..p1.." expired")
  285.             end
  286.     --Renew lease upon receiving command
  287.             if p2 ~= 8 then rats[p1] = os.clock() end
  288.         end
  289.     end
  290. end
  291.  
  292. function checkIce()         --Checks Ice status
  293. --If ice is pumping
  294.     if evt == "redstone" and wireschk("ice") then
  295. --If it previously wasnt pumping
  296.         if ice[2] > 0 then
  297.             if not thermal[3] then wires("reactor", not wiring[7]) end
  298.             redraw("INFO: Ice pumping again.")
  299.         end
  300.         ice[2], ice[4] = 0, os.startTimer(ice[3]/2)
  301. --If no ice has pumped in last ice[3]/2 seconds and reactor is on
  302.     elseif evt == "timer" and p1 == ice[4] and ice[2] == 0 and wiring[6] == "On" then
  303.         redraw("WARNING: No ice in last "..tostring(ice[3]/2).." seconds")
  304.         ice[2] = 1
  305. --If no ice has pumped in ice[3] seconds, shutdown reactor
  306.     elseif evt == "timer" and p1 == ice[4] and ice[2] == 1 and wiring[6] == "On" then
  307.         wires("reactor", wiring[7])
  308.         redraw("SEVERE: No ice in "..tostring(ice[3]).." seconds. Reactor Shutdown")
  309.         ice[2] = 2
  310.     end
  311. end
  312.  
  313. function checkThermal()     --Checks thermal monitor status
  314. --If reactor was overheated and now cooled down
  315.     if evt == "redstone" and not wireschk("thermal") and thermal[3] == true and wiring[6] == "Off" then
  316.         thermal[3], wiring[8] = os.startTimer(thermal[2]), "Cool"
  317.         redraw("INFO: Cooled down. Restarting in "..tostring(thermal[2]).." seconds")
  318. --If reactor is overheating turn it off
  319.     elseif evt == "redstone" and wireschk("thermal") and not thermal[3] and wiring[6] == "On" then
  320.         thermal[3], wiring[8] = true, "Hot"
  321.         wires("reactor", wiring[7])
  322.         redraw("SEVERE: Overheating!! Shutdown Reactor")
  323. --If timer is on to restart reactor
  324.     elseif evt == "timer" and p1 == thermal[3] then
  325.         wires("reactor", not wiring[7])
  326.         redraw("INFO: Reactor Restarted")
  327.         thermal[3] = false
  328.     end
  329. end
  330.  
  331. function checkEsu()         --Checks ESU status
  332.     if evt == "redstone" and not wireschk("esu") and thermal[4] == true and wiring[6] == "Off" then
  333.         redraw("INFO: ESU not full. Resarting in "..tostring(thermal[2]).." seconds")
  334.         thermal[4] = os.startTimer(thermal[2])
  335.     elseif evt == "redstone" and wireschk("esu") and not thermal[4] and wiring[6] == "On" then
  336.         thermal[4] = true
  337.         wires("reactor", wiring[7])
  338.         redraw("INFO: ESU filled. Shutdown Reactor")
  339.     elseif evt == "timer" and p1 == thermal[4] then
  340.         if not wireschk("esu") then
  341.             thermal[4] = false
  342.             wires("reactor", not wiring[7])
  343.             redraw("INFO: Reactor Restarted")
  344.         else
  345.             redraw("INFO: ESU full again, Resarting in "..tostring(thermal[2]).." seconds")
  346.             thermal[4] = os.startTimer(thermal[2])
  347.         end
  348.     end
  349. end
  350.  
  351. function checkCountdowns()  --Handles timed shutdown and auto-closing of menu
  352.     if relock and relock <= 0 then
  353.         relock = nil
  354.         reset()
  355.     elseif relock and relock > 0 then
  356.         relock = relock-1
  357.     end
  358.     if downtime and downtime > 0 and wiring[6] == "On" then
  359.         downtime = downtime-1
  360.         redraw()
  361.     elseif downtime and downtime <= 0 then
  362.         downtime = nil
  363.         userAction(1)
  364.     end
  365. --Check for and remove expired RAT leases
  366.     for id, jointime in pairs(rats) do
  367.         if type(jointime) == "number" and jointime+60 < os.clock() then
  368.             rats[id] = false
  369.             redraw("INFO: Lease for controller "..id.." expired")
  370.         end
  371.     end
  372. end
  373.  
  374. function setup()            --First Time Setup
  375.     term.clear()
  376.     term.setCursorPos(1, 1)
  377.     print("bundled/redstone wiring?")
  378.     local wiretype = string.lower(read())
  379.     print("Use Ice Checker? yes/no")
  380.     ice[1] = string.lower(read())
  381.     if ice[1] == "yes" then
  382.         ice[1] = true
  383.         print("How long before shutdown due to lack of ice?")
  384.         ice[3] = tonumber(read())
  385.     else ice[1] = false end
  386.     print("Thermal monitor connected? yes/no")
  387.     thermal[1] = string.lower(read())
  388.     if thermal[1] == "yes" then thermal[1] = true else thermal[1] = false end
  389.     print("Use energy storage unit auto-shutdown? yes/no")
  390.     wiring["esu"] = string.lower(read())
  391.     if wiring["esu"] == "no" then wiring["esu"] = false end
  392.     if thermal[1] or wiring["esu"] then
  393.         print("How long before restart after overheat/ESU filled?")
  394.         thermal[2] = tonumber(read())
  395.     end
  396.     print("Use door control? yes/no")
  397.     wiring["door"] = string.lower(read())
  398.     if wiring["door"] == "no" then wiring["door"] = false end
  399.     if wiretype == "bundled" then
  400.         print("What face is the bundled cable connected to?")
  401.         wiring[1] = string.lower(read())
  402.         print("What colour is the reactor wire?")
  403.         wiring["reactor"] = string.lower(read())
  404.         if ice[1] then
  405.             print("What colour is the ice detection wire?")
  406.             wiring["ice"] = string.lower(read())
  407.         end
  408.         if thermal[1] then
  409.             print("What colour is the thermal wire?")
  410.             wiring["thermal"] = string.lower(read())
  411.         end
  412.         if wiring["door"] then
  413.             print("What colour is the door wire?")
  414.             wiring["door"] = string.lower(read())
  415.         end
  416.         if wiring["esu"] then
  417.             print("What colour is the energy storage unit wire?")
  418.             wiring["esu"] = string.lower(read())
  419.         end
  420.     elseif wiretype == "redstone" then
  421.         wiring[1] = true
  422.         print("What face is the reactor wire on?")
  423.         wiring["reactor"] = string.lower(read())
  424.         if ice[1] then
  425.             print("What face is the ice detection wire on?")
  426.             wiring["ice"] = string.lower(read())
  427.         end
  428.         if thermal[1] then
  429.             print("What face is the thermal wire?")
  430.             wiring["thermal"] = string.lower(read())
  431.         end
  432.         if wiring["door"] then
  433.             print("What face is the door wire on?")
  434.             wiring["door"] = string.lower(read())
  435.         end
  436.         if wiring["esu"] then
  437.             print("What face is the energy storage unit wire on?")
  438.             wiring["esu"] = string.lower(read())
  439.         end
  440.     end
  441.     print("What redstone state turns the reactor OFF? on/off")
  442.     local state = string.lower(read())
  443.     if state == "on" then wiring[7] = true else wiring[7] = false end
  444.     print("How many EUs/tick are made?")
  445.     eutick = tonumber(read())
  446.     print("Use M1cr0s login server? (yes/no)")
  447.     local ans = string.lower(read())
  448.     if ans == "yes" then
  449.         print("Getting Server ID")
  450.         rednet.open(m1.getperipheral("modem"))
  451.         repeat
  452.             rednet.broadcast("srvidreq")
  453.             m1cr0s[1], junk = rednet.receive(3)
  454.         until type(m1cr0s[1]) == "number"
  455.         rednet.close(m1.getperipheral("modem"))
  456.         print("Minimum Rank required to use this?")
  457.         m1cr0s[2] = tonumber(read())
  458.     else
  459.         term.clear()
  460.         term.setCursorPos(1, 1)
  461.         m1cr0s[1] = "no"
  462.         print("Enter Username:")
  463.         m1cr0s[2] = read()
  464.         print("Enter Password:")
  465.         m1cr0s[3] = {}
  466.         repeat
  467.             event, key = os.pullEvent("key")
  468.             if event == "key" and key == 14 then table.remove(m1cr0s[3])
  469.             elseif event == "key" and key ~= 28 and key ~= 1 then table.insert(m1cr0s[3], key*(m1cr0s[2]:len()/2)) end
  470.             m1.printex(4, " ")
  471.             for i,letter in ipairs(m1cr0s[3]) do m1.printex(4, "*", i, "noclr") end
  472.         until event == "key" and key == 28
  473.     end
  474.     ice[2], ice[4], wiring[5], wiring[6], wiring[8] = ice[2] or 0, ice[4] or 0, "Closed", "On", "Cool" --Stops problems with nils
  475.     save()
  476.     print("Finished, Rebooting...")
  477.     os.sleep(1)
  478.     os.reboot()
  479. end
  480.  
  481. function ticker()           --Manages Timers
  482.     evt, p1, p2 = os.pullEvent()
  483.     checkUser()
  484.     checkMsg()
  485.     if thermal[1] then checkThermal() end
  486.     if wiring["esu"] and thermal[4] ~= 0 then checkEsu() end
  487.     if p1 == ticktime then
  488.         checkCountdowns()
  489.         ticktime, savecount = os.startTimer(1), savecount+1
  490.     end
  491.     if p1 == ice[4] then
  492.         checkIce()
  493.         ice[4] = os.startTimer(ice[3]/2)
  494.     else checkIce() end
  495.     if savecount >= 5 then
  496.         save()
  497.         savecount = 0
  498.     end
  499. end
  500.  
  501. function startup()          --Loads settings
  502.     if fs.exists("/reactor/settings") == false then setup() end
  503.     term.clear()
  504.     save(1)
  505.     if wiring["door"] and wiring[5] == "Open" then wires("door") end
  506. --Print last known problems if any
  507.     if ice[1] and ice[2] == 2 then
  508.         redraw("SEVERE: No ice on last run. Shutdown Reactor")
  509.     elseif ice[1] and ice[2] ~= 0 then
  510.         redraw("WARNING: Ice fault on last run of program.")
  511.     end
  512.     if thermal[1] and not wireschk("thermal") and thermal[3] then
  513.         thermal[3] = os.startTimer(thermal[2])
  514.         wiring[8] = "Cool"
  515.         redraw("INFO: Cooled down. Restarting in "..tostring(thermal[2]).." seconds")
  516.     elseif thermal[1] and wireschk("thermal") and not thermal[3] then
  517.         wires("reactor", wiring[7])
  518.         thermal[3], wiring[8] = true, "Hot"
  519.         redraw("SEVERE: Overheating!! Shutdown Reactor")
  520.     end
  521.     if downtime ~= nil then
  522.         wires("reactor", not wiring[7])
  523.         redraw("INFO: Reactor shutting down in "..tostring(downtime).." seconds")
  524.     elseif wiring[6] == "On" then
  525.         wires("reactor", not wiring[7])
  526.         redraw("INFO: Reactor Restarted")
  527.     elseif wiring[6] == "Off" then
  528.         wires("reactor", wiring[7])
  529.         redraw("INFO: Booted")
  530.     end
  531.     reset()
  532.     if m1.getperipheral("modem") == nil then error("\nPlease Attach a Wireless Modem") end
  533.     rednet.open(m1.getperipheral("modem"))
  534.     repeat ticker() until false
  535.     rednet.close(m1.getperipheral("modem"))
  536. end
  537.  
  538. startup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement