Advertisement
eternalclickbait

Untitled

Nov 15th, 2019
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. --Reactor and turbine control script by EternalClickbait
  2. --Reactor, turbine and monitor must be connected with wired modems to the computer
  3.  
  4. local reactors = {}
  5. local turbines = {}
  6. local monitors = {}
  7.  
  8. --The maximum temperature for the reactor
  9. local reactorMaxTemp = 200
  10. --The maximum energy in our turbine's buffer. Max is 1M (1,000,000)
  11. local turbineMaxEnergy = 500000
  12.  
  13. --Prints a message to all monitors/windows
  14. function log(message)
  15. print(message)
  16. for _, side in ipairs(monitors) do
  17. peripheral.wrap(side).write(message)
  18. end
  19. end
  20.  
  21. --// maps a given range from a specific iterator to a new range
  22. local function map(n, start, stop, newStart, newStop, withinBounds)
  23. local value = ((n - start) / (stop - start)) * (newStop - newStart) + newStart
  24.  
  25. --// Returns basic value
  26. if not withinBounds then
  27. return value
  28. end
  29.  
  30. --// Returns values constrained to exact range
  31. if newStart < newStop then
  32. return math.max(math.min(value, newStop), newStart)
  33. else
  34. return math.max(math.min(value, newStart), newStop)
  35. end
  36. end
  37.  
  38. --Sets the scales on all monitors for easily visible text
  39. function setMonitorScales(scale)
  40. for _, side in ipairs(monitors) do
  41. local m = peripheral.wrap(side)
  42. local x,y = m.getSize()
  43. --Normalize the scales
  44. x = map (x, 7,56, 1,5.5)
  45. y = map (y, 5,30, 1,5.5)
  46. local avg = (x+y)/2 --And average them
  47. local s = (tonumber(scale) * tonumber(avg))
  48. m.write(avg)
  49. m.write("\n")
  50. m.write(scale)
  51. m.write("\n")
  52. m.write(s)
  53. m.setTextScale(s)
  54. end
  55. end
  56.  
  57. --Clears all monitors/windows
  58. function clear()
  59. term.clear()
  60. for _, side in ipairs(monitors) do
  61. peripheral.wrap(side).clear()
  62. peripheral.wrap(side).setCursorPos(1,1)--Reset the cursor position
  63. end
  64. term.setCursorPos(1,1)
  65. end
  66.  
  67. --Updates the list of reactors, turbines and monitor
  68. function updatePeripherals()
  69. local peripherals = peripheral.getNames() --Get a list of all the peripherals
  70. log("Peripherals:")
  71. for _, pSide in ipairs(peripherals) do
  72. local pType = peripheral.getType(pSide)
  73. local pFunctions = peripheral.wrap(pSide)
  74.  
  75. if(pType == "BigReactors-Reactor") then --If we found a reactor
  76. table.insert(reactors, pSide)
  77. elseif (pType == "BigReactors-Turbine") then
  78. table.insert(turbines, pSide)
  79. elseif (pType == "monitor") then
  80. table.insert(monitors, pSide)
  81. end
  82. end
  83. end
  84.  
  85. --Lists all of the peripherals connected
  86. function listPeripherals()
  87. log("Reactors:")
  88. for i, pSide in ipairs(reactors) do
  89. log("\t" ..i.. ":\t" ..pSide)
  90. end
  91.  
  92. log("Turbines:")
  93. for i, pSide in ipairs(turbines) do
  94. log("\t" ..i.. ":\t" ..pSide)
  95. end
  96.  
  97. log("Monitors:")
  98. for i, pSide in ipairs(monitors) do
  99. log("\t" ..i.. ":\t" ..pSide)
  100. end
  101. end
  102.  
  103.  
  104. --Updates all info on screen
  105. function update()
  106. --Clear the window(s)
  107. clear()
  108. end
  109.  
  110. log ("Turbine max energy: " ..turbineMaxEnergy)
  111. log ("Reactor max temp:" ..reactorMaxTemp)
  112.  
  113. updatePeripherals()
  114. listPeripherals()
  115. sleep(2)
  116. local i = 0.5
  117. while true do
  118. update()
  119. setMonitorScales(i)
  120. log("Current scale: " ..i)
  121. i = i +0.1
  122. sleep(2)
  123. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement