Gintarus

Reactor_rev

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