Advertisement
Wihad

Draconic Reactor

Feb 3rd, 2017
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.65 KB | None | 0 0
  1. local ReactorInfo={}
  2. local Temp, FS, FSM, ES, ESM, FC, FCM, FCR, GR, FDR, ST, SHF, SLF
  3. local Temp1,ES1,FS1,Time, globalTime=0,0,0,0,0
  4. local Reactor=peripheral.wrap("top")
  5. local FluxGateOut=peripheral.wrap("back")
  6. local FluxgateIn=peripheral.wrap("bottom")
  7. while true do
  8.   ReactorInfo=Reactor.getReactorInfo()
  9.   for a,b in pairs(ReactorInfo) do
  10.     if a=="status" then ST=b
  11.     elseif a=="fieldStrength" then FS=b
  12.     elseif a=="maxFieldStrength" then FSM=b
  13.     elseif a=="energySaturation" then ES=b
  14.     elseif a=="maxEnergySaturation" then ESM=b
  15.     elseif a=="fuelConversion" then FC=b
  16.     elseif a=="maxFuelConversion" then FCM=b
  17.     elseif a=="fuelConversionRate" then FCR=b
  18.     elseif a=="generationRate" then GR=b
  19.     elseif a=="fieldDrainRate" then FDR=b
  20.     elseif a=="temperature" then Temp=b
  21.     end
  22.   end
  23.   SHF=FluxGateOut.getSignalHighFlow()
  24.   SLF=FluxgateIn.getSignalLowFlow()
  25.  
  26.   if ST=="offline" then
  27.     if FC/FCM<0.2 then
  28.       Reactor.chargeReactor()
  29.     end
  30.   elseif ST=="charging" then
  31.     FluxgateIn.setSignalLowFlow(1000000)
  32.   elseif ST=="charged" then
  33.     FluxgateIn.setSignalLowFlow(50000)
  34.     FluxGateOut.setSignalHighFlow(10000)
  35.     Reactor.activateReactor()
  36.   elseif ST=="online" then
  37.     if (Temp>8000 or FS/FSM<0.2 or ES/ESM<0.1) then         --emergency shut down output
  38.       redstone.setOutput("back",false)
  39.       FluxGateOut.setSignalLowFlow(0)
  40.       FluxGateOut.setSignalHighFlow(SHF*0.95)
  41.       if FS/FSM<0.2 then FluxgateIn.setSignalLowFlow(SLF*1.5+1000) end
  42.     elseif (Temp<7500 and FS/FSM>0.25 and ES/ESM>0.25) then
  43.       redstone.setOutput("back",true)
  44.     end
  45.  
  46.     if (((Temp<7500 and Temp-Temp1<50) or (Temp<5000 and Temp-Temp1<1000)) and Time==10) then
  47.       if ES/ESM>0.99 then
  48.         FluxGateOut.setSignalHighFlow(10000)
  49.       elseif ((ES/ESM>0.6) and ((ES-ES1)/ESM>-0.05)) then       --(-0.5%/s)
  50.         FluxGateOut.setSignalHighFlow(SHF*(1+2/(SHF^0.2)))
  51. print("ES1:"..((ES-ES1)/ESM*10).."%")
  52.       elseif ((ES/ESM>0.15) and ((ES-ES1)/ESM>-0.01)) then      --(-0.1%/s)
  53.         FluxGateOut.setSignalHighFlow(SHF*(1+2/(SHF^0.5)))
  54. print("ES2:"..((ES-ES1)/ESM*10).."%")
  55.       elseif ES/ESM>0.1 and ES/ESM<0.15 then
  56.         FluxGateOut.setSignalHighFlow(SHF*(1+(ES-ES1)/ESM))
  57. print("ES3 *"..(ES-ES1)/ESM)
  58.       end
  59.      
  60.       if FS/FSM>0.99 then
  61.         FluxgateIn.setSignalLowFlow(2000)
  62.       elseif (FS/FSM>0.6 and (FS-FS1)/FSM>-0.05) then           --(-0.5%/s)
  63.         FluxgateIn.setSignalLowFlow(SLF*0.95)      
  64. print("FS1:"..((FS-FS1)/FSM*10).."%")
  65.       elseif (FS/FSM>0.3 and (FS-FS1)/FSM>-0.01) then           --(-0.1%/s)
  66.         FluxgateIn.setSignalLowFlow(SLF*0.98)
  67. print("FS2:"..((FS-FS1)/FSM*10).."%")
  68.       elseif FS/FSM>0.25 and FS/FSM<0.3 then
  69.         FluxgateIn.setSignalLowFlow(SLF*(1-(FS-FS1)/FSM/10))
  70. print("FS3 *"..(FS-FS1)/FSM/10)
  71.       end
  72.     end
  73.  
  74.     if Temp>7000 and Temp-Temp1>10 then
  75.       FluxGateOut.setSignalHighFlow(SHF*0.99)
  76. print("T1")
  77.     elseif Temp>7500 and Temp-Temp1>5 then
  78.       FluxGateOut.setSignalHighFlow(SHF*0.99)
  79. print("T2")
  80.     elseif Temp>7800 and Temp-Temp1>0 then
  81.       FluxGateOut.setSignalHighFlow(SHF*0.95)
  82. print("T3")
  83.     end
  84.  
  85.     if ((ES-ES1)/ESM<-0.01 and ES/ESM<0.25) then                    -- (-0.5%/s)
  86.       FluxGateOut.setSignalHighFlow(SHF*0.98)
  87. print("ES4:"..((ES-ES1)/ESM*50).."%")
  88.     end
  89.  
  90.     if ((FS-FS1)/FSM<-0.004 and FS/FSM<0.3) or ((FS-FS1)/FSM<-0 and FS/FSM<0.25) then   -- (-0.2%/s , 0%)
  91.       FluxgateIn.setSignalLowFlow(SLF*1.1)
  92. print("FS4:"..((FS-FS1)/FSM*50).."%")
  93.     end
  94.    
  95.  
  96.     if FC/FCM>0.9 then                                          --90% Fuel is consumed ---> Shut down
  97.       redstone.setOutput("back",false)
  98.       FluxGateOut.setSignalLowFlow(0)
  99.       Reactor.stopReactor()
  100.     end
  101.     Temp1=Temp
  102.     ES1=ES
  103.     FS1=FS
  104.   end
  105.  
  106.   if Time==10 then Time=0 end
  107.   Time=Time+2
  108.   print("............."..globalTime.."............")
  109.   globalTime=globalTime+2
  110.   sleep(2)  
  111. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement