Advertisement
Guest User

startup

a guest
Jan 17th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.94 KB | None | 0 0
  1.  
  2. if shell.getRunningProgram() ~= "startup" then
  3.   print("script not properly installed")
  4.   print("do you want to install autoreactor to this computer and reboot? [y/n]")
  5.   input= read("*")
  6.   if input  == "y" or input == "Y" then
  7.     if fs.exists("/startup") == true then
  8.       print ("setup has detected a startup on this computer, overwrite? y/n")
  9.       input = read("*")
  10.       if input == "N" or input == "n" then
  11.         os.exit()
  12.       else
  13.         shell.run("rm /startup")
  14.       end
  15.     end  
  16.     shell.run("cp "..shell.getRunningProgram().." /startup")
  17.     print ("Copy compleete, please remove anny disks")
  18.     while true do    
  19.       if fs.exists("/disk/startup") == false then
  20.         os.reboot()
  21.       end
  22.     os.sleep(5)
  23.     end
  24.   end
  25. end
  26.  
  27.  
  28. sides = {"top","front","back","bottom","left","right"}
  29. reactorstring = "BigReactors-Reactor"
  30. turbinestring = "BigReactors-Turbine"
  31. monitorstring = "monitor"
  32. modemstring = "modem"
  33. modemchannel = 666 -- dont ask me why
  34. modemsendrate = 1.0
  35. reactorside = nil
  36. turbineside = nil
  37. monitorside = nil
  38. modemside = nil
  39. mincoolant = 5000
  40. targetspeed = 1839.2
  41. speedupto = 1500
  42. panniccoolant = 1000
  43. delay = 0.2
  44. print "detecting sides "
  45. for a= 1,6 do
  46.   if peripheral.isPresent(sides[a]) then
  47.     device = peripheral.getType(sides[a])
  48.     print (sides[a]..": "..device)
  49.     if device == reactorstring then
  50.    
  51.       print("Found a reactor on side: ".. sides[a])
  52.       reactorside = sides[a]
  53.     elseif device == turbinestring then
  54.       print("Found a Turbine on side: ".. sides[a])
  55.       turbineside = sides[a]
  56.     elseif device == modemstring then
  57.       print("Found a modem on side: "..sides[a])
  58.       modemside = sides[a]
  59.     elseif device == monitorstring then
  60.       print("Found a monitor on side: "..sides[a])
  61.       monitorside = sides[a]
  62.     end
  63.   end
  64. end
  65. if reactorside ~= nil and turbineside ~= nil then
  66.   error("You cant controle both with one computer")
  67. elseif reactorside==nil and turbineside==nil and monitorside == nil then
  68.   error("You need to place this computer agianst a computerport or a monitor!")
  69. elseif monitorside ~= nil and modemside == nil then
  70.   error("Found a monitor but no modem")
  71. end
  72.  
  73. if monitorside ~= nil then
  74.   print("monitor started")
  75.   modem = peripheral.wrap(modemside) -- bothway
  76.   modem.open(modemchannel)
  77.   local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  78.   print("The message was: "..message)
  79.   print("The sender is: "..(senderDistance or "an unknown number of").." blocks away from me.")
  80.  
  81. end
  82. print("setup fase finished!")
  83. if reactorside ~= nil then
  84.   if modemside ~= nil then
  85.     modem = peripheral.wrap(modemside)
  86.     modem.open(modemchannel)
  87.     modem.transmit(modemchannel,modemchannel,"test")
  88.   end
  89.  
  90. -- reactorscript
  91.   term.clear()
  92.   reactor = peripheral.wrap(reactorside)
  93.   maxfluid = reactor.getHotFluidAmountMax()
  94.   pump = false
  95.   while true do
  96.     hotfluid = reactor.getHotFluidAmount()
  97.     coolant= reactor.getCoolantAmount()
  98.     if coolant < mincoolant then
  99.       for a=1,6 do
  100.         rs.setOutput(sides[a],true)
  101.       end
  102.       pump = true
  103.     elseif pump == true then
  104.       pump = false
  105.       for a=1,6 do
  106.         rs.setOutput(sides[a],false)
  107.       end
  108.     end
  109.     t = hotfluid / maxfluid
  110.     if coolant < panniccoolant then
  111.       t = 1
  112.     end
  113.     reactor.setAllControlRodLevels(t*100)
  114.     term.setCursorPos(1,1)
  115.     -- reminder we can also catch fuel levels
  116.     sendstring = "RDATA"
  117.     print ("rodlevel: "..(t*100).."%")
  118.     sendstring = sendstring .. ":"..t
  119.     print ("Fuel temp: "..reactor.getFuelTemperature().." C")
  120.     sendstring = sendstring .. ":".. reactor.getFuelTemperature()
  121.     print ("Casing temp: "..reactor.getCasingTemperature().." C")
  122.     sendstring = sendstring .. ":".. reactor.getCasingTemperature()
  123.     print ("Steam : "..reactor.getHotFluidProducedLastTick() .." Mb/t")
  124.     sendstring = sendstring .. ":".. reactor.getHotFluidProducedLastTick()
  125.     print ("coolant: "..reactor.getCoolantAmount() .." Mb")
  126.     sendstring = sendstring .. ":".. reactor.getCoolantAmount()
  127.     print ("is running: "..tostring( reactor.getActive()) )
  128.     sendstring = sendstring .. ":".. tostring(reactor.getActive())
  129.     print ("reactor rods: "..reactor.getNumberOfControlRods())
  130.     print ("reactor fuelspace :"..reactor.getFuelAmountMax())
  131.     local maxx,maxy,maxz = reactor.getMaximumCoordinate()
  132.     local minx,miny,minz = reactor.getMinimumCoordinate()
  133.     print ("Reactorsize : ".. (1+(maxx-minx)).." X "..(1+(maxz-minz)).." X "..(1+(maxy-miny)))
  134.     print ("Cyanide : "..reactor.getWasteAmount())
  135.     print ("Fuel: "..reactor.getFuelAmount())
  136.     print ("Consumtion rate: "..reactor.getFuelConsumedLastTick())
  137.     print ("Fertilization: "..reactor.getFuelReactivity())
  138.     modem.transmit(modemchannel,modemchannel,sendstring)
  139.     os.sleep(delay)  
  140.   end
  141. end
  142. if turbineside ~= nil then
  143. if modemside ~= nil then
  144.   modem =peripheral.wrap(modemside)
  145.   modem.open(modemchannel)
  146.   modem.transmit(modemchannel,modemchannel,"Ttest")
  147. end
  148.   -- turbine script
  149.   term.clear()
  150.   turbine = peripheral.wrap(turbineside)
  151.   turbine.setVentNone()
  152.   vent = false
  153.   while true do
  154.     if turbine.getOutputAmount() > (turbine.getFluidAmountMax()/2) then
  155.     turbine.setVentAll()
  156.     vent = true
  157.     elseif vent == true then
  158.     vent = false
  159.     turbine.setVentNone()
  160.     end
  161.    
  162.     term.setCursorPos(1,1)
  163.     speed = turbine.getRotorSpeed()
  164.     if speed < speedupto then
  165.       turbine.setInductorEngaged(false)
  166.       turbine.setFluidFlowRateMax(2000)
  167.     elseif speed > targetspeed then
  168.       if turbine.getEnergyStored() > 900000 then
  169.         turbine.setInductorEngaged(false)
  170.       else
  171.         turbine.setInductorEngaged(true)
  172.       end
  173.       overspeed = speed - targetspeed
  174.       turbine.setFluidFlowRateMax(2000 -math.pow( overspeed,overspeed))
  175.     else
  176.       turbine.setFluidFlowRateMax(2000)
  177.       if turbine.getEnergyStored() > 900000 then
  178.         turbine.setInductorEngaged(false)
  179.       else
  180.         turbine.setInductorEngaged(true)
  181.       end
  182.     end
  183.     print("speed: "..speed.. " RPM")
  184.     print ("producing: "..turbine.getEnergyProducedLastTick ().." rf/t")
  185.     print ("Flowrate: "..turbine.getFluidFlowRate().." Mb/t")
  186.     print ("inductor: "..tostring(turbine.getInductorEngaged()))
  187.     print ("is running: "..tostring(turbine.getActive()) )
  188.     print ("RotorMass: "..turbine.getRotorMass())
  189.     print ("Efficiency: "..turbine.getBladeEfficiency())
  190.     print ("Output: "..turbine.getOutputAmount())
  191.     print ("Blade: "..turbine.getNumberOfBlades())
  192.     print ("Energy: "..turbine.getEnergyStored())
  193.     print ("Input: "..turbine.getInputAmount())
  194.     print ("Flow: "..turbine.getFluidFlowRate())
  195.         local maxx,maxy,maxz = turbine.getMaximumCoordinate()
  196.     local minx,miny,minz = turbine.getMinimumCoordinate()
  197.     print ("turbineSize: "..(1+(maxx-minx)).." X "..(1+(maxz-minz)).." X "..(1+(maxy-miny)))
  198.     os.sleep(delay)
  199.    
  200.    
  201.   end
  202. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement