Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("API/draw")
- --CONSTANTS--
- SCALE = 0.5
- --VARIABLES--
- --Counters
- tickCount = 0
- --Switches
- drawn = false
- monitorBool = false
- buttonInit = false
- baseBool = true
- turtleBool = false
- itemBool = false
- bpBool = false
- overlayBool = false
- facing = false
- --Lengths
- buttonLen = 15
- chunkTileX = 10
- chunkTileY = 8
- turtleTileX = 10
- turtleTileY = 9
- bpTileX = 4
- bpTileY = 3
- --UTILITY FUNCTIONS--
- function getPeripherals()
- perData = peripheral.getNames()
- for i = 1, #perData do
- if peripheral.getType(perData[i]) == "modem" then
- m = peripheral.wrap(perData[i])
- if m.isWireless() then
- wifiSide = perData[i]
- rednet.open(wifiSide)
- end
- elseif peripheral.getType(perData[i]) == "monitor" then
- mon = peripheral.wrap(perData[i])
- mon.setTextScale(SCALE)
- x, y = mon.getSize()
- end
- end
- end
- function switchMon()
- if monitorBool then
- term.restore()
- else
- term.redirect(mon)
- end
- monitorBool = not monitorBool
- end
- function debugMsg(text)
- switchMon()
- if text ~= " " then
- timeNow = os.time()
- timeStamp = textutils.formatTime(timeNow, true)
- if #timeStamp < 5 then
- timeStamp = "0"..timeStamp
- end
- term.setBackgroundColor(draw.black)
- term.setTextColor(draw.lime)
- print(timeStamp..": "..text)
- else
- print()
- end
- switchMon()
- end
- function locNames()
- cLabel = {}
- cLabel[1] = "nwnw"
- cLabel[2] = "nnw"
- cLabel[3] = "nn"
- cLabel[4] = "nne"
- cLabel[5] = "nene"
- cLabel[6] = "nww"
- cLabel[7] = "nw"
- cLabel[8] = "n"
- cLabel[9] = "ne"
- cLabel[10] = "nee"
- cLabel[11] = "ww"
- cLabel[12] = "w"
- cLabel[13] = "HQ"
- cLabel[14] = "e"
- cLabel[15] = "ee"
- cLabel[16] = "sww"
- cLabel[17] = "sw"
- cLabel[18] = "s"
- cLabel[19] = "se"
- cLabel[20] = "see"
- cLabel[21] = "swsw"
- cLabel[22] = "ssw"
- cLabel[23] = "ss"
- cLabel[24] = "sse"
- cLabel[25] = "sese"
- end
- function getStartData()
- draw.clear()
- draw.inputBox("Home chunk X pos:")
- x = tonumber(read())
- draw.inputBox("Home chunk Y pos:")
- y = tonumber(read())
- draw.inputBox("Home chunk Z pos:")
- z = tonumber(read())
- xmod = x - 32
- zmod = z - 32
- grX = 10
- grY = 2
- griMagic = {}
- for i = 1, 25 do
- griMagic[i] = {
- xPos = xmod;
- zPos = zmod;
- scrX = grX;
- scrY = grY;
- }
- if i % 5 == 0 then
- xmod = xmod - 64
- zmod = zmod + 16
- grX = 10
- grY = grY + 7
- else
- xmod = xmod + 16
- grX = grX + 9
- end
- end
- end
- function saveLocs()
- data = fs.open("Tables/locData", "w")
- data.writeLine(textutils.serialize(locData))
- data.close()
- end
- function loadLocs()
- if fs.exists("Tables/locData") then
- data = fs.open("Tables/locData", "r")
- locData = textutils.unserialize(data.readLine())
- data.close()
- --debugMsg("SYSTEM: Location data loaded...TRUE")
- else
- term.restore()
- locNames()
- getStartData()
- locData = {}
- for i = 1, 25 do
- locData[i] = {
- name = cLabel[i];
- scrX = griMagic[i]["scrX"];
- scrY = griMagic[i]["scrY"];
- xPos = griMagic[i]["xPos"];
- yPos = y;
- zPos = griMagic[i]["zPos"];
- hPos = 0;
- selected = false;
- mined = false;
- field = false;
- planted = false;
- built = false;
- colour = draw.red;
- turtle = nil;
- jobs = {
- miner = {};
- sorter = {};
- utility = {};
- };
- }
- end
- term.redirect(mon)
- end
- --debugMsg(" ")
- saveLocs()
- end
- function saveTurtles()
- data = fs.open("Tables/tData", "w")
- data.writeLine(textutils.serialize(tData))
- data.close()
- end
- function loadTurtles()
- if fs.exists("Tables/tData") then
- data = fs.open("Tables/tData", "r")
- tData = textutils.unserialize(data.readLine())
- data.close()
- --debugMsg("SYSTEM: Turtle list loaded...TRUE")
- else
- tData = {}
- debugMsg("SYSTEM: New turtle list generated...TRUE")
- end
- saveTurtles()
- end
- function saveChests()
- data = fs.open("Tables/chests", "w")
- data.writeLine(textutils.serialize(chestTab))
- data.close()
- end
- function loadChestData()
- if fs.exists("Tables/chests") then
- data = fs.open("Tables/chests", "r")
- chestTab = textutils.unserialize(data.readLine())
- data.close()
- else
- chestTab = {}
- end
- end
- --BUTTON FUNCTIONS--
- function buttonSetup()
- scrTab = {}
- buttonX = x - buttonLen
- buttonY = 1
- spaceLength = " "
- for i = 1, buttonLen do
- spaceLength = spaceLength.." "
- end
- for i = 1, y do
- draw.writeText(x - buttonLen, i, draw.black, draw.black, spaceLength)
- end
- end
- function addButton(label, command, colour, opt1, opt2)
- if scrTab[1] ~= nil then
- newMax = #scrTab + 1
- else
- newMax = 1
- end
- scrTab[newMax] = {
- text = label;
- order = command;
- colour = colour;
- opt1 = opt1;
- opt2 = opt2;
- scrX = buttonX;
- scrY = buttonY;
- }
- if buttonY < y - 3 then
- buttonY = buttonY + 3
- else
- buttonY = 1
- buttonX = buttonX - buttonLen
- end
- end
- function drawButtons()
- if scrTab == nil then
- buttonSetup()
- else
- if not buttonInit then
- dashLen = "-"
- spaceLen = " "
- for i = 1, buttonLen - 3 do
- dashLen = dashLen.."-"
- spaceLen = spaceLen.." "
- end
- buttonInit = true
- end
- for i = 1, #scrTab do
- draw.writeText(scrTab[i]["scrX"], scrTab[i]["scrY"], draw.black, scrTab[i]["colour"], "+"..dashLen.."+")
- draw.writeText(scrTab[i]["scrX"], scrTab[i]["scrY"] + 1, draw.black, scrTab[i]["colour"], ":"..spaceLen..":")
- draw.writeText(scrTab[i]["scrX"], scrTab[i]["scrY"] + 2, draw.black, scrTab[i]["colour"], "+"..dashLen.."+")
- draw.box(scrTab[i]["scrX"] + 1, scrTab[i]["scrY"] + 1, scrTab[i]["scrX"] + (buttonLen - 2), scrTab[i]["scrY"] + 1, scrTab[i]["colour"])
- draw.centerText(scrTab[i]["scrX"] + 1, scrTab[i]["scrX"] + (buttonLen - 2), scrTab[i]["scrY"] + 1, scrTab[i]["colour"], draw.black, scrTab[i]["text"])
- end
- end
- end
- --BUTTON GROUPS--
- function mainMenu()
- buttonSetup()
- addButton("Base", "Base", draw.lime)
- addButton("Items", "Item", draw.lime)
- addButton("Turtles", "Turtle", draw.lime)
- end
- function BPMenu()
- buttonSetup()
- addButton("Exit", "none", draw.red)
- if not gridView then
- addButton("Back", "none", draw.red)
- end
- addButton("Load", "none", draw.lightBlue)
- addButton("Load Preset", "none", draw.lightBlue)
- addButton("Save", "none", draw.lightBlue)
- addButton("Up Level", "none", draw.green)
- addButton("Down Level", "none", draw.green)
- if overlayBool then
- addButton("Overlay", "none", draw.white)
- else
- addButton("Overlay", "none", draw.blue)
- end
- if facing then
- addButton("Facing", "none", draw.white)
- else
- addButton("Facing", "none", draw.blue)
- end
- end
- function BPButtons()
- buttonSetup()
- addButton("Menu", "none", draw.white)
- addButton("Clear", "air", draw.blue, "ai", draw.blue)
- addButton("Plants", "none", draw.lime)
- addButton("Wood", "none", draw.brown)
- addButton("Stone", "none", draw.grey)
- addButton("Fancy", "none", draw.lightBlue)
- addButton("Utility", "none", draw.orange)
- addButton("Access", "none", draw.green)
- addButton("Mods", "none", draw.yellow)
- end
- function plantMenu()
- buttonSetup()
- addButton("Menu", "none", draw.white)
- addButton("Back", "none", draw.red)
- addButton("Dirt", "Dirt", draw.brown, "Di", draw.brown)
- addButton("Oak Sap", "Oak Sapling", draw.green, "Sa", draw.green)
- addButton("Seeds", "Seeds", draw.lime, "Se", draw.yellow)
- addButton("Sugar", "Sugar Canes", draw.lime, "Su", draw.lime)
- addButton("Melon", "Melon Seeds", draw.green, "Me", draw.green)
- addButton("Pumpkin", "Pumpkin Seeds", draw.orange, "Pu", draw.orange)
- end
- function woodMenu()
- buttonSetup()
- addButton("Menu", "none", draw.white)
- addButton("Back", "none", draw.red)
- addButton("Oak", "Oak Wood", draw.brown, "OW", draw.brown)
- addButton("Oak Planks", "Oak Wood Planks", draw.brown, "OP", draw.brown)
- addButton("Oak Stairs", "Oak Wood Stairs", draw.brown, "ST", draw.brown)
- addButton("Fence", "Fence", draw.brown, "Fe", draw.brown)
- end
- function stoneMenu()
- buttonSetup()
- addButton("Menu", "none", draw.white)
- addButton("Back", "none", draw.red)
- addButton("Cobble", "Cobblestone", draw.lightGrey, "CO", draw.lightGrey)
- addButton("Cobble St", "Stone Stairs", draw.lightGrey, "ST", draw.lightGrey)
- addButton("Stone", "Stone", draw.lightGrey, "ST", draw.lightGrey)
- addButton("Stone Br", "Stone Bricks", draw.grey, "SB", draw.grey)
- addButton("Stone Br St", "Stone Bricks Stairs", draw.grey, "SB", draw.grey)
- end
- function fancyMenu()
- buttonSetup()
- addButton("Menu", "none", draw.white)
- addButton("Back", "none", draw.red)
- addButton("Glass", "Glass", draw.lightBlue, "GL", draw.lightBlue)
- addButton("Glass Pane", "Glass Pane", draw.lightBlue, "GP", draw.lightBlue)
- addButton("Torch", "Torch", draw.orange, "TO", draw.orange)
- end
- function utilityMenu()
- buttonSetup()
- addButton("Menu", "none", draw.white)
- addButton("Back", "none", draw.red)
- addButton("Workbench", "Crafting Table", draw.orange, "CR", draw.orange)
- addButton("Furnace", "Furnace", draw.grey, "FU", draw.grey)
- addButton("Chest", "Chest", draw.yellow, "CH", draw.yellow)
- addButton("Iron Chest", "Iron Chest", draw.lightGrey, "CH", draw.lightGrey)
- addButton("Gold Chest", "Gold Chest", draw.yellow, "CH", draw.yellow)
- addButton("Diamond Chest", "Diamond Chest", draw.lightBlue, "CH", draw.lightBlue)
- end
- function accessMenu()
- buttonSetup()
- addButton("Menu", "none", draw.white)
- addButton("Back", "none", draw.red)
- addButton("Storage", "storage", draw.yellow, "CA", draw.yellow)
- addButton("Furnace", "furnace", draw.grey, "FA", draw.grey)
- end
- function modsMenu()
- buttonSetup()
- addButton("Menu", "none", draw.white)
- addButton("Back", "none", draw.red)
- addButton("IC2", "none", draw.lightGrey)
- --addButton("Buildcraft", "none", draw.blue)
- --addButton("Forestry", "none", draw.blue)
- end
- function IC2Menu()
- buttonSetup()
- addButton("Menu", "none", draw.white)
- addButton("Back", "none", draw.red)
- addButton("Generator", "Generator", draw.lightGrey, "MA", draw.lightGrey)
- addButton("Macerator", "Macerator", draw.lightGrey, "MA", draw.lightGrey)
- addButton("Elec Furnace", "Electric Furnace", draw.lightGrey, "EF", draw.lightGrey)
- addButton("Tin Cable", "Insulated Tin Cable", draw.lightGrey, "TC", draw.lightGrey)
- addButton("Cop Cable", "Copper Cable", draw.orange, "CC", draw.orange)
- addButton("Bat Box", "Bat Box", draw.brown, "BB", draw.brown)
- end
- function turtleMenu()
- mainMenu()
- if selChunk == nil then
- chunkFound = false
- for i = 1, #locData do
- if not locData[i]["mined"] then
- chunkFound = true
- selChunk = locData[i]["name"]
- break
- end
- end
- if not chunkFound then
- selChunk = "HQ"
- end
- end
- for i = 1, #tData do
- if tData[i]["selected"] then
- if tData[i]["type"] == "Unassigned" then
- addButton("Set Miner", "setMiner", draw.lightGrey)
- addButton("Set Sorter", "setSorter", draw.orange)
- addButton("set Utility", "setUtility", draw.blue)
- elseif tData[i]["type"] == "miner" then
- miningMenu(selChunk)
- elseif tData[i]["type"] == "sorter" then
- sortMenu()
- elseif tData[i]["type"] == "utility" then
- utilMenu()
- end
- end
- end
- end
- function baseMenu()
- mainMenu()
- end
- function zoomMenu()
- mainMenu()
- addButton("Edit BP "..selChunk, "Blueprints/"..selChunk, draw.lightBlue, 16, 16)
- end
- function miningMenu(label)
- mainMenu()
- if baseBool then
- addButton("Zoom", "none", draw.purple)
- addButton("Edit BP "..label, "Blueprints/"..label, draw.lightBlue, 16, 16)
- elseif turtleBool then
- addButton("Recall", "recall", draw.red)
- end
- addButton("Mine "..label, "mine "..label.." 16 16", draw.lightGrey, label, "mine")
- addButton("Clear "..label, "clear "..label.." 16 16 "..locData[1]["yPos"] + 1, draw.white, label, "clear")
- addButton("Chop "..label, "clear "..label.." 16 16 "..locData[1]["yPos"] + 2, draw.white, label, "chop")
- addButton("Plant "..label, "plant "..label.." justTrees "..locData[1]["yPos"] + 2, draw.white, label, "chop")
- addButton("Build "..label, "build "..label.." "..label, draw.lightBlue, label, "built")
- end
- function sortMenu()
- end
- function utilMenu()
- end
- function presetMenu()
- buttonSetup()
- addButton("Menu", "none", draw.white)
- addButton("Back", "none", draw.red)
- fileTab = fs.list("Presets")
- for i = 1, #fileTab do
- addButton(fileTab[i], "Preset", draw.green)
- end
- end
- --JOB FUNCTIONS--
- function addJob(chunk, order, tType)
- for i = 1, #locData do
- if locData[i]["name"] == chunk then
- if locData[i]["jobs"][tType][1] == nil then
- newMax = 1
- else
- newMax = #locData[i]["jobs"][tType] + 1
- end
- locData[i]["jobs"][tType][newMax] = {}
- locData[i]["jobs"][tType][newMax]["order"] = order
- locData[i]["jobs"][tType][newMax]["type"] = tType
- break
- end
- end
- debugMsg("ADDJOB: "..order.." added.")
- saveLocs()
- end
- function removeJob(chunk, tType)
- for i = 1, #locData do
- if locData[i]["name"] == chunk then
- if #locData[i]["jobs"][tType] > 1 then
- for j = 2, #locData[i]["jobs"][tType] do
- locData[i]["jobs"][tType][j - 1] = locData[i]["jobs"][tType][j]
- locData[i]["jobs"][tType][j] = nil
- end
- else
- locData[i]["jobs"][tType][1] = nil
- end
- end
- end
- saveLocs()
- end
- function checkJobs(tType)
- --debugMsg("JOBDAT: Checking "..tType.." jobs.")
- loadLocs()
- for i = 1, #locData do
- if locData[i]["jobs"][tType][1] ~= nil then
- --debugMsg("JOBDAT: Job entry Found... "..locData[i]["name"])
- if checkSend(locData[i]["jobs"][tType][1]["order"], locData[i]["jobs"][tType][1]["type"]) then
- debugMsg("JOBDAT: "..locData[i][tType][1]["order"].." sent.")
- removeJob(locData[i]["name"], tType)
- end
- end
- end
- --debugMsg(" ")
- end
- function setType(id, tType)
- for i = 1, #tData do
- if tData[i]["identifier"] == id then
- tData[i]["type"] = tType
- if tType == "miner" then
- tData[i]["colour"] = draw.lightGrey
- elseif tType == "support" then
- tData[i]["colour"] = draw.orange
- elseif tType == "utility" then
- tData[i]["colour"] = draw.blue
- end
- end
- end
- saveTurtles()
- end
- --TURTLE FUNCTIONS--
- function saveTurtleChests()
- data = fs.open("Tables/tChests", "w")
- data.writeLine(textutils.serialize(tcTab))
- data.close()
- end
- function loadTurtleChests()
- if fs.exists("Tables/tChests") then
- data = fs.open("Tables/tChests", "r")
- tcTab = textutils.unserialize(data.readLine())
- data.close()
- else
- tcTab = {}
- end
- end
- function readFile()
- tTab = nil
- data = fs.open("Tables/tSheet", "r")
- tTab = textutils.unserialize(data.readLine())
- data.close()
- fs.delete("Tables/tSheet")
- end
- function addTurtle(tId)
- loadTurtles()
- if tData[1] == nil then
- newMax = 1
- else
- newMax = #tData + 1
- end
- tData[newMax] = {}
- tData[newMax] = tTab
- tData[newMax]["identifier"] = tId
- tData[newMax]["action"] = "No task"
- tData[newMax]["colour"] = draw.purple
- tData[newMax]["type"] = "Unassigned"
- tData[newMax]["selected"] = false
- tData[newMax]["scrX"] = 1
- tData[newMax]["scrY"] = 1
- saveTurtles()
- debugMsg("TURTLE: "..tData[newMax]["name"].." added.")
- makeTurtleTable()
- signalUpdate()
- end
- function addTurtleChest(chLabel, xLoc, yLoc, zLoc, hLoc)
- debugMsg("ADD TC: Adding new turtle chest for "..chLabel..".")
- loadTurtleChests()
- for i = 1, #tcTab do
- if tcTab[i]["name"] == chLabel then
- debugMsg("ADD TC: Chest already exists.")
- end
- end
- if tcTab[1] == nil then
- newMax = 1
- else
- newMax = #tcTab + 1
- end
- tcTab[newMax] = {
- name = chLabel;
- xPos = xLoc;
- yPos = yLoc;
- zPos = zLoc;
- hPos = hLoc;
- }
- saveTurtleChests()
- debugMsg("ADD TC: Chest added.")
- end
- function makeTurtleTable()
- loadTurtles()
- debugMsg("MACHTA: Begin Turtle update...TRUE")
- for i = 1, #tData do
- debugMsg("MACHTA: Checking "..tData[i]["name"].."'s stored data.")
- if tData[i]["homeH"] == 0 then
- addTurtleChest(tData[i]["name"].."Chest", tData[i]["homeX"] + 1, tData[i]["homeY"], tData[i]["homeZ"] + 1, tData[i]["homeH"])
- addTurtleChest(tData[i]["name"].."Fuel", tData[i]["homeX"] - 1, tData[i]["homeY"], tData[i]["homeZ"] + 1, tData[i]["homeH"])
- elseif tData[i]["homeH"] == 1 then
- addTurtleChest(tData[i]["name"].."Chest", tData[i]["homeX"] - 1, tData[i]["homeY"], tData[i]["homeZ"] + 1, tData[i]["homeH"])
- addTurtleChest(tData[i]["name"].."Fuel", tData[i]["homeX"] - 1, tData[i]["homeY"], tData[i]["homeZ"] - 1, tData[i]["homeH"])
- elseif tData[i]["homeH"] == 2 then
- addTurtleChest(tData[i]["name"].."Chest", tData[i]["homeX"] - 1, tData[i]["homeY"], tData[i]["homeZ"] - 1, tData[i]["homeH"])
- addTurtleChest(tData[i]["name"].."Fuel", tData[i]["homeX"] + 1, tData[i]["homeY"], tData[i]["homeZ"] - 1, tData[i]["homeH"])
- elseif tData[i]["homeH"] == 3 then
- addTurtleChest(tData[i]["name"].."Chest", tData[i]["homeX"] + 1, tData[i]["homeY"], tData[i]["homeZ"] - 1, tData[i]["homeH"])
- addTurtleChest(tData[i]["name"].."Fuel", tData[i]["homeX"] + 1, tData[i]["homeY"], tData[i]["homeZ"] + 1, tData[i]["homeH"])
- end
- debugMsg("MACHTA: Check complete.")
- end
- debugMsg("MACHTA: All updates complete.")
- saveTurtleChests()
- end
- function turtleLookup(tId, label)
- loadTurtleChests()
- debugMsg("TUR LU: Checking turtle chests for "..label..".")
- for i = 1, #tcTab do
- debugMsg("TUR LU: found "..tcTab[i]["name"]..".")
- if tcTab[i]["name"] == label then
- debugMsg("TUR LU: "..label.." found.")
- rednet.send(tId, "travel "..tcTab[i]["name"])
- end
- end
- end
- function signalUpdate()
- debugMsg("UPDATE: Update triggered.")
- for i = 1, #tData do
- tData[i]["updated"] = false
- if not tData[i]["updated"] then
- debugMsg("UPDATE: "..tData[i]["name"].." needs update.")
- end
- end
- update = true
- saveTurtles()
- end
- function updateTurtleChests(tId, tName)
- loadTurtleChests()
- if tcTab[1] == nil then
- makeTurtleTable()
- end
- debugMsg("UPD TC: Updating "..tName.."'s turtle data.")
- for i = 1, #tcTab do
- rednet.send(tId, "updateLocs "..tcTab[i]["name"].." "..tcTab[i]["xPos"].." "..tcTab[i]["yPos"].." "..tcTab[i]["zPos"].." "..tcTab[i]["hPos"])
- sleep(.1)
- end
- debugMsg("LOCUPD: "..tName.."'s turtle data fully updated.")
- saveTurtles()
- end
- function updateLocs(tId, tName)
- --debugMsg("UPD LO: Updating "..tName.."'s location data.")
- for i = 1, #locData do
- rednet.send(tId, "updateLocs "..locData[i]["name"].." "..locData[i]["xPos"].." "..locData[i]["yPos"].." "..locData[i]["zPos"].." "..locData[i]["hPos"])
- sleep(.1)
- end
- --debugMsg("LOCUPD: "..tName.."'s location data fully updated.")
- saveTurtles()
- end
- function updateBP(tId, tName)
- --debugMsg("UPD BP: Updating "..tName.."'s blueprint data.")
- fileTab = fs.list("Blueprints")
- for i = 1, #fileTab do
- debugMsg("UPD BP: Updating "..fileTab[i].." blueprint data.")
- loadBlueprint(fileTab[i])
- bpTab = textutils.serialize(bpTab)
- rednet.send(tId, "updateBP "..fileTab[i])
- sleep(.1)
- rednet.send(tId, bpTab)
- sleep(.1)
- end
- --debugMsg("UPD BP: Updating "..tName.."'s blueprints done.")
- end
- function updateChests(tId, tName)
- --debugMsg("UPD CH: Updating "..tName.."'s chest data.")
- loadChestData()
- for i = 1, #chestTab do
- rednet.send(tId, "updateLocs "..chestTab[i]["id"].." "..chestTab[i]["xPos"].." "..chestTab[i]["yPos"].." "..chestTab[i]["zPos"].." "..chestTab[i]["hPos"])
- sleep(.1)
- end
- --debugMsg("LOCUPD: "..tName.."'s chest data fully updated.")
- end
- function checkUpdates(tId, tName)
- for i = 1, #tData do
- if tData[i]["identifier"] == tId then
- if not tData[i]["updated"] then
- debugMsg("UPDATE: Updating "..tName..".")
- updateTurtleChests(tId, tName)
- updateLocs(tId, tName)
- updateChests(tId, tName)
- updateBP(tId, tName)
- tData[i]["updated"] = true
- return
- end
- end
- end
- end
- function pushUpdates()
- for i = 1, #tData do
- if tData[i]["action"] == "No task" then
- if not tData[i]["updated"] then
- debugMsg("UPDATE: Updating "..tData[i]["name"]..".")
- updateLocs(tData[i]["identifier"], tData[i]["name"])
- updateTurtleChests(tData[i]["identifier"], tData[i]["name"])
- updateChests(tData[i]["identifier"], tData[i]["name"])
- updateBP(tData[i]["identifier"], tData[i]["name"])
- tData[i]["updated"] = true
- return
- end
- end
- end
- end
- function checkTurtles(tId) --All turtle state messages here
- loadTurtles()
- readFile()
- found = false
- for i = 1, #tData do
- if tData[i]["identifier"] == tId then
- --debugMsg("TURTLE: "..tData[newMax]["name"].." reported in.")
- found = true
- tData[i]["xPos"] = tTab["xPos"]
- tData[i]["yPos"] = tTab["yPos"]
- tData[i]["zPos"] = tTab["zPos"]
- tData[i]["hPos"] = tTab["hPos"]
- tData[i]["state"] = tTab["state"]
- tData[i]["home"] = tTab["home"]
- tData[i]["opt1"] = tTab["opt1"]
- tData[i]["opt2"] = tTab["opt2"]
- if tData[i]["state"] == "Idle" then --Start of turtle task updates
- tData[i]["action"] = "No task"
- debugMsg("TURTLE: "..tData[i]["name"].." idle.")
- checkUpdates(tId, tData[i]["name"])
- elseif tData[i]["state"] == "Digging" then
- tData[i]["action"] = "Digging"
- elseif tData[i]["state"] == "Inbound" then
- tData[i]["action"] = "Inbound"
- elseif tData[i]["state"] == "Outbound" then
- tData[i]["action"] = "Outbound"
- elseif tData[i]["state"] == "Need sort" then
- if tData[i]["type"] ~= "sorter" then
- addJob("HQ", "sort "..tData[i]["name"].."Chest", "sorter")
- end
- elseif tData[i]["state"] == "Need update" then
- checkUpdates(tData[i]["identifier"])
- elseif tData[i]["state"] == "Chest lookup" then
- chestLookup(tData[i]["identifier"], tData[i]["opt1"])
- elseif tData[i]["state"] == "Turtle lookup" then
- turtleLookup(tData[i]["identifier"], tData[i]["opt1"])
- tData[i]["action"] = "Sorting"
- elseif tData[i]["state"] == "Item add" then
- chestModify(tData[i]["opt2"], tData[i]["opt1"])
- if itemBool then
- drawCurrent()
- end
- elseif tData[i]["state"] == "Item take" then
- chestModify(tData[i]["opt2"], tData[i]["opt1"], "subtract")
- if itemBool then
- drawCurrent()
- end
- end
- saveTurtles()
- break
- end
- end
- if not found then
- addTurtle(tId)
- end
- end
- function checkSend(order, tType)
- --debugMsg("TURTLE: Checking for "..tType.." Turtles.")
- for i = 1, #tData do
- if tData[i]["action"] == "No task" and tData[i]["type"] == tType then
- --debugMsg("TURTLE: Found "..tData[i]["name"].." sending job.")
- tData[i]["action"] = "Got Job"
- rednet.send(tData[i]["identifier"], order)
- return true
- end
- end
- --debugMsg("TURTLE: No idle Turtles found.")
- return false
- end
- --ITEM FUNCTIONS--
- function addChest(itemType, xLoc, yLoc, zLoc, hLoc)
- loadChestData()
- if chestTab[1] == nil then
- newMax = 1
- else
- for i = 1, #chestTab do
- if chestTab[i]["xPos"] == xLoc and chestTab[i]["yPos"] == yLoc and chestTab[i]["zPos"] == zLoc and chestTab[i]["hPos"] == hLoc then
- debugMsg("ADDCHE: Chest exists.")
- return
- end
- end
- newMax = #chestTab + 1
- end
- label = newMax
- chestTab[newMax] = {
- id = label;
- type = itemType;
- xPos = xLoc;
- yPos = yLoc;
- zPos = zLoc;
- hPos = hLoc;
- label = "Nowt";
- amt = 0;
- }
- saveChests()
- debugMsg("ADDCHE: "..itemType.." added X: "..xLoc.." Y: "..yLoc.." Z: "..zLoc)
- end
- function chestLookup(tId, itemName)
- loadChestData()
- debugMsg("CHE LU: Checking for "..itemName)
- chestFound = false
- for i = 1, #chestTab do
- if chestTab[i]["label"] == itemName then
- debugMsg("CHE LU: "..itemName.." found.")
- chestFound = true
- rednet.send(tId, "travel "..i)
- break
- end
- end
- if not chestFound then
- debugMsg("CHE LU: "..itemName.." not found.")
- debugMsg("CHE LU: Setting up new chest.")
- for i = 1, #chestTab do
- if chestTab[i]["label"] == "Nowt" then
- rednet.send(tId, "travel "..i)
- chestTab[i]["label"] = itemName
- debugMsg("CHE LU: Chest added, ID: "..i)
- saveChests()
- break
- end
- end
- end
- end
- function chestModify(amount, itemType)
- loadChestData()
- debugMsg("CHEMOD: Checking for "..itemType)
- for i = 1, #chestTab do
- if chestTab[i]["label"] == itemType then
- debugMsg("CHEMOD: "..itemType.." found.")
- if modify == nil then
- chestTab[i]["amt"] = chestTab[i]["amt"] + amount
- debugMsg("CHEMOD: "..chestTab[i]["amt"].." "..itemType..".")
- saveChests()
- return
- else
- chestTab[i]["amt"] = chestTab[i]["amt"] - amount
- debugMsg("CHEMOD: "..chestTab[i]["amt"].." "..itemType..".")
- saveChests()
- return
- end
- end
- end
- end
- --BLUEPRINT FUNCTIONS--
- function newBlueprint(sizeX, sizeZ)
- bpTab = {}
- newBPLayer(1, sizeX, sizeZ, "air")
- turtleGridUpdate()
- end
- function newBPLayer(level, sizeX, sizeZ, itemType)
- bpTab[level] = {}
- local scrX, scrY = 8, 4
- for j = 1, sizeX do
- bpTab[level][j] = {}
- for k = 1, sizeZ do --this might need reversing to the X axis loop
- bpTab[level][j][k] = {}
- bpTab[level][j][k][1] = itemType
- bpTab[level][j][k][2] = draw.blue
- bpTab[level][j][k][3] = scrX
- bpTab[level][j][k][4] = scrY
- bpTab[level][j][k][5] = nil
- bpTab[level][j][k][6] = string.sub(itemType, 1, 2)
- if k ~= sizeX then
- scrX = scrX + 3
- else
- scrX = 8
- scrY = scrY + 2
- end
- end
- end
- debugMsg("Layer "..level.." added.")
- end
- function makeChestTable()
- debugMsg("MACHTA: Begin Table update...TRUE")
- for h = 1, #bpTab do
- debugMsg("MACHTA: Checking layer"..h)
- for i = 1, #bpTab[h] do
- for j = 1, #bpTab[h][i] do
- if bpTab[h][i][j][1] == "storage" then
- addChest("storage", bpTab[1][i][j]["xPos"], locData[1]["yPos"] + (h - 1), bpTab[1][i][j]["zPos"], bpTab[h][i][j][5])
- elseif bpTab[h][i][j][1] == "furnace" then
- addChest("furnace", bpTab[1][i][j]["xPos"], locData[1]["yPos"] + (h - 1), bpTab[1][i][j]["zPos"], bpTab[h][i][j][5])
- end
- end
- end
- end
- debugMsg(" ")
- end
- function saveBlueprint(filename)
- data = fs.open("Blueprints/"..filename, "w")
- data.writeLine(textutils.serialize(bpTab))
- data.close()
- end
- function loadBlueprint(label)
- if fs.exists("Blueprints/"..label) then
- data = fs.open("Blueprints/"..label, "r")
- bpTab = textutils.unserialize(data.readLine())
- data.close()
- else
- newBlueprint(16, 16)
- newBPLayer(2, 16, 16)
- end
- end
- function loadPreset(label)
- data = fs.open("Presets/"..label, "r")
- bpTab = textutils.unserialize(data.readLine())
- data.close()
- end
- function loadLastBP()
- if fs.exists("Blueprints/"..selChunk) then
- data = fs.open("Blueprints/"..selChunk, "r")
- bpTab = textutils.unserialize(data.readLine())
- data.close()
- layer = 1
- item = "air"
- lab = "ai"
- itemColour = draw.blue
- else
- newBlueprint(1, 16, 16, "Dirt")
- end
- end
- --SCREEN FUNCTIONS--
- function updateChunkState(chunk, state)
- for i = 1, #locData do
- if locData[i]["name"] == chunk then
- if state == "mine" then
- locData[i]["mined"] = true
- locData[i]["field"] = false
- locData[i]["planted"] = false
- locData[i]["built"] = false
- break
- elseif state == "field" then
- locData[i]["field"] = true
- break
- elseif state == "planted" then
- locData[i]["planted"] = true
- break
- elseif state == "chop" or state == clear then
- locData[i]["planted"] = false
- locData[i]["built"] = false
- break
- elseif state == "built" then
- locData[i]["built"] = true
- break
- end
- end
- end
- debugMsg("SCRDAT: "..chunk.." state updated.")
- end
- function updateBaseScreen()
- loadLocs()
- loadTurtles()
- for i = 1, #locData do
- if not locData[i]["selected"] then
- locData[i]["colour"] = draw.purple
- end
- if locData[i]["mined"] then
- locData[i]["colour"] = draw.lightGrey
- end
- if locData[i]["field"] then
- locData[i]["colour"] = draw.brown
- end
- if locData[i]["planted"] then
- locData[i]["colour"] = draw.green
- end
- if locData[i]["built"] then
- locData[i]["colour"] = draw.grey
- end
- if locData[i]["turtle"] ~= "None" then
- locData[i]["colour"] = draw.green
- end
- if locData[i]["selected"] then
- locData[i]["colour"] = draw.lime
- end
- locData[i]["turtle"] = "None"
- tCount = 0
- for j = 1, #tData do
- if tData[j]["xPos"] >= locData[i]["xPos"] and tData[j]["xPos"] <= locData[i]["xPos"] + 15 then
- if tData[j]["zPos"] <= locData[i]["zPos"] and tData[j]["zPos"] >= locData[i]["zPos"] - 15 then
- locData[i]["turtle"] = tData[j]["name"]
- tCount = tCount + 1
- end
- end
- end
- if tCount > 1 then
- locData[i]["turtle"] = tCount.." x"
- end
- saveLocs()
- end
- end
- function baseScreen()
- if not drawn then
- draw.clear()
- end
- updateBaseScreen()
- if selChunk ~= nil then
- draw.centerText(1, x - buttonLen, 2, draw.black, draw.lime, selChunk.." selected.")
- end
- for i = 1, #locData do
- if not drawn then
- local dashLenBase = "-"
- local spaceLenBase = " "
- for i = 1, chunkTileX - 3 do
- dashLenBase = dashLenBase.."-"
- spaceLenBase = spaceLenBase.." "
- end
- draw.centerText(locData[i]["scrX"], locData[i]["scrX"] + chunkTileX, locData[i]["scrY"], draw.black, draw.lime, "+"..dashLenBase.."+")
- for j = 1, chunkTileY - 2 do
- draw.centerText(locData[i]["scrX"], locData[i]["scrX"] + chunkTileX, locData[i]["scrY"] + j, draw.black, draw.lime, ":"..spaceLenBase..":")
- end
- draw.centerText(locData[i]["scrX"], locData[i]["scrX"] + chunkTileX, locData[i]["scrY"] + (chunkTileY - 1), draw.black, draw.lime, "+"..dashLenBase.."+")
- end
- draw.box(locData[i]["scrX"] + 1, locData[i]["scrY"] + 1, locData[i]["scrX"] + chunkTileX - 2, locData[i]["scrY"] + chunkTileY - 2, locData[i]["colour"])
- draw.centerText(locData[i]["scrX"], locData[i]["scrX"] + chunkTileX, locData[i]["scrY"] + 1, locData[i]["colour"], draw.black, locData[i]["name"])
- draw.centerText(locData[i]["scrX"], locData[i]["scrX"] + chunkTileX, locData[i]["scrY"] + 2, locData[i]["colour"], draw.black, locData[i]["turtle"])
- if locData[i]["mined"] then
- draw.centerText(locData[i]["scrX"], locData[i]["scrX"] + chunkTileX, locData[i]["scrY"] + 3, locData[i]["colour"], draw.black, "Mined")
- end
- if locData[i]["field"] then
- draw.centerText(locData[i]["scrX"], locData[i]["scrX"] + chunkTileX, locData[i]["scrY"] + 4, locData[i]["colour"], draw.black, "Field")
- end
- if locData[i]["planted"] then
- draw.centerText(locData[i]["scrX"], locData[i]["scrX"] + chunkTileX, locData[i]["scrY"] + 5, locData[i]["colour"], draw.black, "Planted")
- end
- if locData[i]["built"] then
- draw.centerText(locData[i]["scrX"], locData[i]["scrX"] + chunkTileX, locData[i]["scrY"] + 6, locData[i]["colour"], draw.black, "Built")
- end
- end
- if not drawn then
- drawn = true
- end
- drawButtons()
- end
- function turtleScreen()
- loadTurtles()
- local stx, sty = 3, 2
- if not drawn then
- draw.clear()
- dashLenTur = "-"
- spaceLenTur = " "
- for i = 1, turtleTileX - 3 do
- dashLenTur = dashLenTur.."-"
- spaceLenTur = spaceLenTur.." "
- end
- end
- for i = 1, #tData do
- tData[i]["scrX"] = stx
- tData[i]["scrY"] = sty
- if not drawn then
- draw.centerText(stx, stx + turtleTileX, sty, draw.black, draw.lime, "+"..dashLenTur.."+")
- for j = 1, turtleTileY - 2 do
- draw.centerText(stx, stx + turtleTileX, sty + j, draw.black, draw.lime, ":"..spaceLenTur..":")
- end
- draw.centerText(stx, stx + turtleTileX, sty + (turtleTileY - 1), draw.black, draw.lime, "+"..dashLenTur.."+")
- draw.box(stx + 1, sty + 1, stx + (turtleTileX - 2), sty + (turtleTileY - 2), tData[i]["colour"])
- end
- draw.centerText(stx + 1, stx + (turtleTileX - 1), sty + 1, tData[i]["colour"], draw.black, tData[i]["name"])
- draw.centerText(stx + 1, stx + (turtleTileX - 1), sty + 2, tData[i]["colour"], draw.black, string.sub(tData[i]["state"], 1, turtleTileX - 2))
- draw.centerText(stx + 1, stx + (turtleTileX - 1), sty + 3, tData[i]["colour"], draw.black, tData[i]["action"])
- draw.centerText(stx + 1, stx + (turtleTileX - 1), sty + 4, tData[i]["colour"], draw.black, tData[i]["xPos"])
- draw.centerText(stx + 1, stx + (turtleTileX - 1), sty + 5, tData[i]["colour"], draw.black, tData[i]["yPos"])
- draw.centerText(stx + 1, stx + (turtleTileX - 1), sty + 6, tData[i]["colour"], draw.black, tData[i]["zPos"])
- if tData[i]["hPos"] == 0 then
- draw.centerText(stx + 1, stx + (turtleTileX - 1), sty + 7, tData[i]["colour"], draw.black, "North")
- elseif tData[i]["hPos"] == 1 then
- draw.centerText(stx + 1, stx + (turtleTileX - 1), sty + 7, tData[i]["colour"], draw.black, "East")
- elseif tData[i]["hPos"] == 2 then
- draw.centerText(stx + 1, stx + (turtleTileX - 1), sty + 7, tData[i]["colour"], draw.black, "South")
- elseif tData[i]["hPos"] == 3 then
- draw.centerText(stx + 1, stx + (turtleTileX - 1), sty + 7, tData[i]["colour"], draw.black, "West")
- end
- if i % 5 ~= 0 then
- stx = stx + (turtleTileX - 1)
- else
- stx = 3
- sty = sty + (turtleTileY - 1)
- end
- end
- end
- function itemScreen()
- if not drawn then
- draw.clear()
- end
- loadChestData()
- chestCount = 0
- scrX = 4
- scrY = 4
- for i = 1, #chestTab do
- if chestTab[i]["type"] == "storage" then
- if chestTab[i]["amt"] < 64 then
- if chestTab[i]["label"] ~= "Nowt" then
- colour = draw.red
- else
- colour = draw.purple
- end
- elseif chestTab[i]["amt"] >= 64 then
- colour = draw.orange
- end
- if chestTab[i]["amt"] >= 256 then
- colour = draw.green
- end
- if chestTab[i]["amt"] >= 1728 then
- colour = draw.lightGrey
- end
- if chestTab[i]["amt"] >= 3456 then
- colour = draw.yellow
- end
- if chestTab[i]["amt"] >= 5184 then
- colour = draw.lightBlue
- end
- draw.box(scrX, scrY, scrX + 16, scrY, colour)
- draw.writeText(scrX, scrY, colour, draw.black, string.sub(chestTab[i]["label"], 1, 10))
- draw.writeText(scrX + 11, scrY, colour, draw.black, ": "..chestTab[i]["amt"])
- if scrY < y then
- scrY = scrY + 1
- else
- scrX = scrX + 17
- scrY = 4
- end
- chestCount = chestCount + 1
- debugMsg("ITMSCR: "..i.." "..chestCount..", "..chestTab[i]["amt"].." "..chestTab[i]["label"])
- end
- end
- draw.centerText(1, x - buttonLen, 2, draw.black, draw.lime, chestCount.." storage chests.")
- end
- function gridSquare(gsX, gsY, colour, text)
- if not drawn then
- draw.writeText(gsX, gsY, draw.black, draw.lightBlue, "+--+")
- draw.writeText(gsX, gsY + 1, draw.black, draw.lightBlue, ": :")
- draw.writeText(gsX, gsY + 2, draw.black, draw.lightBlue, "+--+")
- end
- if text ~= "ai" then
- draw.writeText(gsX + 1, gsY + 1, colour, draw.black, text)
- else
- draw.box(gsX + 1, gsY + 1, gsX + 2, gsY + 1, colour)
- end
- end
- function bpScreen(level, overlay)
- x, y = mon.getSize()
- if not drawn then
- draw.clear()
- end
- if bpBool then
- draw.centerText(1, x - buttonLen, 2, draw.black, draw.lime, "Level: "..layer.."/"..#bpTab..", "..item.." selected.")
- else
- if selTurtleName ~= nil then
- draw.centerText(1, x - buttonLen, 2, draw.black, draw.lime, selChunk.." "..selTurtleName.." selected.")
- else
- draw.centerText(1, x - buttonLen, 2, draw.black, draw.lime, selChunk.." selected.")
- end
- end
- for i = 1, #bpTab[level] do
- for j = 1, #bpTab[level][i] do
- if bpTab[level][i][j][5] ~= nil then
- label = string.sub(bpTab[level][i][j][6], 1, 1)
- if bpTab[level][i][j][5] == 0 then
- label = label..">"
- elseif bpTab[level][i][j][5] == 1 then
- label = label.."v"
- elseif bpTab[level][i][j][5] == 2 then
- label = label.."<"
- elseif bpTab[level][i][j][5] == 3 then
- label = label.."^"
- end
- else
- if bpBool then
- label = bpTab[level][i][j][6]
- else
- label = " "
- end
- end
- if overlay ~= nil then
- if bpTab[level][i][j][1] ~= "air" then
- gridSquare(bpTab[level][i][j][3], bpTab[level][i][j][4], bpTab[level][i][j][2], label)
- else
- gridSquare(bpTab[level - 1][i][j][3], bpTab[level - 1][i][j][4], bpTab[level - 1][i][j][2], label)
- end
- else
- gridSquare(bpTab[level][i][j][3], bpTab[level][i][j][4], bpTab[level][i][j][2], label)
- end
- end
- end
- drawButtons()
- if not drawn then
- drawn = true
- end
- end
- function drawCurrent()
- if baseBool then
- baseScreen()
- elseif itemBool then
- itemScreen()
- elseif turtleBool then
- turtleScreen()
- elseif bpBool or gridView then
- if overlayBool then
- --bpScreen(layer - 1)
- bpScreen(layer, true)
- else
- bpScreen(layer)
- end
- if gridView then
- if not turtleOverlay then
- turtleGridUpdate()
- end
- drawTurtles()
- end
- end
- drawButtons()
- end
- function turtleGridUpdate()
- for i = 1, #locData do
- if locData[i]["name"] == selChunk then
- xStart = locData[i]["xPos"]
- zStart = locData[i]["zPos"]
- break
- end
- end
- for i = 1, #bpTab[1] do
- for j = 1, #bpTab[1][i] do
- bpTab[1][i][j]["xPos"] = xStart + (i - 1)
- bpTab[1][i][j]["zPos"] = zStart - (j - 1)
- end
- end
- turtleOverlay = true
- end
- function drawTurtles()
- --debugMsg("OVRLAY: Checking for turtles in "..selChunk..".")
- for i = 1, #locData do
- if locData[i]["name"] == selChunk then
- if locData[i]["turtle"] ~= "None" then
- --debugMsg("OVRLAY: Turtles suspected in chunk.")
- for j = 1, #tData do
- if tData[j]["xPos"] >= locData[i]["xPos"] and tData[j]["xPos"] <= locData[i]["xPos"] + 15 then
- if tData[j]["zPos"] <= locData[i]["zPos"] and tData[j]["zPos"] >= locData[i]["zPos"] - 15 then
- --debugMsg("OVRLAY: "..tData[j]["name"].." found in chunk.")
- for k = 1, #bpTab[1] do
- for l = 1, #bpTab[1][k] do
- if tData[j]["xPos"] == bpTab[1][k][l]["xPos"] then
- if tData[j]["zPos"] == bpTab[1][k][l]["zPos"] then
- if tData[j]["type"] == "Unassigned" then
- dCol = draw.purple
- elseif tData[j]["type"] == "miner" then
- dCol = draw.lightGrey
- elseif tData[j]["type"] == "sorter" then
- dCol = draw.orange
- elseif tData[j]["type"] == "sorter" then
- dCol = draw.blue
- end
- if tData[j]["selected"] then
- dCol = draw.lime
- end
- if tData[j]["hPos"] == 0 then
- gridSquare(bpTab[1][k][l][3], bpTab[1][k][l][4], dCol, j..">")
- elseif tData[j]["hPos"] == 1 then
- gridSquare(bpTab[1][k][l][3], bpTab[1][k][l][4], dCol, j.."v")
- elseif tData[j]["hPos"] == 2 then
- gridSquare(bpTab[1][k][l][3], bpTab[1][k][l][4], dCol, j.."<")
- elseif tData[j]["hPos"] == 3 then
- gridSquare(bpTab[1][k][l][3], bpTab[1][k][l][4], dCol, j.."^")
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
- --RUN FUNCTIONS--
- function changeScreen(screenName)
- drawn = false
- baseBool = false
- itemBool = false
- turtleBool = false
- bpBool = false
- gridView = false
- overlayBool = false
- turtleOverlay = false
- if screenName == "Base" then
- baseScreen()
- baseBool = true
- mainMenu()
- elseif screenName == "Items" then
- itemScreen()
- itemBool = true
- mainMenu()
- elseif screenName == "Turtles" then
- turtleScreen()
- turtleBool = true
- mainMenu()
- elseif screenName == "BP" then
- loadBlueprint(selChunk)
- turtleGridUpdate()
- layer = 1
- item = "air"
- lab = "ai"
- itemColour = draw.blue
- BPButtons()
- draw.clear()
- bpScreen(layer)
- bpBool = true
- return
- elseif screenName == "Zoom" then
- debugMsg("RUNSYS: "..selChunk)
- loadBlueprint(selChunk)
- zoomMenu()
- gridView = true
- overlayBool = true
- layer = 2
- drawCurrent()
- end
- end
- function listener(tId, msg) --Handles all rednet messages--
- if string.sub(msg, 1, 9) == "itemTally" then
- shell.run(msg)
- elseif msg == "tick" then
- tickCount = tickCount + 1
- if tickCount >= 10 then
- tickCount = 0
- if update then
- pushUpdates()
- update = false
- end
- checkJobs("miner")
- checkJobs("sorter")
- checkJobs("utility")
- end
- else
- data = fs.open("Tables/tSheet", "w")
- data.write(msg)
- data.close()
- checkTurtles(tId)
- updateBaseScreen()
- if turtleBool or baseBool or gridView then
- drawCurrent()
- end
- end
- end
- function clearTurtleSelect()
- selTurtle = nil
- selTurtleName = nil
- for j = 1, #tData do
- tData[j]["selected"] = false
- if tData[j]["type"] == "miner" then
- tData[j]["colour"] = draw.lightGrey
- elseif tData[j]["type"] == "sorter" then
- tData[j]["colour"] = draw.orange
- elseif tData[j]["type"] == "utility" then
- tData[j]["colour"] = draw.blue
- else
- tData[j]["colour"] = draw.purple
- end
- end
- saveTurtles()
- end
- function sensor(xClick, yClick) --Handles all monitor touches
- if xClick > x - buttonLen then
- for i = 1, #scrTab do --ALL SIDE BUTTON CHECKING DONE HERE
- if scrTab[i] ~= nil then
- if xClick >= tonumber(scrTab[i]["scrX"]) and xClick <= x - 2 then
- if yClick == scrTab[i]["scrY"] + 1 then
- if scrTab[i]["text"] == "Base" then
- changeScreen(scrTab[i]["text"])
- break
- elseif scrTab[i]["text"] == "Items" then
- changeScreen(scrTab[i]["text"])
- break
- elseif scrTab[i]["text"] == "Turtles" then
- changeScreen(scrTab[i]["text"])
- break
- elseif scrTab[i]["text"] == "Set Miner" then
- setType(selTurtle, "miner")
- mainMenu()
- break
- elseif scrTab[i]["text"] == "Set Sorter" then
- setType(selTurtle, "sorter")
- mainMenu()
- break
- elseif scrTab[i]["text"] == "Set Utility" then
- setType(selTurtle, "utility")
- mainMenu()
- break
- elseif scrTab[i]["text"] == "Recall" then
- rednet.send(selTurtle, "recall")
- elseif scrTab[i]["text"] == "Mine "..selChunk then
- addJob(selChunk, scrTab[i]["order"], "miner")
- updateChunkState(selChunk, scrTab[i]["opt2"])
- mainMenu()
- break
- elseif scrTab[i]["text"] == "Clear "..selChunk then
- addJob(selChunk, scrTab[i]["order"], "miner")
- updateChunkState(selChunk, scrTab[i]["opt2"])
- mainMenu()
- break
- elseif scrTab[i]["text"] == "Chop "..selChunk then
- addJob(selChunk, scrTab[i]["order"], "miner")
- updateChunkState(selChunk, scrTab[i]["opt2"])
- mainMenu()
- break
- elseif scrTab[i]["text"] == "Plant "..selChunk then
- addJob(selChunk, scrTab[i]["order"], "miner")
- updateChunkState(selChunk, scrTab[i]["opt2"])
- mainMenu()
- break
- elseif scrTab[i]["text"] == "Build "..selChunk then
- addJob(selChunk, scrTab[i]["order"], "miner")
- updateChunkState(selChunk, scrTab[i]["opt2"])
- mainMenu()
- break
- elseif scrTab[i]["text"] == "Zoom" then
- changeScreen("Zoom")
- break
- elseif scrTab[i]["text"] == "Load Preset" then
- presetMenu()
- break
- elseif scrTab[i]["order"] == "Preset" then
- loadPreset(scrTab[i]["text"])
- layer = 1
- bpScreen(layer)
- break
- elseif scrTab[i]["text"] == "Edit BP "..selChunk then --Start of Blueprint functions
- changeScreen("BP")
- break
- elseif scrTab[i]["text"] == "Menu" then
- BPMenu()
- break
- elseif scrTab[i]["text"] == "Exit" then
- changeScreen("Base")
- break
- elseif scrTab[i]["text"] == "Save" then
- makeChestTable()
- saveBlueprint(selChunk)
- signalUpdate()
- break
- elseif scrTab[i]["text"] == "Load" then
- loadLastBP()
- break
- elseif scrTab[i]["text"] == "Back" then
- BPButtons()
- break
- elseif scrTab[i]["text"] == "Up Level" then
- layer = layer + 1
- if bpTab[layer] == nil then
- newBPLayer(layer, 16, 16)
- end
- drawCurrent()
- break
- elseif scrTab[i]["text"] == "Down Level" then
- if layer > 1 then
- overlayBool = false
- layer = layer - 1
- end
- drawCurrent()
- BPMenu()
- break
- elseif scrTab[i]["text"] == "Overlay" then
- if layer == 1 then
- overlayBool = false
- else
- overlayBool = not overlayBool
- end
- drawCurrent()
- BPMenu()
- break
- elseif scrTab[i]["text"] == "Facing" then
- facing = not facing
- BPMenu()
- break
- elseif scrTab[i]["text"] == "Plants" then
- plantMenu()
- break
- elseif scrTab[i]["text"] == "Wood" then
- woodMenu()
- break
- elseif scrTab[i]["text"] == "Stone" then
- stoneMenu()
- break
- elseif scrTab[i]["text"] == "Fancy" then
- fancyMenu()
- break
- elseif scrTab[i]["text"] == "Utility" then
- utilityMenu()
- break
- elseif scrTab[i]["text"] == "Access" then
- accessMenu()
- break
- elseif scrTab[i]["text"] == "Mods" then
- modsMenu()
- break
- elseif scrTab[i]["text"] == "IC2" then
- IC2Menu()
- break
- else
- debugMsg("SENSOR: "..scrTab[i]["order"])
- if bpBool then
- drawn = false
- debugMsg("SENSOR: "..scrTab[i]["order"].." "..scrTab[i]["opt1"].." "..scrTab[i]["opt2"])
- item = scrTab[i]["order"]
- lab = scrTab[i]["opt1"]
- itemColour = tonumber(scrTab[i]["opt2"])
- drawCurrent()
- break
- end
- end
- end
- end
- end
- end
- else
- if baseBool then
- for i = 1, #locData do
- if xClick >= locData[i]["scrX"] + 1 and xClick <= locData[i]["scrX"] + (chunkTileX - 1) then
- if yClick >= locData[i]["scrY"] + 1 and yClick <= locData[i]["scrY"] + (chunkTileY - 1) then
- debugMsg("SENSOR: "..locData[i]["name"].." Selected.")
- for j = 1, #locData do
- locData[j]["selected"] = false
- end
- locData[i]["selected"] = true
- selChunk = locData[i]["name"]
- miningMenu(locData[i]["name"])
- saveLocs()
- drawCurrent()
- break
- end
- end
- end
- end
- if itemBool then
- end
- if turtleBool then
- turtleFound = false
- for i = 1, #tData do
- if xClick >= tData[i]["scrX"] + 1 and xClick <= tData[i]["scrX"] + (turtleTileX - 1) then
- if yClick >= tData[i]["scrY"] + 1 and yClick <= tData[i]["scrY"] + (turtleTileY - 1) then
- debugMsg("SYSRUN: "..tData[i]["name"].." selected.")
- clearTurtleSelect()
- tData[i]["selected"] = true
- selTurtle = tData[i]["identifier"]
- selTurtleName = tData[i]["name"]
- tData[i]["colour"] = draw.lime
- turtleMenu()
- turtleFound = true
- saveTurtles()
- break
- end
- end
- end
- if not turtleFound then
- clearTurtleSelect()
- mainMenu()
- end
- drawCurrent()
- end
- if bpBool then
- for i = 1, #bpTab[layer] do
- for j = 1, #bpTab[layer] do
- if xClick >= bpTab[layer][i][j][3] and xClick <= bpTab[layer][i][j][3] + 2 then
- if yClick == bpTab[layer][i][j][4] + 1 then
- bpTab[layer][i][j][1] = item
- bpTab[layer][i][j][2] = itemColour
- bpTab[layer][i][j][6] = lab
- if facing then
- if bpTab[layer][i][j][5] == nil or bpTab[layer][i][j][5] == 3 then
- bpTab[layer][i][j][5] = 0
- elseif bpTab[layer][i][j][5] == 1 then
- bpTab[layer][i][j][5] = 2
- elseif bpTab[layer][i][j][5] == 2 then
- bpTab[layer][i][j][5] = 3
- elseif bpTab[layer][i][j][5] == 0 then
- bpTab[layer][i][j][5] = 1
- end
- else
- bpTab[layer][i][j][5] = nil
- end
- end
- end
- end
- end
- end
- if gridView then
- for i = 1, #bpTab[layer] do
- for j = 1, #bpTab[layer] do
- if xClick >= bpTab[layer][i][j][3] and xClick <= bpTab[layer][i][j][3] + 2 then
- if yClick == bpTab[layer][i][j][4] + 1 then
- debugMsg("SYSRUN: i: "..i..", j: "..j)
- debugMsg("SYSRUN: x: "..bpTab[1][i][j]["xPos"]..", z: "..bpTab[1][i][j]["zPos"])
- end
- end
- end
- end
- end
- end
- end
- function run()
- event, p1, p2, p3, p4, p5 = os.pullEvent()
- if event == "rednet_message" then
- listener(p1, p2)
- elseif event == "monitor_touch" then
- --debugMsg("SENSOR: "..p2..", "..p3)
- sensor(p2, p3)
- drawCurrent()
- elseif event == "key" then
- running = false
- end
- end
- --PROGRAM START--
- draw.clear()
- getPeripherals()
- switchMon()
- loadLocs()
- loadChestData()
- loadTurtles()
- loadTurtleChests()
- mainMenu()
- drawCurrent()
- running = true
- while running do
- run()
- end
- switchMon()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement