forked from ShaeTsuPog/MekaControl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mekacontrol.lua
107 lines (91 loc) · 6.12 KB
/
mekacontrol.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
-- CREDITS TO: ShaeTsuPog
-- https://github.com/ShaeTsuPog/MekaControl/blob/main/mekacontrol.lua
-- trimmed by: wojtakbar ^-^
local rla = peripheral.find("fissionReactorLogicAdapter")
local boi = peripheral.find("boilerValve")
local trb = peripheral.find("turbineValve")
local ind = peripheral.find("inductionPort")
local mon = peripheral.find("monitor")
local scramCount = 0
local function regulator()
local coolant = math.ceil(rla.getCoolantFilledPercentage() * 100)
local heated = math.ceil(rla.getHeatedCoolantFilledPercentage() * 100)
local waste = math.ceil(rla.getWasteFilledPercentage() * 100)
local damage = rla.getDamagePercent()
local energy = math.ceil(ind.getEnergyFilledPercentage() * 100)
local status = rla.getStatus() and "Online" or "Offline"
if coolant > 70 and heated < 70 and waste < 70 and damage < 1 and energy < 90 and status == "false"
then
rla.activate()
print("ACTIVATED | INFO: " .. "C:" .. string.format("%3.0f", coolant) .. "%",
"H:" .. string.format("%3.0f", heated) .. "%", "W:" .. string.format("%3.0f", waste) .. "%",
"E:" .. string.format("%3.0f", energy) .. "%")
elseif status == "true" and (coolant <= 70 or heated >= 70 or waste >= 70 or damage >= 1 or energy >= 90)
then
rla.scram()
print("SCRAMMED | INFO: " .. "C:" .. string.format("%3.0f", coolant) .. "%",
"H:" .. string.format("%3.0f", heated) .. "%", "W:" .. string.format("%3.0f", waste) .. "%",
"E:" .. string.format("%3.0f", energy) .. "%")
scramCount = scramCount + 1
end
end
local function info()
local fuel = math.ceil(rla.getFuelFilledPercentage() * 100)
local coolant = math.ceil(rla.getCoolantFilledPercentage() * 100)
local heated = math.ceil(rla.getHeatedCoolantFilledPercentage() * 100)
local waste = math.ceil(rla.getWasteFilledPercentage() * 100)
local steam = math.ceil(trb.getSteamFilledPercentage() * 100)
local bheated = math.ceil(boi.getHeatedCoolantFilledPercentage() * 100)
local bcoolant = math.ceil(boi.getCooledCoolantFilledPercentage() * 100)
local bwater = math.ceil(boi.getWaterFilledPercentage() * 100)
local bsteam = math.ceil(boi.getSteamFilledPercentage() * 100)
local status = rla.getStatus() and "Online" or "Offline"
local function formatEnergy(energy, feByT)
local localEnergyDisplay = string.format("%.2f", energy)
if energy < 1000 then
localEnergyDisplay = energy .. (feByT and " FE/t" or " FE")
elseif energy > 1000 and energy < 1e6 then
localEnergyDisplay = string.format("%.2f", energy / 1000) .. (feByT and " kFE/t" or " kFE")
elseif energy > 1e6 and energy < 1e9 then
localEnergyDisplay = string.format("%.2f", energy / 1e6) .. (feByT and " MFE/t" or " MFE")
elseif energy > 1e9 and energy < 1e12 then
localEnergyDisplay = string.format("%.2f", energy / 1e9) .. (feByT and " GFE/t" or " GFE")
elseif energy > 1e12 and energy < 1e15 then
localEnergyDisplay = string.format("%.2f", energy / 1e12) .. (feByT and " TFE/t" or " TFE")
elseif energy > 1e15 then
localEnergyDisplay = string.format("%.2f", energy / 1e15) .. (feByT and " PFE/t" or " PFE")
end
return localEnergyDisplay
end
local prodDisp = formatEnergy(mekanismEnergyHelper.joulesToFE(trb.getProductionRate()), true)
local inputDisp = formatEnergy(mekanismEnergyHelper.joulesToFE(ind.getLastInput()), true)
local outputDisp = formatEnergy(mekanismEnergyHelper.joulesToFE(ind.getLastOutput()), true)
local energyDisp = formatEnergy(mekanismEnergyHelper.joulesToFE(ind.getEnergy()), false)
local maxEnergyDisp = formatEnergy(mekanismEnergyHelper.joulesToFE(ind.getMaxEnergy()), false)
local epercentDisp = math.ceil(ind.getEnergyFilledPercentage() * 100)
mon.clear()
mon.setCursorPos(1,1) mon.setTextColor(16) mon.write("Fission Reactor")
mon.setCursorPos(1,2) mon.setTextColor(512) mon.write("Status: ") mon.setTextColor(1) mon.write(status)
mon.setCursorPos(1,3) mon.setTextColor(32) mon.write("Fuel: ") mon.setTextColor(1) mon.write(fuel .. "%")
mon.setCursorPos(1,4) mon.setTextColor(2048) mon.write("Coolant: ") mon.setTextColor(1) mon.write(coolant .. "%")
mon.setCursorPos(1,5) mon.setTextColor(4) mon.write("Heated: ") mon.setTextColor(1) mon.write(heated .. "%")
mon.setCursorPos(1,6) mon.setTextColor(4096) mon.write("Waste: ") mon.setTextColor(1) mon.write(waste .. "%")
mon.setCursorPos(1,8) mon.setTextColor(16) mon.write("Thermoelectric Boiler")
mon.setCursorPos(1,9) mon.setTextColor(4) mon.write("Heated: ") mon.setTextColor(1) mon.write(bheated .. "%")
mon.setCursorPos(1,10) mon.setTextColor(2048) mon.write("Cooled: ") mon.setTextColor(1) mon.write(bcoolant .. "%")
mon.setCursorPos(1,11) mon.setTextColor(8) mon.write("Water: ") mon.setTextColor(1) mon.write(bwater .. "%")
mon.setCursorPos(1,12) mon.setTextColor(256) mon.write("Steam: ") mon.setTextColor(1) mon.write(bsteam .. "%")
mon.setCursorPos(1,14) mon.setTextColor(16) mon.write("Industrial Turbine")
mon.setCursorPos(1,15) mon.setTextColor(8192) mon.write("Production: ") mon.setTextColor(1) mon.write(prodDisp)
mon.setCursorPos(1,16) mon.setTextColor(256) mon.write("Steam: ") mon.setTextColor(1) mon.write(steam .. "%")
mon.setCursorPos(1,18) mon.setTextColor(16) mon.write("Induction Matrix")
mon.setCursorPos(1,19) mon.setTextColor(8192) mon.write("Input: ") mon.setTextColor(1) mon.write(inputDisp)
mon.setCursorPos(1,20) mon.setTextColor(8192) mon.write("Output: ") mon.setTextColor(1) mon.write(outputDisp)
mon.setCursorPos(1,21) mon.setTextColor(8192) mon.write("Energy: ") mon.setTextColor(1) mon.write(energyDisp .. "/" .. maxEnergyDisp)
mon.setCursorPos(1,22) mon.setTextColor(8192) mon.write("Filled: ") mon.setTextColor(1) mon.write(epercentDisp .. "%")
mon.setCursorPos(1,24) mon.setTextColor(16384) mon.write("SCRAM COUNT: ") mon.write(string.format("%3.0f", scramCount))
end
while true do
regulator()
info()
end