sdykhuis

Colony2

Jul 13th, 2025
5
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.25 KB | None | 0 0
  1. ---@diagnostic disable: undefined-global
  2.  
  3. --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
  4.  
  5.  
  6.  
  7. --** ULTIMATE CC X MINECOLONIES PROGRAM **--
  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. --* VARIABLES
  50.  
  51. ----------------------------------------------------------------------------
  52.  
  53.  
  54.  
  55. -- Displays Ticker in the first row right-side. Default: 15
  56.  
  57. local refreshInterval = 10
  58.  
  59.  
  60.  
  61. -- If true, Advanced Computer will show all Log information. Default: false
  62.  
  63. local bShowInGameLog = false
  64.  
  65.  
  66.  
  67. -- Name of the log file e.g. "logFileName"_log.txt
  68.  
  69. local logFileName = "CCxM"
  70.  
  71.  
  72.  
  73. ----------------------------------------------------------------------------
  74.  
  75. --* LOG (FATAL ERROR WARN_ INFO_ DEBUG TRACE)
  76.  
  77. ----------------------------------------------------------------------------
  78.  
  79.  
  80.  
  81. -- Log a message to a file and optionally print it to the console
  82.  
  83. function logToFile(message, level, bPrint)
  84.  
  85. level = level or "INFO_"
  86.  
  87. bPrint = bPrint or bShowInGameLog
  88.  
  89.  
  90.  
  91. local logFolder = logFileName .. "_logs"
  92.  
  93. local logFilePath = logFolder .. "/" .. logFileName .. "_log_latest.txt"
  94.  
  95.  
  96.  
  97.  
  98.  
  99. if not fs.exists(logFolder) then
  100.  
  101. local success, err = pcall(function() fs.makeDir(logFolder) end)
  102.  
  103. if not success then
  104.  
  105. print(string.format("Failed to create log folder: %s", err))
  106.  
  107. return
  108.  
  109. end
  110.  
  111. end
  112.  
  113.  
  114.  
  115.  
  116.  
  117. local success, err = pcall(function()
  118.  
  119. local logFile = fs.open(logFilePath, "a")
  120.  
  121. if logFile then
  122.  
  123. -- Write the log entry with a timestamp and level
  124.  
  125. logFile.writeLine(string.format("[%s] [%s] %s", os.date("%Y-%m-%d %H:%M:%S"), level, message))
  126.  
  127. logFile.close()
  128.  
  129. else
  130.  
  131. error("Unable to open log file.")
  132.  
  133. end
  134.  
  135. end)
  136.  
  137.  
  138.  
  139.  
  140.  
  141. if not success then
  142.  
  143. print(string.format("Error writing to log file: %s", err))
  144.  
  145. return
  146.  
  147. end
  148.  
  149.  
  150.  
  151. -- Optionally print the message to the console
  152.  
  153. if bPrint then
  154.  
  155. if level == "ERROR" or level == "FATAL" then
  156.  
  157. print("")
  158.  
  159. end
  160.  
  161.  
  162.  
  163. print(string.format("[%s] %s", level, message))
  164.  
  165.  
  166.  
  167. if level == "ERROR" or level == "FATAL" then
  168.  
  169. print("")
  170.  
  171. end
  172.  
  173. end
  174.  
  175.  
  176.  
  177.  
  178.  
  179. logCounter = (logCounter or 0) + 1
  180.  
  181. if logCounter >= 250 then
  182.  
  183. rotateLogs(logFolder, logFilePath)
  184.  
  185. logCounter = 0
  186.  
  187. end
  188.  
  189. end
  190.  
  191.  
  192.  
  193. -- Rotates logs and limits the number of old logs stored
  194.  
  195. function rotateLogs(logFolder, logFilePath)
  196.  
  197. local maxLogs = 5 -- Maximum number of log files to keep
  198.  
  199.  
  200.  
  201.  
  202.  
  203. local timestamp = os.date("%Y-%m-%d_%H-%M-%S")
  204.  
  205. local archivedLog = string.format("%s/log_%s.txt", logFolder, timestamp)
  206.  
  207.  
  208.  
  209.  
  210.  
  211. local success, err = pcall(function()
  212.  
  213. if fs.exists(logFilePath) then
  214.  
  215. fs.move(logFilePath, archivedLog)
  216.  
  217. end
  218.  
  219. end)
  220.  
  221.  
  222.  
  223. if not success then
  224.  
  225. print(string.format("Failed to rotate log file: %s", err))
  226.  
  227. return
  228.  
  229. end
  230.  
  231.  
  232.  
  233.  
  234.  
  235. local logs = fs.list(logFolder)
  236.  
  237. table.sort(logs)
  238.  
  239.  
  240.  
  241. local logCount = #logs
  242.  
  243. while logCount > maxLogs do
  244.  
  245. local oldestLog = logFolder .. "/" .. logs[1]
  246.  
  247. local deleteSuccess, deleteErr = pcall(function() fs.delete(oldestLog) end)
  248.  
  249. if not deleteSuccess then
  250.  
  251. print(string.format("Failed to delete old log file: %s", deleteErr))
  252.  
  253. break
  254.  
  255. end
  256.  
  257. table.remove(logs, 1)
  258.  
  259. logCount = logCount - 1
  260.  
  261. end
  262.  
  263. end
  264.  
  265.  
  266.  
  267. ----------------------------------------------------------------------------
  268.  
  269. --* ERROR-HANDLING FUNCTION
  270.  
  271. ----------------------------------------------------------------------------
  272.  
  273.  
  274.  
  275. function safeCall(func, ...)
  276.  
  277. local success, result = pcall(func, ...)
  278.  
  279. if not success then
  280.  
  281. logToFile((result or "Unknown error"), "ERROR")
  282.  
  283. return false
  284.  
  285. end
  286.  
  287. return true
  288.  
  289. end
  290.  
  291.  
  292.  
  293. ----------------------------------------------------------------------------
  294.  
  295. --* GENERIC HELPER FUNCTIONS
  296.  
  297. ----------------------------------------------------------------------------
  298.  
  299.  
  300.  
  301. local function trimLeadingWhitespace(str)
  302.  
  303. return str:match("^%s*(.*)$")
  304.  
  305. end
  306.  
  307.  
  308.  
  309. function getLastWord(str)
  310.  
  311. return string.match(str, "%S+$")
  312.  
  313. end
  314.  
  315.  
  316.  
  317. function tableToString(tbl, indent)
  318.  
  319. indent = indent or 0
  320.  
  321. local toString = string.rep(" ", indent) .. "{\n"
  322.  
  323. for key, value in pairs(tbl) do
  324.  
  325. local formattedKey = type(key) == "string" and string.format("%q", key) or tostring(key)
  326.  
  327. if type(value) == "table" then
  328.  
  329. toString = toString ..
  330.  
  331. string.rep(" ", indent + 1) ..
  332.  
  333. "[" .. formattedKey .. "] = " .. tableToString(value, indent + 1) .. ",\n"
  334.  
  335. else
  336.  
  337. local formattedValue = type(value) == "string" and string.format("%q", value) or tostring(value)
  338.  
  339. toString = toString ..
  340.  
  341. string.rep(" ", indent + 1) .. "[" .. formattedKey .. "] = " .. formattedValue .. ",\n"
  342.  
  343. end
  344.  
  345. end
  346.  
  347. return toString .. string.rep(" ", indent) .. "}"
  348.  
  349. end
  350.  
  351.  
  352.  
  353. function writeToLogFile(fileName, equipment_list, builder_list, others_list)
  354.  
  355. local file = io.open(fileName, "w") -- Open file in write mode
  356.  
  357.  
  358.  
  359. if not file then
  360.  
  361. error("Could not open file for writing: " .. fileName)
  362.  
  363. end
  364.  
  365.  
  366.  
  367. -- Write the contents of each list
  368.  
  369. file:write("Equipment List:\n")
  370.  
  371. file:write(tableToString(equipment_list) .. "\n\n")
  372.  
  373.  
  374.  
  375. file:write("Builder List:\n")
  376.  
  377. file:write(tableToString(builder_list) .. "\n\n")
  378.  
  379.  
  380.  
  381. file:write("Others List:\n")
  382.  
  383. file:write(tableToString(others_list) .. "\n\n")
  384.  
  385.  
  386.  
  387. file:close() -- Close the file
  388.  
  389. end
  390.  
  391.  
  392.  
  393. local function ensure_width(line, width)
  394.  
  395. width = width or term.getSize()
  396.  
  397.  
  398.  
  399. line = line:sub(1, width)
  400.  
  401. if #line < width then
  402.  
  403. line = line .. (" "):rep(width - #line)
  404.  
  405. end
  406.  
  407.  
  408.  
  409. return line
  410.  
  411. end
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419. ----------------------------------------------------------------------------
  420.  
  421. --* CHECK REQUIREMENTS
  422.  
  423. ----------------------------------------------------------------------------
  424.  
  425.  
  426.  
  427. local monitor = peripheral.find("monitor")
  428.  
  429. local colony
  430.  
  431. local bridge
  432.  
  433. local storage
  434.  
  435.  
  436.  
  437.  
  438.  
  439. function getPeripheral(type)
  440.  
  441. local peripheral = peripheral.find(type)
  442.  
  443. if not peripheral then
  444.  
  445. logToFile(type .. " peripheral not found.", "WARN_")
  446.  
  447. return nil
  448.  
  449. end
  450.  
  451.  
  452.  
  453. logToFile(type .. " peripheral found.")
  454.  
  455.  
  456.  
  457. return peripheral
  458.  
  459. end
  460.  
  461.  
  462.  
  463. function updatePeripheralMonitor()
  464.  
  465. monitor = getPeripheral("monitor")
  466.  
  467.  
  468.  
  469. if monitor then
  470.  
  471. return true
  472.  
  473. else
  474.  
  475. return false
  476.  
  477. end
  478.  
  479. end
  480.  
  481.  
  482.  
  483. function checkMonitorSize()
  484.  
  485. monitor.setTextScale(0.5)
  486.  
  487. local width, height = monitor.getSize()
  488.  
  489.  
  490.  
  491. if width < 79 or height < 38 then
  492.  
  493. logToFile("Use more Monitors! (min 4x3)", "WARN_")
  494.  
  495.  
  496.  
  497. return false
  498.  
  499. end
  500.  
  501.  
  502.  
  503. return true
  504.  
  505. end
  506.  
  507.  
  508.  
  509. function updatePeripheralColonyIntegrator()
  510. colony = getPeripheral("colonyIntegrator") or getPeripheral("colony_integrator")
  511.  
  512. if colony then
  513. return true
  514. else
  515. return false
  516. end
  517. end
  518.  
  519. function getStorageBridge()
  520. local meBridge = getPeripheral("meBridge") or getPeripheral("me_bridge")
  521. local rsBridge = getPeripheral("rsBridge") or getPeripheral("rs_bridge")
  522.  
  523. if meBridge then
  524. return meBridge
  525. elseif rsBridge then
  526. return rsBridge
  527. else
  528. logToFile("Neither ME Storage Bridge nor RS Storage Bridge found.", "WARN_")
  529.  
  530. return nil
  531. end
  532. end
  533.  
  534.  
  535.  
  536. function updatePeripheralStorageBridge()
  537.  
  538. bridge = getStorageBridge()
  539.  
  540.  
  541.  
  542. if bridge then
  543.  
  544. return true
  545.  
  546. else
  547.  
  548. return false
  549.  
  550. end
  551.  
  552. end
  553.  
  554.  
  555.  
  556. function autodetectStorage()
  557.  
  558. for _, side in pairs(peripheral.getNames()) do
  559.  
  560. if peripheral.hasType(side, "inventory") then
  561.  
  562. logToFile("Storage detected on " .. side)
  563.  
  564.  
  565.  
  566. return side
  567.  
  568. end
  569.  
  570. end
  571.  
  572. logToFile("No storage container detected!", "WARN_")
  573.  
  574.  
  575.  
  576. return nil
  577.  
  578. end
  579.  
  580.  
  581.  
  582. function updatePeripheralStorage()
  583.  
  584. storage = autodetectStorage()
  585.  
  586.  
  587.  
  588. if storage then
  589.  
  590. return true
  591.  
  592. else
  593.  
  594. return false
  595.  
  596. end
  597.  
  598. end
  599.  
  600.  
  601.  
  602. ----------------------------------------------------------------------------
  603.  
  604. -- MONITOR DASHBOARD NAME
  605.  
  606. ----------------------------------------------------------------------------
  607.  
  608.  
  609.  
  610. -- 1st line on dashboard with color changing depending on the refreshInterval
  611.  
  612. -- Reset through a rainbow
  613.  
  614.  
  615.  
  616. local dashboardName = "MineColonies DASHBOARD"
  617.  
  618.  
  619.  
  620. local rainbowColors = {
  621.  
  622. colors.red, colors.orange, colors.yellow,
  623.  
  624. colors.green, colors.cyan, colors.blue,
  625.  
  626. colors.purple, colors.magenta, colors.pink
  627.  
  628.  
  629.  
  630. }
  631.  
  632.  
  633.  
  634.  
  635.  
  636. function monitorDisplayDashboardName(monitor, y, text, colorsTable)
  637.  
  638. local w, h = monitor.getSize()
  639.  
  640. local x = math.floor((w - #text) / 2) + 1
  641.  
  642.  
  643.  
  644. for i = 1, #text do
  645.  
  646. local char = text:sub(i, i)
  647.  
  648. local color = colorsTable[i]
  649.  
  650. monitor.setTextColor(color)
  651.  
  652. monitor.setCursorPos(x + i - 1, y)
  653.  
  654. monitor.write(char)
  655.  
  656. sleep(0.01)
  657.  
  658. end
  659.  
  660. end
  661.  
  662.  
  663.  
  664. function dashboardGenerateTransitionColors(progress, length)
  665.  
  666. local colorsTable = {}
  667.  
  668. local threshold = math.floor((progress) * length)
  669.  
  670.  
  671.  
  672. for i = 1, length do
  673.  
  674. if i <= threshold then
  675.  
  676. table.insert(colorsTable, colors.orange)
  677.  
  678. else
  679.  
  680. table.insert(colorsTable, colors.white)
  681.  
  682. end
  683.  
  684. end
  685.  
  686.  
  687.  
  688. return colorsTable
  689.  
  690. end
  691.  
  692.  
  693.  
  694. function dashboardGenerateRainbowColors(baseColors, length)
  695.  
  696. local result = {}
  697.  
  698. local totalColors = #baseColors
  699.  
  700.  
  701.  
  702. for i = 1, length do
  703.  
  704. result[i] = baseColors[((i - 1) % totalColors) + 1]
  705.  
  706. end
  707.  
  708.  
  709.  
  710. return result
  711.  
  712. end
  713.  
  714.  
  715.  
  716. function monitorDashboardName()
  717.  
  718. local startTime = os.clock()
  719.  
  720. local y = 1
  721.  
  722.  
  723.  
  724. while true do
  725.  
  726. local elapsedTime = os.clock() - startTime
  727.  
  728. local progress = math.min(elapsedTime / (refreshInterval - 1), 1)
  729.  
  730.  
  731.  
  732. if elapsedTime >= refreshInterval then
  733.  
  734. sleep(0.5)
  735.  
  736.  
  737.  
  738. local rainbowColorsTable = dashboardGenerateRainbowColors(rainbowColors, #dashboardName)
  739.  
  740.  
  741.  
  742. monitorDisplayDashboardName(monitor, y, dashboardName, rainbowColorsTable)
  743.  
  744. sleep(0.1)
  745.  
  746. else
  747.  
  748. local colorsTable = dashboardGenerateTransitionColors(progress, #dashboardName)
  749.  
  750.  
  751.  
  752. monitorDisplayDashboardName(monitor, y, dashboardName, colorsTable)
  753.  
  754. sleep(0.1)
  755.  
  756. end
  757.  
  758.  
  759.  
  760.  
  761.  
  762. if elapsedTime >= refreshInterval then
  763.  
  764. break
  765.  
  766. end
  767.  
  768. end
  769.  
  770. end
  771.  
  772.  
  773.  
  774. ----------------------------------------------------------------------------
  775.  
  776. --* ART
  777.  
  778. ----------------------------------------------------------------------------
  779.  
  780.  
  781.  
  782. local artUltimateCCxM_Logo = [[
  783.  
  784. _ _ _ _ _ _
  785.  
  786. | | | | | |_(_)_ __ ___ __ _| |_ ___
  787.  
  788. | | | | | __| | '_ ` _ \ / _` | __/ _ \
  789.  
  790. | |_| | | |_| | | | | | | (_| | || __/
  791.  
  792. \____|_____|_|_| |_|___|_____|\__\___|
  793.  
  794. / ___/ ___|__ __| \/ (_)_ __ ___
  795.  
  796. | | | | \ \/ /| |\/| | | '_ \ / _ \
  797.  
  798. | |__| |___ > < | | | | | | | | __/
  799.  
  800. \____\____|/_/\_\|_| |_|_|_| |_|\___|
  801.  
  802. / ___|___ | | ___ _ __ (_) ___ ___
  803.  
  804. | | / _ \| |/ _ \| '_ \| |/ _ \/ __|
  805.  
  806. | |__| (_) | | (_) | | | | | __/\__ \
  807.  
  808. \____\___/|_|\___/|_| |_|_|\___||___/
  809.  
  810. ]]
  811.  
  812.  
  813.  
  814.  
  815.  
  816. ----------------------------------------------------------------------------
  817.  
  818. --* MONITOR OR TERMINAL OUTPUT
  819.  
  820. ----------------------------------------------------------------------------
  821.  
  822.  
  823.  
  824. function resetDefault(screen)
  825.  
  826. screen.setTextColor(colors.white)
  827.  
  828. screen.setBackgroundColor(colors.black)
  829.  
  830. screen.setCursorPos(1, 1)
  831.  
  832. screen.clear()
  833.  
  834. end
  835.  
  836.  
  837.  
  838. function drawLoadingBar(screen, x, y, width, progress, bgColor, barColor)
  839.  
  840. screen.setBackgroundColor(bgColor or colors.gray)
  841.  
  842. screen.setTextColor(colors.white)
  843.  
  844. screen.setCursorPos(x, y)
  845.  
  846.  
  847.  
  848. -- Draw the empty bar
  849.  
  850. screen.write(string.rep(" ", width))
  851.  
  852.  
  853.  
  854. -- Draw the filled part
  855.  
  856. local filledWidth = math.floor(progress * width)
  857.  
  858. screen.setCursorPos(x, y)
  859.  
  860. screen.setBackgroundColor(barColor or colors.green)
  861.  
  862. screen.write(string.rep(" ", filledWidth))
  863.  
  864. end
  865.  
  866.  
  867.  
  868. ----------------------------------------------------------------------------
  869.  
  870. --* MONITOR OUTPUT
  871.  
  872. ----------------------------------------------------------------------------
  873.  
  874. local x, y = 1, 1
  875.  
  876. function monitorDisplayArt(asciiArt, monitor_)
  877.  
  878. monitor_.clear()
  879.  
  880.  
  881.  
  882. local x, y = 1, 2
  883.  
  884.  
  885.  
  886. for line in asciiArt:gmatch("[^\n]+") do
  887.  
  888. monitor_.setCursorPos(x, y)
  889.  
  890. monitor_.write(line)
  891.  
  892. y = y + 1
  893.  
  894. end
  895.  
  896. end
  897.  
  898.  
  899.  
  900. function monitorLoadingAnimation()
  901.  
  902. resetDefault(monitor)
  903.  
  904.  
  905.  
  906. monitor.setTextScale(1)
  907.  
  908.  
  909.  
  910. local width, height = monitor.getSize()
  911.  
  912.  
  913.  
  914. local barWidth = math.floor(width * 0.9)
  915.  
  916. local barX = math.floor((width - barWidth) / 2 + 1)
  917.  
  918. local barHeight = 17
  919.  
  920.  
  921.  
  922. monitor.setTextColor(colors.orange)
  923.  
  924. monitor.setCursorPos(1, 1)
  925.  
  926.  
  927.  
  928. monitorDisplayArt(artUltimateCCxM_Logo, monitor)
  929.  
  930.  
  931.  
  932. local barSpeed = 30
  933.  
  934. for i = 0, barSpeed do
  935.  
  936. local progress = i / barSpeed
  937.  
  938. drawLoadingBar(monitor, barX, barHeight, barWidth, progress, colors.gray, colors.orange)
  939.  
  940. sleep(0.1)
  941.  
  942. end
  943.  
  944.  
  945.  
  946.  
  947.  
  948.  
  949.  
  950. resetDefault(monitor)
  951.  
  952.  
  953.  
  954. monitor.setTextScale(0.5)
  955.  
  956. end
  957.  
  958.  
  959.  
  960. function monitorPrintText(y, pos, text, ...)
  961.  
  962. local w, h = monitor.getSize()
  963.  
  964. local fg = monitor.getTextColor()
  965.  
  966. local bg = monitor.getBackgroundColor()
  967.  
  968.  
  969.  
  970. local x = 1
  971.  
  972. if pos == "left" then
  973.  
  974. x = 4
  975.  
  976. text = ensure_width(text, math.floor(w / 2) - 2)
  977.  
  978. elseif pos == "center" then
  979.  
  980. x = math.floor((w - #text) / 2)
  981.  
  982. elseif pos == "right" then
  983.  
  984. x = w - #text - 2
  985.  
  986. elseif pos == "middle" then
  987.  
  988. x = math.floor((w - #text) / 2)
  989.  
  990. y = math.floor(h / 2) - 2
  991.  
  992. end
  993.  
  994.  
  995.  
  996. if select("#", ...) > 0 then
  997.  
  998. monitor.setTextColor(select(1, ...))
  999.  
  1000. end
  1001.  
  1002. if select("#", ...) > 1 then
  1003.  
  1004. monitor.setBackgroundColor(select(2, ...))
  1005.  
  1006. end
  1007.  
  1008.  
  1009.  
  1010. monitor.setCursorPos(x, y)
  1011.  
  1012. monitor.write(text)
  1013.  
  1014. monitor.setTextColor(fg)
  1015.  
  1016. monitor.setBackgroundColor(bg)
  1017.  
  1018. end
  1019.  
  1020.  
  1021.  
  1022. function drawBox(xMin, xMax, yMin, yMax, title, bcolor, tcolor)
  1023.  
  1024. monitor.setBackgroundColor(bcolor)
  1025.  
  1026. for xPos = xMin, xMax, 1 do
  1027.  
  1028. monitor.setCursorPos(xPos, yMin)
  1029.  
  1030. monitor.write(" ")
  1031.  
  1032. end
  1033.  
  1034. for yPos = yMin, yMax, 1 do
  1035.  
  1036. monitor.setCursorPos(xMin, yPos)
  1037.  
  1038. monitor.write(" ")
  1039.  
  1040. monitor.setCursorPos(xMax, yPos)
  1041.  
  1042. monitor.write(" ")
  1043.  
  1044. end
  1045.  
  1046. for xPos = xMin, xMax, 1 do
  1047.  
  1048. monitor.setCursorPos(xPos, yMax)
  1049.  
  1050. monitor.write(" ")
  1051.  
  1052. end
  1053.  
  1054. monitor.setCursorPos(xMin + 2, yMin)
  1055.  
  1056. monitor.setBackgroundColor(colors.black)
  1057.  
  1058. monitor.setTextColor(tcolor)
  1059.  
  1060. monitor.write(" ")
  1061.  
  1062. monitor.write(title)
  1063.  
  1064. monitor.write(" ")
  1065.  
  1066. monitor.setTextColor(colors.white)
  1067.  
  1068. end
  1069.  
  1070.  
  1071.  
  1072. function monitorDashboardRequests(equipment_list, builder_list, others_list)
  1073.  
  1074. local x, y = monitor.getSize()
  1075.  
  1076.  
  1077.  
  1078. local equipment_count = #equipment_list
  1079.  
  1080. local builder_count = #builder_list
  1081.  
  1082. local others_count = #others_list
  1083.  
  1084.  
  1085.  
  1086.  
  1087.  
  1088.  
  1089.  
  1090. drawBox(2, x - 1, 3, (equipment_count + math.ceil(builder_count / 2) + others_count) + 11, "REQUESTS", colors.gray,
  1091.  
  1092. colors.purple)
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098. --Builder
  1099.  
  1100. monitorPrintText(5, "center", "Builder", colors.orange)
  1101.  
  1102. local half = math.ceil(builder_count / 2)
  1103.  
  1104.  
  1105.  
  1106. for i = 1, half do
  1107.  
  1108. local item = builder_list[i]
  1109.  
  1110. if item then
  1111.  
  1112. monitorPrintText(i + 5, "left", (item.provided .. "/" .. item.name), item.displayColor)
  1113.  
  1114. end
  1115.  
  1116. end
  1117.  
  1118.  
  1119.  
  1120. for i = half + 1, builder_count do
  1121.  
  1122. local item = builder_list[i]
  1123.  
  1124. if item then
  1125.  
  1126. monitorPrintText(i - half + 5, "right", (item.provided .. "/" .. item.name),
  1127.  
  1128. item.displayColor)
  1129.  
  1130. end
  1131.  
  1132. end
  1133.  
  1134.  
  1135.  
  1136.  
  1137.  
  1138. --Equipment
  1139.  
  1140. monitorPrintText(math.ceil(builder_count / 2) + 7, "center", "Equipment", colors.orange)
  1141.  
  1142. for i, item in pairs(equipment_list) do
  1143.  
  1144. monitorPrintText(math.ceil(builder_count / 2) + i + 7, "left", item.name, item.displayColor)
  1145.  
  1146. monitorPrintText(math.ceil(builder_count / 2) + i + 7, "right", item.target, colors.lightGray)
  1147.  
  1148. end
  1149.  
  1150.  
  1151.  
  1152.  
  1153.  
  1154. --Others
  1155.  
  1156. monitorPrintText(equipment_count + math.ceil(builder_count / 2) + 9, "center", "Other", colors.orange)
  1157.  
  1158. for i, item in pairs(others_list) do
  1159.  
  1160. monitorPrintText(i + equipment_count + math.ceil(builder_count / 2) + 9, "left",
  1161.  
  1162. (item.provided .. "/" .. item.name),
  1163.  
  1164. item.displayColor)
  1165.  
  1166. monitorPrintText(i + equipment_count + math.ceil(builder_count / 2) + 9, "right", item.target, colors.lightGray)
  1167.  
  1168. end
  1169.  
  1170. end
  1171.  
  1172.  
  1173.  
  1174. ----------------------------------------------------------------------------
  1175.  
  1176. --* TERMINAL OUTPUT
  1177.  
  1178. ----------------------------------------------------------------------------
  1179.  
  1180. local termWidth, termHeight = term.getSize()
  1181.  
  1182. local needTermDrawRequirements = true
  1183.  
  1184. local needTermDrawRequirements_executed = false
  1185.  
  1186.  
  1187.  
  1188. function termDisplayArt(asciiArt)
  1189.  
  1190. term.clear()
  1191.  
  1192.  
  1193.  
  1194. local x, y = 6, 2
  1195.  
  1196.  
  1197.  
  1198. for line in asciiArt:gmatch("[^\n]+") do
  1199.  
  1200. term.setCursorPos(x, y)
  1201.  
  1202. term.write(line)
  1203.  
  1204. y = y + 1
  1205.  
  1206. end
  1207.  
  1208. end
  1209.  
  1210.  
  1211.  
  1212. -- Function to simulate the loading process
  1213.  
  1214. function termLoadingAnimation()
  1215.  
  1216. resetDefault(term)
  1217.  
  1218.  
  1219.  
  1220. local width, height = term.getSize()
  1221.  
  1222.  
  1223.  
  1224. local barWidth = math.floor(width * 0.8)
  1225.  
  1226. local barX = math.floor((width - barWidth) / 2 + 1)
  1227.  
  1228. local barHeight = math.floor(height * 0.9)
  1229.  
  1230.  
  1231.  
  1232. term.setTextColor(colors.orange)
  1233.  
  1234. term.setCursorPos(1, 1)
  1235.  
  1236.  
  1237.  
  1238. termDisplayArt(artUltimateCCxM_Logo)
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244. local barSpeed = 25
  1245.  
  1246. for i = 0, barSpeed do
  1247.  
  1248. local progress = i / barSpeed
  1249.  
  1250. drawLoadingBar(term, barX, barHeight, barWidth, progress, colors.gray, colors.orange)
  1251.  
  1252. sleep(0.1)
  1253.  
  1254. end
  1255.  
  1256.  
  1257.  
  1258. resetDefault(term)
  1259.  
  1260. end
  1261.  
  1262.  
  1263.  
  1264. function termDrawProgramReq_helper(y, isRequirementMet)
  1265.  
  1266. if isRequirementMet then
  1267.  
  1268. term.setTextColor(colors.green)
  1269.  
  1270. term.setCursorPos(49, y)
  1271.  
  1272. term.write("[O]")
  1273.  
  1274. else
  1275.  
  1276. term.setTextColor(colors.red)
  1277.  
  1278. term.setCursorPos(49, y)
  1279.  
  1280. term.write("[X]")
  1281.  
  1282. end
  1283.  
  1284.  
  1285.  
  1286. term.setTextColor(colors.white)
  1287.  
  1288. end
  1289.  
  1290.  
  1291.  
  1292. function termDrawProgramReq_Header()
  1293.  
  1294. local text_Divider = "-------------------------------------------------------"
  1295.  
  1296. term.setCursorPos(math.floor((termWidth - #text_Divider) / 2) + 1, 4)
  1297.  
  1298.  
  1299.  
  1300. term.write(text_Divider)
  1301.  
  1302.  
  1303.  
  1304. local text_Requirements = "\187 Program Requirements \171"
  1305.  
  1306. term.setCursorPos(math.floor((termWidth - #text_Requirements) / 2) + 1, 2)
  1307.  
  1308.  
  1309.  
  1310. textutils.slowWrite(text_Requirements, 16)
  1311.  
  1312. end
  1313.  
  1314.  
  1315.  
  1316. function termDrawCheckRequirements()
  1317.  
  1318. if not needTermDrawRequirements_executed then
  1319.  
  1320. term.clear()
  1321.  
  1322. end
  1323.  
  1324.  
  1325.  
  1326. local text_Monitor_1 = "\16 Monitor attached"
  1327.  
  1328. term.setCursorPos(2, 6)
  1329.  
  1330. term.write(text_Monitor_1)
  1331.  
  1332.  
  1333.  
  1334. local text_Monitor_2 = "\16 Monitor size (min 4x3)"
  1335.  
  1336. term.setCursorPos(2, 8)
  1337.  
  1338. term.write(text_Monitor_2)
  1339.  
  1340.  
  1341.  
  1342. local text_Colony_1 = "\16 Colony Integrator attached"
  1343.  
  1344. term.setCursorPos(2, 10)
  1345.  
  1346. term.write(text_Colony_1)
  1347.  
  1348.  
  1349.  
  1350. local text_Colony_2 = "\16 Colony Integrator in a colony"
  1351.  
  1352. term.setCursorPos(2, 12)
  1353.  
  1354. term.write(text_Colony_2)
  1355.  
  1356.  
  1357.  
  1358. local text_StoargeBridge = "\16 ME or RS Bridge attached"
  1359.  
  1360. term.setCursorPos(2, 14)
  1361.  
  1362. term.write(text_StoargeBridge)
  1363.  
  1364.  
  1365.  
  1366. local text_Stoarge = "\16 Storage/Warehouse attached"
  1367.  
  1368. term.setCursorPos(2, 16)
  1369.  
  1370. term.write(text_Stoarge)
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380. if updatePeripheralMonitor() then
  1381.  
  1382. termDrawProgramReq_helper(6, true)
  1383.  
  1384.  
  1385.  
  1386. if checkMonitorSize() then
  1387.  
  1388. termDrawProgramReq_helper(8, true)
  1389.  
  1390. else
  1391.  
  1392. termDrawProgramReq_helper(8, false)
  1393.  
  1394. end
  1395.  
  1396. else
  1397.  
  1398. termDrawProgramReq_helper(6, false)
  1399.  
  1400. termDrawProgramReq_helper(8, false)
  1401.  
  1402. end
  1403.  
  1404.  
  1405.  
  1406.  
  1407.  
  1408. if updatePeripheralColonyIntegrator() then
  1409.  
  1410. termDrawProgramReq_helper(10, true)
  1411.  
  1412.  
  1413.  
  1414. if colony.isInColony() then
  1415.  
  1416. termDrawProgramReq_helper(12, true)
  1417.  
  1418. else
  1419.  
  1420. termDrawProgramReq_helper(12, false)
  1421.  
  1422. end
  1423.  
  1424. else
  1425.  
  1426. termDrawProgramReq_helper(10, false)
  1427.  
  1428. termDrawProgramReq_helper(12, false)
  1429.  
  1430. end
  1431.  
  1432.  
  1433.  
  1434.  
  1435.  
  1436. if updatePeripheralStorageBridge() then
  1437.  
  1438. termDrawProgramReq_helper(14, true)
  1439.  
  1440. else
  1441.  
  1442. termDrawProgramReq_helper(14, false)
  1443.  
  1444. end
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450. if updatePeripheralStorage() then
  1451.  
  1452. termDrawProgramReq_helper(16, true)
  1453.  
  1454. else
  1455.  
  1456. termDrawProgramReq_helper(16, false)
  1457.  
  1458. end
  1459.  
  1460.  
  1461.  
  1462. if not needTermDrawRequirements_executed then
  1463.  
  1464. termDrawProgramReq_Header()
  1465.  
  1466. needTermDrawRequirements_executed = true
  1467.  
  1468. end
  1469.  
  1470.  
  1471.  
  1472.  
  1473.  
  1474.  
  1475.  
  1476. if updatePeripheralMonitor() and updatePeripheralColonyIntegrator() and updatePeripheralStorageBridge() and updatePeripheralStorage() then
  1477.  
  1478. if checkMonitorSize() and colony.isInColony() then
  1479.  
  1480. termDrawProgramReq_helper(6, true)
  1481.  
  1482. termDrawProgramReq_helper(8, true)
  1483.  
  1484. termDrawProgramReq_helper(10, true)
  1485.  
  1486. termDrawProgramReq_helper(12, true)
  1487.  
  1488. termDrawProgramReq_helper(14, true)
  1489.  
  1490. termDrawProgramReq_helper(16, true)
  1491.  
  1492.  
  1493.  
  1494. needTermDrawRequirements = false
  1495.  
  1496. needTermDrawRequirements_executed = false
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502. local text_RequirementsFullfilled = "Requirements fullfilled"
  1503.  
  1504. term.setCursorPos(math.floor((termWidth - #text_RequirementsFullfilled) / 2), 19)
  1505.  
  1506. term.setTextColor(colors.green)
  1507.  
  1508. sleep(0.5)
  1509.  
  1510. textutils.slowWrite(text_RequirementsFullfilled, 16)
  1511.  
  1512. textutils.slowWrite(" . . .", 5)
  1513.  
  1514. sleep(1)
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520. -- Cleanup
  1521.  
  1522. term.setTextColor(colors.white)
  1523.  
  1524. term.clear()
  1525.  
  1526. term.setCursorPos(1, 1)
  1527.  
  1528.  
  1529.  
  1530. return true
  1531.  
  1532. end
  1533.  
  1534. end
  1535.  
  1536.  
  1537.  
  1538. return true
  1539.  
  1540. end
  1541.  
  1542.  
  1543.  
  1544. function termShowLog()
  1545.  
  1546. term.setCursorPos(1, 1)
  1547.  
  1548. term.clearLine()
  1549.  
  1550. term.setCursorPos(1, 2)
  1551.  
  1552. term.clearLine()
  1553.  
  1554. term.setCursorPos(1, 3)
  1555.  
  1556. term.clearLine()
  1557.  
  1558.  
  1559.  
  1560.  
  1561.  
  1562. local text_Divider = "-------------------------------------------------------"
  1563.  
  1564. term.setCursorPos(math.floor((termWidth - #text_Divider) / 2) + 1, 4)
  1565.  
  1566. term.write(text_Divider)
  1567.  
  1568.  
  1569.  
  1570. local text_Requirements = "\187 MineColonies Logs \171"
  1571.  
  1572. term.setCursorPos(math.floor((termWidth - #text_Requirements) / 2) + 1, 2)
  1573.  
  1574. textutils.slowWrite(text_Requirements, 16)
  1575.  
  1576. end
  1577.  
  1578.  
  1579.  
  1580. ----------------------------------------------------------------------------
  1581.  
  1582. --* MINECOLONIES
  1583.  
  1584. ----------------------------------------------------------------------------
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.  
  1591.  
  1592. local function isEquipment(desc)
  1593.  
  1594. local equipmentKeywords = { "Sword ", "Bow ", "Pickaxe ", "Axe ", "Shovel ", "Hoe ", "Shears ", "Helmet ",
  1595.  
  1596. "Chestplate ", "Leggings ", "Boots " }
  1597.  
  1598.  
  1599.  
  1600. for _, keyword in ipairs(equipmentKeywords) do
  1601.  
  1602. if string.find(desc, keyword) then
  1603.  
  1604. return true
  1605.  
  1606. end
  1607.  
  1608. end
  1609.  
  1610. return false
  1611.  
  1612. end
  1613.  
  1614.  
  1615.  
  1616. function colonyCategorizeRequests()
  1617.  
  1618. local equipment_list = {}
  1619.  
  1620. local builder_list = {}
  1621.  
  1622. local others_list = {}
  1623.  
  1624.  
  1625.  
  1626. for _, req in ipairs(colony.getRequests()) do
  1627.  
  1628. local name = req.name
  1629.  
  1630. local target = req.target or ""
  1631.  
  1632. local desc = req.desc or ""
  1633.  
  1634. local count = req.count
  1635.  
  1636. local item_displayName = trimLeadingWhitespace(req.items[1].displayName)
  1637.  
  1638. local item_name = req.items[1].name
  1639.  
  1640. local itemIsEquipment = isEquipment(desc)
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646. -- Equipment Categorization
  1647.  
  1648. if itemIsEquipment then
  1649.  
  1650. local levelTable = {
  1651.  
  1652. ["and with maximal level: Leather"] = "Leather",
  1653.  
  1654. ["and with maximal level: Stone"] = "Stone",
  1655.  
  1656. ["and with maximal level: Chain"] = "Chain",
  1657.  
  1658. ["and with maximal level: Gold"] = "Gold",
  1659.  
  1660. ["and with maximal level: Iron"] = "Iron",
  1661.  
  1662. ["and with maximal level: Diamond"] = "Diamond",
  1663.  
  1664.  
  1665.  
  1666. ["with maximal level: Wood or Gold"] = "Wood or Gold"
  1667.  
  1668. }
  1669.  
  1670.  
  1671.  
  1672. local level = "Any Level"
  1673.  
  1674.  
  1675.  
  1676. for pattern, mappedLevel in pairs(levelTable) do
  1677.  
  1678. if string.find(desc, pattern) then
  1679.  
  1680. level = mappedLevel
  1681.  
  1682. break
  1683.  
  1684. end
  1685.  
  1686. end
  1687.  
  1688.  
  1689.  
  1690. local new_name = level .. " " .. name
  1691.  
  1692.  
  1693.  
  1694. table.insert(equipment_list, {
  1695.  
  1696. name = new_name,
  1697.  
  1698. target = target,
  1699.  
  1700. count = count,
  1701.  
  1702. item_displayName = item_displayName,
  1703.  
  1704. item_name = item_name,
  1705.  
  1706. desc = desc,
  1707.  
  1708. provided = 0,
  1709.  
  1710. isCraftable = false,
  1711.  
  1712. equipment = itemIsEquipment,
  1713.  
  1714. displayColor = colors.white,
  1715.  
  1716. level = level
  1717.  
  1718. })
  1719.  
  1720.  
  1721.  
  1722. -- Builder Categorization
  1723.  
  1724. elseif string.find(target, "Builder") then
  1725.  
  1726. table.insert(builder_list, {
  1727.  
  1728. name = name,
  1729.  
  1730. target = target,
  1731.  
  1732. count = count,
  1733.  
  1734. item_displayName = item_displayName,
  1735.  
  1736. item_name = item_name,
  1737.  
  1738. desc = desc,
  1739.  
  1740. provided = 0,
  1741.  
  1742. isCraftable = false,
  1743.  
  1744. equipment = itemIsEquipment,
  1745.  
  1746. displayColor = colors.white,
  1747.  
  1748. level = ""
  1749.  
  1750. })
  1751.  
  1752.  
  1753.  
  1754. -- Non-Builder Categorization
  1755.  
  1756. else
  1757.  
  1758. table.insert(others_list, {
  1759.  
  1760. name = name,
  1761.  
  1762. target = target,
  1763.  
  1764. count = count,
  1765.  
  1766. item_displayName = item_displayName,
  1767.  
  1768. item_name = item_name,
  1769.  
  1770. desc = desc,
  1771.  
  1772. provided = 0,
  1773.  
  1774. isCraftable = false,
  1775.  
  1776. equipment = itemIsEquipment,
  1777.  
  1778. displayColor = colors.white,
  1779.  
  1780. level = ""
  1781.  
  1782. })
  1783.  
  1784. end
  1785.  
  1786. end
  1787.  
  1788.  
  1789.  
  1790. return equipment_list, builder_list, others_list
  1791.  
  1792. end
  1793.  
  1794.  
  1795.  
  1796. ----------------------------------------------------------------------------
  1797.  
  1798. --* STORAGE SYSTEM REQUEST AND SEND
  1799.  
  1800. ----------------------------------------------------------------------------
  1801.  
  1802.  
  1803.  
  1804. -- Color code: red = not available
  1805.  
  1806. -- yellow = stuck
  1807.  
  1808. -- blue = crafting
  1809.  
  1810. -- green = fully exported
  1811.  
  1812.  
  1813.  
  1814. -- Try or skip equipment craft
  1815.  
  1816. local b_craftEquipment = true
  1817.  
  1818.  
  1819.  
  1820. -- Choose "Iron" or "Diamond" or "Iron and Diamond"
  1821.  
  1822. local craftEquipmentOfLevel = "Iron"
  1823.  
  1824.  
  1825.  
  1826. function equipmentCraft(name, level, item_name)
  1827.  
  1828. if (item_name == "minecraft:bow") then
  1829.  
  1830. return item_name, true
  1831.  
  1832. end
  1833.  
  1834.  
  1835.  
  1836. if (level == "Iron" or level == "Iron and Diamond" or level == "Any Level") and (craftEquipmentOfLevel == "Iron" or craftEquipmentOfLevel == "Iron and Diamond") then
  1837.  
  1838. if level == "Any Level" then
  1839.  
  1840. level = "Iron"
  1841.  
  1842. end
  1843.  
  1844.  
  1845.  
  1846. item_name = string.lower("minecraft:" .. level .. "_" .. getLastWord(name))
  1847.  
  1848.  
  1849.  
  1850. return item_name, true
  1851.  
  1852. elseif (level == "Diamond" or level == "Iron and Diamond" or level == "Any Level") and craftEquipmentOfLevel == "Diamond" then
  1853.  
  1854. if level == "Any Level" then
  1855.  
  1856. level = "Diamond"
  1857.  
  1858. end
  1859.  
  1860.  
  1861.  
  1862. item_name = string.lower("minecraft:" .. level .. "_" .. getLastWord(name))
  1863.  
  1864. return item_name, true
  1865.  
  1866. end
  1867.  
  1868.  
  1869.  
  1870. return item_name, false
  1871.  
  1872. end
  1873.  
  1874.  
  1875.  
  1876. function storageSystemHandleRequests(request_list)
  1877.  
  1878. for _, item in ipairs(request_list) do
  1879.  
  1880. local itemStored = 0
  1881.  
  1882. local b_CurrentlyCrafting = false
  1883.  
  1884. local b_equipmentCraft = true
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890. if item.equipment then
  1891.  
  1892. item.item_name, b_equipmentCraft = equipmentCraft(item.name, item.level, item.item_name)
  1893.  
  1894. end
  1895.  
  1896.  
  1897.  
  1898. --getItem() to see if item in system (if not, error), count and if craftable
  1899.  
  1900. b_functionGetItem = safeCall(function()
  1901.  
  1902. itemStored = (bridge.getItem({ name = item.item_name })).count or 0
  1903.  
  1904. item.isCraftable = (bridge.getItem({ name = item.item_name })).isCraftable
  1905.  
  1906. end)
  1907.  
  1908.  
  1909.  
  1910. if not b_functionGetItem then
  1911.  
  1912. logToFile(item.item_displayName .. " isn't in system and isn't craftable.", "WARN_", true)
  1913.  
  1914.  
  1915.  
  1916. item.displayColor = colors.red
  1917.  
  1918.  
  1919.  
  1920. goto continue
  1921.  
  1922. end
  1923.  
  1924.  
  1925.  
  1926. if not (itemStored == 0) then
  1927.  
  1928. b_functionExportItemToPeripheral = safeCall(function()
  1929.  
  1930. item.provided = bridge.exportItemToPeripheral({ name = item.item_name, count = item.count }, storage)
  1931.  
  1932. end)
  1933.  
  1934.  
  1935.  
  1936. if not b_functionExportItemToPeripheral then
  1937.  
  1938. logToFile("Failed to export item.", "WARN_", true)
  1939.  
  1940. item.displayColor = colors.yellow
  1941.  
  1942. end
  1943.  
  1944.  
  1945.  
  1946. if (item.provided == item.count) then
  1947.  
  1948. item.displayColor = colors.green
  1949.  
  1950. else
  1951.  
  1952. item.displayColor = colors.yellow
  1953.  
  1954. end
  1955.  
  1956. end
  1957.  
  1958.  
  1959.  
  1960. if not b_craftEquipment and item.equipment then
  1961.  
  1962. goto continue
  1963.  
  1964. end
  1965.  
  1966.  
  1967.  
  1968. if (item.provided < item.count) and item.isCraftable and b_equipmentCraft then
  1969.  
  1970. b_functionIsItemCrafting = safeCall(function()
  1971.  
  1972. b_CurrentlyCrafting = bridge.isItemCrafting({ name = item.item_name })
  1973.  
  1974. end)
  1975.  
  1976.  
  1977.  
  1978. if not b_functionIsItemCrafting then
  1979.  
  1980. logToFile("Asking for crafting job failed.", "WARN_")
  1981.  
  1982. end
  1983.  
  1984.  
  1985.  
  1986. if b_CurrentlyCrafting then
  1987.  
  1988. item.displayColor = colors.blue
  1989.  
  1990. goto continue
  1991.  
  1992. end
  1993.  
  1994. end
  1995.  
  1996.  
  1997.  
  1998.  
  1999.  
  2000.  
  2001.  
  2002. local b_craftItem = not b_CurrentlyCrafting and item.isCraftable and (item.provided < item.count)
  2003.  
  2004.  
  2005.  
  2006. if b_craftItem then
  2007.  
  2008. -- Skip Equipments if set to false
  2009.  
  2010. if not b_craftEquipment and item.equipment then
  2011.  
  2012. goto continue
  2013.  
  2014. end
  2015.  
  2016.  
  2017.  
  2018.  
  2019.  
  2020. b_functionCraftItem = safeCall(function()
  2021.  
  2022. local craftedItem = { name = item.item_name, count = item.count - item.provided }
  2023.  
  2024.  
  2025.  
  2026. return bridge.craftItem(craftedItem)
  2027.  
  2028. end)
  2029.  
  2030.  
  2031.  
  2032. if not b_functionCraftItem then
  2033.  
  2034. logToFile("Crafting request failed. (Items missing)", "WARN_", true)
  2035.  
  2036. item.displayColor = colors.yellow
  2037.  
  2038. goto continue
  2039.  
  2040. end
  2041.  
  2042.  
  2043.  
  2044. item.displayColor = colors.blue
  2045.  
  2046. end
  2047.  
  2048.  
  2049.  
  2050. ::continue::
  2051.  
  2052. end
  2053.  
  2054. end
  2055.  
  2056.  
  2057.  
  2058. ----------------------------------------------------------------------------
  2059.  
  2060. --* MAIN LOGIC FUNCTIONS
  2061.  
  2062. ----------------------------------------------------------------------------
  2063.  
  2064.  
  2065.  
  2066. function updatePeripheralAll()
  2067.  
  2068. if not updatePeripheralMonitor() or not checkMonitorSize() then
  2069.  
  2070. needTermDrawRequirements = true
  2071.  
  2072. end
  2073.  
  2074.  
  2075.  
  2076. if not updatePeripheralColonyIntegrator() or not colony.isInColony() then
  2077.  
  2078. needTermDrawRequirements = true
  2079.  
  2080. end
  2081.  
  2082.  
  2083.  
  2084. if not updatePeripheralStorageBridge() then
  2085.  
  2086. needTermDrawRequirements = true
  2087.  
  2088. end
  2089.  
  2090.  
  2091.  
  2092. if not updatePeripheralStorage() then
  2093.  
  2094. needTermDrawRequirements = true
  2095.  
  2096. end
  2097.  
  2098.  
  2099.  
  2100.  
  2101.  
  2102. while needTermDrawRequirements do
  2103.  
  2104. termDrawCheckRequirements()
  2105.  
  2106. sleep(1)
  2107.  
  2108. end
  2109.  
  2110. end
  2111.  
  2112.  
  2113.  
  2114. function requestAndFulfill()
  2115.  
  2116. local equipment_list, builder_list, others_list = colonyCategorizeRequests()
  2117.  
  2118.  
  2119.  
  2120. writeToLogFile("log1.txt", equipment_list, builder_list, others_list)
  2121.  
  2122.  
  2123.  
  2124. storageSystemHandleRequests(equipment_list)
  2125.  
  2126.  
  2127.  
  2128. storageSystemHandleRequests(builder_list)
  2129.  
  2130.  
  2131.  
  2132. storageSystemHandleRequests(others_list)
  2133.  
  2134.  
  2135.  
  2136. writeToLogFile("log2.txt", equipment_list, builder_list, others_list)
  2137.  
  2138.  
  2139.  
  2140. return equipment_list, builder_list, others_list
  2141.  
  2142. end
  2143.  
  2144.  
  2145.  
  2146. --TODO
  2147.  
  2148. function monitorShowDashboard(equipment_list, builder_list, others_list)
  2149.  
  2150. monitor.clear()
  2151.  
  2152.  
  2153.  
  2154. monitorDashboardRequests(equipment_list, builder_list, others_list)
  2155.  
  2156.  
  2157.  
  2158. -- monitorDashboardResearch()
  2159.  
  2160.  
  2161.  
  2162. -- monitorDashboardStats()
  2163.  
  2164.  
  2165.  
  2166. monitorDashboardName()
  2167.  
  2168. end
  2169.  
  2170.  
  2171.  
  2172. ----------------------------------------------------------------------------
  2173.  
  2174. --* MAIN
  2175.  
  2176. ----------------------------------------------------------------------------
  2177.  
  2178.  
  2179.  
  2180. function main()
  2181.  
  2182. termLoadingAnimation()
  2183.  
  2184.  
  2185.  
  2186. updatePeripheralAll()
  2187.  
  2188.  
  2189.  
  2190. monitorLoadingAnimation()
  2191.  
  2192.  
  2193.  
  2194.  
  2195.  
  2196.  
  2197.  
  2198. while true do
  2199.  
  2200. updatePeripheralAll()
  2201.  
  2202.  
  2203.  
  2204. termShowLog()
  2205.  
  2206. term.setCursorPos(1, 5)
  2207.  
  2208.  
  2209.  
  2210. local equipment_list, builder_list, others_list = requestAndFulfill()
  2211.  
  2212.  
  2213.  
  2214. monitorShowDashboard(equipment_list, builder_list, others_list)
  2215.  
  2216. end
  2217.  
  2218. end
  2219.  
  2220.  
  2221.  
  2222. main()
Advertisement
Add Comment
Please, Sign In to add comment