View difference between Paste ID: VSB2smHM and SLKdWUcq
SHOW: | | - or go back to the newest paste.
1
local config = {
2
    -- maxCoreEnergy - на этом уровне будет поддерживаться количество энергии в ядре
3
    -- 1000 * 10^9 соответсвунт 1000 B или 1 T
4-
    maxCoreEnergy = 1000 * 10^9,
4+
    maxCoreEnergy = 100 * 10^9,
5
    maxDiffEnergy = 20000, -- максимальная скорость накапливания энергии Rf/t, тестировалось на этом значении
6
    step = 10000,  -- шаг изменния значения на гейте
7
    step2 = 50000, -- шаг на кнопку
8
    sleepTime = 0.1, -- шаг замеров в сек
9
}
10
 
11
 
12
local keyb = require("keyboard")
13
local event = require("event")
14
local term = require("term")
15
local unicode = require("unicode")
16
local com = require('component')
17
local gpu = com.gpu
18
local w, h = 80 , 25
19
20
21
gpu.setResolution(w, h) -- lvl 2
22
 
23
local function coreEnergy()
24
    return com.draconic_rf_storage.getEnergyStored()
25
end
26
 
27
local function format(num)
28
    if num >= 10^12 then
29
        return string.format("%0.3f T", num/10^12)
30
    elseif num >= 10^9 then
31
        return string.format("%0.3f B", num/10^9)
32
    elseif num >= 10^6 then
33
        return string.format("%0.3f M", num/10^6)
34
    elseif num >= 10^3 then
35
        return string.format("%0.3f K", num/10^3)
36
    else
37
        return string.format("%d", num)
38
    end
39
end
40
 
41
local filVal = 0
42
function expRunningAvg(newVal)
43
    filVal = filVal + ((newVal-filVal) * 0.3)
44
    return filVal
45
end
46
 
47
if false == com.isAvailable("draconic_rf_storage") then
48
    print("Rf storage not connected!")
49
    os.exit()
50
end
51
 
52
if false == com.isAvailable("flux_gate") then
53
    print("Flux gate not connected!")
54
    os.exit()
55
end
56
 
57
local time = os.time()
58
local energy = coreEnergy()
59
60
function asbMax(t)
61
    local  max = t[1]
62
    for _, val in ipairs(t) do
63
        if math.abs(val) > max then
64
            max = math.abs(val)
65
        end
66
    end
67
 
68
    return max
69
end
70
 
71
local _MID = h/2 + 3
72
local _NUM_READ = w
73
local energyLog = {}
74
local current = 0
75
 
76
function displayGraph(diff)
77
    current = current + 1
78
    if current > _NUM_READ then
79
        current = 1
80
    end
81
 
82
    energyLog[current] = diff
83
 
84
    local maxVal = asbMax(energyLog)
85
 
86
    gpu.fill(1, _MID, w, 1, '━')
87
    local row = 1
88
    for i = current, _NUM_READ + current - 1 do
89
        local key = i % w + 1
90
 
91
        if energyLog[key] then
92
            local d = (math.ceil(energyLog[key] / (maxVal * 0.1)))
93
            if d > 0 then
94
              gpu.setForeground(0x00ff00)
95
              gpu.fill(row, _MID-d, 1, d, '█')
96
            else
97
              gpu.setForeground(0xff0000)
98
              gpu.fill(row, _MID+1, 1, math.abs(d), '█')
99
              
100
            end
101
        end
102
        row = row + 1
103
    end
104
end
105
 
106
function displayData(core, diff, action, fluxGateFlow)
107
    gpu.fill(1, 1, w, h, " ")
108
    gpu.set(3, 1, string.format("Энергии в ядре: %s [%0.0f Rf]", format(core), core))
109
    gpu.set(3, 2, string.format("Выход на гейте: %s Rf [%0.0f Rf]  %s", format(fluxGateFlow), fluxGateFlow, action))
110
    gpu.set(3, 3, string.format('Накопление энергии: %0.1f Rf/t', diff))
111
    gpu.set(w - unicode.len("Поддерживание : "..format(config.maxCoreEnergy).." "), 1,string.format("Поддерживание : %s", format(config.maxCoreEnergy), config.maxCoreEnergy)) -- вывод поддерживание энергии by BG
112
    gpu.setBackground(0xFFFFFF) 
113
    gpu.setForeground(0x000000)
114
    gpu.set(73, 2, " + ")
115
    gpu.set(77, 2, " - ")
116
    gpu.setBackground(0x000000) 
117
    gpu.setForeground(0xFFFFFF)
118
    displayGraph(diff) 
119
end
120
121
 
122
local running = true
123
124
125
function touch (w, h)
126
  local StepButton = 10^9
127
  
128
  if keyb.isControlDown() then
129
      StepButton = 5 * 10^10
130
  elseif keyb.isShiftDown() then
131
      StepButton = 10^11
132
  end
133
  if w >= 73 and w <= 75 and h == 2 then
134
    config.maxCoreEnergy = config.maxCoreEnergy + StepButton
135
    gpu.setBackground(0x00FF00)
136
    gpu.set(73 , 2, " + ")
137
    gpu.setBackground(0x000000)
138
  elseif w >= 77 and w <= 79 and h == 2 then 
139
    config.maxCoreEnergy = config.maxCoreEnergy - StepButton
140
    gpu.setBackground(0xFF0000)
141
    gpu.set(77 , 2, " - ")
142
    gpu.setBackground(0x000000)
143
  
144
  end
145
end
146
147
while running do
148
    
149
    term.setCursor(1,1)
150
    gpu.setForeground(0xffffff)
151
    os.sleep(config.sleepTime)
152
 
153
    local tmpEnergy = coreEnergy()
154
    local tmpTime = os.time()
155
 
156
    local energyDiff = tmpEnergy - energy
157
    local timeDiff = tmpTime - time
158
 -- тут менять на умножить 3.5
159-
    local diff = expRunningAvg(energyDiff / timeDiff)
159+
    local diff = expRunningAvg(energyDiff / timeDiff) 
160
 
161
    local fluxGateFlow  = com.flux_gate.getFlow()
162
    
163
 
164
    local action = ""
165
    
166
    
167
 
168
    if tmpEnergy > config.maxCoreEnergy then 
169-
        if diff > (config.maxDiffEnergy * -1) then  -- не больше (and fluxGateFlow < 17000000) by BG
169+
        if diff > (config.maxDiffEnergy * -1) and
170
            fluxGateFlow < 17000000 then  -- не больше (and fluxGateFlow < 17000000) by BG
171
            action = 'Повышаю ▲'
172
            com.flux_gate.setSignalLowFlow(fluxGateFlow + config.step)
173
        end
174-
        if diff < config.maxDiffEnergy and fluxGateFlow > 10000 then
174+
175
        if diff < config.maxDiffEnergy and fluxGateFlow > 300000 then
176
            action = 'Понижаю ▼'
177
            com.flux_gate.setSignalLowFlow(fluxGateFlow - config.step)
178
        end
179
    end
180
    
181
    displayData(tmpEnergy, diff, action, fluxGateFlow)
182
    
183
    local e,_,w,h,_,_ = event.pull(0.1, "touch")
184
    if e == "touch" then
185
    touch(w, h)
186
    end
187
188
    time = tmpTime
189
    energy = tmpEnergy
190
end
191
192
--pastebin get SLKdWUcq gate.lua