SHOW:
|
|
- or go back to the newest paste.
| 1 | - | -- pay attention to the fact that things return error now instead of origin values |
| 1 | + | |
| 2 | - | -- especially on reassembling on restart of server and things of the sort |
| 2 | + | |
| 3 | local VERISON = "NEW" | |
| 4 | ||
| 5 | function checkVersionTooOld() | |
| 6 | - | -- ****************************************************** -- |
| 6 | + | local monitorsCheck = {peripheral.find("monitor")}
|
| 7 | - | -- ****************************************************** -- |
| 7 | + | |
| 8 | - | -- ** Reactor Madness Program ** -- |
| 8 | + | |
| 9 | - | -- ** for Big Reactor ** -- |
| 9 | + | function checkVersionNEW() |
| 10 | - | -- ** Written by krakaen ** -- |
| 10 | + | local reactorsArray = {peripheral.find("BigReactors-Reactor")}
|
| 11 | - | -- ** Video Tutorial ** -- |
| 11 | + | reactorsArray[0].getEnergyStats(); |
| 12 | - | -- ** https://www.youtube.com/watch?v=SbbT7ncyS2M ** -- |
| 12 | + | |
| 13 | - | -- ****************************************************** -- |
| 13 | + | |
| 14 | - | -- ****************************************************** -- |
| 14 | + | function checkErrors() |
| 15 | if pcall(checkVersionTooOld) then | |
| 16 | - | -- ******** Version 0.1 Changelog (02/16/2016) ******** |
| 16 | + | |
| 17 | - | -- Changed currentRFTotal to 1 (makes power show at start) |
| 17 | + | |
| 18 | error("The version of ComputerCraft is too old to use this program, sorry", 0)
| |
| 19 | - | -- ******** Version 0.2 Changelog (02/16/2016) ******** |
| 19 | + | |
| 20 | - | -- Added fuel usage (mb/t) |
| 20 | + | local monitorsCheck = {peripheral.find("monitor")}
|
| 21 | - | -- Added function round |
| 21 | + | local reactorsCheck = {peripheral.find("BigReactors-Reactor")}
|
| 22 | - | -- Added function comma_value |
| 22 | + | |
| 23 | - | -- Added function format_num |
| 23 | + | if monitorsCheck[1] == nil then |
| 24 | error("The Monitor is not being detected, make sure the connections(modem) are activated", 0)
| |
| 25 | - | -- ******** Version 0.3 Changelog (02/17/2016) ******** |
| 25 | + | |
| 26 | - | -- Change Rod looking for 0 instead of 1 |
| 26 | + | |
| 27 | if reactorsCheck[1] == nil then | |
| 28 | - | -- ******** Version 0.4 Changelog (10/18/2016) ******** |
| 28 | + | error("The Reactor is not being detected, make sure the connections(modem) are activated. The problem could also be related to chunk protection on some public servers, ask an admin about it.", 0)
|
| 29 | - | -- Change rodLevel to do a Math.ceil instead of Math.floor |
| 29 | + | |
| 30 | ||
| 31 | - | -- ******** Version 0.5 Changelog (03/01/2017) ******** |
| 31 | + | if pcall(checkVersionNEW) then |
| 32 | - | -- Change drawBoxed and drawFilledBox for drawLines with for loop |
| 32 | + | VERISON = "NEW" |
| 33 | - | -- to get compatibility with 1.60+ |
| 33 | + | |
| 34 | VERISON = "OLD" | |
| 35 | - | -- ******** Version 0.6 Changelog (03/22/2017) ******** |
| 35 | + | |
| 36 | - | -- Added Custom error handling |
| 36 | + | |
| 37 | - | -- fixed typo in controlsSize for controlsSize |
| 37 | + | |
| 38 | -- you need to give the index to be able to use the program | |
| 39 | - | -- ******** Version 0.7 Changelog (05/15/2018) ******** |
| 39 | + | -- ex : Reactor Data |
| 40 | - | -- Added new functions for extreme reactor handling. Will work on both new and old versions |
| 40 | + | |
| 41 | local args = { ... }
| |
| 42 | - | -- ******** Version 0.8 Changelog (31/10/2020) ******** |
| 42 | + | |
| 43 | - | -- Added new functions for Bigger reactor handling. Will work on both new, newer and old versions |
| 43 | + | |
| 44 | local filleds = {}
| |
| 45 | - | -- ******** Version 0.9 Changelog (24/04/2021) ******** |
| 45 | + | |
| 46 | - | -- Added new functions for newer Bigger reactor handling. Will work on both new, newer and old versions. |
| 46 | + | |
| 47 | local texts = {}
| |
| 48 | - | -- ******** Version 0.10 Changelog (19/09/2021) ******** |
| 48 | + | |
| 49 | - | -- Added fix to calculate size of power tank on Extreme Reactor and fixed the total RB decimal issue. |
| 49 | + | |
| 50 | ||
| 51 | local infosSize = {}
| |
| 52 | - | -- ex : NameOfProgram Index (reactor Krakaen) |
| 52 | + | |
| 53 | local numbersSize = {}
| |
| 54 | local currentRfTotal = 1 | |
| 55 | local currentRfTick = 1 | |
| 56 | local currentFuelConsumedLastTick = 0.00001 | |
| 57 | ||
| 58 | ||
| 59 | local rfPerTickMax = 1 | |
| 60 | local minPowerRod = 0 | |
| 61 | local maxPowerRod = 100 | |
| 62 | local currentRodLevel = 1 | |
| 63 | ||
| 64 | local index = "" | |
| 65 | ||
| 66 | checkErrors() | |
| 67 | ||
| 68 | if (#args == 0) then | |
| 69 | error("No index Given, Make sure to start the 'start' program and not the 'reactor' program", 0)
| |
| 70 | end | |
| 71 | ||
| 72 | if (#args == 1) then | |
| 73 | - | local rfTotalMax = 10000000 |
| 73 | + | |
| 74 | end | |
| 75 | ||
| 76 | local monitors = {peripheral.find("monitor")}
| |
| 77 | local mon = monitors[1] | |
| 78 | local reactors = {peripheral.find("BigReactors-Reactor")}
| |
| 79 | ||
| 80 | - | local reactors = {}
|
| 80 | + | |
| 81 | - | local monitors = {}
|
| 81 | + | |
| 82 | mon.clear() | |
| 83 | - | local VERSION = "NONE" |
| 83 | + | |
| 84 | mon.setBackgroundColor(colors.black) | |
| 85 | ||
| 86 | - | local uselessMonitors = {peripheral.find("monitor")}
|
| 86 | + | |
| 87 | button = {}
| |
| 88 | end | |
| 89 | - | function checkMBFunctionAvailability() |
| 89 | + | |
| 90 | - | local uselessMbConnected = reactors[1].mbIsConnected() |
| 90 | + | |
| 91 | - | local uselessMbAssembled = reactors[1].mbIsAssembled() |
| 91 | + | |
| 92 | ||
| 93 | function setButton(name, title, func, xmin, ymin, xmax, ymax, elem, elem2, color) | |
| 94 | - | function checkEnergyCapacityFunction() |
| 94 | + | |
| 95 | - | local uselessEnergyCapacity = reactors[1].getEnergyStats().energyCapacity |
| 95 | + | |
| 96 | button[name]["func"] = func | |
| 97 | button[name]["active"] = false | |
| 98 | - | -- VERSIONS - BIG, EXTREME, BIGGERv1, BIGGERv2 |
| 98 | + | |
| 99 | - | function initReactor() |
| 99 | + | |
| 100 | button[name]["xmax"] = xmax | |
| 101 | - | monitors = {peripheral.find("monitor")}
|
| 101 | + | |
| 102 | button[name]["color"] = color | |
| 103 | - | -- allow 5 seconds to detect if the reactor is on the network |
| 103 | + | |
| 104 | - | print("Detecting reactor. This may take up to 5 seconds.")
|
| 104 | + | |
| 105 | - | local looptyloop = 0 |
| 105 | + | |
| 106 | - | while looptyloop ~= 5 do |
| 106 | + | |
| 107 | - | if peripheral.find("BigReactors-Reactor") ~= nil then
|
| 107 | + | |
| 108 | - | reactors = {peripheral.find("BigReactors-Reactor")}
|
| 108 | + | |
| 109 | - | if pcall(checkEnergyCapacityFunction) then |
| 109 | + | |
| 110 | - | rfTotalMax = reactors[1].getEnergyStats().energyCapacity |
| 110 | + | |
| 111 | - | end |
| 111 | + | |
| 112 | - | if pcall(checkMBFunctionAvailability) then |
| 112 | + | |
| 113 | - | VERSION = "EXTREME" |
| 113 | + | |
| 114 | - | else |
| 114 | + | |
| 115 | - | VERSION = "BIG" |
| 115 | + | |
| 116 | - | end |
| 116 | + | |
| 117 | - | break |
| 117 | + | |
| 118 | - | elseif peripheral.find("bigger-reactor") ~= nil then
|
| 118 | + | |
| 119 | - | reactors = {peripheral.find("bigger-reactor")}
|
| 119 | + | |
| 120 | - | VERSION = "BIGGERv1" |
| 120 | + | |
| 121 | - | break |
| 121 | + | |
| 122 | - | elseif peripheral.find("BiggerReactors_Reactor") ~= nil then
|
| 122 | + | |
| 123 | - | reactors = {peripheral.find("BiggerReactors_Reactor")}
|
| 123 | + | |
| 124 | - | VERSION = "BIGGERv2" |
| 124 | + | |
| 125 | - | rfTotalMax = reactors[1].battery().capacity() |
| 125 | + | |
| 126 | - | break |
| 126 | + | |
| 127 | end | |
| 128 | mon.setBackgroundColor(colors.black) | |
| 129 | - | sleep(1) |
| 129 | + | |
| 130 | - | looptyloop = looptyloop + 1 |
| 130 | + | |
| 131 | ||
| 132 | function screen() | |
| 133 | - | if monitors[1] == nil then |
| 133 | + | |
| 134 | - | error("The Monitor is not being detected, make sure the connections(modem) are activated", 0)
|
| 134 | + | |
| 135 | local on = data["active"] | |
| 136 | currColor = data["color"] | |
| 137 | - | if reactors[1] == nil then |
| 137 | + | |
| 138 | - | error("The Reactor is not being detected, make sure the connections(modem) are activated. The problem could also be related to chunk protection on some public servers, ask an admin about it.", 0)
|
| 138 | + | |
| 139 | end | |
| 140 | ||
| 141 | ||
| 142 | function flash(name) | |
| 143 | - | print("Reactor detected. Program Starting.")
|
| 143 | + | |
| 144 | screen() | |
| 145 | end | |
| 146 | ||
| 147 | - | error("No index Given, Make sure to start the 'start' program and not the 'reactor' program", 0)
|
| 147 | + | |
| 148 | function checkxy(x, y) | |
| 149 | for name, data in pairs(button) do | |
| 150 | if y>=data["ymin"] and y <= data["ymax"] then | |
| 151 | if x>=data["xmin"] and x<= data["xmax"] then | |
| 152 | data["func"](data["elem"], data["elem2"]) | |
| 153 | flash(data['name']) | |
| 154 | - | initReactor() -- Init and Verify that everything is okay to start the program |
| 154 | + | |
| 155 | --data["active"] = not data["active"] | |
| 156 | --print(name) | |
| 157 | end | |
| 158 | - | -- Use the black thingy sponge to clear the chalkboard |
| 158 | + | |
| 159 | end | |
| 160 | return false | |
| 161 | end | |
| 162 | ||
| 163 | function label(w, h, text) | |
| 164 | mon.setCursorPos(w, h) | |
| 165 | mon.write(text) | |
| 166 | end | |
| 167 | ||
| 168 | function draw() | |
| 169 | ||
| 170 | - | -- All the things that make my buttons work |
| 170 | + | |
| 171 | local counter = 1 | |
| 172 | for i=value[2],value[4],1 do | |
| 173 | paintutils.drawLine(value[1] , value[2]+counter, value[3], value[2]+counter, value[5]) | |
| 174 | counter = counter + 1 | |
| 175 | end | |
| 176 | end | |
| 177 | ||
| 178 | for key,value in pairs(boxes) do | |
| 179 | paintutils.drawLine(value[1] , value[2], value[1], value[4], value[5]) | |
| 180 | paintutils.drawLine(value[1] , value[2], value[3], value[2], value[5]) | |
| 181 | paintutils.drawLine(value[1] , value[4], value[3], value[4], value[5]) | |
| 182 | paintutils.drawLine(value[3] , value[2], value[3], value[4], value[5]) | |
| 183 | end | |
| 184 | ||
| 185 | for key,value in pairs(lines) do | |
| 186 | - | -- stuff and things for buttons |
| 186 | + | |
| 187 | end | |
| 188 | ||
| 189 | for key,value in pairs(texts) do | |
| 190 | mon.setCursorPos(value[1], value[2]) | |
| 191 | mon.setTextColor(value[4]) | |
| 192 | mon.setBackgroundColor(value[5]) | |
| 193 | mon.write(value[3]) | |
| 194 | end | |
| 195 | screen() | |
| 196 | resetDraw() | |
| 197 | end | |
| 198 | ||
| 199 | ||
| 200 | function resetDraw() | |
| 201 | filleds = {}
| |
| 202 | boxes = {}
| |
| 203 | lines = {}
| |
| 204 | texts = {}
| |
| 205 | end | |
| 206 | ||
| 207 | function clickEvent() | |
| 208 | local myEvent={os.pullEvent("monitor_touch")}
| |
| 209 | checkxy(myEvent[3], myEvent[4]) | |
| 210 | end | |
| 211 | ||
| 212 | - | -- stuff and things for buttons |
| 212 | + | |
| 213 | function powerUp(m,n) | |
| 214 | local reactor = reactors[1] | |
| 215 | reactor.setActive(true) | |
| 216 | end | |
| 217 | --M & Ns are a good source of food, right? | |
| 218 | function powerDown(m,n) | |
| 219 | local reactor = reactors[1] | |
| 220 | reactor.setActive(false) | |
| 221 | end | |
| 222 | ||
| 223 | - | -- stuff and things for buttons |
| 223 | + | |
| 224 | function modifyRods(limit, number) | |
| 225 | local tempLevel = 0 | |
| 226 | ||
| 227 | if limit == "min" then | |
| 228 | tempLevel = minPowerRod + number | |
| 229 | - | -- magical handler for clicky clicks |
| 229 | + | |
| 230 | minPowerRod = 0 | |
| 231 | end | |
| 232 | ||
| 233 | if tempLevel >= maxPowerRod then | |
| 234 | minPowerRod = maxPowerRod -10 | |
| 235 | end | |
| 236 | ||
| 237 | if tempLevel < maxPowerRod and tempLevel > 0 then | |
| 238 | minPowerRod = tempLevel | |
| 239 | end | |
| 240 | else | |
| 241 | tempLevel = maxPowerRod + number | |
| 242 | if tempLevel <= minPowerRod then | |
| 243 | maxPowerRod = minPowerRod +10 | |
| 244 | end | |
| 245 | ||
| 246 | - | -- Don't question my code, it works on my machine... |
| 246 | + | |
| 247 | maxPowerRod = 100 | |
| 248 | end | |
| 249 | ||
| 250 | if tempLevel > minPowerRod and tempLevel < 100 then | |
| 251 | maxPowerRod = tempLevel | |
| 252 | end | |
| 253 | - | -- Draw function : put's all the beautiful magic in the screen |
| 253 | + | |
| 254 | ||
| 255 | table.insert(lines, {controlsSize['inX'], controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, controlsSize['inX'] + controlsSize['width'], controlsSize['inY']+(controlsSize['sectionHeight']*1)+4, colors.black})
| |
| 256 | ||
| 257 | table.insert(texts, {controlsSize['inX']+5, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, minPowerRod .. '%', colors.lightBlue, colors.black})
| |
| 258 | table.insert(texts, {controlsSize['inX']+13, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, '--', colors.white, colors.black})
| |
| 259 | table.insert(texts, {controlsSize['inX']+20, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, maxPowerRod .. '%', colors.purple, colors.black})
| |
| 260 | ||
| 261 | setInfoToFile() | |
| 262 | adjustRodsLevel() | |
| 263 | end | |
| 264 | ||
| 265 | function adjustRodsLevel() | |
| 266 | local reactor = reactors[1] | |
| 267 | local rfTotalMax = 10000000 | |
| 268 | ||
| 269 | local allStats = getAllStats() | |
| 270 | local currentRfTotal = allStats["rfTotal"] | |
| 271 | local reactorRodsLevel = allStats["reactorRodsLevel"] | |
| 272 | ||
| 273 | differenceMinMax = maxPowerRod - minPowerRod | |
| 274 | ||
| 275 | maxPower = (rfTotalMax/100) * maxPowerRod | |
| 276 | minPower = (rfTotalMax/100) * minPowerRod | |
| 277 | ||
| 278 | if currentRfTotal >= maxPower then | |
| 279 | currentRfTotal = maxPower | |
| 280 | end | |
| 281 | ||
| 282 | if currentRfTotal <= minPower then | |
| 283 | currentRfTotal = minPower | |
| 284 | end | |
| 285 | - | -- Resets the elements to draw to only draw the neccessity |
| 285 | + | |
| 286 | currentRfTotal = currentRfTotal - (rfTotalMax/100) * minPowerRod | |
| 287 | ||
| 288 | local rfInBetween = (rfTotalMax/100) * differenceMinMax | |
| 289 | local rodLevel = math.ceil((currentRfTotal/rfInBetween)*100) | |
| 290 | ||
| 291 | if VERSION == "NEW" then | |
| 292 | if reactor.mbIsConnected() == true and reactor.mbIsAssembled() == true then | |
| 293 | for key,value in pairs(reactorRodsLevel) do | |
| 294 | - | -- Handles all the clicks for the buttons |
| 294 | + | reactorRodsLevel[key] = rodLevel |
| 295 | end | |
| 296 | reactor.setControlRodsLevels(reactorRodsLevel) | |
| 297 | end | |
| 298 | else | |
| 299 | reactor.setAllControlRodLevels(rodLevel) | |
| 300 | end | |
| 301 | - | -- Power up the reactor (M&N are a good source of food right?) |
| 301 | + | |
| 302 | ||
| 303 | function addDrawBoxesSingleReactor() | |
| 304 | local w, h = mon.getSize() | |
| 305 | local margin = math.floor((w/100)*2) | |
| 306 | ||
| 307 | infosSize['startX'] = margin + 1 | |
| 308 | - | -- Power down the reactor (M&N are a good source of food right?) |
| 308 | + | |
| 309 | infosSize['endX'] = (((w-(margin*2))/3)*2)-margin | |
| 310 | infosSize['endY'] = h - margin | |
| 311 | infosSize['height'] = infosSize['endY']-infosSize['startY']-(margin*2)-2 | |
| 312 | infosSize['width'] = infosSize['endX']-infosSize['startX']-(margin*2)-2 | |
| 313 | infosSize['inX'] = infosSize['startX'] + margin +1 | |
| 314 | infosSize['inY'] = infosSize['startY'] + margin +1 | |
| 315 | - | -- Handles and calculate the Min and Max of the power limitation |
| 315 | + | |
| 316 | ||
| 317 | table.insert(boxes, {infosSize['startX'] , infosSize['startY'], infosSize['endX'], infosSize['endY'], colors.gray})
| |
| 318 | local name = "INFOS" | |
| 319 | table.insert(lines, {infosSize['startX'] + margin , infosSize['startY'], infosSize['startX'] + (margin*2) + #name+1, infosSize['startY'], colors.black})
| |
| 320 | table.insert(texts, {infosSize['startX'] + (margin*2), infosSize['startY'], name, colors.white, colors.black})
| |
| 321 | ||
| 322 | local names = {}
| |
| 323 | names[1] = 'ENERGY LAST TICK' | |
| 324 | names[2] = 'ENERGY STORED' | |
| 325 | names[3] = 'CONTROL ROD LEVEL' | |
| 326 | ||
| 327 | for i=0,2,1 do | |
| 328 | table.insert(texts, {infosSize['inX'] + margin, infosSize['inY'] + (infosSize['sectionHeight']*i) +i, names[i+1], colors.white, colors.black})
| |
| 329 | table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 2 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray})
| |
| 330 | end | |
| 331 | ||
| 332 | ||
| 333 | controlsSize['startX'] = infosSize['endX'] + margin + 1 | |
| 334 | controlsSize['startY'] = margin + 1 | |
| 335 | controlsSize['endX'] = w-margin | |
| 336 | controlsSize['endY'] = (((h - (margin*2))/3)*2) +1 | |
| 337 | controlsSize['height'] = controlsSize['endY']-controlsSize['startY']-(margin)-1 | |
| 338 | controlsSize['width'] = controlsSize['endX']-controlsSize['startX']-(margin*2)-2 | |
| 339 | controlsSize['inX'] = controlsSize['startX'] + margin +1 | |
| 340 | controlsSize['inY'] = controlsSize['startY'] + margin | |
| 341 | ||
| 342 | table.insert(boxes, {controlsSize['startX'] , controlsSize['startY'], controlsSize['endX'], controlsSize['endY'], colors.gray})
| |
| 343 | name = "CONTROLS" | |
| 344 | table.insert(lines, {controlsSize['startX'] + margin , controlsSize['startY'], controlsSize['startX'] + (margin*2) + #name+1, controlsSize['startY'], colors.black})
| |
| 345 | table.insert(texts, {controlsSize['startX'] + (margin*2), controlsSize['startY'], name, colors.white, colors.black})
| |
| 346 | ||
| 347 | controlsSize['sectionHeight'] = math.floor(controlsSize['height']/4) | |
| 348 | ||
| 349 | reactor = reactors[1] | |
| 350 | ||
| 351 | mon.setTextColor(colors.white) | |
| 352 | setButton("ON","ON", powerUp, controlsSize['inX'], controlsSize['inY'], controlsSize['inX'] + math.floor(controlsSize['width']/2) -1, controlsSize['inY'] +2, 0, 0, colors.green)
| |
| 353 | setButton("OFF","OFF", powerDown, controlsSize['inX'] + math.floor(controlsSize['width']/2) +2, controlsSize['inY'], controlsSize['inX'] + controlsSize['width'], controlsSize['inY'] +2,0, 0, colors.red)
| |
| 354 | ||
| 355 | table.insert(texts, {controlsSize['inX']+8, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+1, 'AUTO-CONTROL', colors.white, colors.black})
| |
| 356 | ||
| 357 | table.insert(texts, {controlsSize['inX']+5, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+3, 'MIN', colors.lightBlue, colors.black})
| |
| 358 | - | -- Calculate and adjusts the level of the rods |
| 358 | + | |
| 359 | - | -- TOMODIFY |
| 359 | + | |
| 360 | table.insert(texts, {controlsSize['inX']+13, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, '--', colors.white, colors.black})
| |
| 361 | table.insert(texts, {controlsSize['inX']+20, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+3, 'MAX', colors.purple, colors.black})
| |
| 362 | table.insert(texts, {controlsSize['inX']+20, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, maxPowerRod..'%', colors.purple, colors.black})
| |
| 363 | mon.setTextColor(colors.white) | |
| 364 | ||
| 365 | setButton("low-10","-10", modifyRods, controlsSize['inX'], controlsSize['inY'] +(controlsSize['sectionHeight']*2)+2, controlsSize['inX'] + math.floor(controlsSize['width']/2) -1, controlsSize['inY'] +(controlsSize['sectionHeight']*2)+4, "min", -10, colors.lightBlue)
| |
| 366 | setButton("high-10","-10", modifyRods, controlsSize['inX'] + math.floor(controlsSize['width']/2) +2, controlsSize['inY'] +(controlsSize['sectionHeight']*2)+2, controlsSize['inX'] + controlsSize['width'], controlsSize['inY'] +(controlsSize['sectionHeight']*2)+4, "max", -10, colors.purple)
| |
| 367 | ||
| 368 | setButton("low+10","+10", modifyRods, controlsSize['inX'], controlsSize['inY'] +(controlsSize['sectionHeight']*3)+2, controlsSize['inX'] + math.floor(controlsSize['width']/2) -1, controlsSize['inY'] +(controlsSize['sectionHeight']*3)+4, "min", 10, colors.lightBlue)
| |
| 369 | setButton("high+10","+10", modifyRods, controlsSize['inX'] + math.floor(controlsSize['width']/2) +2, controlsSize['inY'] +(controlsSize['sectionHeight']*3)+2, controlsSize['inX'] + controlsSize['width'], controlsSize['inY'] +(controlsSize['sectionHeight']*3)+4, "max", 10, colors.purple)
| |
| 370 | ||
| 371 | ||
| 372 | numbersSize['startX'] = infosSize['endX'] + margin + 1 | |
| 373 | numbersSize['startY'] = controlsSize['endY'] + margin + 1 | |
| 374 | numbersSize['endX'] = w-margin | |
| 375 | numbersSize['endY'] = h-margin | |
| 376 | numbersSize['height'] = numbersSize['endY']-numbersSize['startY']-(margin)-1 | |
| 377 | numbersSize['width'] = numbersSize['endX']-numbersSize['startX']-(margin*2)-2 | |
| 378 | numbersSize['inX'] = numbersSize['startX'] + margin +1 | |
| 379 | numbersSize['inY'] = numbersSize['startY'] + margin | |
| 380 | ||
| 381 | table.insert(boxes, {numbersSize['startX'] , numbersSize['startY'], numbersSize['endX'], numbersSize['endY'], colors.gray})
| |
| 382 | name = "NUMBERS" | |
| 383 | table.insert(lines, {numbersSize['startX'] + margin , numbersSize['startY'], numbersSize['startX'] + (margin*2) + #name+1, numbersSize['startY'], colors.black})
| |
| 384 | - | if VERSION == "EXTREME" then |
| 384 | + | |
| 385 | - | for key,value in pairs(reactorRodsLevel) do |
| 385 | + | |
| 386 | - | reactorRodsLevel[key] = rodLevel |
| 386 | + | |
| 387 | while refresh do | |
| 388 | - | reactor.setControlRodsLevels(reactorRodsLevel) |
| 388 | + | |
| 389 | end | |
| 390 | end | |
| 391 | ||
| 392 | function getAllStats() | |
| 393 | local stats = {}
| |
| 394 | - | -- Creates the frame and the basic of the visual |
| 394 | + | |
| 395 | - | -- Also adds the variables informations for placement of stuff and things |
| 395 | + | |
| 396 | if VERSION == "NEW" then | |
| 397 | if reactor.mbIsConnected() == true and reactor.mbIsAssembled() == true then | |
| 398 | local reactorEnergyStats = reactor.getEnergyStats() | |
| 399 | local reactorFuelStats = reactor.getFuelStats() | |
| 400 | stats["reactorRodsLevel"] = reactor.getControlRodsLevels() | |
| 401 | ||
| 402 | stats["rfTotal"] = reactorEnergyStats["energyStored"] | |
| 403 | stats["rfPerTick"] = math.ceil(reactorEnergyStats["energyProducedLastTick"]) | |
| 404 | stats["rodLevel"] = stats["reactorRodsLevel"][0] | |
| 405 | stats["fuelPerTick"] = round(reactorFuelStats["fuelConsumedLastTick"], 2) | |
| 406 | end | |
| 407 | else | |
| 408 | stats["rfTotal"] = reactor.getEnergyStored() | |
| 409 | stats["rfPerTick"] = math.floor(reactor.getEnergyProducedLastTick()) | |
| 410 | stats["rodLevel"] = math.floor(reactor.getControlRodLevel(0)) | |
| 411 | stats["fuelPerTick"] = reactor.getFuelConsumedLastTick() | |
| 412 | end | |
| 413 | ||
| 414 | return stats | |
| 415 | end | |
| 416 | ||
| 417 | function refreshSingleReactor() | |
| 418 | local rfPerTick = 0 | |
| 419 | local rfTotal = 0 | |
| 420 | local rfTotalMax = 10000000 | |
| 421 | local reactor = reactors[1] | |
| 422 | ||
| 423 | local allStats = getAllStats() | |
| 424 | rfTotal = allStats["rfTotal"] | |
| 425 | rfPerTick = allStats["rfPerTick"] | |
| 426 | rodLevel = allStats["rodLevel"] | |
| 427 | - | -- Controls |
| 427 | + | |
| 428 | ||
| 429 | local i = 0 | |
| 430 | local infotoAdd = 'RF PER TICK : ' | |
| 431 | ||
| 432 | if currentRfTick ~= rfPerTick then | |
| 433 | currentRfTick = rfPerTick | |
| 434 | if rfPerTick > rfPerTickMax then | |
| 435 | rfPerTickMax = rfPerTick | |
| 436 | end | |
| 437 | ||
| 438 | table.insert(lines, {numbersSize['inX'] , numbersSize['inY'],numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'], colors.black})
| |
| 439 | table.insert(texts, {numbersSize['inX'], numbersSize['inY'], infotoAdd .. rfPerTick .. " RF", colors.white, colors.black})
| |
| 440 | table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray})
| |
| 441 | ||
| 442 | width = math.floor((infosSize['width'] / rfPerTickMax)*rfPerTick) | |
| 443 | table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + width, infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.green})
| |
| 444 | ||
| 445 | end | |
| 446 | ||
| 447 | i = 1 | |
| 448 | infotoAdd = 'ENERGY STORED : ' | |
| 449 | if currentRfTotal ~= rfTotal then | |
| 450 | currentRfTotal = rfTotal | |
| 451 | ||
| 452 | table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray})
| |
| 453 | ||
| 454 | width = math.floor((infosSize['width'] / rfTotalMax)*rfTotal) | |
| 455 | table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + width, infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.green})
| |
| 456 | table.insert(lines, {numbersSize['inX'] , numbersSize['inY'] +2 ,numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'] +2, colors.black})
| |
| 457 | table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 2 , infotoAdd .. rfTotal .. " RF", colors.white, colors.black})
| |
| 458 | end | |
| 459 | ||
| 460 | i = 2 | |
| 461 | infotoAdd = 'CONTROL ROD LEVEL : ' | |
| 462 | if currentRodLevel ~= rodLevel then | |
| 463 | currentRodLevel = rodLevel | |
| 464 | ||
| 465 | table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray})
| |
| 466 | ||
| 467 | - | -- Numbers |
| 467 | + | |
| 468 | table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + width, infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.green})
| |
| 469 | table.insert(lines, {numbersSize['inX'] , numbersSize['inY']+4 ,numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'] +4, colors.black})
| |
| 470 | table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 4 , infotoAdd .. rodLevel .. "%", colors.white, colors.black})
| |
| 471 | end | |
| 472 | ||
| 473 | i = 3 | |
| 474 | infotoAdd = 'FUEL USAGE : ' | |
| 475 | if currentFuelConsumedLastTick ~= fuelPerTick then | |
| 476 | currentFuelConsumedLastTick = fuelPerTick | |
| 477 | ||
| 478 | table.insert(lines, {numbersSize['inX'] , numbersSize['inY']+6 ,numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'] +6, colors.black})
| |
| 479 | table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 6 , infotoAdd .. format_num(tonumber(fuelPerTick),3) .. "mb/t", colors.white, colors.black})
| |
| 480 | end | |
| 481 | ||
| 482 | mon.setTextColor(colors.white) | |
| 483 | adjustRodsLevel() | |
| 484 | ||
| 485 | draw() | |
| 486 | ||
| 487 | sleep(2) | |
| 488 | end | |
| 489 | - | -- Gets the stats needed for the program to function based on the version of the reactor |
| 489 | + | |
| 490 | - | -- TOMODIFY |
| 490 | + | |
| 491 | function getInfoFromFile() | |
| 492 | ||
| 493 | if (fs.exists(index..".txt") == false) then | |
| 494 | file = io.open(index..".txt","w") | |
| 495 | - | if VERSION == "EXTREME" then |
| 495 | + | |
| 496 | - | local reactorEnergyStats = reactor.getEnergyStats() |
| 496 | + | |
| 497 | - | local reactorFuelStats = reactor.getFuelStats() |
| 497 | + | |
| 498 | file:close() | |
| 499 | - | stats["reactorRodsLevel"] = reactor.getControlRodsLevels() |
| 499 | + | |
| 500 | - | stats["rfTotal"] = math.floor(reactorEnergyStats["energyStored"]) |
| 500 | + | |
| 501 | - | stats["rfPerTick"] = math.floor(reactorEnergyStats["energyProducedLastTick"]) |
| 501 | + | |
| 502 | - | stats["rodLevel"] = stats["reactorRodsLevel"][0] |
| 502 | + | |
| 503 | - | stats["fuelPerTick"] = round(reactorFuelStats["fuelConsumedLastTick"], 2) |
| 503 | + | |
| 504 | - | elseif VERSION == "BIG" or VERSION == "BIGGERv1" then |
| 504 | + | |
| 505 | - | stats["rfTotal"] = math.floor(reactor.getEnergyStored()) |
| 505 | + | |
| 506 | ||
| 507 | function setInfoToFile() | |
| 508 | file = io.open(index..".txt","w") | |
| 509 | - | elseif VERSION == "BIGGERv2" then |
| 509 | + | |
| 510 | - | stats["rfTotal"] = reactor.battery().stored() |
| 510 | + | |
| 511 | - | stats["rfPerTick"] = math.floor(reactor.battery().producedLastTick()) |
| 511 | + | |
| 512 | - | stats["rodLevel"] = math.floor(reactor.getControlRod(0).level()) |
| 512 | + | |
| 513 | - | stats["fuelPerTick"] = reactor.fuelTank().burnedLastTick() |
| 513 | + | |
| 514 | function comma_value(amount) | |
| 515 | local formatted = amount | |
| 516 | while true do | |
| 517 | formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') | |
| 518 | if (k==0) then | |
| 519 | - | -- Makes and Handles the draw function for less lag in the visual |
| 519 | + | |
| 520 | end | |
| 521 | end | |
| 522 | return formatted | |
| 523 | end | |
| 524 | ||
| 525 | ||
| 526 | function round(val, decimal) | |
| 527 | if (decimal) then | |
| 528 | return math.floor( (val * 10^decimal) + 0.5) / (10^decimal) | |
| 529 | else | |
| 530 | return math.floor(val+0.5) | |
| 531 | end | |
| 532 | end | |
| 533 | ||
| 534 | function format_num(amount, decimal, prefix, neg_prefix) | |
| 535 | local str_amount, formatted, famount, remain | |
| 536 | ||
| 537 | decimal = decimal or 2 -- default 2 decimal places | |
| 538 | neg_prefix = neg_prefix or "-" -- default negative sign | |
| 539 | ||
| 540 | famount = math.abs(round(amount,decimal)) | |
| 541 | famount = math.floor(famount) | |
| 542 | ||
| 543 | remain = round(math.abs(amount) - famount, decimal) | |
| 544 | ||
| 545 | formatted = comma_value(famount) | |
| 546 | ||
| 547 | if (decimal > 0) then | |
| 548 | remain = string.sub(tostring(remain),3) | |
| 549 | formatted = formatted .. "." .. remain .. | |
| 550 | string.rep("0", decimal - string.len(remain))
| |
| 551 | end | |
| 552 | ||
| 553 | formatted = (prefix or "") .. formatted | |
| 554 | ||
| 555 | if (amount<0) then | |
| 556 | if (neg_prefix=="()") then | |
| 557 | formatted = "("..formatted ..")"
| |
| 558 | else | |
| 559 | formatted = neg_prefix .. formatted | |
| 560 | end | |
| 561 | end | |
| 562 | ||
| 563 | return formatted | |
| 564 | end | |
| 565 | ||
| 566 | mon.setBackgroundColor(colors.black) | |
| 567 | mon.clear() | |
| 568 | mon.setTextScale(0.5) | |
| 569 | ||
| 570 | getInfoFromFile() | |
| 571 | ||
| 572 | ||
| 573 | addDrawBoxesSingleReactor() |