SHOW:
|
|
- or go back to the newest paste.
| 1 | local event = require("event")
| |
| 2 | local term = require("term")
| |
| 3 | local os = require("os")
| |
| 4 | local com = require("component")
| |
| 5 | local keyb = require("keyboard")
| |
| 6 | local gpu = com.gpu | |
| 7 | ||
| 8 | local fileName = "/home/gtadrs15.txt" | |
| 9 | local cfgName = "/home/DracReactorConfig.cfg" | |
| 10 | ||
| 11 | local function parseNum(str) | |
| 12 | local n = "" | |
| 13 | for i=1,#str do | |
| 14 | local ch = str:byte(i,i) | |
| 15 | if ch >= 48 and ch <= 57 or ch == 46 then | |
| 16 | n = n..string.char(ch) | |
| 17 | end | |
| 18 | end | |
| 19 | if n ~= "" then | |
| 20 | return tonumber(n) | |
| 21 | else return n | |
| 22 | end | |
| 23 | end | |
| 24 | ||
| 25 | local cfg = {}
| |
| 26 | local confnames = | |
| 27 | {
| |
| 28 | [1] = "default_interval", | |
| 29 | [2] = "ctrl_interval", | |
| 30 | [3] = "shift_interval", | |
| 31 | [4] = "ctrlShift_interval", | |
| 32 | [5] = "shield", | |
| 33 | [6] = "tempCriticalEdge", | |
| 34 | [7] = "forceModeTempLowEdge", | |
| 35 | [8] = "forceModeStepCase", | |
| 36 | [9] = "forceModeStep", | |
| 37 | [10] = "safeModeTempWaitEdge", | |
| 38 | [11] = "safeModeTempToWaitEdge", | |
| 39 | [12] = "safeModeStepCase", | |
| 40 | [13] = "safemodeStep" | |
| 41 | } | |
| 42 | ||
| 43 | local function readParse(name) | |
| 44 | local file = io.open(name,"r") | |
| 45 | if file then | |
| 46 | local tab = {}
| |
| 47 | local i = 1 | |
| 48 | while true do | |
| 49 | local str = file:read("*l")
| |
| 50 | if str == nil then | |
| 51 | break | |
| 52 | end | |
| 53 | if parseNum(str) ~= "" then | |
| 54 | tab[i] = parseNum(str) | |
| 55 | i=i+1 | |
| 56 | end | |
| 57 | end | |
| 58 | return tab | |
| 59 | else | |
| 60 | return false | |
| 61 | end | |
| 62 | end | |
| 63 | ||
| 64 | local function configWrite(name) | |
| 65 | if not readParse(name) then | |
| 66 | local file = io.open(name,"w") | |
| 67 | file:write([[ | |
| 68 | -- Интервалы для кнопок +/- | |
| 69 | default_interval = 1000 | |
| 70 | ctrl_interval = 5000 | |
| 71 | shift_interval = 10000 | |
| 72 | ctrlShift_interval = 20000 | |
| 73 | -- Автономный режим: | |
| 74 | -- Основные константы | |
| 75 | shield = 25 - Щиты будут автоматически поддерживаться на этом уровне ( в %) | |
| 76 | tempCriticalEdge = 8100 -- Если температура превысит это значение, программа экстренно понизит поток вывода; | |
| 77 | -- Форсированный режим | |
| 78 | forceModeTempLowEdge = 7500 -- Пока температура не превысит это значение, программа будет работать в форсированном режиме, иначе - перейдет в безопасный режим; | |
| 79 | forceModeStepCase = 5000 -- Если разница между текущей выработкой энергии и выставленным потоком превысит это значение, то к потоку добавится | |
| 80 | forceModeStep = 20000 -- это значение | |
| 81 | -- безопасный режим | |
| 82 | safeModeTempWaitEdge = 8000 -- Если температура превысит это значение, программа будет ожидать, | |
| 83 | safeModeTempToWaitEdge = 7850 -- пока температура не понизится до этого значения; | |
| 84 | safeModeStepCase = 0 -- Если разница между текущей выработкой энергии и выставленным потоком превысит это значение, то к потоку добавится | |
| 85 | safemodeStep = 8000 -- это значение]]) | |
| 86 | file:close() | |
| 87 | elseif #readParse(name) < 13 then | |
| 88 | local file = io.open(name,"w") | |
| 89 | file:write([[ | |
| 90 | -- Интервалы для кнопок +/- | |
| 91 | default_interval = 1000 | |
| 92 | ctrl_interval = 5000 | |
| 93 | shift_interval = 10000 | |
| 94 | ctrlShift_interval = 20000 | |
| 95 | -- Автономный режим: | |
| 96 | -- Основные константы | |
| 97 | shield = 25 - Щиты будут автоматически поддерживаться на этом уровне ( в %) | |
| 98 | tempCriticalEdge = 8100 -- Если температура превысит это значение, программа экстренно понизит поток вывода; | |
| 99 | -- Форсированный режим | |
| 100 | forceModeTempLowEdge = 7500 -- Пока температура не превысит это значение, программа будет работать в форсированном режиме, иначе - перейдет в безопасный режим; | |
| 101 | forceModeStepCase = 5000 -- Если разница между текущей выработкой энергии и выставленным потоком превысит это значение, то к потоку добавится | |
| 102 | forceModeStep = 20000 -- это значение | |
| 103 | -- безопасный режим | |
| 104 | safeModeTempWaitEdge = 8000 -- Если температура превысит это значение, программа будет ожидать, | |
| 105 | safeModeTempToWaitEdge = 7850 -- пока температура не понизится до этого значения; | |
| 106 | safeModeStepCase = 0 -- Если разница между текущей выработкой энергии и выставленным потоком превысит это значение, то к потоку добавится | |
| 107 | safemodeStep = 8000 -- это значение]]) | |
| 108 | file:close() | |
| 109 | elseif cfg.default_interval ~= nil and | |
| 110 | cfg.ctrl_interval ~= nil and | |
| 111 | cfg.shift_interval ~= nil and | |
| 112 | cfg.ctrlShift_interval ~= nil and | |
| 113 | cfg.shield ~= nil and | |
| 114 | cfg.tempCriticalEdge ~= nil and | |
| 115 | cfg.forceModeTempLowEdge ~= nil and | |
| 116 | cfg.forceModeStepCase ~= nil and | |
| 117 | cfg.forceModeStep ~= nil and | |
| 118 | cfg.safeModeTempWaitEdge ~= nil and | |
| 119 | cfg.safeModeTempToWaitEdge ~= nil and | |
| 120 | cfg.safeModeStepCase ~= nil and | |
| 121 | cfg.safemodeStep ~= nil then | |
| 122 | ||
| 123 | local file = io.open(name,"w") | |
| 124 | file:write(string.format( | |
| 125 | [[ | |
| 126 | -- Интервалы для кнопок +/- | |
| 127 | default_interval = %d | |
| 128 | ctrl_interval = %d | |
| 129 | shift_interval = %d | |
| 130 | ctrlShift_interval = %d | |
| 131 | -- Автономный режим: | |
| 132 | -- Основные константы | |
| 133 | shield = %0.2f - Щиты будут автоматически поддерживаться на этом уровне ( в %) | |
| 134 | tempCriticalEdge = %d -- Если температура превысит это значение, программа экстренно понизит поток вывода; | |
| 135 | -- Форсированный режим | |
| 136 | forceModeTempLowEdge = %d -- Пока температура не превысит это значение, программа будет работать в форсированном режиме, иначе - перейдет в безопасный режим; | |
| 137 | forceModeStepCase = %d -- Если разница между текущей выработкой энергии и выставленным потоком превысит это значение, то к потоку добавится | |
| 138 | forceModeStep = %d -- это значение | |
| 139 | -- Безопасный режим | |
| 140 | safeModeTempWaitEdge = %d -- Если температура превысит это значение, программа будет ожидать, | |
| 141 | safeModeTempToWaitEdge = %d -- пока температура не понизится до этого значения; | |
| 142 | safeModeStepCase = %d -- Если разница между текущей выработкой энергии и выставленным потоком превысит это значение, то к потоку добавится | |
| 143 | safemodeStep = %d -- это значение]], | |
| 144 | cfg.default_interval, | |
| 145 | cfg.ctrl_interval, | |
| 146 | cfg.shift_interval, | |
| 147 | cfg.ctrlShift_interval, | |
| 148 | cfg.shield, | |
| 149 | cfg.tempCriticalEdge, | |
| 150 | cfg.forceModeTempLowEdge, | |
| 151 | cfg.forceModeStepCase, | |
| 152 | cfg.forceModeStep, | |
| 153 | cfg.safeModeTempWaitEdge, | |
| 154 | cfg.safeModeTempToWaitEdge, | |
| 155 | cfg.safeModeStepCase, | |
| 156 | cfg.safemodeStep | |
| 157 | )) | |
| 158 | file:close() | |
| 159 | end | |
| 160 | end | |
| 161 | ||
| 162 | local function makeConfig(tab,tab2) | |
| 163 | local config = {}
| |
| 164 | for i=1,#tab do | |
| 165 | config[i] = i | |
| 166 | end | |
| 167 | local iter = 1 | |
| 168 | for k,v in pairs(config) do | |
| 169 | k = tab[iter] | |
| 170 | v = tab2[iter] | |
| 171 | config[tostring(k)] = v | |
| 172 | iter = iter + 1 | |
| 173 | end | |
| 174 | for i=1,#tab do | |
| 175 | config[i] = nil | |
| 176 | end | |
| 177 | return config | |
| 178 | end | |
| 179 | ||
| 180 | local function fileCreate(name) | |
| 181 | local file = io.open(name,"a") | |
| 182 | file:close() | |
| 183 | end | |
| 184 | ||
| 185 | configWrite(cfgName) | |
| 186 | cfg = makeConfig(confnames,readParse(cfgName)) | |
| 187 | ||
| 188 | local function fileWrite(name,uadr,dadr) | |
| 189 | local file = io.open(name,"w") | |
| 190 | file:write(uadr.."\n"..dadr.."\n") | |
| 191 | file:close() | |
| 192 | end | |
| 193 | ||
| 194 | local function fileRead(name) | |
| 195 | local file = io.open(name,"r") | |
| 196 | local uadr,dadr = file:read("*l","*l")
| |
| 197 | file:close() | |
| 198 | return uadr,dadr | |
| 199 | end | |
| 200 | ||
| 201 | local color = { }
| |
| 202 | color["red"] = 0xFF0000 | |
| 203 | color["green"] = 0x00FF00 | |
| 204 | color["yellow"] = 0xFFFF00 | |
| 205 | color["skyblue"] = 0x00FFFF | |
| 206 | color["black"] = 0x000000 | |
| 207 | color["grey"] = 0xC0C0C0 | |
| 208 | color["blue"] = 0x000080 | |
| 209 | color["white"] = 0xFFFFFF | |
| 210 | ||
| 211 | local rback = gpu.getBackground() | |
| 212 | local rfore = gpu.getForeground() | |
| 213 | ||
| 214 | local handleMain | |
| 215 | local handleOptions | |
| 216 | local handleStart | |
| 217 | ||
| 218 | local menuItem = {}
| |
| 219 | menuItem["options"] = | |
| 220 | {
| |
| 221 | ["name"] ="Настройки |", | |
| 222 | ["x"] = 1, | |
| 223 | ["y"] = 2 | |
| 224 | } | |
| 225 | menuItem["save"] = | |
| 226 | {
| |
| 227 | ["name"] ="Сохранить |", | |
| 228 | ["x"] = 1, | |
| 229 | ["y"] = 2 | |
| 230 | } | |
| 231 | menuItem["cancel"] = | |
| 232 | {
| |
| 233 | ["name"] =" Отменить", | |
| 234 | ["x"] = 12, | |
| 235 | ["y"] = 2 | |
| 236 | } | |
| 237 | ||
| 238 | local xz,yz = gpu.maxResolution() | |
| 239 | gpu.setResolution(80,25) | |
| 240 | ||
| 241 | gpu.setBackground(0xF0F0F0) | |
| 242 | gpu.setForeground(0x000000) | |
| 243 | ||
| 244 | local prog = true | |
| 245 | local addCord = {}
| |
| 246 | local subCord = {}
| |
| 247 | local num = {}
| |
| 248 | num["name"] = "Число : " | |
| 249 | num["value"] = 0 | |
| 250 | local OptionDefault = {}
| |
| 251 | local OptionCtrl = {}
| |
| 252 | local OptionShift = {}
| |
| 253 | local OptionCtrlShift = {}
| |
| 254 | local OptionShield = {}
| |
| 255 | OptionDefault["value"] = cfg.default_interval | |
| 256 | OptionCtrl["value"] = cfg.ctrl_interval | |
| 257 | OptionShift["value"] = cfg.shift_interval | |
| 258 | OptionCtrlShift["value"] = cfg.ctrlShift_interval | |
| 259 | OptionShield["value"] = cfg.shield | |
| 260 | ||
| 261 | local flux = {}
| |
| 262 | flux["up"] = | |
| 263 | {
| |
| 264 | ["adr"] = nil, | |
| 265 | ["x"] = nil, | |
| 266 | ["y"] = nil | |
| 267 | } | |
| 268 | flux["down"] = | |
| 269 | {
| |
| 270 | ["adr"] = nil, | |
| 271 | ["x"] = nil, | |
| 272 | ["y"] = nil | |
| 273 | } | |
| 274 | ||
| 275 | local infcord = | |
| 276 | {
| |
| 277 | ["status"] = | |
| 278 | {
| |
| 279 | ["value"] = nil, | |
| 280 | ["x"] = nil, | |
| 281 | ["y"] = nil | |
| 282 | }, | |
| 283 | ["temp"] = | |
| 284 | {
| |
| 285 | ["value"] = nil, | |
| 286 | ["x"] = nil, | |
| 287 | ["y"] = nil | |
| 288 | }, | |
| 289 | ["generation"] = | |
| 290 | {
| |
| 291 | ["value"] = nil, | |
| 292 | ["x"] = nil, | |
| 293 | ["y"] = nil | |
| 294 | }, | |
| 295 | ["flow"] = | |
| 296 | {
| |
| 297 | ["value"] = nil, | |
| 298 | ["x"] = nil, | |
| 299 | ["y"] = nil | |
| 300 | }, | |
| 301 | ["puregen"] = | |
| 302 | {
| |
| 303 | ["value"] = nil, | |
| 304 | ["x"] = nil, | |
| 305 | ["y"] = nil | |
| 306 | }, | |
| 307 | ["drain"] = | |
| 308 | {
| |
| 309 | ["value"] = nil, | |
| 310 | ["x"] = nil, | |
| 311 | ["y"] = nil | |
| 312 | }, | |
| 313 | ["fstrth"] = | |
| 314 | {
| |
| 315 | ["value"] = nil, | |
| 316 | ["x"] = nil, | |
| 317 | ["y"] = nil | |
| 318 | }, | |
| 319 | ["esturn"] = | |
| 320 | {
| |
| 321 | ["value"] = nil, | |
| 322 | ["x"] = nil, | |
| 323 | ["y"] = nil | |
| 324 | }, | |
| 325 | ["fuel"] = | |
| 326 | {
| |
| 327 | ["value"] = nil, | |
| 328 | ["x"] = nil, | |
| 329 | ["y"] = nil | |
| 330 | }, | |
| 331 | ["fuelconv"] = | |
| 332 | {
| |
| 333 | ["value"] = nil, | |
| 334 | ["x"] = nil, | |
| 335 | ["y"] = nil | |
| 336 | }, | |
| 337 | ["core"] = | |
| 338 | {
| |
| 339 | ["value"] = nil, | |
| 340 | ["x"] = nil, | |
| 341 | ["y"] = nil | |
| 342 | } | |
| 343 | } | |
| 344 | ||
| 345 | local button = | |
| 346 | {
| |
| 347 | ["continue"] = | |
| 348 | {
| |
| 349 | ["name"] = "Продолжить", | |
| 350 | ["x"] = nil, | |
| 351 | ["y"] = nil | |
| 352 | }, | |
| 353 | ["change"] = | |
| 354 | {
| |
| 355 | ["name"] = "Изменить", | |
| 356 | ["x"] = nil, | |
| 357 | ["y"] = nil | |
| 358 | }, | |
| 359 | ["add"] = | |
| 360 | {
| |
| 361 | ["name"] = " + ", | |
| 362 | ["x"] = nil, | |
| 363 | ["y"] = nil | |
| 364 | }, | |
| 365 | ["sub"] = | |
| 366 | {
| |
| 367 | ["name"] = " - ", | |
| 368 | ["x"] = nil, | |
| 369 | ["y"] = nil | |
| 370 | }, | |
| 371 | ["start"] = | |
| 372 | {
| |
| 373 | ["name"] = "Запустить реактор", | |
| 374 | ["x"] = nil, | |
| 375 | ["y"] = nil, | |
| 376 | ["visible"] = nil | |
| 377 | }, | |
| 378 | ["stop"] = | |
| 379 | {
| |
| 380 | ["name"] = "Выключить реактор", | |
| 381 | ["x"] = nil, | |
| 382 | ["y"] = nil, | |
| 383 | ["visible"] = nil | |
| 384 | }, | |
| 385 | ["charge"] = | |
| 386 | {
| |
| 387 | ["name"] = "Зарядить реактор ", | |
| 388 | ["x"] = nil, | |
| 389 | ["y"] = nil, | |
| 390 | ["visible"] = nil | |
| 391 | }, | |
| 392 | ["autoon"] = | |
| 393 | {
| |
| 394 | ["name"] = "Включен", | |
| 395 | ["x"] = nil, | |
| 396 | ["y"] = nil, | |
| 397 | }, | |
| 398 | ["autooff"] = | |
| 399 | {
| |
| 400 | ["name"] = "Выключен", | |
| 401 | ["x"] = nil, | |
| 402 | ["y"] = nil, | |
| 403 | } | |
| 404 | } | |
| 405 | ||
| 406 | local ops = true | |
| 407 | local upchoose = true | |
| 408 | local downchoose = true | |
| 409 | local conf = false | |
| 410 | local buts = false | |
| 411 | local canedit = true | |
| 412 | local canclose = true | |
| 413 | local temprise | |
| 414 | local autostate = false | |
| 415 | ||
| 416 | local upadr = nil | |
| 417 | local downadr = nil | |
| 418 | ||
| 419 | printf = function (s,...) | |
| 420 | return io.write(s:format(...)) | |
| 421 | end | |
| 422 | ||
| 423 | local function guiWrite(x,y,cf,cb,s,...) | |
| 424 | term.setCursor(x,y) | |
| 425 | if cf >=0 and cb >=0 then | |
| 426 | local fg = gpu.getForeground() | |
| 427 | local bg = gpu.getBackground() | |
| 428 | gpu.setForeground(cf) | |
| 429 | gpu.setBackground(cb) | |
| 430 | printf(s,...) | |
| 431 | gpu.setForeground(fg) | |
| 432 | gpu.setBackground(bg) | |
| 433 | elseif cb <0 and cf>=0 then | |
| 434 | local fg = gpu.getForeground() | |
| 435 | gpu.setForeground(cf) | |
| 436 | printf(s,...) | |
| 437 | gpu.setForeground(fg) | |
| 438 | elseif cf < 0 and cb >= 0 then | |
| 439 | local bg = gpu.getBackground() | |
| 440 | printf(s,...) | |
| 441 | gpu.setBackground(bg) | |
| 442 | else | |
| 443 | printf(s,...) | |
| 444 | end | |
| 445 | end | |
| 446 | ||
| 447 | local function getCord(param) | |
| 448 | param.x,param.y = term.getCursor() | |
| 449 | return param.x,param.y | |
| 450 | end | |
| 451 | ||
| 452 | local function guiClear(y) | |
| 453 | local fg = gpu.getForeground() | |
| 454 | local bg = gpu.getBackground() | |
| 455 | gpu.setForeground(color.black) | |
| 456 | gpu.setBackground(color.grey) | |
| 457 | for i=y+3,3,-1 do | |
| 458 | term.setCursor(1,i) | |
| 459 | term.clearLine() | |
| 460 | end | |
| 461 | gpu.setForeground(fg) | |
| 462 | gpu.setBackground(bg) | |
| 463 | end | |
| 464 | ||
| 465 | local function makeButton(x,y,text) | |
| 466 | term.setCursor(x,y) | |
| 467 | local fg = gpu.getForeground() | |
| 468 | local bg = gpu.getBackground() | |
| 469 | gpu.setBackground(0x000000) | |
| 470 | gpu.setForeground(0xFFFFFF) | |
| 471 | printf(text) | |
| 472 | gpu.setBackground(bg) | |
| 473 | gpu.setForeground(fg) | |
| 474 | ||
| 475 | end | |
| 476 | ||
| 477 | local function show(fc,bc,param) | |
| 478 | local fg = gpu.getForeground() | |
| 479 | local bg = gpu.getBackground() | |
| 480 | term.setCursor(param.x,param.y) | |
| 481 | gpu.setForeground(fc) | |
| 482 | gpu.setBackground(bc) | |
| 483 | local st = " " | |
| 484 | for i = 0,#tostring(param.value) do | |
| 485 | st=st.." " | |
| 486 | end | |
| 487 | gpu.set(param.x,param.y,st) | |
| 488 | printf("%d",param.value)
| |
| 489 | gpu.setForeground(fg) | |
| 490 | gpu.setBackground(bg) | |
| 491 | end | |
| 492 | ||
| 493 | local function numformat(n) | |
| 494 | local s = tostring(n) | |
| 495 | if n >= 1000 and n < 1000000 then | |
| 496 | local t = s:sub(1,#s-3) | |
| 497 | local e = s:sub(#s-2) | |
| 498 | s = t.." "..e.." " | |
| 499 | return s | |
| 500 | elseif n >= 1000000 then | |
| 501 | local m = s:sub(1,#s-6) | |
| 502 | local t = s:sub(#s-5,#s-3) | |
| 503 | local e = s:sub(#s-2) | |
| 504 | s = m.." "..t.." "..e.." " | |
| 505 | return s | |
| 506 | else | |
| 507 | s=s.." " | |
| 508 | return s | |
| 509 | end | |
| 510 | end | |
| 511 | ||
| 512 | local function coreformat() | |
| 513 | local num = com.draconic_rf_storage.getEnergyStored() | |
| 514 | if num > 10^12 then | |
| 515 | return string.format(" Накоплено в ядре: %0.3f T \n",num/10^12)
| |
| 516 | elseif num > 10^9 then | |
| 517 | return string.format(" Накоплено в ядре: %0.3f B \n",num/10^9)
| |
| 518 | elseif num > 10^6 then | |
| 519 | return string.format(" Накоплено в ядре: %0.3f M \n",num/10^6)
| |
| 520 | elseif num > 10^3 then | |
| 521 | return string.format(" Накоплено в ядре: %0.3f K \n",num/10^3)
| |
| 522 | else | |
| 523 | return string.format(" Накоплено в ядре: %d \n",num)
| |
| 524 | end | |
| 525 | end | |
| 526 | ||
| 527 | -- Анализ и корректировка запомненных адресов | |
| 528 | local function proxyCheck() | |
| 529 | flux.up.adr,flux.down.adr = fileRead(fileName) | |
| 530 | if flux.up.adr ~= nil and flux.down.adr ~= nil then | |
| 531 | if com.get(flux.up.adr) ~= nil and com.get(flux.down.adr) ~=nil then | |
| 532 | return true | |
| 533 | elseif com.get(flux.up.adr) == nil and com.get(flux.down.adr) == nil then | |
| 534 | flux.up.adr = nil | |
| 535 | flux.down.adr = nil | |
| 536 | return false | |
| 537 | elseif com.get(flux.up.adr) == nil then | |
| 538 | for adrs in com.list("flux_gate") do
| |
| 539 | if adrs ~= flux.down.adr then | |
| 540 | flux.up.adr = adrs | |
| 541 | end | |
| 542 | end | |
| 543 | fileWrite(fileName,flux.up.adr,flux.down.adr) | |
| 544 | return true | |
| 545 | elseif com.get(flux.down.adr) == nil then | |
| 546 | for adrs in com.list("flux_gate") do
| |
| 547 | if adrs ~= flux.up.adr then | |
| 548 | flux.down.adr = adrs | |
| 549 | end | |
| 550 | end | |
| 551 | fileWrite(fileName,flux.up.adr,flux.down.adr) | |
| 552 | return true | |
| 553 | end | |
| 554 | end | |
| 555 | end | |
| 556 | ||
| 557 | local function checkButtons() | |
| 558 | local inf = reactor.getReactorInfo() | |
| 559 | infcord.status.value = inf.status | |
| 560 | if infcord.status.value == "offline" then | |
| 561 | guiWrite(button.charge.x,button.charge.y,color.skyblue,color.black,"%s",button.charge.name) | |
| 562 | button.charge.visible = true | |
| 563 | elseif infcord.status.value == "stopping" then | |
| 564 | if (inf.energySaturation/inf.maxEnergySaturation)*100 >=50 and (inf.fieldStrength/inf.maxFieldStrength)*100 >= 50 and inf.temperature > 2000 then | |
| 565 | guiWrite(button.start.x,button.start.y,color.green,color.black,"%s",button.start.name) | |
| 566 | button.start.visible = true | |
| 567 | elseif infcord.status.value ~= "charging" then | |
| 568 | guiWrite(button.charge.x,button.charge.y,color.skyblue,color.black,"%s",button.charge.name) | |
| 569 | button.charge.visible = true | |
| 570 | end | |
| 571 | elseif infcord.status.value == "online" or infcord.status.value == "charging" then | |
| 572 | guiWrite(button.stop.x,button.stop.y,color.red,color.black,"%s",button.stop.name) | |
| 573 | button.stop.visible = true | |
| 574 | elseif infcord.status.value == "charged" then | |
| 575 | guiWrite(button.start.x,button.start.y,color.green,color.black,"%s",button.start.name) | |
| 576 | button.start.visible = true | |
| 577 | guiWrite(button.stop.x,button.stop.y,color.red,color.black,"%s",button.stop.name) | |
| 578 | button.stop.visible = true | |
| 579 | end | |
| 580 | end | |
| 581 | -- Инициализация программы, анализ и настройка всей технической белеберды | |
| 582 | local function screenStart() | |
| 583 | handleMain = false | |
| 584 | handleOptions = false | |
| 585 | handleStart = true | |
| 586 | local x,y = gpu.getResolution() | |
| 587 | gpu.setBackground(0xC0C0C0) | |
| 588 | gpu.setForeground(0x000000) | |
| 589 | term.clear() | |
| 590 | gpu.setBackground(0x000080) | |
| 591 | gpu.setForeground(0xFFFFFF) | |
| 592 | term.clearLine() | |
| 593 | printf("Draconic reactor control made by Freeazzy from McSkill.ru (Preparation)\n")
| |
| 594 | gpu.setBackground(0xFFFFFF) | |
| 595 | gpu.setForeground(0x000000) | |
| 596 | term.clearLine() | |
| 597 | printf("Это страница для настройки программы при первом запуске или после сбоя")
| |
| 598 | gpu.setBackground(0xFF0000) | |
| 599 | gpu.set(x-2,1," X ") | |
| 600 | gpu.setBackground(0xC0C0C0) | |
| 601 | term.setCursor(1,4) | |
| 602 | if not com.isAvailable("draconic_reactor") then
| |
| 603 | printf("подключите адаптер к стабилизатору реактора")
| |
| 604 | while not com.isAvailable("draconic_reactor") do
| |
| 605 | os.sleep(0) | |
| 606 | if not ops then return end | |
| 607 | end | |
| 608 | guiClear(2) | |
| 609 | end | |
| 610 | reactor = com.draconic_reactor | |
| 611 | local i = 0 | |
| 612 | for address in com.list("flux_gate") do
| |
| 613 | i=i+1 | |
| 614 | end | |
| 615 | if i<2 then | |
| 616 | printf("Подключите адаптеры к обоим флюкс-гейтам")
| |
| 617 | ||
| 618 | while true do | |
| 619 | if not ops then return end | |
| 620 | i=0 | |
| 621 | for address in com.list("flux_gate") do
| |
| 622 | i=i+1 | |
| 623 | end | |
| 624 | if i == 2 then | |
| 625 | break | |
| 626 | end | |
| 627 | os.sleep(0) | |
| 628 | end | |
| 629 | guiClear(2) | |
| 630 | end | |
| 631 | proxyCheck() | |
| 632 | if flux.up.adr == nil or flux.down.adr == nil then | |
| 633 | while not conf do | |
| 634 | buts = false | |
| 635 | if not ops then return end | |
| 636 | i=1 | |
| 637 | flux[1]= | |
| 638 | {
| |
| 639 | ["adr"]=nil, | |
| 640 | ["x"]=nil, | |
| 641 | ["y"]=nil | |
| 642 | } | |
| 643 | flux[2]= | |
| 644 | {
| |
| 645 | ["adr"]=nil, | |
| 646 | ["x"]=nil, | |
| 647 | ["y"]=nil | |
| 648 | } | |
| 649 | printf(" Адреса подключенных флюкс-гейтов\n\n")
| |
| 650 | for adr in com.list("flux_gate") do
| |
| 651 | flux[i].x,flux[i].y = term.getCursor() | |
| 652 | flux[i].adr = adr | |
| 653 | printf (" "..flux[i].adr.."\n\n")
| |
| 654 | i=i+1 | |
| 655 | end | |
| 656 | printf(" Выберите адрес флюкс-гейта, отвечающего за выработку энергии\n")
| |
| 657 | ||
| 658 | while upchoose do | |
| 659 | os.sleep(0) | |
| 660 | if not ops then return end | |
| 661 | end | |
| 662 | printf(" Выберите адрес флюкс-гейта, отвечающего за стабилизацию реактора\n")
| |
| 663 | ||
| 664 | while downchoose do | |
| 665 | os.sleep(0) | |
| 666 | if not ops then return end | |
| 667 | end | |
| 668 | printf("\n адрес энергетического гейта : %s\n",flux.up.adr)
| |
| 669 | printf(" адрес стабилизирующего гейта : %s\n",flux.down.adr)
| |
| 670 | ||
| 671 | if reactor.getReactorInfo().status == "offline" then | |
| 672 | com.proxy(com.get(flux.up.adr)).setSignalHighFlow(0) | |
| 673 | com.proxy(com.get(flux.up.adr)).setSignalLowFlow(535000) | |
| 674 | com.proxy(com.get(flux.down.adr)).setOverrideEnabled(true) | |
| 675 | end | |
| 676 | ||
| 677 | button.continue.x,button.continue.y = term.getCursor() | |
| 678 | makeButton(button.continue.x+8,button.continue.y+1,button.continue.name) | |
| 679 | button.change.x,button.change.y = term.getCursor() | |
| 680 | makeButton(button.change.x+2,button.change.y,button.change.name) | |
| 681 | while not buts do | |
| 682 | os.sleep(0) | |
| 683 | if not ops then return end | |
| 684 | end | |
| 685 | if flux.up.adr ~= nil and flux.down.adr ~= nil then | |
| 686 | upgate = com.proxy(com.get(flux.up.adr)) | |
| 687 | downgate = com.proxy(com.get(flux.down.adr)) | |
| 688 | fileWrite(fileName,flux.up.adr,flux.down.adr) | |
| 689 | end | |
| 690 | end | |
| 691 | else | |
| 692 | upgate = com.proxy(com.get(flux.up.adr)) | |
| 693 | downgate = com.proxy(com.get(flux.down.adr)) | |
| 694 | end | |
| 695 | ||
| 696 | end | |
| 697 | -- Экран настроек | |
| 698 | local function screenOptions() | |
| 699 | handleMain = false | |
| 700 | handleStart = false | |
| 701 | handleOptions = true | |
| 702 | local x,y = gpu.getResolution() | |
| 703 | gpu.setBackground(0xC0C0C0) | |
| 704 | gpu.setForeground(0x000000) | |
| 705 | term.clear() | |
| 706 | gpu.setBackground(0x000080) | |
| 707 | gpu.setForeground(0xFFFFFF) | |
| 708 | term.clearLine() | |
| 709 | printf("Draconic reactor control made by Freeazzy from McSkill.ru (Options)\n")
| |
| 710 | gpu.setBackground(0xFFFFFF) | |
| 711 | gpu.setForeground(0x000000) | |
| 712 | term.clearLine() | |
| 713 | menuItem.save.x,menuItem.save.y =term.getCursor() | |
| 714 | printf(menuItem.save.name) | |
| 715 | menuItem.cancel.x,menuItem.cancel.y =term.getCursor() | |
| 716 | printf(menuItem.cancel.name) | |
| 717 | gpu.setBackground(0xFF0000) | |
| 718 | gpu.set(x-2,1," X ") | |
| 719 | gpu.setBackground(0xC0C0C0) | |
| 720 | term.setCursor(1,4) | |
| 721 | printf(" Интервал для щелчка: ")
| |
| 722 | OptionDefault["x"],OptionDefault["y"] = term.getCursor() | |
| 723 | printf("%d\n",OptionDefault.value)
| |
| 724 | printf(" Интервал для CTRL: ")
| |
| 725 | OptionCtrl["x"],OptionCtrl["y"] = term.getCursor() | |
| 726 | printf("%d\n",OptionCtrl.value)
| |
| 727 | printf(" Интервал для SHIFT: ")
| |
| 728 | OptionShift["x"],OptionShift["y"] = term.getCursor() | |
| 729 | printf("%d\n",OptionShift.value)
| |
| 730 | printf(" Интервал для CTRL+SHIFT: ")
| |
| 731 | OptionCtrlShift["x"],OptionCtrlShift["y"] = term.getCursor() | |
| 732 | printf("%d\n",OptionCtrlShift.value)
| |
| 733 | printf(" Уровень щитов: ")
| |
| 734 | OptionShield["x"],OptionShield["y"] = term.getCursor() | |
| 735 | printf("%d\n",OptionShield.value)
| |
| 736 | end | |
| 737 | -- Инициализация главного экрана | |
| 738 | local function screenMain() | |
| 739 | handleOptions = false | |
| 740 | handleStart = false | |
| 741 | handleMain = true | |
| 742 | local x,y = gpu.getResolution() | |
| 743 | local inf = reactor.getReactorInfo() | |
| 744 | infcord.status.value = inf.status | |
| 745 | gpu.setBackground(0xC0C0C0) | |
| 746 | gpu.setForeground(0x000000) | |
| 747 | term.clear() | |
| 748 | gpu.setBackground(0x000080) | |
| 749 | gpu.setForeground(0xFFFFFF) | |
| 750 | term.clearLine() | |
| 751 | printf("Draconic reactor control made by Freeazzy from McSkill.ru\n")
| |
| 752 | gpu.setBackground(0xFFFFFF) | |
| 753 | gpu.setForeground(0x000000) | |
| 754 | term.clearLine() | |
| 755 | menuItem.options.x,menuItem.options.y =term.getCursor() | |
| 756 | printf(menuItem.options.name) | |
| 757 | gpu.setBackground(0xFF0000) | |
| 758 | gpu.set(x-2,1," X ") | |
| 759 | gpu.setBackground(0xC0C0C0) | |
| 760 | term.setCursor(1,4) | |
| 761 | gpu.setBackground(0x909090) | |
| 762 | printf(" Температура: ")
| |
| 763 | gpu.setBackground(0xC0C0C0) | |
| 764 | printf(" ")
| |
| 765 | getCord(infcord.temp) | |
| 766 | guiWrite(infcord.temp.x,infcord.temp.y,-1,-1,"%0.2f\n",inf.temperature) | |
| 767 | printf(" Вырабатывает: ")
| |
| 768 | getCord(infcord.generation) | |
| 769 | guiWrite(infcord.generation.x,infcord.generation.y,-1,-1,"%s \n",numformat(inf.generationRate)) | |
| 770 | gpu.setBackground(0x909090) | |
| 771 | printf (" Поток: ")
| |
| 772 | gpu.setBackground(0xC0C0C0) | |
| 773 | printf(" ")
| |
| 774 | getCord(infcord.flow) | |
| 775 | infcord.flow.value = upgate.getFlow() | |
| 776 | guiWrite(infcord.flow.x,infcord.flow.y,-1,-1,"%s ",numformat(infcord.flow.value)) | |
| 777 | getCord(button.add) | |
| 778 | makeButton(button.add.x + 4, button.add.y ,button.add.name) | |
| 779 | getCord(button.sub) | |
| 780 | makeButton(button.sub.x+2,button.sub.y,button.sub.name) | |
| 781 | ||
| 782 | printf("\n")
| |
| 783 | printf (" Итоговая мосч: ")
| |
| 784 | getCord(infcord.puregen) | |
| 785 | guiWrite(infcord.puregen.x,infcord.puregen.y,-1,-1,"%s \n",numformat(inf.generationRate - downgate.getFlow())) | |
| 786 | gpu.setBackground(0x909090) | |
| 787 | printf (" Поглощает: ")
| |
| 788 | gpu.setBackground(0xC0C0C0) | |
| 789 | printf(" ")
| |
| 790 | getCord(infcord.drain) | |
| 791 | guiWrite(infcord.drain.x,infcord.drain.y,-1,-1,"%s \n",numformat(downgate.getFlow())) | |
| 792 | ||
| 793 | printf (" Мощность поля: ")
| |
| 794 | getCord(infcord.fstrth) | |
| 795 | if inf.maxFieldStrength > 0 then | |
| 796 | guiWrite(infcord.fstrth.x,infcord.fstrth.y,-1,-1,"%d / %d (%0.2f %%) \n",inf.fieldStrength -inf.fieldDrainRate,inf.maxFieldStrength,((inf.fieldStrength-inf.fieldDrainRate)/inf.maxFieldStrength)*100) | |
| 797 | else | |
| 798 | guiWrite(infcord.fstrth.x,infcord.fstrth.y,-1,-1,"0 / 0 (0 %%) \n") | |
| 799 | end | |
| 800 | gpu.setBackground(0x909090) | |
| 801 | printf (" Насыщенность: ")
| |
| 802 | gpu.setBackground(0xC0C0C0) | |
| 803 | printf(" ")
| |
| 804 | getCord(infcord.esturn) | |
| 805 | if inf.maxEnergySaturation > 0 then | |
| 806 | guiWrite(infcord.esturn.x,infcord.esturn.y,-1,-1,"%d / %d (%0.2f %%) \n",inf.energySaturation,inf.maxEnergySaturation,(inf.energySaturation/inf.maxEnergySaturation)*100) | |
| 807 | else | |
| 808 | guiWrite(infcord.esturn.x,infcord.esturn.y,-1,-1,"0 / 0 (0 %%) \n") | |
| 809 | end | |
| 810 | printf (" топливо: ")
| |
| 811 | getCord(infcord.fuel) | |
| 812 | ||
| 813 | if inf.fuelConversion/inf.maxFuelConversion < 0.78 then | |
| 814 | guiWrite(infcord.fuel.x,infcord.fuel.y,-1,-1,"%d / %d (%0.2f %%) \n",inf.fuelConversion,inf.maxFuelConversion,(inf.fuelConversion/inf.maxFuelConversion)*100) | |
| 815 | else | |
| 816 | if inf.maxFuelConversion > 0 then | |
| 817 | if inf.status == "online" or inf.status == "charging" or inf.status == "charged" then | |
| 818 | guiWrite(infcord.fuel.x,infcord.fuel.y,color.red,-1,"%d / %d (%0.2f %%) Критический уровень топлива\n",inf.fuelConversion,inf.maxFuelConversion,(inf.fuelConversion/inf.maxFuelConversion)*100) | |
| 819 | else | |
| 820 | guiWrite(infcord.fuel.x,infcord.fuel.y,-1,-1,"%d / %d (%0.2f %%) Критический уровень топлива\n",inf.fuelConversion,inf.maxFuelConversion,(inf.fuelConversion/inf.maxFuelConversion)*100) | |
| 821 | end | |
| 822 | else | |
| 823 | guiWrite(infcord.fuel.x,infcord.fuel.y,-1,-1,"0 / 0 (0 %%) \n") | |
| 824 | end | |
| 825 | end | |
| 826 | gpu.setBackground(0x909090) | |
| 827 | printf (" расход топлива: ")
| |
| 828 | gpu.setBackground(0xC0C0C0) | |
| 829 | printf(" ")
| |
| 830 | getCord(infcord.fuelconv) | |
| 831 | guiWrite(infcord.fuelconv.x,infcord.fuelconv.y,-1,-1,"%d\n",inf.fuelConversionRate) | |
| 832 | ||
| 833 | getCord(infcord.core) | |
| 834 | if com.isAvailable("draconic_rf_storage") then
| |
| 835 | guiWrite(infcord.core.x,infcord.core.y,-1,-1,coreformat()) | |
| 836 | end | |
| 837 | printf("\n")
| |
| 838 | getCord(button.stop) | |
| 839 | getCord(button.start) | |
| 840 | getCord(button.charge) | |
| 841 | button.start.y = button.stop.y+2 | |
| 842 | button.charge.y = button.stop.y +2 | |
| 843 | printf(" Автономный режим: ")
| |
| 844 | getCord(button.autoon) | |
| 845 | getCord(button.autooff) | |
| 846 | if not autostate then | |
| 847 | guiWrite(button.autooff.x,button.autooff.y,color.red,color.black,"%s\n",button.autooff.name) | |
| 848 | else | |
| 849 | guiWrite(button.autoon.x,button.autoon.y,color.green,color.black,"%s\n",button.autoon.name) | |
| 850 | end | |
| 851 | checkButtons() | |
| 852 | ||
| 853 | end | |
| 854 | local screen = {}
| |
| 855 | screen["main"] = screenMain | |
| 856 | screen["options"] = screenOptions | |
| 857 | ||
| 858 | local function editOption(param) | |
| 859 | local rd = true | |
| 860 | while rd do | |
| 861 | gpu.fill(param.x, param.y, #tostring(param.value), 1, " ") | |
| 862 | term.setCursor(param.x,param.y) | |
| 863 | ||
| 864 | param.value = term.read(false,false) | |
| 865 | local val = tonumber(param.value) | |
| 866 | if val then | |
| 867 | show(color.black,color.grey,param) | |
| 868 | rd = false | |
| 869 | end | |
| 870 | end | |
| 871 | canedit = true | |
| 872 | canclose = true | |
| 873 | screen.options() | |
| 874 | end | |
| 875 | ||
| 876 | local function add(n,i) | |
| 877 | n.value=n.value+i | |
| 878 | upgate.setSignalLowFlow(n.value) | |
| 879 | return n.value | |
| 880 | end | |
| 881 | ||
| 882 | local function sub(n,i) | |
| 883 | term.setCursor(n.x,n.y) | |
| 884 | n.value=n.value-i | |
| 885 | return n.value | |
| 886 | end | |
| 887 | -- Обновление информации на экране + анализ поведения температуры | |
| 888 | local function refreshInfo() | |
| 889 | local inf = reactor.getReactorInfo() | |
| 890 | infcord.status.value = inf.status | |
| 891 | local tbuf1 = inf.temperature | |
| 892 | os.sleep(0.1) | |
| 893 | local tbuf2 = reactor.getReactorInfo().temperature | |
| 894 | if handleMain then | |
| 895 | if tbuf2>tbuf1 then | |
| 896 | guiWrite(infcord.temp.x,infcord.temp.y,color.red,-1,"%0.2f \n",inf.temperature) | |
| 897 | temprise = true | |
| 898 | elseif tbuf2<tbuf1 then | |
| 899 | guiWrite(infcord.temp.x,infcord.temp.y,color.blue,-1,"%0.2f \n",inf.temperature) | |
| 900 | temprise = false | |
| 901 | else | |
| 902 | if inf.temperature == 2000 then | |
| 903 | guiWrite(infcord.temp.x,infcord.temp.y,-1,-1,"%0.2f \n",inf.temperature) | |
| 904 | end | |
| 905 | end | |
| 906 | guiWrite(infcord.generation.x,infcord.generation.y,-1,-1,"%s\n",numformat(inf.generationRate)) | |
| 907 | infcord.flow.value = upgate.getFlow() | |
| 908 | guiWrite(infcord.flow.x,infcord.flow.y,-1,-1,"%s",numformat(infcord.flow.value)) | |
| 909 | guiWrite(infcord.puregen.x,infcord.puregen.y,-1,-1,"%s\n",numformat(inf.generationRate - downgate.getFlow())) | |
| 910 | infcord.drain.value = inf.fieldDrainRate | |
| 911 | guiWrite(infcord.drain.x,infcord.drain.y,-1,-1,"%s\n",numformat(downgate.getFlow())) | |
| 912 | if inf.maxFieldStrength > 0 then | |
| 913 | guiWrite(infcord.fstrth.x,infcord.fstrth.y,-1,-1,"%d / %d (%0.2f %%) \n",inf.fieldStrength-inf.fieldDrainRate,inf.maxFieldStrength,((inf.fieldStrength-inf.fieldDrainRate)/inf.maxFieldStrength)*100) | |
| 914 | else | |
| 915 | guiWrite(infcord.fstrth.x,infcord.fstrth.y,-1,-1,"0 / 0 (0 %%) \n") | |
| 916 | end | |
| 917 | if inf.maxEnergySaturation > 0 then | |
| 918 | guiWrite(infcord.esturn.x,infcord.esturn.y,-1,-1,"%d / %d (%0.2f %%) \n",inf.energySaturation,inf.maxEnergySaturation,(inf.energySaturation/inf.maxEnergySaturation)*100) | |
| 919 | else | |
| 920 | guiWrite(infcord.esturn.x,infcord.esturn.y,-1,-1,"0 / 0 (0 %%) \n") | |
| 921 | end | |
| 922 | if inf.fuelConversion/inf.maxFuelConversion < 0.78 then | |
| 923 | guiWrite(infcord.fuel.x,infcord.fuel.y,-1,-1,"%d / %d (%0.2f %%) \n",inf.fuelConversion,inf.maxFuelConversion,(inf.fuelConversion/inf.maxFuelConversion)*100) | |
| 924 | else | |
| 925 | if inf.maxFuelConversion > 0 then | |
| 926 | if inf.status == "online" or inf.status == "charging" or inf.status == "charged" then | |
| 927 | guiWrite(infcord.fuel.x,infcord.fuel.y,color.red,-1,"%d / %d (%0.2f %%) Критический уровень топлива\n",inf.fuelConversion,inf.maxFuelConversion,(inf.fuelConversion/inf.maxFuelConversion)*100) | |
| 928 | else | |
| 929 | guiWrite(infcord.fuel.x,infcord.fuel.y,-1,-1,"%d / %d (%0.2f %%) Критический уровень топлива\n",inf.fuelConversion,inf.maxFuelConversion,(inf.fuelConversion/inf.maxFuelConversion)*100) | |
| 930 | end | |
| 931 | else | |
| 932 | guiWrite(infcord.fuel.x,infcord.fuel.y,-1,-1,"0 / 0 (0 %%)\n") | |
| 933 | end | |
| 934 | end | |
| 935 | guiWrite(infcord.fuelconv.x,infcord.fuelconv.y,-1,-1,"%d\n",inf.fuelConversionRate) | |
| 936 | com.proxy(com.get(flux.down.adr)) | |
| 937 | if com.isAvailable("draconic_rf_storage") then
| |
| 938 | guiWrite(infcord.core.x,infcord.core.y,-1,-1,coreformat()) | |
| 939 | if button.stop.y ~= infcord.core.y + 2 then | |
| 940 | screenMain() | |
| 941 | end | |
| 942 | elseif button.stop.y ~= infcord.fuelconv.y + 2 then | |
| 943 | screenMain() | |
| 944 | end | |
| 945 | checkButtons() | |
| 946 | end | |
| 947 | end | |
| 948 | -- Алгоритм автономного режима | |
| 949 | local waittemp | |
| 950 | local function auto(state) | |
| 951 | ||
| 952 | if state then | |
| 953 | local inf = reactor.getReactorInfo() | |
| 954 | downflow = inf.fieldDrainRate / (1 - (cfg.shield/100)) | |
| 955 | downgate.setOverrideEnabled(true) | |
| 956 | downgate.setFlowOverride(downflow) | |
| 957 | ||
| 958 | if inf.temperature < cfg.forceModeTempLowEdge then | |
| 959 | if infcord.flow.value - inf.generationRate <= cfg.forceModeStepCase then | |
| 960 | upgate.setSignalLowFlow(infcord.flow.value + cfg.forceModeStep) | |
| 961 | guiWrite(infcord.flow.x,infcord.flow.y,color.red,color.grey,"%s",numformat(infcord.flow.value)) | |
| 962 | end | |
| 963 | elseif infcord.flow.value - inf.generationRate <= cfg.safeModeStepCase and inf.temperature >= cfg.forceModeTempLowEdge then | |
| 964 | if not waittemp and not waitfield then | |
| 965 | upgate.setSignalLowFlow(upgate.getSignalLowFlow() + cfg.safemodeStep) | |
| 966 | guiWrite(infcord.flow.x,infcord.flow.y,color.red,color.grey,"%s",numformat(infcord.flow.value)) | |
| 967 | elseif inf.temperature < cfg.safeModeTempToWaitEdge then | |
| 968 | waittemp = false | |
| 969 | end | |
| 970 | ||
| 971 | elseif temprise and inf.temperature >= cfg.safeModeTempWaitEdge then | |
| 972 | if inf.temperature > cfg.safeModeTempWaitEdge then | |
| 973 | waittemp = true | |
| 974 | end | |
| 975 | if inf.temperature > cfg.tempCriticalEdge then | |
| 976 | upgate.setSignalLowFlow(inf.generationRate - 1000) | |
| 977 | end | |
| 978 | end | |
| 979 | else | |
| 980 | if infcord.status.value == "charging" then | |
| 981 | downflow = 900000 | |
| 982 | else | |
| 983 | downflow = infcord.drain.value / (1 - (cfg.shield/100)) | |
| 984 | end | |
| 985 | downgate.setOverrideEnabled(false) | |
| 986 | downgate.setSignalHighFlow(downflow) | |
| 987 | downgate.setSignalLowFlow(downflow) | |
| 988 | end | |
| 989 | end | |
| 990 | -- Обработчик событий | |
| 991 | local function tcall(type,scrnAdr,x,y,btn,player) | |
| 992 | local rx,ry = gpu.getResolution() | |
| 993 | --выход | |
| 994 | if x >= rx-2 and x<=rx and y == 1 then | |
| 995 | event.ignore("touch",tcall)
| |
| 996 | prog = false | |
| 997 | ops = false | |
| 998 | end | |
| 999 | -- Стартовый экран | |
| 1000 | if handleStart then | |
| 1001 | if x>=flux[1].x and x<= flux[1].x+#flux[1].adr-1 and y==flux[1].y and upchoose then | |
| 1002 | flux.up.adr = flux[1].adr | |
| 1003 | ||
| 1004 | upchoose = false | |
| 1005 | return | |
| 1006 | end | |
| 1007 | if x>=flux[2].x and x<= flux[2].x+#flux[2].adr-1 and y==flux[2].y and upchoose then | |
| 1008 | flux.up.adr= flux[2].adr | |
| 1009 | upchoose = false | |
| 1010 | return | |
| 1011 | end | |
| 1012 | ||
| 1013 | if x>=flux[1].x and x<= flux[1].x+#flux[1].adr-1 and y==flux[1].y and downchoose then | |
| 1014 | flux.down.adr = flux[1].adr | |
| 1015 | downchoose = false | |
| 1016 | return | |
| 1017 | end | |
| 1018 | if x>=flux[2].x and x<= flux[2].x+#flux[2].adr-1 and y==flux[2].y and downchoose then | |
| 1019 | flux.down.adr= flux[2].adr | |
| 1020 | downchoose = false | |
| 1021 | return | |
| 1022 | end | |
| 1023 | if x >= button.continue.x+8 and x <= button.continue.x+7+#button.continue.name/2 and y == button.continue.y+1 and flux.up.adr ~= nil and flux.down.adr ~= nil then | |
| 1024 | conf = true | |
| 1025 | buts = true | |
| 1026 | screenMain() | |
| 1027 | return | |
| 1028 | end | |
| 1029 | if x >= button.change.x+2 and x <= button.change.x+1+#button.change.name/2-1 and y == button.change.y and flux.up.adr ~= nil and flux.down.adr ~= nil then | |
| 1030 | conf = false | |
| 1031 | buts = true | |
| 1032 | com.proxy(com.get(flux.down.adr)).setOverrideEnabled(false) | |
| 1033 | flux.up.adr=nil | |
| 1034 | flux.down.adr=nil | |
| 1035 | upchoose = true | |
| 1036 | downchoose = true | |
| 1037 | guiClear(16) | |
| 1038 | return | |
| 1039 | end | |
| 1040 | end | |
| 1041 | -- Главный экран | |
| 1042 | if handleMain then | |
| 1043 | -- Увеличение | |
| 1044 | if x >= button.add.x+4 and x <= button.add.x+3+#button.add.name and y == button.add.y then | |
| 1045 | if keyb.isShiftDown() then | |
| 1046 | if keyb.isControlDown() then | |
| 1047 | upgate.setSignalLowFlow(add(infcord.flow,cfg.ctrlShift_interval)) | |
| 1048 | else | |
| 1049 | upgate.setSignalLowFlow(add(infcord.flow,cfg.shift_interval)) | |
| 1050 | end | |
| 1051 | else | |
| 1052 | if keyb.isControlDown() then | |
| 1053 | upgate.setSignalLowFlow(add(infcord.flow,cfg.ctrl_interval)) | |
| 1054 | else | |
| 1055 | upgate.setSignalLowFlow(add(infcord.flow,cfg.default_interval)) | |
| 1056 | end | |
| 1057 | end | |
| 1058 | guiWrite(infcord.flow.x,infcord.flow.y,color.red,color.grey,"%s",numformat(infcord.flow.value)) | |
| 1059 | end | |
| 1060 | --Уменьшение | |
| 1061 | if x >= button.sub.x+2 and x <= button.sub.x+1+#button.sub.name and y == button.sub.y then | |
| 1062 | if keyb.isShiftDown() then | |
| 1063 | if keyb.isControlDown() then | |
| 1064 | upgate.setSignalLowFlow(sub(infcord.flow,cfg.ctrlShift_interval)) | |
| 1065 | else | |
| 1066 | upgate.setSignalLowFlow(sub(infcord.flow,cfg.shift_interval)) | |
| 1067 | end | |
| 1068 | else | |
| 1069 | if keyb.isControlDown() then | |
| 1070 | upgate.setSignalLowFlow(sub(infcord.flow,cfg.ctrl_interval)) | |
| 1071 | else | |
| 1072 | upgate.setSignalLowFlow(sub(infcord.flow,cfg.default_interval)) | |
| 1073 | end | |
| 1074 | end | |
| 1075 | guiWrite(infcord.flow.x,infcord.flow.y,color.blue,color.grey,"%s",numformat(infcord.flow.value)) | |
| 1076 | end | |
| 1077 | ||
| 1078 | if not autostate then | |
| 1079 | if x >= button.autooff.x and x <= button.autooff.x+#button.autooff.name/2-1 and y == button.autooff.y then | |
| 1080 | gpu.set(button.autooff.x, button.autooff.y," ") | |
| 1081 | autostate = true | |
| 1082 | guiWrite(button.autoon.x,button.autoon.y,color.green,color.black,"%s\n",button.autoon.name) | |
| 1083 | end | |
| 1084 | else | |
| 1085 | if x >= button.autoon.x and x <= button.autoon.x+#button.autoon.name/2-1 and y == button.autoon.y then | |
| 1086 | gpu.set(button.autoon.x, button.autoon.y," ") | |
| 1087 | autostate = false | |
| 1088 | guiWrite(button.autooff.x,button.autooff.y,color.red,color.black,"%s\n",button.autooff.name) | |
| 1089 | end | |
| 1090 | end | |
| 1091 | if button.charge.visible then | |
| 1092 | if x >= button.charge.x and x <= button.charge.x+#button.charge.name/2 and y == button.charge.y then | |
| 1093 | reactor.chargeReactor() | |
| 1094 | guiWrite(button.charge.x,button.charge.y,-1,color.grey," ",button.charge.name) | |
| 1095 | button.charge.visible = false | |
| 1096 | end | |
| 1097 | end | |
| 1098 | if button.start.visible then | |
| 1099 | if x >= button.start.x and x <= button.start.x+#button.start.name/2-1 and y == button.start.y then | |
| 1100 | reactor.activateReactor() | |
| 1101 | guiWrite(button.start.x,button.start.y,-1,color.grey," ",button.start.name) | |
| 1102 | button.start.visible = false | |
| 1103 | end | |
| 1104 | end | |
| 1105 | if button.stop.visible then | |
| 1106 | if x >= button.stop.x and x <= button.stop.x+#button.stop.name/2-1 and y == button.stop.y then | |
| 1107 | reactor.stopReactor() | |
| 1108 | guiWrite(button.stop.x,button.stop.y,-1,color.grey," ",button.stop.name) | |
| 1109 | button.stop.visible = false | |
| 1110 | end | |
| 1111 | end | |
| 1112 | --меню | |
| 1113 | if x>= menuItem.options.x and x <= (menuItem.options.x + #menuItem.options.name/2-1) and y == menuItem.options.y then | |
| 1114 | screenOptions() | |
| 1115 | return | |
| 1116 | end | |
| 1117 | if x == 1 and y == 1 then | |
| 1118 | event.ignore("touch",tcall)
| |
| 1119 | prog = false | |
| 1120 | end | |
| 1121 | end | |
| 1122 | -- Экран настроек | |
| 1123 | if handleOptions then | |
| 1124 | -- Работа со значениями | |
| 1125 | if canedit then | |
| 1126 | if x >= OptionDefault.x and x <= OptionDefault.x + #tostring(OptionDefault.value)-1 and y == OptionDefault.y then | |
| 1127 | canclose = false | |
| 1128 | canedit = false | |
| 1129 | editOption(OptionDefault) | |
| 1130 | end | |
| 1131 | if x >= OptionCtrl.x and x <= OptionCtrl.x + #tostring(OptionCtrl.value)-1 and y == OptionCtrl.y then | |
| 1132 | canclose = false | |
| 1133 | canedit = false | |
| 1134 | editOption(OptionCtrl) | |
| 1135 | end | |
| 1136 | if x >= OptionShift.x and x <= OptionShift.x + #tostring(OptionShift.value)-1 and y == OptionShift.y then | |
| 1137 | canclose = false | |
| 1138 | canedit = false | |
| 1139 | editOption(OptionShift) | |
| 1140 | end | |
| 1141 | if x >= OptionCtrlShift.x and x <= OptionCtrlShift.x + #tostring(OptionCtrlShift.value)-1 and y == OptionCtrlShift.y then | |
| 1142 | canclose = false | |
| 1143 | canedit = false | |
| 1144 | editOption(OptionCtrlShift) | |
| 1145 | end | |
| 1146 | if x >= OptionShield.x and x <= OptionShield.x + #tostring(OptionShield.value)-1 and y == OptionShield.y then | |
| 1147 | canclose = false | |
| 1148 | canedit = false | |
| 1149 | editOption(OptionShield) | |
| 1150 | end | |
| 1151 | end | |
| 1152 | -- меню | |
| 1153 | if canclose then | |
| 1154 | if x>= menuItem.save.x and x <= (menuItem.save.x + #menuItem.save.name/2-1) and y == menuItem.save.y then | |
| 1155 | cfg.default_interval = OptionDefault.value | |
| 1156 | cfg.ctrl_interval = OptionCtrl.value | |
| 1157 | cfg.shift_interval = OptionShift.value | |
| 1158 | cfg.ctrlShift_interval = OptionCtrlShift.value | |
| 1159 | cfg.shield = OptionShield.value | |
| 1160 | configWrite(cfgName) | |
| 1161 | screenMain() | |
| 1162 | end | |
| 1163 | if x>= menuItem.cancel.x and x <= (menuItem.cancel.x + #menuItem.cancel.name/2-1) and y == menuItem.cancel.y then | |
| 1164 | OptionDefault.value = cfg.default_interval | |
| 1165 | OptionCtrl.value = cfg.ctrl_interval | |
| 1166 | OptionShift.value = cfg.shift_interval | |
| 1167 | OptionCtrlShift.value = cfg.ctrlShift_interval | |
| 1168 | OptionShield.value = cfg.ctrlShift_interval | |
| 1169 | screenMain() | |
| 1170 | return | |
| 1171 | end | |
| 1172 | end | |
| 1173 | end | |
| 1174 | end | |
| 1175 | ||
| 1176 | event.listen("touch",tcall)
| |
| 1177 | fileCreate(fileName) | |
| 1178 | flux.up.adr,flux.down.adr = fileRead(fileName) | |
| 1179 | screenStart() | |
| 1180 | if upgate ~= nil and downgate ~= nil then | |
| 1181 | screen.main() | |
| 1182 | end | |
| 1183 | while prog do | |
| 1184 | if not pcall(refreshInfo) then | |
| 1185 | autostate = false | |
| 1186 | if not pcall (screenStart) then | |
| 1187 | break | |
| 1188 | end | |
| 1189 | if not pcall(screenMain) then | |
| 1190 | screenStart() | |
| 1191 | if not pcall(screenMain) then | |
| 1192 | break | |
| 1193 | end | |
| 1194 | end | |
| 1195 | end | |
| 1196 | auto(autostate) | |
| 1197 | os.sleep(0) | |
| 1198 | end | |
| 1199 | gpu.setBackground(rback) | |
| 1200 | gpu.setForeground(rfore) | |
| 1201 | gpu.setResolution(xz,yz) | |
| 1202 | term.clear() |