Advertisement
Guest User

Untitled

a guest
Sep 13th, 2012
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.31 KB | None | 0 0
  1. -- Code by mrrg
  2. --
  3. -- Make sure reactor is OFF! controlled by red wire
  4. rout = colors.combine(rout,colors.red)
  5. rs.setBundledOutput("back",rout)
  6. -- Make sure rin is initialized
  7. rin=rs.getBundledInput("bottom")
  8. term.clear()
  9. term.setCursorPos(1,1)
  10. print("======IRON NOVA REACTOR CONTROL SYSTEM V0.1======")
  11. print("=================================================")
  12. local sides=redstone.getSides()
  13. print("=========== Scanning for pheripherals ===========")
  14. print("")
  15. for i=1,#sides do
  16. if(peripheral.isPresent(sides[i])) then
  17. local type=peripheral.getType(sides[i])
  18. print("Found a "..type.." on the "..sides[i].."side.")
  19. if(type=="SensorController") then
  20. side = sides[i]
  21. local all_sens = sensors.getSensors(sides[i])
  22. for i=1,#all_sens do
  23. if(all_sens[i]=="Reactor") then
  24. sensor=all_sens[i]
  25. else
  26. print("Reactor sensor not found!")
  27. end
  28. end
  29. print(" Sensor name: "..sensor)
  30. end
  31. end
  32. end
  33. ok=false
  34. print("")
  35. print("=========== Analyzing reactor sensors ===========")
  36. sensorInfo = sensors.getSensorInfo(side,sensor,"cardType","name","distance","SensorRange","loc","activereading")
  37. print("Name: "..sensorInfo.name)
  38. print("Type: "..sensorInfo.cardType)
  39. --print("Distance: "..sensorInfo.distance)
  40. --print("Range: "..sensorInfo.SensorRange)
  41. targets = sensors.getAvailableTargets(side,sensor)
  42. for i=1,#targets do
  43. target=targets[i]
  44. local status = sensors.setTarget(side,sensor,target)
  45. print(" Found "..#targets.." sensor target/targets.")
  46. if(status) then
  47. readings=sensors.getAvailableReadings(side,sensor)
  48. for i=1,#readings do
  49. --print("Readings: "..readings[i])
  50. if(readings[i]=="Reactor") then
  51. print(" Found a reactor core.")
  52. local status = sensors.setActiveReading(side,sensor,"Reactor")
  53. if(status) then
  54. if sensorInfo.cardType == "IndustrialCraft2 SensorModule" then
  55. core = sensors.getReadingAsTable(side, sensor,"heat","maxheat","output","chambers")
  56. print(" Accessing core readings ok.")
  57. ok=true;
  58. else
  59. core = sensors.getReadingAsTable(side,sensor)
  60. end
  61. end
  62. end
  63. end
  64. end
  65. end
  66. -- Make sure reactor is OFF! controlled by red wire
  67. rout = colors.combine(rout,colors.red)
  68. rs.setBundledOutput("back",rout)
  69. --If we can read the reactor core with ic2 sensor module then go on
  70. if(ok) then
  71. print("")
  72. print("Press P to power up reactor")
  73.  
  74. shutdown=true
  75. cool_in_transit=0
  76. cool_detect=false
  77. request_cool_cnt=0
  78. mon = peripheral.wrap('right')
  79. mon.setTextScale(1)
  80. mon.clear()
  81. mon.setCursorPos(1,1)
  82. mon.write(" IRON NOVA REACTOR")
  83. mon.setCursorPos(1,2)
  84. mon.write(" CONTROL SYSTEM V0.1")
  85. while true do
  86. event,arg = os.pullEvent()
  87. -- Update redstone input
  88. if(event == "redstone") then
  89. rin=rs.getBundledInput("bottom")
  90. end
  91. -- Handle keys
  92. if(event == "key") then
  93. -- print(arg)
  94. if(arg==25) then -- Start reactor
  95. os.startTimer(1)
  96. shutdown=false
  97. term.clear()
  98. term.setCursorPos(1,1)
  99. end
  100. if(arg==31) then -- Shutdown reactor
  101. shutdown=true
  102. end
  103. end
  104. -- Handle timer event, control the reactor
  105. if(event=="timer") then
  106. sensors.setActiveReading(side,sensor,"Reactor")
  107. core = sensors.getReadingAsTable(side, sensor,"heat","maxheat","output","chambers")
  108.  
  109. term.clear()
  110. term.setCursorPos(1,1)
  111.  
  112. heat = core[2]
  113. power = core[6]
  114. print("======IRON NOVA REACTOR CONTROL SYSTEM V0.1======")
  115.  
  116. if(colors.test(rout,colors.red)) then
  117. print("Reactor is : OFFLINE")
  118. else
  119. print("Rector is : ONLINE")
  120. end
  121. print("Temperature : "..heat.." deg C");
  122. mon.setCursorPos(1,5)
  123. mon.write("Temperature : "..heat.." deg C");
  124. print("Production : "..power.." EU/t ");
  125. mon.setCursorPos(1,6)
  126. mon.write("Production : "..power.." EU/t");
  127. if(colors.test(rin,colors.blue)) then
  128. print("External cooling is : OFFLINE")
  129. else
  130. print("External cooling is : ONLINE")
  131. end
  132. if(colors.test(rin,colors.purple)) then
  133. print("Internal cooling is : ONLINE")
  134. else
  135. print("Internal cooling is : OFFLINE")
  136. end
  137. if(colors.test(rin,colors.red)) then
  138. print("Power line 1 is : OFF")
  139. else
  140. print("Power line 1 is : ON")
  141. end
  142.  
  143. if(colors.test(rin,colors.lime)) then
  144. print("Power line 2 is : OFF")
  145. else
  146. print("Power line 2 is : ON")
  147. end
  148.  
  149. if(colors.test(rin,colors.white)) then
  150. print("Power line 3 is : OFF")
  151. else
  152. print("Power line 3 is : ON")
  153. end
  154. if(colors.test(rin,colors.yellow)) then
  155. print("Power line 4 is : OFF")
  156. else
  157. print("Power line 4 is : ON")
  158. end
  159. if(shutdown or eshutdown) then
  160. rout = colors.combine(rout,colors.red)
  161. rs.setBundledOutput("back",rout)
  162. else
  163. if(heat>4000) then
  164. rout = colors.combine(rout,colors.red)
  165. rs.setBundledOutput("back",rout)
  166. end
  167. if(heat<1500) then
  168. rout = colors.subtract(rout,colors.red)
  169. rs.setBundledOutput("back",rout)
  170. end
  171. end
  172.  
  173. sensors.setActiveReading(side,sensor,"ReactorContent")
  174. contents = sensors.getReadingAsTable(side,sensor)
  175.  
  176. -- 1*Uranium
  177. -- N*Ice
  178. -- 1*Coolant
  179. uranium=0
  180. ice=0
  181. coolant=0
  182. for i=1,#contents-1,2 do
  183. if(string.find(contents[i+1],"1*Uran")~=nil) then
  184. uranium=uranium+1;
  185. end
  186.  
  187. if(string.find(contents[i+1],"1*Cool")~=nil) then
  188. coolant=coolant+1;
  189. end
  190.  
  191. ice_str = contents[i+1]
  192. if(string.find(ice_str,"Ice")~=nil) then
  193.  
  194. if(string.sub(ice_str,3,3)=="*") then
  195. num=tonumber(string.sub(ice_str,1,2))
  196. else
  197. num=tonumber(string.sub(ice_str,1,1))
  198. end
  199. ice=ice+num
  200. end
  201. end
  202. print("Uranium cells : "..uranium)
  203. print("Coolant cells : "..coolant)
  204. print("ICE Blocks : "..ice)
  205.  
  206. mon.setCursorPos(1,8)
  207. mon.write("Uranium cells : "..uranium)
  208. mon.setCursorPos(1,9)
  209. mon.write("Coolant cells : "..coolant)
  210. mon.setCursorPos(1,10)
  211. mon.write("ICE Blocks : "..ice.." ")
  212. cool_detect_old=cool_detect
  213. cool_detect=colors.test(rin,colors.cyan)
  214. if(cool_detect==true and cool_detect_old==false) then
  215. cool_in_transit=cool_in_transit+1
  216. end
  217. print("Coolant cells in transit : "..cool_in_transit)
  218.  
  219. if(coolant<15 and request_cool_cnt==0) then
  220. request_cool_cnt=200
  221. end
  222. if(request_cool_cnt>0) then
  223. if(request_cool_cnt==200) then
  224. rout = colors.combine(rout,colors.brown)
  225. rs.setBundledOutput("back",rout)
  226. end
  227. if(request_cool_cnt==100) then
  228. rout = colors.subtract(rout,colors.brown)
  229. rs.setBundledOutput("back",rout)
  230. end
  231.  
  232. if(request_cool_cnt==1) then
  233. cool_in_transit=0
  234. end
  235. request_cool_cnt=request_cool_cnt-1
  236. end
  237. if(colors.test(rin,colors.orange)) then
  238. print("EMERGENCY SHUTDOWN : ENABLED")
  239. shutdown=true
  240. eshutdown=true
  241. else
  242. print("EMERGENCY SHUTDOWN : DISABLED")
  243. eshutdown=false
  244. end
  245. os.startTimer(0.1)
  246. print("")
  247. print("Press S to shutdown reactor and P to power it up.")
  248. end
  249. end
  250. else
  251. print("Can not get readings from reactor core.")
  252. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement