Advertisement
Aguia_016

turebina

Mar 1st, 2024 (edited)
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.51 KB | Gaming | 0 0
  1. -- THIS VARIABLE MUST BE SET TO PROPERLY CONFIGURE THE PROGRAM!
  2. -- Valid choices are:
  3. -- reactor, turbine, display
  4.  
  5. mode = "setme"
  6.  
  7. if mode == "setme" then
  8.             print("The mode has not been set!")
  9.             print("Please set the mode and try again.")
  10. end
  11.  
  12. -- Variables
  13. -- These can be changed according to your setup
  14.  
  15. -- Communications variables
  16. local reactorInfo = "reactInfo" -- protocol used to send information
  17. local reactorCmd = "reactCmd" -- protocol used to receive commands
  18.  
  19.  
  20. -- Reactor Variables:
  21. local reactorComputerPortSide = "back" --Side that the reactor's computer port is on
  22. local reactorComputerModemSide = "top" --Side the wireless modem is on (for the computer connected to reactor)
  23.  
  24. -- Reactor Monitor Variables:
  25.  
  26. local rmonMonitorSide = "top" --Side the monitor is on for the display of reactor stats
  27. local rmonModemSide = "back" --Side the wireless modem is on for the computer displaying stats
  28.  
  29. -- General Use Functions
  30. function round(val, decimal)
  31.   if (decimal) then
  32.     return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
  33.   else
  34.     return math.floor(val+0.5)
  35.   end
  36. end
  37.  
  38. -- WRM - information sender
  39.  
  40. function reactorPoll()
  41. rednet.open(reactorComputerModemSide)
  42. reactor = peripheral.wrap(reactorComputerPortSide)
  43. connected = reactor.getConnected()
  44. if connected == false then
  45. rednet.broadcast(connected,reactorInfo)
  46. sleep(0.1)
  47. else
  48. local reactorResults = {
  49. active = reactor.getActive(),
  50. rodcount = reactor.getNumberOfControlRods(),
  51. energystored = reactor.getEnergyStored(),
  52. fueltemp = reactor.getFuelTemperature(),
  53. casingtemp = reactor.getCasingTemperature(),
  54. fuelamount = reactor.getFuelAmount(),
  55. wasteamount = reactor.getWasteAmount(),
  56. maxfuel = reactor.getFuelAmountMax(),
  57. rodlevel = reactor.getControlRodLevel(0),
  58. energyproduction = reactor.getEnergyProducedLastTick(),
  59. coolantamount = reactor.getCoolantAmount(),
  60. coolanttype = reactor.getCoolantType(),
  61. hotfluidamount = reactor.getHotFluidAmount(),
  62. hotfluidtype = reactor.getHotFluidType(),
  63. fuelreactivity = reactor.getFuelReactivity(),
  64. fuelconsumed = reactor.getFuelConsumedLastTick(),
  65. reactortype = reactor.isActivelyCooled()
  66. }
  67. rednet.broadcast(reactorResults,reactorInfo)
  68. sleep(0.1)
  69. end
  70. end
  71.  
  72.  
  73. function reactorPowerChange()
  74.  
  75. local id, msg, proto = rednet.receive(reactorCmd,0.1)
  76.  
  77. if msg == "poweron" then
  78.  
  79. if reactor.getActive() == true then
  80. reactor.setActive(false)
  81. elseif reactor.getActive() == false then
  82. reactor.setActive(true)
  83. end
  84.  
  85. end
  86.  
  87. end
  88.  
  89. function reactorCRodChange()
  90. local e = reactor.getControlRodLevel(0)
  91. local id, msg, proto = rednet.receive(reactorCmd,0.1)
  92.  
  93. if msg == "minus" then
  94. local e = e+1
  95. reactor.setAllControlRodLevels(e)
  96.  
  97.  
  98. elseif msg == "minusten" then
  99. local e = e+10
  100. reactor.setAllControlRodLevels(e)
  101.  
  102.  
  103. elseif msg == "plusten" then
  104. local e = e-10
  105. reactor.setAllControlRodLevels(e)
  106.  
  107.  
  108. elseif msg == "plus" then
  109. local e = e-1
  110. reactor.setAllControlRodLevels(e)
  111.  
  112. elseif msg == "zero" then
  113. local e = 100
  114. reactor.setAllControlRodLevels(e)
  115.  
  116. elseif msg == "sto" then
  117. local e = 0
  118. reactor.setAllControlRodLevels(e)
  119. end
  120. end
  121.  
  122. -- Wireless Reactor Monitoring (receiver)
  123.  
  124. function printdataorig() -- original printdata code (not in use)
  125. local id, msg, proto = rednet.receive(reactInfo)
  126. term.redirect(mon)
  127. term.clear()
  128. mon.setTextScale(0.5)
  129. term.setCursorPos(1,1)
  130. if msg == false then
  131. write("STATUS: ")
  132. mon.setBackgroundColour(colors.red)
  133. write("ERROR")
  134. mon.setBackgroundColour(colors.black)
  135. print()
  136. print()
  137. print("Something is wrong with program or reactor setup")
  138. print("Press Ctrl+T to terminate program")
  139. else
  140. write("STATUS: ")
  141. if msg.active == true then
  142. mon.setBackgroundColour(colors.lime)
  143. write("ACTIVE")
  144. elseif msg.active == false then
  145. mon.setBackgroundColour(colors.yellow)
  146. write("NOT ACTIVE")
  147. end
  148. mon.setBackgroundColour(colors.black)
  149. print()
  150. print()
  151. print("Rods Level:          " .. 100-tostring(msg.rodlevel) .." %")
  152. print("Energy Production: " .. math.floor(msg.energylasttick,0) .. " RF/t")
  153. print("Energy Stored:    " .. msg.energystored .. " RF")
  154. print()
  155. print("Fuel:                      " .. msg.fuelamount .. "/" .. msg.fuelmax .. " mB")
  156. print("Fuel Usage:          " .. math.ceil(msg.fueleatlasttick*100)/100 .. " mB/t")
  157. print("Fuel Temperature:  " .. math.floor(msg.fueltemp,1) .. " C")
  158. print("Fuel Reactivity:   " .. math.floor(msg.fuelreact,1) .. " %")
  159. print("Waste:                    " .. msg.wasteamount .. " mB")
  160. print()
  161. print("Casing Temperature:" .. math.floor(msg.casingtemp,1) .. " C")
  162. print()
  163. mon.setBackgroundColour(colors.orange)
  164. write("POWER ")
  165. mon.setBackgroundColour(colors.black)
  166. write(" ")
  167. mon.setBackgroundColour(colors.gray)
  168. write("   RODS LEVEL   ")
  169. print()
  170. mon.setBackgroundColour(colors.orange)
  171. write("SWITCH")
  172. mon.setBackgroundColour(colors.black)
  173. write(" ")
  174. mon.setBackgroundColour(colors.gray)
  175. write("|<")
  176. mon.setBackgroundColour(colors.black)
  177. write(" ")
  178. mon.setBackgroundColour(colors.gray)
  179. write("<<")
  180. mon.setBackgroundColour(colors.black)
  181. write(" ")
  182. mon.setBackgroundColour(colors.gray)
  183. write("<")
  184. mon.setBackgroundColour(colors.black)
  185. write("  ")
  186. mon.setBackgroundColour(colors.gray)
  187. write(">")
  188. mon.setBackgroundColour(colors.black)
  189. write(" ")
  190. mon.setBackgroundColour(colors.gray)
  191. write(">>")
  192. mon.setBackgroundColour(colors.black)
  193. write(" ")
  194. mon.setBackgroundColour(colors.gray)
  195. write(">|")
  196. mon.setBackgroundColour(colors.black)
  197.  
  198. end
  199. sleep(0.11)
  200. end
  201.  
  202.  
  203. function reactorPowerControl() -- original reactor controls. (not in use and not rewritten yet)
  204.  
  205. local event, par1, tx, ty = os.pullEvent()
  206. if event == "monitor_touch"  then
  207.  
  208. if tx == 8 or tx == 9 and ty == 16 then
  209. rednet.broadcast("zero",reactCmd)
  210.  
  211. elseif tx == 11 or tx == 12 and ty == 16 then
  212. rednet.broadcast("minusten",reactCmd)
  213.  
  214. elseif tx == 14 and ty == 16 then
  215. rednet.broadcast("minus",reactCmd)
  216.  
  217. elseif tx == 17 and ty == 16 then
  218. rednet.broadcast("plus",reactCmd)
  219.  
  220. elseif tx == 19 or tx == 20 and ty == 16 then
  221. rednet.broadcast("plusten",reactCmd)
  222.  
  223. elseif tx == 22 or tx == 24 and ty == 16 then
  224. rednet.broadcast("sto",reactCmd)
  225.  
  226. elseif tx<7 and ty == 15 or tx<7 and ty == 16 then
  227. rednet.broadcast("poweron",reactCmd)
  228. end
  229. end
  230. end
  231.  
  232.  
  233. function printdata() -- Passive reactor completed, need active and turbine
  234. rednet.open(rmonModemSide)
  235. local mon = peripheral.wrap(rmonMonitorSide)
  236. local monX ,monY = mon.getSize()
  237. local id, msg, proto = rednet.receive(reactInfo)
  238. term.redirect(mon)
  239. term.clear()
  240. mon.setTextScale(1)
  241. term.setCursorPos(1,1)
  242. if msg == false then
  243. write("STATUS: ")
  244. mon.setBackgroundColour(colors.red)
  245. write("ERROR")
  246. mon.setBackgroundColour(colors.black)
  247. print()
  248. print()
  249. print("Something is wrong with program or reactor setup")
  250. print("Press Ctrl+T to terminate program")
  251. elseif msg.reactortype == false then -- Passive Reactor stat display
  252. write("PASSIVE REACTOR: ")
  253. if msg.active == true then
  254. mon.setBackgroundColour(colors.lime)
  255. write("ONLINE")
  256. elseif msg.active == false then
  257. mon.setBackgroundColour(colors.yellow)
  258. write("OFFLINE")
  259. end
  260. mon.setBackgroundColour(colors.black)
  261. mon.setCursorPos(30,1)
  262. write("CORE REACTIVITY: " .. math.floor(msg.fuelreactivity,1) .. "%")
  263. print()
  264. print("TEMPERATURE")
  265. print(" CORE:            " .. math.floor(msg.fueltemp,1) .. " C")
  266. print(" CASING:    " .. math.floor(msg.casingtemp,1) .. " C")
  267. print()
  268. print("ENERGY")
  269. print(" PRODUCED: " .. math.floor(msg.energyproduction,0) .. " RF/t")
  270. print(" STORED:   " .. msg.energystored .. " RF")
  271. print("                  " .. round(msg.energystored/10000000*100,2) .. "%")
  272. --print()
  273. print("FUEL")
  274. print(" LEVEL:    " .. round(msg.fuelamount/msg.maxfuel*100,2) .. "%")
  275. print(" USAGE:     " .. round(msg.fuelconsumed,3) .. " mB/t")
  276. print(" WASTE:      " .. round(msg.wasteamount/1000,3) .. " mB")
  277. print()
  278. print("CONTROL ROD")
  279. print(" COUNT:           " .. msg.rodcount)
  280. print(" INSERTION:       " .. msg.rodlevel .. " %")
  281. elseif msg.reactortype == false then -- active Reactor stat display
  282. write("ACTIVE REACTOR: ")
  283. if msg.active == true then
  284. mon.setBackgroundColour(colors.lime)
  285. write("ONLINE")
  286. elseif msg.active == false then
  287. mon.setBackgroundColour(colors.yellow)
  288. write("OFFLINE")
  289. end
  290.  
  291. end
  292. sleep(0.11)
  293. end
  294.  
  295.  
  296. if mode == "reactor" then
  297. --REACTOR LOOP
  298.     while true do
  299.             parallel.waitForAll(reactorPoll, reactorPowerChange, reactorCRodChange)
  300.     end
  301. elseif mode == "display" then
  302. --MONITOR LOOP
  303.     while true do
  304.             parallel.waitForAny(printdata,reactorPowerControl)
  305.     end
  306. elseif mode == "turbine" then
  307. --TURBINE LOOP
  308.     print("Coding for turbines has not been completed (yet)")
  309. end
Tags: turebina
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement