View difference between Paste ID: d3mpke9m and q5dN2abi
SHOW: | | - or go back to the newest paste.
1
print("Starting Reactor Controller")
2
print("Version 1")
3
print("By Bixilon")
4
5
--Init Modem
6
7
local modem_connected = false
8
9
10
for _, side in pairs(rs.getSides()) do
11
  if peripheral.getType(side) == "modem" then
12
    modem_connected = true
13
    rednet.open(side)
14
  end
15
end
16
17
if not modem_connected then
18
  print("A modem was not found, please attach one and re-run this program")
19
  stop()
20
else
21
  print("A modem was found! Connecting...")
22
end
23
24
--Connecting done
25
26
local mode = 0 -- 0 = unset, 1 = controller (monitor), 2 = reactor controller, 3 = turbine controller
27
28
29
--Init Reactor
30
31
local reactor_connected = false
32
local reactor = nil
33
34
for _, side in pairs(rs.getSides()) do
35
  if peripheral.getType(side) == "BigReactors-Reactor" then
36
    reactor_connected = true
37
    reactor = peripheral.wrap(side)
38
  end
39
end
40
41
42
--Init Turbine
43
44
local turbine_connected = false
45
local turbine = nil
46
47
for _, side in pairs(rs.getSides()) do
48
  if peripheral.getType(side) == "BigReactors-Turbine" then
49
    turbine_connected = true
50
    turbine = peripheral.wrap(side)
51
  end
52
end
53
54
--Init Monitor
55
56
local monitor_connected = false
57
local monitor = nil
58
59
for _, side in pairs(rs.getSides()) do
60
  if peripheral.getType(side) == "monitor" then
61
    monitor_connected = true
62
    monitor = peripheral.wrap(side)
63
  end
64
end
65
66
67
--Detect mode
68
if monitor_connected then
69
  mode = 1 -- Prio 1
70
  print("Monitor connceted! I am THE controller now")
71
elseif reactor_connected then
72
  mode = 2 -- Prio 2
73
  print("Reactor connected! I am a reactor controller now")
74
elseif turbine_connected then
75
  mode = 2 -- Prio 3
76
  print("Turbine connceted! I am a turbine controller now")
77
else 
78
  print("There is no monitor/turbine/reactor attatched! Please attatch one and re-run the program")
79
  stop()
80
end
81
82
83
84-
--Reactor Controller
84+
--Reactor Controller (init)
85
if mode == 2 then
86
  if not reactor.getConnected() then
87
    -- Reactor does not work
88
    print("Reactor is broken!")
89
    stop()
90
  end
91
  if not reactor.isActivelyCooled() then
92
    -- Reaktor does not produce steam!
93
    print("Reactor does not produce steam")
94
  end
95
end
96
97
98
--Turbine Controller (init)
99
if mode == 3 then
100
  if not turbine.getConnected() then
101
    -- Turbine does not work
102
    print("Turbine is broken!")
103
    stop()
104
  end
105
end
106
107
108
print("Program started...")
109
while true do
110
  if mode == 1 then
111
  end
112
  if mode == 2 then
113
    print("Coolant: " ..reactor.getCoolantAmount())
114
    print("Hot: " ..reactor.getHotFluidAmount())
115
  end
116
  if mode == 3 then
117
  end
118
  --Sleep to avoid warning
119
  sleep(1)
120
end
121
122
123
124
125
126
127
128
129
130
--End
131
function stop()
132
  print("Stopping")
133
  for _, side in pairs(rs.getSides()) do
134
    if peripheral.getType(side) == "modem" then
135
      present = true
136
      rednet.close(side)
137
    end
138
  end
139
  print("Stopped!")
140
  do return end
141
end
142
stop()