le_Fish

QuarrySwarmPCConfig

May 7th, 2020
1,306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.40 KB | None | 0 0
  1. if peripheral.getType("right") ~= "modem" and peripheral.getType("left") ~= "modem" then
  2.     error("Need a modem for a swarmbot main-pc")
  3. end
  4.  
  5. function installDiskDriver()
  6.     turtle.forward()
  7.     turtle.turnLeft()
  8.     if fs.exists("/disk/startup") then
  9.         fs.delete("/disk/startup")
  10.         sleep(5)
  11.     end
  12.     file = fs.open("/disk/startup", "w")
  13.     file.writeLine([[
  14.         shell.run("rm","data")
  15.         shell.run("rm","startup")
  16.         shell.run("rm","swarmBot")
  17.         shell.run("rm","movementApi")
  18.         shell.run("rm","gpsApi")
  19.         shell.run("rm","digApi")
  20.     ]])
  21.     file.writeLine("shell.run('pastebin', 'get', 'gXF1tY1Y', 'swarmBot')")
  22.     file.writeLine(
  23.         [[
  24.         file = fs.open('startup','w')
  25.         file.writeLine("sleep(1)")
  26.         file.writeLine("shell.run('swarmBot')")
  27.         file.close()
  28.         shell.run('swarmBot')
  29.     ]]
  30.     )
  31.     file.close()
  32.     print("Set config")
  33.     turtle.turnRight()
  34.     turtle.back()
  35. end
  36.  
  37. function bigRegisterFunction()
  38.     local position = vector.new(gps.locate(10))
  39.     local chunk = {math.floor(position.x / 16), math.floor(position.y / 16)}
  40.     local input = nil
  41.  
  42.     local config = {
  43.         chunk = {},
  44.         directions = {},
  45.         parkHeight = 85,
  46.         flyHeight = 85
  47.     }
  48.  
  49.     print("Swarmbot main-pc registration")
  50.     print("-----------------------------")
  51.     print("My current chunk is " .. chunk[1] .. "," .. chunk[2])
  52.     print("Is this correct? y/n")
  53.  
  54.     while true do
  55.         input = read():lower()
  56.         if input == "n" then
  57.             error("I'm not in the correct chunk?")
  58.         else
  59.             config.chunk[1] = chunk[1]
  60.             config.chunk[2] = chunk[2]
  61.             input = nil
  62.             break
  63.         end
  64.     end
  65.  
  66.     print("At which level should working turtle's home?")
  67.     print("Default is my height + 4, which is currently: " .. position.z + 4)
  68.  
  69.     while true do
  70.         input = tonumber(read())
  71.         if input == "" or input == nil then
  72.             config.parkHeight = position.z + 4
  73.             break
  74.         elseif type(input) == "number" and input < 256 then
  75.             config.parkHeight = input
  76.             input = nil
  77.             break
  78.         else
  79.             print("Wrong input? Input should be number, was: " .. type(input) .. " with a value of " .. input)
  80.         end
  81.     end
  82.  
  83.     print("At which level should working turtle's fly?")
  84.     print("Default is my height + 12, which is currently: " .. position.z + 12)
  85.  
  86.     while true do
  87.         input = tonumber(read())
  88.         if input == "" or input == nil then
  89.             config.flyHeight = position.z + 8
  90.             break
  91.         elseif type(input) == "number" and input < 256 then
  92.             config.flyHeight = input
  93.             input = nil
  94.             break
  95.         else
  96.             print("Wrong input? Input should be number, was: " .. type(input) .. " with a value of " .. input)
  97.         end
  98.     end
  99.    
  100.     print("At which level should working turtle's start?")
  101.     print("Default is my height, which is currently: " .. position.z)
  102.  
  103.     while true do
  104.         input = tonumber(read())
  105.         if input == "" or input == nil then
  106.             config.startHeight = position.z
  107.             break
  108.         elseif type(input) == "number" and input < 256 then
  109.             config.startHeight = input
  110.             input = nil
  111.             break
  112.         else
  113.             print("Wrong input? Input should be number, was: " .. type(input) .. " with a value of " .. input)
  114.         end
  115.     end
  116.  
  117.     print("Where should I work toward")
  118.     print("(note that I mine to the left side)")
  119.     print("String should contain N E S or W (or a combination)")
  120.  
  121.     while true do
  122.         input = read()
  123.         if input ~= nil and input ~= "" then
  124.             if type(input) ~= "string" then
  125.                 print("Wrong input? Input should be string, was: " .. type(input) .. " with a value of " .. input)
  126.             else
  127.                 if string.match(input:lower(), "n") then
  128.                     config.directions[#config.directions + 1] = "n"
  129.                 end
  130.                 if string.match(input:lower(), "e") then
  131.                     config.directions[#config.directions + 1] = "e"
  132.                 end
  133.                 if string.match(input:lower(), "s") then
  134.                     config.directions[#config.directions + 1] = "s"
  135.                 end
  136.                 if string.match(input:lower(), "w") then
  137.                     config.directions[#config.directions + 1] = "w"
  138.                 end
  139.                 if
  140.                     not string.match(input:lower(), "w") and not string.match(input:lower(), "s") and
  141.                         not string.match(input:lower(), "e") and
  142.                         not string.match(input:lower(), "n")
  143.                  then
  144.                     print("Wrong input? Input should include atleast n,e,s or w")
  145.                 else
  146.                     break
  147.                 end
  148.             end
  149.         end
  150.     end
  151.  
  152.     print("Whats the max length I can go in chunks")
  153.     print("Default is 128")
  154.     while true do
  155.         input = tonumber(read())
  156.         if input == "" or input == nil then
  157.             config.maxLength = 128
  158.             break
  159.         elseif type(input) == "number" then
  160.             config.maxLength = input
  161.             input = nil
  162.             break
  163.         else
  164.             print("Wrong input? Input should be number, was: " .. type(input) .. " with a value of " .. input)
  165.         end
  166.     end
  167.     term.clear()
  168.     term.setCursorPos(1, 1)
  169.     print("My config is as follows:")
  170.     print("Home chunk: " .. config.chunk[1] .. "," .. config.chunk[2])
  171.     print("Turtle's park at this height: " .. config.parkHeight)
  172.     print("Turtle's start at this height: " .. config.startHeight)
  173.     print("Turtle's flies at this height: " .. config.flyHeight)
  174.     local directions = ""
  175.     for i = 1, #config.directions do
  176.         if config.directions[i] ~= nil then
  177.             directions = directions .. tostring(config.directions[i]) .. " "
  178.         end
  179.     end
  180.  
  181.     print("I'm going to mine towards: " .. directions)
  182.     print("I'm going to mine a lenght of: " .. config.maxLength .. " chunks")
  183.     print("Is this all correct? y/n")
  184.  
  185.     while true do
  186.         input = read()
  187.         if input ~= nil or input ~= "" then
  188.             if input == "n" then
  189.                 term.clear()
  190.                 term.setCursorPos(1, 1)
  191.                 bigRegisterFunction()
  192.             else
  193.                 input = nil
  194.                 break
  195.             end
  196.         end
  197.     end
  198.  
  199.     print("Saving input.")
  200.  
  201.     local file = fs.open("data/config", "w")
  202.     file.writeLine(textutils.serialize(config))
  203.     file.close()
  204.  
  205.     term.clear()
  206.     term.setCursorPos(1, 1)
  207.     print("Should I install the disk driver? y/n")
  208.     while true do
  209.         input = read():lower()
  210.         if input == "y" then
  211.             installDiskDriver()
  212.             break
  213.         elseif input == "n" then
  214.             break
  215.         end
  216.         sleep(1)
  217.     end
  218. end
  219. term.clear()
  220. term.setCursorPos(1, 1)
  221. bigRegisterFunction()
Advertisement
Add Comment
Please, Sign In to add comment