Advertisement
Tacnuke

Hexicubes nuclear control cc code

May 18th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. -- all credit goes to Hexicube @ http://www.computercraft.info/forums2/index.php?/topic/2038-nuclear-reactor-control-system/ for this code.
  2. -- the purpose of this paste is to make it easier to import into your world.
  3. -- this setup uses 1 bundled cable
  4.  
  5. --[[START OF CONFIG]]--
  6.  
  7. --[[POSSIBLE CABLE COLOURS]]--
  8. --white orange magneta lightBlue
  9. --yellow lime pink gray
  10. --lightGray cyan purple blue
  11. --brown green red black
  12.  
  13. --[[BUNDLED CABLE SIDE]]--
  14. local cableSide = "back" --side of computer the bundled cable is on
  15.  
  16. --[[REQUIRED CABLES]]--
  17. local coolDownCol = colors.white --input from heat sensor (temp should be lower than heatUp one)
  18. local heatUpCol = colors.red --input from heat sensor (temp should be higher than coolDown one)
  19. local controlCol = colors.black --output to control the reactor
  20.  
  21. --[[OPTIONAL CABLES]]--
  22. local storageStateCol = colors.green --input from EU storage set to "Emit if partially full"
  23. local onCol = colors.pink --output to show the reactor is online
  24. local offCol = colors.purple --output to show the reactor is offline
  25. local emptyCol = colors.lime --output to show the reactor needs uranium [requires storageStateCol]
  26. local storageFullCol = colors.orange --output to show the EU storage is full [requires storageStateCol]
  27.  
  28. --[[OTHER SETTINGS]]--
  29. local companyName = "HexCorp Industries" --name of your company
  30.  
  31. --[[END OF CONFIG]]--
  32.  
  33.  
  34. os.pullEvent = os.pullEventRaw --Prevent Ctrl+T from closing the program
  35.  
  36. --Initialise reactor state variables
  37. local reactorEnabled = true
  38. local reactorEmpty = false
  39. local storageFull = false
  40. local timeSinceActive = 0
  41. local timeSinceFull = 0
  42. local timeSinceNotFull = 0
  43.  
  44. local width, height = term.getSize() --Store the size of the screen
  45.  
  46. local function clearScreen()
  47. term.clear() --Clear the screen
  48. --Print the program and company names
  49. term.setCursorPos(1, 1)
  50. term.write("Nuclear Reactor Control Unit")
  51. term.setCursorPos(width-#companyName+1, height)
  52. term.write(companyName)
  53. end
  54.  
  55. local function doTick()
  56. --Increment reactor active timer and check inputs
  57. timeSinceActive = timeSinceActive + 1
  58. local hot = rs.testBundledInput(cableSide, heatUpCol)
  59. local cold = rs.testBundledInput(cableSide, coolDownCol)
  60. local full = rs.testBundledInput(cableSide, storageStateCol)
  61. if full then --The EU storage is giving a signal, increment its variable
  62. timeSinceFull = timeSinceFull + 1
  63. timeSinceNotFull = 0
  64. else --The EU storage is not giving a signal, increment its other variable
  65. timeSinceNotFull = timeSinceNotFull + 1
  66. timeSinceFull = 0
  67. storageFull = false
  68. end
  69. if timeSinceFull >= 20 then --There has been an EU signal for 20 ticks, the EU storage may be full
  70. hot = true
  71. timeSinceFull = 20
  72. storageFull = true
  73. else storageFull = false end
  74. if timeSinceNotFull >= 20 then --There has not been an EU signal for 20 ticks, the reactor may be out of uranium
  75. timeSinceNotFull = 20
  76. reactorEmpty = true
  77. else reactorEmpty = false end
  78. if reactorEnabled then
  79. if hot then --Disable the reactor, because it is too hot
  80. reactorEnabled = false
  81. reactorEmpty = false
  82. end
  83. else
  84. reactorEmpty = false
  85. if not cold then --Enable the reactor, because it has cooled down
  86. reactorEnabled = true
  87. timeSinceActive = 0
  88. end
  89. end
  90. clearScreen()
  91. term.setCursorPos(1, 3)
  92. term.write("Current status: ")
  93. if reactorEmpty then
  94. term.write("Cells Depleted")
  95. rs.setBundledOutput(cableSide, emptyCol + onCol)
  96. elseif storageFull then
  97. term.write("Energy Storage Full")
  98. rs.setBundledOutput(cableSide, storageFullCol + offCol + controlCol)
  99. elseif reactorEnabled then
  100. term.write("Active")
  101. rs.setBundledOutput(cableSide, onCol)
  102. else
  103. term.write("Inactive")
  104. rs.setBundledOutput(cableSide, offCol + controlCol)
  105. end
  106. term.setCursorPos(1, 4)
  107. term.write("Temperature: ")
  108. if hot then term.write("|Cold |Warm >Hot")
  109. elseif cold then term.write("|Cold >Warm |Hot")
  110. else term.write(">Cold |Warm |Hot") end
  111. sleep(0.25) --Four ticks to the second
  112. end
  113.  
  114. while true do doTick() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement