Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ----config----
  2. maxRun = 0 --up to what number can the reactor run (Number is of the Reactor Controll rods)
  3. maxThemp =1200 --maximal temperature
  4. useThemp =false --Use temperature to define at which controll the therperature is reached it set maxRun according to maxThemp
  5. startCD = 9000000 --at what energy the Cooldown starts
  6. endCD =  7000000 --at what energy the Cooldown ends
  7. endWarmup =3000000 --at what energy does the Powerup stops
  8. maxItemsPerMonitor =10 --when gets the Monitor Special scrolled
  9. ShowInfos =true --Additional infos like RF/Tick etc will be displayed
  10. changeMonitors=false -- If set to true the Monitors will change so the Normal one is the other one
  11. mapTrys=10 --How many times the RF/TICK shall be mesured to make one mesurement out of it
  12. firstRun =true  --the Reactor runs the first time and have to get mapped
  13. reactorMap = {} --This will be replaced with the MAP for THIS SPECIFIC reactor after the First run
  14. thempMap = {} --THIS will be replaced with a Temperature map for THIS SPECIFIC reactor
  15. check=2 --difference between Mesurements  
  16. tickTime =0.5 --time per tick of the programm (NOT MINECRAFT) lower is faster information does have to be a denominator of check so that a Int is the solution ALSO if tickTIme 0.25 or lower it seems buggy
  17. wait = 10 --time between mesurements for the MAPPING the higher the more accurate (more than 20 should be useless)
  18.  
  19.  
  20.  
  21. -----End of Config-----
  22.  
  23. --Made By Xarlas (FTB Forum and Computercraft Forums)
  24.  
  25. --Do NOT Republish as own work
  26. --If you want to use parts of this code for your own code
  27. --give Credits ! (for example Link to my Profile on FTB Forums or the therad where this was Published )
  28.  
  29.  
  30.  
  31. --DO NOT CHANGE ANYTHING AFTER HERE (exept you know what you are doing)
  32.  -- IN THE CODE  "reactorMap =" or  "thempMap =" or "firstRun =" MUST NOT BEEN USED use no space betwen the Variable and the = (reason is the Function replaceConfig replaceCONFIG) or type --NOT CHANGE in the line
  33.  
  34. Var =0  --Differenz from last Messure (variance)
  35. Cont=0  -- Controll rod Level while Cooldown (CD)
  36. NoCD =true --NO Coodlown
  37. NoPU =true --NO Powerup
  38. LastN  = false  --last variance negative
  39. Stabil = false  --Reactor seems stable
  40. Port= nil --Compouter port (Reactor)
  41. UnvPeriph=nil --Peripheral not Validated
  42. MonitorNormal = nil --Monitor that displays information that change often
  43. MonitorSpecial = nil --Monitor that displays special events
  44. CounterMain=0 --CounterMain checking when regulator can be called
  45. EnergyVarTick = 0-- Energy Variance per tick
  46. function startup() --Initialisation
  47.  
  48. searchSide()
  49. if MonitorSpecial ~=nil then
  50.     MonitorSpecial.clear()
  51.     MonitorSpecial.setCursorPos(1,1)
  52. end
  53. if Port == nil then
  54. special_out("Place Computer next to a Big Reactors Reactor Computer Port or Connect it Via MODEMS and try again ")
  55. end
  56.  
  57.  
  58.  
  59. if firstRun then
  60. special_out("Please Wait The Reactor is getting Mapped ")
  61. reactorMap={}
  62. thempMap={}
  63. MapReactor()
  64. saveProg(replaceConfig(loadProg()))
  65. end
  66.  
  67. if useThemp then
  68. special_out("Detect Temprature and adjust to maximum ")
  69. getMaxControll()
  70. end
  71.  
  72. Checker()
  73.  
  74.  
  75. end
  76.  
  77.  
  78. function searchSide()  --searches al 4 sides for peripherals when it found any it trys to Validate them maybe add top and pottom for Monitors
  79.  
  80. allPeripherals = peripheral.getNames()
  81. i=1
  82. while allPeripherals[i] do
  83. thing = allPeripherals[i]
  84. UnvPeriph=peripheral.wrap(thing)
  85. if string.find(thing,"monitor") then
  86. pcall(ValidateMonitor)
  87.  
  88. elseif string.find(thing,"BigReactors-Reactor") then
  89. pcall(ValidateReactor)
  90.  
  91. else
  92. pcall(ValidateReactor)
  93. pcall(ValidateMonitor)
  94. end
  95.  
  96. i=i+1
  97. end
  98.  
  99. end
  100.  
  101.  
  102. function ValidateReactor ()  --Validates if the Peripheral is An Reactor Computer port JUST CALL WITH "pcall" or else the Program will crash
  103.  
  104. if UnvPeriph.getEnergyStored()~=nil then
  105. Port=UnvPeriph
  106. print("Reactor Validated")
  107. UnvPeriph =nil
  108. end
  109.  
  110. end
  111.  
  112.  
  113. function ValidateMonitor()  --Will Validate Peripherals as Monitors and wrap them ( and assign them)
  114.  
  115. if not changeMonitors then
  116.  
  117. if UnvPeriph.getSize()~=nil and MonitorSpecial ==nil then
  118.  
  119. MonitorSpecial=UnvPeriph
  120. UnvPeriph=nil
  121. print("Special Monitor Validated")
  122. end
  123.  
  124. if UnvPeriph.getSize()~=nil and MonitorNormal ==nil then
  125.  
  126. MonitorNormal=UnvPeriph
  127. UnvPeriph=nil
  128. print("Normal Monitor Validated")
  129. end
  130.  
  131. end
  132.  
  133. if changeMonitors then
  134.  
  135. if UnvPeriph.getSize()~=nil and MonitorNormal ==nil then
  136.  
  137. MonitorNormal=UnvPeriph
  138. UnvPeriph=nil
  139. print("Normal Monitor Validated")
  140. end
  141.  
  142. if UnvPeriph.getSize()~=nil and MonitorSpecial ==nil then
  143.  
  144. MonitorSpecial=UnvPeriph
  145. UnvPeriph=nil
  146. print("Special Monitor Validated")
  147. end
  148.  
  149. end
  150.  
  151. end
  152.  
  153.  
  154. function getMaxControll() --Calculates maxRun so that it runs not higher than MaxThemp themerature
  155.  
  156. for i=1,101,1 do
  157.    
  158.  
  159.    
  160.     if thempMap[i]>=maxRun then
  161.  
  162.     maxRun=i-1
  163.     end
  164.    
  165.     if thempMap[i]< maxThemp then
  166.     special_out("Set MAXRUN to ".. maxRun)
  167.         break
  168.    
  169.     end
  170.    
  171.     end
  172.  
  173.  
  174.  
  175. end
  176.  
  177.  
  178. function Checker()  --checks Energy und Calculates variance
  179.    
  180.     while true do
  181.         Energy = Port.getEnergyStored() --initialize Energy with Energy stored
  182.         os.sleep(tickTime)
  183.         Var = Port.getEnergyStored()-Energy --Energy Varianze to tlast Mesurement tickTime ago
  184.         EnergyVarTick=math.floor(Var/((tickTime/0.05)+1)) -- +1 workaround for mesuring one tick to long
  185.         CounterMain=CounterMain+tickTime
  186.      
  187.        
  188.         if ShowInfos then
  189.             displayInfos()
  190.         end
  191.        
  192.         if CounterMain>=check  then
  193.             Regulator()
  194.             CounterMain=0
  195.         end
  196.            
  197.     end
  198.    
  199. end
  200.  
  201.  
  202. function Regulator()  --Reguliert The Rods
  203.    
  204.     EnergyUsed = reactorMap[Port.getControlRodLevel(0)+1] -EnergyVarTick
  205.    
  206.     if NoCD and NoPU then   --Suche wert der am nächsten an EnergyUsed von der Positiven dran ist und setzte diesen
  207.    
  208.     for i=1,101,1 do
  209.    
  210.     if reactorMap[maxRun+1]<=EnergyUsed then    --wenn mehr energy als maximal an controll erlaubt
  211.     Port.setAllControlRodLevels(maxRun)
  212.     break
  213.     end
  214.    
  215.  
  216.    
  217.  
  218.    
  219.     if reactorMap[i]>=EnergyUsed then
  220.  
  221.     Port.setAllControlRodLevels(i-1)
  222.     end
  223.    
  224.     if reactorMap[i]< EnergyUsed then
  225.         break
  226.    
  227.     end
  228.    
  229.     end
  230.     end
  231.    
  232.     if Port.getEnergyStored()> startCD and NoCD then
  233.         special_out ("Start Cooldown")
  234.         Cont = Port.getControlRodLevel(0)
  235.         Port.setAllControlRodLevels(100)
  236.         NoCD= false
  237.     end
  238.    
  239.     if not NoCD and Port.getEnergyStored()< endCD then
  240.         special_out("Stop Cooldown")
  241.         NoCD=true
  242.         LastN=false
  243.         Stabil=false
  244.         Port.setAllControlRodLevels(Cont)
  245.    
  246.     end
  247.     if Port.getEnergyStored()<endWarmup and NoPU then
  248.    
  249.         special_out ("Start Startup")
  250.         NoPU = false
  251.         Port.setAllControlRodLevels(maxRun)
  252.     end
  253.    
  254.     if not NoPU and Port.getEnergyStored()>endWarmup then
  255.         special_out ("Stop Startup")
  256.         NoPU=true
  257.         LastN=false
  258.         Stabil=false
  259.     end
  260.  
  261. end
  262.  
  263.  
  264. function MapReactor () --Does the MAPPING for the reactor
  265.     Port.setActive(true)
  266.     Port.setAllControlRodLevels(0)
  267.     os.sleep(wait)
  268.    
  269. for i=0,100,1 do        --All 100 % mappen
  270.     Port.setAllControlRodLevels(i)
  271.     os.sleep(wait)
  272.     try={}
  273.     tryThemp={}
  274.     for j=1,mapTrys,1 do  --Try Map trys time
  275.         produce=0
  276.         Themp = Port.getFuelTemperature()
  277.             while i~=100 and produce==0 do 
  278.                 displayInfos()
  279.                 produce=Port.getEnergyProducedLastTick()
  280.                 os.sleep(0.1)
  281.             end
  282.         table.insert(try,produce)
  283.         table.insert(tryThemp,Themp)
  284.         displayInfos()
  285.         os.sleep(1)
  286.     end
  287.    
  288.     produced=0
  289.     FullThemp=0
  290.     for h=1,mapTrys,1 do
  291.     produced=produced+try[h]
  292.     FullThemp=FullThemp+tryThemp[h]
  293.     end
  294.     produced =math.floor(produced/mapTrys) --round it to avoid .XXXX which are useles because Messungenauigkeit
  295.     FullThemp=math.floor(FullThemp/mapTrys) --round it to avoid .XXXX which are useles because Messungenauigkeit
  296.    
  297.     if i==100 then
  298.     produced=0
  299.     end
  300.    
  301.     table.insert(reactorMap,produced)
  302.     table.insert(thempMap,FullThemp)
  303.     special_out("At ".. i .." % control the Reactor Produce ".. produced .. "RF/Tick")
  304.     special_out("and has a Temperature of " .. FullThemp .." C" )
  305.     displayInfos()
  306.  
  307. end
  308. special_out("Reactor Mapped")
  309. firstRun = false
  310.  
  311. end
  312.  
  313.  
  314. function loadProg() --loads this Programm as a table
  315.  
  316.  local file = io.open(shell.getRunningProgram() , "r"); --trys to get Filname while running if fails use name directly
  317.  local data = {}
  318.  for line in file:lines() do
  319.  table.insert (data, line);
  320.  end
  321.  io.close(file)
  322.  return data
  323. end
  324.  
  325.  
  326. function replaceConfig(data) --makes changes in the config and returns new programm optimize with replace (remove than insert) Do NOT remove the "NOT CHANGE" or the Function will stop working
  327. notEnd =true
  328. newData={}
  329. --länge einer tabelle mit table.getn( myTable ) dann for schleife
  330.  
  331. i=1
  332. while notEnd do
  333.    
  334.     line = data[i]
  335.    
  336.     if string.find(data[i],"firstRun =") and not string.find(data[i],"--NOT CHANGE") then --NOT CHANGE
  337.    
  338.     line = "firstRun = false" --NOT CHANGE
  339.    
  340.     end
  341.  
  342.     if string.find( data[i],"reactorMap = {") and not string.find(data[i],"--NOT CHANGE") then --NOT CHANGE
  343.     line="reactorMap = {" --NOT CHANGE
  344.         for z = 1, 100, 1 do
  345.            
  346.         line = line .. reactorMap[z].." , "
  347.         end
  348.     line =line .. " 0 } " --say the LAST (100%) is = RF/TICK THIS is a fix for a problem in the MapReactor where one if does not work
  349.    
  350.     end
  351.    
  352.     if string.find( data[i],"thempMap = ") and not string.find(data[i],"--NOT CHANGE") then --NOT CHANGE
  353.     line="thempMap = {" --NOT CHANGE
  354.         for z = 1, 100, 1 do
  355.            
  356.         line = line .. thempMap[z].." , "
  357.         end
  358.     line = line .. thempMap[101] .. "  } " --say the LAST (100%) is = RF/TICK THIS is a fix for a problem in the MapReactor where one if does not work
  359.    
  360.     end
  361.  
  362.     if data[i]=="--end" then
  363.     notEnd = false
  364.     end
  365.     table.insert (newData,line);
  366.     i=i+1
  367.    
  368. end
  369.  
  370. return newData
  371. end
  372.  
  373.  
  374. function saveProg (data) --saves table as Programm
  375.  
  376.  local file=io.open(shell.getRunningProgram() , "w"); --trys to get Filname while running if fails use name directly
  377. notEnd =true
  378. i=1
  379. while notEnd do --länge einer tabelle mit table.getn( myTable ) mit for schleife
  380.  
  381.     file:write(data[i]);
  382.     file:write("\n");
  383.     if data[i]=="--end" then
  384.     notEnd = false
  385.     end
  386.     i=i+1
  387. end
  388. file:flush()
  389. io.close(file)
  390. end
  391.  
  392.  
  393. function normal_out(text) --does print information on NORMAL Monitor use for Things everytime should be displayed
  394.  
  395. if MonitorNormal ~=nil then
  396. local positionXNormal,positionYNormal=MonitorNormal.getCursorPos()
  397. MonitorNormal.write(text)
  398. MonitorNormal.setCursorPos(1,positionYNormal+1) --place cursor on next line
  399.  
  400. else
  401. print (text)
  402. end
  403.  
  404.  
  405. end
  406.  
  407.  
  408. function special_out(text) -- use this instead of print
  409.  
  410. if MonitorSpecial ~=nil then
  411. local positionX,positionY=MonitorSpecial.getCursorPos()
  412. if positionY> maxItemsPerMonitor then
  413. MonitorSpecial.scroll(1)
  414. MonitorSpecial.setCursorPos(1,positionY-1)
  415. positionY=positionY-1
  416. end
  417.  
  418. MonitorSpecial.write(text)
  419. MonitorSpecial.setCursorPos(1,positionY+1) --place cursor on netxt line
  420.  
  421. end
  422.  
  423. if MonitorSpecial ==nil then
  424. print (text)
  425. end
  426.  
  427. end
  428.  
  429.  
  430. function displayInfos() --does show a few informations about the Reactor
  431. if MonitorNormal ~= nil then
  432.     MonitorNormal.clear()
  433.     MonitorNormal.setCursorPos(1,1)
  434. end
  435.  
  436. if ShowInfos then
  437. normal_out("The Energy in the Reactor is "..Port.getEnergyStored().." RF")
  438. normal_out("Which is "..Port.getEnergyStored()/100000 .." % of the Maximal Capacity" )
  439. normal_out("It uses "..Port.getFuelConsumedLastTick().." MB per Tick ")
  440. normal_out("To generate ".. math.floor(Port.getEnergyProducedLastTick()).." RF/Tick ")
  441. normal_out("The Efficiency of the Reactor is ".. math.floor(Port.getEnergyProducedLastTick()/Port.getFuelConsumedLastTick()) .. " RF per MB")
  442. if not firstRun then
  443. normal_out (EnergyVarTick.. " is the Energy Variance per Tick")
  444. end
  445. normal_out(Port.getControlRodLevel(0).." is The Control Level")
  446. normal_out( "The Reactor Fuel is " .. math.floor(Port.getFuelTemperature()) .." C Hot")
  447. end
  448. end
  449.  
  450. startup()
  451.  
  452. -- DONT REMOVE THE LAST LINE even if it seems to be a comment it wont save the controll Temperature otherwise and WILL NOT WORK (program wont do ANYTHING !!!)
  453. --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement