SHOW:
|
|
- or go back to the newest paste.
| 1 | local offReac = 9902 --температура перегрева реактора до отключения | |
| 2 | local perDamage = 90 --процент износа конденсатора при котором он меняется | |
| 3 | ||
| 4 | local com = require("component")
| |
| 5 | local computer = require("computer")
| |
| 6 | local event = require("event")
| |
| 7 | local gpu = com.gpu | |
| 8 | local w,h = gpu.getResolution() | |
| 9 | local per,noFuel,lowEu,toReac,run = 0,0,0,1,true | |
| 10 | local sideReac,sideInv,sideRed,OutputEUt,StartEUt | |
| 11 | local slotReac = {}
| |
| 12 | ||
| 13 | if not com.isAvailable("transposer") then
| |
| 14 | print("нет транспозера")
| |
| 15 | os.exit() | |
| 16 | end | |
| 17 | local tr = com.transposer | |
| 18 | ||
| 19 | if not com.isAvailable("redstone") then
| |
| 20 | print("нет контроллера красного камня")
| |
| 21 | os.exit() | |
| 22 | end | |
| 23 | local red = com.redstone | |
| 24 | ||
| 25 | if not com.isAvailable("reactor_chamber") then
| |
| 26 | print("камера реактора не найдена")
| |
| 27 | os.exit() | |
| 28 | end | |
| 29 | local reactor = com.reactor_chamber | |
| 30 | ||
| 31 | if reactor.producesEnergy() then | |
| 32 | print("\n".."остановите реактор !")
| |
| 33 | for i = 0,5 do | |
| 34 | if red.getOutput(i) > 0 then | |
| 35 | red.setOutput(i, 0) | |
| 36 | end | |
| 37 | end | |
| 38 | os.exit() | |
| 39 | end | |
| 40 | ||
| 41 | if reactor.getHeat() > offReac then | |
| 42 | print("\n".."перегрев реактора !")
| |
| 43 | os.exit() | |
| 44 | end | |
| 45 | ||
| 46 | print("поиск реактора и сундука")
| |
| 47 | for i = 0,5 do | |
| 48 | local vr = tr.getInventorySize(i) | |
| 49 | if vr ~= nil then | |
| 50 | if vr == 58 then | |
| 51 | print("реактор в стороне: "..i)
| |
| 52 | sideReac = i | |
| 53 | else | |
| 54 | sideInv = i | |
| 55 | print("сундук в стороне: "..i)
| |
| 56 | end | |
| 57 | end | |
| 58 | end | |
| 59 | if not sideReac then | |
| 60 | print("\n".."камера реактора не найдена")
| |
| 61 | os.exit() | |
| 62 | end | |
| 63 | if not sideInv then | |
| 64 | print("\n".."сундук не найден")
| |
| 65 | os.exit() | |
| 66 | end | |
| 67 | local slotsReac = tr.getInventorySize(sideReac) | |
| 68 | local slotsInv = tr.getInventorySize(sideInv) | |
| 69 | ||
| 70 | local function getAllStacks(side) | |
| 71 | local temp = {}
| |
| 72 | local tmp = false | |
| 73 | for i = 1, tr.getInventorySize(side) do | |
| 74 | tmp = tr.getStackInSlot(side, i) | |
| 75 | if tmp ~= nil then | |
| 76 | temp[i-1] = tmp | |
| 77 | end | |
| 78 | end | |
| 79 | return temp | |
| 80 | end | |
| 81 | ||
| 82 | print("сохранение конденсаторов")
| |
| 83 | local data = getAllStacks(sideReac) | |
| 84 | for i = 0,slotsReac do | |
| 85 | if data[i] and data[i].name then | |
| 86 | if string.find(data[i].name,"ondensator") then | |
| 87 | local per = math.ceil(100*data[i].damage/data[i].maxDamage) | |
| 88 | print("слот: "..(i+1).." износ: "..per.." %")
| |
| 89 | if per >= perDamage then | |
| 90 | print("\n".."замените конденсатор в слоте: "..(i+1))
| |
| 91 | os.exit() | |
| 92 | end | |
| 93 | table.insert(slotReac, i+1) | |
| 94 | end | |
| 95 | end | |
| 96 | end | |
| 97 | ||
| 98 | print("пробный запуск")
| |
| 99 | for k,n in pairs({3,2,4,5,0,1}) do
| |
| 100 | red.setOutput(n, 15) | |
| 101 | if reactor.producesEnergy() then | |
| 102 | os.sleep(1) | |
| 103 | StartEUt = math.ceil(reactor.getReactorEUOutput()) | |
| 104 | print("StartEUt = "..StartEUt)
| |
| 105 | sideRed = n | |
| 106 | red.setOutput(n, 0) | |
| 107 | print("редстоун в стороне: "..sideRed)
| |
| 108 | break | |
| 109 | else | |
| 110 | red.setOutput(n, 0) | |
| 111 | end | |
| 112 | if k == 6 then | |
| 113 | print("\n".."реактор не запускается")
| |
| 114 | os.exit() | |
| 115 | end | |
| 116 | end | |
| 117 | ||
| 118 | print("настройка завершена".."\n".."старт...")
| |
| 119 | --os.sleep(2) | |
| 120 | ||
| 121 | local function gui() | |
| 122 | gpu.setResolution(28,15) | |
| 123 | gpu.setBackground(0x000000) | |
| 124 | gpu.fill(1,1,28,15," ") | |
| 125 | gpu.setForeground(0x669999) | |
| 126 | gpu.set(1,1,"┌──────────────────────────┐") | |
| 127 | gpu.set(1,2,"│ │ │ │ │ │ │ │ │ │") | |
| 128 | gpu.set(1,3,"│──────────────────────────│") | |
| 129 | gpu.set(1,4,"│ │ │ │ │ │ │ │ │ │") | |
| 130 | gpu.set(1,5,"│──────────────────────────│") | |
| 131 | gpu.set(1,6,"│ │ │ │ │ │ │ │ │ │") | |
| 132 | gpu.set(1,7,"│──────────────────────────│") | |
| 133 | gpu.set(1,8,"│ │ │ │ │ │ │ │ │ │") | |
| 134 | gpu.set(1,9,"│──────────────────────────│") | |
| 135 | gpu.set(1,10,"│ │ │ │ │ │ │ │ │ │") | |
| 136 | gpu.set(1,11,"│──────────────────────────│") | |
| 137 | gpu.set(1,12,"│ │ │ │ │ │ │ │ │ │") | |
| 138 | gpu.set(1,13,"└──────────────────────────┘") | |
| 139 | end | |
| 140 | ||
| 141 | local xy = {
| |
| 142 | {"2","2"},{"5","2"},{"8","2"},{"11","2"},{"14","2"},{"17","2"},{"20","2"},{"23","2"},{"26","2"},
| |
| 143 | {"2","4"},{"5","4"},{"8","4"},{"11","4"},{"14","4"},{"17","4"},{"20","4"},{"23","4"},{"26","4"},
| |
| 144 | {"2","6"},{"5","6"},{"8","6"},{"11","6"},{"14","6"},{"17","6"},{"20","6"},{"23","6"},{"26","6"},
| |
| 145 | {"2","8"},{"5","8"},{"8","8"},{"11","8"},{"14","8"},{"17","8"},{"20","8"},{"23","8"},{"26","8"},
| |
| 146 | {"2","10"},{"5","10"},{"8","10"},{"11","10"},{"14","10"},{"17","10"},{"20","10"},{"23","10"},{"26","10"},
| |
| 147 | {"2","12"},{"5","12"},{"8","12"},{"11","12"},{"14","12"},{"17","12"},{"20","12"},{"23","12"},{"26","12"},
| |
| 148 | } | |
| 149 | ||
| 150 | local function stop(wait) | |
| 151 | local e = ({event.pull(wait,"key_down")})[4]
| |
| 152 | if e == 18 or e == 20 then | |
| 153 | red.setOutput(sideRed, 0) | |
| 154 | gpu.setResolution(w, h) | |
| 155 | gpu.setBackground(0x000000) | |
| 156 | gpu.setForeground(0xFFFFFF) | |
| 157 | gpu.fill(1, 1, w, h, " ") | |
| 158 | print("программа завершена")
| |
| 159 | os.sleep(1) | |
| 160 | if reactor.producesEnergy() then | |
| 161 | print("ВНИМАНИЕ реактор по прежнему активен !!!")
| |
| 162 | else | |
| 163 | print("реактор остановлен")
| |
| 164 | end | |
| 165 | run = false | |
| 166 | end | |
| 167 | end | |
| 168 | ||
| 169 | local function alert(message) | |
| 170 | gpu.setForeground(0xFF9900) | |
| 171 | gpu.set(1,14," для завершения нажмите E ") | |
| 172 | gpu.setForeground(0xFF0000) | |
| 173 | gpu.set(1,15,message) | |
| 174 | computer.beep(500, 1) | |
| 175 | stop(3) | |
| 176 | end | |
| 177 | ||
| 178 | ||
| 179 | local function ReactorControl() | |
| 180 | local data = getAllStacks(sideReac) | |
| 181 | for i = 1,#slotReac do | |
| 182 | data = tr.getStackInSlot(sideReac, slotReac[i]) | |
| 183 | if data.damage then | |
| 184 | per = math.ceil(100*data.damage/data.maxDamage) | |
| 185 | gpu.setForeground(0xFF9900) | |
| 186 | gpu.set(tonumber(xy[slotReac[i]][1]),tonumber(xy[slotReac[i]][2]),tostring(per)) | |
| 187 | else | |
| 188 | per = 0 | |
| 189 | end | |
| 190 | if per == 100 then | |
| 191 | red.setOutput(sideRed, 0) | |
| 192 | alert(" снизте % замены конденсат. ")
| |
| 193 | while run do | |
| 194 | computer.beep(500, 1) | |
| 195 | stop(3) | |
| 196 | end | |
| 197 | os.exit() | |
| 198 | end | |
| 199 | if per >= perDamage or per == 0 then | |
| 200 | gpu.setForeground(0xFF9900) | |
| 201 | gpu.set(1,15," замена конденсаторов ") | |
| 202 | if red.getOutput(sideRed) > 0 then | |
| 203 | red.setOutput(sideRed, 0) | |
| 204 | os.sleep(0.5) | |
| 205 | end | |
| 206 | tr.transferItem(sideReac, sideInv, 1, slotReac[i]) | |
| 207 | gpu.setForeground(0xFF0000) | |
| 208 | gpu.set(tonumber(xy[slotReac[i]][1]),tonumber(xy[slotReac[i]][2]),"██") | |
| 209 | os.sleep(0.5) | |
| 210 | local data1 = getAllStacks(sideInv) | |
| 211 | for i1 = 0,slotsInv do | |
| 212 | if data1[i1] and data1[i1].name then | |
| 213 | local per = math.ceil(100*data1[i1].damage/data1[i1].maxDamage) | |
| 214 | if string.find(data1[i1].name,"ondensator") and per < 90 then | |
| 215 | toReac = tr.transferItem(sideInv, sideReac, 1, i1+1, slotReac[i]) | |
| 216 | gpu.setForeground(0x00FF00) | |
| 217 | gpu.set(tonumber(xy[slotReac[i]][1]),tonumber(xy[slotReac[i]][2]),"██") | |
| 218 | break | |
| 219 | else | |
| 220 | toReac = 0 | |
| 221 | end | |
| 222 | end | |
| 223 | end | |
| 224 | end | |
| 225 | end | |
| 226 | ||
| 227 | local function circuitCheck() | |
| 228 | local data = getAllStacks(sideReac) | |
| 229 | local sh = 0 | |
| 230 | for i = 1,#slotReac do | |
| 231 | if data[slotReac[i]-1].damage then | |
| 232 | sh = sh + 1 | |
| 233 | end | |
| 234 | end | |
| 235 | if sh == #slotReac then | |
| 236 | return true | |
| 237 | else | |
| 238 | return false | |
| 239 | end | |
| 240 | end | |
| 241 | ||
| 242 | if reactor.getHeat() > offReac then | |
| 243 | red.setOutput(sideRed, 0) | |
| 244 | alert(" перегрев реактора ! ")
| |
| 245 | elseif not circuitCheck() then | |
| 246 | alert(" нет целых конденсаторов ! ")
| |
| 247 | elseif toReac == 0 then | |
| 248 | alert(" в сундуке нет места ! ")
| |
| 249 | elseif noFuel >= 5 then | |
| 250 | alert(" нет топлива ! ")
| |
| 251 | else | |
| 252 | red.setOutput(sideRed, 15) | |
| 253 | if not reactor.producesEnergy() then | |
| 254 | alert(" реактор не запускается ! ")
| |
| 255 | else | |
| 256 | OutputEUt = math.ceil(reactor.getReactorEUOutput()) | |
| 257 | gpu.setForeground(0x00FF00) | |
| 258 | gpu.set(1,14," eu/t = "..OutputEUt.." ") | |
| 259 | gpu.set(1,15," реактор активен ") | |
| 260 | end | |
| 261 | end | |
| 262 | stop(0.1) | |
| 263 | ||
| 264 | if reactor.producesEnergy() and reactor.getReactorEUOutput() == 0 then | |
| 265 | noFuel = noFuel + 1 | |
| 266 | else | |
| 267 | noFuel = 0 | |
| 268 | if OutputEUt and OutputEUt < StartEUt then | |
| 269 | lowEu = lowEu + 1 | |
| 270 | else | |
| 271 | lowEu = 0 | |
| 272 | end | |
| 273 | end | |
| 274 | if noFuel == 3 or lowEu == 3 then | |
| 275 | local data2 = getAllStacks(sideReac) | |
| 276 | local data3 = getAllStacks(sideInv) | |
| 277 | for i2 = 0,slotsReac do | |
| 278 | if data2[i2] and data2[i2].name then | |
| 279 | if string.find(data2[i2].name,"depleted") then | |
| 280 | gpu.setForeground(0xFF9900) | |
| 281 | gpu.set(1,15," замена стержней ") | |
| 282 | tr.transferItem(sideReac, sideInv, 1, i2+1) | |
| 283 | for i3 = 0,slotsInv do | |
| 284 | if data3[i3] and data3[i3].name then | |
| 285 | if string.find(data3[i3].name,"MOX") or string.find(data3[i3].name,"Uran") then | |
| 286 | if not string.find(data3[i3].name,"depleted") then | |
| 287 | tr.transferItem(sideInv, sideReac, 1, i3+1, i2+1) | |
| 288 | break | |
| 289 | end | |
| 290 | end | |
| 291 | end | |
| 292 | end | |
| 293 | end | |
| 294 | end | |
| 295 | end | |
| 296 | StartEUt = math.ceil(reactor.getReactorEUOutput()) | |
| 297 | lowEu = 0 | |
| 298 | ||
| 299 | end | |
| 300 | if OutputEUt and OutputEUt > StartEUt then | |
| 301 | StartEUt = math.ceil(reactor.getReactorEUOutput()) | |
| 302 | end | |
| 303 | end | |
| 304 | ||
| 305 | gui() | |
| 306 | gpu.setForeground(0xFF9900) | |
| 307 | gpu.set(1,14," для завершения нажмите E ") | |
| 308 | os.sleep(1) | |
| 309 | while run do | |
| 310 | local ok,err = pcall(ReactorControl) | |
| 311 | if not ok then | |
| 312 | red.setOutput(sideRed, 0) | |
| 313 | gpu.setResolution(w, h) | |
| 314 | gpu.setBackground(0x000000) | |
| 315 | gpu.setForeground(0xFFFFFF) | |
| 316 | os.execute("cls")
| |
| 317 | print("программа аварийно завершена")
| |
| 318 | if type(err) == "table" then | |
| 319 | io.stderr:write(table.unpack(err)) | |
| 320 | else | |
| 321 | io.stderr:write(err) | |
| 322 | end | |
| 323 | run = false | |
| 324 | end | |
| 325 | end |